Newer
Older
package server
import (
"testing"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
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
"github.com/stretchr/testify/assert"
)
func TestOpenMsgReceived(t *testing.T) {
tests := []struct {
asn uint32
name string
msg packet.BGPOpen
wantsCease bool
}{
{
name: "valid open message (16bit ASN)",
asn: 12345,
msg: packet.BGPOpen{
HoldTime: 90,
BGPIdentifier: 1,
Version: 4,
ASN: 12345,
},
},
{
name: "valid open message (32bit ASN)",
asn: 202739,
msg: packet.BGPOpen{
HoldTime: 90,
BGPIdentifier: 1,
Version: 4,
ASN: 23456,
OptParmLen: 1,
OptParams: []packet.OptParam{
{
Type: packet.CapabilitiesParamType,
Length: 6,
Value: packet.Capabilities{
packet.Capability{
Code: packet.ASN4CapabilityCode,
Length: 4,
Value: packet.ASN4Capability{
ASN4: 202739,
},
},
},
},
},
},
},
{
name: "open message does not match configured remote ASN",
asn: 12345,
msg: packet.BGPOpen{
HoldTime: 90,
BGPIdentifier: 1,
Version: 4,
ASN: 54321,
},
wantsCease: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
s := &openSentState{
fsm: fsm,
}
state, _ := s.handleOpenMessage(&test.msg)
if test.wantsCease {
assert.IsType(t, &ceaseState{}, state, "state")
return
}
assert.IsType(t, &openConfirmState{}, state, "state")
assert.Equal(t, test.asn, s.peerASNRcvd, "asn")
})
}
}