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 | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 22 | @staticmethod |
| 23 | def unpack(reader): |
| 24 | subtype, = reader.peek('!H', 0) |
| 25 | try: |
| 26 | subclass = action.subtypes[subtype] |
| 27 | except KeyError: |
| 28 | raise loxi.ProtocolError("unknown action subtype %#x" % subtype) |
| 29 | return subclass.unpack(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 30 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 31 | |
| 32 | class experimenter(action): |
| 33 | subtypes = {} |
| 34 | |
| 35 | @staticmethod |
| 36 | def unpack(reader): |
| 37 | subtype, = reader.peek('!L', 4) |
| 38 | try: |
| 39 | subclass = experimenter.subtypes[subtype] |
| 40 | except KeyError: |
| 41 | raise loxi.ProtocolError("unknown experimenter action subtype %#x" % subtype) |
| 42 | return subclass.unpack(reader) |
| 43 | |
| 44 | action.subtypes[65535] = experimenter |
| 45 | |
| 46 | class bsn(experimenter): |
| 47 | subtypes = {} |
| 48 | |
| 49 | @staticmethod |
| 50 | def unpack(reader): |
| 51 | subtype, = reader.peek('!L', 8) |
| 52 | try: |
| 53 | subclass = bsn.subtypes[subtype] |
| 54 | except KeyError: |
| 55 | raise loxi.ProtocolError("unknown bsn experimenter action subtype %#x" % subtype) |
| 56 | return subclass.unpack(reader) |
| 57 | |
| 58 | experimenter.subtypes[6035143] = bsn |
| 59 | |
| 60 | class bsn_mirror(bsn): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 61 | type = 65535 |
| 62 | experimenter = 6035143 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 63 | subtype = 1 |
| 64 | |
| 65 | def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None): |
| 66 | if dest_port != None: |
| 67 | self.dest_port = dest_port |
| 68 | else: |
| 69 | self.dest_port = 0 |
| 70 | if vlan_tag != None: |
| 71 | self.vlan_tag = vlan_tag |
| 72 | else: |
| 73 | self.vlan_tag = 0 |
| 74 | if copy_stage != None: |
| 75 | self.copy_stage = copy_stage |
| 76 | else: |
| 77 | self.copy_stage = 0 |
| 78 | return |
| 79 | |
| 80 | def pack(self): |
| 81 | packed = [] |
| 82 | packed.append(struct.pack("!H", self.type)) |
| 83 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 84 | packed.append(struct.pack("!L", self.experimenter)) |
| 85 | packed.append(struct.pack("!L", self.subtype)) |
| 86 | packed.append(struct.pack("!L", self.dest_port)) |
| 87 | packed.append(struct.pack("!L", self.vlan_tag)) |
| 88 | packed.append(struct.pack("!B", self.copy_stage)) |
| 89 | packed.append('\x00' * 3) |
| 90 | length = sum([len(x) for x in packed]) |
| 91 | packed[1] = struct.pack("!H", length) |
| 92 | return ''.join(packed) |
| 93 | |
| 94 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 95 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 96 | obj = bsn_mirror() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 97 | _type = reader.read("!H")[0] |
| 98 | assert(_type == 65535) |
| 99 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 100 | orig_reader = reader |
| 101 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 102 | _experimenter = reader.read("!L")[0] |
| 103 | assert(_experimenter == 6035143) |
| 104 | _subtype = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 105 | assert(_subtype == 1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 106 | obj.dest_port = reader.read("!L")[0] |
| 107 | obj.vlan_tag = reader.read("!L")[0] |
| 108 | obj.copy_stage = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 109 | reader.skip(3) |
| 110 | return obj |
| 111 | |
| 112 | def __eq__(self, other): |
| 113 | if type(self) != type(other): return False |
| 114 | if self.dest_port != other.dest_port: return False |
| 115 | if self.vlan_tag != other.vlan_tag: return False |
| 116 | if self.copy_stage != other.copy_stage: return False |
| 117 | return True |
| 118 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 119 | def pretty_print(self, q): |
| 120 | q.text("bsn_mirror {") |
| 121 | with q.group(): |
| 122 | with q.indent(2): |
| 123 | q.breakable() |
| 124 | q.text("dest_port = "); |
| 125 | q.text("%#x" % self.dest_port) |
| 126 | q.text(","); q.breakable() |
| 127 | q.text("vlan_tag = "); |
| 128 | q.text("%#x" % self.vlan_tag) |
| 129 | q.text(","); q.breakable() |
| 130 | q.text("copy_stage = "); |
| 131 | q.text("%#x" % self.copy_stage) |
| 132 | q.breakable() |
| 133 | q.text('}') |
| 134 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 135 | bsn.subtypes[1] = bsn_mirror |
| 136 | |
| 137 | class bsn_set_tunnel_dst(bsn): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 138 | type = 65535 |
| 139 | experimenter = 6035143 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 140 | subtype = 2 |
| 141 | |
| 142 | def __init__(self, dst=None): |
| 143 | if dst != None: |
| 144 | self.dst = dst |
| 145 | else: |
| 146 | self.dst = 0 |
| 147 | return |
| 148 | |
| 149 | def pack(self): |
| 150 | packed = [] |
| 151 | packed.append(struct.pack("!H", self.type)) |
| 152 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 153 | packed.append(struct.pack("!L", self.experimenter)) |
| 154 | packed.append(struct.pack("!L", self.subtype)) |
| 155 | packed.append(struct.pack("!L", self.dst)) |
| 156 | length = sum([len(x) for x in packed]) |
| 157 | packed[1] = struct.pack("!H", length) |
| 158 | return ''.join(packed) |
| 159 | |
| 160 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 161 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 162 | obj = bsn_set_tunnel_dst() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 163 | _type = reader.read("!H")[0] |
| 164 | assert(_type == 65535) |
| 165 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 166 | orig_reader = reader |
| 167 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 168 | _experimenter = reader.read("!L")[0] |
| 169 | assert(_experimenter == 6035143) |
| 170 | _subtype = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 171 | assert(_subtype == 2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 172 | obj.dst = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 173 | return obj |
| 174 | |
| 175 | def __eq__(self, other): |
| 176 | if type(self) != type(other): return False |
| 177 | if self.dst != other.dst: return False |
| 178 | return True |
| 179 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 180 | def pretty_print(self, q): |
| 181 | q.text("bsn_set_tunnel_dst {") |
| 182 | with q.group(): |
| 183 | with q.indent(2): |
| 184 | q.breakable() |
| 185 | q.text("dst = "); |
| 186 | q.text("%#x" % self.dst) |
| 187 | q.breakable() |
| 188 | q.text('}') |
| 189 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 190 | bsn.subtypes[2] = bsn_set_tunnel_dst |
| 191 | |
| 192 | class copy_ttl_in(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 193 | type = 12 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 194 | |
| 195 | def __init__(self): |
| 196 | return |
| 197 | |
| 198 | def pack(self): |
| 199 | packed = [] |
| 200 | packed.append(struct.pack("!H", self.type)) |
| 201 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 202 | packed.append('\x00' * 4) |
| 203 | length = sum([len(x) for x in packed]) |
| 204 | packed[1] = struct.pack("!H", length) |
| 205 | return ''.join(packed) |
| 206 | |
| 207 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 208 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 209 | obj = copy_ttl_in() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 210 | _type = reader.read("!H")[0] |
| 211 | assert(_type == 12) |
| 212 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 213 | orig_reader = reader |
| 214 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 215 | reader.skip(4) |
| 216 | return obj |
| 217 | |
| 218 | def __eq__(self, other): |
| 219 | if type(self) != type(other): return False |
| 220 | return True |
| 221 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 222 | def pretty_print(self, q): |
| 223 | q.text("copy_ttl_in {") |
| 224 | with q.group(): |
| 225 | with q.indent(2): |
| 226 | q.breakable() |
| 227 | q.breakable() |
| 228 | q.text('}') |
| 229 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 230 | action.subtypes[12] = copy_ttl_in |
| 231 | |
| 232 | class copy_ttl_out(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 233 | type = 11 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 234 | |
| 235 | def __init__(self): |
| 236 | return |
| 237 | |
| 238 | def pack(self): |
| 239 | packed = [] |
| 240 | packed.append(struct.pack("!H", self.type)) |
| 241 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 242 | packed.append('\x00' * 4) |
| 243 | length = sum([len(x) for x in packed]) |
| 244 | packed[1] = struct.pack("!H", length) |
| 245 | return ''.join(packed) |
| 246 | |
| 247 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 248 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 249 | obj = copy_ttl_out() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 250 | _type = reader.read("!H")[0] |
| 251 | assert(_type == 11) |
| 252 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 253 | orig_reader = reader |
| 254 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 255 | reader.skip(4) |
| 256 | return obj |
| 257 | |
| 258 | def __eq__(self, other): |
| 259 | if type(self) != type(other): return False |
| 260 | return True |
| 261 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 262 | def pretty_print(self, q): |
| 263 | q.text("copy_ttl_out {") |
| 264 | with q.group(): |
| 265 | with q.indent(2): |
| 266 | q.breakable() |
| 267 | q.breakable() |
| 268 | q.text('}') |
| 269 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 270 | action.subtypes[11] = copy_ttl_out |
| 271 | |
| 272 | class dec_mpls_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 273 | type = 16 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 274 | |
| 275 | def __init__(self): |
| 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('\x00' * 4) |
| 283 | length = sum([len(x) for x in packed]) |
| 284 | packed[1] = struct.pack("!H", length) |
| 285 | return ''.join(packed) |
| 286 | |
| 287 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 288 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 289 | obj = dec_mpls_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 290 | _type = reader.read("!H")[0] |
| 291 | assert(_type == 16) |
| 292 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 293 | orig_reader = reader |
| 294 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 295 | reader.skip(4) |
| 296 | return obj |
| 297 | |
| 298 | def __eq__(self, other): |
| 299 | if type(self) != type(other): return False |
| 300 | return True |
| 301 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 302 | def pretty_print(self, q): |
| 303 | q.text("dec_mpls_ttl {") |
| 304 | with q.group(): |
| 305 | with q.indent(2): |
| 306 | q.breakable() |
| 307 | q.breakable() |
| 308 | q.text('}') |
| 309 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 310 | action.subtypes[16] = dec_mpls_ttl |
| 311 | |
| 312 | class dec_nw_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 313 | type = 24 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 314 | |
| 315 | def __init__(self): |
| 316 | return |
| 317 | |
| 318 | def pack(self): |
| 319 | packed = [] |
| 320 | packed.append(struct.pack("!H", self.type)) |
| 321 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 322 | packed.append('\x00' * 4) |
| 323 | length = sum([len(x) for x in packed]) |
| 324 | packed[1] = struct.pack("!H", length) |
| 325 | return ''.join(packed) |
| 326 | |
| 327 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 328 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 329 | obj = dec_nw_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 330 | _type = reader.read("!H")[0] |
| 331 | assert(_type == 24) |
| 332 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 333 | orig_reader = reader |
| 334 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 335 | reader.skip(4) |
| 336 | return obj |
| 337 | |
| 338 | def __eq__(self, other): |
| 339 | if type(self) != type(other): return False |
| 340 | return True |
| 341 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 342 | def pretty_print(self, q): |
| 343 | q.text("dec_nw_ttl {") |
| 344 | with q.group(): |
| 345 | with q.indent(2): |
| 346 | q.breakable() |
| 347 | q.breakable() |
| 348 | q.text('}') |
| 349 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 350 | action.subtypes[24] = dec_nw_ttl |
| 351 | |
| 352 | class group(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 353 | type = 22 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 354 | |
| 355 | def __init__(self, group_id=None): |
| 356 | if group_id != None: |
| 357 | self.group_id = group_id |
| 358 | else: |
| 359 | self.group_id = 0 |
| 360 | return |
| 361 | |
| 362 | def pack(self): |
| 363 | packed = [] |
| 364 | packed.append(struct.pack("!H", self.type)) |
| 365 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 366 | packed.append(struct.pack("!L", self.group_id)) |
| 367 | length = sum([len(x) for x in packed]) |
| 368 | packed[1] = struct.pack("!H", length) |
| 369 | return ''.join(packed) |
| 370 | |
| 371 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 372 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 373 | obj = group() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 374 | _type = reader.read("!H")[0] |
| 375 | assert(_type == 22) |
| 376 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 377 | orig_reader = reader |
| 378 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 379 | obj.group_id = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 380 | return obj |
| 381 | |
| 382 | def __eq__(self, other): |
| 383 | if type(self) != type(other): return False |
| 384 | if self.group_id != other.group_id: return False |
| 385 | return True |
| 386 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 387 | def pretty_print(self, q): |
| 388 | q.text("group {") |
| 389 | with q.group(): |
| 390 | with q.indent(2): |
| 391 | q.breakable() |
| 392 | q.text("group_id = "); |
| 393 | q.text("%#x" % self.group_id) |
| 394 | q.breakable() |
| 395 | q.text('}') |
| 396 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 397 | action.subtypes[22] = group |
| 398 | |
| 399 | class nicira(experimenter): |
| 400 | subtypes = {} |
| 401 | |
| 402 | @staticmethod |
| 403 | def unpack(reader): |
| 404 | subtype, = reader.peek('!H', 8) |
| 405 | try: |
| 406 | subclass = nicira.subtypes[subtype] |
| 407 | except KeyError: |
| 408 | raise loxi.ProtocolError("unknown nicira experimenter action subtype %#x" % subtype) |
| 409 | return subclass.unpack(reader) |
| 410 | |
| 411 | experimenter.subtypes[8992] = nicira |
| 412 | |
| 413 | class nicira_dec_ttl(nicira): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 414 | type = 65535 |
| 415 | experimenter = 8992 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 416 | subtype = 18 |
| 417 | |
| 418 | def __init__(self): |
| 419 | return |
| 420 | |
| 421 | def pack(self): |
| 422 | packed = [] |
| 423 | packed.append(struct.pack("!H", self.type)) |
| 424 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 425 | packed.append(struct.pack("!L", self.experimenter)) |
| 426 | packed.append(struct.pack("!H", self.subtype)) |
| 427 | packed.append('\x00' * 2) |
| 428 | packed.append('\x00' * 4) |
| 429 | length = sum([len(x) for x in packed]) |
| 430 | packed[1] = struct.pack("!H", length) |
| 431 | return ''.join(packed) |
| 432 | |
| 433 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 434 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 435 | obj = nicira_dec_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 436 | _type = reader.read("!H")[0] |
| 437 | assert(_type == 65535) |
| 438 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 439 | orig_reader = reader |
| 440 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 441 | _experimenter = reader.read("!L")[0] |
| 442 | assert(_experimenter == 8992) |
| 443 | _subtype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 444 | assert(_subtype == 18) |
| 445 | reader.skip(2) |
| 446 | reader.skip(4) |
| 447 | return obj |
| 448 | |
| 449 | def __eq__(self, other): |
| 450 | if type(self) != type(other): return False |
| 451 | return True |
| 452 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 453 | def pretty_print(self, q): |
| 454 | q.text("nicira_dec_ttl {") |
| 455 | with q.group(): |
| 456 | with q.indent(2): |
| 457 | q.breakable() |
| 458 | q.breakable() |
| 459 | q.text('}') |
| 460 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 461 | nicira.subtypes[18] = nicira_dec_ttl |
| 462 | |
| 463 | class output(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 464 | type = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 465 | |
| 466 | def __init__(self, port=None, max_len=None): |
| 467 | if port != None: |
| 468 | self.port = port |
| 469 | else: |
| 470 | self.port = 0 |
| 471 | if max_len != None: |
| 472 | self.max_len = max_len |
| 473 | else: |
| 474 | self.max_len = 0 |
| 475 | return |
| 476 | |
| 477 | def pack(self): |
| 478 | packed = [] |
| 479 | packed.append(struct.pack("!H", self.type)) |
| 480 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 481 | packed.append(util.pack_port_no(self.port)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 482 | packed.append(struct.pack("!H", self.max_len)) |
| 483 | packed.append('\x00' * 6) |
| 484 | length = sum([len(x) for x in packed]) |
| 485 | packed[1] = struct.pack("!H", length) |
| 486 | return ''.join(packed) |
| 487 | |
| 488 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 489 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 490 | obj = output() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 491 | _type = reader.read("!H")[0] |
| 492 | assert(_type == 0) |
| 493 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 494 | orig_reader = reader |
| 495 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 496 | obj.port = util.unpack_port_no(reader) |
| 497 | obj.max_len = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 498 | reader.skip(6) |
| 499 | return obj |
| 500 | |
| 501 | def __eq__(self, other): |
| 502 | if type(self) != type(other): return False |
| 503 | if self.port != other.port: return False |
| 504 | if self.max_len != other.max_len: return False |
| 505 | return True |
| 506 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 507 | def pretty_print(self, q): |
| 508 | q.text("output {") |
| 509 | with q.group(): |
| 510 | with q.indent(2): |
| 511 | q.breakable() |
| 512 | q.text("port = "); |
| 513 | q.text(util.pretty_port(self.port)) |
| 514 | q.text(","); q.breakable() |
| 515 | q.text("max_len = "); |
| 516 | q.text("%#x" % self.max_len) |
| 517 | q.breakable() |
| 518 | q.text('}') |
| 519 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 520 | action.subtypes[0] = output |
| 521 | |
| 522 | class pop_mpls(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 523 | type = 20 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 524 | |
| 525 | def __init__(self, ethertype=None): |
| 526 | if ethertype != None: |
| 527 | self.ethertype = ethertype |
| 528 | else: |
| 529 | self.ethertype = 0 |
| 530 | return |
| 531 | |
| 532 | def pack(self): |
| 533 | packed = [] |
| 534 | packed.append(struct.pack("!H", self.type)) |
| 535 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 536 | packed.append(struct.pack("!H", self.ethertype)) |
| 537 | packed.append('\x00' * 2) |
| 538 | length = sum([len(x) for x in packed]) |
| 539 | packed[1] = struct.pack("!H", length) |
| 540 | return ''.join(packed) |
| 541 | |
| 542 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 543 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 544 | obj = pop_mpls() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 545 | _type = reader.read("!H")[0] |
| 546 | assert(_type == 20) |
| 547 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 548 | orig_reader = reader |
| 549 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 550 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 551 | reader.skip(2) |
| 552 | return obj |
| 553 | |
| 554 | def __eq__(self, other): |
| 555 | if type(self) != type(other): return False |
| 556 | if self.ethertype != other.ethertype: return False |
| 557 | return True |
| 558 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 559 | def pretty_print(self, q): |
| 560 | q.text("pop_mpls {") |
| 561 | with q.group(): |
| 562 | with q.indent(2): |
| 563 | q.breakable() |
| 564 | q.text("ethertype = "); |
| 565 | q.text("%#x" % self.ethertype) |
| 566 | q.breakable() |
| 567 | q.text('}') |
| 568 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 569 | action.subtypes[20] = pop_mpls |
| 570 | |
| 571 | class pop_vlan(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 572 | type = 18 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 573 | |
| 574 | def __init__(self): |
| 575 | return |
| 576 | |
| 577 | def pack(self): |
| 578 | packed = [] |
| 579 | packed.append(struct.pack("!H", self.type)) |
| 580 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 581 | packed.append('\x00' * 4) |
| 582 | length = sum([len(x) for x in packed]) |
| 583 | packed[1] = struct.pack("!H", length) |
| 584 | return ''.join(packed) |
| 585 | |
| 586 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 587 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 588 | obj = pop_vlan() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 589 | _type = reader.read("!H")[0] |
| 590 | assert(_type == 18) |
| 591 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 592 | orig_reader = reader |
| 593 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 594 | reader.skip(4) |
| 595 | return obj |
| 596 | |
| 597 | def __eq__(self, other): |
| 598 | if type(self) != type(other): return False |
| 599 | return True |
| 600 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 601 | def pretty_print(self, q): |
| 602 | q.text("pop_vlan {") |
| 603 | with q.group(): |
| 604 | with q.indent(2): |
| 605 | q.breakable() |
| 606 | q.breakable() |
| 607 | q.text('}') |
| 608 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 609 | action.subtypes[18] = pop_vlan |
| 610 | |
| 611 | class push_mpls(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 612 | type = 19 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 613 | |
| 614 | def __init__(self, ethertype=None): |
| 615 | if ethertype != None: |
| 616 | self.ethertype = ethertype |
| 617 | else: |
| 618 | self.ethertype = 0 |
| 619 | return |
| 620 | |
| 621 | def pack(self): |
| 622 | packed = [] |
| 623 | packed.append(struct.pack("!H", self.type)) |
| 624 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 625 | packed.append(struct.pack("!H", self.ethertype)) |
| 626 | packed.append('\x00' * 2) |
| 627 | length = sum([len(x) for x in packed]) |
| 628 | packed[1] = struct.pack("!H", length) |
| 629 | return ''.join(packed) |
| 630 | |
| 631 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 632 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 633 | obj = push_mpls() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 634 | _type = reader.read("!H")[0] |
| 635 | assert(_type == 19) |
| 636 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 637 | orig_reader = reader |
| 638 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 639 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 640 | reader.skip(2) |
| 641 | return obj |
| 642 | |
| 643 | def __eq__(self, other): |
| 644 | if type(self) != type(other): return False |
| 645 | if self.ethertype != other.ethertype: return False |
| 646 | return True |
| 647 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 648 | def pretty_print(self, q): |
| 649 | q.text("push_mpls {") |
| 650 | with q.group(): |
| 651 | with q.indent(2): |
| 652 | q.breakable() |
| 653 | q.text("ethertype = "); |
| 654 | q.text("%#x" % self.ethertype) |
| 655 | q.breakable() |
| 656 | q.text('}') |
| 657 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 658 | action.subtypes[19] = push_mpls |
| 659 | |
| 660 | class push_vlan(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 661 | type = 17 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 662 | |
| 663 | def __init__(self, ethertype=None): |
| 664 | if ethertype != None: |
| 665 | self.ethertype = ethertype |
| 666 | else: |
| 667 | self.ethertype = 0 |
| 668 | return |
| 669 | |
| 670 | def pack(self): |
| 671 | packed = [] |
| 672 | packed.append(struct.pack("!H", self.type)) |
| 673 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 674 | packed.append(struct.pack("!H", self.ethertype)) |
| 675 | packed.append('\x00' * 2) |
| 676 | length = sum([len(x) for x in packed]) |
| 677 | packed[1] = struct.pack("!H", length) |
| 678 | return ''.join(packed) |
| 679 | |
| 680 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 681 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 682 | obj = push_vlan() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 683 | _type = reader.read("!H")[0] |
| 684 | assert(_type == 17) |
| 685 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 686 | orig_reader = reader |
| 687 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 688 | obj.ethertype = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 689 | reader.skip(2) |
| 690 | return obj |
| 691 | |
| 692 | def __eq__(self, other): |
| 693 | if type(self) != type(other): return False |
| 694 | if self.ethertype != other.ethertype: return False |
| 695 | return True |
| 696 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 697 | def pretty_print(self, q): |
| 698 | q.text("push_vlan {") |
| 699 | with q.group(): |
| 700 | with q.indent(2): |
| 701 | q.breakable() |
| 702 | q.text("ethertype = "); |
| 703 | q.text("%#x" % self.ethertype) |
| 704 | q.breakable() |
| 705 | q.text('}') |
| 706 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 707 | action.subtypes[17] = push_vlan |
| 708 | |
| 709 | class set_field(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 710 | type = 25 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 711 | |
| 712 | def __init__(self, field=None): |
| 713 | if field != None: |
| 714 | self.field = field |
| 715 | else: |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 716 | self.field = None |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 717 | return |
| 718 | |
| 719 | def pack(self): |
| 720 | packed = [] |
| 721 | packed.append(struct.pack("!H", self.type)) |
| 722 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 723 | packed.append(self.field.pack()) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 724 | length = sum([len(x) for x in packed]) |
Rich Lane | d53156a | 2013-08-05 17:17:33 -0700 | [diff] [blame] | 725 | packed.append(loxi.generic_util.pad_to(8, length)) |
| 726 | length += len(packed[-1]) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 727 | packed[1] = struct.pack("!H", length) |
| 728 | return ''.join(packed) |
| 729 | |
| 730 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 731 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 732 | obj = set_field() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 733 | _type = reader.read("!H")[0] |
| 734 | assert(_type == 25) |
| 735 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 736 | orig_reader = reader |
| 737 | reader = orig_reader.slice(_len - (2 + 2)) |
| 738 | obj.field = oxm.oxm.unpack(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 739 | return obj |
| 740 | |
| 741 | def __eq__(self, other): |
| 742 | if type(self) != type(other): return False |
| 743 | if self.field != other.field: return False |
| 744 | return True |
| 745 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 746 | def pretty_print(self, q): |
| 747 | q.text("set_field {") |
| 748 | with q.group(): |
| 749 | with q.indent(2): |
| 750 | q.breakable() |
| 751 | q.text("field = "); |
| 752 | q.pp(self.field) |
| 753 | q.breakable() |
| 754 | q.text('}') |
| 755 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 756 | action.subtypes[25] = set_field |
| 757 | |
| 758 | class set_mpls_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 759 | type = 15 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 760 | |
| 761 | def __init__(self, mpls_ttl=None): |
| 762 | if mpls_ttl != None: |
| 763 | self.mpls_ttl = mpls_ttl |
| 764 | else: |
| 765 | self.mpls_ttl = 0 |
| 766 | return |
| 767 | |
| 768 | def pack(self): |
| 769 | packed = [] |
| 770 | packed.append(struct.pack("!H", self.type)) |
| 771 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 772 | packed.append(struct.pack("!B", self.mpls_ttl)) |
| 773 | packed.append('\x00' * 3) |
| 774 | length = sum([len(x) for x in packed]) |
| 775 | packed[1] = struct.pack("!H", length) |
| 776 | return ''.join(packed) |
| 777 | |
| 778 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 779 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 780 | obj = set_mpls_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 781 | _type = reader.read("!H")[0] |
| 782 | assert(_type == 15) |
| 783 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 784 | orig_reader = reader |
| 785 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 786 | obj.mpls_ttl = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 787 | reader.skip(3) |
| 788 | return obj |
| 789 | |
| 790 | def __eq__(self, other): |
| 791 | if type(self) != type(other): return False |
| 792 | if self.mpls_ttl != other.mpls_ttl: return False |
| 793 | return True |
| 794 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 795 | def pretty_print(self, q): |
| 796 | q.text("set_mpls_ttl {") |
| 797 | with q.group(): |
| 798 | with q.indent(2): |
| 799 | q.breakable() |
| 800 | q.text("mpls_ttl = "); |
| 801 | q.text("%#x" % self.mpls_ttl) |
| 802 | q.breakable() |
| 803 | q.text('}') |
| 804 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 805 | action.subtypes[15] = set_mpls_ttl |
| 806 | |
| 807 | class set_nw_ttl(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 808 | type = 23 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 809 | |
| 810 | def __init__(self, nw_ttl=None): |
| 811 | if nw_ttl != None: |
| 812 | self.nw_ttl = nw_ttl |
| 813 | else: |
| 814 | self.nw_ttl = 0 |
| 815 | return |
| 816 | |
| 817 | def pack(self): |
| 818 | packed = [] |
| 819 | packed.append(struct.pack("!H", self.type)) |
| 820 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 821 | packed.append(struct.pack("!B", self.nw_ttl)) |
| 822 | packed.append('\x00' * 3) |
| 823 | length = sum([len(x) for x in packed]) |
| 824 | packed[1] = struct.pack("!H", length) |
| 825 | return ''.join(packed) |
| 826 | |
| 827 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 828 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 829 | obj = set_nw_ttl() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 830 | _type = reader.read("!H")[0] |
| 831 | assert(_type == 23) |
| 832 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 833 | orig_reader = reader |
| 834 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 835 | obj.nw_ttl = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 836 | reader.skip(3) |
| 837 | return obj |
| 838 | |
| 839 | def __eq__(self, other): |
| 840 | if type(self) != type(other): return False |
| 841 | if self.nw_ttl != other.nw_ttl: return False |
| 842 | return True |
| 843 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 844 | def pretty_print(self, q): |
| 845 | q.text("set_nw_ttl {") |
| 846 | with q.group(): |
| 847 | with q.indent(2): |
| 848 | q.breakable() |
| 849 | q.text("nw_ttl = "); |
| 850 | q.text("%#x" % self.nw_ttl) |
| 851 | q.breakable() |
| 852 | q.text('}') |
| 853 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 854 | action.subtypes[23] = set_nw_ttl |
| 855 | |
| 856 | class set_queue(action): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 857 | type = 21 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 858 | |
| 859 | def __init__(self, queue_id=None): |
| 860 | if queue_id != None: |
| 861 | self.queue_id = queue_id |
| 862 | else: |
| 863 | self.queue_id = 0 |
| 864 | return |
| 865 | |
| 866 | def pack(self): |
| 867 | packed = [] |
| 868 | packed.append(struct.pack("!H", self.type)) |
| 869 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 870 | packed.append(struct.pack("!L", self.queue_id)) |
| 871 | length = sum([len(x) for x in packed]) |
| 872 | packed[1] = struct.pack("!H", length) |
| 873 | return ''.join(packed) |
| 874 | |
| 875 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 876 | def unpack(reader): |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 877 | obj = set_queue() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 878 | _type = reader.read("!H")[0] |
| 879 | assert(_type == 21) |
| 880 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 881 | orig_reader = reader |
| 882 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 883 | obj.queue_id = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 884 | return obj |
| 885 | |
| 886 | def __eq__(self, other): |
| 887 | if type(self) != type(other): return False |
| 888 | if self.queue_id != other.queue_id: return False |
| 889 | return True |
| 890 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 891 | def pretty_print(self, q): |
| 892 | q.text("set_queue {") |
| 893 | with q.group(): |
| 894 | with q.indent(2): |
| 895 | q.breakable() |
| 896 | q.text("queue_id = "); |
| 897 | q.text("%#x" % self.queue_id) |
| 898 | q.breakable() |
| 899 | q.text('}') |
| 900 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame^] | 901 | action.subtypes[21] = set_queue |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 902 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 903 | |