The second is patch to add or skip RD 0:0 label for the next_hop address in 
MP_REACH_NLRI attribute. 

According to RFC, next_hop address seems to be required to contain RD of 0 when 
advertise VPN prefix.
This is defined in RFC 4659(3.2.1.1.  BGP Speaker Requesting IPv6 Transport) 
for VPN-IPv6
and in RFC 4364(4.3.2.  Route Distribution Among PEs by BGP) for VPN-IPv4.

Signed-off-by: Hiroshi Yokoi <[email protected]>
---
 ryu/lib/packet/bgp.py | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index b077be3..b91ece7 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:
-- 
1.8.5.2 (Apple Git-48)



------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to