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