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
fd45a9a4
Commit
fd45a9a4
authored
7 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Making routing table thread safe
parent
c68656cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
routingtable/routingtable/table.go
+18
-0
18 additions, 0 deletions
routingtable/routingtable/table.go
with
18 additions
and
0 deletions
routingtable/routingtable/table.go
+
18
−
0
View file @
fd45a9a4
...
@@ -20,6 +20,9 @@ func NewRoutingTable() *RoutingTable {
...
@@ -20,6 +20,9 @@ func NewRoutingTable() *RoutingTable {
// 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
()
defer
rt
.
mu
.
Unlock
()
if
rt
.
root
==
nil
{
if
rt
.
root
==
nil
{
rt
.
root
=
newNode
(
pfx
,
p
,
pfx
.
Pfxlen
(),
false
)
rt
.
root
=
newNode
(
pfx
,
p
,
pfx
.
Pfxlen
(),
false
)
return
nil
return
nil
...
@@ -31,12 +34,18 @@ func (rt *RoutingTable) AddPath(pfx net.Prefix, p *route.Path) error {
...
@@ -31,12 +34,18 @@ func (rt *RoutingTable) AddPath(pfx net.Prefix, p *route.Path) error {
// RemovePath removes a path from the trie
// RemovePath removes a path from the trie
func
(
rt
*
RoutingTable
)
RemovePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
func
(
rt
*
RoutingTable
)
RemovePath
(
pfx
net
.
Prefix
,
p
*
route
.
Path
)
error
{
rt
.
mu
.
Lock
()
defer
rt
.
mu
.
Unlock
()
rt
.
root
.
removePath
(
pfx
,
p
)
rt
.
root
.
removePath
(
pfx
,
p
)
return
nil
return
nil
}
}
// LPM performs a longest prefix match for pfx on lpm
// LPM performs a longest prefix match for pfx on lpm
func
(
rt
*
RoutingTable
)
LPM
(
pfx
net
.
Prefix
)
(
res
[]
*
route
.
Route
)
{
func
(
rt
*
RoutingTable
)
LPM
(
pfx
net
.
Prefix
)
(
res
[]
*
route
.
Route
)
{
rt
.
mu
.
RLock
()
defer
rt
.
mu
.
RUnlock
()
if
rt
.
root
==
nil
{
if
rt
.
root
==
nil
{
return
nil
return
nil
}
}
...
@@ -47,6 +56,9 @@ func (rt *RoutingTable) LPM(pfx net.Prefix) (res []*route.Route) {
...
@@ -47,6 +56,9 @@ func (rt *RoutingTable) LPM(pfx net.Prefix) (res []*route.Route) {
// Get get's the route for pfx from the LPM
// Get get's the route for pfx from the LPM
func
(
rt
*
RoutingTable
)
Get
(
pfx
net
.
Prefix
)
*
route
.
Route
{
func
(
rt
*
RoutingTable
)
Get
(
pfx
net
.
Prefix
)
*
route
.
Route
{
rt
.
mu
.
RLock
()
defer
rt
.
mu
.
RUnlock
()
if
rt
.
root
==
nil
{
if
rt
.
root
==
nil
{
return
nil
return
nil
}
}
...
@@ -60,6 +72,9 @@ func (rt *RoutingTable) Get(pfx net.Prefix) *route.Route {
...
@@ -60,6 +72,9 @@ func (rt *RoutingTable) Get(pfx net.Prefix) *route.Route {
// GetLonger get's prefix pfx and all it's more specifics from the LPM
// GetLonger get's prefix pfx and all it's more specifics from the LPM
func
(
rt
*
RoutingTable
)
GetLonger
(
pfx
net
.
Prefix
)
(
res
[]
*
route
.
Route
)
{
func
(
rt
*
RoutingTable
)
GetLonger
(
pfx
net
.
Prefix
)
(
res
[]
*
route
.
Route
)
{
rt
.
mu
.
RLock
()
defer
rt
.
mu
.
RUnlock
()
if
rt
.
root
==
nil
{
if
rt
.
root
==
nil
{
return
[]
*
route
.
Route
{}
return
[]
*
route
.
Route
{}
}
}
...
@@ -69,6 +84,9 @@ func (rt *RoutingTable) GetLonger(pfx net.Prefix) (res []*route.Route) {
...
@@ -69,6 +84,9 @@ func (rt *RoutingTable) GetLonger(pfx net.Prefix) (res []*route.Route) {
// Dump dumps all routes in table rt into a slice
// Dump dumps all routes in table rt into a slice
func
(
rt
*
RoutingTable
)
Dump
()
[]
*
route
.
Route
{
func
(
rt
*
RoutingTable
)
Dump
()
[]
*
route
.
Route
{
rt
.
mu
.
RLock
()
defer
rt
.
mu
.
RUnlock
()
res
:=
make
([]
*
route
.
Route
,
0
)
res
:=
make
([]
*
route
.
Route
,
0
)
return
rt
.
root
.
dump
(
res
)
return
rt
.
root
.
dump
(
res
)
}
}
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