blob: adb6543219d3089368afc07604ef3263ad4ada56 [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 Lane1b75abf2014-02-05 11:23:20 -0800286class bsn_dhcp_offload(bsn):
287 type = 65535
288 experimenter = 6035143
289 subtype = 2
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
306 def unpack(reader):
307 obj = bsn_dhcp_offload()
308 _type = reader.read("!H")[0]
309 assert(_type == 65535)
310 _len = reader.read("!H")[0]
311 orig_reader = reader
312 reader = orig_reader.slice(_len - (2 + 2))
313 _experimenter = reader.read("!L")[0]
314 assert(_experimenter == 6035143)
315 _subtype = reader.read("!L")[0]
316 assert(_subtype == 2)
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
324 def pretty_print(self, q):
325 q.text("bsn_dhcp_offload {")
326 with q.group():
327 with q.indent(2):
328 q.breakable()
329 q.breakable()
330 q.text('}')
331
332bsn.subtypes[2] = bsn_dhcp_offload
333
Rich Lane7dcdf022013-12-11 14:45:27 -0800334class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800335 type = 65535
336 experimenter = 6035143
337 subtype = 0
338
339 def __init__(self):
340 return
341
342 def pack(self):
343 packed = []
344 packed.append(struct.pack("!H", self.type))
345 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
346 packed.append(struct.pack("!L", self.experimenter))
347 packed.append(struct.pack("!L", self.subtype))
348 packed.append('\x00' * 4)
349 length = sum([len(x) for x in packed])
350 packed[1] = struct.pack("!H", length)
351 return ''.join(packed)
352
353 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800354 def unpack(reader):
Rich Lane7b0f2012013-11-22 14:15:26 -0800355 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800356 _type = reader.read("!H")[0]
357 assert(_type == 65535)
358 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800359 orig_reader = reader
360 reader = orig_reader.slice(_len - (2 + 2))
Rich Lane7b0f2012013-11-22 14:15:26 -0800361 _experimenter = reader.read("!L")[0]
362 assert(_experimenter == 6035143)
363 _subtype = reader.read("!L")[0]
364 assert(_subtype == 0)
365 reader.skip(4)
366 return obj
367
368 def __eq__(self, other):
369 if type(self) != type(other): return False
370 return True
371
Rich Lane7b0f2012013-11-22 14:15:26 -0800372 def pretty_print(self, q):
373 q.text("bsn_disable_src_mac_check {")
374 with q.group():
375 with q.indent(2):
376 q.breakable()
377 q.breakable()
378 q.text('}')
379
Rich Lane7dcdf022013-12-11 14:45:27 -0800380bsn.subtypes[0] = bsn_disable_src_mac_check
381
382class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700383 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700384
385 def __init__(self):
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 length = sum([len(x) for x in packed])
394 packed[1] = struct.pack("!H", length)
395 return ''.join(packed)
396
397 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800398 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700399 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700400 _type = reader.read("!H")[0]
401 assert(_type == 5)
402 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800403 orig_reader = reader
404 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700405 reader.skip(4)
406 return obj
407
408 def __eq__(self, other):
409 if type(self) != type(other): return False
410 return True
411
Rich Laneca3da272013-05-05 09:07:33 -0700412 def pretty_print(self, q):
413 q.text("clear_actions {")
414 with q.group():
415 with q.indent(2):
416 q.breakable()
417 q.breakable()
418 q.text('}')
419
Rich Lane7dcdf022013-12-11 14:45:27 -0800420instruction.subtypes[5] = clear_actions
421
422class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700423 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700424
425 def __init__(self, table_id=None):
426 if table_id != None:
427 self.table_id = table_id
428 else:
429 self.table_id = 0
430 return
431
432 def pack(self):
433 packed = []
434 packed.append(struct.pack("!H", self.type))
435 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
436 packed.append(struct.pack("!B", self.table_id))
437 packed.append('\x00' * 3)
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 = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700445 _type = reader.read("!H")[0]
446 assert(_type == 1)
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.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700451 reader.skip(3)
452 return obj
453
454 def __eq__(self, other):
455 if type(self) != type(other): return False
456 if self.table_id != other.table_id: return False
457 return True
458
Rich Laneca3da272013-05-05 09:07:33 -0700459 def pretty_print(self, q):
460 q.text("goto_table {")
461 with q.group():
462 with q.indent(2):
463 q.breakable()
464 q.text("table_id = ");
465 q.text("%#x" % self.table_id)
466 q.breakable()
467 q.text('}')
468
Rich Lane7dcdf022013-12-11 14:45:27 -0800469instruction.subtypes[1] = goto_table
470
471class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700472 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700473
474 def __init__(self, meter_id=None):
475 if meter_id != None:
476 self.meter_id = meter_id
477 else:
478 self.meter_id = 0
479 return
480
481 def pack(self):
482 packed = []
483 packed.append(struct.pack("!H", self.type))
484 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
485 packed.append(struct.pack("!L", self.meter_id))
486 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 = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700493 _type = reader.read("!H")[0]
494 assert(_type == 6)
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))
Dan Talaycof6202252013-07-02 01:00:29 -0700498 obj.meter_id = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700499 return obj
500
501 def __eq__(self, other):
502 if type(self) != type(other): return False
503 if self.meter_id != other.meter_id: return False
504 return True
505
Rich Laneca3da272013-05-05 09:07:33 -0700506 def pretty_print(self, q):
507 q.text("meter {")
508 with q.group():
509 with q.indent(2):
510 q.breakable()
511 q.text("meter_id = ");
512 q.text("%#x" % self.meter_id)
513 q.breakable()
514 q.text('}')
515
Rich Lane7dcdf022013-12-11 14:45:27 -0800516instruction.subtypes[6] = meter
517
518class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700519 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700520
521 def __init__(self, actions=None):
522 if actions != None:
523 self.actions = actions
524 else:
525 self.actions = []
526 return
527
528 def pack(self):
529 packed = []
530 packed.append(struct.pack("!H", self.type))
531 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
532 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800533 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700534 length = sum([len(x) for x in packed])
535 packed[1] = struct.pack("!H", length)
536 return ''.join(packed)
537
538 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800539 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700540 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700541 _type = reader.read("!H")[0]
542 assert(_type == 3)
543 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800544 orig_reader = reader
545 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700546 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800547 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700548 return obj
549
550 def __eq__(self, other):
551 if type(self) != type(other): return False
552 if self.actions != other.actions: return False
553 return True
554
Rich Laneca3da272013-05-05 09:07:33 -0700555 def pretty_print(self, q):
556 q.text("write_actions {")
557 with q.group():
558 with q.indent(2):
559 q.breakable()
560 q.text("actions = ");
561 q.pp(self.actions)
562 q.breakable()
563 q.text('}')
564
Rich Lane7dcdf022013-12-11 14:45:27 -0800565instruction.subtypes[3] = write_actions
566
567class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700568 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700569
570 def __init__(self, metadata=None, metadata_mask=None):
571 if metadata != None:
572 self.metadata = metadata
573 else:
574 self.metadata = 0
575 if metadata_mask != None:
576 self.metadata_mask = metadata_mask
577 else:
578 self.metadata_mask = 0
579 return
580
581 def pack(self):
582 packed = []
583 packed.append(struct.pack("!H", self.type))
584 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
585 packed.append('\x00' * 4)
586 packed.append(struct.pack("!Q", self.metadata))
587 packed.append(struct.pack("!Q", self.metadata_mask))
588 length = sum([len(x) for x in packed])
589 packed[1] = struct.pack("!H", length)
590 return ''.join(packed)
591
592 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800593 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700594 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700595 _type = reader.read("!H")[0]
596 assert(_type == 2)
597 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800598 orig_reader = reader
599 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700600 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700601 obj.metadata = reader.read("!Q")[0]
602 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700603 return obj
604
605 def __eq__(self, other):
606 if type(self) != type(other): return False
607 if self.metadata != other.metadata: return False
608 if self.metadata_mask != other.metadata_mask: return False
609 return True
610
Rich Laneca3da272013-05-05 09:07:33 -0700611 def pretty_print(self, q):
612 q.text("write_metadata {")
613 with q.group():
614 with q.indent(2):
615 q.breakable()
616 q.text("metadata = ");
617 q.text("%#x" % self.metadata)
618 q.text(","); q.breakable()
619 q.text("metadata_mask = ");
620 q.text("%#x" % self.metadata_mask)
621 q.breakable()
622 q.text('}')
623
Rich Lane7dcdf022013-12-11 14:45:27 -0800624instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700625
Rich Lane7b0f2012013-11-22 14:15:26 -0800626