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
bb07a834
Commit
bb07a834
authored
6 years ago
by
cedi
Browse files
Options
Downloads
Patches
Plain Diff
Add unit-tests for netlink_path
parent
673eafda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
route/netlink_path.go
+11
-6
11 additions, 6 deletions
route/netlink_path.go
route/path_test.go
+181
-0
181 additions, 0 deletions
route/path_test.go
with
192 additions
and
6 deletions
route/netlink_path.go
+
11
−
6
View file @
bb07a834
...
...
@@ -4,12 +4,20 @@ import (
"fmt"
bnet
"github.com/bio-routing/bio-rd/net"
log
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
// ProtoBio is the protocol number constant for bio from /etc/iproute2/rt_protos
const
ProtoBio
=
45
const
(
ProtoUnspec
=
0
// unspec (from /etc/iproute2/rt_protos)
ProtoRedirect
=
1
// redirect (from /etc/iproute2/rt_protos)
ProtoKernel
=
2
// kernel (from /etc/iproute2/rt_protos)
ProtoBoot
=
3
// boot (from /etc/iproute2/rt_protos)
ProtoStatic
=
4
// static (from /etc/iproute2/rt_protos)
ProtoZebra
=
11
// zebra (from /etc/iproute2/rt_protos)
ProtoBird
=
12
// bird (from /etc/iproute2/rt_protos)
ProtoDHCP
=
16
// dhcp (from /etc/iproute2/rt_protos)
ProtoBio
=
45
// bio
)
// NetlinkPath represents a path learned via Netlink of a route
type
NetlinkPath
struct
{
...
...
@@ -65,9 +73,6 @@ func NewNlPathFromRoute(r *netlink.Route, kernel bool) (*NetlinkPath, error) {
dst
=
bnet
.
NewPfxFromIPNet
(
r
.
Dst
)
}
log
.
Warnf
(
"IPFromBytes: %v goes to %v"
,
r
.
Src
,
src
)
log
.
Warnf
(
"IPFromBytes: %v goes to %v"
,
r
.
Dst
,
dst
)
nextHop
,
_
:=
bnet
.
IPFromBytes
(
r
.
Gw
)
return
&
NetlinkPath
{
...
...
This diff is collapsed.
Click to expand it.
route/path_test.go
+
181
−
0
View file @
bb07a834
package
route
import
(
"fmt"
"testing"
bnet
"github.com/bio-routing/bio-rd/net"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
)
func
TestPathNextHop
(
t
*
testing
.
T
)
{
...
...
@@ -321,3 +323,182 @@ func TestPathsContains(t *testing.T) {
}
}
}
func
TestNewNlPath
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
source
*
Path
expected
*
NetlinkPath
}{
{
name
:
"BGPPath"
,
source
:
&
Path
{
Type
:
BGPPathType
,
BGPPath
:
&
BGPPath
{
NextHop
:
bnet
.
IPv4
(
123
),
},
},
expected
:
&
NetlinkPath
{
NextHop
:
bnet
.
IPv4
(
123
),
Protocol
:
ProtoBio
,
},
},
}
for
_
,
test
:=
range
tests
{
var
converted
*
NetlinkPath
switch
test
.
source
.
Type
{
case
BGPPathType
:
converted
=
NewNlPathFromBgpPath
(
test
.
source
.
BGPPath
)
default
:
assert
.
Fail
(
t
,
fmt
.
Sprintf
(
"Source-type %d is not supported"
,
test
.
source
.
Type
))
}
assert
.
Equalf
(
t
,
test
.
expected
,
converted
,
test
.
name
)
}
}
func
TestNewNlPathFromNetlinkRoute
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
source
*
netlink
.
Route
expected
*
NetlinkPath
expectError
bool
}{
{
name
:
"Simple"
,
source
:
&
netlink
.
Route
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv4FromOctets
(
10
,
0
,
0
,
0
),
8
)
.
GetIPNet
(),
Src
:
bnet
.
IPv4
(
456
)
.
Bytes
(),
Gw
:
bnet
.
IPv4
(
789
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv4FromOctets
(
10
,
0
,
0
,
0
),
8
),
Src
:
bnet
.
IPv4
(
456
),
NextHop
:
bnet
.
IPv4
(
789
),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
Kernel
:
true
,
},
expectError
:
false
,
},
{
name
:
"No source, no destination"
,
source
:
&
netlink
.
Route
{
Gw
:
bnet
.
IPv4
(
789
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{},
expectError
:
true
,
},
{
name
:
"No source but destination"
,
source
:
&
netlink
.
Route
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv4FromOctets
(
10
,
0
,
0
,
0
),
8
)
.
GetIPNet
(),
Gw
:
bnet
.
IPv4
(
789
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv4FromOctets
(
10
,
0
,
0
,
0
),
8
),
Src
:
bnet
.
IPv4FromOctets
(
0
,
0
,
0
,
0
),
NextHop
:
bnet
.
IPv4
(
789
),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
Kernel
:
true
,
},
expectError
:
false
,
},
{
name
:
"Source but no destination"
,
source
:
&
netlink
.
Route
{
Src
:
bnet
.
IPv4
(
456
)
.
Bytes
(),
Gw
:
bnet
.
IPv4
(
789
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv4FromOctets
(
0
,
0
,
0
,
0
),
0
),
Src
:
bnet
.
IPv4
(
456
),
NextHop
:
bnet
.
IPv4
(
789
),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
Kernel
:
true
,
},
expectError
:
false
,
},
{
name
:
"No source but destination IPv6"
,
source
:
&
netlink
.
Route
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv6
(
2001
,
0
),
48
)
.
GetIPNet
(),
Gw
:
bnet
.
IPv6
(
2001
,
2
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv6
(
2001
,
0
),
48
),
Src
:
bnet
.
IPv6FromBlocks
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
),
NextHop
:
bnet
.
IPv6
(
2001
,
2
),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
Kernel
:
true
,
},
expectError
:
false
,
},
{
name
:
"Source but no destination IPv6"
,
source
:
&
netlink
.
Route
{
Src
:
bnet
.
IPv6
(
2001
,
0
)
.
Bytes
(),
Gw
:
bnet
.
IPv6
(
2001
,
2
)
.
Bytes
(),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
},
expected
:
&
NetlinkPath
{
Dst
:
bnet
.
NewPfx
(
bnet
.
IPv6FromBlocks
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
),
0
),
Src
:
bnet
.
IPv6
(
2001
,
0
),
NextHop
:
bnet
.
IPv6
(
2001
,
2
),
Protocol
:
ProtoKernel
,
Priority
:
1
,
Table
:
254
,
Type
:
1
,
Kernel
:
true
,
},
expectError
:
false
,
},
}
for
_
,
test
:=
range
tests
{
converted
,
err
:=
NewNlPathFromRoute
(
test
.
source
,
true
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
)
}
else
{
assert
.
NoError
(
t
,
err
)
assert
.
Equalf
(
t
,
test
.
expected
,
converted
,
test
.
name
)
}
}
}
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