blob: 98dbfefa84ee1f1b061202acea220c4835e1703f [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001# 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 Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Lane7dcdf022013-12-11 14:45:27 -08005
6# Automatically generated by LOXI from template module.py
Rich Laneb658ddd2013-03-12 10:15:10 -07007# Do not modify
8
Rich Laneb658ddd2013-03-12 10:15:10 -07009import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Laneb658ddd2013-03-12 10:15:10 -070011import const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
Rich Laneb658ddd2013-03-12 10:15:10 -070014import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070015import loxi.generic_util
16
Rich Lane7dcdf022013-12-11 14:45:27 -080017class bsn_interface(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -070018
Rich Lanec2ee4b82013-04-24 17:12:38 -070019 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070020 if hw_addr != None:
21 self.hw_addr = hw_addr
22 else:
23 self.hw_addr = [0,0,0,0,0,0]
Rich Laneb658ddd2013-03-12 10:15:10 -070024 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 Lanec2ee4b82013-04-24 17:12:38 -070036 return
Rich Laneb658ddd2013-03-12 10:15:10 -070037
38 def pack(self):
39 packed = []
40 packed.append(struct.pack("!6B", *self.hw_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -070041 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -070042 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 Lane7dcdf022013-12-11 14:45:27 -080048 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -070049 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070050 obj.hw_addr = list(reader.read('!6B'))
51 reader.skip(2)
52 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -070053 obj.ipv4_addr = reader.read("!L")[0]
54 obj.ipv4_netmask = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -070055 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 Laneb658ddd2013-03-12 10:15:10 -070060 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 Laneb658ddd2013-03-12 10:15:10 -070065 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 Laneb658ddd2013-03-12 10:15:10 -070073 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 Lane7dcdf022013-12-11 14:45:27 -080084
85class bsn_vport(loxi.OFObject):
86 subtypes = {}
87
Rich Lane95f7fc92014-01-27 17:08:16 -080088
89 def __init__(self, type=None):
90 if type != None:
91 self.type = type
92 else:
93 self.type = 0
94 return
95
96 def pack(self):
97 packed = []
98 packed.append(struct.pack("!H", self.type))
99 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
100 length = sum([len(x) for x in packed])
101 packed[1] = struct.pack("!H", length)
102 return ''.join(packed)
103
Rich Lane7dcdf022013-12-11 14:45:27 -0800104 @staticmethod
105 def unpack(reader):
106 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -0800107 subclass = bsn_vport.subtypes.get(subtype)
108 if subclass:
109 return subclass.unpack(reader)
110
111 obj = bsn_vport()
112 obj.type = reader.read("!H")[0]
113 _length = reader.read("!H")[0]
114 orig_reader = reader
115 reader = orig_reader.slice(_length - (2 + 2))
116 return obj
117
118 def __eq__(self, other):
119 if type(self) != type(other): return False
120 if self.type != other.type: return False
121 return True
122
123 def pretty_print(self, q):
124 q.text("bsn_vport {")
125 with q.group():
126 with q.indent(2):
127 q.breakable()
128 q.breakable()
129 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800130
131
Rich Lane93b33132014-04-21 12:20:58 -0700132class bsn_vport_l2gre(bsn_vport):
133 type = 1
134
135 def __init__(self, flags=None, port_no=None, local_mac=None, nh_mac=None, src_ip=None, dst_ip=None, dscp=None, ttl=None, vpn=None, if_name=None):
136 if flags != None:
137 self.flags = flags
138 else:
139 self.flags = 0
140 if port_no != None:
141 self.port_no = port_no
142 else:
143 self.port_no = 0
144 if local_mac != None:
145 self.local_mac = local_mac
146 else:
147 self.local_mac = [0,0,0,0,0,0]
148 if nh_mac != None:
149 self.nh_mac = nh_mac
150 else:
151 self.nh_mac = [0,0,0,0,0,0]
152 if src_ip != None:
153 self.src_ip = src_ip
154 else:
155 self.src_ip = 0
156 if dst_ip != None:
157 self.dst_ip = dst_ip
158 else:
159 self.dst_ip = 0
160 if dscp != None:
161 self.dscp = dscp
162 else:
163 self.dscp = 0
164 if ttl != None:
165 self.ttl = ttl
166 else:
167 self.ttl = 0
168 if vpn != None:
169 self.vpn = vpn
170 else:
171 self.vpn = 0
172 if if_name != None:
173 self.if_name = if_name
174 else:
175 self.if_name = ""
176 return
177
178 def pack(self):
179 packed = []
180 packed.append(struct.pack("!H", self.type))
181 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
182 packed.append(struct.pack("!L", self.flags))
183 packed.append(util.pack_port_no(self.port_no))
184 packed.append(struct.pack("!6B", *self.local_mac))
185 packed.append(struct.pack("!6B", *self.nh_mac))
186 packed.append(struct.pack("!L", self.src_ip))
187 packed.append(struct.pack("!L", self.dst_ip))
188 packed.append(struct.pack("!B", self.dscp))
189 packed.append(struct.pack("!B", self.ttl))
190 packed.append('\x00' * 2)
191 packed.append(struct.pack("!L", self.vpn))
192 packed.append(struct.pack("!16s", self.if_name))
193 length = sum([len(x) for x in packed])
194 packed[1] = struct.pack("!H", length)
195 return ''.join(packed)
196
197 @staticmethod
198 def unpack(reader):
199 obj = bsn_vport_l2gre()
200 _type = reader.read("!H")[0]
201 assert(_type == 1)
202 _length = reader.read("!H")[0]
203 orig_reader = reader
204 reader = orig_reader.slice(_length - (2 + 2))
205 obj.flags = reader.read("!L")[0]
206 obj.port_no = util.unpack_port_no(reader)
207 obj.local_mac = list(reader.read('!6B'))
208 obj.nh_mac = list(reader.read('!6B'))
209 obj.src_ip = reader.read("!L")[0]
210 obj.dst_ip = reader.read("!L")[0]
211 obj.dscp = reader.read("!B")[0]
212 obj.ttl = reader.read("!B")[0]
213 reader.skip(2)
214 obj.vpn = reader.read("!L")[0]
215 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
216 return obj
217
218 def __eq__(self, other):
219 if type(self) != type(other): return False
220 if self.flags != other.flags: return False
221 if self.port_no != other.port_no: return False
222 if self.local_mac != other.local_mac: return False
223 if self.nh_mac != other.nh_mac: return False
224 if self.src_ip != other.src_ip: return False
225 if self.dst_ip != other.dst_ip: return False
226 if self.dscp != other.dscp: return False
227 if self.ttl != other.ttl: return False
228 if self.vpn != other.vpn: return False
229 if self.if_name != other.if_name: return False
230 return True
231
232 def pretty_print(self, q):
233 q.text("bsn_vport_l2gre {")
234 with q.group():
235 with q.indent(2):
236 q.breakable()
237 q.text("flags = ");
238 q.text("%#x" % self.flags)
239 q.text(","); q.breakable()
240 q.text("port_no = ");
241 q.text(util.pretty_port(self.port_no))
242 q.text(","); q.breakable()
243 q.text("local_mac = ");
244 q.text(util.pretty_mac(self.local_mac))
245 q.text(","); q.breakable()
246 q.text("nh_mac = ");
247 q.text(util.pretty_mac(self.nh_mac))
248 q.text(","); q.breakable()
249 q.text("src_ip = ");
250 q.text(util.pretty_ipv4(self.src_ip))
251 q.text(","); q.breakable()
252 q.text("dst_ip = ");
253 q.text(util.pretty_ipv4(self.dst_ip))
254 q.text(","); q.breakable()
255 q.text("dscp = ");
256 q.text("%#x" % self.dscp)
257 q.text(","); q.breakable()
258 q.text("ttl = ");
259 q.text("%#x" % self.ttl)
260 q.text(","); q.breakable()
261 q.text("vpn = ");
262 q.text("%#x" % self.vpn)
263 q.text(","); q.breakable()
264 q.text("if_name = ");
265 q.pp(self.if_name)
266 q.breakable()
267 q.text('}')
268
269bsn_vport.subtypes[1] = bsn_vport_l2gre
270
Rich Lane7dcdf022013-12-11 14:45:27 -0800271class bsn_vport_q_in_q(bsn_vport):
Dan Talaycof6202252013-07-02 01:00:29 -0700272 type = 0
273
Kiran Poola150d8b02013-09-20 13:30:39 -0700274 def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None, if_name=None):
Dan Talaycof6202252013-07-02 01:00:29 -0700275 if port_no != None:
276 self.port_no = port_no
277 else:
278 self.port_no = 0
279 if ingress_tpid != None:
280 self.ingress_tpid = ingress_tpid
281 else:
282 self.ingress_tpid = 0
283 if ingress_vlan_id != None:
284 self.ingress_vlan_id = ingress_vlan_id
285 else:
286 self.ingress_vlan_id = 0
287 if egress_tpid != None:
288 self.egress_tpid = egress_tpid
289 else:
290 self.egress_tpid = 0
291 if egress_vlan_id != None:
292 self.egress_vlan_id = egress_vlan_id
293 else:
294 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700295 if if_name != None:
296 self.if_name = if_name
297 else:
298 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700299 return
300
301 def pack(self):
302 packed = []
303 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700304 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700305 packed.append(struct.pack("!L", self.port_no))
306 packed.append(struct.pack("!H", self.ingress_tpid))
307 packed.append(struct.pack("!H", self.ingress_vlan_id))
308 packed.append(struct.pack("!H", self.egress_tpid))
309 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700310 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700311 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700312 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700313 return ''.join(packed)
314
315 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800316 def unpack(reader):
Dan Talaycof6202252013-07-02 01:00:29 -0700317 obj = bsn_vport_q_in_q()
Dan Talaycof6202252013-07-02 01:00:29 -0700318 _type = reader.read("!H")[0]
319 assert(_type == 0)
320 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800321 orig_reader = reader
322 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700323 obj.port_no = reader.read("!L")[0]
324 obj.ingress_tpid = reader.read("!H")[0]
325 obj.ingress_vlan_id = reader.read("!H")[0]
326 obj.egress_tpid = reader.read("!H")[0]
327 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700328 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700329 return obj
330
331 def __eq__(self, other):
332 if type(self) != type(other): return False
333 if self.port_no != other.port_no: return False
334 if self.ingress_tpid != other.ingress_tpid: return False
335 if self.ingress_vlan_id != other.ingress_vlan_id: return False
336 if self.egress_tpid != other.egress_tpid: return False
337 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700338 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700339 return True
340
Dan Talaycof6202252013-07-02 01:00:29 -0700341 def pretty_print(self, q):
342 q.text("bsn_vport_q_in_q {")
343 with q.group():
344 with q.indent(2):
345 q.breakable()
346 q.text("port_no = ");
347 q.text("%#x" % self.port_no)
348 q.text(","); q.breakable()
349 q.text("ingress_tpid = ");
350 q.text("%#x" % self.ingress_tpid)
351 q.text(","); q.breakable()
352 q.text("ingress_vlan_id = ");
353 q.text("%#x" % self.ingress_vlan_id)
354 q.text(","); q.breakable()
355 q.text("egress_tpid = ");
356 q.text("%#x" % self.egress_tpid)
357 q.text(","); q.breakable()
358 q.text("egress_vlan_id = ");
359 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700360 q.text(","); q.breakable()
361 q.text("if_name = ");
362 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700363 q.breakable()
364 q.text('}')
365
Rich Lane7dcdf022013-12-11 14:45:27 -0800366bsn_vport.subtypes[0] = bsn_vport_q_in_q
367
368class flow_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700369
Rich Lanec2ee4b82013-04-24 17:12:38 -0700370 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 Laneb658ddd2013-03-12 10:15:10 -0700371 if table_id != None:
372 self.table_id = table_id
373 else:
374 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700375 if match != None:
376 self.match = match
377 else:
378 self.match = common.match()
379 if duration_sec != None:
380 self.duration_sec = duration_sec
381 else:
382 self.duration_sec = 0
383 if duration_nsec != None:
384 self.duration_nsec = duration_nsec
385 else:
386 self.duration_nsec = 0
387 if priority != None:
388 self.priority = priority
389 else:
390 self.priority = 0
391 if idle_timeout != None:
392 self.idle_timeout = idle_timeout
393 else:
394 self.idle_timeout = 0
395 if hard_timeout != None:
396 self.hard_timeout = hard_timeout
397 else:
398 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700399 if cookie != None:
400 self.cookie = cookie
401 else:
402 self.cookie = 0
403 if packet_count != None:
404 self.packet_count = packet_count
405 else:
406 self.packet_count = 0
407 if byte_count != None:
408 self.byte_count = byte_count
409 else:
410 self.byte_count = 0
411 if actions != None:
412 self.actions = actions
413 else:
414 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700415 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700416
417 def pack(self):
418 packed = []
419 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
420 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700421 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700422 packed.append(self.match.pack())
423 packed.append(struct.pack("!L", self.duration_sec))
424 packed.append(struct.pack("!L", self.duration_nsec))
425 packed.append(struct.pack("!H", self.priority))
426 packed.append(struct.pack("!H", self.idle_timeout))
427 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700428 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700429 packed.append(struct.pack("!Q", self.cookie))
430 packed.append(struct.pack("!Q", self.packet_count))
431 packed.append(struct.pack("!Q", self.byte_count))
Rich Lane7dcdf022013-12-11 14:45:27 -0800432 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneb658ddd2013-03-12 10:15:10 -0700433 length = sum([len(x) for x in packed])
434 packed[0] = struct.pack("!H", length)
435 return ''.join(packed)
436
437 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800438 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700439 obj = flow_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700440 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800441 orig_reader = reader
442 reader = orig_reader.slice(_length - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700443 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700444 reader.skip(1)
445 obj.match = common.match.unpack(reader)
Dan Talaycof6202252013-07-02 01:00:29 -0700446 obj.duration_sec = reader.read("!L")[0]
447 obj.duration_nsec = reader.read("!L")[0]
448 obj.priority = reader.read("!H")[0]
449 obj.idle_timeout = reader.read("!H")[0]
450 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700451 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700452 obj.cookie = reader.read("!Q")[0]
453 obj.packet_count = reader.read("!Q")[0]
454 obj.byte_count = reader.read("!Q")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800455 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -0700456 return obj
457
458 def __eq__(self, other):
459 if type(self) != type(other): return False
460 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700461 if self.match != other.match: return False
462 if self.duration_sec != other.duration_sec: return False
463 if self.duration_nsec != other.duration_nsec: return False
464 if self.priority != other.priority: return False
465 if self.idle_timeout != other.idle_timeout: return False
466 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700467 if self.cookie != other.cookie: return False
468 if self.packet_count != other.packet_count: return False
469 if self.byte_count != other.byte_count: return False
470 if self.actions != other.actions: return False
471 return True
472
Rich Laneb658ddd2013-03-12 10:15:10 -0700473 def pretty_print(self, q):
474 q.text("flow_stats_entry {")
475 with q.group():
476 with q.indent(2):
477 q.breakable()
478 q.text("table_id = ");
479 q.text("%#x" % self.table_id)
480 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700481 q.text("match = ");
482 q.pp(self.match)
483 q.text(","); q.breakable()
484 q.text("duration_sec = ");
485 q.text("%#x" % self.duration_sec)
486 q.text(","); q.breakable()
487 q.text("duration_nsec = ");
488 q.text("%#x" % self.duration_nsec)
489 q.text(","); q.breakable()
490 q.text("priority = ");
491 q.text("%#x" % self.priority)
492 q.text(","); q.breakable()
493 q.text("idle_timeout = ");
494 q.text("%#x" % self.idle_timeout)
495 q.text(","); q.breakable()
496 q.text("hard_timeout = ");
497 q.text("%#x" % self.hard_timeout)
498 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700499 q.text("cookie = ");
500 q.text("%#x" % self.cookie)
501 q.text(","); q.breakable()
502 q.text("packet_count = ");
503 q.text("%#x" % self.packet_count)
504 q.text(","); q.breakable()
505 q.text("byte_count = ");
506 q.text("%#x" % self.byte_count)
507 q.text(","); q.breakable()
508 q.text("actions = ");
509 q.pp(self.actions)
510 q.breakable()
511 q.text('}')
512
Rich Lane7dcdf022013-12-11 14:45:27 -0800513
514class match_v1(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700515
Rich Lanefe600f52013-07-09 13:22:32 -0700516 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 Laneb658ddd2013-03-12 10:15:10 -0700517 if wildcards != None:
518 self.wildcards = wildcards
519 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700520 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -0700521 if in_port != None:
522 self.in_port = in_port
523 else:
524 self.in_port = 0
525 if eth_src != None:
526 self.eth_src = eth_src
527 else:
528 self.eth_src = [0,0,0,0,0,0]
529 if eth_dst != None:
530 self.eth_dst = eth_dst
531 else:
532 self.eth_dst = [0,0,0,0,0,0]
533 if vlan_vid != None:
534 self.vlan_vid = vlan_vid
535 else:
536 self.vlan_vid = 0
537 if vlan_pcp != None:
538 self.vlan_pcp = vlan_pcp
539 else:
540 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700541 if eth_type != None:
542 self.eth_type = eth_type
543 else:
544 self.eth_type = 0
545 if ip_dscp != None:
546 self.ip_dscp = ip_dscp
547 else:
548 self.ip_dscp = 0
549 if ip_proto != None:
550 self.ip_proto = ip_proto
551 else:
552 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700553 if ipv4_src != None:
554 self.ipv4_src = ipv4_src
555 else:
556 self.ipv4_src = 0
557 if ipv4_dst != None:
558 self.ipv4_dst = ipv4_dst
559 else:
560 self.ipv4_dst = 0
561 if tcp_src != None:
562 self.tcp_src = tcp_src
563 else:
564 self.tcp_src = 0
565 if tcp_dst != None:
566 self.tcp_dst = tcp_dst
567 else:
568 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700569 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700570
571 def pack(self):
572 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700573 packed.append(util.pack_wc_bmap(self.wildcards))
574 packed.append(util.pack_port_no(self.in_port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700575 packed.append(struct.pack("!6B", *self.eth_src))
576 packed.append(struct.pack("!6B", *self.eth_dst))
577 packed.append(struct.pack("!H", self.vlan_vid))
578 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700579 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700580 packed.append(struct.pack("!H", self.eth_type))
581 packed.append(struct.pack("!B", self.ip_dscp))
582 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanefe600f52013-07-09 13:22:32 -0700583 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700584 packed.append(struct.pack("!L", self.ipv4_src))
585 packed.append(struct.pack("!L", self.ipv4_dst))
586 packed.append(struct.pack("!H", self.tcp_src))
587 packed.append(struct.pack("!H", self.tcp_dst))
588 return ''.join(packed)
589
590 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800591 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700592 obj = match_v1()
Dan Talaycof6202252013-07-02 01:00:29 -0700593 obj.wildcards = util.unpack_wc_bmap(reader)
594 obj.in_port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700595 obj.eth_src = list(reader.read('!6B'))
596 obj.eth_dst = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700597 obj.vlan_vid = reader.read("!H")[0]
598 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700599 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700600 obj.eth_type = reader.read("!H")[0]
601 obj.ip_dscp = reader.read("!B")[0]
602 obj.ip_proto = reader.read("!B")[0]
Rich Lanefe600f52013-07-09 13:22:32 -0700603 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700604 obj.ipv4_src = reader.read("!L")[0]
605 obj.ipv4_dst = reader.read("!L")[0]
606 obj.tcp_src = reader.read("!H")[0]
607 obj.tcp_dst = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700608 return obj
609
610 def __eq__(self, other):
611 if type(self) != type(other): return False
612 if self.wildcards != other.wildcards: return False
613 if self.in_port != other.in_port: return False
614 if self.eth_src != other.eth_src: return False
615 if self.eth_dst != other.eth_dst: return False
616 if self.vlan_vid != other.vlan_vid: return False
617 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700618 if self.eth_type != other.eth_type: return False
619 if self.ip_dscp != other.ip_dscp: return False
620 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700621 if self.ipv4_src != other.ipv4_src: return False
622 if self.ipv4_dst != other.ipv4_dst: return False
623 if self.tcp_src != other.tcp_src: return False
624 if self.tcp_dst != other.tcp_dst: return False
625 return True
626
Rich Laneb658ddd2013-03-12 10:15:10 -0700627 def pretty_print(self, q):
628 q.text("match_v1 {")
629 with q.group():
630 with q.indent(2):
631 q.breakable()
632 q.text("wildcards = ");
633 q.text(util.pretty_wildcards(self.wildcards))
634 q.text(","); q.breakable()
635 q.text("in_port = ");
636 q.text(util.pretty_port(self.in_port))
637 q.text(","); q.breakable()
638 q.text("eth_src = ");
639 q.text(util.pretty_mac(self.eth_src))
640 q.text(","); q.breakable()
641 q.text("eth_dst = ");
642 q.text(util.pretty_mac(self.eth_dst))
643 q.text(","); q.breakable()
644 q.text("vlan_vid = ");
645 q.text("%#x" % self.vlan_vid)
646 q.text(","); q.breakable()
647 q.text("vlan_pcp = ");
648 q.text("%#x" % self.vlan_pcp)
649 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700650 q.text("eth_type = ");
651 q.text("%#x" % self.eth_type)
652 q.text(","); q.breakable()
653 q.text("ip_dscp = ");
654 q.text("%#x" % self.ip_dscp)
655 q.text(","); q.breakable()
656 q.text("ip_proto = ");
657 q.text("%#x" % self.ip_proto)
658 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700659 q.text("ipv4_src = ");
660 q.text(util.pretty_ipv4(self.ipv4_src))
661 q.text(","); q.breakable()
662 q.text("ipv4_dst = ");
663 q.text(util.pretty_ipv4(self.ipv4_dst))
664 q.text(","); q.breakable()
665 q.text("tcp_src = ");
666 q.text("%#x" % self.tcp_src)
667 q.text(","); q.breakable()
668 q.text("tcp_dst = ");
669 q.text("%#x" % self.tcp_dst)
670 q.breakable()
671 q.text('}')
672
Rich Lane7dcdf022013-12-11 14:45:27 -0800673
674class packet_queue(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700675
Rich Lanec2ee4b82013-04-24 17:12:38 -0700676 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700677 if queue_id != None:
678 self.queue_id = queue_id
679 else:
680 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700681 if properties != None:
682 self.properties = properties
683 else:
684 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700685 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700686
687 def pack(self):
688 packed = []
689 packed.append(struct.pack("!L", self.queue_id))
690 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700691 packed.append('\x00' * 2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800692 packed.append(loxi.generic_util.pack_list(self.properties))
Rich Laneb658ddd2013-03-12 10:15:10 -0700693 length = sum([len(x) for x in packed])
694 packed[1] = struct.pack("!H", length)
695 return ''.join(packed)
696
697 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800698 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700699 obj = packet_queue()
Dan Talaycof6202252013-07-02 01:00:29 -0700700 obj.queue_id = reader.read("!L")[0]
701 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800702 orig_reader = reader
703 reader = orig_reader.slice(_len - (4 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700704 reader.skip(2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800705 obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -0700706 return obj
707
708 def __eq__(self, other):
709 if type(self) != type(other): return False
710 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700711 if self.properties != other.properties: return False
712 return True
713
Rich Laneb658ddd2013-03-12 10:15:10 -0700714 def pretty_print(self, q):
715 q.text("packet_queue {")
716 with q.group():
717 with q.indent(2):
718 q.breakable()
719 q.text("queue_id = ");
720 q.text("%#x" % self.queue_id)
721 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700722 q.text("properties = ");
723 q.pp(self.properties)
724 q.breakable()
725 q.text('}')
726
Rich Lane7dcdf022013-12-11 14:45:27 -0800727
728class port_desc(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700729
730 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
731 if port_no != None:
732 self.port_no = port_no
733 else:
734 self.port_no = 0
735 if hw_addr != None:
736 self.hw_addr = hw_addr
737 else:
738 self.hw_addr = [0,0,0,0,0,0]
739 if name != None:
740 self.name = name
741 else:
742 self.name = ""
743 if config != None:
744 self.config = config
745 else:
746 self.config = 0
747 if state != None:
748 self.state = state
749 else:
750 self.state = 0
751 if curr != None:
752 self.curr = curr
753 else:
754 self.curr = 0
755 if advertised != None:
756 self.advertised = advertised
757 else:
758 self.advertised = 0
759 if supported != None:
760 self.supported = supported
761 else:
762 self.supported = 0
763 if peer != None:
764 self.peer = peer
765 else:
766 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700767 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700768
769 def pack(self):
770 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700771 packed.append(util.pack_port_no(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -0700772 packed.append(struct.pack("!6B", *self.hw_addr))
773 packed.append(struct.pack("!16s", self.name))
774 packed.append(struct.pack("!L", self.config))
775 packed.append(struct.pack("!L", self.state))
776 packed.append(struct.pack("!L", self.curr))
777 packed.append(struct.pack("!L", self.advertised))
778 packed.append(struct.pack("!L", self.supported))
779 packed.append(struct.pack("!L", self.peer))
780 return ''.join(packed)
781
782 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800783 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700784 obj = port_desc()
Dan Talaycof6202252013-07-02 01:00:29 -0700785 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700786 obj.hw_addr = list(reader.read('!6B'))
787 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700788 obj.config = reader.read("!L")[0]
789 obj.state = reader.read("!L")[0]
790 obj.curr = reader.read("!L")[0]
791 obj.advertised = reader.read("!L")[0]
792 obj.supported = reader.read("!L")[0]
793 obj.peer = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700794 return obj
795
796 def __eq__(self, other):
797 if type(self) != type(other): return False
798 if self.port_no != other.port_no: return False
799 if self.hw_addr != other.hw_addr: return False
800 if self.name != other.name: return False
801 if self.config != other.config: return False
802 if self.state != other.state: return False
803 if self.curr != other.curr: return False
804 if self.advertised != other.advertised: return False
805 if self.supported != other.supported: return False
806 if self.peer != other.peer: return False
807 return True
808
Rich Laneb658ddd2013-03-12 10:15:10 -0700809 def pretty_print(self, q):
810 q.text("port_desc {")
811 with q.group():
812 with q.indent(2):
813 q.breakable()
814 q.text("port_no = ");
815 q.text(util.pretty_port(self.port_no))
816 q.text(","); q.breakable()
817 q.text("hw_addr = ");
818 q.text(util.pretty_mac(self.hw_addr))
819 q.text(","); q.breakable()
820 q.text("name = ");
821 q.pp(self.name)
822 q.text(","); q.breakable()
823 q.text("config = ");
824 q.text("%#x" % self.config)
825 q.text(","); q.breakable()
826 q.text("state = ");
827 q.text("%#x" % self.state)
828 q.text(","); q.breakable()
829 q.text("curr = ");
830 q.text("%#x" % self.curr)
831 q.text(","); q.breakable()
832 q.text("advertised = ");
833 q.text("%#x" % self.advertised)
834 q.text(","); q.breakable()
835 q.text("supported = ");
836 q.text("%#x" % self.supported)
837 q.text(","); q.breakable()
838 q.text("peer = ");
839 q.text("%#x" % self.peer)
840 q.breakable()
841 q.text('}')
842
Rich Lane7dcdf022013-12-11 14:45:27 -0800843
844class port_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700845
Rich Lanec2ee4b82013-04-24 17:12:38 -0700846 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 Laneb658ddd2013-03-12 10:15:10 -0700847 if port_no != None:
848 self.port_no = port_no
849 else:
850 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700851 if rx_packets != None:
852 self.rx_packets = rx_packets
853 else:
854 self.rx_packets = 0
855 if tx_packets != None:
856 self.tx_packets = tx_packets
857 else:
858 self.tx_packets = 0
859 if rx_bytes != None:
860 self.rx_bytes = rx_bytes
861 else:
862 self.rx_bytes = 0
863 if tx_bytes != None:
864 self.tx_bytes = tx_bytes
865 else:
866 self.tx_bytes = 0
867 if rx_dropped != None:
868 self.rx_dropped = rx_dropped
869 else:
870 self.rx_dropped = 0
871 if tx_dropped != None:
872 self.tx_dropped = tx_dropped
873 else:
874 self.tx_dropped = 0
875 if rx_errors != None:
876 self.rx_errors = rx_errors
877 else:
878 self.rx_errors = 0
879 if tx_errors != None:
880 self.tx_errors = tx_errors
881 else:
882 self.tx_errors = 0
883 if rx_frame_err != None:
884 self.rx_frame_err = rx_frame_err
885 else:
886 self.rx_frame_err = 0
887 if rx_over_err != None:
888 self.rx_over_err = rx_over_err
889 else:
890 self.rx_over_err = 0
891 if rx_crc_err != None:
892 self.rx_crc_err = rx_crc_err
893 else:
894 self.rx_crc_err = 0
895 if collisions != None:
896 self.collisions = collisions
897 else:
898 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700899 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700900
901 def pack(self):
902 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700903 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700904 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700905 packed.append(struct.pack("!Q", self.rx_packets))
906 packed.append(struct.pack("!Q", self.tx_packets))
907 packed.append(struct.pack("!Q", self.rx_bytes))
908 packed.append(struct.pack("!Q", self.tx_bytes))
909 packed.append(struct.pack("!Q", self.rx_dropped))
910 packed.append(struct.pack("!Q", self.tx_dropped))
911 packed.append(struct.pack("!Q", self.rx_errors))
912 packed.append(struct.pack("!Q", self.tx_errors))
913 packed.append(struct.pack("!Q", self.rx_frame_err))
914 packed.append(struct.pack("!Q", self.rx_over_err))
915 packed.append(struct.pack("!Q", self.rx_crc_err))
916 packed.append(struct.pack("!Q", self.collisions))
917 return ''.join(packed)
918
919 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800920 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700921 obj = port_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700922 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700923 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700924 obj.rx_packets = reader.read("!Q")[0]
925 obj.tx_packets = reader.read("!Q")[0]
926 obj.rx_bytes = reader.read("!Q")[0]
927 obj.tx_bytes = reader.read("!Q")[0]
928 obj.rx_dropped = reader.read("!Q")[0]
929 obj.tx_dropped = reader.read("!Q")[0]
930 obj.rx_errors = reader.read("!Q")[0]
931 obj.tx_errors = reader.read("!Q")[0]
932 obj.rx_frame_err = reader.read("!Q")[0]
933 obj.rx_over_err = reader.read("!Q")[0]
934 obj.rx_crc_err = reader.read("!Q")[0]
935 obj.collisions = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700936 return obj
937
938 def __eq__(self, other):
939 if type(self) != type(other): return False
940 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700941 if self.rx_packets != other.rx_packets: return False
942 if self.tx_packets != other.tx_packets: return False
943 if self.rx_bytes != other.rx_bytes: return False
944 if self.tx_bytes != other.tx_bytes: return False
945 if self.rx_dropped != other.rx_dropped: return False
946 if self.tx_dropped != other.tx_dropped: return False
947 if self.rx_errors != other.rx_errors: return False
948 if self.tx_errors != other.tx_errors: return False
949 if self.rx_frame_err != other.rx_frame_err: return False
950 if self.rx_over_err != other.rx_over_err: return False
951 if self.rx_crc_err != other.rx_crc_err: return False
952 if self.collisions != other.collisions: return False
953 return True
954
Rich Laneb658ddd2013-03-12 10:15:10 -0700955 def pretty_print(self, q):
956 q.text("port_stats_entry {")
957 with q.group():
958 with q.indent(2):
959 q.breakable()
960 q.text("port_no = ");
961 q.text(util.pretty_port(self.port_no))
962 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700963 q.text("rx_packets = ");
964 q.text("%#x" % self.rx_packets)
965 q.text(","); q.breakable()
966 q.text("tx_packets = ");
967 q.text("%#x" % self.tx_packets)
968 q.text(","); q.breakable()
969 q.text("rx_bytes = ");
970 q.text("%#x" % self.rx_bytes)
971 q.text(","); q.breakable()
972 q.text("tx_bytes = ");
973 q.text("%#x" % self.tx_bytes)
974 q.text(","); q.breakable()
975 q.text("rx_dropped = ");
976 q.text("%#x" % self.rx_dropped)
977 q.text(","); q.breakable()
978 q.text("tx_dropped = ");
979 q.text("%#x" % self.tx_dropped)
980 q.text(","); q.breakable()
981 q.text("rx_errors = ");
982 q.text("%#x" % self.rx_errors)
983 q.text(","); q.breakable()
984 q.text("tx_errors = ");
985 q.text("%#x" % self.tx_errors)
986 q.text(","); q.breakable()
987 q.text("rx_frame_err = ");
988 q.text("%#x" % self.rx_frame_err)
989 q.text(","); q.breakable()
990 q.text("rx_over_err = ");
991 q.text("%#x" % self.rx_over_err)
992 q.text(","); q.breakable()
993 q.text("rx_crc_err = ");
994 q.text("%#x" % self.rx_crc_err)
995 q.text(","); q.breakable()
996 q.text("collisions = ");
997 q.text("%#x" % self.collisions)
998 q.breakable()
999 q.text('}')
1000
Rich Lane7dcdf022013-12-11 14:45:27 -08001001
1002class queue_prop(loxi.OFObject):
1003 subtypes = {}
1004
Rich Lane95f7fc92014-01-27 17:08:16 -08001005
1006 def __init__(self, type=None):
1007 if type != None:
1008 self.type = type
1009 else:
1010 self.type = 0
1011 return
1012
1013 def pack(self):
1014 packed = []
1015 packed.append(struct.pack("!H", self.type))
1016 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1017 packed.append('\x00' * 4)
1018 length = sum([len(x) for x in packed])
1019 packed[1] = struct.pack("!H", length)
1020 return ''.join(packed)
1021
Rich Lane7dcdf022013-12-11 14:45:27 -08001022 @staticmethod
1023 def unpack(reader):
1024 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -08001025 subclass = queue_prop.subtypes.get(subtype)
1026 if subclass:
1027 return subclass.unpack(reader)
1028
1029 obj = queue_prop()
1030 obj.type = reader.read("!H")[0]
1031 _len = reader.read("!H")[0]
1032 orig_reader = reader
1033 reader = orig_reader.slice(_len - (2 + 2))
1034 reader.skip(4)
1035 return obj
1036
1037 def __eq__(self, other):
1038 if type(self) != type(other): return False
1039 if self.type != other.type: return False
1040 return True
1041
1042 def pretty_print(self, q):
1043 q.text("queue_prop {")
1044 with q.group():
1045 with q.indent(2):
1046 q.breakable()
1047 q.breakable()
1048 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -08001049
1050
1051class queue_prop_min_rate(queue_prop):
Dan Talaycof6202252013-07-02 01:00:29 -07001052 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -07001053
Rich Lanec2ee4b82013-04-24 17:12:38 -07001054 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001055 if rate != None:
1056 self.rate = rate
1057 else:
1058 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001059 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001060
1061 def pack(self):
1062 packed = []
1063 packed.append(struct.pack("!H", self.type))
1064 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001065 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -07001066 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001067 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -07001068 length = sum([len(x) for x in packed])
1069 packed[1] = struct.pack("!H", length)
1070 return ''.join(packed)
1071
1072 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001073 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001074 obj = queue_prop_min_rate()
Dan Talaycof6202252013-07-02 01:00:29 -07001075 _type = reader.read("!H")[0]
1076 assert(_type == 1)
1077 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001078 orig_reader = reader
1079 reader = orig_reader.slice(_len - (2 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001080 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001081 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001082 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -07001083 return obj
1084
1085 def __eq__(self, other):
1086 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001087 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001088 return True
1089
Rich Laneb658ddd2013-03-12 10:15:10 -07001090 def pretty_print(self, q):
1091 q.text("queue_prop_min_rate {")
1092 with q.group():
1093 with q.indent(2):
1094 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001095 q.text("rate = ");
1096 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -07001097 q.breakable()
1098 q.text('}')
1099
Rich Lane7dcdf022013-12-11 14:45:27 -08001100queue_prop.subtypes[1] = queue_prop_min_rate
1101
1102class queue_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -07001103
Rich Lanec2ee4b82013-04-24 17:12:38 -07001104 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001105 if port_no != None:
1106 self.port_no = port_no
1107 else:
1108 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001109 if queue_id != None:
1110 self.queue_id = queue_id
1111 else:
1112 self.queue_id = 0
1113 if tx_bytes != None:
1114 self.tx_bytes = tx_bytes
1115 else:
1116 self.tx_bytes = 0
1117 if tx_packets != None:
1118 self.tx_packets = tx_packets
1119 else:
1120 self.tx_packets = 0
1121 if tx_errors != None:
1122 self.tx_errors = tx_errors
1123 else:
1124 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001125 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001126
1127 def pack(self):
1128 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001129 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001130 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07001131 packed.append(struct.pack("!L", self.queue_id))
1132 packed.append(struct.pack("!Q", self.tx_bytes))
1133 packed.append(struct.pack("!Q", self.tx_packets))
1134 packed.append(struct.pack("!Q", self.tx_errors))
1135 return ''.join(packed)
1136
1137 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001138 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001139 obj = queue_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001140 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001141 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -07001142 obj.queue_id = reader.read("!L")[0]
1143 obj.tx_bytes = reader.read("!Q")[0]
1144 obj.tx_packets = reader.read("!Q")[0]
1145 obj.tx_errors = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001146 return obj
1147
1148 def __eq__(self, other):
1149 if type(self) != type(other): return False
1150 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001151 if self.queue_id != other.queue_id: return False
1152 if self.tx_bytes != other.tx_bytes: return False
1153 if self.tx_packets != other.tx_packets: return False
1154 if self.tx_errors != other.tx_errors: return False
1155 return True
1156
Rich Laneb658ddd2013-03-12 10:15:10 -07001157 def pretty_print(self, q):
1158 q.text("queue_stats_entry {")
1159 with q.group():
1160 with q.indent(2):
1161 q.breakable()
1162 q.text("port_no = ");
1163 q.text(util.pretty_port(self.port_no))
1164 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001165 q.text("queue_id = ");
1166 q.text("%#x" % self.queue_id)
1167 q.text(","); q.breakable()
1168 q.text("tx_bytes = ");
1169 q.text("%#x" % self.tx_bytes)
1170 q.text(","); q.breakable()
1171 q.text("tx_packets = ");
1172 q.text("%#x" % self.tx_packets)
1173 q.text(","); q.breakable()
1174 q.text("tx_errors = ");
1175 q.text("%#x" % self.tx_errors)
1176 q.breakable()
1177 q.text('}')
1178
Rich Lane7dcdf022013-12-11 14:45:27 -08001179
1180class table_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -07001181
Rich Lanec2ee4b82013-04-24 17:12:38 -07001182 def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001183 if table_id != None:
1184 self.table_id = table_id
1185 else:
1186 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001187 if name != None:
1188 self.name = name
1189 else:
1190 self.name = ""
1191 if wildcards != None:
1192 self.wildcards = wildcards
1193 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001194 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -07001195 if max_entries != None:
1196 self.max_entries = max_entries
1197 else:
1198 self.max_entries = 0
1199 if active_count != None:
1200 self.active_count = active_count
1201 else:
1202 self.active_count = 0
1203 if lookup_count != None:
1204 self.lookup_count = lookup_count
1205 else:
1206 self.lookup_count = 0
1207 if matched_count != None:
1208 self.matched_count = matched_count
1209 else:
1210 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001211 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001212
1213 def pack(self):
1214 packed = []
1215 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001216 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001217 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001218 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Laneb658ddd2013-03-12 10:15:10 -07001219 packed.append(struct.pack("!L", self.max_entries))
1220 packed.append(struct.pack("!L", self.active_count))
1221 packed.append(struct.pack("!Q", self.lookup_count))
1222 packed.append(struct.pack("!Q", self.matched_count))
1223 return ''.join(packed)
1224
1225 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001226 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001227 obj = table_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001228 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001229 reader.skip(3)
1230 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001231 obj.wildcards = util.unpack_wc_bmap(reader)
1232 obj.max_entries = reader.read("!L")[0]
1233 obj.active_count = reader.read("!L")[0]
1234 obj.lookup_count = reader.read("!Q")[0]
1235 obj.matched_count = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001236 return obj
1237
1238 def __eq__(self, other):
1239 if type(self) != type(other): return False
1240 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001241 if self.name != other.name: return False
1242 if self.wildcards != other.wildcards: return False
1243 if self.max_entries != other.max_entries: return False
1244 if self.active_count != other.active_count: return False
1245 if self.lookup_count != other.lookup_count: return False
1246 if self.matched_count != other.matched_count: return False
1247 return True
1248
Rich Laneb658ddd2013-03-12 10:15:10 -07001249 def pretty_print(self, q):
1250 q.text("table_stats_entry {")
1251 with q.group():
1252 with q.indent(2):
1253 q.breakable()
1254 q.text("table_id = ");
1255 q.text("%#x" % self.table_id)
1256 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001257 q.text("name = ");
1258 q.pp(self.name)
1259 q.text(","); q.breakable()
1260 q.text("wildcards = ");
1261 q.text(util.pretty_wildcards(self.wildcards))
1262 q.text(","); q.breakable()
1263 q.text("max_entries = ");
1264 q.text("%#x" % self.max_entries)
1265 q.text(","); q.breakable()
1266 q.text("active_count = ");
1267 q.text("%#x" % self.active_count)
1268 q.text(","); q.breakable()
1269 q.text("lookup_count = ");
1270 q.text("%#x" % self.lookup_count)
1271 q.text(","); q.breakable()
1272 q.text("matched_count = ");
1273 q.text("%#x" % self.matched_count)
1274 q.breakable()
1275 q.text('}')
1276
Rich Lanec2ee4b82013-04-24 17:12:38 -07001277
Rich Lane7dcdf022013-12-11 14:45:27 -08001278
Rich Lanec2ee4b82013-04-24 17:12:38 -07001279match = match_v1