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