blob: 698fe7ab596d026e8e0725c1734c762d963dff43 [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 Lanec2ee4b82013-04-24 17:12:38 -07005
6# Automatically generated by LOXI from template common.py
7# Do not modify
8
9import sys
10import struct
11import action
12import instruction # for unpack_list
13import const
14import util
15import loxi.generic_util
16
17import oxm
18
19# HACK make this module visible as 'common' to simplify code generation
20common = sys.modules[__name__]
21
22def unpack_list_flow_stats_entry(reader):
23 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
24
25def unpack_list_queue_prop(reader):
26 def deserializer(reader, typ):
27 if typ == const.OFPQT_MIN_RATE:
28 return queue_prop_min_rate.unpack(reader)
29 else:
30 raise loxi.ProtocolError("unknown queue prop %d" % typ)
31 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
32
33def unpack_list_packet_queue(reader):
34 def wrapper(reader):
35 length, = reader.peek('!4xH')
36 return packet_queue.unpack(reader.slice(length))
37 return loxi.generic_util.unpack_list(reader, wrapper)
38
39def unpack_list_hello_elem(reader):
40 def deserializer(reader, typ):
41 if typ == const.OFPHET_VERSIONBITMAP:
42 return hello_elem_versionbitmap.unpack(reader)
43 else:
44 return None
45 return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
46
47def unpack_list_bucket(reader):
48 return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
49
50def unpack_list_group_desc_stats_entry(reader):
51 return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
52
53def unpack_list_group_stats_entry(reader):
54 return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
55
56def unpack_list_meter_stats(reader):
57 def wrapper(reader):
58 length, = reader.peek('!4xH')
59 return meter_stats.unpack(reader.slice(length))
60 return loxi.generic_util.unpack_list(reader, wrapper)
61
62class bsn_interface(object):
63
64 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
65 if hw_addr != None:
66 self.hw_addr = hw_addr
67 else:
68 self.hw_addr = [0,0,0,0,0,0]
69 if name != None:
70 self.name = name
71 else:
72 self.name = ""
73 if ipv4_addr != None:
74 self.ipv4_addr = ipv4_addr
75 else:
76 self.ipv4_addr = 0
77 if ipv4_netmask != None:
78 self.ipv4_netmask = ipv4_netmask
79 else:
80 self.ipv4_netmask = 0
81 return
82
83 def pack(self):
84 packed = []
85 packed.append(struct.pack("!6B", *self.hw_addr))
86 packed.append('\x00' * 2)
87 packed.append(struct.pack("!16s", self.name))
88 packed.append(struct.pack("!L", self.ipv4_addr))
89 packed.append(struct.pack("!L", self.ipv4_netmask))
90 return ''.join(packed)
91
92 @staticmethod
93 def unpack(buf):
94 obj = bsn_interface()
95 if type(buf) == loxi.generic_util.OFReader:
96 reader = buf
97 else:
98 reader = loxi.generic_util.OFReader(buf)
99 obj.hw_addr = list(reader.read('!6B'))
100 reader.skip(2)
101 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700102 obj.ipv4_addr = reader.read("!L")[0]
103 obj.ipv4_netmask = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700104 return obj
105
106 def __eq__(self, other):
107 if type(self) != type(other): return False
108 if self.hw_addr != other.hw_addr: return False
109 if self.name != other.name: return False
110 if self.ipv4_addr != other.ipv4_addr: return False
111 if self.ipv4_netmask != other.ipv4_netmask: return False
112 return True
113
114 def __ne__(self, other):
115 return not self.__eq__(other)
116
117 def show(self):
118 import loxi.pp
119 return loxi.pp.pp(self)
120
121 def pretty_print(self, q):
122 q.text("bsn_interface {")
123 with q.group():
124 with q.indent(2):
125 q.breakable()
126 q.text("hw_addr = ");
127 q.text(util.pretty_mac(self.hw_addr))
128 q.text(","); q.breakable()
129 q.text("name = ");
130 q.pp(self.name)
131 q.text(","); q.breakable()
132 q.text("ipv4_addr = ");
133 q.text(util.pretty_ipv4(self.ipv4_addr))
134 q.text(","); q.breakable()
135 q.text("ipv4_netmask = ");
136 q.text(util.pretty_ipv4(self.ipv4_netmask))
137 q.breakable()
138 q.text('}')
139
Dan Talaycof6202252013-07-02 01:00:29 -0700140class bsn_vport_q_in_q(object):
141 type = 0
142
143 def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None):
144 if port_no != None:
145 self.port_no = port_no
146 else:
147 self.port_no = 0
148 if ingress_tpid != None:
149 self.ingress_tpid = ingress_tpid
150 else:
151 self.ingress_tpid = 0
152 if ingress_vlan_id != None:
153 self.ingress_vlan_id = ingress_vlan_id
154 else:
155 self.ingress_vlan_id = 0
156 if egress_tpid != None:
157 self.egress_tpid = egress_tpid
158 else:
159 self.egress_tpid = 0
160 if egress_vlan_id != None:
161 self.egress_vlan_id = egress_vlan_id
162 else:
163 self.egress_vlan_id = 0
164 return
165
166 def pack(self):
167 packed = []
168 packed.append(struct.pack("!H", self.type))
169 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
170 packed.append(struct.pack("!L", self.port_no))
171 packed.append(struct.pack("!H", self.ingress_tpid))
172 packed.append(struct.pack("!H", self.ingress_vlan_id))
173 packed.append(struct.pack("!H", self.egress_tpid))
174 packed.append(struct.pack("!H", self.egress_vlan_id))
175 length = sum([len(x) for x in packed])
176 packed[1] = struct.pack("!H", length)
177 return ''.join(packed)
178
179 @staticmethod
180 def unpack(buf):
181 obj = bsn_vport_q_in_q()
182 if type(buf) == loxi.generic_util.OFReader:
183 reader = buf
184 else:
185 reader = loxi.generic_util.OFReader(buf)
186 _type = reader.read("!H")[0]
187 assert(_type == 0)
188 _length = reader.read("!H")[0]
189 obj.port_no = reader.read("!L")[0]
190 obj.ingress_tpid = reader.read("!H")[0]
191 obj.ingress_vlan_id = reader.read("!H")[0]
192 obj.egress_tpid = reader.read("!H")[0]
193 obj.egress_vlan_id = reader.read("!H")[0]
194 return obj
195
196 def __eq__(self, other):
197 if type(self) != type(other): return False
198 if self.port_no != other.port_no: return False
199 if self.ingress_tpid != other.ingress_tpid: return False
200 if self.ingress_vlan_id != other.ingress_vlan_id: return False
201 if self.egress_tpid != other.egress_tpid: return False
202 if self.egress_vlan_id != other.egress_vlan_id: return False
203 return True
204
205 def __ne__(self, other):
206 return not self.__eq__(other)
207
208 def show(self):
209 import loxi.pp
210 return loxi.pp.pp(self)
211
212 def pretty_print(self, q):
213 q.text("bsn_vport_q_in_q {")
214 with q.group():
215 with q.indent(2):
216 q.breakable()
217 q.text("port_no = ");
218 q.text("%#x" % self.port_no)
219 q.text(","); q.breakable()
220 q.text("ingress_tpid = ");
221 q.text("%#x" % self.ingress_tpid)
222 q.text(","); q.breakable()
223 q.text("ingress_vlan_id = ");
224 q.text("%#x" % self.ingress_vlan_id)
225 q.text(","); q.breakable()
226 q.text("egress_tpid = ");
227 q.text("%#x" % self.egress_tpid)
228 q.text(","); q.breakable()
229 q.text("egress_vlan_id = ");
230 q.text("%#x" % self.egress_vlan_id)
231 q.breakable()
232 q.text('}')
233
Rich Lanec2ee4b82013-04-24 17:12:38 -0700234class bucket(object):
235
236 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
237 if weight != None:
238 self.weight = weight
239 else:
240 self.weight = 0
241 if watch_port != None:
242 self.watch_port = watch_port
243 else:
244 self.watch_port = 0
245 if watch_group != None:
246 self.watch_group = watch_group
247 else:
248 self.watch_group = 0
249 if actions != None:
250 self.actions = actions
251 else:
252 self.actions = []
253 return
254
255 def pack(self):
256 packed = []
257 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
258 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700259 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700260 packed.append(struct.pack("!L", self.watch_group))
261 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700262 packed.append(util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700263 length = sum([len(x) for x in packed])
264 packed[0] = struct.pack("!H", length)
265 return ''.join(packed)
266
267 @staticmethod
268 def unpack(buf):
269 obj = bucket()
270 if type(buf) == loxi.generic_util.OFReader:
271 reader = buf
272 else:
273 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700274 _len = reader.read("!H")[0]
275 obj.weight = reader.read("!H")[0]
276 obj.watch_port = util.unpack_port_no(reader)
277 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700278 reader.skip(4)
279 obj.actions = action.unpack_list(reader)
280 return obj
281
282 def __eq__(self, other):
283 if type(self) != type(other): return False
284 if self.weight != other.weight: return False
285 if self.watch_port != other.watch_port: return False
286 if self.watch_group != other.watch_group: return False
287 if self.actions != other.actions: return False
288 return True
289
290 def __ne__(self, other):
291 return not self.__eq__(other)
292
293 def show(self):
294 import loxi.pp
295 return loxi.pp.pp(self)
296
297 def pretty_print(self, q):
298 q.text("bucket {")
299 with q.group():
300 with q.indent(2):
301 q.breakable()
302 q.text("weight = ");
303 q.text("%#x" % self.weight)
304 q.text(","); q.breakable()
305 q.text("watch_port = ");
306 q.text(util.pretty_port(self.watch_port))
307 q.text(","); q.breakable()
308 q.text("watch_group = ");
309 q.text("%#x" % self.watch_group)
310 q.text(","); q.breakable()
311 q.text("actions = ");
312 q.pp(self.actions)
313 q.breakable()
314 q.text('}')
315
316class bucket_counter(object):
317
318 def __init__(self, packet_count=None, byte_count=None):
319 if packet_count != None:
320 self.packet_count = packet_count
321 else:
322 self.packet_count = 0
323 if byte_count != None:
324 self.byte_count = byte_count
325 else:
326 self.byte_count = 0
327 return
328
329 def pack(self):
330 packed = []
331 packed.append(struct.pack("!Q", self.packet_count))
332 packed.append(struct.pack("!Q", self.byte_count))
333 return ''.join(packed)
334
335 @staticmethod
336 def unpack(buf):
337 obj = bucket_counter()
338 if type(buf) == loxi.generic_util.OFReader:
339 reader = buf
340 else:
341 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700342 obj.packet_count = reader.read("!Q")[0]
343 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700344 return obj
345
346 def __eq__(self, other):
347 if type(self) != type(other): return False
348 if self.packet_count != other.packet_count: return False
349 if self.byte_count != other.byte_count: return False
350 return True
351
352 def __ne__(self, other):
353 return not self.__eq__(other)
354
355 def show(self):
356 import loxi.pp
357 return loxi.pp.pp(self)
358
359 def pretty_print(self, q):
360 q.text("bucket_counter {")
361 with q.group():
362 with q.indent(2):
363 q.breakable()
364 q.text("packet_count = ");
365 q.text("%#x" % self.packet_count)
366 q.text(","); q.breakable()
367 q.text("byte_count = ");
368 q.text("%#x" % self.byte_count)
369 q.breakable()
370 q.text('}')
371
372class flow_stats_entry(object):
373
374 def __init__(self, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, match=None, instructions=None):
375 if table_id != None:
376 self.table_id = table_id
377 else:
378 self.table_id = 0
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
399 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 match != None:
412 self.match = match
413 else:
414 self.match = common.match()
415 if instructions != None:
416 self.instructions = instructions
417 else:
418 self.instructions = []
419 return
420
421 def pack(self):
422 packed = []
423 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
424 packed.append(struct.pack("!B", self.table_id))
425 packed.append('\x00' * 1)
426 packed.append(struct.pack("!L", self.duration_sec))
427 packed.append(struct.pack("!L", self.duration_nsec))
428 packed.append(struct.pack("!H", self.priority))
429 packed.append(struct.pack("!H", self.idle_timeout))
430 packed.append(struct.pack("!H", self.hard_timeout))
431 packed.append('\x00' * 6)
432 packed.append(struct.pack("!Q", self.cookie))
433 packed.append(struct.pack("!Q", self.packet_count))
434 packed.append(struct.pack("!Q", self.byte_count))
435 packed.append(self.match.pack())
Dan Talaycof6202252013-07-02 01:00:29 -0700436 packed.append(util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700437 length = sum([len(x) for x in packed])
438 packed[0] = struct.pack("!H", length)
439 return ''.join(packed)
440
441 @staticmethod
442 def unpack(buf):
443 obj = flow_stats_entry()
444 if type(buf) == loxi.generic_util.OFReader:
445 reader = buf
446 else:
447 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700448 _length = reader.read("!H")[0]
449 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700450 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700451 obj.duration_sec = reader.read("!L")[0]
452 obj.duration_nsec = reader.read("!L")[0]
453 obj.priority = reader.read("!H")[0]
454 obj.idle_timeout = reader.read("!H")[0]
455 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700456 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700457 obj.cookie = reader.read("!Q")[0]
458 obj.packet_count = reader.read("!Q")[0]
459 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700460 obj.match = common.match.unpack(reader)
461 obj.instructions = instruction.unpack_list(reader)
462 return obj
463
464 def __eq__(self, other):
465 if type(self) != type(other): return False
466 if self.table_id != other.table_id: return False
467 if self.duration_sec != other.duration_sec: return False
468 if self.duration_nsec != other.duration_nsec: return False
469 if self.priority != other.priority: return False
470 if self.idle_timeout != other.idle_timeout: return False
471 if self.hard_timeout != other.hard_timeout: return False
472 if self.cookie != other.cookie: return False
473 if self.packet_count != other.packet_count: return False
474 if self.byte_count != other.byte_count: return False
475 if self.match != other.match: return False
476 if self.instructions != other.instructions: return False
477 return True
478
479 def __ne__(self, other):
480 return not self.__eq__(other)
481
482 def show(self):
483 import loxi.pp
484 return loxi.pp.pp(self)
485
486 def pretty_print(self, q):
487 q.text("flow_stats_entry {")
488 with q.group():
489 with q.indent(2):
490 q.breakable()
491 q.text("table_id = ");
492 q.text("%#x" % self.table_id)
493 q.text(","); q.breakable()
494 q.text("duration_sec = ");
495 q.text("%#x" % self.duration_sec)
496 q.text(","); q.breakable()
497 q.text("duration_nsec = ");
498 q.text("%#x" % self.duration_nsec)
499 q.text(","); q.breakable()
500 q.text("priority = ");
501 q.text("%#x" % self.priority)
502 q.text(","); q.breakable()
503 q.text("idle_timeout = ");
504 q.text("%#x" % self.idle_timeout)
505 q.text(","); q.breakable()
506 q.text("hard_timeout = ");
507 q.text("%#x" % self.hard_timeout)
508 q.text(","); q.breakable()
509 q.text("cookie = ");
510 q.text("%#x" % self.cookie)
511 q.text(","); q.breakable()
512 q.text("packet_count = ");
513 q.text("%#x" % self.packet_count)
514 q.text(","); q.breakable()
515 q.text("byte_count = ");
516 q.text("%#x" % self.byte_count)
517 q.text(","); q.breakable()
518 q.text("match = ");
519 q.pp(self.match)
520 q.text(","); q.breakable()
521 q.text("instructions = ");
522 q.pp(self.instructions)
523 q.breakable()
524 q.text('}')
525
526class group_desc_stats_entry(object):
527
528 def __init__(self, type=None, group_id=None, buckets=None):
529 if type != None:
530 self.type = type
531 else:
532 self.type = 0
533 if group_id != None:
534 self.group_id = group_id
535 else:
536 self.group_id = 0
537 if buckets != None:
538 self.buckets = buckets
539 else:
540 self.buckets = []
541 return
542
543 def pack(self):
544 packed = []
545 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
546 packed.append(struct.pack("!B", self.type))
547 packed.append('\x00' * 1)
548 packed.append(struct.pack("!L", self.group_id))
Dan Talaycof6202252013-07-02 01:00:29 -0700549 packed.append(util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700550 length = sum([len(x) for x in packed])
551 packed[0] = struct.pack("!H", length)
552 return ''.join(packed)
553
554 @staticmethod
555 def unpack(buf):
556 obj = group_desc_stats_entry()
557 if type(buf) == loxi.generic_util.OFReader:
558 reader = buf
559 else:
560 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700561 _length = reader.read("!H")[0]
562 obj.type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700563 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700564 obj.group_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700565 obj.buckets = common.unpack_list_bucket(reader)
566 return obj
567
568 def __eq__(self, other):
569 if type(self) != type(other): return False
570 if self.type != other.type: return False
571 if self.group_id != other.group_id: return False
572 if self.buckets != other.buckets: return False
573 return True
574
575 def __ne__(self, other):
576 return not self.__eq__(other)
577
578 def show(self):
579 import loxi.pp
580 return loxi.pp.pp(self)
581
582 def pretty_print(self, q):
583 q.text("group_desc_stats_entry {")
584 with q.group():
585 with q.indent(2):
586 q.breakable()
587 q.text("type = ");
588 q.text("%#x" % self.type)
589 q.text(","); q.breakable()
590 q.text("group_id = ");
591 q.text("%#x" % self.group_id)
592 q.text(","); q.breakable()
593 q.text("buckets = ");
594 q.pp(self.buckets)
595 q.breakable()
596 q.text('}')
597
598class group_stats_entry(object):
599
600 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
601 if group_id != None:
602 self.group_id = group_id
603 else:
604 self.group_id = 0
605 if ref_count != None:
606 self.ref_count = ref_count
607 else:
608 self.ref_count = 0
609 if packet_count != None:
610 self.packet_count = packet_count
611 else:
612 self.packet_count = 0
613 if byte_count != None:
614 self.byte_count = byte_count
615 else:
616 self.byte_count = 0
617 if bucket_stats != None:
618 self.bucket_stats = bucket_stats
619 else:
620 self.bucket_stats = []
621 return
622
623 def pack(self):
624 packed = []
625 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
626 packed.append('\x00' * 2)
627 packed.append(struct.pack("!L", self.group_id))
628 packed.append(struct.pack("!L", self.ref_count))
629 packed.append('\x00' * 4)
630 packed.append(struct.pack("!Q", self.packet_count))
631 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700632 packed.append(util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700633 length = sum([len(x) for x in packed])
634 packed[0] = struct.pack("!H", length)
635 return ''.join(packed)
636
637 @staticmethod
638 def unpack(buf):
639 obj = group_stats_entry()
640 if type(buf) == loxi.generic_util.OFReader:
641 reader = buf
642 else:
643 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700644 _length = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700645 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700646 obj.group_id = reader.read("!L")[0]
647 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700648 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700649 obj.packet_count = reader.read("!Q")[0]
650 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700651 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
652 return obj
653
654 def __eq__(self, other):
655 if type(self) != type(other): return False
656 if self.group_id != other.group_id: return False
657 if self.ref_count != other.ref_count: return False
658 if self.packet_count != other.packet_count: return False
659 if self.byte_count != other.byte_count: return False
660 if self.bucket_stats != other.bucket_stats: return False
661 return True
662
663 def __ne__(self, other):
664 return not self.__eq__(other)
665
666 def show(self):
667 import loxi.pp
668 return loxi.pp.pp(self)
669
670 def pretty_print(self, q):
671 q.text("group_stats_entry {")
672 with q.group():
673 with q.indent(2):
674 q.breakable()
675 q.text("group_id = ");
676 q.text("%#x" % self.group_id)
677 q.text(","); q.breakable()
678 q.text("ref_count = ");
679 q.text("%#x" % self.ref_count)
680 q.text(","); q.breakable()
681 q.text("packet_count = ");
682 q.text("%#x" % self.packet_count)
683 q.text(","); q.breakable()
684 q.text("byte_count = ");
685 q.text("%#x" % self.byte_count)
686 q.text(","); q.breakable()
687 q.text("bucket_stats = ");
688 q.pp(self.bucket_stats)
689 q.breakable()
690 q.text('}')
691
692class match_v3(object):
693 type = 1
694
695 def __init__(self, oxm_list=None):
696 if oxm_list != None:
697 self.oxm_list = oxm_list
698 else:
699 self.oxm_list = []
700 return
701
702 def pack(self):
703 packed = []
704 packed.append(struct.pack("!H", self.type))
705 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700706 packed.append(util.pack_list(self.oxm_list))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700707 length = sum([len(x) for x in packed])
708 packed[1] = struct.pack("!H", length)
Rich Laned53156a2013-08-05 17:17:33 -0700709 packed.append(loxi.generic_util.pad_to(8, length))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700710 return ''.join(packed)
711
712 @staticmethod
713 def unpack(buf):
714 obj = match_v3()
715 if type(buf) == loxi.generic_util.OFReader:
716 reader = buf
717 else:
718 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700719 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700720 assert(_type == 1)
Dan Talaycof6202252013-07-02 01:00:29 -0700721 _length = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700722 obj.oxm_list = oxm.unpack_list(reader.slice(_length-4))
Rich Laned53156a2013-08-05 17:17:33 -0700723 reader.skip_align()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700724 return obj
725
726 def __eq__(self, other):
727 if type(self) != type(other): return False
728 if self.oxm_list != other.oxm_list: return False
729 return True
730
731 def __ne__(self, other):
732 return not self.__eq__(other)
733
734 def show(self):
735 import loxi.pp
736 return loxi.pp.pp(self)
737
738 def pretty_print(self, q):
739 q.text("match_v3 {")
740 with q.group():
741 with q.indent(2):
742 q.breakable()
743 q.text("oxm_list = ");
744 q.pp(self.oxm_list)
745 q.breakable()
746 q.text('}')
747
748class packet_queue(object):
749
750 def __init__(self, queue_id=None, port=None, properties=None):
751 if queue_id != None:
752 self.queue_id = queue_id
753 else:
754 self.queue_id = 0
755 if port != None:
756 self.port = port
757 else:
758 self.port = 0
759 if properties != None:
760 self.properties = properties
761 else:
762 self.properties = []
763 return
764
765 def pack(self):
766 packed = []
767 packed.append(struct.pack("!L", self.queue_id))
Dan Talaycof6202252013-07-02 01:00:29 -0700768 packed.append(util.pack_port_no(self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700769 packed.append(struct.pack("!H", 0)) # placeholder for len at index 2
770 packed.append('\x00' * 6)
Dan Talaycof6202252013-07-02 01:00:29 -0700771 packed.append(util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700772 length = sum([len(x) for x in packed])
773 packed[2] = struct.pack("!H", length)
774 return ''.join(packed)
775
776 @staticmethod
777 def unpack(buf):
778 obj = packet_queue()
779 if type(buf) == loxi.generic_util.OFReader:
780 reader = buf
781 else:
782 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700783 obj.queue_id = reader.read("!L")[0]
784 obj.port = util.unpack_port_no(reader)
785 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700786 reader.skip(6)
787 obj.properties = common.unpack_list_queue_prop(reader)
788 return obj
789
790 def __eq__(self, other):
791 if type(self) != type(other): return False
792 if self.queue_id != other.queue_id: return False
793 if self.port != other.port: return False
794 if self.properties != other.properties: return False
795 return True
796
797 def __ne__(self, other):
798 return not self.__eq__(other)
799
800 def show(self):
801 import loxi.pp
802 return loxi.pp.pp(self)
803
804 def pretty_print(self, q):
805 q.text("packet_queue {")
806 with q.group():
807 with q.indent(2):
808 q.breakable()
809 q.text("queue_id = ");
810 q.text("%#x" % self.queue_id)
811 q.text(","); q.breakable()
812 q.text("port = ");
813 q.text(util.pretty_port(self.port))
814 q.text(","); q.breakable()
815 q.text("properties = ");
816 q.pp(self.properties)
817 q.breakable()
818 q.text('}')
819
820class port_desc(object):
821
822 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None, curr_speed=None, max_speed=None):
823 if port_no != None:
824 self.port_no = port_no
825 else:
826 self.port_no = 0
827 if hw_addr != None:
828 self.hw_addr = hw_addr
829 else:
830 self.hw_addr = [0,0,0,0,0,0]
831 if name != None:
832 self.name = name
833 else:
834 self.name = ""
835 if config != None:
836 self.config = config
837 else:
838 self.config = 0
839 if state != None:
840 self.state = state
841 else:
842 self.state = 0
843 if curr != None:
844 self.curr = curr
845 else:
846 self.curr = 0
847 if advertised != None:
848 self.advertised = advertised
849 else:
850 self.advertised = 0
851 if supported != None:
852 self.supported = supported
853 else:
854 self.supported = 0
855 if peer != None:
856 self.peer = peer
857 else:
858 self.peer = 0
859 if curr_speed != None:
860 self.curr_speed = curr_speed
861 else:
862 self.curr_speed = 0
863 if max_speed != None:
864 self.max_speed = max_speed
865 else:
866 self.max_speed = 0
867 return
868
869 def pack(self):
870 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700871 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700872 packed.append('\x00' * 4)
873 packed.append(struct.pack("!6B", *self.hw_addr))
874 packed.append('\x00' * 2)
875 packed.append(struct.pack("!16s", self.name))
876 packed.append(struct.pack("!L", self.config))
877 packed.append(struct.pack("!L", self.state))
878 packed.append(struct.pack("!L", self.curr))
879 packed.append(struct.pack("!L", self.advertised))
880 packed.append(struct.pack("!L", self.supported))
881 packed.append(struct.pack("!L", self.peer))
882 packed.append(struct.pack("!L", self.curr_speed))
883 packed.append(struct.pack("!L", self.max_speed))
884 return ''.join(packed)
885
886 @staticmethod
887 def unpack(buf):
888 obj = port_desc()
889 if type(buf) == loxi.generic_util.OFReader:
890 reader = buf
891 else:
892 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700893 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700894 reader.skip(4)
895 obj.hw_addr = list(reader.read('!6B'))
896 reader.skip(2)
897 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700898 obj.config = reader.read("!L")[0]
899 obj.state = reader.read("!L")[0]
900 obj.curr = reader.read("!L")[0]
901 obj.advertised = reader.read("!L")[0]
902 obj.supported = reader.read("!L")[0]
903 obj.peer = reader.read("!L")[0]
904 obj.curr_speed = reader.read("!L")[0]
905 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700906 return obj
907
908 def __eq__(self, other):
909 if type(self) != type(other): return False
910 if self.port_no != other.port_no: return False
911 if self.hw_addr != other.hw_addr: return False
912 if self.name != other.name: return False
913 if self.config != other.config: return False
914 if self.state != other.state: return False
915 if self.curr != other.curr: return False
916 if self.advertised != other.advertised: return False
917 if self.supported != other.supported: return False
918 if self.peer != other.peer: return False
919 if self.curr_speed != other.curr_speed: return False
920 if self.max_speed != other.max_speed: return False
921 return True
922
923 def __ne__(self, other):
924 return not self.__eq__(other)
925
926 def show(self):
927 import loxi.pp
928 return loxi.pp.pp(self)
929
930 def pretty_print(self, q):
931 q.text("port_desc {")
932 with q.group():
933 with q.indent(2):
934 q.breakable()
935 q.text("port_no = ");
936 q.text(util.pretty_port(self.port_no))
937 q.text(","); q.breakable()
938 q.text("hw_addr = ");
939 q.text(util.pretty_mac(self.hw_addr))
940 q.text(","); q.breakable()
941 q.text("name = ");
942 q.pp(self.name)
943 q.text(","); q.breakable()
944 q.text("config = ");
945 q.text("%#x" % self.config)
946 q.text(","); q.breakable()
947 q.text("state = ");
948 q.text("%#x" % self.state)
949 q.text(","); q.breakable()
950 q.text("curr = ");
951 q.text("%#x" % self.curr)
952 q.text(","); q.breakable()
953 q.text("advertised = ");
954 q.text("%#x" % self.advertised)
955 q.text(","); q.breakable()
956 q.text("supported = ");
957 q.text("%#x" % self.supported)
958 q.text(","); q.breakable()
959 q.text("peer = ");
960 q.text("%#x" % self.peer)
961 q.text(","); q.breakable()
962 q.text("curr_speed = ");
963 q.text("%#x" % self.curr_speed)
964 q.text(","); q.breakable()
965 q.text("max_speed = ");
966 q.text("%#x" % self.max_speed)
967 q.breakable()
968 q.text('}')
969
970class port_stats_entry(object):
971
972 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):
973 if port_no != None:
974 self.port_no = port_no
975 else:
976 self.port_no = 0
977 if rx_packets != None:
978 self.rx_packets = rx_packets
979 else:
980 self.rx_packets = 0
981 if tx_packets != None:
982 self.tx_packets = tx_packets
983 else:
984 self.tx_packets = 0
985 if rx_bytes != None:
986 self.rx_bytes = rx_bytes
987 else:
988 self.rx_bytes = 0
989 if tx_bytes != None:
990 self.tx_bytes = tx_bytes
991 else:
992 self.tx_bytes = 0
993 if rx_dropped != None:
994 self.rx_dropped = rx_dropped
995 else:
996 self.rx_dropped = 0
997 if tx_dropped != None:
998 self.tx_dropped = tx_dropped
999 else:
1000 self.tx_dropped = 0
1001 if rx_errors != None:
1002 self.rx_errors = rx_errors
1003 else:
1004 self.rx_errors = 0
1005 if tx_errors != None:
1006 self.tx_errors = tx_errors
1007 else:
1008 self.tx_errors = 0
1009 if rx_frame_err != None:
1010 self.rx_frame_err = rx_frame_err
1011 else:
1012 self.rx_frame_err = 0
1013 if rx_over_err != None:
1014 self.rx_over_err = rx_over_err
1015 else:
1016 self.rx_over_err = 0
1017 if rx_crc_err != None:
1018 self.rx_crc_err = rx_crc_err
1019 else:
1020 self.rx_crc_err = 0
1021 if collisions != None:
1022 self.collisions = collisions
1023 else:
1024 self.collisions = 0
1025 return
1026
1027 def pack(self):
1028 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001029 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001030 packed.append('\x00' * 4)
1031 packed.append(struct.pack("!Q", self.rx_packets))
1032 packed.append(struct.pack("!Q", self.tx_packets))
1033 packed.append(struct.pack("!Q", self.rx_bytes))
1034 packed.append(struct.pack("!Q", self.tx_bytes))
1035 packed.append(struct.pack("!Q", self.rx_dropped))
1036 packed.append(struct.pack("!Q", self.tx_dropped))
1037 packed.append(struct.pack("!Q", self.rx_errors))
1038 packed.append(struct.pack("!Q", self.tx_errors))
1039 packed.append(struct.pack("!Q", self.rx_frame_err))
1040 packed.append(struct.pack("!Q", self.rx_over_err))
1041 packed.append(struct.pack("!Q", self.rx_crc_err))
1042 packed.append(struct.pack("!Q", self.collisions))
1043 return ''.join(packed)
1044
1045 @staticmethod
1046 def unpack(buf):
1047 obj = port_stats_entry()
1048 if type(buf) == loxi.generic_util.OFReader:
1049 reader = buf
1050 else:
1051 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001052 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001053 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001054 obj.rx_packets = reader.read("!Q")[0]
1055 obj.tx_packets = reader.read("!Q")[0]
1056 obj.rx_bytes = reader.read("!Q")[0]
1057 obj.tx_bytes = reader.read("!Q")[0]
1058 obj.rx_dropped = reader.read("!Q")[0]
1059 obj.tx_dropped = reader.read("!Q")[0]
1060 obj.rx_errors = reader.read("!Q")[0]
1061 obj.tx_errors = reader.read("!Q")[0]
1062 obj.rx_frame_err = reader.read("!Q")[0]
1063 obj.rx_over_err = reader.read("!Q")[0]
1064 obj.rx_crc_err = reader.read("!Q")[0]
1065 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001066 return obj
1067
1068 def __eq__(self, other):
1069 if type(self) != type(other): return False
1070 if self.port_no != other.port_no: return False
1071 if self.rx_packets != other.rx_packets: return False
1072 if self.tx_packets != other.tx_packets: return False
1073 if self.rx_bytes != other.rx_bytes: return False
1074 if self.tx_bytes != other.tx_bytes: return False
1075 if self.rx_dropped != other.rx_dropped: return False
1076 if self.tx_dropped != other.tx_dropped: return False
1077 if self.rx_errors != other.rx_errors: return False
1078 if self.tx_errors != other.tx_errors: return False
1079 if self.rx_frame_err != other.rx_frame_err: return False
1080 if self.rx_over_err != other.rx_over_err: return False
1081 if self.rx_crc_err != other.rx_crc_err: return False
1082 if self.collisions != other.collisions: return False
1083 return True
1084
1085 def __ne__(self, other):
1086 return not self.__eq__(other)
1087
1088 def show(self):
1089 import loxi.pp
1090 return loxi.pp.pp(self)
1091
1092 def pretty_print(self, q):
1093 q.text("port_stats_entry {")
1094 with q.group():
1095 with q.indent(2):
1096 q.breakable()
1097 q.text("port_no = ");
1098 q.text(util.pretty_port(self.port_no))
1099 q.text(","); q.breakable()
1100 q.text("rx_packets = ");
1101 q.text("%#x" % self.rx_packets)
1102 q.text(","); q.breakable()
1103 q.text("tx_packets = ");
1104 q.text("%#x" % self.tx_packets)
1105 q.text(","); q.breakable()
1106 q.text("rx_bytes = ");
1107 q.text("%#x" % self.rx_bytes)
1108 q.text(","); q.breakable()
1109 q.text("tx_bytes = ");
1110 q.text("%#x" % self.tx_bytes)
1111 q.text(","); q.breakable()
1112 q.text("rx_dropped = ");
1113 q.text("%#x" % self.rx_dropped)
1114 q.text(","); q.breakable()
1115 q.text("tx_dropped = ");
1116 q.text("%#x" % self.tx_dropped)
1117 q.text(","); q.breakable()
1118 q.text("rx_errors = ");
1119 q.text("%#x" % self.rx_errors)
1120 q.text(","); q.breakable()
1121 q.text("tx_errors = ");
1122 q.text("%#x" % self.tx_errors)
1123 q.text(","); q.breakable()
1124 q.text("rx_frame_err = ");
1125 q.text("%#x" % self.rx_frame_err)
1126 q.text(","); q.breakable()
1127 q.text("rx_over_err = ");
1128 q.text("%#x" % self.rx_over_err)
1129 q.text(","); q.breakable()
1130 q.text("rx_crc_err = ");
1131 q.text("%#x" % self.rx_crc_err)
1132 q.text(","); q.breakable()
1133 q.text("collisions = ");
1134 q.text("%#x" % self.collisions)
1135 q.breakable()
1136 q.text('}')
1137
1138class queue_prop_experimenter(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001139 type = 65535
Rich Lanec2ee4b82013-04-24 17:12:38 -07001140
1141 def __init__(self, experimenter=None, data=None):
1142 if experimenter != None:
1143 self.experimenter = experimenter
1144 else:
1145 self.experimenter = 0
1146 if data != None:
1147 self.data = data
1148 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001149 self.data = ''
Rich Lanec2ee4b82013-04-24 17:12:38 -07001150 return
1151
1152 def pack(self):
1153 packed = []
1154 packed.append(struct.pack("!H", self.type))
1155 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1156 packed.append('\x00' * 4)
1157 packed.append(struct.pack("!L", self.experimenter))
1158 packed.append('\x00' * 4)
1159 packed.append(self.data)
1160 length = sum([len(x) for x in packed])
1161 packed[1] = struct.pack("!H", length)
1162 return ''.join(packed)
1163
1164 @staticmethod
1165 def unpack(buf):
1166 obj = queue_prop_experimenter()
1167 if type(buf) == loxi.generic_util.OFReader:
1168 reader = buf
1169 else:
1170 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001171 _type = reader.read("!H")[0]
1172 assert(_type == 65535)
1173 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001174 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001175 obj.experimenter = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001176 reader.skip(4)
1177 obj.data = str(reader.read_all())
1178 return obj
1179
1180 def __eq__(self, other):
1181 if type(self) != type(other): return False
1182 if self.experimenter != other.experimenter: return False
1183 if self.data != other.data: return False
1184 return True
1185
1186 def __ne__(self, other):
1187 return not self.__eq__(other)
1188
1189 def show(self):
1190 import loxi.pp
1191 return loxi.pp.pp(self)
1192
1193 def pretty_print(self, q):
1194 q.text("queue_prop_experimenter {")
1195 with q.group():
1196 with q.indent(2):
1197 q.breakable()
1198 q.text("experimenter = ");
1199 q.text("%#x" % self.experimenter)
1200 q.text(","); q.breakable()
1201 q.text("data = ");
1202 q.pp(self.data)
1203 q.breakable()
1204 q.text('}')
1205
1206class queue_prop_max_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001207 type = 2
Rich Lanec2ee4b82013-04-24 17:12:38 -07001208
1209 def __init__(self, rate=None):
1210 if rate != None:
1211 self.rate = rate
1212 else:
1213 self.rate = 0
1214 return
1215
1216 def pack(self):
1217 packed = []
1218 packed.append(struct.pack("!H", self.type))
1219 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1220 packed.append('\x00' * 4)
1221 packed.append(struct.pack("!H", self.rate))
1222 packed.append('\x00' * 6)
1223 length = sum([len(x) for x in packed])
1224 packed[1] = struct.pack("!H", length)
1225 return ''.join(packed)
1226
1227 @staticmethod
1228 def unpack(buf):
1229 obj = queue_prop_max_rate()
1230 if type(buf) == loxi.generic_util.OFReader:
1231 reader = buf
1232 else:
1233 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001234 _type = reader.read("!H")[0]
1235 assert(_type == 2)
1236 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001237 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001238 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001239 reader.skip(6)
1240 return obj
1241
1242 def __eq__(self, other):
1243 if type(self) != type(other): return False
1244 if self.rate != other.rate: return False
1245 return True
1246
1247 def __ne__(self, other):
1248 return not self.__eq__(other)
1249
1250 def show(self):
1251 import loxi.pp
1252 return loxi.pp.pp(self)
1253
1254 def pretty_print(self, q):
1255 q.text("queue_prop_max_rate {")
1256 with q.group():
1257 with q.indent(2):
1258 q.breakable()
1259 q.text("rate = ");
1260 q.text("%#x" % self.rate)
1261 q.breakable()
1262 q.text('}')
1263
1264class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001265 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001266
1267 def __init__(self, rate=None):
1268 if rate != None:
1269 self.rate = rate
1270 else:
1271 self.rate = 0
1272 return
1273
1274 def pack(self):
1275 packed = []
1276 packed.append(struct.pack("!H", self.type))
1277 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1278 packed.append('\x00' * 4)
1279 packed.append(struct.pack("!H", self.rate))
1280 packed.append('\x00' * 6)
1281 length = sum([len(x) for x in packed])
1282 packed[1] = struct.pack("!H", length)
1283 return ''.join(packed)
1284
1285 @staticmethod
1286 def unpack(buf):
1287 obj = queue_prop_min_rate()
1288 if type(buf) == loxi.generic_util.OFReader:
1289 reader = buf
1290 else:
1291 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001292 _type = reader.read("!H")[0]
1293 assert(_type == 1)
1294 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001295 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001296 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001297 reader.skip(6)
1298 return obj
1299
1300 def __eq__(self, other):
1301 if type(self) != type(other): return False
1302 if self.rate != other.rate: return False
1303 return True
1304
1305 def __ne__(self, other):
1306 return not self.__eq__(other)
1307
1308 def show(self):
1309 import loxi.pp
1310 return loxi.pp.pp(self)
1311
1312 def pretty_print(self, q):
1313 q.text("queue_prop_min_rate {")
1314 with q.group():
1315 with q.indent(2):
1316 q.breakable()
1317 q.text("rate = ");
1318 q.text("%#x" % self.rate)
1319 q.breakable()
1320 q.text('}')
1321
1322class queue_stats_entry(object):
1323
1324 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1325 if port_no != None:
1326 self.port_no = port_no
1327 else:
1328 self.port_no = 0
1329 if queue_id != None:
1330 self.queue_id = queue_id
1331 else:
1332 self.queue_id = 0
1333 if tx_bytes != None:
1334 self.tx_bytes = tx_bytes
1335 else:
1336 self.tx_bytes = 0
1337 if tx_packets != None:
1338 self.tx_packets = tx_packets
1339 else:
1340 self.tx_packets = 0
1341 if tx_errors != None:
1342 self.tx_errors = tx_errors
1343 else:
1344 self.tx_errors = 0
1345 return
1346
1347 def pack(self):
1348 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001349 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001350 packed.append(struct.pack("!L", self.queue_id))
1351 packed.append(struct.pack("!Q", self.tx_bytes))
1352 packed.append(struct.pack("!Q", self.tx_packets))
1353 packed.append(struct.pack("!Q", self.tx_errors))
1354 return ''.join(packed)
1355
1356 @staticmethod
1357 def unpack(buf):
1358 obj = queue_stats_entry()
1359 if type(buf) == loxi.generic_util.OFReader:
1360 reader = buf
1361 else:
1362 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001363 obj.port_no = util.unpack_port_no(reader)
1364 obj.queue_id = reader.read("!L")[0]
1365 obj.tx_bytes = reader.read("!Q")[0]
1366 obj.tx_packets = reader.read("!Q")[0]
1367 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001368 return obj
1369
1370 def __eq__(self, other):
1371 if type(self) != type(other): return False
1372 if self.port_no != other.port_no: return False
1373 if self.queue_id != other.queue_id: return False
1374 if self.tx_bytes != other.tx_bytes: return False
1375 if self.tx_packets != other.tx_packets: return False
1376 if self.tx_errors != other.tx_errors: return False
1377 return True
1378
1379 def __ne__(self, other):
1380 return not self.__eq__(other)
1381
1382 def show(self):
1383 import loxi.pp
1384 return loxi.pp.pp(self)
1385
1386 def pretty_print(self, q):
1387 q.text("queue_stats_entry {")
1388 with q.group():
1389 with q.indent(2):
1390 q.breakable()
1391 q.text("port_no = ");
1392 q.text(util.pretty_port(self.port_no))
1393 q.text(","); q.breakable()
1394 q.text("queue_id = ");
1395 q.text("%#x" % self.queue_id)
1396 q.text(","); q.breakable()
1397 q.text("tx_bytes = ");
1398 q.text("%#x" % self.tx_bytes)
1399 q.text(","); q.breakable()
1400 q.text("tx_packets = ");
1401 q.text("%#x" % self.tx_packets)
1402 q.text(","); q.breakable()
1403 q.text("tx_errors = ");
1404 q.text("%#x" % self.tx_errors)
1405 q.breakable()
1406 q.text('}')
1407
1408class table_stats_entry(object):
1409
1410 def __init__(self, table_id=None, name=None, match=None, wildcards=None, write_actions=None, apply_actions=None, write_setfields=None, apply_setfields=None, metadata_match=None, metadata_write=None, instructions=None, config=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
1411 if table_id != None:
1412 self.table_id = table_id
1413 else:
1414 self.table_id = 0
1415 if name != None:
1416 self.name = name
1417 else:
1418 self.name = ""
1419 if match != None:
1420 self.match = match
1421 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001422 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001423 if wildcards != None:
1424 self.wildcards = wildcards
1425 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001426 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001427 if write_actions != None:
1428 self.write_actions = write_actions
1429 else:
1430 self.write_actions = 0
1431 if apply_actions != None:
1432 self.apply_actions = apply_actions
1433 else:
1434 self.apply_actions = 0
1435 if write_setfields != None:
1436 self.write_setfields = write_setfields
1437 else:
1438 self.write_setfields = 0
1439 if apply_setfields != None:
1440 self.apply_setfields = apply_setfields
1441 else:
1442 self.apply_setfields = 0
1443 if metadata_match != None:
1444 self.metadata_match = metadata_match
1445 else:
1446 self.metadata_match = 0
1447 if metadata_write != None:
1448 self.metadata_write = metadata_write
1449 else:
1450 self.metadata_write = 0
1451 if instructions != None:
1452 self.instructions = instructions
1453 else:
1454 self.instructions = 0
1455 if config != None:
1456 self.config = config
1457 else:
1458 self.config = 0
1459 if max_entries != None:
1460 self.max_entries = max_entries
1461 else:
1462 self.max_entries = 0
1463 if active_count != None:
1464 self.active_count = active_count
1465 else:
1466 self.active_count = 0
1467 if lookup_count != None:
1468 self.lookup_count = lookup_count
1469 else:
1470 self.lookup_count = 0
1471 if matched_count != None:
1472 self.matched_count = matched_count
1473 else:
1474 self.matched_count = 0
1475 return
1476
1477 def pack(self):
1478 packed = []
1479 packed.append(struct.pack("!B", self.table_id))
1480 packed.append('\x00' * 7)
1481 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001482 packed.append(util.pack_match_bmap(self.match))
1483 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001484 packed.append(struct.pack("!L", self.write_actions))
1485 packed.append(struct.pack("!L", self.apply_actions))
1486 packed.append(struct.pack("!Q", self.write_setfields))
1487 packed.append(struct.pack("!Q", self.apply_setfields))
1488 packed.append(struct.pack("!Q", self.metadata_match))
1489 packed.append(struct.pack("!Q", self.metadata_write))
1490 packed.append(struct.pack("!L", self.instructions))
1491 packed.append(struct.pack("!L", self.config))
1492 packed.append(struct.pack("!L", self.max_entries))
1493 packed.append(struct.pack("!L", self.active_count))
1494 packed.append(struct.pack("!Q", self.lookup_count))
1495 packed.append(struct.pack("!Q", self.matched_count))
1496 return ''.join(packed)
1497
1498 @staticmethod
1499 def unpack(buf):
1500 obj = table_stats_entry()
1501 if type(buf) == loxi.generic_util.OFReader:
1502 reader = buf
1503 else:
1504 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001505 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001506 reader.skip(7)
1507 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001508 obj.match = util.unpack_match_bmap(reader)
1509 obj.wildcards = util.unpack_wc_bmap(reader)
1510 obj.write_actions = reader.read("!L")[0]
1511 obj.apply_actions = reader.read("!L")[0]
1512 obj.write_setfields = reader.read("!Q")[0]
1513 obj.apply_setfields = reader.read("!Q")[0]
1514 obj.metadata_match = reader.read("!Q")[0]
1515 obj.metadata_write = reader.read("!Q")[0]
1516 obj.instructions = reader.read("!L")[0]
1517 obj.config = reader.read("!L")[0]
1518 obj.max_entries = reader.read("!L")[0]
1519 obj.active_count = reader.read("!L")[0]
1520 obj.lookup_count = reader.read("!Q")[0]
1521 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001522 return obj
1523
1524 def __eq__(self, other):
1525 if type(self) != type(other): return False
1526 if self.table_id != other.table_id: return False
1527 if self.name != other.name: return False
1528 if self.match != other.match: return False
1529 if self.wildcards != other.wildcards: return False
1530 if self.write_actions != other.write_actions: return False
1531 if self.apply_actions != other.apply_actions: return False
1532 if self.write_setfields != other.write_setfields: return False
1533 if self.apply_setfields != other.apply_setfields: return False
1534 if self.metadata_match != other.metadata_match: return False
1535 if self.metadata_write != other.metadata_write: return False
1536 if self.instructions != other.instructions: return False
1537 if self.config != other.config: return False
1538 if self.max_entries != other.max_entries: return False
1539 if self.active_count != other.active_count: return False
1540 if self.lookup_count != other.lookup_count: return False
1541 if self.matched_count != other.matched_count: return False
1542 return True
1543
1544 def __ne__(self, other):
1545 return not self.__eq__(other)
1546
1547 def show(self):
1548 import loxi.pp
1549 return loxi.pp.pp(self)
1550
1551 def pretty_print(self, q):
1552 q.text("table_stats_entry {")
1553 with q.group():
1554 with q.indent(2):
1555 q.breakable()
1556 q.text("table_id = ");
1557 q.text("%#x" % self.table_id)
1558 q.text(","); q.breakable()
1559 q.text("name = ");
1560 q.pp(self.name)
1561 q.text(","); q.breakable()
1562 q.text("match = ");
1563 q.pp(self.match)
1564 q.text(","); q.breakable()
1565 q.text("wildcards = ");
1566 q.pp(self.wildcards)
1567 q.text(","); q.breakable()
1568 q.text("write_actions = ");
1569 q.text("%#x" % self.write_actions)
1570 q.text(","); q.breakable()
1571 q.text("apply_actions = ");
1572 q.text("%#x" % self.apply_actions)
1573 q.text(","); q.breakable()
1574 q.text("write_setfields = ");
1575 q.text("%#x" % self.write_setfields)
1576 q.text(","); q.breakable()
1577 q.text("apply_setfields = ");
1578 q.text("%#x" % self.apply_setfields)
1579 q.text(","); q.breakable()
1580 q.text("metadata_match = ");
1581 q.text("%#x" % self.metadata_match)
1582 q.text(","); q.breakable()
1583 q.text("metadata_write = ");
1584 q.text("%#x" % self.metadata_write)
1585 q.text(","); q.breakable()
1586 q.text("instructions = ");
1587 q.text("%#x" % self.instructions)
1588 q.text(","); q.breakable()
1589 q.text("config = ");
1590 q.text("%#x" % self.config)
1591 q.text(","); q.breakable()
1592 q.text("max_entries = ");
1593 q.text("%#x" % self.max_entries)
1594 q.text(","); q.breakable()
1595 q.text("active_count = ");
1596 q.text("%#x" % self.active_count)
1597 q.text(","); q.breakable()
1598 q.text("lookup_count = ");
1599 q.text("%#x" % self.lookup_count)
1600 q.text(","); q.breakable()
1601 q.text("matched_count = ");
1602 q.text("%#x" % self.matched_count)
1603 q.breakable()
1604 q.text('}')
1605
1606
1607match = match_v3