Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | |
| 5 | # Automatically generated by LOXI from template util.py |
| 6 | # Do not modify |
| 7 | |
| 8 | import loxi |
| 9 | import const |
| 10 | import struct |
| 11 | |
| 12 | def pretty_mac(mac): |
| 13 | return ':'.join(["%02x" % x for x in mac]) |
| 14 | |
| 15 | def pretty_ipv4(v): |
| 16 | return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF) |
| 17 | |
| 18 | def pretty_flags(v, flag_names): |
| 19 | set_flags = [] |
| 20 | for flag_name in flag_names: |
| 21 | flag_value = getattr(const, flag_name) |
| 22 | if v & flag_value == flag_value: |
| 23 | set_flags.append(flag_name) |
| 24 | elif v & flag_value: |
| 25 | set_flags.append('%s&%#x' % (flag_name, v & flag_value)) |
| 26 | v &= ~flag_value |
| 27 | if v: |
| 28 | set_flags.append("%#x" % v) |
| 29 | return '|'.join(set_flags) or '0' |
| 30 | |
| 31 | |
| 32 | def pretty_port(v): |
| 33 | named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')] |
| 34 | for (k, v2) in named_ports: |
| 35 | if v == v2: |
| 36 | return k |
| 37 | return v |