1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from nose.tools import eq_
20 from ryu.lib import addrconv
23 class Test_addrconv(unittest.TestCase):
24 """ Test case for ryu.lib.addrconv
34 def _test_conv(conv, text_value, bin_value):
35 eq_(conv.text_to_bin(text_value), bin_value)
36 eq_(conv.bin_to_text(bin_value), text_value)
39 self._test_conv(addrconv.ipv4, '0.0.0.0', b'\x00\x00\x00\x00')
40 self._test_conv(addrconv.ipv4, '127.0.0.1', b'\x7f\x00\x00\x01')
41 self._test_conv(addrconv.ipv4, '255.255.0.0', b'\xff\xff\x00\x00')
44 self._test_conv(addrconv.ipv6, 'ff02::1',
45 (b'\xff\x02\x00\x00\x00\x00\x00\x00'
46 b'\x00\x00\x00\x00\x00\x00\x00\x01'))
47 self._test_conv(addrconv.ipv6, 'fe80::f00b:a4ff:fe7d:f8ea',
48 (b'\xfe\x80\x00\x00\x00\x00\x00\x00'
49 b'\xf0\x0b\xa4\xff\xfe\x7d\xf8\xea'))
50 self._test_conv(addrconv.ipv6, '::',
51 (b'\x00\x00\x00\x00\x00\x00\x00\x00'
52 b'\x00\x00\x00\x00\x00\x00\x00\x00'))
55 self._test_conv(addrconv.mac, 'f2:0b:a4:01:0a:23',
56 b'\xf2\x0b\xa4\x01\x0a\x23')