Rich Lane | 5ec97b8 | 2013-01-06 18:04:25 -0800 | [diff] [blame] | 1 | |
| 2 | # Python OpenFlow message wrapper classes |
| 3 | |
| 4 | from cstruct import * |
| 5 | from action_list import action_list |
| 6 | from instruction_list import instruction_list |
| 7 | from bucket_list import bucket_list |
| 8 | from error import * |
| 9 | |
| 10 | # Define templates for documentation |
| 11 | class ofp_template_msg(object): |
| 12 | """ |
| 13 | Sample base class for template_msg; normally auto generated |
| 14 | This class should live in the of_header name space and provides the |
| 15 | base class for this type of message. It will be wrapped for the |
| 16 | high level API. |
| 17 | |
| 18 | """ |
| 19 | def __init__(self): |
| 20 | """ |
| 21 | Constructor for base class |
| 22 | |
| 23 | """ |
| 24 | self.header = ofp_header() |
| 25 | # Additional base data members declared here |
| 26 | |
| 27 | # Normally will define pack, unpack, __len__ functions |
| 28 | |
| 29 | class template_msg(ofp_template_msg): |
| 30 | """ |
| 31 | Sample class wrapper for template_msg |
| 32 | This class should live in the of_message name space and provides the |
| 33 | high level API for an OpenFlow message object. These objects must |
| 34 | implement the functions indicated in this template. |
| 35 | |
| 36 | """ |
| 37 | def __init__(self): |
| 38 | """ |
| 39 | Constructor |
| 40 | Must set the header type value appropriately for the message |
| 41 | |
| 42 | """ |
| 43 | |
| 44 | ##@var header |
| 45 | # OpenFlow message header: length, version, xid, type |
| 46 | ofp_template_msg.__init__(self) |
| 47 | self.header = ofp_header() |
| 48 | # For a real message, will be set to an integer |
| 49 | self.header.type = "TEMPLATE_MSG_VALUE" |
| 50 | def pack(self): |
| 51 | """ |
| 52 | Pack object into string |
| 53 | |
| 54 | @return The packed string which can go on the wire |
| 55 | |
| 56 | """ |
| 57 | pass |
| 58 | def unpack(self, binary_string): |
| 59 | """ |
| 60 | Unpack object from a binary string |
| 61 | |
| 62 | @param binary_string The wire protocol byte string holding the object |
| 63 | represented as an array of bytes. |
| 64 | |
| 65 | @return Typically returns the remainder of binary_string that |
| 66 | was not parsed. May give a warning if that string is non-empty |
| 67 | |
| 68 | """ |
| 69 | pass |
| 70 | def __len__(self): |
| 71 | """ |
| 72 | Return the length of this object once packed into a string |
| 73 | |
| 74 | @return An integer representing the number bytes in the packed |
| 75 | string. |
| 76 | |
| 77 | """ |
| 78 | pass |
| 79 | def show(self, prefix=''): |
| 80 | """ |
| 81 | Generate a string (with multiple lines) describing the contents |
| 82 | of the object in a readable manner |
| 83 | |
| 84 | @param prefix Pre-pended at the beginning of each line. |
| 85 | |
| 86 | """ |
| 87 | pass |
| 88 | def __eq__(self, other): |
| 89 | """ |
| 90 | Return True if self and other hold the same data |
| 91 | |
| 92 | @param other Other object in comparison |
| 93 | |
| 94 | """ |
| 95 | pass |
| 96 | def __ne__(self, other): |
| 97 | """ |
| 98 | Return True if self and other do not hold the same data |
| 99 | |
| 100 | @param other Other object in comparison |
| 101 | |
| 102 | """ |
| 103 | pass |
| 104 | |
| 105 | |
| 106 | ################################################################ |
| 107 | # |
| 108 | # OpenFlow Message Definitions |
| 109 | # |
| 110 | ################################################################ |
| 111 | |
| 112 | class barrier_reply(object): |
| 113 | """ |
| 114 | Wrapper class for barrier_reply |
| 115 | |
| 116 | OpenFlow message header: length, version, xid, type |
| 117 | @arg length: The total length of the message |
| 118 | @arg version: The OpenFlow version (2) |
| 119 | @arg xid: The transaction ID |
| 120 | @arg type: The message type (OFPT_BARRIER_REPLY=21) |
| 121 | |
| 122 | |
| 123 | """ |
| 124 | |
| 125 | def __init__(self): |
| 126 | self.header = ofp_header() |
| 127 | self.header.type = OFPT_BARRIER_REPLY |
| 128 | |
| 129 | |
| 130 | def pack(self): |
| 131 | """ |
| 132 | Pack object into string |
| 133 | |
| 134 | @return The packed string which can go on the wire |
| 135 | |
| 136 | """ |
| 137 | self.header.length = len(self) |
| 138 | packed = self.header.pack() |
| 139 | |
| 140 | return packed |
| 141 | |
| 142 | def unpack(self, binary_string): |
| 143 | """ |
| 144 | Unpack object from a binary string |
| 145 | |
| 146 | @param binary_string The wire protocol byte string holding the object |
| 147 | represented as an array of bytes. |
| 148 | @return The remainder of binary_string that was not parsed. |
| 149 | |
| 150 | """ |
| 151 | binary_string = self.header.unpack(binary_string) |
| 152 | |
| 153 | # Fixme: If no self.data, add check for data remaining |
| 154 | return binary_string |
| 155 | |
| 156 | def __len__(self): |
| 157 | """ |
| 158 | Return the length of this object once packed into a string |
| 159 | |
| 160 | @return An integer representing the number bytes in the packed |
| 161 | string. |
| 162 | |
| 163 | """ |
| 164 | length = OFP_HEADER_BYTES |
| 165 | |
| 166 | return length |
| 167 | |
| 168 | def show(self, prefix=''): |
| 169 | """ |
| 170 | Generate a string (with multiple lines) describing the contents |
| 171 | of the object in a readable manner |
| 172 | |
| 173 | @param prefix Pre-pended at the beginning of each line. |
| 174 | |
| 175 | """ |
| 176 | |
| 177 | outstr = prefix + 'barrier_reply (OFPT_BARRIER_REPLY)\n' |
| 178 | prefix += ' ' |
| 179 | outstr += prefix + 'ofp header\n' |
| 180 | outstr += self.header.show(prefix + ' ') |
| 181 | return outstr |
| 182 | |
| 183 | def __eq__(self, other): |
| 184 | """ |
| 185 | Return True if self and other hold the same data |
| 186 | |
| 187 | @param other Other object in comparison |
| 188 | |
| 189 | """ |
| 190 | if type(self) != type(other): return False |
| 191 | if not self.header.__eq__(other.header): return False |
| 192 | |
| 193 | return True |
| 194 | |
| 195 | def __ne__(self, other): |
| 196 | """ |
| 197 | Return True if self and other do not hold the same data |
| 198 | |
| 199 | @param other Other object in comparison |
| 200 | |
| 201 | """ |
| 202 | return not self.__eq__(other) |
| 203 | |
| 204 | |
| 205 | class barrier_request(object): |
| 206 | """ |
| 207 | Wrapper class for barrier_request |
| 208 | |
| 209 | OpenFlow message header: length, version, xid, type |
| 210 | @arg length: The total length of the message |
| 211 | @arg version: The OpenFlow version (2) |
| 212 | @arg xid: The transaction ID |
| 213 | @arg type: The message type (OFPT_BARRIER_REQUEST=20) |
| 214 | |
| 215 | |
| 216 | """ |
| 217 | |
| 218 | def __init__(self): |
| 219 | self.header = ofp_header() |
| 220 | self.header.type = OFPT_BARRIER_REQUEST |
| 221 | |
| 222 | |
| 223 | def pack(self): |
| 224 | """ |
| 225 | Pack object into string |
| 226 | |
| 227 | @return The packed string which can go on the wire |
| 228 | |
| 229 | """ |
| 230 | self.header.length = len(self) |
| 231 | packed = self.header.pack() |
| 232 | |
| 233 | return packed |
| 234 | |
| 235 | def unpack(self, binary_string): |
| 236 | """ |
| 237 | Unpack object from a binary string |
| 238 | |
| 239 | @param binary_string The wire protocol byte string holding the object |
| 240 | represented as an array of bytes. |
| 241 | @return The remainder of binary_string that was not parsed. |
| 242 | |
| 243 | """ |
| 244 | binary_string = self.header.unpack(binary_string) |
| 245 | |
| 246 | # Fixme: If no self.data, add check for data remaining |
| 247 | return binary_string |
| 248 | |
| 249 | def __len__(self): |
| 250 | """ |
| 251 | Return the length of this object once packed into a string |
| 252 | |
| 253 | @return An integer representing the number bytes in the packed |
| 254 | string. |
| 255 | |
| 256 | """ |
| 257 | length = OFP_HEADER_BYTES |
| 258 | |
| 259 | return length |
| 260 | |
| 261 | def show(self, prefix=''): |
| 262 | """ |
| 263 | Generate a string (with multiple lines) describing the contents |
| 264 | of the object in a readable manner |
| 265 | |
| 266 | @param prefix Pre-pended at the beginning of each line. |
| 267 | |
| 268 | """ |
| 269 | |
| 270 | outstr = prefix + 'barrier_request (OFPT_BARRIER_REQUEST)\n' |
| 271 | prefix += ' ' |
| 272 | outstr += prefix + 'ofp header\n' |
| 273 | outstr += self.header.show(prefix + ' ') |
| 274 | return outstr |
| 275 | |
| 276 | def __eq__(self, other): |
| 277 | """ |
| 278 | Return True if self and other hold the same data |
| 279 | |
| 280 | @param other Other object in comparison |
| 281 | |
| 282 | """ |
| 283 | if type(self) != type(other): return False |
| 284 | if not self.header.__eq__(other.header): return False |
| 285 | |
| 286 | return True |
| 287 | |
| 288 | def __ne__(self, other): |
| 289 | """ |
| 290 | Return True if self and other do not hold the same data |
| 291 | |
| 292 | @param other Other object in comparison |
| 293 | |
| 294 | """ |
| 295 | return not self.__eq__(other) |
| 296 | |
| 297 | |
| 298 | class echo_reply(object): |
| 299 | """ |
| 300 | Wrapper class for echo_reply |
| 301 | |
| 302 | OpenFlow message header: length, version, xid, type |
| 303 | @arg length: The total length of the message |
| 304 | @arg version: The OpenFlow version (2) |
| 305 | @arg xid: The transaction ID |
| 306 | @arg type: The message type (OFPT_ECHO_REPLY=3) |
| 307 | |
| 308 | @arg data: Binary string following message members |
| 309 | |
| 310 | """ |
| 311 | |
| 312 | def __init__(self): |
| 313 | self.header = ofp_header() |
| 314 | self.header.type = OFPT_ECHO_REPLY |
| 315 | self.data = "" |
| 316 | |
| 317 | |
| 318 | def pack(self): |
| 319 | """ |
| 320 | Pack object into string |
| 321 | |
| 322 | @return The packed string which can go on the wire |
| 323 | |
| 324 | """ |
| 325 | self.header.length = len(self) |
| 326 | packed = self.header.pack() |
| 327 | |
| 328 | packed += self.data |
| 329 | return packed |
| 330 | |
| 331 | def unpack(self, binary_string): |
| 332 | """ |
| 333 | Unpack object from a binary string |
| 334 | |
| 335 | @param binary_string The wire protocol byte string holding the object |
| 336 | represented as an array of bytes. |
| 337 | @return The remainder of binary_string that was not parsed. |
| 338 | |
| 339 | """ |
| 340 | binary_string = self.header.unpack(binary_string) |
| 341 | |
| 342 | self.data = binary_string |
| 343 | binary_string = '' |
| 344 | return binary_string |
| 345 | |
| 346 | def __len__(self): |
| 347 | """ |
| 348 | Return the length of this object once packed into a string |
| 349 | |
| 350 | @return An integer representing the number bytes in the packed |
| 351 | string. |
| 352 | |
| 353 | """ |
| 354 | length = OFP_HEADER_BYTES |
| 355 | |
| 356 | length += len(self.data) |
| 357 | return length |
| 358 | |
| 359 | def show(self, prefix=''): |
| 360 | """ |
| 361 | Generate a string (with multiple lines) describing the contents |
| 362 | of the object in a readable manner |
| 363 | |
| 364 | @param prefix Pre-pended at the beginning of each line. |
| 365 | |
| 366 | """ |
| 367 | |
| 368 | outstr = prefix + 'echo_reply (OFPT_ECHO_REPLY)\n' |
| 369 | prefix += ' ' |
| 370 | outstr += prefix + 'ofp header\n' |
| 371 | outstr += self.header.show(prefix + ' ') |
| 372 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 373 | ##@todo Fix this circular reference |
| 374 | # if len(self.data) > 0: |
| 375 | # obj = of_message_parse(self.data) |
| 376 | # if obj != None: |
| 377 | # outstr += obj.show(prefix) |
| 378 | # else: |
| 379 | # outstr += prefix + "Unable to parse data\n" |
| 380 | return outstr |
| 381 | |
| 382 | def __eq__(self, other): |
| 383 | """ |
| 384 | Return True if self and other hold the same data |
| 385 | |
| 386 | @param other Other object in comparison |
| 387 | |
| 388 | """ |
| 389 | if type(self) != type(other): return False |
| 390 | if not self.header.__eq__(other.header): return False |
| 391 | |
| 392 | if self.data != other.data: return False |
| 393 | return True |
| 394 | |
| 395 | def __ne__(self, other): |
| 396 | """ |
| 397 | Return True if self and other do not hold the same data |
| 398 | |
| 399 | @param other Other object in comparison |
| 400 | |
| 401 | """ |
| 402 | return not self.__eq__(other) |
| 403 | |
| 404 | |
| 405 | class echo_request(object): |
| 406 | """ |
| 407 | Wrapper class for echo_request |
| 408 | |
| 409 | OpenFlow message header: length, version, xid, type |
| 410 | @arg length: The total length of the message |
| 411 | @arg version: The OpenFlow version (2) |
| 412 | @arg xid: The transaction ID |
| 413 | @arg type: The message type (OFPT_ECHO_REQUEST=2) |
| 414 | |
| 415 | @arg data: Binary string following message members |
| 416 | |
| 417 | """ |
| 418 | |
| 419 | def __init__(self): |
| 420 | self.header = ofp_header() |
| 421 | self.header.type = OFPT_ECHO_REQUEST |
| 422 | self.data = "" |
| 423 | |
| 424 | |
| 425 | def pack(self): |
| 426 | """ |
| 427 | Pack object into string |
| 428 | |
| 429 | @return The packed string which can go on the wire |
| 430 | |
| 431 | """ |
| 432 | self.header.length = len(self) |
| 433 | packed = self.header.pack() |
| 434 | |
| 435 | packed += self.data |
| 436 | return packed |
| 437 | |
| 438 | def unpack(self, binary_string): |
| 439 | """ |
| 440 | Unpack object from a binary string |
| 441 | |
| 442 | @param binary_string The wire protocol byte string holding the object |
| 443 | represented as an array of bytes. |
| 444 | @return The remainder of binary_string that was not parsed. |
| 445 | |
| 446 | """ |
| 447 | binary_string = self.header.unpack(binary_string) |
| 448 | |
| 449 | self.data = binary_string |
| 450 | binary_string = '' |
| 451 | return binary_string |
| 452 | |
| 453 | def __len__(self): |
| 454 | """ |
| 455 | Return the length of this object once packed into a string |
| 456 | |
| 457 | @return An integer representing the number bytes in the packed |
| 458 | string. |
| 459 | |
| 460 | """ |
| 461 | length = OFP_HEADER_BYTES |
| 462 | |
| 463 | length += len(self.data) |
| 464 | return length |
| 465 | |
| 466 | def show(self, prefix=''): |
| 467 | """ |
| 468 | Generate a string (with multiple lines) describing the contents |
| 469 | of the object in a readable manner |
| 470 | |
| 471 | @param prefix Pre-pended at the beginning of each line. |
| 472 | |
| 473 | """ |
| 474 | |
| 475 | outstr = prefix + 'echo_request (OFPT_ECHO_REQUEST)\n' |
| 476 | prefix += ' ' |
| 477 | outstr += prefix + 'ofp header\n' |
| 478 | outstr += self.header.show(prefix + ' ') |
| 479 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 480 | ##@todo Fix this circular reference |
| 481 | # if len(self.data) > 0: |
| 482 | # obj = of_message_parse(self.data) |
| 483 | # if obj != None: |
| 484 | # outstr += obj.show(prefix) |
| 485 | # else: |
| 486 | # outstr += prefix + "Unable to parse data\n" |
| 487 | return outstr |
| 488 | |
| 489 | def __eq__(self, other): |
| 490 | """ |
| 491 | Return True if self and other hold the same data |
| 492 | |
| 493 | @param other Other object in comparison |
| 494 | |
| 495 | """ |
| 496 | if type(self) != type(other): return False |
| 497 | if not self.header.__eq__(other.header): return False |
| 498 | |
| 499 | if self.data != other.data: return False |
| 500 | return True |
| 501 | |
| 502 | def __ne__(self, other): |
| 503 | """ |
| 504 | Return True if self and other do not hold the same data |
| 505 | |
| 506 | @param other Other object in comparison |
| 507 | |
| 508 | """ |
| 509 | return not self.__eq__(other) |
| 510 | |
| 511 | |
| 512 | class error(ofp_error_msg): |
| 513 | """ |
| 514 | Wrapper class for error |
| 515 | |
| 516 | OpenFlow message header: length, version, xid, type |
| 517 | @arg length: The total length of the message |
| 518 | @arg version: The OpenFlow version (2) |
| 519 | @arg xid: The transaction ID |
| 520 | @arg type: The message type (OFPT_ERROR=1) |
| 521 | |
| 522 | Data members inherited from ofp_error_msg: |
| 523 | @arg type |
| 524 | @arg code |
| 525 | @arg data: Binary string following message members |
| 526 | |
| 527 | """ |
| 528 | |
| 529 | def __init__(self): |
| 530 | ofp_error_msg.__init__(self) |
| 531 | self.header = ofp_header() |
| 532 | self.header.type = OFPT_ERROR |
| 533 | self.data = "" |
| 534 | |
| 535 | |
| 536 | def pack(self): |
| 537 | """ |
| 538 | Pack object into string |
| 539 | |
| 540 | @return The packed string which can go on the wire |
| 541 | |
| 542 | """ |
| 543 | self.header.length = len(self) |
| 544 | packed = self.header.pack() |
| 545 | |
| 546 | packed += ofp_error_msg.pack(self) |
| 547 | packed += self.data |
| 548 | return packed |
| 549 | |
| 550 | def unpack(self, binary_string): |
| 551 | """ |
| 552 | Unpack object from a binary string |
| 553 | |
| 554 | @param binary_string The wire protocol byte string holding the object |
| 555 | represented as an array of bytes. |
| 556 | @return The remainder of binary_string that was not parsed. |
| 557 | |
| 558 | """ |
| 559 | binary_string = self.header.unpack(binary_string) |
| 560 | |
| 561 | binary_string = ofp_error_msg.unpack(self, binary_string) |
| 562 | self.data = binary_string |
| 563 | binary_string = '' |
| 564 | return binary_string |
| 565 | |
| 566 | def __len__(self): |
| 567 | """ |
| 568 | Return the length of this object once packed into a string |
| 569 | |
| 570 | @return An integer representing the number bytes in the packed |
| 571 | string. |
| 572 | |
| 573 | """ |
| 574 | length = OFP_HEADER_BYTES |
| 575 | |
| 576 | length += ofp_error_msg.__len__(self) |
| 577 | length += len(self.data) |
| 578 | return length |
| 579 | |
| 580 | def show(self, prefix=''): |
| 581 | """ |
| 582 | Generate a string (with multiple lines) describing the contents |
| 583 | of the object in a readable manner |
| 584 | |
| 585 | @param prefix Pre-pended at the beginning of each line. |
| 586 | |
| 587 | """ |
| 588 | |
| 589 | outstr = prefix + 'error (OFPT_ERROR)\n' |
| 590 | prefix += ' ' |
| 591 | outstr += prefix + 'ofp header\n' |
| 592 | outstr += self.header.show(prefix + ' ') |
| 593 | outstr += ofp_error_msg.show(self, prefix) |
| 594 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 595 | ##@todo Fix this circular reference |
| 596 | # if len(self.data) > 0: |
| 597 | # obj = of_message_parse(self.data) |
| 598 | # if obj != None: |
| 599 | # outstr += obj.show(prefix) |
| 600 | # else: |
| 601 | # outstr += prefix + "Unable to parse data\n" |
| 602 | return outstr |
| 603 | |
| 604 | def __eq__(self, other): |
| 605 | """ |
| 606 | Return True if self and other hold the same data |
| 607 | |
| 608 | @param other Other object in comparison |
| 609 | |
| 610 | """ |
| 611 | if type(self) != type(other): return False |
| 612 | if not self.header.__eq__(other.header): return False |
| 613 | |
| 614 | if not ofp_error_msg.__eq__(self, other): return False |
| 615 | if self.data != other.data: return False |
| 616 | return True |
| 617 | |
| 618 | def __ne__(self, other): |
| 619 | """ |
| 620 | Return True if self and other do not hold the same data |
| 621 | |
| 622 | @param other Other object in comparison |
| 623 | |
| 624 | """ |
| 625 | return not self.__eq__(other) |
| 626 | |
| 627 | |
| 628 | class experimenter(ofp_experimenter_header): |
| 629 | """ |
| 630 | Wrapper class for experimenter |
| 631 | |
| 632 | OpenFlow message header: length, version, xid, type |
| 633 | @arg length: The total length of the message |
| 634 | @arg version: The OpenFlow version (2) |
| 635 | @arg xid: The transaction ID |
| 636 | @arg type: The message type (OFPT_EXPERIMENTER=4) |
| 637 | |
| 638 | Data members inherited from ofp_experimenter_header: |
| 639 | @arg experimenter |
| 640 | @arg data: Binary string following message members |
| 641 | |
| 642 | """ |
| 643 | |
| 644 | def __init__(self): |
| 645 | ofp_experimenter_header.__init__(self) |
| 646 | self.header = ofp_header() |
| 647 | self.header.type = OFPT_EXPERIMENTER |
| 648 | self.data = "" |
| 649 | |
| 650 | |
| 651 | def pack(self): |
| 652 | """ |
| 653 | Pack object into string |
| 654 | |
| 655 | @return The packed string which can go on the wire |
| 656 | |
| 657 | """ |
| 658 | self.header.length = len(self) |
| 659 | packed = self.header.pack() |
| 660 | |
| 661 | packed += ofp_experimenter_header.pack(self) |
| 662 | packed += self.data |
| 663 | return packed |
| 664 | |
| 665 | def unpack(self, binary_string): |
| 666 | """ |
| 667 | Unpack object from a binary string |
| 668 | |
| 669 | @param binary_string The wire protocol byte string holding the object |
| 670 | represented as an array of bytes. |
| 671 | @return The remainder of binary_string that was not parsed. |
| 672 | |
| 673 | """ |
| 674 | binary_string = self.header.unpack(binary_string) |
| 675 | |
| 676 | binary_string = ofp_experimenter_header.unpack(self, binary_string) |
| 677 | self.data = binary_string |
| 678 | binary_string = '' |
| 679 | return binary_string |
| 680 | |
| 681 | def __len__(self): |
| 682 | """ |
| 683 | Return the length of this object once packed into a string |
| 684 | |
| 685 | @return An integer representing the number bytes in the packed |
| 686 | string. |
| 687 | |
| 688 | """ |
| 689 | length = OFP_HEADER_BYTES |
| 690 | |
| 691 | length += ofp_experimenter_header.__len__(self) |
| 692 | length += len(self.data) |
| 693 | return length |
| 694 | |
| 695 | def show(self, prefix=''): |
| 696 | """ |
| 697 | Generate a string (with multiple lines) describing the contents |
| 698 | of the object in a readable manner |
| 699 | |
| 700 | @param prefix Pre-pended at the beginning of each line. |
| 701 | |
| 702 | """ |
| 703 | |
| 704 | outstr = prefix + 'experimenter (OFPT_EXPERIMENTER)\n' |
| 705 | prefix += ' ' |
| 706 | outstr += prefix + 'ofp header\n' |
| 707 | outstr += self.header.show(prefix + ' ') |
| 708 | outstr += ofp_experimenter_header.show(self, prefix) |
| 709 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 710 | ##@todo Fix this circular reference |
| 711 | # if len(self.data) > 0: |
| 712 | # obj = of_message_parse(self.data) |
| 713 | # if obj != None: |
| 714 | # outstr += obj.show(prefix) |
| 715 | # else: |
| 716 | # outstr += prefix + "Unable to parse data\n" |
| 717 | return outstr |
| 718 | |
| 719 | def __eq__(self, other): |
| 720 | """ |
| 721 | Return True if self and other hold the same data |
| 722 | |
| 723 | @param other Other object in comparison |
| 724 | |
| 725 | """ |
| 726 | if type(self) != type(other): return False |
| 727 | if not self.header.__eq__(other.header): return False |
| 728 | |
| 729 | if not ofp_experimenter_header.__eq__(self, other): return False |
| 730 | if self.data != other.data: return False |
| 731 | return True |
| 732 | |
| 733 | def __ne__(self, other): |
| 734 | """ |
| 735 | Return True if self and other do not hold the same data |
| 736 | |
| 737 | @param other Other object in comparison |
| 738 | |
| 739 | """ |
| 740 | return not self.__eq__(other) |
| 741 | |
| 742 | |
| 743 | class features_reply(ofp_switch_features): |
| 744 | """ |
| 745 | Wrapper class for features_reply |
| 746 | |
| 747 | OpenFlow message header: length, version, xid, type |
| 748 | @arg length: The total length of the message |
| 749 | @arg version: The OpenFlow version (2) |
| 750 | @arg xid: The transaction ID |
| 751 | @arg type: The message type (OFPT_FEATURES_REPLY=6) |
| 752 | |
| 753 | Data members inherited from ofp_switch_features: |
| 754 | @arg datapath_id |
| 755 | @arg n_buffers |
| 756 | @arg n_tables |
| 757 | @arg capabilities |
| 758 | @arg reserved |
| 759 | @arg ports: Variable length array of TBD |
| 760 | |
| 761 | """ |
| 762 | |
| 763 | def __init__(self): |
| 764 | ofp_switch_features.__init__(self) |
| 765 | self.header = ofp_header() |
| 766 | self.header.type = OFPT_FEATURES_REPLY |
| 767 | self.ports = [] |
| 768 | |
| 769 | |
| 770 | def pack(self): |
| 771 | """ |
| 772 | Pack object into string |
| 773 | |
| 774 | @return The packed string which can go on the wire |
| 775 | |
| 776 | """ |
| 777 | self.header.length = len(self) |
| 778 | packed = self.header.pack() |
| 779 | |
| 780 | packed += ofp_switch_features.pack(self) |
| 781 | for obj in self.ports: |
| 782 | packed += obj.pack() |
| 783 | return packed |
| 784 | |
| 785 | def unpack(self, binary_string): |
| 786 | """ |
| 787 | Unpack object from a binary string |
| 788 | |
| 789 | @param binary_string The wire protocol byte string holding the object |
| 790 | represented as an array of bytes. |
| 791 | @return The remainder of binary_string that was not parsed. |
| 792 | |
| 793 | """ |
| 794 | binary_string = self.header.unpack(binary_string) |
| 795 | |
| 796 | binary_string = ofp_switch_features.unpack(self, binary_string) |
| 797 | while len(binary_string) >= OFP_PORT_BYTES: |
| 798 | new_port = ofp_port() |
| 799 | binary_string = new_port.unpack(binary_string) |
| 800 | self.ports.append(new_port) |
| 801 | # Fixme: If no self.data, add check for data remaining |
| 802 | return binary_string |
| 803 | |
| 804 | def __len__(self): |
| 805 | """ |
| 806 | Return the length of this object once packed into a string |
| 807 | |
| 808 | @return An integer representing the number bytes in the packed |
| 809 | string. |
| 810 | |
| 811 | """ |
| 812 | length = OFP_HEADER_BYTES |
| 813 | |
| 814 | length += ofp_switch_features.__len__(self) |
| 815 | for obj in self.ports: |
| 816 | length += len(obj) |
| 817 | return length |
| 818 | |
| 819 | def show(self, prefix=''): |
| 820 | """ |
| 821 | Generate a string (with multiple lines) describing the contents |
| 822 | of the object in a readable manner |
| 823 | |
| 824 | @param prefix Pre-pended at the beginning of each line. |
| 825 | |
| 826 | """ |
| 827 | |
| 828 | outstr = prefix + 'features_reply (OFPT_FEATURES_REPLY)\n' |
| 829 | prefix += ' ' |
| 830 | outstr += prefix + 'ofp header\n' |
| 831 | outstr += self.header.show(prefix + ' ') |
| 832 | outstr += ofp_switch_features.show(self, prefix) |
| 833 | outstr += prefix + "Array ports\n" |
| 834 | for obj in self.ports: |
| 835 | outstr += obj.show(prefix + ' ') |
| 836 | return outstr |
| 837 | |
| 838 | def __eq__(self, other): |
| 839 | """ |
| 840 | Return True if self and other hold the same data |
| 841 | |
| 842 | @param other Other object in comparison |
| 843 | |
| 844 | """ |
| 845 | if type(self) != type(other): return False |
| 846 | if not self.header.__eq__(other.header): return False |
| 847 | |
| 848 | if not ofp_switch_features.__eq__(self, other): return False |
| 849 | if self.ports != other.ports: return False |
| 850 | return True |
| 851 | |
| 852 | def __ne__(self, other): |
| 853 | """ |
| 854 | Return True if self and other do not hold the same data |
| 855 | |
| 856 | @param other Other object in comparison |
| 857 | |
| 858 | """ |
| 859 | return not self.__eq__(other) |
| 860 | |
| 861 | |
| 862 | class features_request(object): |
| 863 | """ |
| 864 | Wrapper class for features_request |
| 865 | |
| 866 | OpenFlow message header: length, version, xid, type |
| 867 | @arg length: The total length of the message |
| 868 | @arg version: The OpenFlow version (2) |
| 869 | @arg xid: The transaction ID |
| 870 | @arg type: The message type (OFPT_FEATURES_REQUEST=5) |
| 871 | |
| 872 | |
| 873 | """ |
| 874 | |
| 875 | def __init__(self): |
| 876 | self.header = ofp_header() |
| 877 | self.header.type = OFPT_FEATURES_REQUEST |
| 878 | |
| 879 | |
| 880 | def pack(self): |
| 881 | """ |
| 882 | Pack object into string |
| 883 | |
| 884 | @return The packed string which can go on the wire |
| 885 | |
| 886 | """ |
| 887 | self.header.length = len(self) |
| 888 | packed = self.header.pack() |
| 889 | |
| 890 | return packed |
| 891 | |
| 892 | def unpack(self, binary_string): |
| 893 | """ |
| 894 | Unpack object from a binary string |
| 895 | |
| 896 | @param binary_string The wire protocol byte string holding the object |
| 897 | represented as an array of bytes. |
| 898 | @return The remainder of binary_string that was not parsed. |
| 899 | |
| 900 | """ |
| 901 | binary_string = self.header.unpack(binary_string) |
| 902 | |
| 903 | # Fixme: If no self.data, add check for data remaining |
| 904 | return binary_string |
| 905 | |
| 906 | def __len__(self): |
| 907 | """ |
| 908 | Return the length of this object once packed into a string |
| 909 | |
| 910 | @return An integer representing the number bytes in the packed |
| 911 | string. |
| 912 | |
| 913 | """ |
| 914 | length = OFP_HEADER_BYTES |
| 915 | |
| 916 | return length |
| 917 | |
| 918 | def show(self, prefix=''): |
| 919 | """ |
| 920 | Generate a string (with multiple lines) describing the contents |
| 921 | of the object in a readable manner |
| 922 | |
| 923 | @param prefix Pre-pended at the beginning of each line. |
| 924 | |
| 925 | """ |
| 926 | |
| 927 | outstr = prefix + 'features_request (OFPT_FEATURES_REQUEST)\n' |
| 928 | prefix += ' ' |
| 929 | outstr += prefix + 'ofp header\n' |
| 930 | outstr += self.header.show(prefix + ' ') |
| 931 | return outstr |
| 932 | |
| 933 | def __eq__(self, other): |
| 934 | """ |
| 935 | Return True if self and other hold the same data |
| 936 | |
| 937 | @param other Other object in comparison |
| 938 | |
| 939 | """ |
| 940 | if type(self) != type(other): return False |
| 941 | if not self.header.__eq__(other.header): return False |
| 942 | |
| 943 | return True |
| 944 | |
| 945 | def __ne__(self, other): |
| 946 | """ |
| 947 | Return True if self and other do not hold the same data |
| 948 | |
| 949 | @param other Other object in comparison |
| 950 | |
| 951 | """ |
| 952 | return not self.__eq__(other) |
| 953 | |
| 954 | |
| 955 | class flow_mod(ofp_flow_mod): |
| 956 | """ |
| 957 | Wrapper class for flow_mod |
| 958 | |
| 959 | OpenFlow message header: length, version, xid, type |
| 960 | @arg length: The total length of the message |
| 961 | @arg version: The OpenFlow version (2) |
| 962 | @arg xid: The transaction ID |
| 963 | @arg type: The message type (OFPT_FLOW_MOD=14) |
| 964 | |
| 965 | Data members inherited from ofp_flow_mod: |
| 966 | @arg cookie |
| 967 | @arg cookie_mask |
| 968 | @arg table_id |
| 969 | @arg command |
| 970 | @arg idle_timeout |
| 971 | @arg hard_timeout |
| 972 | @arg priority |
| 973 | @arg buffer_id |
| 974 | @arg out_port |
| 975 | @arg out_group |
| 976 | @arg flags |
| 977 | @arg match |
| 978 | @arg instructions: Object of type instruction_list |
| 979 | |
| 980 | """ |
| 981 | |
| 982 | def __init__(self): |
| 983 | ofp_flow_mod.__init__(self) |
| 984 | self.header = ofp_header() |
| 985 | self.header.type = OFPT_FLOW_MOD |
| 986 | self.instructions = instruction_list() |
| 987 | |
| 988 | |
| 989 | def pack(self): |
| 990 | """ |
| 991 | Pack object into string |
| 992 | |
| 993 | @return The packed string which can go on the wire |
| 994 | |
| 995 | """ |
| 996 | self.header.length = len(self) |
| 997 | packed = self.header.pack() |
| 998 | |
| 999 | packed += ofp_flow_mod.pack(self) |
| 1000 | packed += self.instructions.pack() |
| 1001 | return packed |
| 1002 | |
| 1003 | def unpack(self, binary_string): |
| 1004 | """ |
| 1005 | Unpack object from a binary string |
| 1006 | |
| 1007 | @param binary_string The wire protocol byte string holding the object |
| 1008 | represented as an array of bytes. |
| 1009 | @return The remainder of binary_string that was not parsed. |
| 1010 | |
| 1011 | """ |
| 1012 | binary_string = self.header.unpack(binary_string) |
| 1013 | |
| 1014 | binary_string = ofp_flow_mod.unpack(self, binary_string) |
| 1015 | ai_len = self.header.length - (OFP_FLOW_MOD_BYTES + OFP_HEADER_BYTES) |
| 1016 | binary_string = self.instructions.unpack(binary_string, bytes=ai_len) |
| 1017 | # Fixme: If no self.data, add check for data remaining |
| 1018 | return binary_string |
| 1019 | |
| 1020 | def __len__(self): |
| 1021 | """ |
| 1022 | Return the length of this object once packed into a string |
| 1023 | |
| 1024 | @return An integer representing the number bytes in the packed |
| 1025 | string. |
| 1026 | |
| 1027 | """ |
| 1028 | length = OFP_HEADER_BYTES |
| 1029 | |
| 1030 | length += ofp_flow_mod.__len__(self) |
| 1031 | length += len(self.instructions) |
| 1032 | return length |
| 1033 | |
| 1034 | def show(self, prefix=''): |
| 1035 | """ |
| 1036 | Generate a string (with multiple lines) describing the contents |
| 1037 | of the object in a readable manner |
| 1038 | |
| 1039 | @param prefix Pre-pended at the beginning of each line. |
| 1040 | |
| 1041 | """ |
| 1042 | |
| 1043 | outstr = prefix + 'flow_mod (OFPT_FLOW_MOD)\n' |
| 1044 | prefix += ' ' |
| 1045 | outstr += prefix + 'ofp header\n' |
| 1046 | outstr += self.header.show(prefix + ' ') |
| 1047 | outstr += ofp_flow_mod.show(self, prefix) |
| 1048 | outstr += prefix + "List instructions\n" |
| 1049 | outstr += self.instructions.show(prefix + ' ') |
| 1050 | return outstr |
| 1051 | |
| 1052 | def __eq__(self, other): |
| 1053 | """ |
| 1054 | Return True if self and other hold the same data |
| 1055 | |
| 1056 | @param other Other object in comparison |
| 1057 | |
| 1058 | """ |
| 1059 | if type(self) != type(other): return False |
| 1060 | if not self.header.__eq__(other.header): return False |
| 1061 | |
| 1062 | if not ofp_flow_mod.__eq__(self, other): return False |
| 1063 | if self.instructions != other.instructions: return False |
| 1064 | return True |
| 1065 | |
| 1066 | def __ne__(self, other): |
| 1067 | """ |
| 1068 | Return True if self and other do not hold the same data |
| 1069 | |
| 1070 | @param other Other object in comparison |
| 1071 | |
| 1072 | """ |
| 1073 | return not self.__eq__(other) |
| 1074 | |
| 1075 | |
| 1076 | class flow_removed(ofp_flow_removed): |
| 1077 | """ |
| 1078 | Wrapper class for flow_removed |
| 1079 | |
| 1080 | OpenFlow message header: length, version, xid, type |
| 1081 | @arg length: The total length of the message |
| 1082 | @arg version: The OpenFlow version (2) |
| 1083 | @arg xid: The transaction ID |
| 1084 | @arg type: The message type (OFPT_FLOW_REMOVED=11) |
| 1085 | |
| 1086 | Data members inherited from ofp_flow_removed: |
| 1087 | @arg cookie |
| 1088 | @arg priority |
| 1089 | @arg reason |
| 1090 | @arg table_id |
| 1091 | @arg duration_sec |
| 1092 | @arg duration_nsec |
| 1093 | @arg idle_timeout |
| 1094 | @arg packet_count |
| 1095 | @arg byte_count |
| 1096 | @arg match |
| 1097 | |
| 1098 | """ |
| 1099 | |
| 1100 | def __init__(self): |
| 1101 | ofp_flow_removed.__init__(self) |
| 1102 | self.header = ofp_header() |
| 1103 | self.header.type = OFPT_FLOW_REMOVED |
| 1104 | |
| 1105 | |
| 1106 | def pack(self): |
| 1107 | """ |
| 1108 | Pack object into string |
| 1109 | |
| 1110 | @return The packed string which can go on the wire |
| 1111 | |
| 1112 | """ |
| 1113 | self.header.length = len(self) |
| 1114 | packed = self.header.pack() |
| 1115 | |
| 1116 | packed += ofp_flow_removed.pack(self) |
| 1117 | return packed |
| 1118 | |
| 1119 | def unpack(self, binary_string): |
| 1120 | """ |
| 1121 | Unpack object from a binary string |
| 1122 | |
| 1123 | @param binary_string The wire protocol byte string holding the object |
| 1124 | represented as an array of bytes. |
| 1125 | @return The remainder of binary_string that was not parsed. |
| 1126 | |
| 1127 | """ |
| 1128 | binary_string = self.header.unpack(binary_string) |
| 1129 | |
| 1130 | binary_string = ofp_flow_removed.unpack(self, binary_string) |
| 1131 | # Fixme: If no self.data, add check for data remaining |
| 1132 | return binary_string |
| 1133 | |
| 1134 | def __len__(self): |
| 1135 | """ |
| 1136 | Return the length of this object once packed into a string |
| 1137 | |
| 1138 | @return An integer representing the number bytes in the packed |
| 1139 | string. |
| 1140 | |
| 1141 | """ |
| 1142 | length = OFP_HEADER_BYTES |
| 1143 | |
| 1144 | length += ofp_flow_removed.__len__(self) |
| 1145 | return length |
| 1146 | |
| 1147 | def show(self, prefix=''): |
| 1148 | """ |
| 1149 | Generate a string (with multiple lines) describing the contents |
| 1150 | of the object in a readable manner |
| 1151 | |
| 1152 | @param prefix Pre-pended at the beginning of each line. |
| 1153 | |
| 1154 | """ |
| 1155 | |
| 1156 | outstr = prefix + 'flow_removed (OFPT_FLOW_REMOVED)\n' |
| 1157 | prefix += ' ' |
| 1158 | outstr += prefix + 'ofp header\n' |
| 1159 | outstr += self.header.show(prefix + ' ') |
| 1160 | outstr += ofp_flow_removed.show(self, prefix) |
| 1161 | return outstr |
| 1162 | |
| 1163 | def __eq__(self, other): |
| 1164 | """ |
| 1165 | Return True if self and other hold the same data |
| 1166 | |
| 1167 | @param other Other object in comparison |
| 1168 | |
| 1169 | """ |
| 1170 | if type(self) != type(other): return False |
| 1171 | if not self.header.__eq__(other.header): return False |
| 1172 | |
| 1173 | if not ofp_flow_removed.__eq__(self, other): return False |
| 1174 | return True |
| 1175 | |
| 1176 | def __ne__(self, other): |
| 1177 | """ |
| 1178 | Return True if self and other do not hold the same data |
| 1179 | |
| 1180 | @param other Other object in comparison |
| 1181 | |
| 1182 | """ |
| 1183 | return not self.__eq__(other) |
| 1184 | |
| 1185 | |
| 1186 | class get_config_reply(ofp_switch_config): |
| 1187 | """ |
| 1188 | Wrapper class for get_config_reply |
| 1189 | |
| 1190 | OpenFlow message header: length, version, xid, type |
| 1191 | @arg length: The total length of the message |
| 1192 | @arg version: The OpenFlow version (2) |
| 1193 | @arg xid: The transaction ID |
| 1194 | @arg type: The message type (OFPT_GET_CONFIG_REPLY=8) |
| 1195 | |
| 1196 | Data members inherited from ofp_switch_config: |
| 1197 | @arg flags |
| 1198 | @arg miss_send_len |
| 1199 | |
| 1200 | """ |
| 1201 | |
| 1202 | def __init__(self): |
| 1203 | ofp_switch_config.__init__(self) |
| 1204 | self.header = ofp_header() |
| 1205 | self.header.type = OFPT_GET_CONFIG_REPLY |
| 1206 | |
| 1207 | |
| 1208 | def pack(self): |
| 1209 | """ |
| 1210 | Pack object into string |
| 1211 | |
| 1212 | @return The packed string which can go on the wire |
| 1213 | |
| 1214 | """ |
| 1215 | self.header.length = len(self) |
| 1216 | packed = self.header.pack() |
| 1217 | |
| 1218 | packed += ofp_switch_config.pack(self) |
| 1219 | return packed |
| 1220 | |
| 1221 | def unpack(self, binary_string): |
| 1222 | """ |
| 1223 | Unpack object from a binary string |
| 1224 | |
| 1225 | @param binary_string The wire protocol byte string holding the object |
| 1226 | represented as an array of bytes. |
| 1227 | @return The remainder of binary_string that was not parsed. |
| 1228 | |
| 1229 | """ |
| 1230 | binary_string = self.header.unpack(binary_string) |
| 1231 | |
| 1232 | binary_string = ofp_switch_config.unpack(self, binary_string) |
| 1233 | # Fixme: If no self.data, add check for data remaining |
| 1234 | return binary_string |
| 1235 | |
| 1236 | def __len__(self): |
| 1237 | """ |
| 1238 | Return the length of this object once packed into a string |
| 1239 | |
| 1240 | @return An integer representing the number bytes in the packed |
| 1241 | string. |
| 1242 | |
| 1243 | """ |
| 1244 | length = OFP_HEADER_BYTES |
| 1245 | |
| 1246 | length += ofp_switch_config.__len__(self) |
| 1247 | return length |
| 1248 | |
| 1249 | def show(self, prefix=''): |
| 1250 | """ |
| 1251 | Generate a string (with multiple lines) describing the contents |
| 1252 | of the object in a readable manner |
| 1253 | |
| 1254 | @param prefix Pre-pended at the beginning of each line. |
| 1255 | |
| 1256 | """ |
| 1257 | |
| 1258 | outstr = prefix + 'get_config_reply (OFPT_GET_CONFIG_REPLY)\n' |
| 1259 | prefix += ' ' |
| 1260 | outstr += prefix + 'ofp header\n' |
| 1261 | outstr += self.header.show(prefix + ' ') |
| 1262 | outstr += ofp_switch_config.show(self, prefix) |
| 1263 | return outstr |
| 1264 | |
| 1265 | def __eq__(self, other): |
| 1266 | """ |
| 1267 | Return True if self and other hold the same data |
| 1268 | |
| 1269 | @param other Other object in comparison |
| 1270 | |
| 1271 | """ |
| 1272 | if type(self) != type(other): return False |
| 1273 | if not self.header.__eq__(other.header): return False |
| 1274 | |
| 1275 | if not ofp_switch_config.__eq__(self, other): return False |
| 1276 | return True |
| 1277 | |
| 1278 | def __ne__(self, other): |
| 1279 | """ |
| 1280 | Return True if self and other do not hold the same data |
| 1281 | |
| 1282 | @param other Other object in comparison |
| 1283 | |
| 1284 | """ |
| 1285 | return not self.__eq__(other) |
| 1286 | |
| 1287 | |
| 1288 | class get_config_request(object): |
| 1289 | """ |
| 1290 | Wrapper class for get_config_request |
| 1291 | |
| 1292 | OpenFlow message header: length, version, xid, type |
| 1293 | @arg length: The total length of the message |
| 1294 | @arg version: The OpenFlow version (2) |
| 1295 | @arg xid: The transaction ID |
| 1296 | @arg type: The message type (OFPT_GET_CONFIG_REQUEST=7) |
| 1297 | |
| 1298 | |
| 1299 | """ |
| 1300 | |
| 1301 | def __init__(self): |
| 1302 | self.header = ofp_header() |
| 1303 | self.header.type = OFPT_GET_CONFIG_REQUEST |
| 1304 | |
| 1305 | |
| 1306 | def pack(self): |
| 1307 | """ |
| 1308 | Pack object into string |
| 1309 | |
| 1310 | @return The packed string which can go on the wire |
| 1311 | |
| 1312 | """ |
| 1313 | self.header.length = len(self) |
| 1314 | packed = self.header.pack() |
| 1315 | |
| 1316 | return packed |
| 1317 | |
| 1318 | def unpack(self, binary_string): |
| 1319 | """ |
| 1320 | Unpack object from a binary string |
| 1321 | |
| 1322 | @param binary_string The wire protocol byte string holding the object |
| 1323 | represented as an array of bytes. |
| 1324 | @return The remainder of binary_string that was not parsed. |
| 1325 | |
| 1326 | """ |
| 1327 | binary_string = self.header.unpack(binary_string) |
| 1328 | |
| 1329 | # Fixme: If no self.data, add check for data remaining |
| 1330 | return binary_string |
| 1331 | |
| 1332 | def __len__(self): |
| 1333 | """ |
| 1334 | Return the length of this object once packed into a string |
| 1335 | |
| 1336 | @return An integer representing the number bytes in the packed |
| 1337 | string. |
| 1338 | |
| 1339 | """ |
| 1340 | length = OFP_HEADER_BYTES |
| 1341 | |
| 1342 | return length |
| 1343 | |
| 1344 | def show(self, prefix=''): |
| 1345 | """ |
| 1346 | Generate a string (with multiple lines) describing the contents |
| 1347 | of the object in a readable manner |
| 1348 | |
| 1349 | @param prefix Pre-pended at the beginning of each line. |
| 1350 | |
| 1351 | """ |
| 1352 | |
| 1353 | outstr = prefix + 'get_config_request (OFPT_GET_CONFIG_REQUEST)\n' |
| 1354 | prefix += ' ' |
| 1355 | outstr += prefix + 'ofp header\n' |
| 1356 | outstr += self.header.show(prefix + ' ') |
| 1357 | return outstr |
| 1358 | |
| 1359 | def __eq__(self, other): |
| 1360 | """ |
| 1361 | Return True if self and other hold the same data |
| 1362 | |
| 1363 | @param other Other object in comparison |
| 1364 | |
| 1365 | """ |
| 1366 | if type(self) != type(other): return False |
| 1367 | if not self.header.__eq__(other.header): return False |
| 1368 | |
| 1369 | return True |
| 1370 | |
| 1371 | def __ne__(self, other): |
| 1372 | """ |
| 1373 | Return True if self and other do not hold the same data |
| 1374 | |
| 1375 | @param other Other object in comparison |
| 1376 | |
| 1377 | """ |
| 1378 | return not self.__eq__(other) |
| 1379 | |
| 1380 | |
| 1381 | class group_mod(ofp_group_mod): |
| 1382 | """ |
| 1383 | Wrapper class for group_mod |
| 1384 | |
| 1385 | OpenFlow message header: length, version, xid, type |
| 1386 | @arg length: The total length of the message |
| 1387 | @arg version: The OpenFlow version (2) |
| 1388 | @arg xid: The transaction ID |
| 1389 | @arg type: The message type (OFPT_GROUP_MOD=15) |
| 1390 | |
| 1391 | Data members inherited from ofp_group_mod: |
| 1392 | @arg command |
| 1393 | @arg type |
| 1394 | @arg group_id |
| 1395 | @arg buckets: Object of type bucket_list |
| 1396 | |
| 1397 | """ |
| 1398 | |
| 1399 | def __init__(self): |
| 1400 | ofp_group_mod.__init__(self) |
| 1401 | self.header = ofp_header() |
| 1402 | self.header.type = OFPT_GROUP_MOD |
| 1403 | self.buckets = bucket_list() |
| 1404 | |
| 1405 | |
| 1406 | def pack(self): |
| 1407 | """ |
| 1408 | Pack object into string |
| 1409 | |
| 1410 | @return The packed string which can go on the wire |
| 1411 | |
| 1412 | """ |
| 1413 | self.header.length = len(self) |
| 1414 | packed = self.header.pack() |
| 1415 | |
| 1416 | packed += ofp_group_mod.pack(self) |
| 1417 | packed += self.buckets.pack() |
| 1418 | return packed |
| 1419 | |
| 1420 | def unpack(self, binary_string): |
| 1421 | """ |
| 1422 | Unpack object from a binary string |
| 1423 | |
| 1424 | @param binary_string The wire protocol byte string holding the object |
| 1425 | represented as an array of bytes. |
| 1426 | @return The remainder of binary_string that was not parsed. |
| 1427 | |
| 1428 | """ |
| 1429 | binary_string = self.header.unpack(binary_string) |
| 1430 | |
| 1431 | binary_string = ofp_group_mod.unpack(self, binary_string) |
| 1432 | binary_string = self.buckets.unpack(binary_string) |
| 1433 | # Fixme: If no self.data, add check for data remaining |
| 1434 | return binary_string |
| 1435 | |
| 1436 | def __len__(self): |
| 1437 | """ |
| 1438 | Return the length of this object once packed into a string |
| 1439 | |
| 1440 | @return An integer representing the number bytes in the packed |
| 1441 | string. |
| 1442 | |
| 1443 | """ |
| 1444 | length = OFP_HEADER_BYTES |
| 1445 | |
| 1446 | length += ofp_group_mod.__len__(self) |
| 1447 | length += len(self.buckets) |
| 1448 | return length |
| 1449 | |
| 1450 | def show(self, prefix=''): |
| 1451 | """ |
| 1452 | Generate a string (with multiple lines) describing the contents |
| 1453 | of the object in a readable manner |
| 1454 | |
| 1455 | @param prefix Pre-pended at the beginning of each line. |
| 1456 | |
| 1457 | """ |
| 1458 | |
| 1459 | outstr = prefix + 'group_mod (OFPT_GROUP_MOD)\n' |
| 1460 | prefix += ' ' |
| 1461 | outstr += prefix + 'ofp header\n' |
| 1462 | outstr += self.header.show(prefix + ' ') |
| 1463 | outstr += ofp_group_mod.show(self, prefix) |
| 1464 | outstr += prefix + "List buckets\n" |
| 1465 | outstr += self.buckets.show(prefix + ' ') |
| 1466 | return outstr |
| 1467 | |
| 1468 | def __eq__(self, other): |
| 1469 | """ |
| 1470 | Return True if self and other hold the same data |
| 1471 | |
| 1472 | @param other Other object in comparison |
| 1473 | |
| 1474 | """ |
| 1475 | if type(self) != type(other): return False |
| 1476 | if not self.header.__eq__(other.header): return False |
| 1477 | |
| 1478 | if not ofp_group_mod.__eq__(self, other): return False |
| 1479 | if self.buckets != other.buckets: return False |
| 1480 | return True |
| 1481 | |
| 1482 | def __ne__(self, other): |
| 1483 | """ |
| 1484 | Return True if self and other do not hold the same data |
| 1485 | |
| 1486 | @param other Other object in comparison |
| 1487 | |
| 1488 | """ |
| 1489 | return not self.__eq__(other) |
| 1490 | |
| 1491 | |
| 1492 | class hello(object): |
| 1493 | """ |
| 1494 | Wrapper class for hello |
| 1495 | |
| 1496 | OpenFlow message header: length, version, xid, type |
| 1497 | @arg length: The total length of the message |
| 1498 | @arg version: The OpenFlow version (2) |
| 1499 | @arg xid: The transaction ID |
| 1500 | @arg type: The message type (OFPT_HELLO=0) |
| 1501 | |
| 1502 | @arg data: Binary string following message members |
| 1503 | |
| 1504 | """ |
| 1505 | |
| 1506 | def __init__(self): |
| 1507 | self.header = ofp_header() |
| 1508 | self.header.type = OFPT_HELLO |
| 1509 | self.data = "" |
| 1510 | |
| 1511 | |
| 1512 | def pack(self): |
| 1513 | """ |
| 1514 | Pack object into string |
| 1515 | |
| 1516 | @return The packed string which can go on the wire |
| 1517 | |
| 1518 | """ |
| 1519 | self.header.length = len(self) |
| 1520 | packed = self.header.pack() |
| 1521 | |
| 1522 | packed += self.data |
| 1523 | return packed |
| 1524 | |
| 1525 | def unpack(self, binary_string): |
| 1526 | """ |
| 1527 | Unpack object from a binary string |
| 1528 | |
| 1529 | @param binary_string The wire protocol byte string holding the object |
| 1530 | represented as an array of bytes. |
| 1531 | @return The remainder of binary_string that was not parsed. |
| 1532 | |
| 1533 | """ |
| 1534 | binary_string = self.header.unpack(binary_string) |
| 1535 | |
| 1536 | self.data = binary_string |
| 1537 | binary_string = '' |
| 1538 | return binary_string |
| 1539 | |
| 1540 | def __len__(self): |
| 1541 | """ |
| 1542 | Return the length of this object once packed into a string |
| 1543 | |
| 1544 | @return An integer representing the number bytes in the packed |
| 1545 | string. |
| 1546 | |
| 1547 | """ |
| 1548 | length = OFP_HEADER_BYTES |
| 1549 | |
| 1550 | length += len(self.data) |
| 1551 | return length |
| 1552 | |
| 1553 | def show(self, prefix=''): |
| 1554 | """ |
| 1555 | Generate a string (with multiple lines) describing the contents |
| 1556 | of the object in a readable manner |
| 1557 | |
| 1558 | @param prefix Pre-pended at the beginning of each line. |
| 1559 | |
| 1560 | """ |
| 1561 | |
| 1562 | outstr = prefix + 'hello (OFPT_HELLO)\n' |
| 1563 | prefix += ' ' |
| 1564 | outstr += prefix + 'ofp header\n' |
| 1565 | outstr += self.header.show(prefix + ' ') |
| 1566 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 1567 | ##@todo Fix this circular reference |
| 1568 | # if len(self.data) > 0: |
| 1569 | # obj = of_message_parse(self.data) |
| 1570 | # if obj != None: |
| 1571 | # outstr += obj.show(prefix) |
| 1572 | # else: |
| 1573 | # outstr += prefix + "Unable to parse data\n" |
| 1574 | return outstr |
| 1575 | |
| 1576 | def __eq__(self, other): |
| 1577 | """ |
| 1578 | Return True if self and other hold the same data |
| 1579 | |
| 1580 | @param other Other object in comparison |
| 1581 | |
| 1582 | """ |
| 1583 | if type(self) != type(other): return False |
| 1584 | if not self.header.__eq__(other.header): return False |
| 1585 | |
| 1586 | if self.data != other.data: return False |
| 1587 | return True |
| 1588 | |
| 1589 | def __ne__(self, other): |
| 1590 | """ |
| 1591 | Return True if self and other do not hold the same data |
| 1592 | |
| 1593 | @param other Other object in comparison |
| 1594 | |
| 1595 | """ |
| 1596 | return not self.__eq__(other) |
| 1597 | |
| 1598 | |
| 1599 | class packet_in(ofp_packet_in): |
| 1600 | """ |
| 1601 | Wrapper class for packet_in |
| 1602 | |
| 1603 | OpenFlow message header: length, version, xid, type |
| 1604 | @arg length: The total length of the message |
| 1605 | @arg version: The OpenFlow version (2) |
| 1606 | @arg xid: The transaction ID |
| 1607 | @arg type: The message type (OFPT_PACKET_IN=10) |
| 1608 | |
| 1609 | Data members inherited from ofp_packet_in: |
| 1610 | @arg buffer_id |
| 1611 | @arg in_port |
| 1612 | @arg in_phy_port |
| 1613 | @arg total_len |
| 1614 | @arg reason |
| 1615 | @arg table_id |
| 1616 | @arg data: Binary string following message members |
| 1617 | |
| 1618 | """ |
| 1619 | |
| 1620 | def __init__(self): |
| 1621 | ofp_packet_in.__init__(self) |
| 1622 | self.header = ofp_header() |
| 1623 | self.header.type = OFPT_PACKET_IN |
| 1624 | self.data = "" |
| 1625 | |
| 1626 | |
| 1627 | def pack(self): |
| 1628 | """ |
| 1629 | Pack object into string |
| 1630 | |
| 1631 | @return The packed string which can go on the wire |
| 1632 | |
| 1633 | """ |
| 1634 | self.header.length = len(self) |
| 1635 | packed = self.header.pack() |
| 1636 | |
| 1637 | packed += ofp_packet_in.pack(self) |
| 1638 | packed += self.data |
| 1639 | return packed |
| 1640 | |
| 1641 | def unpack(self, binary_string): |
| 1642 | """ |
| 1643 | Unpack object from a binary string |
| 1644 | |
| 1645 | @param binary_string The wire protocol byte string holding the object |
| 1646 | represented as an array of bytes. |
| 1647 | @return The remainder of binary_string that was not parsed. |
| 1648 | |
| 1649 | """ |
| 1650 | binary_string = self.header.unpack(binary_string) |
| 1651 | |
| 1652 | binary_string = ofp_packet_in.unpack(self, binary_string) |
| 1653 | self.data = binary_string |
| 1654 | binary_string = '' |
| 1655 | return binary_string |
| 1656 | |
| 1657 | def __len__(self): |
| 1658 | """ |
| 1659 | Return the length of this object once packed into a string |
| 1660 | |
| 1661 | @return An integer representing the number bytes in the packed |
| 1662 | string. |
| 1663 | |
| 1664 | """ |
| 1665 | length = OFP_HEADER_BYTES |
| 1666 | |
| 1667 | length += ofp_packet_in.__len__(self) |
| 1668 | length += len(self.data) |
| 1669 | return length |
| 1670 | |
| 1671 | def show(self, prefix=''): |
| 1672 | """ |
| 1673 | Generate a string (with multiple lines) describing the contents |
| 1674 | of the object in a readable manner |
| 1675 | |
| 1676 | @param prefix Pre-pended at the beginning of each line. |
| 1677 | |
| 1678 | """ |
| 1679 | |
| 1680 | outstr = prefix + 'packet_in (OFPT_PACKET_IN)\n' |
| 1681 | prefix += ' ' |
| 1682 | outstr += prefix + 'ofp header\n' |
| 1683 | outstr += self.header.show(prefix + ' ') |
| 1684 | outstr += ofp_packet_in.show(self, prefix) |
| 1685 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 1686 | ##@todo Fix this circular reference |
| 1687 | # if len(self.data) > 0: |
| 1688 | # obj = of_message_parse(self.data) |
| 1689 | # if obj != None: |
| 1690 | # outstr += obj.show(prefix) |
| 1691 | # else: |
| 1692 | # outstr += prefix + "Unable to parse data\n" |
| 1693 | return outstr |
| 1694 | |
| 1695 | def __eq__(self, other): |
| 1696 | """ |
| 1697 | Return True if self and other hold the same data |
| 1698 | |
| 1699 | @param other Other object in comparison |
| 1700 | |
| 1701 | """ |
| 1702 | if type(self) != type(other): return False |
| 1703 | if not self.header.__eq__(other.header): return False |
| 1704 | |
| 1705 | if not ofp_packet_in.__eq__(self, other): return False |
| 1706 | if self.data != other.data: return False |
| 1707 | return True |
| 1708 | |
| 1709 | def __ne__(self, other): |
| 1710 | """ |
| 1711 | Return True if self and other do not hold the same data |
| 1712 | |
| 1713 | @param other Other object in comparison |
| 1714 | |
| 1715 | """ |
| 1716 | return not self.__eq__(other) |
| 1717 | |
| 1718 | |
| 1719 | class packet_out(ofp_packet_out): |
| 1720 | """ |
| 1721 | Wrapper class for packet_out |
| 1722 | |
| 1723 | OpenFlow message header: length, version, xid, type |
| 1724 | @arg length: The total length of the message |
| 1725 | @arg version: The OpenFlow version (2) |
| 1726 | @arg xid: The transaction ID |
| 1727 | @arg type: The message type (OFPT_PACKET_OUT=13) |
| 1728 | |
| 1729 | Data members inherited from ofp_packet_out: |
| 1730 | @arg buffer_id |
| 1731 | @arg in_port |
| 1732 | @arg actions_len |
| 1733 | @arg actions: Object of type action_list |
| 1734 | @arg data: Binary string following message members |
| 1735 | |
| 1736 | """ |
| 1737 | |
| 1738 | def __init__(self): |
| 1739 | ofp_packet_out.__init__(self) |
| 1740 | self.header = ofp_header() |
| 1741 | self.header.type = OFPT_PACKET_OUT |
| 1742 | self.actions = action_list() |
| 1743 | self.data = "" |
| 1744 | |
| 1745 | |
| 1746 | def pack(self): |
| 1747 | """ |
| 1748 | Pack object into string |
| 1749 | |
| 1750 | @return The packed string which can go on the wire |
| 1751 | |
| 1752 | """ |
| 1753 | self.header.length = len(self) |
| 1754 | packed = self.header.pack() |
| 1755 | |
| 1756 | self.actions_len = len(self.actions) |
| 1757 | packed += ofp_packet_out.pack(self) |
| 1758 | packed += self.actions.pack() |
| 1759 | packed += self.data |
| 1760 | return packed |
| 1761 | |
| 1762 | def unpack(self, binary_string): |
| 1763 | """ |
| 1764 | Unpack object from a binary string |
| 1765 | |
| 1766 | @param binary_string The wire protocol byte string holding the object |
| 1767 | represented as an array of bytes. |
| 1768 | @return The remainder of binary_string that was not parsed. |
| 1769 | |
| 1770 | """ |
| 1771 | binary_string = self.header.unpack(binary_string) |
| 1772 | |
| 1773 | binary_string = ofp_packet_out.unpack(self, binary_string) |
| 1774 | binary_string = self.actions.unpack(binary_string, bytes=self.actions_len) |
| 1775 | self.data = binary_string |
| 1776 | binary_string = '' |
| 1777 | return binary_string |
| 1778 | |
| 1779 | def __len__(self): |
| 1780 | """ |
| 1781 | Return the length of this object once packed into a string |
| 1782 | |
| 1783 | @return An integer representing the number bytes in the packed |
| 1784 | string. |
| 1785 | |
| 1786 | """ |
| 1787 | length = OFP_HEADER_BYTES |
| 1788 | |
| 1789 | length += ofp_packet_out.__len__(self) |
| 1790 | length += len(self.actions) |
| 1791 | length += len(self.data) |
| 1792 | return length |
| 1793 | |
| 1794 | def show(self, prefix=''): |
| 1795 | """ |
| 1796 | Generate a string (with multiple lines) describing the contents |
| 1797 | of the object in a readable manner |
| 1798 | |
| 1799 | @param prefix Pre-pended at the beginning of each line. |
| 1800 | |
| 1801 | """ |
| 1802 | |
| 1803 | outstr = prefix + 'packet_out (OFPT_PACKET_OUT)\n' |
| 1804 | prefix += ' ' |
| 1805 | outstr += prefix + 'ofp header\n' |
| 1806 | outstr += self.header.show(prefix + ' ') |
| 1807 | outstr += ofp_packet_out.show(self, prefix) |
| 1808 | outstr += prefix + "List actions\n" |
| 1809 | outstr += self.actions.show(prefix + ' ') |
| 1810 | outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n' |
| 1811 | ##@todo Fix this circular reference |
| 1812 | # if len(self.data) > 0: |
| 1813 | # obj = of_message_parse(self.data) |
| 1814 | # if obj != None: |
| 1815 | # outstr += obj.show(prefix) |
| 1816 | # else: |
| 1817 | # outstr += prefix + "Unable to parse data\n" |
| 1818 | return outstr |
| 1819 | |
| 1820 | def __eq__(self, other): |
| 1821 | """ |
| 1822 | Return True if self and other hold the same data |
| 1823 | |
| 1824 | @param other Other object in comparison |
| 1825 | |
| 1826 | """ |
| 1827 | if type(self) != type(other): return False |
| 1828 | if not self.header.__eq__(other.header): return False |
| 1829 | |
| 1830 | if not ofp_packet_out.__eq__(self, other): return False |
| 1831 | if self.data != other.data: return False |
| 1832 | if self.actions != other.actions: return False |
| 1833 | return True |
| 1834 | |
| 1835 | def __ne__(self, other): |
| 1836 | """ |
| 1837 | Return True if self and other do not hold the same data |
| 1838 | |
| 1839 | @param other Other object in comparison |
| 1840 | |
| 1841 | """ |
| 1842 | return not self.__eq__(other) |
| 1843 | |
| 1844 | |
| 1845 | class port_mod(ofp_port_mod): |
| 1846 | """ |
| 1847 | Wrapper class for port_mod |
| 1848 | |
| 1849 | OpenFlow message header: length, version, xid, type |
| 1850 | @arg length: The total length of the message |
| 1851 | @arg version: The OpenFlow version (2) |
| 1852 | @arg xid: The transaction ID |
| 1853 | @arg type: The message type (OFPT_PORT_MOD=16) |
| 1854 | |
| 1855 | Data members inherited from ofp_port_mod: |
| 1856 | @arg port_no |
| 1857 | @arg hw_addr |
| 1858 | @arg config |
| 1859 | @arg mask |
| 1860 | @arg advertise |
| 1861 | |
| 1862 | """ |
| 1863 | |
| 1864 | def __init__(self): |
| 1865 | ofp_port_mod.__init__(self) |
| 1866 | self.header = ofp_header() |
| 1867 | self.header.type = OFPT_PORT_MOD |
| 1868 | |
| 1869 | |
| 1870 | def pack(self): |
| 1871 | """ |
| 1872 | Pack object into string |
| 1873 | |
| 1874 | @return The packed string which can go on the wire |
| 1875 | |
| 1876 | """ |
| 1877 | self.header.length = len(self) |
| 1878 | packed = self.header.pack() |
| 1879 | |
| 1880 | packed += ofp_port_mod.pack(self) |
| 1881 | return packed |
| 1882 | |
| 1883 | def unpack(self, binary_string): |
| 1884 | """ |
| 1885 | Unpack object from a binary string |
| 1886 | |
| 1887 | @param binary_string The wire protocol byte string holding the object |
| 1888 | represented as an array of bytes. |
| 1889 | @return The remainder of binary_string that was not parsed. |
| 1890 | |
| 1891 | """ |
| 1892 | binary_string = self.header.unpack(binary_string) |
| 1893 | |
| 1894 | binary_string = ofp_port_mod.unpack(self, binary_string) |
| 1895 | # Fixme: If no self.data, add check for data remaining |
| 1896 | return binary_string |
| 1897 | |
| 1898 | def __len__(self): |
| 1899 | """ |
| 1900 | Return the length of this object once packed into a string |
| 1901 | |
| 1902 | @return An integer representing the number bytes in the packed |
| 1903 | string. |
| 1904 | |
| 1905 | """ |
| 1906 | length = OFP_HEADER_BYTES |
| 1907 | |
| 1908 | length += ofp_port_mod.__len__(self) |
| 1909 | return length |
| 1910 | |
| 1911 | def show(self, prefix=''): |
| 1912 | """ |
| 1913 | Generate a string (with multiple lines) describing the contents |
| 1914 | of the object in a readable manner |
| 1915 | |
| 1916 | @param prefix Pre-pended at the beginning of each line. |
| 1917 | |
| 1918 | """ |
| 1919 | |
| 1920 | outstr = prefix + 'port_mod (OFPT_PORT_MOD)\n' |
| 1921 | prefix += ' ' |
| 1922 | outstr += prefix + 'ofp header\n' |
| 1923 | outstr += self.header.show(prefix + ' ') |
| 1924 | outstr += ofp_port_mod.show(self, prefix) |
| 1925 | return outstr |
| 1926 | |
| 1927 | def __eq__(self, other): |
| 1928 | """ |
| 1929 | Return True if self and other hold the same data |
| 1930 | |
| 1931 | @param other Other object in comparison |
| 1932 | |
| 1933 | """ |
| 1934 | if type(self) != type(other): return False |
| 1935 | if not self.header.__eq__(other.header): return False |
| 1936 | |
| 1937 | if not ofp_port_mod.__eq__(self, other): return False |
| 1938 | return True |
| 1939 | |
| 1940 | def __ne__(self, other): |
| 1941 | """ |
| 1942 | Return True if self and other do not hold the same data |
| 1943 | |
| 1944 | @param other Other object in comparison |
| 1945 | |
| 1946 | """ |
| 1947 | return not self.__eq__(other) |
| 1948 | |
| 1949 | |
| 1950 | class port_status(ofp_port_status): |
| 1951 | """ |
| 1952 | Wrapper class for port_status |
| 1953 | |
| 1954 | OpenFlow message header: length, version, xid, type |
| 1955 | @arg length: The total length of the message |
| 1956 | @arg version: The OpenFlow version (2) |
| 1957 | @arg xid: The transaction ID |
| 1958 | @arg type: The message type (OFPT_PORT_STATUS=12) |
| 1959 | |
| 1960 | Data members inherited from ofp_port_status: |
| 1961 | @arg reason |
| 1962 | @arg desc |
| 1963 | |
| 1964 | """ |
| 1965 | |
| 1966 | def __init__(self): |
| 1967 | ofp_port_status.__init__(self) |
| 1968 | self.header = ofp_header() |
| 1969 | self.header.type = OFPT_PORT_STATUS |
| 1970 | |
| 1971 | |
| 1972 | def pack(self): |
| 1973 | """ |
| 1974 | Pack object into string |
| 1975 | |
| 1976 | @return The packed string which can go on the wire |
| 1977 | |
| 1978 | """ |
| 1979 | self.header.length = len(self) |
| 1980 | packed = self.header.pack() |
| 1981 | |
| 1982 | packed += ofp_port_status.pack(self) |
| 1983 | return packed |
| 1984 | |
| 1985 | def unpack(self, binary_string): |
| 1986 | """ |
| 1987 | Unpack object from a binary string |
| 1988 | |
| 1989 | @param binary_string The wire protocol byte string holding the object |
| 1990 | represented as an array of bytes. |
| 1991 | @return The remainder of binary_string that was not parsed. |
| 1992 | |
| 1993 | """ |
| 1994 | binary_string = self.header.unpack(binary_string) |
| 1995 | |
| 1996 | binary_string = ofp_port_status.unpack(self, binary_string) |
| 1997 | # Fixme: If no self.data, add check for data remaining |
| 1998 | return binary_string |
| 1999 | |
| 2000 | def __len__(self): |
| 2001 | """ |
| 2002 | Return the length of this object once packed into a string |
| 2003 | |
| 2004 | @return An integer representing the number bytes in the packed |
| 2005 | string. |
| 2006 | |
| 2007 | """ |
| 2008 | length = OFP_HEADER_BYTES |
| 2009 | |
| 2010 | length += ofp_port_status.__len__(self) |
| 2011 | return length |
| 2012 | |
| 2013 | def show(self, prefix=''): |
| 2014 | """ |
| 2015 | Generate a string (with multiple lines) describing the contents |
| 2016 | of the object in a readable manner |
| 2017 | |
| 2018 | @param prefix Pre-pended at the beginning of each line. |
| 2019 | |
| 2020 | """ |
| 2021 | |
| 2022 | outstr = prefix + 'port_status (OFPT_PORT_STATUS)\n' |
| 2023 | prefix += ' ' |
| 2024 | outstr += prefix + 'ofp header\n' |
| 2025 | outstr += self.header.show(prefix + ' ') |
| 2026 | outstr += ofp_port_status.show(self, prefix) |
| 2027 | return outstr |
| 2028 | |
| 2029 | def __eq__(self, other): |
| 2030 | """ |
| 2031 | Return True if self and other hold the same data |
| 2032 | |
| 2033 | @param other Other object in comparison |
| 2034 | |
| 2035 | """ |
| 2036 | if type(self) != type(other): return False |
| 2037 | if not self.header.__eq__(other.header): return False |
| 2038 | |
| 2039 | if not ofp_port_status.__eq__(self, other): return False |
| 2040 | return True |
| 2041 | |
| 2042 | def __ne__(self, other): |
| 2043 | """ |
| 2044 | Return True if self and other do not hold the same data |
| 2045 | |
| 2046 | @param other Other object in comparison |
| 2047 | |
| 2048 | """ |
| 2049 | return not self.__eq__(other) |
| 2050 | |
| 2051 | |
| 2052 | class queue_get_config_reply(ofp_queue_get_config_reply): |
| 2053 | """ |
| 2054 | Wrapper class for queue_get_config_reply |
| 2055 | |
| 2056 | OpenFlow message header: length, version, xid, type |
| 2057 | @arg length: The total length of the message |
| 2058 | @arg version: The OpenFlow version (2) |
| 2059 | @arg xid: The transaction ID |
| 2060 | @arg type: The message type (OFPT_QUEUE_GET_CONFIG_REPLY=23) |
| 2061 | |
| 2062 | Data members inherited from ofp_queue_get_config_reply: |
| 2063 | @arg port |
| 2064 | @arg queues: Variable length array of TBD |
| 2065 | |
| 2066 | """ |
| 2067 | |
| 2068 | def __init__(self): |
| 2069 | ofp_queue_get_config_reply.__init__(self) |
| 2070 | self.header = ofp_header() |
| 2071 | self.header.type = OFPT_QUEUE_GET_CONFIG_REPLY |
| 2072 | self.queues = [] |
| 2073 | |
| 2074 | |
| 2075 | def pack(self): |
| 2076 | """ |
| 2077 | Pack object into string |
| 2078 | |
| 2079 | @return The packed string which can go on the wire |
| 2080 | |
| 2081 | """ |
| 2082 | self.header.length = len(self) |
| 2083 | packed = self.header.pack() |
| 2084 | |
| 2085 | packed += ofp_queue_get_config_reply.pack(self) |
| 2086 | for obj in self.queues: |
| 2087 | packed += obj.pack() |
| 2088 | return packed |
| 2089 | |
| 2090 | def unpack(self, binary_string): |
| 2091 | """ |
| 2092 | Unpack object from a binary string |
| 2093 | |
| 2094 | @param binary_string The wire protocol byte string holding the object |
| 2095 | represented as an array of bytes. |
| 2096 | @return The remainder of binary_string that was not parsed. |
| 2097 | |
| 2098 | """ |
| 2099 | binary_string = self.header.unpack(binary_string) |
| 2100 | |
| 2101 | binary_string = ofp_queue_get_config_reply.unpack(self, binary_string) |
| 2102 | for obj in self.queues: |
| 2103 | binary_string = obj.unpack(binary_string) |
| 2104 | # Fixme: If no self.data, add check for data remaining |
| 2105 | return binary_string |
| 2106 | |
| 2107 | def __len__(self): |
| 2108 | """ |
| 2109 | Return the length of this object once packed into a string |
| 2110 | |
| 2111 | @return An integer representing the number bytes in the packed |
| 2112 | string. |
| 2113 | |
| 2114 | """ |
| 2115 | length = OFP_HEADER_BYTES |
| 2116 | |
| 2117 | length += ofp_queue_get_config_reply.__len__(self) |
| 2118 | for obj in self.queues: |
| 2119 | length += len(obj) |
| 2120 | return length |
| 2121 | |
| 2122 | def show(self, prefix=''): |
| 2123 | """ |
| 2124 | Generate a string (with multiple lines) describing the contents |
| 2125 | of the object in a readable manner |
| 2126 | |
| 2127 | @param prefix Pre-pended at the beginning of each line. |
| 2128 | |
| 2129 | """ |
| 2130 | |
| 2131 | outstr = prefix + 'queue_get_config_reply (OFPT_QUEUE_GET_CONFIG_REPLY)\n' |
| 2132 | prefix += ' ' |
| 2133 | outstr += prefix + 'ofp header\n' |
| 2134 | outstr += self.header.show(prefix + ' ') |
| 2135 | outstr += ofp_queue_get_config_reply.show(self, prefix) |
| 2136 | outstr += prefix + "Array queues\n" |
| 2137 | for obj in self.queues: |
| 2138 | outstr += obj.show(prefix + ' ') |
| 2139 | return outstr |
| 2140 | |
| 2141 | def __eq__(self, other): |
| 2142 | """ |
| 2143 | Return True if self and other hold the same data |
| 2144 | |
| 2145 | @param other Other object in comparison |
| 2146 | |
| 2147 | """ |
| 2148 | if type(self) != type(other): return False |
| 2149 | if not self.header.__eq__(other.header): return False |
| 2150 | |
| 2151 | if not ofp_queue_get_config_reply.__eq__(self, other): return False |
| 2152 | if self.queues != other.queues: return False |
| 2153 | return True |
| 2154 | |
| 2155 | def __ne__(self, other): |
| 2156 | """ |
| 2157 | Return True if self and other do not hold the same data |
| 2158 | |
| 2159 | @param other Other object in comparison |
| 2160 | |
| 2161 | """ |
| 2162 | return not self.__eq__(other) |
| 2163 | |
| 2164 | |
| 2165 | class queue_get_config_request(ofp_queue_get_config_request): |
| 2166 | """ |
| 2167 | Wrapper class for queue_get_config_request |
| 2168 | |
| 2169 | OpenFlow message header: length, version, xid, type |
| 2170 | @arg length: The total length of the message |
| 2171 | @arg version: The OpenFlow version (2) |
| 2172 | @arg xid: The transaction ID |
| 2173 | @arg type: The message type (OFPT_QUEUE_GET_CONFIG_REQUEST=22) |
| 2174 | |
| 2175 | Data members inherited from ofp_queue_get_config_request: |
| 2176 | @arg port |
| 2177 | |
| 2178 | """ |
| 2179 | |
| 2180 | def __init__(self): |
| 2181 | ofp_queue_get_config_request.__init__(self) |
| 2182 | self.header = ofp_header() |
| 2183 | self.header.type = OFPT_QUEUE_GET_CONFIG_REQUEST |
| 2184 | |
| 2185 | |
| 2186 | def pack(self): |
| 2187 | """ |
| 2188 | Pack object into string |
| 2189 | |
| 2190 | @return The packed string which can go on the wire |
| 2191 | |
| 2192 | """ |
| 2193 | self.header.length = len(self) |
| 2194 | packed = self.header.pack() |
| 2195 | |
| 2196 | packed += ofp_queue_get_config_request.pack(self) |
| 2197 | return packed |
| 2198 | |
| 2199 | def unpack(self, binary_string): |
| 2200 | """ |
| 2201 | Unpack object from a binary string |
| 2202 | |
| 2203 | @param binary_string The wire protocol byte string holding the object |
| 2204 | represented as an array of bytes. |
| 2205 | @return The remainder of binary_string that was not parsed. |
| 2206 | |
| 2207 | """ |
| 2208 | binary_string = self.header.unpack(binary_string) |
| 2209 | |
| 2210 | binary_string = ofp_queue_get_config_request.unpack(self, binary_string) |
| 2211 | # Fixme: If no self.data, add check for data remaining |
| 2212 | return binary_string |
| 2213 | |
| 2214 | def __len__(self): |
| 2215 | """ |
| 2216 | Return the length of this object once packed into a string |
| 2217 | |
| 2218 | @return An integer representing the number bytes in the packed |
| 2219 | string. |
| 2220 | |
| 2221 | """ |
| 2222 | length = OFP_HEADER_BYTES |
| 2223 | |
| 2224 | length += ofp_queue_get_config_request.__len__(self) |
| 2225 | return length |
| 2226 | |
| 2227 | def show(self, prefix=''): |
| 2228 | """ |
| 2229 | Generate a string (with multiple lines) describing the contents |
| 2230 | of the object in a readable manner |
| 2231 | |
| 2232 | @param prefix Pre-pended at the beginning of each line. |
| 2233 | |
| 2234 | """ |
| 2235 | |
| 2236 | outstr = prefix + 'queue_get_config_request (OFPT_QUEUE_GET_CONFIG_REQUEST)\n' |
| 2237 | prefix += ' ' |
| 2238 | outstr += prefix + 'ofp header\n' |
| 2239 | outstr += self.header.show(prefix + ' ') |
| 2240 | outstr += ofp_queue_get_config_request.show(self, prefix) |
| 2241 | return outstr |
| 2242 | |
| 2243 | def __eq__(self, other): |
| 2244 | """ |
| 2245 | Return True if self and other hold the same data |
| 2246 | |
| 2247 | @param other Other object in comparison |
| 2248 | |
| 2249 | """ |
| 2250 | if type(self) != type(other): return False |
| 2251 | if not self.header.__eq__(other.header): return False |
| 2252 | |
| 2253 | if not ofp_queue_get_config_request.__eq__(self, other): return False |
| 2254 | return True |
| 2255 | |
| 2256 | def __ne__(self, other): |
| 2257 | """ |
| 2258 | Return True if self and other do not hold the same data |
| 2259 | |
| 2260 | @param other Other object in comparison |
| 2261 | |
| 2262 | """ |
| 2263 | return not self.__eq__(other) |
| 2264 | |
| 2265 | |
| 2266 | class set_config(ofp_switch_config): |
| 2267 | """ |
| 2268 | Wrapper class for set_config |
| 2269 | |
| 2270 | OpenFlow message header: length, version, xid, type |
| 2271 | @arg length: The total length of the message |
| 2272 | @arg version: The OpenFlow version (2) |
| 2273 | @arg xid: The transaction ID |
| 2274 | @arg type: The message type (OFPT_SET_CONFIG=9) |
| 2275 | |
| 2276 | Data members inherited from ofp_switch_config: |
| 2277 | @arg flags |
| 2278 | @arg miss_send_len |
| 2279 | |
| 2280 | """ |
| 2281 | |
| 2282 | def __init__(self): |
| 2283 | ofp_switch_config.__init__(self) |
| 2284 | self.header = ofp_header() |
| 2285 | self.header.type = OFPT_SET_CONFIG |
| 2286 | |
| 2287 | |
| 2288 | def pack(self): |
| 2289 | """ |
| 2290 | Pack object into string |
| 2291 | |
| 2292 | @return The packed string which can go on the wire |
| 2293 | |
| 2294 | """ |
| 2295 | self.header.length = len(self) |
| 2296 | packed = self.header.pack() |
| 2297 | |
| 2298 | packed += ofp_switch_config.pack(self) |
| 2299 | return packed |
| 2300 | |
| 2301 | def unpack(self, binary_string): |
| 2302 | """ |
| 2303 | Unpack object from a binary string |
| 2304 | |
| 2305 | @param binary_string The wire protocol byte string holding the object |
| 2306 | represented as an array of bytes. |
| 2307 | @return The remainder of binary_string that was not parsed. |
| 2308 | |
| 2309 | """ |
| 2310 | binary_string = self.header.unpack(binary_string) |
| 2311 | |
| 2312 | binary_string = ofp_switch_config.unpack(self, binary_string) |
| 2313 | # Fixme: If no self.data, add check for data remaining |
| 2314 | return binary_string |
| 2315 | |
| 2316 | def __len__(self): |
| 2317 | """ |
| 2318 | Return the length of this object once packed into a string |
| 2319 | |
| 2320 | @return An integer representing the number bytes in the packed |
| 2321 | string. |
| 2322 | |
| 2323 | """ |
| 2324 | length = OFP_HEADER_BYTES |
| 2325 | |
| 2326 | length += ofp_switch_config.__len__(self) |
| 2327 | return length |
| 2328 | |
| 2329 | def show(self, prefix=''): |
| 2330 | """ |
| 2331 | Generate a string (with multiple lines) describing the contents |
| 2332 | of the object in a readable manner |
| 2333 | |
| 2334 | @param prefix Pre-pended at the beginning of each line. |
| 2335 | |
| 2336 | """ |
| 2337 | |
| 2338 | outstr = prefix + 'set_config (OFPT_SET_CONFIG)\n' |
| 2339 | prefix += ' ' |
| 2340 | outstr += prefix + 'ofp header\n' |
| 2341 | outstr += self.header.show(prefix + ' ') |
| 2342 | outstr += ofp_switch_config.show(self, prefix) |
| 2343 | return outstr |
| 2344 | |
| 2345 | def __eq__(self, other): |
| 2346 | """ |
| 2347 | Return True if self and other hold the same data |
| 2348 | |
| 2349 | @param other Other object in comparison |
| 2350 | |
| 2351 | """ |
| 2352 | if type(self) != type(other): return False |
| 2353 | if not self.header.__eq__(other.header): return False |
| 2354 | |
| 2355 | if not ofp_switch_config.__eq__(self, other): return False |
| 2356 | return True |
| 2357 | |
| 2358 | def __ne__(self, other): |
| 2359 | """ |
| 2360 | Return True if self and other do not hold the same data |
| 2361 | |
| 2362 | @param other Other object in comparison |
| 2363 | |
| 2364 | """ |
| 2365 | return not self.__eq__(other) |
| 2366 | |
| 2367 | |
| 2368 | class stats_reply(ofp_stats_reply): |
| 2369 | """ |
| 2370 | Wrapper class for stats_reply |
| 2371 | |
| 2372 | OpenFlow message header: length, version, xid, type |
| 2373 | @arg length: The total length of the message |
| 2374 | @arg version: The OpenFlow version (2) |
| 2375 | @arg xid: The transaction ID |
| 2376 | @arg type: The message type (OFPT_STATS_REPLY=19) |
| 2377 | |
| 2378 | Data members inherited from ofp_stats_reply: |
| 2379 | @arg type |
| 2380 | @arg flags |
| 2381 | |
| 2382 | """ |
| 2383 | |
| 2384 | def __init__(self): |
| 2385 | ofp_stats_reply.__init__(self) |
| 2386 | self.header = ofp_header() |
| 2387 | self.header.type = OFPT_STATS_REPLY |
| 2388 | |
| 2389 | |
| 2390 | def pack(self): |
| 2391 | """ |
| 2392 | Pack object into string |
| 2393 | |
| 2394 | @return The packed string which can go on the wire |
| 2395 | |
| 2396 | """ |
| 2397 | self.header.length = len(self) |
| 2398 | packed = self.header.pack() |
| 2399 | |
| 2400 | packed += ofp_stats_reply.pack(self) |
| 2401 | return packed |
| 2402 | |
| 2403 | def unpack(self, binary_string): |
| 2404 | """ |
| 2405 | Unpack object from a binary string |
| 2406 | |
| 2407 | @param binary_string The wire protocol byte string holding the object |
| 2408 | represented as an array of bytes. |
| 2409 | @return The remainder of binary_string that was not parsed. |
| 2410 | |
| 2411 | """ |
| 2412 | binary_string = self.header.unpack(binary_string) |
| 2413 | |
| 2414 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 2415 | # Fixme: If no self.data, add check for data remaining |
| 2416 | return binary_string |
| 2417 | |
| 2418 | def __len__(self): |
| 2419 | """ |
| 2420 | Return the length of this object once packed into a string |
| 2421 | |
| 2422 | @return An integer representing the number bytes in the packed |
| 2423 | string. |
| 2424 | |
| 2425 | """ |
| 2426 | length = OFP_HEADER_BYTES |
| 2427 | |
| 2428 | length += ofp_stats_reply.__len__(self) |
| 2429 | return length |
| 2430 | |
| 2431 | def show(self, prefix=''): |
| 2432 | """ |
| 2433 | Generate a string (with multiple lines) describing the contents |
| 2434 | of the object in a readable manner |
| 2435 | |
| 2436 | @param prefix Pre-pended at the beginning of each line. |
| 2437 | |
| 2438 | """ |
| 2439 | |
| 2440 | outstr = prefix + 'stats_reply (OFPT_STATS_REPLY)\n' |
| 2441 | prefix += ' ' |
| 2442 | outstr += prefix + 'ofp header\n' |
| 2443 | outstr += self.header.show(prefix + ' ') |
| 2444 | outstr += ofp_stats_reply.show(self, prefix) |
| 2445 | return outstr |
| 2446 | |
| 2447 | def __eq__(self, other): |
| 2448 | """ |
| 2449 | Return True if self and other hold the same data |
| 2450 | |
| 2451 | @param other Other object in comparison |
| 2452 | |
| 2453 | """ |
| 2454 | if type(self) != type(other): return False |
| 2455 | if not self.header.__eq__(other.header): return False |
| 2456 | |
| 2457 | if not ofp_stats_reply.__eq__(self, other): return False |
| 2458 | return True |
| 2459 | |
| 2460 | def __ne__(self, other): |
| 2461 | """ |
| 2462 | Return True if self and other do not hold the same data |
| 2463 | |
| 2464 | @param other Other object in comparison |
| 2465 | |
| 2466 | """ |
| 2467 | return not self.__eq__(other) |
| 2468 | |
| 2469 | |
| 2470 | class stats_request(ofp_stats_request): |
| 2471 | """ |
| 2472 | Wrapper class for stats_request |
| 2473 | |
| 2474 | OpenFlow message header: length, version, xid, type |
| 2475 | @arg length: The total length of the message |
| 2476 | @arg version: The OpenFlow version (2) |
| 2477 | @arg xid: The transaction ID |
| 2478 | @arg type: The message type (OFPT_STATS_REQUEST=18) |
| 2479 | |
| 2480 | Data members inherited from ofp_stats_request: |
| 2481 | @arg type |
| 2482 | @arg flags |
| 2483 | |
| 2484 | """ |
| 2485 | |
| 2486 | def __init__(self): |
| 2487 | ofp_stats_request.__init__(self) |
| 2488 | self.header = ofp_header() |
| 2489 | self.header.type = OFPT_STATS_REQUEST |
| 2490 | |
| 2491 | |
| 2492 | def pack(self): |
| 2493 | """ |
| 2494 | Pack object into string |
| 2495 | |
| 2496 | @return The packed string which can go on the wire |
| 2497 | |
| 2498 | """ |
| 2499 | self.header.length = len(self) |
| 2500 | packed = self.header.pack() |
| 2501 | |
| 2502 | packed += ofp_stats_request.pack(self) |
| 2503 | return packed |
| 2504 | |
| 2505 | def unpack(self, binary_string): |
| 2506 | """ |
| 2507 | Unpack object from a binary string |
| 2508 | |
| 2509 | @param binary_string The wire protocol byte string holding the object |
| 2510 | represented as an array of bytes. |
| 2511 | @return The remainder of binary_string that was not parsed. |
| 2512 | |
| 2513 | """ |
| 2514 | binary_string = self.header.unpack(binary_string) |
| 2515 | |
| 2516 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 2517 | # Fixme: If no self.data, add check for data remaining |
| 2518 | return binary_string |
| 2519 | |
| 2520 | def __len__(self): |
| 2521 | """ |
| 2522 | Return the length of this object once packed into a string |
| 2523 | |
| 2524 | @return An integer representing the number bytes in the packed |
| 2525 | string. |
| 2526 | |
| 2527 | """ |
| 2528 | length = OFP_HEADER_BYTES |
| 2529 | |
| 2530 | length += ofp_stats_request.__len__(self) |
| 2531 | return length |
| 2532 | |
| 2533 | def show(self, prefix=''): |
| 2534 | """ |
| 2535 | Generate a string (with multiple lines) describing the contents |
| 2536 | of the object in a readable manner |
| 2537 | |
| 2538 | @param prefix Pre-pended at the beginning of each line. |
| 2539 | |
| 2540 | """ |
| 2541 | |
| 2542 | outstr = prefix + 'stats_request (OFPT_STATS_REQUEST)\n' |
| 2543 | prefix += ' ' |
| 2544 | outstr += prefix + 'ofp header\n' |
| 2545 | outstr += self.header.show(prefix + ' ') |
| 2546 | outstr += ofp_stats_request.show(self, prefix) |
| 2547 | return outstr |
| 2548 | |
| 2549 | def __eq__(self, other): |
| 2550 | """ |
| 2551 | Return True if self and other hold the same data |
| 2552 | |
| 2553 | @param other Other object in comparison |
| 2554 | |
| 2555 | """ |
| 2556 | if type(self) != type(other): return False |
| 2557 | if not self.header.__eq__(other.header): return False |
| 2558 | |
| 2559 | if not ofp_stats_request.__eq__(self, other): return False |
| 2560 | return True |
| 2561 | |
| 2562 | def __ne__(self, other): |
| 2563 | """ |
| 2564 | Return True if self and other do not hold the same data |
| 2565 | |
| 2566 | @param other Other object in comparison |
| 2567 | |
| 2568 | """ |
| 2569 | return not self.__eq__(other) |
| 2570 | |
| 2571 | |
| 2572 | class table_mod(ofp_table_mod): |
| 2573 | """ |
| 2574 | Wrapper class for table_mod |
| 2575 | |
| 2576 | OpenFlow message header: length, version, xid, type |
| 2577 | @arg length: The total length of the message |
| 2578 | @arg version: The OpenFlow version (2) |
| 2579 | @arg xid: The transaction ID |
| 2580 | @arg type: The message type (OFPT_TABLE_MOD=17) |
| 2581 | |
| 2582 | Data members inherited from ofp_table_mod: |
| 2583 | @arg table_id |
| 2584 | @arg config |
| 2585 | |
| 2586 | """ |
| 2587 | |
| 2588 | def __init__(self): |
| 2589 | ofp_table_mod.__init__(self) |
| 2590 | self.header = ofp_header() |
| 2591 | self.header.type = OFPT_TABLE_MOD |
| 2592 | |
| 2593 | |
| 2594 | def pack(self): |
| 2595 | """ |
| 2596 | Pack object into string |
| 2597 | |
| 2598 | @return The packed string which can go on the wire |
| 2599 | |
| 2600 | """ |
| 2601 | self.header.length = len(self) |
| 2602 | packed = self.header.pack() |
| 2603 | |
| 2604 | packed += ofp_table_mod.pack(self) |
| 2605 | return packed |
| 2606 | |
| 2607 | def unpack(self, binary_string): |
| 2608 | """ |
| 2609 | Unpack object from a binary string |
| 2610 | |
| 2611 | @param binary_string The wire protocol byte string holding the object |
| 2612 | represented as an array of bytes. |
| 2613 | @return The remainder of binary_string that was not parsed. |
| 2614 | |
| 2615 | """ |
| 2616 | binary_string = self.header.unpack(binary_string) |
| 2617 | |
| 2618 | binary_string = ofp_table_mod.unpack(self, binary_string) |
| 2619 | # Fixme: If no self.data, add check for data remaining |
| 2620 | return binary_string |
| 2621 | |
| 2622 | def __len__(self): |
| 2623 | """ |
| 2624 | Return the length of this object once packed into a string |
| 2625 | |
| 2626 | @return An integer representing the number bytes in the packed |
| 2627 | string. |
| 2628 | |
| 2629 | """ |
| 2630 | length = OFP_HEADER_BYTES |
| 2631 | |
| 2632 | length += ofp_table_mod.__len__(self) |
| 2633 | return length |
| 2634 | |
| 2635 | def show(self, prefix=''): |
| 2636 | """ |
| 2637 | Generate a string (with multiple lines) describing the contents |
| 2638 | of the object in a readable manner |
| 2639 | |
| 2640 | @param prefix Pre-pended at the beginning of each line. |
| 2641 | |
| 2642 | """ |
| 2643 | |
| 2644 | outstr = prefix + 'table_mod (OFPT_TABLE_MOD)\n' |
| 2645 | prefix += ' ' |
| 2646 | outstr += prefix + 'ofp header\n' |
| 2647 | outstr += self.header.show(prefix + ' ') |
| 2648 | outstr += ofp_table_mod.show(self, prefix) |
| 2649 | return outstr |
| 2650 | |
| 2651 | def __eq__(self, other): |
| 2652 | """ |
| 2653 | Return True if self and other hold the same data |
| 2654 | |
| 2655 | @param other Other object in comparison |
| 2656 | |
| 2657 | """ |
| 2658 | if type(self) != type(other): return False |
| 2659 | if not self.header.__eq__(other.header): return False |
| 2660 | |
| 2661 | if not ofp_table_mod.__eq__(self, other): return False |
| 2662 | return True |
| 2663 | |
| 2664 | def __ne__(self, other): |
| 2665 | """ |
| 2666 | Return True if self and other do not hold the same data |
| 2667 | |
| 2668 | @param other Other object in comparison |
| 2669 | |
| 2670 | """ |
| 2671 | return not self.__eq__(other) |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | ################################################################ |
| 2676 | # |
| 2677 | # Stats request and reply subclass definitions |
| 2678 | # |
| 2679 | ################################################################ |
| 2680 | |
| 2681 | |
| 2682 | # Stats request bodies for desc and table stats are not defined in the |
| 2683 | # OpenFlow header; We define them here. They are empty classes, really |
| 2684 | |
| 2685 | class ofp_desc_stats_request(object): |
| 2686 | """ |
| 2687 | Forced definition of ofp_desc_stats_request (empty class) |
| 2688 | """ |
| 2689 | def __init__(self): |
| 2690 | pass |
| 2691 | def pack(self, assertstruct=True): |
| 2692 | return "" |
| 2693 | def unpack(self, binary_string): |
| 2694 | return binary_string |
| 2695 | def __len__(self): |
| 2696 | return 0 |
| 2697 | def show(self, prefix=''): |
| 2698 | return prefix + "ofp_desc_stats_request (empty)\n" |
| 2699 | def __eq__(self, other): |
| 2700 | return type(self) == type(other) |
| 2701 | def __ne__(self, other): |
| 2702 | return type(self) != type(other) |
| 2703 | |
| 2704 | OFP_DESC_STATS_REQUEST_BYTES = 0 |
| 2705 | |
| 2706 | class ofp_table_stats_request(object): |
| 2707 | """ |
| 2708 | Forced definition of ofp_table_stats_request (empty class) |
| 2709 | """ |
| 2710 | def __init__(self): |
| 2711 | pass |
| 2712 | def pack(self, assertstruct=True): |
| 2713 | return "" |
| 2714 | def unpack(self, binary_string): |
| 2715 | return binary_string |
| 2716 | def __len__(self): |
| 2717 | return 0 |
| 2718 | def show(self, prefix=''): |
| 2719 | return prefix + "ofp_table_stats_request (empty)\n" |
| 2720 | def __eq__(self, other): |
| 2721 | return type(self) == type(other) |
| 2722 | def __ne__(self, other): |
| 2723 | return type(self) != type(other) |
| 2724 | |
| 2725 | OFP_TABLE_STATS_REQUEST_BYTES = 0 |
| 2726 | |
| 2727 | class ofp_group_desc_stats_request(object): |
| 2728 | """ |
| 2729 | Forced definition of ofp_group_desc_stats_request (empty class) |
| 2730 | """ |
| 2731 | def __init__(self): |
| 2732 | pass |
| 2733 | def pack(self, assertstruct=True): |
| 2734 | return "" |
| 2735 | def unpack(self, binary_string): |
| 2736 | return binary_string |
| 2737 | def __len__(self): |
| 2738 | return 0 |
| 2739 | def show(self, prefix=''): |
| 2740 | return prefix + "ofp_group_desc_stats_request (empty)\n" |
| 2741 | def __eq__(self, other): |
| 2742 | return type(self) == type(other) |
| 2743 | def __ne__(self, other): |
| 2744 | return type(self) != type(other) |
| 2745 | |
| 2746 | OFP_GROUP_DESC_STATS_REQUEST_BYTES = 0 |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | # Stats entries define the content of one element in a stats |
| 2751 | # reply for the indicated type; define _entry for consistency |
| 2752 | |
| 2753 | aggregate_stats_entry = ofp_aggregate_stats_reply |
| 2754 | desc_stats_entry = ofp_desc_stats |
| 2755 | port_stats_entry = ofp_port_stats |
| 2756 | queue_stats_entry = ofp_queue_stats |
| 2757 | table_stats_entry = ofp_table_stats |
| 2758 | group_stats_entry = ofp_group_stats |
| 2759 | group_desc_stats_entry = ofp_group_desc_stats |
| 2760 | |
| 2761 | |
| 2762 | # |
| 2763 | # Flow stats entry contains an action list of variable length, so |
| 2764 | # it is done by hand |
| 2765 | # |
| 2766 | |
| 2767 | class flow_stats_entry(ofp_flow_stats): |
| 2768 | """ |
| 2769 | Special case flow stats entry to handle action list object |
| 2770 | """ |
| 2771 | def __init__(self): |
| 2772 | ofp_flow_stats.__init__(self) |
| 2773 | self.instructions = instruction_list() |
| 2774 | |
| 2775 | def pack(self, assertstruct=True): |
| 2776 | self.length = len(self) |
| 2777 | packed = ofp_flow_stats.pack(self, assertstruct) |
| 2778 | packed += self.instructions.pack() |
| 2779 | if len(packed) != self.length: |
| 2780 | print("ERROR: flow_stats_entry pack length not equal", |
| 2781 | self.length, len(packed)) |
| 2782 | return packed |
| 2783 | |
| 2784 | def unpack(self, binary_string): |
| 2785 | binary_string = ofp_flow_stats.unpack(self, binary_string) |
| 2786 | ai_len = self.length - OFP_FLOW_STATS_BYTES |
| 2787 | if ai_len < 0: |
| 2788 | print("ERROR: flow_stats_entry unpack length too small", |
| 2789 | self.length) |
| 2790 | binary_string = self.instructions.unpack(binary_string, bytes=ai_len) |
| 2791 | return binary_string |
| 2792 | |
| 2793 | def __len__(self): |
| 2794 | return OFP_FLOW_STATS_BYTES + len(self.instructions) |
| 2795 | |
| 2796 | def show(self, prefix=''): |
| 2797 | outstr = prefix + "flow_stats_entry\n" |
| 2798 | outstr += ofp_flow_stats.show(self, prefix + ' ') |
| 2799 | outstr += self.instructions.show(prefix + ' ') |
| 2800 | return outstr |
| 2801 | |
| 2802 | def __eq__(self, other): |
| 2803 | if type(self) != type(other): return False |
| 2804 | return (ofp_flow_stats.__eq__(self, other) and |
| 2805 | self.instructions == other.instructions) |
| 2806 | |
| 2807 | def __ne__(self, other): return not self.__eq__(other) |
| 2808 | |
| 2809 | |
| 2810 | class aggregate_stats_request(ofp_stats_request, ofp_aggregate_stats_request): |
| 2811 | """ |
| 2812 | Wrapper class for aggregate stats request message |
| 2813 | """ |
| 2814 | def __init__(self): |
| 2815 | self.header = ofp_header() |
| 2816 | ofp_stats_request.__init__(self) |
| 2817 | ofp_aggregate_stats_request.__init__(self) |
| 2818 | self.header.type = OFPT_STATS_REQUEST |
| 2819 | self.type = OFPST_AGGREGATE |
| 2820 | |
| 2821 | def pack(self, assertstruct=True): |
| 2822 | self.header.length = len(self) |
| 2823 | packed = self.header.pack() |
| 2824 | packed += ofp_stats_request.pack(self) |
| 2825 | packed += ofp_aggregate_stats_request.pack(self) |
| 2826 | return packed |
| 2827 | |
| 2828 | def unpack(self, binary_string): |
| 2829 | binary_string = self.header.unpack(binary_string) |
| 2830 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 2831 | binary_string = ofp_aggregate_stats_request.unpack(self, binary_string) |
| 2832 | if len(binary_string) != 0: |
| 2833 | print "ERROR unpacking aggregate: extra data" |
| 2834 | return binary_string |
| 2835 | |
| 2836 | def __len__(self): |
| 2837 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 2838 | OFP_AGGREGATE_STATS_REQUEST_BYTES |
| 2839 | |
| 2840 | def show(self, prefix=''): |
| 2841 | outstr = prefix + "aggregate_stats_request\n" |
| 2842 | outstr += prefix + "ofp header:\n" |
| 2843 | outstr += self.header.show(prefix + ' ') |
| 2844 | outstr += ofp_stats_request.show(self) |
| 2845 | outstr += ofp_aggregate_stats_request.show(self) |
| 2846 | return outstr |
| 2847 | |
| 2848 | def __eq__(self, other): |
| 2849 | if type(self) != type(other): return False |
| 2850 | return (self.header == other.header and |
| 2851 | ofp_stats_request.__eq__(self, other) and |
| 2852 | ofp_aggregate_stats_request.__eq__(self, other)) |
| 2853 | |
| 2854 | def __ne__(self, other): return not self.__eq__(other) |
| 2855 | |
| 2856 | |
| 2857 | class aggregate_stats_reply(ofp_stats_reply): |
| 2858 | """ |
| 2859 | Wrapper class for aggregate stats reply |
| 2860 | """ |
| 2861 | def __init__(self): |
| 2862 | self.header = ofp_header() |
| 2863 | ofp_stats_reply.__init__(self) |
| 2864 | self.header.type = OFPT_STATS_REPLY |
| 2865 | self.type = OFPST_AGGREGATE |
| 2866 | # stats: Array of type aggregate_stats_entry |
| 2867 | self.stats = [] |
| 2868 | |
| 2869 | def pack(self, assertstruct=True): |
| 2870 | self.header.length = len(self) |
| 2871 | packed = self.header.pack() |
| 2872 | packed += ofp_stats_reply.pack(self) |
| 2873 | for obj in self.stats: |
| 2874 | packed += obj.pack() |
| 2875 | return packed |
| 2876 | |
| 2877 | def unpack(self, binary_string): |
| 2878 | binary_string = self.header.unpack(binary_string) |
| 2879 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 2880 | dummy = aggregate_stats_entry() |
| 2881 | while len(binary_string) >= len(dummy): |
| 2882 | obj = aggregate_stats_entry() |
| 2883 | binary_string = obj.unpack(binary_string) |
| 2884 | self.stats.append(obj) |
| 2885 | if len(binary_string) != 0: |
| 2886 | print "ERROR unpacking aggregate stats string: extra bytes" |
| 2887 | return binary_string |
| 2888 | |
| 2889 | def __len__(self): |
| 2890 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 2891 | for obj in self.stats: |
| 2892 | length += len(obj) |
| 2893 | return length |
| 2894 | |
| 2895 | def show(self, prefix=''): |
| 2896 | outstr = prefix + "aggregate_stats_reply\n" |
| 2897 | outstr += prefix + "ofp header:\n" |
| 2898 | outstr += self.header.show(prefix + ' ') |
| 2899 | outstr += ofp_stats_reply.show(self) |
| 2900 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 2901 | for obj in self.stats: |
| 2902 | outstr += obj.show() |
| 2903 | return outstr |
| 2904 | |
| 2905 | def __eq__(self, other): |
| 2906 | if type(self) != type(other): return False |
| 2907 | return (self.header == other.header and |
| 2908 | ofp_stats_reply.__eq__(self, other) and |
| 2909 | self.stats == other.stats) |
| 2910 | |
| 2911 | def __ne__(self, other): return not self.__eq__(other) |
| 2912 | |
| 2913 | |
| 2914 | class desc_stats_request(ofp_stats_request, ofp_desc_stats_request): |
| 2915 | """ |
| 2916 | Wrapper class for desc stats request message |
| 2917 | """ |
| 2918 | def __init__(self): |
| 2919 | self.header = ofp_header() |
| 2920 | ofp_stats_request.__init__(self) |
| 2921 | ofp_desc_stats_request.__init__(self) |
| 2922 | self.header.type = OFPT_STATS_REQUEST |
| 2923 | self.type = OFPST_DESC |
| 2924 | |
| 2925 | def pack(self, assertstruct=True): |
| 2926 | self.header.length = len(self) |
| 2927 | packed = self.header.pack() |
| 2928 | packed += ofp_stats_request.pack(self) |
| 2929 | packed += ofp_desc_stats_request.pack(self) |
| 2930 | return packed |
| 2931 | |
| 2932 | def unpack(self, binary_string): |
| 2933 | binary_string = self.header.unpack(binary_string) |
| 2934 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 2935 | binary_string = ofp_desc_stats_request.unpack(self, binary_string) |
| 2936 | if len(binary_string) != 0: |
| 2937 | print "ERROR unpacking desc: extra data" |
| 2938 | return binary_string |
| 2939 | |
| 2940 | def __len__(self): |
| 2941 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 2942 | OFP_DESC_STATS_REQUEST_BYTES |
| 2943 | |
| 2944 | def show(self, prefix=''): |
| 2945 | outstr = prefix + "desc_stats_request\n" |
| 2946 | outstr += prefix + "ofp header:\n" |
| 2947 | outstr += self.header.show(prefix + ' ') |
| 2948 | outstr += ofp_stats_request.show(self) |
| 2949 | outstr += ofp_desc_stats_request.show(self) |
| 2950 | return outstr |
| 2951 | |
| 2952 | def __eq__(self, other): |
| 2953 | if type(self) != type(other): return False |
| 2954 | return (self.header == other.header and |
| 2955 | ofp_stats_request.__eq__(self, other) and |
| 2956 | ofp_desc_stats_request.__eq__(self, other)) |
| 2957 | |
| 2958 | def __ne__(self, other): return not self.__eq__(other) |
| 2959 | |
| 2960 | |
| 2961 | class desc_stats_reply(ofp_stats_reply): |
| 2962 | """ |
| 2963 | Wrapper class for desc stats reply |
| 2964 | """ |
| 2965 | def __init__(self): |
| 2966 | self.header = ofp_header() |
| 2967 | ofp_stats_reply.__init__(self) |
| 2968 | self.header.type = OFPT_STATS_REPLY |
| 2969 | self.type = OFPST_DESC |
| 2970 | # stats: Array of type desc_stats_entry |
| 2971 | self.stats = [] |
| 2972 | |
| 2973 | def pack(self, assertstruct=True): |
| 2974 | self.header.length = len(self) |
| 2975 | packed = self.header.pack() |
| 2976 | packed += ofp_stats_reply.pack(self) |
| 2977 | for obj in self.stats: |
| 2978 | packed += obj.pack() |
| 2979 | return packed |
| 2980 | |
| 2981 | def unpack(self, binary_string): |
| 2982 | binary_string = self.header.unpack(binary_string) |
| 2983 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 2984 | dummy = desc_stats_entry() |
| 2985 | while len(binary_string) >= len(dummy): |
| 2986 | obj = desc_stats_entry() |
| 2987 | binary_string = obj.unpack(binary_string) |
| 2988 | self.stats.append(obj) |
| 2989 | if len(binary_string) != 0: |
| 2990 | print "ERROR unpacking desc stats string: extra bytes" |
| 2991 | return binary_string |
| 2992 | |
| 2993 | def __len__(self): |
| 2994 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 2995 | for obj in self.stats: |
| 2996 | length += len(obj) |
| 2997 | return length |
| 2998 | |
| 2999 | def show(self, prefix=''): |
| 3000 | outstr = prefix + "desc_stats_reply\n" |
| 3001 | outstr += prefix + "ofp header:\n" |
| 3002 | outstr += self.header.show(prefix + ' ') |
| 3003 | outstr += ofp_stats_reply.show(self) |
| 3004 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3005 | for obj in self.stats: |
| 3006 | outstr += obj.show() |
| 3007 | return outstr |
| 3008 | |
| 3009 | def __eq__(self, other): |
| 3010 | if type(self) != type(other): return False |
| 3011 | return (self.header == other.header and |
| 3012 | ofp_stats_reply.__eq__(self, other) and |
| 3013 | self.stats == other.stats) |
| 3014 | |
| 3015 | def __ne__(self, other): return not self.__eq__(other) |
| 3016 | |
| 3017 | |
| 3018 | class flow_stats_request(ofp_stats_request, ofp_flow_stats_request): |
| 3019 | """ |
| 3020 | Wrapper class for flow stats request message |
| 3021 | """ |
| 3022 | def __init__(self): |
| 3023 | self.header = ofp_header() |
| 3024 | ofp_stats_request.__init__(self) |
| 3025 | ofp_flow_stats_request.__init__(self) |
| 3026 | self.header.type = OFPT_STATS_REQUEST |
| 3027 | self.type = OFPST_FLOW |
| 3028 | |
| 3029 | def pack(self, assertstruct=True): |
| 3030 | self.header.length = len(self) |
| 3031 | packed = self.header.pack() |
| 3032 | packed += ofp_stats_request.pack(self) |
| 3033 | packed += ofp_flow_stats_request.pack(self) |
| 3034 | return packed |
| 3035 | |
| 3036 | def unpack(self, binary_string): |
| 3037 | binary_string = self.header.unpack(binary_string) |
| 3038 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3039 | binary_string = ofp_flow_stats_request.unpack(self, binary_string) |
| 3040 | if len(binary_string) != 0: |
| 3041 | print "ERROR unpacking flow: extra data" |
| 3042 | return binary_string |
| 3043 | |
| 3044 | def __len__(self): |
| 3045 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3046 | OFP_FLOW_STATS_REQUEST_BYTES |
| 3047 | |
| 3048 | def show(self, prefix=''): |
| 3049 | outstr = prefix + "flow_stats_request\n" |
| 3050 | outstr += prefix + "ofp header:\n" |
| 3051 | outstr += self.header.show(prefix + ' ') |
| 3052 | outstr += ofp_stats_request.show(self) |
| 3053 | outstr += ofp_flow_stats_request.show(self) |
| 3054 | return outstr |
| 3055 | |
| 3056 | def __eq__(self, other): |
| 3057 | if type(self) != type(other): return False |
| 3058 | return (self.header == other.header and |
| 3059 | ofp_stats_request.__eq__(self, other) and |
| 3060 | ofp_flow_stats_request.__eq__(self, other)) |
| 3061 | |
| 3062 | def __ne__(self, other): return not self.__eq__(other) |
| 3063 | |
| 3064 | |
| 3065 | class flow_stats_reply(ofp_stats_reply): |
| 3066 | """ |
| 3067 | Wrapper class for flow stats reply |
| 3068 | """ |
| 3069 | def __init__(self): |
| 3070 | self.header = ofp_header() |
| 3071 | ofp_stats_reply.__init__(self) |
| 3072 | self.header.type = OFPT_STATS_REPLY |
| 3073 | self.type = OFPST_FLOW |
| 3074 | # stats: Array of type flow_stats_entry |
| 3075 | self.stats = [] |
| 3076 | |
| 3077 | def pack(self, assertstruct=True): |
| 3078 | self.header.length = len(self) |
| 3079 | packed = self.header.pack() |
| 3080 | packed += ofp_stats_reply.pack(self) |
| 3081 | for obj in self.stats: |
| 3082 | packed += obj.pack() |
| 3083 | return packed |
| 3084 | |
| 3085 | def unpack(self, binary_string): |
| 3086 | binary_string = self.header.unpack(binary_string) |
| 3087 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3088 | dummy = flow_stats_entry() |
| 3089 | while len(binary_string) >= len(dummy): |
| 3090 | obj = flow_stats_entry() |
| 3091 | binary_string = obj.unpack(binary_string) |
| 3092 | self.stats.append(obj) |
| 3093 | if len(binary_string) != 0: |
| 3094 | print "ERROR unpacking flow stats string: extra bytes" |
| 3095 | return binary_string |
| 3096 | |
| 3097 | def __len__(self): |
| 3098 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3099 | for obj in self.stats: |
| 3100 | length += len(obj) |
| 3101 | return length |
| 3102 | |
| 3103 | def show(self, prefix=''): |
| 3104 | outstr = prefix + "flow_stats_reply\n" |
| 3105 | outstr += prefix + "ofp header:\n" |
| 3106 | outstr += self.header.show(prefix + ' ') |
| 3107 | outstr += ofp_stats_reply.show(self) |
| 3108 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3109 | for obj in self.stats: |
| 3110 | outstr += obj.show() |
| 3111 | return outstr |
| 3112 | |
| 3113 | def __eq__(self, other): |
| 3114 | if type(self) != type(other): return False |
| 3115 | return (self.header == other.header and |
| 3116 | ofp_stats_reply.__eq__(self, other) and |
| 3117 | self.stats == other.stats) |
| 3118 | |
| 3119 | def __ne__(self, other): return not self.__eq__(other) |
| 3120 | |
| 3121 | |
| 3122 | class port_stats_request(ofp_stats_request, ofp_port_stats_request): |
| 3123 | """ |
| 3124 | Wrapper class for port stats request message |
| 3125 | """ |
| 3126 | def __init__(self): |
| 3127 | self.header = ofp_header() |
| 3128 | ofp_stats_request.__init__(self) |
| 3129 | ofp_port_stats_request.__init__(self) |
| 3130 | self.header.type = OFPT_STATS_REQUEST |
| 3131 | self.type = OFPST_PORT |
| 3132 | |
| 3133 | def pack(self, assertstruct=True): |
| 3134 | self.header.length = len(self) |
| 3135 | packed = self.header.pack() |
| 3136 | packed += ofp_stats_request.pack(self) |
| 3137 | packed += ofp_port_stats_request.pack(self) |
| 3138 | return packed |
| 3139 | |
| 3140 | def unpack(self, binary_string): |
| 3141 | binary_string = self.header.unpack(binary_string) |
| 3142 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3143 | binary_string = ofp_port_stats_request.unpack(self, binary_string) |
| 3144 | if len(binary_string) != 0: |
| 3145 | print "ERROR unpacking port: extra data" |
| 3146 | return binary_string |
| 3147 | |
| 3148 | def __len__(self): |
| 3149 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3150 | OFP_PORT_STATS_REQUEST_BYTES |
| 3151 | |
| 3152 | def show(self, prefix=''): |
| 3153 | outstr = prefix + "port_stats_request\n" |
| 3154 | outstr += prefix + "ofp header:\n" |
| 3155 | outstr += self.header.show(prefix + ' ') |
| 3156 | outstr += ofp_stats_request.show(self) |
| 3157 | outstr += ofp_port_stats_request.show(self) |
| 3158 | return outstr |
| 3159 | |
| 3160 | def __eq__(self, other): |
| 3161 | if type(self) != type(other): return False |
| 3162 | return (self.header == other.header and |
| 3163 | ofp_stats_request.__eq__(self, other) and |
| 3164 | ofp_port_stats_request.__eq__(self, other)) |
| 3165 | |
| 3166 | def __ne__(self, other): return not self.__eq__(other) |
| 3167 | |
| 3168 | |
| 3169 | class port_stats_reply(ofp_stats_reply): |
| 3170 | """ |
| 3171 | Wrapper class for port stats reply |
| 3172 | """ |
| 3173 | def __init__(self): |
| 3174 | self.header = ofp_header() |
| 3175 | ofp_stats_reply.__init__(self) |
| 3176 | self.header.type = OFPT_STATS_REPLY |
| 3177 | self.type = OFPST_PORT |
| 3178 | # stats: Array of type port_stats_entry |
| 3179 | self.stats = [] |
| 3180 | |
| 3181 | def pack(self, assertstruct=True): |
| 3182 | self.header.length = len(self) |
| 3183 | packed = self.header.pack() |
| 3184 | packed += ofp_stats_reply.pack(self) |
| 3185 | for obj in self.stats: |
| 3186 | packed += obj.pack() |
| 3187 | return packed |
| 3188 | |
| 3189 | def unpack(self, binary_string): |
| 3190 | binary_string = self.header.unpack(binary_string) |
| 3191 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3192 | dummy = port_stats_entry() |
| 3193 | while len(binary_string) >= len(dummy): |
| 3194 | obj = port_stats_entry() |
| 3195 | binary_string = obj.unpack(binary_string) |
| 3196 | self.stats.append(obj) |
| 3197 | if len(binary_string) != 0: |
| 3198 | print "ERROR unpacking port stats string: extra bytes" |
| 3199 | return binary_string |
| 3200 | |
| 3201 | def __len__(self): |
| 3202 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3203 | for obj in self.stats: |
| 3204 | length += len(obj) |
| 3205 | return length |
| 3206 | |
| 3207 | def show(self, prefix=''): |
| 3208 | outstr = prefix + "port_stats_reply\n" |
| 3209 | outstr += prefix + "ofp header:\n" |
| 3210 | outstr += self.header.show(prefix + ' ') |
| 3211 | outstr += ofp_stats_reply.show(self) |
| 3212 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3213 | for obj in self.stats: |
| 3214 | outstr += obj.show() |
| 3215 | return outstr |
| 3216 | |
| 3217 | def __eq__(self, other): |
| 3218 | if type(self) != type(other): return False |
| 3219 | return (self.header == other.header and |
| 3220 | ofp_stats_reply.__eq__(self, other) and |
| 3221 | self.stats == other.stats) |
| 3222 | |
| 3223 | def __ne__(self, other): return not self.__eq__(other) |
| 3224 | |
| 3225 | |
| 3226 | class queue_stats_request(ofp_stats_request, ofp_queue_stats_request): |
| 3227 | """ |
| 3228 | Wrapper class for queue stats request message |
| 3229 | """ |
| 3230 | def __init__(self): |
| 3231 | self.header = ofp_header() |
| 3232 | ofp_stats_request.__init__(self) |
| 3233 | ofp_queue_stats_request.__init__(self) |
| 3234 | self.header.type = OFPT_STATS_REQUEST |
| 3235 | self.type = OFPST_QUEUE |
| 3236 | |
| 3237 | def pack(self, assertstruct=True): |
| 3238 | self.header.length = len(self) |
| 3239 | packed = self.header.pack() |
| 3240 | packed += ofp_stats_request.pack(self) |
| 3241 | packed += ofp_queue_stats_request.pack(self) |
| 3242 | return packed |
| 3243 | |
| 3244 | def unpack(self, binary_string): |
| 3245 | binary_string = self.header.unpack(binary_string) |
| 3246 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3247 | binary_string = ofp_queue_stats_request.unpack(self, binary_string) |
| 3248 | if len(binary_string) != 0: |
| 3249 | print "ERROR unpacking queue: extra data" |
| 3250 | return binary_string |
| 3251 | |
| 3252 | def __len__(self): |
| 3253 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3254 | OFP_QUEUE_STATS_REQUEST_BYTES |
| 3255 | |
| 3256 | def show(self, prefix=''): |
| 3257 | outstr = prefix + "queue_stats_request\n" |
| 3258 | outstr += prefix + "ofp header:\n" |
| 3259 | outstr += self.header.show(prefix + ' ') |
| 3260 | outstr += ofp_stats_request.show(self) |
| 3261 | outstr += ofp_queue_stats_request.show(self) |
| 3262 | return outstr |
| 3263 | |
| 3264 | def __eq__(self, other): |
| 3265 | if type(self) != type(other): return False |
| 3266 | return (self.header == other.header and |
| 3267 | ofp_stats_request.__eq__(self, other) and |
| 3268 | ofp_queue_stats_request.__eq__(self, other)) |
| 3269 | |
| 3270 | def __ne__(self, other): return not self.__eq__(other) |
| 3271 | |
| 3272 | |
| 3273 | class queue_stats_reply(ofp_stats_reply): |
| 3274 | """ |
| 3275 | Wrapper class for queue stats reply |
| 3276 | """ |
| 3277 | def __init__(self): |
| 3278 | self.header = ofp_header() |
| 3279 | ofp_stats_reply.__init__(self) |
| 3280 | self.header.type = OFPT_STATS_REPLY |
| 3281 | self.type = OFPST_QUEUE |
| 3282 | # stats: Array of type queue_stats_entry |
| 3283 | self.stats = [] |
| 3284 | |
| 3285 | def pack(self, assertstruct=True): |
| 3286 | self.header.length = len(self) |
| 3287 | packed = self.header.pack() |
| 3288 | packed += ofp_stats_reply.pack(self) |
| 3289 | for obj in self.stats: |
| 3290 | packed += obj.pack() |
| 3291 | return packed |
| 3292 | |
| 3293 | def unpack(self, binary_string): |
| 3294 | binary_string = self.header.unpack(binary_string) |
| 3295 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3296 | dummy = queue_stats_entry() |
| 3297 | while len(binary_string) >= len(dummy): |
| 3298 | obj = queue_stats_entry() |
| 3299 | binary_string = obj.unpack(binary_string) |
| 3300 | self.stats.append(obj) |
| 3301 | if len(binary_string) != 0: |
| 3302 | print "ERROR unpacking queue stats string: extra bytes" |
| 3303 | return binary_string |
| 3304 | |
| 3305 | def __len__(self): |
| 3306 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3307 | for obj in self.stats: |
| 3308 | length += len(obj) |
| 3309 | return length |
| 3310 | |
| 3311 | def show(self, prefix=''): |
| 3312 | outstr = prefix + "queue_stats_reply\n" |
| 3313 | outstr += prefix + "ofp header:\n" |
| 3314 | outstr += self.header.show(prefix + ' ') |
| 3315 | outstr += ofp_stats_reply.show(self) |
| 3316 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3317 | for obj in self.stats: |
| 3318 | outstr += obj.show() |
| 3319 | return outstr |
| 3320 | |
| 3321 | def __eq__(self, other): |
| 3322 | if type(self) != type(other): return False |
| 3323 | return (self.header == other.header and |
| 3324 | ofp_stats_reply.__eq__(self, other) and |
| 3325 | self.stats == other.stats) |
| 3326 | |
| 3327 | def __ne__(self, other): return not self.__eq__(other) |
| 3328 | |
| 3329 | |
| 3330 | class group_stats_request(ofp_stats_request, ofp_group_stats_request): |
| 3331 | """ |
| 3332 | Wrapper class for group stats request message |
| 3333 | """ |
| 3334 | def __init__(self): |
| 3335 | self.header = ofp_header() |
| 3336 | ofp_stats_request.__init__(self) |
| 3337 | ofp_group_stats_request.__init__(self) |
| 3338 | self.header.type = OFPT_STATS_REQUEST |
| 3339 | self.type = OFPST_GROUP |
| 3340 | |
| 3341 | def pack(self, assertstruct=True): |
| 3342 | self.header.length = len(self) |
| 3343 | packed = self.header.pack() |
| 3344 | packed += ofp_stats_request.pack(self) |
| 3345 | packed += ofp_group_stats_request.pack(self) |
| 3346 | return packed |
| 3347 | |
| 3348 | def unpack(self, binary_string): |
| 3349 | binary_string = self.header.unpack(binary_string) |
| 3350 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3351 | binary_string = ofp_group_stats_request.unpack(self, binary_string) |
| 3352 | if len(binary_string) != 0: |
| 3353 | print "ERROR unpacking group: extra data" |
| 3354 | return binary_string |
| 3355 | |
| 3356 | def __len__(self): |
| 3357 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3358 | OFP_GROUP_STATS_REQUEST_BYTES |
| 3359 | |
| 3360 | def show(self, prefix=''): |
| 3361 | outstr = prefix + "group_stats_request\n" |
| 3362 | outstr += prefix + "ofp header:\n" |
| 3363 | outstr += self.header.show(prefix + ' ') |
| 3364 | outstr += ofp_stats_request.show(self) |
| 3365 | outstr += ofp_group_stats_request.show(self) |
| 3366 | return outstr |
| 3367 | |
| 3368 | def __eq__(self, other): |
| 3369 | if type(self) != type(other): return False |
| 3370 | return (self.header == other.header and |
| 3371 | ofp_stats_request.__eq__(self, other) and |
| 3372 | ofp_group_stats_request.__eq__(self, other)) |
| 3373 | |
| 3374 | def __ne__(self, other): return not self.__eq__(other) |
| 3375 | |
| 3376 | |
| 3377 | class group_stats_reply(ofp_stats_reply): |
| 3378 | """ |
| 3379 | Wrapper class for group stats reply |
| 3380 | """ |
| 3381 | def __init__(self): |
| 3382 | self.header = ofp_header() |
| 3383 | ofp_stats_reply.__init__(self) |
| 3384 | self.header.type = OFPT_STATS_REPLY |
| 3385 | self.type = OFPST_GROUP |
| 3386 | # stats: Array of type group_stats_entry |
| 3387 | self.stats = [] |
| 3388 | |
| 3389 | def pack(self, assertstruct=True): |
| 3390 | self.header.length = len(self) |
| 3391 | packed = self.header.pack() |
| 3392 | packed += ofp_stats_reply.pack(self) |
| 3393 | for obj in self.stats: |
| 3394 | packed += obj.pack() |
| 3395 | return packed |
| 3396 | |
| 3397 | def unpack(self, binary_string): |
| 3398 | binary_string = self.header.unpack(binary_string) |
| 3399 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3400 | dummy = group_stats_entry() |
| 3401 | while len(binary_string) >= len(dummy): |
| 3402 | obj = group_stats_entry() |
| 3403 | binary_string = obj.unpack(binary_string) |
| 3404 | self.stats.append(obj) |
| 3405 | if len(binary_string) != 0: |
| 3406 | print "ERROR unpacking group stats string: extra bytes" |
| 3407 | return binary_string |
| 3408 | |
| 3409 | def __len__(self): |
| 3410 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3411 | for obj in self.stats: |
| 3412 | length += len(obj) |
| 3413 | return length |
| 3414 | |
| 3415 | def show(self, prefix=''): |
| 3416 | outstr = prefix + "group_stats_reply\n" |
| 3417 | outstr += prefix + "ofp header:\n" |
| 3418 | outstr += self.header.show(prefix + ' ') |
| 3419 | outstr += ofp_stats_reply.show(self) |
| 3420 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3421 | for obj in self.stats: |
| 3422 | outstr += obj.show() |
| 3423 | return outstr |
| 3424 | |
| 3425 | def __eq__(self, other): |
| 3426 | if type(self) != type(other): return False |
| 3427 | return (self.header == other.header and |
| 3428 | ofp_stats_reply.__eq__(self, other) and |
| 3429 | self.stats == other.stats) |
| 3430 | |
| 3431 | def __ne__(self, other): return not self.__eq__(other) |
| 3432 | |
| 3433 | |
| 3434 | class group_desc_stats_request(ofp_stats_request, ofp_group_desc_stats_request): |
| 3435 | """ |
| 3436 | Wrapper class for group_desc stats request message |
| 3437 | """ |
| 3438 | def __init__(self): |
| 3439 | self.header = ofp_header() |
| 3440 | ofp_stats_request.__init__(self) |
| 3441 | ofp_group_desc_stats_request.__init__(self) |
| 3442 | self.header.type = OFPT_STATS_REQUEST |
| 3443 | self.type = OFPST_GROUP_DESC |
| 3444 | |
| 3445 | def pack(self, assertstruct=True): |
| 3446 | self.header.length = len(self) |
| 3447 | packed = self.header.pack() |
| 3448 | packed += ofp_stats_request.pack(self) |
| 3449 | packed += ofp_group_desc_stats_request.pack(self) |
| 3450 | return packed |
| 3451 | |
| 3452 | def unpack(self, binary_string): |
| 3453 | binary_string = self.header.unpack(binary_string) |
| 3454 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3455 | binary_string = ofp_group_desc_stats_request.unpack(self, binary_string) |
| 3456 | if len(binary_string) != 0: |
| 3457 | print "ERROR unpacking group_desc: extra data" |
| 3458 | return binary_string |
| 3459 | |
| 3460 | def __len__(self): |
| 3461 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3462 | OFP_GROUP_DESC_STATS_REQUEST_BYTES |
| 3463 | |
| 3464 | def show(self, prefix=''): |
| 3465 | outstr = prefix + "group_desc_stats_request\n" |
| 3466 | outstr += prefix + "ofp header:\n" |
| 3467 | outstr += self.header.show(prefix + ' ') |
| 3468 | outstr += ofp_stats_request.show(self) |
| 3469 | outstr += ofp_group_desc_stats_request.show(self) |
| 3470 | return outstr |
| 3471 | |
| 3472 | def __eq__(self, other): |
| 3473 | if type(self) != type(other): return False |
| 3474 | return (self.header == other.header and |
| 3475 | ofp_stats_request.__eq__(self, other) and |
| 3476 | ofp_group_desc_stats_request.__eq__(self, other)) |
| 3477 | |
| 3478 | def __ne__(self, other): return not self.__eq__(other) |
| 3479 | |
| 3480 | |
| 3481 | class group_desc_stats_reply(ofp_stats_reply): |
| 3482 | """ |
| 3483 | Wrapper class for group_desc stats reply |
| 3484 | """ |
| 3485 | def __init__(self): |
| 3486 | self.header = ofp_header() |
| 3487 | ofp_stats_reply.__init__(self) |
| 3488 | self.header.type = OFPT_STATS_REPLY |
| 3489 | self.type = OFPST_GROUP_DESC |
| 3490 | # stats: Array of type group_desc_stats_entry |
| 3491 | self.stats = [] |
| 3492 | |
| 3493 | def pack(self, assertstruct=True): |
| 3494 | self.header.length = len(self) |
| 3495 | packed = self.header.pack() |
| 3496 | packed += ofp_stats_reply.pack(self) |
| 3497 | for obj in self.stats: |
| 3498 | packed += obj.pack() |
| 3499 | return packed |
| 3500 | |
| 3501 | def unpack(self, binary_string): |
| 3502 | binary_string = self.header.unpack(binary_string) |
| 3503 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3504 | dummy = group_desc_stats_entry() |
| 3505 | while len(binary_string) >= len(dummy): |
| 3506 | obj = group_desc_stats_entry() |
| 3507 | binary_string = obj.unpack(binary_string) |
| 3508 | self.stats.append(obj) |
| 3509 | if len(binary_string) != 0: |
| 3510 | print "ERROR unpacking group_desc stats string: extra bytes" |
| 3511 | return binary_string |
| 3512 | |
| 3513 | def __len__(self): |
| 3514 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3515 | for obj in self.stats: |
| 3516 | length += len(obj) |
| 3517 | return length |
| 3518 | |
| 3519 | def show(self, prefix=''): |
| 3520 | outstr = prefix + "group_desc_stats_reply\n" |
| 3521 | outstr += prefix + "ofp header:\n" |
| 3522 | outstr += self.header.show(prefix + ' ') |
| 3523 | outstr += ofp_stats_reply.show(self) |
| 3524 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3525 | for obj in self.stats: |
| 3526 | outstr += obj.show() |
| 3527 | return outstr |
| 3528 | |
| 3529 | def __eq__(self, other): |
| 3530 | if type(self) != type(other): return False |
| 3531 | return (self.header == other.header and |
| 3532 | ofp_stats_reply.__eq__(self, other) and |
| 3533 | self.stats == other.stats) |
| 3534 | |
| 3535 | def __ne__(self, other): return not self.__eq__(other) |
| 3536 | |
| 3537 | |
| 3538 | class table_stats_request(ofp_stats_request, ofp_table_stats_request): |
| 3539 | """ |
| 3540 | Wrapper class for table stats request message |
| 3541 | """ |
| 3542 | def __init__(self): |
| 3543 | self.header = ofp_header() |
| 3544 | ofp_stats_request.__init__(self) |
| 3545 | ofp_table_stats_request.__init__(self) |
| 3546 | self.header.type = OFPT_STATS_REQUEST |
| 3547 | self.type = OFPST_TABLE |
| 3548 | |
| 3549 | def pack(self, assertstruct=True): |
| 3550 | self.header.length = len(self) |
| 3551 | packed = self.header.pack() |
| 3552 | packed += ofp_stats_request.pack(self) |
| 3553 | packed += ofp_table_stats_request.pack(self) |
| 3554 | return packed |
| 3555 | |
| 3556 | def unpack(self, binary_string): |
| 3557 | binary_string = self.header.unpack(binary_string) |
| 3558 | binary_string = ofp_stats_request.unpack(self, binary_string) |
| 3559 | binary_string = ofp_table_stats_request.unpack(self, binary_string) |
| 3560 | if len(binary_string) != 0: |
| 3561 | print "ERROR unpacking table: extra data" |
| 3562 | return binary_string |
| 3563 | |
| 3564 | def __len__(self): |
| 3565 | return len(self.header) + OFP_STATS_REQUEST_BYTES + \ |
| 3566 | OFP_TABLE_STATS_REQUEST_BYTES |
| 3567 | |
| 3568 | def show(self, prefix=''): |
| 3569 | outstr = prefix + "table_stats_request\n" |
| 3570 | outstr += prefix + "ofp header:\n" |
| 3571 | outstr += self.header.show(prefix + ' ') |
| 3572 | outstr += ofp_stats_request.show(self) |
| 3573 | outstr += ofp_table_stats_request.show(self) |
| 3574 | return outstr |
| 3575 | |
| 3576 | def __eq__(self, other): |
| 3577 | if type(self) != type(other): return False |
| 3578 | return (self.header == other.header and |
| 3579 | ofp_stats_request.__eq__(self, other) and |
| 3580 | ofp_table_stats_request.__eq__(self, other)) |
| 3581 | |
| 3582 | def __ne__(self, other): return not self.__eq__(other) |
| 3583 | |
| 3584 | |
| 3585 | class table_stats_reply(ofp_stats_reply): |
| 3586 | """ |
| 3587 | Wrapper class for table stats reply |
| 3588 | """ |
| 3589 | def __init__(self): |
| 3590 | self.header = ofp_header() |
| 3591 | ofp_stats_reply.__init__(self) |
| 3592 | self.header.type = OFPT_STATS_REPLY |
| 3593 | self.type = OFPST_TABLE |
| 3594 | # stats: Array of type table_stats_entry |
| 3595 | self.stats = [] |
| 3596 | |
| 3597 | def pack(self, assertstruct=True): |
| 3598 | self.header.length = len(self) |
| 3599 | packed = self.header.pack() |
| 3600 | packed += ofp_stats_reply.pack(self) |
| 3601 | for obj in self.stats: |
| 3602 | packed += obj.pack() |
| 3603 | return packed |
| 3604 | |
| 3605 | def unpack(self, binary_string): |
| 3606 | binary_string = self.header.unpack(binary_string) |
| 3607 | binary_string = ofp_stats_reply.unpack(self, binary_string) |
| 3608 | dummy = table_stats_entry() |
| 3609 | while len(binary_string) >= len(dummy): |
| 3610 | obj = table_stats_entry() |
| 3611 | binary_string = obj.unpack(binary_string) |
| 3612 | self.stats.append(obj) |
| 3613 | if len(binary_string) != 0: |
| 3614 | print "ERROR unpacking table stats string: extra bytes" |
| 3615 | return binary_string |
| 3616 | |
| 3617 | def __len__(self): |
| 3618 | length = len(self.header) + OFP_STATS_REPLY_BYTES |
| 3619 | for obj in self.stats: |
| 3620 | length += len(obj) |
| 3621 | return length |
| 3622 | |
| 3623 | def show(self, prefix=''): |
| 3624 | outstr = prefix + "table_stats_reply\n" |
| 3625 | outstr += prefix + "ofp header:\n" |
| 3626 | outstr += self.header.show(prefix + ' ') |
| 3627 | outstr += ofp_stats_reply.show(self) |
| 3628 | outstr += prefix + "Stats array of length " + str(len(self.stats)) + '\n' |
| 3629 | for obj in self.stats: |
| 3630 | outstr += obj.show() |
| 3631 | return outstr |
| 3632 | |
| 3633 | def __eq__(self, other): |
| 3634 | if type(self) != type(other): return False |
| 3635 | return (self.header == other.header and |
| 3636 | ofp_stats_reply.__eq__(self, other) and |
| 3637 | self.stats == other.stats) |
| 3638 | |
| 3639 | def __ne__(self, other): return not self.__eq__(other) |
| 3640 | |
| 3641 | |
| 3642 | # @todo Add buckets to group and group_desc stats obejcts" |
| 3643 | message_type_list = ( |
| 3644 | aggregate_stats_reply, |
| 3645 | aggregate_stats_request, |
| 3646 | bad_action_error_msg, |
| 3647 | bad_request_error_msg, |
| 3648 | barrier_reply, |
| 3649 | barrier_request, |
| 3650 | desc_stats_reply, |
| 3651 | desc_stats_request, |
| 3652 | echo_reply, |
| 3653 | echo_request, |
| 3654 | error, |
| 3655 | experimenter, |
| 3656 | features_reply, |
| 3657 | features_request, |
| 3658 | flow_mod, |
| 3659 | flow_mod_failed_error_msg, |
| 3660 | flow_removed, |
| 3661 | flow_stats_reply, |
| 3662 | flow_stats_request, |
| 3663 | get_config_reply, |
| 3664 | get_config_request, |
| 3665 | group_desc_stats_request, |
| 3666 | group_desc_stats_reply, |
| 3667 | group_stats_request, |
| 3668 | group_stats_reply, |
| 3669 | group_mod, |
| 3670 | group_mod_failed_error_msg, |
| 3671 | hello, |
| 3672 | hello_failed_error_msg, |
| 3673 | packet_in, |
| 3674 | packet_out, |
| 3675 | port_mod, |
| 3676 | port_mod_failed_error_msg, |
| 3677 | port_stats_reply, |
| 3678 | port_stats_request, |
| 3679 | port_status, |
| 3680 | queue_get_config_reply, |
| 3681 | queue_get_config_request, |
| 3682 | queue_op_failed_error_msg, |
| 3683 | queue_stats_reply, |
| 3684 | queue_stats_request, |
| 3685 | set_config, |
| 3686 | switch_config_failed_error_msg, |
| 3687 | table_mod, |
| 3688 | table_mod_failed_error_msg, |
| 3689 | table_stats_reply, |
| 3690 | table_stats_request, |
| 3691 | ) |
| 3692 | |