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