blob: 6a3abfb08bfaabd38d6614f7d2996bd7b4d70f2a [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 Laneb658ddd2013-03-12 10:15:10 -07005
6# Automatically generated by LOXI from template action.py
7# Do not modify
8
9import struct
10import const
11import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070012import loxi.generic_util
Rich Laneb658ddd2013-03-12 10:15:10 -070013import loxi
14
Rich Lanec2ee4b82013-04-24 17:12:38 -070015def unpack_list(reader):
16 def deserializer(reader, typ):
17 parser = parsers.get(typ)
18 if not parser: raise loxi.ProtocolError("unknown action type %d" % typ)
19 return parser(reader)
20 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
Rich Laneb658ddd2013-03-12 10:15:10 -070021
22class Action(object):
23 type = None # override in subclass
24 pass
25
26class bsn_mirror(Action):
Dan Talaycof6202252013-07-02 01:00:29 -070027 type = 65535
28 experimenter = 6035143
Rich Laneb658ddd2013-03-12 10:15:10 -070029 subtype = 1
30
Rich Lanec2ee4b82013-04-24 17:12:38 -070031 def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070032 if dest_port != None:
33 self.dest_port = dest_port
34 else:
35 self.dest_port = 0
36 if vlan_tag != None:
37 self.vlan_tag = vlan_tag
38 else:
39 self.vlan_tag = 0
40 if copy_stage != None:
41 self.copy_stage = copy_stage
42 else:
43 self.copy_stage = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -070044 return
Rich Laneb658ddd2013-03-12 10:15:10 -070045
46 def pack(self):
47 packed = []
48 packed.append(struct.pack("!H", self.type))
49 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
50 packed.append(struct.pack("!L", self.experimenter))
51 packed.append(struct.pack("!L", self.subtype))
52 packed.append(struct.pack("!L", self.dest_port))
53 packed.append(struct.pack("!L", self.vlan_tag))
54 packed.append(struct.pack("!B", self.copy_stage))
Rich Lanec2ee4b82013-04-24 17:12:38 -070055 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -070056 length = sum([len(x) for x in packed])
57 packed[1] = struct.pack("!H", length)
58 return ''.join(packed)
59
60 @staticmethod
61 def unpack(buf):
62 obj = bsn_mirror()
Rich Lanec2ee4b82013-04-24 17:12:38 -070063 if type(buf) == loxi.generic_util.OFReader:
64 reader = buf
65 else:
66 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -070067 _type = reader.read("!H")[0]
68 assert(_type == 65535)
69 _len = reader.read("!H")[0]
70 _experimenter = reader.read("!L")[0]
71 assert(_experimenter == 6035143)
72 _subtype = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -070073 assert(_subtype == 1)
Dan Talaycof6202252013-07-02 01:00:29 -070074 obj.dest_port = reader.read("!L")[0]
75 obj.vlan_tag = reader.read("!L")[0]
76 obj.copy_stage = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -070077 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -070078 return obj
79
80 def __eq__(self, other):
81 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -070082 if self.dest_port != other.dest_port: return False
83 if self.vlan_tag != other.vlan_tag: return False
84 if self.copy_stage != other.copy_stage: return False
Rich Laneb658ddd2013-03-12 10:15:10 -070085 return True
86
87 def __ne__(self, other):
88 return not self.__eq__(other)
89
90 def show(self):
91 import loxi.pp
92 return loxi.pp.pp(self)
93
94 def pretty_print(self, q):
95 q.text("bsn_mirror {")
96 with q.group():
97 with q.indent(2):
98 q.breakable()
99 q.text("dest_port = ");
100 q.text("%#x" % self.dest_port)
101 q.text(","); q.breakable()
102 q.text("vlan_tag = ");
103 q.text("%#x" % self.vlan_tag)
104 q.text(","); q.breakable()
105 q.text("copy_stage = ");
106 q.text("%#x" % self.copy_stage)
Rich Laneb658ddd2013-03-12 10:15:10 -0700107 q.breakable()
108 q.text('}')
109
110class bsn_set_tunnel_dst(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700111 type = 65535
112 experimenter = 6035143
Rich Laneb658ddd2013-03-12 10:15:10 -0700113 subtype = 2
114
115 def __init__(self, dst=None):
116 if dst != None:
117 self.dst = dst
118 else:
119 self.dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700120 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700121
122 def pack(self):
123 packed = []
124 packed.append(struct.pack("!H", self.type))
125 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
126 packed.append(struct.pack("!L", self.experimenter))
127 packed.append(struct.pack("!L", self.subtype))
128 packed.append(struct.pack("!L", self.dst))
129 length = sum([len(x) for x in packed])
130 packed[1] = struct.pack("!H", length)
131 return ''.join(packed)
132
133 @staticmethod
134 def unpack(buf):
135 obj = bsn_set_tunnel_dst()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700136 if type(buf) == loxi.generic_util.OFReader:
137 reader = buf
138 else:
139 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700140 _type = reader.read("!H")[0]
141 assert(_type == 65535)
142 _len = reader.read("!H")[0]
143 _experimenter = reader.read("!L")[0]
144 assert(_experimenter == 6035143)
145 _subtype = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700146 assert(_subtype == 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700147 obj.dst = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700148 return obj
149
150 def __eq__(self, other):
151 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700152 if self.dst != other.dst: return False
153 return True
154
155 def __ne__(self, other):
156 return not self.__eq__(other)
157
158 def show(self):
159 import loxi.pp
160 return loxi.pp.pp(self)
161
162 def pretty_print(self, q):
163 q.text("bsn_set_tunnel_dst {")
164 with q.group():
165 with q.indent(2):
166 q.breakable()
167 q.text("dst = ");
168 q.text("%#x" % self.dst)
169 q.breakable()
170 q.text('}')
171
172class enqueue(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700173 type = 11
Rich Laneb658ddd2013-03-12 10:15:10 -0700174
Rich Lanec2ee4b82013-04-24 17:12:38 -0700175 def __init__(self, port=None, queue_id=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700176 if port != None:
177 self.port = port
178 else:
179 self.port = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700180 if queue_id != None:
181 self.queue_id = queue_id
182 else:
183 self.queue_id = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700184 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700185
186 def pack(self):
187 packed = []
188 packed.append(struct.pack("!H", self.type))
189 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700190 packed.append(util.pack_port_no(self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700191 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700192 packed.append(struct.pack("!L", self.queue_id))
193 length = sum([len(x) for x in packed])
194 packed[1] = struct.pack("!H", length)
195 return ''.join(packed)
196
197 @staticmethod
198 def unpack(buf):
199 obj = enqueue()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700200 if type(buf) == loxi.generic_util.OFReader:
201 reader = buf
202 else:
203 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700204 _type = reader.read("!H")[0]
205 assert(_type == 11)
206 _len = reader.read("!H")[0]
207 obj.port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700208 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700209 obj.queue_id = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700210 return obj
211
212 def __eq__(self, other):
213 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700214 if self.port != other.port: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700215 if self.queue_id != other.queue_id: return False
216 return True
217
218 def __ne__(self, other):
219 return not self.__eq__(other)
220
221 def show(self):
222 import loxi.pp
223 return loxi.pp.pp(self)
224
225 def pretty_print(self, q):
226 q.text("enqueue {")
227 with q.group():
228 with q.indent(2):
229 q.breakable()
230 q.text("port = ");
231 q.text(util.pretty_port(self.port))
232 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700233 q.text("queue_id = ");
234 q.text("%#x" % self.queue_id)
235 q.breakable()
236 q.text('}')
237
238class nicira_dec_ttl(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700239 type = 65535
240 experimenter = 8992
Rich Laneb658ddd2013-03-12 10:15:10 -0700241 subtype = 18
242
Rich Lanec2ee4b82013-04-24 17:12:38 -0700243 def __init__(self):
244 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700245
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("!H", self.subtype))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700252 packed.append('\x00' * 2)
253 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700254 length = sum([len(x) for x in packed])
255 packed[1] = struct.pack("!H", length)
256 return ''.join(packed)
257
258 @staticmethod
259 def unpack(buf):
260 obj = nicira_dec_ttl()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700261 if type(buf) == loxi.generic_util.OFReader:
262 reader = buf
263 else:
264 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700265 _type = reader.read("!H")[0]
266 assert(_type == 65535)
267 _len = reader.read("!H")[0]
268 _experimenter = reader.read("!L")[0]
269 assert(_experimenter == 8992)
270 _subtype = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700271 assert(_subtype == 18)
272 reader.skip(2)
273 reader.skip(4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700274 return obj
275
276 def __eq__(self, other):
277 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700278 return True
279
280 def __ne__(self, other):
281 return not self.__eq__(other)
282
283 def show(self):
284 import loxi.pp
285 return loxi.pp.pp(self)
286
287 def pretty_print(self, q):
288 q.text("nicira_dec_ttl {")
289 with q.group():
290 with q.indent(2):
291 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700292 q.breakable()
293 q.text('}')
294
295class output(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700296 type = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700297
298 def __init__(self, port=None, max_len=None):
299 if port != None:
300 self.port = port
301 else:
302 self.port = 0
303 if max_len != None:
304 self.max_len = max_len
305 else:
306 self.max_len = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700307 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700308
309 def pack(self):
310 packed = []
311 packed.append(struct.pack("!H", self.type))
312 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700313 packed.append(util.pack_port_no(self.port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700314 packed.append(struct.pack("!H", self.max_len))
315 length = sum([len(x) for x in packed])
316 packed[1] = struct.pack("!H", length)
317 return ''.join(packed)
318
319 @staticmethod
320 def unpack(buf):
321 obj = output()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700322 if type(buf) == loxi.generic_util.OFReader:
323 reader = buf
324 else:
325 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700326 _type = reader.read("!H")[0]
327 assert(_type == 0)
328 _len = reader.read("!H")[0]
329 obj.port = util.unpack_port_no(reader)
330 obj.max_len = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700331 return obj
332
333 def __eq__(self, other):
334 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700335 if self.port != other.port: return False
336 if self.max_len != other.max_len: return False
337 return True
338
339 def __ne__(self, other):
340 return not self.__eq__(other)
341
342 def show(self):
343 import loxi.pp
344 return loxi.pp.pp(self)
345
346 def pretty_print(self, q):
347 q.text("output {")
348 with q.group():
349 with q.indent(2):
350 q.breakable()
351 q.text("port = ");
352 q.text(util.pretty_port(self.port))
353 q.text(","); q.breakable()
354 q.text("max_len = ");
355 q.text("%#x" % self.max_len)
356 q.breakable()
357 q.text('}')
358
359class set_dl_dst(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700360 type = 5
Rich Laneb658ddd2013-03-12 10:15:10 -0700361
Rich Lanec2ee4b82013-04-24 17:12:38 -0700362 def __init__(self, dl_addr=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700363 if dl_addr != None:
364 self.dl_addr = dl_addr
365 else:
366 self.dl_addr = [0,0,0,0,0,0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700367 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700368
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("!6B", *self.dl_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700374 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700375 length = sum([len(x) for x in packed])
376 packed[1] = struct.pack("!H", length)
377 return ''.join(packed)
378
379 @staticmethod
380 def unpack(buf):
381 obj = set_dl_dst()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700382 if type(buf) == loxi.generic_util.OFReader:
383 reader = buf
384 else:
385 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700386 _type = reader.read("!H")[0]
387 assert(_type == 5)
388 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700389 obj.dl_addr = list(reader.read('!6B'))
390 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700391 return obj
392
393 def __eq__(self, other):
394 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700395 if self.dl_addr != other.dl_addr: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700396 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("set_dl_dst {")
407 with q.group():
408 with q.indent(2):
409 q.breakable()
410 q.text("dl_addr = ");
411 q.text(util.pretty_mac(self.dl_addr))
Rich Laneb658ddd2013-03-12 10:15:10 -0700412 q.breakable()
413 q.text('}')
414
415class set_dl_src(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700416 type = 4
Rich Laneb658ddd2013-03-12 10:15:10 -0700417
Rich Lanec2ee4b82013-04-24 17:12:38 -0700418 def __init__(self, dl_addr=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700419 if dl_addr != None:
420 self.dl_addr = dl_addr
421 else:
422 self.dl_addr = [0,0,0,0,0,0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700423 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700424
425 def pack(self):
426 packed = []
427 packed.append(struct.pack("!H", self.type))
428 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
429 packed.append(struct.pack("!6B", *self.dl_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700430 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700431 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 = set_dl_src()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700438 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 == 4)
444 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700445 obj.dl_addr = list(reader.read('!6B'))
446 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700447 return obj
448
449 def __eq__(self, other):
450 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700451 if self.dl_addr != other.dl_addr: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700452 return True
453
454 def __ne__(self, other):
455 return not self.__eq__(other)
456
457 def show(self):
458 import loxi.pp
459 return loxi.pp.pp(self)
460
461 def pretty_print(self, q):
462 q.text("set_dl_src {")
463 with q.group():
464 with q.indent(2):
465 q.breakable()
466 q.text("dl_addr = ");
467 q.text(util.pretty_mac(self.dl_addr))
Rich Laneb658ddd2013-03-12 10:15:10 -0700468 q.breakable()
469 q.text('}')
470
471class set_nw_dst(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700472 type = 7
Rich Laneb658ddd2013-03-12 10:15:10 -0700473
474 def __init__(self, nw_addr=None):
475 if nw_addr != None:
476 self.nw_addr = nw_addr
477 else:
478 self.nw_addr = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700479 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700480
481 def pack(self):
482 packed = []
483 packed.append(struct.pack("!H", self.type))
484 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
485 packed.append(struct.pack("!L", self.nw_addr))
486 length = sum([len(x) for x in packed])
487 packed[1] = struct.pack("!H", length)
488 return ''.join(packed)
489
490 @staticmethod
491 def unpack(buf):
492 obj = set_nw_dst()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700493 if type(buf) == loxi.generic_util.OFReader:
494 reader = buf
495 else:
496 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700497 _type = reader.read("!H")[0]
498 assert(_type == 7)
499 _len = reader.read("!H")[0]
500 obj.nw_addr = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700501 return obj
502
503 def __eq__(self, other):
504 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700505 if self.nw_addr != other.nw_addr: return False
506 return True
507
508 def __ne__(self, other):
509 return not self.__eq__(other)
510
511 def show(self):
512 import loxi.pp
513 return loxi.pp.pp(self)
514
515 def pretty_print(self, q):
516 q.text("set_nw_dst {")
517 with q.group():
518 with q.indent(2):
519 q.breakable()
520 q.text("nw_addr = ");
521 q.text("%#x" % self.nw_addr)
522 q.breakable()
523 q.text('}')
524
525class set_nw_src(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700526 type = 6
Rich Laneb658ddd2013-03-12 10:15:10 -0700527
528 def __init__(self, nw_addr=None):
529 if nw_addr != None:
530 self.nw_addr = nw_addr
531 else:
532 self.nw_addr = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700533 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700534
535 def pack(self):
536 packed = []
537 packed.append(struct.pack("!H", self.type))
538 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
539 packed.append(struct.pack("!L", self.nw_addr))
540 length = sum([len(x) for x in packed])
541 packed[1] = struct.pack("!H", length)
542 return ''.join(packed)
543
544 @staticmethod
545 def unpack(buf):
546 obj = set_nw_src()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700547 if type(buf) == loxi.generic_util.OFReader:
548 reader = buf
549 else:
550 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700551 _type = reader.read("!H")[0]
552 assert(_type == 6)
553 _len = reader.read("!H")[0]
554 obj.nw_addr = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700555 return obj
556
557 def __eq__(self, other):
558 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700559 if self.nw_addr != other.nw_addr: return False
560 return True
561
562 def __ne__(self, other):
563 return not self.__eq__(other)
564
565 def show(self):
566 import loxi.pp
567 return loxi.pp.pp(self)
568
569 def pretty_print(self, q):
570 q.text("set_nw_src {")
571 with q.group():
572 with q.indent(2):
573 q.breakable()
574 q.text("nw_addr = ");
575 q.text("%#x" % self.nw_addr)
576 q.breakable()
577 q.text('}')
578
579class set_nw_tos(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700580 type = 8
Rich Laneb658ddd2013-03-12 10:15:10 -0700581
Rich Lanec2ee4b82013-04-24 17:12:38 -0700582 def __init__(self, nw_tos=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700583 if nw_tos != None:
584 self.nw_tos = nw_tos
585 else:
586 self.nw_tos = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700587 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700588
589 def pack(self):
590 packed = []
591 packed.append(struct.pack("!H", self.type))
592 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
593 packed.append(struct.pack("!B", self.nw_tos))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700594 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700595 length = sum([len(x) for x in packed])
596 packed[1] = struct.pack("!H", length)
597 return ''.join(packed)
598
599 @staticmethod
600 def unpack(buf):
601 obj = set_nw_tos()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700602 if type(buf) == loxi.generic_util.OFReader:
603 reader = buf
604 else:
605 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700606 _type = reader.read("!H")[0]
607 assert(_type == 8)
608 _len = reader.read("!H")[0]
609 obj.nw_tos = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700610 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700611 return obj
612
613 def __eq__(self, other):
614 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700615 if self.nw_tos != other.nw_tos: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700616 return True
617
618 def __ne__(self, other):
619 return not self.__eq__(other)
620
621 def show(self):
622 import loxi.pp
623 return loxi.pp.pp(self)
624
625 def pretty_print(self, q):
626 q.text("set_nw_tos {")
627 with q.group():
628 with q.indent(2):
629 q.breakable()
630 q.text("nw_tos = ");
631 q.text("%#x" % self.nw_tos)
Rich Laneb658ddd2013-03-12 10:15:10 -0700632 q.breakable()
633 q.text('}')
634
635class set_tp_dst(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700636 type = 10
Rich Laneb658ddd2013-03-12 10:15:10 -0700637
Rich Lanec2ee4b82013-04-24 17:12:38 -0700638 def __init__(self, tp_port=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700639 if tp_port != None:
640 self.tp_port = tp_port
641 else:
642 self.tp_port = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700643 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700644
645 def pack(self):
646 packed = []
647 packed.append(struct.pack("!H", self.type))
648 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
649 packed.append(struct.pack("!H", self.tp_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700650 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700651 length = sum([len(x) for x in packed])
652 packed[1] = struct.pack("!H", length)
653 return ''.join(packed)
654
655 @staticmethod
656 def unpack(buf):
657 obj = set_tp_dst()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700658 if type(buf) == loxi.generic_util.OFReader:
659 reader = buf
660 else:
661 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700662 _type = reader.read("!H")[0]
663 assert(_type == 10)
664 _len = reader.read("!H")[0]
665 obj.tp_port = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700666 reader.skip(2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700667 return obj
668
669 def __eq__(self, other):
670 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700671 if self.tp_port != other.tp_port: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700672 return True
673
674 def __ne__(self, other):
675 return not self.__eq__(other)
676
677 def show(self):
678 import loxi.pp
679 return loxi.pp.pp(self)
680
681 def pretty_print(self, q):
682 q.text("set_tp_dst {")
683 with q.group():
684 with q.indent(2):
685 q.breakable()
686 q.text("tp_port = ");
687 q.text("%#x" % self.tp_port)
Rich Laneb658ddd2013-03-12 10:15:10 -0700688 q.breakable()
689 q.text('}')
690
691class set_tp_src(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700692 type = 9
Rich Laneb658ddd2013-03-12 10:15:10 -0700693
Rich Lanec2ee4b82013-04-24 17:12:38 -0700694 def __init__(self, tp_port=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700695 if tp_port != None:
696 self.tp_port = tp_port
697 else:
698 self.tp_port = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700699 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700700
701 def pack(self):
702 packed = []
703 packed.append(struct.pack("!H", self.type))
704 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
705 packed.append(struct.pack("!H", self.tp_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700706 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700707 length = sum([len(x) for x in packed])
708 packed[1] = struct.pack("!H", length)
709 return ''.join(packed)
710
711 @staticmethod
712 def unpack(buf):
713 obj = set_tp_src()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700714 if type(buf) == loxi.generic_util.OFReader:
715 reader = buf
716 else:
717 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700718 _type = reader.read("!H")[0]
719 assert(_type == 9)
720 _len = reader.read("!H")[0]
721 obj.tp_port = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700722 reader.skip(2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700723 return obj
724
725 def __eq__(self, other):
726 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700727 if self.tp_port != other.tp_port: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700728 return True
729
730 def __ne__(self, other):
731 return not self.__eq__(other)
732
733 def show(self):
734 import loxi.pp
735 return loxi.pp.pp(self)
736
737 def pretty_print(self, q):
738 q.text("set_tp_src {")
739 with q.group():
740 with q.indent(2):
741 q.breakable()
742 q.text("tp_port = ");
743 q.text("%#x" % self.tp_port)
Rich Laneb658ddd2013-03-12 10:15:10 -0700744 q.breakable()
745 q.text('}')
746
747class set_vlan_pcp(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700748 type = 2
Rich Laneb658ddd2013-03-12 10:15:10 -0700749
Rich Lanec2ee4b82013-04-24 17:12:38 -0700750 def __init__(self, vlan_pcp=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700751 if vlan_pcp != None:
752 self.vlan_pcp = vlan_pcp
753 else:
754 self.vlan_pcp = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700755 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700756
757 def pack(self):
758 packed = []
759 packed.append(struct.pack("!H", self.type))
760 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
761 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700762 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700763 length = sum([len(x) for x in packed])
764 packed[1] = struct.pack("!H", length)
765 return ''.join(packed)
766
767 @staticmethod
768 def unpack(buf):
769 obj = set_vlan_pcp()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700770 if type(buf) == loxi.generic_util.OFReader:
771 reader = buf
772 else:
773 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700774 _type = reader.read("!H")[0]
775 assert(_type == 2)
776 _len = reader.read("!H")[0]
777 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700778 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700779 return obj
780
781 def __eq__(self, other):
782 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700783 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700784 return True
785
786 def __ne__(self, other):
787 return not self.__eq__(other)
788
789 def show(self):
790 import loxi.pp
791 return loxi.pp.pp(self)
792
793 def pretty_print(self, q):
794 q.text("set_vlan_pcp {")
795 with q.group():
796 with q.indent(2):
797 q.breakable()
798 q.text("vlan_pcp = ");
799 q.text("%#x" % self.vlan_pcp)
Rich Laneb658ddd2013-03-12 10:15:10 -0700800 q.breakable()
801 q.text('}')
802
803class set_vlan_vid(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700804 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -0700805
Rich Lanec2ee4b82013-04-24 17:12:38 -0700806 def __init__(self, vlan_vid=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700807 if vlan_vid != None:
808 self.vlan_vid = vlan_vid
809 else:
810 self.vlan_vid = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700811 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700812
813 def pack(self):
814 packed = []
815 packed.append(struct.pack("!H", self.type))
816 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
817 packed.append(struct.pack("!H", self.vlan_vid))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700818 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700819 length = sum([len(x) for x in packed])
820 packed[1] = struct.pack("!H", length)
821 return ''.join(packed)
822
823 @staticmethod
824 def unpack(buf):
825 obj = set_vlan_vid()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700826 if type(buf) == loxi.generic_util.OFReader:
827 reader = buf
828 else:
829 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700830 _type = reader.read("!H")[0]
831 assert(_type == 1)
832 _len = reader.read("!H")[0]
833 obj.vlan_vid = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700834 reader.skip(2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700835 return obj
836
837 def __eq__(self, other):
838 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700839 if self.vlan_vid != other.vlan_vid: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700840 return True
841
842 def __ne__(self, other):
843 return not self.__eq__(other)
844
845 def show(self):
846 import loxi.pp
847 return loxi.pp.pp(self)
848
849 def pretty_print(self, q):
850 q.text("set_vlan_vid {")
851 with q.group():
852 with q.indent(2):
853 q.breakable()
854 q.text("vlan_vid = ");
855 q.text("%#x" % self.vlan_vid)
Rich Laneb658ddd2013-03-12 10:15:10 -0700856 q.breakable()
857 q.text('}')
858
859class strip_vlan(Action):
Dan Talaycof6202252013-07-02 01:00:29 -0700860 type = 3
Rich Laneb658ddd2013-03-12 10:15:10 -0700861
Rich Lanec2ee4b82013-04-24 17:12:38 -0700862 def __init__(self):
863 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700864
865 def pack(self):
866 packed = []
867 packed.append(struct.pack("!H", self.type))
868 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700869 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700870 length = sum([len(x) for x in packed])
871 packed[1] = struct.pack("!H", length)
872 return ''.join(packed)
873
874 @staticmethod
875 def unpack(buf):
876 obj = strip_vlan()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700877 if type(buf) == loxi.generic_util.OFReader:
878 reader = buf
879 else:
880 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700881 _type = reader.read("!H")[0]
882 assert(_type == 3)
883 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700884 reader.skip(4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700885 return obj
886
887 def __eq__(self, other):
888 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700889 return True
890
891 def __ne__(self, other):
892 return not self.__eq__(other)
893
894 def show(self):
895 import loxi.pp
896 return loxi.pp.pp(self)
897
898 def pretty_print(self, q):
899 q.text("strip_vlan {")
900 with q.group():
901 with q.indent(2):
902 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700903 q.breakable()
904 q.text('}')
905
906
Rich Lane6f4978c2013-10-20 21:33:52 -0700907def parse_experimenter(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700908 experimenter, = reader.peek("!4xL")
Rich Laneb658ddd2013-03-12 10:15:10 -0700909 if experimenter == 0x005c16c7: # Big Switch Networks
Rich Lanec2ee4b82013-04-24 17:12:38 -0700910 subtype, = reader.peek("!8xL")
Rich Laneb658ddd2013-03-12 10:15:10 -0700911 elif experimenter == 0x00002320: # Nicira
Rich Lanec2ee4b82013-04-24 17:12:38 -0700912 subtype, = reader.peek("!8xH")
Rich Laneb658ddd2013-03-12 10:15:10 -0700913 else:
914 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
915
916 if subtype in experimenter_parsers[experimenter]:
Rich Lanec2ee4b82013-04-24 17:12:38 -0700917 return experimenter_parsers[experimenter][subtype](reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700918 else:
919 raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
920
921parsers = {
Rich Laneb658ddd2013-03-12 10:15:10 -0700922 const.OFPAT_OUTPUT : output.unpack,
Rich Laneb658ddd2013-03-12 10:15:10 -0700923 const.OFPAT_SET_VLAN_VID : set_vlan_vid.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -0700924 const.OFPAT_SET_VLAN_PCP : set_vlan_pcp.unpack,
Rich Laneb658ddd2013-03-12 10:15:10 -0700925 const.OFPAT_STRIP_VLAN : strip_vlan.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -0700926 const.OFPAT_SET_DL_SRC : set_dl_src.unpack,
927 const.OFPAT_SET_DL_DST : set_dl_dst.unpack,
928 const.OFPAT_SET_NW_SRC : set_nw_src.unpack,
929 const.OFPAT_SET_NW_DST : set_nw_dst.unpack,
930 const.OFPAT_SET_NW_TOS : set_nw_tos.unpack,
931 const.OFPAT_SET_TP_SRC : set_tp_src.unpack,
932 const.OFPAT_SET_TP_DST : set_tp_dst.unpack,
933 const.OFPAT_ENQUEUE : enqueue.unpack,
Rich Lane6f4978c2013-10-20 21:33:52 -0700934 const.OFPAT_EXPERIMENTER : parse_experimenter,
Rich Laneb658ddd2013-03-12 10:15:10 -0700935}
936
937experimenter_parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -0700938 8992 : {
Rich Laneb658ddd2013-03-12 10:15:10 -0700939 18: nicira_dec_ttl.unpack,
940 },
Dan Talaycof6202252013-07-02 01:00:29 -0700941 6035143 : {
Rich Laneb658ddd2013-03-12 10:15:10 -0700942 1: bsn_mirror.unpack,
943 2: bsn_set_tunnel_dst.unpack,
944 },
945}