blob: 8775b88835fa2cbea8dc7fc712172b8d6a817916 [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -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
5# Automatically generated by LOXI from template action.py
6# Do not modify
7
8import struct
9import const
10import util
11import loxi.generic_util
12import loxi
13
14def unpack_list(reader):
15 def deserializer(reader, typ):
16 parser = parsers.get(typ)
17 if not parser: raise loxi.ProtocolError("unknown action type %d" % typ)
18 return parser(reader)
19 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
20
21class Action(object):
22 type = None # override in subclass
23 pass
24
25class bsn_mirror(Action):
26 type = const.OFPAT_EXPERIMENTER
27 experimenter = 0x5c16c7
28 subtype = 1
29
30 def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None):
31 if dest_port != None:
32 self.dest_port = dest_port
33 else:
34 self.dest_port = 0
35 if vlan_tag != None:
36 self.vlan_tag = vlan_tag
37 else:
38 self.vlan_tag = 0
39 if copy_stage != None:
40 self.copy_stage = copy_stage
41 else:
42 self.copy_stage = 0
43 return
44
45 def pack(self):
46 packed = []
47 packed.append(struct.pack("!H", self.type))
48 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
49 packed.append(struct.pack("!L", self.experimenter))
50 packed.append(struct.pack("!L", self.subtype))
51 packed.append(struct.pack("!L", self.dest_port))
52 packed.append(struct.pack("!L", self.vlan_tag))
53 packed.append(struct.pack("!B", self.copy_stage))
54 packed.append('\x00' * 3)
55 length = sum([len(x) for x in packed])
56 packed[1] = struct.pack("!H", length)
57 return ''.join(packed)
58
59 @staticmethod
60 def unpack(buf):
61 obj = bsn_mirror()
62 if type(buf) == loxi.generic_util.OFReader:
63 reader = buf
64 else:
65 reader = loxi.generic_util.OFReader(buf)
66 _type = reader.read('!H')[0]
67 assert(_type == const.OFPAT_EXPERIMENTER)
68 _len = reader.read('!H')[0]
69 _experimenter = reader.read('!L')[0]
70 assert(_experimenter == 0x5c16c7)
71 _subtype = reader.read('!L')[0]
72 assert(_subtype == 1)
73 obj.dest_port = reader.read('!L')[0]
74 obj.vlan_tag = reader.read('!L')[0]
75 obj.copy_stage = reader.read('!B')[0]
76 reader.skip(3)
77 return obj
78
79 def __eq__(self, other):
80 if type(self) != type(other): return False
81 if self.dest_port != other.dest_port: return False
82 if self.vlan_tag != other.vlan_tag: return False
83 if self.copy_stage != other.copy_stage: return False
84 return True
85
86 def __ne__(self, other):
87 return not self.__eq__(other)
88
89 def show(self):
90 import loxi.pp
91 return loxi.pp.pp(self)
92
93 def pretty_print(self, q):
94 q.text("bsn_mirror {")
95 with q.group():
96 with q.indent(2):
97 q.breakable()
98 q.text("dest_port = ");
99 q.text("%#x" % self.dest_port)
100 q.text(","); q.breakable()
101 q.text("vlan_tag = ");
102 q.text("%#x" % self.vlan_tag)
103 q.text(","); q.breakable()
104 q.text("copy_stage = ");
105 q.text("%#x" % self.copy_stage)
106 q.breakable()
107 q.text('}')
108
109class bsn_set_tunnel_dst(Action):
110 type = const.OFPAT_EXPERIMENTER
111 experimenter = 0x5c16c7
112 subtype = 2
113
114 def __init__(self, dst=None):
115 if dst != None:
116 self.dst = dst
117 else:
118 self.dst = 0
119 return
120
121 def pack(self):
122 packed = []
123 packed.append(struct.pack("!H", self.type))
124 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
125 packed.append(struct.pack("!L", self.experimenter))
126 packed.append(struct.pack("!L", self.subtype))
127 packed.append(struct.pack("!L", self.dst))
128 length = sum([len(x) for x in packed])
129 packed[1] = struct.pack("!H", length)
130 return ''.join(packed)
131
132 @staticmethod
133 def unpack(buf):
134 obj = bsn_set_tunnel_dst()
135 if type(buf) == loxi.generic_util.OFReader:
136 reader = buf
137 else:
138 reader = loxi.generic_util.OFReader(buf)
139 _type = reader.read('!H')[0]
140 assert(_type == const.OFPAT_EXPERIMENTER)
141 _len = reader.read('!H')[0]
142 _experimenter = reader.read('!L')[0]
143 assert(_experimenter == 0x5c16c7)
144 _subtype = reader.read('!L')[0]
145 assert(_subtype == 2)
146 obj.dst = reader.read('!L')[0]
147 return obj
148
149 def __eq__(self, other):
150 if type(self) != type(other): return False
151 if self.dst != other.dst: return False
152 return True
153
154 def __ne__(self, other):
155 return not self.__eq__(other)
156
157 def show(self):
158 import loxi.pp
159 return loxi.pp.pp(self)
160
161 def pretty_print(self, q):
162 q.text("bsn_set_tunnel_dst {")
163 with q.group():
164 with q.indent(2):
165 q.breakable()
166 q.text("dst = ");
167 q.text("%#x" % self.dst)
168 q.breakable()
169 q.text('}')
170
171class copy_ttl_in(Action):
172 type = const.OFPAT_COPY_TTL_IN
173
174 def __init__(self):
175 return
176
177 def pack(self):
178 packed = []
179 packed.append(struct.pack("!H", self.type))
180 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
181 packed.append('\x00' * 4)
182 length = sum([len(x) for x in packed])
183 packed[1] = struct.pack("!H", length)
184 return ''.join(packed)
185
186 @staticmethod
187 def unpack(buf):
188 obj = copy_ttl_in()
189 if type(buf) == loxi.generic_util.OFReader:
190 reader = buf
191 else:
192 reader = loxi.generic_util.OFReader(buf)
193 _type = reader.read('!H')[0]
194 assert(_type == const.OFPAT_COPY_TTL_IN)
195 _len = reader.read('!H')[0]
196 reader.skip(4)
197 return obj
198
199 def __eq__(self, other):
200 if type(self) != type(other): return False
201 return True
202
203 def __ne__(self, other):
204 return not self.__eq__(other)
205
206 def show(self):
207 import loxi.pp
208 return loxi.pp.pp(self)
209
210 def pretty_print(self, q):
211 q.text("copy_ttl_in {")
212 with q.group():
213 with q.indent(2):
214 q.breakable()
215 q.breakable()
216 q.text('}')
217
218class copy_ttl_out(Action):
219 type = const.OFPAT_COPY_TTL_OUT
220
221 def __init__(self):
222 return
223
224 def pack(self):
225 packed = []
226 packed.append(struct.pack("!H", self.type))
227 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
228 packed.append('\x00' * 4)
229 length = sum([len(x) for x in packed])
230 packed[1] = struct.pack("!H", length)
231 return ''.join(packed)
232
233 @staticmethod
234 def unpack(buf):
235 obj = copy_ttl_out()
236 if type(buf) == loxi.generic_util.OFReader:
237 reader = buf
238 else:
239 reader = loxi.generic_util.OFReader(buf)
240 _type = reader.read('!H')[0]
241 assert(_type == const.OFPAT_COPY_TTL_OUT)
242 _len = reader.read('!H')[0]
243 reader.skip(4)
244 return obj
245
246 def __eq__(self, other):
247 if type(self) != type(other): return False
248 return True
249
250 def __ne__(self, other):
251 return not self.__eq__(other)
252
253 def show(self):
254 import loxi.pp
255 return loxi.pp.pp(self)
256
257 def pretty_print(self, q):
258 q.text("copy_ttl_out {")
259 with q.group():
260 with q.indent(2):
261 q.breakable()
262 q.breakable()
263 q.text('}')
264
265class dec_mpls_ttl(Action):
266 type = const.OFPAT_DEC_MPLS_TTL
267
268 def __init__(self):
269 return
270
271 def pack(self):
272 packed = []
273 packed.append(struct.pack("!H", self.type))
274 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
275 packed.append('\x00' * 4)
276 length = sum([len(x) for x in packed])
277 packed[1] = struct.pack("!H", length)
278 return ''.join(packed)
279
280 @staticmethod
281 def unpack(buf):
282 obj = dec_mpls_ttl()
283 if type(buf) == loxi.generic_util.OFReader:
284 reader = buf
285 else:
286 reader = loxi.generic_util.OFReader(buf)
287 _type = reader.read('!H')[0]
288 assert(_type == const.OFPAT_DEC_MPLS_TTL)
289 _len = reader.read('!H')[0]
290 reader.skip(4)
291 return obj
292
293 def __eq__(self, other):
294 if type(self) != type(other): return False
295 return True
296
297 def __ne__(self, other):
298 return not self.__eq__(other)
299
300 def show(self):
301 import loxi.pp
302 return loxi.pp.pp(self)
303
304 def pretty_print(self, q):
305 q.text("dec_mpls_ttl {")
306 with q.group():
307 with q.indent(2):
308 q.breakable()
309 q.breakable()
310 q.text('}')
311
312class dec_nw_ttl(Action):
313 type = const.OFPAT_DEC_NW_TTL
314
315 def __init__(self):
316 return
317
318 def pack(self):
319 packed = []
320 packed.append(struct.pack("!H", self.type))
321 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
322 packed.append('\x00' * 4)
323 length = sum([len(x) for x in packed])
324 packed[1] = struct.pack("!H", length)
325 return ''.join(packed)
326
327 @staticmethod
328 def unpack(buf):
329 obj = dec_nw_ttl()
330 if type(buf) == loxi.generic_util.OFReader:
331 reader = buf
332 else:
333 reader = loxi.generic_util.OFReader(buf)
334 _type = reader.read('!H')[0]
335 assert(_type == const.OFPAT_DEC_NW_TTL)
336 _len = reader.read('!H')[0]
337 reader.skip(4)
338 return obj
339
340 def __eq__(self, other):
341 if type(self) != type(other): return False
342 return True
343
344 def __ne__(self, other):
345 return not self.__eq__(other)
346
347 def show(self):
348 import loxi.pp
349 return loxi.pp.pp(self)
350
351 def pretty_print(self, q):
352 q.text("dec_nw_ttl {")
353 with q.group():
354 with q.indent(2):
355 q.breakable()
356 q.breakable()
357 q.text('}')
358
359class group(Action):
360 type = const.OFPAT_GROUP
361
362 def __init__(self, group_id=None):
363 if group_id != None:
364 self.group_id = group_id
365 else:
366 self.group_id = 0
367 return
368
369 def pack(self):
370 packed = []
371 packed.append(struct.pack("!H", self.type))
372 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
373 packed.append(struct.pack("!L", self.group_id))
374 length = sum([len(x) for x in packed])
375 packed[1] = struct.pack("!H", length)
376 return ''.join(packed)
377
378 @staticmethod
379 def unpack(buf):
380 obj = group()
381 if type(buf) == loxi.generic_util.OFReader:
382 reader = buf
383 else:
384 reader = loxi.generic_util.OFReader(buf)
385 _type = reader.read('!H')[0]
386 assert(_type == const.OFPAT_GROUP)
387 _len = reader.read('!H')[0]
388 obj.group_id = reader.read('!L')[0]
389 return obj
390
391 def __eq__(self, other):
392 if type(self) != type(other): return False
393 if self.group_id != other.group_id: return False
394 return True
395
396 def __ne__(self, other):
397 return not self.__eq__(other)
398
399 def show(self):
400 import loxi.pp
401 return loxi.pp.pp(self)
402
403 def pretty_print(self, q):
404 q.text("group {")
405 with q.group():
406 with q.indent(2):
407 q.breakable()
408 q.text("group_id = ");
409 q.text("%#x" % self.group_id)
410 q.breakable()
411 q.text('}')
412
413class nicira_dec_ttl(Action):
414 type = const.OFPAT_EXPERIMENTER
415 experimenter = 0x2320
416 subtype = 18
417
418 def __init__(self):
419 return
420
421 def pack(self):
422 packed = []
423 packed.append(struct.pack("!H", self.type))
424 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
425 packed.append(struct.pack("!L", self.experimenter))
426 packed.append(struct.pack("!H", self.subtype))
427 packed.append('\x00' * 2)
428 packed.append('\x00' * 4)
429 length = sum([len(x) for x in packed])
430 packed[1] = struct.pack("!H", length)
431 return ''.join(packed)
432
433 @staticmethod
434 def unpack(buf):
435 obj = nicira_dec_ttl()
436 if type(buf) == loxi.generic_util.OFReader:
437 reader = buf
438 else:
439 reader = loxi.generic_util.OFReader(buf)
440 _type = reader.read('!H')[0]
441 assert(_type == const.OFPAT_EXPERIMENTER)
442 _len = reader.read('!H')[0]
443 _experimenter = reader.read('!L')[0]
444 assert(_experimenter == 0x2320)
445 _subtype = reader.read('!H')[0]
446 assert(_subtype == 18)
447 reader.skip(2)
448 reader.skip(4)
449 return obj
450
451 def __eq__(self, other):
452 if type(self) != type(other): return False
453 return True
454
455 def __ne__(self, other):
456 return not self.__eq__(other)
457
458 def show(self):
459 import loxi.pp
460 return loxi.pp.pp(self)
461
462 def pretty_print(self, q):
463 q.text("nicira_dec_ttl {")
464 with q.group():
465 with q.indent(2):
466 q.breakable()
467 q.breakable()
468 q.text('}')
469
470class output(Action):
471 type = const.OFPAT_OUTPUT
472
473 def __init__(self, port=None, max_len=None):
474 if port != None:
475 self.port = port
476 else:
477 self.port = 0
478 if max_len != None:
479 self.max_len = max_len
480 else:
481 self.max_len = 0
482 return
483
484 def pack(self):
485 packed = []
486 packed.append(struct.pack("!H", self.type))
487 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
488 packed.append(struct.pack("!L", self.port))
489 packed.append(struct.pack("!H", self.max_len))
490 packed.append('\x00' * 6)
491 length = sum([len(x) for x in packed])
492 packed[1] = struct.pack("!H", length)
493 return ''.join(packed)
494
495 @staticmethod
496 def unpack(buf):
497 obj = output()
498 if type(buf) == loxi.generic_util.OFReader:
499 reader = buf
500 else:
501 reader = loxi.generic_util.OFReader(buf)
502 _type = reader.read('!H')[0]
503 assert(_type == const.OFPAT_OUTPUT)
504 _len = reader.read('!H')[0]
505 obj.port = reader.read('!L')[0]
506 obj.max_len = reader.read('!H')[0]
507 reader.skip(6)
508 return obj
509
510 def __eq__(self, other):
511 if type(self) != type(other): return False
512 if self.port != other.port: return False
513 if self.max_len != other.max_len: return False
514 return True
515
516 def __ne__(self, other):
517 return not self.__eq__(other)
518
519 def show(self):
520 import loxi.pp
521 return loxi.pp.pp(self)
522
523 def pretty_print(self, q):
524 q.text("output {")
525 with q.group():
526 with q.indent(2):
527 q.breakable()
528 q.text("port = ");
529 q.text(util.pretty_port(self.port))
530 q.text(","); q.breakable()
531 q.text("max_len = ");
532 q.text("%#x" % self.max_len)
533 q.breakable()
534 q.text('}')
535
536class pop_mpls(Action):
537 type = const.OFPAT_POP_MPLS
538
539 def __init__(self, ethertype=None):
540 if ethertype != None:
541 self.ethertype = ethertype
542 else:
543 self.ethertype = 0
544 return
545
546 def pack(self):
547 packed = []
548 packed.append(struct.pack("!H", self.type))
549 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
550 packed.append(struct.pack("!H", self.ethertype))
551 packed.append('\x00' * 2)
552 length = sum([len(x) for x in packed])
553 packed[1] = struct.pack("!H", length)
554 return ''.join(packed)
555
556 @staticmethod
557 def unpack(buf):
558 obj = pop_mpls()
559 if type(buf) == loxi.generic_util.OFReader:
560 reader = buf
561 else:
562 reader = loxi.generic_util.OFReader(buf)
563 _type = reader.read('!H')[0]
564 assert(_type == const.OFPAT_POP_MPLS)
565 _len = reader.read('!H')[0]
566 obj.ethertype = reader.read('!H')[0]
567 reader.skip(2)
568 return obj
569
570 def __eq__(self, other):
571 if type(self) != type(other): return False
572 if self.ethertype != other.ethertype: return False
573 return True
574
575 def __ne__(self, other):
576 return not self.__eq__(other)
577
578 def show(self):
579 import loxi.pp
580 return loxi.pp.pp(self)
581
582 def pretty_print(self, q):
583 q.text("pop_mpls {")
584 with q.group():
585 with q.indent(2):
586 q.breakable()
587 q.text("ethertype = ");
588 q.text("%#x" % self.ethertype)
589 q.breakable()
590 q.text('}')
591
592class pop_vlan(Action):
593 type = const.OFPAT_POP_VLAN
594
595 def __init__(self):
596 return
597
598 def pack(self):
599 packed = []
600 packed.append(struct.pack("!H", self.type))
601 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
602 packed.append('\x00' * 4)
603 length = sum([len(x) for x in packed])
604 packed[1] = struct.pack("!H", length)
605 return ''.join(packed)
606
607 @staticmethod
608 def unpack(buf):
609 obj = pop_vlan()
610 if type(buf) == loxi.generic_util.OFReader:
611 reader = buf
612 else:
613 reader = loxi.generic_util.OFReader(buf)
614 _type = reader.read('!H')[0]
615 assert(_type == const.OFPAT_POP_VLAN)
616 _len = reader.read('!H')[0]
617 reader.skip(4)
618 return obj
619
620 def __eq__(self, other):
621 if type(self) != type(other): return False
622 return True
623
624 def __ne__(self, other):
625 return not self.__eq__(other)
626
627 def show(self):
628 import loxi.pp
629 return loxi.pp.pp(self)
630
631 def pretty_print(self, q):
632 q.text("pop_vlan {")
633 with q.group():
634 with q.indent(2):
635 q.breakable()
636 q.breakable()
637 q.text('}')
638
639class push_mpls(Action):
640 type = const.OFPAT_PUSH_MPLS
641
642 def __init__(self, ethertype=None):
643 if ethertype != None:
644 self.ethertype = ethertype
645 else:
646 self.ethertype = 0
647 return
648
649 def pack(self):
650 packed = []
651 packed.append(struct.pack("!H", self.type))
652 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
653 packed.append(struct.pack("!H", self.ethertype))
654 packed.append('\x00' * 2)
655 length = sum([len(x) for x in packed])
656 packed[1] = struct.pack("!H", length)
657 return ''.join(packed)
658
659 @staticmethod
660 def unpack(buf):
661 obj = push_mpls()
662 if type(buf) == loxi.generic_util.OFReader:
663 reader = buf
664 else:
665 reader = loxi.generic_util.OFReader(buf)
666 _type = reader.read('!H')[0]
667 assert(_type == const.OFPAT_PUSH_MPLS)
668 _len = reader.read('!H')[0]
669 obj.ethertype = reader.read('!H')[0]
670 reader.skip(2)
671 return obj
672
673 def __eq__(self, other):
674 if type(self) != type(other): return False
675 if self.ethertype != other.ethertype: return False
676 return True
677
678 def __ne__(self, other):
679 return not self.__eq__(other)
680
681 def show(self):
682 import loxi.pp
683 return loxi.pp.pp(self)
684
685 def pretty_print(self, q):
686 q.text("push_mpls {")
687 with q.group():
688 with q.indent(2):
689 q.breakable()
690 q.text("ethertype = ");
691 q.text("%#x" % self.ethertype)
692 q.breakable()
693 q.text('}')
694
695class push_vlan(Action):
696 type = const.OFPAT_PUSH_VLAN
697
698 def __init__(self, ethertype=None):
699 if ethertype != None:
700 self.ethertype = ethertype
701 else:
702 self.ethertype = 0
703 return
704
705 def pack(self):
706 packed = []
707 packed.append(struct.pack("!H", self.type))
708 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
709 packed.append(struct.pack("!H", self.ethertype))
710 packed.append('\x00' * 2)
711 length = sum([len(x) for x in packed])
712 packed[1] = struct.pack("!H", length)
713 return ''.join(packed)
714
715 @staticmethod
716 def unpack(buf):
717 obj = push_vlan()
718 if type(buf) == loxi.generic_util.OFReader:
719 reader = buf
720 else:
721 reader = loxi.generic_util.OFReader(buf)
722 _type = reader.read('!H')[0]
723 assert(_type == const.OFPAT_PUSH_VLAN)
724 _len = reader.read('!H')[0]
725 obj.ethertype = reader.read('!H')[0]
726 reader.skip(2)
727 return obj
728
729 def __eq__(self, other):
730 if type(self) != type(other): return False
731 if self.ethertype != other.ethertype: return False
732 return True
733
734 def __ne__(self, other):
735 return not self.__eq__(other)
736
737 def show(self):
738 import loxi.pp
739 return loxi.pp.pp(self)
740
741 def pretty_print(self, q):
742 q.text("push_vlan {")
743 with q.group():
744 with q.indent(2):
745 q.breakable()
746 q.text("ethertype = ");
747 q.text("%#x" % self.ethertype)
748 q.breakable()
749 q.text('}')
750
751class set_field(Action):
752 type = const.OFPAT_SET_FIELD
753
754 def __init__(self, field=None):
755 if field != None:
756 self.field = field
757 else:
758 self.field = ""
759 return
760
761 def pack(self):
762 packed = []
763 packed.append(struct.pack("!H", self.type))
764 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
765 packed.append(self.field)
766 length = sum([len(x) for x in packed])
767 packed[1] = struct.pack("!H", length)
768 return ''.join(packed)
769
770 @staticmethod
771 def unpack(buf):
772 obj = set_field()
773 if type(buf) == loxi.generic_util.OFReader:
774 reader = buf
775 else:
776 reader = loxi.generic_util.OFReader(buf)
777 _type = reader.read('!H')[0]
778 assert(_type == const.OFPAT_SET_FIELD)
779 _len = reader.read('!H')[0]
780 obj.field = str(reader.read_all())
781 return obj
782
783 def __eq__(self, other):
784 if type(self) != type(other): return False
785 if self.field != other.field: return False
786 return True
787
788 def __ne__(self, other):
789 return not self.__eq__(other)
790
791 def show(self):
792 import loxi.pp
793 return loxi.pp.pp(self)
794
795 def pretty_print(self, q):
796 q.text("set_field {")
797 with q.group():
798 with q.indent(2):
799 q.breakable()
800 q.text("field = ");
801 q.pp(self.field)
802 q.breakable()
803 q.text('}')
804
805class set_mpls_ttl(Action):
806 type = const.OFPAT_SET_MPLS_TTL
807
808 def __init__(self, mpls_ttl=None):
809 if mpls_ttl != None:
810 self.mpls_ttl = mpls_ttl
811 else:
812 self.mpls_ttl = 0
813 return
814
815 def pack(self):
816 packed = []
817 packed.append(struct.pack("!H", self.type))
818 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
819 packed.append(struct.pack("!B", self.mpls_ttl))
820 packed.append('\x00' * 3)
821 length = sum([len(x) for x in packed])
822 packed[1] = struct.pack("!H", length)
823 return ''.join(packed)
824
825 @staticmethod
826 def unpack(buf):
827 obj = set_mpls_ttl()
828 if type(buf) == loxi.generic_util.OFReader:
829 reader = buf
830 else:
831 reader = loxi.generic_util.OFReader(buf)
832 _type = reader.read('!H')[0]
833 assert(_type == const.OFPAT_SET_MPLS_TTL)
834 _len = reader.read('!H')[0]
835 obj.mpls_ttl = reader.read('!B')[0]
836 reader.skip(3)
837 return obj
838
839 def __eq__(self, other):
840 if type(self) != type(other): return False
841 if self.mpls_ttl != other.mpls_ttl: return False
842 return True
843
844 def __ne__(self, other):
845 return not self.__eq__(other)
846
847 def show(self):
848 import loxi.pp
849 return loxi.pp.pp(self)
850
851 def pretty_print(self, q):
852 q.text("set_mpls_ttl {")
853 with q.group():
854 with q.indent(2):
855 q.breakable()
856 q.text("mpls_ttl = ");
857 q.text("%#x" % self.mpls_ttl)
858 q.breakable()
859 q.text('}')
860
861class set_nw_ttl(Action):
862 type = const.OFPAT_SET_NW_TTL
863
864 def __init__(self, nw_ttl=None):
865 if nw_ttl != None:
866 self.nw_ttl = nw_ttl
867 else:
868 self.nw_ttl = 0
869 return
870
871 def pack(self):
872 packed = []
873 packed.append(struct.pack("!H", self.type))
874 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
875 packed.append(struct.pack("!B", self.nw_ttl))
876 packed.append('\x00' * 3)
877 length = sum([len(x) for x in packed])
878 packed[1] = struct.pack("!H", length)
879 return ''.join(packed)
880
881 @staticmethod
882 def unpack(buf):
883 obj = set_nw_ttl()
884 if type(buf) == loxi.generic_util.OFReader:
885 reader = buf
886 else:
887 reader = loxi.generic_util.OFReader(buf)
888 _type = reader.read('!H')[0]
889 assert(_type == const.OFPAT_SET_NW_TTL)
890 _len = reader.read('!H')[0]
891 obj.nw_ttl = reader.read('!B')[0]
892 reader.skip(3)
893 return obj
894
895 def __eq__(self, other):
896 if type(self) != type(other): return False
897 if self.nw_ttl != other.nw_ttl: return False
898 return True
899
900 def __ne__(self, other):
901 return not self.__eq__(other)
902
903 def show(self):
904 import loxi.pp
905 return loxi.pp.pp(self)
906
907 def pretty_print(self, q):
908 q.text("set_nw_ttl {")
909 with q.group():
910 with q.indent(2):
911 q.breakable()
912 q.text("nw_ttl = ");
913 q.text("%#x" % self.nw_ttl)
914 q.breakable()
915 q.text('}')
916
917class set_queue(Action):
918 type = const.OFPAT_SET_QUEUE
919
920 def __init__(self, queue_id=None):
921 if queue_id != None:
922 self.queue_id = queue_id
923 else:
924 self.queue_id = 0
925 return
926
927 def pack(self):
928 packed = []
929 packed.append(struct.pack("!H", self.type))
930 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
931 packed.append(struct.pack("!L", self.queue_id))
932 length = sum([len(x) for x in packed])
933 packed[1] = struct.pack("!H", length)
934 return ''.join(packed)
935
936 @staticmethod
937 def unpack(buf):
938 obj = set_queue()
939 if type(buf) == loxi.generic_util.OFReader:
940 reader = buf
941 else:
942 reader = loxi.generic_util.OFReader(buf)
943 _type = reader.read('!H')[0]
944 assert(_type == const.OFPAT_SET_QUEUE)
945 _len = reader.read('!H')[0]
946 obj.queue_id = reader.read('!L')[0]
947 return obj
948
949 def __eq__(self, other):
950 if type(self) != type(other): return False
951 if self.queue_id != other.queue_id: return False
952 return True
953
954 def __ne__(self, other):
955 return not self.__eq__(other)
956
957 def show(self):
958 import loxi.pp
959 return loxi.pp.pp(self)
960
961 def pretty_print(self, q):
962 q.text("set_queue {")
963 with q.group():
964 with q.indent(2):
965 q.breakable()
966 q.text("queue_id = ");
967 q.text("%#x" % self.queue_id)
968 q.breakable()
969 q.text('}')
970
971
972def parse_experimenter(reader):
973
974 experimenter, = reader.peek("!4xL")
975 if experimenter == 0x005c16c7: # Big Switch Networks
976 subtype, = reader.peek("!8xL")
977 elif experimenter == 0x00002320: # Nicira
978 subtype, = reader.peek("!8xH")
979 else:
980 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
981
982 if subtype in experimenter_parsers[experimenter]:
983 return experimenter_parsers[experimenter][subtype](reader)
984 else:
985 raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
986
987parsers = {
988 const.OFPAT_COPY_TTL_IN : copy_ttl_in.unpack,
989 const.OFPAT_COPY_TTL_OUT : copy_ttl_out.unpack,
990 const.OFPAT_DEC_MPLS_TTL : dec_mpls_ttl.unpack,
991 const.OFPAT_DEC_NW_TTL : dec_nw_ttl.unpack,
992 const.OFPAT_EXPERIMENTER : parse_experimenter,
993 const.OFPAT_GROUP : group.unpack,
994 const.OFPAT_OUTPUT : output.unpack,
995 const.OFPAT_POP_MPLS : pop_mpls.unpack,
996 const.OFPAT_POP_VLAN : pop_vlan.unpack,
997 const.OFPAT_PUSH_MPLS : push_mpls.unpack,
998 const.OFPAT_PUSH_VLAN : push_vlan.unpack,
999 const.OFPAT_SET_FIELD : set_field.unpack,
1000 const.OFPAT_SET_MPLS_TTL : set_mpls_ttl.unpack,
1001 const.OFPAT_SET_NW_TTL : set_nw_ttl.unpack,
1002 const.OFPAT_SET_QUEUE : set_queue.unpack,
1003}
1004
1005experimenter_parsers = {
1006}