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