1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # vim: tabstop=4 shiftwidth=4 softtabstop=4
23 from nose.tools import *
25 from ryu.lib import mac
27 LOG = logging.getLogger('test_mac')
30 class Test_mac(unittest.TestCase):
40 def test_mac_is_multicast(self):
41 addr = b'\x01\x23\x45\x67\x89\x0a'
44 res = mac.is_multicast(addr)
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'
52 res = mac.haddr_to_str(val)
56 def test_mac_haddr_to_str_none(self):
61 res = mac.haddr_to_str(addr)
65 @raises(AssertionError)
66 def test_mac_haddr_to_str_assert(self):
67 val = b'\xaa\xaa\xaa\xaa\xaa'
69 res = mac.haddr_to_str(val)
71 def test_mac_haddr_to_bin_false(self):
72 """ len(hexes) = 6 (False)
74 addr = 'aa:aa:aa:aa:aa:aa'
75 val = b'\xaa\xaa\xaa\xaa\xaa\xaa'
77 res = mac.haddr_to_bin(addr)
82 def test_mac_haddr_to_bin_true(self):
83 """ len(hexes) != 6 (True)
85 addr = 'aa:aa:aa:aa:aa'
86 res = mac.haddr_to_bin(addr)
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'
93 res = mac.haddr_bitand(addr, mask)