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