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