Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 4 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 5 | |
| 6 | # Automatically generated by LOXI from template common.py |
| 7 | # Do not modify |
| 8 | |
| 9 | import sys |
| 10 | import struct |
| 11 | import action |
| 12 | import instruction # for unpack_list |
| 13 | import const |
| 14 | import util |
| 15 | import loxi.generic_util |
| 16 | |
| 17 | |
| 18 | # HACK make this module visible as 'common' to simplify code generation |
| 19 | common = sys.modules[__name__] |
| 20 | |
| 21 | def unpack_list_flow_stats_entry(reader): |
| 22 | return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack) |
| 23 | |
| 24 | def unpack_list_queue_prop(reader): |
| 25 | def deserializer(reader, typ): |
| 26 | if typ == const.OFPQT_MIN_RATE: |
| 27 | return queue_prop_min_rate.unpack(reader) |
| 28 | else: |
| 29 | raise loxi.ProtocolError("unknown queue prop %d" % typ) |
| 30 | return loxi.generic_util.unpack_list_tlv16(reader, deserializer) |
| 31 | |
| 32 | def unpack_list_packet_queue(reader): |
| 33 | def wrapper(reader): |
| 34 | length, = reader.peek('!4xH') |
| 35 | return packet_queue.unpack(reader.slice(length)) |
| 36 | return loxi.generic_util.unpack_list(reader, wrapper) |
| 37 | |
| 38 | def unpack_list_hello_elem(reader): |
| 39 | def deserializer(reader, typ): |
| 40 | if typ == const.OFPHET_VERSIONBITMAP: |
| 41 | return hello_elem_versionbitmap.unpack(reader) |
| 42 | else: |
| 43 | return None |
| 44 | return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None] |
| 45 | |
| 46 | def unpack_list_bucket(reader): |
| 47 | return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack) |
| 48 | |
| 49 | def unpack_list_group_desc_stats_entry(reader): |
| 50 | return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack) |
| 51 | |
| 52 | def unpack_list_group_stats_entry(reader): |
| 53 | return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack) |
| 54 | |
| 55 | def unpack_list_meter_stats(reader): |
| 56 | def wrapper(reader): |
| 57 | length, = reader.peek('!4xH') |
| 58 | return meter_stats.unpack(reader.slice(length)) |
| 59 | return loxi.generic_util.unpack_list(reader, wrapper) |
| 60 | |
| 61 | class bsn_interface(object): |
| 62 | |
| 63 | def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None): |
| 64 | if hw_addr != None: |
| 65 | self.hw_addr = hw_addr |
| 66 | else: |
| 67 | self.hw_addr = [0,0,0,0,0,0] |
| 68 | if name != None: |
| 69 | self.name = name |
| 70 | else: |
| 71 | self.name = "" |
| 72 | if ipv4_addr != None: |
| 73 | self.ipv4_addr = ipv4_addr |
| 74 | else: |
| 75 | self.ipv4_addr = 0 |
| 76 | if ipv4_netmask != None: |
| 77 | self.ipv4_netmask = ipv4_netmask |
| 78 | else: |
| 79 | self.ipv4_netmask = 0 |
| 80 | return |
| 81 | |
| 82 | def pack(self): |
| 83 | packed = [] |
| 84 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 85 | packed.append('\x00' * 2) |
| 86 | packed.append(struct.pack("!16s", self.name)) |
| 87 | packed.append(struct.pack("!L", self.ipv4_addr)) |
| 88 | packed.append(struct.pack("!L", self.ipv4_netmask)) |
| 89 | return ''.join(packed) |
| 90 | |
| 91 | @staticmethod |
| 92 | def unpack(buf): |
| 93 | obj = bsn_interface() |
| 94 | if type(buf) == loxi.generic_util.OFReader: |
| 95 | reader = buf |
| 96 | else: |
| 97 | reader = loxi.generic_util.OFReader(buf) |
| 98 | obj.hw_addr = list(reader.read('!6B')) |
| 99 | reader.skip(2) |
| 100 | obj.name = reader.read("!16s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 101 | obj.ipv4_addr = reader.read("!L")[0] |
| 102 | obj.ipv4_netmask = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 103 | return obj |
| 104 | |
| 105 | def __eq__(self, other): |
| 106 | if type(self) != type(other): return False |
| 107 | if self.hw_addr != other.hw_addr: return False |
| 108 | if self.name != other.name: return False |
| 109 | if self.ipv4_addr != other.ipv4_addr: return False |
| 110 | if self.ipv4_netmask != other.ipv4_netmask: return False |
| 111 | return True |
| 112 | |
| 113 | def __ne__(self, other): |
| 114 | return not self.__eq__(other) |
| 115 | |
| 116 | def show(self): |
| 117 | import loxi.pp |
| 118 | return loxi.pp.pp(self) |
| 119 | |
| 120 | def pretty_print(self, q): |
| 121 | q.text("bsn_interface {") |
| 122 | with q.group(): |
| 123 | with q.indent(2): |
| 124 | q.breakable() |
| 125 | q.text("hw_addr = "); |
| 126 | q.text(util.pretty_mac(self.hw_addr)) |
| 127 | q.text(","); q.breakable() |
| 128 | q.text("name = "); |
| 129 | q.pp(self.name) |
| 130 | q.text(","); q.breakable() |
| 131 | q.text("ipv4_addr = "); |
| 132 | q.text(util.pretty_ipv4(self.ipv4_addr)) |
| 133 | q.text(","); q.breakable() |
| 134 | q.text("ipv4_netmask = "); |
| 135 | q.text(util.pretty_ipv4(self.ipv4_netmask)) |
| 136 | q.breakable() |
| 137 | q.text('}') |
| 138 | |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 139 | class bsn_vport_q_in_q(object): |
| 140 | type = 0 |
| 141 | |
| 142 | def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None): |
| 143 | if port_no != None: |
| 144 | self.port_no = port_no |
| 145 | else: |
| 146 | self.port_no = 0 |
| 147 | if ingress_tpid != None: |
| 148 | self.ingress_tpid = ingress_tpid |
| 149 | else: |
| 150 | self.ingress_tpid = 0 |
| 151 | if ingress_vlan_id != None: |
| 152 | self.ingress_vlan_id = ingress_vlan_id |
| 153 | else: |
| 154 | self.ingress_vlan_id = 0 |
| 155 | if egress_tpid != None: |
| 156 | self.egress_tpid = egress_tpid |
| 157 | else: |
| 158 | self.egress_tpid = 0 |
| 159 | if egress_vlan_id != None: |
| 160 | self.egress_vlan_id = egress_vlan_id |
| 161 | else: |
| 162 | self.egress_vlan_id = 0 |
| 163 | return |
| 164 | |
| 165 | def pack(self): |
| 166 | packed = [] |
| 167 | packed.append(struct.pack("!H", self.type)) |
| 168 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 169 | packed.append(struct.pack("!L", self.port_no)) |
| 170 | packed.append(struct.pack("!H", self.ingress_tpid)) |
| 171 | packed.append(struct.pack("!H", self.ingress_vlan_id)) |
| 172 | packed.append(struct.pack("!H", self.egress_tpid)) |
| 173 | packed.append(struct.pack("!H", self.egress_vlan_id)) |
| 174 | length = sum([len(x) for x in packed]) |
| 175 | packed[1] = struct.pack("!H", length) |
| 176 | return ''.join(packed) |
| 177 | |
| 178 | @staticmethod |
| 179 | def unpack(buf): |
| 180 | obj = bsn_vport_q_in_q() |
| 181 | if type(buf) == loxi.generic_util.OFReader: |
| 182 | reader = buf |
| 183 | else: |
| 184 | reader = loxi.generic_util.OFReader(buf) |
| 185 | _type = reader.read("!H")[0] |
| 186 | assert(_type == 0) |
| 187 | _length = reader.read("!H")[0] |
| 188 | obj.port_no = reader.read("!L")[0] |
| 189 | obj.ingress_tpid = reader.read("!H")[0] |
| 190 | obj.ingress_vlan_id = reader.read("!H")[0] |
| 191 | obj.egress_tpid = reader.read("!H")[0] |
| 192 | obj.egress_vlan_id = reader.read("!H")[0] |
| 193 | return obj |
| 194 | |
| 195 | def __eq__(self, other): |
| 196 | if type(self) != type(other): return False |
| 197 | if self.port_no != other.port_no: return False |
| 198 | if self.ingress_tpid != other.ingress_tpid: return False |
| 199 | if self.ingress_vlan_id != other.ingress_vlan_id: return False |
| 200 | if self.egress_tpid != other.egress_tpid: return False |
| 201 | if self.egress_vlan_id != other.egress_vlan_id: return False |
| 202 | return True |
| 203 | |
| 204 | def __ne__(self, other): |
| 205 | return not self.__eq__(other) |
| 206 | |
| 207 | def show(self): |
| 208 | import loxi.pp |
| 209 | return loxi.pp.pp(self) |
| 210 | |
| 211 | def pretty_print(self, q): |
| 212 | q.text("bsn_vport_q_in_q {") |
| 213 | with q.group(): |
| 214 | with q.indent(2): |
| 215 | q.breakable() |
| 216 | q.text("port_no = "); |
| 217 | q.text("%#x" % self.port_no) |
| 218 | q.text(","); q.breakable() |
| 219 | q.text("ingress_tpid = "); |
| 220 | q.text("%#x" % self.ingress_tpid) |
| 221 | q.text(","); q.breakable() |
| 222 | q.text("ingress_vlan_id = "); |
| 223 | q.text("%#x" % self.ingress_vlan_id) |
| 224 | q.text(","); q.breakable() |
| 225 | q.text("egress_tpid = "); |
| 226 | q.text("%#x" % self.egress_tpid) |
| 227 | q.text(","); q.breakable() |
| 228 | q.text("egress_vlan_id = "); |
| 229 | q.text("%#x" % self.egress_vlan_id) |
| 230 | q.breakable() |
| 231 | q.text('}') |
| 232 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 233 | class bucket(object): |
| 234 | |
| 235 | def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None): |
| 236 | if weight != None: |
| 237 | self.weight = weight |
| 238 | else: |
| 239 | self.weight = 0 |
| 240 | if watch_port != None: |
| 241 | self.watch_port = watch_port |
| 242 | else: |
| 243 | self.watch_port = 0 |
| 244 | if watch_group != None: |
| 245 | self.watch_group = watch_group |
| 246 | else: |
| 247 | self.watch_group = 0 |
| 248 | if actions != None: |
| 249 | self.actions = actions |
| 250 | else: |
| 251 | self.actions = [] |
| 252 | return |
| 253 | |
| 254 | def pack(self): |
| 255 | packed = [] |
| 256 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 0 |
| 257 | packed.append(struct.pack("!H", self.weight)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 258 | packed.append(util.pack_port_no(self.watch_port)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 259 | packed.append(struct.pack("!L", self.watch_group)) |
| 260 | packed.append('\x00' * 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 261 | packed.append(util.pack_list(self.actions)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 262 | length = sum([len(x) for x in packed]) |
| 263 | packed[0] = struct.pack("!H", length) |
| 264 | return ''.join(packed) |
| 265 | |
| 266 | @staticmethod |
| 267 | def unpack(buf): |
| 268 | obj = bucket() |
| 269 | if type(buf) == loxi.generic_util.OFReader: |
| 270 | reader = buf |
| 271 | else: |
| 272 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 273 | _len = reader.read("!H")[0] |
| 274 | obj.weight = reader.read("!H")[0] |
| 275 | obj.watch_port = util.unpack_port_no(reader) |
| 276 | obj.watch_group = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 277 | reader.skip(4) |
| 278 | obj.actions = action.unpack_list(reader) |
| 279 | return obj |
| 280 | |
| 281 | def __eq__(self, other): |
| 282 | if type(self) != type(other): return False |
| 283 | if self.weight != other.weight: return False |
| 284 | if self.watch_port != other.watch_port: return False |
| 285 | if self.watch_group != other.watch_group: return False |
| 286 | if self.actions != other.actions: return False |
| 287 | return True |
| 288 | |
| 289 | def __ne__(self, other): |
| 290 | return not self.__eq__(other) |
| 291 | |
| 292 | def show(self): |
| 293 | import loxi.pp |
| 294 | return loxi.pp.pp(self) |
| 295 | |
| 296 | def pretty_print(self, q): |
| 297 | q.text("bucket {") |
| 298 | with q.group(): |
| 299 | with q.indent(2): |
| 300 | q.breakable() |
| 301 | q.text("weight = "); |
| 302 | q.text("%#x" % self.weight) |
| 303 | q.text(","); q.breakable() |
| 304 | q.text("watch_port = "); |
| 305 | q.text(util.pretty_port(self.watch_port)) |
| 306 | q.text(","); q.breakable() |
| 307 | q.text("watch_group = "); |
| 308 | q.text("%#x" % self.watch_group) |
| 309 | q.text(","); q.breakable() |
| 310 | q.text("actions = "); |
| 311 | q.pp(self.actions) |
| 312 | q.breakable() |
| 313 | q.text('}') |
| 314 | |
| 315 | class bucket_counter(object): |
| 316 | |
| 317 | def __init__(self, packet_count=None, byte_count=None): |
| 318 | if packet_count != None: |
| 319 | self.packet_count = packet_count |
| 320 | else: |
| 321 | self.packet_count = 0 |
| 322 | if byte_count != None: |
| 323 | self.byte_count = byte_count |
| 324 | else: |
| 325 | self.byte_count = 0 |
| 326 | return |
| 327 | |
| 328 | def pack(self): |
| 329 | packed = [] |
| 330 | packed.append(struct.pack("!Q", self.packet_count)) |
| 331 | packed.append(struct.pack("!Q", self.byte_count)) |
| 332 | return ''.join(packed) |
| 333 | |
| 334 | @staticmethod |
| 335 | def unpack(buf): |
| 336 | obj = bucket_counter() |
| 337 | if type(buf) == loxi.generic_util.OFReader: |
| 338 | reader = buf |
| 339 | else: |
| 340 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 341 | obj.packet_count = reader.read("!Q")[0] |
| 342 | obj.byte_count = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 343 | return obj |
| 344 | |
| 345 | def __eq__(self, other): |
| 346 | if type(self) != type(other): return False |
| 347 | if self.packet_count != other.packet_count: return False |
| 348 | if self.byte_count != other.byte_count: return False |
| 349 | return True |
| 350 | |
| 351 | def __ne__(self, other): |
| 352 | return not self.__eq__(other) |
| 353 | |
| 354 | def show(self): |
| 355 | import loxi.pp |
| 356 | return loxi.pp.pp(self) |
| 357 | |
| 358 | def pretty_print(self, q): |
| 359 | q.text("bucket_counter {") |
| 360 | with q.group(): |
| 361 | with q.indent(2): |
| 362 | q.breakable() |
| 363 | q.text("packet_count = "); |
| 364 | q.text("%#x" % self.packet_count) |
| 365 | q.text(","); q.breakable() |
| 366 | q.text("byte_count = "); |
| 367 | q.text("%#x" % self.byte_count) |
| 368 | q.breakable() |
| 369 | q.text('}') |
| 370 | |
| 371 | class flow_stats_entry(object): |
| 372 | |
| 373 | def __init__(self, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, match=None, instructions=None): |
| 374 | if table_id != None: |
| 375 | self.table_id = table_id |
| 376 | else: |
| 377 | self.table_id = 0 |
| 378 | if duration_sec != None: |
| 379 | self.duration_sec = duration_sec |
| 380 | else: |
| 381 | self.duration_sec = 0 |
| 382 | if duration_nsec != None: |
| 383 | self.duration_nsec = duration_nsec |
| 384 | else: |
| 385 | self.duration_nsec = 0 |
| 386 | if priority != None: |
| 387 | self.priority = priority |
| 388 | else: |
| 389 | self.priority = 0 |
| 390 | if idle_timeout != None: |
| 391 | self.idle_timeout = idle_timeout |
| 392 | else: |
| 393 | self.idle_timeout = 0 |
| 394 | if hard_timeout != None: |
| 395 | self.hard_timeout = hard_timeout |
| 396 | else: |
| 397 | self.hard_timeout = 0 |
| 398 | if cookie != None: |
| 399 | self.cookie = cookie |
| 400 | else: |
| 401 | self.cookie = 0 |
| 402 | if packet_count != None: |
| 403 | self.packet_count = packet_count |
| 404 | else: |
| 405 | self.packet_count = 0 |
| 406 | if byte_count != None: |
| 407 | self.byte_count = byte_count |
| 408 | else: |
| 409 | self.byte_count = 0 |
| 410 | if match != None: |
| 411 | self.match = match |
| 412 | else: |
| 413 | self.match = common.match() |
| 414 | if instructions != None: |
| 415 | self.instructions = instructions |
| 416 | else: |
| 417 | self.instructions = [] |
| 418 | return |
| 419 | |
| 420 | def pack(self): |
| 421 | packed = [] |
| 422 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 423 | packed.append(struct.pack("!B", self.table_id)) |
| 424 | packed.append('\x00' * 1) |
| 425 | packed.append(struct.pack("!L", self.duration_sec)) |
| 426 | packed.append(struct.pack("!L", self.duration_nsec)) |
| 427 | packed.append(struct.pack("!H", self.priority)) |
| 428 | packed.append(struct.pack("!H", self.idle_timeout)) |
| 429 | packed.append(struct.pack("!H", self.hard_timeout)) |
| 430 | packed.append('\x00' * 6) |
| 431 | packed.append(struct.pack("!Q", self.cookie)) |
| 432 | packed.append(struct.pack("!Q", self.packet_count)) |
| 433 | packed.append(struct.pack("!Q", self.byte_count)) |
| 434 | packed.append(self.match.pack()) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 435 | packed.append(util.pack_list(self.instructions)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 436 | length = sum([len(x) for x in packed]) |
| 437 | packed[0] = struct.pack("!H", length) |
| 438 | return ''.join(packed) |
| 439 | |
| 440 | @staticmethod |
| 441 | def unpack(buf): |
| 442 | obj = flow_stats_entry() |
| 443 | if type(buf) == loxi.generic_util.OFReader: |
| 444 | reader = buf |
| 445 | else: |
| 446 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 447 | _length = reader.read("!H")[0] |
| 448 | obj.table_id = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 449 | reader.skip(1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 450 | obj.duration_sec = reader.read("!L")[0] |
| 451 | obj.duration_nsec = reader.read("!L")[0] |
| 452 | obj.priority = reader.read("!H")[0] |
| 453 | obj.idle_timeout = reader.read("!H")[0] |
| 454 | obj.hard_timeout = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 455 | reader.skip(6) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 456 | obj.cookie = reader.read("!Q")[0] |
| 457 | obj.packet_count = reader.read("!Q")[0] |
| 458 | obj.byte_count = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 459 | obj.match = common.match.unpack(reader) |
| 460 | obj.instructions = instruction.unpack_list(reader) |
| 461 | return obj |
| 462 | |
| 463 | def __eq__(self, other): |
| 464 | if type(self) != type(other): return False |
| 465 | if self.table_id != other.table_id: return False |
| 466 | if self.duration_sec != other.duration_sec: return False |
| 467 | if self.duration_nsec != other.duration_nsec: return False |
| 468 | if self.priority != other.priority: return False |
| 469 | if self.idle_timeout != other.idle_timeout: return False |
| 470 | if self.hard_timeout != other.hard_timeout: return False |
| 471 | if self.cookie != other.cookie: return False |
| 472 | if self.packet_count != other.packet_count: return False |
| 473 | if self.byte_count != other.byte_count: return False |
| 474 | if self.match != other.match: return False |
| 475 | if self.instructions != other.instructions: return False |
| 476 | return True |
| 477 | |
| 478 | def __ne__(self, other): |
| 479 | return not self.__eq__(other) |
| 480 | |
| 481 | def show(self): |
| 482 | import loxi.pp |
| 483 | return loxi.pp.pp(self) |
| 484 | |
| 485 | def pretty_print(self, q): |
| 486 | q.text("flow_stats_entry {") |
| 487 | with q.group(): |
| 488 | with q.indent(2): |
| 489 | q.breakable() |
| 490 | q.text("table_id = "); |
| 491 | q.text("%#x" % self.table_id) |
| 492 | q.text(","); q.breakable() |
| 493 | q.text("duration_sec = "); |
| 494 | q.text("%#x" % self.duration_sec) |
| 495 | q.text(","); q.breakable() |
| 496 | q.text("duration_nsec = "); |
| 497 | q.text("%#x" % self.duration_nsec) |
| 498 | q.text(","); q.breakable() |
| 499 | q.text("priority = "); |
| 500 | q.text("%#x" % self.priority) |
| 501 | q.text(","); q.breakable() |
| 502 | q.text("idle_timeout = "); |
| 503 | q.text("%#x" % self.idle_timeout) |
| 504 | q.text(","); q.breakable() |
| 505 | q.text("hard_timeout = "); |
| 506 | q.text("%#x" % self.hard_timeout) |
| 507 | q.text(","); q.breakable() |
| 508 | q.text("cookie = "); |
| 509 | q.text("%#x" % self.cookie) |
| 510 | q.text(","); q.breakable() |
| 511 | q.text("packet_count = "); |
| 512 | q.text("%#x" % self.packet_count) |
| 513 | q.text(","); q.breakable() |
| 514 | q.text("byte_count = "); |
| 515 | q.text("%#x" % self.byte_count) |
| 516 | q.text(","); q.breakable() |
| 517 | q.text("match = "); |
| 518 | q.pp(self.match) |
| 519 | q.text(","); q.breakable() |
| 520 | q.text("instructions = "); |
| 521 | q.pp(self.instructions) |
| 522 | q.breakable() |
| 523 | q.text('}') |
| 524 | |
| 525 | class group_desc_stats_entry(object): |
| 526 | |
| 527 | def __init__(self, type=None, group_id=None, buckets=None): |
| 528 | if type != None: |
| 529 | self.type = type |
| 530 | else: |
| 531 | self.type = 0 |
| 532 | if group_id != None: |
| 533 | self.group_id = group_id |
| 534 | else: |
| 535 | self.group_id = 0 |
| 536 | if buckets != None: |
| 537 | self.buckets = buckets |
| 538 | else: |
| 539 | self.buckets = [] |
| 540 | return |
| 541 | |
| 542 | def pack(self): |
| 543 | packed = [] |
| 544 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 545 | packed.append(struct.pack("!B", self.type)) |
| 546 | packed.append('\x00' * 1) |
| 547 | packed.append(struct.pack("!L", self.group_id)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 548 | packed.append(util.pack_list(self.buckets)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 549 | length = sum([len(x) for x in packed]) |
| 550 | packed[0] = struct.pack("!H", length) |
| 551 | return ''.join(packed) |
| 552 | |
| 553 | @staticmethod |
| 554 | def unpack(buf): |
| 555 | obj = group_desc_stats_entry() |
| 556 | if type(buf) == loxi.generic_util.OFReader: |
| 557 | reader = buf |
| 558 | else: |
| 559 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 560 | _length = reader.read("!H")[0] |
| 561 | obj.type = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 562 | reader.skip(1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 563 | obj.group_id = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 564 | obj.buckets = common.unpack_list_bucket(reader) |
| 565 | return obj |
| 566 | |
| 567 | def __eq__(self, other): |
| 568 | if type(self) != type(other): return False |
| 569 | if self.type != other.type: return False |
| 570 | if self.group_id != other.group_id: return False |
| 571 | if self.buckets != other.buckets: return False |
| 572 | return True |
| 573 | |
| 574 | def __ne__(self, other): |
| 575 | return not self.__eq__(other) |
| 576 | |
| 577 | def show(self): |
| 578 | import loxi.pp |
| 579 | return loxi.pp.pp(self) |
| 580 | |
| 581 | def pretty_print(self, q): |
| 582 | q.text("group_desc_stats_entry {") |
| 583 | with q.group(): |
| 584 | with q.indent(2): |
| 585 | q.breakable() |
| 586 | q.text("type = "); |
| 587 | q.text("%#x" % self.type) |
| 588 | q.text(","); q.breakable() |
| 589 | q.text("group_id = "); |
| 590 | q.text("%#x" % self.group_id) |
| 591 | q.text(","); q.breakable() |
| 592 | q.text("buckets = "); |
| 593 | q.pp(self.buckets) |
| 594 | q.breakable() |
| 595 | q.text('}') |
| 596 | |
| 597 | class group_stats_entry(object): |
| 598 | |
| 599 | def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None): |
| 600 | if group_id != None: |
| 601 | self.group_id = group_id |
| 602 | else: |
| 603 | self.group_id = 0 |
| 604 | if ref_count != None: |
| 605 | self.ref_count = ref_count |
| 606 | else: |
| 607 | self.ref_count = 0 |
| 608 | if packet_count != None: |
| 609 | self.packet_count = packet_count |
| 610 | else: |
| 611 | self.packet_count = 0 |
| 612 | if byte_count != None: |
| 613 | self.byte_count = byte_count |
| 614 | else: |
| 615 | self.byte_count = 0 |
| 616 | if bucket_stats != None: |
| 617 | self.bucket_stats = bucket_stats |
| 618 | else: |
| 619 | self.bucket_stats = [] |
| 620 | return |
| 621 | |
| 622 | def pack(self): |
| 623 | packed = [] |
| 624 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 625 | packed.append('\x00' * 2) |
| 626 | packed.append(struct.pack("!L", self.group_id)) |
| 627 | packed.append(struct.pack("!L", self.ref_count)) |
| 628 | packed.append('\x00' * 4) |
| 629 | packed.append(struct.pack("!Q", self.packet_count)) |
| 630 | packed.append(struct.pack("!Q", self.byte_count)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 631 | packed.append(util.pack_list(self.bucket_stats)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 632 | length = sum([len(x) for x in packed]) |
| 633 | packed[0] = struct.pack("!H", length) |
| 634 | return ''.join(packed) |
| 635 | |
| 636 | @staticmethod |
| 637 | def unpack(buf): |
| 638 | obj = group_stats_entry() |
| 639 | if type(buf) == loxi.generic_util.OFReader: |
| 640 | reader = buf |
| 641 | else: |
| 642 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 643 | _length = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 644 | reader.skip(2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 645 | obj.group_id = reader.read("!L")[0] |
| 646 | obj.ref_count = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 647 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 648 | obj.packet_count = reader.read("!Q")[0] |
| 649 | obj.byte_count = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 650 | obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack) |
| 651 | return obj |
| 652 | |
| 653 | def __eq__(self, other): |
| 654 | if type(self) != type(other): return False |
| 655 | if self.group_id != other.group_id: return False |
| 656 | if self.ref_count != other.ref_count: return False |
| 657 | if self.packet_count != other.packet_count: return False |
| 658 | if self.byte_count != other.byte_count: return False |
| 659 | if self.bucket_stats != other.bucket_stats: return False |
| 660 | return True |
| 661 | |
| 662 | def __ne__(self, other): |
| 663 | return not self.__eq__(other) |
| 664 | |
| 665 | def show(self): |
| 666 | import loxi.pp |
| 667 | return loxi.pp.pp(self) |
| 668 | |
| 669 | def pretty_print(self, q): |
| 670 | q.text("group_stats_entry {") |
| 671 | with q.group(): |
| 672 | with q.indent(2): |
| 673 | q.breakable() |
| 674 | q.text("group_id = "); |
| 675 | q.text("%#x" % self.group_id) |
| 676 | q.text(","); q.breakable() |
| 677 | q.text("ref_count = "); |
| 678 | q.text("%#x" % self.ref_count) |
| 679 | q.text(","); q.breakable() |
| 680 | q.text("packet_count = "); |
| 681 | q.text("%#x" % self.packet_count) |
| 682 | q.text(","); q.breakable() |
| 683 | q.text("byte_count = "); |
| 684 | q.text("%#x" % self.byte_count) |
| 685 | q.text(","); q.breakable() |
| 686 | q.text("bucket_stats = "); |
| 687 | q.pp(self.bucket_stats) |
| 688 | q.breakable() |
| 689 | q.text('}') |
| 690 | |
| 691 | class match_v2(object): |
| 692 | type = 0 |
| 693 | |
| 694 | def __init__(self, in_port=None, wildcards=None, eth_src=None, eth_src_mask=None, eth_dst=None, eth_dst_mask=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_src_mask=None, ipv4_dst=None, ipv4_dst_mask=None, tcp_src=None, tcp_dst=None, mpls_label=None, mpls_tc=None, metadata=None, metadata_mask=None): |
| 695 | if in_port != None: |
| 696 | self.in_port = in_port |
| 697 | else: |
| 698 | self.in_port = 0 |
| 699 | if wildcards != None: |
| 700 | self.wildcards = wildcards |
| 701 | else: |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 702 | self.wildcards = util.init_wc_bmap() |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 703 | if eth_src != None: |
| 704 | self.eth_src = eth_src |
| 705 | else: |
| 706 | self.eth_src = [0,0,0,0,0,0] |
| 707 | if eth_src_mask != None: |
| 708 | self.eth_src_mask = eth_src_mask |
| 709 | else: |
| 710 | self.eth_src_mask = [0,0,0,0,0,0] |
| 711 | if eth_dst != None: |
| 712 | self.eth_dst = eth_dst |
| 713 | else: |
| 714 | self.eth_dst = [0,0,0,0,0,0] |
| 715 | if eth_dst_mask != None: |
| 716 | self.eth_dst_mask = eth_dst_mask |
| 717 | else: |
| 718 | self.eth_dst_mask = [0,0,0,0,0,0] |
| 719 | if vlan_vid != None: |
| 720 | self.vlan_vid = vlan_vid |
| 721 | else: |
| 722 | self.vlan_vid = 0 |
| 723 | if vlan_pcp != None: |
| 724 | self.vlan_pcp = vlan_pcp |
| 725 | else: |
| 726 | self.vlan_pcp = 0 |
| 727 | if eth_type != None: |
| 728 | self.eth_type = eth_type |
| 729 | else: |
| 730 | self.eth_type = 0 |
| 731 | if ip_dscp != None: |
| 732 | self.ip_dscp = ip_dscp |
| 733 | else: |
| 734 | self.ip_dscp = 0 |
| 735 | if ip_proto != None: |
| 736 | self.ip_proto = ip_proto |
| 737 | else: |
| 738 | self.ip_proto = 0 |
| 739 | if ipv4_src != None: |
| 740 | self.ipv4_src = ipv4_src |
| 741 | else: |
| 742 | self.ipv4_src = 0 |
| 743 | if ipv4_src_mask != None: |
| 744 | self.ipv4_src_mask = ipv4_src_mask |
| 745 | else: |
| 746 | self.ipv4_src_mask = 0 |
| 747 | if ipv4_dst != None: |
| 748 | self.ipv4_dst = ipv4_dst |
| 749 | else: |
| 750 | self.ipv4_dst = 0 |
| 751 | if ipv4_dst_mask != None: |
| 752 | self.ipv4_dst_mask = ipv4_dst_mask |
| 753 | else: |
| 754 | self.ipv4_dst_mask = 0 |
| 755 | if tcp_src != None: |
| 756 | self.tcp_src = tcp_src |
| 757 | else: |
| 758 | self.tcp_src = 0 |
| 759 | if tcp_dst != None: |
| 760 | self.tcp_dst = tcp_dst |
| 761 | else: |
| 762 | self.tcp_dst = 0 |
| 763 | if mpls_label != None: |
| 764 | self.mpls_label = mpls_label |
| 765 | else: |
| 766 | self.mpls_label = 0 |
| 767 | if mpls_tc != None: |
| 768 | self.mpls_tc = mpls_tc |
| 769 | else: |
| 770 | self.mpls_tc = 0 |
| 771 | if metadata != None: |
| 772 | self.metadata = metadata |
| 773 | else: |
| 774 | self.metadata = 0 |
| 775 | if metadata_mask != None: |
| 776 | self.metadata_mask = metadata_mask |
| 777 | else: |
| 778 | self.metadata_mask = 0 |
| 779 | return |
| 780 | |
| 781 | def pack(self): |
| 782 | packed = [] |
| 783 | packed.append(struct.pack("!H", self.type)) |
| 784 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 785 | packed.append(util.pack_port_no(self.in_port)) |
| 786 | packed.append(util.pack_wc_bmap(self.wildcards)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 787 | packed.append(struct.pack("!6B", *self.eth_src)) |
| 788 | packed.append(struct.pack("!6B", *self.eth_src_mask)) |
| 789 | packed.append(struct.pack("!6B", *self.eth_dst)) |
| 790 | packed.append(struct.pack("!6B", *self.eth_dst_mask)) |
| 791 | packed.append(struct.pack("!H", self.vlan_vid)) |
| 792 | packed.append(struct.pack("!B", self.vlan_pcp)) |
| 793 | packed.append('\x00' * 1) |
| 794 | packed.append(struct.pack("!H", self.eth_type)) |
| 795 | packed.append(struct.pack("!B", self.ip_dscp)) |
| 796 | packed.append(struct.pack("!B", self.ip_proto)) |
| 797 | packed.append(struct.pack("!L", self.ipv4_src)) |
| 798 | packed.append(struct.pack("!L", self.ipv4_src_mask)) |
| 799 | packed.append(struct.pack("!L", self.ipv4_dst)) |
| 800 | packed.append(struct.pack("!L", self.ipv4_dst_mask)) |
| 801 | packed.append(struct.pack("!H", self.tcp_src)) |
| 802 | packed.append(struct.pack("!H", self.tcp_dst)) |
| 803 | packed.append(struct.pack("!L", self.mpls_label)) |
| 804 | packed.append(struct.pack("!B", self.mpls_tc)) |
| 805 | packed.append('\x00' * 3) |
| 806 | packed.append(struct.pack("!Q", self.metadata)) |
| 807 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 808 | length = sum([len(x) for x in packed]) |
| 809 | packed[1] = struct.pack("!H", length) |
| 810 | return ''.join(packed) |
| 811 | |
| 812 | @staticmethod |
| 813 | def unpack(buf): |
| 814 | obj = match_v2() |
| 815 | if type(buf) == loxi.generic_util.OFReader: |
| 816 | reader = buf |
| 817 | else: |
| 818 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 819 | _type = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 820 | assert(_type == 0) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 821 | _length = reader.read("!H")[0] |
| 822 | obj.in_port = util.unpack_port_no(reader) |
| 823 | obj.wildcards = util.unpack_wc_bmap(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 824 | obj.eth_src = list(reader.read('!6B')) |
| 825 | obj.eth_src_mask = list(reader.read('!6B')) |
| 826 | obj.eth_dst = list(reader.read('!6B')) |
| 827 | obj.eth_dst_mask = list(reader.read('!6B')) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 828 | obj.vlan_vid = reader.read("!H")[0] |
| 829 | obj.vlan_pcp = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 830 | reader.skip(1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 831 | obj.eth_type = reader.read("!H")[0] |
| 832 | obj.ip_dscp = reader.read("!B")[0] |
| 833 | obj.ip_proto = reader.read("!B")[0] |
| 834 | obj.ipv4_src = reader.read("!L")[0] |
| 835 | obj.ipv4_src_mask = reader.read("!L")[0] |
| 836 | obj.ipv4_dst = reader.read("!L")[0] |
| 837 | obj.ipv4_dst_mask = reader.read("!L")[0] |
| 838 | obj.tcp_src = reader.read("!H")[0] |
| 839 | obj.tcp_dst = reader.read("!H")[0] |
| 840 | obj.mpls_label = reader.read("!L")[0] |
| 841 | obj.mpls_tc = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 842 | reader.skip(3) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 843 | obj.metadata = reader.read("!Q")[0] |
| 844 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 845 | return obj |
| 846 | |
| 847 | def __eq__(self, other): |
| 848 | if type(self) != type(other): return False |
| 849 | if self.in_port != other.in_port: return False |
| 850 | if self.wildcards != other.wildcards: return False |
| 851 | if self.eth_src != other.eth_src: return False |
| 852 | if self.eth_src_mask != other.eth_src_mask: return False |
| 853 | if self.eth_dst != other.eth_dst: return False |
| 854 | if self.eth_dst_mask != other.eth_dst_mask: return False |
| 855 | if self.vlan_vid != other.vlan_vid: return False |
| 856 | if self.vlan_pcp != other.vlan_pcp: return False |
| 857 | if self.eth_type != other.eth_type: return False |
| 858 | if self.ip_dscp != other.ip_dscp: return False |
| 859 | if self.ip_proto != other.ip_proto: return False |
| 860 | if self.ipv4_src != other.ipv4_src: return False |
| 861 | if self.ipv4_src_mask != other.ipv4_src_mask: return False |
| 862 | if self.ipv4_dst != other.ipv4_dst: return False |
| 863 | if self.ipv4_dst_mask != other.ipv4_dst_mask: return False |
| 864 | if self.tcp_src != other.tcp_src: return False |
| 865 | if self.tcp_dst != other.tcp_dst: return False |
| 866 | if self.mpls_label != other.mpls_label: return False |
| 867 | if self.mpls_tc != other.mpls_tc: return False |
| 868 | if self.metadata != other.metadata: return False |
| 869 | if self.metadata_mask != other.metadata_mask: return False |
| 870 | return True |
| 871 | |
| 872 | def __ne__(self, other): |
| 873 | return not self.__eq__(other) |
| 874 | |
| 875 | def show(self): |
| 876 | import loxi.pp |
| 877 | return loxi.pp.pp(self) |
| 878 | |
| 879 | def pretty_print(self, q): |
| 880 | q.text("match_v2 {") |
| 881 | with q.group(): |
| 882 | with q.indent(2): |
| 883 | q.breakable() |
| 884 | q.text("in_port = "); |
| 885 | q.text(util.pretty_port(self.in_port)) |
| 886 | q.text(","); q.breakable() |
| 887 | q.text("wildcards = "); |
| 888 | q.text(util.pretty_wildcards(self.wildcards)) |
| 889 | q.text(","); q.breakable() |
| 890 | q.text("eth_src = "); |
| 891 | q.text(util.pretty_mac(self.eth_src)) |
| 892 | q.text(","); q.breakable() |
| 893 | q.text("eth_src_mask = "); |
| 894 | q.text(util.pretty_mac(self.eth_src_mask)) |
| 895 | q.text(","); q.breakable() |
| 896 | q.text("eth_dst = "); |
| 897 | q.text(util.pretty_mac(self.eth_dst)) |
| 898 | q.text(","); q.breakable() |
| 899 | q.text("eth_dst_mask = "); |
| 900 | q.text(util.pretty_mac(self.eth_dst_mask)) |
| 901 | q.text(","); q.breakable() |
| 902 | q.text("vlan_vid = "); |
| 903 | q.text("%#x" % self.vlan_vid) |
| 904 | q.text(","); q.breakable() |
| 905 | q.text("vlan_pcp = "); |
| 906 | q.text("%#x" % self.vlan_pcp) |
| 907 | q.text(","); q.breakable() |
| 908 | q.text("eth_type = "); |
| 909 | q.text("%#x" % self.eth_type) |
| 910 | q.text(","); q.breakable() |
| 911 | q.text("ip_dscp = "); |
| 912 | q.text("%#x" % self.ip_dscp) |
| 913 | q.text(","); q.breakable() |
| 914 | q.text("ip_proto = "); |
| 915 | q.text("%#x" % self.ip_proto) |
| 916 | q.text(","); q.breakable() |
| 917 | q.text("ipv4_src = "); |
| 918 | q.text(util.pretty_ipv4(self.ipv4_src)) |
| 919 | q.text(","); q.breakable() |
| 920 | q.text("ipv4_src_mask = "); |
| 921 | q.text(util.pretty_ipv4(self.ipv4_src_mask)) |
| 922 | q.text(","); q.breakable() |
| 923 | q.text("ipv4_dst = "); |
| 924 | q.text(util.pretty_ipv4(self.ipv4_dst)) |
| 925 | q.text(","); q.breakable() |
| 926 | q.text("ipv4_dst_mask = "); |
| 927 | q.text(util.pretty_ipv4(self.ipv4_dst_mask)) |
| 928 | q.text(","); q.breakable() |
| 929 | q.text("tcp_src = "); |
| 930 | q.text("%#x" % self.tcp_src) |
| 931 | q.text(","); q.breakable() |
| 932 | q.text("tcp_dst = "); |
| 933 | q.text("%#x" % self.tcp_dst) |
| 934 | q.text(","); q.breakable() |
| 935 | q.text("mpls_label = "); |
| 936 | q.text("%#x" % self.mpls_label) |
| 937 | q.text(","); q.breakable() |
| 938 | q.text("mpls_tc = "); |
| 939 | q.text("%#x" % self.mpls_tc) |
| 940 | q.text(","); q.breakable() |
| 941 | q.text("metadata = "); |
| 942 | q.text("%#x" % self.metadata) |
| 943 | q.text(","); q.breakable() |
| 944 | q.text("metadata_mask = "); |
| 945 | q.text("%#x" % self.metadata_mask) |
| 946 | q.breakable() |
| 947 | q.text('}') |
| 948 | |
| 949 | class packet_queue(object): |
| 950 | |
| 951 | def __init__(self, queue_id=None, properties=None): |
| 952 | if queue_id != None: |
| 953 | self.queue_id = queue_id |
| 954 | else: |
| 955 | self.queue_id = 0 |
| 956 | if properties != None: |
| 957 | self.properties = properties |
| 958 | else: |
| 959 | self.properties = [] |
| 960 | return |
| 961 | |
| 962 | def pack(self): |
| 963 | packed = [] |
| 964 | packed.append(struct.pack("!L", self.queue_id)) |
| 965 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 966 | packed.append('\x00' * 2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 967 | packed.append(util.pack_list(self.properties)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 968 | length = sum([len(x) for x in packed]) |
| 969 | packed[1] = struct.pack("!H", length) |
| 970 | return ''.join(packed) |
| 971 | |
| 972 | @staticmethod |
| 973 | def unpack(buf): |
| 974 | obj = packet_queue() |
| 975 | if type(buf) == loxi.generic_util.OFReader: |
| 976 | reader = buf |
| 977 | else: |
| 978 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 979 | obj.queue_id = reader.read("!L")[0] |
| 980 | _len = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 981 | reader.skip(2) |
| 982 | obj.properties = common.unpack_list_queue_prop(reader) |
| 983 | return obj |
| 984 | |
| 985 | def __eq__(self, other): |
| 986 | if type(self) != type(other): return False |
| 987 | if self.queue_id != other.queue_id: return False |
| 988 | if self.properties != other.properties: return False |
| 989 | return True |
| 990 | |
| 991 | def __ne__(self, other): |
| 992 | return not self.__eq__(other) |
| 993 | |
| 994 | def show(self): |
| 995 | import loxi.pp |
| 996 | return loxi.pp.pp(self) |
| 997 | |
| 998 | def pretty_print(self, q): |
| 999 | q.text("packet_queue {") |
| 1000 | with q.group(): |
| 1001 | with q.indent(2): |
| 1002 | q.breakable() |
| 1003 | q.text("queue_id = "); |
| 1004 | q.text("%#x" % self.queue_id) |
| 1005 | q.text(","); q.breakable() |
| 1006 | q.text("properties = "); |
| 1007 | q.pp(self.properties) |
| 1008 | q.breakable() |
| 1009 | q.text('}') |
| 1010 | |
| 1011 | class port_desc(object): |
| 1012 | |
| 1013 | def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None, curr_speed=None, max_speed=None): |
| 1014 | if port_no != None: |
| 1015 | self.port_no = port_no |
| 1016 | else: |
| 1017 | self.port_no = 0 |
| 1018 | if hw_addr != None: |
| 1019 | self.hw_addr = hw_addr |
| 1020 | else: |
| 1021 | self.hw_addr = [0,0,0,0,0,0] |
| 1022 | if name != None: |
| 1023 | self.name = name |
| 1024 | else: |
| 1025 | self.name = "" |
| 1026 | if config != None: |
| 1027 | self.config = config |
| 1028 | else: |
| 1029 | self.config = 0 |
| 1030 | if state != None: |
| 1031 | self.state = state |
| 1032 | else: |
| 1033 | self.state = 0 |
| 1034 | if curr != None: |
| 1035 | self.curr = curr |
| 1036 | else: |
| 1037 | self.curr = 0 |
| 1038 | if advertised != None: |
| 1039 | self.advertised = advertised |
| 1040 | else: |
| 1041 | self.advertised = 0 |
| 1042 | if supported != None: |
| 1043 | self.supported = supported |
| 1044 | else: |
| 1045 | self.supported = 0 |
| 1046 | if peer != None: |
| 1047 | self.peer = peer |
| 1048 | else: |
| 1049 | self.peer = 0 |
| 1050 | if curr_speed != None: |
| 1051 | self.curr_speed = curr_speed |
| 1052 | else: |
| 1053 | self.curr_speed = 0 |
| 1054 | if max_speed != None: |
| 1055 | self.max_speed = max_speed |
| 1056 | else: |
| 1057 | self.max_speed = 0 |
| 1058 | return |
| 1059 | |
| 1060 | def pack(self): |
| 1061 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1062 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1063 | packed.append('\x00' * 4) |
| 1064 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 1065 | packed.append('\x00' * 2) |
| 1066 | packed.append(struct.pack("!16s", self.name)) |
| 1067 | packed.append(struct.pack("!L", self.config)) |
| 1068 | packed.append(struct.pack("!L", self.state)) |
| 1069 | packed.append(struct.pack("!L", self.curr)) |
| 1070 | packed.append(struct.pack("!L", self.advertised)) |
| 1071 | packed.append(struct.pack("!L", self.supported)) |
| 1072 | packed.append(struct.pack("!L", self.peer)) |
| 1073 | packed.append(struct.pack("!L", self.curr_speed)) |
| 1074 | packed.append(struct.pack("!L", self.max_speed)) |
| 1075 | return ''.join(packed) |
| 1076 | |
| 1077 | @staticmethod |
| 1078 | def unpack(buf): |
| 1079 | obj = port_desc() |
| 1080 | if type(buf) == loxi.generic_util.OFReader: |
| 1081 | reader = buf |
| 1082 | else: |
| 1083 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1084 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1085 | reader.skip(4) |
| 1086 | obj.hw_addr = list(reader.read('!6B')) |
| 1087 | reader.skip(2) |
| 1088 | obj.name = reader.read("!16s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1089 | obj.config = reader.read("!L")[0] |
| 1090 | obj.state = reader.read("!L")[0] |
| 1091 | obj.curr = reader.read("!L")[0] |
| 1092 | obj.advertised = reader.read("!L")[0] |
| 1093 | obj.supported = reader.read("!L")[0] |
| 1094 | obj.peer = reader.read("!L")[0] |
| 1095 | obj.curr_speed = reader.read("!L")[0] |
| 1096 | obj.max_speed = reader.read("!L")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1097 | return obj |
| 1098 | |
| 1099 | def __eq__(self, other): |
| 1100 | if type(self) != type(other): return False |
| 1101 | if self.port_no != other.port_no: return False |
| 1102 | if self.hw_addr != other.hw_addr: return False |
| 1103 | if self.name != other.name: return False |
| 1104 | if self.config != other.config: return False |
| 1105 | if self.state != other.state: return False |
| 1106 | if self.curr != other.curr: return False |
| 1107 | if self.advertised != other.advertised: return False |
| 1108 | if self.supported != other.supported: return False |
| 1109 | if self.peer != other.peer: return False |
| 1110 | if self.curr_speed != other.curr_speed: return False |
| 1111 | if self.max_speed != other.max_speed: return False |
| 1112 | return True |
| 1113 | |
| 1114 | def __ne__(self, other): |
| 1115 | return not self.__eq__(other) |
| 1116 | |
| 1117 | def show(self): |
| 1118 | import loxi.pp |
| 1119 | return loxi.pp.pp(self) |
| 1120 | |
| 1121 | def pretty_print(self, q): |
| 1122 | q.text("port_desc {") |
| 1123 | with q.group(): |
| 1124 | with q.indent(2): |
| 1125 | q.breakable() |
| 1126 | q.text("port_no = "); |
| 1127 | q.text(util.pretty_port(self.port_no)) |
| 1128 | q.text(","); q.breakable() |
| 1129 | q.text("hw_addr = "); |
| 1130 | q.text(util.pretty_mac(self.hw_addr)) |
| 1131 | q.text(","); q.breakable() |
| 1132 | q.text("name = "); |
| 1133 | q.pp(self.name) |
| 1134 | q.text(","); q.breakable() |
| 1135 | q.text("config = "); |
| 1136 | q.text("%#x" % self.config) |
| 1137 | q.text(","); q.breakable() |
| 1138 | q.text("state = "); |
| 1139 | q.text("%#x" % self.state) |
| 1140 | q.text(","); q.breakable() |
| 1141 | q.text("curr = "); |
| 1142 | q.text("%#x" % self.curr) |
| 1143 | q.text(","); q.breakable() |
| 1144 | q.text("advertised = "); |
| 1145 | q.text("%#x" % self.advertised) |
| 1146 | q.text(","); q.breakable() |
| 1147 | q.text("supported = "); |
| 1148 | q.text("%#x" % self.supported) |
| 1149 | q.text(","); q.breakable() |
| 1150 | q.text("peer = "); |
| 1151 | q.text("%#x" % self.peer) |
| 1152 | q.text(","); q.breakable() |
| 1153 | q.text("curr_speed = "); |
| 1154 | q.text("%#x" % self.curr_speed) |
| 1155 | q.text(","); q.breakable() |
| 1156 | q.text("max_speed = "); |
| 1157 | q.text("%#x" % self.max_speed) |
| 1158 | q.breakable() |
| 1159 | q.text('}') |
| 1160 | |
| 1161 | class port_stats_entry(object): |
| 1162 | |
| 1163 | def __init__(self, port_no=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None): |
| 1164 | if port_no != None: |
| 1165 | self.port_no = port_no |
| 1166 | else: |
| 1167 | self.port_no = 0 |
| 1168 | if rx_packets != None: |
| 1169 | self.rx_packets = rx_packets |
| 1170 | else: |
| 1171 | self.rx_packets = 0 |
| 1172 | if tx_packets != None: |
| 1173 | self.tx_packets = tx_packets |
| 1174 | else: |
| 1175 | self.tx_packets = 0 |
| 1176 | if rx_bytes != None: |
| 1177 | self.rx_bytes = rx_bytes |
| 1178 | else: |
| 1179 | self.rx_bytes = 0 |
| 1180 | if tx_bytes != None: |
| 1181 | self.tx_bytes = tx_bytes |
| 1182 | else: |
| 1183 | self.tx_bytes = 0 |
| 1184 | if rx_dropped != None: |
| 1185 | self.rx_dropped = rx_dropped |
| 1186 | else: |
| 1187 | self.rx_dropped = 0 |
| 1188 | if tx_dropped != None: |
| 1189 | self.tx_dropped = tx_dropped |
| 1190 | else: |
| 1191 | self.tx_dropped = 0 |
| 1192 | if rx_errors != None: |
| 1193 | self.rx_errors = rx_errors |
| 1194 | else: |
| 1195 | self.rx_errors = 0 |
| 1196 | if tx_errors != None: |
| 1197 | self.tx_errors = tx_errors |
| 1198 | else: |
| 1199 | self.tx_errors = 0 |
| 1200 | if rx_frame_err != None: |
| 1201 | self.rx_frame_err = rx_frame_err |
| 1202 | else: |
| 1203 | self.rx_frame_err = 0 |
| 1204 | if rx_over_err != None: |
| 1205 | self.rx_over_err = rx_over_err |
| 1206 | else: |
| 1207 | self.rx_over_err = 0 |
| 1208 | if rx_crc_err != None: |
| 1209 | self.rx_crc_err = rx_crc_err |
| 1210 | else: |
| 1211 | self.rx_crc_err = 0 |
| 1212 | if collisions != None: |
| 1213 | self.collisions = collisions |
| 1214 | else: |
| 1215 | self.collisions = 0 |
| 1216 | return |
| 1217 | |
| 1218 | def pack(self): |
| 1219 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1220 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1221 | packed.append('\x00' * 4) |
| 1222 | packed.append(struct.pack("!Q", self.rx_packets)) |
| 1223 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 1224 | packed.append(struct.pack("!Q", self.rx_bytes)) |
| 1225 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 1226 | packed.append(struct.pack("!Q", self.rx_dropped)) |
| 1227 | packed.append(struct.pack("!Q", self.tx_dropped)) |
| 1228 | packed.append(struct.pack("!Q", self.rx_errors)) |
| 1229 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 1230 | packed.append(struct.pack("!Q", self.rx_frame_err)) |
| 1231 | packed.append(struct.pack("!Q", self.rx_over_err)) |
| 1232 | packed.append(struct.pack("!Q", self.rx_crc_err)) |
| 1233 | packed.append(struct.pack("!Q", self.collisions)) |
| 1234 | return ''.join(packed) |
| 1235 | |
| 1236 | @staticmethod |
| 1237 | def unpack(buf): |
| 1238 | obj = port_stats_entry() |
| 1239 | if type(buf) == loxi.generic_util.OFReader: |
| 1240 | reader = buf |
| 1241 | else: |
| 1242 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1243 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1244 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1245 | obj.rx_packets = reader.read("!Q")[0] |
| 1246 | obj.tx_packets = reader.read("!Q")[0] |
| 1247 | obj.rx_bytes = reader.read("!Q")[0] |
| 1248 | obj.tx_bytes = reader.read("!Q")[0] |
| 1249 | obj.rx_dropped = reader.read("!Q")[0] |
| 1250 | obj.tx_dropped = reader.read("!Q")[0] |
| 1251 | obj.rx_errors = reader.read("!Q")[0] |
| 1252 | obj.tx_errors = reader.read("!Q")[0] |
| 1253 | obj.rx_frame_err = reader.read("!Q")[0] |
| 1254 | obj.rx_over_err = reader.read("!Q")[0] |
| 1255 | obj.rx_crc_err = reader.read("!Q")[0] |
| 1256 | obj.collisions = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1257 | return obj |
| 1258 | |
| 1259 | def __eq__(self, other): |
| 1260 | if type(self) != type(other): return False |
| 1261 | if self.port_no != other.port_no: return False |
| 1262 | if self.rx_packets != other.rx_packets: return False |
| 1263 | if self.tx_packets != other.tx_packets: return False |
| 1264 | if self.rx_bytes != other.rx_bytes: return False |
| 1265 | if self.tx_bytes != other.tx_bytes: return False |
| 1266 | if self.rx_dropped != other.rx_dropped: return False |
| 1267 | if self.tx_dropped != other.tx_dropped: return False |
| 1268 | if self.rx_errors != other.rx_errors: return False |
| 1269 | if self.tx_errors != other.tx_errors: return False |
| 1270 | if self.rx_frame_err != other.rx_frame_err: return False |
| 1271 | if self.rx_over_err != other.rx_over_err: return False |
| 1272 | if self.rx_crc_err != other.rx_crc_err: return False |
| 1273 | if self.collisions != other.collisions: return False |
| 1274 | return True |
| 1275 | |
| 1276 | def __ne__(self, other): |
| 1277 | return not self.__eq__(other) |
| 1278 | |
| 1279 | def show(self): |
| 1280 | import loxi.pp |
| 1281 | return loxi.pp.pp(self) |
| 1282 | |
| 1283 | def pretty_print(self, q): |
| 1284 | q.text("port_stats_entry {") |
| 1285 | with q.group(): |
| 1286 | with q.indent(2): |
| 1287 | q.breakable() |
| 1288 | q.text("port_no = "); |
| 1289 | q.text(util.pretty_port(self.port_no)) |
| 1290 | q.text(","); q.breakable() |
| 1291 | q.text("rx_packets = "); |
| 1292 | q.text("%#x" % self.rx_packets) |
| 1293 | q.text(","); q.breakable() |
| 1294 | q.text("tx_packets = "); |
| 1295 | q.text("%#x" % self.tx_packets) |
| 1296 | q.text(","); q.breakable() |
| 1297 | q.text("rx_bytes = "); |
| 1298 | q.text("%#x" % self.rx_bytes) |
| 1299 | q.text(","); q.breakable() |
| 1300 | q.text("tx_bytes = "); |
| 1301 | q.text("%#x" % self.tx_bytes) |
| 1302 | q.text(","); q.breakable() |
| 1303 | q.text("rx_dropped = "); |
| 1304 | q.text("%#x" % self.rx_dropped) |
| 1305 | q.text(","); q.breakable() |
| 1306 | q.text("tx_dropped = "); |
| 1307 | q.text("%#x" % self.tx_dropped) |
| 1308 | q.text(","); q.breakable() |
| 1309 | q.text("rx_errors = "); |
| 1310 | q.text("%#x" % self.rx_errors) |
| 1311 | q.text(","); q.breakable() |
| 1312 | q.text("tx_errors = "); |
| 1313 | q.text("%#x" % self.tx_errors) |
| 1314 | q.text(","); q.breakable() |
| 1315 | q.text("rx_frame_err = "); |
| 1316 | q.text("%#x" % self.rx_frame_err) |
| 1317 | q.text(","); q.breakable() |
| 1318 | q.text("rx_over_err = "); |
| 1319 | q.text("%#x" % self.rx_over_err) |
| 1320 | q.text(","); q.breakable() |
| 1321 | q.text("rx_crc_err = "); |
| 1322 | q.text("%#x" % self.rx_crc_err) |
| 1323 | q.text(","); q.breakable() |
| 1324 | q.text("collisions = "); |
| 1325 | q.text("%#x" % self.collisions) |
| 1326 | q.breakable() |
| 1327 | q.text('}') |
| 1328 | |
| 1329 | class queue_prop_min_rate(object): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1330 | type = 1 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1331 | |
| 1332 | def __init__(self, rate=None): |
| 1333 | if rate != None: |
| 1334 | self.rate = rate |
| 1335 | else: |
| 1336 | self.rate = 0 |
| 1337 | return |
| 1338 | |
| 1339 | def pack(self): |
| 1340 | packed = [] |
| 1341 | packed.append(struct.pack("!H", self.type)) |
| 1342 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1343 | packed.append('\x00' * 4) |
| 1344 | packed.append(struct.pack("!H", self.rate)) |
| 1345 | packed.append('\x00' * 6) |
| 1346 | length = sum([len(x) for x in packed]) |
| 1347 | packed[1] = struct.pack("!H", length) |
| 1348 | return ''.join(packed) |
| 1349 | |
| 1350 | @staticmethod |
| 1351 | def unpack(buf): |
| 1352 | obj = queue_prop_min_rate() |
| 1353 | if type(buf) == loxi.generic_util.OFReader: |
| 1354 | reader = buf |
| 1355 | else: |
| 1356 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1357 | _type = reader.read("!H")[0] |
| 1358 | assert(_type == 1) |
| 1359 | _len = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1360 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1361 | obj.rate = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1362 | reader.skip(6) |
| 1363 | return obj |
| 1364 | |
| 1365 | def __eq__(self, other): |
| 1366 | if type(self) != type(other): return False |
| 1367 | if self.rate != other.rate: return False |
| 1368 | return True |
| 1369 | |
| 1370 | def __ne__(self, other): |
| 1371 | return not self.__eq__(other) |
| 1372 | |
| 1373 | def show(self): |
| 1374 | import loxi.pp |
| 1375 | return loxi.pp.pp(self) |
| 1376 | |
| 1377 | def pretty_print(self, q): |
| 1378 | q.text("queue_prop_min_rate {") |
| 1379 | with q.group(): |
| 1380 | with q.indent(2): |
| 1381 | q.breakable() |
| 1382 | q.text("rate = "); |
| 1383 | q.text("%#x" % self.rate) |
| 1384 | q.breakable() |
| 1385 | q.text('}') |
| 1386 | |
| 1387 | class queue_stats_entry(object): |
| 1388 | |
| 1389 | def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): |
| 1390 | if port_no != None: |
| 1391 | self.port_no = port_no |
| 1392 | else: |
| 1393 | self.port_no = 0 |
| 1394 | if queue_id != None: |
| 1395 | self.queue_id = queue_id |
| 1396 | else: |
| 1397 | self.queue_id = 0 |
| 1398 | if tx_bytes != None: |
| 1399 | self.tx_bytes = tx_bytes |
| 1400 | else: |
| 1401 | self.tx_bytes = 0 |
| 1402 | if tx_packets != None: |
| 1403 | self.tx_packets = tx_packets |
| 1404 | else: |
| 1405 | self.tx_packets = 0 |
| 1406 | if tx_errors != None: |
| 1407 | self.tx_errors = tx_errors |
| 1408 | else: |
| 1409 | self.tx_errors = 0 |
| 1410 | return |
| 1411 | |
| 1412 | def pack(self): |
| 1413 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1414 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1415 | packed.append(struct.pack("!L", self.queue_id)) |
| 1416 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 1417 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 1418 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 1419 | return ''.join(packed) |
| 1420 | |
| 1421 | @staticmethod |
| 1422 | def unpack(buf): |
| 1423 | obj = queue_stats_entry() |
| 1424 | if type(buf) == loxi.generic_util.OFReader: |
| 1425 | reader = buf |
| 1426 | else: |
| 1427 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1428 | obj.port_no = util.unpack_port_no(reader) |
| 1429 | obj.queue_id = reader.read("!L")[0] |
| 1430 | obj.tx_bytes = reader.read("!Q")[0] |
| 1431 | obj.tx_packets = reader.read("!Q")[0] |
| 1432 | obj.tx_errors = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1433 | return obj |
| 1434 | |
| 1435 | def __eq__(self, other): |
| 1436 | if type(self) != type(other): return False |
| 1437 | if self.port_no != other.port_no: return False |
| 1438 | if self.queue_id != other.queue_id: return False |
| 1439 | if self.tx_bytes != other.tx_bytes: return False |
| 1440 | if self.tx_packets != other.tx_packets: return False |
| 1441 | if self.tx_errors != other.tx_errors: return False |
| 1442 | return True |
| 1443 | |
| 1444 | def __ne__(self, other): |
| 1445 | return not self.__eq__(other) |
| 1446 | |
| 1447 | def show(self): |
| 1448 | import loxi.pp |
| 1449 | return loxi.pp.pp(self) |
| 1450 | |
| 1451 | def pretty_print(self, q): |
| 1452 | q.text("queue_stats_entry {") |
| 1453 | with q.group(): |
| 1454 | with q.indent(2): |
| 1455 | q.breakable() |
| 1456 | q.text("port_no = "); |
| 1457 | q.text(util.pretty_port(self.port_no)) |
| 1458 | q.text(","); q.breakable() |
| 1459 | q.text("queue_id = "); |
| 1460 | q.text("%#x" % self.queue_id) |
| 1461 | q.text(","); q.breakable() |
| 1462 | q.text("tx_bytes = "); |
| 1463 | q.text("%#x" % self.tx_bytes) |
| 1464 | q.text(","); q.breakable() |
| 1465 | q.text("tx_packets = "); |
| 1466 | q.text("%#x" % self.tx_packets) |
| 1467 | q.text(","); q.breakable() |
| 1468 | q.text("tx_errors = "); |
| 1469 | q.text("%#x" % self.tx_errors) |
| 1470 | q.breakable() |
| 1471 | q.text('}') |
| 1472 | |
| 1473 | class table_stats_entry(object): |
| 1474 | |
| 1475 | def __init__(self, table_id=None, name=None, wildcards=None, match=None, instructions=None, write_actions=None, apply_actions=None, config=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None): |
| 1476 | if table_id != None: |
| 1477 | self.table_id = table_id |
| 1478 | else: |
| 1479 | self.table_id = 0 |
| 1480 | if name != None: |
| 1481 | self.name = name |
| 1482 | else: |
| 1483 | self.name = "" |
| 1484 | if wildcards != None: |
| 1485 | self.wildcards = wildcards |
| 1486 | else: |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1487 | self.wildcards = util.init_wc_bmap() |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1488 | if match != None: |
| 1489 | self.match = match |
| 1490 | else: |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1491 | self.match = util.init_match_bmap() |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1492 | if instructions != None: |
| 1493 | self.instructions = instructions |
| 1494 | else: |
| 1495 | self.instructions = 0 |
| 1496 | if write_actions != None: |
| 1497 | self.write_actions = write_actions |
| 1498 | else: |
| 1499 | self.write_actions = 0 |
| 1500 | if apply_actions != None: |
| 1501 | self.apply_actions = apply_actions |
| 1502 | else: |
| 1503 | self.apply_actions = 0 |
| 1504 | if config != None: |
| 1505 | self.config = config |
| 1506 | else: |
| 1507 | self.config = 0 |
| 1508 | if max_entries != None: |
| 1509 | self.max_entries = max_entries |
| 1510 | else: |
| 1511 | self.max_entries = 0 |
| 1512 | if active_count != None: |
| 1513 | self.active_count = active_count |
| 1514 | else: |
| 1515 | self.active_count = 0 |
| 1516 | if lookup_count != None: |
| 1517 | self.lookup_count = lookup_count |
| 1518 | else: |
| 1519 | self.lookup_count = 0 |
| 1520 | if matched_count != None: |
| 1521 | self.matched_count = matched_count |
| 1522 | else: |
| 1523 | self.matched_count = 0 |
| 1524 | return |
| 1525 | |
| 1526 | def pack(self): |
| 1527 | packed = [] |
| 1528 | packed.append(struct.pack("!B", self.table_id)) |
| 1529 | packed.append('\x00' * 7) |
| 1530 | packed.append(struct.pack("!32s", self.name)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1531 | packed.append(util.pack_wc_bmap(self.wildcards)) |
| 1532 | packed.append(util.pack_match_bmap(self.match)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1533 | packed.append(struct.pack("!L", self.instructions)) |
| 1534 | packed.append(struct.pack("!L", self.write_actions)) |
| 1535 | packed.append(struct.pack("!L", self.apply_actions)) |
| 1536 | packed.append(struct.pack("!L", self.config)) |
| 1537 | packed.append(struct.pack("!L", self.max_entries)) |
| 1538 | packed.append(struct.pack("!L", self.active_count)) |
| 1539 | packed.append(struct.pack("!Q", self.lookup_count)) |
| 1540 | packed.append(struct.pack("!Q", self.matched_count)) |
| 1541 | return ''.join(packed) |
| 1542 | |
| 1543 | @staticmethod |
| 1544 | def unpack(buf): |
| 1545 | obj = table_stats_entry() |
| 1546 | if type(buf) == loxi.generic_util.OFReader: |
| 1547 | reader = buf |
| 1548 | else: |
| 1549 | reader = loxi.generic_util.OFReader(buf) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1550 | obj.table_id = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1551 | reader.skip(7) |
| 1552 | obj.name = reader.read("!32s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame^] | 1553 | obj.wildcards = util.unpack_wc_bmap(reader) |
| 1554 | obj.match = util.unpack_match_bmap(reader) |
| 1555 | obj.instructions = reader.read("!L")[0] |
| 1556 | obj.write_actions = reader.read("!L")[0] |
| 1557 | obj.apply_actions = reader.read("!L")[0] |
| 1558 | obj.config = reader.read("!L")[0] |
| 1559 | obj.max_entries = reader.read("!L")[0] |
| 1560 | obj.active_count = reader.read("!L")[0] |
| 1561 | obj.lookup_count = reader.read("!Q")[0] |
| 1562 | obj.matched_count = reader.read("!Q")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1563 | return obj |
| 1564 | |
| 1565 | def __eq__(self, other): |
| 1566 | if type(self) != type(other): return False |
| 1567 | if self.table_id != other.table_id: return False |
| 1568 | if self.name != other.name: return False |
| 1569 | if self.wildcards != other.wildcards: return False |
| 1570 | if self.match != other.match: return False |
| 1571 | if self.instructions != other.instructions: return False |
| 1572 | if self.write_actions != other.write_actions: return False |
| 1573 | if self.apply_actions != other.apply_actions: return False |
| 1574 | if self.config != other.config: return False |
| 1575 | if self.max_entries != other.max_entries: return False |
| 1576 | if self.active_count != other.active_count: return False |
| 1577 | if self.lookup_count != other.lookup_count: return False |
| 1578 | if self.matched_count != other.matched_count: return False |
| 1579 | return True |
| 1580 | |
| 1581 | def __ne__(self, other): |
| 1582 | return not self.__eq__(other) |
| 1583 | |
| 1584 | def show(self): |
| 1585 | import loxi.pp |
| 1586 | return loxi.pp.pp(self) |
| 1587 | |
| 1588 | def pretty_print(self, q): |
| 1589 | q.text("table_stats_entry {") |
| 1590 | with q.group(): |
| 1591 | with q.indent(2): |
| 1592 | q.breakable() |
| 1593 | q.text("table_id = "); |
| 1594 | q.text("%#x" % self.table_id) |
| 1595 | q.text(","); q.breakable() |
| 1596 | q.text("name = "); |
| 1597 | q.pp(self.name) |
| 1598 | q.text(","); q.breakable() |
| 1599 | q.text("wildcards = "); |
| 1600 | q.text(util.pretty_wildcards(self.wildcards)) |
| 1601 | q.text(","); q.breakable() |
| 1602 | q.text("match = "); |
| 1603 | q.pp(self.match) |
| 1604 | q.text(","); q.breakable() |
| 1605 | q.text("instructions = "); |
| 1606 | q.text("%#x" % self.instructions) |
| 1607 | q.text(","); q.breakable() |
| 1608 | q.text("write_actions = "); |
| 1609 | q.text("%#x" % self.write_actions) |
| 1610 | q.text(","); q.breakable() |
| 1611 | q.text("apply_actions = "); |
| 1612 | q.text("%#x" % self.apply_actions) |
| 1613 | q.text(","); q.breakable() |
| 1614 | q.text("config = "); |
| 1615 | q.text("%#x" % self.config) |
| 1616 | q.text(","); q.breakable() |
| 1617 | q.text("max_entries = "); |
| 1618 | q.text("%#x" % self.max_entries) |
| 1619 | q.text(","); q.breakable() |
| 1620 | q.text("active_count = "); |
| 1621 | q.text("%#x" % self.active_count) |
| 1622 | q.text(","); q.breakable() |
| 1623 | q.text("lookup_count = "); |
| 1624 | q.text("%#x" % self.lookup_count) |
| 1625 | q.text(","); q.breakable() |
| 1626 | q.text("matched_count = "); |
| 1627 | q.text("%#x" % self.matched_count) |
| 1628 | q.breakable() |
| 1629 | q.text('}') |
| 1630 | |
| 1631 | |
| 1632 | match = match_v2 |