summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-07-23 12:54:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-07-24 04:12:06 +0900
commitfaf13ff99fd47424c4fb93f1c2a6b3b80c81e0d1 (patch)
tree5c8b453f1fcff611b7e3b3aabee64b7c92bbe0b8
parent343e0f6997602063707b6b61dfc8051639042d89 (diff)
addrconv: replace bin<->text converters for ipv6
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/ip.py29
1 files changed, 3 insertions, 26 deletions
diff --git a/ryu/lib/ip.py b/ryu/lib/ip.py
index b302d8d8..7b2e29dd 100644
--- a/ryu/lib/ip.py
+++ b/ryu/lib/ip.py
@@ -1,4 +1,4 @@
-import struct
+from ryu.lib import addrconv
def ipv4_arg_to_bin(w, x, y, z):
@@ -26,39 +26,16 @@ def ipv4_to_str(ip):
z = ip & 0xff
return "%i.%i.%i.%i" % (w, x, y, z)
-IPV6_PACK_STR = '!8H'
-
-
-def ipv6_to_arg_list(ipv6):
- '''
- convert ipv6 string to a list of 8 different parts
- '''
- args = []
- if '::' in ipv6:
- h, t = ipv6.split('::')
- h_list = [int(x, 16) for x in h.split(':')]
- t_list = [int(x, 16) for x in t.split(':')]
- args += h_list
- zero = [0]
- args += ((8 - len(h_list) - len(t_list)) * zero)
- args += t_list
- else:
- args = [int(x, 16) for x in ipv6.split(':')]
-
- return args
-
def ipv6_to_bin(ipv6):
'''
convert ipv6 string to binary representation
'''
- args = ipv6_to_arg_list(ipv6)
- return struct.pack(IPV6_PACK_STR, *args)
+ return addrconv.ipv6.text_to_bin(ipv6)
def ipv6_to_str(bin_addr):
'''
convert binary representation to human readable string
'''
- args = struct.unpack_from(IPV6_PACK_STR, bin_addr)
- return ':'.join('%x' % x for x in args)
+ return addrconv.ipv6.bin_to_text(bin_addr)