blob: 9c7a23f2dc8f6a401a98ff1761461833e543f700 [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.
# See the file LICENSE.pyloxi which should have been included in the source distribution
# Automatically generated by LOXI from template module.py
# Do not modify
import struct
import loxi
import const
import common
import action
import instruction
import oxm
import action_id
import instruction_id
import meter_band
import util
import loxi.generic_util
class meter_band(loxi.OFObject):
subtypes = {}
@staticmethod
def unpack(reader):
subtype, = reader.peek('!H', 0)
try:
subclass = meter_band.subtypes[subtype]
except KeyError:
raise loxi.ProtocolError("unknown meter_band subtype %#x" % subtype)
return subclass.unpack(reader)
class drop(meter_band):
type = 1
def __init__(self, rate=None, burst_size=None):
if rate != None:
self.rate = rate
else:
self.rate = 0
if burst_size != None:
self.burst_size = burst_size
else:
self.burst_size = 0
return
def pack(self):
packed = []
packed.append(struct.pack("!H", self.type))
packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
packed.append(struct.pack("!L", self.rate))
packed.append(struct.pack("!L", self.burst_size))
packed.append('\x00' * 4)
length = sum([len(x) for x in packed])
packed[1] = struct.pack("!H", length)
return ''.join(packed)
@staticmethod
def unpack(reader):
obj = drop()
_type = reader.read("!H")[0]
assert(_type == 1)
_len = reader.read("!H")[0]
orig_reader = reader
reader = orig_reader.slice(_len - (2 + 2))
obj.rate = reader.read("!L")[0]
obj.burst_size = reader.read("!L")[0]
reader.skip(4)
return obj
def __eq__(self, other):
if type(self) != type(other): return False
if self.rate != other.rate: return False
if self.burst_size != other.burst_size: return False
return True
def pretty_print(self, q):
q.text("drop {")
with q.group():
with q.indent(2):
q.breakable()
q.text("rate = ");
q.text("%#x" % self.rate)
q.text(","); q.breakable()
q.text("burst_size = ");
q.text("%#x" % self.burst_size)
q.breakable()
q.text('}')
meter_band.subtypes[1] = drop
class dscp_remark(meter_band):
type = 2
def __init__(self, rate=None, burst_size=None, prec_level=None):
if rate != None:
self.rate = rate
else:
self.rate = 0
if burst_size != None:
self.burst_size = burst_size
else:
self.burst_size = 0
if prec_level != None:
self.prec_level = prec_level
else:
self.prec_level = 0
return
def pack(self):
packed = []
packed.append(struct.pack("!H", self.type))
packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
packed.append(struct.pack("!L", self.rate))
packed.append(struct.pack("!L", self.burst_size))
packed.append(struct.pack("!B", self.prec_level))
packed.append('\x00' * 3)
length = sum([len(x) for x in packed])
packed[1] = struct.pack("!H", length)
return ''.join(packed)
@staticmethod
def unpack(reader):
obj = dscp_remark()
_type = reader.read("!H")[0]
assert(_type == 2)
_len = reader.read("!H")[0]
orig_reader = reader
reader = orig_reader.slice(_len - (2 + 2))
obj.rate = reader.read("!L")[0]
obj.burst_size = reader.read("!L")[0]
obj.prec_level = reader.read("!B")[0]
reader.skip(3)
return obj
def __eq__(self, other):
if type(self) != type(other): return False
if self.rate != other.rate: return False
if self.burst_size != other.burst_size: return False
if self.prec_level != other.prec_level: return False
return True
def pretty_print(self, q):
q.text("dscp_remark {")
with q.group():
with q.indent(2):
q.breakable()
q.text("rate = ");
q.text("%#x" % self.rate)
q.text(","); q.breakable()
q.text("burst_size = ");
q.text("%#x" % self.burst_size)
q.text(","); q.breakable()
q.text("prec_level = ");
q.text("%#x" % self.prec_level)
q.breakable()
q.text('}')
meter_band.subtypes[2] = dscp_remark
class experimenter(meter_band):
type = 65535
def __init__(self, rate=None, burst_size=None, experimenter=None):
if rate != None:
self.rate = rate
else:
self.rate = 0
if burst_size != None:
self.burst_size = burst_size
else:
self.burst_size = 0
if experimenter != None:
self.experimenter = experimenter
else:
self.experimenter = 0
return
def pack(self):
packed = []
packed.append(struct.pack("!H", self.type))
packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
packed.append(struct.pack("!L", self.rate))
packed.append(struct.pack("!L", self.burst_size))
packed.append(struct.pack("!L", self.experimenter))
length = sum([len(x) for x in packed])
packed[1] = struct.pack("!H", length)
return ''.join(packed)
@staticmethod
def unpack(reader):
obj = experimenter()
_type = reader.read("!H")[0]
assert(_type == 65535)
_len = reader.read("!H")[0]
orig_reader = reader
reader = orig_reader.slice(_len - (2 + 2))
obj.rate = reader.read("!L")[0]
obj.burst_size = reader.read("!L")[0]
obj.experimenter = reader.read("!L")[0]
return obj
def __eq__(self, other):
if type(self) != type(other): return False
if self.rate != other.rate: return False
if self.burst_size != other.burst_size: return False
if self.experimenter != other.experimenter: return False
return True
def pretty_print(self, q):
q.text("experimenter {")
with q.group():
with q.indent(2):
q.breakable()
q.text("rate = ");
q.text("%#x" % self.rate)
q.text(","); q.breakable()
q.text("burst_size = ");
q.text("%#x" % self.burst_size)
q.text(","); q.breakable()
q.text("experimenter = ");
q.text("%#x" % self.experimenter)
q.breakable()
q.text('}')
meter_band.subtypes[65535] = experimenter