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