Skip to content

Commit

Permalink
add test for BGP-LS EPE
Browse files Browse the repository at this point in the history
  • Loading branch information
kanaya516 committed Jan 8, 2023
1 parent d1cd6b3 commit 17eb68a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8184,7 +8184,11 @@ func (l *LsTLVNodeDescriptor) String() string {
return fmt.Sprintf("{ASN: %v, BGP LS ID: %v, OSPF AREA: %v, IGP ROUTER ID: %v}", nd.Asn, nd.BGPLsID, nd.OspfAreaID, nd.IGPRouterID)
}

return fmt.Sprintf("{ASN: %v, BGP LS ID: %v, OSPF AREA: %v, IGP ROUTER ID: %v, BGP ROUTER ID: %v, BGP CONFEDERATION MEMBER: %v}", nd.Asn, nd.BGPLsID, nd.OspfAreaID, nd.IGPRouterID, nd.BGPRouterID, nd.BGPConfederationMember)
if l.LsTLV.Type == LS_TLV_REMOTE_NODE_DESC {
return fmt.Sprintf("{ASN: %v, BGP LS ID: %v, BGP ROUTER ID: %v, BGP CONFEDERATION MEMBER: %v}", nd.Asn, nd.BGPLsID, nd.BGPRouterID, nd.BGPConfederationMember)
}

return fmt.Sprintf("{ASN: %v, BGP LS ID: %v, BGP ROUTER ID: %v}", nd.Asn, nd.BGPLsID, nd.BGPRouterID)
}

func (l *LsTLVNodeDescriptor) MarshalJSON() ([]byte, error) {
Expand Down
44 changes: 44 additions & 0 deletions pkg/packet/bgp/bgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,35 @@ func Test_LsTLVBgpRouterID(t *testing.T) {
}
}

func Test_LsTLVBgpConfederationMember(t *testing.T) {
assert := assert.New(t)

var tests = []struct {
in []byte
want string
err bool
}{
{[]byte{0x02, 0x05, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07}, `{"type":517,"bgp_confederation_member":117901063}`, false},
{[]byte{0x02, 0x05, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, 0xFF}, `{"type":517,"bgp_confederation_member":117901063}`, false},
{[]byte{0x02, 0x05, 0x00, 0x03, 0x07, 0x07, 0x07}, "", true},
{[]byte{0xfe, 0xfe, 0x00, 0x00}, "", true},
}

for _, test := range tests {
tlv := LsTLVBgpConfederationMember{}
if test.err {
assert.Error(tlv.DecodeFromBytes(test.in))
continue
} else {
assert.NoError(tlv.DecodeFromBytes(test.in))
}

got, err := tlv.MarshalJSON()
assert.NoError(err)
assert.Equal(got, []byte(test.want))
}
}

func Test_LsTLVOspfAreaID(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -3014,6 +3043,21 @@ func Test_LsNodeDescriptor(t *testing.T) {
0x01, 0x00, 0x00, 0x0a, // Missing optional TLVs
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // TLV IGP Router ID: 0102.0304.0506
}, "{ASN: 0, BGP LS ID: 0, OSPF AREA: 0, IGP ROUTER ID: 0102.0304.0506}", false, true},
{[]byte{
0x01, 0x01, 0x00, 0x20, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 117901063
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID: 117901063
0x02, 0x04, 0x00, 0x04, 0x0a, 0xff, 0x00, 0x01, // TLV BGP ROUTER ID: "10.255.0.1"
0x02, 0x05, 0x00, 0x04, 0x07, 0x07, 0x07, 0x08, // TLV BGP CONFEDERATION MEMBER: 117901064
}, "{ASN: 117901063, BGP LS ID: 117901063, BGP ROUTER ID: 10.255.0.1, BGP CONFEDERATION MEMBER: 117901064}",
false, true},
{[]byte{
0x01, 0x01, 0x00, 0x18, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 117901063
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID: 117901063
0x02, 0x04, 0x00, 0x04, 0x0a, 0xff, 0x00, 0x01, // TLV BGP ROUTER ID: "10.255.0.1"
}, "{ASN: 117901063, BGP LS ID: 117901063, BGP ROUTER ID: 10.255.0.1, BGP CONFEDERATION MEMBER: 0}",
false, true},
}

for _, test := range tests {
Expand Down

0 comments on commit 17eb68a

Please sign in to comment.