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
1ee4258a
Commit
1ee4258a
authored
6 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Added some tests
parent
db54622f
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
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
164 additions
and
4 deletions
route/path.go
+
4
−
4
View file @
1ee4258a
...
@@ -2,11 +2,11 @@ package route
...
@@ -2,11 +2,11 @@ package route
import
(
import
(
"fmt"
"fmt"
"log"
bnet
"github.com/bio-routing/bio-rd/net"
bnet
"github.com/bio-routing/bio-rd/net"
)
)
// Path represents a network path
type
Path
struct
{
type
Path
struct
{
Type
uint8
Type
uint8
StaticPath
*
StaticPath
StaticPath
*
StaticPath
...
@@ -46,6 +46,7 @@ func (p *Path) Select(q *Path) int8 {
...
@@ -46,6 +46,7 @@ func (p *Path) Select(q *Path) int8 {
panic
(
"Unknown path type"
)
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
{
func
(
p
*
Path
)
ECMP
(
q
*
Path
)
bool
{
switch
p
.
Type
{
switch
p
.
Type
{
case
BGPPathType
:
case
BGPPathType
:
...
@@ -59,6 +60,7 @@ func (p *Path) ECMP(q *Path) bool {
...
@@ -59,6 +60,7 @@ func (p *Path) ECMP(q *Path) bool {
panic
(
"Unknown path type"
)
panic
(
"Unknown path type"
)
}
}
// Equal checks if paths p and q are equal
func
(
p
*
Path
)
Equal
(
q
*
Path
)
bool
{
func
(
p
*
Path
)
Equal
(
q
*
Path
)
bool
{
if
p
==
nil
||
q
==
nil
{
if
p
==
nil
||
q
==
nil
{
return
false
return
false
...
@@ -162,9 +164,7 @@ func (p *Path) NextHop() bnet.IP {
...
@@ -162,9 +164,7 @@ func (p *Path) NextHop() bnet.IP {
return
p
.
StaticPath
.
NextHop
return
p
.
StaticPath
.
NextHop
case
NetlinkPathType
:
case
NetlinkPathType
:
return
p
.
NetlinkPath
.
NextHop
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 @
1ee4258a
...
@@ -3,9 +3,169 @@ package route
...
@@ -3,9 +3,169 @@ package route
import
(
import
(
"testing"
"testing"
bnet
"github.com/bio-routing/bio-rd/net"
"github.com/stretchr/testify/assert"
"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
)
{
func
TestPathsDiff
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
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