Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
45ab7091
Commit
45ab7091
authored
6 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Adding route count to route table
parent
631f24f8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
routingtable/table.go
+14
-4
14 additions, 4 deletions
routingtable/table.go
routingtable/trie.go
+2
-3
2 additions, 3 deletions
routingtable/trie.go
with
16 additions
and
7 deletions
routingtable/table.go
+
14
−
4
View file @
45ab7091
...
@@ -2,6 +2,7 @@ package routingtable
...
@@ -2,6 +2,7 @@ package routingtable
import
(
import
(
"sync"
"sync"
"sync/atomic"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/route"
...
@@ -9,8 +10,9 @@ import (
...
@@ -9,8 +10,9 @@ import (
// RoutingTable is a binary trie that stores prefixes and their paths
// RoutingTable is a binary trie that stores prefixes and their paths
type
RoutingTable
struct
{
type
RoutingTable
struct
{
root
*
node
routeCount
int64
mu
sync
.
RWMutex
root
*
node
mu
sync
.
RWMutex
}
}
// NewRoutingTable creates a new routing table
// NewRoutingTable creates a new routing table
...
@@ -18,6 +20,11 @@ func NewRoutingTable() *RoutingTable {
...
@@ -18,6 +20,11 @@ func NewRoutingTable() *RoutingTable {
return
&
RoutingTable
{}
return
&
RoutingTable
{}
}
}
// GetRouteCount gets the amount of stored routes
func
(
rt
*
RoutingTable
)
GetRouteCount
()
int64
{
return
atomic
.
LoadInt64
(
&
rt
.
routeCount
)
}
// AddPath adds a path to the routing table
// AddPath adds a path to the routing table
func
(
rt
*
RoutingTable
)
AddPath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
func
(
rt
*
RoutingTable
)
AddPath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
rt
.
mu
.
Lock
()
rt
.
mu
.
Lock
()
...
@@ -29,6 +36,7 @@ func (rt *RoutingTable) AddPath(pfx net.Prefix, p *route.Path) error {
...
@@ -29,6 +36,7 @@ func (rt *RoutingTable) AddPath(pfx net.Prefix, p *route.Path) error {
func
(
rt
*
RoutingTable
)
addPath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
func
(
rt
*
RoutingTable
)
addPath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
if
rt
.
root
==
nil
{
if
rt
.
root
==
nil
{
rt
.
root
=
newNode
(
pfx
,
p
,
pfx
.
Pfxlen
(),
false
)
rt
.
root
=
newNode
(
pfx
,
p
,
pfx
.
Pfxlen
(),
false
)
atomic
.
AddInt64
(
&
rt
.
routeCount
,
1
)
return
nil
return
nil
}
}
...
@@ -55,11 +63,13 @@ func (rt *RoutingTable) ReplacePath(pfx net.Prefix, p *route.Path) []*route.Path
...
@@ -55,11 +63,13 @@ func (rt *RoutingTable) ReplacePath(pfx net.Prefix, p *route.Path) []*route.Path
}
}
// RemovePath removes a path from the trie
// RemovePath removes a path from the trie
func
(
rt
*
RoutingTable
)
RemovePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
bool
{
func
(
rt
*
RoutingTable
)
RemovePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
{
rt
.
mu
.
Lock
()
rt
.
mu
.
Lock
()
defer
rt
.
mu
.
Unlock
()
defer
rt
.
mu
.
Unlock
()
return
rt
.
removePath
(
pfx
,
p
)
if
rt
.
removePath
(
pfx
,
p
)
{
atomic
.
AddInt64
(
&
rt
.
routeCount
,
-
1
)
}
}
}
func
(
rt
*
RoutingTable
)
removePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
bool
{
func
(
rt
*
RoutingTable
)
removePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
bool
{
...
...
This diff is collapsed.
Click to expand it.
routingtable/trie.go
+
2
−
3
View file @
45ab7091
...
@@ -27,7 +27,7 @@ func newNode(pfx net.Prefix, path *route.Path, skip uint8, dummy bool) *node {
...
@@ -27,7 +27,7 @@ func newNode(pfx net.Prefix, path *route.Path, skip uint8, dummy bool) *node {
return
n
return
n
}
}
func
(
n
*
node
)
removePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
(
success
bool
)
{
func
(
n
*
node
)
removePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
(
final
bool
)
{
if
n
==
nil
{
if
n
==
nil
{
return
false
return
false
}
}
...
@@ -37,14 +37,13 @@ func (n *node) removePath(pfx net.Prefix, p *route.Path) (success bool) {
...
@@ -37,14 +37,13 @@ func (n *node) removePath(pfx net.Prefix, p *route.Path) (success bool) {
return
return
}
}
nPaths
:=
len
(
n
.
route
.
Paths
())
nPathsAfterDel
:=
n
.
route
.
RemovePath
(
p
)
nPathsAfterDel
:=
n
.
route
.
RemovePath
(
p
)
if
len
(
n
.
route
.
Paths
())
==
0
{
if
len
(
n
.
route
.
Paths
())
==
0
{
// FIXME: Can this node actually be removed from the trie entirely?
// FIXME: Can this node actually be removed from the trie entirely?
n
.
dummy
=
true
n
.
dummy
=
true
}
}
return
nPathsAfterDel
<
nPaths
return
nPathsAfterDel
==
0
}
}
b
:=
getBitUint32
(
pfx
.
Addr
(),
n
.
route
.
Pfxlen
()
+
1
)
b
:=
getBitUint32
(
pfx
.
Addr
(),
n
.
route
.
Pfxlen
()
+
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment