summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYusuke Iwase <iwase.yusuke0@gmail.com>2015-10-06 16:50:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-10-11 21:51:38 +0900
commite7ce316918a1c911a24994c43b4952d794eed614 (patch)
treeb143ad4ab3cc9bfc16dd3a86468e281a7569ea61
parent9e542b885110404fd5ac8bfd25f5c4c97adc933a (diff)
test_ip: Add tests for IPv4-int conversion
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/lib/test_ip.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/ryu/tests/unit/lib/test_ip.py b/ryu/tests/unit/lib/test_ip.py
index f23f98c8..5aa74109 100644
--- a/ryu/tests/unit/lib/test_ip.py
+++ b/ryu/tests/unit/lib/test_ip.py
@@ -1,8 +1,21 @@
+# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import unittest
import logging
import struct
-import netaddr
-from struct import *
from nose.tools import *
from ryu.lib import ip
@@ -11,9 +24,9 @@ LOG = logging.getLogger('test_ip')
class Test_ip(unittest.TestCase):
- '''
- test case for ip address module
- '''
+ """
+ test case for ip address module
+ """
def setUp(self):
pass
@@ -28,13 +41,27 @@ class Test_ip(unittest.TestCase):
(res,) = struct.unpack('!I', ip.ipv4_to_bin(ipv4_str))
eq_(val, res)
- def test_ipv4_to_str(self):
+ def test_ipv4_to_int(self):
+ ipv4_str = '10.28.197.1'
+ val = 169657601
+
+ res = ip.ipv4_to_int(ipv4_str)
+ eq_(val, res)
+
+ def test_ipv4_to_str_from_bin(self):
ipv4_bin = struct.pack('!I', 0x0a1cc501)
val = '10.28.197.1'
res = ip.ipv4_to_str(ipv4_bin)
eq_(val, res)
+ def test_ipv4_to_str_from_int(self):
+ ipv4_int = 169657601
+ val = '10.28.197.1'
+
+ res = ip.ipv4_to_str(ipv4_int)
+ eq_(val, res)
+
def test_ipv6_to_bin(self):
ipv6_str = '2013:da8:215:8f2:aa20:66ff:fe4c:9c3c'
val = struct.pack('!8H', 0x2013, 0xda8, 0x215, 0x8f2, 0xaa20, 0x66ff,