Rich Lane | ca3da27 | 2013-05-05 09:07:33 -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 | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 5 | |
| 6 | # Automatically generated by LOXI from template instruction.py |
| 7 | # Do not modify |
| 8 | |
| 9 | import struct |
| 10 | import action |
| 11 | import const |
| 12 | import util |
| 13 | import loxi.generic_util |
| 14 | import loxi |
| 15 | |
| 16 | def unpack_list(reader): |
| 17 | def deserializer(reader, typ): |
| 18 | parser = parsers.get(typ) |
| 19 | if not parser: raise loxi.ProtocolError("unknown instruction type %d" % typ) |
| 20 | return parser(reader) |
| 21 | return loxi.generic_util.unpack_list_tlv16(reader, deserializer) |
| 22 | |
| 23 | class Instruction(object): |
| 24 | type = None # override in subclass |
| 25 | pass |
| 26 | |
| 27 | class apply_actions(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 28 | type = 4 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 29 | |
| 30 | def __init__(self, actions=None): |
| 31 | if actions != None: |
| 32 | self.actions = actions |
| 33 | else: |
| 34 | self.actions = [] |
| 35 | return |
| 36 | |
| 37 | def pack(self): |
| 38 | packed = [] |
| 39 | packed.append(struct.pack("!H", self.type)) |
| 40 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 41 | packed.append('\x00' * 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 42 | packed.append(util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 43 | length = sum([len(x) for x in packed]) |
| 44 | packed[1] = struct.pack("!H", length) |
| 45 | return ''.join(packed) |
| 46 | |
| 47 | @staticmethod |
| 48 | def unpack(buf): |
| 49 | obj = apply_actions() |
| 50 | if type(buf) == loxi.generic_util.OFReader: |
| 51 | reader = buf |
| 52 | else: |
| 53 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 54 | _type = reader.read("!H")[0] |
| 55 | assert(_type == 4) |
| 56 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 57 | reader.skip(4) |
| 58 | obj.actions = action.unpack_list(reader) |
| 59 | return obj |
| 60 | |
| 61 | def __eq__(self, other): |
| 62 | if type(self) != type(other): return False |
| 63 | if self.actions != other.actions: return False |
| 64 | return True |
| 65 | |
| 66 | def __ne__(self, other): |
| 67 | return not self.__eq__(other) |
| 68 | |
| 69 | def show(self): |
| 70 | import loxi.pp |
| 71 | return loxi.pp.pp(self) |
| 72 | |
| 73 | def pretty_print(self, q): |
| 74 | q.text("apply_actions {") |
| 75 | with q.group(): |
| 76 | with q.indent(2): |
| 77 | q.breakable() |
| 78 | q.text("actions = "); |
| 79 | q.pp(self.actions) |
| 80 | q.breakable() |
| 81 | q.text('}') |
| 82 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 83 | class bsn_disable_src_mac_check(Instruction): |
| 84 | type = 65535 |
| 85 | experimenter = 6035143 |
| 86 | subtype = 0 |
| 87 | |
| 88 | def __init__(self): |
| 89 | return |
| 90 | |
| 91 | def pack(self): |
| 92 | packed = [] |
| 93 | packed.append(struct.pack("!H", self.type)) |
| 94 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 95 | packed.append(struct.pack("!L", self.experimenter)) |
| 96 | packed.append(struct.pack("!L", self.subtype)) |
| 97 | packed.append('\x00' * 4) |
| 98 | length = sum([len(x) for x in packed]) |
| 99 | packed[1] = struct.pack("!H", length) |
| 100 | return ''.join(packed) |
| 101 | |
| 102 | @staticmethod |
| 103 | def unpack(buf): |
| 104 | obj = bsn_disable_src_mac_check() |
| 105 | if type(buf) == loxi.generic_util.OFReader: |
| 106 | reader = buf |
| 107 | else: |
| 108 | reader = loxi.generic_util.OFReader(buf) |
| 109 | _type = reader.read("!H")[0] |
| 110 | assert(_type == 65535) |
| 111 | _len = reader.read("!H")[0] |
| 112 | _experimenter = reader.read("!L")[0] |
| 113 | assert(_experimenter == 6035143) |
| 114 | _subtype = reader.read("!L")[0] |
| 115 | assert(_subtype == 0) |
| 116 | reader.skip(4) |
| 117 | return obj |
| 118 | |
| 119 | def __eq__(self, other): |
| 120 | if type(self) != type(other): return False |
| 121 | return True |
| 122 | |
| 123 | def __ne__(self, other): |
| 124 | return not self.__eq__(other) |
| 125 | |
| 126 | def show(self): |
| 127 | import loxi.pp |
| 128 | return loxi.pp.pp(self) |
| 129 | |
| 130 | def pretty_print(self, q): |
| 131 | q.text("bsn_disable_src_mac_check {") |
| 132 | with q.group(): |
| 133 | with q.indent(2): |
| 134 | q.breakable() |
| 135 | q.breakable() |
| 136 | q.text('}') |
| 137 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 138 | class clear_actions(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 139 | type = 5 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 140 | |
| 141 | def __init__(self): |
| 142 | return |
| 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('\x00' * 4) |
| 149 | length = sum([len(x) for x in packed]) |
| 150 | packed[1] = struct.pack("!H", length) |
| 151 | return ''.join(packed) |
| 152 | |
| 153 | @staticmethod |
| 154 | def unpack(buf): |
| 155 | obj = clear_actions() |
| 156 | if type(buf) == loxi.generic_util.OFReader: |
| 157 | reader = buf |
| 158 | else: |
| 159 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 160 | _type = reader.read("!H")[0] |
| 161 | assert(_type == 5) |
| 162 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 163 | reader.skip(4) |
| 164 | return obj |
| 165 | |
| 166 | def __eq__(self, other): |
| 167 | if type(self) != type(other): return False |
| 168 | return True |
| 169 | |
| 170 | def __ne__(self, other): |
| 171 | return not self.__eq__(other) |
| 172 | |
| 173 | def show(self): |
| 174 | import loxi.pp |
| 175 | return loxi.pp.pp(self) |
| 176 | |
| 177 | def pretty_print(self, q): |
| 178 | q.text("clear_actions {") |
| 179 | with q.group(): |
| 180 | with q.indent(2): |
| 181 | q.breakable() |
| 182 | q.breakable() |
| 183 | q.text('}') |
| 184 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 185 | class goto_table(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 186 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 187 | |
| 188 | def __init__(self, table_id=None): |
| 189 | if table_id != None: |
| 190 | self.table_id = table_id |
| 191 | else: |
| 192 | self.table_id = 0 |
| 193 | return |
| 194 | |
| 195 | def pack(self): |
| 196 | packed = [] |
| 197 | packed.append(struct.pack("!H", self.type)) |
| 198 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 199 | packed.append(struct.pack("!B", self.table_id)) |
| 200 | packed.append('\x00' * 3) |
| 201 | length = sum([len(x) for x in packed]) |
| 202 | packed[1] = struct.pack("!H", length) |
| 203 | return ''.join(packed) |
| 204 | |
| 205 | @staticmethod |
| 206 | def unpack(buf): |
| 207 | obj = goto_table() |
| 208 | if type(buf) == loxi.generic_util.OFReader: |
| 209 | reader = buf |
| 210 | else: |
| 211 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 212 | _type = reader.read("!H")[0] |
| 213 | assert(_type == 1) |
| 214 | _len = reader.read("!H")[0] |
| 215 | obj.table_id = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 216 | reader.skip(3) |
| 217 | return obj |
| 218 | |
| 219 | def __eq__(self, other): |
| 220 | if type(self) != type(other): return False |
| 221 | if self.table_id != other.table_id: return False |
| 222 | return True |
| 223 | |
| 224 | def __ne__(self, other): |
| 225 | return not self.__eq__(other) |
| 226 | |
| 227 | def show(self): |
| 228 | import loxi.pp |
| 229 | return loxi.pp.pp(self) |
| 230 | |
| 231 | def pretty_print(self, q): |
| 232 | q.text("goto_table {") |
| 233 | with q.group(): |
| 234 | with q.indent(2): |
| 235 | q.breakable() |
| 236 | q.text("table_id = "); |
| 237 | q.text("%#x" % self.table_id) |
| 238 | q.breakable() |
| 239 | q.text('}') |
| 240 | |
| 241 | class meter(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 242 | type = 6 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 243 | |
| 244 | def __init__(self, meter_id=None): |
| 245 | if meter_id != None: |
| 246 | self.meter_id = meter_id |
| 247 | else: |
| 248 | self.meter_id = 0 |
| 249 | return |
| 250 | |
| 251 | def pack(self): |
| 252 | packed = [] |
| 253 | packed.append(struct.pack("!H", self.type)) |
| 254 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 255 | packed.append(struct.pack("!L", self.meter_id)) |
| 256 | length = sum([len(x) for x in packed]) |
| 257 | packed[1] = struct.pack("!H", length) |
| 258 | return ''.join(packed) |
| 259 | |
| 260 | @staticmethod |
| 261 | def unpack(buf): |
| 262 | obj = meter() |
| 263 | if type(buf) == loxi.generic_util.OFReader: |
| 264 | reader = buf |
| 265 | else: |
| 266 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 267 | _type = reader.read("!H")[0] |
| 268 | assert(_type == 6) |
| 269 | _len = reader.read("!H")[0] |
| 270 | obj.meter_id = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 271 | return obj |
| 272 | |
| 273 | def __eq__(self, other): |
| 274 | if type(self) != type(other): return False |
| 275 | if self.meter_id != other.meter_id: return False |
| 276 | return True |
| 277 | |
| 278 | def __ne__(self, other): |
| 279 | return not self.__eq__(other) |
| 280 | |
| 281 | def show(self): |
| 282 | import loxi.pp |
| 283 | return loxi.pp.pp(self) |
| 284 | |
| 285 | def pretty_print(self, q): |
| 286 | q.text("meter {") |
| 287 | with q.group(): |
| 288 | with q.indent(2): |
| 289 | q.breakable() |
| 290 | q.text("meter_id = "); |
| 291 | q.text("%#x" % self.meter_id) |
| 292 | q.breakable() |
| 293 | q.text('}') |
| 294 | |
| 295 | class write_actions(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 296 | type = 3 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 297 | |
| 298 | def __init__(self, actions=None): |
| 299 | if actions != None: |
| 300 | self.actions = actions |
| 301 | else: |
| 302 | self.actions = [] |
| 303 | return |
| 304 | |
| 305 | def pack(self): |
| 306 | packed = [] |
| 307 | packed.append(struct.pack("!H", self.type)) |
| 308 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 309 | packed.append('\x00' * 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 310 | packed.append(util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 311 | length = sum([len(x) for x in packed]) |
| 312 | packed[1] = struct.pack("!H", length) |
| 313 | return ''.join(packed) |
| 314 | |
| 315 | @staticmethod |
| 316 | def unpack(buf): |
| 317 | obj = write_actions() |
| 318 | if type(buf) == loxi.generic_util.OFReader: |
| 319 | reader = buf |
| 320 | else: |
| 321 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 322 | _type = reader.read("!H")[0] |
| 323 | assert(_type == 3) |
| 324 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 325 | reader.skip(4) |
| 326 | obj.actions = action.unpack_list(reader) |
| 327 | return obj |
| 328 | |
| 329 | def __eq__(self, other): |
| 330 | if type(self) != type(other): return False |
| 331 | if self.actions != other.actions: return False |
| 332 | return True |
| 333 | |
| 334 | def __ne__(self, other): |
| 335 | return not self.__eq__(other) |
| 336 | |
| 337 | def show(self): |
| 338 | import loxi.pp |
| 339 | return loxi.pp.pp(self) |
| 340 | |
| 341 | def pretty_print(self, q): |
| 342 | q.text("write_actions {") |
| 343 | with q.group(): |
| 344 | with q.indent(2): |
| 345 | q.breakable() |
| 346 | q.text("actions = "); |
| 347 | q.pp(self.actions) |
| 348 | q.breakable() |
| 349 | q.text('}') |
| 350 | |
| 351 | class write_metadata(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 352 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 353 | |
| 354 | def __init__(self, metadata=None, metadata_mask=None): |
| 355 | if metadata != None: |
| 356 | self.metadata = metadata |
| 357 | else: |
| 358 | self.metadata = 0 |
| 359 | if metadata_mask != None: |
| 360 | self.metadata_mask = metadata_mask |
| 361 | else: |
| 362 | self.metadata_mask = 0 |
| 363 | return |
| 364 | |
| 365 | def pack(self): |
| 366 | packed = [] |
| 367 | packed.append(struct.pack("!H", self.type)) |
| 368 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 369 | packed.append('\x00' * 4) |
| 370 | packed.append(struct.pack("!Q", self.metadata)) |
| 371 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 372 | length = sum([len(x) for x in packed]) |
| 373 | packed[1] = struct.pack("!H", length) |
| 374 | return ''.join(packed) |
| 375 | |
| 376 | @staticmethod |
| 377 | def unpack(buf): |
| 378 | obj = write_metadata() |
| 379 | if type(buf) == loxi.generic_util.OFReader: |
| 380 | reader = buf |
| 381 | else: |
| 382 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 383 | _type = reader.read("!H")[0] |
| 384 | assert(_type == 2) |
| 385 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 386 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 387 | obj.metadata = reader.read("!Q")[0] |
| 388 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 389 | return obj |
| 390 | |
| 391 | def __eq__(self, other): |
| 392 | if type(self) != type(other): return False |
| 393 | if self.metadata != other.metadata: return False |
| 394 | if self.metadata_mask != other.metadata_mask: 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("write_metadata {") |
| 406 | with q.group(): |
| 407 | with q.indent(2): |
| 408 | q.breakable() |
| 409 | q.text("metadata = "); |
| 410 | q.text("%#x" % self.metadata) |
| 411 | q.text(","); q.breakable() |
| 412 | q.text("metadata_mask = "); |
| 413 | q.text("%#x" % self.metadata_mask) |
| 414 | q.breakable() |
| 415 | q.text('}') |
| 416 | |
| 417 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 418 | def parse_experimenter(reader): |
| 419 | experimenter, = reader.peek("!4xL") |
| 420 | if experimenter == 0x005c16c7: # Big Switch Networks |
| 421 | subtype, = reader.peek("!8xL") |
| 422 | else: |
| 423 | raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter) |
| 424 | |
| 425 | if subtype in experimenter_parsers[experimenter]: |
| 426 | return experimenter_parsers[experimenter][subtype](reader) |
| 427 | else: |
| 428 | raise loxi.ProtocolError("unexpected experimenter id %#x subtype %#x" % (experimenter, subtype)) |
| 429 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 430 | parsers = { |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 431 | const.OFPIT_GOTO_TABLE : goto_table.unpack, |
| 432 | const.OFPIT_WRITE_METADATA : write_metadata.unpack, |
| 433 | const.OFPIT_WRITE_ACTIONS : write_actions.unpack, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 434 | const.OFPIT_APPLY_ACTIONS : apply_actions.unpack, |
| 435 | const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 436 | const.OFPIT_METER : meter.unpack, |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 437 | const.OFPIT_EXPERIMENTER : parse_experimenter, |
| 438 | } |
| 439 | |
| 440 | experimenter_parsers = { |
| 441 | 6035143 : { |
| 442 | 0: bsn_disable_src_mac_check.unpack, |
| 443 | }, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 444 | } |