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