Newer
Older
expected []byte
expectedError error
name: "Normal withdraw with ADD-PATH",
addPathTX: true,
prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24),
path: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 1,
},
},
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
0x00, 0x1f, // BGP Message Length
0x02, // BGP Message Type == Update
0x00, 0x08, // WithDraw Octet length
0x00, 0x00, 0x00, 0x01, // NLRI Path Identifier
0x18, // Prefix Length
0x54, 0x38, 0xd4, // Prefix,
0x00, 0x00, // Total Path Attribute Length
},
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
expectedError: nil,
},
{
name: "Normal withdraw without ADD-PATH",
addPathTX: false,
prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24),
path: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 1,
},
},
expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
0x00, 0x1b, // BGP Message Length
0x02, // BGP Message Type == Update
0x00, 0x04, // WithDraw Octet length
0x18, // Prefix Length
0x54, 0x38, 0xd4, // Prefix,
0x00, 0x00, // Total Path Attribute Length
},
expectedError: nil,
name: "Non bgp withdraw",
addPathTX: true,
prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24),
path: &route.Path{
expected: []byte{},
expectedError: errors.New("wrong path type, expected BGPPathType"),
name: "Nil BGPPathType",
addPathTX: true,
prefix: bnet.NewPfx(bnet.IPv4(1413010532), 24),
path: &route.Path{
expected: []byte{},
expectedError: errors.New("got nil BGPPath"),
t.Parallel()
t.Run(tc.name, func(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
u := &UpdateSender{
fsm: &FSM{},
options: &packet.EncodeOptions{
UseAddPath: tc.addPathTX,
},
}
err := u.withdrawPrefixIPv4(buf, tc.prefix, tc.path)
assert.Equal(t, tc.expectedError, err, "error mismatch")
assert.Equal(t, tc.expected, buf.Bytes(), "expected different bytes")
})