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 | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 7 | # Do not modify |
| 8 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 9 | import struct |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 10 | import loxi |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 11 | import const |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 12 | import common |
| 13 | import action |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 14 | import util |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 15 | import loxi.generic_util |
| 16 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 17 | class bsn_interface(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 18 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 19 | def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 20 | if hw_addr != None: |
| 21 | self.hw_addr = hw_addr |
| 22 | else: |
| 23 | self.hw_addr = [0,0,0,0,0,0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 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 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 36 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 37 | |
| 38 | def pack(self): |
| 39 | packed = [] |
| 40 | packed.append(struct.pack("!6B", *self.hw_addr)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 41 | packed.append('\x00' * 2) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 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 | b658ddd | 2013-03-12 10:15:10 -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 | b658ddd | 2013-03-12 10:15:10 -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 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 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 | b658ddd | 2013-03-12 10:15:10 -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() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 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 |
| 115 | reader = orig_reader.slice(_length - (2 + 2)) |
| 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 | 5587ab1 | 2014-06-30 11:19:09 -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, 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 |
| 176 | if if_name != None: |
| 177 | self.if_name = if_name |
| 178 | else: |
| 179 | self.if_name = "" |
| 180 | return |
| 181 | |
| 182 | def pack(self): |
| 183 | packed = [] |
| 184 | packed.append(struct.pack("!H", self.type)) |
| 185 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 186 | packed.append(struct.pack("!L", self.flags)) |
| 187 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | 5587ab1 | 2014-06-30 11:19:09 -0700 | [diff] [blame] | 188 | packed.append(util.pack_port_no(self.loopback_port_no)) |
Rich Lane | 93b3313 | 2014-04-21 12:20:58 -0700 | [diff] [blame] | 189 | packed.append(struct.pack("!6B", *self.local_mac)) |
| 190 | packed.append(struct.pack("!6B", *self.nh_mac)) |
| 191 | packed.append(struct.pack("!L", self.src_ip)) |
| 192 | packed.append(struct.pack("!L", self.dst_ip)) |
| 193 | packed.append(struct.pack("!B", self.dscp)) |
| 194 | packed.append(struct.pack("!B", self.ttl)) |
| 195 | packed.append('\x00' * 2) |
| 196 | packed.append(struct.pack("!L", self.vpn)) |
| 197 | packed.append(struct.pack("!16s", self.if_name)) |
| 198 | length = sum([len(x) for x in packed]) |
| 199 | packed[1] = struct.pack("!H", length) |
| 200 | return ''.join(packed) |
| 201 | |
| 202 | @staticmethod |
| 203 | def unpack(reader): |
| 204 | obj = bsn_vport_l2gre() |
| 205 | _type = reader.read("!H")[0] |
| 206 | assert(_type == 1) |
| 207 | _length = reader.read("!H")[0] |
| 208 | orig_reader = reader |
| 209 | reader = orig_reader.slice(_length - (2 + 2)) |
| 210 | obj.flags = reader.read("!L")[0] |
| 211 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | 5587ab1 | 2014-06-30 11:19:09 -0700 | [diff] [blame] | 212 | obj.loopback_port_no = util.unpack_port_no(reader) |
Rich Lane | 93b3313 | 2014-04-21 12:20:58 -0700 | [diff] [blame] | 213 | obj.local_mac = list(reader.read('!6B')) |
| 214 | obj.nh_mac = list(reader.read('!6B')) |
| 215 | obj.src_ip = reader.read("!L")[0] |
| 216 | obj.dst_ip = reader.read("!L")[0] |
| 217 | obj.dscp = reader.read("!B")[0] |
| 218 | obj.ttl = reader.read("!B")[0] |
| 219 | reader.skip(2) |
| 220 | obj.vpn = reader.read("!L")[0] |
| 221 | obj.if_name = reader.read("!16s")[0].rstrip("\x00") |
| 222 | return obj |
| 223 | |
| 224 | def __eq__(self, other): |
| 225 | if type(self) != type(other): return False |
| 226 | if self.flags != other.flags: return False |
| 227 | if self.port_no != other.port_no: return False |
Rich Lane | 5587ab1 | 2014-06-30 11:19:09 -0700 | [diff] [blame] | 228 | if self.loopback_port_no != other.loopback_port_no: return False |
Rich Lane | 93b3313 | 2014-04-21 12:20:58 -0700 | [diff] [blame] | 229 | if self.local_mac != other.local_mac: return False |
| 230 | if self.nh_mac != other.nh_mac: return False |
| 231 | if self.src_ip != other.src_ip: return False |
| 232 | if self.dst_ip != other.dst_ip: return False |
| 233 | if self.dscp != other.dscp: return False |
| 234 | if self.ttl != other.ttl: return False |
| 235 | if self.vpn != other.vpn: return False |
| 236 | if self.if_name != other.if_name: return False |
| 237 | return True |
| 238 | |
| 239 | def pretty_print(self, q): |
| 240 | q.text("bsn_vport_l2gre {") |
| 241 | with q.group(): |
| 242 | with q.indent(2): |
| 243 | q.breakable() |
| 244 | q.text("flags = "); |
| 245 | q.text("%#x" % self.flags) |
| 246 | q.text(","); q.breakable() |
| 247 | q.text("port_no = "); |
| 248 | q.text(util.pretty_port(self.port_no)) |
| 249 | q.text(","); q.breakable() |
Rich Lane | 5587ab1 | 2014-06-30 11:19:09 -0700 | [diff] [blame] | 250 | q.text("loopback_port_no = "); |
| 251 | q.text(util.pretty_port(self.loopback_port_no)) |
| 252 | q.text(","); q.breakable() |
Rich Lane | 93b3313 | 2014-04-21 12:20:58 -0700 | [diff] [blame] | 253 | q.text("local_mac = "); |
| 254 | q.text(util.pretty_mac(self.local_mac)) |
| 255 | q.text(","); q.breakable() |
| 256 | q.text("nh_mac = "); |
| 257 | q.text(util.pretty_mac(self.nh_mac)) |
| 258 | q.text(","); q.breakable() |
| 259 | q.text("src_ip = "); |
| 260 | q.text(util.pretty_ipv4(self.src_ip)) |
| 261 | q.text(","); q.breakable() |
| 262 | q.text("dst_ip = "); |
| 263 | q.text(util.pretty_ipv4(self.dst_ip)) |
| 264 | q.text(","); q.breakable() |
| 265 | q.text("dscp = "); |
| 266 | q.text("%#x" % self.dscp) |
| 267 | q.text(","); q.breakable() |
| 268 | q.text("ttl = "); |
| 269 | q.text("%#x" % self.ttl) |
| 270 | q.text(","); q.breakable() |
| 271 | q.text("vpn = "); |
| 272 | q.text("%#x" % self.vpn) |
| 273 | q.text(","); q.breakable() |
| 274 | q.text("if_name = "); |
| 275 | q.pp(self.if_name) |
| 276 | q.breakable() |
| 277 | q.text('}') |
| 278 | |
| 279 | bsn_vport.subtypes[1] = bsn_vport_l2gre |
| 280 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 281 | class bsn_vport_q_in_q(bsn_vport): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 282 | type = 0 |
| 283 | |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 284 | 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] | 285 | if port_no != None: |
| 286 | self.port_no = port_no |
| 287 | else: |
| 288 | self.port_no = 0 |
| 289 | if ingress_tpid != None: |
| 290 | self.ingress_tpid = ingress_tpid |
| 291 | else: |
| 292 | self.ingress_tpid = 0 |
| 293 | if ingress_vlan_id != None: |
| 294 | self.ingress_vlan_id = ingress_vlan_id |
| 295 | else: |
| 296 | self.ingress_vlan_id = 0 |
| 297 | if egress_tpid != None: |
| 298 | self.egress_tpid = egress_tpid |
| 299 | else: |
| 300 | self.egress_tpid = 0 |
| 301 | if egress_vlan_id != None: |
| 302 | self.egress_vlan_id = egress_vlan_id |
| 303 | else: |
| 304 | self.egress_vlan_id = 0 |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 305 | if if_name != None: |
| 306 | self.if_name = if_name |
| 307 | else: |
| 308 | self.if_name = "" |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 309 | return |
| 310 | |
| 311 | def pack(self): |
| 312 | packed = [] |
| 313 | packed.append(struct.pack("!H", self.type)) |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 314 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 315 | packed.append(struct.pack("!L", self.port_no)) |
| 316 | packed.append(struct.pack("!H", self.ingress_tpid)) |
| 317 | packed.append(struct.pack("!H", self.ingress_vlan_id)) |
| 318 | packed.append(struct.pack("!H", self.egress_tpid)) |
| 319 | packed.append(struct.pack("!H", self.egress_vlan_id)) |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 320 | packed.append(struct.pack("!16s", self.if_name)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 321 | length = sum([len(x) for x in packed]) |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 322 | packed[1] = struct.pack("!H", length) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 323 | return ''.join(packed) |
| 324 | |
| 325 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 326 | def unpack(reader): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 327 | obj = bsn_vport_q_in_q() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 328 | _type = reader.read("!H")[0] |
| 329 | assert(_type == 0) |
| 330 | _length = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 331 | orig_reader = reader |
| 332 | reader = orig_reader.slice(_length - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 333 | obj.port_no = reader.read("!L")[0] |
| 334 | obj.ingress_tpid = reader.read("!H")[0] |
| 335 | obj.ingress_vlan_id = reader.read("!H")[0] |
| 336 | obj.egress_tpid = reader.read("!H")[0] |
| 337 | obj.egress_vlan_id = reader.read("!H")[0] |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 338 | obj.if_name = reader.read("!16s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 339 | return obj |
| 340 | |
| 341 | def __eq__(self, other): |
| 342 | if type(self) != type(other): return False |
| 343 | if self.port_no != other.port_no: return False |
| 344 | if self.ingress_tpid != other.ingress_tpid: return False |
| 345 | if self.ingress_vlan_id != other.ingress_vlan_id: return False |
| 346 | if self.egress_tpid != other.egress_tpid: return False |
| 347 | if self.egress_vlan_id != other.egress_vlan_id: return False |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 348 | if self.if_name != other.if_name: return False |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 349 | return True |
| 350 | |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 351 | def pretty_print(self, q): |
| 352 | q.text("bsn_vport_q_in_q {") |
| 353 | with q.group(): |
| 354 | with q.indent(2): |
| 355 | q.breakable() |
| 356 | q.text("port_no = "); |
| 357 | q.text("%#x" % self.port_no) |
| 358 | q.text(","); q.breakable() |
| 359 | q.text("ingress_tpid = "); |
| 360 | q.text("%#x" % self.ingress_tpid) |
| 361 | q.text(","); q.breakable() |
| 362 | q.text("ingress_vlan_id = "); |
| 363 | q.text("%#x" % self.ingress_vlan_id) |
| 364 | q.text(","); q.breakable() |
| 365 | q.text("egress_tpid = "); |
| 366 | q.text("%#x" % self.egress_tpid) |
| 367 | q.text(","); q.breakable() |
| 368 | q.text("egress_vlan_id = "); |
| 369 | q.text("%#x" % self.egress_vlan_id) |
Kiran Poola | 150d8b0 | 2013-09-20 13:30:39 -0700 | [diff] [blame] | 370 | q.text(","); q.breakable() |
| 371 | q.text("if_name = "); |
| 372 | q.pp(self.if_name) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 373 | q.breakable() |
| 374 | q.text('}') |
| 375 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 376 | bsn_vport.subtypes[0] = bsn_vport_q_in_q |
| 377 | |
| 378 | class flow_stats_entry(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 379 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 380 | def __init__(self, table_id=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, actions=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 381 | if table_id != None: |
| 382 | self.table_id = table_id |
| 383 | else: |
| 384 | self.table_id = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 385 | if match != None: |
| 386 | self.match = match |
| 387 | else: |
| 388 | self.match = common.match() |
| 389 | if duration_sec != None: |
| 390 | self.duration_sec = duration_sec |
| 391 | else: |
| 392 | self.duration_sec = 0 |
| 393 | if duration_nsec != None: |
| 394 | self.duration_nsec = duration_nsec |
| 395 | else: |
| 396 | self.duration_nsec = 0 |
| 397 | if priority != None: |
| 398 | self.priority = priority |
| 399 | else: |
| 400 | self.priority = 0 |
| 401 | if idle_timeout != None: |
| 402 | self.idle_timeout = idle_timeout |
| 403 | else: |
| 404 | self.idle_timeout = 0 |
| 405 | if hard_timeout != None: |
| 406 | self.hard_timeout = hard_timeout |
| 407 | else: |
| 408 | self.hard_timeout = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 409 | if cookie != None: |
| 410 | self.cookie = cookie |
| 411 | else: |
| 412 | self.cookie = 0 |
| 413 | if packet_count != None: |
| 414 | self.packet_count = packet_count |
| 415 | else: |
| 416 | self.packet_count = 0 |
| 417 | if byte_count != None: |
| 418 | self.byte_count = byte_count |
| 419 | else: |
| 420 | self.byte_count = 0 |
| 421 | if actions != None: |
| 422 | self.actions = actions |
| 423 | else: |
| 424 | self.actions = [] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 425 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 426 | |
| 427 | def pack(self): |
| 428 | packed = [] |
| 429 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 430 | packed.append(struct.pack("!B", self.table_id)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 431 | packed.append('\x00' * 1) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 432 | packed.append(self.match.pack()) |
| 433 | packed.append(struct.pack("!L", self.duration_sec)) |
| 434 | packed.append(struct.pack("!L", self.duration_nsec)) |
| 435 | packed.append(struct.pack("!H", self.priority)) |
| 436 | packed.append(struct.pack("!H", self.idle_timeout)) |
| 437 | packed.append(struct.pack("!H", self.hard_timeout)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 438 | packed.append('\x00' * 6) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 439 | packed.append(struct.pack("!Q", self.cookie)) |
| 440 | packed.append(struct.pack("!Q", self.packet_count)) |
| 441 | packed.append(struct.pack("!Q", self.byte_count)) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 442 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 443 | length = sum([len(x) for x in packed]) |
| 444 | packed[0] = struct.pack("!H", length) |
| 445 | return ''.join(packed) |
| 446 | |
| 447 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 448 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 449 | obj = flow_stats_entry() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 450 | _length = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 451 | orig_reader = reader |
| 452 | reader = orig_reader.slice(_length - (0 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 453 | obj.table_id = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 454 | reader.skip(1) |
| 455 | obj.match = common.match.unpack(reader) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 456 | obj.duration_sec = reader.read("!L")[0] |
| 457 | obj.duration_nsec = reader.read("!L")[0] |
| 458 | obj.priority = reader.read("!H")[0] |
| 459 | obj.idle_timeout = reader.read("!H")[0] |
| 460 | obj.hard_timeout = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 461 | reader.skip(6) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 462 | obj.cookie = reader.read("!Q")[0] |
| 463 | obj.packet_count = reader.read("!Q")[0] |
| 464 | obj.byte_count = reader.read("!Q")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 465 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 466 | return obj |
| 467 | |
| 468 | def __eq__(self, other): |
| 469 | if type(self) != type(other): return False |
| 470 | if self.table_id != other.table_id: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 471 | if self.match != other.match: return False |
| 472 | if self.duration_sec != other.duration_sec: return False |
| 473 | if self.duration_nsec != other.duration_nsec: return False |
| 474 | if self.priority != other.priority: return False |
| 475 | if self.idle_timeout != other.idle_timeout: return False |
| 476 | if self.hard_timeout != other.hard_timeout: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 477 | if self.cookie != other.cookie: return False |
| 478 | if self.packet_count != other.packet_count: return False |
| 479 | if self.byte_count != other.byte_count: return False |
| 480 | if self.actions != other.actions: return False |
| 481 | return True |
| 482 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 483 | def pretty_print(self, q): |
| 484 | q.text("flow_stats_entry {") |
| 485 | with q.group(): |
| 486 | with q.indent(2): |
| 487 | q.breakable() |
| 488 | q.text("table_id = "); |
| 489 | q.text("%#x" % self.table_id) |
| 490 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 491 | q.text("match = "); |
| 492 | q.pp(self.match) |
| 493 | q.text(","); q.breakable() |
| 494 | q.text("duration_sec = "); |
| 495 | q.text("%#x" % self.duration_sec) |
| 496 | q.text(","); q.breakable() |
| 497 | q.text("duration_nsec = "); |
| 498 | q.text("%#x" % self.duration_nsec) |
| 499 | q.text(","); q.breakable() |
| 500 | q.text("priority = "); |
| 501 | q.text("%#x" % self.priority) |
| 502 | q.text(","); q.breakable() |
| 503 | q.text("idle_timeout = "); |
| 504 | q.text("%#x" % self.idle_timeout) |
| 505 | q.text(","); q.breakable() |
| 506 | q.text("hard_timeout = "); |
| 507 | q.text("%#x" % self.hard_timeout) |
| 508 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 509 | q.text("cookie = "); |
| 510 | q.text("%#x" % self.cookie) |
| 511 | q.text(","); q.breakable() |
| 512 | q.text("packet_count = "); |
| 513 | q.text("%#x" % self.packet_count) |
| 514 | q.text(","); q.breakable() |
| 515 | q.text("byte_count = "); |
| 516 | q.text("%#x" % self.byte_count) |
| 517 | q.text(","); q.breakable() |
| 518 | q.text("actions = "); |
| 519 | q.pp(self.actions) |
| 520 | q.breakable() |
| 521 | q.text('}') |
| 522 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 523 | |
| 524 | class match_v1(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 525 | |
Rich Lane | fe600f5 | 2013-07-09 13:22:32 -0700 | [diff] [blame] | 526 | def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 527 | if wildcards != None: |
| 528 | self.wildcards = wildcards |
| 529 | else: |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 530 | self.wildcards = util.init_wc_bmap() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 531 | if in_port != None: |
| 532 | self.in_port = in_port |
| 533 | else: |
| 534 | self.in_port = 0 |
| 535 | if eth_src != None: |
| 536 | self.eth_src = eth_src |
| 537 | else: |
| 538 | self.eth_src = [0,0,0,0,0,0] |
| 539 | if eth_dst != None: |
| 540 | self.eth_dst = eth_dst |
| 541 | else: |
| 542 | self.eth_dst = [0,0,0,0,0,0] |
| 543 | if vlan_vid != None: |
| 544 | self.vlan_vid = vlan_vid |
| 545 | else: |
| 546 | self.vlan_vid = 0 |
| 547 | if vlan_pcp != None: |
| 548 | self.vlan_pcp = vlan_pcp |
| 549 | else: |
| 550 | self.vlan_pcp = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 551 | if eth_type != None: |
| 552 | self.eth_type = eth_type |
| 553 | else: |
| 554 | self.eth_type = 0 |
| 555 | if ip_dscp != None: |
| 556 | self.ip_dscp = ip_dscp |
| 557 | else: |
| 558 | self.ip_dscp = 0 |
| 559 | if ip_proto != None: |
| 560 | self.ip_proto = ip_proto |
| 561 | else: |
| 562 | self.ip_proto = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 563 | if ipv4_src != None: |
| 564 | self.ipv4_src = ipv4_src |
| 565 | else: |
| 566 | self.ipv4_src = 0 |
| 567 | if ipv4_dst != None: |
| 568 | self.ipv4_dst = ipv4_dst |
| 569 | else: |
| 570 | self.ipv4_dst = 0 |
| 571 | if tcp_src != None: |
| 572 | self.tcp_src = tcp_src |
| 573 | else: |
| 574 | self.tcp_src = 0 |
| 575 | if tcp_dst != None: |
| 576 | self.tcp_dst = tcp_dst |
| 577 | else: |
| 578 | self.tcp_dst = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 579 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 580 | |
| 581 | def pack(self): |
| 582 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 583 | packed.append(util.pack_wc_bmap(self.wildcards)) |
| 584 | packed.append(util.pack_port_no(self.in_port)) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 585 | packed.append(struct.pack("!6B", *self.eth_src)) |
| 586 | packed.append(struct.pack("!6B", *self.eth_dst)) |
| 587 | packed.append(struct.pack("!H", self.vlan_vid)) |
| 588 | packed.append(struct.pack("!B", self.vlan_pcp)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 589 | packed.append('\x00' * 1) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 590 | packed.append(struct.pack("!H", self.eth_type)) |
| 591 | packed.append(struct.pack("!B", self.ip_dscp)) |
| 592 | packed.append(struct.pack("!B", self.ip_proto)) |
Rich Lane | fe600f5 | 2013-07-09 13:22:32 -0700 | [diff] [blame] | 593 | packed.append('\x00' * 2) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 594 | packed.append(struct.pack("!L", self.ipv4_src)) |
| 595 | packed.append(struct.pack("!L", self.ipv4_dst)) |
| 596 | packed.append(struct.pack("!H", self.tcp_src)) |
| 597 | packed.append(struct.pack("!H", self.tcp_dst)) |
| 598 | return ''.join(packed) |
| 599 | |
| 600 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 601 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 602 | obj = match_v1() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 603 | obj.wildcards = util.unpack_wc_bmap(reader) |
| 604 | obj.in_port = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 605 | obj.eth_src = list(reader.read('!6B')) |
| 606 | obj.eth_dst = list(reader.read('!6B')) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 607 | obj.vlan_vid = reader.read("!H")[0] |
| 608 | obj.vlan_pcp = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 609 | reader.skip(1) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 610 | obj.eth_type = reader.read("!H")[0] |
| 611 | obj.ip_dscp = reader.read("!B")[0] |
| 612 | obj.ip_proto = reader.read("!B")[0] |
Rich Lane | fe600f5 | 2013-07-09 13:22:32 -0700 | [diff] [blame] | 613 | reader.skip(2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 614 | obj.ipv4_src = reader.read("!L")[0] |
| 615 | obj.ipv4_dst = reader.read("!L")[0] |
| 616 | obj.tcp_src = reader.read("!H")[0] |
| 617 | obj.tcp_dst = reader.read("!H")[0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 618 | return obj |
| 619 | |
| 620 | def __eq__(self, other): |
| 621 | if type(self) != type(other): return False |
| 622 | if self.wildcards != other.wildcards: return False |
| 623 | if self.in_port != other.in_port: return False |
| 624 | if self.eth_src != other.eth_src: return False |
| 625 | if self.eth_dst != other.eth_dst: return False |
| 626 | if self.vlan_vid != other.vlan_vid: return False |
| 627 | if self.vlan_pcp != other.vlan_pcp: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 628 | if self.eth_type != other.eth_type: return False |
| 629 | if self.ip_dscp != other.ip_dscp: return False |
| 630 | if self.ip_proto != other.ip_proto: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 631 | if self.ipv4_src != other.ipv4_src: return False |
| 632 | if self.ipv4_dst != other.ipv4_dst: return False |
| 633 | if self.tcp_src != other.tcp_src: return False |
| 634 | if self.tcp_dst != other.tcp_dst: return False |
| 635 | return True |
| 636 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 637 | def pretty_print(self, q): |
| 638 | q.text("match_v1 {") |
| 639 | with q.group(): |
| 640 | with q.indent(2): |
| 641 | q.breakable() |
| 642 | q.text("wildcards = "); |
| 643 | q.text(util.pretty_wildcards(self.wildcards)) |
| 644 | q.text(","); q.breakable() |
| 645 | q.text("in_port = "); |
| 646 | q.text(util.pretty_port(self.in_port)) |
| 647 | q.text(","); q.breakable() |
| 648 | q.text("eth_src = "); |
| 649 | q.text(util.pretty_mac(self.eth_src)) |
| 650 | q.text(","); q.breakable() |
| 651 | q.text("eth_dst = "); |
| 652 | q.text(util.pretty_mac(self.eth_dst)) |
| 653 | q.text(","); q.breakable() |
| 654 | q.text("vlan_vid = "); |
| 655 | q.text("%#x" % self.vlan_vid) |
| 656 | q.text(","); q.breakable() |
| 657 | q.text("vlan_pcp = "); |
| 658 | q.text("%#x" % self.vlan_pcp) |
| 659 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 660 | q.text("eth_type = "); |
| 661 | q.text("%#x" % self.eth_type) |
| 662 | q.text(","); q.breakable() |
| 663 | q.text("ip_dscp = "); |
| 664 | q.text("%#x" % self.ip_dscp) |
| 665 | q.text(","); q.breakable() |
| 666 | q.text("ip_proto = "); |
| 667 | q.text("%#x" % self.ip_proto) |
| 668 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 669 | q.text("ipv4_src = "); |
| 670 | q.text(util.pretty_ipv4(self.ipv4_src)) |
| 671 | q.text(","); q.breakable() |
| 672 | q.text("ipv4_dst = "); |
| 673 | q.text(util.pretty_ipv4(self.ipv4_dst)) |
| 674 | q.text(","); q.breakable() |
| 675 | q.text("tcp_src = "); |
| 676 | q.text("%#x" % self.tcp_src) |
| 677 | q.text(","); q.breakable() |
| 678 | q.text("tcp_dst = "); |
| 679 | q.text("%#x" % self.tcp_dst) |
| 680 | q.breakable() |
| 681 | q.text('}') |
| 682 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 683 | |
| 684 | class packet_queue(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 685 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 686 | def __init__(self, queue_id=None, properties=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 687 | if queue_id != None: |
| 688 | self.queue_id = queue_id |
| 689 | else: |
| 690 | self.queue_id = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 691 | if properties != None: |
| 692 | self.properties = properties |
| 693 | else: |
| 694 | self.properties = [] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 695 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 696 | |
| 697 | def pack(self): |
| 698 | packed = [] |
| 699 | packed.append(struct.pack("!L", self.queue_id)) |
| 700 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 701 | packed.append('\x00' * 2) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 702 | packed.append(loxi.generic_util.pack_list(self.properties)) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 703 | length = sum([len(x) for x in packed]) |
| 704 | packed[1] = struct.pack("!H", length) |
| 705 | return ''.join(packed) |
| 706 | |
| 707 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 708 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 709 | obj = packet_queue() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 710 | obj.queue_id = reader.read("!L")[0] |
| 711 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 712 | orig_reader = reader |
| 713 | reader = orig_reader.slice(_len - (4 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 714 | reader.skip(2) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 715 | obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 716 | return obj |
| 717 | |
| 718 | def __eq__(self, other): |
| 719 | if type(self) != type(other): return False |
| 720 | if self.queue_id != other.queue_id: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 721 | if self.properties != other.properties: return False |
| 722 | return True |
| 723 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 724 | def pretty_print(self, q): |
| 725 | q.text("packet_queue {") |
| 726 | with q.group(): |
| 727 | with q.indent(2): |
| 728 | q.breakable() |
| 729 | q.text("queue_id = "); |
| 730 | q.text("%#x" % self.queue_id) |
| 731 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 732 | q.text("properties = "); |
| 733 | q.pp(self.properties) |
| 734 | q.breakable() |
| 735 | q.text('}') |
| 736 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 737 | |
| 738 | class port_desc(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 739 | |
| 740 | def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None): |
| 741 | if port_no != None: |
| 742 | self.port_no = port_no |
| 743 | else: |
| 744 | self.port_no = 0 |
| 745 | if hw_addr != None: |
| 746 | self.hw_addr = hw_addr |
| 747 | else: |
| 748 | self.hw_addr = [0,0,0,0,0,0] |
| 749 | if name != None: |
| 750 | self.name = name |
| 751 | else: |
| 752 | self.name = "" |
| 753 | if config != None: |
| 754 | self.config = config |
| 755 | else: |
| 756 | self.config = 0 |
| 757 | if state != None: |
| 758 | self.state = state |
| 759 | else: |
| 760 | self.state = 0 |
| 761 | if curr != None: |
| 762 | self.curr = curr |
| 763 | else: |
| 764 | self.curr = 0 |
| 765 | if advertised != None: |
| 766 | self.advertised = advertised |
| 767 | else: |
| 768 | self.advertised = 0 |
| 769 | if supported != None: |
| 770 | self.supported = supported |
| 771 | else: |
| 772 | self.supported = 0 |
| 773 | if peer != None: |
| 774 | self.peer = peer |
| 775 | else: |
| 776 | self.peer = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 777 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 778 | |
| 779 | def pack(self): |
| 780 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 781 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 782 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 783 | packed.append(struct.pack("!16s", self.name)) |
| 784 | packed.append(struct.pack("!L", self.config)) |
| 785 | packed.append(struct.pack("!L", self.state)) |
| 786 | packed.append(struct.pack("!L", self.curr)) |
| 787 | packed.append(struct.pack("!L", self.advertised)) |
| 788 | packed.append(struct.pack("!L", self.supported)) |
| 789 | packed.append(struct.pack("!L", self.peer)) |
| 790 | return ''.join(packed) |
| 791 | |
| 792 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 793 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 794 | obj = port_desc() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 795 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 796 | obj.hw_addr = list(reader.read('!6B')) |
| 797 | obj.name = reader.read("!16s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 798 | obj.config = reader.read("!L")[0] |
| 799 | obj.state = reader.read("!L")[0] |
| 800 | obj.curr = reader.read("!L")[0] |
| 801 | obj.advertised = reader.read("!L")[0] |
| 802 | obj.supported = reader.read("!L")[0] |
| 803 | obj.peer = reader.read("!L")[0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 804 | return obj |
| 805 | |
| 806 | def __eq__(self, other): |
| 807 | if type(self) != type(other): return False |
| 808 | if self.port_no != other.port_no: return False |
| 809 | if self.hw_addr != other.hw_addr: return False |
| 810 | if self.name != other.name: return False |
| 811 | if self.config != other.config: return False |
| 812 | if self.state != other.state: return False |
| 813 | if self.curr != other.curr: return False |
| 814 | if self.advertised != other.advertised: return False |
| 815 | if self.supported != other.supported: return False |
| 816 | if self.peer != other.peer: return False |
| 817 | return True |
| 818 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 819 | def pretty_print(self, q): |
| 820 | q.text("port_desc {") |
| 821 | with q.group(): |
| 822 | with q.indent(2): |
| 823 | q.breakable() |
| 824 | q.text("port_no = "); |
| 825 | q.text(util.pretty_port(self.port_no)) |
| 826 | q.text(","); q.breakable() |
| 827 | q.text("hw_addr = "); |
| 828 | q.text(util.pretty_mac(self.hw_addr)) |
| 829 | q.text(","); q.breakable() |
| 830 | q.text("name = "); |
| 831 | q.pp(self.name) |
| 832 | q.text(","); q.breakable() |
| 833 | q.text("config = "); |
| 834 | q.text("%#x" % self.config) |
| 835 | q.text(","); q.breakable() |
| 836 | q.text("state = "); |
| 837 | q.text("%#x" % self.state) |
| 838 | q.text(","); q.breakable() |
| 839 | q.text("curr = "); |
| 840 | q.text("%#x" % self.curr) |
| 841 | q.text(","); q.breakable() |
| 842 | q.text("advertised = "); |
| 843 | q.text("%#x" % self.advertised) |
| 844 | q.text(","); q.breakable() |
| 845 | q.text("supported = "); |
| 846 | q.text("%#x" % self.supported) |
| 847 | q.text(","); q.breakable() |
| 848 | q.text("peer = "); |
| 849 | q.text("%#x" % self.peer) |
| 850 | q.breakable() |
| 851 | q.text('}') |
| 852 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 853 | |
| 854 | class port_stats_entry(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 855 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 856 | 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): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 857 | if port_no != None: |
| 858 | self.port_no = port_no |
| 859 | else: |
| 860 | self.port_no = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 861 | if rx_packets != None: |
| 862 | self.rx_packets = rx_packets |
| 863 | else: |
| 864 | self.rx_packets = 0 |
| 865 | if tx_packets != None: |
| 866 | self.tx_packets = tx_packets |
| 867 | else: |
| 868 | self.tx_packets = 0 |
| 869 | if rx_bytes != None: |
| 870 | self.rx_bytes = rx_bytes |
| 871 | else: |
| 872 | self.rx_bytes = 0 |
| 873 | if tx_bytes != None: |
| 874 | self.tx_bytes = tx_bytes |
| 875 | else: |
| 876 | self.tx_bytes = 0 |
| 877 | if rx_dropped != None: |
| 878 | self.rx_dropped = rx_dropped |
| 879 | else: |
| 880 | self.rx_dropped = 0 |
| 881 | if tx_dropped != None: |
| 882 | self.tx_dropped = tx_dropped |
| 883 | else: |
| 884 | self.tx_dropped = 0 |
| 885 | if rx_errors != None: |
| 886 | self.rx_errors = rx_errors |
| 887 | else: |
| 888 | self.rx_errors = 0 |
| 889 | if tx_errors != None: |
| 890 | self.tx_errors = tx_errors |
| 891 | else: |
| 892 | self.tx_errors = 0 |
| 893 | if rx_frame_err != None: |
| 894 | self.rx_frame_err = rx_frame_err |
| 895 | else: |
| 896 | self.rx_frame_err = 0 |
| 897 | if rx_over_err != None: |
| 898 | self.rx_over_err = rx_over_err |
| 899 | else: |
| 900 | self.rx_over_err = 0 |
| 901 | if rx_crc_err != None: |
| 902 | self.rx_crc_err = rx_crc_err |
| 903 | else: |
| 904 | self.rx_crc_err = 0 |
| 905 | if collisions != None: |
| 906 | self.collisions = collisions |
| 907 | else: |
| 908 | self.collisions = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 909 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 910 | |
| 911 | def pack(self): |
| 912 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 913 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 914 | packed.append('\x00' * 6) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 915 | packed.append(struct.pack("!Q", self.rx_packets)) |
| 916 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 917 | packed.append(struct.pack("!Q", self.rx_bytes)) |
| 918 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 919 | packed.append(struct.pack("!Q", self.rx_dropped)) |
| 920 | packed.append(struct.pack("!Q", self.tx_dropped)) |
| 921 | packed.append(struct.pack("!Q", self.rx_errors)) |
| 922 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 923 | packed.append(struct.pack("!Q", self.rx_frame_err)) |
| 924 | packed.append(struct.pack("!Q", self.rx_over_err)) |
| 925 | packed.append(struct.pack("!Q", self.rx_crc_err)) |
| 926 | packed.append(struct.pack("!Q", self.collisions)) |
| 927 | return ''.join(packed) |
| 928 | |
| 929 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 930 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 931 | obj = port_stats_entry() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 932 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 933 | reader.skip(6) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 934 | obj.rx_packets = reader.read("!Q")[0] |
| 935 | obj.tx_packets = reader.read("!Q")[0] |
| 936 | obj.rx_bytes = reader.read("!Q")[0] |
| 937 | obj.tx_bytes = reader.read("!Q")[0] |
| 938 | obj.rx_dropped = reader.read("!Q")[0] |
| 939 | obj.tx_dropped = reader.read("!Q")[0] |
| 940 | obj.rx_errors = reader.read("!Q")[0] |
| 941 | obj.tx_errors = reader.read("!Q")[0] |
| 942 | obj.rx_frame_err = reader.read("!Q")[0] |
| 943 | obj.rx_over_err = reader.read("!Q")[0] |
| 944 | obj.rx_crc_err = reader.read("!Q")[0] |
| 945 | obj.collisions = reader.read("!Q")[0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 946 | return obj |
| 947 | |
| 948 | def __eq__(self, other): |
| 949 | if type(self) != type(other): return False |
| 950 | if self.port_no != other.port_no: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 951 | if self.rx_packets != other.rx_packets: return False |
| 952 | if self.tx_packets != other.tx_packets: return False |
| 953 | if self.rx_bytes != other.rx_bytes: return False |
| 954 | if self.tx_bytes != other.tx_bytes: return False |
| 955 | if self.rx_dropped != other.rx_dropped: return False |
| 956 | if self.tx_dropped != other.tx_dropped: return False |
| 957 | if self.rx_errors != other.rx_errors: return False |
| 958 | if self.tx_errors != other.tx_errors: return False |
| 959 | if self.rx_frame_err != other.rx_frame_err: return False |
| 960 | if self.rx_over_err != other.rx_over_err: return False |
| 961 | if self.rx_crc_err != other.rx_crc_err: return False |
| 962 | if self.collisions != other.collisions: return False |
| 963 | return True |
| 964 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 965 | def pretty_print(self, q): |
| 966 | q.text("port_stats_entry {") |
| 967 | with q.group(): |
| 968 | with q.indent(2): |
| 969 | q.breakable() |
| 970 | q.text("port_no = "); |
| 971 | q.text(util.pretty_port(self.port_no)) |
| 972 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 973 | q.text("rx_packets = "); |
| 974 | q.text("%#x" % self.rx_packets) |
| 975 | q.text(","); q.breakable() |
| 976 | q.text("tx_packets = "); |
| 977 | q.text("%#x" % self.tx_packets) |
| 978 | q.text(","); q.breakable() |
| 979 | q.text("rx_bytes = "); |
| 980 | q.text("%#x" % self.rx_bytes) |
| 981 | q.text(","); q.breakable() |
| 982 | q.text("tx_bytes = "); |
| 983 | q.text("%#x" % self.tx_bytes) |
| 984 | q.text(","); q.breakable() |
| 985 | q.text("rx_dropped = "); |
| 986 | q.text("%#x" % self.rx_dropped) |
| 987 | q.text(","); q.breakable() |
| 988 | q.text("tx_dropped = "); |
| 989 | q.text("%#x" % self.tx_dropped) |
| 990 | q.text(","); q.breakable() |
| 991 | q.text("rx_errors = "); |
| 992 | q.text("%#x" % self.rx_errors) |
| 993 | q.text(","); q.breakable() |
| 994 | q.text("tx_errors = "); |
| 995 | q.text("%#x" % self.tx_errors) |
| 996 | q.text(","); q.breakable() |
| 997 | q.text("rx_frame_err = "); |
| 998 | q.text("%#x" % self.rx_frame_err) |
| 999 | q.text(","); q.breakable() |
| 1000 | q.text("rx_over_err = "); |
| 1001 | q.text("%#x" % self.rx_over_err) |
| 1002 | q.text(","); q.breakable() |
| 1003 | q.text("rx_crc_err = "); |
| 1004 | q.text("%#x" % self.rx_crc_err) |
| 1005 | q.text(","); q.breakable() |
| 1006 | q.text("collisions = "); |
| 1007 | q.text("%#x" % self.collisions) |
| 1008 | q.breakable() |
| 1009 | q.text('}') |
| 1010 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1011 | |
| 1012 | class queue_prop(loxi.OFObject): |
| 1013 | subtypes = {} |
| 1014 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 1015 | |
| 1016 | def __init__(self, type=None): |
| 1017 | if type != None: |
| 1018 | self.type = type |
| 1019 | else: |
| 1020 | self.type = 0 |
| 1021 | return |
| 1022 | |
| 1023 | def pack(self): |
| 1024 | packed = [] |
| 1025 | packed.append(struct.pack("!H", self.type)) |
| 1026 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1027 | packed.append('\x00' * 4) |
| 1028 | length = sum([len(x) for x in packed]) |
| 1029 | packed[1] = struct.pack("!H", length) |
| 1030 | return ''.join(packed) |
| 1031 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1032 | @staticmethod |
| 1033 | def unpack(reader): |
| 1034 | subtype, = reader.peek('!H', 0) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 1035 | subclass = queue_prop.subtypes.get(subtype) |
| 1036 | if subclass: |
| 1037 | return subclass.unpack(reader) |
| 1038 | |
| 1039 | obj = queue_prop() |
| 1040 | obj.type = reader.read("!H")[0] |
| 1041 | _len = reader.read("!H")[0] |
| 1042 | orig_reader = reader |
| 1043 | reader = orig_reader.slice(_len - (2 + 2)) |
| 1044 | reader.skip(4) |
| 1045 | return obj |
| 1046 | |
| 1047 | def __eq__(self, other): |
| 1048 | if type(self) != type(other): return False |
| 1049 | if self.type != other.type: return False |
| 1050 | return True |
| 1051 | |
| 1052 | def pretty_print(self, q): |
| 1053 | q.text("queue_prop {") |
| 1054 | with q.group(): |
| 1055 | with q.indent(2): |
| 1056 | q.breakable() |
| 1057 | q.breakable() |
| 1058 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1059 | |
| 1060 | |
| 1061 | class queue_prop_min_rate(queue_prop): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1062 | type = 1 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1063 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1064 | def __init__(self, rate=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1065 | if rate != None: |
| 1066 | self.rate = rate |
| 1067 | else: |
| 1068 | self.rate = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1069 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1070 | |
| 1071 | def pack(self): |
| 1072 | packed = [] |
| 1073 | packed.append(struct.pack("!H", self.type)) |
| 1074 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1075 | packed.append('\x00' * 4) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1076 | packed.append(struct.pack("!H", self.rate)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1077 | packed.append('\x00' * 6) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1078 | length = sum([len(x) for x in packed]) |
| 1079 | packed[1] = struct.pack("!H", length) |
| 1080 | return ''.join(packed) |
| 1081 | |
| 1082 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1083 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1084 | obj = queue_prop_min_rate() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1085 | _type = reader.read("!H")[0] |
| 1086 | assert(_type == 1) |
| 1087 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1088 | orig_reader = reader |
| 1089 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1090 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1091 | obj.rate = reader.read("!H")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1092 | reader.skip(6) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1093 | return obj |
| 1094 | |
| 1095 | def __eq__(self, other): |
| 1096 | if type(self) != type(other): return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1097 | if self.rate != other.rate: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1098 | return True |
| 1099 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1100 | def pretty_print(self, q): |
| 1101 | q.text("queue_prop_min_rate {") |
| 1102 | with q.group(): |
| 1103 | with q.indent(2): |
| 1104 | q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1105 | q.text("rate = "); |
| 1106 | q.text("%#x" % self.rate) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1107 | q.breakable() |
| 1108 | q.text('}') |
| 1109 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1110 | queue_prop.subtypes[1] = queue_prop_min_rate |
| 1111 | |
| 1112 | class queue_stats_entry(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1113 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1114 | def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1115 | if port_no != None: |
| 1116 | self.port_no = port_no |
| 1117 | else: |
| 1118 | self.port_no = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1119 | if queue_id != None: |
| 1120 | self.queue_id = queue_id |
| 1121 | else: |
| 1122 | self.queue_id = 0 |
| 1123 | if tx_bytes != None: |
| 1124 | self.tx_bytes = tx_bytes |
| 1125 | else: |
| 1126 | self.tx_bytes = 0 |
| 1127 | if tx_packets != None: |
| 1128 | self.tx_packets = tx_packets |
| 1129 | else: |
| 1130 | self.tx_packets = 0 |
| 1131 | if tx_errors != None: |
| 1132 | self.tx_errors = tx_errors |
| 1133 | else: |
| 1134 | self.tx_errors = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1135 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1136 | |
| 1137 | def pack(self): |
| 1138 | packed = [] |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1139 | packed.append(util.pack_port_no(self.port_no)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1140 | packed.append('\x00' * 2) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1141 | packed.append(struct.pack("!L", self.queue_id)) |
| 1142 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 1143 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 1144 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 1145 | return ''.join(packed) |
| 1146 | |
| 1147 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1148 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1149 | obj = queue_stats_entry() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1150 | obj.port_no = util.unpack_port_no(reader) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1151 | reader.skip(2) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1152 | obj.queue_id = reader.read("!L")[0] |
| 1153 | obj.tx_bytes = reader.read("!Q")[0] |
| 1154 | obj.tx_packets = reader.read("!Q")[0] |
| 1155 | obj.tx_errors = reader.read("!Q")[0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1156 | return obj |
| 1157 | |
| 1158 | def __eq__(self, other): |
| 1159 | if type(self) != type(other): return False |
| 1160 | if self.port_no != other.port_no: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1161 | if self.queue_id != other.queue_id: return False |
| 1162 | if self.tx_bytes != other.tx_bytes: return False |
| 1163 | if self.tx_packets != other.tx_packets: return False |
| 1164 | if self.tx_errors != other.tx_errors: return False |
| 1165 | return True |
| 1166 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1167 | def pretty_print(self, q): |
| 1168 | q.text("queue_stats_entry {") |
| 1169 | with q.group(): |
| 1170 | with q.indent(2): |
| 1171 | q.breakable() |
| 1172 | q.text("port_no = "); |
| 1173 | q.text(util.pretty_port(self.port_no)) |
| 1174 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1175 | q.text("queue_id = "); |
| 1176 | q.text("%#x" % self.queue_id) |
| 1177 | q.text(","); q.breakable() |
| 1178 | q.text("tx_bytes = "); |
| 1179 | q.text("%#x" % self.tx_bytes) |
| 1180 | q.text(","); q.breakable() |
| 1181 | q.text("tx_packets = "); |
| 1182 | q.text("%#x" % self.tx_packets) |
| 1183 | q.text(","); q.breakable() |
| 1184 | q.text("tx_errors = "); |
| 1185 | q.text("%#x" % self.tx_errors) |
| 1186 | q.breakable() |
| 1187 | q.text('}') |
| 1188 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1189 | |
| 1190 | class table_stats_entry(loxi.OFObject): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1191 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1192 | def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1193 | if table_id != None: |
| 1194 | self.table_id = table_id |
| 1195 | else: |
| 1196 | self.table_id = 0 |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1197 | if name != None: |
| 1198 | self.name = name |
| 1199 | else: |
| 1200 | self.name = "" |
| 1201 | if wildcards != None: |
| 1202 | self.wildcards = wildcards |
| 1203 | else: |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1204 | self.wildcards = util.init_wc_bmap() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1205 | if max_entries != None: |
| 1206 | self.max_entries = max_entries |
| 1207 | else: |
| 1208 | self.max_entries = 0 |
| 1209 | if active_count != None: |
| 1210 | self.active_count = active_count |
| 1211 | else: |
| 1212 | self.active_count = 0 |
| 1213 | if lookup_count != None: |
| 1214 | self.lookup_count = lookup_count |
| 1215 | else: |
| 1216 | self.lookup_count = 0 |
| 1217 | if matched_count != None: |
| 1218 | self.matched_count = matched_count |
| 1219 | else: |
| 1220 | self.matched_count = 0 |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1221 | return |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1222 | |
| 1223 | def pack(self): |
| 1224 | packed = [] |
| 1225 | packed.append(struct.pack("!B", self.table_id)) |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1226 | packed.append('\x00' * 3) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1227 | packed.append(struct.pack("!32s", self.name)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1228 | packed.append(util.pack_wc_bmap(self.wildcards)) |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1229 | packed.append(struct.pack("!L", self.max_entries)) |
| 1230 | packed.append(struct.pack("!L", self.active_count)) |
| 1231 | packed.append(struct.pack("!Q", self.lookup_count)) |
| 1232 | packed.append(struct.pack("!Q", self.matched_count)) |
| 1233 | return ''.join(packed) |
| 1234 | |
| 1235 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1236 | def unpack(reader): |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1237 | obj = table_stats_entry() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1238 | obj.table_id = reader.read("!B")[0] |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1239 | reader.skip(3) |
| 1240 | obj.name = reader.read("!32s")[0].rstrip("\x00") |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 1241 | obj.wildcards = util.unpack_wc_bmap(reader) |
| 1242 | obj.max_entries = reader.read("!L")[0] |
| 1243 | obj.active_count = reader.read("!L")[0] |
| 1244 | obj.lookup_count = reader.read("!Q")[0] |
| 1245 | obj.matched_count = reader.read("!Q")[0] |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1246 | return obj |
| 1247 | |
| 1248 | def __eq__(self, other): |
| 1249 | if type(self) != type(other): return False |
| 1250 | if self.table_id != other.table_id: return False |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1251 | if self.name != other.name: return False |
| 1252 | if self.wildcards != other.wildcards: return False |
| 1253 | if self.max_entries != other.max_entries: return False |
| 1254 | if self.active_count != other.active_count: return False |
| 1255 | if self.lookup_count != other.lookup_count: return False |
| 1256 | if self.matched_count != other.matched_count: return False |
| 1257 | return True |
| 1258 | |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1259 | def pretty_print(self, q): |
| 1260 | q.text("table_stats_entry {") |
| 1261 | with q.group(): |
| 1262 | with q.indent(2): |
| 1263 | q.breakable() |
| 1264 | q.text("table_id = "); |
| 1265 | q.text("%#x" % self.table_id) |
| 1266 | q.text(","); q.breakable() |
Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1267 | q.text("name = "); |
| 1268 | q.pp(self.name) |
| 1269 | q.text(","); q.breakable() |
| 1270 | q.text("wildcards = "); |
| 1271 | q.text(util.pretty_wildcards(self.wildcards)) |
| 1272 | q.text(","); q.breakable() |
| 1273 | q.text("max_entries = "); |
| 1274 | q.text("%#x" % self.max_entries) |
| 1275 | q.text(","); q.breakable() |
| 1276 | q.text("active_count = "); |
| 1277 | q.text("%#x" % self.active_count) |
| 1278 | q.text(","); q.breakable() |
| 1279 | q.text("lookup_count = "); |
| 1280 | q.text("%#x" % self.lookup_count) |
| 1281 | q.text(","); q.breakable() |
| 1282 | q.text("matched_count = "); |
| 1283 | q.text("%#x" % self.matched_count) |
| 1284 | q.breakable() |
| 1285 | q.text('}') |
| 1286 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1287 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 1288 | |
Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -0700 | [diff] [blame] | 1289 | match = match_v1 |