blob: d431d4c8cdf0bd9ae3818bb4deedb194858cc853 [file] [log] [blame]
# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
# Copyright (c) 2011, 2012 Open Networking Foundation
# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
# Automatically generated by LOXI from template util.py
# Do not modify
import loxi
import const
import struct
def pretty_mac(mac):
return ':'.join(["%02x" % x for x in mac])
def pretty_ipv4(v):
return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
def pretty_flags(v, flag_names):
set_flags = []
for flag_name in flag_names:
flag_value = getattr(const, flag_name)
if v & flag_value == flag_value:
set_flags.append(flag_name)
elif v & flag_value:
set_flags.append('%s&%#x' % (flag_name, v & flag_value))
v &= ~flag_value
if v:
set_flags.append("%#x" % v)
return '|'.join(set_flags) or '0'
def pretty_port(v):
named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
for (k, v2) in named_ports:
if v == v2:
return k
return v