diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-03-22 16:24:46 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-04-03 08:32:46 +0900 |
commit | a381f1b60b879c245b0bb37fe65fd5c7b7be1f56 (patch) | |
tree | ea7a8e8a4241d7f880ce1515fe79fe9495eac7d5 /packet | |
parent | 752cec366b9adf0fae6b98aabbd7cd8aacfca492 (diff) |
packet/bgp: Remove length argument from NewEVPNNLRI
The length value can be retrieved from the route type specific data
field and need not to be specified at the initialization.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 14 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 6 | ||||
-rw-r--r-- | packet/bgp/helper.go | 8 |
3 files changed, 16 insertions, 12 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 61cd4a54..21788549 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2855,11 +2855,15 @@ func (n *EVPNNLRI) RD() RouteDistinguisherInterface { return n.RouteTypeData.rd() } -func NewEVPNNLRI(routetype uint8, length uint8, routetypedata EVPNRouteTypeInterface) *EVPNNLRI { +func NewEVPNNLRI(routeType uint8, routeTypeData EVPNRouteTypeInterface) *EVPNNLRI { + var l uint8 + if routeTypeData != nil { + l = uint8(routeTypeData.Len()) + } return &EVPNNLRI{ - RouteType: routetype, - Length: length, - RouteTypeData: routetypedata, + RouteType: routeType, + Length: l, + RouteTypeData: routeTypeData, } } @@ -4681,7 +4685,7 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8) (prefix AddrPrefixInterfac case RF_IPv6_MPLS: prefix = NewLabeledIPv6AddrPrefix(0, "", *NewMPLSLabelStack()) case RF_EVPN: - prefix = NewEVPNNLRI(0, 0, nil) + prefix = NewEVPNNLRI(0, nil) case RF_RTC_UC: prefix = &RouteTargetMembershipNLRI{} case RF_IPv4_ENCAP: diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 248fb346..65847b55 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -585,7 +585,7 @@ func Test_EVPNIPPrefixRoute(t *testing.T) { GWIPAddress: net.IP{10, 10, 10, 10}, Label: 1000, } - n1 := NewEVPNNLRI(EVPN_IP_PREFIX, 0, r) + n1 := NewEVPNNLRI(EVPN_IP_PREFIX, r) buf1, err := n1.Serialize() assert.Nil(err) n2, err := NewPrefixFromRouteFamily(RouteFamilyToAfiSafi(RF_EVPN)) @@ -722,13 +722,13 @@ func Test_AddPath(t *testing.T) { } opt = &MarshallingOption{AddPath: map[RouteFamily]BGPAddPathMode{RF_EVPN: BGP_ADD_PATH_BOTH}} { - n1 := NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0, + n1 := NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}) n1.SetPathLocalIdentifier(40) bits, err := n1.Serialize(opt) assert.Nil(err) - n2 := NewEVPNNLRI(0, 0, nil) + n2 := NewEVPNNLRI(0, nil) err = n2.DecodeFromBytes(bits, opt) assert.Nil(err) assert.Equal(n2.PathIdentifier(), uint32(40)) diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go index ecae6bdd..c816c9d6 100644 --- a/packet/bgp/helper.go +++ b/packet/bgp/helper.go @@ -92,17 +92,17 @@ func NewTestBGPUpdateMessage() *BGPMessage { mac, _ := net.ParseMAC("01:23:45:67:89:ab") prefixes5 := []AddrPrefixInterface{ - NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0, + NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}), - NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0, + NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, &EVPNMacIPAdvertisementRoute{NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, 48, mac, 32, net.ParseIP("192.2.1.2"), []uint32{3, 4}}), - NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, 0, + NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, &EVPNMulticastEthernetTagRoute{NewRouteDistinguisherFourOctetAS(5, 6), 3, 32, net.ParseIP("192.2.1.2")}), - NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, 0, + NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, &EVPNEthernetSegmentRoute{NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 32, net.ParseIP("192.2.1.1")}), |