backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / lib / test_mac.py
1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # vim: tabstop=4 shiftwidth=4 softtabstop=4
17
18 import unittest
19 import logging
20 import struct
21 import netaddr
22 from struct import *
23 from nose.tools import *
24
25 from ryu.lib import mac
26
27 LOG = logging.getLogger('test_mac')
28
29
30 class Test_mac(unittest.TestCase):
31     """ Test case for mac
32     """
33
34     def setUp(self):
35         pass
36
37     def tearDown(self):
38         pass
39
40     def test_mac_is_multicast(self):
41         addr = b'\x01\x23\x45\x67\x89\x0a'
42         val = True
43
44         res = mac.is_multicast(addr)
45
46         eq_(val, res)
47
48     def test_mac_haddr_to_str(self):
49         addr = 'aa:aa:aa:aa:aa:aa'
50         val = b'\xaa\xaa\xaa\xaa\xaa\xaa'
51
52         res = mac.haddr_to_str(val)
53
54         eq_(addr, res)
55
56     def test_mac_haddr_to_str_none(self):
57         """ addr is None
58         """
59         addr = None
60         val = 'None'
61         res = mac.haddr_to_str(addr)
62
63         eq_(val, res)
64
65     @raises(AssertionError)
66     def test_mac_haddr_to_str_assert(self):
67         val = b'\xaa\xaa\xaa\xaa\xaa'
68
69         res = mac.haddr_to_str(val)
70
71     def test_mac_haddr_to_bin_false(self):
72         """ len(hexes) = 6 (False)
73         """
74         addr = 'aa:aa:aa:aa:aa:aa'
75         val = b'\xaa\xaa\xaa\xaa\xaa\xaa'
76
77         res = mac.haddr_to_bin(addr)
78
79         eq_(val, res)
80
81     @raises(ValueError)
82     def test_mac_haddr_to_bin_true(self):
83         """ len(hexes) != 6 (True)
84         """
85         addr = 'aa:aa:aa:aa:aa'
86         res = mac.haddr_to_bin(addr)
87
88     def test_mac_haddr_bitand(self):
89         addr = b'\xaa\xaa\xaa\xaa\xaa\xaa'
90         mask = b'\xff\xff\xff\x00\x00\x00'
91         val = b'\xaa\xaa\xaa\x00\x00\x00'
92
93         res = mac.haddr_bitand(addr, mask)
94
95         eq_(val, res)