blob: f5b75e42c51b0f330833120490000d45acb6d369 [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2# Copyright (c) 2011, 2012 Open Networking Foundation
3# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
4
5# Automatically generated by LOXI from template message.py
6# Do not modify
7
8import struct
9import loxi
10import const
11import common
12import action # for unpack_list
13import instruction # for unpack_list
14import util
15import loxi.generic_util
16
17class Message(object):
18 version = const.OFP_VERSION
19 type = None # override in subclass
20 xid = None
21
22class aggregate_stats_reply(Message):
23 version = const.OFP_VERSION
24 type = const.OFPT_STATS_REPLY
25 stats_type = const.OFPST_AGGREGATE
26
27 def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None):
28 self.xid = xid
29 if flags != None:
30 self.flags = flags
31 else:
32 self.flags = 0
33 if packet_count != None:
34 self.packet_count = packet_count
35 else:
36 self.packet_count = 0
37 if byte_count != None:
38 self.byte_count = byte_count
39 else:
40 self.byte_count = 0
41 if flow_count != None:
42 self.flow_count = flow_count
43 else:
44 self.flow_count = 0
45
46 def pack(self):
47 packed = []
48 packed.append(struct.pack("!B", self.version))
49 packed.append(struct.pack("!B", self.type))
50 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
51 packed.append(struct.pack("!L", self.xid))
52 packed.append(struct.pack("!H", self.stats_type))
53 packed.append(struct.pack("!H", self.flags))
54 packed.append('\x00' * 4)
55 packed.append(struct.pack("!Q", self.packet_count))
56 packed.append(struct.pack("!Q", self.byte_count))
57 packed.append(struct.pack("!L", self.flow_count))
58 packed.append('\x00' * 4)
59 length = sum([len(x) for x in packed])
60 packed[2] = struct.pack("!H", length)
61 return ''.join(packed)
62
63 @staticmethod
64 def unpack(buf):
65 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
66 obj = aggregate_stats_reply()
67 if type(buf) == loxi.generic_util.OFReader:
68 reader = buf
69 else:
70 reader = loxi.generic_util.OFReader(buf)
71 _version = reader.read('!B')[0]
72 assert(_version == const.OFP_VERSION)
73 _type = reader.read('!B')[0]
74 assert(_type == const.OFPT_STATS_REPLY)
75 _length = reader.read('!H')[0]
76 obj.xid = reader.read('!L')[0]
77 _stats_type = reader.read('!H')[0]
78 assert(_stats_type == const.OFPST_AGGREGATE)
79 obj.flags = reader.read('!H')[0]
80 reader.skip(4)
81 obj.packet_count = reader.read('!Q')[0]
82 obj.byte_count = reader.read('!Q')[0]
83 obj.flow_count = reader.read('!L')[0]
84 reader.skip(4)
85 return obj
86
87 def __eq__(self, other):
88 if type(self) != type(other): return False
89 if self.version != other.version: return False
90 if self.type != other.type: return False
91 if self.xid != other.xid: return False
92 if self.flags != other.flags: return False
93 if self.packet_count != other.packet_count: return False
94 if self.byte_count != other.byte_count: return False
95 if self.flow_count != other.flow_count: return False
96 return True
97
98 def __ne__(self, other):
99 return not self.__eq__(other)
100
101 def __str__(self):
102 return self.show()
103
104 def show(self):
105 import loxi.pp
106 return loxi.pp.pp(self)
107
108 def pretty_print(self, q):
109 q.text("aggregate_stats_reply {")
110 with q.group():
111 with q.indent(2):
112 q.breakable()
113 q.text("xid = ");
114 if self.xid != None:
115 q.text("%#x" % self.xid)
116 else:
117 q.text('None')
118 q.text(","); q.breakable()
119 q.text("flags = ");
120 q.text("%#x" % self.flags)
121 q.text(","); q.breakable()
122 q.text("packet_count = ");
123 q.text("%#x" % self.packet_count)
124 q.text(","); q.breakable()
125 q.text("byte_count = ");
126 q.text("%#x" % self.byte_count)
127 q.text(","); q.breakable()
128 q.text("flow_count = ");
129 q.text("%#x" % self.flow_count)
130 q.breakable()
131 q.text('}')
132
133class aggregate_stats_request(Message):
134 version = const.OFP_VERSION
135 type = const.OFPT_STATS_REQUEST
136 stats_type = const.OFPST_AGGREGATE
137
138 def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
139 self.xid = xid
140 if flags != None:
141 self.flags = flags
142 else:
143 self.flags = 0
144 if table_id != None:
145 self.table_id = table_id
146 else:
147 self.table_id = 0
148 if out_port != None:
149 self.out_port = out_port
150 else:
151 self.out_port = 0
152 if out_group != None:
153 self.out_group = out_group
154 else:
155 self.out_group = 0
156 if cookie != None:
157 self.cookie = cookie
158 else:
159 self.cookie = 0
160 if cookie_mask != None:
161 self.cookie_mask = cookie_mask
162 else:
163 self.cookie_mask = 0
164 if match != None:
165 self.match = match
166 else:
167 self.match = common.match()
168
169 def pack(self):
170 packed = []
171 packed.append(struct.pack("!B", self.version))
172 packed.append(struct.pack("!B", self.type))
173 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
174 packed.append(struct.pack("!L", self.xid))
175 packed.append(struct.pack("!H", self.stats_type))
176 packed.append(struct.pack("!H", self.flags))
177 packed.append('\x00' * 4)
178 packed.append(struct.pack("!B", self.table_id))
179 packed.append('\x00' * 3)
180 packed.append(struct.pack("!L", self.out_port))
181 packed.append(struct.pack("!L", self.out_group))
182 packed.append('\x00' * 4)
183 packed.append(struct.pack("!Q", self.cookie))
184 packed.append(struct.pack("!Q", self.cookie_mask))
185 packed.append(self.match.pack())
186 length = sum([len(x) for x in packed])
187 packed[2] = struct.pack("!H", length)
188 return ''.join(packed)
189
190 @staticmethod
191 def unpack(buf):
192 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
193 obj = aggregate_stats_request()
194 if type(buf) == loxi.generic_util.OFReader:
195 reader = buf
196 else:
197 reader = loxi.generic_util.OFReader(buf)
198 _version = reader.read('!B')[0]
199 assert(_version == const.OFP_VERSION)
200 _type = reader.read('!B')[0]
201 assert(_type == const.OFPT_STATS_REQUEST)
202 _length = reader.read('!H')[0]
203 obj.xid = reader.read('!L')[0]
204 _stats_type = reader.read('!H')[0]
205 assert(_stats_type == const.OFPST_AGGREGATE)
206 obj.flags = reader.read('!H')[0]
207 reader.skip(4)
208 obj.table_id = reader.read('!B')[0]
209 reader.skip(3)
210 obj.out_port = reader.read('!L')[0]
211 obj.out_group = reader.read('!L')[0]
212 reader.skip(4)
213 obj.cookie = reader.read('!Q')[0]
214 obj.cookie_mask = reader.read('!Q')[0]
215 obj.match = common.match.unpack(reader)
216 return obj
217
218 def __eq__(self, other):
219 if type(self) != type(other): return False
220 if self.version != other.version: return False
221 if self.type != other.type: return False
222 if self.xid != other.xid: return False
223 if self.flags != other.flags: return False
224 if self.table_id != other.table_id: return False
225 if self.out_port != other.out_port: return False
226 if self.out_group != other.out_group: return False
227 if self.cookie != other.cookie: return False
228 if self.cookie_mask != other.cookie_mask: return False
229 if self.match != other.match: return False
230 return True
231
232 def __ne__(self, other):
233 return not self.__eq__(other)
234
235 def __str__(self):
236 return self.show()
237
238 def show(self):
239 import loxi.pp
240 return loxi.pp.pp(self)
241
242 def pretty_print(self, q):
243 q.text("aggregate_stats_request {")
244 with q.group():
245 with q.indent(2):
246 q.breakable()
247 q.text("xid = ");
248 if self.xid != None:
249 q.text("%#x" % self.xid)
250 else:
251 q.text('None')
252 q.text(","); q.breakable()
253 q.text("flags = ");
254 q.text("%#x" % self.flags)
255 q.text(","); q.breakable()
256 q.text("table_id = ");
257 q.text("%#x" % self.table_id)
258 q.text(","); q.breakable()
259 q.text("out_port = ");
260 q.text(util.pretty_port(self.out_port))
261 q.text(","); q.breakable()
262 q.text("out_group = ");
263 q.text("%#x" % self.out_group)
264 q.text(","); q.breakable()
265 q.text("cookie = ");
266 q.text("%#x" % self.cookie)
267 q.text(","); q.breakable()
268 q.text("cookie_mask = ");
269 q.text("%#x" % self.cookie_mask)
270 q.text(","); q.breakable()
271 q.text("match = ");
272 q.pp(self.match)
273 q.breakable()
274 q.text('}')
275
276class barrier_reply(Message):
277 version = const.OFP_VERSION
278 type = const.OFPT_BARRIER_REPLY
279
280 def __init__(self, xid=None):
281 self.xid = xid
282
283 def pack(self):
284 packed = []
285 packed.append(struct.pack("!B", self.version))
286 packed.append(struct.pack("!B", self.type))
287 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
288 packed.append(struct.pack("!L", self.xid))
289 length = sum([len(x) for x in packed])
290 packed[2] = struct.pack("!H", length)
291 return ''.join(packed)
292
293 @staticmethod
294 def unpack(buf):
295 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
296 obj = barrier_reply()
297 if type(buf) == loxi.generic_util.OFReader:
298 reader = buf
299 else:
300 reader = loxi.generic_util.OFReader(buf)
301 _version = reader.read('!B')[0]
302 assert(_version == const.OFP_VERSION)
303 _type = reader.read('!B')[0]
304 assert(_type == const.OFPT_BARRIER_REPLY)
305 _length = reader.read('!H')[0]
306 obj.xid = reader.read('!L')[0]
307 return obj
308
309 def __eq__(self, other):
310 if type(self) != type(other): return False
311 if self.version != other.version: return False
312 if self.type != other.type: return False
313 if self.xid != other.xid: return False
314 return True
315
316 def __ne__(self, other):
317 return not self.__eq__(other)
318
319 def __str__(self):
320 return self.show()
321
322 def show(self):
323 import loxi.pp
324 return loxi.pp.pp(self)
325
326 def pretty_print(self, q):
327 q.text("barrier_reply {")
328 with q.group():
329 with q.indent(2):
330 q.breakable()
331 q.text("xid = ");
332 if self.xid != None:
333 q.text("%#x" % self.xid)
334 else:
335 q.text('None')
336 q.breakable()
337 q.text('}')
338
339class barrier_request(Message):
340 version = const.OFP_VERSION
341 type = const.OFPT_BARRIER_REQUEST
342
343 def __init__(self, xid=None):
344 self.xid = xid
345
346 def pack(self):
347 packed = []
348 packed.append(struct.pack("!B", self.version))
349 packed.append(struct.pack("!B", self.type))
350 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
351 packed.append(struct.pack("!L", self.xid))
352 length = sum([len(x) for x in packed])
353 packed[2] = struct.pack("!H", length)
354 return ''.join(packed)
355
356 @staticmethod
357 def unpack(buf):
358 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
359 obj = barrier_request()
360 if type(buf) == loxi.generic_util.OFReader:
361 reader = buf
362 else:
363 reader = loxi.generic_util.OFReader(buf)
364 _version = reader.read('!B')[0]
365 assert(_version == const.OFP_VERSION)
366 _type = reader.read('!B')[0]
367 assert(_type == const.OFPT_BARRIER_REQUEST)
368 _length = reader.read('!H')[0]
369 obj.xid = reader.read('!L')[0]
370 return obj
371
372 def __eq__(self, other):
373 if type(self) != type(other): return False
374 if self.version != other.version: return False
375 if self.type != other.type: return False
376 if self.xid != other.xid: return False
377 return True
378
379 def __ne__(self, other):
380 return not self.__eq__(other)
381
382 def __str__(self):
383 return self.show()
384
385 def show(self):
386 import loxi.pp
387 return loxi.pp.pp(self)
388
389 def pretty_print(self, q):
390 q.text("barrier_request {")
391 with q.group():
392 with q.indent(2):
393 q.breakable()
394 q.text("xid = ");
395 if self.xid != None:
396 q.text("%#x" % self.xid)
397 else:
398 q.text('None')
399 q.breakable()
400 q.text('}')
401
402class bsn_get_interfaces_reply(Message):
403 version = const.OFP_VERSION
404 type = const.OFPT_EXPERIMENTER
405 experimenter = 0x5c16c7
406 subtype = 10
407
408 def __init__(self, xid=None, interfaces=None):
409 self.xid = xid
410 if interfaces != None:
411 self.interfaces = interfaces
412 else:
413 self.interfaces = []
414
415 def pack(self):
416 packed = []
417 packed.append(struct.pack("!B", self.version))
418 packed.append(struct.pack("!B", self.type))
419 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
420 packed.append(struct.pack("!L", self.xid))
421 packed.append(struct.pack("!L", self.experimenter))
422 packed.append(struct.pack("!L", self.subtype))
423 packed.append("".join([x.pack() for x in self.interfaces]))
424 length = sum([len(x) for x in packed])
425 packed[2] = struct.pack("!H", length)
426 return ''.join(packed)
427
428 @staticmethod
429 def unpack(buf):
430 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
431 obj = bsn_get_interfaces_reply()
432 if type(buf) == loxi.generic_util.OFReader:
433 reader = buf
434 else:
435 reader = loxi.generic_util.OFReader(buf)
436 _version = reader.read('!B')[0]
437 assert(_version == const.OFP_VERSION)
438 _type = reader.read('!B')[0]
439 assert(_type == const.OFPT_EXPERIMENTER)
440 _length = reader.read('!H')[0]
441 obj.xid = reader.read('!L')[0]
442 _experimenter = reader.read('!L')[0]
443 assert(_experimenter == 0x5c16c7)
444 _subtype = reader.read('!L')[0]
445 assert(_subtype == 10)
446 obj.interfaces = loxi.generic_util.unpack_list(reader, common.bsn_interface.unpack)
447 return obj
448
449 def __eq__(self, other):
450 if type(self) != type(other): return False
451 if self.version != other.version: return False
452 if self.type != other.type: return False
453 if self.xid != other.xid: return False
454 if self.interfaces != other.interfaces: return False
455 return True
456
457 def __ne__(self, other):
458 return not self.__eq__(other)
459
460 def __str__(self):
461 return self.show()
462
463 def show(self):
464 import loxi.pp
465 return loxi.pp.pp(self)
466
467 def pretty_print(self, q):
468 q.text("bsn_get_interfaces_reply {")
469 with q.group():
470 with q.indent(2):
471 q.breakable()
472 q.text("xid = ");
473 if self.xid != None:
474 q.text("%#x" % self.xid)
475 else:
476 q.text('None')
477 q.text(","); q.breakable()
478 q.text("interfaces = ");
479 q.pp(self.interfaces)
480 q.breakable()
481 q.text('}')
482
483class bsn_get_interfaces_request(Message):
484 version = const.OFP_VERSION
485 type = const.OFPT_EXPERIMENTER
486 experimenter = 0x5c16c7
487 subtype = 9
488
489 def __init__(self, xid=None):
490 self.xid = xid
491
492 def pack(self):
493 packed = []
494 packed.append(struct.pack("!B", self.version))
495 packed.append(struct.pack("!B", self.type))
496 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
497 packed.append(struct.pack("!L", self.xid))
498 packed.append(struct.pack("!L", self.experimenter))
499 packed.append(struct.pack("!L", self.subtype))
500 length = sum([len(x) for x in packed])
501 packed[2] = struct.pack("!H", length)
502 return ''.join(packed)
503
504 @staticmethod
505 def unpack(buf):
506 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
507 obj = bsn_get_interfaces_request()
508 if type(buf) == loxi.generic_util.OFReader:
509 reader = buf
510 else:
511 reader = loxi.generic_util.OFReader(buf)
512 _version = reader.read('!B')[0]
513 assert(_version == const.OFP_VERSION)
514 _type = reader.read('!B')[0]
515 assert(_type == const.OFPT_EXPERIMENTER)
516 _length = reader.read('!H')[0]
517 obj.xid = reader.read('!L')[0]
518 _experimenter = reader.read('!L')[0]
519 assert(_experimenter == 0x5c16c7)
520 _subtype = reader.read('!L')[0]
521 assert(_subtype == 9)
522 return obj
523
524 def __eq__(self, other):
525 if type(self) != type(other): return False
526 if self.version != other.version: return False
527 if self.type != other.type: return False
528 if self.xid != other.xid: return False
529 return True
530
531 def __ne__(self, other):
532 return not self.__eq__(other)
533
534 def __str__(self):
535 return self.show()
536
537 def show(self):
538 import loxi.pp
539 return loxi.pp.pp(self)
540
541 def pretty_print(self, q):
542 q.text("bsn_get_interfaces_request {")
543 with q.group():
544 with q.indent(2):
545 q.breakable()
546 q.text("xid = ");
547 if self.xid != None:
548 q.text("%#x" % self.xid)
549 else:
550 q.text('None')
551 q.breakable()
552 q.text('}')
553
554class bsn_get_mirroring_reply(Message):
555 version = const.OFP_VERSION
556 type = const.OFPT_EXPERIMENTER
557 experimenter = 0x5c16c7
558 subtype = 5
559
560 def __init__(self, xid=None, report_mirror_ports=None):
561 self.xid = xid
562 if report_mirror_ports != None:
563 self.report_mirror_ports = report_mirror_ports
564 else:
565 self.report_mirror_ports = 0
566
567 def pack(self):
568 packed = []
569 packed.append(struct.pack("!B", self.version))
570 packed.append(struct.pack("!B", self.type))
571 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
572 packed.append(struct.pack("!L", self.xid))
573 packed.append(struct.pack("!L", self.experimenter))
574 packed.append(struct.pack("!L", self.subtype))
575 packed.append(struct.pack("!B", self.report_mirror_ports))
576 packed.append('\x00' * 3)
577 length = sum([len(x) for x in packed])
578 packed[2] = struct.pack("!H", length)
579 return ''.join(packed)
580
581 @staticmethod
582 def unpack(buf):
583 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
584 obj = bsn_get_mirroring_reply()
585 if type(buf) == loxi.generic_util.OFReader:
586 reader = buf
587 else:
588 reader = loxi.generic_util.OFReader(buf)
589 _version = reader.read('!B')[0]
590 assert(_version == const.OFP_VERSION)
591 _type = reader.read('!B')[0]
592 assert(_type == const.OFPT_EXPERIMENTER)
593 _length = reader.read('!H')[0]
594 obj.xid = reader.read('!L')[0]
595 _experimenter = reader.read('!L')[0]
596 assert(_experimenter == 0x5c16c7)
597 _subtype = reader.read('!L')[0]
598 assert(_subtype == 5)
599 obj.report_mirror_ports = reader.read('!B')[0]
600 reader.skip(3)
601 return obj
602
603 def __eq__(self, other):
604 if type(self) != type(other): return False
605 if self.version != other.version: return False
606 if self.type != other.type: return False
607 if self.xid != other.xid: return False
608 if self.report_mirror_ports != other.report_mirror_ports: return False
609 return True
610
611 def __ne__(self, other):
612 return not self.__eq__(other)
613
614 def __str__(self):
615 return self.show()
616
617 def show(self):
618 import loxi.pp
619 return loxi.pp.pp(self)
620
621 def pretty_print(self, q):
622 q.text("bsn_get_mirroring_reply {")
623 with q.group():
624 with q.indent(2):
625 q.breakable()
626 q.text("xid = ");
627 if self.xid != None:
628 q.text("%#x" % self.xid)
629 else:
630 q.text('None')
631 q.text(","); q.breakable()
632 q.text("report_mirror_ports = ");
633 q.text("%#x" % self.report_mirror_ports)
634 q.breakable()
635 q.text('}')
636
637class bsn_get_mirroring_request(Message):
638 version = const.OFP_VERSION
639 type = const.OFPT_EXPERIMENTER
640 experimenter = 0x5c16c7
641 subtype = 4
642
643 def __init__(self, xid=None, report_mirror_ports=None):
644 self.xid = xid
645 if report_mirror_ports != None:
646 self.report_mirror_ports = report_mirror_ports
647 else:
648 self.report_mirror_ports = 0
649
650 def pack(self):
651 packed = []
652 packed.append(struct.pack("!B", self.version))
653 packed.append(struct.pack("!B", self.type))
654 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
655 packed.append(struct.pack("!L", self.xid))
656 packed.append(struct.pack("!L", self.experimenter))
657 packed.append(struct.pack("!L", self.subtype))
658 packed.append(struct.pack("!B", self.report_mirror_ports))
659 packed.append('\x00' * 3)
660 length = sum([len(x) for x in packed])
661 packed[2] = struct.pack("!H", length)
662 return ''.join(packed)
663
664 @staticmethod
665 def unpack(buf):
666 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
667 obj = bsn_get_mirroring_request()
668 if type(buf) == loxi.generic_util.OFReader:
669 reader = buf
670 else:
671 reader = loxi.generic_util.OFReader(buf)
672 _version = reader.read('!B')[0]
673 assert(_version == const.OFP_VERSION)
674 _type = reader.read('!B')[0]
675 assert(_type == const.OFPT_EXPERIMENTER)
676 _length = reader.read('!H')[0]
677 obj.xid = reader.read('!L')[0]
678 _experimenter = reader.read('!L')[0]
679 assert(_experimenter == 0x5c16c7)
680 _subtype = reader.read('!L')[0]
681 assert(_subtype == 4)
682 obj.report_mirror_ports = reader.read('!B')[0]
683 reader.skip(3)
684 return obj
685
686 def __eq__(self, other):
687 if type(self) != type(other): return False
688 if self.version != other.version: return False
689 if self.type != other.type: return False
690 if self.xid != other.xid: return False
691 if self.report_mirror_ports != other.report_mirror_ports: return False
692 return True
693
694 def __ne__(self, other):
695 return not self.__eq__(other)
696
697 def __str__(self):
698 return self.show()
699
700 def show(self):
701 import loxi.pp
702 return loxi.pp.pp(self)
703
704 def pretty_print(self, q):
705 q.text("bsn_get_mirroring_request {")
706 with q.group():
707 with q.indent(2):
708 q.breakable()
709 q.text("xid = ");
710 if self.xid != None:
711 q.text("%#x" % self.xid)
712 else:
713 q.text('None')
714 q.text(","); q.breakable()
715 q.text("report_mirror_ports = ");
716 q.text("%#x" % self.report_mirror_ports)
717 q.breakable()
718 q.text('}')
719
720class bsn_set_mirroring(Message):
721 version = const.OFP_VERSION
722 type = const.OFPT_EXPERIMENTER
723 experimenter = 0x5c16c7
724 subtype = 3
725
726 def __init__(self, xid=None, report_mirror_ports=None):
727 self.xid = xid
728 if report_mirror_ports != None:
729 self.report_mirror_ports = report_mirror_ports
730 else:
731 self.report_mirror_ports = 0
732
733 def pack(self):
734 packed = []
735 packed.append(struct.pack("!B", self.version))
736 packed.append(struct.pack("!B", self.type))
737 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
738 packed.append(struct.pack("!L", self.xid))
739 packed.append(struct.pack("!L", self.experimenter))
740 packed.append(struct.pack("!L", self.subtype))
741 packed.append(struct.pack("!B", self.report_mirror_ports))
742 packed.append('\x00' * 3)
743 length = sum([len(x) for x in packed])
744 packed[2] = struct.pack("!H", length)
745 return ''.join(packed)
746
747 @staticmethod
748 def unpack(buf):
749 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
750 obj = bsn_set_mirroring()
751 if type(buf) == loxi.generic_util.OFReader:
752 reader = buf
753 else:
754 reader = loxi.generic_util.OFReader(buf)
755 _version = reader.read('!B')[0]
756 assert(_version == const.OFP_VERSION)
757 _type = reader.read('!B')[0]
758 assert(_type == const.OFPT_EXPERIMENTER)
759 _length = reader.read('!H')[0]
760 obj.xid = reader.read('!L')[0]
761 _experimenter = reader.read('!L')[0]
762 assert(_experimenter == 0x5c16c7)
763 _subtype = reader.read('!L')[0]
764 assert(_subtype == 3)
765 obj.report_mirror_ports = reader.read('!B')[0]
766 reader.skip(3)
767 return obj
768
769 def __eq__(self, other):
770 if type(self) != type(other): return False
771 if self.version != other.version: return False
772 if self.type != other.type: return False
773 if self.xid != other.xid: return False
774 if self.report_mirror_ports != other.report_mirror_ports: return False
775 return True
776
777 def __ne__(self, other):
778 return not self.__eq__(other)
779
780 def __str__(self):
781 return self.show()
782
783 def show(self):
784 import loxi.pp
785 return loxi.pp.pp(self)
786
787 def pretty_print(self, q):
788 q.text("bsn_set_mirroring {")
789 with q.group():
790 with q.indent(2):
791 q.breakable()
792 q.text("xid = ");
793 if self.xid != None:
794 q.text("%#x" % self.xid)
795 else:
796 q.text('None')
797 q.text(","); q.breakable()
798 q.text("report_mirror_ports = ");
799 q.text("%#x" % self.report_mirror_ports)
800 q.breakable()
801 q.text('}')
802
803class bsn_set_pktin_suppression(Message):
804 version = const.OFP_VERSION
805 type = const.OFPT_EXPERIMENTER
806 experimenter = 0x5c16c7
807 subtype = 11
808
809 def __init__(self, xid=None, enabled=None, idle_timeout=None, hard_timeout=None, priority=None, cookie=None):
810 self.xid = xid
811 if enabled != None:
812 self.enabled = enabled
813 else:
814 self.enabled = 0
815 if idle_timeout != None:
816 self.idle_timeout = idle_timeout
817 else:
818 self.idle_timeout = 0
819 if hard_timeout != None:
820 self.hard_timeout = hard_timeout
821 else:
822 self.hard_timeout = 0
823 if priority != None:
824 self.priority = priority
825 else:
826 self.priority = 0
827 if cookie != None:
828 self.cookie = cookie
829 else:
830 self.cookie = 0
831
832 def pack(self):
833 packed = []
834 packed.append(struct.pack("!B", self.version))
835 packed.append(struct.pack("!B", self.type))
836 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
837 packed.append(struct.pack("!L", self.xid))
838 packed.append(struct.pack("!L", self.experimenter))
839 packed.append(struct.pack("!L", self.subtype))
840 packed.append(struct.pack("!B", self.enabled))
841 packed.append('\x00' * 1)
842 packed.append(struct.pack("!H", self.idle_timeout))
843 packed.append(struct.pack("!H", self.hard_timeout))
844 packed.append(struct.pack("!H", self.priority))
845 packed.append(struct.pack("!Q", self.cookie))
846 length = sum([len(x) for x in packed])
847 packed[2] = struct.pack("!H", length)
848 return ''.join(packed)
849
850 @staticmethod
851 def unpack(buf):
852 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
853 obj = bsn_set_pktin_suppression()
854 if type(buf) == loxi.generic_util.OFReader:
855 reader = buf
856 else:
857 reader = loxi.generic_util.OFReader(buf)
858 _version = reader.read('!B')[0]
859 assert(_version == const.OFP_VERSION)
860 _type = reader.read('!B')[0]
861 assert(_type == const.OFPT_EXPERIMENTER)
862 _length = reader.read('!H')[0]
863 obj.xid = reader.read('!L')[0]
864 _experimenter = reader.read('!L')[0]
865 assert(_experimenter == 0x5c16c7)
866 _subtype = reader.read('!L')[0]
867 assert(_subtype == 11)
868 obj.enabled = reader.read('!B')[0]
869 reader.skip(1)
870 obj.idle_timeout = reader.read('!H')[0]
871 obj.hard_timeout = reader.read('!H')[0]
872 obj.priority = reader.read('!H')[0]
873 obj.cookie = reader.read('!Q')[0]
874 return obj
875
876 def __eq__(self, other):
877 if type(self) != type(other): return False
878 if self.version != other.version: return False
879 if self.type != other.type: return False
880 if self.xid != other.xid: return False
881 if self.enabled != other.enabled: return False
882 if self.idle_timeout != other.idle_timeout: return False
883 if self.hard_timeout != other.hard_timeout: return False
884 if self.priority != other.priority: return False
885 if self.cookie != other.cookie: return False
886 return True
887
888 def __ne__(self, other):
889 return not self.__eq__(other)
890
891 def __str__(self):
892 return self.show()
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("bsn_set_pktin_suppression {")
900 with q.group():
901 with q.indent(2):
902 q.breakable()
903 q.text("xid = ");
904 if self.xid != None:
905 q.text("%#x" % self.xid)
906 else:
907 q.text('None')
908 q.text(","); q.breakable()
909 q.text("enabled = ");
910 q.text("%#x" % self.enabled)
911 q.text(","); q.breakable()
912 q.text("idle_timeout = ");
913 q.text("%#x" % self.idle_timeout)
914 q.text(","); q.breakable()
915 q.text("hard_timeout = ");
916 q.text("%#x" % self.hard_timeout)
917 q.text(","); q.breakable()
918 q.text("priority = ");
919 q.text("%#x" % self.priority)
920 q.text(","); q.breakable()
921 q.text("cookie = ");
922 q.text("%#x" % self.cookie)
923 q.breakable()
924 q.text('}')
925
926class desc_stats_reply(Message):
927 version = const.OFP_VERSION
928 type = const.OFPT_STATS_REPLY
929 stats_type = const.OFPST_DESC
930
931 def __init__(self, xid=None, flags=None, mfr_desc=None, hw_desc=None, sw_desc=None, serial_num=None, dp_desc=None):
932 self.xid = xid
933 if flags != None:
934 self.flags = flags
935 else:
936 self.flags = 0
937 if mfr_desc != None:
938 self.mfr_desc = mfr_desc
939 else:
940 self.mfr_desc = ""
941 if hw_desc != None:
942 self.hw_desc = hw_desc
943 else:
944 self.hw_desc = ""
945 if sw_desc != None:
946 self.sw_desc = sw_desc
947 else:
948 self.sw_desc = ""
949 if serial_num != None:
950 self.serial_num = serial_num
951 else:
952 self.serial_num = ""
953 if dp_desc != None:
954 self.dp_desc = dp_desc
955 else:
956 self.dp_desc = ""
957
958 def pack(self):
959 packed = []
960 packed.append(struct.pack("!B", self.version))
961 packed.append(struct.pack("!B", self.type))
962 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
963 packed.append(struct.pack("!L", self.xid))
964 packed.append(struct.pack("!H", self.stats_type))
965 packed.append(struct.pack("!H", self.flags))
966 packed.append('\x00' * 4)
967 packed.append(struct.pack("!256s", self.mfr_desc))
968 packed.append(struct.pack("!256s", self.hw_desc))
969 packed.append(struct.pack("!256s", self.sw_desc))
970 packed.append(struct.pack("!32s", self.serial_num))
971 packed.append(struct.pack("!256s", self.dp_desc))
972 length = sum([len(x) for x in packed])
973 packed[2] = struct.pack("!H", length)
974 return ''.join(packed)
975
976 @staticmethod
977 def unpack(buf):
978 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
979 obj = desc_stats_reply()
980 if type(buf) == loxi.generic_util.OFReader:
981 reader = buf
982 else:
983 reader = loxi.generic_util.OFReader(buf)
984 _version = reader.read('!B')[0]
985 assert(_version == const.OFP_VERSION)
986 _type = reader.read('!B')[0]
987 assert(_type == const.OFPT_STATS_REPLY)
988 _length = reader.read('!H')[0]
989 obj.xid = reader.read('!L')[0]
990 _stats_type = reader.read('!H')[0]
991 assert(_stats_type == const.OFPST_DESC)
992 obj.flags = reader.read('!H')[0]
993 reader.skip(4)
994 obj.mfr_desc = reader.read("!256s")[0].rstrip("\x00")
995 obj.hw_desc = reader.read("!256s")[0].rstrip("\x00")
996 obj.sw_desc = reader.read("!256s")[0].rstrip("\x00")
997 obj.serial_num = reader.read("!32s")[0].rstrip("\x00")
998 obj.dp_desc = reader.read("!256s")[0].rstrip("\x00")
999 return obj
1000
1001 def __eq__(self, other):
1002 if type(self) != type(other): return False
1003 if self.version != other.version: return False
1004 if self.type != other.type: return False
1005 if self.xid != other.xid: return False
1006 if self.flags != other.flags: return False
1007 if self.mfr_desc != other.mfr_desc: return False
1008 if self.hw_desc != other.hw_desc: return False
1009 if self.sw_desc != other.sw_desc: return False
1010 if self.serial_num != other.serial_num: return False
1011 if self.dp_desc != other.dp_desc: return False
1012 return True
1013
1014 def __ne__(self, other):
1015 return not self.__eq__(other)
1016
1017 def __str__(self):
1018 return self.show()
1019
1020 def show(self):
1021 import loxi.pp
1022 return loxi.pp.pp(self)
1023
1024 def pretty_print(self, q):
1025 q.text("desc_stats_reply {")
1026 with q.group():
1027 with q.indent(2):
1028 q.breakable()
1029 q.text("xid = ");
1030 if self.xid != None:
1031 q.text("%#x" % self.xid)
1032 else:
1033 q.text('None')
1034 q.text(","); q.breakable()
1035 q.text("flags = ");
1036 q.text("%#x" % self.flags)
1037 q.text(","); q.breakable()
1038 q.text("mfr_desc = ");
1039 q.pp(self.mfr_desc)
1040 q.text(","); q.breakable()
1041 q.text("hw_desc = ");
1042 q.pp(self.hw_desc)
1043 q.text(","); q.breakable()
1044 q.text("sw_desc = ");
1045 q.pp(self.sw_desc)
1046 q.text(","); q.breakable()
1047 q.text("serial_num = ");
1048 q.pp(self.serial_num)
1049 q.text(","); q.breakable()
1050 q.text("dp_desc = ");
1051 q.pp(self.dp_desc)
1052 q.breakable()
1053 q.text('}')
1054
1055class desc_stats_request(Message):
1056 version = const.OFP_VERSION
1057 type = const.OFPT_STATS_REQUEST
1058 stats_type = const.OFPST_DESC
1059
1060 def __init__(self, xid=None, flags=None):
1061 self.xid = xid
1062 if flags != None:
1063 self.flags = flags
1064 else:
1065 self.flags = 0
1066
1067 def pack(self):
1068 packed = []
1069 packed.append(struct.pack("!B", self.version))
1070 packed.append(struct.pack("!B", self.type))
1071 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1072 packed.append(struct.pack("!L", self.xid))
1073 packed.append(struct.pack("!H", self.stats_type))
1074 packed.append(struct.pack("!H", self.flags))
1075 packed.append('\x00' * 4)
1076 length = sum([len(x) for x in packed])
1077 packed[2] = struct.pack("!H", length)
1078 return ''.join(packed)
1079
1080 @staticmethod
1081 def unpack(buf):
1082 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1083 obj = desc_stats_request()
1084 if type(buf) == loxi.generic_util.OFReader:
1085 reader = buf
1086 else:
1087 reader = loxi.generic_util.OFReader(buf)
1088 _version = reader.read('!B')[0]
1089 assert(_version == const.OFP_VERSION)
1090 _type = reader.read('!B')[0]
1091 assert(_type == const.OFPT_STATS_REQUEST)
1092 _length = reader.read('!H')[0]
1093 obj.xid = reader.read('!L')[0]
1094 _stats_type = reader.read('!H')[0]
1095 assert(_stats_type == const.OFPST_DESC)
1096 obj.flags = reader.read('!H')[0]
1097 reader.skip(4)
1098 return obj
1099
1100 def __eq__(self, other):
1101 if type(self) != type(other): return False
1102 if self.version != other.version: return False
1103 if self.type != other.type: return False
1104 if self.xid != other.xid: return False
1105 if self.flags != other.flags: return False
1106 return True
1107
1108 def __ne__(self, other):
1109 return not self.__eq__(other)
1110
1111 def __str__(self):
1112 return self.show()
1113
1114 def show(self):
1115 import loxi.pp
1116 return loxi.pp.pp(self)
1117
1118 def pretty_print(self, q):
1119 q.text("desc_stats_request {")
1120 with q.group():
1121 with q.indent(2):
1122 q.breakable()
1123 q.text("xid = ");
1124 if self.xid != None:
1125 q.text("%#x" % self.xid)
1126 else:
1127 q.text('None')
1128 q.text(","); q.breakable()
1129 q.text("flags = ");
1130 q.text("%#x" % self.flags)
1131 q.breakable()
1132 q.text('}')
1133
1134class echo_reply(Message):
1135 version = const.OFP_VERSION
1136 type = const.OFPT_ECHO_REPLY
1137
1138 def __init__(self, xid=None, data=None):
1139 self.xid = xid
1140 if data != None:
1141 self.data = data
1142 else:
1143 self.data = ""
1144
1145 def pack(self):
1146 packed = []
1147 packed.append(struct.pack("!B", self.version))
1148 packed.append(struct.pack("!B", self.type))
1149 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1150 packed.append(struct.pack("!L", self.xid))
1151 packed.append(self.data)
1152 length = sum([len(x) for x in packed])
1153 packed[2] = struct.pack("!H", length)
1154 return ''.join(packed)
1155
1156 @staticmethod
1157 def unpack(buf):
1158 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1159 obj = echo_reply()
1160 if type(buf) == loxi.generic_util.OFReader:
1161 reader = buf
1162 else:
1163 reader = loxi.generic_util.OFReader(buf)
1164 _version = reader.read('!B')[0]
1165 assert(_version == const.OFP_VERSION)
1166 _type = reader.read('!B')[0]
1167 assert(_type == const.OFPT_ECHO_REPLY)
1168 _length = reader.read('!H')[0]
1169 obj.xid = reader.read('!L')[0]
1170 obj.data = str(reader.read_all())
1171 return obj
1172
1173 def __eq__(self, other):
1174 if type(self) != type(other): return False
1175 if self.version != other.version: return False
1176 if self.type != other.type: return False
1177 if self.xid != other.xid: return False
1178 if self.data != other.data: return False
1179 return True
1180
1181 def __ne__(self, other):
1182 return not self.__eq__(other)
1183
1184 def __str__(self):
1185 return self.show()
1186
1187 def show(self):
1188 import loxi.pp
1189 return loxi.pp.pp(self)
1190
1191 def pretty_print(self, q):
1192 q.text("echo_reply {")
1193 with q.group():
1194 with q.indent(2):
1195 q.breakable()
1196 q.text("xid = ");
1197 if self.xid != None:
1198 q.text("%#x" % self.xid)
1199 else:
1200 q.text('None')
1201 q.text(","); q.breakable()
1202 q.text("data = ");
1203 q.pp(self.data)
1204 q.breakable()
1205 q.text('}')
1206
1207class echo_request(Message):
1208 version = const.OFP_VERSION
1209 type = const.OFPT_ECHO_REQUEST
1210
1211 def __init__(self, xid=None, data=None):
1212 self.xid = xid
1213 if data != None:
1214 self.data = data
1215 else:
1216 self.data = ""
1217
1218 def pack(self):
1219 packed = []
1220 packed.append(struct.pack("!B", self.version))
1221 packed.append(struct.pack("!B", self.type))
1222 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1223 packed.append(struct.pack("!L", self.xid))
1224 packed.append(self.data)
1225 length = sum([len(x) for x in packed])
1226 packed[2] = struct.pack("!H", length)
1227 return ''.join(packed)
1228
1229 @staticmethod
1230 def unpack(buf):
1231 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1232 obj = echo_request()
1233 if type(buf) == loxi.generic_util.OFReader:
1234 reader = buf
1235 else:
1236 reader = loxi.generic_util.OFReader(buf)
1237 _version = reader.read('!B')[0]
1238 assert(_version == const.OFP_VERSION)
1239 _type = reader.read('!B')[0]
1240 assert(_type == const.OFPT_ECHO_REQUEST)
1241 _length = reader.read('!H')[0]
1242 obj.xid = reader.read('!L')[0]
1243 obj.data = str(reader.read_all())
1244 return obj
1245
1246 def __eq__(self, other):
1247 if type(self) != type(other): return False
1248 if self.version != other.version: return False
1249 if self.type != other.type: return False
1250 if self.xid != other.xid: return False
1251 if self.data != other.data: return False
1252 return True
1253
1254 def __ne__(self, other):
1255 return not self.__eq__(other)
1256
1257 def __str__(self):
1258 return self.show()
1259
1260 def show(self):
1261 import loxi.pp
1262 return loxi.pp.pp(self)
1263
1264 def pretty_print(self, q):
1265 q.text("echo_request {")
1266 with q.group():
1267 with q.indent(2):
1268 q.breakable()
1269 q.text("xid = ");
1270 if self.xid != None:
1271 q.text("%#x" % self.xid)
1272 else:
1273 q.text('None')
1274 q.text(","); q.breakable()
1275 q.text("data = ");
1276 q.pp(self.data)
1277 q.breakable()
1278 q.text('}')
1279
1280class error_msg(Message):
1281 version = const.OFP_VERSION
1282 type = const.OFPT_ERROR
1283
1284 def __init__(self, xid=None, err_type=None, code=None, data=None):
1285 self.xid = xid
1286 if err_type != None:
1287 self.err_type = err_type
1288 else:
1289 self.err_type = 0
1290 if code != None:
1291 self.code = code
1292 else:
1293 self.code = 0
1294 if data != None:
1295 self.data = data
1296 else:
1297 self.data = ""
1298
1299 def pack(self):
1300 packed = []
1301 packed.append(struct.pack("!B", self.version))
1302 packed.append(struct.pack("!B", self.type))
1303 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1304 packed.append(struct.pack("!L", self.xid))
1305 packed.append(struct.pack("!H", self.err_type))
1306 packed.append(struct.pack("!H", self.code))
1307 packed.append(self.data)
1308 length = sum([len(x) for x in packed])
1309 packed[2] = struct.pack("!H", length)
1310 return ''.join(packed)
1311
1312 @staticmethod
1313 def unpack(buf):
1314 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1315 obj = error_msg()
1316 if type(buf) == loxi.generic_util.OFReader:
1317 reader = buf
1318 else:
1319 reader = loxi.generic_util.OFReader(buf)
1320 _version = reader.read('!B')[0]
1321 assert(_version == const.OFP_VERSION)
1322 _type = reader.read('!B')[0]
1323 assert(_type == const.OFPT_ERROR)
1324 _length = reader.read('!H')[0]
1325 obj.xid = reader.read('!L')[0]
1326 obj.err_type = reader.read('!H')[0]
1327 obj.code = reader.read('!H')[0]
1328 obj.data = str(reader.read_all())
1329 return obj
1330
1331 def __eq__(self, other):
1332 if type(self) != type(other): return False
1333 if self.version != other.version: return False
1334 if self.type != other.type: return False
1335 if self.xid != other.xid: return False
1336 if self.err_type != other.err_type: return False
1337 if self.code != other.code: return False
1338 if self.data != other.data: return False
1339 return True
1340
1341 def __ne__(self, other):
1342 return not self.__eq__(other)
1343
1344 def __str__(self):
1345 return self.show()
1346
1347 def show(self):
1348 import loxi.pp
1349 return loxi.pp.pp(self)
1350
1351 def pretty_print(self, q):
1352 q.text("error_msg {")
1353 with q.group():
1354 with q.indent(2):
1355 q.breakable()
1356 q.text("xid = ");
1357 if self.xid != None:
1358 q.text("%#x" % self.xid)
1359 else:
1360 q.text('None')
1361 q.text(","); q.breakable()
1362 q.text("err_type = ");
1363 q.text("%#x" % self.err_type)
1364 q.text(","); q.breakable()
1365 q.text("code = ");
1366 q.text("%#x" % self.code)
1367 q.text(","); q.breakable()
1368 q.text("data = ");
1369 q.pp(self.data)
1370 q.breakable()
1371 q.text('}')
1372
1373class experimenter_stats_reply(Message):
1374 version = const.OFP_VERSION
1375 type = const.OFPT_STATS_REPLY
1376 stats_type = const.OFPST_EXPERIMENTER
1377
1378 def __init__(self, xid=None, flags=None, experimenter=None, subtype=None, data=None):
1379 self.xid = xid
1380 if flags != None:
1381 self.flags = flags
1382 else:
1383 self.flags = 0
1384 if experimenter != None:
1385 self.experimenter = experimenter
1386 else:
1387 self.experimenter = 0
1388 if subtype != None:
1389 self.subtype = subtype
1390 else:
1391 self.subtype = 0
1392 if data != None:
1393 self.data = data
1394 else:
1395 self.data = ""
1396
1397 def pack(self):
1398 packed = []
1399 packed.append(struct.pack("!B", self.version))
1400 packed.append(struct.pack("!B", self.type))
1401 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1402 packed.append(struct.pack("!L", self.xid))
1403 packed.append(struct.pack("!H", self.stats_type))
1404 packed.append(struct.pack("!H", self.flags))
1405 packed.append('\x00' * 4)
1406 packed.append(struct.pack("!L", self.experimenter))
1407 packed.append(struct.pack("!L", self.subtype))
1408 packed.append(self.data)
1409 length = sum([len(x) for x in packed])
1410 packed[2] = struct.pack("!H", length)
1411 return ''.join(packed)
1412
1413 @staticmethod
1414 def unpack(buf):
1415 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1416 obj = experimenter_stats_reply()
1417 if type(buf) == loxi.generic_util.OFReader:
1418 reader = buf
1419 else:
1420 reader = loxi.generic_util.OFReader(buf)
1421 _version = reader.read('!B')[0]
1422 assert(_version == const.OFP_VERSION)
1423 _type = reader.read('!B')[0]
1424 assert(_type == const.OFPT_STATS_REPLY)
1425 _length = reader.read('!H')[0]
1426 obj.xid = reader.read('!L')[0]
1427 _stats_type = reader.read('!H')[0]
1428 assert(_stats_type == const.OFPST_EXPERIMENTER)
1429 obj.flags = reader.read('!H')[0]
1430 reader.skip(4)
1431 obj.experimenter = reader.read('!L')[0]
1432 obj.subtype = reader.read('!L')[0]
1433 obj.data = str(reader.read_all())
1434 return obj
1435
1436 def __eq__(self, other):
1437 if type(self) != type(other): return False
1438 if self.version != other.version: return False
1439 if self.type != other.type: return False
1440 if self.xid != other.xid: return False
1441 if self.flags != other.flags: return False
1442 if self.experimenter != other.experimenter: return False
1443 if self.subtype != other.subtype: return False
1444 if self.data != other.data: return False
1445 return True
1446
1447 def __ne__(self, other):
1448 return not self.__eq__(other)
1449
1450 def __str__(self):
1451 return self.show()
1452
1453 def show(self):
1454 import loxi.pp
1455 return loxi.pp.pp(self)
1456
1457 def pretty_print(self, q):
1458 q.text("experimenter_stats_reply {")
1459 with q.group():
1460 with q.indent(2):
1461 q.breakable()
1462 q.text("xid = ");
1463 if self.xid != None:
1464 q.text("%#x" % self.xid)
1465 else:
1466 q.text('None')
1467 q.text(","); q.breakable()
1468 q.text("flags = ");
1469 q.text("%#x" % self.flags)
1470 q.text(","); q.breakable()
1471 q.text("experimenter = ");
1472 q.text("%#x" % self.experimenter)
1473 q.text(","); q.breakable()
1474 q.text("subtype = ");
1475 q.text("%#x" % self.subtype)
1476 q.text(","); q.breakable()
1477 q.text("data = ");
1478 q.pp(self.data)
1479 q.breakable()
1480 q.text('}')
1481
1482class experimenter_stats_request(Message):
1483 version = const.OFP_VERSION
1484 type = const.OFPT_STATS_REQUEST
1485 stats_type = const.OFPST_EXPERIMENTER
1486
1487 def __init__(self, xid=None, flags=None, experimenter=None, subtype=None, data=None):
1488 self.xid = xid
1489 if flags != None:
1490 self.flags = flags
1491 else:
1492 self.flags = 0
1493 if experimenter != None:
1494 self.experimenter = experimenter
1495 else:
1496 self.experimenter = 0
1497 if subtype != None:
1498 self.subtype = subtype
1499 else:
1500 self.subtype = 0
1501 if data != None:
1502 self.data = data
1503 else:
1504 self.data = ""
1505
1506 def pack(self):
1507 packed = []
1508 packed.append(struct.pack("!B", self.version))
1509 packed.append(struct.pack("!B", self.type))
1510 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1511 packed.append(struct.pack("!L", self.xid))
1512 packed.append(struct.pack("!H", self.stats_type))
1513 packed.append(struct.pack("!H", self.flags))
1514 packed.append('\x00' * 4)
1515 packed.append(struct.pack("!L", self.experimenter))
1516 packed.append(struct.pack("!L", self.subtype))
1517 packed.append(self.data)
1518 length = sum([len(x) for x in packed])
1519 packed[2] = struct.pack("!H", length)
1520 return ''.join(packed)
1521
1522 @staticmethod
1523 def unpack(buf):
1524 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1525 obj = experimenter_stats_request()
1526 if type(buf) == loxi.generic_util.OFReader:
1527 reader = buf
1528 else:
1529 reader = loxi.generic_util.OFReader(buf)
1530 _version = reader.read('!B')[0]
1531 assert(_version == const.OFP_VERSION)
1532 _type = reader.read('!B')[0]
1533 assert(_type == const.OFPT_STATS_REQUEST)
1534 _length = reader.read('!H')[0]
1535 obj.xid = reader.read('!L')[0]
1536 _stats_type = reader.read('!H')[0]
1537 assert(_stats_type == const.OFPST_EXPERIMENTER)
1538 obj.flags = reader.read('!H')[0]
1539 reader.skip(4)
1540 obj.experimenter = reader.read('!L')[0]
1541 obj.subtype = reader.read('!L')[0]
1542 obj.data = str(reader.read_all())
1543 return obj
1544
1545 def __eq__(self, other):
1546 if type(self) != type(other): return False
1547 if self.version != other.version: return False
1548 if self.type != other.type: return False
1549 if self.xid != other.xid: return False
1550 if self.flags != other.flags: return False
1551 if self.experimenter != other.experimenter: return False
1552 if self.subtype != other.subtype: return False
1553 if self.data != other.data: return False
1554 return True
1555
1556 def __ne__(self, other):
1557 return not self.__eq__(other)
1558
1559 def __str__(self):
1560 return self.show()
1561
1562 def show(self):
1563 import loxi.pp
1564 return loxi.pp.pp(self)
1565
1566 def pretty_print(self, q):
1567 q.text("experimenter_stats_request {")
1568 with q.group():
1569 with q.indent(2):
1570 q.breakable()
1571 q.text("xid = ");
1572 if self.xid != None:
1573 q.text("%#x" % self.xid)
1574 else:
1575 q.text('None')
1576 q.text(","); q.breakable()
1577 q.text("flags = ");
1578 q.text("%#x" % self.flags)
1579 q.text(","); q.breakable()
1580 q.text("experimenter = ");
1581 q.text("%#x" % self.experimenter)
1582 q.text(","); q.breakable()
1583 q.text("subtype = ");
1584 q.text("%#x" % self.subtype)
1585 q.text(","); q.breakable()
1586 q.text("data = ");
1587 q.pp(self.data)
1588 q.breakable()
1589 q.text('}')
1590
1591class features_reply(Message):
1592 version = const.OFP_VERSION
1593 type = const.OFPT_FEATURES_REPLY
1594
1595 def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, reserved=None, ports=None):
1596 self.xid = xid
1597 if datapath_id != None:
1598 self.datapath_id = datapath_id
1599 else:
1600 self.datapath_id = 0
1601 if n_buffers != None:
1602 self.n_buffers = n_buffers
1603 else:
1604 self.n_buffers = 0
1605 if n_tables != None:
1606 self.n_tables = n_tables
1607 else:
1608 self.n_tables = 0
1609 if capabilities != None:
1610 self.capabilities = capabilities
1611 else:
1612 self.capabilities = 0
1613 if reserved != None:
1614 self.reserved = reserved
1615 else:
1616 self.reserved = 0
1617 if ports != None:
1618 self.ports = ports
1619 else:
1620 self.ports = []
1621
1622 def pack(self):
1623 packed = []
1624 packed.append(struct.pack("!B", self.version))
1625 packed.append(struct.pack("!B", self.type))
1626 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1627 packed.append(struct.pack("!L", self.xid))
1628 packed.append(struct.pack("!Q", self.datapath_id))
1629 packed.append(struct.pack("!L", self.n_buffers))
1630 packed.append(struct.pack("!B", self.n_tables))
1631 packed.append('\x00' * 3)
1632 packed.append(struct.pack("!L", self.capabilities))
1633 packed.append(struct.pack("!L", self.reserved))
1634 packed.append("".join([x.pack() for x in self.ports]))
1635 length = sum([len(x) for x in packed])
1636 packed[2] = struct.pack("!H", length)
1637 return ''.join(packed)
1638
1639 @staticmethod
1640 def unpack(buf):
1641 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1642 obj = features_reply()
1643 if type(buf) == loxi.generic_util.OFReader:
1644 reader = buf
1645 else:
1646 reader = loxi.generic_util.OFReader(buf)
1647 _version = reader.read('!B')[0]
1648 assert(_version == const.OFP_VERSION)
1649 _type = reader.read('!B')[0]
1650 assert(_type == const.OFPT_FEATURES_REPLY)
1651 _length = reader.read('!H')[0]
1652 obj.xid = reader.read('!L')[0]
1653 obj.datapath_id = reader.read('!Q')[0]
1654 obj.n_buffers = reader.read('!L')[0]
1655 obj.n_tables = reader.read('!B')[0]
1656 reader.skip(3)
1657 obj.capabilities = reader.read('!L')[0]
1658 obj.reserved = reader.read('!L')[0]
1659 obj.ports = loxi.generic_util.unpack_list(reader, common.port_desc.unpack)
1660 return obj
1661
1662 def __eq__(self, other):
1663 if type(self) != type(other): return False
1664 if self.version != other.version: return False
1665 if self.type != other.type: return False
1666 if self.xid != other.xid: return False
1667 if self.datapath_id != other.datapath_id: return False
1668 if self.n_buffers != other.n_buffers: return False
1669 if self.n_tables != other.n_tables: return False
1670 if self.capabilities != other.capabilities: return False
1671 if self.reserved != other.reserved: return False
1672 if self.ports != other.ports: return False
1673 return True
1674
1675 def __ne__(self, other):
1676 return not self.__eq__(other)
1677
1678 def __str__(self):
1679 return self.show()
1680
1681 def show(self):
1682 import loxi.pp
1683 return loxi.pp.pp(self)
1684
1685 def pretty_print(self, q):
1686 q.text("features_reply {")
1687 with q.group():
1688 with q.indent(2):
1689 q.breakable()
1690 q.text("xid = ");
1691 if self.xid != None:
1692 q.text("%#x" % self.xid)
1693 else:
1694 q.text('None')
1695 q.text(","); q.breakable()
1696 q.text("datapath_id = ");
1697 q.text("%#x" % self.datapath_id)
1698 q.text(","); q.breakable()
1699 q.text("n_buffers = ");
1700 q.text("%#x" % self.n_buffers)
1701 q.text(","); q.breakable()
1702 q.text("n_tables = ");
1703 q.text("%#x" % self.n_tables)
1704 q.text(","); q.breakable()
1705 q.text("capabilities = ");
1706 q.text("%#x" % self.capabilities)
1707 q.text(","); q.breakable()
1708 q.text("reserved = ");
1709 q.text("%#x" % self.reserved)
1710 q.text(","); q.breakable()
1711 q.text("ports = ");
1712 q.pp(self.ports)
1713 q.breakable()
1714 q.text('}')
1715
1716class features_request(Message):
1717 version = const.OFP_VERSION
1718 type = const.OFPT_FEATURES_REQUEST
1719
1720 def __init__(self, xid=None):
1721 self.xid = xid
1722
1723 def pack(self):
1724 packed = []
1725 packed.append(struct.pack("!B", self.version))
1726 packed.append(struct.pack("!B", self.type))
1727 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1728 packed.append(struct.pack("!L", self.xid))
1729 length = sum([len(x) for x in packed])
1730 packed[2] = struct.pack("!H", length)
1731 return ''.join(packed)
1732
1733 @staticmethod
1734 def unpack(buf):
1735 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1736 obj = features_request()
1737 if type(buf) == loxi.generic_util.OFReader:
1738 reader = buf
1739 else:
1740 reader = loxi.generic_util.OFReader(buf)
1741 _version = reader.read('!B')[0]
1742 assert(_version == const.OFP_VERSION)
1743 _type = reader.read('!B')[0]
1744 assert(_type == const.OFPT_FEATURES_REQUEST)
1745 _length = reader.read('!H')[0]
1746 obj.xid = reader.read('!L')[0]
1747 return obj
1748
1749 def __eq__(self, other):
1750 if type(self) != type(other): return False
1751 if self.version != other.version: return False
1752 if self.type != other.type: return False
1753 if self.xid != other.xid: return False
1754 return True
1755
1756 def __ne__(self, other):
1757 return not self.__eq__(other)
1758
1759 def __str__(self):
1760 return self.show()
1761
1762 def show(self):
1763 import loxi.pp
1764 return loxi.pp.pp(self)
1765
1766 def pretty_print(self, q):
1767 q.text("features_request {")
1768 with q.group():
1769 with q.indent(2):
1770 q.breakable()
1771 q.text("xid = ");
1772 if self.xid != None:
1773 q.text("%#x" % self.xid)
1774 else:
1775 q.text('None')
1776 q.breakable()
1777 q.text('}')
1778
1779class flow_add(Message):
1780 version = const.OFP_VERSION
1781 type = const.OFPT_FLOW_MOD
1782 _command = const.OFPFC_ADD
1783
1784 def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
1785 self.xid = xid
1786 if cookie != None:
1787 self.cookie = cookie
1788 else:
1789 self.cookie = 0
1790 if cookie_mask != None:
1791 self.cookie_mask = cookie_mask
1792 else:
1793 self.cookie_mask = 0
1794 if table_id != None:
1795 self.table_id = table_id
1796 else:
1797 self.table_id = 0
1798 if idle_timeout != None:
1799 self.idle_timeout = idle_timeout
1800 else:
1801 self.idle_timeout = 0
1802 if hard_timeout != None:
1803 self.hard_timeout = hard_timeout
1804 else:
1805 self.hard_timeout = 0
1806 if priority != None:
1807 self.priority = priority
1808 else:
1809 self.priority = 0
1810 if buffer_id != None:
1811 self.buffer_id = buffer_id
1812 else:
1813 self.buffer_id = 0
1814 if out_port != None:
1815 self.out_port = out_port
1816 else:
1817 self.out_port = 0
1818 if out_group != None:
1819 self.out_group = out_group
1820 else:
1821 self.out_group = 0
1822 if flags != None:
1823 self.flags = flags
1824 else:
1825 self.flags = 0
1826 if match != None:
1827 self.match = match
1828 else:
1829 self.match = common.match()
1830 if instructions != None:
1831 self.instructions = instructions
1832 else:
1833 self.instructions = []
1834
1835 def pack(self):
1836 packed = []
1837 packed.append(struct.pack("!B", self.version))
1838 packed.append(struct.pack("!B", self.type))
1839 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1840 packed.append(struct.pack("!L", self.xid))
1841 packed.append(struct.pack("!Q", self.cookie))
1842 packed.append(struct.pack("!Q", self.cookie_mask))
1843 packed.append(struct.pack("!B", self.table_id))
1844 packed.append(struct.pack("!B", self._command))
1845 packed.append(struct.pack("!H", self.idle_timeout))
1846 packed.append(struct.pack("!H", self.hard_timeout))
1847 packed.append(struct.pack("!H", self.priority))
1848 packed.append(struct.pack("!L", self.buffer_id))
1849 packed.append(struct.pack("!L", self.out_port))
1850 packed.append(struct.pack("!L", self.out_group))
1851 packed.append(struct.pack("!H", self.flags))
1852 packed.append('\x00' * 2)
1853 packed.append(self.match.pack())
1854 packed.append("".join([x.pack() for x in self.instructions]))
1855 length = sum([len(x) for x in packed])
1856 packed[2] = struct.pack("!H", length)
1857 return ''.join(packed)
1858
1859 @staticmethod
1860 def unpack(buf):
1861 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1862 obj = flow_add()
1863 if type(buf) == loxi.generic_util.OFReader:
1864 reader = buf
1865 else:
1866 reader = loxi.generic_util.OFReader(buf)
1867 _version = reader.read('!B')[0]
1868 assert(_version == const.OFP_VERSION)
1869 _type = reader.read('!B')[0]
1870 assert(_type == const.OFPT_FLOW_MOD)
1871 _length = reader.read('!H')[0]
1872 obj.xid = reader.read('!L')[0]
1873 obj.cookie = reader.read('!Q')[0]
1874 obj.cookie_mask = reader.read('!Q')[0]
1875 obj.table_id = reader.read('!B')[0]
1876 __command = reader.read('!B')[0]
1877 assert(__command == const.OFPFC_ADD)
1878 obj.idle_timeout = reader.read('!H')[0]
1879 obj.hard_timeout = reader.read('!H')[0]
1880 obj.priority = reader.read('!H')[0]
1881 obj.buffer_id = reader.read('!L')[0]
1882 obj.out_port = reader.read('!L')[0]
1883 obj.out_group = reader.read('!L')[0]
1884 obj.flags = reader.read('!H')[0]
1885 reader.skip(2)
1886 obj.match = common.match.unpack(reader)
1887 obj.instructions = instruction.unpack_list(reader)
1888 return obj
1889
1890 def __eq__(self, other):
1891 if type(self) != type(other): return False
1892 if self.version != other.version: return False
1893 if self.type != other.type: return False
1894 if self.xid != other.xid: return False
1895 if self.cookie != other.cookie: return False
1896 if self.cookie_mask != other.cookie_mask: return False
1897 if self.table_id != other.table_id: return False
1898 if self.idle_timeout != other.idle_timeout: return False
1899 if self.hard_timeout != other.hard_timeout: return False
1900 if self.priority != other.priority: return False
1901 if self.buffer_id != other.buffer_id: return False
1902 if self.out_port != other.out_port: return False
1903 if self.out_group != other.out_group: return False
1904 if self.flags != other.flags: return False
1905 if self.match != other.match: return False
1906 if self.instructions != other.instructions: return False
1907 return True
1908
1909 def __ne__(self, other):
1910 return not self.__eq__(other)
1911
1912 def __str__(self):
1913 return self.show()
1914
1915 def show(self):
1916 import loxi.pp
1917 return loxi.pp.pp(self)
1918
1919 def pretty_print(self, q):
1920 q.text("flow_add {")
1921 with q.group():
1922 with q.indent(2):
1923 q.breakable()
1924 q.text("xid = ");
1925 if self.xid != None:
1926 q.text("%#x" % self.xid)
1927 else:
1928 q.text('None')
1929 q.text(","); q.breakable()
1930 q.text("cookie = ");
1931 q.text("%#x" % self.cookie)
1932 q.text(","); q.breakable()
1933 q.text("cookie_mask = ");
1934 q.text("%#x" % self.cookie_mask)
1935 q.text(","); q.breakable()
1936 q.text("table_id = ");
1937 q.text("%#x" % self.table_id)
1938 q.text(","); q.breakable()
1939 q.text("idle_timeout = ");
1940 q.text("%#x" % self.idle_timeout)
1941 q.text(","); q.breakable()
1942 q.text("hard_timeout = ");
1943 q.text("%#x" % self.hard_timeout)
1944 q.text(","); q.breakable()
1945 q.text("priority = ");
1946 q.text("%#x" % self.priority)
1947 q.text(","); q.breakable()
1948 q.text("buffer_id = ");
1949 q.text("%#x" % self.buffer_id)
1950 q.text(","); q.breakable()
1951 q.text("out_port = ");
1952 q.text(util.pretty_port(self.out_port))
1953 q.text(","); q.breakable()
1954 q.text("out_group = ");
1955 q.text("%#x" % self.out_group)
1956 q.text(","); q.breakable()
1957 q.text("flags = ");
1958 q.text("%#x" % self.flags)
1959 q.text(","); q.breakable()
1960 q.text("match = ");
1961 q.pp(self.match)
1962 q.text(","); q.breakable()
1963 q.text("instructions = ");
1964 q.pp(self.instructions)
1965 q.breakable()
1966 q.text('}')
1967
1968class flow_delete(Message):
1969 version = const.OFP_VERSION
1970 type = const.OFPT_FLOW_MOD
1971 _command = const.OFPFC_DELETE
1972
1973 def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
1974 self.xid = xid
1975 if cookie != None:
1976 self.cookie = cookie
1977 else:
1978 self.cookie = 0
1979 if cookie_mask != None:
1980 self.cookie_mask = cookie_mask
1981 else:
1982 self.cookie_mask = 0
1983 if table_id != None:
1984 self.table_id = table_id
1985 else:
1986 self.table_id = 0
1987 if idle_timeout != None:
1988 self.idle_timeout = idle_timeout
1989 else:
1990 self.idle_timeout = 0
1991 if hard_timeout != None:
1992 self.hard_timeout = hard_timeout
1993 else:
1994 self.hard_timeout = 0
1995 if priority != None:
1996 self.priority = priority
1997 else:
1998 self.priority = 0
1999 if buffer_id != None:
2000 self.buffer_id = buffer_id
2001 else:
2002 self.buffer_id = 0
2003 if out_port != None:
2004 self.out_port = out_port
2005 else:
2006 self.out_port = 0
2007 if out_group != None:
2008 self.out_group = out_group
2009 else:
2010 self.out_group = 0
2011 if flags != None:
2012 self.flags = flags
2013 else:
2014 self.flags = 0
2015 if match != None:
2016 self.match = match
2017 else:
2018 self.match = common.match()
2019 if instructions != None:
2020 self.instructions = instructions
2021 else:
2022 self.instructions = []
2023
2024 def pack(self):
2025 packed = []
2026 packed.append(struct.pack("!B", self.version))
2027 packed.append(struct.pack("!B", self.type))
2028 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2029 packed.append(struct.pack("!L", self.xid))
2030 packed.append(struct.pack("!Q", self.cookie))
2031 packed.append(struct.pack("!Q", self.cookie_mask))
2032 packed.append(struct.pack("!B", self.table_id))
2033 packed.append(struct.pack("!B", self._command))
2034 packed.append(struct.pack("!H", self.idle_timeout))
2035 packed.append(struct.pack("!H", self.hard_timeout))
2036 packed.append(struct.pack("!H", self.priority))
2037 packed.append(struct.pack("!L", self.buffer_id))
2038 packed.append(struct.pack("!L", self.out_port))
2039 packed.append(struct.pack("!L", self.out_group))
2040 packed.append(struct.pack("!H", self.flags))
2041 packed.append('\x00' * 2)
2042 packed.append(self.match.pack())
2043 packed.append("".join([x.pack() for x in self.instructions]))
2044 length = sum([len(x) for x in packed])
2045 packed[2] = struct.pack("!H", length)
2046 return ''.join(packed)
2047
2048 @staticmethod
2049 def unpack(buf):
2050 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2051 obj = flow_delete()
2052 if type(buf) == loxi.generic_util.OFReader:
2053 reader = buf
2054 else:
2055 reader = loxi.generic_util.OFReader(buf)
2056 _version = reader.read('!B')[0]
2057 assert(_version == const.OFP_VERSION)
2058 _type = reader.read('!B')[0]
2059 assert(_type == const.OFPT_FLOW_MOD)
2060 _length = reader.read('!H')[0]
2061 obj.xid = reader.read('!L')[0]
2062 obj.cookie = reader.read('!Q')[0]
2063 obj.cookie_mask = reader.read('!Q')[0]
2064 obj.table_id = reader.read('!B')[0]
2065 __command = reader.read('!B')[0]
2066 assert(__command == const.OFPFC_DELETE)
2067 obj.idle_timeout = reader.read('!H')[0]
2068 obj.hard_timeout = reader.read('!H')[0]
2069 obj.priority = reader.read('!H')[0]
2070 obj.buffer_id = reader.read('!L')[0]
2071 obj.out_port = reader.read('!L')[0]
2072 obj.out_group = reader.read('!L')[0]
2073 obj.flags = reader.read('!H')[0]
2074 reader.skip(2)
2075 obj.match = common.match.unpack(reader)
2076 obj.instructions = instruction.unpack_list(reader)
2077 return obj
2078
2079 def __eq__(self, other):
2080 if type(self) != type(other): return False
2081 if self.version != other.version: return False
2082 if self.type != other.type: return False
2083 if self.xid != other.xid: return False
2084 if self.cookie != other.cookie: return False
2085 if self.cookie_mask != other.cookie_mask: return False
2086 if self.table_id != other.table_id: return False
2087 if self.idle_timeout != other.idle_timeout: return False
2088 if self.hard_timeout != other.hard_timeout: return False
2089 if self.priority != other.priority: return False
2090 if self.buffer_id != other.buffer_id: return False
2091 if self.out_port != other.out_port: return False
2092 if self.out_group != other.out_group: return False
2093 if self.flags != other.flags: return False
2094 if self.match != other.match: return False
2095 if self.instructions != other.instructions: return False
2096 return True
2097
2098 def __ne__(self, other):
2099 return not self.__eq__(other)
2100
2101 def __str__(self):
2102 return self.show()
2103
2104 def show(self):
2105 import loxi.pp
2106 return loxi.pp.pp(self)
2107
2108 def pretty_print(self, q):
2109 q.text("flow_delete {")
2110 with q.group():
2111 with q.indent(2):
2112 q.breakable()
2113 q.text("xid = ");
2114 if self.xid != None:
2115 q.text("%#x" % self.xid)
2116 else:
2117 q.text('None')
2118 q.text(","); q.breakable()
2119 q.text("cookie = ");
2120 q.text("%#x" % self.cookie)
2121 q.text(","); q.breakable()
2122 q.text("cookie_mask = ");
2123 q.text("%#x" % self.cookie_mask)
2124 q.text(","); q.breakable()
2125 q.text("table_id = ");
2126 q.text("%#x" % self.table_id)
2127 q.text(","); q.breakable()
2128 q.text("idle_timeout = ");
2129 q.text("%#x" % self.idle_timeout)
2130 q.text(","); q.breakable()
2131 q.text("hard_timeout = ");
2132 q.text("%#x" % self.hard_timeout)
2133 q.text(","); q.breakable()
2134 q.text("priority = ");
2135 q.text("%#x" % self.priority)
2136 q.text(","); q.breakable()
2137 q.text("buffer_id = ");
2138 q.text("%#x" % self.buffer_id)
2139 q.text(","); q.breakable()
2140 q.text("out_port = ");
2141 q.text(util.pretty_port(self.out_port))
2142 q.text(","); q.breakable()
2143 q.text("out_group = ");
2144 q.text("%#x" % self.out_group)
2145 q.text(","); q.breakable()
2146 q.text("flags = ");
2147 q.text("%#x" % self.flags)
2148 q.text(","); q.breakable()
2149 q.text("match = ");
2150 q.pp(self.match)
2151 q.text(","); q.breakable()
2152 q.text("instructions = ");
2153 q.pp(self.instructions)
2154 q.breakable()
2155 q.text('}')
2156
2157class flow_delete_strict(Message):
2158 version = const.OFP_VERSION
2159 type = const.OFPT_FLOW_MOD
2160 _command = const.OFPFC_DELETE_STRICT
2161
2162 def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
2163 self.xid = xid
2164 if cookie != None:
2165 self.cookie = cookie
2166 else:
2167 self.cookie = 0
2168 if cookie_mask != None:
2169 self.cookie_mask = cookie_mask
2170 else:
2171 self.cookie_mask = 0
2172 if table_id != None:
2173 self.table_id = table_id
2174 else:
2175 self.table_id = 0
2176 if idle_timeout != None:
2177 self.idle_timeout = idle_timeout
2178 else:
2179 self.idle_timeout = 0
2180 if hard_timeout != None:
2181 self.hard_timeout = hard_timeout
2182 else:
2183 self.hard_timeout = 0
2184 if priority != None:
2185 self.priority = priority
2186 else:
2187 self.priority = 0
2188 if buffer_id != None:
2189 self.buffer_id = buffer_id
2190 else:
2191 self.buffer_id = 0
2192 if out_port != None:
2193 self.out_port = out_port
2194 else:
2195 self.out_port = 0
2196 if out_group != None:
2197 self.out_group = out_group
2198 else:
2199 self.out_group = 0
2200 if flags != None:
2201 self.flags = flags
2202 else:
2203 self.flags = 0
2204 if match != None:
2205 self.match = match
2206 else:
2207 self.match = common.match()
2208 if instructions != None:
2209 self.instructions = instructions
2210 else:
2211 self.instructions = []
2212
2213 def pack(self):
2214 packed = []
2215 packed.append(struct.pack("!B", self.version))
2216 packed.append(struct.pack("!B", self.type))
2217 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2218 packed.append(struct.pack("!L", self.xid))
2219 packed.append(struct.pack("!Q", self.cookie))
2220 packed.append(struct.pack("!Q", self.cookie_mask))
2221 packed.append(struct.pack("!B", self.table_id))
2222 packed.append(struct.pack("!B", self._command))
2223 packed.append(struct.pack("!H", self.idle_timeout))
2224 packed.append(struct.pack("!H", self.hard_timeout))
2225 packed.append(struct.pack("!H", self.priority))
2226 packed.append(struct.pack("!L", self.buffer_id))
2227 packed.append(struct.pack("!L", self.out_port))
2228 packed.append(struct.pack("!L", self.out_group))
2229 packed.append(struct.pack("!H", self.flags))
2230 packed.append('\x00' * 2)
2231 packed.append(self.match.pack())
2232 packed.append("".join([x.pack() for x in self.instructions]))
2233 length = sum([len(x) for x in packed])
2234 packed[2] = struct.pack("!H", length)
2235 return ''.join(packed)
2236
2237 @staticmethod
2238 def unpack(buf):
2239 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2240 obj = flow_delete_strict()
2241 if type(buf) == loxi.generic_util.OFReader:
2242 reader = buf
2243 else:
2244 reader = loxi.generic_util.OFReader(buf)
2245 _version = reader.read('!B')[0]
2246 assert(_version == const.OFP_VERSION)
2247 _type = reader.read('!B')[0]
2248 assert(_type == const.OFPT_FLOW_MOD)
2249 _length = reader.read('!H')[0]
2250 obj.xid = reader.read('!L')[0]
2251 obj.cookie = reader.read('!Q')[0]
2252 obj.cookie_mask = reader.read('!Q')[0]
2253 obj.table_id = reader.read('!B')[0]
2254 __command = reader.read('!B')[0]
2255 assert(__command == const.OFPFC_DELETE_STRICT)
2256 obj.idle_timeout = reader.read('!H')[0]
2257 obj.hard_timeout = reader.read('!H')[0]
2258 obj.priority = reader.read('!H')[0]
2259 obj.buffer_id = reader.read('!L')[0]
2260 obj.out_port = reader.read('!L')[0]
2261 obj.out_group = reader.read('!L')[0]
2262 obj.flags = reader.read('!H')[0]
2263 reader.skip(2)
2264 obj.match = common.match.unpack(reader)
2265 obj.instructions = instruction.unpack_list(reader)
2266 return obj
2267
2268 def __eq__(self, other):
2269 if type(self) != type(other): return False
2270 if self.version != other.version: return False
2271 if self.type != other.type: return False
2272 if self.xid != other.xid: return False
2273 if self.cookie != other.cookie: return False
2274 if self.cookie_mask != other.cookie_mask: return False
2275 if self.table_id != other.table_id: return False
2276 if self.idle_timeout != other.idle_timeout: return False
2277 if self.hard_timeout != other.hard_timeout: return False
2278 if self.priority != other.priority: return False
2279 if self.buffer_id != other.buffer_id: return False
2280 if self.out_port != other.out_port: return False
2281 if self.out_group != other.out_group: return False
2282 if self.flags != other.flags: return False
2283 if self.match != other.match: return False
2284 if self.instructions != other.instructions: return False
2285 return True
2286
2287 def __ne__(self, other):
2288 return not self.__eq__(other)
2289
2290 def __str__(self):
2291 return self.show()
2292
2293 def show(self):
2294 import loxi.pp
2295 return loxi.pp.pp(self)
2296
2297 def pretty_print(self, q):
2298 q.text("flow_delete_strict {")
2299 with q.group():
2300 with q.indent(2):
2301 q.breakable()
2302 q.text("xid = ");
2303 if self.xid != None:
2304 q.text("%#x" % self.xid)
2305 else:
2306 q.text('None')
2307 q.text(","); q.breakable()
2308 q.text("cookie = ");
2309 q.text("%#x" % self.cookie)
2310 q.text(","); q.breakable()
2311 q.text("cookie_mask = ");
2312 q.text("%#x" % self.cookie_mask)
2313 q.text(","); q.breakable()
2314 q.text("table_id = ");
2315 q.text("%#x" % self.table_id)
2316 q.text(","); q.breakable()
2317 q.text("idle_timeout = ");
2318 q.text("%#x" % self.idle_timeout)
2319 q.text(","); q.breakable()
2320 q.text("hard_timeout = ");
2321 q.text("%#x" % self.hard_timeout)
2322 q.text(","); q.breakable()
2323 q.text("priority = ");
2324 q.text("%#x" % self.priority)
2325 q.text(","); q.breakable()
2326 q.text("buffer_id = ");
2327 q.text("%#x" % self.buffer_id)
2328 q.text(","); q.breakable()
2329 q.text("out_port = ");
2330 q.text(util.pretty_port(self.out_port))
2331 q.text(","); q.breakable()
2332 q.text("out_group = ");
2333 q.text("%#x" % self.out_group)
2334 q.text(","); q.breakable()
2335 q.text("flags = ");
2336 q.text("%#x" % self.flags)
2337 q.text(","); q.breakable()
2338 q.text("match = ");
2339 q.pp(self.match)
2340 q.text(","); q.breakable()
2341 q.text("instructions = ");
2342 q.pp(self.instructions)
2343 q.breakable()
2344 q.text('}')
2345
2346class flow_modify(Message):
2347 version = const.OFP_VERSION
2348 type = const.OFPT_FLOW_MOD
2349 _command = const.OFPFC_MODIFY
2350
2351 def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
2352 self.xid = xid
2353 if cookie != None:
2354 self.cookie = cookie
2355 else:
2356 self.cookie = 0
2357 if cookie_mask != None:
2358 self.cookie_mask = cookie_mask
2359 else:
2360 self.cookie_mask = 0
2361 if table_id != None:
2362 self.table_id = table_id
2363 else:
2364 self.table_id = 0
2365 if idle_timeout != None:
2366 self.idle_timeout = idle_timeout
2367 else:
2368 self.idle_timeout = 0
2369 if hard_timeout != None:
2370 self.hard_timeout = hard_timeout
2371 else:
2372 self.hard_timeout = 0
2373 if priority != None:
2374 self.priority = priority
2375 else:
2376 self.priority = 0
2377 if buffer_id != None:
2378 self.buffer_id = buffer_id
2379 else:
2380 self.buffer_id = 0
2381 if out_port != None:
2382 self.out_port = out_port
2383 else:
2384 self.out_port = 0
2385 if out_group != None:
2386 self.out_group = out_group
2387 else:
2388 self.out_group = 0
2389 if flags != None:
2390 self.flags = flags
2391 else:
2392 self.flags = 0
2393 if match != None:
2394 self.match = match
2395 else:
2396 self.match = common.match()
2397 if instructions != None:
2398 self.instructions = instructions
2399 else:
2400 self.instructions = []
2401
2402 def pack(self):
2403 packed = []
2404 packed.append(struct.pack("!B", self.version))
2405 packed.append(struct.pack("!B", self.type))
2406 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2407 packed.append(struct.pack("!L", self.xid))
2408 packed.append(struct.pack("!Q", self.cookie))
2409 packed.append(struct.pack("!Q", self.cookie_mask))
2410 packed.append(struct.pack("!B", self.table_id))
2411 packed.append(struct.pack("!B", self._command))
2412 packed.append(struct.pack("!H", self.idle_timeout))
2413 packed.append(struct.pack("!H", self.hard_timeout))
2414 packed.append(struct.pack("!H", self.priority))
2415 packed.append(struct.pack("!L", self.buffer_id))
2416 packed.append(struct.pack("!L", self.out_port))
2417 packed.append(struct.pack("!L", self.out_group))
2418 packed.append(struct.pack("!H", self.flags))
2419 packed.append('\x00' * 2)
2420 packed.append(self.match.pack())
2421 packed.append("".join([x.pack() for x in self.instructions]))
2422 length = sum([len(x) for x in packed])
2423 packed[2] = struct.pack("!H", length)
2424 return ''.join(packed)
2425
2426 @staticmethod
2427 def unpack(buf):
2428 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2429 obj = flow_modify()
2430 if type(buf) == loxi.generic_util.OFReader:
2431 reader = buf
2432 else:
2433 reader = loxi.generic_util.OFReader(buf)
2434 _version = reader.read('!B')[0]
2435 assert(_version == const.OFP_VERSION)
2436 _type = reader.read('!B')[0]
2437 assert(_type == const.OFPT_FLOW_MOD)
2438 _length = reader.read('!H')[0]
2439 obj.xid = reader.read('!L')[0]
2440 obj.cookie = reader.read('!Q')[0]
2441 obj.cookie_mask = reader.read('!Q')[0]
2442 obj.table_id = reader.read('!B')[0]
2443 __command = reader.read('!B')[0]
2444 assert(__command == const.OFPFC_MODIFY)
2445 obj.idle_timeout = reader.read('!H')[0]
2446 obj.hard_timeout = reader.read('!H')[0]
2447 obj.priority = reader.read('!H')[0]
2448 obj.buffer_id = reader.read('!L')[0]
2449 obj.out_port = reader.read('!L')[0]
2450 obj.out_group = reader.read('!L')[0]
2451 obj.flags = reader.read('!H')[0]
2452 reader.skip(2)
2453 obj.match = common.match.unpack(reader)
2454 obj.instructions = instruction.unpack_list(reader)
2455 return obj
2456
2457 def __eq__(self, other):
2458 if type(self) != type(other): return False
2459 if self.version != other.version: return False
2460 if self.type != other.type: return False
2461 if self.xid != other.xid: return False
2462 if self.cookie != other.cookie: return False
2463 if self.cookie_mask != other.cookie_mask: return False
2464 if self.table_id != other.table_id: return False
2465 if self.idle_timeout != other.idle_timeout: return False
2466 if self.hard_timeout != other.hard_timeout: return False
2467 if self.priority != other.priority: return False
2468 if self.buffer_id != other.buffer_id: return False
2469 if self.out_port != other.out_port: return False
2470 if self.out_group != other.out_group: return False
2471 if self.flags != other.flags: return False
2472 if self.match != other.match: return False
2473 if self.instructions != other.instructions: return False
2474 return True
2475
2476 def __ne__(self, other):
2477 return not self.__eq__(other)
2478
2479 def __str__(self):
2480 return self.show()
2481
2482 def show(self):
2483 import loxi.pp
2484 return loxi.pp.pp(self)
2485
2486 def pretty_print(self, q):
2487 q.text("flow_modify {")
2488 with q.group():
2489 with q.indent(2):
2490 q.breakable()
2491 q.text("xid = ");
2492 if self.xid != None:
2493 q.text("%#x" % self.xid)
2494 else:
2495 q.text('None')
2496 q.text(","); q.breakable()
2497 q.text("cookie = ");
2498 q.text("%#x" % self.cookie)
2499 q.text(","); q.breakable()
2500 q.text("cookie_mask = ");
2501 q.text("%#x" % self.cookie_mask)
2502 q.text(","); q.breakable()
2503 q.text("table_id = ");
2504 q.text("%#x" % self.table_id)
2505 q.text(","); q.breakable()
2506 q.text("idle_timeout = ");
2507 q.text("%#x" % self.idle_timeout)
2508 q.text(","); q.breakable()
2509 q.text("hard_timeout = ");
2510 q.text("%#x" % self.hard_timeout)
2511 q.text(","); q.breakable()
2512 q.text("priority = ");
2513 q.text("%#x" % self.priority)
2514 q.text(","); q.breakable()
2515 q.text("buffer_id = ");
2516 q.text("%#x" % self.buffer_id)
2517 q.text(","); q.breakable()
2518 q.text("out_port = ");
2519 q.text(util.pretty_port(self.out_port))
2520 q.text(","); q.breakable()
2521 q.text("out_group = ");
2522 q.text("%#x" % self.out_group)
2523 q.text(","); q.breakable()
2524 q.text("flags = ");
2525 q.text("%#x" % self.flags)
2526 q.text(","); q.breakable()
2527 q.text("match = ");
2528 q.pp(self.match)
2529 q.text(","); q.breakable()
2530 q.text("instructions = ");
2531 q.pp(self.instructions)
2532 q.breakable()
2533 q.text('}')
2534
2535class flow_modify_strict(Message):
2536 version = const.OFP_VERSION
2537 type = const.OFPT_FLOW_MOD
2538 _command = const.OFPFC_MODIFY_STRICT
2539
2540 def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
2541 self.xid = xid
2542 if cookie != None:
2543 self.cookie = cookie
2544 else:
2545 self.cookie = 0
2546 if cookie_mask != None:
2547 self.cookie_mask = cookie_mask
2548 else:
2549 self.cookie_mask = 0
2550 if table_id != None:
2551 self.table_id = table_id
2552 else:
2553 self.table_id = 0
2554 if idle_timeout != None:
2555 self.idle_timeout = idle_timeout
2556 else:
2557 self.idle_timeout = 0
2558 if hard_timeout != None:
2559 self.hard_timeout = hard_timeout
2560 else:
2561 self.hard_timeout = 0
2562 if priority != None:
2563 self.priority = priority
2564 else:
2565 self.priority = 0
2566 if buffer_id != None:
2567 self.buffer_id = buffer_id
2568 else:
2569 self.buffer_id = 0
2570 if out_port != None:
2571 self.out_port = out_port
2572 else:
2573 self.out_port = 0
2574 if out_group != None:
2575 self.out_group = out_group
2576 else:
2577 self.out_group = 0
2578 if flags != None:
2579 self.flags = flags
2580 else:
2581 self.flags = 0
2582 if match != None:
2583 self.match = match
2584 else:
2585 self.match = common.match()
2586 if instructions != None:
2587 self.instructions = instructions
2588 else:
2589 self.instructions = []
2590
2591 def pack(self):
2592 packed = []
2593 packed.append(struct.pack("!B", self.version))
2594 packed.append(struct.pack("!B", self.type))
2595 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2596 packed.append(struct.pack("!L", self.xid))
2597 packed.append(struct.pack("!Q", self.cookie))
2598 packed.append(struct.pack("!Q", self.cookie_mask))
2599 packed.append(struct.pack("!B", self.table_id))
2600 packed.append(struct.pack("!B", self._command))
2601 packed.append(struct.pack("!H", self.idle_timeout))
2602 packed.append(struct.pack("!H", self.hard_timeout))
2603 packed.append(struct.pack("!H", self.priority))
2604 packed.append(struct.pack("!L", self.buffer_id))
2605 packed.append(struct.pack("!L", self.out_port))
2606 packed.append(struct.pack("!L", self.out_group))
2607 packed.append(struct.pack("!H", self.flags))
2608 packed.append('\x00' * 2)
2609 packed.append(self.match.pack())
2610 packed.append("".join([x.pack() for x in self.instructions]))
2611 length = sum([len(x) for x in packed])
2612 packed[2] = struct.pack("!H", length)
2613 return ''.join(packed)
2614
2615 @staticmethod
2616 def unpack(buf):
2617 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2618 obj = flow_modify_strict()
2619 if type(buf) == loxi.generic_util.OFReader:
2620 reader = buf
2621 else:
2622 reader = loxi.generic_util.OFReader(buf)
2623 _version = reader.read('!B')[0]
2624 assert(_version == const.OFP_VERSION)
2625 _type = reader.read('!B')[0]
2626 assert(_type == const.OFPT_FLOW_MOD)
2627 _length = reader.read('!H')[0]
2628 obj.xid = reader.read('!L')[0]
2629 obj.cookie = reader.read('!Q')[0]
2630 obj.cookie_mask = reader.read('!Q')[0]
2631 obj.table_id = reader.read('!B')[0]
2632 __command = reader.read('!B')[0]
2633 assert(__command == const.OFPFC_MODIFY_STRICT)
2634 obj.idle_timeout = reader.read('!H')[0]
2635 obj.hard_timeout = reader.read('!H')[0]
2636 obj.priority = reader.read('!H')[0]
2637 obj.buffer_id = reader.read('!L')[0]
2638 obj.out_port = reader.read('!L')[0]
2639 obj.out_group = reader.read('!L')[0]
2640 obj.flags = reader.read('!H')[0]
2641 reader.skip(2)
2642 obj.match = common.match.unpack(reader)
2643 obj.instructions = instruction.unpack_list(reader)
2644 return obj
2645
2646 def __eq__(self, other):
2647 if type(self) != type(other): return False
2648 if self.version != other.version: return False
2649 if self.type != other.type: return False
2650 if self.xid != other.xid: return False
2651 if self.cookie != other.cookie: return False
2652 if self.cookie_mask != other.cookie_mask: return False
2653 if self.table_id != other.table_id: return False
2654 if self.idle_timeout != other.idle_timeout: return False
2655 if self.hard_timeout != other.hard_timeout: return False
2656 if self.priority != other.priority: return False
2657 if self.buffer_id != other.buffer_id: return False
2658 if self.out_port != other.out_port: return False
2659 if self.out_group != other.out_group: return False
2660 if self.flags != other.flags: return False
2661 if self.match != other.match: return False
2662 if self.instructions != other.instructions: return False
2663 return True
2664
2665 def __ne__(self, other):
2666 return not self.__eq__(other)
2667
2668 def __str__(self):
2669 return self.show()
2670
2671 def show(self):
2672 import loxi.pp
2673 return loxi.pp.pp(self)
2674
2675 def pretty_print(self, q):
2676 q.text("flow_modify_strict {")
2677 with q.group():
2678 with q.indent(2):
2679 q.breakable()
2680 q.text("xid = ");
2681 if self.xid != None:
2682 q.text("%#x" % self.xid)
2683 else:
2684 q.text('None')
2685 q.text(","); q.breakable()
2686 q.text("cookie = ");
2687 q.text("%#x" % self.cookie)
2688 q.text(","); q.breakable()
2689 q.text("cookie_mask = ");
2690 q.text("%#x" % self.cookie_mask)
2691 q.text(","); q.breakable()
2692 q.text("table_id = ");
2693 q.text("%#x" % self.table_id)
2694 q.text(","); q.breakable()
2695 q.text("idle_timeout = ");
2696 q.text("%#x" % self.idle_timeout)
2697 q.text(","); q.breakable()
2698 q.text("hard_timeout = ");
2699 q.text("%#x" % self.hard_timeout)
2700 q.text(","); q.breakable()
2701 q.text("priority = ");
2702 q.text("%#x" % self.priority)
2703 q.text(","); q.breakable()
2704 q.text("buffer_id = ");
2705 q.text("%#x" % self.buffer_id)
2706 q.text(","); q.breakable()
2707 q.text("out_port = ");
2708 q.text(util.pretty_port(self.out_port))
2709 q.text(","); q.breakable()
2710 q.text("out_group = ");
2711 q.text("%#x" % self.out_group)
2712 q.text(","); q.breakable()
2713 q.text("flags = ");
2714 q.text("%#x" % self.flags)
2715 q.text(","); q.breakable()
2716 q.text("match = ");
2717 q.pp(self.match)
2718 q.text(","); q.breakable()
2719 q.text("instructions = ");
2720 q.pp(self.instructions)
2721 q.breakable()
2722 q.text('}')
2723
2724class flow_removed(Message):
2725 version = const.OFP_VERSION
2726 type = const.OFPT_FLOW_REMOVED
2727
2728 def __init__(self, xid=None, cookie=None, priority=None, reason=None, table_id=None, duration_sec=None, duration_nsec=None, idle_timeout=None, hard_timeout=None, packet_count=None, byte_count=None, match=None):
2729 self.xid = xid
2730 if cookie != None:
2731 self.cookie = cookie
2732 else:
2733 self.cookie = 0
2734 if priority != None:
2735 self.priority = priority
2736 else:
2737 self.priority = 0
2738 if reason != None:
2739 self.reason = reason
2740 else:
2741 self.reason = 0
2742 if table_id != None:
2743 self.table_id = table_id
2744 else:
2745 self.table_id = 0
2746 if duration_sec != None:
2747 self.duration_sec = duration_sec
2748 else:
2749 self.duration_sec = 0
2750 if duration_nsec != None:
2751 self.duration_nsec = duration_nsec
2752 else:
2753 self.duration_nsec = 0
2754 if idle_timeout != None:
2755 self.idle_timeout = idle_timeout
2756 else:
2757 self.idle_timeout = 0
2758 if hard_timeout != None:
2759 self.hard_timeout = hard_timeout
2760 else:
2761 self.hard_timeout = 0
2762 if packet_count != None:
2763 self.packet_count = packet_count
2764 else:
2765 self.packet_count = 0
2766 if byte_count != None:
2767 self.byte_count = byte_count
2768 else:
2769 self.byte_count = 0
2770 if match != None:
2771 self.match = match
2772 else:
2773 self.match = common.match()
2774
2775 def pack(self):
2776 packed = []
2777 packed.append(struct.pack("!B", self.version))
2778 packed.append(struct.pack("!B", self.type))
2779 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2780 packed.append(struct.pack("!L", self.xid))
2781 packed.append(struct.pack("!Q", self.cookie))
2782 packed.append(struct.pack("!H", self.priority))
2783 packed.append(struct.pack("!B", self.reason))
2784 packed.append(struct.pack("!B", self.table_id))
2785 packed.append(struct.pack("!L", self.duration_sec))
2786 packed.append(struct.pack("!L", self.duration_nsec))
2787 packed.append(struct.pack("!H", self.idle_timeout))
2788 packed.append(struct.pack("!H", self.hard_timeout))
2789 packed.append(struct.pack("!Q", self.packet_count))
2790 packed.append(struct.pack("!Q", self.byte_count))
2791 packed.append(self.match.pack())
2792 length = sum([len(x) for x in packed])
2793 packed[2] = struct.pack("!H", length)
2794 return ''.join(packed)
2795
2796 @staticmethod
2797 def unpack(buf):
2798 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2799 obj = flow_removed()
2800 if type(buf) == loxi.generic_util.OFReader:
2801 reader = buf
2802 else:
2803 reader = loxi.generic_util.OFReader(buf)
2804 _version = reader.read('!B')[0]
2805 assert(_version == const.OFP_VERSION)
2806 _type = reader.read('!B')[0]
2807 assert(_type == const.OFPT_FLOW_REMOVED)
2808 _length = reader.read('!H')[0]
2809 obj.xid = reader.read('!L')[0]
2810 obj.cookie = reader.read('!Q')[0]
2811 obj.priority = reader.read('!H')[0]
2812 obj.reason = reader.read('!B')[0]
2813 obj.table_id = reader.read('!B')[0]
2814 obj.duration_sec = reader.read('!L')[0]
2815 obj.duration_nsec = reader.read('!L')[0]
2816 obj.idle_timeout = reader.read('!H')[0]
2817 obj.hard_timeout = reader.read('!H')[0]
2818 obj.packet_count = reader.read('!Q')[0]
2819 obj.byte_count = reader.read('!Q')[0]
2820 obj.match = common.match.unpack(reader)
2821 return obj
2822
2823 def __eq__(self, other):
2824 if type(self) != type(other): return False
2825 if self.version != other.version: return False
2826 if self.type != other.type: return False
2827 if self.xid != other.xid: return False
2828 if self.cookie != other.cookie: return False
2829 if self.priority != other.priority: return False
2830 if self.reason != other.reason: return False
2831 if self.table_id != other.table_id: return False
2832 if self.duration_sec != other.duration_sec: return False
2833 if self.duration_nsec != other.duration_nsec: return False
2834 if self.idle_timeout != other.idle_timeout: return False
2835 if self.hard_timeout != other.hard_timeout: return False
2836 if self.packet_count != other.packet_count: return False
2837 if self.byte_count != other.byte_count: return False
2838 if self.match != other.match: return False
2839 return True
2840
2841 def __ne__(self, other):
2842 return not self.__eq__(other)
2843
2844 def __str__(self):
2845 return self.show()
2846
2847 def show(self):
2848 import loxi.pp
2849 return loxi.pp.pp(self)
2850
2851 def pretty_print(self, q):
2852 q.text("flow_removed {")
2853 with q.group():
2854 with q.indent(2):
2855 q.breakable()
2856 q.text("xid = ");
2857 if self.xid != None:
2858 q.text("%#x" % self.xid)
2859 else:
2860 q.text('None')
2861 q.text(","); q.breakable()
2862 q.text("cookie = ");
2863 q.text("%#x" % self.cookie)
2864 q.text(","); q.breakable()
2865 q.text("priority = ");
2866 q.text("%#x" % self.priority)
2867 q.text(","); q.breakable()
2868 q.text("reason = ");
2869 q.text("%#x" % self.reason)
2870 q.text(","); q.breakable()
2871 q.text("table_id = ");
2872 q.text("%#x" % self.table_id)
2873 q.text(","); q.breakable()
2874 q.text("duration_sec = ");
2875 q.text("%#x" % self.duration_sec)
2876 q.text(","); q.breakable()
2877 q.text("duration_nsec = ");
2878 q.text("%#x" % self.duration_nsec)
2879 q.text(","); q.breakable()
2880 q.text("idle_timeout = ");
2881 q.text("%#x" % self.idle_timeout)
2882 q.text(","); q.breakable()
2883 q.text("hard_timeout = ");
2884 q.text("%#x" % self.hard_timeout)
2885 q.text(","); q.breakable()
2886 q.text("packet_count = ");
2887 q.text("%#x" % self.packet_count)
2888 q.text(","); q.breakable()
2889 q.text("byte_count = ");
2890 q.text("%#x" % self.byte_count)
2891 q.text(","); q.breakable()
2892 q.text("match = ");
2893 q.pp(self.match)
2894 q.breakable()
2895 q.text('}')
2896
2897class flow_stats_reply(Message):
2898 version = const.OFP_VERSION
2899 type = const.OFPT_STATS_REPLY
2900 stats_type = const.OFPST_FLOW
2901
2902 def __init__(self, xid=None, flags=None, entries=None):
2903 self.xid = xid
2904 if flags != None:
2905 self.flags = flags
2906 else:
2907 self.flags = 0
2908 if entries != None:
2909 self.entries = entries
2910 else:
2911 self.entries = []
2912
2913 def pack(self):
2914 packed = []
2915 packed.append(struct.pack("!B", self.version))
2916 packed.append(struct.pack("!B", self.type))
2917 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2918 packed.append(struct.pack("!L", self.xid))
2919 packed.append(struct.pack("!H", self.stats_type))
2920 packed.append(struct.pack("!H", self.flags))
2921 packed.append('\x00' * 4)
2922 packed.append("".join([x.pack() for x in self.entries]))
2923 length = sum([len(x) for x in packed])
2924 packed[2] = struct.pack("!H", length)
2925 return ''.join(packed)
2926
2927 @staticmethod
2928 def unpack(buf):
2929 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2930 obj = flow_stats_reply()
2931 if type(buf) == loxi.generic_util.OFReader:
2932 reader = buf
2933 else:
2934 reader = loxi.generic_util.OFReader(buf)
2935 _version = reader.read('!B')[0]
2936 assert(_version == const.OFP_VERSION)
2937 _type = reader.read('!B')[0]
2938 assert(_type == const.OFPT_STATS_REPLY)
2939 _length = reader.read('!H')[0]
2940 obj.xid = reader.read('!L')[0]
2941 _stats_type = reader.read('!H')[0]
2942 assert(_stats_type == const.OFPST_FLOW)
2943 obj.flags = reader.read('!H')[0]
2944 reader.skip(4)
2945 obj.entries = common.unpack_list_flow_stats_entry(reader)
2946 return obj
2947
2948 def __eq__(self, other):
2949 if type(self) != type(other): return False
2950 if self.version != other.version: return False
2951 if self.type != other.type: return False
2952 if self.xid != other.xid: return False
2953 if self.flags != other.flags: return False
2954 if self.entries != other.entries: return False
2955 return True
2956
2957 def __ne__(self, other):
2958 return not self.__eq__(other)
2959
2960 def __str__(self):
2961 return self.show()
2962
2963 def show(self):
2964 import loxi.pp
2965 return loxi.pp.pp(self)
2966
2967 def pretty_print(self, q):
2968 q.text("flow_stats_reply {")
2969 with q.group():
2970 with q.indent(2):
2971 q.breakable()
2972 q.text("xid = ");
2973 if self.xid != None:
2974 q.text("%#x" % self.xid)
2975 else:
2976 q.text('None')
2977 q.text(","); q.breakable()
2978 q.text("flags = ");
2979 q.text("%#x" % self.flags)
2980 q.text(","); q.breakable()
2981 q.text("entries = ");
2982 q.pp(self.entries)
2983 q.breakable()
2984 q.text('}')
2985
2986class flow_stats_request(Message):
2987 version = const.OFP_VERSION
2988 type = const.OFPT_STATS_REQUEST
2989 stats_type = const.OFPST_FLOW
2990
2991 def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
2992 self.xid = xid
2993 if flags != None:
2994 self.flags = flags
2995 else:
2996 self.flags = 0
2997 if table_id != None:
2998 self.table_id = table_id
2999 else:
3000 self.table_id = 0
3001 if out_port != None:
3002 self.out_port = out_port
3003 else:
3004 self.out_port = 0
3005 if out_group != None:
3006 self.out_group = out_group
3007 else:
3008 self.out_group = 0
3009 if cookie != None:
3010 self.cookie = cookie
3011 else:
3012 self.cookie = 0
3013 if cookie_mask != None:
3014 self.cookie_mask = cookie_mask
3015 else:
3016 self.cookie_mask = 0
3017 if match != None:
3018 self.match = match
3019 else:
3020 self.match = common.match()
3021
3022 def pack(self):
3023 packed = []
3024 packed.append(struct.pack("!B", self.version))
3025 packed.append(struct.pack("!B", self.type))
3026 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3027 packed.append(struct.pack("!L", self.xid))
3028 packed.append(struct.pack("!H", self.stats_type))
3029 packed.append(struct.pack("!H", self.flags))
3030 packed.append('\x00' * 4)
3031 packed.append(struct.pack("!B", self.table_id))
3032 packed.append('\x00' * 3)
3033 packed.append(struct.pack("!L", self.out_port))
3034 packed.append(struct.pack("!L", self.out_group))
3035 packed.append('\x00' * 4)
3036 packed.append(struct.pack("!Q", self.cookie))
3037 packed.append(struct.pack("!Q", self.cookie_mask))
3038 packed.append(self.match.pack())
3039 length = sum([len(x) for x in packed])
3040 packed[2] = struct.pack("!H", length)
3041 return ''.join(packed)
3042
3043 @staticmethod
3044 def unpack(buf):
3045 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3046 obj = flow_stats_request()
3047 if type(buf) == loxi.generic_util.OFReader:
3048 reader = buf
3049 else:
3050 reader = loxi.generic_util.OFReader(buf)
3051 _version = reader.read('!B')[0]
3052 assert(_version == const.OFP_VERSION)
3053 _type = reader.read('!B')[0]
3054 assert(_type == const.OFPT_STATS_REQUEST)
3055 _length = reader.read('!H')[0]
3056 obj.xid = reader.read('!L')[0]
3057 _stats_type = reader.read('!H')[0]
3058 assert(_stats_type == const.OFPST_FLOW)
3059 obj.flags = reader.read('!H')[0]
3060 reader.skip(4)
3061 obj.table_id = reader.read('!B')[0]
3062 reader.skip(3)
3063 obj.out_port = reader.read('!L')[0]
3064 obj.out_group = reader.read('!L')[0]
3065 reader.skip(4)
3066 obj.cookie = reader.read('!Q')[0]
3067 obj.cookie_mask = reader.read('!Q')[0]
3068 obj.match = common.match.unpack(reader)
3069 return obj
3070
3071 def __eq__(self, other):
3072 if type(self) != type(other): return False
3073 if self.version != other.version: return False
3074 if self.type != other.type: return False
3075 if self.xid != other.xid: return False
3076 if self.flags != other.flags: return False
3077 if self.table_id != other.table_id: return False
3078 if self.out_port != other.out_port: return False
3079 if self.out_group != other.out_group: return False
3080 if self.cookie != other.cookie: return False
3081 if self.cookie_mask != other.cookie_mask: return False
3082 if self.match != other.match: return False
3083 return True
3084
3085 def __ne__(self, other):
3086 return not self.__eq__(other)
3087
3088 def __str__(self):
3089 return self.show()
3090
3091 def show(self):
3092 import loxi.pp
3093 return loxi.pp.pp(self)
3094
3095 def pretty_print(self, q):
3096 q.text("flow_stats_request {")
3097 with q.group():
3098 with q.indent(2):
3099 q.breakable()
3100 q.text("xid = ");
3101 if self.xid != None:
3102 q.text("%#x" % self.xid)
3103 else:
3104 q.text('None')
3105 q.text(","); q.breakable()
3106 q.text("flags = ");
3107 q.text("%#x" % self.flags)
3108 q.text(","); q.breakable()
3109 q.text("table_id = ");
3110 q.text("%#x" % self.table_id)
3111 q.text(","); q.breakable()
3112 q.text("out_port = ");
3113 q.text(util.pretty_port(self.out_port))
3114 q.text(","); q.breakable()
3115 q.text("out_group = ");
3116 q.text("%#x" % self.out_group)
3117 q.text(","); q.breakable()
3118 q.text("cookie = ");
3119 q.text("%#x" % self.cookie)
3120 q.text(","); q.breakable()
3121 q.text("cookie_mask = ");
3122 q.text("%#x" % self.cookie_mask)
3123 q.text(","); q.breakable()
3124 q.text("match = ");
3125 q.pp(self.match)
3126 q.breakable()
3127 q.text('}')
3128
3129class get_config_reply(Message):
3130 version = const.OFP_VERSION
3131 type = const.OFPT_GET_CONFIG_REPLY
3132
3133 def __init__(self, xid=None, flags=None, miss_send_len=None):
3134 self.xid = xid
3135 if flags != None:
3136 self.flags = flags
3137 else:
3138 self.flags = 0
3139 if miss_send_len != None:
3140 self.miss_send_len = miss_send_len
3141 else:
3142 self.miss_send_len = 0
3143
3144 def pack(self):
3145 packed = []
3146 packed.append(struct.pack("!B", self.version))
3147 packed.append(struct.pack("!B", self.type))
3148 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3149 packed.append(struct.pack("!L", self.xid))
3150 packed.append(struct.pack("!H", self.flags))
3151 packed.append(struct.pack("!H", self.miss_send_len))
3152 length = sum([len(x) for x in packed])
3153 packed[2] = struct.pack("!H", length)
3154 return ''.join(packed)
3155
3156 @staticmethod
3157 def unpack(buf):
3158 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3159 obj = get_config_reply()
3160 if type(buf) == loxi.generic_util.OFReader:
3161 reader = buf
3162 else:
3163 reader = loxi.generic_util.OFReader(buf)
3164 _version = reader.read('!B')[0]
3165 assert(_version == const.OFP_VERSION)
3166 _type = reader.read('!B')[0]
3167 assert(_type == const.OFPT_GET_CONFIG_REPLY)
3168 _length = reader.read('!H')[0]
3169 obj.xid = reader.read('!L')[0]
3170 obj.flags = reader.read('!H')[0]
3171 obj.miss_send_len = reader.read('!H')[0]
3172 return obj
3173
3174 def __eq__(self, other):
3175 if type(self) != type(other): return False
3176 if self.version != other.version: return False
3177 if self.type != other.type: return False
3178 if self.xid != other.xid: return False
3179 if self.flags != other.flags: return False
3180 if self.miss_send_len != other.miss_send_len: return False
3181 return True
3182
3183 def __ne__(self, other):
3184 return not self.__eq__(other)
3185
3186 def __str__(self):
3187 return self.show()
3188
3189 def show(self):
3190 import loxi.pp
3191 return loxi.pp.pp(self)
3192
3193 def pretty_print(self, q):
3194 q.text("get_config_reply {")
3195 with q.group():
3196 with q.indent(2):
3197 q.breakable()
3198 q.text("xid = ");
3199 if self.xid != None:
3200 q.text("%#x" % self.xid)
3201 else:
3202 q.text('None')
3203 q.text(","); q.breakable()
3204 q.text("flags = ");
3205 q.text("%#x" % self.flags)
3206 q.text(","); q.breakable()
3207 q.text("miss_send_len = ");
3208 q.text("%#x" % self.miss_send_len)
3209 q.breakable()
3210 q.text('}')
3211
3212class get_config_request(Message):
3213 version = const.OFP_VERSION
3214 type = const.OFPT_GET_CONFIG_REQUEST
3215
3216 def __init__(self, xid=None):
3217 self.xid = xid
3218
3219 def pack(self):
3220 packed = []
3221 packed.append(struct.pack("!B", self.version))
3222 packed.append(struct.pack("!B", self.type))
3223 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3224 packed.append(struct.pack("!L", self.xid))
3225 length = sum([len(x) for x in packed])
3226 packed[2] = struct.pack("!H", length)
3227 return ''.join(packed)
3228
3229 @staticmethod
3230 def unpack(buf):
3231 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3232 obj = get_config_request()
3233 if type(buf) == loxi.generic_util.OFReader:
3234 reader = buf
3235 else:
3236 reader = loxi.generic_util.OFReader(buf)
3237 _version = reader.read('!B')[0]
3238 assert(_version == const.OFP_VERSION)
3239 _type = reader.read('!B')[0]
3240 assert(_type == const.OFPT_GET_CONFIG_REQUEST)
3241 _length = reader.read('!H')[0]
3242 obj.xid = reader.read('!L')[0]
3243 return obj
3244
3245 def __eq__(self, other):
3246 if type(self) != type(other): return False
3247 if self.version != other.version: return False
3248 if self.type != other.type: return False
3249 if self.xid != other.xid: return False
3250 return True
3251
3252 def __ne__(self, other):
3253 return not self.__eq__(other)
3254
3255 def __str__(self):
3256 return self.show()
3257
3258 def show(self):
3259 import loxi.pp
3260 return loxi.pp.pp(self)
3261
3262 def pretty_print(self, q):
3263 q.text("get_config_request {")
3264 with q.group():
3265 with q.indent(2):
3266 q.breakable()
3267 q.text("xid = ");
3268 if self.xid != None:
3269 q.text("%#x" % self.xid)
3270 else:
3271 q.text('None')
3272 q.breakable()
3273 q.text('}')
3274
3275class group_desc_stats_reply(Message):
3276 version = const.OFP_VERSION
3277 type = const.OFPT_STATS_REPLY
3278 stats_type = const.OFPST_GROUP_DESC
3279
3280 def __init__(self, xid=None, flags=None, entries=None):
3281 self.xid = xid
3282 if flags != None:
3283 self.flags = flags
3284 else:
3285 self.flags = 0
3286 if entries != None:
3287 self.entries = entries
3288 else:
3289 self.entries = []
3290
3291 def pack(self):
3292 packed = []
3293 packed.append(struct.pack("!B", self.version))
3294 packed.append(struct.pack("!B", self.type))
3295 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3296 packed.append(struct.pack("!L", self.xid))
3297 packed.append(struct.pack("!H", self.stats_type))
3298 packed.append(struct.pack("!H", self.flags))
3299 packed.append('\x00' * 4)
3300 packed.append("".join([x.pack() for x in self.entries]))
3301 length = sum([len(x) for x in packed])
3302 packed[2] = struct.pack("!H", length)
3303 return ''.join(packed)
3304
3305 @staticmethod
3306 def unpack(buf):
3307 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3308 obj = group_desc_stats_reply()
3309 if type(buf) == loxi.generic_util.OFReader:
3310 reader = buf
3311 else:
3312 reader = loxi.generic_util.OFReader(buf)
3313 _version = reader.read('!B')[0]
3314 assert(_version == const.OFP_VERSION)
3315 _type = reader.read('!B')[0]
3316 assert(_type == const.OFPT_STATS_REPLY)
3317 _length = reader.read('!H')[0]
3318 obj.xid = reader.read('!L')[0]
3319 _stats_type = reader.read('!H')[0]
3320 assert(_stats_type == const.OFPST_GROUP_DESC)
3321 obj.flags = reader.read('!H')[0]
3322 reader.skip(4)
3323 obj.entries = common.unpack_list_group_desc_stats_entry(reader)
3324 return obj
3325
3326 def __eq__(self, other):
3327 if type(self) != type(other): return False
3328 if self.version != other.version: return False
3329 if self.type != other.type: return False
3330 if self.xid != other.xid: return False
3331 if self.flags != other.flags: return False
3332 if self.entries != other.entries: return False
3333 return True
3334
3335 def __ne__(self, other):
3336 return not self.__eq__(other)
3337
3338 def __str__(self):
3339 return self.show()
3340
3341 def show(self):
3342 import loxi.pp
3343 return loxi.pp.pp(self)
3344
3345 def pretty_print(self, q):
3346 q.text("group_desc_stats_reply {")
3347 with q.group():
3348 with q.indent(2):
3349 q.breakable()
3350 q.text("xid = ");
3351 if self.xid != None:
3352 q.text("%#x" % self.xid)
3353 else:
3354 q.text('None')
3355 q.text(","); q.breakable()
3356 q.text("flags = ");
3357 q.text("%#x" % self.flags)
3358 q.text(","); q.breakable()
3359 q.text("entries = ");
3360 q.pp(self.entries)
3361 q.breakable()
3362 q.text('}')
3363
3364class group_desc_stats_request(Message):
3365 version = const.OFP_VERSION
3366 type = const.OFPT_STATS_REQUEST
3367 stats_type = const.OFPST_GROUP_DESC
3368
3369 def __init__(self, xid=None, flags=None):
3370 self.xid = xid
3371 if flags != None:
3372 self.flags = flags
3373 else:
3374 self.flags = 0
3375
3376 def pack(self):
3377 packed = []
3378 packed.append(struct.pack("!B", self.version))
3379 packed.append(struct.pack("!B", self.type))
3380 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3381 packed.append(struct.pack("!L", self.xid))
3382 packed.append(struct.pack("!H", self.stats_type))
3383 packed.append(struct.pack("!H", self.flags))
3384 packed.append('\x00' * 4)
3385 length = sum([len(x) for x in packed])
3386 packed[2] = struct.pack("!H", length)
3387 return ''.join(packed)
3388
3389 @staticmethod
3390 def unpack(buf):
3391 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3392 obj = group_desc_stats_request()
3393 if type(buf) == loxi.generic_util.OFReader:
3394 reader = buf
3395 else:
3396 reader = loxi.generic_util.OFReader(buf)
3397 _version = reader.read('!B')[0]
3398 assert(_version == const.OFP_VERSION)
3399 _type = reader.read('!B')[0]
3400 assert(_type == const.OFPT_STATS_REQUEST)
3401 _length = reader.read('!H')[0]
3402 obj.xid = reader.read('!L')[0]
3403 _stats_type = reader.read('!H')[0]
3404 assert(_stats_type == const.OFPST_GROUP_DESC)
3405 obj.flags = reader.read('!H')[0]
3406 reader.skip(4)
3407 return obj
3408
3409 def __eq__(self, other):
3410 if type(self) != type(other): return False
3411 if self.version != other.version: return False
3412 if self.type != other.type: return False
3413 if self.xid != other.xid: return False
3414 if self.flags != other.flags: return False
3415 return True
3416
3417 def __ne__(self, other):
3418 return not self.__eq__(other)
3419
3420 def __str__(self):
3421 return self.show()
3422
3423 def show(self):
3424 import loxi.pp
3425 return loxi.pp.pp(self)
3426
3427 def pretty_print(self, q):
3428 q.text("group_desc_stats_request {")
3429 with q.group():
3430 with q.indent(2):
3431 q.breakable()
3432 q.text("xid = ");
3433 if self.xid != None:
3434 q.text("%#x" % self.xid)
3435 else:
3436 q.text('None')
3437 q.text(","); q.breakable()
3438 q.text("flags = ");
3439 q.text("%#x" % self.flags)
3440 q.breakable()
3441 q.text('}')
3442
3443class group_features_stats_reply(Message):
3444 version = const.OFP_VERSION
3445 type = const.OFPT_STATS_REPLY
3446 stats_type = const.OFPST_GROUP_FEATURES
3447
3448 def __init__(self, xid=None, flags=None, types=None, capabilities=None, max_groups_all=None, max_groups_select=None, max_groups_indirect=None, max_groups_ff=None, actions_all=None, actions_select=None, actions_indirect=None, actions_ff=None):
3449 self.xid = xid
3450 if flags != None:
3451 self.flags = flags
3452 else:
3453 self.flags = 0
3454 if types != None:
3455 self.types = types
3456 else:
3457 self.types = 0
3458 if capabilities != None:
3459 self.capabilities = capabilities
3460 else:
3461 self.capabilities = 0
3462 if max_groups_all != None:
3463 self.max_groups_all = max_groups_all
3464 else:
3465 self.max_groups_all = 0
3466 if max_groups_select != None:
3467 self.max_groups_select = max_groups_select
3468 else:
3469 self.max_groups_select = 0
3470 if max_groups_indirect != None:
3471 self.max_groups_indirect = max_groups_indirect
3472 else:
3473 self.max_groups_indirect = 0
3474 if max_groups_ff != None:
3475 self.max_groups_ff = max_groups_ff
3476 else:
3477 self.max_groups_ff = 0
3478 if actions_all != None:
3479 self.actions_all = actions_all
3480 else:
3481 self.actions_all = 0
3482 if actions_select != None:
3483 self.actions_select = actions_select
3484 else:
3485 self.actions_select = 0
3486 if actions_indirect != None:
3487 self.actions_indirect = actions_indirect
3488 else:
3489 self.actions_indirect = 0
3490 if actions_ff != None:
3491 self.actions_ff = actions_ff
3492 else:
3493 self.actions_ff = 0
3494
3495 def pack(self):
3496 packed = []
3497 packed.append(struct.pack("!B", self.version))
3498 packed.append(struct.pack("!B", self.type))
3499 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3500 packed.append(struct.pack("!L", self.xid))
3501 packed.append(struct.pack("!H", self.stats_type))
3502 packed.append(struct.pack("!H", self.flags))
3503 packed.append('\x00' * 4)
3504 packed.append(struct.pack("!L", self.types))
3505 packed.append(struct.pack("!L", self.capabilities))
3506 packed.append(struct.pack("!L", self.max_groups_all))
3507 packed.append(struct.pack("!L", self.max_groups_select))
3508 packed.append(struct.pack("!L", self.max_groups_indirect))
3509 packed.append(struct.pack("!L", self.max_groups_ff))
3510 packed.append(struct.pack("!L", self.actions_all))
3511 packed.append(struct.pack("!L", self.actions_select))
3512 packed.append(struct.pack("!L", self.actions_indirect))
3513 packed.append(struct.pack("!L", self.actions_ff))
3514 length = sum([len(x) for x in packed])
3515 packed[2] = struct.pack("!H", length)
3516 return ''.join(packed)
3517
3518 @staticmethod
3519 def unpack(buf):
3520 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3521 obj = group_features_stats_reply()
3522 if type(buf) == loxi.generic_util.OFReader:
3523 reader = buf
3524 else:
3525 reader = loxi.generic_util.OFReader(buf)
3526 _version = reader.read('!B')[0]
3527 assert(_version == const.OFP_VERSION)
3528 _type = reader.read('!B')[0]
3529 assert(_type == const.OFPT_STATS_REPLY)
3530 _length = reader.read('!H')[0]
3531 obj.xid = reader.read('!L')[0]
3532 _stats_type = reader.read('!H')[0]
3533 assert(_stats_type == const.OFPST_GROUP_FEATURES)
3534 obj.flags = reader.read('!H')[0]
3535 reader.skip(4)
3536 obj.types = reader.read('!L')[0]
3537 obj.capabilities = reader.read('!L')[0]
3538 obj.max_groups_all = reader.read('!L')[0]
3539 obj.max_groups_select = reader.read('!L')[0]
3540 obj.max_groups_indirect = reader.read('!L')[0]
3541 obj.max_groups_ff = reader.read('!L')[0]
3542 obj.actions_all = reader.read('!L')[0]
3543 obj.actions_select = reader.read('!L')[0]
3544 obj.actions_indirect = reader.read('!L')[0]
3545 obj.actions_ff = reader.read('!L')[0]
3546 return obj
3547
3548 def __eq__(self, other):
3549 if type(self) != type(other): return False
3550 if self.version != other.version: return False
3551 if self.type != other.type: return False
3552 if self.xid != other.xid: return False
3553 if self.flags != other.flags: return False
3554 if self.types != other.types: return False
3555 if self.capabilities != other.capabilities: return False
3556 if self.max_groups_all != other.max_groups_all: return False
3557 if self.max_groups_select != other.max_groups_select: return False
3558 if self.max_groups_indirect != other.max_groups_indirect: return False
3559 if self.max_groups_ff != other.max_groups_ff: return False
3560 if self.actions_all != other.actions_all: return False
3561 if self.actions_select != other.actions_select: return False
3562 if self.actions_indirect != other.actions_indirect: return False
3563 if self.actions_ff != other.actions_ff: return False
3564 return True
3565
3566 def __ne__(self, other):
3567 return not self.__eq__(other)
3568
3569 def __str__(self):
3570 return self.show()
3571
3572 def show(self):
3573 import loxi.pp
3574 return loxi.pp.pp(self)
3575
3576 def pretty_print(self, q):
3577 q.text("group_features_stats_reply {")
3578 with q.group():
3579 with q.indent(2):
3580 q.breakable()
3581 q.text("xid = ");
3582 if self.xid != None:
3583 q.text("%#x" % self.xid)
3584 else:
3585 q.text('None')
3586 q.text(","); q.breakable()
3587 q.text("flags = ");
3588 q.text("%#x" % self.flags)
3589 q.text(","); q.breakable()
3590 q.text("types = ");
3591 q.text("%#x" % self.types)
3592 q.text(","); q.breakable()
3593 q.text("capabilities = ");
3594 q.text("%#x" % self.capabilities)
3595 q.text(","); q.breakable()
3596 q.text("max_groups_all = ");
3597 q.text("%#x" % self.max_groups_all)
3598 q.text(","); q.breakable()
3599 q.text("max_groups_select = ");
3600 q.text("%#x" % self.max_groups_select)
3601 q.text(","); q.breakable()
3602 q.text("max_groups_indirect = ");
3603 q.text("%#x" % self.max_groups_indirect)
3604 q.text(","); q.breakable()
3605 q.text("max_groups_ff = ");
3606 q.text("%#x" % self.max_groups_ff)
3607 q.text(","); q.breakable()
3608 q.text("actions_all = ");
3609 q.text("%#x" % self.actions_all)
3610 q.text(","); q.breakable()
3611 q.text("actions_select = ");
3612 q.text("%#x" % self.actions_select)
3613 q.text(","); q.breakable()
3614 q.text("actions_indirect = ");
3615 q.text("%#x" % self.actions_indirect)
3616 q.text(","); q.breakable()
3617 q.text("actions_ff = ");
3618 q.text("%#x" % self.actions_ff)
3619 q.breakable()
3620 q.text('}')
3621
3622class group_features_stats_request(Message):
3623 version = const.OFP_VERSION
3624 type = const.OFPT_STATS_REQUEST
3625 stats_type = const.OFPST_GROUP_FEATURES
3626
3627 def __init__(self, xid=None, flags=None):
3628 self.xid = xid
3629 if flags != None:
3630 self.flags = flags
3631 else:
3632 self.flags = 0
3633
3634 def pack(self):
3635 packed = []
3636 packed.append(struct.pack("!B", self.version))
3637 packed.append(struct.pack("!B", self.type))
3638 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3639 packed.append(struct.pack("!L", self.xid))
3640 packed.append(struct.pack("!H", self.stats_type))
3641 packed.append(struct.pack("!H", self.flags))
3642 packed.append('\x00' * 4)
3643 length = sum([len(x) for x in packed])
3644 packed[2] = struct.pack("!H", length)
3645 return ''.join(packed)
3646
3647 @staticmethod
3648 def unpack(buf):
3649 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3650 obj = group_features_stats_request()
3651 if type(buf) == loxi.generic_util.OFReader:
3652 reader = buf
3653 else:
3654 reader = loxi.generic_util.OFReader(buf)
3655 _version = reader.read('!B')[0]
3656 assert(_version == const.OFP_VERSION)
3657 _type = reader.read('!B')[0]
3658 assert(_type == const.OFPT_STATS_REQUEST)
3659 _length = reader.read('!H')[0]
3660 obj.xid = reader.read('!L')[0]
3661 _stats_type = reader.read('!H')[0]
3662 assert(_stats_type == const.OFPST_GROUP_FEATURES)
3663 obj.flags = reader.read('!H')[0]
3664 reader.skip(4)
3665 return obj
3666
3667 def __eq__(self, other):
3668 if type(self) != type(other): return False
3669 if self.version != other.version: return False
3670 if self.type != other.type: return False
3671 if self.xid != other.xid: return False
3672 if self.flags != other.flags: return False
3673 return True
3674
3675 def __ne__(self, other):
3676 return not self.__eq__(other)
3677
3678 def __str__(self):
3679 return self.show()
3680
3681 def show(self):
3682 import loxi.pp
3683 return loxi.pp.pp(self)
3684
3685 def pretty_print(self, q):
3686 q.text("group_features_stats_request {")
3687 with q.group():
3688 with q.indent(2):
3689 q.breakable()
3690 q.text("xid = ");
3691 if self.xid != None:
3692 q.text("%#x" % self.xid)
3693 else:
3694 q.text('None')
3695 q.text(","); q.breakable()
3696 q.text("flags = ");
3697 q.text("%#x" % self.flags)
3698 q.breakable()
3699 q.text('}')
3700
3701class group_mod(Message):
3702 version = const.OFP_VERSION
3703 type = const.OFPT_GROUP_MOD
3704
3705 def __init__(self, xid=None, command=None, group_type=None, group_id=None, buckets=None):
3706 self.xid = xid
3707 if command != None:
3708 self.command = command
3709 else:
3710 self.command = 0
3711 if group_type != None:
3712 self.group_type = group_type
3713 else:
3714 self.group_type = 0
3715 if group_id != None:
3716 self.group_id = group_id
3717 else:
3718 self.group_id = 0
3719 if buckets != None:
3720 self.buckets = buckets
3721 else:
3722 self.buckets = []
3723
3724 def pack(self):
3725 packed = []
3726 packed.append(struct.pack("!B", self.version))
3727 packed.append(struct.pack("!B", self.type))
3728 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3729 packed.append(struct.pack("!L", self.xid))
3730 packed.append(struct.pack("!H", self.command))
3731 packed.append(struct.pack("!B", self.group_type))
3732 packed.append('\x00' * 1)
3733 packed.append(struct.pack("!L", self.group_id))
3734 packed.append("".join([x.pack() for x in self.buckets]))
3735 length = sum([len(x) for x in packed])
3736 packed[2] = struct.pack("!H", length)
3737 return ''.join(packed)
3738
3739 @staticmethod
3740 def unpack(buf):
3741 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3742 obj = group_mod()
3743 if type(buf) == loxi.generic_util.OFReader:
3744 reader = buf
3745 else:
3746 reader = loxi.generic_util.OFReader(buf)
3747 _version = reader.read('!B')[0]
3748 assert(_version == const.OFP_VERSION)
3749 _type = reader.read('!B')[0]
3750 assert(_type == const.OFPT_GROUP_MOD)
3751 _length = reader.read('!H')[0]
3752 obj.xid = reader.read('!L')[0]
3753 obj.command = reader.read('!H')[0]
3754 obj.group_type = reader.read('!B')[0]
3755 reader.skip(1)
3756 obj.group_id = reader.read('!L')[0]
3757 obj.buckets = common.unpack_list_bucket(reader)
3758 return obj
3759
3760 def __eq__(self, other):
3761 if type(self) != type(other): return False
3762 if self.version != other.version: return False
3763 if self.type != other.type: return False
3764 if self.xid != other.xid: return False
3765 if self.command != other.command: return False
3766 if self.group_type != other.group_type: return False
3767 if self.group_id != other.group_id: return False
3768 if self.buckets != other.buckets: return False
3769 return True
3770
3771 def __ne__(self, other):
3772 return not self.__eq__(other)
3773
3774 def __str__(self):
3775 return self.show()
3776
3777 def show(self):
3778 import loxi.pp
3779 return loxi.pp.pp(self)
3780
3781 def pretty_print(self, q):
3782 q.text("group_mod {")
3783 with q.group():
3784 with q.indent(2):
3785 q.breakable()
3786 q.text("xid = ");
3787 if self.xid != None:
3788 q.text("%#x" % self.xid)
3789 else:
3790 q.text('None')
3791 q.text(","); q.breakable()
3792 q.text("command = ");
3793 q.text("%#x" % self.command)
3794 q.text(","); q.breakable()
3795 q.text("group_type = ");
3796 q.text("%#x" % self.group_type)
3797 q.text(","); q.breakable()
3798 q.text("group_id = ");
3799 q.text("%#x" % self.group_id)
3800 q.text(","); q.breakable()
3801 q.text("buckets = ");
3802 q.pp(self.buckets)
3803 q.breakable()
3804 q.text('}')
3805
3806class group_stats_reply(Message):
3807 version = const.OFP_VERSION
3808 type = const.OFPT_STATS_REPLY
3809 stats_type = const.OFPST_GROUP
3810
3811 def __init__(self, xid=None, flags=None, entries=None):
3812 self.xid = xid
3813 if flags != None:
3814 self.flags = flags
3815 else:
3816 self.flags = 0
3817 if entries != None:
3818 self.entries = entries
3819 else:
3820 self.entries = []
3821
3822 def pack(self):
3823 packed = []
3824 packed.append(struct.pack("!B", self.version))
3825 packed.append(struct.pack("!B", self.type))
3826 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3827 packed.append(struct.pack("!L", self.xid))
3828 packed.append(struct.pack("!H", self.stats_type))
3829 packed.append(struct.pack("!H", self.flags))
3830 packed.append('\x00' * 4)
3831 packed.append("".join([x.pack() for x in self.entries]))
3832 length = sum([len(x) for x in packed])
3833 packed[2] = struct.pack("!H", length)
3834 return ''.join(packed)
3835
3836 @staticmethod
3837 def unpack(buf):
3838 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3839 obj = group_stats_reply()
3840 if type(buf) == loxi.generic_util.OFReader:
3841 reader = buf
3842 else:
3843 reader = loxi.generic_util.OFReader(buf)
3844 _version = reader.read('!B')[0]
3845 assert(_version == const.OFP_VERSION)
3846 _type = reader.read('!B')[0]
3847 assert(_type == const.OFPT_STATS_REPLY)
3848 _length = reader.read('!H')[0]
3849 obj.xid = reader.read('!L')[0]
3850 _stats_type = reader.read('!H')[0]
3851 assert(_stats_type == const.OFPST_GROUP)
3852 obj.flags = reader.read('!H')[0]
3853 reader.skip(4)
3854 obj.entries = common.unpack_list_group_stats_entry(reader)
3855 return obj
3856
3857 def __eq__(self, other):
3858 if type(self) != type(other): return False
3859 if self.version != other.version: return False
3860 if self.type != other.type: return False
3861 if self.xid != other.xid: return False
3862 if self.flags != other.flags: return False
3863 if self.entries != other.entries: return False
3864 return True
3865
3866 def __ne__(self, other):
3867 return not self.__eq__(other)
3868
3869 def __str__(self):
3870 return self.show()
3871
3872 def show(self):
3873 import loxi.pp
3874 return loxi.pp.pp(self)
3875
3876 def pretty_print(self, q):
3877 q.text("group_stats_reply {")
3878 with q.group():
3879 with q.indent(2):
3880 q.breakable()
3881 q.text("xid = ");
3882 if self.xid != None:
3883 q.text("%#x" % self.xid)
3884 else:
3885 q.text('None')
3886 q.text(","); q.breakable()
3887 q.text("flags = ");
3888 q.text("%#x" % self.flags)
3889 q.text(","); q.breakable()
3890 q.text("entries = ");
3891 q.pp(self.entries)
3892 q.breakable()
3893 q.text('}')
3894
3895class group_stats_request(Message):
3896 version = const.OFP_VERSION
3897 type = const.OFPT_STATS_REQUEST
3898 stats_type = const.OFPST_GROUP
3899
3900 def __init__(self, xid=None, flags=None, group_id=None):
3901 self.xid = xid
3902 if flags != None:
3903 self.flags = flags
3904 else:
3905 self.flags = 0
3906 if group_id != None:
3907 self.group_id = group_id
3908 else:
3909 self.group_id = 0
3910
3911 def pack(self):
3912 packed = []
3913 packed.append(struct.pack("!B", self.version))
3914 packed.append(struct.pack("!B", self.type))
3915 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3916 packed.append(struct.pack("!L", self.xid))
3917 packed.append(struct.pack("!H", self.stats_type))
3918 packed.append(struct.pack("!H", self.flags))
3919 packed.append('\x00' * 4)
3920 packed.append(struct.pack("!L", self.group_id))
3921 packed.append('\x00' * 4)
3922 length = sum([len(x) for x in packed])
3923 packed[2] = struct.pack("!H", length)
3924 return ''.join(packed)
3925
3926 @staticmethod
3927 def unpack(buf):
3928 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3929 obj = group_stats_request()
3930 if type(buf) == loxi.generic_util.OFReader:
3931 reader = buf
3932 else:
3933 reader = loxi.generic_util.OFReader(buf)
3934 _version = reader.read('!B')[0]
3935 assert(_version == const.OFP_VERSION)
3936 _type = reader.read('!B')[0]
3937 assert(_type == const.OFPT_STATS_REQUEST)
3938 _length = reader.read('!H')[0]
3939 obj.xid = reader.read('!L')[0]
3940 _stats_type = reader.read('!H')[0]
3941 assert(_stats_type == const.OFPST_GROUP)
3942 obj.flags = reader.read('!H')[0]
3943 reader.skip(4)
3944 obj.group_id = reader.read('!L')[0]
3945 reader.skip(4)
3946 return obj
3947
3948 def __eq__(self, other):
3949 if type(self) != type(other): return False
3950 if self.version != other.version: return False
3951 if self.type != other.type: return False
3952 if self.xid != other.xid: return False
3953 if self.flags != other.flags: return False
3954 if self.group_id != other.group_id: return False
3955 return True
3956
3957 def __ne__(self, other):
3958 return not self.__eq__(other)
3959
3960 def __str__(self):
3961 return self.show()
3962
3963 def show(self):
3964 import loxi.pp
3965 return loxi.pp.pp(self)
3966
3967 def pretty_print(self, q):
3968 q.text("group_stats_request {")
3969 with q.group():
3970 with q.indent(2):
3971 q.breakable()
3972 q.text("xid = ");
3973 if self.xid != None:
3974 q.text("%#x" % self.xid)
3975 else:
3976 q.text('None')
3977 q.text(","); q.breakable()
3978 q.text("flags = ");
3979 q.text("%#x" % self.flags)
3980 q.text(","); q.breakable()
3981 q.text("group_id = ");
3982 q.text("%#x" % self.group_id)
3983 q.breakable()
3984 q.text('}')
3985
3986class hello(Message):
3987 version = const.OFP_VERSION
3988 type = const.OFPT_HELLO
3989
3990 def __init__(self, xid=None):
3991 self.xid = xid
3992
3993 def pack(self):
3994 packed = []
3995 packed.append(struct.pack("!B", self.version))
3996 packed.append(struct.pack("!B", self.type))
3997 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3998 packed.append(struct.pack("!L", self.xid))
3999 length = sum([len(x) for x in packed])
4000 packed[2] = struct.pack("!H", length)
4001 return ''.join(packed)
4002
4003 @staticmethod
4004 def unpack(buf):
4005 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4006 obj = hello()
4007 if type(buf) == loxi.generic_util.OFReader:
4008 reader = buf
4009 else:
4010 reader = loxi.generic_util.OFReader(buf)
4011 _version = reader.read('!B')[0]
4012 assert(_version == const.OFP_VERSION)
4013 _type = reader.read('!B')[0]
4014 assert(_type == const.OFPT_HELLO)
4015 _length = reader.read('!H')[0]
4016 obj.xid = reader.read('!L')[0]
4017 return obj
4018
4019 def __eq__(self, other):
4020 if type(self) != type(other): return False
4021 if self.version != other.version: return False
4022 if self.type != other.type: return False
4023 if self.xid != other.xid: return False
4024 return True
4025
4026 def __ne__(self, other):
4027 return not self.__eq__(other)
4028
4029 def __str__(self):
4030 return self.show()
4031
4032 def show(self):
4033 import loxi.pp
4034 return loxi.pp.pp(self)
4035
4036 def pretty_print(self, q):
4037 q.text("hello {")
4038 with q.group():
4039 with q.indent(2):
4040 q.breakable()
4041 q.text("xid = ");
4042 if self.xid != None:
4043 q.text("%#x" % self.xid)
4044 else:
4045 q.text('None')
4046 q.breakable()
4047 q.text('}')
4048
4049class packet_in(Message):
4050 version = const.OFP_VERSION
4051 type = const.OFPT_PACKET_IN
4052
4053 def __init__(self, xid=None, buffer_id=None, total_len=None, reason=None, table_id=None, match=None, data=None):
4054 self.xid = xid
4055 if buffer_id != None:
4056 self.buffer_id = buffer_id
4057 else:
4058 self.buffer_id = 0
4059 if total_len != None:
4060 self.total_len = total_len
4061 else:
4062 self.total_len = 0
4063 if reason != None:
4064 self.reason = reason
4065 else:
4066 self.reason = 0
4067 if table_id != None:
4068 self.table_id = table_id
4069 else:
4070 self.table_id = 0
4071 if match != None:
4072 self.match = match
4073 else:
4074 self.match = common.match()
4075 if data != None:
4076 self.data = data
4077 else:
4078 self.data = ""
4079
4080 def pack(self):
4081 packed = []
4082 packed.append(struct.pack("!B", self.version))
4083 packed.append(struct.pack("!B", self.type))
4084 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4085 packed.append(struct.pack("!L", self.xid))
4086 packed.append(struct.pack("!L", self.buffer_id))
4087 packed.append(struct.pack("!H", self.total_len))
4088 packed.append(struct.pack("!B", self.reason))
4089 packed.append(struct.pack("!B", self.table_id))
4090 packed.append(self.match.pack())
4091 packed.append('\x00' * 2)
4092 packed.append(self.data)
4093 length = sum([len(x) for x in packed])
4094 packed[2] = struct.pack("!H", length)
4095 return ''.join(packed)
4096
4097 @staticmethod
4098 def unpack(buf):
4099 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4100 obj = packet_in()
4101 if type(buf) == loxi.generic_util.OFReader:
4102 reader = buf
4103 else:
4104 reader = loxi.generic_util.OFReader(buf)
4105 _version = reader.read('!B')[0]
4106 assert(_version == const.OFP_VERSION)
4107 _type = reader.read('!B')[0]
4108 assert(_type == const.OFPT_PACKET_IN)
4109 _length = reader.read('!H')[0]
4110 obj.xid = reader.read('!L')[0]
4111 obj.buffer_id = reader.read('!L')[0]
4112 obj.total_len = reader.read('!H')[0]
4113 obj.reason = reader.read('!B')[0]
4114 obj.table_id = reader.read('!B')[0]
4115 obj.match = common.match.unpack(reader)
4116 reader.skip(2)
4117 obj.data = str(reader.read_all())
4118 return obj
4119
4120 def __eq__(self, other):
4121 if type(self) != type(other): return False
4122 if self.version != other.version: return False
4123 if self.type != other.type: return False
4124 if self.xid != other.xid: return False
4125 if self.buffer_id != other.buffer_id: return False
4126 if self.total_len != other.total_len: return False
4127 if self.reason != other.reason: return False
4128 if self.table_id != other.table_id: return False
4129 if self.match != other.match: return False
4130 if self.data != other.data: return False
4131 return True
4132
4133 def __ne__(self, other):
4134 return not self.__eq__(other)
4135
4136 def __str__(self):
4137 return self.show()
4138
4139 def show(self):
4140 import loxi.pp
4141 return loxi.pp.pp(self)
4142
4143 def pretty_print(self, q):
4144 q.text("packet_in {")
4145 with q.group():
4146 with q.indent(2):
4147 q.breakable()
4148 q.text("xid = ");
4149 if self.xid != None:
4150 q.text("%#x" % self.xid)
4151 else:
4152 q.text('None')
4153 q.text(","); q.breakable()
4154 q.text("buffer_id = ");
4155 q.text("%#x" % self.buffer_id)
4156 q.text(","); q.breakable()
4157 q.text("total_len = ");
4158 q.text("%#x" % self.total_len)
4159 q.text(","); q.breakable()
4160 q.text("reason = ");
4161 q.text("%#x" % self.reason)
4162 q.text(","); q.breakable()
4163 q.text("table_id = ");
4164 q.text("%#x" % self.table_id)
4165 q.text(","); q.breakable()
4166 q.text("match = ");
4167 q.pp(self.match)
4168 q.text(","); q.breakable()
4169 q.text("data = ");
4170 q.pp(self.data)
4171 q.breakable()
4172 q.text('}')
4173
4174class packet_out(Message):
4175 version = const.OFP_VERSION
4176 type = const.OFPT_PACKET_OUT
4177
4178 def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
4179 self.xid = xid
4180 if buffer_id != None:
4181 self.buffer_id = buffer_id
4182 else:
4183 self.buffer_id = 0
4184 if in_port != None:
4185 self.in_port = in_port
4186 else:
4187 self.in_port = 0
4188 if actions != None:
4189 self.actions = actions
4190 else:
4191 self.actions = []
4192 if data != None:
4193 self.data = data
4194 else:
4195 self.data = ""
4196
4197 def pack(self):
4198 packed = []
4199 packed.append(struct.pack("!B", self.version))
4200 packed.append(struct.pack("!B", self.type))
4201 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4202 packed.append(struct.pack("!L", self.xid))
4203 packed.append(struct.pack("!L", self.buffer_id))
4204 packed.append(struct.pack("!L", self.in_port))
4205 packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
4206 packed.append('\x00' * 6)
4207 packed.append("".join([x.pack() for x in self.actions]))
4208 packed[6] = struct.pack("!H", len(packed[-1]))
4209 packed.append(self.data)
4210 length = sum([len(x) for x in packed])
4211 packed[2] = struct.pack("!H", length)
4212 return ''.join(packed)
4213
4214 @staticmethod
4215 def unpack(buf):
4216 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4217 obj = packet_out()
4218 if type(buf) == loxi.generic_util.OFReader:
4219 reader = buf
4220 else:
4221 reader = loxi.generic_util.OFReader(buf)
4222 _version = reader.read('!B')[0]
4223 assert(_version == const.OFP_VERSION)
4224 _type = reader.read('!B')[0]
4225 assert(_type == const.OFPT_PACKET_OUT)
4226 _length = reader.read('!H')[0]
4227 obj.xid = reader.read('!L')[0]
4228 obj.buffer_id = reader.read('!L')[0]
4229 obj.in_port = reader.read('!L')[0]
4230 _actions_len = reader.read('!H')[0]
4231 reader.skip(6)
4232 obj.actions = action.unpack_list(reader.slice(_actions_len))
4233 obj.data = str(reader.read_all())
4234 return obj
4235
4236 def __eq__(self, other):
4237 if type(self) != type(other): return False
4238 if self.version != other.version: return False
4239 if self.type != other.type: return False
4240 if self.xid != other.xid: return False
4241 if self.buffer_id != other.buffer_id: return False
4242 if self.in_port != other.in_port: return False
4243 if self.actions != other.actions: return False
4244 if self.data != other.data: return False
4245 return True
4246
4247 def __ne__(self, other):
4248 return not self.__eq__(other)
4249
4250 def __str__(self):
4251 return self.show()
4252
4253 def show(self):
4254 import loxi.pp
4255 return loxi.pp.pp(self)
4256
4257 def pretty_print(self, q):
4258 q.text("packet_out {")
4259 with q.group():
4260 with q.indent(2):
4261 q.breakable()
4262 q.text("xid = ");
4263 if self.xid != None:
4264 q.text("%#x" % self.xid)
4265 else:
4266 q.text('None')
4267 q.text(","); q.breakable()
4268 q.text("buffer_id = ");
4269 q.text("%#x" % self.buffer_id)
4270 q.text(","); q.breakable()
4271 q.text("in_port = ");
4272 q.text(util.pretty_port(self.in_port))
4273 q.text(","); q.breakable()
4274 q.text("actions = ");
4275 q.pp(self.actions)
4276 q.text(","); q.breakable()
4277 q.text("data = ");
4278 q.pp(self.data)
4279 q.breakable()
4280 q.text('}')
4281
4282class port_mod(Message):
4283 version = const.OFP_VERSION
4284 type = const.OFPT_PORT_MOD
4285
4286 def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None):
4287 self.xid = xid
4288 if port_no != None:
4289 self.port_no = port_no
4290 else:
4291 self.port_no = 0
4292 if hw_addr != None:
4293 self.hw_addr = hw_addr
4294 else:
4295 self.hw_addr = [0,0,0,0,0,0]
4296 if config != None:
4297 self.config = config
4298 else:
4299 self.config = 0
4300 if mask != None:
4301 self.mask = mask
4302 else:
4303 self.mask = 0
4304 if advertise != None:
4305 self.advertise = advertise
4306 else:
4307 self.advertise = 0
4308
4309 def pack(self):
4310 packed = []
4311 packed.append(struct.pack("!B", self.version))
4312 packed.append(struct.pack("!B", self.type))
4313 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4314 packed.append(struct.pack("!L", self.xid))
4315 packed.append(struct.pack("!L", self.port_no))
4316 packed.append('\x00' * 4)
4317 packed.append(struct.pack("!6B", *self.hw_addr))
4318 packed.append('\x00' * 2)
4319 packed.append(struct.pack("!L", self.config))
4320 packed.append(struct.pack("!L", self.mask))
4321 packed.append(struct.pack("!L", self.advertise))
4322 packed.append('\x00' * 4)
4323 length = sum([len(x) for x in packed])
4324 packed[2] = struct.pack("!H", length)
4325 return ''.join(packed)
4326
4327 @staticmethod
4328 def unpack(buf):
4329 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4330 obj = port_mod()
4331 if type(buf) == loxi.generic_util.OFReader:
4332 reader = buf
4333 else:
4334 reader = loxi.generic_util.OFReader(buf)
4335 _version = reader.read('!B')[0]
4336 assert(_version == const.OFP_VERSION)
4337 _type = reader.read('!B')[0]
4338 assert(_type == const.OFPT_PORT_MOD)
4339 _length = reader.read('!H')[0]
4340 obj.xid = reader.read('!L')[0]
4341 obj.port_no = reader.read('!L')[0]
4342 reader.skip(4)
4343 obj.hw_addr = list(reader.read('!6B'))
4344 reader.skip(2)
4345 obj.config = reader.read('!L')[0]
4346 obj.mask = reader.read('!L')[0]
4347 obj.advertise = reader.read('!L')[0]
4348 reader.skip(4)
4349 return obj
4350
4351 def __eq__(self, other):
4352 if type(self) != type(other): return False
4353 if self.version != other.version: return False
4354 if self.type != other.type: return False
4355 if self.xid != other.xid: return False
4356 if self.port_no != other.port_no: return False
4357 if self.hw_addr != other.hw_addr: return False
4358 if self.config != other.config: return False
4359 if self.mask != other.mask: return False
4360 if self.advertise != other.advertise: return False
4361 return True
4362
4363 def __ne__(self, other):
4364 return not self.__eq__(other)
4365
4366 def __str__(self):
4367 return self.show()
4368
4369 def show(self):
4370 import loxi.pp
4371 return loxi.pp.pp(self)
4372
4373 def pretty_print(self, q):
4374 q.text("port_mod {")
4375 with q.group():
4376 with q.indent(2):
4377 q.breakable()
4378 q.text("xid = ");
4379 if self.xid != None:
4380 q.text("%#x" % self.xid)
4381 else:
4382 q.text('None')
4383 q.text(","); q.breakable()
4384 q.text("port_no = ");
4385 q.text(util.pretty_port(self.port_no))
4386 q.text(","); q.breakable()
4387 q.text("hw_addr = ");
4388 q.text(util.pretty_mac(self.hw_addr))
4389 q.text(","); q.breakable()
4390 q.text("config = ");
4391 q.text("%#x" % self.config)
4392 q.text(","); q.breakable()
4393 q.text("mask = ");
4394 q.text("%#x" % self.mask)
4395 q.text(","); q.breakable()
4396 q.text("advertise = ");
4397 q.text("%#x" % self.advertise)
4398 q.breakable()
4399 q.text('}')
4400
4401class port_stats_reply(Message):
4402 version = const.OFP_VERSION
4403 type = const.OFPT_STATS_REPLY
4404 stats_type = const.OFPST_PORT
4405
4406 def __init__(self, xid=None, flags=None, entries=None):
4407 self.xid = xid
4408 if flags != None:
4409 self.flags = flags
4410 else:
4411 self.flags = 0
4412 if entries != None:
4413 self.entries = entries
4414 else:
4415 self.entries = []
4416
4417 def pack(self):
4418 packed = []
4419 packed.append(struct.pack("!B", self.version))
4420 packed.append(struct.pack("!B", self.type))
4421 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4422 packed.append(struct.pack("!L", self.xid))
4423 packed.append(struct.pack("!H", self.stats_type))
4424 packed.append(struct.pack("!H", self.flags))
4425 packed.append('\x00' * 4)
4426 packed.append("".join([x.pack() for x in self.entries]))
4427 length = sum([len(x) for x in packed])
4428 packed[2] = struct.pack("!H", length)
4429 return ''.join(packed)
4430
4431 @staticmethod
4432 def unpack(buf):
4433 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4434 obj = port_stats_reply()
4435 if type(buf) == loxi.generic_util.OFReader:
4436 reader = buf
4437 else:
4438 reader = loxi.generic_util.OFReader(buf)
4439 _version = reader.read('!B')[0]
4440 assert(_version == const.OFP_VERSION)
4441 _type = reader.read('!B')[0]
4442 assert(_type == const.OFPT_STATS_REPLY)
4443 _length = reader.read('!H')[0]
4444 obj.xid = reader.read('!L')[0]
4445 _stats_type = reader.read('!H')[0]
4446 assert(_stats_type == const.OFPST_PORT)
4447 obj.flags = reader.read('!H')[0]
4448 reader.skip(4)
4449 obj.entries = loxi.generic_util.unpack_list(reader, common.port_stats_entry.unpack)
4450 return obj
4451
4452 def __eq__(self, other):
4453 if type(self) != type(other): return False
4454 if self.version != other.version: return False
4455 if self.type != other.type: return False
4456 if self.xid != other.xid: return False
4457 if self.flags != other.flags: return False
4458 if self.entries != other.entries: return False
4459 return True
4460
4461 def __ne__(self, other):
4462 return not self.__eq__(other)
4463
4464 def __str__(self):
4465 return self.show()
4466
4467 def show(self):
4468 import loxi.pp
4469 return loxi.pp.pp(self)
4470
4471 def pretty_print(self, q):
4472 q.text("port_stats_reply {")
4473 with q.group():
4474 with q.indent(2):
4475 q.breakable()
4476 q.text("xid = ");
4477 if self.xid != None:
4478 q.text("%#x" % self.xid)
4479 else:
4480 q.text('None')
4481 q.text(","); q.breakable()
4482 q.text("flags = ");
4483 q.text("%#x" % self.flags)
4484 q.text(","); q.breakable()
4485 q.text("entries = ");
4486 q.pp(self.entries)
4487 q.breakable()
4488 q.text('}')
4489
4490class port_stats_request(Message):
4491 version = const.OFP_VERSION
4492 type = const.OFPT_STATS_REQUEST
4493 stats_type = const.OFPST_PORT
4494
4495 def __init__(self, xid=None, flags=None, port_no=None):
4496 self.xid = xid
4497 if flags != None:
4498 self.flags = flags
4499 else:
4500 self.flags = 0
4501 if port_no != None:
4502 self.port_no = port_no
4503 else:
4504 self.port_no = 0
4505
4506 def pack(self):
4507 packed = []
4508 packed.append(struct.pack("!B", self.version))
4509 packed.append(struct.pack("!B", self.type))
4510 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4511 packed.append(struct.pack("!L", self.xid))
4512 packed.append(struct.pack("!H", self.stats_type))
4513 packed.append(struct.pack("!H", self.flags))
4514 packed.append('\x00' * 4)
4515 packed.append(struct.pack("!L", self.port_no))
4516 packed.append('\x00' * 4)
4517 length = sum([len(x) for x in packed])
4518 packed[2] = struct.pack("!H", length)
4519 return ''.join(packed)
4520
4521 @staticmethod
4522 def unpack(buf):
4523 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4524 obj = port_stats_request()
4525 if type(buf) == loxi.generic_util.OFReader:
4526 reader = buf
4527 else:
4528 reader = loxi.generic_util.OFReader(buf)
4529 _version = reader.read('!B')[0]
4530 assert(_version == const.OFP_VERSION)
4531 _type = reader.read('!B')[0]
4532 assert(_type == const.OFPT_STATS_REQUEST)
4533 _length = reader.read('!H')[0]
4534 obj.xid = reader.read('!L')[0]
4535 _stats_type = reader.read('!H')[0]
4536 assert(_stats_type == const.OFPST_PORT)
4537 obj.flags = reader.read('!H')[0]
4538 reader.skip(4)
4539 obj.port_no = reader.read('!L')[0]
4540 reader.skip(4)
4541 return obj
4542
4543 def __eq__(self, other):
4544 if type(self) != type(other): return False
4545 if self.version != other.version: return False
4546 if self.type != other.type: return False
4547 if self.xid != other.xid: return False
4548 if self.flags != other.flags: return False
4549 if self.port_no != other.port_no: return False
4550 return True
4551
4552 def __ne__(self, other):
4553 return not self.__eq__(other)
4554
4555 def __str__(self):
4556 return self.show()
4557
4558 def show(self):
4559 import loxi.pp
4560 return loxi.pp.pp(self)
4561
4562 def pretty_print(self, q):
4563 q.text("port_stats_request {")
4564 with q.group():
4565 with q.indent(2):
4566 q.breakable()
4567 q.text("xid = ");
4568 if self.xid != None:
4569 q.text("%#x" % self.xid)
4570 else:
4571 q.text('None')
4572 q.text(","); q.breakable()
4573 q.text("flags = ");
4574 q.text("%#x" % self.flags)
4575 q.text(","); q.breakable()
4576 q.text("port_no = ");
4577 q.text(util.pretty_port(self.port_no))
4578 q.breakable()
4579 q.text('}')
4580
4581class port_status(Message):
4582 version = const.OFP_VERSION
4583 type = const.OFPT_PORT_STATUS
4584
4585 def __init__(self, xid=None, reason=None, desc=None):
4586 self.xid = xid
4587 if reason != None:
4588 self.reason = reason
4589 else:
4590 self.reason = 0
4591 if desc != None:
4592 self.desc = desc
4593 else:
4594 self.desc = common.port_desc()
4595
4596 def pack(self):
4597 packed = []
4598 packed.append(struct.pack("!B", self.version))
4599 packed.append(struct.pack("!B", self.type))
4600 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4601 packed.append(struct.pack("!L", self.xid))
4602 packed.append(struct.pack("!B", self.reason))
4603 packed.append('\x00' * 7)
4604 packed.append(self.desc.pack())
4605 length = sum([len(x) for x in packed])
4606 packed[2] = struct.pack("!H", length)
4607 return ''.join(packed)
4608
4609 @staticmethod
4610 def unpack(buf):
4611 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4612 obj = port_status()
4613 if type(buf) == loxi.generic_util.OFReader:
4614 reader = buf
4615 else:
4616 reader = loxi.generic_util.OFReader(buf)
4617 _version = reader.read('!B')[0]
4618 assert(_version == const.OFP_VERSION)
4619 _type = reader.read('!B')[0]
4620 assert(_type == const.OFPT_PORT_STATUS)
4621 _length = reader.read('!H')[0]
4622 obj.xid = reader.read('!L')[0]
4623 obj.reason = reader.read('!B')[0]
4624 reader.skip(7)
4625 obj.desc = common.port_desc.unpack(reader)
4626 return obj
4627
4628 def __eq__(self, other):
4629 if type(self) != type(other): return False
4630 if self.version != other.version: return False
4631 if self.type != other.type: return False
4632 if self.xid != other.xid: return False
4633 if self.reason != other.reason: return False
4634 if self.desc != other.desc: return False
4635 return True
4636
4637 def __ne__(self, other):
4638 return not self.__eq__(other)
4639
4640 def __str__(self):
4641 return self.show()
4642
4643 def show(self):
4644 import loxi.pp
4645 return loxi.pp.pp(self)
4646
4647 def pretty_print(self, q):
4648 q.text("port_status {")
4649 with q.group():
4650 with q.indent(2):
4651 q.breakable()
4652 q.text("xid = ");
4653 if self.xid != None:
4654 q.text("%#x" % self.xid)
4655 else:
4656 q.text('None')
4657 q.text(","); q.breakable()
4658 q.text("reason = ");
4659 q.text("%#x" % self.reason)
4660 q.text(","); q.breakable()
4661 q.text("desc = ");
4662 q.pp(self.desc)
4663 q.breakable()
4664 q.text('}')
4665
4666class queue_get_config_reply(Message):
4667 version = const.OFP_VERSION
4668 type = const.OFPT_QUEUE_GET_CONFIG_REPLY
4669
4670 def __init__(self, xid=None, port=None, queues=None):
4671 self.xid = xid
4672 if port != None:
4673 self.port = port
4674 else:
4675 self.port = 0
4676 if queues != None:
4677 self.queues = queues
4678 else:
4679 self.queues = []
4680
4681 def pack(self):
4682 packed = []
4683 packed.append(struct.pack("!B", self.version))
4684 packed.append(struct.pack("!B", self.type))
4685 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4686 packed.append(struct.pack("!L", self.xid))
4687 packed.append(struct.pack("!L", self.port))
4688 packed.append('\x00' * 4)
4689 packed.append("".join([x.pack() for x in self.queues]))
4690 length = sum([len(x) for x in packed])
4691 packed[2] = struct.pack("!H", length)
4692 return ''.join(packed)
4693
4694 @staticmethod
4695 def unpack(buf):
4696 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4697 obj = queue_get_config_reply()
4698 if type(buf) == loxi.generic_util.OFReader:
4699 reader = buf
4700 else:
4701 reader = loxi.generic_util.OFReader(buf)
4702 _version = reader.read('!B')[0]
4703 assert(_version == const.OFP_VERSION)
4704 _type = reader.read('!B')[0]
4705 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REPLY)
4706 _length = reader.read('!H')[0]
4707 obj.xid = reader.read('!L')[0]
4708 obj.port = reader.read('!L')[0]
4709 reader.skip(4)
4710 obj.queues = common.unpack_list_packet_queue(reader)
4711 return obj
4712
4713 def __eq__(self, other):
4714 if type(self) != type(other): return False
4715 if self.version != other.version: return False
4716 if self.type != other.type: return False
4717 if self.xid != other.xid: return False
4718 if self.port != other.port: return False
4719 if self.queues != other.queues: return False
4720 return True
4721
4722 def __ne__(self, other):
4723 return not self.__eq__(other)
4724
4725 def __str__(self):
4726 return self.show()
4727
4728 def show(self):
4729 import loxi.pp
4730 return loxi.pp.pp(self)
4731
4732 def pretty_print(self, q):
4733 q.text("queue_get_config_reply {")
4734 with q.group():
4735 with q.indent(2):
4736 q.breakable()
4737 q.text("xid = ");
4738 if self.xid != None:
4739 q.text("%#x" % self.xid)
4740 else:
4741 q.text('None')
4742 q.text(","); q.breakable()
4743 q.text("port = ");
4744 q.text(util.pretty_port(self.port))
4745 q.text(","); q.breakable()
4746 q.text("queues = ");
4747 q.pp(self.queues)
4748 q.breakable()
4749 q.text('}')
4750
4751class queue_get_config_request(Message):
4752 version = const.OFP_VERSION
4753 type = const.OFPT_QUEUE_GET_CONFIG_REQUEST
4754
4755 def __init__(self, xid=None, port=None):
4756 self.xid = xid
4757 if port != None:
4758 self.port = port
4759 else:
4760 self.port = 0
4761
4762 def pack(self):
4763 packed = []
4764 packed.append(struct.pack("!B", self.version))
4765 packed.append(struct.pack("!B", self.type))
4766 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4767 packed.append(struct.pack("!L", self.xid))
4768 packed.append(struct.pack("!L", self.port))
4769 packed.append('\x00' * 4)
4770 length = sum([len(x) for x in packed])
4771 packed[2] = struct.pack("!H", length)
4772 return ''.join(packed)
4773
4774 @staticmethod
4775 def unpack(buf):
4776 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4777 obj = queue_get_config_request()
4778 if type(buf) == loxi.generic_util.OFReader:
4779 reader = buf
4780 else:
4781 reader = loxi.generic_util.OFReader(buf)
4782 _version = reader.read('!B')[0]
4783 assert(_version == const.OFP_VERSION)
4784 _type = reader.read('!B')[0]
4785 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REQUEST)
4786 _length = reader.read('!H')[0]
4787 obj.xid = reader.read('!L')[0]
4788 obj.port = reader.read('!L')[0]
4789 reader.skip(4)
4790 return obj
4791
4792 def __eq__(self, other):
4793 if type(self) != type(other): return False
4794 if self.version != other.version: return False
4795 if self.type != other.type: return False
4796 if self.xid != other.xid: return False
4797 if self.port != other.port: return False
4798 return True
4799
4800 def __ne__(self, other):
4801 return not self.__eq__(other)
4802
4803 def __str__(self):
4804 return self.show()
4805
4806 def show(self):
4807 import loxi.pp
4808 return loxi.pp.pp(self)
4809
4810 def pretty_print(self, q):
4811 q.text("queue_get_config_request {")
4812 with q.group():
4813 with q.indent(2):
4814 q.breakable()
4815 q.text("xid = ");
4816 if self.xid != None:
4817 q.text("%#x" % self.xid)
4818 else:
4819 q.text('None')
4820 q.text(","); q.breakable()
4821 q.text("port = ");
4822 q.text(util.pretty_port(self.port))
4823 q.breakable()
4824 q.text('}')
4825
4826class queue_stats_reply(Message):
4827 version = const.OFP_VERSION
4828 type = const.OFPT_STATS_REPLY
4829 stats_type = const.OFPST_QUEUE
4830
4831 def __init__(self, xid=None, flags=None, entries=None):
4832 self.xid = xid
4833 if flags != None:
4834 self.flags = flags
4835 else:
4836 self.flags = 0
4837 if entries != None:
4838 self.entries = entries
4839 else:
4840 self.entries = []
4841
4842 def pack(self):
4843 packed = []
4844 packed.append(struct.pack("!B", self.version))
4845 packed.append(struct.pack("!B", self.type))
4846 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4847 packed.append(struct.pack("!L", self.xid))
4848 packed.append(struct.pack("!H", self.stats_type))
4849 packed.append(struct.pack("!H", self.flags))
4850 packed.append('\x00' * 4)
4851 packed.append("".join([x.pack() for x in self.entries]))
4852 length = sum([len(x) for x in packed])
4853 packed[2] = struct.pack("!H", length)
4854 return ''.join(packed)
4855
4856 @staticmethod
4857 def unpack(buf):
4858 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4859 obj = queue_stats_reply()
4860 if type(buf) == loxi.generic_util.OFReader:
4861 reader = buf
4862 else:
4863 reader = loxi.generic_util.OFReader(buf)
4864 _version = reader.read('!B')[0]
4865 assert(_version == const.OFP_VERSION)
4866 _type = reader.read('!B')[0]
4867 assert(_type == const.OFPT_STATS_REPLY)
4868 _length = reader.read('!H')[0]
4869 obj.xid = reader.read('!L')[0]
4870 _stats_type = reader.read('!H')[0]
4871 assert(_stats_type == const.OFPST_QUEUE)
4872 obj.flags = reader.read('!H')[0]
4873 reader.skip(4)
4874 obj.entries = loxi.generic_util.unpack_list(reader, common.queue_stats_entry.unpack)
4875 return obj
4876
4877 def __eq__(self, other):
4878 if type(self) != type(other): return False
4879 if self.version != other.version: return False
4880 if self.type != other.type: return False
4881 if self.xid != other.xid: return False
4882 if self.flags != other.flags: return False
4883 if self.entries != other.entries: return False
4884 return True
4885
4886 def __ne__(self, other):
4887 return not self.__eq__(other)
4888
4889 def __str__(self):
4890 return self.show()
4891
4892 def show(self):
4893 import loxi.pp
4894 return loxi.pp.pp(self)
4895
4896 def pretty_print(self, q):
4897 q.text("queue_stats_reply {")
4898 with q.group():
4899 with q.indent(2):
4900 q.breakable()
4901 q.text("xid = ");
4902 if self.xid != None:
4903 q.text("%#x" % self.xid)
4904 else:
4905 q.text('None')
4906 q.text(","); q.breakable()
4907 q.text("flags = ");
4908 q.text("%#x" % self.flags)
4909 q.text(","); q.breakable()
4910 q.text("entries = ");
4911 q.pp(self.entries)
4912 q.breakable()
4913 q.text('}')
4914
4915class queue_stats_request(Message):
4916 version = const.OFP_VERSION
4917 type = const.OFPT_STATS_REQUEST
4918 stats_type = const.OFPST_QUEUE
4919
4920 def __init__(self, xid=None, flags=None, port_no=None, queue_id=None):
4921 self.xid = xid
4922 if flags != None:
4923 self.flags = flags
4924 else:
4925 self.flags = 0
4926 if port_no != None:
4927 self.port_no = port_no
4928 else:
4929 self.port_no = 0
4930 if queue_id != None:
4931 self.queue_id = queue_id
4932 else:
4933 self.queue_id = 0
4934
4935 def pack(self):
4936 packed = []
4937 packed.append(struct.pack("!B", self.version))
4938 packed.append(struct.pack("!B", self.type))
4939 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4940 packed.append(struct.pack("!L", self.xid))
4941 packed.append(struct.pack("!H", self.stats_type))
4942 packed.append(struct.pack("!H", self.flags))
4943 packed.append('\x00' * 4)
4944 packed.append(struct.pack("!L", self.port_no))
4945 packed.append(struct.pack("!L", self.queue_id))
4946 length = sum([len(x) for x in packed])
4947 packed[2] = struct.pack("!H", length)
4948 return ''.join(packed)
4949
4950 @staticmethod
4951 def unpack(buf):
4952 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4953 obj = queue_stats_request()
4954 if type(buf) == loxi.generic_util.OFReader:
4955 reader = buf
4956 else:
4957 reader = loxi.generic_util.OFReader(buf)
4958 _version = reader.read('!B')[0]
4959 assert(_version == const.OFP_VERSION)
4960 _type = reader.read('!B')[0]
4961 assert(_type == const.OFPT_STATS_REQUEST)
4962 _length = reader.read('!H')[0]
4963 obj.xid = reader.read('!L')[0]
4964 _stats_type = reader.read('!H')[0]
4965 assert(_stats_type == const.OFPST_QUEUE)
4966 obj.flags = reader.read('!H')[0]
4967 reader.skip(4)
4968 obj.port_no = reader.read('!L')[0]
4969 obj.queue_id = reader.read('!L')[0]
4970 return obj
4971
4972 def __eq__(self, other):
4973 if type(self) != type(other): return False
4974 if self.version != other.version: return False
4975 if self.type != other.type: return False
4976 if self.xid != other.xid: return False
4977 if self.flags != other.flags: return False
4978 if self.port_no != other.port_no: return False
4979 if self.queue_id != other.queue_id: return False
4980 return True
4981
4982 def __ne__(self, other):
4983 return not self.__eq__(other)
4984
4985 def __str__(self):
4986 return self.show()
4987
4988 def show(self):
4989 import loxi.pp
4990 return loxi.pp.pp(self)
4991
4992 def pretty_print(self, q):
4993 q.text("queue_stats_request {")
4994 with q.group():
4995 with q.indent(2):
4996 q.breakable()
4997 q.text("xid = ");
4998 if self.xid != None:
4999 q.text("%#x" % self.xid)
5000 else:
5001 q.text('None')
5002 q.text(","); q.breakable()
5003 q.text("flags = ");
5004 q.text("%#x" % self.flags)
5005 q.text(","); q.breakable()
5006 q.text("port_no = ");
5007 q.text(util.pretty_port(self.port_no))
5008 q.text(","); q.breakable()
5009 q.text("queue_id = ");
5010 q.text("%#x" % self.queue_id)
5011 q.breakable()
5012 q.text('}')
5013
5014class role_reply(Message):
5015 version = const.OFP_VERSION
5016 type = const.OFPT_ROLE_REPLY
5017
5018 def __init__(self, xid=None, data=None):
5019 self.xid = xid
5020 if data != None:
5021 self.data = data
5022 else:
5023 self.data = ""
5024
5025 def pack(self):
5026 packed = []
5027 packed.append(struct.pack("!B", self.version))
5028 packed.append(struct.pack("!B", self.type))
5029 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5030 packed.append(struct.pack("!L", self.xid))
5031 packed.append(self.data)
5032 length = sum([len(x) for x in packed])
5033 packed[2] = struct.pack("!H", length)
5034 return ''.join(packed)
5035
5036 @staticmethod
5037 def unpack(buf):
5038 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5039 obj = role_reply()
5040 if type(buf) == loxi.generic_util.OFReader:
5041 reader = buf
5042 else:
5043 reader = loxi.generic_util.OFReader(buf)
5044 _version = reader.read('!B')[0]
5045 assert(_version == const.OFP_VERSION)
5046 _type = reader.read('!B')[0]
5047 assert(_type == const.OFPT_ROLE_REPLY)
5048 _length = reader.read('!H')[0]
5049 obj.xid = reader.read('!L')[0]
5050 obj.data = str(reader.read_all())
5051 return obj
5052
5053 def __eq__(self, other):
5054 if type(self) != type(other): return False
5055 if self.version != other.version: return False
5056 if self.type != other.type: return False
5057 if self.xid != other.xid: return False
5058 if self.data != other.data: return False
5059 return True
5060
5061 def __ne__(self, other):
5062 return not self.__eq__(other)
5063
5064 def __str__(self):
5065 return self.show()
5066
5067 def show(self):
5068 import loxi.pp
5069 return loxi.pp.pp(self)
5070
5071 def pretty_print(self, q):
5072 q.text("role_reply {")
5073 with q.group():
5074 with q.indent(2):
5075 q.breakable()
5076 q.text("xid = ");
5077 if self.xid != None:
5078 q.text("%#x" % self.xid)
5079 else:
5080 q.text('None')
5081 q.text(","); q.breakable()
5082 q.text("data = ");
5083 q.pp(self.data)
5084 q.breakable()
5085 q.text('}')
5086
5087class role_request(Message):
5088 version = const.OFP_VERSION
5089 type = const.OFPT_ROLE_REQUEST
5090
5091 def __init__(self, xid=None, role=None, generation_id=None):
5092 self.xid = xid
5093 if role != None:
5094 self.role = role
5095 else:
5096 self.role = 0
5097 if generation_id != None:
5098 self.generation_id = generation_id
5099 else:
5100 self.generation_id = 0
5101
5102 def pack(self):
5103 packed = []
5104 packed.append(struct.pack("!B", self.version))
5105 packed.append(struct.pack("!B", self.type))
5106 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5107 packed.append(struct.pack("!L", self.xid))
5108 packed.append(struct.pack("!L", self.role))
5109 packed.append('\x00' * 4)
5110 packed.append(struct.pack("!Q", self.generation_id))
5111 length = sum([len(x) for x in packed])
5112 packed[2] = struct.pack("!H", length)
5113 return ''.join(packed)
5114
5115 @staticmethod
5116 def unpack(buf):
5117 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5118 obj = role_request()
5119 if type(buf) == loxi.generic_util.OFReader:
5120 reader = buf
5121 else:
5122 reader = loxi.generic_util.OFReader(buf)
5123 _version = reader.read('!B')[0]
5124 assert(_version == const.OFP_VERSION)
5125 _type = reader.read('!B')[0]
5126 assert(_type == const.OFPT_ROLE_REQUEST)
5127 _length = reader.read('!H')[0]
5128 obj.xid = reader.read('!L')[0]
5129 obj.role = reader.read('!L')[0]
5130 reader.skip(4)
5131 obj.generation_id = reader.read('!Q')[0]
5132 return obj
5133
5134 def __eq__(self, other):
5135 if type(self) != type(other): return False
5136 if self.version != other.version: return False
5137 if self.type != other.type: return False
5138 if self.xid != other.xid: return False
5139 if self.role != other.role: return False
5140 if self.generation_id != other.generation_id: return False
5141 return True
5142
5143 def __ne__(self, other):
5144 return not self.__eq__(other)
5145
5146 def __str__(self):
5147 return self.show()
5148
5149 def show(self):
5150 import loxi.pp
5151 return loxi.pp.pp(self)
5152
5153 def pretty_print(self, q):
5154 q.text("role_request {")
5155 with q.group():
5156 with q.indent(2):
5157 q.breakable()
5158 q.text("xid = ");
5159 if self.xid != None:
5160 q.text("%#x" % self.xid)
5161 else:
5162 q.text('None')
5163 q.text(","); q.breakable()
5164 q.text("role = ");
5165 q.text("%#x" % self.role)
5166 q.text(","); q.breakable()
5167 q.text("generation_id = ");
5168 q.text("%#x" % self.generation_id)
5169 q.breakable()
5170 q.text('}')
5171
5172class set_config(Message):
5173 version = const.OFP_VERSION
5174 type = const.OFPT_SET_CONFIG
5175
5176 def __init__(self, xid=None, flags=None, miss_send_len=None):
5177 self.xid = xid
5178 if flags != None:
5179 self.flags = flags
5180 else:
5181 self.flags = 0
5182 if miss_send_len != None:
5183 self.miss_send_len = miss_send_len
5184 else:
5185 self.miss_send_len = 0
5186
5187 def pack(self):
5188 packed = []
5189 packed.append(struct.pack("!B", self.version))
5190 packed.append(struct.pack("!B", self.type))
5191 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5192 packed.append(struct.pack("!L", self.xid))
5193 packed.append(struct.pack("!H", self.flags))
5194 packed.append(struct.pack("!H", self.miss_send_len))
5195 length = sum([len(x) for x in packed])
5196 packed[2] = struct.pack("!H", length)
5197 return ''.join(packed)
5198
5199 @staticmethod
5200 def unpack(buf):
5201 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5202 obj = set_config()
5203 if type(buf) == loxi.generic_util.OFReader:
5204 reader = buf
5205 else:
5206 reader = loxi.generic_util.OFReader(buf)
5207 _version = reader.read('!B')[0]
5208 assert(_version == const.OFP_VERSION)
5209 _type = reader.read('!B')[0]
5210 assert(_type == const.OFPT_SET_CONFIG)
5211 _length = reader.read('!H')[0]
5212 obj.xid = reader.read('!L')[0]
5213 obj.flags = reader.read('!H')[0]
5214 obj.miss_send_len = reader.read('!H')[0]
5215 return obj
5216
5217 def __eq__(self, other):
5218 if type(self) != type(other): return False
5219 if self.version != other.version: return False
5220 if self.type != other.type: return False
5221 if self.xid != other.xid: return False
5222 if self.flags != other.flags: return False
5223 if self.miss_send_len != other.miss_send_len: return False
5224 return True
5225
5226 def __ne__(self, other):
5227 return not self.__eq__(other)
5228
5229 def __str__(self):
5230 return self.show()
5231
5232 def show(self):
5233 import loxi.pp
5234 return loxi.pp.pp(self)
5235
5236 def pretty_print(self, q):
5237 q.text("set_config {")
5238 with q.group():
5239 with q.indent(2):
5240 q.breakable()
5241 q.text("xid = ");
5242 if self.xid != None:
5243 q.text("%#x" % self.xid)
5244 else:
5245 q.text('None')
5246 q.text(","); q.breakable()
5247 q.text("flags = ");
5248 q.text("%#x" % self.flags)
5249 q.text(","); q.breakable()
5250 q.text("miss_send_len = ");
5251 q.text("%#x" % self.miss_send_len)
5252 q.breakable()
5253 q.text('}')
5254
5255class table_mod(Message):
5256 version = const.OFP_VERSION
5257 type = const.OFPT_TABLE_MOD
5258
5259 def __init__(self, xid=None, table_id=None, config=None):
5260 self.xid = xid
5261 if table_id != None:
5262 self.table_id = table_id
5263 else:
5264 self.table_id = 0
5265 if config != None:
5266 self.config = config
5267 else:
5268 self.config = 0
5269
5270 def pack(self):
5271 packed = []
5272 packed.append(struct.pack("!B", self.version))
5273 packed.append(struct.pack("!B", self.type))
5274 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5275 packed.append(struct.pack("!L", self.xid))
5276 packed.append(struct.pack("!B", self.table_id))
5277 packed.append('\x00' * 3)
5278 packed.append(struct.pack("!L", self.config))
5279 length = sum([len(x) for x in packed])
5280 packed[2] = struct.pack("!H", length)
5281 return ''.join(packed)
5282
5283 @staticmethod
5284 def unpack(buf):
5285 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5286 obj = table_mod()
5287 if type(buf) == loxi.generic_util.OFReader:
5288 reader = buf
5289 else:
5290 reader = loxi.generic_util.OFReader(buf)
5291 _version = reader.read('!B')[0]
5292 assert(_version == const.OFP_VERSION)
5293 _type = reader.read('!B')[0]
5294 assert(_type == const.OFPT_TABLE_MOD)
5295 _length = reader.read('!H')[0]
5296 obj.xid = reader.read('!L')[0]
5297 obj.table_id = reader.read('!B')[0]
5298 reader.skip(3)
5299 obj.config = reader.read('!L')[0]
5300 return obj
5301
5302 def __eq__(self, other):
5303 if type(self) != type(other): return False
5304 if self.version != other.version: return False
5305 if self.type != other.type: return False
5306 if self.xid != other.xid: return False
5307 if self.table_id != other.table_id: return False
5308 if self.config != other.config: return False
5309 return True
5310
5311 def __ne__(self, other):
5312 return not self.__eq__(other)
5313
5314 def __str__(self):
5315 return self.show()
5316
5317 def show(self):
5318 import loxi.pp
5319 return loxi.pp.pp(self)
5320
5321 def pretty_print(self, q):
5322 q.text("table_mod {")
5323 with q.group():
5324 with q.indent(2):
5325 q.breakable()
5326 q.text("xid = ");
5327 if self.xid != None:
5328 q.text("%#x" % self.xid)
5329 else:
5330 q.text('None')
5331 q.text(","); q.breakable()
5332 q.text("table_id = ");
5333 q.text("%#x" % self.table_id)
5334 q.text(","); q.breakable()
5335 q.text("config = ");
5336 q.text("%#x" % self.config)
5337 q.breakable()
5338 q.text('}')
5339
5340class table_stats_reply(Message):
5341 version = const.OFP_VERSION
5342 type = const.OFPT_STATS_REPLY
5343 stats_type = const.OFPST_TABLE
5344
5345 def __init__(self, xid=None, flags=None, entries=None):
5346 self.xid = xid
5347 if flags != None:
5348 self.flags = flags
5349 else:
5350 self.flags = 0
5351 if entries != None:
5352 self.entries = entries
5353 else:
5354 self.entries = []
5355
5356 def pack(self):
5357 packed = []
5358 packed.append(struct.pack("!B", self.version))
5359 packed.append(struct.pack("!B", self.type))
5360 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5361 packed.append(struct.pack("!L", self.xid))
5362 packed.append(struct.pack("!H", self.stats_type))
5363 packed.append(struct.pack("!H", self.flags))
5364 packed.append('\x00' * 4)
5365 packed.append("".join([x.pack() for x in self.entries]))
5366 length = sum([len(x) for x in packed])
5367 packed[2] = struct.pack("!H", length)
5368 return ''.join(packed)
5369
5370 @staticmethod
5371 def unpack(buf):
5372 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5373 obj = table_stats_reply()
5374 if type(buf) == loxi.generic_util.OFReader:
5375 reader = buf
5376 else:
5377 reader = loxi.generic_util.OFReader(buf)
5378 _version = reader.read('!B')[0]
5379 assert(_version == const.OFP_VERSION)
5380 _type = reader.read('!B')[0]
5381 assert(_type == const.OFPT_STATS_REPLY)
5382 _length = reader.read('!H')[0]
5383 obj.xid = reader.read('!L')[0]
5384 _stats_type = reader.read('!H')[0]
5385 assert(_stats_type == const.OFPST_TABLE)
5386 obj.flags = reader.read('!H')[0]
5387 reader.skip(4)
5388 obj.entries = loxi.generic_util.unpack_list(reader, common.table_stats_entry.unpack)
5389 return obj
5390
5391 def __eq__(self, other):
5392 if type(self) != type(other): return False
5393 if self.version != other.version: return False
5394 if self.type != other.type: return False
5395 if self.xid != other.xid: return False
5396 if self.flags != other.flags: return False
5397 if self.entries != other.entries: return False
5398 return True
5399
5400 def __ne__(self, other):
5401 return not self.__eq__(other)
5402
5403 def __str__(self):
5404 return self.show()
5405
5406 def show(self):
5407 import loxi.pp
5408 return loxi.pp.pp(self)
5409
5410 def pretty_print(self, q):
5411 q.text("table_stats_reply {")
5412 with q.group():
5413 with q.indent(2):
5414 q.breakable()
5415 q.text("xid = ");
5416 if self.xid != None:
5417 q.text("%#x" % self.xid)
5418 else:
5419 q.text('None')
5420 q.text(","); q.breakable()
5421 q.text("flags = ");
5422 q.text("%#x" % self.flags)
5423 q.text(","); q.breakable()
5424 q.text("entries = ");
5425 q.pp(self.entries)
5426 q.breakable()
5427 q.text('}')
5428
5429class table_stats_request(Message):
5430 version = const.OFP_VERSION
5431 type = const.OFPT_STATS_REQUEST
5432 stats_type = const.OFPST_TABLE
5433
5434 def __init__(self, xid=None, flags=None):
5435 self.xid = xid
5436 if flags != None:
5437 self.flags = flags
5438 else:
5439 self.flags = 0
5440
5441 def pack(self):
5442 packed = []
5443 packed.append(struct.pack("!B", self.version))
5444 packed.append(struct.pack("!B", self.type))
5445 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5446 packed.append(struct.pack("!L", self.xid))
5447 packed.append(struct.pack("!H", self.stats_type))
5448 packed.append(struct.pack("!H", self.flags))
5449 packed.append('\x00' * 4)
5450 length = sum([len(x) for x in packed])
5451 packed[2] = struct.pack("!H", length)
5452 return ''.join(packed)
5453
5454 @staticmethod
5455 def unpack(buf):
5456 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5457 obj = table_stats_request()
5458 if type(buf) == loxi.generic_util.OFReader:
5459 reader = buf
5460 else:
5461 reader = loxi.generic_util.OFReader(buf)
5462 _version = reader.read('!B')[0]
5463 assert(_version == const.OFP_VERSION)
5464 _type = reader.read('!B')[0]
5465 assert(_type == const.OFPT_STATS_REQUEST)
5466 _length = reader.read('!H')[0]
5467 obj.xid = reader.read('!L')[0]
5468 _stats_type = reader.read('!H')[0]
5469 assert(_stats_type == const.OFPST_TABLE)
5470 obj.flags = reader.read('!H')[0]
5471 reader.skip(4)
5472 return obj
5473
5474 def __eq__(self, other):
5475 if type(self) != type(other): return False
5476 if self.version != other.version: return False
5477 if self.type != other.type: return False
5478 if self.xid != other.xid: return False
5479 if self.flags != other.flags: return False
5480 return True
5481
5482 def __ne__(self, other):
5483 return not self.__eq__(other)
5484
5485 def __str__(self):
5486 return self.show()
5487
5488 def show(self):
5489 import loxi.pp
5490 return loxi.pp.pp(self)
5491
5492 def pretty_print(self, q):
5493 q.text("table_stats_request {")
5494 with q.group():
5495 with q.indent(2):
5496 q.breakable()
5497 q.text("xid = ");
5498 if self.xid != None:
5499 q.text("%#x" % self.xid)
5500 else:
5501 q.text('None')
5502 q.text(","); q.breakable()
5503 q.text("flags = ");
5504 q.text("%#x" % self.flags)
5505 q.breakable()
5506 q.text('}')
5507
5508
5509def parse_header(buf):
5510 if len(buf) < 8:
5511 raise loxi.ProtocolError("too short to be an OpenFlow message")
5512 return struct.unpack_from("!BBHL", buf)
5513
5514def parse_message(buf):
5515 msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
5516 if msg_ver != const.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
5517 raise loxi.ProtocolError("wrong OpenFlow version")
5518 if len(buf) != msg_len:
5519 raise loxi.ProtocolError("incorrect message size")
5520 if msg_type in parsers:
5521 return parsers[msg_type](buf)
5522 else:
5523 raise loxi.ProtocolError("unexpected message type")
5524
5525def parse_flow_mod(buf):
5526 if len(buf) < 56 + 2:
5527 raise loxi.ProtocolError("message too short")
5528 cmd, = struct.unpack_from("!H", buf, 56)
5529 if cmd in flow_mod_parsers:
5530 return flow_mod_parsers[cmd](buf)
5531 else:
5532 raise loxi.ProtocolError("unexpected flow mod cmd %u" % cmd)
5533
5534def parse_stats_reply(buf):
5535 if len(buf) < 8 + 2:
5536 raise loxi.ProtocolError("message too short")
5537 stats_type, = struct.unpack_from("!H", buf, 8)
5538 if stats_type in stats_reply_parsers:
5539 return stats_reply_parsers[stats_type](buf)
5540 else:
5541 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5542
5543def parse_stats_request(buf):
5544 if len(buf) < 8 + 2:
5545 raise loxi.ProtocolError("message too short")
5546 stats_type, = struct.unpack_from("!H", buf, 8)
5547 if stats_type in stats_request_parsers:
5548 return stats_request_parsers[stats_type](buf)
5549 else:
5550 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5551
5552def parse_experimenter(buf):
5553 if len(buf) < 16:
5554 raise loxi.ProtocolError("experimenter message too short")
5555
5556 experimenter, = struct.unpack_from("!L", buf, 8)
5557 if experimenter == 0x005c16c7: # Big Switch Networks
5558 subtype, = struct.unpack_from("!L", buf, 12)
5559 elif experimenter == 0x00002320: # Nicira
5560 subtype, = struct.unpack_from("!L", buf, 12)
5561 else:
5562 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
5563
5564 if subtype in experimenter_parsers[experimenter]:
5565 return experimenter_parsers[experimenter][subtype](buf)
5566 else:
5567 raise loxi.ProtocolError("unexpected experimenter %#x subtype %#x" % (experimenter, subtype))
5568
5569parsers = {
5570 const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
5571 const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
5572 const.OFPT_ECHO_REPLY : echo_reply.unpack,
5573 const.OFPT_ECHO_REQUEST : echo_request.unpack,
5574 const.OFPT_ERROR : error_msg.unpack,
5575 const.OFPT_EXPERIMENTER : parse_experimenter,
5576 const.OFPT_FEATURES_REPLY : features_reply.unpack,
5577 const.OFPT_FEATURES_REQUEST : features_request.unpack,
5578 const.OFPT_FLOW_MOD : parse_flow_mod,
5579 const.OFPT_FLOW_REMOVED : flow_removed.unpack,
5580 const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
5581 const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
5582 const.OFPT_GROUP_MOD : group_mod.unpack,
5583 const.OFPT_HELLO : hello.unpack,
5584 const.OFPT_PACKET_IN : packet_in.unpack,
5585 const.OFPT_PACKET_OUT : packet_out.unpack,
5586 const.OFPT_PORT_MOD : port_mod.unpack,
5587 const.OFPT_PORT_STATUS : port_status.unpack,
5588 const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
5589 const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
5590 const.OFPT_ROLE_REPLY : role_reply.unpack,
5591 const.OFPT_ROLE_REQUEST : role_request.unpack,
5592 const.OFPT_SET_CONFIG : set_config.unpack,
5593 const.OFPT_STATS_REPLY : parse_stats_reply,
5594 const.OFPT_STATS_REQUEST : parse_stats_request,
5595 const.OFPT_TABLE_MOD : table_mod.unpack,
5596}
5597
5598flow_mod_parsers = {
5599 const.OFPFC_ADD : flow_add.unpack,
5600 const.OFPFC_MODIFY : flow_modify.unpack,
5601 const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
5602 const.OFPFC_DELETE : flow_delete.unpack,
5603 const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
5604}
5605
5606stats_reply_parsers = {
5607 const.OFPST_DESC : desc_stats_reply.unpack,
5608 const.OFPST_FLOW : flow_stats_reply.unpack,
5609 const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
5610 const.OFPST_TABLE : table_stats_reply.unpack,
5611 const.OFPST_PORT : port_stats_reply.unpack,
5612 const.OFPST_QUEUE : queue_stats_reply.unpack,
5613 const.OFPST_EXPERIMENTER : experimenter_stats_reply.unpack,
Rich Lane90c961c2013-05-14 09:26:50 -07005614 const.OFPST_GROUP : group_stats_reply.unpack,
5615 const.OFPST_GROUP_DESC : group_desc_stats_reply.unpack,
5616 const.OFPST_GROUP_FEATURES : group_features_stats_reply.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07005617}
5618
5619stats_request_parsers = {
5620 const.OFPST_DESC : desc_stats_request.unpack,
5621 const.OFPST_FLOW : flow_stats_request.unpack,
5622 const.OFPST_AGGREGATE : aggregate_stats_request.unpack,
5623 const.OFPST_TABLE : table_stats_request.unpack,
5624 const.OFPST_PORT : port_stats_request.unpack,
5625 const.OFPST_QUEUE : queue_stats_request.unpack,
5626 const.OFPST_EXPERIMENTER : experimenter_stats_request.unpack,
Rich Lane90c961c2013-05-14 09:26:50 -07005627 const.OFPST_GROUP : group_stats_request.unpack,
5628 const.OFPST_GROUP_DESC : group_desc_stats_request.unpack,
5629 const.OFPST_GROUP_FEATURES : group_features_stats_request.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07005630}
5631
5632experimenter_parsers = {
5633}