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