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 | |
| 83 | class clear_actions(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 84 | type = 5 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 85 | |
| 86 | def __init__(self): |
| 87 | return |
| 88 | |
| 89 | def pack(self): |
| 90 | packed = [] |
| 91 | packed.append(struct.pack("!H", self.type)) |
| 92 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 93 | packed.append('\x00' * 4) |
| 94 | length = sum([len(x) for x in packed]) |
| 95 | packed[1] = struct.pack("!H", length) |
| 96 | return ''.join(packed) |
| 97 | |
| 98 | @staticmethod |
| 99 | def unpack(buf): |
| 100 | obj = clear_actions() |
| 101 | if type(buf) == loxi.generic_util.OFReader: |
| 102 | reader = buf |
| 103 | else: |
| 104 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 105 | _type = reader.read("!H")[0] |
| 106 | assert(_type == 5) |
| 107 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 108 | reader.skip(4) |
| 109 | return obj |
| 110 | |
| 111 | def __eq__(self, other): |
| 112 | if type(self) != type(other): return False |
| 113 | return True |
| 114 | |
| 115 | def __ne__(self, other): |
| 116 | return not self.__eq__(other) |
| 117 | |
| 118 | def show(self): |
| 119 | import loxi.pp |
| 120 | return loxi.pp.pp(self) |
| 121 | |
| 122 | def pretty_print(self, q): |
| 123 | q.text("clear_actions {") |
| 124 | with q.group(): |
| 125 | with q.indent(2): |
| 126 | q.breakable() |
| 127 | q.breakable() |
| 128 | q.text('}') |
| 129 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 130 | class goto_table(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 131 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 132 | |
| 133 | def __init__(self, table_id=None): |
| 134 | if table_id != None: |
| 135 | self.table_id = table_id |
| 136 | else: |
| 137 | self.table_id = 0 |
| 138 | return |
| 139 | |
| 140 | def pack(self): |
| 141 | packed = [] |
| 142 | packed.append(struct.pack("!H", self.type)) |
| 143 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 144 | packed.append(struct.pack("!B", self.table_id)) |
| 145 | packed.append('\x00' * 3) |
| 146 | length = sum([len(x) for x in packed]) |
| 147 | packed[1] = struct.pack("!H", length) |
| 148 | return ''.join(packed) |
| 149 | |
| 150 | @staticmethod |
| 151 | def unpack(buf): |
| 152 | obj = goto_table() |
| 153 | if type(buf) == loxi.generic_util.OFReader: |
| 154 | reader = buf |
| 155 | else: |
| 156 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 157 | _type = reader.read("!H")[0] |
| 158 | assert(_type == 1) |
| 159 | _len = reader.read("!H")[0] |
| 160 | obj.table_id = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 161 | reader.skip(3) |
| 162 | return obj |
| 163 | |
| 164 | def __eq__(self, other): |
| 165 | if type(self) != type(other): return False |
| 166 | if self.table_id != other.table_id: return False |
| 167 | return True |
| 168 | |
| 169 | def __ne__(self, other): |
| 170 | return not self.__eq__(other) |
| 171 | |
| 172 | def show(self): |
| 173 | import loxi.pp |
| 174 | return loxi.pp.pp(self) |
| 175 | |
| 176 | def pretty_print(self, q): |
| 177 | q.text("goto_table {") |
| 178 | with q.group(): |
| 179 | with q.indent(2): |
| 180 | q.breakable() |
| 181 | q.text("table_id = "); |
| 182 | q.text("%#x" % self.table_id) |
| 183 | q.breakable() |
| 184 | q.text('}') |
| 185 | |
| 186 | class meter(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 187 | type = 6 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 188 | |
| 189 | def __init__(self, meter_id=None): |
| 190 | if meter_id != None: |
| 191 | self.meter_id = meter_id |
| 192 | else: |
| 193 | self.meter_id = 0 |
| 194 | return |
| 195 | |
| 196 | def pack(self): |
| 197 | packed = [] |
| 198 | packed.append(struct.pack("!H", self.type)) |
| 199 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 200 | packed.append(struct.pack("!L", self.meter_id)) |
| 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 = meter() |
| 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 == 6) |
| 214 | _len = reader.read("!H")[0] |
| 215 | obj.meter_id = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 216 | return obj |
| 217 | |
| 218 | def __eq__(self, other): |
| 219 | if type(self) != type(other): return False |
| 220 | if self.meter_id != other.meter_id: return False |
| 221 | return True |
| 222 | |
| 223 | def __ne__(self, other): |
| 224 | return not self.__eq__(other) |
| 225 | |
| 226 | def show(self): |
| 227 | import loxi.pp |
| 228 | return loxi.pp.pp(self) |
| 229 | |
| 230 | def pretty_print(self, q): |
| 231 | q.text("meter {") |
| 232 | with q.group(): |
| 233 | with q.indent(2): |
| 234 | q.breakable() |
| 235 | q.text("meter_id = "); |
| 236 | q.text("%#x" % self.meter_id) |
| 237 | q.breakable() |
| 238 | q.text('}') |
| 239 | |
| 240 | class write_actions(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 241 | type = 3 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 242 | |
| 243 | def __init__(self, actions=None): |
| 244 | if actions != None: |
| 245 | self.actions = actions |
| 246 | else: |
| 247 | self.actions = [] |
| 248 | return |
| 249 | |
| 250 | def pack(self): |
| 251 | packed = [] |
| 252 | packed.append(struct.pack("!H", self.type)) |
| 253 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 254 | packed.append('\x00' * 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 255 | packed.append(util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 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 = write_actions() |
| 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 == 3) |
| 269 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 270 | reader.skip(4) |
| 271 | obj.actions = action.unpack_list(reader) |
| 272 | return obj |
| 273 | |
| 274 | def __eq__(self, other): |
| 275 | if type(self) != type(other): return False |
| 276 | if self.actions != other.actions: return False |
| 277 | return True |
| 278 | |
| 279 | def __ne__(self, other): |
| 280 | return not self.__eq__(other) |
| 281 | |
| 282 | def show(self): |
| 283 | import loxi.pp |
| 284 | return loxi.pp.pp(self) |
| 285 | |
| 286 | def pretty_print(self, q): |
| 287 | q.text("write_actions {") |
| 288 | with q.group(): |
| 289 | with q.indent(2): |
| 290 | q.breakable() |
| 291 | q.text("actions = "); |
| 292 | q.pp(self.actions) |
| 293 | q.breakable() |
| 294 | q.text('}') |
| 295 | |
| 296 | class write_metadata(Instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 297 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 298 | |
| 299 | def __init__(self, metadata=None, metadata_mask=None): |
| 300 | if metadata != None: |
| 301 | self.metadata = metadata |
| 302 | else: |
| 303 | self.metadata = 0 |
| 304 | if metadata_mask != None: |
| 305 | self.metadata_mask = metadata_mask |
| 306 | else: |
| 307 | self.metadata_mask = 0 |
| 308 | return |
| 309 | |
| 310 | def pack(self): |
| 311 | packed = [] |
| 312 | packed.append(struct.pack("!H", self.type)) |
| 313 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 314 | packed.append('\x00' * 4) |
| 315 | packed.append(struct.pack("!Q", self.metadata)) |
| 316 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 317 | length = sum([len(x) for x in packed]) |
| 318 | packed[1] = struct.pack("!H", length) |
| 319 | return ''.join(packed) |
| 320 | |
| 321 | @staticmethod |
| 322 | def unpack(buf): |
| 323 | obj = write_metadata() |
| 324 | if type(buf) == loxi.generic_util.OFReader: |
| 325 | reader = buf |
| 326 | else: |
| 327 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 328 | _type = reader.read("!H")[0] |
| 329 | assert(_type == 2) |
| 330 | _len = reader.read("!H")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 331 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 332 | obj.metadata = reader.read("!Q")[0] |
| 333 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 334 | return obj |
| 335 | |
| 336 | def __eq__(self, other): |
| 337 | if type(self) != type(other): return False |
| 338 | if self.metadata != other.metadata: return False |
| 339 | if self.metadata_mask != other.metadata_mask: return False |
| 340 | return True |
| 341 | |
| 342 | def __ne__(self, other): |
| 343 | return not self.__eq__(other) |
| 344 | |
| 345 | def show(self): |
| 346 | import loxi.pp |
| 347 | return loxi.pp.pp(self) |
| 348 | |
| 349 | def pretty_print(self, q): |
| 350 | q.text("write_metadata {") |
| 351 | with q.group(): |
| 352 | with q.indent(2): |
| 353 | q.breakable() |
| 354 | q.text("metadata = "); |
| 355 | q.text("%#x" % self.metadata) |
| 356 | q.text(","); q.breakable() |
| 357 | q.text("metadata_mask = "); |
| 358 | q.text("%#x" % self.metadata_mask) |
| 359 | q.breakable() |
| 360 | q.text('}') |
| 361 | |
| 362 | |
| 363 | parsers = { |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 364 | const.OFPIT_GOTO_TABLE : goto_table.unpack, |
| 365 | const.OFPIT_WRITE_METADATA : write_metadata.unpack, |
| 366 | const.OFPIT_WRITE_ACTIONS : write_actions.unpack, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 367 | const.OFPIT_APPLY_ACTIONS : apply_actions.unpack, |
| 368 | const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 369 | const.OFPIT_METER : meter.unpack, |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 370 | } |