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