blob: a1e7877e229aee2ea26469f7bb0effb4cac8d298 [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.
Dan Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Lanec2ee4b82013-04-24 17:12:38 -07005
6# Automatically generated by LOXI from template action.py
7# Do not modify
8
9import struct
10import const
11import util
12import loxi.generic_util
13import loxi
Rich Laned53156a2013-08-05 17:17:33 -070014import oxm # for unpack
Rich Lanec2ee4b82013-04-24 17:12:38 -070015
16def unpack_list(reader):
17 def deserializer(reader, typ):
18 parser = parsers.get(typ)
19 if not parser: raise loxi.ProtocolError("unknown action type %d" % typ)
20 return parser(reader)
21 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
22
23class Action(object):
24 type = None # override in subclass
25 pass
26
27class bsn_mirror(Action):
Dan Talaycof6202252013-07-02 01:00:29 -070028 type = 65535
29 experimenter = 6035143
Rich Lanec2ee4b82013-04-24 17:12:38 -070030 subtype = 1
31
32 def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None):
33 if dest_port != None:
34 self.dest_port = dest_port
35 else:
36 self.dest_port = 0
37 if vlan_tag != None:
38 self.vlan_tag = vlan_tag
39 else:
40 self.vlan_tag = 0
41 if copy_stage != None:
42 self.copy_stage = copy_stage
43 else:
44 self.copy_stage = 0
45 return
46
47 def pack(self):
48 packed = []
49 packed.append(struct.pack("!H", self.type))
50 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
51 packed.append(struct.pack("!L", self.experimenter))
52 packed.append(struct.pack("!L", self.subtype))
53 packed.append(struct.pack("!L", self.dest_port))
54 packed.append(struct.pack("!L", self.vlan_tag))
55 packed.append(struct.pack("!B", self.copy_stage))
56 packed.append('\x00' * 3)
57 length = sum([len(x) for x in packed])
58 packed[1] = struct.pack("!H", length)
59 return ''.join(packed)
60
61 @staticmethod
62 def unpack(buf):
63 obj = bsn_mirror()
64 if type(buf) == loxi.generic_util.OFReader:
65 reader = buf
66 else:
67 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -070068 _type = reader.read("!H")[0]
69 assert(_type == 65535)
70 _len = reader.read("!H")[0]
71 _experimenter = reader.read("!L")[0]
72 assert(_experimenter == 6035143)
73 _subtype = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -070074 assert(_subtype == 1)
Dan Talaycof6202252013-07-02 01:00:29 -070075 obj.dest_port = reader.read("!L")[0]
76 obj.vlan_tag = reader.read("!L")[0]
77 obj.copy_stage = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -070078 reader.skip(3)
79 return obj
80
81 def __eq__(self, other):
82 if type(self) != type(other): return False
83 if self.dest_port != other.dest_port: return False
84 if self.vlan_tag != other.vlan_tag: return False
85 if self.copy_stage != other.copy_stage: return False
86 return True
87
88 def __ne__(self, other):
89 return not self.__eq__(other)
90
91 def show(self):
92 import loxi.pp
93 return loxi.pp.pp(self)
94
95 def pretty_print(self, q):
96 q.text("bsn_mirror {")
97 with q.group():
98 with q.indent(2):
99 q.breakable()
100 q.text("dest_port = ");
101 q.text("%#x" % self.dest_port)
102 q.text(","); q.breakable()
103 q.text("vlan_tag = ");
104 q.text("%#x" % self.vlan_tag)
105 q.text(","); q.breakable()
106 q.text("copy_stage = ");
107 q.text("%#x" % self.copy_stage)
108 q.breakable()
109 q.text('}')
110
111class bsn_set_tunnel_dst(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700112 type = 65535
113 experimenter = 6035143
Rich Lanec2ee4b82013-04-24 17:12:38 -0700114 subtype = 2
115
116 def __init__(self, dst=None):
117 if dst != None:
118 self.dst = dst
119 else:
120 self.dst = 0
121 return
122
123 def pack(self):
124 packed = []
125 packed.append(struct.pack("!H", self.type))
126 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
127 packed.append(struct.pack("!L", self.experimenter))
128 packed.append(struct.pack("!L", self.subtype))
129 packed.append(struct.pack("!L", self.dst))
130 length = sum([len(x) for x in packed])
131 packed[1] = struct.pack("!H", length)
132 return ''.join(packed)
133
134 @staticmethod
135 def unpack(buf):
136 obj = bsn_set_tunnel_dst()
137 if type(buf) == loxi.generic_util.OFReader:
138 reader = buf
139 else:
140 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700141 _type = reader.read("!H")[0]
142 assert(_type == 65535)
143 _len = reader.read("!H")[0]
144 _experimenter = reader.read("!L")[0]
145 assert(_experimenter == 6035143)
146 _subtype = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700147 assert(_subtype == 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700148 obj.dst = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700149 return obj
150
151 def __eq__(self, other):
152 if type(self) != type(other): return False
153 if self.dst != other.dst: return False
154 return True
155
156 def __ne__(self, other):
157 return not self.__eq__(other)
158
159 def show(self):
160 import loxi.pp
161 return loxi.pp.pp(self)
162
163 def pretty_print(self, q):
164 q.text("bsn_set_tunnel_dst {")
165 with q.group():
166 with q.indent(2):
167 q.breakable()
168 q.text("dst = ");
169 q.text("%#x" % self.dst)
170 q.breakable()
171 q.text('}')
172
173class copy_ttl_in(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700174 type = 12
Rich Lanec2ee4b82013-04-24 17:12:38 -0700175
176 def __init__(self):
177 return
178
179 def pack(self):
180 packed = []
181 packed.append(struct.pack("!H", self.type))
182 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
183 packed.append('\x00' * 4)
184 length = sum([len(x) for x in packed])
185 packed[1] = struct.pack("!H", length)
186 return ''.join(packed)
187
188 @staticmethod
189 def unpack(buf):
190 obj = copy_ttl_in()
191 if type(buf) == loxi.generic_util.OFReader:
192 reader = buf
193 else:
194 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700195 _type = reader.read("!H")[0]
196 assert(_type == 12)
197 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700198 reader.skip(4)
199 return obj
200
201 def __eq__(self, other):
202 if type(self) != type(other): return False
203 return True
204
205 def __ne__(self, other):
206 return not self.__eq__(other)
207
208 def show(self):
209 import loxi.pp
210 return loxi.pp.pp(self)
211
212 def pretty_print(self, q):
213 q.text("copy_ttl_in {")
214 with q.group():
215 with q.indent(2):
216 q.breakable()
217 q.breakable()
218 q.text('}')
219
220class copy_ttl_out(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700221 type = 11
Rich Lanec2ee4b82013-04-24 17:12:38 -0700222
223 def __init__(self):
224 return
225
226 def pack(self):
227 packed = []
228 packed.append(struct.pack("!H", self.type))
229 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
230 packed.append('\x00' * 4)
231 length = sum([len(x) for x in packed])
232 packed[1] = struct.pack("!H", length)
233 return ''.join(packed)
234
235 @staticmethod
236 def unpack(buf):
237 obj = copy_ttl_out()
238 if type(buf) == loxi.generic_util.OFReader:
239 reader = buf
240 else:
241 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700242 _type = reader.read("!H")[0]
243 assert(_type == 11)
244 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700245 reader.skip(4)
246 return obj
247
248 def __eq__(self, other):
249 if type(self) != type(other): return False
250 return True
251
252 def __ne__(self, other):
253 return not self.__eq__(other)
254
255 def show(self):
256 import loxi.pp
257 return loxi.pp.pp(self)
258
259 def pretty_print(self, q):
260 q.text("copy_ttl_out {")
261 with q.group():
262 with q.indent(2):
263 q.breakable()
264 q.breakable()
265 q.text('}')
266
267class dec_mpls_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700268 type = 16
Rich Lanec2ee4b82013-04-24 17:12:38 -0700269
270 def __init__(self):
271 return
272
273 def pack(self):
274 packed = []
275 packed.append(struct.pack("!H", self.type))
276 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
277 packed.append('\x00' * 4)
278 length = sum([len(x) for x in packed])
279 packed[1] = struct.pack("!H", length)
280 return ''.join(packed)
281
282 @staticmethod
283 def unpack(buf):
284 obj = dec_mpls_ttl()
285 if type(buf) == loxi.generic_util.OFReader:
286 reader = buf
287 else:
288 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700289 _type = reader.read("!H")[0]
290 assert(_type == 16)
291 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700292 reader.skip(4)
293 return obj
294
295 def __eq__(self, other):
296 if type(self) != type(other): return False
297 return True
298
299 def __ne__(self, other):
300 return not self.__eq__(other)
301
302 def show(self):
303 import loxi.pp
304 return loxi.pp.pp(self)
305
306 def pretty_print(self, q):
307 q.text("dec_mpls_ttl {")
308 with q.group():
309 with q.indent(2):
310 q.breakable()
311 q.breakable()
312 q.text('}')
313
314class dec_nw_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700315 type = 24
Rich Lanec2ee4b82013-04-24 17:12:38 -0700316
317 def __init__(self):
318 return
319
320 def pack(self):
321 packed = []
322 packed.append(struct.pack("!H", self.type))
323 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
324 packed.append('\x00' * 4)
325 length = sum([len(x) for x in packed])
326 packed[1] = struct.pack("!H", length)
327 return ''.join(packed)
328
329 @staticmethod
330 def unpack(buf):
331 obj = dec_nw_ttl()
332 if type(buf) == loxi.generic_util.OFReader:
333 reader = buf
334 else:
335 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700336 _type = reader.read("!H")[0]
337 assert(_type == 24)
338 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700339 reader.skip(4)
340 return obj
341
342 def __eq__(self, other):
343 if type(self) != type(other): return False
344 return True
345
346 def __ne__(self, other):
347 return not self.__eq__(other)
348
349 def show(self):
350 import loxi.pp
351 return loxi.pp.pp(self)
352
353 def pretty_print(self, q):
354 q.text("dec_nw_ttl {")
355 with q.group():
356 with q.indent(2):
357 q.breakable()
358 q.breakable()
359 q.text('}')
360
361class group(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700362 type = 22
Rich Lanec2ee4b82013-04-24 17:12:38 -0700363
364 def __init__(self, group_id=None):
365 if group_id != None:
366 self.group_id = group_id
367 else:
368 self.group_id = 0
369 return
370
371 def pack(self):
372 packed = []
373 packed.append(struct.pack("!H", self.type))
374 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
375 packed.append(struct.pack("!L", self.group_id))
376 length = sum([len(x) for x in packed])
377 packed[1] = struct.pack("!H", length)
378 return ''.join(packed)
379
380 @staticmethod
381 def unpack(buf):
382 obj = group()
383 if type(buf) == loxi.generic_util.OFReader:
384 reader = buf
385 else:
386 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700387 _type = reader.read("!H")[0]
388 assert(_type == 22)
389 _len = reader.read("!H")[0]
390 obj.group_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700391 return obj
392
393 def __eq__(self, other):
394 if type(self) != type(other): return False
395 if self.group_id != other.group_id: return False
396 return True
397
398 def __ne__(self, other):
399 return not self.__eq__(other)
400
401 def show(self):
402 import loxi.pp
403 return loxi.pp.pp(self)
404
405 def pretty_print(self, q):
406 q.text("group {")
407 with q.group():
408 with q.indent(2):
409 q.breakable()
410 q.text("group_id = ");
411 q.text("%#x" % self.group_id)
412 q.breakable()
413 q.text('}')
414
415class nicira_dec_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700416 type = 65535
417 experimenter = 8992
Rich Lanec2ee4b82013-04-24 17:12:38 -0700418 subtype = 18
419
420 def __init__(self):
421 return
422
423 def pack(self):
424 packed = []
425 packed.append(struct.pack("!H", self.type))
426 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
427 packed.append(struct.pack("!L", self.experimenter))
428 packed.append(struct.pack("!H", self.subtype))
429 packed.append('\x00' * 2)
430 packed.append('\x00' * 4)
431 length = sum([len(x) for x in packed])
432 packed[1] = struct.pack("!H", length)
433 return ''.join(packed)
434
435 @staticmethod
436 def unpack(buf):
437 obj = nicira_dec_ttl()
438 if type(buf) == loxi.generic_util.OFReader:
439 reader = buf
440 else:
441 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700442 _type = reader.read("!H")[0]
443 assert(_type == 65535)
444 _len = reader.read("!H")[0]
445 _experimenter = reader.read("!L")[0]
446 assert(_experimenter == 8992)
447 _subtype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700448 assert(_subtype == 18)
449 reader.skip(2)
450 reader.skip(4)
451 return obj
452
453 def __eq__(self, other):
454 if type(self) != type(other): return False
455 return True
456
457 def __ne__(self, other):
458 return not self.__eq__(other)
459
460 def show(self):
461 import loxi.pp
462 return loxi.pp.pp(self)
463
464 def pretty_print(self, q):
465 q.text("nicira_dec_ttl {")
466 with q.group():
467 with q.indent(2):
468 q.breakable()
469 q.breakable()
470 q.text('}')
471
472class output(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700473 type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700474
475 def __init__(self, port=None, max_len=None):
476 if port != None:
477 self.port = port
478 else:
479 self.port = 0
480 if max_len != None:
481 self.max_len = max_len
482 else:
483 self.max_len = 0
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
Dan Talaycof6202252013-07-02 01:00:29 -0700490 packed.append(util.pack_port_no(self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700491 packed.append(struct.pack("!H", self.max_len))
492 packed.append('\x00' * 6)
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(buf):
499 obj = output()
500 if type(buf) == loxi.generic_util.OFReader:
501 reader = buf
502 else:
503 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700504 _type = reader.read("!H")[0]
505 assert(_type == 0)
506 _len = reader.read("!H")[0]
507 obj.port = util.unpack_port_no(reader)
508 obj.max_len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700509 reader.skip(6)
510 return obj
511
512 def __eq__(self, other):
513 if type(self) != type(other): return False
514 if self.port != other.port: return False
515 if self.max_len != other.max_len: return False
516 return True
517
518 def __ne__(self, other):
519 return not self.__eq__(other)
520
521 def show(self):
522 import loxi.pp
523 return loxi.pp.pp(self)
524
525 def pretty_print(self, q):
526 q.text("output {")
527 with q.group():
528 with q.indent(2):
529 q.breakable()
530 q.text("port = ");
531 q.text(util.pretty_port(self.port))
532 q.text(","); q.breakable()
533 q.text("max_len = ");
534 q.text("%#x" % self.max_len)
535 q.breakable()
536 q.text('}')
537
538class pop_mpls(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700539 type = 20
Rich Lanec2ee4b82013-04-24 17:12:38 -0700540
541 def __init__(self, ethertype=None):
542 if ethertype != None:
543 self.ethertype = ethertype
544 else:
545 self.ethertype = 0
546 return
547
548 def pack(self):
549 packed = []
550 packed.append(struct.pack("!H", self.type))
551 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
552 packed.append(struct.pack("!H", self.ethertype))
553 packed.append('\x00' * 2)
554 length = sum([len(x) for x in packed])
555 packed[1] = struct.pack("!H", length)
556 return ''.join(packed)
557
558 @staticmethod
559 def unpack(buf):
560 obj = pop_mpls()
561 if type(buf) == loxi.generic_util.OFReader:
562 reader = buf
563 else:
564 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700565 _type = reader.read("!H")[0]
566 assert(_type == 20)
567 _len = reader.read("!H")[0]
568 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700569 reader.skip(2)
570 return obj
571
572 def __eq__(self, other):
573 if type(self) != type(other): return False
574 if self.ethertype != other.ethertype: return False
575 return True
576
577 def __ne__(self, other):
578 return not self.__eq__(other)
579
580 def show(self):
581 import loxi.pp
582 return loxi.pp.pp(self)
583
584 def pretty_print(self, q):
585 q.text("pop_mpls {")
586 with q.group():
587 with q.indent(2):
588 q.breakable()
589 q.text("ethertype = ");
590 q.text("%#x" % self.ethertype)
591 q.breakable()
592 q.text('}')
593
594class pop_pbb(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700595 type = 27
Rich Lanec2ee4b82013-04-24 17:12:38 -0700596
597 def __init__(self):
598 return
599
600 def pack(self):
601 packed = []
602 packed.append(struct.pack("!H", self.type))
603 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
604 packed.append('\x00' * 4)
605 length = sum([len(x) for x in packed])
606 packed[1] = struct.pack("!H", length)
607 return ''.join(packed)
608
609 @staticmethod
610 def unpack(buf):
611 obj = pop_pbb()
612 if type(buf) == loxi.generic_util.OFReader:
613 reader = buf
614 else:
615 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700616 _type = reader.read("!H")[0]
617 assert(_type == 27)
618 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700619 reader.skip(4)
620 return obj
621
622 def __eq__(self, other):
623 if type(self) != type(other): return False
624 return True
625
626 def __ne__(self, other):
627 return not self.__eq__(other)
628
629 def show(self):
630 import loxi.pp
631 return loxi.pp.pp(self)
632
633 def pretty_print(self, q):
634 q.text("pop_pbb {")
635 with q.group():
636 with q.indent(2):
637 q.breakable()
638 q.breakable()
639 q.text('}')
640
641class pop_vlan(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700642 type = 18
Rich Lanec2ee4b82013-04-24 17:12:38 -0700643
644 def __init__(self):
645 return
646
647 def pack(self):
648 packed = []
649 packed.append(struct.pack("!H", self.type))
650 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
651 packed.append('\x00' * 4)
652 length = sum([len(x) for x in packed])
653 packed[1] = struct.pack("!H", length)
654 return ''.join(packed)
655
656 @staticmethod
657 def unpack(buf):
658 obj = pop_vlan()
659 if type(buf) == loxi.generic_util.OFReader:
660 reader = buf
661 else:
662 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700663 _type = reader.read("!H")[0]
664 assert(_type == 18)
665 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700666 reader.skip(4)
667 return obj
668
669 def __eq__(self, other):
670 if type(self) != type(other): return False
671 return True
672
673 def __ne__(self, other):
674 return not self.__eq__(other)
675
676 def show(self):
677 import loxi.pp
678 return loxi.pp.pp(self)
679
680 def pretty_print(self, q):
681 q.text("pop_vlan {")
682 with q.group():
683 with q.indent(2):
684 q.breakable()
685 q.breakable()
686 q.text('}')
687
688class push_mpls(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700689 type = 19
Rich Lanec2ee4b82013-04-24 17:12:38 -0700690
691 def __init__(self, ethertype=None):
692 if ethertype != None:
693 self.ethertype = ethertype
694 else:
695 self.ethertype = 0
696 return
697
698 def pack(self):
699 packed = []
700 packed.append(struct.pack("!H", self.type))
701 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
702 packed.append(struct.pack("!H", self.ethertype))
703 packed.append('\x00' * 2)
704 length = sum([len(x) for x in packed])
705 packed[1] = struct.pack("!H", length)
706 return ''.join(packed)
707
708 @staticmethod
709 def unpack(buf):
710 obj = push_mpls()
711 if type(buf) == loxi.generic_util.OFReader:
712 reader = buf
713 else:
714 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700715 _type = reader.read("!H")[0]
716 assert(_type == 19)
717 _len = reader.read("!H")[0]
718 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700719 reader.skip(2)
720 return obj
721
722 def __eq__(self, other):
723 if type(self) != type(other): return False
724 if self.ethertype != other.ethertype: return False
725 return True
726
727 def __ne__(self, other):
728 return not self.__eq__(other)
729
730 def show(self):
731 import loxi.pp
732 return loxi.pp.pp(self)
733
734 def pretty_print(self, q):
735 q.text("push_mpls {")
736 with q.group():
737 with q.indent(2):
738 q.breakable()
739 q.text("ethertype = ");
740 q.text("%#x" % self.ethertype)
741 q.breakable()
742 q.text('}')
743
744class push_pbb(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700745 type = 26
Rich Lanec2ee4b82013-04-24 17:12:38 -0700746
747 def __init__(self, ethertype=None):
748 if ethertype != None:
749 self.ethertype = ethertype
750 else:
751 self.ethertype = 0
752 return
753
754 def pack(self):
755 packed = []
756 packed.append(struct.pack("!H", self.type))
757 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
758 packed.append(struct.pack("!H", self.ethertype))
759 packed.append('\x00' * 2)
760 length = sum([len(x) for x in packed])
761 packed[1] = struct.pack("!H", length)
762 return ''.join(packed)
763
764 @staticmethod
765 def unpack(buf):
766 obj = push_pbb()
767 if type(buf) == loxi.generic_util.OFReader:
768 reader = buf
769 else:
770 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700771 _type = reader.read("!H")[0]
772 assert(_type == 26)
773 _len = reader.read("!H")[0]
774 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700775 reader.skip(2)
776 return obj
777
778 def __eq__(self, other):
779 if type(self) != type(other): return False
780 if self.ethertype != other.ethertype: return False
781 return True
782
783 def __ne__(self, other):
784 return not self.__eq__(other)
785
786 def show(self):
787 import loxi.pp
788 return loxi.pp.pp(self)
789
790 def pretty_print(self, q):
791 q.text("push_pbb {")
792 with q.group():
793 with q.indent(2):
794 q.breakable()
795 q.text("ethertype = ");
796 q.text("%#x" % self.ethertype)
797 q.breakable()
798 q.text('}')
799
800class push_vlan(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700801 type = 17
Rich Lanec2ee4b82013-04-24 17:12:38 -0700802
803 def __init__(self, ethertype=None):
804 if ethertype != None:
805 self.ethertype = ethertype
806 else:
807 self.ethertype = 0
808 return
809
810 def pack(self):
811 packed = []
812 packed.append(struct.pack("!H", self.type))
813 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
814 packed.append(struct.pack("!H", self.ethertype))
815 packed.append('\x00' * 2)
816 length = sum([len(x) for x in packed])
817 packed[1] = struct.pack("!H", length)
818 return ''.join(packed)
819
820 @staticmethod
821 def unpack(buf):
822 obj = push_vlan()
823 if type(buf) == loxi.generic_util.OFReader:
824 reader = buf
825 else:
826 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700827 _type = reader.read("!H")[0]
828 assert(_type == 17)
829 _len = reader.read("!H")[0]
830 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700831 reader.skip(2)
832 return obj
833
834 def __eq__(self, other):
835 if type(self) != type(other): return False
836 if self.ethertype != other.ethertype: return False
837 return True
838
839 def __ne__(self, other):
840 return not self.__eq__(other)
841
842 def show(self):
843 import loxi.pp
844 return loxi.pp.pp(self)
845
846 def pretty_print(self, q):
847 q.text("push_vlan {")
848 with q.group():
849 with q.indent(2):
850 q.breakable()
851 q.text("ethertype = ");
852 q.text("%#x" % self.ethertype)
853 q.breakable()
854 q.text('}')
855
856class set_field(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700857 type = 25
Rich Lanec2ee4b82013-04-24 17:12:38 -0700858
859 def __init__(self, field=None):
860 if field != None:
861 self.field = field
862 else:
Rich Laned53156a2013-08-05 17:17:33 -0700863 self.field = None
Rich Lanec2ee4b82013-04-24 17:12:38 -0700864 return
865
866 def pack(self):
867 packed = []
868 packed.append(struct.pack("!H", self.type))
869 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Laned53156a2013-08-05 17:17:33 -0700870 packed.append(self.field.pack())
Rich Lanec2ee4b82013-04-24 17:12:38 -0700871 length = sum([len(x) for x in packed])
Rich Laned53156a2013-08-05 17:17:33 -0700872 packed.append(loxi.generic_util.pad_to(8, length))
873 length += len(packed[-1])
Rich Lanec2ee4b82013-04-24 17:12:38 -0700874 packed[1] = struct.pack("!H", length)
875 return ''.join(packed)
876
877 @staticmethod
878 def unpack(buf):
879 obj = set_field()
880 if type(buf) == loxi.generic_util.OFReader:
881 reader = buf
882 else:
883 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700884 _type = reader.read("!H")[0]
885 assert(_type == 25)
886 _len = reader.read("!H")[0]
Rich Laned53156a2013-08-05 17:17:33 -0700887 obj.field = oxm.unpack(reader)
888 reader.skip_align()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700889 return obj
890
891 def __eq__(self, other):
892 if type(self) != type(other): return False
893 if self.field != other.field: return False
894 return True
895
896 def __ne__(self, other):
897 return not self.__eq__(other)
898
899 def show(self):
900 import loxi.pp
901 return loxi.pp.pp(self)
902
903 def pretty_print(self, q):
904 q.text("set_field {")
905 with q.group():
906 with q.indent(2):
907 q.breakable()
908 q.text("field = ");
909 q.pp(self.field)
910 q.breakable()
911 q.text('}')
912
913class set_mpls_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700914 type = 15
Rich Lanec2ee4b82013-04-24 17:12:38 -0700915
916 def __init__(self, mpls_ttl=None):
917 if mpls_ttl != None:
918 self.mpls_ttl = mpls_ttl
919 else:
920 self.mpls_ttl = 0
921 return
922
923 def pack(self):
924 packed = []
925 packed.append(struct.pack("!H", self.type))
926 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
927 packed.append(struct.pack("!B", self.mpls_ttl))
928 packed.append('\x00' * 3)
929 length = sum([len(x) for x in packed])
930 packed[1] = struct.pack("!H", length)
931 return ''.join(packed)
932
933 @staticmethod
934 def unpack(buf):
935 obj = set_mpls_ttl()
936 if type(buf) == loxi.generic_util.OFReader:
937 reader = buf
938 else:
939 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700940 _type = reader.read("!H")[0]
941 assert(_type == 15)
942 _len = reader.read("!H")[0]
943 obj.mpls_ttl = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700944 reader.skip(3)
945 return obj
946
947 def __eq__(self, other):
948 if type(self) != type(other): return False
949 if self.mpls_ttl != other.mpls_ttl: return False
950 return True
951
952 def __ne__(self, other):
953 return not self.__eq__(other)
954
955 def show(self):
956 import loxi.pp
957 return loxi.pp.pp(self)
958
959 def pretty_print(self, q):
960 q.text("set_mpls_ttl {")
961 with q.group():
962 with q.indent(2):
963 q.breakable()
964 q.text("mpls_ttl = ");
965 q.text("%#x" % self.mpls_ttl)
966 q.breakable()
967 q.text('}')
968
969class set_nw_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700970 type = 23
Rich Lanec2ee4b82013-04-24 17:12:38 -0700971
972 def __init__(self, nw_ttl=None):
973 if nw_ttl != None:
974 self.nw_ttl = nw_ttl
975 else:
976 self.nw_ttl = 0
977 return
978
979 def pack(self):
980 packed = []
981 packed.append(struct.pack("!H", self.type))
982 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
983 packed.append(struct.pack("!B", self.nw_ttl))
984 packed.append('\x00' * 3)
985 length = sum([len(x) for x in packed])
986 packed[1] = struct.pack("!H", length)
987 return ''.join(packed)
988
989 @staticmethod
990 def unpack(buf):
991 obj = set_nw_ttl()
992 if type(buf) == loxi.generic_util.OFReader:
993 reader = buf
994 else:
995 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700996 _type = reader.read("!H")[0]
997 assert(_type == 23)
998 _len = reader.read("!H")[0]
999 obj.nw_ttl = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001000 reader.skip(3)
1001 return obj
1002
1003 def __eq__(self, other):
1004 if type(self) != type(other): return False
1005 if self.nw_ttl != other.nw_ttl: return False
1006 return True
1007
1008 def __ne__(self, other):
1009 return not self.__eq__(other)
1010
1011 def show(self):
1012 import loxi.pp
1013 return loxi.pp.pp(self)
1014
1015 def pretty_print(self, q):
1016 q.text("set_nw_ttl {")
1017 with q.group():
1018 with q.indent(2):
1019 q.breakable()
1020 q.text("nw_ttl = ");
1021 q.text("%#x" % self.nw_ttl)
1022 q.breakable()
1023 q.text('}')
1024
1025class set_queue(Action):
Dan Talaycof6202252013-07-02 01:00:29 -07001026 type = 21
Rich Lanec2ee4b82013-04-24 17:12:38 -07001027
1028 def __init__(self, queue_id=None):
1029 if queue_id != None:
1030 self.queue_id = queue_id
1031 else:
1032 self.queue_id = 0
1033 return
1034
1035 def pack(self):
1036 packed = []
1037 packed.append(struct.pack("!H", self.type))
1038 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1039 packed.append(struct.pack("!L", self.queue_id))
1040 length = sum([len(x) for x in packed])
1041 packed[1] = struct.pack("!H", length)
1042 return ''.join(packed)
1043
1044 @staticmethod
1045 def unpack(buf):
1046 obj = set_queue()
1047 if type(buf) == loxi.generic_util.OFReader:
1048 reader = buf
1049 else:
1050 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001051 _type = reader.read("!H")[0]
1052 assert(_type == 21)
1053 _len = reader.read("!H")[0]
1054 obj.queue_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001055 return obj
1056
1057 def __eq__(self, other):
1058 if type(self) != type(other): return False
1059 if self.queue_id != other.queue_id: return False
1060 return True
1061
1062 def __ne__(self, other):
1063 return not self.__eq__(other)
1064
1065 def show(self):
1066 import loxi.pp
1067 return loxi.pp.pp(self)
1068
1069 def pretty_print(self, q):
1070 q.text("set_queue {")
1071 with q.group():
1072 with q.indent(2):
1073 q.breakable()
1074 q.text("queue_id = ");
1075 q.text("%#x" % self.queue_id)
1076 q.breakable()
1077 q.text('}')
1078
1079
1080def parse_experimenter(reader):
1081
1082 experimenter, = reader.peek("!4xL")
1083 if experimenter == 0x005c16c7: # Big Switch Networks
1084 subtype, = reader.peek("!8xL")
1085 elif experimenter == 0x00002320: # Nicira
1086 subtype, = reader.peek("!8xH")
1087 else:
1088 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
1089
1090 if subtype in experimenter_parsers[experimenter]:
1091 return experimenter_parsers[experimenter][subtype](reader)
1092 else:
1093 raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
1094
1095parsers = {
Rich Lanec2ee4b82013-04-24 17:12:38 -07001096 const.OFPAT_OUTPUT : output.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -07001097 const.OFPAT_COPY_TTL_OUT : copy_ttl_out.unpack,
1098 const.OFPAT_COPY_TTL_IN : copy_ttl_in.unpack,
1099 const.OFPAT_SET_MPLS_TTL : set_mpls_ttl.unpack,
1100 const.OFPAT_DEC_MPLS_TTL : dec_mpls_ttl.unpack,
1101 const.OFPAT_PUSH_VLAN : push_vlan.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07001102 const.OFPAT_POP_VLAN : pop_vlan.unpack,
1103 const.OFPAT_PUSH_MPLS : push_mpls.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -07001104 const.OFPAT_POP_MPLS : pop_mpls.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07001105 const.OFPAT_SET_QUEUE : set_queue.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -07001106 const.OFPAT_GROUP : group.unpack,
1107 const.OFPAT_SET_NW_TTL : set_nw_ttl.unpack,
1108 const.OFPAT_DEC_NW_TTL : dec_nw_ttl.unpack,
1109 const.OFPAT_SET_FIELD : set_field.unpack,
1110 const.OFPAT_PUSH_PBB : push_pbb.unpack,
1111 const.OFPAT_POP_PBB : pop_pbb.unpack,
1112 const.OFPAT_EXPERIMENTER : parse_experimenter,
Rich Lanec2ee4b82013-04-24 17:12:38 -07001113}
1114
1115experimenter_parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -07001116 8992 : {
1117 18: nicira_dec_ttl.unpack,
1118 },
1119 6035143 : {
1120 1: bsn_mirror.unpack,
1121 2: bsn_set_tunnel_dst.unpack,
1122 },
Rich Lanec2ee4b82013-04-24 17:12:38 -07001123}