blob: cebf31ea4ad2714b8fbcea6ea2f664f190a739fb [file] [log] [blame]
Rich Lane2e079da2014-10-29 15:30:24 -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 const
12import port_desc_prop
13import meter_band
14import table_mod_prop
15import instruction
16import queue_desc_prop
17import oxm
18import bundle_prop
19import common
20import instruction_id
21import action
22import role_prop
23import message
24import queue_stats_prop
25import port_stats_prop
26import port_mod_prop
27import async_config_prop
28import action_id
29import util
30import loxi.generic_util
31
32class instruction(loxi.OFObject):
33 subtypes = {}
34
35
36 def __init__(self, type=None):
37 if type != None:
38 self.type = type
39 else:
40 self.type = 0
41 return
42
43 def pack(self):
44 packed = []
45 packed.append(struct.pack("!H", self.type))
46 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
47 length = sum([len(x) for x in packed])
48 packed[1] = struct.pack("!H", length)
49 return ''.join(packed)
50
51 @staticmethod
52 def unpack(reader):
53 subtype, = reader.peek('!H', 0)
54 subclass = instruction.subtypes.get(subtype)
55 if subclass:
56 return subclass.unpack(reader)
57
58 obj = instruction()
59 obj.type = reader.read("!H")[0]
60 _len = reader.read("!H")[0]
61 orig_reader = reader
62 reader = orig_reader.slice(_len - (2 + 2))
63 return obj
64
65 def __eq__(self, other):
66 if type(self) != type(other): return False
67 if self.type != other.type: return False
68 return True
69
70 def pretty_print(self, q):
71 q.text("instruction {")
72 with q.group():
73 with q.indent(2):
74 q.breakable()
75 q.breakable()
76 q.text('}')
77
78
79class apply_actions(instruction):
80 type = 4
81
82 def __init__(self, actions=None):
83 if actions != None:
84 self.actions = actions
85 else:
86 self.actions = []
87 return
88
89 def pack(self):
90 packed = []
91 packed.append(struct.pack("!H", self.type))
92 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
93 packed.append('\x00' * 4)
94 packed.append(loxi.generic_util.pack_list(self.actions))
95 length = sum([len(x) for x in packed])
96 packed[1] = struct.pack("!H", length)
97 return ''.join(packed)
98
99 @staticmethod
100 def unpack(reader):
101 obj = apply_actions()
102 _type = reader.read("!H")[0]
103 assert(_type == 4)
104 _len = reader.read("!H")[0]
105 orig_reader = reader
106 reader = orig_reader.slice(_len - (2 + 2))
107 reader.skip(4)
108 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
109 return obj
110
111 def __eq__(self, other):
112 if type(self) != type(other): return False
113 if self.actions != other.actions: return False
114 return True
115
116 def pretty_print(self, q):
117 q.text("apply_actions {")
118 with q.group():
119 with q.indent(2):
120 q.breakable()
121 q.text("actions = ");
122 q.pp(self.actions)
123 q.breakable()
124 q.text('}')
125
126instruction.subtypes[4] = apply_actions
127
128class clear_actions(instruction):
129 type = 5
130
131 def __init__(self):
132 return
133
134 def pack(self):
135 packed = []
136 packed.append(struct.pack("!H", self.type))
137 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
138 packed.append('\x00' * 4)
139 length = sum([len(x) for x in packed])
140 packed[1] = struct.pack("!H", length)
141 return ''.join(packed)
142
143 @staticmethod
144 def unpack(reader):
145 obj = clear_actions()
146 _type = reader.read("!H")[0]
147 assert(_type == 5)
148 _len = reader.read("!H")[0]
149 orig_reader = reader
150 reader = orig_reader.slice(_len - (2 + 2))
151 reader.skip(4)
152 return obj
153
154 def __eq__(self, other):
155 if type(self) != type(other): return False
156 return True
157
158 def pretty_print(self, q):
159 q.text("clear_actions {")
160 with q.group():
161 with q.indent(2):
162 q.breakable()
163 q.breakable()
164 q.text('}')
165
166instruction.subtypes[5] = clear_actions
167
168class experimenter(instruction):
169 subtypes = {}
170
171 type = 65535
172
173 def __init__(self, experimenter=None, data=None):
174 if experimenter != None:
175 self.experimenter = experimenter
176 else:
177 self.experimenter = 0
178 if data != None:
179 self.data = data
180 else:
181 self.data = ''
182 return
183
184 def pack(self):
185 packed = []
186 packed.append(struct.pack("!H", self.type))
187 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
188 packed.append(struct.pack("!L", self.experimenter))
189 packed.append(self.data)
190 length = sum([len(x) for x in packed])
191 packed[1] = struct.pack("!H", length)
192 return ''.join(packed)
193
194 @staticmethod
195 def unpack(reader):
196 subtype, = reader.peek('!L', 4)
197 subclass = experimenter.subtypes.get(subtype)
198 if subclass:
199 return subclass.unpack(reader)
200
201 obj = experimenter()
202 _type = reader.read("!H")[0]
203 assert(_type == 65535)
204 _len = reader.read("!H")[0]
205 orig_reader = reader
206 reader = orig_reader.slice(_len - (2 + 2))
207 obj.experimenter = reader.read("!L")[0]
208 obj.data = str(reader.read_all())
209 return obj
210
211 def __eq__(self, other):
212 if type(self) != type(other): return False
213 if self.experimenter != other.experimenter: return False
214 if self.data != other.data: return False
215 return True
216
217 def pretty_print(self, q):
218 q.text("experimenter {")
219 with q.group():
220 with q.indent(2):
221 q.breakable()
222 q.text("data = ");
223 q.pp(self.data)
224 q.breakable()
225 q.text('}')
226
227instruction.subtypes[65535] = experimenter
228
229class goto_table(instruction):
230 type = 1
231
232 def __init__(self, table_id=None):
233 if table_id != None:
234 self.table_id = table_id
235 else:
236 self.table_id = 0
237 return
238
239 def pack(self):
240 packed = []
241 packed.append(struct.pack("!H", self.type))
242 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
243 packed.append(struct.pack("!B", self.table_id))
244 packed.append('\x00' * 3)
245 length = sum([len(x) for x in packed])
246 packed[1] = struct.pack("!H", length)
247 return ''.join(packed)
248
249 @staticmethod
250 def unpack(reader):
251 obj = goto_table()
252 _type = reader.read("!H")[0]
253 assert(_type == 1)
254 _len = reader.read("!H")[0]
255 orig_reader = reader
256 reader = orig_reader.slice(_len - (2 + 2))
257 obj.table_id = reader.read("!B")[0]
258 reader.skip(3)
259 return obj
260
261 def __eq__(self, other):
262 if type(self) != type(other): return False
263 if self.table_id != other.table_id: return False
264 return True
265
266 def pretty_print(self, q):
267 q.text("goto_table {")
268 with q.group():
269 with q.indent(2):
270 q.breakable()
271 q.text("table_id = ");
272 q.text("%#x" % self.table_id)
273 q.breakable()
274 q.text('}')
275
276instruction.subtypes[1] = goto_table
277
278class meter(instruction):
279 type = 6
280
281 def __init__(self, meter_id=None):
282 if meter_id != None:
283 self.meter_id = meter_id
284 else:
285 self.meter_id = 0
286 return
287
288 def pack(self):
289 packed = []
290 packed.append(struct.pack("!H", self.type))
291 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
292 packed.append(struct.pack("!L", self.meter_id))
293 length = sum([len(x) for x in packed])
294 packed[1] = struct.pack("!H", length)
295 return ''.join(packed)
296
297 @staticmethod
298 def unpack(reader):
299 obj = meter()
300 _type = reader.read("!H")[0]
301 assert(_type == 6)
302 _len = reader.read("!H")[0]
303 orig_reader = reader
304 reader = orig_reader.slice(_len - (2 + 2))
305 obj.meter_id = reader.read("!L")[0]
306 return obj
307
308 def __eq__(self, other):
309 if type(self) != type(other): return False
310 if self.meter_id != other.meter_id: return False
311 return True
312
313 def pretty_print(self, q):
314 q.text("meter {")
315 with q.group():
316 with q.indent(2):
317 q.breakable()
318 q.text("meter_id = ");
319 q.text("%#x" % self.meter_id)
320 q.breakable()
321 q.text('}')
322
323instruction.subtypes[6] = meter
324
325class write_actions(instruction):
326 type = 3
327
328 def __init__(self, actions=None):
329 if actions != None:
330 self.actions = actions
331 else:
332 self.actions = []
333 return
334
335 def pack(self):
336 packed = []
337 packed.append(struct.pack("!H", self.type))
338 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
339 packed.append('\x00' * 4)
340 packed.append(loxi.generic_util.pack_list(self.actions))
341 length = sum([len(x) for x in packed])
342 packed[1] = struct.pack("!H", length)
343 return ''.join(packed)
344
345 @staticmethod
346 def unpack(reader):
347 obj = write_actions()
348 _type = reader.read("!H")[0]
349 assert(_type == 3)
350 _len = reader.read("!H")[0]
351 orig_reader = reader
352 reader = orig_reader.slice(_len - (2 + 2))
353 reader.skip(4)
354 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
355 return obj
356
357 def __eq__(self, other):
358 if type(self) != type(other): return False
359 if self.actions != other.actions: return False
360 return True
361
362 def pretty_print(self, q):
363 q.text("write_actions {")
364 with q.group():
365 with q.indent(2):
366 q.breakable()
367 q.text("actions = ");
368 q.pp(self.actions)
369 q.breakable()
370 q.text('}')
371
372instruction.subtypes[3] = write_actions
373
374class write_metadata(instruction):
375 type = 2
376
377 def __init__(self, metadata=None, metadata_mask=None):
378 if metadata != None:
379 self.metadata = metadata
380 else:
381 self.metadata = 0
382 if metadata_mask != None:
383 self.metadata_mask = metadata_mask
384 else:
385 self.metadata_mask = 0
386 return
387
388 def pack(self):
389 packed = []
390 packed.append(struct.pack("!H", self.type))
391 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
392 packed.append('\x00' * 4)
393 packed.append(struct.pack("!Q", self.metadata))
394 packed.append(struct.pack("!Q", self.metadata_mask))
395 length = sum([len(x) for x in packed])
396 packed[1] = struct.pack("!H", length)
397 return ''.join(packed)
398
399 @staticmethod
400 def unpack(reader):
401 obj = write_metadata()
402 _type = reader.read("!H")[0]
403 assert(_type == 2)
404 _len = reader.read("!H")[0]
405 orig_reader = reader
406 reader = orig_reader.slice(_len - (2 + 2))
407 reader.skip(4)
408 obj.metadata = reader.read("!Q")[0]
409 obj.metadata_mask = reader.read("!Q")[0]
410 return obj
411
412 def __eq__(self, other):
413 if type(self) != type(other): return False
414 if self.metadata != other.metadata: return False
415 if self.metadata_mask != other.metadata_mask: return False
416 return True
417
418 def pretty_print(self, q):
419 q.text("write_metadata {")
420 with q.group():
421 with q.indent(2):
422 q.breakable()
423 q.text("metadata = ");
424 q.text("%#x" % self.metadata)
425 q.text(","); q.breakable()
426 q.text("metadata_mask = ");
427 q.text("%#x" % self.metadata_mask)
428 q.breakable()
429 q.text('}')
430
431instruction.subtypes[2] = write_metadata
432
433