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
5bf3640a
Commit
5bf3640a
authored
6 years ago
by
cedi
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/netlink' of github.com:bio-routing/bio-rd into feature/netlink
parents
1bb12c52
84fdb5ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
net/prefix_test.go
+58
-0
58 additions, 0 deletions
net/prefix_test.go
route/bgp_path_test.go
+184
-0
184 additions, 0 deletions
route/bgp_path_test.go
route/path.go
+4
-4
4 additions, 4 deletions
route/path.go
route/path_test.go
+160
-0
160 additions, 0 deletions
route/path_test.go
with
406 additions
and
4 deletions
net/prefix_test.go
+
58
−
0
View file @
5bf3640a
package
net
import
(
gonet
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func
TestGetIPNet
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
pfx
Prefix
expected
*
gonet
.
IPNet
}{
{
name
:
"Some prefix IPv4"
,
pfx
:
NewPfx
(
IPv4FromOctets
(
127
,
0
,
0
,
0
),
8
),
expected
:
&
gonet
.
IPNet
{
IP
:
gonet
.
IP
{
127
,
0
,
0
,
0
},
Mask
:
gonet
.
IPMask
{
255
,
0
,
0
,
0
},
},
},
{
name
:
"Some prefix IPv6"
,
pfx
:
NewPfx
(
IPv6FromBlocks
(
0xffff
,
0xffff
,
0xffff
,
0xffff
,
0x0
,
0x0
,
0x0
,
0x0
),
64
),
expected
:
&
gonet
.
IPNet
{
IP
:
gonet
.
IP
{
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
Mask
:
gonet
.
IPMask
{
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
},
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
pfx
.
GetIPNet
()
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestNewPfxFromIPNet
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
ipNet
*
gonet
.
IPNet
expected
Prefix
}{
{
name
:
"Some Prefix"
,
ipNet
:
&
gonet
.
IPNet
{
IP
:
gonet
.
IP
{
127
,
0
,
0
,
0
},
Mask
:
gonet
.
IPMask
{
255
,
0
,
0
,
0
},
},
expected
:
NewPfx
(
IPv4FromOctets
(
127
,
0
,
0
,
0
),
8
),
},
}
for
_
,
test
:=
range
tests
{
res
:=
NewPfxFromIPNet
(
test
.
ipNet
)
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestNewPfx
(
t
*
testing
.
T
)
{
p
:=
NewPfx
(
IPv4
(
123
),
11
)
if
p
.
addr
!=
IPv4
(
123
)
||
p
.
pfxlen
!=
11
{
...
...
@@ -371,6 +424,11 @@ func TestStrToAddr(t *testing.T) {
wantFail
bool
expected
uint32
}{
{
name
:
"Non numeric"
,
input
:
"10.10.10.a"
,
wantFail
:
true
,
},
{
name
:
"Invalid address #1"
,
input
:
"10.10.10"
,
...
...
This diff is collapsed.
Click to expand it.
route/bgp_path_test.go
+
184
−
0
View file @
5bf3640a
...
...
@@ -7,6 +7,121 @@ import (
"github.com/stretchr/testify/assert"
)
func
TestBGPSelect
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
BGPPath
q
*
BGPPath
expected
int8
}{
{
name
:
"Lpref"
,
p
:
&
BGPPath
{
LocalPref
:
200
,
},
q
:
&
BGPPath
{
LocalPref
:
100
,
},
expected
:
1
,
},
{
name
:
"Lpref #2"
,
p
:
&
BGPPath
{
LocalPref
:
100
,
},
q
:
&
BGPPath
{
LocalPref
:
200
,
},
expected
:
-
1
,
},
{
name
:
"AS Path Len"
,
p
:
&
BGPPath
{
ASPathLen
:
100
,
},
q
:
&
BGPPath
{
ASPathLen
:
200
,
},
expected
:
1
,
},
{
name
:
"AS Path Len #2"
,
p
:
&
BGPPath
{
ASPathLen
:
200
,
},
q
:
&
BGPPath
{
ASPathLen
:
100
,
},
expected
:
-
1
,
},
{
name
:
"Origin"
,
p
:
&
BGPPath
{
Origin
:
1
,
},
q
:
&
BGPPath
{
Origin
:
2
,
},
expected
:
1
,
},
{
name
:
"Origin #2"
,
p
:
&
BGPPath
{
Origin
:
2
,
},
q
:
&
BGPPath
{
Origin
:
1
,
},
expected
:
-
1
,
},
{
name
:
"MED"
,
p
:
&
BGPPath
{
MED
:
1
,
},
q
:
&
BGPPath
{
MED
:
2
,
},
expected
:
1
,
},
{
name
:
"MED #2"
,
p
:
&
BGPPath
{
MED
:
2
,
},
q
:
&
BGPPath
{
MED
:
1
,
},
expected
:
-
1
,
},
{
name
:
"EBGP"
,
p
:
&
BGPPath
{
EBGP
:
true
,
},
q
:
&
BGPPath
{
EBGP
:
false
,
},
expected
:
1
,
},
{
name
:
"EBGP #2"
,
p
:
&
BGPPath
{
EBGP
:
false
,
},
q
:
&
BGPPath
{
EBGP
:
true
,
},
expected
:
-
1
,
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
Select
(
test
.
q
)
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestCommunitiesString
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
@@ -65,6 +180,55 @@ func TestLargeCommunitiesString(t *testing.T) {
}
}
func
TestBGPECMP
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
BGPPath
q
*
BGPPath
expected
bool
}{
{
name
:
"Equal"
,
p
:
&
BGPPath
{},
q
:
&
BGPPath
{},
expected
:
true
,
},
{
name
:
"Lpref"
,
p
:
&
BGPPath
{
LocalPref
:
200
},
q
:
&
BGPPath
{},
expected
:
false
,
},
{
name
:
"MED"
,
p
:
&
BGPPath
{
MED
:
200
},
q
:
&
BGPPath
{},
expected
:
false
,
},
{
name
:
"ASPath Len"
,
p
:
&
BGPPath
{
ASPathLen
:
2
,
},
q
:
&
BGPPath
{
ASPathLen
:
1
,
},
expected
:
false
,
},
{
name
:
"Origin"
,
p
:
&
BGPPath
{
Origin
:
1
},
q
:
&
BGPPath
{},
expected
:
false
,
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
ECMP
(
test
.
q
)
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestLength
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
@@ -123,6 +287,26 @@ func TestLength(t *testing.T) {
},
expected
:
71
,
},
{
name
:
"Cluster list, unknown attr and originator"
,
path
:
&
BGPPath
{
ASPath
:
[]
types
.
ASPathSegment
{
{
Type
:
types
.
ASSequence
,
ASNs
:
[]
uint32
{
15169
,
199714
},
},
},
ClusterList
:
[]
uint32
{
10
,
20
,
30
},
UnknownAttributes
:
[]
types
.
UnknownPathAttribute
{
{
TypeCode
:
100
,
Value
:
[]
byte
{
1
,
2
,
3
},
},
},
OriginatorID
:
10
,
},
expected
:
54
,
},
}
for
_
,
test
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
route/path.go
+
4
−
4
View file @
5bf3640a
...
...
@@ -2,11 +2,11 @@ package route
import
(
"fmt"
"log"
bnet
"github.com/bio-routing/bio-rd/net"
)
// Path represents a network path
type
Path
struct
{
Type
uint8
StaticPath
*
StaticPath
...
...
@@ -46,6 +46,7 @@ func (p *Path) Select(q *Path) int8 {
panic
(
"Unknown path type"
)
}
// ECMP checks if path p and q are equal enough to be considered for ECMP usage
func
(
p
*
Path
)
ECMP
(
q
*
Path
)
bool
{
switch
p
.
Type
{
case
BGPPathType
:
...
...
@@ -59,6 +60,7 @@ func (p *Path) ECMP(q *Path) bool {
panic
(
"Unknown path type"
)
}
// Equal checks if paths p and q are equal
func
(
p
*
Path
)
Equal
(
q
*
Path
)
bool
{
if
p
==
nil
||
q
==
nil
{
return
false
...
...
@@ -162,9 +164,7 @@ func (p *Path) NextHop() bnet.IP {
return
p
.
StaticPath
.
NextHop
case
NetlinkPathType
:
return
p
.
NetlinkPath
.
NextHop
default
:
log
.
Panic
(
"Type %d not implemented (yet)"
,
p
.
Type
)
}
return
bnet
.
IP
{}
panic
(
"Unknown path type"
)
}
This diff is collapsed.
Click to expand it.
route/path_test.go
+
160
−
0
View file @
5bf3640a
...
...
@@ -3,9 +3,169 @@ package route
import
(
"testing"
bnet
"github.com/bio-routing/bio-rd/net"
"github.com/stretchr/testify/assert"
)
func
TestPathNextHop
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
Path
expected
bnet
.
IP
}{
{
name
:
"BGP Path"
,
p
:
&
Path
{
Type
:
BGPPathType
,
BGPPath
:
&
BGPPath
{
NextHop
:
bnet
.
IPv4
(
123
),
},
},
expected
:
bnet
.
IPv4
(
123
),
},
{
name
:
"Static Path"
,
p
:
&
Path
{
Type
:
StaticPathType
,
StaticPath
:
&
StaticPath
{
NextHop
:
bnet
.
IPv4
(
456
),
},
},
expected
:
bnet
.
IPv4
(
456
),
},
{
name
:
"Netlink Path"
,
p
:
&
Path
{
Type
:
NetlinkPathType
,
NetlinkPath
:
&
NetlinkPath
{
NextHop
:
bnet
.
IPv4
(
1000
),
},
},
expected
:
bnet
.
IPv4
(
1000
),
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
NextHop
()
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestPathCopy
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
Path
expected
*
Path
}{
{
name
:
"nil test"
,
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
Copy
()
assert
.
Equal
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestEqual
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
Path
q
*
Path
expected
bool
}{
{
name
:
"Different types"
,
p
:
&
Path
{
Type
:
100
},
q
:
&
Path
{
Type
:
200
},
expected
:
false
,
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
Equal
(
test
.
q
)
assert
.
Equalf
(
t
,
test
.
expected
,
res
,
test
.
name
)
}
}
func
TestSelect
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
p
*
Path
q
*
Path
expected
int8
}{
{
name
:
"All nil"
,
expected
:
0
,
},
{
name
:
"p nil"
,
q
:
&
Path
{},
expected
:
-
1
,
},
{
name
:
"q nil"
,
p
:
&
Path
{},
expected
:
1
,
},
{
name
:
"p > q"
,
p
:
&
Path
{
Type
:
20
},
q
:
&
Path
{
Type
:
10
},
expected
:
1
,
},
{
name
:
"p < q"
,
p
:
&
Path
{
Type
:
10
},
q
:
&
Path
{
Type
:
20
},
expected
:
-
1
,
},
{
name
:
"Static"
,
p
:
&
Path
{
Type
:
StaticPathType
,
StaticPath
:
&
StaticPath
{},
},
q
:
&
Path
{
Type
:
StaticPathType
,
StaticPath
:
&
StaticPath
{},
},
expected
:
0
,
},
{
name
:
"BGP"
,
p
:
&
Path
{
Type
:
BGPPathType
,
BGPPath
:
&
BGPPath
{},
},
q
:
&
Path
{
Type
:
BGPPathType
,
BGPPath
:
&
BGPPath
{},
},
expected
:
0
,
},
{
name
:
"Netlink"
,
p
:
&
Path
{
Type
:
NetlinkPathType
,
NetlinkPath
:
&
NetlinkPath
{},
},
q
:
&
Path
{
Type
:
NetlinkPathType
,
NetlinkPath
:
&
NetlinkPath
{},
},
expected
:
0
,
},
}
for
_
,
test
:=
range
tests
{
res
:=
test
.
p
.
Select
(
test
.
q
)
assert
.
Equalf
(
t
,
test
.
expected
,
res
,
"Test %q"
,
test
.
name
)
}
}
func
TestPathsDiff
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
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