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