summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-11-09 10:44:01 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-11-14 12:49:14 +0900
commita376adf6b66ca93cf4de0852e2ac91e2aa942d8d (patch)
tree101e7df4f53a56ab35e53783a9e667ef74bf4268
parente760300e93fcadc24602534ffc4f45691b68da09 (diff)
packet/bgp: Fix the EvpnNLRI to use the ryu.lib.ip
Also, this patch changes size of ip_len from bit to byte. Signed-off-by: Shinpei Muraoka <shinpei.muraoka@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bgp.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index a07c1ac7..dabf2331 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -1418,22 +1418,11 @@ class EvpnNLRI(StringifyMixin, _TypeDisp):
@staticmethod
def _ip_addr_from_bin(buf, ip_len):
- _len = ip_len // 8
- if _len == 4:
- return addrconv.ipv4.bin_to_text(buf[:_len]), buf[_len:]
- elif _len == 16:
- return addrconv.ipv6.bin_to_text(buf[:_len]), buf[_len:]
- else:
- raise struct.error('Invalid ip address length: %s' % ip_len)
+ return ip.bin_to_text(buf[:ip_len]), buf[ip_len:]
@staticmethod
def _ip_addr_to_bin(ip_addr):
- if '.' in ip_addr:
- # IPv4 address
- return addrconv.ipv4.text_to_bin(ip_addr)
- else:
- # IPv6 address
- return addrconv.ipv6.text_to_bin(ip_addr)
+ return ip.text_to_bin(ip_addr)
@staticmethod
def _mpls_label_from_bin(buf):
@@ -1697,7 +1686,7 @@ class EvpnMacIPAdvertisementNLRI(EvpnNLRI):
mac_addr, rest = cls._mac_addr_from_bin(rest, mac_addr_len)
ip_addr_len, rest = cls._ip_addr_len_from_bin(rest)
if ip_addr_len != 0:
- ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len)
+ ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len // 8)
else:
ip_addr = None
@@ -1796,7 +1785,7 @@ class EvpnInclusiveMulticastEthernetTagNLRI(EvpnNLRI):
route_dist, rest = cls._rd_from_bin(buf)
ethernet_tag_id, rest = cls._ethernet_tag_id_from_bin(rest)
ip_addr_len, rest = cls._ip_addr_len_from_bin(rest)
- ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len)
+ ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len // 8)
return {
'route_dist': route_dist.formatted_str,
@@ -1855,7 +1844,7 @@ class EvpnEthernetSegmentNLRI(EvpnNLRI):
route_dist, rest = cls._rd_from_bin(buf)
esi, rest = cls._esi_from_bin(rest)
ip_addr_len, rest = cls._ip_addr_len_from_bin(rest)
- ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len)
+ ip_addr, rest = cls._ip_addr_from_bin(rest, ip_addr_len // 8)
return {
'route_dist': route_dist.formatted_str,