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