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_vlan(Action): |
| 593 | type = const.OFPAT_POP_VLAN |
| 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_vlan() |
| 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_VLAN) |
| 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_vlan {") |
| 633 | with q.group(): |
| 634 | with q.indent(2): |
| 635 | q.breakable() |
| 636 | q.breakable() |
| 637 | q.text('}') |
| 638 | |
| 639 | class push_mpls(Action): |
| 640 | type = const.OFPAT_PUSH_MPLS |
| 641 | |
| 642 | def __init__(self, ethertype=None): |
| 643 | if ethertype != None: |
| 644 | self.ethertype = ethertype |
| 645 | else: |
| 646 | self.ethertype = 0 |
| 647 | return |
| 648 | |
| 649 | def pack(self): |
| 650 | packed = [] |
| 651 | packed.append(struct.pack("!H", self.type)) |
| 652 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 653 | packed.append(struct.pack("!H", self.ethertype)) |
| 654 | packed.append('\x00' * 2) |
| 655 | length = sum([len(x) for x in packed]) |
| 656 | packed[1] = struct.pack("!H", length) |
| 657 | return ''.join(packed) |
| 658 | |
| 659 | @staticmethod |
| 660 | def unpack(buf): |
| 661 | obj = push_mpls() |
| 662 | if type(buf) == loxi.generic_util.OFReader: |
| 663 | reader = buf |
| 664 | else: |
| 665 | reader = loxi.generic_util.OFReader(buf) |
| 666 | _type = reader.read('!H')[0] |
| 667 | assert(_type == const.OFPAT_PUSH_MPLS) |
| 668 | _len = reader.read('!H')[0] |
| 669 | obj.ethertype = reader.read('!H')[0] |
| 670 | reader.skip(2) |
| 671 | return obj |
| 672 | |
| 673 | def __eq__(self, other): |
| 674 | if type(self) != type(other): return False |
| 675 | if self.ethertype != other.ethertype: return False |
| 676 | return True |
| 677 | |
| 678 | def __ne__(self, other): |
| 679 | return not self.__eq__(other) |
| 680 | |
| 681 | def show(self): |
| 682 | import loxi.pp |
| 683 | return loxi.pp.pp(self) |
| 684 | |
| 685 | def pretty_print(self, q): |
| 686 | q.text("push_mpls {") |
| 687 | with q.group(): |
| 688 | with q.indent(2): |
| 689 | q.breakable() |
| 690 | q.text("ethertype = "); |
| 691 | q.text("%#x" % self.ethertype) |
| 692 | q.breakable() |
| 693 | q.text('}') |
| 694 | |
| 695 | class push_vlan(Action): |
| 696 | type = const.OFPAT_PUSH_VLAN |
| 697 | |
| 698 | def __init__(self, ethertype=None): |
| 699 | if ethertype != None: |
| 700 | self.ethertype = ethertype |
| 701 | else: |
| 702 | self.ethertype = 0 |
| 703 | return |
| 704 | |
| 705 | def pack(self): |
| 706 | packed = [] |
| 707 | packed.append(struct.pack("!H", self.type)) |
| 708 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 709 | packed.append(struct.pack("!H", self.ethertype)) |
| 710 | packed.append('\x00' * 2) |
| 711 | length = sum([len(x) for x in packed]) |
| 712 | packed[1] = struct.pack("!H", length) |
| 713 | return ''.join(packed) |
| 714 | |
| 715 | @staticmethod |
| 716 | def unpack(buf): |
| 717 | obj = push_vlan() |
| 718 | if type(buf) == loxi.generic_util.OFReader: |
| 719 | reader = buf |
| 720 | else: |
| 721 | reader = loxi.generic_util.OFReader(buf) |
| 722 | _type = reader.read('!H')[0] |
| 723 | assert(_type == const.OFPAT_PUSH_VLAN) |
| 724 | _len = reader.read('!H')[0] |
| 725 | obj.ethertype = reader.read('!H')[0] |
| 726 | reader.skip(2) |
| 727 | return obj |
| 728 | |
| 729 | def __eq__(self, other): |
| 730 | if type(self) != type(other): return False |
| 731 | if self.ethertype != other.ethertype: return False |
| 732 | return True |
| 733 | |
| 734 | def __ne__(self, other): |
| 735 | return not self.__eq__(other) |
| 736 | |
| 737 | def show(self): |
| 738 | import loxi.pp |
| 739 | return loxi.pp.pp(self) |
| 740 | |
| 741 | def pretty_print(self, q): |
| 742 | q.text("push_vlan {") |
| 743 | with q.group(): |
| 744 | with q.indent(2): |
| 745 | q.breakable() |
| 746 | q.text("ethertype = "); |
| 747 | q.text("%#x" % self.ethertype) |
| 748 | q.breakable() |
| 749 | q.text('}') |
| 750 | |
| 751 | class set_dl_dst(Action): |
| 752 | type = const.OFPAT_SET_DL_DST |
| 753 | |
| 754 | def __init__(self, dl_addr=None): |
| 755 | if dl_addr != None: |
| 756 | self.dl_addr = dl_addr |
| 757 | else: |
| 758 | self.dl_addr = [0,0,0,0,0,0] |
| 759 | return |
| 760 | |
| 761 | def pack(self): |
| 762 | packed = [] |
| 763 | packed.append(struct.pack("!H", self.type)) |
| 764 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 765 | packed.append(struct.pack("!6B", *self.dl_addr)) |
| 766 | packed.append('\x00' * 6) |
| 767 | length = sum([len(x) for x in packed]) |
| 768 | packed[1] = struct.pack("!H", length) |
| 769 | return ''.join(packed) |
| 770 | |
| 771 | @staticmethod |
| 772 | def unpack(buf): |
| 773 | obj = set_dl_dst() |
| 774 | if type(buf) == loxi.generic_util.OFReader: |
| 775 | reader = buf |
| 776 | else: |
| 777 | reader = loxi.generic_util.OFReader(buf) |
| 778 | _type = reader.read('!H')[0] |
| 779 | assert(_type == const.OFPAT_SET_DL_DST) |
| 780 | _len = reader.read('!H')[0] |
| 781 | obj.dl_addr = list(reader.read('!6B')) |
| 782 | reader.skip(6) |
| 783 | return obj |
| 784 | |
| 785 | def __eq__(self, other): |
| 786 | if type(self) != type(other): return False |
| 787 | if self.dl_addr != other.dl_addr: return False |
| 788 | return True |
| 789 | |
| 790 | def __ne__(self, other): |
| 791 | return not self.__eq__(other) |
| 792 | |
| 793 | def show(self): |
| 794 | import loxi.pp |
| 795 | return loxi.pp.pp(self) |
| 796 | |
| 797 | def pretty_print(self, q): |
| 798 | q.text("set_dl_dst {") |
| 799 | with q.group(): |
| 800 | with q.indent(2): |
| 801 | q.breakable() |
| 802 | q.text("dl_addr = "); |
| 803 | q.text(util.pretty_mac(self.dl_addr)) |
| 804 | q.breakable() |
| 805 | q.text('}') |
| 806 | |
| 807 | class set_dl_src(Action): |
| 808 | type = const.OFPAT_SET_DL_SRC |
| 809 | |
| 810 | def __init__(self, dl_addr=None): |
| 811 | if dl_addr != None: |
| 812 | self.dl_addr = dl_addr |
| 813 | else: |
| 814 | self.dl_addr = [0,0,0,0,0,0] |
| 815 | return |
| 816 | |
| 817 | def pack(self): |
| 818 | packed = [] |
| 819 | packed.append(struct.pack("!H", self.type)) |
| 820 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 821 | packed.append(struct.pack("!6B", *self.dl_addr)) |
| 822 | packed.append('\x00' * 6) |
| 823 | length = sum([len(x) for x in packed]) |
| 824 | packed[1] = struct.pack("!H", length) |
| 825 | return ''.join(packed) |
| 826 | |
| 827 | @staticmethod |
| 828 | def unpack(buf): |
| 829 | obj = set_dl_src() |
| 830 | if type(buf) == loxi.generic_util.OFReader: |
| 831 | reader = buf |
| 832 | else: |
| 833 | reader = loxi.generic_util.OFReader(buf) |
| 834 | _type = reader.read('!H')[0] |
| 835 | assert(_type == const.OFPAT_SET_DL_SRC) |
| 836 | _len = reader.read('!H')[0] |
| 837 | obj.dl_addr = list(reader.read('!6B')) |
| 838 | reader.skip(6) |
| 839 | return obj |
| 840 | |
| 841 | def __eq__(self, other): |
| 842 | if type(self) != type(other): return False |
| 843 | if self.dl_addr != other.dl_addr: return False |
| 844 | return True |
| 845 | |
| 846 | def __ne__(self, other): |
| 847 | return not self.__eq__(other) |
| 848 | |
| 849 | def show(self): |
| 850 | import loxi.pp |
| 851 | return loxi.pp.pp(self) |
| 852 | |
| 853 | def pretty_print(self, q): |
| 854 | q.text("set_dl_src {") |
| 855 | with q.group(): |
| 856 | with q.indent(2): |
| 857 | q.breakable() |
| 858 | q.text("dl_addr = "); |
| 859 | q.text(util.pretty_mac(self.dl_addr)) |
| 860 | q.breakable() |
| 861 | q.text('}') |
| 862 | |
| 863 | class set_mpls_label(Action): |
| 864 | type = const.OFPAT_SET_MPLS_LABEL |
| 865 | |
| 866 | def __init__(self, mpls_label=None): |
| 867 | if mpls_label != None: |
| 868 | self.mpls_label = mpls_label |
| 869 | else: |
| 870 | self.mpls_label = 0 |
| 871 | return |
| 872 | |
| 873 | def pack(self): |
| 874 | packed = [] |
| 875 | packed.append(struct.pack("!H", self.type)) |
| 876 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 877 | packed.append(struct.pack("!L", self.mpls_label)) |
| 878 | length = sum([len(x) for x in packed]) |
| 879 | packed[1] = struct.pack("!H", length) |
| 880 | return ''.join(packed) |
| 881 | |
| 882 | @staticmethod |
| 883 | def unpack(buf): |
| 884 | obj = set_mpls_label() |
| 885 | if type(buf) == loxi.generic_util.OFReader: |
| 886 | reader = buf |
| 887 | else: |
| 888 | reader = loxi.generic_util.OFReader(buf) |
| 889 | _type = reader.read('!H')[0] |
| 890 | assert(_type == const.OFPAT_SET_MPLS_LABEL) |
| 891 | _len = reader.read('!H')[0] |
| 892 | obj.mpls_label = reader.read('!L')[0] |
| 893 | return obj |
| 894 | |
| 895 | def __eq__(self, other): |
| 896 | if type(self) != type(other): return False |
| 897 | if self.mpls_label != other.mpls_label: return False |
| 898 | return True |
| 899 | |
| 900 | def __ne__(self, other): |
| 901 | return not self.__eq__(other) |
| 902 | |
| 903 | def show(self): |
| 904 | import loxi.pp |
| 905 | return loxi.pp.pp(self) |
| 906 | |
| 907 | def pretty_print(self, q): |
| 908 | q.text("set_mpls_label {") |
| 909 | with q.group(): |
| 910 | with q.indent(2): |
| 911 | q.breakable() |
| 912 | q.text("mpls_label = "); |
| 913 | q.text("%#x" % self.mpls_label) |
| 914 | q.breakable() |
| 915 | q.text('}') |
| 916 | |
| 917 | class set_mpls_tc(Action): |
| 918 | type = const.OFPAT_SET_MPLS_TC |
| 919 | |
| 920 | def __init__(self, mpls_tc=None): |
| 921 | if mpls_tc != None: |
| 922 | self.mpls_tc = mpls_tc |
| 923 | else: |
| 924 | self.mpls_tc = 0 |
| 925 | return |
| 926 | |
| 927 | def pack(self): |
| 928 | packed = [] |
| 929 | packed.append(struct.pack("!H", self.type)) |
| 930 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 931 | packed.append(struct.pack("!B", self.mpls_tc)) |
| 932 | packed.append('\x00' * 3) |
| 933 | length = sum([len(x) for x in packed]) |
| 934 | packed[1] = struct.pack("!H", length) |
| 935 | return ''.join(packed) |
| 936 | |
| 937 | @staticmethod |
| 938 | def unpack(buf): |
| 939 | obj = set_mpls_tc() |
| 940 | if type(buf) == loxi.generic_util.OFReader: |
| 941 | reader = buf |
| 942 | else: |
| 943 | reader = loxi.generic_util.OFReader(buf) |
| 944 | _type = reader.read('!H')[0] |
| 945 | assert(_type == const.OFPAT_SET_MPLS_TC) |
| 946 | _len = reader.read('!H')[0] |
| 947 | obj.mpls_tc = reader.read('!B')[0] |
| 948 | reader.skip(3) |
| 949 | return obj |
| 950 | |
| 951 | def __eq__(self, other): |
| 952 | if type(self) != type(other): return False |
| 953 | if self.mpls_tc != other.mpls_tc: return False |
| 954 | return True |
| 955 | |
| 956 | def __ne__(self, other): |
| 957 | return not self.__eq__(other) |
| 958 | |
| 959 | def show(self): |
| 960 | import loxi.pp |
| 961 | return loxi.pp.pp(self) |
| 962 | |
| 963 | def pretty_print(self, q): |
| 964 | q.text("set_mpls_tc {") |
| 965 | with q.group(): |
| 966 | with q.indent(2): |
| 967 | q.breakable() |
| 968 | q.text("mpls_tc = "); |
| 969 | q.text("%#x" % self.mpls_tc) |
| 970 | q.breakable() |
| 971 | q.text('}') |
| 972 | |
| 973 | class set_mpls_ttl(Action): |
| 974 | type = const.OFPAT_SET_MPLS_TTL |
| 975 | |
| 976 | def __init__(self, mpls_ttl=None): |
| 977 | if mpls_ttl != None: |
| 978 | self.mpls_ttl = mpls_ttl |
| 979 | else: |
| 980 | self.mpls_ttl = 0 |
| 981 | return |
| 982 | |
| 983 | def pack(self): |
| 984 | packed = [] |
| 985 | packed.append(struct.pack("!H", self.type)) |
| 986 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 987 | packed.append(struct.pack("!B", self.mpls_ttl)) |
| 988 | packed.append('\x00' * 3) |
| 989 | length = sum([len(x) for x in packed]) |
| 990 | packed[1] = struct.pack("!H", length) |
| 991 | return ''.join(packed) |
| 992 | |
| 993 | @staticmethod |
| 994 | def unpack(buf): |
| 995 | obj = set_mpls_ttl() |
| 996 | if type(buf) == loxi.generic_util.OFReader: |
| 997 | reader = buf |
| 998 | else: |
| 999 | reader = loxi.generic_util.OFReader(buf) |
| 1000 | _type = reader.read('!H')[0] |
| 1001 | assert(_type == const.OFPAT_SET_MPLS_TTL) |
| 1002 | _len = reader.read('!H')[0] |
| 1003 | obj.mpls_ttl = reader.read('!B')[0] |
| 1004 | reader.skip(3) |
| 1005 | return obj |
| 1006 | |
| 1007 | def __eq__(self, other): |
| 1008 | if type(self) != type(other): return False |
| 1009 | if self.mpls_ttl != other.mpls_ttl: return False |
| 1010 | return True |
| 1011 | |
| 1012 | def __ne__(self, other): |
| 1013 | return not self.__eq__(other) |
| 1014 | |
| 1015 | def show(self): |
| 1016 | import loxi.pp |
| 1017 | return loxi.pp.pp(self) |
| 1018 | |
| 1019 | def pretty_print(self, q): |
| 1020 | q.text("set_mpls_ttl {") |
| 1021 | with q.group(): |
| 1022 | with q.indent(2): |
| 1023 | q.breakable() |
| 1024 | q.text("mpls_ttl = "); |
| 1025 | q.text("%#x" % self.mpls_ttl) |
| 1026 | q.breakable() |
| 1027 | q.text('}') |
| 1028 | |
| 1029 | class set_nw_dst(Action): |
| 1030 | type = const.OFPAT_SET_NW_DST |
| 1031 | |
| 1032 | def __init__(self, nw_addr=None): |
| 1033 | if nw_addr != None: |
| 1034 | self.nw_addr = nw_addr |
| 1035 | else: |
| 1036 | self.nw_addr = 0 |
| 1037 | return |
| 1038 | |
| 1039 | def pack(self): |
| 1040 | packed = [] |
| 1041 | packed.append(struct.pack("!H", self.type)) |
| 1042 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1043 | packed.append(struct.pack("!L", self.nw_addr)) |
| 1044 | length = sum([len(x) for x in packed]) |
| 1045 | packed[1] = struct.pack("!H", length) |
| 1046 | return ''.join(packed) |
| 1047 | |
| 1048 | @staticmethod |
| 1049 | def unpack(buf): |
| 1050 | obj = set_nw_dst() |
| 1051 | if type(buf) == loxi.generic_util.OFReader: |
| 1052 | reader = buf |
| 1053 | else: |
| 1054 | reader = loxi.generic_util.OFReader(buf) |
| 1055 | _type = reader.read('!H')[0] |
| 1056 | assert(_type == const.OFPAT_SET_NW_DST) |
| 1057 | _len = reader.read('!H')[0] |
| 1058 | obj.nw_addr = reader.read('!L')[0] |
| 1059 | return obj |
| 1060 | |
| 1061 | def __eq__(self, other): |
| 1062 | if type(self) != type(other): return False |
| 1063 | if self.nw_addr != other.nw_addr: return False |
| 1064 | return True |
| 1065 | |
| 1066 | def __ne__(self, other): |
| 1067 | return not self.__eq__(other) |
| 1068 | |
| 1069 | def show(self): |
| 1070 | import loxi.pp |
| 1071 | return loxi.pp.pp(self) |
| 1072 | |
| 1073 | def pretty_print(self, q): |
| 1074 | q.text("set_nw_dst {") |
| 1075 | with q.group(): |
| 1076 | with q.indent(2): |
| 1077 | q.breakable() |
| 1078 | q.text("nw_addr = "); |
| 1079 | q.text("%#x" % self.nw_addr) |
| 1080 | q.breakable() |
| 1081 | q.text('}') |
| 1082 | |
| 1083 | class set_nw_ecn(Action): |
| 1084 | type = const.OFPAT_SET_NW_ECN |
| 1085 | |
| 1086 | def __init__(self, nw_ecn=None): |
| 1087 | if nw_ecn != None: |
| 1088 | self.nw_ecn = nw_ecn |
| 1089 | else: |
| 1090 | self.nw_ecn = 0 |
| 1091 | return |
| 1092 | |
| 1093 | def pack(self): |
| 1094 | packed = [] |
| 1095 | packed.append(struct.pack("!H", self.type)) |
| 1096 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1097 | packed.append(struct.pack("!B", self.nw_ecn)) |
| 1098 | packed.append('\x00' * 3) |
| 1099 | length = sum([len(x) for x in packed]) |
| 1100 | packed[1] = struct.pack("!H", length) |
| 1101 | return ''.join(packed) |
| 1102 | |
| 1103 | @staticmethod |
| 1104 | def unpack(buf): |
| 1105 | obj = set_nw_ecn() |
| 1106 | if type(buf) == loxi.generic_util.OFReader: |
| 1107 | reader = buf |
| 1108 | else: |
| 1109 | reader = loxi.generic_util.OFReader(buf) |
| 1110 | _type = reader.read('!H')[0] |
| 1111 | assert(_type == const.OFPAT_SET_NW_ECN) |
| 1112 | _len = reader.read('!H')[0] |
| 1113 | obj.nw_ecn = reader.read('!B')[0] |
| 1114 | reader.skip(3) |
| 1115 | return obj |
| 1116 | |
| 1117 | def __eq__(self, other): |
| 1118 | if type(self) != type(other): return False |
| 1119 | if self.nw_ecn != other.nw_ecn: return False |
| 1120 | return True |
| 1121 | |
| 1122 | def __ne__(self, other): |
| 1123 | return not self.__eq__(other) |
| 1124 | |
| 1125 | def show(self): |
| 1126 | import loxi.pp |
| 1127 | return loxi.pp.pp(self) |
| 1128 | |
| 1129 | def pretty_print(self, q): |
| 1130 | q.text("set_nw_ecn {") |
| 1131 | with q.group(): |
| 1132 | with q.indent(2): |
| 1133 | q.breakable() |
| 1134 | q.text("nw_ecn = "); |
| 1135 | q.text("%#x" % self.nw_ecn) |
| 1136 | q.breakable() |
| 1137 | q.text('}') |
| 1138 | |
| 1139 | class set_nw_src(Action): |
| 1140 | type = const.OFPAT_SET_NW_SRC |
| 1141 | |
| 1142 | def __init__(self, nw_addr=None): |
| 1143 | if nw_addr != None: |
| 1144 | self.nw_addr = nw_addr |
| 1145 | else: |
| 1146 | self.nw_addr = 0 |
| 1147 | return |
| 1148 | |
| 1149 | def pack(self): |
| 1150 | packed = [] |
| 1151 | packed.append(struct.pack("!H", self.type)) |
| 1152 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1153 | packed.append(struct.pack("!L", self.nw_addr)) |
| 1154 | length = sum([len(x) for x in packed]) |
| 1155 | packed[1] = struct.pack("!H", length) |
| 1156 | return ''.join(packed) |
| 1157 | |
| 1158 | @staticmethod |
| 1159 | def unpack(buf): |
| 1160 | obj = set_nw_src() |
| 1161 | if type(buf) == loxi.generic_util.OFReader: |
| 1162 | reader = buf |
| 1163 | else: |
| 1164 | reader = loxi.generic_util.OFReader(buf) |
| 1165 | _type = reader.read('!H')[0] |
| 1166 | assert(_type == const.OFPAT_SET_NW_SRC) |
| 1167 | _len = reader.read('!H')[0] |
| 1168 | obj.nw_addr = reader.read('!L')[0] |
| 1169 | return obj |
| 1170 | |
| 1171 | def __eq__(self, other): |
| 1172 | if type(self) != type(other): return False |
| 1173 | if self.nw_addr != other.nw_addr: return False |
| 1174 | return True |
| 1175 | |
| 1176 | def __ne__(self, other): |
| 1177 | return not self.__eq__(other) |
| 1178 | |
| 1179 | def show(self): |
| 1180 | import loxi.pp |
| 1181 | return loxi.pp.pp(self) |
| 1182 | |
| 1183 | def pretty_print(self, q): |
| 1184 | q.text("set_nw_src {") |
| 1185 | with q.group(): |
| 1186 | with q.indent(2): |
| 1187 | q.breakable() |
| 1188 | q.text("nw_addr = "); |
| 1189 | q.text("%#x" % self.nw_addr) |
| 1190 | q.breakable() |
| 1191 | q.text('}') |
| 1192 | |
| 1193 | class set_nw_tos(Action): |
| 1194 | type = const.OFPAT_SET_NW_TOS |
| 1195 | |
| 1196 | def __init__(self, nw_tos=None): |
| 1197 | if nw_tos != None: |
| 1198 | self.nw_tos = nw_tos |
| 1199 | else: |
| 1200 | self.nw_tos = 0 |
| 1201 | return |
| 1202 | |
| 1203 | def pack(self): |
| 1204 | packed = [] |
| 1205 | packed.append(struct.pack("!H", self.type)) |
| 1206 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1207 | packed.append(struct.pack("!B", self.nw_tos)) |
| 1208 | packed.append('\x00' * 3) |
| 1209 | length = sum([len(x) for x in packed]) |
| 1210 | packed[1] = struct.pack("!H", length) |
| 1211 | return ''.join(packed) |
| 1212 | |
| 1213 | @staticmethod |
| 1214 | def unpack(buf): |
| 1215 | obj = set_nw_tos() |
| 1216 | if type(buf) == loxi.generic_util.OFReader: |
| 1217 | reader = buf |
| 1218 | else: |
| 1219 | reader = loxi.generic_util.OFReader(buf) |
| 1220 | _type = reader.read('!H')[0] |
| 1221 | assert(_type == const.OFPAT_SET_NW_TOS) |
| 1222 | _len = reader.read('!H')[0] |
| 1223 | obj.nw_tos = reader.read('!B')[0] |
| 1224 | reader.skip(3) |
| 1225 | return obj |
| 1226 | |
| 1227 | def __eq__(self, other): |
| 1228 | if type(self) != type(other): return False |
| 1229 | if self.nw_tos != other.nw_tos: return False |
| 1230 | return True |
| 1231 | |
| 1232 | def __ne__(self, other): |
| 1233 | return not self.__eq__(other) |
| 1234 | |
| 1235 | def show(self): |
| 1236 | import loxi.pp |
| 1237 | return loxi.pp.pp(self) |
| 1238 | |
| 1239 | def pretty_print(self, q): |
| 1240 | q.text("set_nw_tos {") |
| 1241 | with q.group(): |
| 1242 | with q.indent(2): |
| 1243 | q.breakable() |
| 1244 | q.text("nw_tos = "); |
| 1245 | q.text("%#x" % self.nw_tos) |
| 1246 | q.breakable() |
| 1247 | q.text('}') |
| 1248 | |
| 1249 | class set_nw_ttl(Action): |
| 1250 | type = const.OFPAT_SET_NW_TTL |
| 1251 | |
| 1252 | def __init__(self, nw_ttl=None): |
| 1253 | if nw_ttl != None: |
| 1254 | self.nw_ttl = nw_ttl |
| 1255 | else: |
| 1256 | self.nw_ttl = 0 |
| 1257 | return |
| 1258 | |
| 1259 | def pack(self): |
| 1260 | packed = [] |
| 1261 | packed.append(struct.pack("!H", self.type)) |
| 1262 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1263 | packed.append(struct.pack("!B", self.nw_ttl)) |
| 1264 | packed.append('\x00' * 3) |
| 1265 | length = sum([len(x) for x in packed]) |
| 1266 | packed[1] = struct.pack("!H", length) |
| 1267 | return ''.join(packed) |
| 1268 | |
| 1269 | @staticmethod |
| 1270 | def unpack(buf): |
| 1271 | obj = set_nw_ttl() |
| 1272 | if type(buf) == loxi.generic_util.OFReader: |
| 1273 | reader = buf |
| 1274 | else: |
| 1275 | reader = loxi.generic_util.OFReader(buf) |
| 1276 | _type = reader.read('!H')[0] |
| 1277 | assert(_type == const.OFPAT_SET_NW_TTL) |
| 1278 | _len = reader.read('!H')[0] |
| 1279 | obj.nw_ttl = reader.read('!B')[0] |
| 1280 | reader.skip(3) |
| 1281 | return obj |
| 1282 | |
| 1283 | def __eq__(self, other): |
| 1284 | if type(self) != type(other): return False |
| 1285 | if self.nw_ttl != other.nw_ttl: return False |
| 1286 | return True |
| 1287 | |
| 1288 | def __ne__(self, other): |
| 1289 | return not self.__eq__(other) |
| 1290 | |
| 1291 | def show(self): |
| 1292 | import loxi.pp |
| 1293 | return loxi.pp.pp(self) |
| 1294 | |
| 1295 | def pretty_print(self, q): |
| 1296 | q.text("set_nw_ttl {") |
| 1297 | with q.group(): |
| 1298 | with q.indent(2): |
| 1299 | q.breakable() |
| 1300 | q.text("nw_ttl = "); |
| 1301 | q.text("%#x" % self.nw_ttl) |
| 1302 | q.breakable() |
| 1303 | q.text('}') |
| 1304 | |
| 1305 | class set_queue(Action): |
| 1306 | type = const.OFPAT_SET_QUEUE |
| 1307 | |
| 1308 | def __init__(self, queue_id=None): |
| 1309 | if queue_id != None: |
| 1310 | self.queue_id = queue_id |
| 1311 | else: |
| 1312 | self.queue_id = 0 |
| 1313 | return |
| 1314 | |
| 1315 | def pack(self): |
| 1316 | packed = [] |
| 1317 | packed.append(struct.pack("!H", self.type)) |
| 1318 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1319 | packed.append(struct.pack("!L", self.queue_id)) |
| 1320 | length = sum([len(x) for x in packed]) |
| 1321 | packed[1] = struct.pack("!H", length) |
| 1322 | return ''.join(packed) |
| 1323 | |
| 1324 | @staticmethod |
| 1325 | def unpack(buf): |
| 1326 | obj = set_queue() |
| 1327 | if type(buf) == loxi.generic_util.OFReader: |
| 1328 | reader = buf |
| 1329 | else: |
| 1330 | reader = loxi.generic_util.OFReader(buf) |
| 1331 | _type = reader.read('!H')[0] |
| 1332 | assert(_type == const.OFPAT_SET_QUEUE) |
| 1333 | _len = reader.read('!H')[0] |
| 1334 | obj.queue_id = reader.read('!L')[0] |
| 1335 | return obj |
| 1336 | |
| 1337 | def __eq__(self, other): |
| 1338 | if type(self) != type(other): return False |
| 1339 | if self.queue_id != other.queue_id: return False |
| 1340 | return True |
| 1341 | |
| 1342 | def __ne__(self, other): |
| 1343 | return not self.__eq__(other) |
| 1344 | |
| 1345 | def show(self): |
| 1346 | import loxi.pp |
| 1347 | return loxi.pp.pp(self) |
| 1348 | |
| 1349 | def pretty_print(self, q): |
| 1350 | q.text("set_queue {") |
| 1351 | with q.group(): |
| 1352 | with q.indent(2): |
| 1353 | q.breakable() |
| 1354 | q.text("queue_id = "); |
| 1355 | q.text("%#x" % self.queue_id) |
| 1356 | q.breakable() |
| 1357 | q.text('}') |
| 1358 | |
| 1359 | class set_tp_dst(Action): |
| 1360 | type = const.OFPAT_SET_TP_DST |
| 1361 | |
| 1362 | def __init__(self, tp_port=None): |
| 1363 | if tp_port != None: |
| 1364 | self.tp_port = tp_port |
| 1365 | else: |
| 1366 | self.tp_port = 0 |
| 1367 | return |
| 1368 | |
| 1369 | def pack(self): |
| 1370 | packed = [] |
| 1371 | packed.append(struct.pack("!H", self.type)) |
| 1372 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1373 | packed.append(struct.pack("!H", self.tp_port)) |
| 1374 | packed.append('\x00' * 2) |
| 1375 | length = sum([len(x) for x in packed]) |
| 1376 | packed[1] = struct.pack("!H", length) |
| 1377 | return ''.join(packed) |
| 1378 | |
| 1379 | @staticmethod |
| 1380 | def unpack(buf): |
| 1381 | obj = set_tp_dst() |
| 1382 | if type(buf) == loxi.generic_util.OFReader: |
| 1383 | reader = buf |
| 1384 | else: |
| 1385 | reader = loxi.generic_util.OFReader(buf) |
| 1386 | _type = reader.read('!H')[0] |
| 1387 | assert(_type == const.OFPAT_SET_TP_DST) |
| 1388 | _len = reader.read('!H')[0] |
| 1389 | obj.tp_port = reader.read('!H')[0] |
| 1390 | reader.skip(2) |
| 1391 | return obj |
| 1392 | |
| 1393 | def __eq__(self, other): |
| 1394 | if type(self) != type(other): return False |
| 1395 | if self.tp_port != other.tp_port: return False |
| 1396 | return True |
| 1397 | |
| 1398 | def __ne__(self, other): |
| 1399 | return not self.__eq__(other) |
| 1400 | |
| 1401 | def show(self): |
| 1402 | import loxi.pp |
| 1403 | return loxi.pp.pp(self) |
| 1404 | |
| 1405 | def pretty_print(self, q): |
| 1406 | q.text("set_tp_dst {") |
| 1407 | with q.group(): |
| 1408 | with q.indent(2): |
| 1409 | q.breakable() |
| 1410 | q.text("tp_port = "); |
| 1411 | q.text("%#x" % self.tp_port) |
| 1412 | q.breakable() |
| 1413 | q.text('}') |
| 1414 | |
| 1415 | class set_tp_src(Action): |
| 1416 | type = const.OFPAT_SET_TP_SRC |
| 1417 | |
| 1418 | def __init__(self, tp_port=None): |
| 1419 | if tp_port != None: |
| 1420 | self.tp_port = tp_port |
| 1421 | else: |
| 1422 | self.tp_port = 0 |
| 1423 | return |
| 1424 | |
| 1425 | def pack(self): |
| 1426 | packed = [] |
| 1427 | packed.append(struct.pack("!H", self.type)) |
| 1428 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1429 | packed.append(struct.pack("!H", self.tp_port)) |
| 1430 | packed.append('\x00' * 2) |
| 1431 | length = sum([len(x) for x in packed]) |
| 1432 | packed[1] = struct.pack("!H", length) |
| 1433 | return ''.join(packed) |
| 1434 | |
| 1435 | @staticmethod |
| 1436 | def unpack(buf): |
| 1437 | obj = set_tp_src() |
| 1438 | if type(buf) == loxi.generic_util.OFReader: |
| 1439 | reader = buf |
| 1440 | else: |
| 1441 | reader = loxi.generic_util.OFReader(buf) |
| 1442 | _type = reader.read('!H')[0] |
| 1443 | assert(_type == const.OFPAT_SET_TP_SRC) |
| 1444 | _len = reader.read('!H')[0] |
| 1445 | obj.tp_port = reader.read('!H')[0] |
| 1446 | reader.skip(2) |
| 1447 | return obj |
| 1448 | |
| 1449 | def __eq__(self, other): |
| 1450 | if type(self) != type(other): return False |
| 1451 | if self.tp_port != other.tp_port: return False |
| 1452 | return True |
| 1453 | |
| 1454 | def __ne__(self, other): |
| 1455 | return not self.__eq__(other) |
| 1456 | |
| 1457 | def show(self): |
| 1458 | import loxi.pp |
| 1459 | return loxi.pp.pp(self) |
| 1460 | |
| 1461 | def pretty_print(self, q): |
| 1462 | q.text("set_tp_src {") |
| 1463 | with q.group(): |
| 1464 | with q.indent(2): |
| 1465 | q.breakable() |
| 1466 | q.text("tp_port = "); |
| 1467 | q.text("%#x" % self.tp_port) |
| 1468 | q.breakable() |
| 1469 | q.text('}') |
| 1470 | |
| 1471 | class set_vlan_pcp(Action): |
| 1472 | type = const.OFPAT_SET_VLAN_PCP |
| 1473 | |
| 1474 | def __init__(self, vlan_pcp=None): |
| 1475 | if vlan_pcp != None: |
| 1476 | self.vlan_pcp = vlan_pcp |
| 1477 | else: |
| 1478 | self.vlan_pcp = 0 |
| 1479 | return |
| 1480 | |
| 1481 | def pack(self): |
| 1482 | packed = [] |
| 1483 | packed.append(struct.pack("!H", self.type)) |
| 1484 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1485 | packed.append(struct.pack("!B", self.vlan_pcp)) |
| 1486 | packed.append('\x00' * 3) |
| 1487 | length = sum([len(x) for x in packed]) |
| 1488 | packed[1] = struct.pack("!H", length) |
| 1489 | return ''.join(packed) |
| 1490 | |
| 1491 | @staticmethod |
| 1492 | def unpack(buf): |
| 1493 | obj = set_vlan_pcp() |
| 1494 | if type(buf) == loxi.generic_util.OFReader: |
| 1495 | reader = buf |
| 1496 | else: |
| 1497 | reader = loxi.generic_util.OFReader(buf) |
| 1498 | _type = reader.read('!H')[0] |
| 1499 | assert(_type == const.OFPAT_SET_VLAN_PCP) |
| 1500 | _len = reader.read('!H')[0] |
| 1501 | obj.vlan_pcp = reader.read('!B')[0] |
| 1502 | reader.skip(3) |
| 1503 | return obj |
| 1504 | |
| 1505 | def __eq__(self, other): |
| 1506 | if type(self) != type(other): return False |
| 1507 | if self.vlan_pcp != other.vlan_pcp: return False |
| 1508 | return True |
| 1509 | |
| 1510 | def __ne__(self, other): |
| 1511 | return not self.__eq__(other) |
| 1512 | |
| 1513 | def show(self): |
| 1514 | import loxi.pp |
| 1515 | return loxi.pp.pp(self) |
| 1516 | |
| 1517 | def pretty_print(self, q): |
| 1518 | q.text("set_vlan_pcp {") |
| 1519 | with q.group(): |
| 1520 | with q.indent(2): |
| 1521 | q.breakable() |
| 1522 | q.text("vlan_pcp = "); |
| 1523 | q.text("%#x" % self.vlan_pcp) |
| 1524 | q.breakable() |
| 1525 | q.text('}') |
| 1526 | |
| 1527 | class set_vlan_vid(Action): |
| 1528 | type = const.OFPAT_SET_VLAN_VID |
| 1529 | |
| 1530 | def __init__(self, vlan_vid=None): |
| 1531 | if vlan_vid != None: |
| 1532 | self.vlan_vid = vlan_vid |
| 1533 | else: |
| 1534 | self.vlan_vid = 0 |
| 1535 | return |
| 1536 | |
| 1537 | def pack(self): |
| 1538 | packed = [] |
| 1539 | packed.append(struct.pack("!H", self.type)) |
| 1540 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1541 | packed.append(struct.pack("!H", self.vlan_vid)) |
| 1542 | packed.append('\x00' * 2) |
| 1543 | length = sum([len(x) for x in packed]) |
| 1544 | packed[1] = struct.pack("!H", length) |
| 1545 | return ''.join(packed) |
| 1546 | |
| 1547 | @staticmethod |
| 1548 | def unpack(buf): |
| 1549 | obj = set_vlan_vid() |
| 1550 | if type(buf) == loxi.generic_util.OFReader: |
| 1551 | reader = buf |
| 1552 | else: |
| 1553 | reader = loxi.generic_util.OFReader(buf) |
| 1554 | _type = reader.read('!H')[0] |
| 1555 | assert(_type == const.OFPAT_SET_VLAN_VID) |
| 1556 | _len = reader.read('!H')[0] |
| 1557 | obj.vlan_vid = reader.read('!H')[0] |
| 1558 | reader.skip(2) |
| 1559 | return obj |
| 1560 | |
| 1561 | def __eq__(self, other): |
| 1562 | if type(self) != type(other): return False |
| 1563 | if self.vlan_vid != other.vlan_vid: return False |
| 1564 | return True |
| 1565 | |
| 1566 | def __ne__(self, other): |
| 1567 | return not self.__eq__(other) |
| 1568 | |
| 1569 | def show(self): |
| 1570 | import loxi.pp |
| 1571 | return loxi.pp.pp(self) |
| 1572 | |
| 1573 | def pretty_print(self, q): |
| 1574 | q.text("set_vlan_vid {") |
| 1575 | with q.group(): |
| 1576 | with q.indent(2): |
| 1577 | q.breakable() |
| 1578 | q.text("vlan_vid = "); |
| 1579 | q.text("%#x" % self.vlan_vid) |
| 1580 | q.breakable() |
| 1581 | q.text('}') |
| 1582 | |
| 1583 | |
| 1584 | def parse_experimenter(reader): |
| 1585 | |
| 1586 | experimenter, = reader.peek("!4xL") |
| 1587 | if experimenter == 0x005c16c7: # Big Switch Networks |
| 1588 | subtype, = reader.peek("!8xL") |
| 1589 | elif experimenter == 0x00002320: # Nicira |
| 1590 | subtype, = reader.peek("!8xH") |
| 1591 | else: |
| 1592 | raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter) |
| 1593 | |
| 1594 | if subtype in experimenter_parsers[experimenter]: |
| 1595 | return experimenter_parsers[experimenter][subtype](reader) |
| 1596 | else: |
| 1597 | raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype) |
| 1598 | |
| 1599 | parsers = { |
| 1600 | const.OFPAT_COPY_TTL_IN : copy_ttl_in.unpack, |
| 1601 | const.OFPAT_COPY_TTL_OUT : copy_ttl_out.unpack, |
| 1602 | const.OFPAT_DEC_MPLS_TTL : dec_mpls_ttl.unpack, |
| 1603 | const.OFPAT_DEC_NW_TTL : dec_nw_ttl.unpack, |
| 1604 | const.OFPAT_EXPERIMENTER : parse_experimenter, |
| 1605 | const.OFPAT_GROUP : group.unpack, |
| 1606 | const.OFPAT_OUTPUT : output.unpack, |
| 1607 | const.OFPAT_POP_MPLS : pop_mpls.unpack, |
| 1608 | const.OFPAT_POP_VLAN : pop_vlan.unpack, |
| 1609 | const.OFPAT_PUSH_MPLS : push_mpls.unpack, |
| 1610 | const.OFPAT_PUSH_VLAN : push_vlan.unpack, |
| 1611 | const.OFPAT_SET_DL_DST : set_dl_dst.unpack, |
| 1612 | const.OFPAT_SET_DL_SRC : set_dl_src.unpack, |
| 1613 | const.OFPAT_SET_MPLS_LABEL : set_mpls_label.unpack, |
| 1614 | const.OFPAT_SET_MPLS_TC : set_mpls_tc.unpack, |
| 1615 | const.OFPAT_SET_MPLS_TTL : set_mpls_ttl.unpack, |
| 1616 | const.OFPAT_SET_NW_DST : set_nw_dst.unpack, |
| 1617 | const.OFPAT_SET_NW_ECN : set_nw_ecn.unpack, |
| 1618 | const.OFPAT_SET_NW_SRC : set_nw_src.unpack, |
| 1619 | const.OFPAT_SET_NW_TOS : set_nw_tos.unpack, |
| 1620 | const.OFPAT_SET_NW_TTL : set_nw_ttl.unpack, |
| 1621 | const.OFPAT_SET_QUEUE : set_queue.unpack, |
| 1622 | const.OFPAT_SET_TP_DST : set_tp_dst.unpack, |
| 1623 | const.OFPAT_SET_TP_SRC : set_tp_src.unpack, |
| 1624 | const.OFPAT_SET_VLAN_PCP : set_vlan_pcp.unpack, |
| 1625 | const.OFPAT_SET_VLAN_VID : set_vlan_vid.unpack, |
| 1626 | } |
| 1627 | |
| 1628 | experimenter_parsers = { |
| 1629 | } |