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