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 server
import (
"testing"
"time"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/stretchr/testify/assert"
)
func TestOpenMessage(t *testing.T) {
tests := []struct {
name string
localASN uint32
holdTime time.Duration
routerID uint32
expected packet.BGPOpen
}{
{
name: "16bit ASN",
localASN: 12345,
holdTime: time.Duration(30 * time.Second),
routerID: 1,
expected: packet.BGPOpen{
ASN: 12345,
BGPIdentifier: 1,
HoldTime: 30,
OptParams: []packet.OptParam{
packet.OptParam{
Type: packet.CapabilitiesParamType,
Value: packet.Capabilities{
packet.Capability{
Code: 65,
Value: packet.ASN4Capability{
ASN4: 12345,
},
},
},
},
},
Version: 4,
},
},
{
name: "32bit ASN",
localASN: 202739,
holdTime: time.Duration(30 * time.Second),
routerID: 1,
expected: packet.BGPOpen{
ASN: 23456,
BGPIdentifier: 1,
HoldTime: 30,
OptParams: []packet.OptParam{
packet.OptParam{
Type: packet.CapabilitiesParamType,
Value: packet.Capabilities{
packet.Capability{
Code: 65,
Value: packet.ASN4Capability{
ASN4: 202739,
},
},
},
},
},
Version: 4,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
localASN: test.localASN,
holdTime: test.holdTime,
routerID: test.routerID,
optOpenParams: []packet.OptParam{
packet.OptParam{
Type: packet.CapabilitiesParamType,
Value: packet.Capabilities{
packet.Capability{
Code: 65,
Value: packet.ASN4Capability{
ASN4: test.localASN,
},
},
},
},
},
}
fsm := newFSM2(&p)
msg := fsm.openMessage()
assert.Equal(t, &test.expected, msg)
})
}
}