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