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. |
| 4 | |
| 5 | # Automatically generated by LOXI from template instruction.py |
| 6 | # Do not modify |
| 7 | |
| 8 | import struct |
| 9 | import action |
| 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 instruction type %d" % typ) |
| 19 | return parser(reader) |
| 20 | return loxi.generic_util.unpack_list_tlv16(reader, deserializer) |
| 21 | |
| 22 | class Instruction(object): |
| 23 | type = None # override in subclass |
| 24 | pass |
| 25 | |
| 26 | class apply_actions(Instruction): |
| 27 | type = const.OFPIT_APPLY_ACTIONS |
| 28 | |
| 29 | def __init__(self, actions=None): |
| 30 | if actions != None: |
| 31 | self.actions = actions |
| 32 | else: |
| 33 | self.actions = [] |
| 34 | return |
| 35 | |
| 36 | def pack(self): |
| 37 | packed = [] |
| 38 | packed.append(struct.pack("!H", self.type)) |
| 39 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 40 | packed.append('\x00' * 4) |
| 41 | packed.append("".join([x.pack() for x in self.actions])) |
| 42 | length = sum([len(x) for x in packed]) |
| 43 | packed[1] = struct.pack("!H", length) |
| 44 | return ''.join(packed) |
| 45 | |
| 46 | @staticmethod |
| 47 | def unpack(buf): |
| 48 | obj = apply_actions() |
| 49 | if type(buf) == loxi.generic_util.OFReader: |
| 50 | reader = buf |
| 51 | else: |
| 52 | reader = loxi.generic_util.OFReader(buf) |
| 53 | _type = reader.read('!H')[0] |
| 54 | assert(_type == const.OFPIT_APPLY_ACTIONS) |
| 55 | _len = reader.read('!H')[0] |
| 56 | reader.skip(4) |
| 57 | obj.actions = action.unpack_list(reader) |
| 58 | return obj |
| 59 | |
| 60 | def __eq__(self, other): |
| 61 | if type(self) != type(other): return False |
| 62 | if self.actions != other.actions: return False |
| 63 | return True |
| 64 | |
| 65 | def __ne__(self, other): |
| 66 | return not self.__eq__(other) |
| 67 | |
| 68 | def show(self): |
| 69 | import loxi.pp |
| 70 | return loxi.pp.pp(self) |
| 71 | |
| 72 | def pretty_print(self, q): |
| 73 | q.text("apply_actions {") |
| 74 | with q.group(): |
| 75 | with q.indent(2): |
| 76 | q.breakable() |
| 77 | q.text("actions = "); |
| 78 | q.pp(self.actions) |
| 79 | q.breakable() |
| 80 | q.text('}') |
| 81 | |
| 82 | class clear_actions(Instruction): |
| 83 | type = const.OFPIT_CLEAR_ACTIONS |
| 84 | |
| 85 | def __init__(self): |
| 86 | return |
| 87 | |
| 88 | def pack(self): |
| 89 | packed = [] |
| 90 | packed.append(struct.pack("!H", self.type)) |
| 91 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 92 | packed.append('\x00' * 4) |
| 93 | length = sum([len(x) for x in packed]) |
| 94 | packed[1] = struct.pack("!H", length) |
| 95 | return ''.join(packed) |
| 96 | |
| 97 | @staticmethod |
| 98 | def unpack(buf): |
| 99 | obj = clear_actions() |
| 100 | if type(buf) == loxi.generic_util.OFReader: |
| 101 | reader = buf |
| 102 | else: |
| 103 | reader = loxi.generic_util.OFReader(buf) |
| 104 | _type = reader.read('!H')[0] |
| 105 | assert(_type == const.OFPIT_CLEAR_ACTIONS) |
| 106 | _len = reader.read('!H')[0] |
| 107 | reader.skip(4) |
| 108 | return obj |
| 109 | |
| 110 | def __eq__(self, other): |
| 111 | if type(self) != type(other): return False |
| 112 | return True |
| 113 | |
| 114 | def __ne__(self, other): |
| 115 | return not self.__eq__(other) |
| 116 | |
| 117 | def show(self): |
| 118 | import loxi.pp |
| 119 | return loxi.pp.pp(self) |
| 120 | |
| 121 | def pretty_print(self, q): |
| 122 | q.text("clear_actions {") |
| 123 | with q.group(): |
| 124 | with q.indent(2): |
| 125 | q.breakable() |
| 126 | q.breakable() |
| 127 | q.text('}') |
| 128 | |
| 129 | class experimenter(Instruction): |
| 130 | type = const.OFPIT_EXPERIMENTER |
| 131 | |
| 132 | def __init__(self, experimenter=None, data=None): |
| 133 | if experimenter != None: |
| 134 | self.experimenter = experimenter |
| 135 | else: |
| 136 | self.experimenter = 0 |
| 137 | if data != None: |
| 138 | self.data = data |
| 139 | else: |
| 140 | self.data = "" |
| 141 | return |
| 142 | |
| 143 | def pack(self): |
| 144 | packed = [] |
| 145 | packed.append(struct.pack("!H", self.type)) |
| 146 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 147 | packed.append(struct.pack("!L", self.experimenter)) |
| 148 | packed.append(self.data) |
| 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 = experimenter() |
| 156 | if type(buf) == loxi.generic_util.OFReader: |
| 157 | reader = buf |
| 158 | else: |
| 159 | reader = loxi.generic_util.OFReader(buf) |
| 160 | _type = reader.read('!H')[0] |
| 161 | assert(_type == const.OFPIT_EXPERIMENTER) |
| 162 | _len = reader.read('!H')[0] |
| 163 | obj.experimenter = reader.read('!L')[0] |
| 164 | obj.data = str(reader.read_all()) |
| 165 | return obj |
| 166 | |
| 167 | def __eq__(self, other): |
| 168 | if type(self) != type(other): return False |
| 169 | if self.experimenter != other.experimenter: return False |
| 170 | if self.data != other.data: return False |
| 171 | return True |
| 172 | |
| 173 | def __ne__(self, other): |
| 174 | return not self.__eq__(other) |
| 175 | |
| 176 | def show(self): |
| 177 | import loxi.pp |
| 178 | return loxi.pp.pp(self) |
| 179 | |
| 180 | def pretty_print(self, q): |
| 181 | q.text("experimenter {") |
| 182 | with q.group(): |
| 183 | with q.indent(2): |
| 184 | q.breakable() |
| 185 | q.text("experimenter = "); |
| 186 | q.text("%#x" % self.experimenter) |
| 187 | q.text(","); q.breakable() |
| 188 | q.text("data = "); |
| 189 | q.pp(self.data) |
| 190 | q.breakable() |
| 191 | q.text('}') |
| 192 | |
| 193 | class goto_table(Instruction): |
| 194 | type = const.OFPIT_GOTO_TABLE |
| 195 | |
| 196 | def __init__(self, table_id=None): |
| 197 | if table_id != None: |
| 198 | self.table_id = table_id |
| 199 | else: |
| 200 | self.table_id = 0 |
| 201 | return |
| 202 | |
| 203 | def pack(self): |
| 204 | packed = [] |
| 205 | packed.append(struct.pack("!H", self.type)) |
| 206 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 207 | packed.append(struct.pack("!B", self.table_id)) |
| 208 | packed.append('\x00' * 3) |
| 209 | length = sum([len(x) for x in packed]) |
| 210 | packed[1] = struct.pack("!H", length) |
| 211 | return ''.join(packed) |
| 212 | |
| 213 | @staticmethod |
| 214 | def unpack(buf): |
| 215 | obj = goto_table() |
| 216 | if type(buf) == loxi.generic_util.OFReader: |
| 217 | reader = buf |
| 218 | else: |
| 219 | reader = loxi.generic_util.OFReader(buf) |
| 220 | _type = reader.read('!H')[0] |
| 221 | assert(_type == const.OFPIT_GOTO_TABLE) |
| 222 | _len = reader.read('!H')[0] |
| 223 | obj.table_id = reader.read('!B')[0] |
| 224 | reader.skip(3) |
| 225 | return obj |
| 226 | |
| 227 | def __eq__(self, other): |
| 228 | if type(self) != type(other): return False |
| 229 | if self.table_id != other.table_id: return False |
| 230 | return True |
| 231 | |
| 232 | def __ne__(self, other): |
| 233 | return not self.__eq__(other) |
| 234 | |
| 235 | def show(self): |
| 236 | import loxi.pp |
| 237 | return loxi.pp.pp(self) |
| 238 | |
| 239 | def pretty_print(self, q): |
| 240 | q.text("goto_table {") |
| 241 | with q.group(): |
| 242 | with q.indent(2): |
| 243 | q.breakable() |
| 244 | q.text("table_id = "); |
| 245 | q.text("%#x" % self.table_id) |
| 246 | q.breakable() |
| 247 | q.text('}') |
| 248 | |
| 249 | class write_actions(Instruction): |
| 250 | type = const.OFPIT_WRITE_ACTIONS |
| 251 | |
| 252 | def __init__(self, actions=None): |
| 253 | if actions != None: |
| 254 | self.actions = actions |
| 255 | else: |
| 256 | self.actions = [] |
| 257 | return |
| 258 | |
| 259 | def pack(self): |
| 260 | packed = [] |
| 261 | packed.append(struct.pack("!H", self.type)) |
| 262 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 263 | packed.append('\x00' * 4) |
| 264 | packed.append("".join([x.pack() for x in self.actions])) |
| 265 | length = sum([len(x) for x in packed]) |
| 266 | packed[1] = struct.pack("!H", length) |
| 267 | return ''.join(packed) |
| 268 | |
| 269 | @staticmethod |
| 270 | def unpack(buf): |
| 271 | obj = write_actions() |
| 272 | if type(buf) == loxi.generic_util.OFReader: |
| 273 | reader = buf |
| 274 | else: |
| 275 | reader = loxi.generic_util.OFReader(buf) |
| 276 | _type = reader.read('!H')[0] |
| 277 | assert(_type == const.OFPIT_WRITE_ACTIONS) |
| 278 | _len = reader.read('!H')[0] |
| 279 | reader.skip(4) |
| 280 | obj.actions = action.unpack_list(reader) |
| 281 | return obj |
| 282 | |
| 283 | def __eq__(self, other): |
| 284 | if type(self) != type(other): return False |
| 285 | if self.actions != other.actions: return False |
| 286 | return True |
| 287 | |
| 288 | def __ne__(self, other): |
| 289 | return not self.__eq__(other) |
| 290 | |
| 291 | def show(self): |
| 292 | import loxi.pp |
| 293 | return loxi.pp.pp(self) |
| 294 | |
| 295 | def pretty_print(self, q): |
| 296 | q.text("write_actions {") |
| 297 | with q.group(): |
| 298 | with q.indent(2): |
| 299 | q.breakable() |
| 300 | q.text("actions = "); |
| 301 | q.pp(self.actions) |
| 302 | q.breakable() |
| 303 | q.text('}') |
| 304 | |
| 305 | class write_metadata(Instruction): |
| 306 | type = const.OFPIT_WRITE_METADATA |
| 307 | |
| 308 | def __init__(self, metadata=None, metadata_mask=None): |
| 309 | if metadata != None: |
| 310 | self.metadata = metadata |
| 311 | else: |
| 312 | self.metadata = 0 |
| 313 | if metadata_mask != None: |
| 314 | self.metadata_mask = metadata_mask |
| 315 | else: |
| 316 | self.metadata_mask = 0 |
| 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 | packed.append(struct.pack("!Q", self.metadata)) |
| 325 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 326 | length = sum([len(x) for x in packed]) |
| 327 | packed[1] = struct.pack("!H", length) |
| 328 | return ''.join(packed) |
| 329 | |
| 330 | @staticmethod |
| 331 | def unpack(buf): |
| 332 | obj = write_metadata() |
| 333 | if type(buf) == loxi.generic_util.OFReader: |
| 334 | reader = buf |
| 335 | else: |
| 336 | reader = loxi.generic_util.OFReader(buf) |
| 337 | _type = reader.read('!H')[0] |
| 338 | assert(_type == const.OFPIT_WRITE_METADATA) |
| 339 | _len = reader.read('!H')[0] |
| 340 | reader.skip(4) |
| 341 | obj.metadata = reader.read('!Q')[0] |
| 342 | obj.metadata_mask = reader.read('!Q')[0] |
| 343 | return obj |
| 344 | |
| 345 | def __eq__(self, other): |
| 346 | if type(self) != type(other): return False |
| 347 | if self.metadata != other.metadata: return False |
| 348 | if self.metadata_mask != other.metadata_mask: return False |
| 349 | return True |
| 350 | |
| 351 | def __ne__(self, other): |
| 352 | return not self.__eq__(other) |
| 353 | |
| 354 | def show(self): |
| 355 | import loxi.pp |
| 356 | return loxi.pp.pp(self) |
| 357 | |
| 358 | def pretty_print(self, q): |
| 359 | q.text("write_metadata {") |
| 360 | with q.group(): |
| 361 | with q.indent(2): |
| 362 | q.breakable() |
| 363 | q.text("metadata = "); |
| 364 | q.text("%#x" % self.metadata) |
| 365 | q.text(","); q.breakable() |
| 366 | q.text("metadata_mask = "); |
| 367 | q.text("%#x" % self.metadata_mask) |
| 368 | q.breakable() |
| 369 | q.text('}') |
| 370 | |
| 371 | |
| 372 | parsers = { |
| 373 | const.OFPIT_APPLY_ACTIONS : apply_actions.unpack, |
| 374 | const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack, |
| 375 | const.OFPIT_EXPERIMENTER : experimenter.unpack, |
| 376 | const.OFPIT_GOTO_TABLE : goto_table.unpack, |
| 377 | const.OFPIT_WRITE_ACTIONS : write_actions.unpack, |
| 378 | const.OFPIT_WRITE_METADATA : write_metadata.unpack, |
| 379 | } |