summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-06-29 20:55:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-06-30 12:24:41 +0900
commit0ab9f19d609f33ed7189dbdafa54c2b7508fbee3 (patch)
treed599ec1c33772718a952951fb3ed06c0fac7ec4d
parent8907f5e426652e419ff08f8e6346e3448f876fd0 (diff)
packet/bgp: fix BGPPathAttributeMpReachNLRI next_hop parser and serializer
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bgp.py15
-rw-r--r--ryu/tests/unit/packet/test_bgp.py4
2 files changed, 14 insertions, 5 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 67ae58fe..55bac822 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -26,6 +26,7 @@ import abc
import six
import struct
import copy
+import netaddr
from ryu.ofproto.ofproto_parser import msg_pack_into
from ryu.lib.stringify import StringifyMixin
@@ -1777,6 +1778,10 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
self.safi = safi
self.next_hop_len = next_hop_len
self.next_hop = next_hop
+ if RouteFamily(afi, safi) in (RF_IPv6_UC, RF_IPv6_VPN):
+ self._next_hop_bin = addrconv.ipv6.text_to_bin(next_hop)
+ else:
+ self._next_hop_bin = addrconv.ipv4.text_to_bin(next_hop)
self.reserved = reserved
self.nlri = nlri
addr_cls = _get_addr_class(afi, safi)
@@ -1797,24 +1802,28 @@ 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):
+ next_hop = addrconv.ipv6.bin_to_text(next_hop_bin)
+ else:
+ next_hop = addrconv.ipv4.bin_to_text(next_hop_bin)
return {
'afi': afi,
'safi': safi,
'next_hop_len': next_hop_len,
- 'next_hop': next_hop_bin,
+ 'next_hop': next_hop,
'reserved': reserved,
'nlri': nlri,
}
def serialize_value(self):
# fixup
- self.next_hop_len = len(self.next_hop)
+ self.next_hop_len = len(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
+ buf += self._next_hop_bin
buf += self.reserved
binnlri = bytearray()
for n in self.nlri:
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py
index 00804dd2..0b563536 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -118,7 +118,7 @@ class Test_bgp(unittest.TestCase):
bgp.BGPPathAttributeAs4Aggregator(as_number=100040000,
addr='192.0.2.99'),
bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
- next_hop='abcd',
+ next_hop='1.1.1.1',
nlri=mp_nlri),
bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
withdrawn_routes=mp_nlri),
@@ -261,7 +261,7 @@ class Test_bgp(unittest.TestCase):
bgp.BGPPathAttributeAs4Aggregator(as_number=100040000,
addr='192.0.2.99'),
bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
- next_hop='abcd',
+ next_hop='1.1.1.1',
nlri=mp_nlri),
bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
withdrawn_routes=mp_nlri),