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