blob: 45aa2d013c4c6469bdcd0be6d682c901bdcb2b9c [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.
4
5# Automatically generated by LOXI from template util.py
6# Do not modify
7
8import loxi
9import const
10import struct
11
12def pretty_mac(mac):
13 return ':'.join(["%02x" % x for x in mac])
14
15def pretty_ipv4(v):
16 return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
17
18def 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
31def pretty_wildcards(v):
32 if v == const.OFPFW_ALL:
33 return 'OFPFW_ALL'
34 flag_names = ['OFPFW_IN_PORT', 'OFPFW_DL_VLAN', 'OFPFW_DL_SRC', 'OFPFW_DL_DST',
35 'OFPFW_DL_TYPE', 'OFPFW_NW_PROTO', 'OFPFW_TP_SRC', 'OFPFW_TP_DST',
36 'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP',
37 'OFPFW_NW_TOS']
38 return pretty_flags(v, flag_names)
39
40def pretty_port(v):
41 named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
42 for (k, v2) in named_ports:
43 if v == v2:
44 return k
45 return v