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