summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/lib/packet/bgp.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index b077be31..b91ece7e 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -1771,6 +1771,7 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
_VALUE_PACK_STR = '!HBB' # afi, safi, next hop len
_ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
_class_prefixes = ['_BinAddrPrefix']
+ _rd_length = 8
def __init__(self, afi, safi, next_hop, nlri,
next_hop_len=0, reserved='\0',
@@ -1806,8 +1807,16 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
while binnlri:
n, binnlri = addr_cls.parser(binnlri)
nlri.append(n)
- if RouteFamily(afi, safi) in (RF_IPv6_UC, RF_IPv6_VPN):
+
+ rf = RouteFamily(afi, safi)
+ if rf == RF_IPv6_UC:
next_hop = addrconv.ipv6.bin_to_text(next_hop_bin)
+ elif rf == RF_IPv6_VPN:
+ next_hop = addrconv.ipv6.bin_to_text(next_hop_bin[cls._rd_length:])
+ next_hop_len -= cls._rd_length
+ elif rf == RF_IPv4_VPN:
+ next_hop = addrconv.ipv4.bin_to_text(next_hop_bin[cls._rd_length:])
+ next_hop_len -= cls._rd_length
else:
next_hop = addrconv.ipv4.bin_to_text(next_hop_bin)
return {
@@ -1822,12 +1831,22 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
def serialize_value(self):
# fixup
self.next_hop_len = len(self._next_hop_bin)
+
+ if RouteFamily(self.afi, self.safi) in (RF_IPv4_VPN, RF_IPv6_VPN):
+ empty_label_stack = '\x00' * self._rd_length
+ next_hop_len = len(self._next_hop_bin) + len(empty_label_stack)
+ next_hop_bin = empty_label_stack
+ next_hop_bin += self._next_hop_bin
+ else:
+ next_hop_len = self.next_hop_len
+ next_hop_bin = self._next_hop_bin
+
self.reserved = '\0'
buf = bytearray()
msg_pack_into(self._VALUE_PACK_STR, buf, 0, self.afi,
- self.safi, self.next_hop_len)
- buf += self._next_hop_bin
+ self.safi, next_hop_len)
+ buf += next_hop_bin
buf += self.reserved
binnlri = bytearray()
for n in self.nlri: