summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-09 22:23:46 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-09 22:23:46 +0900
commitf3342c236eff5e5bc378fd320b538a0f02ac20e3 (patch)
tree25b573bd26acb92b5ae0d7f60dc18eeff822bfa6
parenta1c1142ee400e8c90613fe27f3f6499b4678eabf (diff)
packet: fix EVPN parser/serializer
Also add unit test. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--packet/bgp.go26
-rw-r--r--packet/bgp_test.go19
2 files changed, 34 insertions, 11 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 7779d205..5cd748e7 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1169,7 +1169,7 @@ func (er *EVPNMulticastEthernetTagRoute) DecodeFromBytes(data []byte) error {
er.IPAddressLength = data[4]
data = data[5:]
if er.IPAddressLength == 32 || er.IPAddressLength == 128 {
- er.IPAddress = net.IP(data)
+ er.IPAddress = net.IP(data[:er.IPAddressLength/8])
} else {
return fmt.Errorf("Invalid IP address length", er.IPAddressLength)
}
@@ -1203,7 +1203,7 @@ type EVPNEthernetSegmentRoute struct {
RD RouteDistinguisherInterface
ESI EthernetSegmentIdentifier
IPAddressLength uint8
- IPAddress IPAddrPrefix
+ IPAddress net.IP
}
func (er *EVPNEthernetSegmentRoute) DecodeFromBytes(data []byte) error {
@@ -1212,9 +1212,11 @@ func (er *EVPNEthernetSegmentRoute) DecodeFromBytes(data []byte) error {
er.ESI.DecodeFromBytes(data)
data = data[10:]
er.IPAddressLength = data[0]
- err := er.IPAddress.DecodeFromBytes(data[1:])
- if err != nil {
- return err
+ data = data[1:]
+ if er.IPAddressLength == 32 || er.IPAddressLength == 128 {
+ er.IPAddress = net.IP(data[:er.IPAddressLength/8])
+ } else {
+ return fmt.Errorf("Invalid IP address length", er.IPAddressLength)
}
return nil
}
@@ -1229,13 +1231,15 @@ func (er *EVPNEthernetSegmentRoute) Serialize() ([]byte, error) {
return nil, err
}
buf = append(buf, tbuf...)
- tbuf = make([]byte, 1)
- tbuf, err = er.IPAddress.Serialize()
- if err != nil {
- return nil, err
+ buf = append(buf, er.IPAddressLength)
+ if er.IPAddressLength == 32 || er.IPAddressLength == 128 {
+ if er.IPAddressLength == 32 {
+ er.IPAddress = er.IPAddress.To4()
+ }
+ buf = append(buf, []byte(er.IPAddress)...)
+ } else {
+ return nil, fmt.Errorf("Invalid IP address length", er.IPAddressLength)
}
- buf = append(buf, tbuf...)
-
return buf, nil
}
diff --git a/packet/bgp_test.go b/packet/bgp_test.go
index d2d99b9e..97734606 100644
--- a/packet/bgp_test.go
+++ b/packet/bgp_test.go
@@ -83,6 +83,24 @@ func update() *BGPMessage {
mp_nlri4 := []AddrPrefixInterface{NewLabelledIPAddrPrefix(25, "192.168.0.0",
*NewLabel(5, 6, 7))}
+ mac, _ := net.ParseMAC("01:23:45:67:89:ab")
+ mp_nlri5 := []AddrPrefixInterface{
+ NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0,
+ &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}),
+ NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0,
+ &EVPNMacIPAdvertisementRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, 48,
+ mac, 32, net.ParseIP("192.2.1.2"),
+ []uint32{3}}),
+ NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, 0,
+ &EVPNMulticastEthernetTagRoute{NewRouteDistinguisherFourOctetAS(5, 6), 3, 32, net.ParseIP("192.2.1.2")}),
+ NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, 0,
+ &EVPNEthernetSegmentRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)},
+ 32, net.ParseIP("192.2.1.1")}),
+ }
+
p := []PathAttributeInterface{
NewPathAttributeOrigin(3),
NewPathAttributeAsPath(aspath1),
@@ -104,6 +122,7 @@ func update() *BGPMessage {
NewPathAttributeMpReachNLRI("1023::", mp_nlri2),
NewPathAttributeMpReachNLRI("fe80::", mp_nlri3),
NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri4),
+ NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri5),
NewPathAttributeMpUnreachNLRI(mp_nlri),
//NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}),
//NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}),