blob: e9c03dd2b7f7621006fd134fc098982f77e6e060 [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 Lane9ec3fca2014-02-26 16:22:56 -0800286class bsn_deny(bsn):
287 type = 65535
288 experimenter = 6035143
289 subtype = 5
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_deny()
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 == 5)
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_deny {")
326 with q.group():
327 with q.indent(2):
328 q.breakable()
329 q.breakable()
330 q.text('}')
331
332bsn.subtypes[5] = bsn_deny
333
Rich Lane1b75abf2014-02-05 11:23:20 -0800334class bsn_dhcp_offload(bsn):
335 type = 65535
336 experimenter = 6035143
337 subtype = 2
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
354 def unpack(reader):
355 obj = bsn_dhcp_offload()
356 _type = reader.read("!H")[0]
357 assert(_type == 65535)
358 _len = reader.read("!H")[0]
359 orig_reader = reader
360 reader = orig_reader.slice(_len - (2 + 2))
361 _experimenter = reader.read("!L")[0]
362 assert(_experimenter == 6035143)
363 _subtype = reader.read("!L")[0]
364 assert(_subtype == 2)
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
372 def pretty_print(self, q):
373 q.text("bsn_dhcp_offload {")
374 with q.group():
375 with q.indent(2):
376 q.breakable()
377 q.breakable()
378 q.text('}')
379
380bsn.subtypes[2] = bsn_dhcp_offload
381
Rich Lane9ec3fca2014-02-26 16:22:56 -0800382class bsn_disable_split_horizon_check(bsn):
383 type = 65535
384 experimenter = 6035143
385 subtype = 3
386
387 def __init__(self):
388 return
389
390 def pack(self):
391 packed = []
392 packed.append(struct.pack("!H", self.type))
393 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
394 packed.append(struct.pack("!L", self.experimenter))
395 packed.append(struct.pack("!L", self.subtype))
396 packed.append('\x00' * 4)
397 length = sum([len(x) for x in packed])
398 packed[1] = struct.pack("!H", length)
399 return ''.join(packed)
400
401 @staticmethod
402 def unpack(reader):
403 obj = bsn_disable_split_horizon_check()
404 _type = reader.read("!H")[0]
405 assert(_type == 65535)
406 _len = reader.read("!H")[0]
407 orig_reader = reader
408 reader = orig_reader.slice(_len - (2 + 2))
409 _experimenter = reader.read("!L")[0]
410 assert(_experimenter == 6035143)
411 _subtype = reader.read("!L")[0]
412 assert(_subtype == 3)
413 reader.skip(4)
414 return obj
415
416 def __eq__(self, other):
417 if type(self) != type(other): return False
418 return True
419
420 def pretty_print(self, q):
421 q.text("bsn_disable_split_horizon_check {")
422 with q.group():
423 with q.indent(2):
424 q.breakable()
425 q.breakable()
426 q.text('}')
427
428bsn.subtypes[3] = bsn_disable_split_horizon_check
429
Rich Lane7dcdf022013-12-11 14:45:27 -0800430class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800431 type = 65535
432 experimenter = 6035143
433 subtype = 0
434
435 def __init__(self):
436 return
437
438 def pack(self):
439 packed = []
440 packed.append(struct.pack("!H", self.type))
441 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
442 packed.append(struct.pack("!L", self.experimenter))
443 packed.append(struct.pack("!L", self.subtype))
444 packed.append('\x00' * 4)
445 length = sum([len(x) for x in packed])
446 packed[1] = struct.pack("!H", length)
447 return ''.join(packed)
448
449 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800450 def unpack(reader):
Rich Lane7b0f2012013-11-22 14:15:26 -0800451 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800452 _type = reader.read("!H")[0]
453 assert(_type == 65535)
454 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800455 orig_reader = reader
456 reader = orig_reader.slice(_len - (2 + 2))
Rich Lane7b0f2012013-11-22 14:15:26 -0800457 _experimenter = reader.read("!L")[0]
458 assert(_experimenter == 6035143)
459 _subtype = reader.read("!L")[0]
460 assert(_subtype == 0)
461 reader.skip(4)
462 return obj
463
464 def __eq__(self, other):
465 if type(self) != type(other): return False
466 return True
467
Rich Lane7b0f2012013-11-22 14:15:26 -0800468 def pretty_print(self, q):
469 q.text("bsn_disable_src_mac_check {")
470 with q.group():
471 with q.indent(2):
472 q.breakable()
473 q.breakable()
474 q.text('}')
475
Rich Lane7dcdf022013-12-11 14:45:27 -0800476bsn.subtypes[0] = bsn_disable_src_mac_check
477
Rich Lane9ec3fca2014-02-26 16:22:56 -0800478class bsn_permit(bsn):
479 type = 65535
480 experimenter = 6035143
481 subtype = 4
482
483 def __init__(self):
484 return
485
486 def pack(self):
487 packed = []
488 packed.append(struct.pack("!H", self.type))
489 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
490 packed.append(struct.pack("!L", self.experimenter))
491 packed.append(struct.pack("!L", self.subtype))
492 packed.append('\x00' * 4)
493 length = sum([len(x) for x in packed])
494 packed[1] = struct.pack("!H", length)
495 return ''.join(packed)
496
497 @staticmethod
498 def unpack(reader):
499 obj = bsn_permit()
500 _type = reader.read("!H")[0]
501 assert(_type == 65535)
502 _len = reader.read("!H")[0]
503 orig_reader = reader
504 reader = orig_reader.slice(_len - (2 + 2))
505 _experimenter = reader.read("!L")[0]
506 assert(_experimenter == 6035143)
507 _subtype = reader.read("!L")[0]
508 assert(_subtype == 4)
509 reader.skip(4)
510 return obj
511
512 def __eq__(self, other):
513 if type(self) != type(other): return False
514 return True
515
516 def pretty_print(self, q):
517 q.text("bsn_permit {")
518 with q.group():
519 with q.indent(2):
520 q.breakable()
521 q.breakable()
522 q.text('}')
523
524bsn.subtypes[4] = bsn_permit
525
Rich Lane7dcdf022013-12-11 14:45:27 -0800526class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700527 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700528
529 def __init__(self):
530 return
531
532 def pack(self):
533 packed = []
534 packed.append(struct.pack("!H", self.type))
535 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
536 packed.append('\x00' * 4)
537 length = sum([len(x) for x in packed])
538 packed[1] = struct.pack("!H", length)
539 return ''.join(packed)
540
541 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800542 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700543 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700544 _type = reader.read("!H")[0]
545 assert(_type == 5)
546 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800547 orig_reader = reader
548 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700549 reader.skip(4)
550 return obj
551
552 def __eq__(self, other):
553 if type(self) != type(other): return False
554 return True
555
Rich Laneca3da272013-05-05 09:07:33 -0700556 def pretty_print(self, q):
557 q.text("clear_actions {")
558 with q.group():
559 with q.indent(2):
560 q.breakable()
561 q.breakable()
562 q.text('}')
563
Rich Lane7dcdf022013-12-11 14:45:27 -0800564instruction.subtypes[5] = clear_actions
565
566class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700567 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700568
569 def __init__(self, table_id=None):
570 if table_id != None:
571 self.table_id = table_id
572 else:
573 self.table_id = 0
574 return
575
576 def pack(self):
577 packed = []
578 packed.append(struct.pack("!H", self.type))
579 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
580 packed.append(struct.pack("!B", self.table_id))
581 packed.append('\x00' * 3)
582 length = sum([len(x) for x in packed])
583 packed[1] = struct.pack("!H", length)
584 return ''.join(packed)
585
586 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800587 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700588 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700589 _type = reader.read("!H")[0]
590 assert(_type == 1)
591 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800592 orig_reader = reader
593 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700594 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700595 reader.skip(3)
596 return obj
597
598 def __eq__(self, other):
599 if type(self) != type(other): return False
600 if self.table_id != other.table_id: return False
601 return True
602
Rich Laneca3da272013-05-05 09:07:33 -0700603 def pretty_print(self, q):
604 q.text("goto_table {")
605 with q.group():
606 with q.indent(2):
607 q.breakable()
608 q.text("table_id = ");
609 q.text("%#x" % self.table_id)
610 q.breakable()
611 q.text('}')
612
Rich Lane7dcdf022013-12-11 14:45:27 -0800613instruction.subtypes[1] = goto_table
614
615class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700616 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700617
618 def __init__(self, meter_id=None):
619 if meter_id != None:
620 self.meter_id = meter_id
621 else:
622 self.meter_id = 0
623 return
624
625 def pack(self):
626 packed = []
627 packed.append(struct.pack("!H", self.type))
628 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
629 packed.append(struct.pack("!L", self.meter_id))
630 length = sum([len(x) for x in packed])
631 packed[1] = struct.pack("!H", length)
632 return ''.join(packed)
633
634 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800635 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700636 obj = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700637 _type = reader.read("!H")[0]
638 assert(_type == 6)
639 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800640 orig_reader = reader
641 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700642 obj.meter_id = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700643 return obj
644
645 def __eq__(self, other):
646 if type(self) != type(other): return False
647 if self.meter_id != other.meter_id: return False
648 return True
649
Rich Laneca3da272013-05-05 09:07:33 -0700650 def pretty_print(self, q):
651 q.text("meter {")
652 with q.group():
653 with q.indent(2):
654 q.breakable()
655 q.text("meter_id = ");
656 q.text("%#x" % self.meter_id)
657 q.breakable()
658 q.text('}')
659
Rich Lane7dcdf022013-12-11 14:45:27 -0800660instruction.subtypes[6] = meter
661
662class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700663 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700664
665 def __init__(self, actions=None):
666 if actions != None:
667 self.actions = actions
668 else:
669 self.actions = []
670 return
671
672 def pack(self):
673 packed = []
674 packed.append(struct.pack("!H", self.type))
675 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
676 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800677 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700678 length = sum([len(x) for x in packed])
679 packed[1] = struct.pack("!H", length)
680 return ''.join(packed)
681
682 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800683 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700684 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700685 _type = reader.read("!H")[0]
686 assert(_type == 3)
687 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800688 orig_reader = reader
689 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700690 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800691 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700692 return obj
693
694 def __eq__(self, other):
695 if type(self) != type(other): return False
696 if self.actions != other.actions: return False
697 return True
698
Rich Laneca3da272013-05-05 09:07:33 -0700699 def pretty_print(self, q):
700 q.text("write_actions {")
701 with q.group():
702 with q.indent(2):
703 q.breakable()
704 q.text("actions = ");
705 q.pp(self.actions)
706 q.breakable()
707 q.text('}')
708
Rich Lane7dcdf022013-12-11 14:45:27 -0800709instruction.subtypes[3] = write_actions
710
711class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700712 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700713
714 def __init__(self, metadata=None, metadata_mask=None):
715 if metadata != None:
716 self.metadata = metadata
717 else:
718 self.metadata = 0
719 if metadata_mask != None:
720 self.metadata_mask = metadata_mask
721 else:
722 self.metadata_mask = 0
723 return
724
725 def pack(self):
726 packed = []
727 packed.append(struct.pack("!H", self.type))
728 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
729 packed.append('\x00' * 4)
730 packed.append(struct.pack("!Q", self.metadata))
731 packed.append(struct.pack("!Q", self.metadata_mask))
732 length = sum([len(x) for x in packed])
733 packed[1] = struct.pack("!H", length)
734 return ''.join(packed)
735
736 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800737 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700738 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700739 _type = reader.read("!H")[0]
740 assert(_type == 2)
741 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800742 orig_reader = reader
743 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700744 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700745 obj.metadata = reader.read("!Q")[0]
746 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700747 return obj
748
749 def __eq__(self, other):
750 if type(self) != type(other): return False
751 if self.metadata != other.metadata: return False
752 if self.metadata_mask != other.metadata_mask: return False
753 return True
754
Rich Laneca3da272013-05-05 09:07:33 -0700755 def pretty_print(self, q):
756 q.text("write_metadata {")
757 with q.group():
758 with q.indent(2):
759 q.breakable()
760 q.text("metadata = ");
761 q.text("%#x" % self.metadata)
762 q.text(","); q.breakable()
763 q.text("metadata_mask = ");
764 q.text("%#x" % self.metadata_mask)
765 q.breakable()
766 q.text('}')
767
Rich Lane7dcdf022013-12-11 14:45:27 -0800768instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700769
Rich Lane7b0f2012013-11-22 14:15:26 -0800770