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. |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 4 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 5 | |
| 6 | # Automatically generated by LOXI from template util.py |
| 7 | # Do not modify |
| 8 | |
| 9 | import loxi |
| 10 | import const |
| 11 | import struct |
| 12 | |
| 13 | def pretty_mac(mac): |
| 14 | return ':'.join(["%02x" % x for x in mac]) |
| 15 | |
| 16 | def pretty_ipv4(v): |
| 17 | return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF) |
| 18 | |
| 19 | def pretty_flags(v, flag_names): |
| 20 | set_flags = [] |
| 21 | for flag_name in flag_names: |
| 22 | flag_value = getattr(const, flag_name) |
| 23 | if v & flag_value == flag_value: |
| 24 | set_flags.append(flag_name) |
| 25 | elif v & flag_value: |
| 26 | set_flags.append('%s&%#x' % (flag_name, v & flag_value)) |
| 27 | v &= ~flag_value |
| 28 | if v: |
| 29 | set_flags.append("%#x" % v) |
| 30 | return '|'.join(set_flags) or '0' |
| 31 | |
| 32 | |
| 33 | def pretty_port(v): |
| 34 | named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')] |
| 35 | for (k, v2) in named_ports: |
| 36 | if v == v2: |
| 37 | return k |
| 38 | return v |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 39 | |
| 40 | def pack_port_no(value): |
| 41 | return struct.pack("!L", value) |
| 42 | |
| 43 | def unpack_port_no(reader): |
| 44 | return reader.read("!L")[0] |
| 45 | |
| 46 | def pack_fm_cmd(value): |
| 47 | return struct.pack("!B", value) |
| 48 | |
| 49 | def unpack_fm_cmd(reader): |
| 50 | return reader.read("!B")[0] |
| 51 | |
| 52 | def init_wc_bmap(): |
| 53 | return 0 |
| 54 | |
| 55 | def pack_wc_bmap(value): |
| 56 | return struct.pack("!Q", value) |
| 57 | |
| 58 | def unpack_wc_bmap(reader): |
| 59 | return reader.read("!Q")[0] |
| 60 | |
| 61 | def init_match_bmap(): |
| 62 | return 0 |
| 63 | |
| 64 | def pack_match_bmap(value): |
| 65 | return struct.pack("!Q", value) |
| 66 | |
| 67 | def unpack_match_bmap(reader): |
| 68 | return reader.read("!Q")[0] |
| 69 | |
| 70 | def pack_list(values): |
| 71 | return "".join([x.pack() for x in values]) |