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