Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -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 | c2ee4b8 | 2013-04-24 17:12:38 -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 | c2ee4b8 | 2013-04-24 17:12:38 -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 | c2ee4b8 | 2013-04-24 17:12:38 -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 |
| 15 | import oxm |
| 16 | import action_id |
| 17 | import instruction_id |
| 18 | import meter_band |
Rich Lane | 5454b68 | 2014-01-14 17:07:36 -0800 | [diff] [blame] | 19 | import bsn_tlv |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 20 | import util |
| 21 | import loxi.generic_util |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 22 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 23 | class action(loxi.OFObject): |
| 24 | subtypes = {} |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 25 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 26 | |
| 27 | def __init__(self, type=None): |
| 28 | if type != None: |
| 29 | self.type = type |
| 30 | else: |
| 31 | self.type = 0 |
| 32 | return |
| 33 | |
| 34 | def pack(self): |
| 35 | packed = [] |
| 36 | packed.append(struct.pack("!H", self.type)) |
| 37 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 38 | packed.append('\x00' * 4) |
| 39 | length = sum([len(x) for x in packed]) |
| 40 | packed[1] = struct.pack("!H", length) |
| 41 | return ''.join(packed) |
| 42 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 43 | @staticmethod |
| 44 | def unpack(reader): |
| 45 | subtype, = reader.peek('!H', 0) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 46 | subclass = action.subtypes.get(subtype) |
| 47 | if subclass: |
| 48 | return subclass.unpack(reader) |
| 49 | |
| 50 | obj = action() |
| 51 | obj.type = reader.read("!H")[0] |
| 52 | _len = reader.read("!H")[0] |
| 53 | orig_reader = reader |
| 54 | reader = orig_reader.slice(_len - (2 + 2)) |
| 55 | reader.skip(4) |
| 56 | return obj |
| 57 | |
| 58 | def __eq__(self, other): |
| 59 | if type(self) != type(other): return False |
| 60 | if self.type != other.type: return False |
| 61 | return True |
| 62 | |
| 63 | def pretty_print(self, q): |
| 64 | q.text("action {") |
| 65 | with q.group(): |
| 66 | with q.indent(2): |
| 67 | q.breakable() |
| 68 | q.breakable() |
| 69 | q.text('}') |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 70 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 71 | |
| 72 | class experimenter(action): |
| 73 | subtypes = {} |
| 74 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 75 | type = 65535 |
| 76 | |
| 77 | def __init__(self, experimenter=None, data=None): |
| 78 | if experimenter != None: |
| 79 | self.experimenter = experimenter |
| 80 | else: |
| 81 | self.experimenter = 0 |
| 82 | if data != None: |
| 83 | self.data = data |
| 84 | else: |
| 85 | self.data = '' |
| 86 | return |
| 87 | |
| 88 | def pack(self): |
| 89 | packed = [] |
| 90 | packed.append(struct.pack("!H", self.type)) |
| 91 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 92 | packed.append(struct.pack("!L", self.experimenter)) |
| 93 | packed.append(self.data) |
| 94 | length = sum([len(x) for x in packed]) |
| 95 | packed.append(loxi.generic_util.pad_to(8, length)) |
| 96 | length += len(packed[-1]) |
| 97 | packed[1] = struct.pack("!H", length) |
| 98 | return ''.join(packed) |
| 99 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 100 | @staticmethod |
| 101 | def unpack(reader): |
| 102 | subtype, = reader.peek('!L', 4) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 103 | subclass = experimenter.subtypes.get(subtype) |
| 104 | if subclass: |
| 105 | return subclass.unpack(reader) |
| 106 | |
| 107 | obj = experimenter() |
| 108 | _type = reader.read("!H")[0] |
| 109 | assert(_type == 65535) |
| 110 | _len = reader.read("!H")[0] |
| 111 | orig_reader = reader |
| 112 | reader = orig_reader.slice(_len - (2 + 2)) |
| 113 | obj.experimenter = reader.read("!L")[0] |
| 114 | obj.data = str(reader.read_all()) |
| 115 | return obj |
| 116 | |
| 117 | def __eq__(self, other): |
| 118 | if type(self) != type(other): return False |
| 119 | if self.experimenter != other.experimenter: return False |
| 120 | if self.data != other.data: return False |
| 121 | return True |
| 122 | |
| 123 | def pretty_print(self, q): |
| 124 | q.text("experimenter {") |
| 125 | with q.group(): |
| 126 | with q.indent(2): |
| 127 | q.breakable() |
| 128 | q.text("data = "); |
| 129 | q.pp(self.data) |
| 130 | q.breakable() |
| 131 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 132 | |
| 133 | action.subtypes[65535] = experimenter |
| 134 | |
| 135 | class bsn(experimenter): |
| 136 | subtypes = {} |
| 137 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 138 | type = 65535 |
| 139 | experimenter = 6035143 |
| 140 | |
| 141 | def __init__(self, subtype=None): |
| 142 | if subtype != None: |
| 143 | self.subtype = subtype |
| 144 | else: |
| 145 | self.subtype = 0 |
| 146 | return |
| 147 | |
| 148 | def pack(self): |
| 149 | packed = [] |
| 150 | packed.append(struct.pack("!H", self.type)) |
| 151 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 152 | packed.append(struct.pack("!L", self.experimenter)) |
| 153 | packed.append(struct.pack("!L", self.subtype)) |
| 154 | packed.append('\x00' * 4) |
| 155 | length = sum([len(x) for x in packed]) |
| 156 | packed[1] = struct.pack("!H", length) |
| 157 | return ''.join(packed) |
| 158 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 159 | @staticmethod |
| 160 | def unpack(reader): |
| 161 | subtype, = reader.peek('!L', 8) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 162 | subclass = bsn.subtypes.get(subtype) |
| 163 | if subclass: |
| 164 | return subclass.unpack(reader) |
| 165 | |
| 166 | obj = bsn() |
| 167 | _type = reader.read("!H")[0] |
| 168 | assert(_type == 65535) |
| 169 | _len = reader.read("!H")[0] |
| 170 | orig_reader = reader |
| 171 | reader = orig_reader.slice(_len - (2 + 2)) |
| 172 | _experimenter = reader.read("!L")[0] |
| 173 | assert(_experimenter == 6035143) |
| 174 | obj.subtype = reader.read("!L")[0] |
| 175 | reader.skip(4) |
| 176 | return obj |
| 177 | |
| 178 | def __eq__(self, other): |
| 179 | if type(self) != type(other): return False |
| 180 | if self.subtype != other.subtype: return False |
| 181 | return True |
| 182 | |
| 183 | def pretty_print(self, q): |
| 184 | q.text("bsn {") |
| 185 | with q.group(): |
| 186 | with q.indent(2): |
| 187 | q.breakable() |
| 188 | q.breakable() |
| 189 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 190 | |
| 191 | experimenter.subtypes[6035143] = bsn |
| 192 | |
Rich Lane | 5587ab1 | 2014-06-30 11:19:09 -0700 | [diff] [blame] | 193 | class bsn_checksum(bsn): |
| 194 | type = 65535 |
| 195 | experimenter = 6035143 |
| 196 | subtype = 4 |
| 197 | |
| 198 | def __init__(self, checksum=None): |
| 199 | if checksum != None: |
| 200 | self.checksum = checksum |
| 201 | else: |
| 202 | self.checksum = 0 |
| 203 | return |
| 204 | |
| 205 | def pack(self): |
| 206 | packed = [] |
| 207 | packed.append(struct.pack("!H", self.type)) |
| 208 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 209 | packed.append(struct.pack("!L", self.experimenter)) |
| 210 | packed.append(struct.pack("!L", self.subtype)) |
| 211 | packed.append(util.pack_checksum_128(self.checksum)) |
| 212 | length = sum([len(x) for x in packed]) |
| 213 | packed[1] = struct.pack("!H", length) |
| 214 | return ''.join(packed) |
| 215 | |
| 216 | @staticmethod |
| 217 | def unpack(reader): |
| 218 | obj = bsn_checksum() |
| 219 | _type = reader.read("!H")[0] |
| 220 | assert(_type == 65535) |
| 221 | _len = reader.read("!H")[0] |
| 222 | orig_reader = reader |
| 223 | reader = orig_reader.slice(_len - (2 + 2)) |
| 224 | _experimenter = reader.read("!L")[0] |
| 225 | assert(_experimenter == 6035143) |
| 226 | _subtype = reader.read("!L")[0] |
| 227 | assert(_subtype == 4) |
| 228 | obj.checksum = util.unpack_checksum_128(reader) |
| 229 | return obj |
| 230 | |
| 231 | def __eq__(self, other): |
| 232 | if type(self) != type(other): return False |
| 233 | if self.checksum != other.checksum: return False |
| 234 | return True |
| 235 | |
| 236 | def pretty_print(self, q): |
| 237 | q.text("bsn_checksum {") |
| 238 | with q.group(): |
| 239 | with q.indent(2): |
| 240 | q.breakable() |
| 241 | q.text("checksum = "); |
| 242 | q.pp(self.checksum) |
| 243 | q.breakable() |
| 244 | q.text('}') |
| 245 | |
| 246 | bsn.subtypes[4] = bsn_checksum |
| 247 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 248 | class bsn_mirror(bsn): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 249 | type = 65535 |
| 250 | experimenter = 6035143 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 251 | subtype = 1 |
| 252 | |
| 253 | def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None): |
| 254 | if dest_port != None: |
| 255 | self.dest_port = dest_port |
| 256 | else: |
| 257 | self.dest_port = 0 |
| 258 | if vlan_tag != None: |
| 259 | self.vlan_tag = vlan_tag |
| 260 | else: |
| 261 | self.vlan_tag = 0 |
| 262 | if copy_stage != None: |
| 263 | self.copy_stage = copy_stage |
| 264 | else: |
| 265 | self.copy_stage = 0 |
| 266 | return |
| 267 | |
| 268 | def pack(self): |
| 269 | packed = [] |
| 270 | packed.append(struct.pack("!H", self.type)) |
| 271 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 272 | packed.append(struct.pack("!L", self.experimenter)) |
| 273 | packed.append(struct.pack("!L", self.subtype)) |
| 274 | packed.append(struct.pack("!L", self.dest_port)) |
| 275 | packed.append(struct.pack("!L", self.vlan_tag)) |
| 276 | packed.append(struct.pack("!B", self.copy_stage)) |
| 277 | packed.append('\x00' * 3) |
| 278 | length = sum([len(x) for x in packed]) |
| 279 | packed[1] = struct.pack("!H", length) |
| 280 | return ''.join(packed) |
| 281 | |
| 282 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 283 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 284 | obj = bsn_mirror() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 285 | _type = reader.read("!H")[0] |
| 286 | assert(_type == 65535) |
| 287 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 288 | orig_reader = reader |
| 289 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 290 | _experimenter = reader.read("!L")[0] |
| 291 | assert(_experimenter == 6035143) |
| 292 | _subtype = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 293 | assert(_subtype == 1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 294 | obj.dest_port = reader.read("!L")[0] |
| 295 | obj.vlan_tag = reader.read("!L")[0] |
| 296 | obj.copy_stage = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 297 | reader.skip(3) |
| 298 | return obj |
| 299 | |
| 300 | def __eq__(self, other): |
| 301 | if type(self) != type(other): return False |
| 302 | if self.dest_port != other.dest_port: return False |
| 303 | if self.vlan_tag != other.vlan_tag: return False |
| 304 | if self.copy_stage != other.copy_stage: return False |
| 305 | return True |
| 306 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 307 | def pretty_print(self, q): |
| 308 | q.text("bsn_mirror {") |
| 309 | with q.group(): |
| 310 | with q.indent(2): |
| 311 | q.breakable() |
| 312 | q.text("dest_port = "); |
| 313 | q.text("%#x" % self.dest_port) |
| 314 | q.text(","); q.breakable() |
| 315 | q.text("vlan_tag = "); |
| 316 | q.text("%#x" % self.vlan_tag) |
| 317 | q.text(","); q.breakable() |
| 318 | q.text("copy_stage = "); |
| 319 | q.text("%#x" % self.copy_stage) |
| 320 | q.breakable() |
| 321 | q.text('}') |
| 322 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 323 | bsn.subtypes[1] = bsn_mirror |
| 324 | |
| 325 | class bsn_set_tunnel_dst(bsn): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 326 | type = 65535 |
| 327 | experimenter = 6035143 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 328 | subtype = 2 |
| 329 | |
| 330 | def __init__(self, dst=None): |
| 331 | if dst != None: |
| 332 | self.dst = dst |
| 333 | else: |
| 334 | self.dst = 0 |
| 335 | return |
| 336 | |
| 337 | def pack(self): |
| 338 | packed = [] |
| 339 | packed.append(struct.pack("!H", self.type)) |
| 340 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 341 | packed.append(struct.pack("!L", self.experimenter)) |
| 342 | packed.append(struct.pack("!L", self.subtype)) |
| 343 | packed.append(struct.pack("!L", self.dst)) |
| 344 | length = sum([len(x) for x in packed]) |
| 345 | packed[1] = struct.pack("!H", length) |
| 346 | return ''.join(packed) |
| 347 | |
| 348 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 349 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 350 | obj = bsn_set_tunnel_dst() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 351 | _type = reader.read("!H")[0] |
| 352 | assert(_type == 65535) |
| 353 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 354 | orig_reader = reader |
| 355 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 356 | _experimenter = reader.read("!L")[0] |
| 357 | assert(_experimenter == 6035143) |
| 358 | _subtype = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 359 | assert(_subtype == 2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 360 | obj.dst = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 361 | return obj |
| 362 | |
| 363 | def __eq__(self, other): |
| 364 | if type(self) != type(other): return False |
| 365 | if self.dst != other.dst: return False |
| 366 | return True |
| 367 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 368 | def pretty_print(self, q): |
| 369 | q.text("bsn_set_tunnel_dst {") |
| 370 | with q.group(): |
| 371 | with q.indent(2): |
| 372 | q.breakable() |
| 373 | q.text("dst = "); |
| 374 | q.text("%#x" % self.dst) |
| 375 | q.breakable() |
| 376 | q.text('}') |
| 377 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 378 | bsn.subtypes[2] = bsn_set_tunnel_dst |
| 379 | |
| 380 | class copy_ttl_in(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 381 | type = 12 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 382 | |
| 383 | def __init__(self): |
| 384 | return |
| 385 | |
| 386 | def pack(self): |
| 387 | packed = [] |
| 388 | packed.append(struct.pack("!H", self.type)) |
| 389 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 390 | packed.append('\x00' * 4) |
| 391 | length = sum([len(x) for x in packed]) |
| 392 | packed[1] = struct.pack("!H", length) |
| 393 | return ''.join(packed) |
| 394 | |
| 395 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 396 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 397 | obj = copy_ttl_in() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 398 | _type = reader.read("!H")[0] |
| 399 | assert(_type == 12) |
| 400 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 401 | orig_reader = reader |
| 402 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 403 | reader.skip(4) |
| 404 | return obj |
| 405 | |
| 406 | def __eq__(self, other): |
| 407 | if type(self) != type(other): return False |
| 408 | return True |
| 409 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 410 | def pretty_print(self, q): |
| 411 | q.text("copy_ttl_in {") |
| 412 | with q.group(): |
| 413 | with q.indent(2): |
| 414 | q.breakable() |
| 415 | q.breakable() |
| 416 | q.text('}') |
| 417 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 418 | action.subtypes[12] = copy_ttl_in |
| 419 | |
| 420 | class copy_ttl_out(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 421 | type = 11 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 422 | |
| 423 | def __init__(self): |
| 424 | return |
| 425 | |
| 426 | def pack(self): |
| 427 | packed = [] |
| 428 | packed.append(struct.pack("!H", self.type)) |
| 429 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 430 | packed.append('\x00' * 4) |
| 431 | length = sum([len(x) for x in packed]) |
| 432 | packed[1] = struct.pack("!H", length) |
| 433 | return ''.join(packed) |
| 434 | |
| 435 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 436 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 437 | obj = copy_ttl_out() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 438 | _type = reader.read("!H")[0] |
| 439 | assert(_type == 11) |
| 440 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 441 | orig_reader = reader |
| 442 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 443 | reader.skip(4) |
| 444 | return obj |
| 445 | |
| 446 | def __eq__(self, other): |
| 447 | if type(self) != type(other): return False |
| 448 | return True |
| 449 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 450 | def pretty_print(self, q): |
| 451 | q.text("copy_ttl_out {") |
| 452 | with q.group(): |
| 453 | with q.indent(2): |
| 454 | q.breakable() |
| 455 | q.breakable() |
| 456 | q.text('}') |
| 457 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 458 | action.subtypes[11] = copy_ttl_out |
| 459 | |
| 460 | class dec_mpls_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 461 | type = 16 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 462 | |
| 463 | def __init__(self): |
| 464 | return |
| 465 | |
| 466 | def pack(self): |
| 467 | packed = [] |
| 468 | packed.append(struct.pack("!H", self.type)) |
| 469 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 470 | packed.append('\x00' * 4) |
| 471 | length = sum([len(x) for x in packed]) |
| 472 | packed[1] = struct.pack("!H", length) |
| 473 | return ''.join(packed) |
| 474 | |
| 475 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 476 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 477 | obj = dec_mpls_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 478 | _type = reader.read("!H")[0] |
| 479 | assert(_type == 16) |
| 480 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 481 | orig_reader = reader |
| 482 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 483 | reader.skip(4) |
| 484 | return obj |
| 485 | |
| 486 | def __eq__(self, other): |
| 487 | if type(self) != type(other): return False |
| 488 | return True |
| 489 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 490 | def pretty_print(self, q): |
| 491 | q.text("dec_mpls_ttl {") |
| 492 | with q.group(): |
| 493 | with q.indent(2): |
| 494 | q.breakable() |
| 495 | q.breakable() |
| 496 | q.text('}') |
| 497 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 498 | action.subtypes[16] = dec_mpls_ttl |
| 499 | |
| 500 | class dec_nw_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 501 | type = 24 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 502 | |
| 503 | def __init__(self): |
| 504 | return |
| 505 | |
| 506 | def pack(self): |
| 507 | packed = [] |
| 508 | packed.append(struct.pack("!H", self.type)) |
| 509 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 510 | packed.append('\x00' * 4) |
| 511 | length = sum([len(x) for x in packed]) |
| 512 | packed[1] = struct.pack("!H", length) |
| 513 | return ''.join(packed) |
| 514 | |
| 515 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 516 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 517 | obj = dec_nw_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 518 | _type = reader.read("!H")[0] |
| 519 | assert(_type == 24) |
| 520 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 521 | orig_reader = reader |
| 522 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 523 | reader.skip(4) |
| 524 | return obj |
| 525 | |
| 526 | def __eq__(self, other): |
| 527 | if type(self) != type(other): return False |
| 528 | return True |
| 529 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 530 | def pretty_print(self, q): |
| 531 | q.text("dec_nw_ttl {") |
| 532 | with q.group(): |
| 533 | with q.indent(2): |
| 534 | q.breakable() |
| 535 | q.breakable() |
| 536 | q.text('}') |
| 537 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 538 | action.subtypes[24] = dec_nw_ttl |
| 539 | |
| 540 | class group(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 541 | type = 22 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 542 | |
| 543 | def __init__(self, group_id=None): |
| 544 | if group_id != None: |
| 545 | self.group_id = group_id |
| 546 | else: |
| 547 | self.group_id = 0 |
| 548 | return |
| 549 | |
| 550 | def pack(self): |
| 551 | packed = [] |
| 552 | packed.append(struct.pack("!H", self.type)) |
| 553 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 554 | packed.append(struct.pack("!L", self.group_id)) |
| 555 | length = sum([len(x) for x in packed]) |
| 556 | packed[1] = struct.pack("!H", length) |
| 557 | return ''.join(packed) |
| 558 | |
| 559 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 560 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 561 | obj = group() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 562 | _type = reader.read("!H")[0] |
| 563 | assert(_type == 22) |
| 564 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 565 | orig_reader = reader |
| 566 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 567 | obj.group_id = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 568 | return obj |
| 569 | |
| 570 | def __eq__(self, other): |
| 571 | if type(self) != type(other): return False |
| 572 | if self.group_id != other.group_id: return False |
| 573 | return True |
| 574 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 575 | def pretty_print(self, q): |
| 576 | q.text("group {") |
| 577 | with q.group(): |
| 578 | with q.indent(2): |
| 579 | q.breakable() |
| 580 | q.text("group_id = "); |
| 581 | q.text("%#x" % self.group_id) |
| 582 | q.breakable() |
| 583 | q.text('}') |
| 584 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 585 | action.subtypes[22] = group |
| 586 | |
| 587 | class nicira(experimenter): |
| 588 | subtypes = {} |
| 589 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 590 | type = 65535 |
| 591 | experimenter = 8992 |
| 592 | |
| 593 | def __init__(self, subtype=None): |
| 594 | if subtype != None: |
| 595 | self.subtype = subtype |
| 596 | else: |
| 597 | self.subtype = 0 |
| 598 | return |
| 599 | |
| 600 | def pack(self): |
| 601 | packed = [] |
| 602 | packed.append(struct.pack("!H", self.type)) |
| 603 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 604 | packed.append(struct.pack("!L", self.experimenter)) |
| 605 | packed.append(struct.pack("!H", self.subtype)) |
| 606 | packed.append('\x00' * 2) |
| 607 | packed.append('\x00' * 4) |
| 608 | length = sum([len(x) for x in packed]) |
| 609 | packed[1] = struct.pack("!H", length) |
| 610 | return ''.join(packed) |
| 611 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 612 | @staticmethod |
| 613 | def unpack(reader): |
| 614 | subtype, = reader.peek('!H', 8) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 615 | subclass = nicira.subtypes.get(subtype) |
| 616 | if subclass: |
| 617 | return subclass.unpack(reader) |
| 618 | |
| 619 | obj = nicira() |
| 620 | _type = reader.read("!H")[0] |
| 621 | assert(_type == 65535) |
| 622 | _len = reader.read("!H")[0] |
| 623 | orig_reader = reader |
| 624 | reader = orig_reader.slice(_len - (2 + 2)) |
| 625 | _experimenter = reader.read("!L")[0] |
| 626 | assert(_experimenter == 8992) |
| 627 | obj.subtype = reader.read("!H")[0] |
| 628 | reader.skip(2) |
| 629 | reader.skip(4) |
| 630 | return obj |
| 631 | |
| 632 | def __eq__(self, other): |
| 633 | if type(self) != type(other): return False |
| 634 | if self.subtype != other.subtype: return False |
| 635 | return True |
| 636 | |
| 637 | def pretty_print(self, q): |
| 638 | q.text("nicira {") |
| 639 | with q.group(): |
| 640 | with q.indent(2): |
| 641 | q.breakable() |
| 642 | q.breakable() |
| 643 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 644 | |
| 645 | experimenter.subtypes[8992] = nicira |
| 646 | |
| 647 | class nicira_dec_ttl(nicira): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 648 | type = 65535 |
| 649 | experimenter = 8992 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 650 | subtype = 18 |
| 651 | |
| 652 | def __init__(self): |
| 653 | return |
| 654 | |
| 655 | def pack(self): |
| 656 | packed = [] |
| 657 | packed.append(struct.pack("!H", self.type)) |
| 658 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 659 | packed.append(struct.pack("!L", self.experimenter)) |
| 660 | packed.append(struct.pack("!H", self.subtype)) |
| 661 | packed.append('\x00' * 2) |
| 662 | packed.append('\x00' * 4) |
| 663 | length = sum([len(x) for x in packed]) |
| 664 | packed[1] = struct.pack("!H", length) |
| 665 | return ''.join(packed) |
| 666 | |
| 667 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 668 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 669 | obj = nicira_dec_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 670 | _type = reader.read("!H")[0] |
| 671 | assert(_type == 65535) |
| 672 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 673 | orig_reader = reader |
| 674 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 675 | _experimenter = reader.read("!L")[0] |
| 676 | assert(_experimenter == 8992) |
| 677 | _subtype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 678 | assert(_subtype == 18) |
| 679 | reader.skip(2) |
| 680 | reader.skip(4) |
| 681 | return obj |
| 682 | |
| 683 | def __eq__(self, other): |
| 684 | if type(self) != type(other): return False |
| 685 | return True |
| 686 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 687 | def pretty_print(self, q): |
| 688 | q.text("nicira_dec_ttl {") |
| 689 | with q.group(): |
| 690 | with q.indent(2): |
| 691 | q.breakable() |
| 692 | q.breakable() |
| 693 | q.text('}') |
| 694 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 695 | nicira.subtypes[18] = nicira_dec_ttl |
| 696 | |
| 697 | class output(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 698 | type = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 699 | |
| 700 | def __init__(self, port=None, max_len=None): |
| 701 | if port != None: |
| 702 | self.port = port |
| 703 | else: |
| 704 | self.port = 0 |
| 705 | if max_len != None: |
| 706 | self.max_len = max_len |
| 707 | else: |
| 708 | self.max_len = 0 |
| 709 | return |
| 710 | |
| 711 | def pack(self): |
| 712 | packed = [] |
| 713 | packed.append(struct.pack("!H", self.type)) |
| 714 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 715 | packed.append(util.pack_port_no(self.port)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 716 | packed.append(struct.pack("!H", self.max_len)) |
| 717 | packed.append('\x00' * 6) |
| 718 | length = sum([len(x) for x in packed]) |
| 719 | packed[1] = struct.pack("!H", length) |
| 720 | return ''.join(packed) |
| 721 | |
| 722 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 723 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 724 | obj = output() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 725 | _type = reader.read("!H")[0] |
| 726 | assert(_type == 0) |
| 727 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 728 | orig_reader = reader |
| 729 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 730 | obj.port = util.unpack_port_no(reader) |
| 731 | obj.max_len = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 732 | reader.skip(6) |
| 733 | return obj |
| 734 | |
| 735 | def __eq__(self, other): |
| 736 | if type(self) != type(other): return False |
| 737 | if self.port != other.port: return False |
| 738 | if self.max_len != other.max_len: return False |
| 739 | return True |
| 740 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 741 | def pretty_print(self, q): |
| 742 | q.text("output {") |
| 743 | with q.group(): |
| 744 | with q.indent(2): |
| 745 | q.breakable() |
| 746 | q.text("port = "); |
| 747 | q.text(util.pretty_port(self.port)) |
| 748 | q.text(","); q.breakable() |
| 749 | q.text("max_len = "); |
| 750 | q.text("%#x" % self.max_len) |
| 751 | q.breakable() |
| 752 | q.text('}') |
| 753 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 754 | action.subtypes[0] = output |
| 755 | |
| 756 | class pop_mpls(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 757 | type = 20 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 758 | |
| 759 | def __init__(self, ethertype=None): |
| 760 | if ethertype != None: |
| 761 | self.ethertype = ethertype |
| 762 | else: |
| 763 | self.ethertype = 0 |
| 764 | return |
| 765 | |
| 766 | def pack(self): |
| 767 | packed = [] |
| 768 | packed.append(struct.pack("!H", self.type)) |
| 769 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 770 | packed.append(struct.pack("!H", self.ethertype)) |
| 771 | packed.append('\x00' * 2) |
| 772 | length = sum([len(x) for x in packed]) |
| 773 | packed[1] = struct.pack("!H", length) |
| 774 | return ''.join(packed) |
| 775 | |
| 776 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 777 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 778 | obj = pop_mpls() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 779 | _type = reader.read("!H")[0] |
| 780 | assert(_type == 20) |
| 781 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 782 | orig_reader = reader |
| 783 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 784 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 785 | reader.skip(2) |
| 786 | return obj |
| 787 | |
| 788 | def __eq__(self, other): |
| 789 | if type(self) != type(other): return False |
| 790 | if self.ethertype != other.ethertype: return False |
| 791 | return True |
| 792 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 793 | def pretty_print(self, q): |
| 794 | q.text("pop_mpls {") |
| 795 | with q.group(): |
| 796 | with q.indent(2): |
| 797 | q.breakable() |
| 798 | q.text("ethertype = "); |
| 799 | q.text("%#x" % self.ethertype) |
| 800 | q.breakable() |
| 801 | q.text('}') |
| 802 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 803 | action.subtypes[20] = pop_mpls |
| 804 | |
| 805 | class pop_pbb(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 806 | type = 27 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 807 | |
| 808 | def __init__(self): |
| 809 | return |
| 810 | |
| 811 | def pack(self): |
| 812 | packed = [] |
| 813 | packed.append(struct.pack("!H", self.type)) |
| 814 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 815 | packed.append('\x00' * 4) |
| 816 | length = sum([len(x) for x in packed]) |
| 817 | packed[1] = struct.pack("!H", length) |
| 818 | return ''.join(packed) |
| 819 | |
| 820 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 821 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 822 | obj = pop_pbb() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 823 | _type = reader.read("!H")[0] |
| 824 | assert(_type == 27) |
| 825 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 826 | orig_reader = reader |
| 827 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 828 | reader.skip(4) |
| 829 | return obj |
| 830 | |
| 831 | def __eq__(self, other): |
| 832 | if type(self) != type(other): return False |
| 833 | return True |
| 834 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 835 | def pretty_print(self, q): |
| 836 | q.text("pop_pbb {") |
| 837 | with q.group(): |
| 838 | with q.indent(2): |
| 839 | q.breakable() |
| 840 | q.breakable() |
| 841 | q.text('}') |
| 842 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 843 | action.subtypes[27] = pop_pbb |
| 844 | |
| 845 | class pop_vlan(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 846 | type = 18 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 847 | |
| 848 | def __init__(self): |
| 849 | return |
| 850 | |
| 851 | def pack(self): |
| 852 | packed = [] |
| 853 | packed.append(struct.pack("!H", self.type)) |
| 854 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 855 | packed.append('\x00' * 4) |
| 856 | length = sum([len(x) for x in packed]) |
| 857 | packed[1] = struct.pack("!H", length) |
| 858 | return ''.join(packed) |
| 859 | |
| 860 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 861 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 862 | obj = pop_vlan() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 863 | _type = reader.read("!H")[0] |
| 864 | assert(_type == 18) |
| 865 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 866 | orig_reader = reader |
| 867 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 868 | reader.skip(4) |
| 869 | return obj |
| 870 | |
| 871 | def __eq__(self, other): |
| 872 | if type(self) != type(other): return False |
| 873 | return True |
| 874 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 875 | def pretty_print(self, q): |
| 876 | q.text("pop_vlan {") |
| 877 | with q.group(): |
| 878 | with q.indent(2): |
| 879 | q.breakable() |
| 880 | q.breakable() |
| 881 | q.text('}') |
| 882 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 883 | action.subtypes[18] = pop_vlan |
| 884 | |
| 885 | class push_mpls(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 886 | type = 19 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 887 | |
| 888 | def __init__(self, ethertype=None): |
| 889 | if ethertype != None: |
| 890 | self.ethertype = ethertype |
| 891 | else: |
| 892 | self.ethertype = 0 |
| 893 | return |
| 894 | |
| 895 | def pack(self): |
| 896 | packed = [] |
| 897 | packed.append(struct.pack("!H", self.type)) |
| 898 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 899 | packed.append(struct.pack("!H", self.ethertype)) |
| 900 | packed.append('\x00' * 2) |
| 901 | length = sum([len(x) for x in packed]) |
| 902 | packed[1] = struct.pack("!H", length) |
| 903 | return ''.join(packed) |
| 904 | |
| 905 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 906 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 907 | obj = push_mpls() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 908 | _type = reader.read("!H")[0] |
| 909 | assert(_type == 19) |
| 910 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 911 | orig_reader = reader |
| 912 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 913 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 914 | reader.skip(2) |
| 915 | return obj |
| 916 | |
| 917 | def __eq__(self, other): |
| 918 | if type(self) != type(other): return False |
| 919 | if self.ethertype != other.ethertype: return False |
| 920 | return True |
| 921 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 922 | def pretty_print(self, q): |
| 923 | q.text("push_mpls {") |
| 924 | with q.group(): |
| 925 | with q.indent(2): |
| 926 | q.breakable() |
| 927 | q.text("ethertype = "); |
| 928 | q.text("%#x" % self.ethertype) |
| 929 | q.breakable() |
| 930 | q.text('}') |
| 931 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 932 | action.subtypes[19] = push_mpls |
| 933 | |
| 934 | class push_pbb(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 935 | type = 26 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 936 | |
| 937 | def __init__(self, ethertype=None): |
| 938 | if ethertype != None: |
| 939 | self.ethertype = ethertype |
| 940 | else: |
| 941 | self.ethertype = 0 |
| 942 | return |
| 943 | |
| 944 | def pack(self): |
| 945 | packed = [] |
| 946 | packed.append(struct.pack("!H", self.type)) |
| 947 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 948 | packed.append(struct.pack("!H", self.ethertype)) |
| 949 | packed.append('\x00' * 2) |
| 950 | length = sum([len(x) for x in packed]) |
| 951 | packed[1] = struct.pack("!H", length) |
| 952 | return ''.join(packed) |
| 953 | |
| 954 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 955 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 956 | obj = push_pbb() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 957 | _type = reader.read("!H")[0] |
| 958 | assert(_type == 26) |
| 959 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 960 | orig_reader = reader |
| 961 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 962 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 963 | reader.skip(2) |
| 964 | return obj |
| 965 | |
| 966 | def __eq__(self, other): |
| 967 | if type(self) != type(other): return False |
| 968 | if self.ethertype != other.ethertype: return False |
| 969 | return True |
| 970 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 971 | def pretty_print(self, q): |
| 972 | q.text("push_pbb {") |
| 973 | with q.group(): |
| 974 | with q.indent(2): |
| 975 | q.breakable() |
| 976 | q.text("ethertype = "); |
| 977 | q.text("%#x" % self.ethertype) |
| 978 | q.breakable() |
| 979 | q.text('}') |
| 980 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 981 | action.subtypes[26] = push_pbb |
| 982 | |
| 983 | class push_vlan(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 984 | type = 17 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 985 | |
| 986 | def __init__(self, ethertype=None): |
| 987 | if ethertype != None: |
| 988 | self.ethertype = ethertype |
| 989 | else: |
| 990 | self.ethertype = 0 |
| 991 | return |
| 992 | |
| 993 | def pack(self): |
| 994 | packed = [] |
| 995 | packed.append(struct.pack("!H", self.type)) |
| 996 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 997 | packed.append(struct.pack("!H", self.ethertype)) |
| 998 | packed.append('\x00' * 2) |
| 999 | length = sum([len(x) for x in packed]) |
| 1000 | packed[1] = struct.pack("!H", length) |
| 1001 | return ''.join(packed) |
| 1002 | |
| 1003 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1004 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1005 | obj = push_vlan() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1006 | _type = reader.read("!H")[0] |
| 1007 | assert(_type == 17) |
| 1008 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1009 | orig_reader = reader |
| 1010 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1011 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1012 | reader.skip(2) |
| 1013 | return obj |
| 1014 | |
| 1015 | def __eq__(self, other): |
| 1016 | if type(self) != type(other): return False |
| 1017 | if self.ethertype != other.ethertype: return False |
| 1018 | return True |
| 1019 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1020 | def pretty_print(self, q): |
| 1021 | q.text("push_vlan {") |
| 1022 | with q.group(): |
| 1023 | with q.indent(2): |
| 1024 | q.breakable() |
| 1025 | q.text("ethertype = "); |
| 1026 | q.text("%#x" % self.ethertype) |
| 1027 | q.breakable() |
| 1028 | q.text('}') |
| 1029 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1030 | action.subtypes[17] = push_vlan |
| 1031 | |
| 1032 | class set_field(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1033 | type = 25 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1034 | |
| 1035 | def __init__(self, field=None): |
| 1036 | if field != None: |
| 1037 | self.field = field |
| 1038 | else: |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 1039 | self.field = None |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1040 | return |
| 1041 | |
| 1042 | def pack(self): |
| 1043 | packed = [] |
| 1044 | packed.append(struct.pack("!H", self.type)) |
| 1045 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 1046 | packed.append(self.field.pack()) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1047 | length = sum([len(x) for x in packed]) |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 1048 | packed.append(loxi.generic_util.pad_to(8, length)) |
| 1049 | length += len(packed[-1]) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1050 | packed[1] = struct.pack("!H", length) |
| 1051 | return ''.join(packed) |
| 1052 | |
| 1053 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1054 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1055 | obj = set_field() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1056 | _type = reader.read("!H")[0] |
| 1057 | assert(_type == 25) |
| 1058 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1059 | orig_reader = reader |
| 1060 | reader = orig_reader.slice(_len - (2 + 2)) |
| 1061 | obj.field = oxm.oxm.unpack(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1062 | return obj |
| 1063 | |
| 1064 | def __eq__(self, other): |
| 1065 | if type(self) != type(other): return False |
| 1066 | if self.field != other.field: return False |
| 1067 | return True |
| 1068 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1069 | def pretty_print(self, q): |
| 1070 | q.text("set_field {") |
| 1071 | with q.group(): |
| 1072 | with q.indent(2): |
| 1073 | q.breakable() |
| 1074 | q.text("field = "); |
| 1075 | q.pp(self.field) |
| 1076 | q.breakable() |
| 1077 | q.text('}') |
| 1078 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1079 | action.subtypes[25] = set_field |
| 1080 | |
| 1081 | class set_mpls_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1082 | type = 15 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1083 | |
| 1084 | def __init__(self, mpls_ttl=None): |
| 1085 | if mpls_ttl != None: |
| 1086 | self.mpls_ttl = mpls_ttl |
| 1087 | else: |
| 1088 | self.mpls_ttl = 0 |
| 1089 | return |
| 1090 | |
| 1091 | def pack(self): |
| 1092 | packed = [] |
| 1093 | packed.append(struct.pack("!H", self.type)) |
| 1094 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1095 | packed.append(struct.pack("!B", self.mpls_ttl)) |
| 1096 | packed.append('\x00' * 3) |
| 1097 | length = sum([len(x) for x in packed]) |
| 1098 | packed[1] = struct.pack("!H", length) |
| 1099 | return ''.join(packed) |
| 1100 | |
| 1101 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1102 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1103 | obj = set_mpls_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1104 | _type = reader.read("!H")[0] |
| 1105 | assert(_type == 15) |
| 1106 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1107 | orig_reader = reader |
| 1108 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1109 | obj.mpls_ttl = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1110 | reader.skip(3) |
| 1111 | return obj |
| 1112 | |
| 1113 | def __eq__(self, other): |
| 1114 | if type(self) != type(other): return False |
| 1115 | if self.mpls_ttl != other.mpls_ttl: return False |
| 1116 | return True |
| 1117 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1118 | def pretty_print(self, q): |
| 1119 | q.text("set_mpls_ttl {") |
| 1120 | with q.group(): |
| 1121 | with q.indent(2): |
| 1122 | q.breakable() |
| 1123 | q.text("mpls_ttl = "); |
| 1124 | q.text("%#x" % self.mpls_ttl) |
| 1125 | q.breakable() |
| 1126 | q.text('}') |
| 1127 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1128 | action.subtypes[15] = set_mpls_ttl |
| 1129 | |
| 1130 | class set_nw_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1131 | type = 23 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1132 | |
| 1133 | def __init__(self, nw_ttl=None): |
| 1134 | if nw_ttl != None: |
| 1135 | self.nw_ttl = nw_ttl |
| 1136 | else: |
| 1137 | self.nw_ttl = 0 |
| 1138 | return |
| 1139 | |
| 1140 | def pack(self): |
| 1141 | packed = [] |
| 1142 | packed.append(struct.pack("!H", self.type)) |
| 1143 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1144 | packed.append(struct.pack("!B", self.nw_ttl)) |
| 1145 | packed.append('\x00' * 3) |
| 1146 | length = sum([len(x) for x in packed]) |
| 1147 | packed[1] = struct.pack("!H", length) |
| 1148 | return ''.join(packed) |
| 1149 | |
| 1150 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1151 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1152 | obj = set_nw_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1153 | _type = reader.read("!H")[0] |
| 1154 | assert(_type == 23) |
| 1155 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1156 | orig_reader = reader |
| 1157 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1158 | obj.nw_ttl = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1159 | reader.skip(3) |
| 1160 | return obj |
| 1161 | |
| 1162 | def __eq__(self, other): |
| 1163 | if type(self) != type(other): return False |
| 1164 | if self.nw_ttl != other.nw_ttl: return False |
| 1165 | return True |
| 1166 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1167 | def pretty_print(self, q): |
| 1168 | q.text("set_nw_ttl {") |
| 1169 | with q.group(): |
| 1170 | with q.indent(2): |
| 1171 | q.breakable() |
| 1172 | q.text("nw_ttl = "); |
| 1173 | q.text("%#x" % self.nw_ttl) |
| 1174 | q.breakable() |
| 1175 | q.text('}') |
| 1176 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1177 | action.subtypes[23] = set_nw_ttl |
| 1178 | |
| 1179 | class set_queue(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1180 | type = 21 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1181 | |
| 1182 | def __init__(self, queue_id=None): |
| 1183 | if queue_id != None: |
| 1184 | self.queue_id = queue_id |
| 1185 | else: |
| 1186 | self.queue_id = 0 |
| 1187 | return |
| 1188 | |
| 1189 | def pack(self): |
| 1190 | packed = [] |
| 1191 | packed.append(struct.pack("!H", self.type)) |
| 1192 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1193 | packed.append(struct.pack("!L", self.queue_id)) |
| 1194 | length = sum([len(x) for x in packed]) |
| 1195 | packed[1] = struct.pack("!H", length) |
| 1196 | return ''.join(packed) |
| 1197 | |
| 1198 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1199 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1200 | obj = set_queue() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1201 | _type = reader.read("!H")[0] |
| 1202 | assert(_type == 21) |
| 1203 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1204 | orig_reader = reader |
| 1205 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1206 | obj.queue_id = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1207 | return obj |
| 1208 | |
| 1209 | def __eq__(self, other): |
| 1210 | if type(self) != type(other): return False |
| 1211 | if self.queue_id != other.queue_id: return False |
| 1212 | return True |
| 1213 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1214 | def pretty_print(self, q): |
| 1215 | q.text("set_queue {") |
| 1216 | with q.group(): |
| 1217 | with q.indent(2): |
| 1218 | q.breakable() |
| 1219 | q.text("queue_id = "); |
| 1220 | q.text("%#x" % self.queue_id) |
| 1221 | q.breakable() |
| 1222 | q.text('}') |
| 1223 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1224 | action.subtypes[21] = set_queue |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1225 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1226 | |