Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | |
| 5 | # Automatically generated by LOXI from template action.py |
| 6 | # Do not modify |
| 7 | |
| 8 | import struct |
| 9 | import const |
| 10 | import util |
| 11 | import loxi.generic_util |
| 12 | import loxi |
| 13 | |
| 14 | def unpack_list(reader): |
| 15 | def deserializer(reader, typ): |
| 16 | parser = parsers.get(typ) |
| 17 | if not parser: raise loxi.ProtocolError("unknown action type %d" % typ) |
| 18 | return parser(reader) |
| 19 | return loxi.generic_util.unpack_list_tlv16(reader, deserializer) |
| 20 | |
| 21 | class Action(object): |
| 22 | type = None # override in subclass |
| 23 | pass |
| 24 | |
| 25 | class bsn_mirror(Action): |
| 26 | type = const.OFPAT_EXPERIMENTER |
| 27 | experimenter = 0x5c16c7 |
| 28 | subtype = 1 |
| 29 | |
| 30 | def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None): |
| 31 | if dest_port != None: |
| 32 | self.dest_port = dest_port |
| 33 | else: |
| 34 | self.dest_port = 0 |
| 35 | if vlan_tag != None: |
| 36 | self.vlan_tag = vlan_tag |
| 37 | else: |
| 38 | self.vlan_tag = 0 |
| 39 | if copy_stage != None: |
| 40 | self.copy_stage = copy_stage |
| 41 | else: |
| 42 | self.copy_stage = 0 |
| 43 | return |
| 44 | |
| 45 | def pack(self): |
| 46 | packed = [] |
| 47 | packed.append(struct.pack("!H", self.type)) |
| 48 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 49 | packed.append(struct.pack("!L", self.experimenter)) |
| 50 | packed.append(struct.pack("!L", self.subtype)) |
| 51 | packed.append(struct.pack("!L", self.dest_port)) |
| 52 | packed.append(struct.pack("!L", self.vlan_tag)) |
| 53 | packed.append(struct.pack("!B", self.copy_stage)) |
| 54 | packed.append('\x00' * 3) |
| 55 | length = sum([len(x) for x in packed]) |
| 56 | packed[1] = struct.pack("!H", length) |
| 57 | return ''.join(packed) |
| 58 | |
| 59 | @staticmethod |
| 60 | def unpack(buf): |
| 61 | obj = bsn_mirror() |
| 62 | if type(buf) == loxi.generic_util.OFReader: |
| 63 | reader = buf |
| 64 | else: |
| 65 | reader = loxi.generic_util.OFReader(buf) |
| 66 | _type = reader.read('!H')[0] |
| 67 | assert(_type == const.OFPAT_EXPERIMENTER) |
| 68 | _len = reader.read('!H')[0] |
| 69 | _experimenter = reader.read('!L')[0] |
| 70 | assert(_experimenter == 0x5c16c7) |
| 71 | _subtype = reader.read('!L')[0] |
| 72 | assert(_subtype == 1) |
| 73 | obj.dest_port = reader.read('!L')[0] |
| 74 | obj.vlan_tag = reader.read('!L')[0] |
| 75 | obj.copy_stage = reader.read('!B')[0] |
| 76 | reader.skip(3) |
| 77 | return obj |
| 78 | |
| 79 | def __eq__(self, other): |
| 80 | if type(self) != type(other): return False |
| 81 | if self.dest_port != other.dest_port: return False |
| 82 | if self.vlan_tag != other.vlan_tag: return False |
| 83 | if self.copy_stage != other.copy_stage: return False |
| 84 | return True |
| 85 | |
| 86 | def __ne__(self, other): |
| 87 | return not self.__eq__(other) |
| 88 | |
| 89 | def show(self): |
| 90 | import loxi.pp |
| 91 | return loxi.pp.pp(self) |
| 92 | |
| 93 | def pretty_print(self, q): |
| 94 | q.text("bsn_mirror {") |
| 95 | with q.group(): |
| 96 | with q.indent(2): |
| 97 | q.breakable() |
| 98 | q.text("dest_port = "); |
| 99 | q.text("%#x" % self.dest_port) |
| 100 | q.text(","); q.breakable() |
| 101 | q.text("vlan_tag = "); |
| 102 | q.text("%#x" % self.vlan_tag) |
| 103 | q.text(","); q.breakable() |
| 104 | q.text("copy_stage = "); |
| 105 | q.text("%#x" % self.copy_stage) |
| 106 | q.breakable() |
| 107 | q.text('}') |
| 108 | |
| 109 | class bsn_set_tunnel_dst(Action): |
| 110 | type = const.OFPAT_EXPERIMENTER |
| 111 | experimenter = 0x5c16c7 |
| 112 | subtype = 2 |
| 113 | |
| 114 | def __init__(self, dst=None): |
| 115 | if dst != None: |
| 116 | self.dst = dst |
| 117 | else: |
| 118 | self.dst = 0 |
| 119 | return |
| 120 | |
| 121 | def pack(self): |
| 122 | packed = [] |
| 123 | packed.append(struct.pack("!H", self.type)) |
| 124 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 125 | packed.append(struct.pack("!L", self.experimenter)) |
| 126 | packed.append(struct.pack("!L", self.subtype)) |
| 127 | packed.append(struct.pack("!L", self.dst)) |
| 128 | length = sum([len(x) for x in packed]) |
| 129 | packed[1] = struct.pack("!H", length) |
| 130 | return ''.join(packed) |
| 131 | |
| 132 | @staticmethod |
| 133 | def unpack(buf): |
| 134 | obj = bsn_set_tunnel_dst() |
| 135 | if type(buf) == loxi.generic_util.OFReader: |
| 136 | reader = buf |
| 137 | else: |
| 138 | reader = loxi.generic_util.OFReader(buf) |
| 139 | _type = reader.read('!H')[0] |
| 140 | assert(_type == const.OFPAT_EXPERIMENTER) |
| 141 | _len = reader.read('!H')[0] |
| 142 | _experimenter = reader.read('!L')[0] |
| 143 | assert(_experimenter == 0x5c16c7) |
| 144 | _subtype = reader.read('!L')[0] |
| 145 | assert(_subtype == 2) |
| 146 | obj.dst = reader.read('!L')[0] |
| 147 | return obj |
| 148 | |
| 149 | def __eq__(self, other): |
| 150 | if type(self) != type(other): return False |
| 151 | if self.dst != other.dst: return False |
| 152 | return True |
| 153 | |
| 154 | def __ne__(self, other): |
| 155 | return not self.__eq__(other) |
| 156 | |
| 157 | def show(self): |
| 158 | import loxi.pp |
| 159 | return loxi.pp.pp(self) |
| 160 | |
| 161 | def pretty_print(self, q): |
| 162 | q.text("bsn_set_tunnel_dst {") |
| 163 | with q.group(): |
| 164 | with q.indent(2): |
| 165 | q.breakable() |
| 166 | q.text("dst = "); |
| 167 | q.text("%#x" % self.dst) |
| 168 | q.breakable() |
| 169 | q.text('}') |
| 170 | |
| 171 | class copy_ttl_in(Action): |
| 172 | type = const.OFPAT_COPY_TTL_IN |
| 173 | |
| 174 | def __init__(self): |
| 175 | return |
| 176 | |
| 177 | def pack(self): |
| 178 | packed = [] |
| 179 | packed.append(struct.pack("!H", self.type)) |
| 180 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 181 | packed.append('\x00' * 4) |
| 182 | length = sum([len(x) for x in packed]) |
| 183 | packed[1] = struct.pack("!H", length) |
| 184 | return ''.join(packed) |
| 185 | |
| 186 | @staticmethod |
| 187 | def unpack(buf): |
| 188 | obj = copy_ttl_in() |
| 189 | if type(buf) == loxi.generic_util.OFReader: |
| 190 | reader = buf |
| 191 | else: |
| 192 | reader = loxi.generic_util.OFReader(buf) |
| 193 | _type = reader.read('!H')[0] |
| 194 | assert(_type == const.OFPAT_COPY_TTL_IN) |
| 195 | _len = reader.read('!H')[0] |
| 196 | reader.skip(4) |
| 197 | return obj |
| 198 | |
| 199 | def __eq__(self, other): |
| 200 | if type(self) != type(other): return False |
| 201 | return True |
| 202 | |
| 203 | def __ne__(self, other): |
| 204 | return not self.__eq__(other) |
| 205 | |
| 206 | def show(self): |
| 207 | import loxi.pp |
| 208 | return loxi.pp.pp(self) |
| 209 | |
| 210 | def pretty_print(self, q): |
| 211 | q.text("copy_ttl_in {") |
| 212 | with q.group(): |
| 213 | with q.indent(2): |
| 214 | q.breakable() |
| 215 | q.breakable() |
| 216 | q.text('}') |
| 217 | |
| 218 | class copy_ttl_out(Action): |
| 219 | type = const.OFPAT_COPY_TTL_OUT |
| 220 | |
| 221 | def __init__(self): |
| 222 | return |
| 223 | |
| 224 | def pack(self): |
| 225 | packed = [] |
| 226 | packed.append(struct.pack("!H", self.type)) |
| 227 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 228 | packed.append('\x00' * 4) |
| 229 | length = sum([len(x) for x in packed]) |
| 230 | packed[1] = struct.pack("!H", length) |
| 231 | return ''.join(packed) |
| 232 | |
| 233 | @staticmethod |
| 234 | def unpack(buf): |
| 235 | obj = copy_ttl_out() |
| 236 | if type(buf) == loxi.generic_util.OFReader: |
| 237 | reader = buf |
| 238 | else: |
| 239 | reader = loxi.generic_util.OFReader(buf) |
| 240 | _type = reader.read('!H')[0] |
| 241 | assert(_type == const.OFPAT_COPY_TTL_OUT) |
| 242 | _len = reader.read('!H')[0] |
| 243 | reader.skip(4) |
| 244 | return obj |
| 245 | |
| 246 | def __eq__(self, other): |
| 247 | if type(self) != type(other): return False |
| 248 | return True |
| 249 | |
| 250 | def __ne__(self, other): |
| 251 | return not self.__eq__(other) |
| 252 | |
| 253 | def show(self): |
| 254 | import loxi.pp |
| 255 | return loxi.pp.pp(self) |
| 256 | |
| 257 | def pretty_print(self, q): |
| 258 | q.text("copy_ttl_out {") |
| 259 | with q.group(): |
| 260 | with q.indent(2): |
| 261 | q.breakable() |
| 262 | q.breakable() |
| 263 | q.text('}') |
| 264 | |
| 265 | class dec_mpls_ttl(Action): |
| 266 | type = const.OFPAT_DEC_MPLS_TTL |
| 267 | |
| 268 | def __init__(self): |
| 269 | return |
| 270 | |
| 271 | def pack(self): |
| 272 | packed = [] |
| 273 | packed.append(struct.pack("!H", self.type)) |
| 274 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 275 | packed.append('\x00' * 4) |
| 276 | length = sum([len(x) for x in packed]) |
| 277 | packed[1] = struct.pack("!H", length) |
| 278 | return ''.join(packed) |
| 279 | |
| 280 | @staticmethod |
| 281 | def unpack(buf): |
| 282 | obj = dec_mpls_ttl() |
| 283 | if type(buf) == loxi.generic_util.OFReader: |
| 284 | reader = buf |
| 285 | else: |
| 286 | reader = loxi.generic_util.OFReader(buf) |
| 287 | _type = reader.read('!H')[0] |
| 288 | assert(_type == const.OFPAT_DEC_MPLS_TTL) |
| 289 | _len = reader.read('!H')[0] |
| 290 | reader.skip(4) |
| 291 | return obj |
| 292 | |
| 293 | def __eq__(self, other): |
| 294 | if type(self) != type(other): return False |
| 295 | return True |
| 296 | |
| 297 | def __ne__(self, other): |
| 298 | return not self.__eq__(other) |
| 299 | |
| 300 | def show(self): |
| 301 | import loxi.pp |
| 302 | return loxi.pp.pp(self) |
| 303 | |
| 304 | def pretty_print(self, q): |
| 305 | q.text("dec_mpls_ttl {") |
| 306 | with q.group(): |
| 307 | with q.indent(2): |
| 308 | q.breakable() |
| 309 | q.breakable() |
| 310 | q.text('}') |
| 311 | |
| 312 | class dec_nw_ttl(Action): |
| 313 | type = const.OFPAT_DEC_NW_TTL |
| 314 | |
| 315 | def __init__(self): |
| 316 | return |
| 317 | |
| 318 | def pack(self): |
| 319 | packed = [] |
| 320 | packed.append(struct.pack("!H", self.type)) |
| 321 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 322 | packed.append('\x00' * 4) |
| 323 | length = sum([len(x) for x in packed]) |
| 324 | packed[1] = struct.pack("!H", length) |
| 325 | return ''.join(packed) |
| 326 | |
| 327 | @staticmethod |
| 328 | def unpack(buf): |
| 329 | obj = dec_nw_ttl() |
| 330 | if type(buf) == loxi.generic_util.OFReader: |
| 331 | reader = buf |
| 332 | else: |
| 333 | reader = loxi.generic_util.OFReader(buf) |
| 334 | _type = reader.read('!H')[0] |
| 335 | assert(_type == const.OFPAT_DEC_NW_TTL) |
| 336 | _len = reader.read('!H')[0] |
| 337 | reader.skip(4) |
| 338 | return obj |
| 339 | |
| 340 | def __eq__(self, other): |
| 341 | if type(self) != type(other): return False |
| 342 | return True |
| 343 | |
| 344 | def __ne__(self, other): |
| 345 | return not self.__eq__(other) |
| 346 | |
| 347 | def show(self): |
| 348 | import loxi.pp |
| 349 | return loxi.pp.pp(self) |
| 350 | |
| 351 | def pretty_print(self, q): |
| 352 | q.text("dec_nw_ttl {") |
| 353 | with q.group(): |
| 354 | with q.indent(2): |
| 355 | q.breakable() |
| 356 | q.breakable() |
| 357 | q.text('}') |
| 358 | |
| 359 | class group(Action): |
| 360 | type = const.OFPAT_GROUP |
| 361 | |
| 362 | def __init__(self, group_id=None): |
| 363 | if group_id != None: |
| 364 | self.group_id = group_id |
| 365 | else: |
| 366 | self.group_id = 0 |
| 367 | return |
| 368 | |
| 369 | def pack(self): |
| 370 | packed = [] |
| 371 | packed.append(struct.pack("!H", self.type)) |
| 372 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 373 | packed.append(struct.pack("!L", self.group_id)) |
| 374 | length = sum([len(x) for x in packed]) |
| 375 | packed[1] = struct.pack("!H", length) |
| 376 | return ''.join(packed) |
| 377 | |
| 378 | @staticmethod |
| 379 | def unpack(buf): |
| 380 | obj = group() |
| 381 | if type(buf) == loxi.generic_util.OFReader: |
| 382 | reader = buf |
| 383 | else: |
| 384 | reader = loxi.generic_util.OFReader(buf) |
| 385 | _type = reader.read('!H')[0] |
| 386 | assert(_type == const.OFPAT_GROUP) |
| 387 | _len = reader.read('!H')[0] |
| 388 | obj.group_id = reader.read('!L')[0] |
| 389 | return obj |
| 390 | |
| 391 | def __eq__(self, other): |
| 392 | if type(self) != type(other): return False |
| 393 | if self.group_id != other.group_id: return False |
| 394 | return True |
| 395 | |
| 396 | def __ne__(self, other): |
| 397 | return not self.__eq__(other) |
| 398 | |
| 399 | def show(self): |
| 400 | import loxi.pp |
| 401 | return loxi.pp.pp(self) |
| 402 | |
| 403 | def pretty_print(self, q): |
| 404 | q.text("group {") |
| 405 | with q.group(): |
| 406 | with q.indent(2): |
| 407 | q.breakable() |
| 408 | q.text("group_id = "); |
| 409 | q.text("%#x" % self.group_id) |
| 410 | q.breakable() |
| 411 | q.text('}') |
| 412 | |
| 413 | class nicira_dec_ttl(Action): |
| 414 | type = const.OFPAT_EXPERIMENTER |
| 415 | experimenter = 0x2320 |
| 416 | subtype = 18 |
| 417 | |
| 418 | def __init__(self): |
| 419 | return |
| 420 | |
| 421 | def pack(self): |
| 422 | packed = [] |
| 423 | packed.append(struct.pack("!H", self.type)) |
| 424 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 425 | packed.append(struct.pack("!L", self.experimenter)) |
| 426 | packed.append(struct.pack("!H", self.subtype)) |
| 427 | packed.append('\x00' * 2) |
| 428 | packed.append('\x00' * 4) |
| 429 | length = sum([len(x) for x in packed]) |
| 430 | packed[1] = struct.pack("!H", length) |
| 431 | return ''.join(packed) |
| 432 | |
| 433 | @staticmethod |
| 434 | def unpack(buf): |
| 435 | obj = nicira_dec_ttl() |
| 436 | if type(buf) == loxi.generic_util.OFReader: |
| 437 | reader = buf |
| 438 | else: |
| 439 | reader = loxi.generic_util.OFReader(buf) |
| 440 | _type = reader.read('!H')[0] |
| 441 | assert(_type == const.OFPAT_EXPERIMENTER) |
| 442 | _len = reader.read('!H')[0] |
| 443 | _experimenter = reader.read('!L')[0] |
| 444 | assert(_experimenter == 0x2320) |
| 445 | _subtype = reader.read('!H')[0] |
| 446 | assert(_subtype == 18) |
| 447 | reader.skip(2) |
| 448 | reader.skip(4) |
| 449 | return obj |
| 450 | |
| 451 | def __eq__(self, other): |
| 452 | if type(self) != type(other): return False |
| 453 | return True |
| 454 | |
| 455 | def __ne__(self, other): |
| 456 | return not self.__eq__(other) |
| 457 | |
| 458 | def show(self): |
| 459 | import loxi.pp |
| 460 | return loxi.pp.pp(self) |
| 461 | |
| 462 | def pretty_print(self, q): |
| 463 | q.text("nicira_dec_ttl {") |
| 464 | with q.group(): |
| 465 | with q.indent(2): |
| 466 | q.breakable() |
| 467 | q.breakable() |
| 468 | q.text('}') |
| 469 | |
| 470 | class output(Action): |
| 471 | type = const.OFPAT_OUTPUT |
| 472 | |
| 473 | def __init__(self, port=None, max_len=None): |
| 474 | if port != None: |
| 475 | self.port = port |
| 476 | else: |
| 477 | self.port = 0 |
| 478 | if max_len != None: |
| 479 | self.max_len = max_len |
| 480 | else: |
| 481 | self.max_len = 0 |
| 482 | return |
| 483 | |
| 484 | def pack(self): |
| 485 | packed = [] |
| 486 | packed.append(struct.pack("!H", self.type)) |
| 487 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 488 | packed.append(struct.pack("!L", self.port)) |
| 489 | packed.append(struct.pack("!H", self.max_len)) |
| 490 | packed.append('\x00' * 6) |
| 491 | length = sum([len(x) for x in packed]) |
| 492 | packed[1] = struct.pack("!H", length) |
| 493 | return ''.join(packed) |
| 494 | |
| 495 | @staticmethod |
| 496 | def unpack(buf): |
| 497 | obj = output() |
| 498 | if type(buf) == loxi.generic_util.OFReader: |
| 499 | reader = buf |
| 500 | else: |
| 501 | reader = loxi.generic_util.OFReader(buf) |
| 502 | _type = reader.read('!H')[0] |
| 503 | assert(_type == const.OFPAT_OUTPUT) |
| 504 | _len = reader.read('!H')[0] |
| 505 | obj.port = reader.read('!L')[0] |
| 506 | obj.max_len = reader.read('!H')[0] |
| 507 | reader.skip(6) |
| 508 | return obj |
| 509 | |
| 510 | def __eq__(self, other): |
| 511 | if type(self) != type(other): return False |
| 512 | if self.port != other.port: return False |
| 513 | if self.max_len != other.max_len: return False |
| 514 | return True |
| 515 | |
| 516 | def __ne__(self, other): |
| 517 | return not self.__eq__(other) |
| 518 | |
| 519 | def show(self): |
| 520 | import loxi.pp |
| 521 | return loxi.pp.pp(self) |
| 522 | |
| 523 | def pretty_print(self, q): |
| 524 | q.text("output {") |
| 525 | with q.group(): |
| 526 | with q.indent(2): |
| 527 | q.breakable() |
| 528 | q.text("port = "); |
| 529 | q.text(util.pretty_port(self.port)) |
| 530 | q.text(","); q.breakable() |
| 531 | q.text("max_len = "); |
| 532 | q.text("%#x" % self.max_len) |
| 533 | q.breakable() |
| 534 | q.text('}') |
| 535 | |
| 536 | class pop_mpls(Action): |
| 537 | type = const.OFPAT_POP_MPLS |
| 538 | |
| 539 | def __init__(self, ethertype=None): |
| 540 | if ethertype != None: |
| 541 | self.ethertype = ethertype |
| 542 | else: |
| 543 | self.ethertype = 0 |
| 544 | return |
| 545 | |
| 546 | def pack(self): |
| 547 | packed = [] |
| 548 | packed.append(struct.pack("!H", self.type)) |
| 549 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 550 | packed.append(struct.pack("!H", self.ethertype)) |
| 551 | packed.append('\x00' * 2) |
| 552 | length = sum([len(x) for x in packed]) |
| 553 | packed[1] = struct.pack("!H", length) |
| 554 | return ''.join(packed) |
| 555 | |
| 556 | @staticmethod |
| 557 | def unpack(buf): |
| 558 | obj = pop_mpls() |
| 559 | if type(buf) == loxi.generic_util.OFReader: |
| 560 | reader = buf |
| 561 | else: |
| 562 | reader = loxi.generic_util.OFReader(buf) |
| 563 | _type = reader.read('!H')[0] |
| 564 | assert(_type == const.OFPAT_POP_MPLS) |
| 565 | _len = reader.read('!H')[0] |
| 566 | obj.ethertype = reader.read('!H')[0] |
| 567 | reader.skip(2) |
| 568 | return obj |
| 569 | |
| 570 | def __eq__(self, other): |
| 571 | if type(self) != type(other): return False |
| 572 | if self.ethertype != other.ethertype: return False |
| 573 | return True |
| 574 | |
| 575 | def __ne__(self, other): |
| 576 | return not self.__eq__(other) |
| 577 | |
| 578 | def show(self): |
| 579 | import loxi.pp |
| 580 | return loxi.pp.pp(self) |
| 581 | |
| 582 | def pretty_print(self, q): |
| 583 | q.text("pop_mpls {") |
| 584 | with q.group(): |
| 585 | with q.indent(2): |
| 586 | q.breakable() |
| 587 | q.text("ethertype = "); |
| 588 | q.text("%#x" % self.ethertype) |
| 589 | q.breakable() |
| 590 | q.text('}') |
| 591 | |
| 592 | class pop_pbb(Action): |
| 593 | type = const.OFPAT_POP_PBB |
| 594 | |
| 595 | def __init__(self): |
| 596 | return |
| 597 | |
| 598 | def pack(self): |
| 599 | packed = [] |
| 600 | packed.append(struct.pack("!H", self.type)) |
| 601 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 602 | packed.append('\x00' * 4) |
| 603 | length = sum([len(x) for x in packed]) |
| 604 | packed[1] = struct.pack("!H", length) |
| 605 | return ''.join(packed) |
| 606 | |
| 607 | @staticmethod |
| 608 | def unpack(buf): |
| 609 | obj = pop_pbb() |
| 610 | if type(buf) == loxi.generic_util.OFReader: |
| 611 | reader = buf |
| 612 | else: |
| 613 | reader = loxi.generic_util.OFReader(buf) |
| 614 | _type = reader.read('!H')[0] |
| 615 | assert(_type == const.OFPAT_POP_PBB) |
| 616 | _len = reader.read('!H')[0] |
| 617 | reader.skip(4) |
| 618 | return obj |
| 619 | |
| 620 | def __eq__(self, other): |
| 621 | if type(self) != type(other): return False |
| 622 | return True |
| 623 | |
| 624 | def __ne__(self, other): |
| 625 | return not self.__eq__(other) |
| 626 | |
| 627 | def show(self): |
| 628 | import loxi.pp |
| 629 | return loxi.pp.pp(self) |
| 630 | |
| 631 | def pretty_print(self, q): |
| 632 | q.text("pop_pbb {") |
| 633 | with q.group(): |
| 634 | with q.indent(2): |
| 635 | q.breakable() |
| 636 | q.breakable() |
| 637 | q.text('}') |
| 638 | |
| 639 | class pop_vlan(Action): |
| 640 | type = const.OFPAT_POP_VLAN |
| 641 | |
| 642 | def __init__(self): |
| 643 | return |
| 644 | |
| 645 | def pack(self): |
| 646 | packed = [] |
| 647 | packed.append(struct.pack("!H", self.type)) |
| 648 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 649 | packed.append('\x00' * 4) |
| 650 | length = sum([len(x) for x in packed]) |
| 651 | packed[1] = struct.pack("!H", length) |
| 652 | return ''.join(packed) |
| 653 | |
| 654 | @staticmethod |
| 655 | def unpack(buf): |
| 656 | obj = pop_vlan() |
| 657 | if type(buf) == loxi.generic_util.OFReader: |
| 658 | reader = buf |
| 659 | else: |
| 660 | reader = loxi.generic_util.OFReader(buf) |
| 661 | _type = reader.read('!H')[0] |
| 662 | assert(_type == const.OFPAT_POP_VLAN) |
| 663 | _len = reader.read('!H')[0] |
| 664 | reader.skip(4) |
| 665 | return obj |
| 666 | |
| 667 | def __eq__(self, other): |
| 668 | if type(self) != type(other): return False |
| 669 | return True |
| 670 | |
| 671 | def __ne__(self, other): |
| 672 | return not self.__eq__(other) |
| 673 | |
| 674 | def show(self): |
| 675 | import loxi.pp |
| 676 | return loxi.pp.pp(self) |
| 677 | |
| 678 | def pretty_print(self, q): |
| 679 | q.text("pop_vlan {") |
| 680 | with q.group(): |
| 681 | with q.indent(2): |
| 682 | q.breakable() |
| 683 | q.breakable() |
| 684 | q.text('}') |
| 685 | |
| 686 | class push_mpls(Action): |
| 687 | type = const.OFPAT_PUSH_MPLS |
| 688 | |
| 689 | def __init__(self, ethertype=None): |
| 690 | if ethertype != None: |
| 691 | self.ethertype = ethertype |
| 692 | else: |
| 693 | self.ethertype = 0 |
| 694 | return |
| 695 | |
| 696 | def pack(self): |
| 697 | packed = [] |
| 698 | packed.append(struct.pack("!H", self.type)) |
| 699 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 700 | packed.append(struct.pack("!H", self.ethertype)) |
| 701 | packed.append('\x00' * 2) |
| 702 | length = sum([len(x) for x in packed]) |
| 703 | packed[1] = struct.pack("!H", length) |
| 704 | return ''.join(packed) |
| 705 | |
| 706 | @staticmethod |
| 707 | def unpack(buf): |
| 708 | obj = push_mpls() |
| 709 | if type(buf) == loxi.generic_util.OFReader: |
| 710 | reader = buf |
| 711 | else: |
| 712 | reader = loxi.generic_util.OFReader(buf) |
| 713 | _type = reader.read('!H')[0] |
| 714 | assert(_type == const.OFPAT_PUSH_MPLS) |
| 715 | _len = reader.read('!H')[0] |
| 716 | obj.ethertype = reader.read('!H')[0] |
| 717 | reader.skip(2) |
| 718 | return obj |
| 719 | |
| 720 | def __eq__(self, other): |
| 721 | if type(self) != type(other): return False |
| 722 | if self.ethertype != other.ethertype: return False |
| 723 | return True |
| 724 | |
| 725 | def __ne__(self, other): |
| 726 | return not self.__eq__(other) |
| 727 | |
| 728 | def show(self): |
| 729 | import loxi.pp |
| 730 | return loxi.pp.pp(self) |
| 731 | |
| 732 | def pretty_print(self, q): |
| 733 | q.text("push_mpls {") |
| 734 | with q.group(): |
| 735 | with q.indent(2): |
| 736 | q.breakable() |
| 737 | q.text("ethertype = "); |
| 738 | q.text("%#x" % self.ethertype) |
| 739 | q.breakable() |
| 740 | q.text('}') |
| 741 | |
| 742 | class push_pbb(Action): |
| 743 | type = const.OFPAT_PUSH_PBB |
| 744 | |
| 745 | def __init__(self, ethertype=None): |
| 746 | if ethertype != None: |
| 747 | self.ethertype = ethertype |
| 748 | else: |
| 749 | self.ethertype = 0 |
| 750 | return |
| 751 | |
| 752 | def pack(self): |
| 753 | packed = [] |
| 754 | packed.append(struct.pack("!H", self.type)) |
| 755 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 756 | packed.append(struct.pack("!H", self.ethertype)) |
| 757 | packed.append('\x00' * 2) |
| 758 | length = sum([len(x) for x in packed]) |
| 759 | packed[1] = struct.pack("!H", length) |
| 760 | return ''.join(packed) |
| 761 | |
| 762 | @staticmethod |
| 763 | def unpack(buf): |
| 764 | obj = push_pbb() |
| 765 | if type(buf) == loxi.generic_util.OFReader: |
| 766 | reader = buf |
| 767 | else: |
| 768 | reader = loxi.generic_util.OFReader(buf) |
| 769 | _type = reader.read('!H')[0] |
| 770 | assert(_type == const.OFPAT_PUSH_PBB) |
| 771 | _len = reader.read('!H')[0] |
| 772 | obj.ethertype = reader.read('!H')[0] |
| 773 | reader.skip(2) |
| 774 | return obj |
| 775 | |
| 776 | def __eq__(self, other): |
| 777 | if type(self) != type(other): return False |
| 778 | if self.ethertype != other.ethertype: return False |
| 779 | return True |
| 780 | |
| 781 | def __ne__(self, other): |
| 782 | return not self.__eq__(other) |
| 783 | |
| 784 | def show(self): |
| 785 | import loxi.pp |
| 786 | return loxi.pp.pp(self) |
| 787 | |
| 788 | def pretty_print(self, q): |
| 789 | q.text("push_pbb {") |
| 790 | with q.group(): |
| 791 | with q.indent(2): |
| 792 | q.breakable() |
| 793 | q.text("ethertype = "); |
| 794 | q.text("%#x" % self.ethertype) |
| 795 | q.breakable() |
| 796 | q.text('}') |
| 797 | |
| 798 | class push_vlan(Action): |
| 799 | type = const.OFPAT_PUSH_VLAN |
| 800 | |
| 801 | def __init__(self, ethertype=None): |
| 802 | if ethertype != None: |
| 803 | self.ethertype = ethertype |
| 804 | else: |
| 805 | self.ethertype = 0 |
| 806 | return |
| 807 | |
| 808 | def pack(self): |
| 809 | packed = [] |
| 810 | packed.append(struct.pack("!H", self.type)) |
| 811 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 812 | packed.append(struct.pack("!H", self.ethertype)) |
| 813 | packed.append('\x00' * 2) |
| 814 | length = sum([len(x) for x in packed]) |
| 815 | packed[1] = struct.pack("!H", length) |
| 816 | return ''.join(packed) |
| 817 | |
| 818 | @staticmethod |
| 819 | def unpack(buf): |
| 820 | obj = push_vlan() |
| 821 | if type(buf) == loxi.generic_util.OFReader: |
| 822 | reader = buf |
| 823 | else: |
| 824 | reader = loxi.generic_util.OFReader(buf) |
| 825 | _type = reader.read('!H')[0] |
| 826 | assert(_type == const.OFPAT_PUSH_VLAN) |
| 827 | _len = reader.read('!H')[0] |
| 828 | obj.ethertype = reader.read('!H')[0] |
| 829 | reader.skip(2) |
| 830 | return obj |
| 831 | |
| 832 | def __eq__(self, other): |
| 833 | if type(self) != type(other): return False |
| 834 | if self.ethertype != other.ethertype: return False |
| 835 | return True |
| 836 | |
| 837 | def __ne__(self, other): |
| 838 | return not self.__eq__(other) |
| 839 | |
| 840 | def show(self): |
| 841 | import loxi.pp |
| 842 | return loxi.pp.pp(self) |
| 843 | |
| 844 | def pretty_print(self, q): |
| 845 | q.text("push_vlan {") |
| 846 | with q.group(): |
| 847 | with q.indent(2): |
| 848 | q.breakable() |
| 849 | q.text("ethertype = "); |
| 850 | q.text("%#x" % self.ethertype) |
| 851 | q.breakable() |
| 852 | q.text('}') |
| 853 | |
| 854 | class set_field(Action): |
| 855 | type = const.OFPAT_SET_FIELD |
| 856 | |
| 857 | def __init__(self, field=None): |
| 858 | if field != None: |
| 859 | self.field = field |
| 860 | else: |
| 861 | self.field = "" |
| 862 | return |
| 863 | |
| 864 | def pack(self): |
| 865 | packed = [] |
| 866 | packed.append(struct.pack("!H", self.type)) |
| 867 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 868 | packed.append(self.field) |
| 869 | length = sum([len(x) for x in packed]) |
| 870 | packed[1] = struct.pack("!H", length) |
| 871 | return ''.join(packed) |
| 872 | |
| 873 | @staticmethod |
| 874 | def unpack(buf): |
| 875 | obj = set_field() |
| 876 | if type(buf) == loxi.generic_util.OFReader: |
| 877 | reader = buf |
| 878 | else: |
| 879 | reader = loxi.generic_util.OFReader(buf) |
| 880 | _type = reader.read('!H')[0] |
| 881 | assert(_type == const.OFPAT_SET_FIELD) |
| 882 | _len = reader.read('!H')[0] |
| 883 | obj.field = str(reader.read_all()) |
| 884 | return obj |
| 885 | |
| 886 | def __eq__(self, other): |
| 887 | if type(self) != type(other): return False |
| 888 | if self.field != other.field: return False |
| 889 | return True |
| 890 | |
| 891 | def __ne__(self, other): |
| 892 | return not self.__eq__(other) |
| 893 | |
| 894 | def show(self): |
| 895 | import loxi.pp |
| 896 | return loxi.pp.pp(self) |
| 897 | |
| 898 | def pretty_print(self, q): |
| 899 | q.text("set_field {") |
| 900 | with q.group(): |
| 901 | with q.indent(2): |
| 902 | q.breakable() |
| 903 | q.text("field = "); |
| 904 | q.pp(self.field) |
| 905 | q.breakable() |
| 906 | q.text('}') |
| 907 | |
| 908 | class set_mpls_ttl(Action): |
| 909 | type = const.OFPAT_SET_MPLS_TTL |
| 910 | |
| 911 | def __init__(self, mpls_ttl=None): |
| 912 | if mpls_ttl != None: |
| 913 | self.mpls_ttl = mpls_ttl |
| 914 | else: |
| 915 | self.mpls_ttl = 0 |
| 916 | return |
| 917 | |
| 918 | def pack(self): |
| 919 | packed = [] |
| 920 | packed.append(struct.pack("!H", self.type)) |
| 921 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 922 | packed.append(struct.pack("!B", self.mpls_ttl)) |
| 923 | packed.append('\x00' * 3) |
| 924 | length = sum([len(x) for x in packed]) |
| 925 | packed[1] = struct.pack("!H", length) |
| 926 | return ''.join(packed) |
| 927 | |
| 928 | @staticmethod |
| 929 | def unpack(buf): |
| 930 | obj = set_mpls_ttl() |
| 931 | if type(buf) == loxi.generic_util.OFReader: |
| 932 | reader = buf |
| 933 | else: |
| 934 | reader = loxi.generic_util.OFReader(buf) |
| 935 | _type = reader.read('!H')[0] |
| 936 | assert(_type == const.OFPAT_SET_MPLS_TTL) |
| 937 | _len = reader.read('!H')[0] |
| 938 | obj.mpls_ttl = reader.read('!B')[0] |
| 939 | reader.skip(3) |
| 940 | return obj |
| 941 | |
| 942 | def __eq__(self, other): |
| 943 | if type(self) != type(other): return False |
| 944 | if self.mpls_ttl != other.mpls_ttl: return False |
| 945 | return True |
| 946 | |
| 947 | def __ne__(self, other): |
| 948 | return not self.__eq__(other) |
| 949 | |
| 950 | def show(self): |
| 951 | import loxi.pp |
| 952 | return loxi.pp.pp(self) |
| 953 | |
| 954 | def pretty_print(self, q): |
| 955 | q.text("set_mpls_ttl {") |
| 956 | with q.group(): |
| 957 | with q.indent(2): |
| 958 | q.breakable() |
| 959 | q.text("mpls_ttl = "); |
| 960 | q.text("%#x" % self.mpls_ttl) |
| 961 | q.breakable() |
| 962 | q.text('}') |
| 963 | |
| 964 | class set_nw_ttl(Action): |
| 965 | type = const.OFPAT_SET_NW_TTL |
| 966 | |
| 967 | def __init__(self, nw_ttl=None): |
| 968 | if nw_ttl != None: |
| 969 | self.nw_ttl = nw_ttl |
| 970 | else: |
| 971 | self.nw_ttl = 0 |
| 972 | return |
| 973 | |
| 974 | def pack(self): |
| 975 | packed = [] |
| 976 | packed.append(struct.pack("!H", self.type)) |
| 977 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 978 | packed.append(struct.pack("!B", self.nw_ttl)) |
| 979 | packed.append('\x00' * 3) |
| 980 | length = sum([len(x) for x in packed]) |
| 981 | packed[1] = struct.pack("!H", length) |
| 982 | return ''.join(packed) |
| 983 | |
| 984 | @staticmethod |
| 985 | def unpack(buf): |
| 986 | obj = set_nw_ttl() |
| 987 | if type(buf) == loxi.generic_util.OFReader: |
| 988 | reader = buf |
| 989 | else: |
| 990 | reader = loxi.generic_util.OFReader(buf) |
| 991 | _type = reader.read('!H')[0] |
| 992 | assert(_type == const.OFPAT_SET_NW_TTL) |
| 993 | _len = reader.read('!H')[0] |
| 994 | obj.nw_ttl = reader.read('!B')[0] |
| 995 | reader.skip(3) |
| 996 | return obj |
| 997 | |
| 998 | def __eq__(self, other): |
| 999 | if type(self) != type(other): return False |
| 1000 | if self.nw_ttl != other.nw_ttl: return False |
| 1001 | return True |
| 1002 | |
| 1003 | def __ne__(self, other): |
| 1004 | return not self.__eq__(other) |
| 1005 | |
| 1006 | def show(self): |
| 1007 | import loxi.pp |
| 1008 | return loxi.pp.pp(self) |
| 1009 | |
| 1010 | def pretty_print(self, q): |
| 1011 | q.text("set_nw_ttl {") |
| 1012 | with q.group(): |
| 1013 | with q.indent(2): |
| 1014 | q.breakable() |
| 1015 | q.text("nw_ttl = "); |
| 1016 | q.text("%#x" % self.nw_ttl) |
| 1017 | q.breakable() |
| 1018 | q.text('}') |
| 1019 | |
| 1020 | class set_queue(Action): |
| 1021 | type = const.OFPAT_SET_QUEUE |
| 1022 | |
| 1023 | def __init__(self, queue_id=None): |
| 1024 | if queue_id != None: |
| 1025 | self.queue_id = queue_id |
| 1026 | else: |
| 1027 | self.queue_id = 0 |
| 1028 | return |
| 1029 | |
| 1030 | def pack(self): |
| 1031 | packed = [] |
| 1032 | packed.append(struct.pack("!H", self.type)) |
| 1033 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1034 | packed.append(struct.pack("!L", self.queue_id)) |
| 1035 | length = sum([len(x) for x in packed]) |
| 1036 | packed[1] = struct.pack("!H", length) |
| 1037 | return ''.join(packed) |
| 1038 | |
| 1039 | @staticmethod |
| 1040 | def unpack(buf): |
| 1041 | obj = set_queue() |
| 1042 | if type(buf) == loxi.generic_util.OFReader: |
| 1043 | reader = buf |
| 1044 | else: |
| 1045 | reader = loxi.generic_util.OFReader(buf) |
| 1046 | _type = reader.read('!H')[0] |
| 1047 | assert(_type == const.OFPAT_SET_QUEUE) |
| 1048 | _len = reader.read('!H')[0] |
| 1049 | obj.queue_id = reader.read('!L')[0] |
| 1050 | return obj |
| 1051 | |
| 1052 | def __eq__(self, other): |
| 1053 | if type(self) != type(other): return False |
| 1054 | if self.queue_id != other.queue_id: return False |
| 1055 | return True |
| 1056 | |
| 1057 | def __ne__(self, other): |
| 1058 | return not self.__eq__(other) |
| 1059 | |
| 1060 | def show(self): |
| 1061 | import loxi.pp |
| 1062 | return loxi.pp.pp(self) |
| 1063 | |
| 1064 | def pretty_print(self, q): |
| 1065 | q.text("set_queue {") |
| 1066 | with q.group(): |
| 1067 | with q.indent(2): |
| 1068 | q.breakable() |
| 1069 | q.text("queue_id = "); |
| 1070 | q.text("%#x" % self.queue_id) |
| 1071 | q.breakable() |
| 1072 | q.text('}') |
| 1073 | |
| 1074 | |
| 1075 | def parse_experimenter(reader): |
| 1076 | |
| 1077 | experimenter, = reader.peek("!4xL") |
| 1078 | if experimenter == 0x005c16c7: # Big Switch Networks |
| 1079 | subtype, = reader.peek("!8xL") |
| 1080 | elif experimenter == 0x00002320: # Nicira |
| 1081 | subtype, = reader.peek("!8xH") |
| 1082 | else: |
| 1083 | raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter) |
| 1084 | |
| 1085 | if subtype in experimenter_parsers[experimenter]: |
| 1086 | return experimenter_parsers[experimenter][subtype](reader) |
| 1087 | else: |
| 1088 | raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype) |
| 1089 | |
| 1090 | parsers = { |
| 1091 | const.OFPAT_COPY_TTL_IN : copy_ttl_in.unpack, |
| 1092 | const.OFPAT_COPY_TTL_OUT : copy_ttl_out.unpack, |
| 1093 | const.OFPAT_DEC_MPLS_TTL : dec_mpls_ttl.unpack, |
| 1094 | const.OFPAT_DEC_NW_TTL : dec_nw_ttl.unpack, |
| 1095 | const.OFPAT_EXPERIMENTER : parse_experimenter, |
| 1096 | const.OFPAT_GROUP : group.unpack, |
| 1097 | const.OFPAT_OUTPUT : output.unpack, |
| 1098 | const.OFPAT_POP_MPLS : pop_mpls.unpack, |
| 1099 | const.OFPAT_POP_PBB : pop_pbb.unpack, |
| 1100 | const.OFPAT_POP_VLAN : pop_vlan.unpack, |
| 1101 | const.OFPAT_PUSH_MPLS : push_mpls.unpack, |
| 1102 | const.OFPAT_PUSH_PBB : push_pbb.unpack, |
| 1103 | const.OFPAT_PUSH_VLAN : push_vlan.unpack, |
| 1104 | const.OFPAT_SET_FIELD : set_field.unpack, |
| 1105 | const.OFPAT_SET_MPLS_TTL : set_mpls_ttl.unpack, |
| 1106 | const.OFPAT_SET_NW_TTL : set_nw_ttl.unpack, |
| 1107 | const.OFPAT_SET_QUEUE : set_queue.unpack, |
| 1108 | } |
| 1109 | |
| 1110 | experimenter_parsers = { |
| 1111 | } |