"...davecgh/go-spew/git@code.fbi.h-da.de:danet/bio-rd.git" did not exist on "c01d30a635d745c9cc6fe33cb68209f828f2bffe"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package packet
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/taktv6/tflow2/convert"
)
func TestSerializeKeepaliveMsg(t *testing.T) {
expected := []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x13, 0x04,
}
res := SerializeKeepaliveMsg()
assert.Equal(t, expected, res)
}
func TestSerializeNotificationMsg(t *testing.T) {
tests := []struct {
name string
input *BGPNotification
expected []byte
}{
{
name: "Valid #1",
input: &BGPNotification{
ErrorCode: 10,
ErrorSubcode: 5,
},
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x15, // Length
0x03, // Type
0x0a, // Error Code
0x05, // Error Subcode
},
},
{
name: "Valid #2",
input: &BGPNotification{
ErrorCode: 11,
ErrorSubcode: 6,
},
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x15, // Length
0x03, // Type
0x0b, // Error Code
0x06, // Error Subcode
},
},
}
for _, test := range tests {
res := SerializeNotificationMsg(test.input)
assert.Equal(t, test.expected, res)
}
}
func TestSerializeOpenMsg(t *testing.T) {
tests := []struct {
name string
input *BGPOpen
expected []byte
}{
{
name: "Valid #1",
input: &BGPOpen{
Version: 4,
HoldTime: 120,
BGPIdentifier: convert.Uint32([]byte{100, 111, 120, 130}),
OptParmLen: 0,
},
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x1d, // Length
0x01, // Type
0x04, // Version
0x3b, 0x41, // ASN
0x00, 0x78, // Holdtime
130, 120, 111, 100, // BGP Identifier
0x00, // Opt. Param Length
},
},
}
for _, test := range tests {
res := SerializeOpenMsg(test.input)
assert.Equal(t, test.expected, res)
}
}
tests := []struct {
name string
optParams []OptParam
expected []byte
}{
{
name: "empty",
optParams: []OptParam{},
expected: []byte{},
},
{
name: "1 Option",
optParams: []OptParam{
{
Type: 2,
Length: 6,
Value: Capability{
Code: 69,
Length: 4,
Value: AddPathCapability{
AFI: 1,
SAFI: 1,
SendReceive: 3,
},
},
},
},
},
}
for _, test := range tests {
buf := bytes.NewBuffer(make([]byte, 0))
serializeOptParams(buf, test.optParams)
assert.Equal(t, test.expected, buf.Bytes())
}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
func TestSerializeHeader(t *testing.T) {
tests := []struct {
name string
length uint16
typ uint8
expected []byte
}{
{
name: "Valid #1",
length: 10,
typ: 5,
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x0a, 0x05,
},
},
{
name: "Valid #12",
length: 256,
typ: 255,
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x01, 0x00, 0xff,
},
},
}
for _, test := range tests {
buf := bytes.NewBuffer([]byte{})
serializeHeader(buf, test.length, test.typ)
assert.Equal(t, test.expected, buf.Bytes())
}
}