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