blob: 5d36bda5de98d85d7030c02d433ac736e5162bb5 [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.
Dan Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneca3da272013-05-05 09:07:33 -07005
Rich Lane7dcdf022013-12-11 14:45:27 -08006# Automatically generated by LOXI from template module.py
Rich Laneca3da272013-05-05 09:07:33 -07007# Do not modify
8
9import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Laneca3da272013-05-05 09:07:33 -070011import const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
14import instruction
15import oxm
16import action_id
17import instruction_id
18import meter_band
Rich Lane5454b682014-01-14 17:07:36 -080019import bsn_tlv
Rich Laneca3da272013-05-05 09:07:33 -070020import util
21import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070022
Rich Lane7dcdf022013-12-11 14:45:27 -080023class instruction(loxi.OFObject):
24 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070025
Rich Lane95f7fc92014-01-27 17:08:16 -080026
27 def __init__(self, type=None):
28 if type != None:
29 self.type = type
30 else:
31 self.type = 0
32 return
33
34 def pack(self):
35 packed = []
36 packed.append(struct.pack("!H", self.type))
37 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
38 length = sum([len(x) for x in packed])
39 packed[1] = struct.pack("!H", length)
40 return ''.join(packed)
41
Rich Lane7dcdf022013-12-11 14:45:27 -080042 @staticmethod
43 def unpack(reader):
44 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080045 subclass = instruction.subtypes.get(subtype)
46 if subclass:
47 return subclass.unpack(reader)
48
49 obj = instruction()
50 obj.type = reader.read("!H")[0]
51 _len = reader.read("!H")[0]
52 orig_reader = reader
53 reader = orig_reader.slice(_len - (2 + 2))
54 return obj
55
56 def __eq__(self, other):
57 if type(self) != type(other): return False
58 if self.type != other.type: return False
59 return True
60
61 def pretty_print(self, q):
62 q.text("instruction {")
63 with q.group():
64 with q.indent(2):
65 q.breakable()
66 q.breakable()
67 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070068
Rich Lane7dcdf022013-12-11 14:45:27 -080069
70class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070071 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070072
73 def __init__(self, actions=None):
74 if actions != None:
75 self.actions = actions
76 else:
77 self.actions = []
78 return
79
80 def pack(self):
81 packed = []
82 packed.append(struct.pack("!H", self.type))
83 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
84 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080085 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070086 length = sum([len(x) for x in packed])
87 packed[1] = struct.pack("!H", length)
88 return ''.join(packed)
89
90 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080091 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070092 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070093 _type = reader.read("!H")[0]
94 assert(_type == 4)
95 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080096 orig_reader = reader
97 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070098 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080099 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700100 return obj
101
102 def __eq__(self, other):
103 if type(self) != type(other): return False
104 if self.actions != other.actions: return False
105 return True
106
Rich Laneca3da272013-05-05 09:07:33 -0700107 def pretty_print(self, q):
108 q.text("apply_actions {")
109 with q.group():
110 with q.indent(2):
111 q.breakable()
112 q.text("actions = ");
113 q.pp(self.actions)
114 q.breakable()
115 q.text('}')
116
Rich Lane7dcdf022013-12-11 14:45:27 -0800117instruction.subtypes[4] = apply_actions
118
119class experimenter(instruction):
120 subtypes = {}
121
Rich Lane95f7fc92014-01-27 17:08:16 -0800122 type = 65535
123
124 def __init__(self, experimenter=None, data=None):
125 if experimenter != None:
126 self.experimenter = experimenter
127 else:
128 self.experimenter = 0
129 if data != None:
130 self.data = data
131 else:
132 self.data = ''
133 return
134
135 def pack(self):
136 packed = []
137 packed.append(struct.pack("!H", self.type))
138 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
139 packed.append(struct.pack("!L", self.experimenter))
140 packed.append(self.data)
141 length = sum([len(x) for x in packed])
142 packed[1] = struct.pack("!H", length)
143 return ''.join(packed)
144
Rich Lane7dcdf022013-12-11 14:45:27 -0800145 @staticmethod
146 def unpack(reader):
147 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800148 subclass = experimenter.subtypes.get(subtype)
149 if subclass:
150 return subclass.unpack(reader)
151
152 obj = experimenter()
153 _type = reader.read("!H")[0]
154 assert(_type == 65535)
155 _len = reader.read("!H")[0]
156 orig_reader = reader
157 reader = orig_reader.slice(_len - (2 + 2))
158 obj.experimenter = reader.read("!L")[0]
159 obj.data = str(reader.read_all())
160 return obj
161
162 def __eq__(self, other):
163 if type(self) != type(other): return False
164 if self.experimenter != other.experimenter: return False
165 if self.data != other.data: return False
166 return True
167
168 def pretty_print(self, q):
169 q.text("experimenter {")
170 with q.group():
171 with q.indent(2):
172 q.breakable()
173 q.text("data = ");
174 q.pp(self.data)
175 q.breakable()
176 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800177
178instruction.subtypes[65535] = experimenter
179
180class bsn(experimenter):
181 subtypes = {}
182
Rich Lane95f7fc92014-01-27 17:08:16 -0800183 type = 65535
184 experimenter = 6035143
185
186 def __init__(self, subtype=None):
187 if subtype != None:
188 self.subtype = subtype
189 else:
190 self.subtype = 0
191 return
192
193 def pack(self):
194 packed = []
195 packed.append(struct.pack("!H", self.type))
196 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
197 packed.append(struct.pack("!L", self.experimenter))
198 packed.append(struct.pack("!L", self.subtype))
199 packed.append('\x00' * 4)
200 length = sum([len(x) for x in packed])
201 packed[1] = struct.pack("!H", length)
202 return ''.join(packed)
203
Rich Lane7dcdf022013-12-11 14:45:27 -0800204 @staticmethod
205 def unpack(reader):
206 subtype, = reader.peek('!L', 8)
Rich Lane95f7fc92014-01-27 17:08:16 -0800207 subclass = bsn.subtypes.get(subtype)
208 if subclass:
209 return subclass.unpack(reader)
210
211 obj = bsn()
212 _type = reader.read("!H")[0]
213 assert(_type == 65535)
214 _len = reader.read("!H")[0]
215 orig_reader = reader
216 reader = orig_reader.slice(_len - (2 + 2))
217 _experimenter = reader.read("!L")[0]
218 assert(_experimenter == 6035143)
219 obj.subtype = reader.read("!L")[0]
220 reader.skip(4)
221 return obj
222
223 def __eq__(self, other):
224 if type(self) != type(other): return False
225 if self.subtype != other.subtype: return False
226 return True
227
228 def pretty_print(self, q):
229 q.text("bsn {")
230 with q.group():
231 with q.indent(2):
232 q.breakable()
233 q.breakable()
234 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800235
236experimenter.subtypes[6035143] = bsn
237
Rich Lane5454b682014-01-14 17:07:36 -0800238class bsn_arp_offload(bsn):
239 type = 65535
240 experimenter = 6035143
241 subtype = 1
242
243 def __init__(self):
244 return
245
246 def pack(self):
247 packed = []
248 packed.append(struct.pack("!H", self.type))
249 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
250 packed.append(struct.pack("!L", self.experimenter))
251 packed.append(struct.pack("!L", self.subtype))
252 packed.append('\x00' * 4)
253 length = sum([len(x) for x in packed])
254 packed[1] = struct.pack("!H", length)
255 return ''.join(packed)
256
257 @staticmethod
258 def unpack(reader):
259 obj = bsn_arp_offload()
260 _type = reader.read("!H")[0]
261 assert(_type == 65535)
262 _len = reader.read("!H")[0]
263 orig_reader = reader
264 reader = orig_reader.slice(_len - (2 + 2))
265 _experimenter = reader.read("!L")[0]
266 assert(_experimenter == 6035143)
267 _subtype = reader.read("!L")[0]
268 assert(_subtype == 1)
269 reader.skip(4)
270 return obj
271
272 def __eq__(self, other):
273 if type(self) != type(other): return False
274 return True
275
276 def pretty_print(self, q):
277 q.text("bsn_arp_offload {")
278 with q.group():
279 with q.indent(2):
280 q.breakable()
281 q.breakable()
282 q.text('}')
283
284bsn.subtypes[1] = bsn_arp_offload
285
Rich Lane7dcdf022013-12-11 14:45:27 -0800286class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800287 type = 65535
288 experimenter = 6035143
289 subtype = 0
290
291 def __init__(self):
292 return
293
294 def pack(self):
295 packed = []
296 packed.append(struct.pack("!H", self.type))
297 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
298 packed.append(struct.pack("!L", self.experimenter))
299 packed.append(struct.pack("!L", self.subtype))
300 packed.append('\x00' * 4)
301 length = sum([len(x) for x in packed])
302 packed[1] = struct.pack("!H", length)
303 return ''.join(packed)
304
305 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800306 def unpack(reader):
Rich Lane7b0f2012013-11-22 14:15:26 -0800307 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800308 _type = reader.read("!H")[0]
309 assert(_type == 65535)
310 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800311 orig_reader = reader
312 reader = orig_reader.slice(_len - (2 + 2))
Rich Lane7b0f2012013-11-22 14:15:26 -0800313 _experimenter = reader.read("!L")[0]
314 assert(_experimenter == 6035143)
315 _subtype = reader.read("!L")[0]
316 assert(_subtype == 0)
317 reader.skip(4)
318 return obj
319
320 def __eq__(self, other):
321 if type(self) != type(other): return False
322 return True
323
Rich Lane7b0f2012013-11-22 14:15:26 -0800324 def pretty_print(self, q):
325 q.text("bsn_disable_src_mac_check {")
326 with q.group():
327 with q.indent(2):
328 q.breakable()
329 q.breakable()
330 q.text('}')
331
Rich Lane7dcdf022013-12-11 14:45:27 -0800332bsn.subtypes[0] = bsn_disable_src_mac_check
333
334class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700335 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700336
337 def __init__(self):
338 return
339
340 def pack(self):
341 packed = []
342 packed.append(struct.pack("!H", self.type))
343 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
344 packed.append('\x00' * 4)
345 length = sum([len(x) for x in packed])
346 packed[1] = struct.pack("!H", length)
347 return ''.join(packed)
348
349 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800350 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700351 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700352 _type = reader.read("!H")[0]
353 assert(_type == 5)
354 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800355 orig_reader = reader
356 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700357 reader.skip(4)
358 return obj
359
360 def __eq__(self, other):
361 if type(self) != type(other): return False
362 return True
363
Rich Laneca3da272013-05-05 09:07:33 -0700364 def pretty_print(self, q):
365 q.text("clear_actions {")
366 with q.group():
367 with q.indent(2):
368 q.breakable()
369 q.breakable()
370 q.text('}')
371
Rich Lane7dcdf022013-12-11 14:45:27 -0800372instruction.subtypes[5] = clear_actions
373
374class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700375 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700376
377 def __init__(self, table_id=None):
378 if table_id != None:
379 self.table_id = table_id
380 else:
381 self.table_id = 0
382 return
383
384 def pack(self):
385 packed = []
386 packed.append(struct.pack("!H", self.type))
387 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
388 packed.append(struct.pack("!B", self.table_id))
389 packed.append('\x00' * 3)
390 length = sum([len(x) for x in packed])
391 packed[1] = struct.pack("!H", length)
392 return ''.join(packed)
393
394 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800395 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700396 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700397 _type = reader.read("!H")[0]
398 assert(_type == 1)
399 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800400 orig_reader = reader
401 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700402 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700403 reader.skip(3)
404 return obj
405
406 def __eq__(self, other):
407 if type(self) != type(other): return False
408 if self.table_id != other.table_id: return False
409 return True
410
Rich Laneca3da272013-05-05 09:07:33 -0700411 def pretty_print(self, q):
412 q.text("goto_table {")
413 with q.group():
414 with q.indent(2):
415 q.breakable()
416 q.text("table_id = ");
417 q.text("%#x" % self.table_id)
418 q.breakable()
419 q.text('}')
420
Rich Lane7dcdf022013-12-11 14:45:27 -0800421instruction.subtypes[1] = goto_table
422
423class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700424 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700425
426 def __init__(self, meter_id=None):
427 if meter_id != None:
428 self.meter_id = meter_id
429 else:
430 self.meter_id = 0
431 return
432
433 def pack(self):
434 packed = []
435 packed.append(struct.pack("!H", self.type))
436 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
437 packed.append(struct.pack("!L", self.meter_id))
438 length = sum([len(x) for x in packed])
439 packed[1] = struct.pack("!H", length)
440 return ''.join(packed)
441
442 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800443 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700444 obj = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700445 _type = reader.read("!H")[0]
446 assert(_type == 6)
447 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800448 orig_reader = reader
449 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700450 obj.meter_id = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700451 return obj
452
453 def __eq__(self, other):
454 if type(self) != type(other): return False
455 if self.meter_id != other.meter_id: return False
456 return True
457
Rich Laneca3da272013-05-05 09:07:33 -0700458 def pretty_print(self, q):
459 q.text("meter {")
460 with q.group():
461 with q.indent(2):
462 q.breakable()
463 q.text("meter_id = ");
464 q.text("%#x" % self.meter_id)
465 q.breakable()
466 q.text('}')
467
Rich Lane7dcdf022013-12-11 14:45:27 -0800468instruction.subtypes[6] = meter
469
470class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700471 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700472
473 def __init__(self, actions=None):
474 if actions != None:
475 self.actions = actions
476 else:
477 self.actions = []
478 return
479
480 def pack(self):
481 packed = []
482 packed.append(struct.pack("!H", self.type))
483 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
484 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800485 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700486 length = sum([len(x) for x in packed])
487 packed[1] = struct.pack("!H", length)
488 return ''.join(packed)
489
490 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800491 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700492 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700493 _type = reader.read("!H")[0]
494 assert(_type == 3)
495 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800496 orig_reader = reader
497 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700498 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800499 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700500 return obj
501
502 def __eq__(self, other):
503 if type(self) != type(other): return False
504 if self.actions != other.actions: return False
505 return True
506
Rich Laneca3da272013-05-05 09:07:33 -0700507 def pretty_print(self, q):
508 q.text("write_actions {")
509 with q.group():
510 with q.indent(2):
511 q.breakable()
512 q.text("actions = ");
513 q.pp(self.actions)
514 q.breakable()
515 q.text('}')
516
Rich Lane7dcdf022013-12-11 14:45:27 -0800517instruction.subtypes[3] = write_actions
518
519class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700520 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700521
522 def __init__(self, metadata=None, metadata_mask=None):
523 if metadata != None:
524 self.metadata = metadata
525 else:
526 self.metadata = 0
527 if metadata_mask != None:
528 self.metadata_mask = metadata_mask
529 else:
530 self.metadata_mask = 0
531 return
532
533 def pack(self):
534 packed = []
535 packed.append(struct.pack("!H", self.type))
536 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
537 packed.append('\x00' * 4)
538 packed.append(struct.pack("!Q", self.metadata))
539 packed.append(struct.pack("!Q", self.metadata_mask))
540 length = sum([len(x) for x in packed])
541 packed[1] = struct.pack("!H", length)
542 return ''.join(packed)
543
544 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800545 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700546 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700547 _type = reader.read("!H")[0]
548 assert(_type == 2)
549 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800550 orig_reader = reader
551 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700552 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700553 obj.metadata = reader.read("!Q")[0]
554 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700555 return obj
556
557 def __eq__(self, other):
558 if type(self) != type(other): return False
559 if self.metadata != other.metadata: return False
560 if self.metadata_mask != other.metadata_mask: return False
561 return True
562
Rich Laneca3da272013-05-05 09:07:33 -0700563 def pretty_print(self, q):
564 q.text("write_metadata {")
565 with q.group():
566 with q.indent(2):
567 q.breakable()
568 q.text("metadata = ");
569 q.text("%#x" % self.metadata)
570 q.text(","); q.breakable()
571 q.text("metadata_mask = ");
572 q.text("%#x" % self.metadata_mask)
573 q.breakable()
574 q.text('}')
575
Rich Lane7dcdf022013-12-11 14:45:27 -0800576instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700577
Rich Lane7b0f2012013-11-22 14:15:26 -0800578