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