diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-07-23 12:54:08 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-07-24 04:12:04 +0900 |
commit | 343e0f6997602063707b6b61dfc8051639042d89 (patch) | |
tree | 283b078a11ed0d4c796aa9ba44f1a73e400adbd6 | |
parent | 80d4202c9161d903afdc22ad4f3d75aa5b7fd81b (diff) |
addrconv: replace bin<->text converters for mac addresses
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/mac.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/ryu/lib/mac.py b/ryu/lib/mac.py index 2c128773..ad10672d 100644 --- a/ryu/lib/mac.py +++ b/ryu/lib/mac.py @@ -14,14 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ryu.lib import addrconv + import itertools # string representation HADDR_PATTERN = r'([0-9a-f]{2}:){5}[0-9a-f]{2}' -# Internal representation of mac address is string[6] -_HADDR_LEN = 6 - DONTCARE = '\x00' * 6 BROADCAST = '\xff' * 6 MULTICAST = '\xfe' + '\xff' * 5 @@ -37,17 +36,19 @@ def haddr_to_str(addr): form""" if addr is None: return 'None' - assert len(addr) == _HADDR_LEN - return ':'.join('%02x' % ord(char) for char in addr) + try: + return addrconv.mac.bin_to_text(addr) + except: + raise AssertionError def haddr_to_bin(string): """Parse mac address string in human readable format into internal representation""" - hexes = string.split(':') - if len(hexes) != _HADDR_LEN: - raise ValueError('Invalid format for mac address: %s' % string) - return ''.join(chr(int(h, 16)) for h in hexes) + try: + return addrconv.mac.text_to_bin(string) + except: + raise ValueError def haddr_bitand(addr, mask): |