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