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