blob: de54fa8ff113ef1746555f59a0a0b20306a89d0f [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001# 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 Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneb658ddd2013-03-12 10:15:10 -07005
6# Automatically generated by LOXI from template util.py
7# Do not modify
8
9import loxi
10import const
Rich Lanec2ee4b82013-04-24 17:12:38 -070011import struct
Rich Laneb658ddd2013-03-12 10:15:10 -070012
13def pretty_mac(mac):
14 return ':'.join(["%02x" % x for x in mac])
15
16def pretty_ipv4(v):
17 return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
18
19def 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
32def pretty_wildcards(v):
33 if v == const.OFPFW_ALL:
34 return 'OFPFW_ALL'
35 flag_names = ['OFPFW_IN_PORT', 'OFPFW_DL_VLAN', 'OFPFW_DL_SRC', 'OFPFW_DL_DST',
36 'OFPFW_DL_TYPE', 'OFPFW_NW_PROTO', 'OFPFW_TP_SRC', 'OFPFW_TP_DST',
37 'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP',
38 'OFPFW_NW_TOS']
39 return pretty_flags(v, flag_names)
40
41def pretty_port(v):
42 named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
43 for (k, v2) in named_ports:
44 if v == v2:
45 return k
46 return v
Dan Talaycof6202252013-07-02 01:00:29 -070047
48def pack_port_no(value):
49 return struct.pack("!H", value)
50
51def unpack_port_no(reader):
52 return reader.read("!H")[0]
53
54def pack_fm_cmd(value):
55 return struct.pack("!H", value)
56
57def unpack_fm_cmd(reader):
58 return reader.read("!H")[0]
59
60def init_wc_bmap():
61 return const.OFPFW_ALL
62
63def pack_wc_bmap(value):
64 return struct.pack("!L", value)
65
66def unpack_wc_bmap(reader):
67 return reader.read("!L")[0]
68
69def init_match_bmap():
70 return const.OFPFW_ALL
71
72def pack_match_bmap(value):
73 return struct.pack("!L", value)
74
75def unpack_match_bmap(reader):
76 return reader.read("!L")[0]
77
78def pack_list(values):
79 return "".join([x.pack() for x in values])