summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-03-22 16:24:46 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-04-03 08:32:46 +0900
commita381f1b60b879c245b0bb37fe65fd5c7b7be1f56 (patch)
treeea7a8e8a4241d7f880ce1515fe79fe9495eac7d5
parent752cec366b9adf0fae6b98aabbd7cd8aacfca492 (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>
-rw-r--r--gobgp/cmd/global.go10
-rw-r--r--packet/bgp/bgp.go14
-rw-r--r--packet/bgp/bgp_test.go6
-rw-r--r--packet/bgp/helper.go8
-rw-r--r--table/path.go4
5 files changed, 23 insertions, 19 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index cbdd44c8..c9be51bc 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -460,7 +460,7 @@ func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface,
ETag: etag,
Label: label,
}
- return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0, r), extcomms, nil
+ return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, r), extcomms, nil
}
func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
@@ -577,7 +577,7 @@ func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, erro
Labels: labels,
ETag: uint32(eTag),
}
- return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0, r), extcomms, nil
+ return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, r), extcomms, nil
}
func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
@@ -651,7 +651,7 @@ func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, e
IPAddress: ip,
ETag: uint32(eTag),
}
- return bgp.NewEVPNNLRI(bgp.EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, 0, r), extcomms, nil
+ return bgp.NewEVPNNLRI(bgp.EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, r), extcomms, nil
}
func ParseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
@@ -715,7 +715,7 @@ func ParseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []str
IPAddressLength: uint8(ipLen),
IPAddress: ip,
}
- return bgp.NewEVPNNLRI(bgp.EVPN_ETHERNET_SEGMENT_ROUTE, 0, r), extcomms, nil
+ return bgp.NewEVPNNLRI(bgp.EVPN_ETHERNET_SEGMENT_ROUTE, r), extcomms, nil
}
func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
@@ -803,7 +803,7 @@ func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, er
GWIPAddress: gw,
Label: label,
}
- return bgp.NewEVPNNLRI(bgp.EVPN_IP_PREFIX, 0, r), extcomms, nil
+ return bgp.NewEVPNNLRI(bgp.EVPN_IP_PREFIX, r), extcomms, nil
}
func ParseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
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")}),
diff --git a/table/path.go b/table/path.go
index 3b3982f6..a04e0d66 100644
--- a/table/path.go
+++ b/table/path.go
@@ -1194,7 +1194,7 @@ func (p *Path) ToGlobal(vrf *Vrf) *Path {
IPAddress: old.IPAddress,
Labels: old.Labels,
}
- nlri = bgp.NewEVPNNLRI(n.RouteType, n.Length, new)
+ nlri = bgp.NewEVPNNLRI(n.RouteType, new)
case bgp.EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG:
old := n.RouteTypeData.(*bgp.EVPNMulticastEthernetTagRoute)
new := &bgp.EVPNMulticastEthernetTagRoute{
@@ -1203,7 +1203,7 @@ func (p *Path) ToGlobal(vrf *Vrf) *Path {
IPAddressLength: old.IPAddressLength,
IPAddress: old.IPAddress,
}
- nlri = bgp.NewEVPNNLRI(n.RouteType, n.Length, new)
+ nlri = bgp.NewEVPNNLRI(n.RouteType, new)
}
default:
return p