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
c4f38982
Commit
c4f38982
authored
5 years ago
by
Marcus Weiner
Browse files
Options
Downloads
Patches
Plain Diff
Test decode of hello packets
parent
e272abf5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Packet/ospfv3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
protocols/ospf/packetv3/packet_test.go
+252
-1
252 additions, 1 deletion
protocols/ospf/packetv3/packet_test.go
with
252 additions
and
1 deletion
protocols/ospf/packetv3/packet_test.go
+
252
−
1
View file @
c4f38982
...
...
@@ -7,8 +7,11 @@ import (
"os"
"testing"
"github.com/bio-routing/bio-rd/net"
ospf
"github.com/bio-routing/bio-rd/protocols/ospf/packetv3"
"github.com/bio-routing/bio-rd/protocols/ospf/packetv3/fixtures"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var
files
=
[]
string
{
...
...
@@ -27,7 +30,7 @@ func init() {
dir
=
cwd
+
"/fixtures/"
}
func
TestDecode
(
t
*
testing
.
T
)
{
func
TestDecode
Dumps
(
t
*
testing
.
T
)
{
for
_
,
path
:=
range
files
{
t
.
Run
(
path
,
func
(
t
*
testing
.
T
)
{
testDecodeFile
(
t
,
dir
+
path
)
...
...
@@ -66,3 +69,251 @@ func testDecodeFile(t *testing.T, path string) {
packetCount
++
}
}
type
test
struct
{
name
string
input
[]
byte
wantFail
bool
expected
interface
{}
}
func
TestDecode
(
t
*
testing
.
T
)
{
tests
:=
[]
test
{
{
name
:
"Hello/Default"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
36
,
// Length
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x94
,
0x1c
,
// Checksum
0
,
// Instance ID
0
,
// Reserved
// Payload (Hello)
0
,
0
,
0
,
6
,
// Interface ID
100
,
// Router Prio
0
,
// Reserved
0
,
0x13
,
// Options: R, E, V6
0
,
30
,
// Hello Interval
0
,
120
,
// Dead Interval
0
,
0
,
0
,
0
,
// Designated Router
0
,
0
,
0
,
0
,
// Backup Designated Router
},
expected
:
&
ospf
.
OSPFv3Message
{
Version
:
3
,
Type
:
ospf
.
MsgTypeHello
,
Checksum
:
0x941c
,
PacketLength
:
36
,
RouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
3
,
3
,
3
,
3
)
.
Ptr
()
.
ToUint32
()),
AreaID
:
0
,
InstanceID
:
0
,
Body
:
&
ospf
.
Hello
{
InterfaceID
:
6
,
RouterPriority
:
100
,
HelloInterval
:
30
,
RouterDeadInterval
:
120
,
Options
:
ospf
.
OptionsFromFlags
(
ospf
.
RouterOptR
,
ospf
.
RouterOptE
,
ospf
.
RouterOptV6
),
},
},
},
{
name
:
"Hello/InvalidLength"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
38
,
// Length (invalid, expecting 36)
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x94
,
0x1a
,
// Checksum
0
,
// Instance ID
0
,
// Reserved
// Payload (20 bytes)
0
,
0
,
0
,
6
,
100
,
0
,
0
,
0x13
,
0
,
30
,
0
,
120
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
},
wantFail
:
true
,
},
{
name
:
"Hello/InvalidChecksum"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
36
,
// Length
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x94
,
0x1d
,
// Checksum (invalid)
0
,
// Instance ID
0
,
// Reserved
// Payload (20 bytes)
0
,
0
,
0
,
6
,
100
,
0
,
0
,
0x13
,
0
,
30
,
0
,
120
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
},
wantFail
:
true
,
},
{
name
:
"Hello/WithNeighbors"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
44
,
// Length
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x8e
,
0x06
,
// Checksum
0
,
// Instance ID
0
,
// Reserved
// Payload (Hello)
0
,
0
,
0
,
6
,
// Interface ID
100
,
// Router Prio
0
,
// Reserved
0
,
0x13
,
// Options: R, E, V6
0
,
30
,
// Hello Interval
0
,
120
,
// Dead Interval
0
,
0
,
0
,
0
,
// Designated Router
0
,
0
,
0
,
0
,
// Backup Designated Router
1
,
1
,
1
,
1
,
// Neighbor 1
2
,
2
,
2
,
2
,
// Neighbor 2
},
expected
:
&
ospf
.
OSPFv3Message
{
Version
:
3
,
Type
:
ospf
.
MsgTypeHello
,
Checksum
:
0x8e06
,
PacketLength
:
44
,
RouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
3
,
3
,
3
,
3
)
.
Ptr
()
.
ToUint32
()),
AreaID
:
0
,
InstanceID
:
0
,
Body
:
&
ospf
.
Hello
{
InterfaceID
:
6
,
RouterPriority
:
100
,
HelloInterval
:
30
,
RouterDeadInterval
:
120
,
Options
:
ospf
.
OptionsFromFlags
(
ospf
.
RouterOptR
,
ospf
.
RouterOptE
,
ospf
.
RouterOptV6
),
Neighbors
:
[]
ospf
.
ID
{
ospf
.
ID
(
net
.
IPv4FromOctets
(
1
,
1
,
1
,
1
)
.
Ptr
()
.
ToUint32
()),
ospf
.
ID
(
net
.
IPv4FromOctets
(
2
,
2
,
2
,
2
)
.
Ptr
()
.
ToUint32
()),
},
},
},
},
{
name
:
"Hello/WithDR"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
44
,
// Length
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x8c
,
0x04
,
// Checksum
0
,
// Instance ID
0
,
// Reserved
// Payload (Hello)
0
,
0
,
0
,
6
,
// Interface ID
100
,
// Router Prio
0
,
// Reserved
0
,
0x13
,
// Options: R, E, V6
0
,
30
,
// Hello Interval
0
,
120
,
// Dead Interval
1
,
1
,
1
,
1
,
// Designated Router
0
,
0
,
0
,
0
,
// Backup Designated Router
1
,
1
,
1
,
1
,
// Neighbor 1
2
,
2
,
2
,
2
,
// Neighbor 2
},
expected
:
&
ospf
.
OSPFv3Message
{
Version
:
3
,
Type
:
ospf
.
MsgTypeHello
,
Checksum
:
0x8c04
,
PacketLength
:
44
,
RouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
3
,
3
,
3
,
3
)
.
Ptr
()
.
ToUint32
()),
AreaID
:
0
,
InstanceID
:
0
,
Body
:
&
ospf
.
Hello
{
InterfaceID
:
6
,
RouterPriority
:
100
,
HelloInterval
:
30
,
RouterDeadInterval
:
120
,
Options
:
ospf
.
OptionsFromFlags
(
ospf
.
RouterOptR
,
ospf
.
RouterOptE
,
ospf
.
RouterOptV6
),
DesignatedRouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
1
,
1
,
1
,
1
)
.
Ptr
()
.
ToUint32
()),
Neighbors
:
[]
ospf
.
ID
{
ospf
.
ID
(
net
.
IPv4FromOctets
(
1
,
1
,
1
,
1
)
.
Ptr
()
.
ToUint32
()),
ospf
.
ID
(
net
.
IPv4FromOctets
(
2
,
2
,
2
,
2
)
.
Ptr
()
.
ToUint32
()),
},
},
},
},
{
name
:
"Hello/WithBDR"
,
input
:
[]
byte
{
// Header
3
,
// Version
1
,
// Type: Hello
0
,
44
,
// Length
3
,
3
,
3
,
3
,
// Source Router
0
,
0
,
0
,
0
,
// Area ID
0x88
,
0x00
,
// Checksum
0
,
// Instance ID
0
,
// Reserved
// Payload (Hello)
0
,
0
,
0
,
6
,
// Interface ID
100
,
// Router Prio
0
,
// Reserved
0
,
0x13
,
// Options: R, E, V6
0
,
30
,
// Hello Interval
0
,
120
,
// Dead Interval
1
,
1
,
1
,
1
,
// Designated Router
2
,
2
,
2
,
2
,
// Backup Designated Router
1
,
1
,
1
,
1
,
// Neighbor 1
2
,
2
,
2
,
2
,
// Neighbor 2
},
expected
:
&
ospf
.
OSPFv3Message
{
Version
:
3
,
Type
:
ospf
.
MsgTypeHello
,
Checksum
:
0x8800
,
PacketLength
:
44
,
RouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
3
,
3
,
3
,
3
)
.
Ptr
()
.
ToUint32
()),
AreaID
:
0
,
InstanceID
:
0
,
Body
:
&
ospf
.
Hello
{
InterfaceID
:
6
,
RouterPriority
:
100
,
HelloInterval
:
30
,
RouterDeadInterval
:
120
,
Options
:
ospf
.
OptionsFromFlags
(
ospf
.
RouterOptR
,
ospf
.
RouterOptE
,
ospf
.
RouterOptV6
),
DesignatedRouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
1
,
1
,
1
,
1
)
.
Ptr
()
.
ToUint32
()),
BackupDesignatedRouterID
:
ospf
.
ID
(
net
.
IPv4FromOctets
(
2
,
2
,
2
,
2
)
.
Ptr
()
.
ToUint32
()),
Neighbors
:
[]
ospf
.
ID
{
ospf
.
ID
(
net
.
IPv4FromOctets
(
1
,
1
,
1
,
1
)
.
Ptr
()
.
ToUint32
()),
ospf
.
ID
(
net
.
IPv4FromOctets
(
2
,
2
,
2
,
2
)
.
Ptr
()
.
ToUint32
()),
},
},
},
},
}
src
,
err
:=
net
.
IPFromString
(
"fe80::3"
)
require
.
NoError
(
t
,
err
)
dst
,
err
:=
net
.
IPFromString
(
"ff02::5"
)
require
.
NoError
(
t
,
err
)
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
buf
:=
bytes
.
NewBuffer
(
test
.
input
)
msg
,
_
,
err
:=
ospf
.
DeserializeOSPFv3Message
(
buf
,
src
,
dst
)
if
test
.
wantFail
{
require
.
Error
(
t
,
err
)
return
}
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
test
.
expected
,
msg
)
})
}
}
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