blob: 6de2b6cfbcb19e4809bb0d43823714093d3b8734 [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, 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 data != None:
1389 self.data = data
1390 else:
1391 self.data = ""
1392
1393 def pack(self):
1394 packed = []
1395 packed.append(struct.pack("!B", self.version))
1396 packed.append(struct.pack("!B", self.type))
1397 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1398 packed.append(struct.pack("!L", self.xid))
1399 packed.append(struct.pack("!H", self.stats_type))
1400 packed.append(struct.pack("!H", self.flags))
1401 packed.append('\x00' * 4)
1402 packed.append(struct.pack("!L", self.experimenter))
1403 packed.append('\x00' * 4)
1404 packed.append(self.data)
1405 length = sum([len(x) for x in packed])
1406 packed[2] = struct.pack("!H", length)
1407 return ''.join(packed)
1408
1409 @staticmethod
1410 def unpack(buf):
1411 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1412 obj = experimenter_stats_reply()
1413 if type(buf) == loxi.generic_util.OFReader:
1414 reader = buf
1415 else:
1416 reader = loxi.generic_util.OFReader(buf)
1417 _version = reader.read('!B')[0]
1418 assert(_version == const.OFP_VERSION)
1419 _type = reader.read('!B')[0]
1420 assert(_type == const.OFPT_STATS_REPLY)
1421 _length = reader.read('!H')[0]
1422 obj.xid = reader.read('!L')[0]
1423 _stats_type = reader.read('!H')[0]
1424 assert(_stats_type == const.OFPST_EXPERIMENTER)
1425 obj.flags = reader.read('!H')[0]
1426 reader.skip(4)
1427 obj.experimenter = reader.read('!L')[0]
1428 reader.skip(4)
1429 obj.data = str(reader.read_all())
1430 return obj
1431
1432 def __eq__(self, other):
1433 if type(self) != type(other): return False
1434 if self.version != other.version: return False
1435 if self.type != other.type: return False
1436 if self.xid != other.xid: return False
1437 if self.flags != other.flags: return False
1438 if self.experimenter != other.experimenter: return False
1439 if self.data != other.data: return False
1440 return True
1441
1442 def __ne__(self, other):
1443 return not self.__eq__(other)
1444
1445 def __str__(self):
1446 return self.show()
1447
1448 def show(self):
1449 import loxi.pp
1450 return loxi.pp.pp(self)
1451
1452 def pretty_print(self, q):
1453 q.text("experimenter_stats_reply {")
1454 with q.group():
1455 with q.indent(2):
1456 q.breakable()
1457 q.text("xid = ");
1458 if self.xid != None:
1459 q.text("%#x" % self.xid)
1460 else:
1461 q.text('None')
1462 q.text(","); q.breakable()
1463 q.text("flags = ");
1464 q.text("%#x" % self.flags)
1465 q.text(","); q.breakable()
1466 q.text("experimenter = ");
1467 q.text("%#x" % self.experimenter)
1468 q.text(","); q.breakable()
1469 q.text("data = ");
1470 q.pp(self.data)
1471 q.breakable()
1472 q.text('}')
1473
1474class experimenter_stats_request(Message):
1475 version = const.OFP_VERSION
1476 type = const.OFPT_STATS_REQUEST
1477 stats_type = const.OFPST_EXPERIMENTER
1478
1479 def __init__(self, xid=None, flags=None, experimenter=None, data=None):
1480 self.xid = xid
1481 if flags != None:
1482 self.flags = flags
1483 else:
1484 self.flags = 0
1485 if experimenter != None:
1486 self.experimenter = experimenter
1487 else:
1488 self.experimenter = 0
1489 if data != None:
1490 self.data = data
1491 else:
1492 self.data = ""
1493
1494 def pack(self):
1495 packed = []
1496 packed.append(struct.pack("!B", self.version))
1497 packed.append(struct.pack("!B", self.type))
1498 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1499 packed.append(struct.pack("!L", self.xid))
1500 packed.append(struct.pack("!H", self.stats_type))
1501 packed.append(struct.pack("!H", self.flags))
1502 packed.append('\x00' * 4)
1503 packed.append(struct.pack("!L", self.experimenter))
1504 packed.append('\x00' * 4)
1505 packed.append(self.data)
1506 length = sum([len(x) for x in packed])
1507 packed[2] = struct.pack("!H", length)
1508 return ''.join(packed)
1509
1510 @staticmethod
1511 def unpack(buf):
1512 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1513 obj = experimenter_stats_request()
1514 if type(buf) == loxi.generic_util.OFReader:
1515 reader = buf
1516 else:
1517 reader = loxi.generic_util.OFReader(buf)
1518 _version = reader.read('!B')[0]
1519 assert(_version == const.OFP_VERSION)
1520 _type = reader.read('!B')[0]
1521 assert(_type == const.OFPT_STATS_REQUEST)
1522 _length = reader.read('!H')[0]
1523 obj.xid = reader.read('!L')[0]
1524 _stats_type = reader.read('!H')[0]
1525 assert(_stats_type == const.OFPST_EXPERIMENTER)
1526 obj.flags = reader.read('!H')[0]
1527 reader.skip(4)
1528 obj.experimenter = reader.read('!L')[0]
1529 reader.skip(4)
1530 obj.data = str(reader.read_all())
1531 return obj
1532
1533 def __eq__(self, other):
1534 if type(self) != type(other): return False
1535 if self.version != other.version: return False
1536 if self.type != other.type: return False
1537 if self.xid != other.xid: return False
1538 if self.flags != other.flags: return False
1539 if self.experimenter != other.experimenter: return False
1540 if self.data != other.data: return False
1541 return True
1542
1543 def __ne__(self, other):
1544 return not self.__eq__(other)
1545
1546 def __str__(self):
1547 return self.show()
1548
1549 def show(self):
1550 import loxi.pp
1551 return loxi.pp.pp(self)
1552
1553 def pretty_print(self, q):
1554 q.text("experimenter_stats_request {")
1555 with q.group():
1556 with q.indent(2):
1557 q.breakable()
1558 q.text("xid = ");
1559 if self.xid != None:
1560 q.text("%#x" % self.xid)
1561 else:
1562 q.text('None')
1563 q.text(","); q.breakable()
1564 q.text("flags = ");
1565 q.text("%#x" % self.flags)
1566 q.text(","); q.breakable()
1567 q.text("experimenter = ");
1568 q.text("%#x" % self.experimenter)
1569 q.text(","); q.breakable()
1570 q.text("data = ");
1571 q.pp(self.data)
1572 q.breakable()
1573 q.text('}')
1574
1575class features_reply(Message):
1576 version = const.OFP_VERSION
1577 type = const.OFPT_FEATURES_REPLY
1578
1579 def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, reserved=None, ports=None):
1580 self.xid = xid
1581 if datapath_id != None:
1582 self.datapath_id = datapath_id
1583 else:
1584 self.datapath_id = 0
1585 if n_buffers != None:
1586 self.n_buffers = n_buffers
1587 else:
1588 self.n_buffers = 0
1589 if n_tables != None:
1590 self.n_tables = n_tables
1591 else:
1592 self.n_tables = 0
1593 if capabilities != None:
1594 self.capabilities = capabilities
1595 else:
1596 self.capabilities = 0
1597 if reserved != None:
1598 self.reserved = reserved
1599 else:
1600 self.reserved = 0
1601 if ports != None:
1602 self.ports = ports
1603 else:
1604 self.ports = []
1605
1606 def pack(self):
1607 packed = []
1608 packed.append(struct.pack("!B", self.version))
1609 packed.append(struct.pack("!B", self.type))
1610 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1611 packed.append(struct.pack("!L", self.xid))
1612 packed.append(struct.pack("!Q", self.datapath_id))
1613 packed.append(struct.pack("!L", self.n_buffers))
1614 packed.append(struct.pack("!B", self.n_tables))
1615 packed.append('\x00' * 3)
1616 packed.append(struct.pack("!L", self.capabilities))
1617 packed.append(struct.pack("!L", self.reserved))
1618 packed.append("".join([x.pack() for x in self.ports]))
1619 length = sum([len(x) for x in packed])
1620 packed[2] = struct.pack("!H", length)
1621 return ''.join(packed)
1622
1623 @staticmethod
1624 def unpack(buf):
1625 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1626 obj = features_reply()
1627 if type(buf) == loxi.generic_util.OFReader:
1628 reader = buf
1629 else:
1630 reader = loxi.generic_util.OFReader(buf)
1631 _version = reader.read('!B')[0]
1632 assert(_version == const.OFP_VERSION)
1633 _type = reader.read('!B')[0]
1634 assert(_type == const.OFPT_FEATURES_REPLY)
1635 _length = reader.read('!H')[0]
1636 obj.xid = reader.read('!L')[0]
1637 obj.datapath_id = reader.read('!Q')[0]
1638 obj.n_buffers = reader.read('!L')[0]
1639 obj.n_tables = reader.read('!B')[0]
1640 reader.skip(3)
1641 obj.capabilities = reader.read('!L')[0]
1642 obj.reserved = reader.read('!L')[0]
1643 obj.ports = loxi.generic_util.unpack_list(reader, common.port_desc.unpack)
1644 return obj
1645
1646 def __eq__(self, other):
1647 if type(self) != type(other): return False
1648 if self.version != other.version: return False
1649 if self.type != other.type: return False
1650 if self.xid != other.xid: return False
1651 if self.datapath_id != other.datapath_id: return False
1652 if self.n_buffers != other.n_buffers: return False
1653 if self.n_tables != other.n_tables: return False
1654 if self.capabilities != other.capabilities: return False
1655 if self.reserved != other.reserved: return False
1656 if self.ports != other.ports: return False
1657 return True
1658
1659 def __ne__(self, other):
1660 return not self.__eq__(other)
1661
1662 def __str__(self):
1663 return self.show()
1664
1665 def show(self):
1666 import loxi.pp
1667 return loxi.pp.pp(self)
1668
1669 def pretty_print(self, q):
1670 q.text("features_reply {")
1671 with q.group():
1672 with q.indent(2):
1673 q.breakable()
1674 q.text("xid = ");
1675 if self.xid != None:
1676 q.text("%#x" % self.xid)
1677 else:
1678 q.text('None')
1679 q.text(","); q.breakable()
1680 q.text("datapath_id = ");
1681 q.text("%#x" % self.datapath_id)
1682 q.text(","); q.breakable()
1683 q.text("n_buffers = ");
1684 q.text("%#x" % self.n_buffers)
1685 q.text(","); q.breakable()
1686 q.text("n_tables = ");
1687 q.text("%#x" % self.n_tables)
1688 q.text(","); q.breakable()
1689 q.text("capabilities = ");
1690 q.text("%#x" % self.capabilities)
1691 q.text(","); q.breakable()
1692 q.text("reserved = ");
1693 q.text("%#x" % self.reserved)
1694 q.text(","); q.breakable()
1695 q.text("ports = ");
1696 q.pp(self.ports)
1697 q.breakable()
1698 q.text('}')
1699
1700class features_request(Message):
1701 version = const.OFP_VERSION
1702 type = const.OFPT_FEATURES_REQUEST
1703
1704 def __init__(self, xid=None):
1705 self.xid = xid
1706
1707 def pack(self):
1708 packed = []
1709 packed.append(struct.pack("!B", self.version))
1710 packed.append(struct.pack("!B", self.type))
1711 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1712 packed.append(struct.pack("!L", self.xid))
1713 length = sum([len(x) for x in packed])
1714 packed[2] = struct.pack("!H", length)
1715 return ''.join(packed)
1716
1717 @staticmethod
1718 def unpack(buf):
1719 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1720 obj = features_request()
1721 if type(buf) == loxi.generic_util.OFReader:
1722 reader = buf
1723 else:
1724 reader = loxi.generic_util.OFReader(buf)
1725 _version = reader.read('!B')[0]
1726 assert(_version == const.OFP_VERSION)
1727 _type = reader.read('!B')[0]
1728 assert(_type == const.OFPT_FEATURES_REQUEST)
1729 _length = reader.read('!H')[0]
1730 obj.xid = reader.read('!L')[0]
1731 return obj
1732
1733 def __eq__(self, other):
1734 if type(self) != type(other): return False
1735 if self.version != other.version: return False
1736 if self.type != other.type: return False
1737 if self.xid != other.xid: return False
1738 return True
1739
1740 def __ne__(self, other):
1741 return not self.__eq__(other)
1742
1743 def __str__(self):
1744 return self.show()
1745
1746 def show(self):
1747 import loxi.pp
1748 return loxi.pp.pp(self)
1749
1750 def pretty_print(self, q):
1751 q.text("features_request {")
1752 with q.group():
1753 with q.indent(2):
1754 q.breakable()
1755 q.text("xid = ");
1756 if self.xid != None:
1757 q.text("%#x" % self.xid)
1758 else:
1759 q.text('None')
1760 q.breakable()
1761 q.text('}')
1762
1763class flow_add(Message):
1764 version = const.OFP_VERSION
1765 type = const.OFPT_FLOW_MOD
1766 _command = const.OFPFC_ADD
1767
1768 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):
1769 self.xid = xid
1770 if cookie != None:
1771 self.cookie = cookie
1772 else:
1773 self.cookie = 0
1774 if cookie_mask != None:
1775 self.cookie_mask = cookie_mask
1776 else:
1777 self.cookie_mask = 0
1778 if table_id != None:
1779 self.table_id = table_id
1780 else:
1781 self.table_id = 0
1782 if idle_timeout != None:
1783 self.idle_timeout = idle_timeout
1784 else:
1785 self.idle_timeout = 0
1786 if hard_timeout != None:
1787 self.hard_timeout = hard_timeout
1788 else:
1789 self.hard_timeout = 0
1790 if priority != None:
1791 self.priority = priority
1792 else:
1793 self.priority = 0
1794 if buffer_id != None:
1795 self.buffer_id = buffer_id
1796 else:
1797 self.buffer_id = 0
1798 if out_port != None:
1799 self.out_port = out_port
1800 else:
1801 self.out_port = 0
1802 if out_group != None:
1803 self.out_group = out_group
1804 else:
1805 self.out_group = 0
1806 if flags != None:
1807 self.flags = flags
1808 else:
1809 self.flags = 0
1810 if match != None:
1811 self.match = match
1812 else:
1813 self.match = common.match()
1814 if instructions != None:
1815 self.instructions = instructions
1816 else:
1817 self.instructions = []
1818
1819 def pack(self):
1820 packed = []
1821 packed.append(struct.pack("!B", self.version))
1822 packed.append(struct.pack("!B", self.type))
1823 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1824 packed.append(struct.pack("!L", self.xid))
1825 packed.append(struct.pack("!Q", self.cookie))
1826 packed.append(struct.pack("!Q", self.cookie_mask))
1827 packed.append(struct.pack("!B", self.table_id))
1828 packed.append(struct.pack("!B", self._command))
1829 packed.append(struct.pack("!H", self.idle_timeout))
1830 packed.append(struct.pack("!H", self.hard_timeout))
1831 packed.append(struct.pack("!H", self.priority))
1832 packed.append(struct.pack("!L", self.buffer_id))
1833 packed.append(struct.pack("!L", self.out_port))
1834 packed.append(struct.pack("!L", self.out_group))
1835 packed.append(struct.pack("!H", self.flags))
1836 packed.append('\x00' * 2)
1837 packed.append(self.match.pack())
1838 packed.append("".join([x.pack() for x in self.instructions]))
1839 length = sum([len(x) for x in packed])
1840 packed[2] = struct.pack("!H", length)
1841 return ''.join(packed)
1842
1843 @staticmethod
1844 def unpack(buf):
1845 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1846 obj = flow_add()
1847 if type(buf) == loxi.generic_util.OFReader:
1848 reader = buf
1849 else:
1850 reader = loxi.generic_util.OFReader(buf)
1851 _version = reader.read('!B')[0]
1852 assert(_version == const.OFP_VERSION)
1853 _type = reader.read('!B')[0]
1854 assert(_type == const.OFPT_FLOW_MOD)
1855 _length = reader.read('!H')[0]
1856 obj.xid = reader.read('!L')[0]
1857 obj.cookie = reader.read('!Q')[0]
1858 obj.cookie_mask = reader.read('!Q')[0]
1859 obj.table_id = reader.read('!B')[0]
1860 __command = reader.read('!B')[0]
1861 assert(__command == const.OFPFC_ADD)
1862 obj.idle_timeout = reader.read('!H')[0]
1863 obj.hard_timeout = reader.read('!H')[0]
1864 obj.priority = reader.read('!H')[0]
1865 obj.buffer_id = reader.read('!L')[0]
1866 obj.out_port = reader.read('!L')[0]
1867 obj.out_group = reader.read('!L')[0]
1868 obj.flags = reader.read('!H')[0]
1869 reader.skip(2)
1870 obj.match = common.match.unpack(reader)
1871 obj.instructions = instruction.unpack_list(reader)
1872 return obj
1873
1874 def __eq__(self, other):
1875 if type(self) != type(other): return False
1876 if self.version != other.version: return False
1877 if self.type != other.type: return False
1878 if self.xid != other.xid: return False
1879 if self.cookie != other.cookie: return False
1880 if self.cookie_mask != other.cookie_mask: return False
1881 if self.table_id != other.table_id: return False
1882 if self.idle_timeout != other.idle_timeout: return False
1883 if self.hard_timeout != other.hard_timeout: return False
1884 if self.priority != other.priority: return False
1885 if self.buffer_id != other.buffer_id: return False
1886 if self.out_port != other.out_port: return False
1887 if self.out_group != other.out_group: return False
1888 if self.flags != other.flags: return False
1889 if self.match != other.match: return False
1890 if self.instructions != other.instructions: return False
1891 return True
1892
1893 def __ne__(self, other):
1894 return not self.__eq__(other)
1895
1896 def __str__(self):
1897 return self.show()
1898
1899 def show(self):
1900 import loxi.pp
1901 return loxi.pp.pp(self)
1902
1903 def pretty_print(self, q):
1904 q.text("flow_add {")
1905 with q.group():
1906 with q.indent(2):
1907 q.breakable()
1908 q.text("xid = ");
1909 if self.xid != None:
1910 q.text("%#x" % self.xid)
1911 else:
1912 q.text('None')
1913 q.text(","); q.breakable()
1914 q.text("cookie = ");
1915 q.text("%#x" % self.cookie)
1916 q.text(","); q.breakable()
1917 q.text("cookie_mask = ");
1918 q.text("%#x" % self.cookie_mask)
1919 q.text(","); q.breakable()
1920 q.text("table_id = ");
1921 q.text("%#x" % self.table_id)
1922 q.text(","); q.breakable()
1923 q.text("idle_timeout = ");
1924 q.text("%#x" % self.idle_timeout)
1925 q.text(","); q.breakable()
1926 q.text("hard_timeout = ");
1927 q.text("%#x" % self.hard_timeout)
1928 q.text(","); q.breakable()
1929 q.text("priority = ");
1930 q.text("%#x" % self.priority)
1931 q.text(","); q.breakable()
1932 q.text("buffer_id = ");
1933 q.text("%#x" % self.buffer_id)
1934 q.text(","); q.breakable()
1935 q.text("out_port = ");
1936 q.text(util.pretty_port(self.out_port))
1937 q.text(","); q.breakable()
1938 q.text("out_group = ");
1939 q.text("%#x" % self.out_group)
1940 q.text(","); q.breakable()
1941 q.text("flags = ");
1942 q.text("%#x" % self.flags)
1943 q.text(","); q.breakable()
1944 q.text("match = ");
1945 q.pp(self.match)
1946 q.text(","); q.breakable()
1947 q.text("instructions = ");
1948 q.pp(self.instructions)
1949 q.breakable()
1950 q.text('}')
1951
1952class flow_delete(Message):
1953 version = const.OFP_VERSION
1954 type = const.OFPT_FLOW_MOD
1955 _command = const.OFPFC_DELETE
1956
1957 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):
1958 self.xid = xid
1959 if cookie != None:
1960 self.cookie = cookie
1961 else:
1962 self.cookie = 0
1963 if cookie_mask != None:
1964 self.cookie_mask = cookie_mask
1965 else:
1966 self.cookie_mask = 0
1967 if table_id != None:
1968 self.table_id = table_id
1969 else:
1970 self.table_id = 0
1971 if idle_timeout != None:
1972 self.idle_timeout = idle_timeout
1973 else:
1974 self.idle_timeout = 0
1975 if hard_timeout != None:
1976 self.hard_timeout = hard_timeout
1977 else:
1978 self.hard_timeout = 0
1979 if priority != None:
1980 self.priority = priority
1981 else:
1982 self.priority = 0
1983 if buffer_id != None:
1984 self.buffer_id = buffer_id
1985 else:
1986 self.buffer_id = 0
1987 if out_port != None:
1988 self.out_port = out_port
1989 else:
1990 self.out_port = 0
1991 if out_group != None:
1992 self.out_group = out_group
1993 else:
1994 self.out_group = 0
1995 if flags != None:
1996 self.flags = flags
1997 else:
1998 self.flags = 0
1999 if match != None:
2000 self.match = match
2001 else:
2002 self.match = common.match()
2003 if instructions != None:
2004 self.instructions = instructions
2005 else:
2006 self.instructions = []
2007
2008 def pack(self):
2009 packed = []
2010 packed.append(struct.pack("!B", self.version))
2011 packed.append(struct.pack("!B", self.type))
2012 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2013 packed.append(struct.pack("!L", self.xid))
2014 packed.append(struct.pack("!Q", self.cookie))
2015 packed.append(struct.pack("!Q", self.cookie_mask))
2016 packed.append(struct.pack("!B", self.table_id))
2017 packed.append(struct.pack("!B", self._command))
2018 packed.append(struct.pack("!H", self.idle_timeout))
2019 packed.append(struct.pack("!H", self.hard_timeout))
2020 packed.append(struct.pack("!H", self.priority))
2021 packed.append(struct.pack("!L", self.buffer_id))
2022 packed.append(struct.pack("!L", self.out_port))
2023 packed.append(struct.pack("!L", self.out_group))
2024 packed.append(struct.pack("!H", self.flags))
2025 packed.append('\x00' * 2)
2026 packed.append(self.match.pack())
2027 packed.append("".join([x.pack() for x in self.instructions]))
2028 length = sum([len(x) for x in packed])
2029 packed[2] = struct.pack("!H", length)
2030 return ''.join(packed)
2031
2032 @staticmethod
2033 def unpack(buf):
2034 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2035 obj = flow_delete()
2036 if type(buf) == loxi.generic_util.OFReader:
2037 reader = buf
2038 else:
2039 reader = loxi.generic_util.OFReader(buf)
2040 _version = reader.read('!B')[0]
2041 assert(_version == const.OFP_VERSION)
2042 _type = reader.read('!B')[0]
2043 assert(_type == const.OFPT_FLOW_MOD)
2044 _length = reader.read('!H')[0]
2045 obj.xid = reader.read('!L')[0]
2046 obj.cookie = reader.read('!Q')[0]
2047 obj.cookie_mask = reader.read('!Q')[0]
2048 obj.table_id = reader.read('!B')[0]
2049 __command = reader.read('!B')[0]
2050 assert(__command == const.OFPFC_DELETE)
2051 obj.idle_timeout = reader.read('!H')[0]
2052 obj.hard_timeout = reader.read('!H')[0]
2053 obj.priority = reader.read('!H')[0]
2054 obj.buffer_id = reader.read('!L')[0]
2055 obj.out_port = reader.read('!L')[0]
2056 obj.out_group = reader.read('!L')[0]
2057 obj.flags = reader.read('!H')[0]
2058 reader.skip(2)
2059 obj.match = common.match.unpack(reader)
2060 obj.instructions = instruction.unpack_list(reader)
2061 return obj
2062
2063 def __eq__(self, other):
2064 if type(self) != type(other): return False
2065 if self.version != other.version: return False
2066 if self.type != other.type: return False
2067 if self.xid != other.xid: return False
2068 if self.cookie != other.cookie: return False
2069 if self.cookie_mask != other.cookie_mask: return False
2070 if self.table_id != other.table_id: return False
2071 if self.idle_timeout != other.idle_timeout: return False
2072 if self.hard_timeout != other.hard_timeout: return False
2073 if self.priority != other.priority: return False
2074 if self.buffer_id != other.buffer_id: return False
2075 if self.out_port != other.out_port: return False
2076 if self.out_group != other.out_group: return False
2077 if self.flags != other.flags: return False
2078 if self.match != other.match: return False
2079 if self.instructions != other.instructions: return False
2080 return True
2081
2082 def __ne__(self, other):
2083 return not self.__eq__(other)
2084
2085 def __str__(self):
2086 return self.show()
2087
2088 def show(self):
2089 import loxi.pp
2090 return loxi.pp.pp(self)
2091
2092 def pretty_print(self, q):
2093 q.text("flow_delete {")
2094 with q.group():
2095 with q.indent(2):
2096 q.breakable()
2097 q.text("xid = ");
2098 if self.xid != None:
2099 q.text("%#x" % self.xid)
2100 else:
2101 q.text('None')
2102 q.text(","); q.breakable()
2103 q.text("cookie = ");
2104 q.text("%#x" % self.cookie)
2105 q.text(","); q.breakable()
2106 q.text("cookie_mask = ");
2107 q.text("%#x" % self.cookie_mask)
2108 q.text(","); q.breakable()
2109 q.text("table_id = ");
2110 q.text("%#x" % self.table_id)
2111 q.text(","); q.breakable()
2112 q.text("idle_timeout = ");
2113 q.text("%#x" % self.idle_timeout)
2114 q.text(","); q.breakable()
2115 q.text("hard_timeout = ");
2116 q.text("%#x" % self.hard_timeout)
2117 q.text(","); q.breakable()
2118 q.text("priority = ");
2119 q.text("%#x" % self.priority)
2120 q.text(","); q.breakable()
2121 q.text("buffer_id = ");
2122 q.text("%#x" % self.buffer_id)
2123 q.text(","); q.breakable()
2124 q.text("out_port = ");
2125 q.text(util.pretty_port(self.out_port))
2126 q.text(","); q.breakable()
2127 q.text("out_group = ");
2128 q.text("%#x" % self.out_group)
2129 q.text(","); q.breakable()
2130 q.text("flags = ");
2131 q.text("%#x" % self.flags)
2132 q.text(","); q.breakable()
2133 q.text("match = ");
2134 q.pp(self.match)
2135 q.text(","); q.breakable()
2136 q.text("instructions = ");
2137 q.pp(self.instructions)
2138 q.breakable()
2139 q.text('}')
2140
2141class flow_delete_strict(Message):
2142 version = const.OFP_VERSION
2143 type = const.OFPT_FLOW_MOD
2144 _command = const.OFPFC_DELETE_STRICT
2145
2146 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):
2147 self.xid = xid
2148 if cookie != None:
2149 self.cookie = cookie
2150 else:
2151 self.cookie = 0
2152 if cookie_mask != None:
2153 self.cookie_mask = cookie_mask
2154 else:
2155 self.cookie_mask = 0
2156 if table_id != None:
2157 self.table_id = table_id
2158 else:
2159 self.table_id = 0
2160 if idle_timeout != None:
2161 self.idle_timeout = idle_timeout
2162 else:
2163 self.idle_timeout = 0
2164 if hard_timeout != None:
2165 self.hard_timeout = hard_timeout
2166 else:
2167 self.hard_timeout = 0
2168 if priority != None:
2169 self.priority = priority
2170 else:
2171 self.priority = 0
2172 if buffer_id != None:
2173 self.buffer_id = buffer_id
2174 else:
2175 self.buffer_id = 0
2176 if out_port != None:
2177 self.out_port = out_port
2178 else:
2179 self.out_port = 0
2180 if out_group != None:
2181 self.out_group = out_group
2182 else:
2183 self.out_group = 0
2184 if flags != None:
2185 self.flags = flags
2186 else:
2187 self.flags = 0
2188 if match != None:
2189 self.match = match
2190 else:
2191 self.match = common.match()
2192 if instructions != None:
2193 self.instructions = instructions
2194 else:
2195 self.instructions = []
2196
2197 def pack(self):
2198 packed = []
2199 packed.append(struct.pack("!B", self.version))
2200 packed.append(struct.pack("!B", self.type))
2201 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2202 packed.append(struct.pack("!L", self.xid))
2203 packed.append(struct.pack("!Q", self.cookie))
2204 packed.append(struct.pack("!Q", self.cookie_mask))
2205 packed.append(struct.pack("!B", self.table_id))
2206 packed.append(struct.pack("!B", self._command))
2207 packed.append(struct.pack("!H", self.idle_timeout))
2208 packed.append(struct.pack("!H", self.hard_timeout))
2209 packed.append(struct.pack("!H", self.priority))
2210 packed.append(struct.pack("!L", self.buffer_id))
2211 packed.append(struct.pack("!L", self.out_port))
2212 packed.append(struct.pack("!L", self.out_group))
2213 packed.append(struct.pack("!H", self.flags))
2214 packed.append('\x00' * 2)
2215 packed.append(self.match.pack())
2216 packed.append("".join([x.pack() for x in self.instructions]))
2217 length = sum([len(x) for x in packed])
2218 packed[2] = struct.pack("!H", length)
2219 return ''.join(packed)
2220
2221 @staticmethod
2222 def unpack(buf):
2223 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2224 obj = flow_delete_strict()
2225 if type(buf) == loxi.generic_util.OFReader:
2226 reader = buf
2227 else:
2228 reader = loxi.generic_util.OFReader(buf)
2229 _version = reader.read('!B')[0]
2230 assert(_version == const.OFP_VERSION)
2231 _type = reader.read('!B')[0]
2232 assert(_type == const.OFPT_FLOW_MOD)
2233 _length = reader.read('!H')[0]
2234 obj.xid = reader.read('!L')[0]
2235 obj.cookie = reader.read('!Q')[0]
2236 obj.cookie_mask = reader.read('!Q')[0]
2237 obj.table_id = reader.read('!B')[0]
2238 __command = reader.read('!B')[0]
2239 assert(__command == const.OFPFC_DELETE_STRICT)
2240 obj.idle_timeout = reader.read('!H')[0]
2241 obj.hard_timeout = reader.read('!H')[0]
2242 obj.priority = reader.read('!H')[0]
2243 obj.buffer_id = reader.read('!L')[0]
2244 obj.out_port = reader.read('!L')[0]
2245 obj.out_group = reader.read('!L')[0]
2246 obj.flags = reader.read('!H')[0]
2247 reader.skip(2)
2248 obj.match = common.match.unpack(reader)
2249 obj.instructions = instruction.unpack_list(reader)
2250 return obj
2251
2252 def __eq__(self, other):
2253 if type(self) != type(other): return False
2254 if self.version != other.version: return False
2255 if self.type != other.type: return False
2256 if self.xid != other.xid: return False
2257 if self.cookie != other.cookie: return False
2258 if self.cookie_mask != other.cookie_mask: return False
2259 if self.table_id != other.table_id: return False
2260 if self.idle_timeout != other.idle_timeout: return False
2261 if self.hard_timeout != other.hard_timeout: return False
2262 if self.priority != other.priority: return False
2263 if self.buffer_id != other.buffer_id: return False
2264 if self.out_port != other.out_port: return False
2265 if self.out_group != other.out_group: return False
2266 if self.flags != other.flags: return False
2267 if self.match != other.match: return False
2268 if self.instructions != other.instructions: return False
2269 return True
2270
2271 def __ne__(self, other):
2272 return not self.__eq__(other)
2273
2274 def __str__(self):
2275 return self.show()
2276
2277 def show(self):
2278 import loxi.pp
2279 return loxi.pp.pp(self)
2280
2281 def pretty_print(self, q):
2282 q.text("flow_delete_strict {")
2283 with q.group():
2284 with q.indent(2):
2285 q.breakable()
2286 q.text("xid = ");
2287 if self.xid != None:
2288 q.text("%#x" % self.xid)
2289 else:
2290 q.text('None')
2291 q.text(","); q.breakable()
2292 q.text("cookie = ");
2293 q.text("%#x" % self.cookie)
2294 q.text(","); q.breakable()
2295 q.text("cookie_mask = ");
2296 q.text("%#x" % self.cookie_mask)
2297 q.text(","); q.breakable()
2298 q.text("table_id = ");
2299 q.text("%#x" % self.table_id)
2300 q.text(","); q.breakable()
2301 q.text("idle_timeout = ");
2302 q.text("%#x" % self.idle_timeout)
2303 q.text(","); q.breakable()
2304 q.text("hard_timeout = ");
2305 q.text("%#x" % self.hard_timeout)
2306 q.text(","); q.breakable()
2307 q.text("priority = ");
2308 q.text("%#x" % self.priority)
2309 q.text(","); q.breakable()
2310 q.text("buffer_id = ");
2311 q.text("%#x" % self.buffer_id)
2312 q.text(","); q.breakable()
2313 q.text("out_port = ");
2314 q.text(util.pretty_port(self.out_port))
2315 q.text(","); q.breakable()
2316 q.text("out_group = ");
2317 q.text("%#x" % self.out_group)
2318 q.text(","); q.breakable()
2319 q.text("flags = ");
2320 q.text("%#x" % self.flags)
2321 q.text(","); q.breakable()
2322 q.text("match = ");
2323 q.pp(self.match)
2324 q.text(","); q.breakable()
2325 q.text("instructions = ");
2326 q.pp(self.instructions)
2327 q.breakable()
2328 q.text('}')
2329
2330class flow_modify(Message):
2331 version = const.OFP_VERSION
2332 type = const.OFPT_FLOW_MOD
2333 _command = const.OFPFC_MODIFY
2334
2335 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):
2336 self.xid = xid
2337 if cookie != None:
2338 self.cookie = cookie
2339 else:
2340 self.cookie = 0
2341 if cookie_mask != None:
2342 self.cookie_mask = cookie_mask
2343 else:
2344 self.cookie_mask = 0
2345 if table_id != None:
2346 self.table_id = table_id
2347 else:
2348 self.table_id = 0
2349 if idle_timeout != None:
2350 self.idle_timeout = idle_timeout
2351 else:
2352 self.idle_timeout = 0
2353 if hard_timeout != None:
2354 self.hard_timeout = hard_timeout
2355 else:
2356 self.hard_timeout = 0
2357 if priority != None:
2358 self.priority = priority
2359 else:
2360 self.priority = 0
2361 if buffer_id != None:
2362 self.buffer_id = buffer_id
2363 else:
2364 self.buffer_id = 0
2365 if out_port != None:
2366 self.out_port = out_port
2367 else:
2368 self.out_port = 0
2369 if out_group != None:
2370 self.out_group = out_group
2371 else:
2372 self.out_group = 0
2373 if flags != None:
2374 self.flags = flags
2375 else:
2376 self.flags = 0
2377 if match != None:
2378 self.match = match
2379 else:
2380 self.match = common.match()
2381 if instructions != None:
2382 self.instructions = instructions
2383 else:
2384 self.instructions = []
2385
2386 def pack(self):
2387 packed = []
2388 packed.append(struct.pack("!B", self.version))
2389 packed.append(struct.pack("!B", self.type))
2390 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2391 packed.append(struct.pack("!L", self.xid))
2392 packed.append(struct.pack("!Q", self.cookie))
2393 packed.append(struct.pack("!Q", self.cookie_mask))
2394 packed.append(struct.pack("!B", self.table_id))
2395 packed.append(struct.pack("!B", self._command))
2396 packed.append(struct.pack("!H", self.idle_timeout))
2397 packed.append(struct.pack("!H", self.hard_timeout))
2398 packed.append(struct.pack("!H", self.priority))
2399 packed.append(struct.pack("!L", self.buffer_id))
2400 packed.append(struct.pack("!L", self.out_port))
2401 packed.append(struct.pack("!L", self.out_group))
2402 packed.append(struct.pack("!H", self.flags))
2403 packed.append('\x00' * 2)
2404 packed.append(self.match.pack())
2405 packed.append("".join([x.pack() for x in self.instructions]))
2406 length = sum([len(x) for x in packed])
2407 packed[2] = struct.pack("!H", length)
2408 return ''.join(packed)
2409
2410 @staticmethod
2411 def unpack(buf):
2412 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2413 obj = flow_modify()
2414 if type(buf) == loxi.generic_util.OFReader:
2415 reader = buf
2416 else:
2417 reader = loxi.generic_util.OFReader(buf)
2418 _version = reader.read('!B')[0]
2419 assert(_version == const.OFP_VERSION)
2420 _type = reader.read('!B')[0]
2421 assert(_type == const.OFPT_FLOW_MOD)
2422 _length = reader.read('!H')[0]
2423 obj.xid = reader.read('!L')[0]
2424 obj.cookie = reader.read('!Q')[0]
2425 obj.cookie_mask = reader.read('!Q')[0]
2426 obj.table_id = reader.read('!B')[0]
2427 __command = reader.read('!B')[0]
2428 assert(__command == const.OFPFC_MODIFY)
2429 obj.idle_timeout = reader.read('!H')[0]
2430 obj.hard_timeout = reader.read('!H')[0]
2431 obj.priority = reader.read('!H')[0]
2432 obj.buffer_id = reader.read('!L')[0]
2433 obj.out_port = reader.read('!L')[0]
2434 obj.out_group = reader.read('!L')[0]
2435 obj.flags = reader.read('!H')[0]
2436 reader.skip(2)
2437 obj.match = common.match.unpack(reader)
2438 obj.instructions = instruction.unpack_list(reader)
2439 return obj
2440
2441 def __eq__(self, other):
2442 if type(self) != type(other): return False
2443 if self.version != other.version: return False
2444 if self.type != other.type: return False
2445 if self.xid != other.xid: return False
2446 if self.cookie != other.cookie: return False
2447 if self.cookie_mask != other.cookie_mask: return False
2448 if self.table_id != other.table_id: return False
2449 if self.idle_timeout != other.idle_timeout: return False
2450 if self.hard_timeout != other.hard_timeout: return False
2451 if self.priority != other.priority: return False
2452 if self.buffer_id != other.buffer_id: return False
2453 if self.out_port != other.out_port: return False
2454 if self.out_group != other.out_group: return False
2455 if self.flags != other.flags: return False
2456 if self.match != other.match: return False
2457 if self.instructions != other.instructions: return False
2458 return True
2459
2460 def __ne__(self, other):
2461 return not self.__eq__(other)
2462
2463 def __str__(self):
2464 return self.show()
2465
2466 def show(self):
2467 import loxi.pp
2468 return loxi.pp.pp(self)
2469
2470 def pretty_print(self, q):
2471 q.text("flow_modify {")
2472 with q.group():
2473 with q.indent(2):
2474 q.breakable()
2475 q.text("xid = ");
2476 if self.xid != None:
2477 q.text("%#x" % self.xid)
2478 else:
2479 q.text('None')
2480 q.text(","); q.breakable()
2481 q.text("cookie = ");
2482 q.text("%#x" % self.cookie)
2483 q.text(","); q.breakable()
2484 q.text("cookie_mask = ");
2485 q.text("%#x" % self.cookie_mask)
2486 q.text(","); q.breakable()
2487 q.text("table_id = ");
2488 q.text("%#x" % self.table_id)
2489 q.text(","); q.breakable()
2490 q.text("idle_timeout = ");
2491 q.text("%#x" % self.idle_timeout)
2492 q.text(","); q.breakable()
2493 q.text("hard_timeout = ");
2494 q.text("%#x" % self.hard_timeout)
2495 q.text(","); q.breakable()
2496 q.text("priority = ");
2497 q.text("%#x" % self.priority)
2498 q.text(","); q.breakable()
2499 q.text("buffer_id = ");
2500 q.text("%#x" % self.buffer_id)
2501 q.text(","); q.breakable()
2502 q.text("out_port = ");
2503 q.text(util.pretty_port(self.out_port))
2504 q.text(","); q.breakable()
2505 q.text("out_group = ");
2506 q.text("%#x" % self.out_group)
2507 q.text(","); q.breakable()
2508 q.text("flags = ");
2509 q.text("%#x" % self.flags)
2510 q.text(","); q.breakable()
2511 q.text("match = ");
2512 q.pp(self.match)
2513 q.text(","); q.breakable()
2514 q.text("instructions = ");
2515 q.pp(self.instructions)
2516 q.breakable()
2517 q.text('}')
2518
2519class flow_modify_strict(Message):
2520 version = const.OFP_VERSION
2521 type = const.OFPT_FLOW_MOD
2522 _command = const.OFPFC_MODIFY_STRICT
2523
2524 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):
2525 self.xid = xid
2526 if cookie != None:
2527 self.cookie = cookie
2528 else:
2529 self.cookie = 0
2530 if cookie_mask != None:
2531 self.cookie_mask = cookie_mask
2532 else:
2533 self.cookie_mask = 0
2534 if table_id != None:
2535 self.table_id = table_id
2536 else:
2537 self.table_id = 0
2538 if idle_timeout != None:
2539 self.idle_timeout = idle_timeout
2540 else:
2541 self.idle_timeout = 0
2542 if hard_timeout != None:
2543 self.hard_timeout = hard_timeout
2544 else:
2545 self.hard_timeout = 0
2546 if priority != None:
2547 self.priority = priority
2548 else:
2549 self.priority = 0
2550 if buffer_id != None:
2551 self.buffer_id = buffer_id
2552 else:
2553 self.buffer_id = 0
2554 if out_port != None:
2555 self.out_port = out_port
2556 else:
2557 self.out_port = 0
2558 if out_group != None:
2559 self.out_group = out_group
2560 else:
2561 self.out_group = 0
2562 if flags != None:
2563 self.flags = flags
2564 else:
2565 self.flags = 0
2566 if match != None:
2567 self.match = match
2568 else:
2569 self.match = common.match()
2570 if instructions != None:
2571 self.instructions = instructions
2572 else:
2573 self.instructions = []
2574
2575 def pack(self):
2576 packed = []
2577 packed.append(struct.pack("!B", self.version))
2578 packed.append(struct.pack("!B", self.type))
2579 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2580 packed.append(struct.pack("!L", self.xid))
2581 packed.append(struct.pack("!Q", self.cookie))
2582 packed.append(struct.pack("!Q", self.cookie_mask))
2583 packed.append(struct.pack("!B", self.table_id))
2584 packed.append(struct.pack("!B", self._command))
2585 packed.append(struct.pack("!H", self.idle_timeout))
2586 packed.append(struct.pack("!H", self.hard_timeout))
2587 packed.append(struct.pack("!H", self.priority))
2588 packed.append(struct.pack("!L", self.buffer_id))
2589 packed.append(struct.pack("!L", self.out_port))
2590 packed.append(struct.pack("!L", self.out_group))
2591 packed.append(struct.pack("!H", self.flags))
2592 packed.append('\x00' * 2)
2593 packed.append(self.match.pack())
2594 packed.append("".join([x.pack() for x in self.instructions]))
2595 length = sum([len(x) for x in packed])
2596 packed[2] = struct.pack("!H", length)
2597 return ''.join(packed)
2598
2599 @staticmethod
2600 def unpack(buf):
2601 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2602 obj = flow_modify_strict()
2603 if type(buf) == loxi.generic_util.OFReader:
2604 reader = buf
2605 else:
2606 reader = loxi.generic_util.OFReader(buf)
2607 _version = reader.read('!B')[0]
2608 assert(_version == const.OFP_VERSION)
2609 _type = reader.read('!B')[0]
2610 assert(_type == const.OFPT_FLOW_MOD)
2611 _length = reader.read('!H')[0]
2612 obj.xid = reader.read('!L')[0]
2613 obj.cookie = reader.read('!Q')[0]
2614 obj.cookie_mask = reader.read('!Q')[0]
2615 obj.table_id = reader.read('!B')[0]
2616 __command = reader.read('!B')[0]
2617 assert(__command == const.OFPFC_MODIFY_STRICT)
2618 obj.idle_timeout = reader.read('!H')[0]
2619 obj.hard_timeout = reader.read('!H')[0]
2620 obj.priority = reader.read('!H')[0]
2621 obj.buffer_id = reader.read('!L')[0]
2622 obj.out_port = reader.read('!L')[0]
2623 obj.out_group = reader.read('!L')[0]
2624 obj.flags = reader.read('!H')[0]
2625 reader.skip(2)
2626 obj.match = common.match.unpack(reader)
2627 obj.instructions = instruction.unpack_list(reader)
2628 return obj
2629
2630 def __eq__(self, other):
2631 if type(self) != type(other): return False
2632 if self.version != other.version: return False
2633 if self.type != other.type: return False
2634 if self.xid != other.xid: return False
2635 if self.cookie != other.cookie: return False
2636 if self.cookie_mask != other.cookie_mask: return False
2637 if self.table_id != other.table_id: return False
2638 if self.idle_timeout != other.idle_timeout: return False
2639 if self.hard_timeout != other.hard_timeout: return False
2640 if self.priority != other.priority: return False
2641 if self.buffer_id != other.buffer_id: return False
2642 if self.out_port != other.out_port: return False
2643 if self.out_group != other.out_group: return False
2644 if self.flags != other.flags: return False
2645 if self.match != other.match: return False
2646 if self.instructions != other.instructions: return False
2647 return True
2648
2649 def __ne__(self, other):
2650 return not self.__eq__(other)
2651
2652 def __str__(self):
2653 return self.show()
2654
2655 def show(self):
2656 import loxi.pp
2657 return loxi.pp.pp(self)
2658
2659 def pretty_print(self, q):
2660 q.text("flow_modify_strict {")
2661 with q.group():
2662 with q.indent(2):
2663 q.breakable()
2664 q.text("xid = ");
2665 if self.xid != None:
2666 q.text("%#x" % self.xid)
2667 else:
2668 q.text('None')
2669 q.text(","); q.breakable()
2670 q.text("cookie = ");
2671 q.text("%#x" % self.cookie)
2672 q.text(","); q.breakable()
2673 q.text("cookie_mask = ");
2674 q.text("%#x" % self.cookie_mask)
2675 q.text(","); q.breakable()
2676 q.text("table_id = ");
2677 q.text("%#x" % self.table_id)
2678 q.text(","); q.breakable()
2679 q.text("idle_timeout = ");
2680 q.text("%#x" % self.idle_timeout)
2681 q.text(","); q.breakable()
2682 q.text("hard_timeout = ");
2683 q.text("%#x" % self.hard_timeout)
2684 q.text(","); q.breakable()
2685 q.text("priority = ");
2686 q.text("%#x" % self.priority)
2687 q.text(","); q.breakable()
2688 q.text("buffer_id = ");
2689 q.text("%#x" % self.buffer_id)
2690 q.text(","); q.breakable()
2691 q.text("out_port = ");
2692 q.text(util.pretty_port(self.out_port))
2693 q.text(","); q.breakable()
2694 q.text("out_group = ");
2695 q.text("%#x" % self.out_group)
2696 q.text(","); q.breakable()
2697 q.text("flags = ");
2698 q.text("%#x" % self.flags)
2699 q.text(","); q.breakable()
2700 q.text("match = ");
2701 q.pp(self.match)
2702 q.text(","); q.breakable()
2703 q.text("instructions = ");
2704 q.pp(self.instructions)
2705 q.breakable()
2706 q.text('}')
2707
2708class flow_removed(Message):
2709 version = const.OFP_VERSION
2710 type = const.OFPT_FLOW_REMOVED
2711
2712 def __init__(self, xid=None, cookie=None, priority=None, reason=None, table_id=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None, match=None):
2713 self.xid = xid
2714 if cookie != None:
2715 self.cookie = cookie
2716 else:
2717 self.cookie = 0
2718 if priority != None:
2719 self.priority = priority
2720 else:
2721 self.priority = 0
2722 if reason != None:
2723 self.reason = reason
2724 else:
2725 self.reason = 0
2726 if table_id != None:
2727 self.table_id = table_id
2728 else:
2729 self.table_id = 0
2730 if duration_sec != None:
2731 self.duration_sec = duration_sec
2732 else:
2733 self.duration_sec = 0
2734 if duration_nsec != None:
2735 self.duration_nsec = duration_nsec
2736 else:
2737 self.duration_nsec = 0
2738 if idle_timeout != None:
2739 self.idle_timeout = idle_timeout
2740 else:
2741 self.idle_timeout = 0
2742 if packet_count != None:
2743 self.packet_count = packet_count
2744 else:
2745 self.packet_count = 0
2746 if byte_count != None:
2747 self.byte_count = byte_count
2748 else:
2749 self.byte_count = 0
2750 if match != None:
2751 self.match = match
2752 else:
2753 self.match = common.match()
2754
2755 def pack(self):
2756 packed = []
2757 packed.append(struct.pack("!B", self.version))
2758 packed.append(struct.pack("!B", self.type))
2759 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2760 packed.append(struct.pack("!L", self.xid))
2761 packed.append(struct.pack("!Q", self.cookie))
2762 packed.append(struct.pack("!H", self.priority))
2763 packed.append(struct.pack("!B", self.reason))
2764 packed.append(struct.pack("!B", self.table_id))
2765 packed.append(struct.pack("!L", self.duration_sec))
2766 packed.append(struct.pack("!L", self.duration_nsec))
2767 packed.append(struct.pack("!H", self.idle_timeout))
2768 packed.append('\x00' * 2)
2769 packed.append(struct.pack("!Q", self.packet_count))
2770 packed.append(struct.pack("!Q", self.byte_count))
2771 packed.append(self.match.pack())
2772 length = sum([len(x) for x in packed])
2773 packed[2] = struct.pack("!H", length)
2774 return ''.join(packed)
2775
2776 @staticmethod
2777 def unpack(buf):
2778 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2779 obj = flow_removed()
2780 if type(buf) == loxi.generic_util.OFReader:
2781 reader = buf
2782 else:
2783 reader = loxi.generic_util.OFReader(buf)
2784 _version = reader.read('!B')[0]
2785 assert(_version == const.OFP_VERSION)
2786 _type = reader.read('!B')[0]
2787 assert(_type == const.OFPT_FLOW_REMOVED)
2788 _length = reader.read('!H')[0]
2789 obj.xid = reader.read('!L')[0]
2790 obj.cookie = reader.read('!Q')[0]
2791 obj.priority = reader.read('!H')[0]
2792 obj.reason = reader.read('!B')[0]
2793 obj.table_id = reader.read('!B')[0]
2794 obj.duration_sec = reader.read('!L')[0]
2795 obj.duration_nsec = reader.read('!L')[0]
2796 obj.idle_timeout = reader.read('!H')[0]
2797 reader.skip(2)
2798 obj.packet_count = reader.read('!Q')[0]
2799 obj.byte_count = reader.read('!Q')[0]
2800 obj.match = common.match.unpack(reader)
2801 return obj
2802
2803 def __eq__(self, other):
2804 if type(self) != type(other): return False
2805 if self.version != other.version: return False
2806 if self.type != other.type: return False
2807 if self.xid != other.xid: return False
2808 if self.cookie != other.cookie: return False
2809 if self.priority != other.priority: return False
2810 if self.reason != other.reason: return False
2811 if self.table_id != other.table_id: return False
2812 if self.duration_sec != other.duration_sec: return False
2813 if self.duration_nsec != other.duration_nsec: return False
2814 if self.idle_timeout != other.idle_timeout: return False
2815 if self.packet_count != other.packet_count: return False
2816 if self.byte_count != other.byte_count: return False
2817 if self.match != other.match: return False
2818 return True
2819
2820 def __ne__(self, other):
2821 return not self.__eq__(other)
2822
2823 def __str__(self):
2824 return self.show()
2825
2826 def show(self):
2827 import loxi.pp
2828 return loxi.pp.pp(self)
2829
2830 def pretty_print(self, q):
2831 q.text("flow_removed {")
2832 with q.group():
2833 with q.indent(2):
2834 q.breakable()
2835 q.text("xid = ");
2836 if self.xid != None:
2837 q.text("%#x" % self.xid)
2838 else:
2839 q.text('None')
2840 q.text(","); q.breakable()
2841 q.text("cookie = ");
2842 q.text("%#x" % self.cookie)
2843 q.text(","); q.breakable()
2844 q.text("priority = ");
2845 q.text("%#x" % self.priority)
2846 q.text(","); q.breakable()
2847 q.text("reason = ");
2848 q.text("%#x" % self.reason)
2849 q.text(","); q.breakable()
2850 q.text("table_id = ");
2851 q.text("%#x" % self.table_id)
2852 q.text(","); q.breakable()
2853 q.text("duration_sec = ");
2854 q.text("%#x" % self.duration_sec)
2855 q.text(","); q.breakable()
2856 q.text("duration_nsec = ");
2857 q.text("%#x" % self.duration_nsec)
2858 q.text(","); q.breakable()
2859 q.text("idle_timeout = ");
2860 q.text("%#x" % self.idle_timeout)
2861 q.text(","); q.breakable()
2862 q.text("packet_count = ");
2863 q.text("%#x" % self.packet_count)
2864 q.text(","); q.breakable()
2865 q.text("byte_count = ");
2866 q.text("%#x" % self.byte_count)
2867 q.text(","); q.breakable()
2868 q.text("match = ");
2869 q.pp(self.match)
2870 q.breakable()
2871 q.text('}')
2872
2873class flow_stats_reply(Message):
2874 version = const.OFP_VERSION
2875 type = const.OFPT_STATS_REPLY
2876 stats_type = const.OFPST_FLOW
2877
2878 def __init__(self, xid=None, flags=None, entries=None):
2879 self.xid = xid
2880 if flags != None:
2881 self.flags = flags
2882 else:
2883 self.flags = 0
2884 if entries != None:
2885 self.entries = entries
2886 else:
2887 self.entries = []
2888
2889 def pack(self):
2890 packed = []
2891 packed.append(struct.pack("!B", self.version))
2892 packed.append(struct.pack("!B", self.type))
2893 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2894 packed.append(struct.pack("!L", self.xid))
2895 packed.append(struct.pack("!H", self.stats_type))
2896 packed.append(struct.pack("!H", self.flags))
2897 packed.append('\x00' * 4)
2898 packed.append("".join([x.pack() for x in self.entries]))
2899 length = sum([len(x) for x in packed])
2900 packed[2] = struct.pack("!H", length)
2901 return ''.join(packed)
2902
2903 @staticmethod
2904 def unpack(buf):
2905 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2906 obj = flow_stats_reply()
2907 if type(buf) == loxi.generic_util.OFReader:
2908 reader = buf
2909 else:
2910 reader = loxi.generic_util.OFReader(buf)
2911 _version = reader.read('!B')[0]
2912 assert(_version == const.OFP_VERSION)
2913 _type = reader.read('!B')[0]
2914 assert(_type == const.OFPT_STATS_REPLY)
2915 _length = reader.read('!H')[0]
2916 obj.xid = reader.read('!L')[0]
2917 _stats_type = reader.read('!H')[0]
2918 assert(_stats_type == const.OFPST_FLOW)
2919 obj.flags = reader.read('!H')[0]
2920 reader.skip(4)
2921 obj.entries = common.unpack_list_flow_stats_entry(reader)
2922 return obj
2923
2924 def __eq__(self, other):
2925 if type(self) != type(other): return False
2926 if self.version != other.version: return False
2927 if self.type != other.type: return False
2928 if self.xid != other.xid: return False
2929 if self.flags != other.flags: return False
2930 if self.entries != other.entries: return False
2931 return True
2932
2933 def __ne__(self, other):
2934 return not self.__eq__(other)
2935
2936 def __str__(self):
2937 return self.show()
2938
2939 def show(self):
2940 import loxi.pp
2941 return loxi.pp.pp(self)
2942
2943 def pretty_print(self, q):
2944 q.text("flow_stats_reply {")
2945 with q.group():
2946 with q.indent(2):
2947 q.breakable()
2948 q.text("xid = ");
2949 if self.xid != None:
2950 q.text("%#x" % self.xid)
2951 else:
2952 q.text('None')
2953 q.text(","); q.breakable()
2954 q.text("flags = ");
2955 q.text("%#x" % self.flags)
2956 q.text(","); q.breakable()
2957 q.text("entries = ");
2958 q.pp(self.entries)
2959 q.breakable()
2960 q.text('}')
2961
2962class flow_stats_request(Message):
2963 version = const.OFP_VERSION
2964 type = const.OFPT_STATS_REQUEST
2965 stats_type = const.OFPST_FLOW
2966
2967 def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
2968 self.xid = xid
2969 if flags != None:
2970 self.flags = flags
2971 else:
2972 self.flags = 0
2973 if table_id != None:
2974 self.table_id = table_id
2975 else:
2976 self.table_id = 0
2977 if out_port != None:
2978 self.out_port = out_port
2979 else:
2980 self.out_port = 0
2981 if out_group != None:
2982 self.out_group = out_group
2983 else:
2984 self.out_group = 0
2985 if cookie != None:
2986 self.cookie = cookie
2987 else:
2988 self.cookie = 0
2989 if cookie_mask != None:
2990 self.cookie_mask = cookie_mask
2991 else:
2992 self.cookie_mask = 0
2993 if match != None:
2994 self.match = match
2995 else:
2996 self.match = common.match()
2997
2998 def pack(self):
2999 packed = []
3000 packed.append(struct.pack("!B", self.version))
3001 packed.append(struct.pack("!B", self.type))
3002 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3003 packed.append(struct.pack("!L", self.xid))
3004 packed.append(struct.pack("!H", self.stats_type))
3005 packed.append(struct.pack("!H", self.flags))
3006 packed.append('\x00' * 4)
3007 packed.append(struct.pack("!B", self.table_id))
3008 packed.append('\x00' * 3)
3009 packed.append(struct.pack("!L", self.out_port))
3010 packed.append(struct.pack("!L", self.out_group))
3011 packed.append('\x00' * 4)
3012 packed.append(struct.pack("!Q", self.cookie))
3013 packed.append(struct.pack("!Q", self.cookie_mask))
3014 packed.append(self.match.pack())
3015 length = sum([len(x) for x in packed])
3016 packed[2] = struct.pack("!H", length)
3017 return ''.join(packed)
3018
3019 @staticmethod
3020 def unpack(buf):
3021 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3022 obj = flow_stats_request()
3023 if type(buf) == loxi.generic_util.OFReader:
3024 reader = buf
3025 else:
3026 reader = loxi.generic_util.OFReader(buf)
3027 _version = reader.read('!B')[0]
3028 assert(_version == const.OFP_VERSION)
3029 _type = reader.read('!B')[0]
3030 assert(_type == const.OFPT_STATS_REQUEST)
3031 _length = reader.read('!H')[0]
3032 obj.xid = reader.read('!L')[0]
3033 _stats_type = reader.read('!H')[0]
3034 assert(_stats_type == const.OFPST_FLOW)
3035 obj.flags = reader.read('!H')[0]
3036 reader.skip(4)
3037 obj.table_id = reader.read('!B')[0]
3038 reader.skip(3)
3039 obj.out_port = reader.read('!L')[0]
3040 obj.out_group = reader.read('!L')[0]
3041 reader.skip(4)
3042 obj.cookie = reader.read('!Q')[0]
3043 obj.cookie_mask = reader.read('!Q')[0]
3044 obj.match = common.match.unpack(reader)
3045 return obj
3046
3047 def __eq__(self, other):
3048 if type(self) != type(other): return False
3049 if self.version != other.version: return False
3050 if self.type != other.type: return False
3051 if self.xid != other.xid: return False
3052 if self.flags != other.flags: return False
3053 if self.table_id != other.table_id: return False
3054 if self.out_port != other.out_port: return False
3055 if self.out_group != other.out_group: return False
3056 if self.cookie != other.cookie: return False
3057 if self.cookie_mask != other.cookie_mask: return False
3058 if self.match != other.match: return False
3059 return True
3060
3061 def __ne__(self, other):
3062 return not self.__eq__(other)
3063
3064 def __str__(self):
3065 return self.show()
3066
3067 def show(self):
3068 import loxi.pp
3069 return loxi.pp.pp(self)
3070
3071 def pretty_print(self, q):
3072 q.text("flow_stats_request {")
3073 with q.group():
3074 with q.indent(2):
3075 q.breakable()
3076 q.text("xid = ");
3077 if self.xid != None:
3078 q.text("%#x" % self.xid)
3079 else:
3080 q.text('None')
3081 q.text(","); q.breakable()
3082 q.text("flags = ");
3083 q.text("%#x" % self.flags)
3084 q.text(","); q.breakable()
3085 q.text("table_id = ");
3086 q.text("%#x" % self.table_id)
3087 q.text(","); q.breakable()
3088 q.text("out_port = ");
3089 q.text(util.pretty_port(self.out_port))
3090 q.text(","); q.breakable()
3091 q.text("out_group = ");
3092 q.text("%#x" % self.out_group)
3093 q.text(","); q.breakable()
3094 q.text("cookie = ");
3095 q.text("%#x" % self.cookie)
3096 q.text(","); q.breakable()
3097 q.text("cookie_mask = ");
3098 q.text("%#x" % self.cookie_mask)
3099 q.text(","); q.breakable()
3100 q.text("match = ");
3101 q.pp(self.match)
3102 q.breakable()
3103 q.text('}')
3104
3105class get_config_reply(Message):
3106 version = const.OFP_VERSION
3107 type = const.OFPT_GET_CONFIG_REPLY
3108
3109 def __init__(self, xid=None, flags=None, miss_send_len=None):
3110 self.xid = xid
3111 if flags != None:
3112 self.flags = flags
3113 else:
3114 self.flags = 0
3115 if miss_send_len != None:
3116 self.miss_send_len = miss_send_len
3117 else:
3118 self.miss_send_len = 0
3119
3120 def pack(self):
3121 packed = []
3122 packed.append(struct.pack("!B", self.version))
3123 packed.append(struct.pack("!B", self.type))
3124 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3125 packed.append(struct.pack("!L", self.xid))
3126 packed.append(struct.pack("!H", self.flags))
3127 packed.append(struct.pack("!H", self.miss_send_len))
3128 length = sum([len(x) for x in packed])
3129 packed[2] = struct.pack("!H", length)
3130 return ''.join(packed)
3131
3132 @staticmethod
3133 def unpack(buf):
3134 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3135 obj = get_config_reply()
3136 if type(buf) == loxi.generic_util.OFReader:
3137 reader = buf
3138 else:
3139 reader = loxi.generic_util.OFReader(buf)
3140 _version = reader.read('!B')[0]
3141 assert(_version == const.OFP_VERSION)
3142 _type = reader.read('!B')[0]
3143 assert(_type == const.OFPT_GET_CONFIG_REPLY)
3144 _length = reader.read('!H')[0]
3145 obj.xid = reader.read('!L')[0]
3146 obj.flags = reader.read('!H')[0]
3147 obj.miss_send_len = reader.read('!H')[0]
3148 return obj
3149
3150 def __eq__(self, other):
3151 if type(self) != type(other): return False
3152 if self.version != other.version: return False
3153 if self.type != other.type: return False
3154 if self.xid != other.xid: return False
3155 if self.flags != other.flags: return False
3156 if self.miss_send_len != other.miss_send_len: return False
3157 return True
3158
3159 def __ne__(self, other):
3160 return not self.__eq__(other)
3161
3162 def __str__(self):
3163 return self.show()
3164
3165 def show(self):
3166 import loxi.pp
3167 return loxi.pp.pp(self)
3168
3169 def pretty_print(self, q):
3170 q.text("get_config_reply {")
3171 with q.group():
3172 with q.indent(2):
3173 q.breakable()
3174 q.text("xid = ");
3175 if self.xid != None:
3176 q.text("%#x" % self.xid)
3177 else:
3178 q.text('None')
3179 q.text(","); q.breakable()
3180 q.text("flags = ");
3181 q.text("%#x" % self.flags)
3182 q.text(","); q.breakable()
3183 q.text("miss_send_len = ");
3184 q.text("%#x" % self.miss_send_len)
3185 q.breakable()
3186 q.text('}')
3187
3188class get_config_request(Message):
3189 version = const.OFP_VERSION
3190 type = const.OFPT_GET_CONFIG_REQUEST
3191
3192 def __init__(self, xid=None):
3193 self.xid = xid
3194
3195 def pack(self):
3196 packed = []
3197 packed.append(struct.pack("!B", self.version))
3198 packed.append(struct.pack("!B", self.type))
3199 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3200 packed.append(struct.pack("!L", self.xid))
3201 length = sum([len(x) for x in packed])
3202 packed[2] = struct.pack("!H", length)
3203 return ''.join(packed)
3204
3205 @staticmethod
3206 def unpack(buf):
3207 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3208 obj = get_config_request()
3209 if type(buf) == loxi.generic_util.OFReader:
3210 reader = buf
3211 else:
3212 reader = loxi.generic_util.OFReader(buf)
3213 _version = reader.read('!B')[0]
3214 assert(_version == const.OFP_VERSION)
3215 _type = reader.read('!B')[0]
3216 assert(_type == const.OFPT_GET_CONFIG_REQUEST)
3217 _length = reader.read('!H')[0]
3218 obj.xid = reader.read('!L')[0]
3219 return obj
3220
3221 def __eq__(self, other):
3222 if type(self) != type(other): return False
3223 if self.version != other.version: return False
3224 if self.type != other.type: return False
3225 if self.xid != other.xid: return False
3226 return True
3227
3228 def __ne__(self, other):
3229 return not self.__eq__(other)
3230
3231 def __str__(self):
3232 return self.show()
3233
3234 def show(self):
3235 import loxi.pp
3236 return loxi.pp.pp(self)
3237
3238 def pretty_print(self, q):
3239 q.text("get_config_request {")
3240 with q.group():
3241 with q.indent(2):
3242 q.breakable()
3243 q.text("xid = ");
3244 if self.xid != None:
3245 q.text("%#x" % self.xid)
3246 else:
3247 q.text('None')
3248 q.breakable()
3249 q.text('}')
3250
3251class group_desc_stats_reply(Message):
3252 version = const.OFP_VERSION
3253 type = const.OFPT_STATS_REPLY
3254 stats_type = const.OFPST_GROUP_DESC
3255
3256 def __init__(self, xid=None, flags=None, entries=None):
3257 self.xid = xid
3258 if flags != None:
3259 self.flags = flags
3260 else:
3261 self.flags = 0
3262 if entries != None:
3263 self.entries = entries
3264 else:
3265 self.entries = []
3266
3267 def pack(self):
3268 packed = []
3269 packed.append(struct.pack("!B", self.version))
3270 packed.append(struct.pack("!B", self.type))
3271 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3272 packed.append(struct.pack("!L", self.xid))
3273 packed.append(struct.pack("!H", self.stats_type))
3274 packed.append(struct.pack("!H", self.flags))
3275 packed.append('\x00' * 4)
3276 packed.append("".join([x.pack() for x in self.entries]))
3277 length = sum([len(x) for x in packed])
3278 packed[2] = struct.pack("!H", length)
3279 return ''.join(packed)
3280
3281 @staticmethod
3282 def unpack(buf):
3283 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3284 obj = group_desc_stats_reply()
3285 if type(buf) == loxi.generic_util.OFReader:
3286 reader = buf
3287 else:
3288 reader = loxi.generic_util.OFReader(buf)
3289 _version = reader.read('!B')[0]
3290 assert(_version == const.OFP_VERSION)
3291 _type = reader.read('!B')[0]
3292 assert(_type == const.OFPT_STATS_REPLY)
3293 _length = reader.read('!H')[0]
3294 obj.xid = reader.read('!L')[0]
3295 _stats_type = reader.read('!H')[0]
3296 assert(_stats_type == const.OFPST_GROUP_DESC)
3297 obj.flags = reader.read('!H')[0]
3298 reader.skip(4)
3299 obj.entries = common.unpack_list_group_desc_stats_entry(reader)
3300 return obj
3301
3302 def __eq__(self, other):
3303 if type(self) != type(other): return False
3304 if self.version != other.version: return False
3305 if self.type != other.type: return False
3306 if self.xid != other.xid: return False
3307 if self.flags != other.flags: return False
3308 if self.entries != other.entries: return False
3309 return True
3310
3311 def __ne__(self, other):
3312 return not self.__eq__(other)
3313
3314 def __str__(self):
3315 return self.show()
3316
3317 def show(self):
3318 import loxi.pp
3319 return loxi.pp.pp(self)
3320
3321 def pretty_print(self, q):
3322 q.text("group_desc_stats_reply {")
3323 with q.group():
3324 with q.indent(2):
3325 q.breakable()
3326 q.text("xid = ");
3327 if self.xid != None:
3328 q.text("%#x" % self.xid)
3329 else:
3330 q.text('None')
3331 q.text(","); q.breakable()
3332 q.text("flags = ");
3333 q.text("%#x" % self.flags)
3334 q.text(","); q.breakable()
3335 q.text("entries = ");
3336 q.pp(self.entries)
3337 q.breakable()
3338 q.text('}')
3339
3340class group_desc_stats_request(Message):
3341 version = const.OFP_VERSION
3342 type = const.OFPT_STATS_REQUEST
3343 stats_type = const.OFPST_GROUP_DESC
3344
3345 def __init__(self, xid=None, flags=None):
3346 self.xid = xid
3347 if flags != None:
3348 self.flags = flags
3349 else:
3350 self.flags = 0
3351
3352 def pack(self):
3353 packed = []
3354 packed.append(struct.pack("!B", self.version))
3355 packed.append(struct.pack("!B", self.type))
3356 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3357 packed.append(struct.pack("!L", self.xid))
3358 packed.append(struct.pack("!H", self.stats_type))
3359 packed.append(struct.pack("!H", self.flags))
3360 packed.append('\x00' * 4)
3361 length = sum([len(x) for x in packed])
3362 packed[2] = struct.pack("!H", length)
3363 return ''.join(packed)
3364
3365 @staticmethod
3366 def unpack(buf):
3367 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3368 obj = group_desc_stats_request()
3369 if type(buf) == loxi.generic_util.OFReader:
3370 reader = buf
3371 else:
3372 reader = loxi.generic_util.OFReader(buf)
3373 _version = reader.read('!B')[0]
3374 assert(_version == const.OFP_VERSION)
3375 _type = reader.read('!B')[0]
3376 assert(_type == const.OFPT_STATS_REQUEST)
3377 _length = reader.read('!H')[0]
3378 obj.xid = reader.read('!L')[0]
3379 _stats_type = reader.read('!H')[0]
3380 assert(_stats_type == const.OFPST_GROUP_DESC)
3381 obj.flags = reader.read('!H')[0]
3382 reader.skip(4)
3383 return obj
3384
3385 def __eq__(self, other):
3386 if type(self) != type(other): return False
3387 if self.version != other.version: return False
3388 if self.type != other.type: return False
3389 if self.xid != other.xid: return False
3390 if self.flags != other.flags: return False
3391 return True
3392
3393 def __ne__(self, other):
3394 return not self.__eq__(other)
3395
3396 def __str__(self):
3397 return self.show()
3398
3399 def show(self):
3400 import loxi.pp
3401 return loxi.pp.pp(self)
3402
3403 def pretty_print(self, q):
3404 q.text("group_desc_stats_request {")
3405 with q.group():
3406 with q.indent(2):
3407 q.breakable()
3408 q.text("xid = ");
3409 if self.xid != None:
3410 q.text("%#x" % self.xid)
3411 else:
3412 q.text('None')
3413 q.text(","); q.breakable()
3414 q.text("flags = ");
3415 q.text("%#x" % self.flags)
3416 q.breakable()
3417 q.text('}')
3418
3419class group_mod(Message):
3420 version = const.OFP_VERSION
3421 type = const.OFPT_GROUP_MOD
3422
3423 def __init__(self, xid=None, command=None, group_type=None, group_id=None, buckets=None):
3424 self.xid = xid
3425 if command != None:
3426 self.command = command
3427 else:
3428 self.command = 0
3429 if group_type != None:
3430 self.group_type = group_type
3431 else:
3432 self.group_type = 0
3433 if group_id != None:
3434 self.group_id = group_id
3435 else:
3436 self.group_id = 0
3437 if buckets != None:
3438 self.buckets = buckets
3439 else:
3440 self.buckets = []
3441
3442 def pack(self):
3443 packed = []
3444 packed.append(struct.pack("!B", self.version))
3445 packed.append(struct.pack("!B", self.type))
3446 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3447 packed.append(struct.pack("!L", self.xid))
3448 packed.append(struct.pack("!H", self.command))
3449 packed.append(struct.pack("!B", self.group_type))
3450 packed.append('\x00' * 1)
3451 packed.append(struct.pack("!L", self.group_id))
3452 packed.append("".join([x.pack() for x in self.buckets]))
3453 length = sum([len(x) for x in packed])
3454 packed[2] = struct.pack("!H", length)
3455 return ''.join(packed)
3456
3457 @staticmethod
3458 def unpack(buf):
3459 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3460 obj = group_mod()
3461 if type(buf) == loxi.generic_util.OFReader:
3462 reader = buf
3463 else:
3464 reader = loxi.generic_util.OFReader(buf)
3465 _version = reader.read('!B')[0]
3466 assert(_version == const.OFP_VERSION)
3467 _type = reader.read('!B')[0]
3468 assert(_type == const.OFPT_GROUP_MOD)
3469 _length = reader.read('!H')[0]
3470 obj.xid = reader.read('!L')[0]
3471 obj.command = reader.read('!H')[0]
3472 obj.group_type = reader.read('!B')[0]
3473 reader.skip(1)
3474 obj.group_id = reader.read('!L')[0]
3475 obj.buckets = common.unpack_list_bucket(reader)
3476 return obj
3477
3478 def __eq__(self, other):
3479 if type(self) != type(other): return False
3480 if self.version != other.version: return False
3481 if self.type != other.type: return False
3482 if self.xid != other.xid: return False
3483 if self.command != other.command: return False
3484 if self.group_type != other.group_type: return False
3485 if self.group_id != other.group_id: return False
3486 if self.buckets != other.buckets: return False
3487 return True
3488
3489 def __ne__(self, other):
3490 return not self.__eq__(other)
3491
3492 def __str__(self):
3493 return self.show()
3494
3495 def show(self):
3496 import loxi.pp
3497 return loxi.pp.pp(self)
3498
3499 def pretty_print(self, q):
3500 q.text("group_mod {")
3501 with q.group():
3502 with q.indent(2):
3503 q.breakable()
3504 q.text("xid = ");
3505 if self.xid != None:
3506 q.text("%#x" % self.xid)
3507 else:
3508 q.text('None')
3509 q.text(","); q.breakable()
3510 q.text("command = ");
3511 q.text("%#x" % self.command)
3512 q.text(","); q.breakable()
3513 q.text("group_type = ");
3514 q.text("%#x" % self.group_type)
3515 q.text(","); q.breakable()
3516 q.text("group_id = ");
3517 q.text("%#x" % self.group_id)
3518 q.text(","); q.breakable()
3519 q.text("buckets = ");
3520 q.pp(self.buckets)
3521 q.breakable()
3522 q.text('}')
3523
3524class group_stats_reply(Message):
3525 version = const.OFP_VERSION
3526 type = const.OFPT_STATS_REPLY
3527 stats_type = const.OFPST_GROUP
3528
3529 def __init__(self, xid=None, flags=None, entries=None):
3530 self.xid = xid
3531 if flags != None:
3532 self.flags = flags
3533 else:
3534 self.flags = 0
3535 if entries != None:
3536 self.entries = entries
3537 else:
3538 self.entries = []
3539
3540 def pack(self):
3541 packed = []
3542 packed.append(struct.pack("!B", self.version))
3543 packed.append(struct.pack("!B", self.type))
3544 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3545 packed.append(struct.pack("!L", self.xid))
3546 packed.append(struct.pack("!H", self.stats_type))
3547 packed.append(struct.pack("!H", self.flags))
3548 packed.append('\x00' * 4)
3549 packed.append("".join([x.pack() for x in self.entries]))
3550 length = sum([len(x) for x in packed])
3551 packed[2] = struct.pack("!H", length)
3552 return ''.join(packed)
3553
3554 @staticmethod
3555 def unpack(buf):
3556 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3557 obj = group_stats_reply()
3558 if type(buf) == loxi.generic_util.OFReader:
3559 reader = buf
3560 else:
3561 reader = loxi.generic_util.OFReader(buf)
3562 _version = reader.read('!B')[0]
3563 assert(_version == const.OFP_VERSION)
3564 _type = reader.read('!B')[0]
3565 assert(_type == const.OFPT_STATS_REPLY)
3566 _length = reader.read('!H')[0]
3567 obj.xid = reader.read('!L')[0]
3568 _stats_type = reader.read('!H')[0]
3569 assert(_stats_type == const.OFPST_GROUP)
3570 obj.flags = reader.read('!H')[0]
3571 reader.skip(4)
3572 obj.entries = common.unpack_list_group_stats_entry(reader)
3573 return obj
3574
3575 def __eq__(self, other):
3576 if type(self) != type(other): return False
3577 if self.version != other.version: return False
3578 if self.type != other.type: return False
3579 if self.xid != other.xid: return False
3580 if self.flags != other.flags: return False
3581 if self.entries != other.entries: return False
3582 return True
3583
3584 def __ne__(self, other):
3585 return not self.__eq__(other)
3586
3587 def __str__(self):
3588 return self.show()
3589
3590 def show(self):
3591 import loxi.pp
3592 return loxi.pp.pp(self)
3593
3594 def pretty_print(self, q):
3595 q.text("group_stats_reply {")
3596 with q.group():
3597 with q.indent(2):
3598 q.breakable()
3599 q.text("xid = ");
3600 if self.xid != None:
3601 q.text("%#x" % self.xid)
3602 else:
3603 q.text('None')
3604 q.text(","); q.breakable()
3605 q.text("flags = ");
3606 q.text("%#x" % self.flags)
3607 q.text(","); q.breakable()
3608 q.text("entries = ");
3609 q.pp(self.entries)
3610 q.breakable()
3611 q.text('}')
3612
3613class group_stats_request(Message):
3614 version = const.OFP_VERSION
3615 type = const.OFPT_STATS_REQUEST
3616 stats_type = const.OFPST_GROUP
3617
3618 def __init__(self, xid=None, flags=None, group_id=None):
3619 self.xid = xid
3620 if flags != None:
3621 self.flags = flags
3622 else:
3623 self.flags = 0
3624 if group_id != None:
3625 self.group_id = group_id
3626 else:
3627 self.group_id = 0
3628
3629 def pack(self):
3630 packed = []
3631 packed.append(struct.pack("!B", self.version))
3632 packed.append(struct.pack("!B", self.type))
3633 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3634 packed.append(struct.pack("!L", self.xid))
3635 packed.append(struct.pack("!H", self.stats_type))
3636 packed.append(struct.pack("!H", self.flags))
3637 packed.append('\x00' * 4)
3638 packed.append(struct.pack("!L", self.group_id))
3639 packed.append('\x00' * 4)
3640 length = sum([len(x) for x in packed])
3641 packed[2] = struct.pack("!H", length)
3642 return ''.join(packed)
3643
3644 @staticmethod
3645 def unpack(buf):
3646 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3647 obj = group_stats_request()
3648 if type(buf) == loxi.generic_util.OFReader:
3649 reader = buf
3650 else:
3651 reader = loxi.generic_util.OFReader(buf)
3652 _version = reader.read('!B')[0]
3653 assert(_version == const.OFP_VERSION)
3654 _type = reader.read('!B')[0]
3655 assert(_type == const.OFPT_STATS_REQUEST)
3656 _length = reader.read('!H')[0]
3657 obj.xid = reader.read('!L')[0]
3658 _stats_type = reader.read('!H')[0]
3659 assert(_stats_type == const.OFPST_GROUP)
3660 obj.flags = reader.read('!H')[0]
3661 reader.skip(4)
3662 obj.group_id = reader.read('!L')[0]
3663 reader.skip(4)
3664 return obj
3665
3666 def __eq__(self, other):
3667 if type(self) != type(other): return False
3668 if self.version != other.version: return False
3669 if self.type != other.type: return False
3670 if self.xid != other.xid: return False
3671 if self.flags != other.flags: return False
3672 if self.group_id != other.group_id: 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_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.text(","); q.breakable()
3699 q.text("group_id = ");
3700 q.text("%#x" % self.group_id)
3701 q.breakable()
3702 q.text('}')
3703
3704class hello(Message):
3705 version = const.OFP_VERSION
3706 type = const.OFPT_HELLO
3707
3708 def __init__(self, xid=None):
3709 self.xid = xid
3710
3711 def pack(self):
3712 packed = []
3713 packed.append(struct.pack("!B", self.version))
3714 packed.append(struct.pack("!B", self.type))
3715 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3716 packed.append(struct.pack("!L", self.xid))
3717 length = sum([len(x) for x in packed])
3718 packed[2] = struct.pack("!H", length)
3719 return ''.join(packed)
3720
3721 @staticmethod
3722 def unpack(buf):
3723 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3724 obj = hello()
3725 if type(buf) == loxi.generic_util.OFReader:
3726 reader = buf
3727 else:
3728 reader = loxi.generic_util.OFReader(buf)
3729 _version = reader.read('!B')[0]
3730 assert(_version == const.OFP_VERSION)
3731 _type = reader.read('!B')[0]
3732 assert(_type == const.OFPT_HELLO)
3733 _length = reader.read('!H')[0]
3734 obj.xid = reader.read('!L')[0]
3735 return obj
3736
3737 def __eq__(self, other):
3738 if type(self) != type(other): return False
3739 if self.version != other.version: return False
3740 if self.type != other.type: return False
3741 if self.xid != other.xid: return False
3742 return True
3743
3744 def __ne__(self, other):
3745 return not self.__eq__(other)
3746
3747 def __str__(self):
3748 return self.show()
3749
3750 def show(self):
3751 import loxi.pp
3752 return loxi.pp.pp(self)
3753
3754 def pretty_print(self, q):
3755 q.text("hello {")
3756 with q.group():
3757 with q.indent(2):
3758 q.breakable()
3759 q.text("xid = ");
3760 if self.xid != None:
3761 q.text("%#x" % self.xid)
3762 else:
3763 q.text('None')
3764 q.breakable()
3765 q.text('}')
3766
3767class packet_in(Message):
3768 version = const.OFP_VERSION
3769 type = const.OFPT_PACKET_IN
3770
3771 def __init__(self, xid=None, buffer_id=None, in_port=None, in_phy_port=None, total_len=None, reason=None, table_id=None, data=None):
3772 self.xid = xid
3773 if buffer_id != None:
3774 self.buffer_id = buffer_id
3775 else:
3776 self.buffer_id = 0
3777 if in_port != None:
3778 self.in_port = in_port
3779 else:
3780 self.in_port = 0
3781 if in_phy_port != None:
3782 self.in_phy_port = in_phy_port
3783 else:
3784 self.in_phy_port = 0
3785 if total_len != None:
3786 self.total_len = total_len
3787 else:
3788 self.total_len = 0
3789 if reason != None:
3790 self.reason = reason
3791 else:
3792 self.reason = 0
3793 if table_id != None:
3794 self.table_id = table_id
3795 else:
3796 self.table_id = 0
3797 if data != None:
3798 self.data = data
3799 else:
3800 self.data = ""
3801
3802 def pack(self):
3803 packed = []
3804 packed.append(struct.pack("!B", self.version))
3805 packed.append(struct.pack("!B", self.type))
3806 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3807 packed.append(struct.pack("!L", self.xid))
3808 packed.append(struct.pack("!L", self.buffer_id))
3809 packed.append(struct.pack("!L", self.in_port))
3810 packed.append(struct.pack("!L", self.in_phy_port))
3811 packed.append(struct.pack("!H", self.total_len))
3812 packed.append(struct.pack("!B", self.reason))
3813 packed.append(struct.pack("!B", self.table_id))
3814 packed.append(self.data)
3815 length = sum([len(x) for x in packed])
3816 packed[2] = struct.pack("!H", length)
3817 return ''.join(packed)
3818
3819 @staticmethod
3820 def unpack(buf):
3821 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3822 obj = packet_in()
3823 if type(buf) == loxi.generic_util.OFReader:
3824 reader = buf
3825 else:
3826 reader = loxi.generic_util.OFReader(buf)
3827 _version = reader.read('!B')[0]
3828 assert(_version == const.OFP_VERSION)
3829 _type = reader.read('!B')[0]
3830 assert(_type == const.OFPT_PACKET_IN)
3831 _length = reader.read('!H')[0]
3832 obj.xid = reader.read('!L')[0]
3833 obj.buffer_id = reader.read('!L')[0]
3834 obj.in_port = reader.read('!L')[0]
3835 obj.in_phy_port = reader.read('!L')[0]
3836 obj.total_len = reader.read('!H')[0]
3837 obj.reason = reader.read('!B')[0]
3838 obj.table_id = reader.read('!B')[0]
3839 obj.data = str(reader.read_all())
3840 return obj
3841
3842 def __eq__(self, other):
3843 if type(self) != type(other): return False
3844 if self.version != other.version: return False
3845 if self.type != other.type: return False
3846 if self.xid != other.xid: return False
3847 if self.buffer_id != other.buffer_id: return False
3848 if self.in_port != other.in_port: return False
3849 if self.in_phy_port != other.in_phy_port: return False
3850 if self.total_len != other.total_len: return False
3851 if self.reason != other.reason: return False
3852 if self.table_id != other.table_id: return False
3853 if self.data != other.data: return False
3854 return True
3855
3856 def __ne__(self, other):
3857 return not self.__eq__(other)
3858
3859 def __str__(self):
3860 return self.show()
3861
3862 def show(self):
3863 import loxi.pp
3864 return loxi.pp.pp(self)
3865
3866 def pretty_print(self, q):
3867 q.text("packet_in {")
3868 with q.group():
3869 with q.indent(2):
3870 q.breakable()
3871 q.text("xid = ");
3872 if self.xid != None:
3873 q.text("%#x" % self.xid)
3874 else:
3875 q.text('None')
3876 q.text(","); q.breakable()
3877 q.text("buffer_id = ");
3878 q.text("%#x" % self.buffer_id)
3879 q.text(","); q.breakable()
3880 q.text("in_port = ");
3881 q.text(util.pretty_port(self.in_port))
3882 q.text(","); q.breakable()
3883 q.text("in_phy_port = ");
3884 q.text(util.pretty_port(self.in_phy_port))
3885 q.text(","); q.breakable()
3886 q.text("total_len = ");
3887 q.text("%#x" % self.total_len)
3888 q.text(","); q.breakable()
3889 q.text("reason = ");
3890 q.text("%#x" % self.reason)
3891 q.text(","); q.breakable()
3892 q.text("table_id = ");
3893 q.text("%#x" % self.table_id)
3894 q.text(","); q.breakable()
3895 q.text("data = ");
3896 q.pp(self.data)
3897 q.breakable()
3898 q.text('}')
3899
3900class packet_out(Message):
3901 version = const.OFP_VERSION
3902 type = const.OFPT_PACKET_OUT
3903
3904 def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
3905 self.xid = xid
3906 if buffer_id != None:
3907 self.buffer_id = buffer_id
3908 else:
3909 self.buffer_id = 0
3910 if in_port != None:
3911 self.in_port = in_port
3912 else:
3913 self.in_port = 0
3914 if actions != None:
3915 self.actions = actions
3916 else:
3917 self.actions = []
3918 if data != None:
3919 self.data = data
3920 else:
3921 self.data = ""
3922
3923 def pack(self):
3924 packed = []
3925 packed.append(struct.pack("!B", self.version))
3926 packed.append(struct.pack("!B", self.type))
3927 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3928 packed.append(struct.pack("!L", self.xid))
3929 packed.append(struct.pack("!L", self.buffer_id))
3930 packed.append(struct.pack("!L", self.in_port))
3931 packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
3932 packed.append('\x00' * 6)
3933 packed.append("".join([x.pack() for x in self.actions]))
3934 packed[6] = struct.pack("!H", len(packed[-1]))
3935 packed.append(self.data)
3936 length = sum([len(x) for x in packed])
3937 packed[2] = struct.pack("!H", length)
3938 return ''.join(packed)
3939
3940 @staticmethod
3941 def unpack(buf):
3942 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3943 obj = packet_out()
3944 if type(buf) == loxi.generic_util.OFReader:
3945 reader = buf
3946 else:
3947 reader = loxi.generic_util.OFReader(buf)
3948 _version = reader.read('!B')[0]
3949 assert(_version == const.OFP_VERSION)
3950 _type = reader.read('!B')[0]
3951 assert(_type == const.OFPT_PACKET_OUT)
3952 _length = reader.read('!H')[0]
3953 obj.xid = reader.read('!L')[0]
3954 obj.buffer_id = reader.read('!L')[0]
3955 obj.in_port = reader.read('!L')[0]
3956 _actions_len = reader.read('!H')[0]
3957 reader.skip(6)
3958 obj.actions = action.unpack_list(reader.slice(_actions_len))
3959 obj.data = str(reader.read_all())
3960 return obj
3961
3962 def __eq__(self, other):
3963 if type(self) != type(other): return False
3964 if self.version != other.version: return False
3965 if self.type != other.type: return False
3966 if self.xid != other.xid: return False
3967 if self.buffer_id != other.buffer_id: return False
3968 if self.in_port != other.in_port: return False
3969 if self.actions != other.actions: return False
3970 if self.data != other.data: return False
3971 return True
3972
3973 def __ne__(self, other):
3974 return not self.__eq__(other)
3975
3976 def __str__(self):
3977 return self.show()
3978
3979 def show(self):
3980 import loxi.pp
3981 return loxi.pp.pp(self)
3982
3983 def pretty_print(self, q):
3984 q.text("packet_out {")
3985 with q.group():
3986 with q.indent(2):
3987 q.breakable()
3988 q.text("xid = ");
3989 if self.xid != None:
3990 q.text("%#x" % self.xid)
3991 else:
3992 q.text('None')
3993 q.text(","); q.breakable()
3994 q.text("buffer_id = ");
3995 q.text("%#x" % self.buffer_id)
3996 q.text(","); q.breakable()
3997 q.text("in_port = ");
3998 q.text(util.pretty_port(self.in_port))
3999 q.text(","); q.breakable()
4000 q.text("actions = ");
4001 q.pp(self.actions)
4002 q.text(","); q.breakable()
4003 q.text("data = ");
4004 q.pp(self.data)
4005 q.breakable()
4006 q.text('}')
4007
4008class port_mod(Message):
4009 version = const.OFP_VERSION
4010 type = const.OFPT_PORT_MOD
4011
4012 def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None):
4013 self.xid = xid
4014 if port_no != None:
4015 self.port_no = port_no
4016 else:
4017 self.port_no = 0
4018 if hw_addr != None:
4019 self.hw_addr = hw_addr
4020 else:
4021 self.hw_addr = [0,0,0,0,0,0]
4022 if config != None:
4023 self.config = config
4024 else:
4025 self.config = 0
4026 if mask != None:
4027 self.mask = mask
4028 else:
4029 self.mask = 0
4030 if advertise != None:
4031 self.advertise = advertise
4032 else:
4033 self.advertise = 0
4034
4035 def pack(self):
4036 packed = []
4037 packed.append(struct.pack("!B", self.version))
4038 packed.append(struct.pack("!B", self.type))
4039 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4040 packed.append(struct.pack("!L", self.xid))
4041 packed.append(struct.pack("!L", self.port_no))
4042 packed.append('\x00' * 4)
4043 packed.append(struct.pack("!6B", *self.hw_addr))
4044 packed.append('\x00' * 2)
4045 packed.append(struct.pack("!L", self.config))
4046 packed.append(struct.pack("!L", self.mask))
4047 packed.append(struct.pack("!L", self.advertise))
4048 packed.append('\x00' * 4)
4049 length = sum([len(x) for x in packed])
4050 packed[2] = struct.pack("!H", length)
4051 return ''.join(packed)
4052
4053 @staticmethod
4054 def unpack(buf):
4055 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4056 obj = port_mod()
4057 if type(buf) == loxi.generic_util.OFReader:
4058 reader = buf
4059 else:
4060 reader = loxi.generic_util.OFReader(buf)
4061 _version = reader.read('!B')[0]
4062 assert(_version == const.OFP_VERSION)
4063 _type = reader.read('!B')[0]
4064 assert(_type == const.OFPT_PORT_MOD)
4065 _length = reader.read('!H')[0]
4066 obj.xid = reader.read('!L')[0]
4067 obj.port_no = reader.read('!L')[0]
4068 reader.skip(4)
4069 obj.hw_addr = list(reader.read('!6B'))
4070 reader.skip(2)
4071 obj.config = reader.read('!L')[0]
4072 obj.mask = reader.read('!L')[0]
4073 obj.advertise = reader.read('!L')[0]
4074 reader.skip(4)
4075 return obj
4076
4077 def __eq__(self, other):
4078 if type(self) != type(other): return False
4079 if self.version != other.version: return False
4080 if self.type != other.type: return False
4081 if self.xid != other.xid: return False
4082 if self.port_no != other.port_no: return False
4083 if self.hw_addr != other.hw_addr: return False
4084 if self.config != other.config: return False
4085 if self.mask != other.mask: return False
4086 if self.advertise != other.advertise: return False
4087 return True
4088
4089 def __ne__(self, other):
4090 return not self.__eq__(other)
4091
4092 def __str__(self):
4093 return self.show()
4094
4095 def show(self):
4096 import loxi.pp
4097 return loxi.pp.pp(self)
4098
4099 def pretty_print(self, q):
4100 q.text("port_mod {")
4101 with q.group():
4102 with q.indent(2):
4103 q.breakable()
4104 q.text("xid = ");
4105 if self.xid != None:
4106 q.text("%#x" % self.xid)
4107 else:
4108 q.text('None')
4109 q.text(","); q.breakable()
4110 q.text("port_no = ");
4111 q.text(util.pretty_port(self.port_no))
4112 q.text(","); q.breakable()
4113 q.text("hw_addr = ");
4114 q.text(util.pretty_mac(self.hw_addr))
4115 q.text(","); q.breakable()
4116 q.text("config = ");
4117 q.text("%#x" % self.config)
4118 q.text(","); q.breakable()
4119 q.text("mask = ");
4120 q.text("%#x" % self.mask)
4121 q.text(","); q.breakable()
4122 q.text("advertise = ");
4123 q.text("%#x" % self.advertise)
4124 q.breakable()
4125 q.text('}')
4126
4127class port_stats_reply(Message):
4128 version = const.OFP_VERSION
4129 type = const.OFPT_STATS_REPLY
4130 stats_type = const.OFPST_PORT
4131
4132 def __init__(self, xid=None, flags=None, entries=None):
4133 self.xid = xid
4134 if flags != None:
4135 self.flags = flags
4136 else:
4137 self.flags = 0
4138 if entries != None:
4139 self.entries = entries
4140 else:
4141 self.entries = []
4142
4143 def pack(self):
4144 packed = []
4145 packed.append(struct.pack("!B", self.version))
4146 packed.append(struct.pack("!B", self.type))
4147 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4148 packed.append(struct.pack("!L", self.xid))
4149 packed.append(struct.pack("!H", self.stats_type))
4150 packed.append(struct.pack("!H", self.flags))
4151 packed.append('\x00' * 4)
4152 packed.append("".join([x.pack() for x in self.entries]))
4153 length = sum([len(x) for x in packed])
4154 packed[2] = struct.pack("!H", length)
4155 return ''.join(packed)
4156
4157 @staticmethod
4158 def unpack(buf):
4159 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4160 obj = port_stats_reply()
4161 if type(buf) == loxi.generic_util.OFReader:
4162 reader = buf
4163 else:
4164 reader = loxi.generic_util.OFReader(buf)
4165 _version = reader.read('!B')[0]
4166 assert(_version == const.OFP_VERSION)
4167 _type = reader.read('!B')[0]
4168 assert(_type == const.OFPT_STATS_REPLY)
4169 _length = reader.read('!H')[0]
4170 obj.xid = reader.read('!L')[0]
4171 _stats_type = reader.read('!H')[0]
4172 assert(_stats_type == const.OFPST_PORT)
4173 obj.flags = reader.read('!H')[0]
4174 reader.skip(4)
4175 obj.entries = loxi.generic_util.unpack_list(reader, common.port_stats_entry.unpack)
4176 return obj
4177
4178 def __eq__(self, other):
4179 if type(self) != type(other): return False
4180 if self.version != other.version: return False
4181 if self.type != other.type: return False
4182 if self.xid != other.xid: return False
4183 if self.flags != other.flags: return False
4184 if self.entries != other.entries: return False
4185 return True
4186
4187 def __ne__(self, other):
4188 return not self.__eq__(other)
4189
4190 def __str__(self):
4191 return self.show()
4192
4193 def show(self):
4194 import loxi.pp
4195 return loxi.pp.pp(self)
4196
4197 def pretty_print(self, q):
4198 q.text("port_stats_reply {")
4199 with q.group():
4200 with q.indent(2):
4201 q.breakable()
4202 q.text("xid = ");
4203 if self.xid != None:
4204 q.text("%#x" % self.xid)
4205 else:
4206 q.text('None')
4207 q.text(","); q.breakable()
4208 q.text("flags = ");
4209 q.text("%#x" % self.flags)
4210 q.text(","); q.breakable()
4211 q.text("entries = ");
4212 q.pp(self.entries)
4213 q.breakable()
4214 q.text('}')
4215
4216class port_stats_request(Message):
4217 version = const.OFP_VERSION
4218 type = const.OFPT_STATS_REQUEST
4219 stats_type = const.OFPST_PORT
4220
4221 def __init__(self, xid=None, flags=None, port_no=None):
4222 self.xid = xid
4223 if flags != None:
4224 self.flags = flags
4225 else:
4226 self.flags = 0
4227 if port_no != None:
4228 self.port_no = port_no
4229 else:
4230 self.port_no = 0
4231
4232 def pack(self):
4233 packed = []
4234 packed.append(struct.pack("!B", self.version))
4235 packed.append(struct.pack("!B", self.type))
4236 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4237 packed.append(struct.pack("!L", self.xid))
4238 packed.append(struct.pack("!H", self.stats_type))
4239 packed.append(struct.pack("!H", self.flags))
4240 packed.append('\x00' * 4)
4241 packed.append(struct.pack("!L", self.port_no))
4242 packed.append('\x00' * 4)
4243 length = sum([len(x) for x in packed])
4244 packed[2] = struct.pack("!H", length)
4245 return ''.join(packed)
4246
4247 @staticmethod
4248 def unpack(buf):
4249 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4250 obj = port_stats_request()
4251 if type(buf) == loxi.generic_util.OFReader:
4252 reader = buf
4253 else:
4254 reader = loxi.generic_util.OFReader(buf)
4255 _version = reader.read('!B')[0]
4256 assert(_version == const.OFP_VERSION)
4257 _type = reader.read('!B')[0]
4258 assert(_type == const.OFPT_STATS_REQUEST)
4259 _length = reader.read('!H')[0]
4260 obj.xid = reader.read('!L')[0]
4261 _stats_type = reader.read('!H')[0]
4262 assert(_stats_type == const.OFPST_PORT)
4263 obj.flags = reader.read('!H')[0]
4264 reader.skip(4)
4265 obj.port_no = reader.read('!L')[0]
4266 reader.skip(4)
4267 return obj
4268
4269 def __eq__(self, other):
4270 if type(self) != type(other): return False
4271 if self.version != other.version: return False
4272 if self.type != other.type: return False
4273 if self.xid != other.xid: return False
4274 if self.flags != other.flags: return False
4275 if self.port_no != other.port_no: return False
4276 return True
4277
4278 def __ne__(self, other):
4279 return not self.__eq__(other)
4280
4281 def __str__(self):
4282 return self.show()
4283
4284 def show(self):
4285 import loxi.pp
4286 return loxi.pp.pp(self)
4287
4288 def pretty_print(self, q):
4289 q.text("port_stats_request {")
4290 with q.group():
4291 with q.indent(2):
4292 q.breakable()
4293 q.text("xid = ");
4294 if self.xid != None:
4295 q.text("%#x" % self.xid)
4296 else:
4297 q.text('None')
4298 q.text(","); q.breakable()
4299 q.text("flags = ");
4300 q.text("%#x" % self.flags)
4301 q.text(","); q.breakable()
4302 q.text("port_no = ");
4303 q.text(util.pretty_port(self.port_no))
4304 q.breakable()
4305 q.text('}')
4306
4307class port_status(Message):
4308 version = const.OFP_VERSION
4309 type = const.OFPT_PORT_STATUS
4310
4311 def __init__(self, xid=None, reason=None, desc=None):
4312 self.xid = xid
4313 if reason != None:
4314 self.reason = reason
4315 else:
4316 self.reason = 0
4317 if desc != None:
4318 self.desc = desc
4319 else:
4320 self.desc = common.port_desc()
4321
4322 def pack(self):
4323 packed = []
4324 packed.append(struct.pack("!B", self.version))
4325 packed.append(struct.pack("!B", self.type))
4326 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4327 packed.append(struct.pack("!L", self.xid))
4328 packed.append(struct.pack("!B", self.reason))
4329 packed.append('\x00' * 7)
4330 packed.append(self.desc.pack())
4331 length = sum([len(x) for x in packed])
4332 packed[2] = struct.pack("!H", length)
4333 return ''.join(packed)
4334
4335 @staticmethod
4336 def unpack(buf):
4337 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4338 obj = port_status()
4339 if type(buf) == loxi.generic_util.OFReader:
4340 reader = buf
4341 else:
4342 reader = loxi.generic_util.OFReader(buf)
4343 _version = reader.read('!B')[0]
4344 assert(_version == const.OFP_VERSION)
4345 _type = reader.read('!B')[0]
4346 assert(_type == const.OFPT_PORT_STATUS)
4347 _length = reader.read('!H')[0]
4348 obj.xid = reader.read('!L')[0]
4349 obj.reason = reader.read('!B')[0]
4350 reader.skip(7)
4351 obj.desc = common.port_desc.unpack(reader)
4352 return obj
4353
4354 def __eq__(self, other):
4355 if type(self) != type(other): return False
4356 if self.version != other.version: return False
4357 if self.type != other.type: return False
4358 if self.xid != other.xid: return False
4359 if self.reason != other.reason: return False
4360 if self.desc != other.desc: 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_status {")
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("reason = ");
4385 q.text("%#x" % self.reason)
4386 q.text(","); q.breakable()
4387 q.text("desc = ");
4388 q.pp(self.desc)
4389 q.breakable()
4390 q.text('}')
4391
4392class queue_get_config_reply(Message):
4393 version = const.OFP_VERSION
4394 type = const.OFPT_QUEUE_GET_CONFIG_REPLY
4395
4396 def __init__(self, xid=None, port=None, queues=None):
4397 self.xid = xid
4398 if port != None:
4399 self.port = port
4400 else:
4401 self.port = 0
4402 if queues != None:
4403 self.queues = queues
4404 else:
4405 self.queues = []
4406
4407 def pack(self):
4408 packed = []
4409 packed.append(struct.pack("!B", self.version))
4410 packed.append(struct.pack("!B", self.type))
4411 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4412 packed.append(struct.pack("!L", self.xid))
4413 packed.append(struct.pack("!L", self.port))
4414 packed.append('\x00' * 4)
4415 packed.append("".join([x.pack() for x in self.queues]))
4416 length = sum([len(x) for x in packed])
4417 packed[2] = struct.pack("!H", length)
4418 return ''.join(packed)
4419
4420 @staticmethod
4421 def unpack(buf):
4422 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4423 obj = queue_get_config_reply()
4424 if type(buf) == loxi.generic_util.OFReader:
4425 reader = buf
4426 else:
4427 reader = loxi.generic_util.OFReader(buf)
4428 _version = reader.read('!B')[0]
4429 assert(_version == const.OFP_VERSION)
4430 _type = reader.read('!B')[0]
4431 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REPLY)
4432 _length = reader.read('!H')[0]
4433 obj.xid = reader.read('!L')[0]
4434 obj.port = reader.read('!L')[0]
4435 reader.skip(4)
4436 obj.queues = common.unpack_list_packet_queue(reader)
4437 return obj
4438
4439 def __eq__(self, other):
4440 if type(self) != type(other): return False
4441 if self.version != other.version: return False
4442 if self.type != other.type: return False
4443 if self.xid != other.xid: return False
4444 if self.port != other.port: return False
4445 if self.queues != other.queues: return False
4446 return True
4447
4448 def __ne__(self, other):
4449 return not self.__eq__(other)
4450
4451 def __str__(self):
4452 return self.show()
4453
4454 def show(self):
4455 import loxi.pp
4456 return loxi.pp.pp(self)
4457
4458 def pretty_print(self, q):
4459 q.text("queue_get_config_reply {")
4460 with q.group():
4461 with q.indent(2):
4462 q.breakable()
4463 q.text("xid = ");
4464 if self.xid != None:
4465 q.text("%#x" % self.xid)
4466 else:
4467 q.text('None')
4468 q.text(","); q.breakable()
4469 q.text("port = ");
4470 q.text(util.pretty_port(self.port))
4471 q.text(","); q.breakable()
4472 q.text("queues = ");
4473 q.pp(self.queues)
4474 q.breakable()
4475 q.text('}')
4476
4477class queue_get_config_request(Message):
4478 version = const.OFP_VERSION
4479 type = const.OFPT_QUEUE_GET_CONFIG_REQUEST
4480
4481 def __init__(self, xid=None, port=None):
4482 self.xid = xid
4483 if port != None:
4484 self.port = port
4485 else:
4486 self.port = 0
4487
4488 def pack(self):
4489 packed = []
4490 packed.append(struct.pack("!B", self.version))
4491 packed.append(struct.pack("!B", self.type))
4492 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4493 packed.append(struct.pack("!L", self.xid))
4494 packed.append(struct.pack("!L", self.port))
4495 packed.append('\x00' * 4)
4496 length = sum([len(x) for x in packed])
4497 packed[2] = struct.pack("!H", length)
4498 return ''.join(packed)
4499
4500 @staticmethod
4501 def unpack(buf):
4502 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4503 obj = queue_get_config_request()
4504 if type(buf) == loxi.generic_util.OFReader:
4505 reader = buf
4506 else:
4507 reader = loxi.generic_util.OFReader(buf)
4508 _version = reader.read('!B')[0]
4509 assert(_version == const.OFP_VERSION)
4510 _type = reader.read('!B')[0]
4511 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REQUEST)
4512 _length = reader.read('!H')[0]
4513 obj.xid = reader.read('!L')[0]
4514 obj.port = reader.read('!L')[0]
4515 reader.skip(4)
4516 return obj
4517
4518 def __eq__(self, other):
4519 if type(self) != type(other): return False
4520 if self.version != other.version: return False
4521 if self.type != other.type: return False
4522 if self.xid != other.xid: return False
4523 if self.port != other.port: return False
4524 return True
4525
4526 def __ne__(self, other):
4527 return not self.__eq__(other)
4528
4529 def __str__(self):
4530 return self.show()
4531
4532 def show(self):
4533 import loxi.pp
4534 return loxi.pp.pp(self)
4535
4536 def pretty_print(self, q):
4537 q.text("queue_get_config_request {")
4538 with q.group():
4539 with q.indent(2):
4540 q.breakable()
4541 q.text("xid = ");
4542 if self.xid != None:
4543 q.text("%#x" % self.xid)
4544 else:
4545 q.text('None')
4546 q.text(","); q.breakable()
4547 q.text("port = ");
4548 q.text(util.pretty_port(self.port))
4549 q.breakable()
4550 q.text('}')
4551
4552class queue_stats_reply(Message):
4553 version = const.OFP_VERSION
4554 type = const.OFPT_STATS_REPLY
4555 stats_type = const.OFPST_QUEUE
4556
4557 def __init__(self, xid=None, flags=None, entries=None):
4558 self.xid = xid
4559 if flags != None:
4560 self.flags = flags
4561 else:
4562 self.flags = 0
4563 if entries != None:
4564 self.entries = entries
4565 else:
4566 self.entries = []
4567
4568 def pack(self):
4569 packed = []
4570 packed.append(struct.pack("!B", self.version))
4571 packed.append(struct.pack("!B", self.type))
4572 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4573 packed.append(struct.pack("!L", self.xid))
4574 packed.append(struct.pack("!H", self.stats_type))
4575 packed.append(struct.pack("!H", self.flags))
4576 packed.append('\x00' * 4)
4577 packed.append("".join([x.pack() for x in self.entries]))
4578 length = sum([len(x) for x in packed])
4579 packed[2] = struct.pack("!H", length)
4580 return ''.join(packed)
4581
4582 @staticmethod
4583 def unpack(buf):
4584 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4585 obj = queue_stats_reply()
4586 if type(buf) == loxi.generic_util.OFReader:
4587 reader = buf
4588 else:
4589 reader = loxi.generic_util.OFReader(buf)
4590 _version = reader.read('!B')[0]
4591 assert(_version == const.OFP_VERSION)
4592 _type = reader.read('!B')[0]
4593 assert(_type == const.OFPT_STATS_REPLY)
4594 _length = reader.read('!H')[0]
4595 obj.xid = reader.read('!L')[0]
4596 _stats_type = reader.read('!H')[0]
4597 assert(_stats_type == const.OFPST_QUEUE)
4598 obj.flags = reader.read('!H')[0]
4599 reader.skip(4)
4600 obj.entries = loxi.generic_util.unpack_list(reader, common.queue_stats_entry.unpack)
4601 return obj
4602
4603 def __eq__(self, other):
4604 if type(self) != type(other): return False
4605 if self.version != other.version: return False
4606 if self.type != other.type: return False
4607 if self.xid != other.xid: return False
4608 if self.flags != other.flags: return False
4609 if self.entries != other.entries: return False
4610 return True
4611
4612 def __ne__(self, other):
4613 return not self.__eq__(other)
4614
4615 def __str__(self):
4616 return self.show()
4617
4618 def show(self):
4619 import loxi.pp
4620 return loxi.pp.pp(self)
4621
4622 def pretty_print(self, q):
4623 q.text("queue_stats_reply {")
4624 with q.group():
4625 with q.indent(2):
4626 q.breakable()
4627 q.text("xid = ");
4628 if self.xid != None:
4629 q.text("%#x" % self.xid)
4630 else:
4631 q.text('None')
4632 q.text(","); q.breakable()
4633 q.text("flags = ");
4634 q.text("%#x" % self.flags)
4635 q.text(","); q.breakable()
4636 q.text("entries = ");
4637 q.pp(self.entries)
4638 q.breakable()
4639 q.text('}')
4640
4641class queue_stats_request(Message):
4642 version = const.OFP_VERSION
4643 type = const.OFPT_STATS_REQUEST
4644 stats_type = const.OFPST_QUEUE
4645
4646 def __init__(self, xid=None, flags=None, port_no=None, queue_id=None):
4647 self.xid = xid
4648 if flags != None:
4649 self.flags = flags
4650 else:
4651 self.flags = 0
4652 if port_no != None:
4653 self.port_no = port_no
4654 else:
4655 self.port_no = 0
4656 if queue_id != None:
4657 self.queue_id = queue_id
4658 else:
4659 self.queue_id = 0
4660
4661 def pack(self):
4662 packed = []
4663 packed.append(struct.pack("!B", self.version))
4664 packed.append(struct.pack("!B", self.type))
4665 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4666 packed.append(struct.pack("!L", self.xid))
4667 packed.append(struct.pack("!H", self.stats_type))
4668 packed.append(struct.pack("!H", self.flags))
4669 packed.append('\x00' * 4)
4670 packed.append(struct.pack("!L", self.port_no))
4671 packed.append(struct.pack("!L", self.queue_id))
4672 length = sum([len(x) for x in packed])
4673 packed[2] = struct.pack("!H", length)
4674 return ''.join(packed)
4675
4676 @staticmethod
4677 def unpack(buf):
4678 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4679 obj = queue_stats_request()
4680 if type(buf) == loxi.generic_util.OFReader:
4681 reader = buf
4682 else:
4683 reader = loxi.generic_util.OFReader(buf)
4684 _version = reader.read('!B')[0]
4685 assert(_version == const.OFP_VERSION)
4686 _type = reader.read('!B')[0]
4687 assert(_type == const.OFPT_STATS_REQUEST)
4688 _length = reader.read('!H')[0]
4689 obj.xid = reader.read('!L')[0]
4690 _stats_type = reader.read('!H')[0]
4691 assert(_stats_type == const.OFPST_QUEUE)
4692 obj.flags = reader.read('!H')[0]
4693 reader.skip(4)
4694 obj.port_no = reader.read('!L')[0]
4695 obj.queue_id = reader.read('!L')[0]
4696 return obj
4697
4698 def __eq__(self, other):
4699 if type(self) != type(other): return False
4700 if self.version != other.version: return False
4701 if self.type != other.type: return False
4702 if self.xid != other.xid: return False
4703 if self.flags != other.flags: return False
4704 if self.port_no != other.port_no: return False
4705 if self.queue_id != other.queue_id: return False
4706 return True
4707
4708 def __ne__(self, other):
4709 return not self.__eq__(other)
4710
4711 def __str__(self):
4712 return self.show()
4713
4714 def show(self):
4715 import loxi.pp
4716 return loxi.pp.pp(self)
4717
4718 def pretty_print(self, q):
4719 q.text("queue_stats_request {")
4720 with q.group():
4721 with q.indent(2):
4722 q.breakable()
4723 q.text("xid = ");
4724 if self.xid != None:
4725 q.text("%#x" % self.xid)
4726 else:
4727 q.text('None')
4728 q.text(","); q.breakable()
4729 q.text("flags = ");
4730 q.text("%#x" % self.flags)
4731 q.text(","); q.breakable()
4732 q.text("port_no = ");
4733 q.text(util.pretty_port(self.port_no))
4734 q.text(","); q.breakable()
4735 q.text("queue_id = ");
4736 q.text("%#x" % self.queue_id)
4737 q.breakable()
4738 q.text('}')
4739
4740class set_config(Message):
4741 version = const.OFP_VERSION
4742 type = const.OFPT_SET_CONFIG
4743
4744 def __init__(self, xid=None, flags=None, miss_send_len=None):
4745 self.xid = xid
4746 if flags != None:
4747 self.flags = flags
4748 else:
4749 self.flags = 0
4750 if miss_send_len != None:
4751 self.miss_send_len = miss_send_len
4752 else:
4753 self.miss_send_len = 0
4754
4755 def pack(self):
4756 packed = []
4757 packed.append(struct.pack("!B", self.version))
4758 packed.append(struct.pack("!B", self.type))
4759 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4760 packed.append(struct.pack("!L", self.xid))
4761 packed.append(struct.pack("!H", self.flags))
4762 packed.append(struct.pack("!H", self.miss_send_len))
4763 length = sum([len(x) for x in packed])
4764 packed[2] = struct.pack("!H", length)
4765 return ''.join(packed)
4766
4767 @staticmethod
4768 def unpack(buf):
4769 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4770 obj = set_config()
4771 if type(buf) == loxi.generic_util.OFReader:
4772 reader = buf
4773 else:
4774 reader = loxi.generic_util.OFReader(buf)
4775 _version = reader.read('!B')[0]
4776 assert(_version == const.OFP_VERSION)
4777 _type = reader.read('!B')[0]
4778 assert(_type == const.OFPT_SET_CONFIG)
4779 _length = reader.read('!H')[0]
4780 obj.xid = reader.read('!L')[0]
4781 obj.flags = reader.read('!H')[0]
4782 obj.miss_send_len = reader.read('!H')[0]
4783 return obj
4784
4785 def __eq__(self, other):
4786 if type(self) != type(other): return False
4787 if self.version != other.version: return False
4788 if self.type != other.type: return False
4789 if self.xid != other.xid: return False
4790 if self.flags != other.flags: return False
4791 if self.miss_send_len != other.miss_send_len: return False
4792 return True
4793
4794 def __ne__(self, other):
4795 return not self.__eq__(other)
4796
4797 def __str__(self):
4798 return self.show()
4799
4800 def show(self):
4801 import loxi.pp
4802 return loxi.pp.pp(self)
4803
4804 def pretty_print(self, q):
4805 q.text("set_config {")
4806 with q.group():
4807 with q.indent(2):
4808 q.breakable()
4809 q.text("xid = ");
4810 if self.xid != None:
4811 q.text("%#x" % self.xid)
4812 else:
4813 q.text('None')
4814 q.text(","); q.breakable()
4815 q.text("flags = ");
4816 q.text("%#x" % self.flags)
4817 q.text(","); q.breakable()
4818 q.text("miss_send_len = ");
4819 q.text("%#x" % self.miss_send_len)
4820 q.breakable()
4821 q.text('}')
4822
4823class table_mod(Message):
4824 version = const.OFP_VERSION
4825 type = const.OFPT_TABLE_MOD
4826
4827 def __init__(self, xid=None, table_id=None, config=None):
4828 self.xid = xid
4829 if table_id != None:
4830 self.table_id = table_id
4831 else:
4832 self.table_id = 0
4833 if config != None:
4834 self.config = config
4835 else:
4836 self.config = 0
4837
4838 def pack(self):
4839 packed = []
4840 packed.append(struct.pack("!B", self.version))
4841 packed.append(struct.pack("!B", self.type))
4842 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4843 packed.append(struct.pack("!L", self.xid))
4844 packed.append(struct.pack("!B", self.table_id))
4845 packed.append('\x00' * 3)
4846 packed.append(struct.pack("!L", self.config))
4847 length = sum([len(x) for x in packed])
4848 packed[2] = struct.pack("!H", length)
4849 return ''.join(packed)
4850
4851 @staticmethod
4852 def unpack(buf):
4853 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4854 obj = table_mod()
4855 if type(buf) == loxi.generic_util.OFReader:
4856 reader = buf
4857 else:
4858 reader = loxi.generic_util.OFReader(buf)
4859 _version = reader.read('!B')[0]
4860 assert(_version == const.OFP_VERSION)
4861 _type = reader.read('!B')[0]
4862 assert(_type == const.OFPT_TABLE_MOD)
4863 _length = reader.read('!H')[0]
4864 obj.xid = reader.read('!L')[0]
4865 obj.table_id = reader.read('!B')[0]
4866 reader.skip(3)
4867 obj.config = reader.read('!L')[0]
4868 return obj
4869
4870 def __eq__(self, other):
4871 if type(self) != type(other): return False
4872 if self.version != other.version: return False
4873 if self.type != other.type: return False
4874 if self.xid != other.xid: return False
4875 if self.table_id != other.table_id: return False
4876 if self.config != other.config: return False
4877 return True
4878
4879 def __ne__(self, other):
4880 return not self.__eq__(other)
4881
4882 def __str__(self):
4883 return self.show()
4884
4885 def show(self):
4886 import loxi.pp
4887 return loxi.pp.pp(self)
4888
4889 def pretty_print(self, q):
4890 q.text("table_mod {")
4891 with q.group():
4892 with q.indent(2):
4893 q.breakable()
4894 q.text("xid = ");
4895 if self.xid != None:
4896 q.text("%#x" % self.xid)
4897 else:
4898 q.text('None')
4899 q.text(","); q.breakable()
4900 q.text("table_id = ");
4901 q.text("%#x" % self.table_id)
4902 q.text(","); q.breakable()
4903 q.text("config = ");
4904 q.text("%#x" % self.config)
4905 q.breakable()
4906 q.text('}')
4907
4908class table_stats_reply(Message):
4909 version = const.OFP_VERSION
4910 type = const.OFPT_STATS_REPLY
4911 stats_type = const.OFPST_TABLE
4912
4913 def __init__(self, xid=None, flags=None, entries=None):
4914 self.xid = xid
4915 if flags != None:
4916 self.flags = flags
4917 else:
4918 self.flags = 0
4919 if entries != None:
4920 self.entries = entries
4921 else:
4922 self.entries = []
4923
4924 def pack(self):
4925 packed = []
4926 packed.append(struct.pack("!B", self.version))
4927 packed.append(struct.pack("!B", self.type))
4928 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4929 packed.append(struct.pack("!L", self.xid))
4930 packed.append(struct.pack("!H", self.stats_type))
4931 packed.append(struct.pack("!H", self.flags))
4932 packed.append('\x00' * 4)
4933 packed.append("".join([x.pack() for x in self.entries]))
4934 length = sum([len(x) for x in packed])
4935 packed[2] = struct.pack("!H", length)
4936 return ''.join(packed)
4937
4938 @staticmethod
4939 def unpack(buf):
4940 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4941 obj = table_stats_reply()
4942 if type(buf) == loxi.generic_util.OFReader:
4943 reader = buf
4944 else:
4945 reader = loxi.generic_util.OFReader(buf)
4946 _version = reader.read('!B')[0]
4947 assert(_version == const.OFP_VERSION)
4948 _type = reader.read('!B')[0]
4949 assert(_type == const.OFPT_STATS_REPLY)
4950 _length = reader.read('!H')[0]
4951 obj.xid = reader.read('!L')[0]
4952 _stats_type = reader.read('!H')[0]
4953 assert(_stats_type == const.OFPST_TABLE)
4954 obj.flags = reader.read('!H')[0]
4955 reader.skip(4)
4956 obj.entries = loxi.generic_util.unpack_list(reader, common.table_stats_entry.unpack)
4957 return obj
4958
4959 def __eq__(self, other):
4960 if type(self) != type(other): return False
4961 if self.version != other.version: return False
4962 if self.type != other.type: return False
4963 if self.xid != other.xid: return False
4964 if self.flags != other.flags: return False
4965 if self.entries != other.entries: return False
4966 return True
4967
4968 def __ne__(self, other):
4969 return not self.__eq__(other)
4970
4971 def __str__(self):
4972 return self.show()
4973
4974 def show(self):
4975 import loxi.pp
4976 return loxi.pp.pp(self)
4977
4978 def pretty_print(self, q):
4979 q.text("table_stats_reply {")
4980 with q.group():
4981 with q.indent(2):
4982 q.breakable()
4983 q.text("xid = ");
4984 if self.xid != None:
4985 q.text("%#x" % self.xid)
4986 else:
4987 q.text('None')
4988 q.text(","); q.breakable()
4989 q.text("flags = ");
4990 q.text("%#x" % self.flags)
4991 q.text(","); q.breakable()
4992 q.text("entries = ");
4993 q.pp(self.entries)
4994 q.breakable()
4995 q.text('}')
4996
4997class table_stats_request(Message):
4998 version = const.OFP_VERSION
4999 type = const.OFPT_STATS_REQUEST
5000 stats_type = const.OFPST_TABLE
5001
5002 def __init__(self, xid=None, flags=None):
5003 self.xid = xid
5004 if flags != None:
5005 self.flags = flags
5006 else:
5007 self.flags = 0
5008
5009 def pack(self):
5010 packed = []
5011 packed.append(struct.pack("!B", self.version))
5012 packed.append(struct.pack("!B", self.type))
5013 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5014 packed.append(struct.pack("!L", self.xid))
5015 packed.append(struct.pack("!H", self.stats_type))
5016 packed.append(struct.pack("!H", self.flags))
5017 packed.append('\x00' * 4)
5018 length = sum([len(x) for x in packed])
5019 packed[2] = struct.pack("!H", length)
5020 return ''.join(packed)
5021
5022 @staticmethod
5023 def unpack(buf):
5024 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5025 obj = table_stats_request()
5026 if type(buf) == loxi.generic_util.OFReader:
5027 reader = buf
5028 else:
5029 reader = loxi.generic_util.OFReader(buf)
5030 _version = reader.read('!B')[0]
5031 assert(_version == const.OFP_VERSION)
5032 _type = reader.read('!B')[0]
5033 assert(_type == const.OFPT_STATS_REQUEST)
5034 _length = reader.read('!H')[0]
5035 obj.xid = reader.read('!L')[0]
5036 _stats_type = reader.read('!H')[0]
5037 assert(_stats_type == const.OFPST_TABLE)
5038 obj.flags = reader.read('!H')[0]
5039 reader.skip(4)
5040 return obj
5041
5042 def __eq__(self, other):
5043 if type(self) != type(other): return False
5044 if self.version != other.version: return False
5045 if self.type != other.type: return False
5046 if self.xid != other.xid: return False
5047 if self.flags != other.flags: return False
5048 return True
5049
5050 def __ne__(self, other):
5051 return not self.__eq__(other)
5052
5053 def __str__(self):
5054 return self.show()
5055
5056 def show(self):
5057 import loxi.pp
5058 return loxi.pp.pp(self)
5059
5060 def pretty_print(self, q):
5061 q.text("table_stats_request {")
5062 with q.group():
5063 with q.indent(2):
5064 q.breakable()
5065 q.text("xid = ");
5066 if self.xid != None:
5067 q.text("%#x" % self.xid)
5068 else:
5069 q.text('None')
5070 q.text(","); q.breakable()
5071 q.text("flags = ");
5072 q.text("%#x" % self.flags)
5073 q.breakable()
5074 q.text('}')
5075
5076
5077def parse_header(buf):
5078 if len(buf) < 8:
5079 raise loxi.ProtocolError("too short to be an OpenFlow message")
5080 return struct.unpack_from("!BBHL", buf)
5081
5082def parse_message(buf):
5083 msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
5084 if msg_ver != const.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
5085 raise loxi.ProtocolError("wrong OpenFlow version")
5086 if len(buf) != msg_len:
5087 raise loxi.ProtocolError("incorrect message size")
5088 if msg_type in parsers:
5089 return parsers[msg_type](buf)
5090 else:
5091 raise loxi.ProtocolError("unexpected message type")
5092
5093def parse_flow_mod(buf):
5094 if len(buf) < 56 + 2:
5095 raise loxi.ProtocolError("message too short")
5096 cmd, = struct.unpack_from("!H", buf, 56)
5097 if cmd in flow_mod_parsers:
5098 return flow_mod_parsers[cmd](buf)
5099 else:
5100 raise loxi.ProtocolError("unexpected flow mod cmd %u" % cmd)
5101
5102def parse_stats_reply(buf):
5103 if len(buf) < 8 + 2:
5104 raise loxi.ProtocolError("message too short")
5105 stats_type, = struct.unpack_from("!H", buf, 8)
5106 if stats_type in stats_reply_parsers:
5107 return stats_reply_parsers[stats_type](buf)
5108 else:
5109 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5110
5111def parse_stats_request(buf):
5112 if len(buf) < 8 + 2:
5113 raise loxi.ProtocolError("message too short")
5114 stats_type, = struct.unpack_from("!H", buf, 8)
5115 if stats_type in stats_request_parsers:
5116 return stats_request_parsers[stats_type](buf)
5117 else:
5118 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5119
5120def parse_experimenter(buf):
5121 if len(buf) < 16:
5122 raise loxi.ProtocolError("experimenter message too short")
5123
5124 experimenter, = struct.unpack_from("!L", buf, 8)
5125 if experimenter == 0x005c16c7: # Big Switch Networks
5126 subtype, = struct.unpack_from("!L", buf, 12)
5127 elif experimenter == 0x00002320: # Nicira
5128 subtype, = struct.unpack_from("!L", buf, 12)
5129 else:
5130 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
5131
5132 if subtype in experimenter_parsers[experimenter]:
5133 return experimenter_parsers[experimenter][subtype](buf)
5134 else:
5135 raise loxi.ProtocolError("unexpected experimenter %#x subtype %#x" % (experimenter, subtype))
5136
5137parsers = {
5138 const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
5139 const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
5140 const.OFPT_ECHO_REPLY : echo_reply.unpack,
5141 const.OFPT_ECHO_REQUEST : echo_request.unpack,
5142 const.OFPT_ERROR : error_msg.unpack,
5143 const.OFPT_EXPERIMENTER : parse_experimenter,
5144 const.OFPT_FEATURES_REPLY : features_reply.unpack,
5145 const.OFPT_FEATURES_REQUEST : features_request.unpack,
5146 const.OFPT_FLOW_MOD : parse_flow_mod,
5147 const.OFPT_FLOW_REMOVED : flow_removed.unpack,
5148 const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
5149 const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
5150 const.OFPT_GROUP_MOD : group_mod.unpack,
5151 const.OFPT_HELLO : hello.unpack,
5152 const.OFPT_PACKET_IN : packet_in.unpack,
5153 const.OFPT_PACKET_OUT : packet_out.unpack,
5154 const.OFPT_PORT_MOD : port_mod.unpack,
5155 const.OFPT_PORT_STATUS : port_status.unpack,
5156 const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
5157 const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
5158 const.OFPT_SET_CONFIG : set_config.unpack,
5159 const.OFPT_STATS_REPLY : parse_stats_reply,
5160 const.OFPT_STATS_REQUEST : parse_stats_request,
5161 const.OFPT_TABLE_MOD : table_mod.unpack,
5162}
5163
5164flow_mod_parsers = {
5165 const.OFPFC_ADD : flow_add.unpack,
5166 const.OFPFC_MODIFY : flow_modify.unpack,
5167 const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
5168 const.OFPFC_DELETE : flow_delete.unpack,
5169 const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
5170}
5171
5172stats_reply_parsers = {
5173 const.OFPST_DESC : desc_stats_reply.unpack,
5174 const.OFPST_FLOW : flow_stats_reply.unpack,
5175 const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
5176 const.OFPST_TABLE : table_stats_reply.unpack,
5177 const.OFPST_PORT : port_stats_reply.unpack,
5178 const.OFPST_QUEUE : queue_stats_reply.unpack,
5179 const.OFPST_EXPERIMENTER : experimenter_stats_reply.unpack,
5180}
5181
5182stats_request_parsers = {
5183 const.OFPST_DESC : desc_stats_request.unpack,
5184 const.OFPST_FLOW : flow_stats_request.unpack,
5185 const.OFPST_AGGREGATE : aggregate_stats_request.unpack,
5186 const.OFPST_TABLE : table_stats_request.unpack,
5187 const.OFPST_PORT : port_stats_request.unpack,
5188 const.OFPST_QUEUE : queue_stats_request.unpack,
5189 const.OFPST_EXPERIMENTER : experimenter_stats_request.unpack,
5190}
5191
5192experimenter_parsers = {
5193}