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
68e33f6a
Commit
68e33f6a
authored
6 years ago
by
Maximilian Wilhelm
Browse files
Options
Downloads
Patches
Plain Diff
Use RWLock with menaingful name, overflow check, white-sapce fixes.
Signed-off-by:
Maximilian Wilhelm
<
max@sdn.clinic
>
parent
a1bc58e3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
protocols/bgp/server/server.go
+1
-2
1 addition, 2 deletions
protocols/bgp/server/server.go
routingtable/BUILD.bazel
+1
-1
1 addition, 1 deletion
routingtable/BUILD.bazel
routingtable/contributing_asn_list.go
+27
-14
27 additions, 14 deletions
routingtable/contributing_asn_list.go
with
29 additions
and
17 deletions
protocols/bgp/server/server.go
+
1
−
2
View file @
68e33f6a
...
@@ -7,10 +7,9 @@ import (
...
@@ -7,10 +7,9 @@ import (
"strings"
"strings"
"sync"
"sync"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
)
)
...
...
This diff is collapsed.
Click to expand it.
routingtable/BUILD.bazel
+
1
−
1
View file @
68e33f6a
...
@@ -26,7 +26,7 @@ go_test(
...
@@ -26,7 +26,7 @@ go_test(
name
=
"
go_default_test
"
,
name
=
"
go_default_test
"
,
srcs
=
[
srcs
=
[
"
client_manager_test.go
"
,
"
client_manager_test.go
"
,
"
contributing_asn_list_test.go
"
,
"
contributing_asn_list_test.go
"
,
"
table_test.go
"
,
"
table_test.go
"
,
"
trie_test.go
"
,
"
trie_test.go
"
,
"
update_helper_test.go
"
,
"
update_helper_test.go
"
,
...
...
This diff is collapsed.
Click to expand it.
routingtable/contributing_asn_list.go
+
27
−
14
View file @
68e33f6a
package
routingtable
package
routingtable
import
(
import
(
"fmt"
"math"
"sync"
"sync"
)
)
...
@@ -11,8 +13,8 @@ type contributingASN struct {
...
@@ -11,8 +13,8 @@ type contributingASN struct {
// ContributingASNs contains a list of contributing ASN to a LocRIB to check ASPaths for possible routing loops.
// ContributingASNs contains a list of contributing ASN to a LocRIB to check ASPaths for possible routing loops.
type
ContributingASNs
struct
{
type
ContributingASNs
struct
{
contributingASNs
[]
*
contributingASN
contributingASNs
[]
*
contributingASN
mu
sync
.
RWMutex
contributingASNsLock
sync
.
RWMutex
}
}
// NewContributingASNs creates a list of contributing ASNs to a LocRIB for routing loop prevention.
// NewContributingASNs creates a list of contributing ASNs to a LocRIB for routing loop prevention.
...
@@ -26,12 +28,17 @@ func NewContributingASNs() *ContributingASNs {
...
@@ -26,12 +28,17 @@ func NewContributingASNs() *ContributingASNs {
// Add a new ASN to the list of contributing ASNs or add the ref count of an existing one.
// Add a new ASN to the list of contributing ASNs or add the ref count of an existing one.
func
(
c
*
ContributingASNs
)
Add
(
asn
uint32
)
{
func
(
c
*
ContributingASNs
)
Add
(
asn
uint32
)
{
c
.
mu
.
R
Lock
()
c
.
contributingASNsLock
.
Lock
()
defer
c
.
mu
.
R
Unlock
()
defer
c
.
contributingASNsLock
.
Unlock
()
for
_
,
cASN
:=
range
c
.
contributingASNs
{
for
_
,
cASN
:=
range
c
.
contributingASNs
{
if
cASN
.
asn
==
asn
{
if
cASN
.
asn
==
asn
{
cASN
.
count
++
cASN
.
count
++
if
cASN
.
count
==
math
.
MaxUint32
{
panic
(
fmt
.
Sprintf
(
"Contributing ASNs counter overflow triggered for AS %d. Dyning of shame."
,
asn
))
}
return
return
}
}
}
}
...
@@ -44,27 +51,33 @@ func (c *ContributingASNs) Add(asn uint32) {
...
@@ -44,27 +51,33 @@ func (c *ContributingASNs) Add(asn uint32) {
// Remove a ASN to the list of contributing ASNs or decrement the ref count of an existing one.
// Remove a ASN to the list of contributing ASNs or decrement the ref count of an existing one.
func
(
c
*
ContributingASNs
)
Remove
(
asn
uint32
)
{
func
(
c
*
ContributingASNs
)
Remove
(
asn
uint32
)
{
c
.
mu
.
R
Lock
()
c
.
contributingASNsLock
.
Lock
()
defer
c
.
mu
.
R
Unlock
()
defer
c
.
contributingASNsLock
.
Unlock
()
asnList
:=
c
.
contributingASNs
asnList
:=
c
.
contributingASNs
for
i
,
cASN
:=
range
asnList
{
for
i
,
cASN
:=
range
asnList
{
if
cASN
.
asn
==
asn
{
if
cASN
.
asn
!=
asn
{
cASN
.
count
--
continue
}
if
cASN
.
count
==
0
{
cASN
.
count
--
copy
(
asnList
[
i
:
],
asnList
[
i
+
1
:
])
asnList
=
asnList
[
:
len
(
asnList
)]
if
cASN
.
count
==
0
{
c
.
contributingASNs
=
asnList
[
:
len
(
asnList
)
-
1
]
copy
(
asnList
[
i
:
],
asnList
[
i
+
1
:
])
}
asnList
=
asnList
[
:
len
(
asnList
)]
return
c
.
contributingASNs
=
asnList
[
:
len
(
asnList
)
-
1
]
}
}
return
}
}
}
}
// IsContributingASN checks if a given ASN is part of the contributing ASNs
// IsContributingASN checks if a given ASN is part of the contributing ASNs
func
(
c
*
ContributingASNs
)
IsContributingASN
(
asn
uint32
)
bool
{
func
(
c
*
ContributingASNs
)
IsContributingASN
(
asn
uint32
)
bool
{
c
.
contributingASNsLock
.
Lock
()
defer
c
.
contributingASNsLock
.
Unlock
()
for
_
,
cASN
:=
range
c
.
contributingASNs
{
for
_
,
cASN
:=
range
c
.
contributingASNs
{
if
asn
==
cASN
.
asn
{
if
asn
==
cASN
.
asn
{
return
true
return
true
...
...
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