blob: 3956aec7c37bb283f4ad01370ddd7fb5a73c17d3 [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# Automatically generated by LOXI from template common.py
6# Do not modify
7
8import sys
9import struct
10import action
11import instruction # for unpack_list
12import const
13import util
14import loxi.generic_util
15
16import oxm
17
18# HACK make this module visible as 'common' to simplify code generation
19common = sys.modules[__name__]
20
21def unpack_list_flow_stats_entry(reader):
22 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
23
24def unpack_list_queue_prop(reader):
25 def deserializer(reader, typ):
26 if typ == const.OFPQT_MIN_RATE:
27 return queue_prop_min_rate.unpack(reader)
28 else:
29 raise loxi.ProtocolError("unknown queue prop %d" % typ)
30 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
31
32def unpack_list_packet_queue(reader):
33 def wrapper(reader):
34 length, = reader.peek('!4xH')
35 return packet_queue.unpack(reader.slice(length))
36 return loxi.generic_util.unpack_list(reader, wrapper)
37
38def unpack_list_hello_elem(reader):
39 def deserializer(reader, typ):
40 if typ == const.OFPHET_VERSIONBITMAP:
41 return hello_elem_versionbitmap.unpack(reader)
42 else:
43 return None
44 return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
45
46def unpack_list_bucket(reader):
47 return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
48
49def unpack_list_group_desc_stats_entry(reader):
50 return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
51
52def unpack_list_group_stats_entry(reader):
53 return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
54
55def unpack_list_meter_stats(reader):
56 def wrapper(reader):
57 length, = reader.peek('!4xH')
58 return meter_stats.unpack(reader.slice(length))
59 return loxi.generic_util.unpack_list(reader, wrapper)
60
61class bsn_interface(object):
62
63 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
64 if hw_addr != None:
65 self.hw_addr = hw_addr
66 else:
67 self.hw_addr = [0,0,0,0,0,0]
68 if name != None:
69 self.name = name
70 else:
71 self.name = ""
72 if ipv4_addr != None:
73 self.ipv4_addr = ipv4_addr
74 else:
75 self.ipv4_addr = 0
76 if ipv4_netmask != None:
77 self.ipv4_netmask = ipv4_netmask
78 else:
79 self.ipv4_netmask = 0
80 return
81
82 def pack(self):
83 packed = []
84 packed.append(struct.pack("!6B", *self.hw_addr))
85 packed.append('\x00' * 2)
86 packed.append(struct.pack("!16s", self.name))
87 packed.append(struct.pack("!L", self.ipv4_addr))
88 packed.append(struct.pack("!L", self.ipv4_netmask))
89 return ''.join(packed)
90
91 @staticmethod
92 def unpack(buf):
93 obj = bsn_interface()
94 if type(buf) == loxi.generic_util.OFReader:
95 reader = buf
96 else:
97 reader = loxi.generic_util.OFReader(buf)
98 obj.hw_addr = list(reader.read('!6B'))
99 reader.skip(2)
100 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700101 obj.ipv4_addr = reader.read("!L")[0]
102 obj.ipv4_netmask = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700103 return obj
104
105 def __eq__(self, other):
106 if type(self) != type(other): return False
107 if self.hw_addr != other.hw_addr: return False
108 if self.name != other.name: return False
109 if self.ipv4_addr != other.ipv4_addr: return False
110 if self.ipv4_netmask != other.ipv4_netmask: return False
111 return True
112
113 def __ne__(self, other):
114 return not self.__eq__(other)
115
116 def show(self):
117 import loxi.pp
118 return loxi.pp.pp(self)
119
120 def pretty_print(self, q):
121 q.text("bsn_interface {")
122 with q.group():
123 with q.indent(2):
124 q.breakable()
125 q.text("hw_addr = ");
126 q.text(util.pretty_mac(self.hw_addr))
127 q.text(","); q.breakable()
128 q.text("name = ");
129 q.pp(self.name)
130 q.text(","); q.breakable()
131 q.text("ipv4_addr = ");
132 q.text(util.pretty_ipv4(self.ipv4_addr))
133 q.text(","); q.breakable()
134 q.text("ipv4_netmask = ");
135 q.text(util.pretty_ipv4(self.ipv4_netmask))
136 q.breakable()
137 q.text('}')
138
Dan Talaycof6202252013-07-02 01:00:29 -0700139class bsn_vport_q_in_q(object):
140 type = 0
141
Kiran Poola150d8b02013-09-20 13:30:39 -0700142 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 -0700143 if port_no != None:
144 self.port_no = port_no
145 else:
146 self.port_no = 0
147 if ingress_tpid != None:
148 self.ingress_tpid = ingress_tpid
149 else:
150 self.ingress_tpid = 0
151 if ingress_vlan_id != None:
152 self.ingress_vlan_id = ingress_vlan_id
153 else:
154 self.ingress_vlan_id = 0
155 if egress_tpid != None:
156 self.egress_tpid = egress_tpid
157 else:
158 self.egress_tpid = 0
159 if egress_vlan_id != None:
160 self.egress_vlan_id = egress_vlan_id
161 else:
162 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700163 if if_name != None:
164 self.if_name = if_name
165 else:
166 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700167 return
168
169 def pack(self):
170 packed = []
171 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700172 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700173 packed.append(struct.pack("!L", self.port_no))
174 packed.append(struct.pack("!H", self.ingress_tpid))
175 packed.append(struct.pack("!H", self.ingress_vlan_id))
176 packed.append(struct.pack("!H", self.egress_tpid))
177 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700178 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700179 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700180 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700181 return ''.join(packed)
182
183 @staticmethod
184 def unpack(buf):
185 obj = bsn_vport_q_in_q()
186 if type(buf) == loxi.generic_util.OFReader:
187 reader = buf
188 else:
189 reader = loxi.generic_util.OFReader(buf)
190 _type = reader.read("!H")[0]
191 assert(_type == 0)
192 _length = reader.read("!H")[0]
193 obj.port_no = reader.read("!L")[0]
194 obj.ingress_tpid = reader.read("!H")[0]
195 obj.ingress_vlan_id = reader.read("!H")[0]
196 obj.egress_tpid = reader.read("!H")[0]
197 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700198 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700199 return obj
200
201 def __eq__(self, other):
202 if type(self) != type(other): return False
203 if self.port_no != other.port_no: return False
204 if self.ingress_tpid != other.ingress_tpid: return False
205 if self.ingress_vlan_id != other.ingress_vlan_id: return False
206 if self.egress_tpid != other.egress_tpid: return False
207 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700208 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700209 return True
210
211 def __ne__(self, other):
212 return not self.__eq__(other)
213
214 def show(self):
215 import loxi.pp
216 return loxi.pp.pp(self)
217
218 def pretty_print(self, q):
219 q.text("bsn_vport_q_in_q {")
220 with q.group():
221 with q.indent(2):
222 q.breakable()
223 q.text("port_no = ");
224 q.text("%#x" % self.port_no)
225 q.text(","); q.breakable()
226 q.text("ingress_tpid = ");
227 q.text("%#x" % self.ingress_tpid)
228 q.text(","); q.breakable()
229 q.text("ingress_vlan_id = ");
230 q.text("%#x" % self.ingress_vlan_id)
231 q.text(","); q.breakable()
232 q.text("egress_tpid = ");
233 q.text("%#x" % self.egress_tpid)
234 q.text(","); q.breakable()
235 q.text("egress_vlan_id = ");
236 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700237 q.text(","); q.breakable()
238 q.text("if_name = ");
239 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700240 q.breakable()
241 q.text('}')
242
Rich Lanec2ee4b82013-04-24 17:12:38 -0700243class bucket(object):
244
245 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
246 if weight != None:
247 self.weight = weight
248 else:
249 self.weight = 0
250 if watch_port != None:
251 self.watch_port = watch_port
252 else:
253 self.watch_port = 0
254 if watch_group != None:
255 self.watch_group = watch_group
256 else:
257 self.watch_group = 0
258 if actions != None:
259 self.actions = actions
260 else:
261 self.actions = []
262 return
263
264 def pack(self):
265 packed = []
266 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
267 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700268 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700269 packed.append(struct.pack("!L", self.watch_group))
270 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700271 packed.append(util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700272 length = sum([len(x) for x in packed])
273 packed[0] = struct.pack("!H", length)
274 return ''.join(packed)
275
276 @staticmethod
277 def unpack(buf):
278 obj = bucket()
279 if type(buf) == loxi.generic_util.OFReader:
280 reader = buf
281 else:
282 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700283 _len = reader.read("!H")[0]
284 obj.weight = reader.read("!H")[0]
285 obj.watch_port = util.unpack_port_no(reader)
286 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700287 reader.skip(4)
288 obj.actions = action.unpack_list(reader)
289 return obj
290
291 def __eq__(self, other):
292 if type(self) != type(other): return False
293 if self.weight != other.weight: return False
294 if self.watch_port != other.watch_port: return False
295 if self.watch_group != other.watch_group: return False
296 if self.actions != other.actions: return False
297 return True
298
299 def __ne__(self, other):
300 return not self.__eq__(other)
301
302 def show(self):
303 import loxi.pp
304 return loxi.pp.pp(self)
305
306 def pretty_print(self, q):
307 q.text("bucket {")
308 with q.group():
309 with q.indent(2):
310 q.breakable()
311 q.text("weight = ");
312 q.text("%#x" % self.weight)
313 q.text(","); q.breakable()
314 q.text("watch_port = ");
315 q.text(util.pretty_port(self.watch_port))
316 q.text(","); q.breakable()
317 q.text("watch_group = ");
318 q.text("%#x" % self.watch_group)
319 q.text(","); q.breakable()
320 q.text("actions = ");
321 q.pp(self.actions)
322 q.breakable()
323 q.text('}')
324
325class bucket_counter(object):
326
327 def __init__(self, packet_count=None, byte_count=None):
328 if packet_count != None:
329 self.packet_count = packet_count
330 else:
331 self.packet_count = 0
332 if byte_count != None:
333 self.byte_count = byte_count
334 else:
335 self.byte_count = 0
336 return
337
338 def pack(self):
339 packed = []
340 packed.append(struct.pack("!Q", self.packet_count))
341 packed.append(struct.pack("!Q", self.byte_count))
342 return ''.join(packed)
343
344 @staticmethod
345 def unpack(buf):
346 obj = bucket_counter()
347 if type(buf) == loxi.generic_util.OFReader:
348 reader = buf
349 else:
350 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700351 obj.packet_count = reader.read("!Q")[0]
352 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700353 return obj
354
355 def __eq__(self, other):
356 if type(self) != type(other): return False
357 if self.packet_count != other.packet_count: return False
358 if self.byte_count != other.byte_count: return False
359 return True
360
361 def __ne__(self, other):
362 return not self.__eq__(other)
363
364 def show(self):
365 import loxi.pp
366 return loxi.pp.pp(self)
367
368 def pretty_print(self, q):
369 q.text("bucket_counter {")
370 with q.group():
371 with q.indent(2):
372 q.breakable()
373 q.text("packet_count = ");
374 q.text("%#x" % self.packet_count)
375 q.text(","); q.breakable()
376 q.text("byte_count = ");
377 q.text("%#x" % self.byte_count)
378 q.breakable()
379 q.text('}')
380
381class flow_stats_entry(object):
382
383 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):
384 if table_id != None:
385 self.table_id = table_id
386 else:
387 self.table_id = 0
388 if duration_sec != None:
389 self.duration_sec = duration_sec
390 else:
391 self.duration_sec = 0
392 if duration_nsec != None:
393 self.duration_nsec = duration_nsec
394 else:
395 self.duration_nsec = 0
396 if priority != None:
397 self.priority = priority
398 else:
399 self.priority = 0
400 if idle_timeout != None:
401 self.idle_timeout = idle_timeout
402 else:
403 self.idle_timeout = 0
404 if hard_timeout != None:
405 self.hard_timeout = hard_timeout
406 else:
407 self.hard_timeout = 0
408 if cookie != None:
409 self.cookie = cookie
410 else:
411 self.cookie = 0
412 if packet_count != None:
413 self.packet_count = packet_count
414 else:
415 self.packet_count = 0
416 if byte_count != None:
417 self.byte_count = byte_count
418 else:
419 self.byte_count = 0
420 if match != None:
421 self.match = match
422 else:
423 self.match = common.match()
424 if instructions != None:
425 self.instructions = instructions
426 else:
427 self.instructions = []
428 return
429
430 def pack(self):
431 packed = []
432 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
433 packed.append(struct.pack("!B", self.table_id))
434 packed.append('\x00' * 1)
435 packed.append(struct.pack("!L", self.duration_sec))
436 packed.append(struct.pack("!L", self.duration_nsec))
437 packed.append(struct.pack("!H", self.priority))
438 packed.append(struct.pack("!H", self.idle_timeout))
439 packed.append(struct.pack("!H", self.hard_timeout))
440 packed.append('\x00' * 6)
441 packed.append(struct.pack("!Q", self.cookie))
442 packed.append(struct.pack("!Q", self.packet_count))
443 packed.append(struct.pack("!Q", self.byte_count))
444 packed.append(self.match.pack())
Dan Talaycof6202252013-07-02 01:00:29 -0700445 packed.append(util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700446 length = sum([len(x) for x in packed])
447 packed[0] = struct.pack("!H", length)
448 return ''.join(packed)
449
450 @staticmethod
451 def unpack(buf):
452 obj = flow_stats_entry()
453 if type(buf) == loxi.generic_util.OFReader:
454 reader = buf
455 else:
456 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700457 _length = reader.read("!H")[0]
458 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700459 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700460 obj.duration_sec = reader.read("!L")[0]
461 obj.duration_nsec = reader.read("!L")[0]
462 obj.priority = reader.read("!H")[0]
463 obj.idle_timeout = reader.read("!H")[0]
464 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700465 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700466 obj.cookie = reader.read("!Q")[0]
467 obj.packet_count = reader.read("!Q")[0]
468 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700469 obj.match = common.match.unpack(reader)
470 obj.instructions = instruction.unpack_list(reader)
471 return obj
472
473 def __eq__(self, other):
474 if type(self) != type(other): return False
475 if self.table_id != other.table_id: return False
476 if self.duration_sec != other.duration_sec: return False
477 if self.duration_nsec != other.duration_nsec: return False
478 if self.priority != other.priority: return False
479 if self.idle_timeout != other.idle_timeout: return False
480 if self.hard_timeout != other.hard_timeout: return False
481 if self.cookie != other.cookie: return False
482 if self.packet_count != other.packet_count: return False
483 if self.byte_count != other.byte_count: return False
484 if self.match != other.match: return False
485 if self.instructions != other.instructions: return False
486 return True
487
488 def __ne__(self, other):
489 return not self.__eq__(other)
490
491 def show(self):
492 import loxi.pp
493 return loxi.pp.pp(self)
494
495 def pretty_print(self, q):
496 q.text("flow_stats_entry {")
497 with q.group():
498 with q.indent(2):
499 q.breakable()
500 q.text("table_id = ");
501 q.text("%#x" % self.table_id)
502 q.text(","); q.breakable()
503 q.text("duration_sec = ");
504 q.text("%#x" % self.duration_sec)
505 q.text(","); q.breakable()
506 q.text("duration_nsec = ");
507 q.text("%#x" % self.duration_nsec)
508 q.text(","); q.breakable()
509 q.text("priority = ");
510 q.text("%#x" % self.priority)
511 q.text(","); q.breakable()
512 q.text("idle_timeout = ");
513 q.text("%#x" % self.idle_timeout)
514 q.text(","); q.breakable()
515 q.text("hard_timeout = ");
516 q.text("%#x" % self.hard_timeout)
517 q.text(","); q.breakable()
518 q.text("cookie = ");
519 q.text("%#x" % self.cookie)
520 q.text(","); q.breakable()
521 q.text("packet_count = ");
522 q.text("%#x" % self.packet_count)
523 q.text(","); q.breakable()
524 q.text("byte_count = ");
525 q.text("%#x" % self.byte_count)
526 q.text(","); q.breakable()
527 q.text("match = ");
528 q.pp(self.match)
529 q.text(","); q.breakable()
530 q.text("instructions = ");
531 q.pp(self.instructions)
532 q.breakable()
533 q.text('}')
534
535class group_desc_stats_entry(object):
536
Rich Lane6f4978c2013-10-20 21:33:52 -0700537 def __init__(self, group_type=None, group_id=None, buckets=None):
538 if group_type != None:
539 self.group_type = group_type
Rich Lanec2ee4b82013-04-24 17:12:38 -0700540 else:
Rich Lane6f4978c2013-10-20 21:33:52 -0700541 self.group_type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700542 if group_id != None:
543 self.group_id = group_id
544 else:
545 self.group_id = 0
546 if buckets != None:
547 self.buckets = buckets
548 else:
549 self.buckets = []
550 return
551
552 def pack(self):
553 packed = []
554 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
Rich Lane6f4978c2013-10-20 21:33:52 -0700555 packed.append(struct.pack("!B", self.group_type))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700556 packed.append('\x00' * 1)
557 packed.append(struct.pack("!L", self.group_id))
Dan Talaycof6202252013-07-02 01:00:29 -0700558 packed.append(util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700559 length = sum([len(x) for x in packed])
560 packed[0] = struct.pack("!H", length)
561 return ''.join(packed)
562
563 @staticmethod
564 def unpack(buf):
565 obj = group_desc_stats_entry()
566 if type(buf) == loxi.generic_util.OFReader:
567 reader = buf
568 else:
569 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700570 _length = reader.read("!H")[0]
Rich Lane6f4978c2013-10-20 21:33:52 -0700571 obj.group_type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700572 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700573 obj.group_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700574 obj.buckets = common.unpack_list_bucket(reader)
575 return obj
576
577 def __eq__(self, other):
578 if type(self) != type(other): return False
Rich Lane6f4978c2013-10-20 21:33:52 -0700579 if self.group_type != other.group_type: return False
Rich Lanec2ee4b82013-04-24 17:12:38 -0700580 if self.group_id != other.group_id: return False
581 if self.buckets != other.buckets: return False
582 return True
583
584 def __ne__(self, other):
585 return not self.__eq__(other)
586
587 def show(self):
588 import loxi.pp
589 return loxi.pp.pp(self)
590
591 def pretty_print(self, q):
592 q.text("group_desc_stats_entry {")
593 with q.group():
594 with q.indent(2):
595 q.breakable()
Rich Lane6f4978c2013-10-20 21:33:52 -0700596 q.text("group_type = ");
597 q.text("%#x" % self.group_type)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700598 q.text(","); q.breakable()
599 q.text("group_id = ");
600 q.text("%#x" % self.group_id)
601 q.text(","); q.breakable()
602 q.text("buckets = ");
603 q.pp(self.buckets)
604 q.breakable()
605 q.text('}')
606
607class group_stats_entry(object):
608
609 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
610 if group_id != None:
611 self.group_id = group_id
612 else:
613 self.group_id = 0
614 if ref_count != None:
615 self.ref_count = ref_count
616 else:
617 self.ref_count = 0
618 if packet_count != None:
619 self.packet_count = packet_count
620 else:
621 self.packet_count = 0
622 if byte_count != None:
623 self.byte_count = byte_count
624 else:
625 self.byte_count = 0
626 if bucket_stats != None:
627 self.bucket_stats = bucket_stats
628 else:
629 self.bucket_stats = []
630 return
631
632 def pack(self):
633 packed = []
634 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
635 packed.append('\x00' * 2)
636 packed.append(struct.pack("!L", self.group_id))
637 packed.append(struct.pack("!L", self.ref_count))
638 packed.append('\x00' * 4)
639 packed.append(struct.pack("!Q", self.packet_count))
640 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700641 packed.append(util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700642 length = sum([len(x) for x in packed])
643 packed[0] = struct.pack("!H", length)
644 return ''.join(packed)
645
646 @staticmethod
647 def unpack(buf):
648 obj = group_stats_entry()
649 if type(buf) == loxi.generic_util.OFReader:
650 reader = buf
651 else:
652 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700653 _length = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700654 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700655 obj.group_id = reader.read("!L")[0]
656 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700657 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700658 obj.packet_count = reader.read("!Q")[0]
659 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700660 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
661 return obj
662
663 def __eq__(self, other):
664 if type(self) != type(other): return False
665 if self.group_id != other.group_id: return False
666 if self.ref_count != other.ref_count: return False
667 if self.packet_count != other.packet_count: return False
668 if self.byte_count != other.byte_count: return False
669 if self.bucket_stats != other.bucket_stats: return False
670 return True
671
672 def __ne__(self, other):
673 return not self.__eq__(other)
674
675 def show(self):
676 import loxi.pp
677 return loxi.pp.pp(self)
678
679 def pretty_print(self, q):
680 q.text("group_stats_entry {")
681 with q.group():
682 with q.indent(2):
683 q.breakable()
684 q.text("group_id = ");
685 q.text("%#x" % self.group_id)
686 q.text(","); q.breakable()
687 q.text("ref_count = ");
688 q.text("%#x" % self.ref_count)
689 q.text(","); q.breakable()
690 q.text("packet_count = ");
691 q.text("%#x" % self.packet_count)
692 q.text(","); q.breakable()
693 q.text("byte_count = ");
694 q.text("%#x" % self.byte_count)
695 q.text(","); q.breakable()
696 q.text("bucket_stats = ");
697 q.pp(self.bucket_stats)
698 q.breakable()
699 q.text('}')
700
701class match_v3(object):
702 type = 1
703
704 def __init__(self, oxm_list=None):
705 if oxm_list != None:
706 self.oxm_list = oxm_list
707 else:
708 self.oxm_list = []
709 return
710
711 def pack(self):
712 packed = []
713 packed.append(struct.pack("!H", self.type))
714 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700715 packed.append(util.pack_list(self.oxm_list))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700716 length = sum([len(x) for x in packed])
717 packed[1] = struct.pack("!H", length)
Rich Laned53156a2013-08-05 17:17:33 -0700718 packed.append(loxi.generic_util.pad_to(8, length))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700719 return ''.join(packed)
720
721 @staticmethod
722 def unpack(buf):
723 obj = match_v3()
724 if type(buf) == loxi.generic_util.OFReader:
725 reader = buf
726 else:
727 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700728 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700729 assert(_type == 1)
Dan Talaycof6202252013-07-02 01:00:29 -0700730 _length = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700731 obj.oxm_list = oxm.unpack_list(reader.slice(_length-4))
Rich Laned53156a2013-08-05 17:17:33 -0700732 reader.skip_align()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700733 return obj
734
735 def __eq__(self, other):
736 if type(self) != type(other): return False
737 if self.oxm_list != other.oxm_list: return False
738 return True
739
740 def __ne__(self, other):
741 return not self.__eq__(other)
742
743 def show(self):
744 import loxi.pp
745 return loxi.pp.pp(self)
746
747 def pretty_print(self, q):
748 q.text("match_v3 {")
749 with q.group():
750 with q.indent(2):
751 q.breakable()
752 q.text("oxm_list = ");
753 q.pp(self.oxm_list)
754 q.breakable()
755 q.text('}')
756
757class packet_queue(object):
758
759 def __init__(self, queue_id=None, port=None, properties=None):
760 if queue_id != None:
761 self.queue_id = queue_id
762 else:
763 self.queue_id = 0
764 if port != None:
765 self.port = port
766 else:
767 self.port = 0
768 if properties != None:
769 self.properties = properties
770 else:
771 self.properties = []
772 return
773
774 def pack(self):
775 packed = []
776 packed.append(struct.pack("!L", self.queue_id))
Dan Talaycof6202252013-07-02 01:00:29 -0700777 packed.append(util.pack_port_no(self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700778 packed.append(struct.pack("!H", 0)) # placeholder for len at index 2
779 packed.append('\x00' * 6)
Dan Talaycof6202252013-07-02 01:00:29 -0700780 packed.append(util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700781 length = sum([len(x) for x in packed])
782 packed[2] = struct.pack("!H", length)
783 return ''.join(packed)
784
785 @staticmethod
786 def unpack(buf):
787 obj = packet_queue()
788 if type(buf) == loxi.generic_util.OFReader:
789 reader = buf
790 else:
791 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700792 obj.queue_id = reader.read("!L")[0]
793 obj.port = util.unpack_port_no(reader)
794 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700795 reader.skip(6)
796 obj.properties = common.unpack_list_queue_prop(reader)
797 return obj
798
799 def __eq__(self, other):
800 if type(self) != type(other): return False
801 if self.queue_id != other.queue_id: return False
802 if self.port != other.port: return False
803 if self.properties != other.properties: return False
804 return True
805
806 def __ne__(self, other):
807 return not self.__eq__(other)
808
809 def show(self):
810 import loxi.pp
811 return loxi.pp.pp(self)
812
813 def pretty_print(self, q):
814 q.text("packet_queue {")
815 with q.group():
816 with q.indent(2):
817 q.breakable()
818 q.text("queue_id = ");
819 q.text("%#x" % self.queue_id)
820 q.text(","); q.breakable()
821 q.text("port = ");
822 q.text(util.pretty_port(self.port))
823 q.text(","); q.breakable()
824 q.text("properties = ");
825 q.pp(self.properties)
826 q.breakable()
827 q.text('}')
828
829class port_desc(object):
830
831 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):
832 if port_no != None:
833 self.port_no = port_no
834 else:
835 self.port_no = 0
836 if hw_addr != None:
837 self.hw_addr = hw_addr
838 else:
839 self.hw_addr = [0,0,0,0,0,0]
840 if name != None:
841 self.name = name
842 else:
843 self.name = ""
844 if config != None:
845 self.config = config
846 else:
847 self.config = 0
848 if state != None:
849 self.state = state
850 else:
851 self.state = 0
852 if curr != None:
853 self.curr = curr
854 else:
855 self.curr = 0
856 if advertised != None:
857 self.advertised = advertised
858 else:
859 self.advertised = 0
860 if supported != None:
861 self.supported = supported
862 else:
863 self.supported = 0
864 if peer != None:
865 self.peer = peer
866 else:
867 self.peer = 0
868 if curr_speed != None:
869 self.curr_speed = curr_speed
870 else:
871 self.curr_speed = 0
872 if max_speed != None:
873 self.max_speed = max_speed
874 else:
875 self.max_speed = 0
876 return
877
878 def pack(self):
879 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700880 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700881 packed.append('\x00' * 4)
882 packed.append(struct.pack("!6B", *self.hw_addr))
883 packed.append('\x00' * 2)
884 packed.append(struct.pack("!16s", self.name))
885 packed.append(struct.pack("!L", self.config))
886 packed.append(struct.pack("!L", self.state))
887 packed.append(struct.pack("!L", self.curr))
888 packed.append(struct.pack("!L", self.advertised))
889 packed.append(struct.pack("!L", self.supported))
890 packed.append(struct.pack("!L", self.peer))
891 packed.append(struct.pack("!L", self.curr_speed))
892 packed.append(struct.pack("!L", self.max_speed))
893 return ''.join(packed)
894
895 @staticmethod
896 def unpack(buf):
897 obj = port_desc()
898 if type(buf) == loxi.generic_util.OFReader:
899 reader = buf
900 else:
901 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700902 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700903 reader.skip(4)
904 obj.hw_addr = list(reader.read('!6B'))
905 reader.skip(2)
906 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700907 obj.config = reader.read("!L")[0]
908 obj.state = reader.read("!L")[0]
909 obj.curr = reader.read("!L")[0]
910 obj.advertised = reader.read("!L")[0]
911 obj.supported = reader.read("!L")[0]
912 obj.peer = reader.read("!L")[0]
913 obj.curr_speed = reader.read("!L")[0]
914 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700915 return obj
916
917 def __eq__(self, other):
918 if type(self) != type(other): return False
919 if self.port_no != other.port_no: return False
920 if self.hw_addr != other.hw_addr: return False
921 if self.name != other.name: return False
922 if self.config != other.config: return False
923 if self.state != other.state: return False
924 if self.curr != other.curr: return False
925 if self.advertised != other.advertised: return False
926 if self.supported != other.supported: return False
927 if self.peer != other.peer: return False
928 if self.curr_speed != other.curr_speed: return False
929 if self.max_speed != other.max_speed: return False
930 return True
931
932 def __ne__(self, other):
933 return not self.__eq__(other)
934
935 def show(self):
936 import loxi.pp
937 return loxi.pp.pp(self)
938
939 def pretty_print(self, q):
940 q.text("port_desc {")
941 with q.group():
942 with q.indent(2):
943 q.breakable()
944 q.text("port_no = ");
945 q.text(util.pretty_port(self.port_no))
946 q.text(","); q.breakable()
947 q.text("hw_addr = ");
948 q.text(util.pretty_mac(self.hw_addr))
949 q.text(","); q.breakable()
950 q.text("name = ");
951 q.pp(self.name)
952 q.text(","); q.breakable()
953 q.text("config = ");
954 q.text("%#x" % self.config)
955 q.text(","); q.breakable()
956 q.text("state = ");
957 q.text("%#x" % self.state)
958 q.text(","); q.breakable()
959 q.text("curr = ");
960 q.text("%#x" % self.curr)
961 q.text(","); q.breakable()
962 q.text("advertised = ");
963 q.text("%#x" % self.advertised)
964 q.text(","); q.breakable()
965 q.text("supported = ");
966 q.text("%#x" % self.supported)
967 q.text(","); q.breakable()
968 q.text("peer = ");
969 q.text("%#x" % self.peer)
970 q.text(","); q.breakable()
971 q.text("curr_speed = ");
972 q.text("%#x" % self.curr_speed)
973 q.text(","); q.breakable()
974 q.text("max_speed = ");
975 q.text("%#x" % self.max_speed)
976 q.breakable()
977 q.text('}')
978
979class port_stats_entry(object):
980
981 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):
982 if port_no != None:
983 self.port_no = port_no
984 else:
985 self.port_no = 0
986 if rx_packets != None:
987 self.rx_packets = rx_packets
988 else:
989 self.rx_packets = 0
990 if tx_packets != None:
991 self.tx_packets = tx_packets
992 else:
993 self.tx_packets = 0
994 if rx_bytes != None:
995 self.rx_bytes = rx_bytes
996 else:
997 self.rx_bytes = 0
998 if tx_bytes != None:
999 self.tx_bytes = tx_bytes
1000 else:
1001 self.tx_bytes = 0
1002 if rx_dropped != None:
1003 self.rx_dropped = rx_dropped
1004 else:
1005 self.rx_dropped = 0
1006 if tx_dropped != None:
1007 self.tx_dropped = tx_dropped
1008 else:
1009 self.tx_dropped = 0
1010 if rx_errors != None:
1011 self.rx_errors = rx_errors
1012 else:
1013 self.rx_errors = 0
1014 if tx_errors != None:
1015 self.tx_errors = tx_errors
1016 else:
1017 self.tx_errors = 0
1018 if rx_frame_err != None:
1019 self.rx_frame_err = rx_frame_err
1020 else:
1021 self.rx_frame_err = 0
1022 if rx_over_err != None:
1023 self.rx_over_err = rx_over_err
1024 else:
1025 self.rx_over_err = 0
1026 if rx_crc_err != None:
1027 self.rx_crc_err = rx_crc_err
1028 else:
1029 self.rx_crc_err = 0
1030 if collisions != None:
1031 self.collisions = collisions
1032 else:
1033 self.collisions = 0
1034 return
1035
1036 def pack(self):
1037 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001038 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001039 packed.append('\x00' * 4)
1040 packed.append(struct.pack("!Q", self.rx_packets))
1041 packed.append(struct.pack("!Q", self.tx_packets))
1042 packed.append(struct.pack("!Q", self.rx_bytes))
1043 packed.append(struct.pack("!Q", self.tx_bytes))
1044 packed.append(struct.pack("!Q", self.rx_dropped))
1045 packed.append(struct.pack("!Q", self.tx_dropped))
1046 packed.append(struct.pack("!Q", self.rx_errors))
1047 packed.append(struct.pack("!Q", self.tx_errors))
1048 packed.append(struct.pack("!Q", self.rx_frame_err))
1049 packed.append(struct.pack("!Q", self.rx_over_err))
1050 packed.append(struct.pack("!Q", self.rx_crc_err))
1051 packed.append(struct.pack("!Q", self.collisions))
1052 return ''.join(packed)
1053
1054 @staticmethod
1055 def unpack(buf):
1056 obj = port_stats_entry()
1057 if type(buf) == loxi.generic_util.OFReader:
1058 reader = buf
1059 else:
1060 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001061 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001062 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001063 obj.rx_packets = reader.read("!Q")[0]
1064 obj.tx_packets = reader.read("!Q")[0]
1065 obj.rx_bytes = reader.read("!Q")[0]
1066 obj.tx_bytes = reader.read("!Q")[0]
1067 obj.rx_dropped = reader.read("!Q")[0]
1068 obj.tx_dropped = reader.read("!Q")[0]
1069 obj.rx_errors = reader.read("!Q")[0]
1070 obj.tx_errors = reader.read("!Q")[0]
1071 obj.rx_frame_err = reader.read("!Q")[0]
1072 obj.rx_over_err = reader.read("!Q")[0]
1073 obj.rx_crc_err = reader.read("!Q")[0]
1074 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001075 return obj
1076
1077 def __eq__(self, other):
1078 if type(self) != type(other): return False
1079 if self.port_no != other.port_no: return False
1080 if self.rx_packets != other.rx_packets: return False
1081 if self.tx_packets != other.tx_packets: return False
1082 if self.rx_bytes != other.rx_bytes: return False
1083 if self.tx_bytes != other.tx_bytes: return False
1084 if self.rx_dropped != other.rx_dropped: return False
1085 if self.tx_dropped != other.tx_dropped: return False
1086 if self.rx_errors != other.rx_errors: return False
1087 if self.tx_errors != other.tx_errors: return False
1088 if self.rx_frame_err != other.rx_frame_err: return False
1089 if self.rx_over_err != other.rx_over_err: return False
1090 if self.rx_crc_err != other.rx_crc_err: return False
1091 if self.collisions != other.collisions: return False
1092 return True
1093
1094 def __ne__(self, other):
1095 return not self.__eq__(other)
1096
1097 def show(self):
1098 import loxi.pp
1099 return loxi.pp.pp(self)
1100
1101 def pretty_print(self, q):
1102 q.text("port_stats_entry {")
1103 with q.group():
1104 with q.indent(2):
1105 q.breakable()
1106 q.text("port_no = ");
1107 q.text(util.pretty_port(self.port_no))
1108 q.text(","); q.breakable()
1109 q.text("rx_packets = ");
1110 q.text("%#x" % self.rx_packets)
1111 q.text(","); q.breakable()
1112 q.text("tx_packets = ");
1113 q.text("%#x" % self.tx_packets)
1114 q.text(","); q.breakable()
1115 q.text("rx_bytes = ");
1116 q.text("%#x" % self.rx_bytes)
1117 q.text(","); q.breakable()
1118 q.text("tx_bytes = ");
1119 q.text("%#x" % self.tx_bytes)
1120 q.text(","); q.breakable()
1121 q.text("rx_dropped = ");
1122 q.text("%#x" % self.rx_dropped)
1123 q.text(","); q.breakable()
1124 q.text("tx_dropped = ");
1125 q.text("%#x" % self.tx_dropped)
1126 q.text(","); q.breakable()
1127 q.text("rx_errors = ");
1128 q.text("%#x" % self.rx_errors)
1129 q.text(","); q.breakable()
1130 q.text("tx_errors = ");
1131 q.text("%#x" % self.tx_errors)
1132 q.text(","); q.breakable()
1133 q.text("rx_frame_err = ");
1134 q.text("%#x" % self.rx_frame_err)
1135 q.text(","); q.breakable()
1136 q.text("rx_over_err = ");
1137 q.text("%#x" % self.rx_over_err)
1138 q.text(","); q.breakable()
1139 q.text("rx_crc_err = ");
1140 q.text("%#x" % self.rx_crc_err)
1141 q.text(","); q.breakable()
1142 q.text("collisions = ");
1143 q.text("%#x" % self.collisions)
1144 q.breakable()
1145 q.text('}')
1146
Rich Lanec2ee4b82013-04-24 17:12:38 -07001147class queue_prop_max_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001148 type = 2
Rich Lanec2ee4b82013-04-24 17:12:38 -07001149
1150 def __init__(self, rate=None):
1151 if rate != None:
1152 self.rate = rate
1153 else:
1154 self.rate = 0
1155 return
1156
1157 def pack(self):
1158 packed = []
1159 packed.append(struct.pack("!H", self.type))
1160 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1161 packed.append('\x00' * 4)
1162 packed.append(struct.pack("!H", self.rate))
1163 packed.append('\x00' * 6)
1164 length = sum([len(x) for x in packed])
1165 packed[1] = struct.pack("!H", length)
1166 return ''.join(packed)
1167
1168 @staticmethod
1169 def unpack(buf):
1170 obj = queue_prop_max_rate()
1171 if type(buf) == loxi.generic_util.OFReader:
1172 reader = buf
1173 else:
1174 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001175 _type = reader.read("!H")[0]
1176 assert(_type == 2)
1177 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001178 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001179 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001180 reader.skip(6)
1181 return obj
1182
1183 def __eq__(self, other):
1184 if type(self) != type(other): return False
1185 if self.rate != other.rate: return False
1186 return True
1187
1188 def __ne__(self, other):
1189 return not self.__eq__(other)
1190
1191 def show(self):
1192 import loxi.pp
1193 return loxi.pp.pp(self)
1194
1195 def pretty_print(self, q):
1196 q.text("queue_prop_max_rate {")
1197 with q.group():
1198 with q.indent(2):
1199 q.breakable()
1200 q.text("rate = ");
1201 q.text("%#x" % self.rate)
1202 q.breakable()
1203 q.text('}')
1204
1205class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001206 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001207
1208 def __init__(self, rate=None):
1209 if rate != None:
1210 self.rate = rate
1211 else:
1212 self.rate = 0
1213 return
1214
1215 def pack(self):
1216 packed = []
1217 packed.append(struct.pack("!H", self.type))
1218 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1219 packed.append('\x00' * 4)
1220 packed.append(struct.pack("!H", self.rate))
1221 packed.append('\x00' * 6)
1222 length = sum([len(x) for x in packed])
1223 packed[1] = struct.pack("!H", length)
1224 return ''.join(packed)
1225
1226 @staticmethod
1227 def unpack(buf):
1228 obj = queue_prop_min_rate()
1229 if type(buf) == loxi.generic_util.OFReader:
1230 reader = buf
1231 else:
1232 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001233 _type = reader.read("!H")[0]
1234 assert(_type == 1)
1235 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001236 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001237 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001238 reader.skip(6)
1239 return obj
1240
1241 def __eq__(self, other):
1242 if type(self) != type(other): return False
1243 if self.rate != other.rate: return False
1244 return True
1245
1246 def __ne__(self, other):
1247 return not self.__eq__(other)
1248
1249 def show(self):
1250 import loxi.pp
1251 return loxi.pp.pp(self)
1252
1253 def pretty_print(self, q):
1254 q.text("queue_prop_min_rate {")
1255 with q.group():
1256 with q.indent(2):
1257 q.breakable()
1258 q.text("rate = ");
1259 q.text("%#x" % self.rate)
1260 q.breakable()
1261 q.text('}')
1262
1263class queue_stats_entry(object):
1264
1265 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1266 if port_no != None:
1267 self.port_no = port_no
1268 else:
1269 self.port_no = 0
1270 if queue_id != None:
1271 self.queue_id = queue_id
1272 else:
1273 self.queue_id = 0
1274 if tx_bytes != None:
1275 self.tx_bytes = tx_bytes
1276 else:
1277 self.tx_bytes = 0
1278 if tx_packets != None:
1279 self.tx_packets = tx_packets
1280 else:
1281 self.tx_packets = 0
1282 if tx_errors != None:
1283 self.tx_errors = tx_errors
1284 else:
1285 self.tx_errors = 0
1286 return
1287
1288 def pack(self):
1289 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001290 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001291 packed.append(struct.pack("!L", self.queue_id))
1292 packed.append(struct.pack("!Q", self.tx_bytes))
1293 packed.append(struct.pack("!Q", self.tx_packets))
1294 packed.append(struct.pack("!Q", self.tx_errors))
1295 return ''.join(packed)
1296
1297 @staticmethod
1298 def unpack(buf):
1299 obj = queue_stats_entry()
1300 if type(buf) == loxi.generic_util.OFReader:
1301 reader = buf
1302 else:
1303 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001304 obj.port_no = util.unpack_port_no(reader)
1305 obj.queue_id = reader.read("!L")[0]
1306 obj.tx_bytes = reader.read("!Q")[0]
1307 obj.tx_packets = reader.read("!Q")[0]
1308 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001309 return obj
1310
1311 def __eq__(self, other):
1312 if type(self) != type(other): return False
1313 if self.port_no != other.port_no: return False
1314 if self.queue_id != other.queue_id: return False
1315 if self.tx_bytes != other.tx_bytes: return False
1316 if self.tx_packets != other.tx_packets: return False
1317 if self.tx_errors != other.tx_errors: return False
1318 return True
1319
1320 def __ne__(self, other):
1321 return not self.__eq__(other)
1322
1323 def show(self):
1324 import loxi.pp
1325 return loxi.pp.pp(self)
1326
1327 def pretty_print(self, q):
1328 q.text("queue_stats_entry {")
1329 with q.group():
1330 with q.indent(2):
1331 q.breakable()
1332 q.text("port_no = ");
1333 q.text(util.pretty_port(self.port_no))
1334 q.text(","); q.breakable()
1335 q.text("queue_id = ");
1336 q.text("%#x" % self.queue_id)
1337 q.text(","); q.breakable()
1338 q.text("tx_bytes = ");
1339 q.text("%#x" % self.tx_bytes)
1340 q.text(","); q.breakable()
1341 q.text("tx_packets = ");
1342 q.text("%#x" % self.tx_packets)
1343 q.text(","); q.breakable()
1344 q.text("tx_errors = ");
1345 q.text("%#x" % self.tx_errors)
1346 q.breakable()
1347 q.text('}')
1348
1349class table_stats_entry(object):
1350
1351 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):
1352 if table_id != None:
1353 self.table_id = table_id
1354 else:
1355 self.table_id = 0
1356 if name != None:
1357 self.name = name
1358 else:
1359 self.name = ""
1360 if match != None:
1361 self.match = match
1362 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001363 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001364 if wildcards != None:
1365 self.wildcards = wildcards
1366 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001367 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001368 if write_actions != None:
1369 self.write_actions = write_actions
1370 else:
1371 self.write_actions = 0
1372 if apply_actions != None:
1373 self.apply_actions = apply_actions
1374 else:
1375 self.apply_actions = 0
1376 if write_setfields != None:
1377 self.write_setfields = write_setfields
1378 else:
1379 self.write_setfields = 0
1380 if apply_setfields != None:
1381 self.apply_setfields = apply_setfields
1382 else:
1383 self.apply_setfields = 0
1384 if metadata_match != None:
1385 self.metadata_match = metadata_match
1386 else:
1387 self.metadata_match = 0
1388 if metadata_write != None:
1389 self.metadata_write = metadata_write
1390 else:
1391 self.metadata_write = 0
1392 if instructions != None:
1393 self.instructions = instructions
1394 else:
1395 self.instructions = 0
1396 if config != None:
1397 self.config = config
1398 else:
1399 self.config = 0
1400 if max_entries != None:
1401 self.max_entries = max_entries
1402 else:
1403 self.max_entries = 0
1404 if active_count != None:
1405 self.active_count = active_count
1406 else:
1407 self.active_count = 0
1408 if lookup_count != None:
1409 self.lookup_count = lookup_count
1410 else:
1411 self.lookup_count = 0
1412 if matched_count != None:
1413 self.matched_count = matched_count
1414 else:
1415 self.matched_count = 0
1416 return
1417
1418 def pack(self):
1419 packed = []
1420 packed.append(struct.pack("!B", self.table_id))
1421 packed.append('\x00' * 7)
1422 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001423 packed.append(util.pack_match_bmap(self.match))
1424 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001425 packed.append(struct.pack("!L", self.write_actions))
1426 packed.append(struct.pack("!L", self.apply_actions))
1427 packed.append(struct.pack("!Q", self.write_setfields))
1428 packed.append(struct.pack("!Q", self.apply_setfields))
1429 packed.append(struct.pack("!Q", self.metadata_match))
1430 packed.append(struct.pack("!Q", self.metadata_write))
1431 packed.append(struct.pack("!L", self.instructions))
1432 packed.append(struct.pack("!L", self.config))
1433 packed.append(struct.pack("!L", self.max_entries))
1434 packed.append(struct.pack("!L", self.active_count))
1435 packed.append(struct.pack("!Q", self.lookup_count))
1436 packed.append(struct.pack("!Q", self.matched_count))
1437 return ''.join(packed)
1438
1439 @staticmethod
1440 def unpack(buf):
1441 obj = table_stats_entry()
1442 if type(buf) == loxi.generic_util.OFReader:
1443 reader = buf
1444 else:
1445 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001446 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001447 reader.skip(7)
1448 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001449 obj.match = util.unpack_match_bmap(reader)
1450 obj.wildcards = util.unpack_wc_bmap(reader)
1451 obj.write_actions = reader.read("!L")[0]
1452 obj.apply_actions = reader.read("!L")[0]
1453 obj.write_setfields = reader.read("!Q")[0]
1454 obj.apply_setfields = reader.read("!Q")[0]
1455 obj.metadata_match = reader.read("!Q")[0]
1456 obj.metadata_write = reader.read("!Q")[0]
1457 obj.instructions = reader.read("!L")[0]
1458 obj.config = reader.read("!L")[0]
1459 obj.max_entries = reader.read("!L")[0]
1460 obj.active_count = reader.read("!L")[0]
1461 obj.lookup_count = reader.read("!Q")[0]
1462 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001463 return obj
1464
1465 def __eq__(self, other):
1466 if type(self) != type(other): return False
1467 if self.table_id != other.table_id: return False
1468 if self.name != other.name: return False
1469 if self.match != other.match: return False
1470 if self.wildcards != other.wildcards: return False
1471 if self.write_actions != other.write_actions: return False
1472 if self.apply_actions != other.apply_actions: return False
1473 if self.write_setfields != other.write_setfields: return False
1474 if self.apply_setfields != other.apply_setfields: return False
1475 if self.metadata_match != other.metadata_match: return False
1476 if self.metadata_write != other.metadata_write: return False
1477 if self.instructions != other.instructions: return False
1478 if self.config != other.config: return False
1479 if self.max_entries != other.max_entries: return False
1480 if self.active_count != other.active_count: return False
1481 if self.lookup_count != other.lookup_count: return False
1482 if self.matched_count != other.matched_count: return False
1483 return True
1484
1485 def __ne__(self, other):
1486 return not self.__eq__(other)
1487
1488 def show(self):
1489 import loxi.pp
1490 return loxi.pp.pp(self)
1491
1492 def pretty_print(self, q):
1493 q.text("table_stats_entry {")
1494 with q.group():
1495 with q.indent(2):
1496 q.breakable()
1497 q.text("table_id = ");
1498 q.text("%#x" % self.table_id)
1499 q.text(","); q.breakable()
1500 q.text("name = ");
1501 q.pp(self.name)
1502 q.text(","); q.breakable()
1503 q.text("match = ");
1504 q.pp(self.match)
1505 q.text(","); q.breakable()
1506 q.text("wildcards = ");
1507 q.pp(self.wildcards)
1508 q.text(","); q.breakable()
1509 q.text("write_actions = ");
1510 q.text("%#x" % self.write_actions)
1511 q.text(","); q.breakable()
1512 q.text("apply_actions = ");
1513 q.text("%#x" % self.apply_actions)
1514 q.text(","); q.breakable()
1515 q.text("write_setfields = ");
1516 q.text("%#x" % self.write_setfields)
1517 q.text(","); q.breakable()
1518 q.text("apply_setfields = ");
1519 q.text("%#x" % self.apply_setfields)
1520 q.text(","); q.breakable()
1521 q.text("metadata_match = ");
1522 q.text("%#x" % self.metadata_match)
1523 q.text(","); q.breakable()
1524 q.text("metadata_write = ");
1525 q.text("%#x" % self.metadata_write)
1526 q.text(","); q.breakable()
1527 q.text("instructions = ");
1528 q.text("%#x" % self.instructions)
1529 q.text(","); q.breakable()
1530 q.text("config = ");
1531 q.text("%#x" % self.config)
1532 q.text(","); q.breakable()
1533 q.text("max_entries = ");
1534 q.text("%#x" % self.max_entries)
1535 q.text(","); q.breakable()
1536 q.text("active_count = ");
1537 q.text("%#x" % self.active_count)
1538 q.text(","); q.breakable()
1539 q.text("lookup_count = ");
1540 q.text("%#x" % self.lookup_count)
1541 q.text(","); q.breakable()
1542 q.text("matched_count = ");
1543 q.text("%#x" % self.matched_count)
1544 q.breakable()
1545 q.text('}')
1546
1547
1548match = match_v3