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
dc43526d
Unverified
Commit
dc43526d
authored
6 years ago
by
takt
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into coverage-badge
parents
8d5d69c8
d095a7a3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
net/ip_test.go
+36
-4
36 additions, 4 deletions
net/ip_test.go
net/prefix_test.go
+12
-11
12 additions, 11 deletions
net/prefix_test.go
route/bgp_path.go
+55
-38
55 additions, 38 deletions
route/bgp_path.go
route/bgp_path_test.go
+34
-3
34 additions, 3 deletions
route/bgp_path_test.go
with
137 additions
and
56 deletions
net/ip_test.go
+
36
−
4
View file @
dc43526d
...
@@ -497,14 +497,23 @@ func TestBitAtPosition(t *testing.T) {
...
@@ -497,14 +497,23 @@ func TestBitAtPosition(t *testing.T) {
position
:
1
,
position
:
1
,
expected
:
true
,
expected
:
true
,
},
},
{
name
:
"IPv4: invalid position"
,
input
:
IPv4
(
0
),
position
:
33
,
expected
:
false
,
},
{
name
:
"IPv6: invalid position"
,
input
:
IPv6
(
0
,
0
),
position
:
129
,
expected
:
false
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
b
:=
test
.
input
.
BitAtPosition
(
test
.
position
)
b
:=
test
.
input
.
BitAtPosition
(
test
.
position
)
if
b
!=
test
.
expected
{
assert
.
Equal
(
t
,
test
.
expected
,
b
,
test
.
name
)
t
.
Errorf
(
"%s: Unexpected failure: Bit %d of %v is %v. Expected %v"
,
test
.
name
,
test
.
position
,
test
.
input
,
b
,
test
.
expected
)
}
}
}
}
}
...
@@ -550,3 +559,26 @@ func TestIPFromString(t *testing.T) {
...
@@ -550,3 +559,26 @@ func TestIPFromString(t *testing.T) {
})
})
}
}
}
}
func
TestSizeBytes
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
IP
expected
uint8
}{
{
name
:
"IPv4"
,
input
:
IPv4
(
0
),
expected
:
4
,
},
{
name
:
"IPv6"
,
input
:
IPv6
(
0
,
0
),
expected
:
16
,
},
}
for
_
,
test
:=
range
tests
{
assert
.
Equal
(
t
,
test
.
expected
,
test
.
input
.
SizeBytes
(),
test
.
name
)
}
}
This diff is collapsed.
Click to expand it.
net/prefix_test.go
+
12
−
11
View file @
dc43526d
...
@@ -300,13 +300,11 @@ func TestGetSupernet(t *testing.T) {
...
@@ -300,13 +300,11 @@ func TestGetSupernet(t *testing.T) {
func
TestContains
(
t
*
testing
.
T
)
{
func
TestContains
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
a
Prefix
a
Prefix
b
Prefix
b
Prefix
expected
bool
expected
bool
}{
}{
{
{
name
:
"Test 1"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
0
),
addr
:
IPv4
(
0
),
pfxlen
:
0
,
pfxlen
:
0
,
...
@@ -318,7 +316,6 @@ func TestContains(t *testing.T) {
...
@@ -318,7 +316,6 @@ func TestContains(t *testing.T) {
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"Test 2"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
100
),
addr
:
IPv4
(
100
),
pfxlen
:
24
,
pfxlen
:
24
,
...
@@ -330,7 +327,6 @@ func TestContains(t *testing.T) {
...
@@ -330,7 +327,6 @@ func TestContains(t *testing.T) {
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"Test 3"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
167772160
),
addr
:
IPv4
(
167772160
),
pfxlen
:
8
,
pfxlen
:
8
,
...
@@ -342,7 +338,6 @@ func TestContains(t *testing.T) {
...
@@ -342,7 +338,6 @@ func TestContains(t *testing.T) {
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"Test 4"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
167772160
),
addr
:
IPv4
(
167772160
),
pfxlen
:
8
,
pfxlen
:
8
,
...
@@ -354,7 +349,6 @@ func TestContains(t *testing.T) {
...
@@ -354,7 +349,6 @@ func TestContains(t *testing.T) {
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"Test 5"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
167772160
),
addr
:
IPv4
(
167772160
),
pfxlen
:
8
,
pfxlen
:
8
,
...
@@ -366,7 +360,6 @@ func TestContains(t *testing.T) {
...
@@ -366,7 +360,6 @@ func TestContains(t *testing.T) {
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"Test 6"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4
(
167772160
),
addr
:
IPv4
(
167772160
),
pfxlen
:
8
,
pfxlen
:
8
,
...
@@ -378,7 +371,6 @@ func TestContains(t *testing.T) {
...
@@ -378,7 +371,6 @@ func TestContains(t *testing.T) {
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"Test 7"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv4FromOctets
(
169
,
0
,
0
,
0
),
addr
:
IPv4FromOctets
(
169
,
0
,
0
,
0
),
pfxlen
:
25
,
pfxlen
:
25
,
...
@@ -390,7 +382,6 @@ func TestContains(t *testing.T) {
...
@@ -390,7 +382,6 @@ func TestContains(t *testing.T) {
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"IPv6: 2001:678:1e0:100::/56 is subnet of 2001:678:1e0::/48"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0
,
0
,
0
,
0
,
0
),
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0
,
0
,
0
,
0
,
0
),
pfxlen
:
48
,
pfxlen
:
48
,
...
@@ -402,7 +393,6 @@ func TestContains(t *testing.T) {
...
@@ -402,7 +393,6 @@ func TestContains(t *testing.T) {
},
},
},
},
{
{
name
:
"IPv6: 2001:678:1e0:100::/56 is subnet of 2001:678:1e0::/48"
,
a
:
Prefix
{
a
:
Prefix
{
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0x200
,
0
,
0
,
0
,
0
),
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0x200
,
0
,
0
,
0
,
0
),
pfxlen
:
56
,
pfxlen
:
56
,
...
@@ -413,11 +403,22 @@ func TestContains(t *testing.T) {
...
@@ -413,11 +403,22 @@ func TestContains(t *testing.T) {
},
},
expected
:
false
,
expected
:
false
,
},
},
{
a
:
Prefix
{
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0x200
,
0
,
0
,
0
,
0
),
pfxlen
:
65
,
},
b
:
Prefix
{
addr
:
IPv6FromBlocks
(
0x2001
,
0x678
,
0x1e0
,
0x100
,
0
,
0
,
0
,
0
),
pfxlen
:
64
,
},
expected
:
false
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
res
:=
test
.
a
.
Contains
(
test
.
b
)
res
:=
test
.
a
.
Contains
(
test
.
b
)
assert
.
Equal
(
t
,
res
,
test
.
expected
,
"
Unexpected result %v for test %s: %s contains %s"
,
res
,
test
.
name
,
test
.
a
,
test
.
b
)
assert
.
Equal
(
t
,
res
,
test
.
expected
,
"
Subnet %s contains %s"
,
test
.
a
,
test
.
b
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
route/bgp_path.go
+
55
−
38
View file @
dc43526d
...
@@ -236,6 +236,8 @@ func (b *BGPPath) better(c *BGPPath) bool {
...
@@ -236,6 +236,8 @@ func (b *BGPPath) better(c *BGPPath) bool {
// Print all known information about a route in logfile friendly format
// Print all known information about a route in logfile friendly format
func
(
b
*
BGPPath
)
String
()
string
{
func
(
b
*
BGPPath
)
String
()
string
{
buf
:=
&
strings
.
Builder
{}
origin
:=
""
origin
:=
""
switch
b
.
Origin
{
switch
b
.
Origin
{
case
0
:
case
0
:
...
@@ -251,30 +253,32 @@ func (b *BGPPath) String() string {
...
@@ -251,30 +253,32 @@ func (b *BGPPath) String() string {
bgpType
=
"external"
bgpType
=
"external"
}
}
ret
:=
fmt
.
S
printf
(
"Local Pref: %d, "
,
b
.
LocalPref
)
fmt
.
F
printf
(
buf
,
"Local Pref: %d, "
,
b
.
LocalPref
)
ret
+=
fmt
.
S
printf
(
"Origin: %s, "
,
origin
)
fmt
.
F
printf
(
buf
,
"Origin: %s, "
,
origin
)
ret
+=
fmt
.
S
printf
(
"AS Path: %v, "
,
b
.
ASPath
)
fmt
.
F
printf
(
buf
,
"AS Path: %v, "
,
b
.
ASPath
)
ret
+=
fmt
.
S
printf
(
"BGP type: %s, "
,
bgpType
)
fmt
.
F
printf
(
buf
,
"BGP type: %s, "
,
bgpType
)
ret
+=
fmt
.
S
printf
(
"NEXT HOP: %s, "
,
b
.
NextHop
)
fmt
.
F
printf
(
buf
,
"NEXT HOP: %s, "
,
b
.
NextHop
)
ret
+=
fmt
.
S
printf
(
"MED: %d, "
,
b
.
MED
)
fmt
.
F
printf
(
buf
,
"MED: %d, "
,
b
.
MED
)
ret
+=
fmt
.
S
printf
(
"Path ID: %d, "
,
b
.
PathIdentifier
)
fmt
.
F
printf
(
buf
,
"Path ID: %d, "
,
b
.
PathIdentifier
)
ret
+=
fmt
.
S
printf
(
"Source: %s, "
,
b
.
Source
)
fmt
.
F
printf
(
buf
,
"Source: %s, "
,
b
.
Source
)
ret
+=
fmt
.
S
printf
(
"Communities: %v, "
,
b
.
Communities
)
fmt
.
F
printf
(
buf
,
"Communities: %v, "
,
b
.
Communities
)
ret
+=
fmt
.
S
printf
(
"LargeCommunities: %v
,
"
,
b
.
LargeCommunities
)
fmt
.
F
printf
(
buf
,
"LargeCommunities: %v"
,
b
.
LargeCommunities
)
if
b
.
OriginatorID
!=
0
{
if
b
.
OriginatorID
!=
0
{
oid
:=
convert
.
Uint32Byte
(
b
.
OriginatorID
)
oid
:=
convert
.
Uint32Byte
(
b
.
OriginatorID
)
ret
+=
fmt
.
S
printf
(
"
OriginatorID: %d.%d.%d.%d
,
"
,
oid
[
0
],
oid
[
1
],
oid
[
2
],
oid
[
3
])
fmt
.
F
printf
(
buf
,
",
OriginatorID: %d.%d.%d.%d"
,
oid
[
0
],
oid
[
1
],
oid
[
2
],
oid
[
3
])
}
}
if
b
.
ClusterList
!=
nil
{
if
b
.
ClusterList
!=
nil
{
ret
+=
fmt
.
S
printf
(
"
ClusterList %s"
,
b
.
ClusterListString
())
fmt
.
F
printf
(
buf
,
",
ClusterList %s"
,
b
.
ClusterListString
())
}
}
return
ret
return
buf
.
String
()
}
}
// Print all known information about a route in human readable form
// Print all known information about a route in human readable form
func
(
b
*
BGPPath
)
Print
()
string
{
func
(
b
*
BGPPath
)
Print
()
string
{
buf
:=
&
strings
.
Builder
{}
origin
:=
""
origin
:=
""
switch
b
.
Origin
{
switch
b
.
Origin
{
case
0
:
case
0
:
...
@@ -290,26 +294,26 @@ func (b *BGPPath) Print() string {
...
@@ -290,26 +294,26 @@ func (b *BGPPath) Print() string {
bgpType
=
"external"
bgpType
=
"external"
}
}
ret
:=
fmt
.
S
printf
(
"
\t\t
Local Pref: %d
\n
"
,
b
.
LocalPref
)
fmt
.
F
printf
(
buf
,
"
\t\t
Local Pref: %d
\n
"
,
b
.
LocalPref
)
ret
+=
fmt
.
S
printf
(
"
\t\t
Origin: %s
\n
"
,
origin
)
fmt
.
F
printf
(
buf
,
"
\t\t
Origin: %s
\n
"
,
origin
)
ret
+=
fmt
.
S
printf
(
"
\t\t
AS Path: %v
\n
"
,
b
.
ASPath
)
fmt
.
F
printf
(
buf
,
"
\t\t
AS Path: %v
\n
"
,
b
.
ASPath
)
ret
+=
fmt
.
S
printf
(
"
\t\t
BGP type: %s
\n
"
,
bgpType
)
fmt
.
F
printf
(
buf
,
"
\t\t
BGP type: %s
\n
"
,
bgpType
)
ret
+=
fmt
.
S
printf
(
"
\t\t
NEXT HOP: %s
\n
"
,
b
.
NextHop
)
fmt
.
F
printf
(
buf
,
"
\t\t
NEXT HOP: %s
\n
"
,
b
.
NextHop
)
ret
+=
fmt
.
S
printf
(
"
\t\t
MED: %d
\n
"
,
b
.
MED
)
fmt
.
F
printf
(
buf
,
"
\t\t
MED: %d
\n
"
,
b
.
MED
)
ret
+=
fmt
.
S
printf
(
"
\t\t
Path ID: %d
\n
"
,
b
.
PathIdentifier
)
fmt
.
F
printf
(
buf
,
"
\t\t
Path ID: %d
\n
"
,
b
.
PathIdentifier
)
ret
+=
fmt
.
S
printf
(
"
\t\t
Source: %s
\n
"
,
b
.
Source
)
fmt
.
F
printf
(
buf
,
"
\t\t
Source: %s
\n
"
,
b
.
Source
)
ret
+=
fmt
.
S
printf
(
"
\t\t
Communities: %v
\n
"
,
b
.
Communities
)
fmt
.
F
printf
(
buf
,
"
\t\t
Communities: %v
\n
"
,
b
.
Communities
)
ret
+=
fmt
.
S
printf
(
"
\t\t
LargeCommunities: %v
\n
"
,
b
.
LargeCommunities
)
fmt
.
F
printf
(
buf
,
"
\t\t
LargeCommunities: %v
\n
"
,
b
.
LargeCommunities
)
if
b
.
OriginatorID
!=
0
{
if
b
.
OriginatorID
!=
0
{
oid
:=
convert
.
Uint32Byte
(
b
.
OriginatorID
)
oid
:=
convert
.
Uint32Byte
(
b
.
OriginatorID
)
ret
+=
fmt
.
S
printf
(
"
\t\t
OriginatorID: %d.%d.%d.%d
\n
"
,
oid
[
0
],
oid
[
1
],
oid
[
2
],
oid
[
3
])
fmt
.
F
printf
(
buf
,
"
\t\t
OriginatorID: %d.%d.%d.%d
\n
"
,
oid
[
0
],
oid
[
1
],
oid
[
2
],
oid
[
3
])
}
}
if
b
.
ClusterList
!=
nil
{
if
b
.
ClusterList
!=
nil
{
ret
+=
fmt
.
S
printf
(
"
\t\t
ClusterList %s
\n
"
,
b
.
ClusterListString
())
fmt
.
F
printf
(
buf
,
"
\t\t
ClusterList %s
\n
"
,
b
.
ClusterListString
())
}
}
return
ret
return
buf
.
String
()
}
}
// Prepend the given BGPPath with the given ASN given times
// Prepend the given BGPPath with the given ASN given times
...
@@ -400,31 +404,44 @@ func (b *BGPPath) ComputeHash() string {
...
@@ -400,31 +404,44 @@ func (b *BGPPath) ComputeHash() string {
// CommunitiesString returns the formated communities
// CommunitiesString returns the formated communities
func
(
b
*
BGPPath
)
CommunitiesString
()
string
{
func
(
b
*
BGPPath
)
CommunitiesString
()
string
{
str
:=
""
str
:=
&
strings
.
Builder
{}
for
_
,
com
:=
range
b
.
Communities
{
str
+=
types
.
CommunityStringForUint32
(
com
)
+
" "
for
i
,
com
:=
range
b
.
Communities
{
if
i
>
0
{
str
.
WriteByte
(
' '
)
}
str
.
WriteString
(
types
.
CommunityStringForUint32
(
com
))
}
}
return
str
ings
.
TrimRight
(
str
,
" "
)
return
str
.
String
(
)
}
}
// ClusterListString returns the formated ClusterList
// ClusterListString returns the formated ClusterList
func
(
b
*
BGPPath
)
ClusterListString
()
string
{
func
(
b
*
BGPPath
)
ClusterListString
()
string
{
str
:=
""
str
:=
&
strings
.
Builder
{}
for
_
,
cid
:=
range
b
.
ClusterList
{
for
i
,
cid
:=
range
b
.
ClusterList
{
if
i
>
0
{
str
.
WriteByte
(
' '
)
}
octes
:=
convert
.
Uint32Byte
(
cid
)
octes
:=
convert
.
Uint32Byte
(
cid
)
str
+=
fmt
.
Sprintf
(
"%d.%d.%d.%d "
,
octes
[
0
],
octes
[
1
],
octes
[
2
],
octes
[
3
])
fmt
.
Fprintf
(
str
,
"%d.%d.%d.%d"
,
octes
[
0
],
octes
[
1
],
octes
[
2
],
octes
[
3
])
}
}
return
str
ings
.
TrimRight
(
str
,
" "
)
return
str
.
String
(
)
}
}
// LargeCommunitiesString returns the formated communities
// LargeCommunitiesString returns the formated communities
func
(
b
*
BGPPath
)
LargeCommunitiesString
()
string
{
func
(
b
*
BGPPath
)
LargeCommunitiesString
()
string
{
str
:=
""
str
:=
&
strings
.
Builder
{}
for
_
,
com
:=
range
b
.
LargeCommunities
{
str
+=
com
.
String
()
+
" "
for
i
,
com
:=
range
b
.
LargeCommunities
{
if
i
>
0
{
str
.
WriteByte
(
' '
)
}
str
.
WriteString
(
com
.
String
())
}
}
return
str
ings
.
TrimRight
(
str
,
" "
)
return
str
.
String
(
)
}
}
This diff is collapsed.
Click to expand it.
route/bgp_path_test.go
+
34
−
3
View file @
dc43526d
...
@@ -311,9 +311,40 @@ func TestLength(t *testing.T) {
...
@@ -311,9 +311,40 @@ func TestLength(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
calcLen
:=
test
.
path
.
Length
()
calcLen
:=
test
.
path
.
Length
()
assert
.
Equal
(
t
,
test
.
expected
,
calcLen
,
test
.
name
)
}
}
func
TestBGPPathString
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
BGPPath
expectedPrint
string
expectedString
string
}{
{
input
:
BGPPath
{
EBGP
:
true
,
OriginatorID
:
23
,
ClusterList
:
[]
uint32
{
10
,
20
},
},
expectedString
:
"Local Pref: 0, Origin: Incomplete, AS Path: , BGP type: external, NEXT HOP: 0:0:0:0:0:0:0:0, MED: 0, Path ID: 0, Source: 0:0:0:0:0:0:0:0, Communities: [], LargeCommunities: [], OriginatorID: 0.0.0.23, ClusterList 0.0.0.10 0.0.0.20"
,
expectedPrint
:
` Local Pref: 0
Origin: Incomplete
AS Path:
BGP type: external
NEXT HOP: 0:0:0:0:0:0:0:0
MED: 0
Path ID: 0
Source: 0:0:0:0:0:0:0:0
Communities: []
LargeCommunities: []
OriginatorID: 0.0.0.23
ClusterList 0.0.0.10 0.0.0.20
`
,
},
}
if
calcLen
!=
test
.
expected
{
for
_
,
test
:=
range
tests
{
t
.
Errorf
(
"Unexpected result for test %q: Expected: %d Got: %d"
,
test
.
name
,
test
.
expected
,
calcLen
)
assert
.
Equal
(
t
,
test
.
expectedString
,
test
.
input
.
String
()
)
}
assert
.
Equal
(
t
,
test
.
expectedPrint
,
test
.
input
.
Print
())
}
}
}
}
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