backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / lib / test_addrconv.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 #
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
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import unittest
18 from nose.tools import eq_
19
20 from ryu.lib import addrconv
21
22
23 class Test_addrconv(unittest.TestCase):
24     """ Test case for ryu.lib.addrconv
25     """
26
27     def setUp(self):
28         pass
29
30     def tearDown(self):
31         pass
32
33     @staticmethod
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)
37
38     def test_ipv4(self):
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')
42
43     def test_ipv6(self):
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'))
53
54     def test_mac(self):
55         self._test_conv(addrconv.mac, 'f2:0b:a4:01:0a:23',
56                         b'\xf2\x0b\xa4\x01\x0a\x23')