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