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