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