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