From 87e25c522e64076897d304ca93a2e6d217a26c37 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Thu, 30 Jun 2016 10:22:44 +0000 Subject: bgp: fix bug of flowspec vpn parser/serializer close #997 Signed-off-by: ISHIDA Wataru --- packet/bgp/bgp_test.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'packet/bgp/bgp_test.go') diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 48366b61..80dcc5af 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -429,7 +429,8 @@ func Test_FlowSpecNlriL2(t *testing.T) { eq := 0x1 item1 := NewFlowSpecComponentItem(eq, int(IPv4)) cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ETHERNET_TYPE, []*FlowSpecComponentItem{item1})) - n1 := NewFlowSpecL2VPN(cmp) + rd, _ := ParseRouteDistinguisher("100:100") + n1 := NewFlowSpecL2VPN(rd, cmp) buf1, err := n1.Serialize() assert.Nil(err) n2, err := NewPrefixFromRouteFamily(RouteFamilyToAfiSafi(RF_FS_L2_VPN)) @@ -455,3 +456,27 @@ func Test_NotificationErrorCode(t *testing.T) { NewNotificationErrorCode(0, BGP_ERROR_SUB_BAD_MESSAGE_TYPE).String() NewNotificationErrorCode(BGP_ERROR_ROUTE_REFRESH_MESSAGE_ERROR+1, 0).String() } + +func Test_FlowSpecNlriVPN(t *testing.T) { + assert := assert.New(t) + cmp := make([]FlowSpecComponentInterface, 0) + cmp = append(cmp, NewFlowSpecDestinationPrefix(NewIPAddrPrefix(24, "10.0.0.0"))) + cmp = append(cmp, NewFlowSpecSourcePrefix(NewIPAddrPrefix(24, "10.0.0.0"))) + rd, _ := ParseRouteDistinguisher("100:100") + n1 := NewFlowSpecIPv4VPN(rd, cmp) + buf1, err := n1.Serialize() + assert.Nil(err) + n2, err := NewPrefixFromRouteFamily(RouteFamilyToAfiSafi(RF_FS_IPv4_VPN)) + assert.Nil(err) + err = n2.DecodeFromBytes(buf1) + assert.Nil(err) + buf2, _ := n2.Serialize() + if reflect.DeepEqual(n1, n2) == true { + t.Log("OK") + } else { + t.Error("Something wrong") + t.Error(len(buf1), n1, buf1) + t.Error(len(buf2), n2, buf2) + t.Log(bytes.Equal(buf1, buf2)) + } +} -- cgit v1.2.3