summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2014-07-31 14:59:49 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-07-31 15:05:15 +0900
commit7acda14a5d8024ea206be03aefd2c06b804e1063 (patch)
tree1dd7c81e9e4aa59a6a66e49d1a102bcf399bff68
parentcc3c00b663b99a7aa8ef381d06febfbab9185443 (diff)
bgp: add code to handle RD 0:0 at the head of nexthop network address in MP_REACH_NLRI path attribute
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 <yokoi.hiroshi@po.ntts.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-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: