blob: 814442ae024d7f55ccdf725799c5772fb413d679 [file] [log] [blame]
Rich Laneca3da272013-05-05 09:07:33 -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 meter_band.py
6# Do not modify
7
8import struct
9import const
10import util
11import loxi.generic_util
12import loxi
13
14def unpack_list(reader):
15 def deserializer(reader, typ):
16 parser = parsers.get(typ)
17 if not parser: raise loxi.ProtocolError("unknown meter band type %d" % typ)
18 return parser(reader)
19 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
20
21class MeterBand(object):
22 type = None # override in subclass
23 pass
24
25class drop(MeterBand):
26 type = const.OFPMBT_DROP
27
28 def __init__(self, rate=None, burst_size=None):
29 if rate != None:
30 self.rate = rate
31 else:
32 self.rate = 0
33 if burst_size != None:
34 self.burst_size = burst_size
35 else:
36 self.burst_size = 0
37 return
38
39 def pack(self):
40 packed = []
41 packed.append(struct.pack("!H", self.type))
42 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
43 packed.append(struct.pack("!L", self.rate))
44 packed.append(struct.pack("!L", self.burst_size))
45 packed.append('\x00' * 4)
46 length = sum([len(x) for x in packed])
47 packed[1] = struct.pack("!H", length)
48 return ''.join(packed)
49
50 @staticmethod
51 def unpack(buf):
52 obj = drop()
53 if type(buf) == loxi.generic_util.OFReader:
54 reader = buf
55 else:
56 reader = loxi.generic_util.OFReader(buf)
57 _type = reader.read('!H')[0]
58 assert(_type == const.OFPMBT_DROP)
59 _len = reader.read('!H')[0]
60 obj.rate = reader.read('!L')[0]
61 obj.burst_size = reader.read('!L')[0]
62 reader.skip(4)
63 return obj
64
65 def __eq__(self, other):
66 if type(self) != type(other): return False
67 if self.rate != other.rate: return False
68 if self.burst_size != other.burst_size: return False
69 return True
70
71 def __ne__(self, other):
72 return not self.__eq__(other)
73
74 def show(self):
75 import loxi.pp
76 return loxi.pp.pp(self)
77
78 def pretty_print(self, q):
79 q.text("drop {")
80 with q.group():
81 with q.indent(2):
82 q.breakable()
83 q.text("rate = ");
84 q.text("%#x" % self.rate)
85 q.text(","); q.breakable()
86 q.text("burst_size = ");
87 q.text("%#x" % self.burst_size)
88 q.breakable()
89 q.text('}')
90
91class dscp_remark(MeterBand):
92 type = const.OFPMBT_DSCP_REMARK
93
94 def __init__(self, rate=None, burst_size=None, prec_level=None):
95 if rate != None:
96 self.rate = rate
97 else:
98 self.rate = 0
99 if burst_size != None:
100 self.burst_size = burst_size
101 else:
102 self.burst_size = 0
103 if prec_level != None:
104 self.prec_level = prec_level
105 else:
106 self.prec_level = 0
107 return
108
109 def pack(self):
110 packed = []
111 packed.append(struct.pack("!H", self.type))
112 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
113 packed.append(struct.pack("!L", self.rate))
114 packed.append(struct.pack("!L", self.burst_size))
115 packed.append(struct.pack("!B", self.prec_level))
116 packed.append('\x00' * 3)
117 length = sum([len(x) for x in packed])
118 packed[1] = struct.pack("!H", length)
119 return ''.join(packed)
120
121 @staticmethod
122 def unpack(buf):
123 obj = dscp_remark()
124 if type(buf) == loxi.generic_util.OFReader:
125 reader = buf
126 else:
127 reader = loxi.generic_util.OFReader(buf)
128 _type = reader.read('!H')[0]
129 assert(_type == const.OFPMBT_DSCP_REMARK)
130 _len = reader.read('!H')[0]
131 obj.rate = reader.read('!L')[0]
132 obj.burst_size = reader.read('!L')[0]
133 obj.prec_level = reader.read('!B')[0]
134 reader.skip(3)
135 return obj
136
137 def __eq__(self, other):
138 if type(self) != type(other): return False
139 if self.rate != other.rate: return False
140 if self.burst_size != other.burst_size: return False
141 if self.prec_level != other.prec_level: return False
142 return True
143
144 def __ne__(self, other):
145 return not self.__eq__(other)
146
147 def show(self):
148 import loxi.pp
149 return loxi.pp.pp(self)
150
151 def pretty_print(self, q):
152 q.text("dscp_remark {")
153 with q.group():
154 with q.indent(2):
155 q.breakable()
156 q.text("rate = ");
157 q.text("%#x" % self.rate)
158 q.text(","); q.breakable()
159 q.text("burst_size = ");
160 q.text("%#x" % self.burst_size)
161 q.text(","); q.breakable()
162 q.text("prec_level = ");
163 q.text("%#x" % self.prec_level)
164 q.breakable()
165 q.text('}')
166
167class experimenter(MeterBand):
168 type = const.OFPMBT_EXPERIMENTER
169
170 def __init__(self, rate=None, burst_size=None, experimenter=None):
171 if rate != None:
172 self.rate = rate
173 else:
174 self.rate = 0
175 if burst_size != None:
176 self.burst_size = burst_size
177 else:
178 self.burst_size = 0
179 if experimenter != None:
180 self.experimenter = experimenter
181 else:
182 self.experimenter = 0
183 return
184
185 def pack(self):
186 packed = []
187 packed.append(struct.pack("!H", self.type))
188 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
189 packed.append(struct.pack("!L", self.rate))
190 packed.append(struct.pack("!L", self.burst_size))
191 packed.append(struct.pack("!L", self.experimenter))
192 length = sum([len(x) for x in packed])
193 packed[1] = struct.pack("!H", length)
194 return ''.join(packed)
195
196 @staticmethod
197 def unpack(buf):
198 obj = experimenter()
199 if type(buf) == loxi.generic_util.OFReader:
200 reader = buf
201 else:
202 reader = loxi.generic_util.OFReader(buf)
203 _type = reader.read('!H')[0]
204 assert(_type == const.OFPMBT_EXPERIMENTER)
205 _len = reader.read('!H')[0]
206 obj.rate = reader.read('!L')[0]
207 obj.burst_size = reader.read('!L')[0]
208 obj.experimenter = reader.read('!L')[0]
209 return obj
210
211 def __eq__(self, other):
212 if type(self) != type(other): return False
213 if self.rate != other.rate: return False
214 if self.burst_size != other.burst_size: return False
215 if self.experimenter != other.experimenter: return False
216 return True
217
218 def __ne__(self, other):
219 return not self.__eq__(other)
220
221 def show(self):
222 import loxi.pp
223 return loxi.pp.pp(self)
224
225 def pretty_print(self, q):
226 q.text("experimenter {")
227 with q.group():
228 with q.indent(2):
229 q.breakable()
230 q.text("rate = ");
231 q.text("%#x" % self.rate)
232 q.text(","); q.breakable()
233 q.text("burst_size = ");
234 q.text("%#x" % self.burst_size)
235 q.text(","); q.breakable()
236 q.text("experimenter = ");
237 q.text("%#x" % self.experimenter)
238 q.breakable()
239 q.text('}')
240
241
242parsers = {
243 const.OFPMBT_DROP : drop.unpack,
244 const.OFPMBT_DSCP_REMARK : dscp_remark.unpack,
245 const.OFPMBT_EXPERIMENTER : experimenter.unpack,
246}