blob: 5b4ce028c0493e33a7880fa47963a5d2a4b474e8 [file] [log] [blame]
Rich Lane6242d9f2013-01-06 17:35:39 -08001
2# Python OpenFlow message wrapper classes
3
4from cstruct import *
5from action_list import action_list
6from error import *
7
8# Define templates for documentation
9class ofp_template_msg:
10 """
11 Sample base class for template_msg; normally auto generated
12 This class should live in the of_header name space and provides the
13 base class for this type of message. It will be wrapped for the
14 high level API.
15
16 """
17 def __init__(self):
18 """
19 Constructor for base class
20
21 """
Rich Lane6242d9f2013-01-06 17:35:39 -080022 # Additional base data members declared here
23
24 # Normally will define pack, unpack, __len__ functions
25
26class template_msg(ofp_template_msg):
27 """
28 Sample class wrapper for template_msg
29 This class should live in the of_message name space and provides the
30 high level API for an OpenFlow message object. These objects must
31 implement the functions indicated in this template.
32
33 """
34 def __init__(self):
35 """
36 Constructor
37 Must set the header type value appropriately for the message
38
39 """
40
41 ##@var header
42 # OpenFlow message header: length, version, xid, type
43 ofp_template_msg.__init__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -080044 # For a real message, will be set to an integer
Rich Laneb73808c2013-03-11 15:22:23 -070045 self.type = "TEMPLATE_MSG_VALUE"
Rich Lane6242d9f2013-01-06 17:35:39 -080046 def pack(self):
47 """
48 Pack object into string
49
50 @return The packed string which can go on the wire
51
52 """
53 pass
54 def unpack(self, binary_string):
55 """
56 Unpack object from a binary string
57
58 @param binary_string The wire protocol byte string holding the object
59 represented as an array of bytes.
60
61 @return Typically returns the remainder of binary_string that
62 was not parsed. May give a warning if that string is non-empty
63
64 """
65 pass
66 def __len__(self):
67 """
68 Return the length of this object once packed into a string
69
70 @return An integer representing the number bytes in the packed
71 string.
72
73 """
74 pass
75 def show(self, prefix=''):
76 """
77 Generate a string (with multiple lines) describing the contents
78 of the object in a readable manner
79
80 @param prefix Pre-pended at the beginning of each line.
81
82 """
83 pass
84 def __eq__(self, other):
85 """
86 Return True if self and other hold the same data
87
88 @param other Other object in comparison
89
90 """
91 pass
92 def __ne__(self, other):
93 """
94 Return True if self and other do not hold the same data
95
96 @param other Other object in comparison
97
98 """
99 pass
100
101
102################################################################
103#
104# OpenFlow Message Definitions
105#
106################################################################
107
Rich Laneb73808c2013-03-11 15:22:23 -0700108class barrier_reply(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -0800109 """
110 Wrapper class for barrier_reply
111
112 OpenFlow message header: length, version, xid, type
113 @arg length: The total length of the message
114 @arg version: The OpenFlow version (1)
115 @arg xid: The transaction ID
116 @arg type: The message type (OFPT_BARRIER_REPLY=19)
117
Rich Laneb73808c2013-03-11 15:22:23 -0700118 Data members inherited from ofp_header:
119 @arg version
120 @arg type
121 @arg length
122 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800123
124 """
125
126 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -0700127 ofp_header.__init__(self)
128 self.version = OFP_VERSION
129 self.type = OFPT_BARRIER_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -0800130 for (k, v) in kwargs.items():
131 if hasattr(self, k):
132 setattr(self, k, v)
133 else:
134 raise NameError("field %s does not exist in %s" % (k, self.__class__))
135
136
137 def pack(self):
138 """
139 Pack object into string
140
141 @return The packed string which can go on the wire
142
143 """
Rich Laneb73808c2013-03-11 15:22:23 -0700144 self.length = len(self)
145 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800146
Rich Laneb73808c2013-03-11 15:22:23 -0700147 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800148 return packed
149
150 def unpack(self, binary_string):
151 """
152 Unpack object from a binary string
153
154 @param binary_string The wire protocol byte string holding the object
155 represented as an array of bytes.
156 @return The remainder of binary_string that was not parsed.
157
158 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800159
Rich Laneb73808c2013-03-11 15:22:23 -0700160 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -0800161 # Fixme: If no self.data, add check for data remaining
162 return binary_string
163
164 def __len__(self):
165 """
166 Return the length of this object once packed into a string
167
168 @return An integer representing the number bytes in the packed
169 string.
170
171 """
Rich Laneb73808c2013-03-11 15:22:23 -0700172 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800173
Rich Laneb73808c2013-03-11 15:22:23 -0700174 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800175 return length
176
177 def show(self, prefix=''):
178 """
179 Generate a string (with multiple lines) describing the contents
180 of the object in a readable manner
181
182 @param prefix Pre-pended at the beginning of each line.
183
184 """
185
186 outstr = prefix + 'barrier_reply (OFPT_BARRIER_REPLY)\n'
187 prefix += ' '
188 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -0700189 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -0800190 return outstr
191
192 def __eq__(self, other):
193 """
194 Return True if self and other hold the same data
195
196 @param other Other object in comparison
197
198 """
199 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800200
Rich Laneb73808c2013-03-11 15:22:23 -0700201 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800202 return True
203
204 def __ne__(self, other):
205 """
206 Return True if self and other do not hold the same data
207
208 @param other Other object in comparison
209
210 """
211 return not self.__eq__(other)
212
213
Rich Laneb73808c2013-03-11 15:22:23 -0700214class barrier_request(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -0800215 """
216 Wrapper class for barrier_request
217
218 OpenFlow message header: length, version, xid, type
219 @arg length: The total length of the message
220 @arg version: The OpenFlow version (1)
221 @arg xid: The transaction ID
222 @arg type: The message type (OFPT_BARRIER_REQUEST=18)
223
Rich Laneb73808c2013-03-11 15:22:23 -0700224 Data members inherited from ofp_header:
225 @arg version
226 @arg type
227 @arg length
228 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800229
230 """
231
232 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -0700233 ofp_header.__init__(self)
234 self.version = OFP_VERSION
235 self.type = OFPT_BARRIER_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -0800236 for (k, v) in kwargs.items():
237 if hasattr(self, k):
238 setattr(self, k, v)
239 else:
240 raise NameError("field %s does not exist in %s" % (k, self.__class__))
241
242
243 def pack(self):
244 """
245 Pack object into string
246
247 @return The packed string which can go on the wire
248
249 """
Rich Laneb73808c2013-03-11 15:22:23 -0700250 self.length = len(self)
251 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800252
Rich Laneb73808c2013-03-11 15:22:23 -0700253 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800254 return packed
255
256 def unpack(self, binary_string):
257 """
258 Unpack object from a binary string
259
260 @param binary_string The wire protocol byte string holding the object
261 represented as an array of bytes.
262 @return The remainder of binary_string that was not parsed.
263
264 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800265
Rich Laneb73808c2013-03-11 15:22:23 -0700266 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -0800267 # Fixme: If no self.data, add check for data remaining
268 return binary_string
269
270 def __len__(self):
271 """
272 Return the length of this object once packed into a string
273
274 @return An integer representing the number bytes in the packed
275 string.
276
277 """
Rich Laneb73808c2013-03-11 15:22:23 -0700278 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800279
Rich Laneb73808c2013-03-11 15:22:23 -0700280 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800281 return length
282
283 def show(self, prefix=''):
284 """
285 Generate a string (with multiple lines) describing the contents
286 of the object in a readable manner
287
288 @param prefix Pre-pended at the beginning of each line.
289
290 """
291
292 outstr = prefix + 'barrier_request (OFPT_BARRIER_REQUEST)\n'
293 prefix += ' '
294 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -0700295 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -0800296 return outstr
297
298 def __eq__(self, other):
299 """
300 Return True if self and other hold the same data
301
302 @param other Other object in comparison
303
304 """
305 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800306
Rich Laneb73808c2013-03-11 15:22:23 -0700307 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800308 return True
309
310 def __ne__(self, other):
311 """
312 Return True if self and other do not hold the same data
313
314 @param other Other object in comparison
315
316 """
317 return not self.__eq__(other)
318
319
Rich Laneb73808c2013-03-11 15:22:23 -0700320class echo_reply(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -0800321 """
322 Wrapper class for echo_reply
323
324 OpenFlow message header: length, version, xid, type
325 @arg length: The total length of the message
326 @arg version: The OpenFlow version (1)
327 @arg xid: The transaction ID
328 @arg type: The message type (OFPT_ECHO_REPLY=3)
329
Rich Laneb73808c2013-03-11 15:22:23 -0700330 Data members inherited from ofp_header:
331 @arg version
332 @arg type
333 @arg length
334 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800335 @arg data: Binary string following message members
336
337 """
338
339 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -0700340 ofp_header.__init__(self)
341 self.version = OFP_VERSION
342 self.type = OFPT_ECHO_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -0800343 self.data = ""
344 for (k, v) in kwargs.items():
345 if hasattr(self, k):
346 setattr(self, k, v)
347 else:
348 raise NameError("field %s does not exist in %s" % (k, self.__class__))
349
350
351 def pack(self):
352 """
353 Pack object into string
354
355 @return The packed string which can go on the wire
356
357 """
Rich Laneb73808c2013-03-11 15:22:23 -0700358 self.length = len(self)
359 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800360
Rich Laneb73808c2013-03-11 15:22:23 -0700361 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800362 packed += self.data
363 return packed
364
365 def unpack(self, binary_string):
366 """
367 Unpack object from a binary string
368
369 @param binary_string The wire protocol byte string holding the object
370 represented as an array of bytes.
371 @return The remainder of binary_string that was not parsed.
372
373 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800374
Rich Laneb73808c2013-03-11 15:22:23 -0700375 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -0800376 self.data = binary_string
377 binary_string = ''
378 return binary_string
379
380 def __len__(self):
381 """
382 Return the length of this object once packed into a string
383
384 @return An integer representing the number bytes in the packed
385 string.
386
387 """
Rich Laneb73808c2013-03-11 15:22:23 -0700388 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800389
Rich Laneb73808c2013-03-11 15:22:23 -0700390 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800391 length += len(self.data)
392 return length
393
394 def show(self, prefix=''):
395 """
396 Generate a string (with multiple lines) describing the contents
397 of the object in a readable manner
398
399 @param prefix Pre-pended at the beginning of each line.
400
401 """
402
403 outstr = prefix + 'echo_reply (OFPT_ECHO_REPLY)\n'
404 prefix += ' '
405 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -0700406 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -0800407 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
408 ##@todo Fix this circular reference
409 # if len(self.data) > 0:
410 # obj = of_message_parse(self.data)
411 # if obj != None:
412 # outstr += obj.show(prefix)
413 # else:
414 # outstr += prefix + "Unable to parse data\n"
415 return outstr
416
417 def __eq__(self, other):
418 """
419 Return True if self and other hold the same data
420
421 @param other Other object in comparison
422
423 """
424 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800425
Rich Laneb73808c2013-03-11 15:22:23 -0700426 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800427 if self.data != other.data: return False
428 return True
429
430 def __ne__(self, other):
431 """
432 Return True if self and other do not hold the same data
433
434 @param other Other object in comparison
435
436 """
437 return not self.__eq__(other)
438
439
Rich Laneb73808c2013-03-11 15:22:23 -0700440class echo_request(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -0800441 """
442 Wrapper class for echo_request
443
444 OpenFlow message header: length, version, xid, type
445 @arg length: The total length of the message
446 @arg version: The OpenFlow version (1)
447 @arg xid: The transaction ID
448 @arg type: The message type (OFPT_ECHO_REQUEST=2)
449
Rich Laneb73808c2013-03-11 15:22:23 -0700450 Data members inherited from ofp_header:
451 @arg version
452 @arg type
453 @arg length
454 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800455 @arg data: Binary string following message members
456
457 """
458
459 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -0700460 ofp_header.__init__(self)
461 self.version = OFP_VERSION
462 self.type = OFPT_ECHO_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -0800463 self.data = ""
464 for (k, v) in kwargs.items():
465 if hasattr(self, k):
466 setattr(self, k, v)
467 else:
468 raise NameError("field %s does not exist in %s" % (k, self.__class__))
469
470
471 def pack(self):
472 """
473 Pack object into string
474
475 @return The packed string which can go on the wire
476
477 """
Rich Laneb73808c2013-03-11 15:22:23 -0700478 self.length = len(self)
479 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800480
Rich Laneb73808c2013-03-11 15:22:23 -0700481 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800482 packed += self.data
483 return packed
484
485 def unpack(self, binary_string):
486 """
487 Unpack object from a binary string
488
489 @param binary_string The wire protocol byte string holding the object
490 represented as an array of bytes.
491 @return The remainder of binary_string that was not parsed.
492
493 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800494
Rich Laneb73808c2013-03-11 15:22:23 -0700495 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -0800496 self.data = binary_string
497 binary_string = ''
498 return binary_string
499
500 def __len__(self):
501 """
502 Return the length of this object once packed into a string
503
504 @return An integer representing the number bytes in the packed
505 string.
506
507 """
Rich Laneb73808c2013-03-11 15:22:23 -0700508 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800509
Rich Laneb73808c2013-03-11 15:22:23 -0700510 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800511 length += len(self.data)
512 return length
513
514 def show(self, prefix=''):
515 """
516 Generate a string (with multiple lines) describing the contents
517 of the object in a readable manner
518
519 @param prefix Pre-pended at the beginning of each line.
520
521 """
522
523 outstr = prefix + 'echo_request (OFPT_ECHO_REQUEST)\n'
524 prefix += ' '
525 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -0700526 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -0800527 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
528 ##@todo Fix this circular reference
529 # if len(self.data) > 0:
530 # obj = of_message_parse(self.data)
531 # if obj != None:
532 # outstr += obj.show(prefix)
533 # else:
534 # outstr += prefix + "Unable to parse data\n"
535 return outstr
536
537 def __eq__(self, other):
538 """
539 Return True if self and other hold the same data
540
541 @param other Other object in comparison
542
543 """
544 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800545
Rich Laneb73808c2013-03-11 15:22:23 -0700546 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800547 if self.data != other.data: return False
548 return True
549
550 def __ne__(self, other):
551 """
552 Return True if self and other do not hold the same data
553
554 @param other Other object in comparison
555
556 """
557 return not self.__eq__(other)
558
559
560class error(ofp_error_msg):
561 """
562 Wrapper class for error
563
564 OpenFlow message header: length, version, xid, type
565 @arg length: The total length of the message
566 @arg version: The OpenFlow version (1)
567 @arg xid: The transaction ID
568 @arg type: The message type (OFPT_ERROR=1)
569
570 Data members inherited from ofp_error_msg:
Rich Laneb73808c2013-03-11 15:22:23 -0700571 @arg version
572 @arg type
573 @arg length
574 @arg xid
Rich Lane4e361bb2013-03-11 13:57:31 -0700575 @arg err_type
Rich Lane6242d9f2013-01-06 17:35:39 -0800576 @arg code
577 @arg data: Binary string following message members
578
579 """
580
581 def __init__(self, **kwargs):
582 ofp_error_msg.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -0700583 self.version = OFP_VERSION
584 self.type = OFPT_ERROR
Rich Lane6242d9f2013-01-06 17:35:39 -0800585 self.data = ""
586 for (k, v) in kwargs.items():
587 if hasattr(self, k):
588 setattr(self, k, v)
589 else:
590 raise NameError("field %s does not exist in %s" % (k, self.__class__))
591
592
593 def pack(self):
594 """
595 Pack object into string
596
597 @return The packed string which can go on the wire
598
599 """
Rich Laneb73808c2013-03-11 15:22:23 -0700600 self.length = len(self)
601 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800602
603 packed += ofp_error_msg.pack(self)
604 packed += self.data
605 return packed
606
607 def unpack(self, binary_string):
608 """
609 Unpack object from a binary string
610
611 @param binary_string The wire protocol byte string holding the object
612 represented as an array of bytes.
613 @return The remainder of binary_string that was not parsed.
614
615 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800616
617 binary_string = ofp_error_msg.unpack(self, binary_string)
618 self.data = binary_string
619 binary_string = ''
620 return binary_string
621
622 def __len__(self):
623 """
624 Return the length of this object once packed into a string
625
626 @return An integer representing the number bytes in the packed
627 string.
628
629 """
Rich Laneb73808c2013-03-11 15:22:23 -0700630 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800631
632 length += ofp_error_msg.__len__(self)
633 length += len(self.data)
634 return length
635
636 def show(self, prefix=''):
637 """
638 Generate a string (with multiple lines) describing the contents
639 of the object in a readable manner
640
641 @param prefix Pre-pended at the beginning of each line.
642
643 """
644
645 outstr = prefix + 'error (OFPT_ERROR)\n'
646 prefix += ' '
647 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -0800648 outstr += ofp_error_msg.show(self, prefix)
649 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
650 ##@todo Fix this circular reference
651 # if len(self.data) > 0:
652 # obj = of_message_parse(self.data)
653 # if obj != None:
654 # outstr += obj.show(prefix)
655 # else:
656 # outstr += prefix + "Unable to parse data\n"
657 return outstr
658
659 def __eq__(self, other):
660 """
661 Return True if self and other hold the same data
662
663 @param other Other object in comparison
664
665 """
666 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800667
668 if not ofp_error_msg.__eq__(self, other): return False
669 if self.data != other.data: return False
670 return True
671
672 def __ne__(self, other):
673 """
674 Return True if self and other do not hold the same data
675
676 @param other Other object in comparison
677
678 """
679 return not self.__eq__(other)
680
681
682class features_reply(ofp_switch_features):
683 """
684 Wrapper class for features_reply
685
686 OpenFlow message header: length, version, xid, type
687 @arg length: The total length of the message
688 @arg version: The OpenFlow version (1)
689 @arg xid: The transaction ID
690 @arg type: The message type (OFPT_FEATURES_REPLY=6)
691
692 Data members inherited from ofp_switch_features:
Rich Laneb73808c2013-03-11 15:22:23 -0700693 @arg version
694 @arg type
695 @arg length
696 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800697 @arg datapath_id
698 @arg n_buffers
699 @arg n_tables
700 @arg capabilities
701 @arg actions
702 @arg ports: Variable length array of TBD
703
704 """
705
706 def __init__(self, **kwargs):
707 ofp_switch_features.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -0700708 self.version = OFP_VERSION
709 self.type = OFPT_FEATURES_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -0800710 self.ports = []
711 for (k, v) in kwargs.items():
712 if hasattr(self, k):
713 setattr(self, k, v)
714 else:
715 raise NameError("field %s does not exist in %s" % (k, self.__class__))
716
717
718 def pack(self):
719 """
720 Pack object into string
721
722 @return The packed string which can go on the wire
723
724 """
Rich Laneb73808c2013-03-11 15:22:23 -0700725 self.length = len(self)
726 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800727
728 packed += ofp_switch_features.pack(self)
729 for obj in self.ports:
730 packed += obj.pack()
731 return packed
732
733 def unpack(self, binary_string):
734 """
735 Unpack object from a binary string
736
737 @param binary_string The wire protocol byte string holding the object
738 represented as an array of bytes.
739 @return The remainder of binary_string that was not parsed.
740
741 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800742
743 binary_string = ofp_switch_features.unpack(self, binary_string)
744 while len(binary_string) >= OFP_PHY_PORT_BYTES:
745 new_port = ofp_phy_port()
746 binary_string = new_port.unpack(binary_string)
747 self.ports.append(new_port)
748 # Fixme: If no self.data, add check for data remaining
749 return binary_string
750
751 def __len__(self):
752 """
753 Return the length of this object once packed into a string
754
755 @return An integer representing the number bytes in the packed
756 string.
757
758 """
Rich Laneb73808c2013-03-11 15:22:23 -0700759 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800760
761 length += ofp_switch_features.__len__(self)
762 for obj in self.ports:
763 length += len(obj)
764 return length
765
766 def show(self, prefix=''):
767 """
768 Generate a string (with multiple lines) describing the contents
769 of the object in a readable manner
770
771 @param prefix Pre-pended at the beginning of each line.
772
773 """
774
775 outstr = prefix + 'features_reply (OFPT_FEATURES_REPLY)\n'
776 prefix += ' '
777 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -0800778 outstr += ofp_switch_features.show(self, prefix)
779 outstr += prefix + "Array ports\n"
780 for obj in self.ports:
781 outstr += obj.show(prefix + ' ')
782 return outstr
783
784 def __eq__(self, other):
785 """
786 Return True if self and other hold the same data
787
788 @param other Other object in comparison
789
790 """
791 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800792
793 if not ofp_switch_features.__eq__(self, other): return False
794 if self.ports != other.ports: return False
795 return True
796
797 def __ne__(self, other):
798 """
799 Return True if self and other do not hold the same data
800
801 @param other Other object in comparison
802
803 """
804 return not self.__eq__(other)
805
806
Rich Laneb73808c2013-03-11 15:22:23 -0700807class features_request(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -0800808 """
809 Wrapper class for features_request
810
811 OpenFlow message header: length, version, xid, type
812 @arg length: The total length of the message
813 @arg version: The OpenFlow version (1)
814 @arg xid: The transaction ID
815 @arg type: The message type (OFPT_FEATURES_REQUEST=5)
816
Rich Laneb73808c2013-03-11 15:22:23 -0700817 Data members inherited from ofp_header:
818 @arg version
819 @arg type
820 @arg length
821 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800822
823 """
824
825 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -0700826 ofp_header.__init__(self)
827 self.version = OFP_VERSION
828 self.type = OFPT_FEATURES_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -0800829 for (k, v) in kwargs.items():
830 if hasattr(self, k):
831 setattr(self, k, v)
832 else:
833 raise NameError("field %s does not exist in %s" % (k, self.__class__))
834
835
836 def pack(self):
837 """
838 Pack object into string
839
840 @return The packed string which can go on the wire
841
842 """
Rich Laneb73808c2013-03-11 15:22:23 -0700843 self.length = len(self)
844 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800845
Rich Laneb73808c2013-03-11 15:22:23 -0700846 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800847 return packed
848
849 def unpack(self, binary_string):
850 """
851 Unpack object from a binary string
852
853 @param binary_string The wire protocol byte string holding the object
854 represented as an array of bytes.
855 @return The remainder of binary_string that was not parsed.
856
857 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800858
Rich Laneb73808c2013-03-11 15:22:23 -0700859 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -0800860 # Fixme: If no self.data, add check for data remaining
861 return binary_string
862
863 def __len__(self):
864 """
865 Return the length of this object once packed into a string
866
867 @return An integer representing the number bytes in the packed
868 string.
869
870 """
Rich Laneb73808c2013-03-11 15:22:23 -0700871 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800872
Rich Laneb73808c2013-03-11 15:22:23 -0700873 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -0800874 return length
875
876 def show(self, prefix=''):
877 """
878 Generate a string (with multiple lines) describing the contents
879 of the object in a readable manner
880
881 @param prefix Pre-pended at the beginning of each line.
882
883 """
884
885 outstr = prefix + 'features_request (OFPT_FEATURES_REQUEST)\n'
886 prefix += ' '
887 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -0700888 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -0800889 return outstr
890
891 def __eq__(self, other):
892 """
893 Return True if self and other hold the same data
894
895 @param other Other object in comparison
896
897 """
898 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800899
Rich Laneb73808c2013-03-11 15:22:23 -0700900 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -0800901 return True
902
903 def __ne__(self, other):
904 """
905 Return True if self and other do not hold the same data
906
907 @param other Other object in comparison
908
909 """
910 return not self.__eq__(other)
911
912
913class flow_mod(ofp_flow_mod):
914 """
915 Wrapper class for flow_mod
916
917 OpenFlow message header: length, version, xid, type
918 @arg length: The total length of the message
919 @arg version: The OpenFlow version (1)
920 @arg xid: The transaction ID
921 @arg type: The message type (OFPT_FLOW_MOD=14)
922
923 Data members inherited from ofp_flow_mod:
Rich Laneb73808c2013-03-11 15:22:23 -0700924 @arg version
925 @arg type
926 @arg length
927 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -0800928 @arg match
929 @arg cookie
930 @arg command
931 @arg idle_timeout
932 @arg hard_timeout
933 @arg priority
934 @arg buffer_id
935 @arg out_port
936 @arg flags
937 @arg actions: Object of type action_list
938
939 """
940
941 def __init__(self, **kwargs):
942 ofp_flow_mod.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -0700943 self.version = OFP_VERSION
944 self.type = OFPT_FLOW_MOD
Rich Lane6242d9f2013-01-06 17:35:39 -0800945 self.actions = []
946 for (k, v) in kwargs.items():
947 if hasattr(self, k):
948 setattr(self, k, v)
949 else:
950 raise NameError("field %s does not exist in %s" % (k, self.__class__))
Rich Lane6242d9f2013-01-06 17:35:39 -0800951
952
953 def pack(self):
954 """
955 Pack object into string
956
957 @return The packed string which can go on the wire
958
959 """
Rich Laneb73808c2013-03-11 15:22:23 -0700960 self.length = len(self)
961 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -0800962
963 packed += ofp_flow_mod.pack(self)
Rich Lane62e96852013-03-11 12:04:45 -0700964 packed += action_list(self.actions).pack()
Rich Lane6242d9f2013-01-06 17:35:39 -0800965 return packed
966
967 def unpack(self, binary_string):
968 """
969 Unpack object from a binary string
970
971 @param binary_string The wire protocol byte string holding the object
972 represented as an array of bytes.
973 @return The remainder of binary_string that was not parsed.
974
975 """
Rich Lane6242d9f2013-01-06 17:35:39 -0800976
977 binary_string = ofp_flow_mod.unpack(self, binary_string)
Rich Laneb73808c2013-03-11 15:22:23 -0700978 ai_len = self.length - (OFP_FLOW_MOD_BYTES + OFP_HEADER_BYTES)
Rich Lane62e96852013-03-11 12:04:45 -0700979 obj = action_list()
980 binary_string = obj.unpack(binary_string, bytes=ai_len)
981 self.actions = list(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -0800982 # Fixme: If no self.data, add check for data remaining
983 return binary_string
984
985 def __len__(self):
986 """
987 Return the length of this object once packed into a string
988
989 @return An integer representing the number bytes in the packed
990 string.
991
992 """
Rich Laneb73808c2013-03-11 15:22:23 -0700993 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -0800994
995 length += ofp_flow_mod.__len__(self)
Rich Lane62e96852013-03-11 12:04:45 -0700996 for obj in self.actions:
997 length += len(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -0800998 return length
999
1000 def show(self, prefix=''):
1001 """
1002 Generate a string (with multiple lines) describing the contents
1003 of the object in a readable manner
1004
1005 @param prefix Pre-pended at the beginning of each line.
1006
1007 """
1008
1009 outstr = prefix + 'flow_mod (OFPT_FLOW_MOD)\n'
1010 prefix += ' '
1011 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001012 outstr += ofp_flow_mod.show(self, prefix)
1013 outstr += prefix + "List actions\n"
Rich Lanee6ea3fe2013-03-08 17:54:38 -08001014 for obj in self.actions:
1015 outstr += obj.show(prefix + " ")
Rich Lane6242d9f2013-01-06 17:35:39 -08001016 return outstr
1017
1018 def __eq__(self, other):
1019 """
1020 Return True if self and other hold the same data
1021
1022 @param other Other object in comparison
1023
1024 """
1025 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001026
1027 if not ofp_flow_mod.__eq__(self, other): return False
1028 if self.actions != other.actions: return False
1029 return True
1030
1031 def __ne__(self, other):
1032 """
1033 Return True if self and other do not hold the same data
1034
1035 @param other Other object in comparison
1036
1037 """
1038 return not self.__eq__(other)
1039
1040
1041class flow_removed(ofp_flow_removed):
1042 """
1043 Wrapper class for flow_removed
1044
1045 OpenFlow message header: length, version, xid, type
1046 @arg length: The total length of the message
1047 @arg version: The OpenFlow version (1)
1048 @arg xid: The transaction ID
1049 @arg type: The message type (OFPT_FLOW_REMOVED=11)
1050
1051 Data members inherited from ofp_flow_removed:
Rich Laneb73808c2013-03-11 15:22:23 -07001052 @arg version
1053 @arg type
1054 @arg length
1055 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001056 @arg match
1057 @arg cookie
1058 @arg priority
1059 @arg reason
1060 @arg duration_sec
1061 @arg duration_nsec
1062 @arg idle_timeout
1063 @arg packet_count
1064 @arg byte_count
1065
1066 """
1067
1068 def __init__(self, **kwargs):
1069 ofp_flow_removed.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001070 self.version = OFP_VERSION
1071 self.type = OFPT_FLOW_REMOVED
Rich Lane6242d9f2013-01-06 17:35:39 -08001072 for (k, v) in kwargs.items():
1073 if hasattr(self, k):
1074 setattr(self, k, v)
1075 else:
1076 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1077
1078
1079 def pack(self):
1080 """
1081 Pack object into string
1082
1083 @return The packed string which can go on the wire
1084
1085 """
Rich Laneb73808c2013-03-11 15:22:23 -07001086 self.length = len(self)
1087 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001088
1089 packed += ofp_flow_removed.pack(self)
1090 return packed
1091
1092 def unpack(self, binary_string):
1093 """
1094 Unpack object from a binary string
1095
1096 @param binary_string The wire protocol byte string holding the object
1097 represented as an array of bytes.
1098 @return The remainder of binary_string that was not parsed.
1099
1100 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001101
1102 binary_string = ofp_flow_removed.unpack(self, binary_string)
1103 # Fixme: If no self.data, add check for data remaining
1104 return binary_string
1105
1106 def __len__(self):
1107 """
1108 Return the length of this object once packed into a string
1109
1110 @return An integer representing the number bytes in the packed
1111 string.
1112
1113 """
Rich Laneb73808c2013-03-11 15:22:23 -07001114 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001115
1116 length += ofp_flow_removed.__len__(self)
1117 return length
1118
1119 def show(self, prefix=''):
1120 """
1121 Generate a string (with multiple lines) describing the contents
1122 of the object in a readable manner
1123
1124 @param prefix Pre-pended at the beginning of each line.
1125
1126 """
1127
1128 outstr = prefix + 'flow_removed (OFPT_FLOW_REMOVED)\n'
1129 prefix += ' '
1130 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001131 outstr += ofp_flow_removed.show(self, prefix)
1132 return outstr
1133
1134 def __eq__(self, other):
1135 """
1136 Return True if self and other hold the same data
1137
1138 @param other Other object in comparison
1139
1140 """
1141 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001142
1143 if not ofp_flow_removed.__eq__(self, other): return False
1144 return True
1145
1146 def __ne__(self, other):
1147 """
1148 Return True if self and other do not hold the same data
1149
1150 @param other Other object in comparison
1151
1152 """
1153 return not self.__eq__(other)
1154
1155
1156class get_config_reply(ofp_switch_config):
1157 """
1158 Wrapper class for get_config_reply
1159
1160 OpenFlow message header: length, version, xid, type
1161 @arg length: The total length of the message
1162 @arg version: The OpenFlow version (1)
1163 @arg xid: The transaction ID
1164 @arg type: The message type (OFPT_GET_CONFIG_REPLY=8)
1165
1166 Data members inherited from ofp_switch_config:
Rich Laneb73808c2013-03-11 15:22:23 -07001167 @arg version
1168 @arg type
1169 @arg length
1170 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001171 @arg flags
1172 @arg miss_send_len
1173
1174 """
1175
1176 def __init__(self, **kwargs):
1177 ofp_switch_config.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001178 self.version = OFP_VERSION
1179 self.type = OFPT_GET_CONFIG_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -08001180 for (k, v) in kwargs.items():
1181 if hasattr(self, k):
1182 setattr(self, k, v)
1183 else:
1184 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1185
1186
1187 def pack(self):
1188 """
1189 Pack object into string
1190
1191 @return The packed string which can go on the wire
1192
1193 """
Rich Laneb73808c2013-03-11 15:22:23 -07001194 self.length = len(self)
1195 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001196
1197 packed += ofp_switch_config.pack(self)
1198 return packed
1199
1200 def unpack(self, binary_string):
1201 """
1202 Unpack object from a binary string
1203
1204 @param binary_string The wire protocol byte string holding the object
1205 represented as an array of bytes.
1206 @return The remainder of binary_string that was not parsed.
1207
1208 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001209
1210 binary_string = ofp_switch_config.unpack(self, binary_string)
1211 # Fixme: If no self.data, add check for data remaining
1212 return binary_string
1213
1214 def __len__(self):
1215 """
1216 Return the length of this object once packed into a string
1217
1218 @return An integer representing the number bytes in the packed
1219 string.
1220
1221 """
Rich Laneb73808c2013-03-11 15:22:23 -07001222 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001223
1224 length += ofp_switch_config.__len__(self)
1225 return length
1226
1227 def show(self, prefix=''):
1228 """
1229 Generate a string (with multiple lines) describing the contents
1230 of the object in a readable manner
1231
1232 @param prefix Pre-pended at the beginning of each line.
1233
1234 """
1235
1236 outstr = prefix + 'get_config_reply (OFPT_GET_CONFIG_REPLY)\n'
1237 prefix += ' '
1238 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001239 outstr += ofp_switch_config.show(self, prefix)
1240 return outstr
1241
1242 def __eq__(self, other):
1243 """
1244 Return True if self and other hold the same data
1245
1246 @param other Other object in comparison
1247
1248 """
1249 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001250
1251 if not ofp_switch_config.__eq__(self, other): return False
1252 return True
1253
1254 def __ne__(self, other):
1255 """
1256 Return True if self and other do not hold the same data
1257
1258 @param other Other object in comparison
1259
1260 """
1261 return not self.__eq__(other)
1262
1263
Rich Laneb73808c2013-03-11 15:22:23 -07001264class get_config_request(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -08001265 """
1266 Wrapper class for get_config_request
1267
1268 OpenFlow message header: length, version, xid, type
1269 @arg length: The total length of the message
1270 @arg version: The OpenFlow version (1)
1271 @arg xid: The transaction ID
1272 @arg type: The message type (OFPT_GET_CONFIG_REQUEST=7)
1273
Rich Laneb73808c2013-03-11 15:22:23 -07001274 Data members inherited from ofp_header:
1275 @arg version
1276 @arg type
1277 @arg length
1278 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001279
1280 """
1281
1282 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -07001283 ofp_header.__init__(self)
1284 self.version = OFP_VERSION
1285 self.type = OFPT_GET_CONFIG_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -08001286 for (k, v) in kwargs.items():
1287 if hasattr(self, k):
1288 setattr(self, k, v)
1289 else:
1290 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1291
1292
1293 def pack(self):
1294 """
1295 Pack object into string
1296
1297 @return The packed string which can go on the wire
1298
1299 """
Rich Laneb73808c2013-03-11 15:22:23 -07001300 self.length = len(self)
1301 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001302
Rich Laneb73808c2013-03-11 15:22:23 -07001303 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -08001304 return packed
1305
1306 def unpack(self, binary_string):
1307 """
1308 Unpack object from a binary string
1309
1310 @param binary_string The wire protocol byte string holding the object
1311 represented as an array of bytes.
1312 @return The remainder of binary_string that was not parsed.
1313
1314 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001315
Rich Laneb73808c2013-03-11 15:22:23 -07001316 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -08001317 # Fixme: If no self.data, add check for data remaining
1318 return binary_string
1319
1320 def __len__(self):
1321 """
1322 Return the length of this object once packed into a string
1323
1324 @return An integer representing the number bytes in the packed
1325 string.
1326
1327 """
Rich Laneb73808c2013-03-11 15:22:23 -07001328 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001329
Rich Laneb73808c2013-03-11 15:22:23 -07001330 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -08001331 return length
1332
1333 def show(self, prefix=''):
1334 """
1335 Generate a string (with multiple lines) describing the contents
1336 of the object in a readable manner
1337
1338 @param prefix Pre-pended at the beginning of each line.
1339
1340 """
1341
1342 outstr = prefix + 'get_config_request (OFPT_GET_CONFIG_REQUEST)\n'
1343 prefix += ' '
1344 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -07001345 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -08001346 return outstr
1347
1348 def __eq__(self, other):
1349 """
1350 Return True if self and other hold the same data
1351
1352 @param other Other object in comparison
1353
1354 """
1355 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001356
Rich Laneb73808c2013-03-11 15:22:23 -07001357 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001358 return True
1359
1360 def __ne__(self, other):
1361 """
1362 Return True if self and other do not hold the same data
1363
1364 @param other Other object in comparison
1365
1366 """
1367 return not self.__eq__(other)
1368
1369
Rich Laneb73808c2013-03-11 15:22:23 -07001370class hello(ofp_header):
Rich Lane6242d9f2013-01-06 17:35:39 -08001371 """
1372 Wrapper class for hello
1373
1374 OpenFlow message header: length, version, xid, type
1375 @arg length: The total length of the message
1376 @arg version: The OpenFlow version (1)
1377 @arg xid: The transaction ID
1378 @arg type: The message type (OFPT_HELLO=0)
1379
Rich Laneb73808c2013-03-11 15:22:23 -07001380 Data members inherited from ofp_header:
1381 @arg version
1382 @arg type
1383 @arg length
1384 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001385 @arg data: Binary string following message members
1386
1387 """
1388
1389 def __init__(self, **kwargs):
Rich Laneb73808c2013-03-11 15:22:23 -07001390 ofp_header.__init__(self)
1391 self.version = OFP_VERSION
1392 self.type = OFPT_HELLO
Rich Lane6242d9f2013-01-06 17:35:39 -08001393 self.data = ""
1394 for (k, v) in kwargs.items():
1395 if hasattr(self, k):
1396 setattr(self, k, v)
1397 else:
1398 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1399
1400
1401 def pack(self):
1402 """
1403 Pack object into string
1404
1405 @return The packed string which can go on the wire
1406
1407 """
Rich Laneb73808c2013-03-11 15:22:23 -07001408 self.length = len(self)
1409 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001410
Rich Laneb73808c2013-03-11 15:22:23 -07001411 packed += ofp_header.pack(self)
Rich Lane6242d9f2013-01-06 17:35:39 -08001412 packed += self.data
1413 return packed
1414
1415 def unpack(self, binary_string):
1416 """
1417 Unpack object from a binary string
1418
1419 @param binary_string The wire protocol byte string holding the object
1420 represented as an array of bytes.
1421 @return The remainder of binary_string that was not parsed.
1422
1423 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001424
Rich Laneb73808c2013-03-11 15:22:23 -07001425 binary_string = ofp_header.unpack(self, binary_string)
Rich Lane6242d9f2013-01-06 17:35:39 -08001426 self.data = binary_string
1427 binary_string = ''
1428 return binary_string
1429
1430 def __len__(self):
1431 """
1432 Return the length of this object once packed into a string
1433
1434 @return An integer representing the number bytes in the packed
1435 string.
1436
1437 """
Rich Laneb73808c2013-03-11 15:22:23 -07001438 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001439
Rich Laneb73808c2013-03-11 15:22:23 -07001440 length += ofp_header.__len__(self)
Rich Lane6242d9f2013-01-06 17:35:39 -08001441 length += len(self.data)
1442 return length
1443
1444 def show(self, prefix=''):
1445 """
1446 Generate a string (with multiple lines) describing the contents
1447 of the object in a readable manner
1448
1449 @param prefix Pre-pended at the beginning of each line.
1450
1451 """
1452
1453 outstr = prefix + 'hello (OFPT_HELLO)\n'
1454 prefix += ' '
1455 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -07001456 outstr += ofp_header.show(self, prefix)
Rich Lane6242d9f2013-01-06 17:35:39 -08001457 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
1458 ##@todo Fix this circular reference
1459 # if len(self.data) > 0:
1460 # obj = of_message_parse(self.data)
1461 # if obj != None:
1462 # outstr += obj.show(prefix)
1463 # else:
1464 # outstr += prefix + "Unable to parse data\n"
1465 return outstr
1466
1467 def __eq__(self, other):
1468 """
1469 Return True if self and other hold the same data
1470
1471 @param other Other object in comparison
1472
1473 """
1474 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001475
Rich Laneb73808c2013-03-11 15:22:23 -07001476 if not ofp_header.__eq__(self, other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001477 if self.data != other.data: return False
1478 return True
1479
1480 def __ne__(self, other):
1481 """
1482 Return True if self and other do not hold the same data
1483
1484 @param other Other object in comparison
1485
1486 """
1487 return not self.__eq__(other)
1488
1489
1490class packet_in(ofp_packet_in):
1491 """
1492 Wrapper class for packet_in
1493
1494 OpenFlow message header: length, version, xid, type
1495 @arg length: The total length of the message
1496 @arg version: The OpenFlow version (1)
1497 @arg xid: The transaction ID
1498 @arg type: The message type (OFPT_PACKET_IN=10)
1499
1500 Data members inherited from ofp_packet_in:
Rich Laneb73808c2013-03-11 15:22:23 -07001501 @arg version
1502 @arg type
1503 @arg length
1504 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001505 @arg buffer_id
1506 @arg total_len
1507 @arg in_port
1508 @arg reason
1509 @arg data: Binary string following message members
1510
1511 """
1512
1513 def __init__(self, **kwargs):
1514 ofp_packet_in.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001515 self.version = OFP_VERSION
1516 self.type = OFPT_PACKET_IN
Rich Lane6242d9f2013-01-06 17:35:39 -08001517 self.data = ""
1518 for (k, v) in kwargs.items():
1519 if hasattr(self, k):
1520 setattr(self, k, v)
1521 else:
1522 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1523
1524
1525 def pack(self):
1526 """
1527 Pack object into string
1528
1529 @return The packed string which can go on the wire
1530
1531 """
Rich Laneb73808c2013-03-11 15:22:23 -07001532 self.length = len(self)
1533 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001534
1535 packed += ofp_packet_in.pack(self)
1536 packed += self.data
1537 return packed
1538
1539 def unpack(self, binary_string):
1540 """
1541 Unpack object from a binary string
1542
1543 @param binary_string The wire protocol byte string holding the object
1544 represented as an array of bytes.
1545 @return The remainder of binary_string that was not parsed.
1546
1547 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001548
1549 binary_string = ofp_packet_in.unpack(self, binary_string)
1550 self.data = binary_string
1551 binary_string = ''
1552 return binary_string
1553
1554 def __len__(self):
1555 """
1556 Return the length of this object once packed into a string
1557
1558 @return An integer representing the number bytes in the packed
1559 string.
1560
1561 """
Rich Laneb73808c2013-03-11 15:22:23 -07001562 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001563
1564 length += ofp_packet_in.__len__(self)
1565 length += len(self.data)
1566 return length
1567
1568 def show(self, prefix=''):
1569 """
1570 Generate a string (with multiple lines) describing the contents
1571 of the object in a readable manner
1572
1573 @param prefix Pre-pended at the beginning of each line.
1574
1575 """
1576
1577 outstr = prefix + 'packet_in (OFPT_PACKET_IN)\n'
1578 prefix += ' '
1579 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001580 outstr += ofp_packet_in.show(self, prefix)
1581 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
1582 ##@todo Fix this circular reference
1583 # if len(self.data) > 0:
1584 # obj = of_message_parse(self.data)
1585 # if obj != None:
1586 # outstr += obj.show(prefix)
1587 # else:
1588 # outstr += prefix + "Unable to parse data\n"
1589 return outstr
1590
1591 def __eq__(self, other):
1592 """
1593 Return True if self and other hold the same data
1594
1595 @param other Other object in comparison
1596
1597 """
1598 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001599
1600 if not ofp_packet_in.__eq__(self, other): return False
1601 if self.data != other.data: return False
1602 return True
1603
1604 def __ne__(self, other):
1605 """
1606 Return True if self and other do not hold the same data
1607
1608 @param other Other object in comparison
1609
1610 """
1611 return not self.__eq__(other)
1612
1613
1614class packet_out(ofp_packet_out):
1615 """
1616 Wrapper class for packet_out
1617
1618 OpenFlow message header: length, version, xid, type
1619 @arg length: The total length of the message
1620 @arg version: The OpenFlow version (1)
1621 @arg xid: The transaction ID
1622 @arg type: The message type (OFPT_PACKET_OUT=13)
1623
1624 Data members inherited from ofp_packet_out:
Rich Laneb73808c2013-03-11 15:22:23 -07001625 @arg version
1626 @arg type
1627 @arg length
1628 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001629 @arg buffer_id
1630 @arg in_port
1631 @arg actions_len
1632 @arg actions: Object of type action_list
1633 @arg data: Binary string following message members
1634
1635 """
1636
1637 def __init__(self, **kwargs):
1638 ofp_packet_out.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001639 self.version = OFP_VERSION
1640 self.type = OFPT_PACKET_OUT
Rich Lane6242d9f2013-01-06 17:35:39 -08001641 self.actions = []
1642 self.data = ""
1643 for (k, v) in kwargs.items():
1644 if hasattr(self, k):
1645 setattr(self, k, v)
1646 else:
1647 raise NameError("field %s does not exist in %s" % (k, self.__class__))
Rich Lane6242d9f2013-01-06 17:35:39 -08001648
1649
1650 def pack(self):
1651 """
1652 Pack object into string
1653
1654 @return The packed string which can go on the wire
1655
1656 """
Rich Laneb73808c2013-03-11 15:22:23 -07001657 self.length = len(self)
1658 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001659
Rich Lane62e96852013-03-11 12:04:45 -07001660 self.actions_len = 0
1661 for obj in self.actions:
1662 self.actions_len += len(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08001663 packed += ofp_packet_out.pack(self)
Rich Lane62e96852013-03-11 12:04:45 -07001664 packed += action_list(self.actions).pack()
Rich Lane6242d9f2013-01-06 17:35:39 -08001665 packed += self.data
1666 return packed
1667
1668 def unpack(self, binary_string):
1669 """
1670 Unpack object from a binary string
1671
1672 @param binary_string The wire protocol byte string holding the object
1673 represented as an array of bytes.
1674 @return The remainder of binary_string that was not parsed.
1675
1676 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001677
1678 binary_string = ofp_packet_out.unpack(self, binary_string)
Rich Lane62e96852013-03-11 12:04:45 -07001679 obj = action_list()
1680 binary_string = obj.unpack(binary_string, bytes=self.actions_len)
1681 self.actions = list(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08001682 self.data = binary_string
1683 binary_string = ''
1684 return binary_string
1685
1686 def __len__(self):
1687 """
1688 Return the length of this object once packed into a string
1689
1690 @return An integer representing the number bytes in the packed
1691 string.
1692
1693 """
Rich Laneb73808c2013-03-11 15:22:23 -07001694 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001695
1696 length += ofp_packet_out.__len__(self)
Rich Lane62e96852013-03-11 12:04:45 -07001697 for obj in self.actions:
1698 length += len(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08001699 length += len(self.data)
1700 return length
1701
1702 def show(self, prefix=''):
1703 """
1704 Generate a string (with multiple lines) describing the contents
1705 of the object in a readable manner
1706
1707 @param prefix Pre-pended at the beginning of each line.
1708
1709 """
1710
1711 outstr = prefix + 'packet_out (OFPT_PACKET_OUT)\n'
1712 prefix += ' '
1713 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001714 outstr += ofp_packet_out.show(self, prefix)
1715 outstr += prefix + "List actions\n"
Rich Lanee6ea3fe2013-03-08 17:54:38 -08001716 for obj in self.actions:
1717 outstr += obj.show(prefix + " ")
Rich Lane6242d9f2013-01-06 17:35:39 -08001718 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
1719 ##@todo Fix this circular reference
1720 # if len(self.data) > 0:
1721 # obj = of_message_parse(self.data)
1722 # if obj != None:
1723 # outstr += obj.show(prefix)
1724 # else:
1725 # outstr += prefix + "Unable to parse data\n"
1726 return outstr
1727
1728 def __eq__(self, other):
1729 """
1730 Return True if self and other hold the same data
1731
1732 @param other Other object in comparison
1733
1734 """
1735 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001736
1737 if not ofp_packet_out.__eq__(self, other): return False
1738 if self.data != other.data: return False
1739 if self.actions != other.actions: return False
1740 return True
1741
1742 def __ne__(self, other):
1743 """
1744 Return True if self and other do not hold the same data
1745
1746 @param other Other object in comparison
1747
1748 """
1749 return not self.__eq__(other)
1750
1751
1752class port_mod(ofp_port_mod):
1753 """
1754 Wrapper class for port_mod
1755
1756 OpenFlow message header: length, version, xid, type
1757 @arg length: The total length of the message
1758 @arg version: The OpenFlow version (1)
1759 @arg xid: The transaction ID
1760 @arg type: The message type (OFPT_PORT_MOD=15)
1761
1762 Data members inherited from ofp_port_mod:
Rich Laneb73808c2013-03-11 15:22:23 -07001763 @arg version
1764 @arg type
1765 @arg length
1766 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001767 @arg port_no
1768 @arg hw_addr
1769 @arg config
1770 @arg mask
1771 @arg advertise
1772
1773 """
1774
1775 def __init__(self, **kwargs):
1776 ofp_port_mod.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001777 self.version = OFP_VERSION
1778 self.type = OFPT_PORT_MOD
Rich Lane6242d9f2013-01-06 17:35:39 -08001779 for (k, v) in kwargs.items():
1780 if hasattr(self, k):
1781 setattr(self, k, v)
1782 else:
1783 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1784
1785
1786 def pack(self):
1787 """
1788 Pack object into string
1789
1790 @return The packed string which can go on the wire
1791
1792 """
Rich Laneb73808c2013-03-11 15:22:23 -07001793 self.length = len(self)
1794 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001795
1796 packed += ofp_port_mod.pack(self)
1797 return packed
1798
1799 def unpack(self, binary_string):
1800 """
1801 Unpack object from a binary string
1802
1803 @param binary_string The wire protocol byte string holding the object
1804 represented as an array of bytes.
1805 @return The remainder of binary_string that was not parsed.
1806
1807 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001808
1809 binary_string = ofp_port_mod.unpack(self, binary_string)
1810 # Fixme: If no self.data, add check for data remaining
1811 return binary_string
1812
1813 def __len__(self):
1814 """
1815 Return the length of this object once packed into a string
1816
1817 @return An integer representing the number bytes in the packed
1818 string.
1819
1820 """
Rich Laneb73808c2013-03-11 15:22:23 -07001821 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001822
1823 length += ofp_port_mod.__len__(self)
1824 return length
1825
1826 def show(self, prefix=''):
1827 """
1828 Generate a string (with multiple lines) describing the contents
1829 of the object in a readable manner
1830
1831 @param prefix Pre-pended at the beginning of each line.
1832
1833 """
1834
1835 outstr = prefix + 'port_mod (OFPT_PORT_MOD)\n'
1836 prefix += ' '
1837 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001838 outstr += ofp_port_mod.show(self, prefix)
1839 return outstr
1840
1841 def __eq__(self, other):
1842 """
1843 Return True if self and other hold the same data
1844
1845 @param other Other object in comparison
1846
1847 """
1848 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001849
1850 if not ofp_port_mod.__eq__(self, other): return False
1851 return True
1852
1853 def __ne__(self, other):
1854 """
1855 Return True if self and other do not hold the same data
1856
1857 @param other Other object in comparison
1858
1859 """
1860 return not self.__eq__(other)
1861
1862
1863class port_status(ofp_port_status):
1864 """
1865 Wrapper class for port_status
1866
1867 OpenFlow message header: length, version, xid, type
1868 @arg length: The total length of the message
1869 @arg version: The OpenFlow version (1)
1870 @arg xid: The transaction ID
1871 @arg type: The message type (OFPT_PORT_STATUS=12)
1872
1873 Data members inherited from ofp_port_status:
Rich Laneb73808c2013-03-11 15:22:23 -07001874 @arg version
1875 @arg type
1876 @arg length
1877 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001878 @arg reason
1879 @arg desc
1880
1881 """
1882
1883 def __init__(self, **kwargs):
1884 ofp_port_status.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001885 self.version = OFP_VERSION
1886 self.type = OFPT_PORT_STATUS
Rich Lane6242d9f2013-01-06 17:35:39 -08001887 for (k, v) in kwargs.items():
1888 if hasattr(self, k):
1889 setattr(self, k, v)
1890 else:
1891 raise NameError("field %s does not exist in %s" % (k, self.__class__))
1892
1893
1894 def pack(self):
1895 """
1896 Pack object into string
1897
1898 @return The packed string which can go on the wire
1899
1900 """
Rich Laneb73808c2013-03-11 15:22:23 -07001901 self.length = len(self)
1902 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08001903
1904 packed += ofp_port_status.pack(self)
1905 return packed
1906
1907 def unpack(self, binary_string):
1908 """
1909 Unpack object from a binary string
1910
1911 @param binary_string The wire protocol byte string holding the object
1912 represented as an array of bytes.
1913 @return The remainder of binary_string that was not parsed.
1914
1915 """
Rich Lane6242d9f2013-01-06 17:35:39 -08001916
1917 binary_string = ofp_port_status.unpack(self, binary_string)
1918 # Fixme: If no self.data, add check for data remaining
1919 return binary_string
1920
1921 def __len__(self):
1922 """
1923 Return the length of this object once packed into a string
1924
1925 @return An integer representing the number bytes in the packed
1926 string.
1927
1928 """
Rich Laneb73808c2013-03-11 15:22:23 -07001929 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08001930
1931 length += ofp_port_status.__len__(self)
1932 return length
1933
1934 def show(self, prefix=''):
1935 """
1936 Generate a string (with multiple lines) describing the contents
1937 of the object in a readable manner
1938
1939 @param prefix Pre-pended at the beginning of each line.
1940
1941 """
1942
1943 outstr = prefix + 'port_status (OFPT_PORT_STATUS)\n'
1944 prefix += ' '
1945 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08001946 outstr += ofp_port_status.show(self, prefix)
1947 return outstr
1948
1949 def __eq__(self, other):
1950 """
1951 Return True if self and other hold the same data
1952
1953 @param other Other object in comparison
1954
1955 """
1956 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08001957
1958 if not ofp_port_status.__eq__(self, other): return False
1959 return True
1960
1961 def __ne__(self, other):
1962 """
1963 Return True if self and other do not hold the same data
1964
1965 @param other Other object in comparison
1966
1967 """
1968 return not self.__eq__(other)
1969
1970
1971class queue_get_config_reply(ofp_queue_get_config_reply):
1972 """
1973 Wrapper class for queue_get_config_reply
1974
1975 OpenFlow message header: length, version, xid, type
1976 @arg length: The total length of the message
1977 @arg version: The OpenFlow version (1)
1978 @arg xid: The transaction ID
1979 @arg type: The message type (OFPT_QUEUE_GET_CONFIG_REPLY=21)
1980
1981 Data members inherited from ofp_queue_get_config_reply:
Rich Laneb73808c2013-03-11 15:22:23 -07001982 @arg version
1983 @arg type
1984 @arg length
1985 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08001986 @arg port
1987 @arg queues: Variable length array of TBD
1988
1989 """
1990
1991 def __init__(self, **kwargs):
1992 ofp_queue_get_config_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07001993 self.version = OFP_VERSION
1994 self.type = OFPT_QUEUE_GET_CONFIG_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -08001995 self.queues = []
1996 for (k, v) in kwargs.items():
1997 if hasattr(self, k):
1998 setattr(self, k, v)
1999 else:
2000 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2001
2002
2003 def pack(self):
2004 """
2005 Pack object into string
2006
2007 @return The packed string which can go on the wire
2008
2009 """
Rich Laneb73808c2013-03-11 15:22:23 -07002010 self.length = len(self)
2011 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002012
2013 packed += ofp_queue_get_config_reply.pack(self)
2014 for obj in self.queues:
2015 packed += obj.pack()
2016 return packed
2017
2018 def unpack(self, binary_string):
2019 """
2020 Unpack object from a binary string
2021
2022 @param binary_string The wire protocol byte string holding the object
2023 represented as an array of bytes.
2024 @return The remainder of binary_string that was not parsed.
2025
2026 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002027
2028 binary_string = ofp_queue_get_config_reply.unpack(self, binary_string)
2029 for obj in self.queues:
2030 binary_string = obj.unpack(binary_string)
2031 # Fixme: If no self.data, add check for data remaining
2032 return binary_string
2033
2034 def __len__(self):
2035 """
2036 Return the length of this object once packed into a string
2037
2038 @return An integer representing the number bytes in the packed
2039 string.
2040
2041 """
Rich Laneb73808c2013-03-11 15:22:23 -07002042 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002043
2044 length += ofp_queue_get_config_reply.__len__(self)
2045 for obj in self.queues:
2046 length += len(obj)
2047 return length
2048
2049 def show(self, prefix=''):
2050 """
2051 Generate a string (with multiple lines) describing the contents
2052 of the object in a readable manner
2053
2054 @param prefix Pre-pended at the beginning of each line.
2055
2056 """
2057
2058 outstr = prefix + 'queue_get_config_reply (OFPT_QUEUE_GET_CONFIG_REPLY)\n'
2059 prefix += ' '
2060 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002061 outstr += ofp_queue_get_config_reply.show(self, prefix)
2062 outstr += prefix + "Array queues\n"
2063 for obj in self.queues:
2064 outstr += obj.show(prefix + ' ')
2065 return outstr
2066
2067 def __eq__(self, other):
2068 """
2069 Return True if self and other hold the same data
2070
2071 @param other Other object in comparison
2072
2073 """
2074 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002075
2076 if not ofp_queue_get_config_reply.__eq__(self, other): return False
2077 if self.queues != other.queues: return False
2078 return True
2079
2080 def __ne__(self, other):
2081 """
2082 Return True if self and other do not hold the same data
2083
2084 @param other Other object in comparison
2085
2086 """
2087 return not self.__eq__(other)
2088
2089
2090class queue_get_config_request(ofp_queue_get_config_request):
2091 """
2092 Wrapper class for queue_get_config_request
2093
2094 OpenFlow message header: length, version, xid, type
2095 @arg length: The total length of the message
2096 @arg version: The OpenFlow version (1)
2097 @arg xid: The transaction ID
2098 @arg type: The message type (OFPT_QUEUE_GET_CONFIG_REQUEST=20)
2099
2100 Data members inherited from ofp_queue_get_config_request:
Rich Laneb73808c2013-03-11 15:22:23 -07002101 @arg version
2102 @arg type
2103 @arg length
2104 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08002105 @arg port
2106
2107 """
2108
2109 def __init__(self, **kwargs):
2110 ofp_queue_get_config_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002111 self.version = OFP_VERSION
2112 self.type = OFPT_QUEUE_GET_CONFIG_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -08002113 for (k, v) in kwargs.items():
2114 if hasattr(self, k):
2115 setattr(self, k, v)
2116 else:
2117 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2118
2119
2120 def pack(self):
2121 """
2122 Pack object into string
2123
2124 @return The packed string which can go on the wire
2125
2126 """
Rich Laneb73808c2013-03-11 15:22:23 -07002127 self.length = len(self)
2128 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002129
2130 packed += ofp_queue_get_config_request.pack(self)
2131 return packed
2132
2133 def unpack(self, binary_string):
2134 """
2135 Unpack object from a binary string
2136
2137 @param binary_string The wire protocol byte string holding the object
2138 represented as an array of bytes.
2139 @return The remainder of binary_string that was not parsed.
2140
2141 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002142
2143 binary_string = ofp_queue_get_config_request.unpack(self, binary_string)
2144 # Fixme: If no self.data, add check for data remaining
2145 return binary_string
2146
2147 def __len__(self):
2148 """
2149 Return the length of this object once packed into a string
2150
2151 @return An integer representing the number bytes in the packed
2152 string.
2153
2154 """
Rich Laneb73808c2013-03-11 15:22:23 -07002155 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002156
2157 length += ofp_queue_get_config_request.__len__(self)
2158 return length
2159
2160 def show(self, prefix=''):
2161 """
2162 Generate a string (with multiple lines) describing the contents
2163 of the object in a readable manner
2164
2165 @param prefix Pre-pended at the beginning of each line.
2166
2167 """
2168
2169 outstr = prefix + 'queue_get_config_request (OFPT_QUEUE_GET_CONFIG_REQUEST)\n'
2170 prefix += ' '
2171 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002172 outstr += ofp_queue_get_config_request.show(self, prefix)
2173 return outstr
2174
2175 def __eq__(self, other):
2176 """
2177 Return True if self and other hold the same data
2178
2179 @param other Other object in comparison
2180
2181 """
2182 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002183
2184 if not ofp_queue_get_config_request.__eq__(self, other): return False
2185 return True
2186
2187 def __ne__(self, other):
2188 """
2189 Return True if self and other do not hold the same data
2190
2191 @param other Other object in comparison
2192
2193 """
2194 return not self.__eq__(other)
2195
2196
2197class set_config(ofp_switch_config):
2198 """
2199 Wrapper class for set_config
2200
2201 OpenFlow message header: length, version, xid, type
2202 @arg length: The total length of the message
2203 @arg version: The OpenFlow version (1)
2204 @arg xid: The transaction ID
2205 @arg type: The message type (OFPT_SET_CONFIG=9)
2206
2207 Data members inherited from ofp_switch_config:
Rich Laneb73808c2013-03-11 15:22:23 -07002208 @arg version
2209 @arg type
2210 @arg length
2211 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08002212 @arg flags
2213 @arg miss_send_len
2214
2215 """
2216
2217 def __init__(self, **kwargs):
2218 ofp_switch_config.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002219 self.version = OFP_VERSION
2220 self.type = OFPT_SET_CONFIG
Rich Lane6242d9f2013-01-06 17:35:39 -08002221 for (k, v) in kwargs.items():
2222 if hasattr(self, k):
2223 setattr(self, k, v)
2224 else:
2225 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2226
2227
2228 def pack(self):
2229 """
2230 Pack object into string
2231
2232 @return The packed string which can go on the wire
2233
2234 """
Rich Laneb73808c2013-03-11 15:22:23 -07002235 self.length = len(self)
2236 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002237
2238 packed += ofp_switch_config.pack(self)
2239 return packed
2240
2241 def unpack(self, binary_string):
2242 """
2243 Unpack object from a binary string
2244
2245 @param binary_string The wire protocol byte string holding the object
2246 represented as an array of bytes.
2247 @return The remainder of binary_string that was not parsed.
2248
2249 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002250
2251 binary_string = ofp_switch_config.unpack(self, binary_string)
2252 # Fixme: If no self.data, add check for data remaining
2253 return binary_string
2254
2255 def __len__(self):
2256 """
2257 Return the length of this object once packed into a string
2258
2259 @return An integer representing the number bytes in the packed
2260 string.
2261
2262 """
Rich Laneb73808c2013-03-11 15:22:23 -07002263 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002264
2265 length += ofp_switch_config.__len__(self)
2266 return length
2267
2268 def show(self, prefix=''):
2269 """
2270 Generate a string (with multiple lines) describing the contents
2271 of the object in a readable manner
2272
2273 @param prefix Pre-pended at the beginning of each line.
2274
2275 """
2276
2277 outstr = prefix + 'set_config (OFPT_SET_CONFIG)\n'
2278 prefix += ' '
2279 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002280 outstr += ofp_switch_config.show(self, prefix)
2281 return outstr
2282
2283 def __eq__(self, other):
2284 """
2285 Return True if self and other hold the same data
2286
2287 @param other Other object in comparison
2288
2289 """
2290 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002291
2292 if not ofp_switch_config.__eq__(self, other): return False
2293 return True
2294
2295 def __ne__(self, other):
2296 """
2297 Return True if self and other do not hold the same data
2298
2299 @param other Other object in comparison
2300
2301 """
2302 return not self.__eq__(other)
2303
2304
2305class stats_reply(ofp_stats_reply):
2306 """
2307 Wrapper class for stats_reply
2308
2309 OpenFlow message header: length, version, xid, type
2310 @arg length: The total length of the message
2311 @arg version: The OpenFlow version (1)
2312 @arg xid: The transaction ID
2313 @arg type: The message type (OFPT_STATS_REPLY=17)
2314
2315 Data members inherited from ofp_stats_reply:
Rich Laneb73808c2013-03-11 15:22:23 -07002316 @arg version
2317 @arg type
2318 @arg length
2319 @arg xid
Rich Lane7c7342a2013-03-11 14:16:58 -07002320 @arg stats_type
Rich Lane6242d9f2013-01-06 17:35:39 -08002321 @arg flags
2322
2323 """
2324
2325 def __init__(self, **kwargs):
2326 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002327 self.version = OFP_VERSION
2328 self.type = OFPT_STATS_REPLY
Rich Lane6242d9f2013-01-06 17:35:39 -08002329 for (k, v) in kwargs.items():
2330 if hasattr(self, k):
2331 setattr(self, k, v)
2332 else:
2333 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2334
2335
2336 def pack(self):
2337 """
2338 Pack object into string
2339
2340 @return The packed string which can go on the wire
2341
2342 """
Rich Laneb73808c2013-03-11 15:22:23 -07002343 self.length = len(self)
2344 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002345
2346 packed += ofp_stats_reply.pack(self)
2347 return packed
2348
2349 def unpack(self, binary_string):
2350 """
2351 Unpack object from a binary string
2352
2353 @param binary_string The wire protocol byte string holding the object
2354 represented as an array of bytes.
2355 @return The remainder of binary_string that was not parsed.
2356
2357 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002358
2359 binary_string = ofp_stats_reply.unpack(self, binary_string)
2360 # Fixme: If no self.data, add check for data remaining
2361 return binary_string
2362
2363 def __len__(self):
2364 """
2365 Return the length of this object once packed into a string
2366
2367 @return An integer representing the number bytes in the packed
2368 string.
2369
2370 """
Rich Laneb73808c2013-03-11 15:22:23 -07002371 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002372
2373 length += ofp_stats_reply.__len__(self)
2374 return length
2375
2376 def show(self, prefix=''):
2377 """
2378 Generate a string (with multiple lines) describing the contents
2379 of the object in a readable manner
2380
2381 @param prefix Pre-pended at the beginning of each line.
2382
2383 """
2384
2385 outstr = prefix + 'stats_reply (OFPT_STATS_REPLY)\n'
2386 prefix += ' '
2387 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002388 outstr += ofp_stats_reply.show(self, prefix)
2389 return outstr
2390
2391 def __eq__(self, other):
2392 """
2393 Return True if self and other hold the same data
2394
2395 @param other Other object in comparison
2396
2397 """
2398 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002399
2400 if not ofp_stats_reply.__eq__(self, other): return False
2401 return True
2402
2403 def __ne__(self, other):
2404 """
2405 Return True if self and other do not hold the same data
2406
2407 @param other Other object in comparison
2408
2409 """
2410 return not self.__eq__(other)
2411
2412
2413class stats_request(ofp_stats_request):
2414 """
2415 Wrapper class for stats_request
2416
2417 OpenFlow message header: length, version, xid, type
2418 @arg length: The total length of the message
2419 @arg version: The OpenFlow version (1)
2420 @arg xid: The transaction ID
2421 @arg type: The message type (OFPT_STATS_REQUEST=16)
2422
2423 Data members inherited from ofp_stats_request:
Rich Laneb73808c2013-03-11 15:22:23 -07002424 @arg version
2425 @arg type
2426 @arg length
2427 @arg xid
Rich Lane7c7342a2013-03-11 14:16:58 -07002428 @arg stats_type
Rich Lane6242d9f2013-01-06 17:35:39 -08002429 @arg flags
2430
2431 """
2432
2433 def __init__(self, **kwargs):
2434 ofp_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002435 self.version = OFP_VERSION
2436 self.type = OFPT_STATS_REQUEST
Rich Lane6242d9f2013-01-06 17:35:39 -08002437 for (k, v) in kwargs.items():
2438 if hasattr(self, k):
2439 setattr(self, k, v)
2440 else:
2441 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2442
2443
2444 def pack(self):
2445 """
2446 Pack object into string
2447
2448 @return The packed string which can go on the wire
2449
2450 """
Rich Laneb73808c2013-03-11 15:22:23 -07002451 self.length = len(self)
2452 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002453
2454 packed += ofp_stats_request.pack(self)
2455 return packed
2456
2457 def unpack(self, binary_string):
2458 """
2459 Unpack object from a binary string
2460
2461 @param binary_string The wire protocol byte string holding the object
2462 represented as an array of bytes.
2463 @return The remainder of binary_string that was not parsed.
2464
2465 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002466
2467 binary_string = ofp_stats_request.unpack(self, binary_string)
2468 # Fixme: If no self.data, add check for data remaining
2469 return binary_string
2470
2471 def __len__(self):
2472 """
2473 Return the length of this object once packed into a string
2474
2475 @return An integer representing the number bytes in the packed
2476 string.
2477
2478 """
Rich Laneb73808c2013-03-11 15:22:23 -07002479 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002480
2481 length += ofp_stats_request.__len__(self)
2482 return length
2483
2484 def show(self, prefix=''):
2485 """
2486 Generate a string (with multiple lines) describing the contents
2487 of the object in a readable manner
2488
2489 @param prefix Pre-pended at the beginning of each line.
2490
2491 """
2492
2493 outstr = prefix + 'stats_request (OFPT_STATS_REQUEST)\n'
2494 prefix += ' '
2495 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002496 outstr += ofp_stats_request.show(self, prefix)
2497 return outstr
2498
2499 def __eq__(self, other):
2500 """
2501 Return True if self and other hold the same data
2502
2503 @param other Other object in comparison
2504
2505 """
2506 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002507
2508 if not ofp_stats_request.__eq__(self, other): return False
2509 return True
2510
2511 def __ne__(self, other):
2512 """
2513 Return True if self and other do not hold the same data
2514
2515 @param other Other object in comparison
2516
2517 """
2518 return not self.__eq__(other)
2519
2520
2521class vendor(ofp_vendor_header):
2522 """
2523 Wrapper class for vendor
2524
2525 OpenFlow message header: length, version, xid, type
2526 @arg length: The total length of the message
2527 @arg version: The OpenFlow version (1)
2528 @arg xid: The transaction ID
2529 @arg type: The message type (OFPT_VENDOR=4)
2530
2531 Data members inherited from ofp_vendor_header:
Rich Laneb73808c2013-03-11 15:22:23 -07002532 @arg version
2533 @arg type
2534 @arg length
2535 @arg xid
Rich Lane6242d9f2013-01-06 17:35:39 -08002536 @arg vendor
2537 @arg data: Binary string following message members
2538
2539 """
2540
2541 def __init__(self, **kwargs):
2542 ofp_vendor_header.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002543 self.version = OFP_VERSION
2544 self.type = OFPT_VENDOR
Rich Lane6242d9f2013-01-06 17:35:39 -08002545 self.data = ""
2546 for (k, v) in kwargs.items():
2547 if hasattr(self, k):
2548 setattr(self, k, v)
2549 else:
2550 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2551
2552
2553 def pack(self):
2554 """
2555 Pack object into string
2556
2557 @return The packed string which can go on the wire
2558
2559 """
Rich Laneb73808c2013-03-11 15:22:23 -07002560 self.length = len(self)
2561 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002562
2563 packed += ofp_vendor_header.pack(self)
2564 packed += self.data
2565 return packed
2566
2567 def unpack(self, binary_string):
2568 """
2569 Unpack object from a binary string
2570
2571 @param binary_string The wire protocol byte string holding the object
2572 represented as an array of bytes.
2573 @return The remainder of binary_string that was not parsed.
2574
2575 """
Rich Lane6242d9f2013-01-06 17:35:39 -08002576
2577 binary_string = ofp_vendor_header.unpack(self, binary_string)
2578 self.data = binary_string
2579 binary_string = ''
2580 return binary_string
2581
2582 def __len__(self):
2583 """
2584 Return the length of this object once packed into a string
2585
2586 @return An integer representing the number bytes in the packed
2587 string.
2588
2589 """
Rich Laneb73808c2013-03-11 15:22:23 -07002590 length = 0
Rich Lane6242d9f2013-01-06 17:35:39 -08002591
2592 length += ofp_vendor_header.__len__(self)
2593 length += len(self.data)
2594 return length
2595
2596 def show(self, prefix=''):
2597 """
2598 Generate a string (with multiple lines) describing the contents
2599 of the object in a readable manner
2600
2601 @param prefix Pre-pended at the beginning of each line.
2602
2603 """
2604
2605 outstr = prefix + 'vendor (OFPT_VENDOR)\n'
2606 prefix += ' '
2607 outstr += prefix + 'ofp header\n'
Rich Lane6242d9f2013-01-06 17:35:39 -08002608 outstr += ofp_vendor_header.show(self, prefix)
2609 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
2610 ##@todo Fix this circular reference
2611 # if len(self.data) > 0:
2612 # obj = of_message_parse(self.data)
2613 # if obj != None:
2614 # outstr += obj.show(prefix)
2615 # else:
2616 # outstr += prefix + "Unable to parse data\n"
2617 return outstr
2618
2619 def __eq__(self, other):
2620 """
2621 Return True if self and other hold the same data
2622
2623 @param other Other object in comparison
2624
2625 """
2626 if type(self) != type(other): return False
Rich Lane6242d9f2013-01-06 17:35:39 -08002627
2628 if not ofp_vendor_header.__eq__(self, other): return False
2629 if self.data != other.data: return False
2630 return True
2631
2632 def __ne__(self, other):
2633 """
2634 Return True if self and other do not hold the same data
2635
2636 @param other Other object in comparison
2637
2638 """
2639 return not self.__eq__(other)
2640
2641
2642
2643################################################################
2644#
2645# Stats request and reply subclass definitions
2646#
2647################################################################
2648
2649
2650# Stats request bodies for desc and table stats are not defined in the
2651# OpenFlow header; We define them here. They are empty classes, really
2652
2653class ofp_desc_stats_request:
2654 """
2655 Forced definition of ofp_desc_stats_request (empty class)
2656 """
2657 def __init__(self):
2658 pass
2659 def pack(self, assertstruct=True):
2660 return ""
2661 def unpack(self, binary_string):
2662 return binary_string
2663 def __len__(self):
2664 return 0
2665 def show(self, prefix=''):
2666 return prefix + "ofp_desc_stats_request (empty)\n"
2667 def __eq__(self, other):
2668 return type(self) == type(other)
2669 def __ne__(self, other):
2670 return type(self) != type(other)
2671
2672OFP_DESC_STATS_REQUEST_BYTES = 0
2673
2674class ofp_table_stats_request:
2675 """
2676 Forced definition of ofp_table_stats_request (empty class)
2677 """
2678 def __init__(self):
2679 pass
2680 def pack(self, assertstruct=True):
2681 return ""
2682 def unpack(self, binary_string):
2683 return binary_string
2684 def __len__(self):
2685 return 0
2686 def show(self, prefix=''):
2687 return prefix + "ofp_table_stats_request (empty)\n"
2688 def __eq__(self, other):
2689 return type(self) == type(other)
2690 def __ne__(self, other):
2691 return type(self) != type(other)
2692
2693OFP_TABLE_STATS_REQUEST_BYTES = 0
2694
2695
2696
2697# Stats entries define the content of one element in a stats
2698# reply for the indicated type; define _entry for consistency
2699
2700aggregate_stats_entry = ofp_aggregate_stats_reply
2701desc_stats_entry = ofp_desc_stats
2702port_stats_entry = ofp_port_stats
2703queue_stats_entry = ofp_queue_stats
2704table_stats_entry = ofp_table_stats
2705
2706
2707#
2708# Flow stats entry contains an action list of variable length, so
2709# it is done by hand
2710#
2711
2712class flow_stats_entry(ofp_flow_stats):
2713 """
2714 Special case flow stats entry to handle action list object
2715 """
2716 def __init__(self):
2717 ofp_flow_stats.__init__(self)
Rich Lane62e96852013-03-11 12:04:45 -07002718 self.actions = []
Rich Lane6242d9f2013-01-06 17:35:39 -08002719
2720 def pack(self, assertstruct=True):
2721 self.length = len(self)
2722 packed = ofp_flow_stats.pack(self, assertstruct)
Rich Lane62e96852013-03-11 12:04:45 -07002723 packed += action_list(self.actions).pack()
Rich Lane6242d9f2013-01-06 17:35:39 -08002724 if len(packed) != self.length:
2725 print("ERROR: flow_stats_entry pack length not equal",
2726 self.length, len(packed))
2727 return packed
2728
2729 def unpack(self, binary_string):
2730 binary_string = ofp_flow_stats.unpack(self, binary_string)
2731 ai_len = self.length - OFP_FLOW_STATS_BYTES
2732 if ai_len < 0:
2733 print("ERROR: flow_stats_entry unpack length too small",
2734 self.length)
Rich Lane62e96852013-03-11 12:04:45 -07002735 obj = action_list()
2736 binary_string = obj.unpack(binary_string, bytes=ai_len)
2737 self.actions = list(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08002738 return binary_string
2739
2740 def __len__(self):
2741 return OFP_FLOW_STATS_BYTES + len(self.actions)
2742
2743 def show(self, prefix=''):
2744 outstr = prefix + "flow_stats_entry\n"
2745 outstr += ofp_flow_stats.show(self, prefix + ' ')
Rich Lanee6ea3fe2013-03-08 17:54:38 -08002746 outstr += prefix + "List actions\n"
2747 for obj in self.actions:
2748 outstr += obj.show(prefix + ' ')
Rich Lane6242d9f2013-01-06 17:35:39 -08002749 return outstr
2750
2751 def __eq__(self, other):
2752 if type(self) != type(other): return False
2753 return (ofp_flow_stats.__eq__(self, other) and
2754 self.actions == other.actions)
2755
2756 def __ne__(self, other): return not self.__eq__(other)
2757
2758
2759class aggregate_stats_request(ofp_stats_request, ofp_aggregate_stats_request):
2760 """
2761 Wrapper class for aggregate stats request message
2762 """
2763 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08002764 ofp_stats_request.__init__(self)
2765 ofp_aggregate_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002766 self.version = OFP_VERSION
2767 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07002768 self.stats_type = OFPST_AGGREGATE
Rich Lane6242d9f2013-01-06 17:35:39 -08002769 for (k, v) in kwargs.items():
2770 if hasattr(self, k):
2771 setattr(self, k, v)
2772 else:
2773 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2774
2775 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07002776 self.length = len(self)
2777 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002778 packed += ofp_stats_request.pack(self)
2779 packed += ofp_aggregate_stats_request.pack(self)
2780 return packed
2781
2782 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08002783 binary_string = ofp_stats_request.unpack(self, binary_string)
2784 binary_string = ofp_aggregate_stats_request.unpack(self, binary_string)
2785 if len(binary_string) != 0:
2786 print "ERROR unpacking aggregate: extra data"
2787 return binary_string
2788
2789 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07002790 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08002791 OFP_AGGREGATE_STATS_REQUEST_BYTES
2792
2793 def show(self, prefix=''):
2794 outstr = prefix + "aggregate_stats_request\n"
2795 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08002796 outstr += ofp_stats_request.show(self)
2797 outstr += ofp_aggregate_stats_request.show(self)
2798 return outstr
2799
2800 def __eq__(self, other):
2801 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07002802 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08002803 ofp_aggregate_stats_request.__eq__(self, other))
2804
2805 def __ne__(self, other): return not self.__eq__(other)
2806
2807
2808class aggregate_stats_reply(ofp_stats_reply):
2809 """
2810 Wrapper class for aggregate stats reply
2811 """
2812 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08002813 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002814 self.version = OFP_VERSION
2815 self.type = OFPT_STATS_REPLY
2816 self.stats_type = OFPST_AGGREGATE
Rich Lane6242d9f2013-01-06 17:35:39 -08002817 # stats: Array of type aggregate_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07002818 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08002819
2820 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07002821 self.length = len(self)
2822 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002823 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002824 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002825 packed += obj.pack()
2826 return packed
2827
2828 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08002829 binary_string = ofp_stats_reply.unpack(self, binary_string)
2830 dummy = aggregate_stats_entry()
2831 while len(binary_string) >= len(dummy):
2832 obj = aggregate_stats_entry()
2833 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002834 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08002835 if len(binary_string) != 0:
2836 print "ERROR unpacking aggregate stats string: extra bytes"
2837 return binary_string
2838
2839 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07002840 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07002841 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002842 length += len(obj)
2843 return length
2844
2845 def show(self, prefix=''):
2846 outstr = prefix + "aggregate_stats_reply\n"
2847 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08002848 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002849 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
2850 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002851 outstr += obj.show()
2852 return outstr
2853
2854 def __eq__(self, other):
2855 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07002856 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07002857 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08002858
2859 def __ne__(self, other): return not self.__eq__(other)
2860
2861
2862class desc_stats_request(ofp_stats_request, ofp_desc_stats_request):
2863 """
2864 Wrapper class for desc stats request message
2865 """
2866 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08002867 ofp_stats_request.__init__(self)
2868 ofp_desc_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002869 self.version = OFP_VERSION
2870 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07002871 self.stats_type = OFPST_DESC
Rich Lane6242d9f2013-01-06 17:35:39 -08002872 for (k, v) in kwargs.items():
2873 if hasattr(self, k):
2874 setattr(self, k, v)
2875 else:
2876 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2877
2878 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07002879 self.length = len(self)
2880 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002881 packed += ofp_stats_request.pack(self)
2882 packed += ofp_desc_stats_request.pack(self)
2883 return packed
2884
2885 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08002886 binary_string = ofp_stats_request.unpack(self, binary_string)
2887 binary_string = ofp_desc_stats_request.unpack(self, binary_string)
2888 if len(binary_string) != 0:
2889 print "ERROR unpacking desc: extra data"
2890 return binary_string
2891
2892 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07002893 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08002894 OFP_DESC_STATS_REQUEST_BYTES
2895
2896 def show(self, prefix=''):
2897 outstr = prefix + "desc_stats_request\n"
2898 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08002899 outstr += ofp_stats_request.show(self)
2900 outstr += ofp_desc_stats_request.show(self)
2901 return outstr
2902
2903 def __eq__(self, other):
2904 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07002905 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08002906 ofp_desc_stats_request.__eq__(self, other))
2907
2908 def __ne__(self, other): return not self.__eq__(other)
2909
2910
2911class desc_stats_reply(ofp_stats_reply):
2912 """
2913 Wrapper class for desc stats reply
2914 """
2915 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08002916 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002917 self.version = OFP_VERSION
2918 self.type = OFPT_STATS_REPLY
2919 self.stats_type = OFPST_DESC
Rich Lane6242d9f2013-01-06 17:35:39 -08002920 # stats: Array of type desc_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07002921 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08002922
2923 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07002924 self.length = len(self)
2925 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002926 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002927 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002928 packed += obj.pack()
2929 return packed
2930
2931 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08002932 binary_string = ofp_stats_reply.unpack(self, binary_string)
2933 dummy = desc_stats_entry()
2934 while len(binary_string) >= len(dummy):
2935 obj = desc_stats_entry()
2936 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002937 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08002938 if len(binary_string) != 0:
2939 print "ERROR unpacking desc stats string: extra bytes"
2940 return binary_string
2941
2942 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07002943 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07002944 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002945 length += len(obj)
2946 return length
2947
2948 def show(self, prefix=''):
2949 outstr = prefix + "desc_stats_reply\n"
2950 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08002951 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07002952 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
2953 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08002954 outstr += obj.show()
2955 return outstr
2956
2957 def __eq__(self, other):
2958 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07002959 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07002960 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08002961
2962 def __ne__(self, other): return not self.__eq__(other)
2963
2964
2965class flow_stats_request(ofp_stats_request, ofp_flow_stats_request):
2966 """
2967 Wrapper class for flow stats request message
2968 """
2969 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08002970 ofp_stats_request.__init__(self)
2971 ofp_flow_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07002972 self.version = OFP_VERSION
2973 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07002974 self.stats_type = OFPST_FLOW
Rich Lane6242d9f2013-01-06 17:35:39 -08002975 for (k, v) in kwargs.items():
2976 if hasattr(self, k):
2977 setattr(self, k, v)
2978 else:
2979 raise NameError("field %s does not exist in %s" % (k, self.__class__))
2980
2981 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07002982 self.length = len(self)
2983 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08002984 packed += ofp_stats_request.pack(self)
2985 packed += ofp_flow_stats_request.pack(self)
2986 return packed
2987
2988 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08002989 binary_string = ofp_stats_request.unpack(self, binary_string)
2990 binary_string = ofp_flow_stats_request.unpack(self, binary_string)
2991 if len(binary_string) != 0:
2992 print "ERROR unpacking flow: extra data"
2993 return binary_string
2994
2995 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07002996 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08002997 OFP_FLOW_STATS_REQUEST_BYTES
2998
2999 def show(self, prefix=''):
3000 outstr = prefix + "flow_stats_request\n"
3001 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003002 outstr += ofp_stats_request.show(self)
3003 outstr += ofp_flow_stats_request.show(self)
3004 return outstr
3005
3006 def __eq__(self, other):
3007 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003008 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08003009 ofp_flow_stats_request.__eq__(self, other))
3010
3011 def __ne__(self, other): return not self.__eq__(other)
3012
3013
3014class flow_stats_reply(ofp_stats_reply):
3015 """
3016 Wrapper class for flow stats reply
3017 """
3018 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08003019 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003020 self.version = OFP_VERSION
3021 self.type = OFPT_STATS_REPLY
3022 self.stats_type = OFPST_FLOW
Rich Lane6242d9f2013-01-06 17:35:39 -08003023 # stats: Array of type flow_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07003024 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08003025
3026 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003027 self.length = len(self)
3028 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003029 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003030 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003031 packed += obj.pack()
3032 return packed
3033
3034 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003035 binary_string = ofp_stats_reply.unpack(self, binary_string)
3036 dummy = flow_stats_entry()
3037 while len(binary_string) >= len(dummy):
3038 obj = flow_stats_entry()
3039 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003040 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08003041 if len(binary_string) != 0:
3042 print "ERROR unpacking flow stats string: extra bytes"
3043 return binary_string
3044
3045 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003046 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07003047 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003048 length += len(obj)
3049 return length
3050
3051 def show(self, prefix=''):
3052 outstr = prefix + "flow_stats_reply\n"
3053 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003054 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003055 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
3056 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003057 outstr += obj.show()
3058 return outstr
3059
3060 def __eq__(self, other):
3061 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003062 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07003063 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08003064
3065 def __ne__(self, other): return not self.__eq__(other)
3066
3067
3068class port_stats_request(ofp_stats_request, ofp_port_stats_request):
3069 """
3070 Wrapper class for port stats request message
3071 """
3072 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08003073 ofp_stats_request.__init__(self)
3074 ofp_port_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003075 self.version = OFP_VERSION
3076 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07003077 self.stats_type = OFPST_PORT
Rich Lane6242d9f2013-01-06 17:35:39 -08003078 for (k, v) in kwargs.items():
3079 if hasattr(self, k):
3080 setattr(self, k, v)
3081 else:
3082 raise NameError("field %s does not exist in %s" % (k, self.__class__))
3083
3084 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003085 self.length = len(self)
3086 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003087 packed += ofp_stats_request.pack(self)
3088 packed += ofp_port_stats_request.pack(self)
3089 return packed
3090
3091 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003092 binary_string = ofp_stats_request.unpack(self, binary_string)
3093 binary_string = ofp_port_stats_request.unpack(self, binary_string)
3094 if len(binary_string) != 0:
3095 print "ERROR unpacking port: extra data"
3096 return binary_string
3097
3098 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003099 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08003100 OFP_PORT_STATS_REQUEST_BYTES
3101
3102 def show(self, prefix=''):
3103 outstr = prefix + "port_stats_request\n"
3104 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003105 outstr += ofp_stats_request.show(self)
3106 outstr += ofp_port_stats_request.show(self)
3107 return outstr
3108
3109 def __eq__(self, other):
3110 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003111 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08003112 ofp_port_stats_request.__eq__(self, other))
3113
3114 def __ne__(self, other): return not self.__eq__(other)
3115
3116
3117class port_stats_reply(ofp_stats_reply):
3118 """
3119 Wrapper class for port stats reply
3120 """
3121 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08003122 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003123 self.version = OFP_VERSION
3124 self.type = OFPT_STATS_REPLY
3125 self.stats_type = OFPST_PORT
Rich Lane6242d9f2013-01-06 17:35:39 -08003126 # stats: Array of type port_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07003127 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08003128
3129 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003130 self.length = len(self)
3131 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003132 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003133 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003134 packed += obj.pack()
3135 return packed
3136
3137 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003138 binary_string = ofp_stats_reply.unpack(self, binary_string)
3139 dummy = port_stats_entry()
3140 while len(binary_string) >= len(dummy):
3141 obj = port_stats_entry()
3142 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003143 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08003144 if len(binary_string) != 0:
3145 print "ERROR unpacking port stats string: extra bytes"
3146 return binary_string
3147
3148 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003149 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07003150 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003151 length += len(obj)
3152 return length
3153
3154 def show(self, prefix=''):
3155 outstr = prefix + "port_stats_reply\n"
3156 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003157 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003158 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
3159 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003160 outstr += obj.show()
3161 return outstr
3162
3163 def __eq__(self, other):
3164 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003165 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07003166 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08003167
3168 def __ne__(self, other): return not self.__eq__(other)
3169
3170
3171class queue_stats_request(ofp_stats_request, ofp_queue_stats_request):
3172 """
3173 Wrapper class for queue stats request message
3174 """
3175 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08003176 ofp_stats_request.__init__(self)
3177 ofp_queue_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003178 self.version = OFP_VERSION
3179 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07003180 self.stats_type = OFPST_QUEUE
Rich Lane6242d9f2013-01-06 17:35:39 -08003181 for (k, v) in kwargs.items():
3182 if hasattr(self, k):
3183 setattr(self, k, v)
3184 else:
3185 raise NameError("field %s does not exist in %s" % (k, self.__class__))
3186
3187 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003188 self.length = len(self)
3189 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003190 packed += ofp_stats_request.pack(self)
3191 packed += ofp_queue_stats_request.pack(self)
3192 return packed
3193
3194 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003195 binary_string = ofp_stats_request.unpack(self, binary_string)
3196 binary_string = ofp_queue_stats_request.unpack(self, binary_string)
3197 if len(binary_string) != 0:
3198 print "ERROR unpacking queue: extra data"
3199 return binary_string
3200
3201 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003202 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08003203 OFP_QUEUE_STATS_REQUEST_BYTES
3204
3205 def show(self, prefix=''):
3206 outstr = prefix + "queue_stats_request\n"
3207 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003208 outstr += ofp_stats_request.show(self)
3209 outstr += ofp_queue_stats_request.show(self)
3210 return outstr
3211
3212 def __eq__(self, other):
3213 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003214 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08003215 ofp_queue_stats_request.__eq__(self, other))
3216
3217 def __ne__(self, other): return not self.__eq__(other)
3218
3219
3220class queue_stats_reply(ofp_stats_reply):
3221 """
3222 Wrapper class for queue stats reply
3223 """
3224 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08003225 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003226 self.version = OFP_VERSION
3227 self.type = OFPT_STATS_REPLY
3228 self.stats_type = OFPST_QUEUE
Rich Lane6242d9f2013-01-06 17:35:39 -08003229 # stats: Array of type queue_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07003230 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08003231
3232 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003233 self.length = len(self)
3234 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003235 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003236 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003237 packed += obj.pack()
3238 return packed
3239
3240 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003241 binary_string = ofp_stats_reply.unpack(self, binary_string)
3242 dummy = queue_stats_entry()
3243 while len(binary_string) >= len(dummy):
3244 obj = queue_stats_entry()
3245 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003246 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08003247 if len(binary_string) != 0:
3248 print "ERROR unpacking queue stats string: extra bytes"
3249 return binary_string
3250
3251 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003252 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07003253 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003254 length += len(obj)
3255 return length
3256
3257 def show(self, prefix=''):
3258 outstr = prefix + "queue_stats_reply\n"
3259 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003260 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003261 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
3262 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003263 outstr += obj.show()
3264 return outstr
3265
3266 def __eq__(self, other):
3267 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003268 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07003269 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08003270
3271 def __ne__(self, other): return not self.__eq__(other)
3272
3273
3274class table_stats_request(ofp_stats_request, ofp_table_stats_request):
3275 """
3276 Wrapper class for table stats request message
3277 """
3278 def __init__(self, **kwargs):
Rich Lane6242d9f2013-01-06 17:35:39 -08003279 ofp_stats_request.__init__(self)
3280 ofp_table_stats_request.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003281 self.version = OFP_VERSION
3282 self.type = OFPT_STATS_REQUEST
Rich Lane7c7342a2013-03-11 14:16:58 -07003283 self.stats_type = OFPST_TABLE
Rich Lane6242d9f2013-01-06 17:35:39 -08003284 for (k, v) in kwargs.items():
3285 if hasattr(self, k):
3286 setattr(self, k, v)
3287 else:
3288 raise NameError("field %s does not exist in %s" % (k, self.__class__))
3289
3290 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003291 self.length = len(self)
3292 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003293 packed += ofp_stats_request.pack(self)
3294 packed += ofp_table_stats_request.pack(self)
3295 return packed
3296
3297 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003298 binary_string = ofp_stats_request.unpack(self, binary_string)
3299 binary_string = ofp_table_stats_request.unpack(self, binary_string)
3300 if len(binary_string) != 0:
3301 print "ERROR unpacking table: extra data"
3302 return binary_string
3303
3304 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003305 return OFP_STATS_REQUEST_BYTES + \
Rich Lane6242d9f2013-01-06 17:35:39 -08003306 OFP_TABLE_STATS_REQUEST_BYTES
3307
3308 def show(self, prefix=''):
3309 outstr = prefix + "table_stats_request\n"
3310 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003311 outstr += ofp_stats_request.show(self)
3312 outstr += ofp_table_stats_request.show(self)
3313 return outstr
3314
3315 def __eq__(self, other):
3316 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003317 return (ofp_stats_request.__eq__(self, other) and
Rich Lane6242d9f2013-01-06 17:35:39 -08003318 ofp_table_stats_request.__eq__(self, other))
3319
3320 def __ne__(self, other): return not self.__eq__(other)
3321
3322
3323class table_stats_reply(ofp_stats_reply):
3324 """
3325 Wrapper class for table stats reply
3326 """
3327 def __init__(self):
Rich Lane6242d9f2013-01-06 17:35:39 -08003328 ofp_stats_reply.__init__(self)
Rich Laneb73808c2013-03-11 15:22:23 -07003329 self.version = OFP_VERSION
3330 self.type = OFPT_STATS_REPLY
3331 self.stats_type = OFPST_TABLE
Rich Lane6242d9f2013-01-06 17:35:39 -08003332 # stats: Array of type table_stats_entry
Rich Lane5fd6faf2013-03-11 13:30:20 -07003333 self.entries = []
Rich Lane6242d9f2013-01-06 17:35:39 -08003334
3335 def pack(self, assertstruct=True):
Rich Laneb73808c2013-03-11 15:22:23 -07003336 self.length = len(self)
3337 packed = ""
Rich Lane6242d9f2013-01-06 17:35:39 -08003338 packed += ofp_stats_reply.pack(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003339 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003340 packed += obj.pack()
3341 return packed
3342
3343 def unpack(self, binary_string):
Rich Lane6242d9f2013-01-06 17:35:39 -08003344 binary_string = ofp_stats_reply.unpack(self, binary_string)
3345 dummy = table_stats_entry()
3346 while len(binary_string) >= len(dummy):
3347 obj = table_stats_entry()
3348 binary_string = obj.unpack(binary_string)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003349 self.entries.append(obj)
Rich Lane6242d9f2013-01-06 17:35:39 -08003350 if len(binary_string) != 0:
3351 print "ERROR unpacking table stats string: extra bytes"
3352 return binary_string
3353
3354 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -07003355 length = OFP_STATS_REPLY_BYTES
Rich Lane5fd6faf2013-03-11 13:30:20 -07003356 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003357 length += len(obj)
3358 return length
3359
3360 def show(self, prefix=''):
3361 outstr = prefix + "table_stats_reply\n"
3362 outstr += prefix + "ofp header:\n"
Rich Lane6242d9f2013-01-06 17:35:39 -08003363 outstr += ofp_stats_reply.show(self)
Rich Lane5fd6faf2013-03-11 13:30:20 -07003364 outstr += prefix + "Stats array of length " + str(len(self.entries)) + '\n'
3365 for obj in self.entries:
Rich Lane6242d9f2013-01-06 17:35:39 -08003366 outstr += obj.show()
3367 return outstr
3368
3369 def __eq__(self, other):
3370 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -07003371 return (ofp_stats_reply.__eq__(self, other) and
Rich Lane5fd6faf2013-03-11 13:30:20 -07003372 self.entries == other.entries)
Rich Lane6242d9f2013-01-06 17:35:39 -08003373
3374 def __ne__(self, other): return not self.__eq__(other)
3375
3376
3377message_type_list = (
3378 aggregate_stats_reply,
3379 aggregate_stats_request,
3380 bad_action_error_msg,
3381 bad_request_error_msg,
3382 barrier_reply,
3383 barrier_request,
3384 desc_stats_reply,
3385 desc_stats_request,
3386 echo_reply,
3387 echo_request,
3388 features_reply,
3389 features_request,
3390 flow_mod,
3391 flow_mod_failed_error_msg,
3392 flow_removed,
3393 flow_stats_reply,
3394 flow_stats_request,
3395 get_config_reply,
3396 get_config_request,
3397 hello,
3398 hello_failed_error_msg,
3399 packet_in,
3400 packet_out,
3401 port_mod,
3402 port_mod_failed_error_msg,
3403 port_stats_reply,
3404 port_stats_request,
3405 port_status,
3406 queue_get_config_reply,
3407 queue_get_config_request,
3408 queue_op_failed_error_msg,
3409 queue_stats_reply,
3410 queue_stats_request,
3411 set_config,
3412 table_stats_reply,
3413 table_stats_request,
3414 vendor
3415 )
3416