blob: 9ae3d8f01da412da2bc2e2094555193cf9872d95 [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_vlan(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700595 type = 18
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_vlan()
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 == 18)
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_vlan {")
635 with q.group():
636 with q.indent(2):
637 q.breakable()
638 q.breakable()
639 q.text('}')
640
641class push_mpls(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700642 type = 19
Rich Lanec2ee4b82013-04-24 17:12:38 -0700643
644 def __init__(self, ethertype=None):
645 if ethertype != None:
646 self.ethertype = ethertype
647 else:
648 self.ethertype = 0
649 return
650
651 def pack(self):
652 packed = []
653 packed.append(struct.pack("!H", self.type))
654 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
655 packed.append(struct.pack("!H", self.ethertype))
656 packed.append('\x00' * 2)
657 length = sum([len(x) for x in packed])
658 packed[1] = struct.pack("!H", length)
659 return ''.join(packed)
660
661 @staticmethod
662 def unpack(buf):
663 obj = push_mpls()
664 if type(buf) == loxi.generic_util.OFReader:
665 reader = buf
666 else:
667 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700668 _type = reader.read("!H")[0]
669 assert(_type == 19)
670 _len = reader.read("!H")[0]
671 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700672 reader.skip(2)
673 return obj
674
675 def __eq__(self, other):
676 if type(self) != type(other): return False
677 if self.ethertype != other.ethertype: return False
678 return True
679
680 def __ne__(self, other):
681 return not self.__eq__(other)
682
683 def show(self):
684 import loxi.pp
685 return loxi.pp.pp(self)
686
687 def pretty_print(self, q):
688 q.text("push_mpls {")
689 with q.group():
690 with q.indent(2):
691 q.breakable()
692 q.text("ethertype = ");
693 q.text("%#x" % self.ethertype)
694 q.breakable()
695 q.text('}')
696
697class push_vlan(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700698 type = 17
Rich Lanec2ee4b82013-04-24 17:12:38 -0700699
700 def __init__(self, ethertype=None):
701 if ethertype != None:
702 self.ethertype = ethertype
703 else:
704 self.ethertype = 0
705 return
706
707 def pack(self):
708 packed = []
709 packed.append(struct.pack("!H", self.type))
710 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
711 packed.append(struct.pack("!H", self.ethertype))
712 packed.append('\x00' * 2)
713 length = sum([len(x) for x in packed])
714 packed[1] = struct.pack("!H", length)
715 return ''.join(packed)
716
717 @staticmethod
718 def unpack(buf):
719 obj = push_vlan()
720 if type(buf) == loxi.generic_util.OFReader:
721 reader = buf
722 else:
723 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700724 _type = reader.read("!H")[0]
725 assert(_type == 17)
726 _len = reader.read("!H")[0]
727 obj.ethertype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700728 reader.skip(2)
729 return obj
730
731 def __eq__(self, other):
732 if type(self) != type(other): return False
733 if self.ethertype != other.ethertype: return False
734 return True
735
736 def __ne__(self, other):
737 return not self.__eq__(other)
738
739 def show(self):
740 import loxi.pp
741 return loxi.pp.pp(self)
742
743 def pretty_print(self, q):
744 q.text("push_vlan {")
745 with q.group():
746 with q.indent(2):
747 q.breakable()
748 q.text("ethertype = ");
749 q.text("%#x" % self.ethertype)
750 q.breakable()
751 q.text('}')
752
753class set_field(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700754 type = 25
Rich Lanec2ee4b82013-04-24 17:12:38 -0700755
756 def __init__(self, field=None):
757 if field != None:
758 self.field = field
759 else:
Rich Laned53156a2013-08-05 17:17:33 -0700760 self.field = None
Rich Lanec2ee4b82013-04-24 17:12:38 -0700761 return
762
763 def pack(self):
764 packed = []
765 packed.append(struct.pack("!H", self.type))
766 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Laned53156a2013-08-05 17:17:33 -0700767 packed.append(self.field.pack())
Rich Lanec2ee4b82013-04-24 17:12:38 -0700768 length = sum([len(x) for x in packed])
Rich Laned53156a2013-08-05 17:17:33 -0700769 packed.append(loxi.generic_util.pad_to(8, length))
770 length += len(packed[-1])
Rich Lanec2ee4b82013-04-24 17:12:38 -0700771 packed[1] = struct.pack("!H", length)
772 return ''.join(packed)
773
774 @staticmethod
775 def unpack(buf):
776 obj = set_field()
777 if type(buf) == loxi.generic_util.OFReader:
778 reader = buf
779 else:
780 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700781 _type = reader.read("!H")[0]
782 assert(_type == 25)
783 _len = reader.read("!H")[0]
Rich Laned53156a2013-08-05 17:17:33 -0700784 obj.field = oxm.unpack(reader)
785 reader.skip_align()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700786 return obj
787
788 def __eq__(self, other):
789 if type(self) != type(other): return False
790 if self.field != other.field: return False
791 return True
792
793 def __ne__(self, other):
794 return not self.__eq__(other)
795
796 def show(self):
797 import loxi.pp
798 return loxi.pp.pp(self)
799
800 def pretty_print(self, q):
801 q.text("set_field {")
802 with q.group():
803 with q.indent(2):
804 q.breakable()
805 q.text("field = ");
806 q.pp(self.field)
807 q.breakable()
808 q.text('}')
809
810class set_mpls_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700811 type = 15
Rich Lanec2ee4b82013-04-24 17:12:38 -0700812
813 def __init__(self, mpls_ttl=None):
814 if mpls_ttl != None:
815 self.mpls_ttl = mpls_ttl
816 else:
817 self.mpls_ttl = 0
818 return
819
820 def pack(self):
821 packed = []
822 packed.append(struct.pack("!H", self.type))
823 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
824 packed.append(struct.pack("!B", self.mpls_ttl))
825 packed.append('\x00' * 3)
826 length = sum([len(x) for x in packed])
827 packed[1] = struct.pack("!H", length)
828 return ''.join(packed)
829
830 @staticmethod
831 def unpack(buf):
832 obj = set_mpls_ttl()
833 if type(buf) == loxi.generic_util.OFReader:
834 reader = buf
835 else:
836 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700837 _type = reader.read("!H")[0]
838 assert(_type == 15)
839 _len = reader.read("!H")[0]
840 obj.mpls_ttl = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700841 reader.skip(3)
842 return obj
843
844 def __eq__(self, other):
845 if type(self) != type(other): return False
846 if self.mpls_ttl != other.mpls_ttl: return False
847 return True
848
849 def __ne__(self, other):
850 return not self.__eq__(other)
851
852 def show(self):
853 import loxi.pp
854 return loxi.pp.pp(self)
855
856 def pretty_print(self, q):
857 q.text("set_mpls_ttl {")
858 with q.group():
859 with q.indent(2):
860 q.breakable()
861 q.text("mpls_ttl = ");
862 q.text("%#x" % self.mpls_ttl)
863 q.breakable()
864 q.text('}')
865
866class set_nw_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700867 type = 23
Rich Lanec2ee4b82013-04-24 17:12:38 -0700868
869 def __init__(self, nw_ttl=None):
870 if nw_ttl != None:
871 self.nw_ttl = nw_ttl
872 else:
873 self.nw_ttl = 0
874 return
875
876 def pack(self):
877 packed = []
878 packed.append(struct.pack("!H", self.type))
879 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
880 packed.append(struct.pack("!B", self.nw_ttl))
881 packed.append('\x00' * 3)
882 length = sum([len(x) for x in packed])
883 packed[1] = struct.pack("!H", length)
884 return ''.join(packed)
885
886 @staticmethod
887 def unpack(buf):
888 obj = set_nw_ttl()
889 if type(buf) == loxi.generic_util.OFReader:
890 reader = buf
891 else:
892 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700893 _type = reader.read("!H")[0]
894 assert(_type == 23)
895 _len = reader.read("!H")[0]
896 obj.nw_ttl = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700897 reader.skip(3)
898 return obj
899
900 def __eq__(self, other):
901 if type(self) != type(other): return False
902 if self.nw_ttl != other.nw_ttl: return False
903 return True
904
905 def __ne__(self, other):
906 return not self.__eq__(other)
907
908 def show(self):
909 import loxi.pp
910 return loxi.pp.pp(self)
911
912 def pretty_print(self, q):
913 q.text("set_nw_ttl {")
914 with q.group():
915 with q.indent(2):
916 q.breakable()
917 q.text("nw_ttl = ");
918 q.text("%#x" % self.nw_ttl)
919 q.breakable()
920 q.text('}')
921
922class set_queue(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700923 type = 21
Rich Lanec2ee4b82013-04-24 17:12:38 -0700924
925 def __init__(self, queue_id=None):
926 if queue_id != None:
927 self.queue_id = queue_id
928 else:
929 self.queue_id = 0
930 return
931
932 def pack(self):
933 packed = []
934 packed.append(struct.pack("!H", self.type))
935 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
936 packed.append(struct.pack("!L", self.queue_id))
937 length = sum([len(x) for x in packed])
938 packed[1] = struct.pack("!H", length)
939 return ''.join(packed)
940
941 @staticmethod
942 def unpack(buf):
943 obj = set_queue()
944 if type(buf) == loxi.generic_util.OFReader:
945 reader = buf
946 else:
947 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700948 _type = reader.read("!H")[0]
949 assert(_type == 21)
950 _len = reader.read("!H")[0]
951 obj.queue_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700952 return obj
953
954 def __eq__(self, other):
955 if type(self) != type(other): return False
956 if self.queue_id != other.queue_id: return False
957 return True
958
959 def __ne__(self, other):
960 return not self.__eq__(other)
961
962 def show(self):
963 import loxi.pp
964 return loxi.pp.pp(self)
965
966 def pretty_print(self, q):
967 q.text("set_queue {")
968 with q.group():
969 with q.indent(2):
970 q.breakable()
971 q.text("queue_id = ");
972 q.text("%#x" % self.queue_id)
973 q.breakable()
974 q.text('}')
975
976
977def parse_experimenter(reader):
978
979 experimenter, = reader.peek("!4xL")
980 if experimenter == 0x005c16c7: # Big Switch Networks
981 subtype, = reader.peek("!8xL")
982 elif experimenter == 0x00002320: # Nicira
983 subtype, = reader.peek("!8xH")
984 else:
985 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
986
987 if subtype in experimenter_parsers[experimenter]:
988 return experimenter_parsers[experimenter][subtype](reader)
989 else:
990 raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
991
992parsers = {
Rich Lanec2ee4b82013-04-24 17:12:38 -0700993 const.OFPAT_OUTPUT : output.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -0700994 const.OFPAT_COPY_TTL_OUT : copy_ttl_out.unpack,
995 const.OFPAT_COPY_TTL_IN : copy_ttl_in.unpack,
996 const.OFPAT_SET_MPLS_TTL : set_mpls_ttl.unpack,
997 const.OFPAT_DEC_MPLS_TTL : dec_mpls_ttl.unpack,
998 const.OFPAT_PUSH_VLAN : push_vlan.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -0700999 const.OFPAT_POP_VLAN : pop_vlan.unpack,
1000 const.OFPAT_PUSH_MPLS : push_mpls.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -07001001 const.OFPAT_POP_MPLS : pop_mpls.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07001002 const.OFPAT_SET_QUEUE : set_queue.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -07001003 const.OFPAT_GROUP : group.unpack,
1004 const.OFPAT_SET_NW_TTL : set_nw_ttl.unpack,
1005 const.OFPAT_DEC_NW_TTL : dec_nw_ttl.unpack,
1006 const.OFPAT_SET_FIELD : set_field.unpack,
1007 const.OFPAT_EXPERIMENTER : parse_experimenter,
Rich Lanec2ee4b82013-04-24 17:12:38 -07001008}
1009
1010experimenter_parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -07001011 8992 : {
1012 18: nicira_dec_ttl.unpack,
1013 },
1014 6035143 : {
1015 1: bsn_mirror.unpack,
1016 2: bsn_set_tunnel_dst.unpack,
1017 },
Rich Lanec2ee4b82013-04-24 17:12:38 -07001018}