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