blob: 868f86dfaf51b8ff5a3192c4b9b1e2154a8ca65b [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
16
17# HACK make this module visible as 'common' to simplify code generation
18common = sys.modules[__name__]
19
20def unpack_list_flow_stats_entry(reader):
21 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
22
23def unpack_list_queue_prop(reader):
24 def deserializer(reader, typ):
25 if typ == const.OFPQT_MIN_RATE:
26 return queue_prop_min_rate.unpack(reader)
27 else:
28 raise loxi.ProtocolError("unknown queue prop %d" % typ)
29 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
30
31def unpack_list_packet_queue(reader):
32 def wrapper(reader):
33 length, = reader.peek('!4xH')
34 return packet_queue.unpack(reader.slice(length))
35 return loxi.generic_util.unpack_list(reader, wrapper)
36
37def unpack_list_hello_elem(reader):
38 def deserializer(reader, typ):
39 if typ == const.OFPHET_VERSIONBITMAP:
40 return hello_elem_versionbitmap.unpack(reader)
41 else:
42 return None
43 return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
44
45def unpack_list_bucket(reader):
46 return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
47
48def unpack_list_group_desc_stats_entry(reader):
49 return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
50
51def unpack_list_group_stats_entry(reader):
52 return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
53
54def unpack_list_meter_stats(reader):
55 def wrapper(reader):
56 length, = reader.peek('!4xH')
57 return meter_stats.unpack(reader.slice(length))
58 return loxi.generic_util.unpack_list(reader, wrapper)
59
60class bsn_interface(object):
61
62 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
63 if hw_addr != None:
64 self.hw_addr = hw_addr
65 else:
66 self.hw_addr = [0,0,0,0,0,0]
67 if name != None:
68 self.name = name
69 else:
70 self.name = ""
71 if ipv4_addr != None:
72 self.ipv4_addr = ipv4_addr
73 else:
74 self.ipv4_addr = 0
75 if ipv4_netmask != None:
76 self.ipv4_netmask = ipv4_netmask
77 else:
78 self.ipv4_netmask = 0
79 return
80
81 def pack(self):
82 packed = []
83 packed.append(struct.pack("!6B", *self.hw_addr))
84 packed.append('\x00' * 2)
85 packed.append(struct.pack("!16s", self.name))
86 packed.append(struct.pack("!L", self.ipv4_addr))
87 packed.append(struct.pack("!L", self.ipv4_netmask))
88 return ''.join(packed)
89
90 @staticmethod
91 def unpack(buf):
92 obj = bsn_interface()
93 if type(buf) == loxi.generic_util.OFReader:
94 reader = buf
95 else:
96 reader = loxi.generic_util.OFReader(buf)
97 obj.hw_addr = list(reader.read('!6B'))
98 reader.skip(2)
99 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700100 obj.ipv4_addr = reader.read("!L")[0]
101 obj.ipv4_netmask = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700102 return obj
103
104 def __eq__(self, other):
105 if type(self) != type(other): return False
106 if self.hw_addr != other.hw_addr: return False
107 if self.name != other.name: return False
108 if self.ipv4_addr != other.ipv4_addr: return False
109 if self.ipv4_netmask != other.ipv4_netmask: return False
110 return True
111
112 def __ne__(self, other):
113 return not self.__eq__(other)
114
115 def show(self):
116 import loxi.pp
117 return loxi.pp.pp(self)
118
119 def pretty_print(self, q):
120 q.text("bsn_interface {")
121 with q.group():
122 with q.indent(2):
123 q.breakable()
124 q.text("hw_addr = ");
125 q.text(util.pretty_mac(self.hw_addr))
126 q.text(","); q.breakable()
127 q.text("name = ");
128 q.pp(self.name)
129 q.text(","); q.breakable()
130 q.text("ipv4_addr = ");
131 q.text(util.pretty_ipv4(self.ipv4_addr))
132 q.text(","); q.breakable()
133 q.text("ipv4_netmask = ");
134 q.text(util.pretty_ipv4(self.ipv4_netmask))
135 q.breakable()
136 q.text('}')
137
Dan Talaycof6202252013-07-02 01:00:29 -0700138class bsn_vport_q_in_q(object):
139 type = 0
140
Kiran Poola150d8b02013-09-20 13:30:39 -0700141 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 -0700142 if port_no != None:
143 self.port_no = port_no
144 else:
145 self.port_no = 0
146 if ingress_tpid != None:
147 self.ingress_tpid = ingress_tpid
148 else:
149 self.ingress_tpid = 0
150 if ingress_vlan_id != None:
151 self.ingress_vlan_id = ingress_vlan_id
152 else:
153 self.ingress_vlan_id = 0
154 if egress_tpid != None:
155 self.egress_tpid = egress_tpid
156 else:
157 self.egress_tpid = 0
158 if egress_vlan_id != None:
159 self.egress_vlan_id = egress_vlan_id
160 else:
161 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700162 if if_name != None:
163 self.if_name = if_name
164 else:
165 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700166 return
167
168 def pack(self):
169 packed = []
170 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700171 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700172 packed.append(struct.pack("!L", self.port_no))
173 packed.append(struct.pack("!H", self.ingress_tpid))
174 packed.append(struct.pack("!H", self.ingress_vlan_id))
175 packed.append(struct.pack("!H", self.egress_tpid))
176 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700177 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700178 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700179 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700180 return ''.join(packed)
181
182 @staticmethod
183 def unpack(buf):
184 obj = bsn_vport_q_in_q()
185 if type(buf) == loxi.generic_util.OFReader:
186 reader = buf
187 else:
188 reader = loxi.generic_util.OFReader(buf)
189 _type = reader.read("!H")[0]
190 assert(_type == 0)
191 _length = reader.read("!H")[0]
192 obj.port_no = reader.read("!L")[0]
193 obj.ingress_tpid = reader.read("!H")[0]
194 obj.ingress_vlan_id = reader.read("!H")[0]
195 obj.egress_tpid = reader.read("!H")[0]
196 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700197 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700198 return obj
199
200 def __eq__(self, other):
201 if type(self) != type(other): return False
202 if self.port_no != other.port_no: return False
203 if self.ingress_tpid != other.ingress_tpid: return False
204 if self.ingress_vlan_id != other.ingress_vlan_id: return False
205 if self.egress_tpid != other.egress_tpid: return False
206 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700207 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700208 return True
209
210 def __ne__(self, other):
211 return not self.__eq__(other)
212
213 def show(self):
214 import loxi.pp
215 return loxi.pp.pp(self)
216
217 def pretty_print(self, q):
218 q.text("bsn_vport_q_in_q {")
219 with q.group():
220 with q.indent(2):
221 q.breakable()
222 q.text("port_no = ");
223 q.text("%#x" % self.port_no)
224 q.text(","); q.breakable()
225 q.text("ingress_tpid = ");
226 q.text("%#x" % self.ingress_tpid)
227 q.text(","); q.breakable()
228 q.text("ingress_vlan_id = ");
229 q.text("%#x" % self.ingress_vlan_id)
230 q.text(","); q.breakable()
231 q.text("egress_tpid = ");
232 q.text("%#x" % self.egress_tpid)
233 q.text(","); q.breakable()
234 q.text("egress_vlan_id = ");
235 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700236 q.text(","); q.breakable()
237 q.text("if_name = ");
238 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700239 q.breakable()
240 q.text('}')
241
Rich Lanec2ee4b82013-04-24 17:12:38 -0700242class bucket(object):
243
244 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
245 if weight != None:
246 self.weight = weight
247 else:
248 self.weight = 0
249 if watch_port != None:
250 self.watch_port = watch_port
251 else:
252 self.watch_port = 0
253 if watch_group != None:
254 self.watch_group = watch_group
255 else:
256 self.watch_group = 0
257 if actions != None:
258 self.actions = actions
259 else:
260 self.actions = []
261 return
262
263 def pack(self):
264 packed = []
265 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
266 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700267 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700268 packed.append(struct.pack("!L", self.watch_group))
269 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700270 packed.append(util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700271 length = sum([len(x) for x in packed])
272 packed[0] = struct.pack("!H", length)
273 return ''.join(packed)
274
275 @staticmethod
276 def unpack(buf):
277 obj = bucket()
278 if type(buf) == loxi.generic_util.OFReader:
279 reader = buf
280 else:
281 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700282 _len = reader.read("!H")[0]
283 obj.weight = reader.read("!H")[0]
284 obj.watch_port = util.unpack_port_no(reader)
285 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700286 reader.skip(4)
287 obj.actions = action.unpack_list(reader)
288 return obj
289
290 def __eq__(self, other):
291 if type(self) != type(other): return False
292 if self.weight != other.weight: return False
293 if self.watch_port != other.watch_port: return False
294 if self.watch_group != other.watch_group: return False
295 if self.actions != other.actions: return False
296 return True
297
298 def __ne__(self, other):
299 return not self.__eq__(other)
300
301 def show(self):
302 import loxi.pp
303 return loxi.pp.pp(self)
304
305 def pretty_print(self, q):
306 q.text("bucket {")
307 with q.group():
308 with q.indent(2):
309 q.breakable()
310 q.text("weight = ");
311 q.text("%#x" % self.weight)
312 q.text(","); q.breakable()
313 q.text("watch_port = ");
314 q.text(util.pretty_port(self.watch_port))
315 q.text(","); q.breakable()
316 q.text("watch_group = ");
317 q.text("%#x" % self.watch_group)
318 q.text(","); q.breakable()
319 q.text("actions = ");
320 q.pp(self.actions)
321 q.breakable()
322 q.text('}')
323
324class bucket_counter(object):
325
326 def __init__(self, packet_count=None, byte_count=None):
327 if packet_count != None:
328 self.packet_count = packet_count
329 else:
330 self.packet_count = 0
331 if byte_count != None:
332 self.byte_count = byte_count
333 else:
334 self.byte_count = 0
335 return
336
337 def pack(self):
338 packed = []
339 packed.append(struct.pack("!Q", self.packet_count))
340 packed.append(struct.pack("!Q", self.byte_count))
341 return ''.join(packed)
342
343 @staticmethod
344 def unpack(buf):
345 obj = bucket_counter()
346 if type(buf) == loxi.generic_util.OFReader:
347 reader = buf
348 else:
349 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700350 obj.packet_count = reader.read("!Q")[0]
351 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700352 return obj
353
354 def __eq__(self, other):
355 if type(self) != type(other): return False
356 if self.packet_count != other.packet_count: return False
357 if self.byte_count != other.byte_count: return False
358 return True
359
360 def __ne__(self, other):
361 return not self.__eq__(other)
362
363 def show(self):
364 import loxi.pp
365 return loxi.pp.pp(self)
366
367 def pretty_print(self, q):
368 q.text("bucket_counter {")
369 with q.group():
370 with q.indent(2):
371 q.breakable()
372 q.text("packet_count = ");
373 q.text("%#x" % self.packet_count)
374 q.text(","); q.breakable()
375 q.text("byte_count = ");
376 q.text("%#x" % self.byte_count)
377 q.breakable()
378 q.text('}')
379
380class flow_stats_entry(object):
381
382 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):
383 if table_id != None:
384 self.table_id = table_id
385 else:
386 self.table_id = 0
387 if duration_sec != None:
388 self.duration_sec = duration_sec
389 else:
390 self.duration_sec = 0
391 if duration_nsec != None:
392 self.duration_nsec = duration_nsec
393 else:
394 self.duration_nsec = 0
395 if priority != None:
396 self.priority = priority
397 else:
398 self.priority = 0
399 if idle_timeout != None:
400 self.idle_timeout = idle_timeout
401 else:
402 self.idle_timeout = 0
403 if hard_timeout != None:
404 self.hard_timeout = hard_timeout
405 else:
406 self.hard_timeout = 0
407 if cookie != None:
408 self.cookie = cookie
409 else:
410 self.cookie = 0
411 if packet_count != None:
412 self.packet_count = packet_count
413 else:
414 self.packet_count = 0
415 if byte_count != None:
416 self.byte_count = byte_count
417 else:
418 self.byte_count = 0
419 if match != None:
420 self.match = match
421 else:
422 self.match = common.match()
423 if instructions != None:
424 self.instructions = instructions
425 else:
426 self.instructions = []
427 return
428
429 def pack(self):
430 packed = []
431 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
432 packed.append(struct.pack("!B", self.table_id))
433 packed.append('\x00' * 1)
434 packed.append(struct.pack("!L", self.duration_sec))
435 packed.append(struct.pack("!L", self.duration_nsec))
436 packed.append(struct.pack("!H", self.priority))
437 packed.append(struct.pack("!H", self.idle_timeout))
438 packed.append(struct.pack("!H", self.hard_timeout))
439 packed.append('\x00' * 6)
440 packed.append(struct.pack("!Q", self.cookie))
441 packed.append(struct.pack("!Q", self.packet_count))
442 packed.append(struct.pack("!Q", self.byte_count))
443 packed.append(self.match.pack())
Dan Talaycof6202252013-07-02 01:00:29 -0700444 packed.append(util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700445 length = sum([len(x) for x in packed])
446 packed[0] = struct.pack("!H", length)
447 return ''.join(packed)
448
449 @staticmethod
450 def unpack(buf):
451 obj = flow_stats_entry()
452 if type(buf) == loxi.generic_util.OFReader:
453 reader = buf
454 else:
455 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700456 _length = reader.read("!H")[0]
457 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700458 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700459 obj.duration_sec = reader.read("!L")[0]
460 obj.duration_nsec = reader.read("!L")[0]
461 obj.priority = reader.read("!H")[0]
462 obj.idle_timeout = reader.read("!H")[0]
463 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700464 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700465 obj.cookie = reader.read("!Q")[0]
466 obj.packet_count = reader.read("!Q")[0]
467 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700468 obj.match = common.match.unpack(reader)
469 obj.instructions = instruction.unpack_list(reader)
470 return obj
471
472 def __eq__(self, other):
473 if type(self) != type(other): return False
474 if self.table_id != other.table_id: return False
475 if self.duration_sec != other.duration_sec: return False
476 if self.duration_nsec != other.duration_nsec: return False
477 if self.priority != other.priority: return False
478 if self.idle_timeout != other.idle_timeout: return False
479 if self.hard_timeout != other.hard_timeout: return False
480 if self.cookie != other.cookie: return False
481 if self.packet_count != other.packet_count: return False
482 if self.byte_count != other.byte_count: return False
483 if self.match != other.match: return False
484 if self.instructions != other.instructions: return False
485 return True
486
487 def __ne__(self, other):
488 return not self.__eq__(other)
489
490 def show(self):
491 import loxi.pp
492 return loxi.pp.pp(self)
493
494 def pretty_print(self, q):
495 q.text("flow_stats_entry {")
496 with q.group():
497 with q.indent(2):
498 q.breakable()
499 q.text("table_id = ");
500 q.text("%#x" % self.table_id)
501 q.text(","); q.breakable()
502 q.text("duration_sec = ");
503 q.text("%#x" % self.duration_sec)
504 q.text(","); q.breakable()
505 q.text("duration_nsec = ");
506 q.text("%#x" % self.duration_nsec)
507 q.text(","); q.breakable()
508 q.text("priority = ");
509 q.text("%#x" % self.priority)
510 q.text(","); q.breakable()
511 q.text("idle_timeout = ");
512 q.text("%#x" % self.idle_timeout)
513 q.text(","); q.breakable()
514 q.text("hard_timeout = ");
515 q.text("%#x" % self.hard_timeout)
516 q.text(","); q.breakable()
517 q.text("cookie = ");
518 q.text("%#x" % self.cookie)
519 q.text(","); q.breakable()
520 q.text("packet_count = ");
521 q.text("%#x" % self.packet_count)
522 q.text(","); q.breakable()
523 q.text("byte_count = ");
524 q.text("%#x" % self.byte_count)
525 q.text(","); q.breakable()
526 q.text("match = ");
527 q.pp(self.match)
528 q.text(","); q.breakable()
529 q.text("instructions = ");
530 q.pp(self.instructions)
531 q.breakable()
532 q.text('}')
533
534class group_desc_stats_entry(object):
535
Rich Lane6f4978c2013-10-20 21:33:52 -0700536 def __init__(self, group_type=None, group_id=None, buckets=None):
537 if group_type != None:
538 self.group_type = group_type
Rich Lanec2ee4b82013-04-24 17:12:38 -0700539 else:
Rich Lane6f4978c2013-10-20 21:33:52 -0700540 self.group_type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700541 if group_id != None:
542 self.group_id = group_id
543 else:
544 self.group_id = 0
545 if buckets != None:
546 self.buckets = buckets
547 else:
548 self.buckets = []
549 return
550
551 def pack(self):
552 packed = []
553 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
Rich Lane6f4978c2013-10-20 21:33:52 -0700554 packed.append(struct.pack("!B", self.group_type))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700555 packed.append('\x00' * 1)
556 packed.append(struct.pack("!L", self.group_id))
Dan Talaycof6202252013-07-02 01:00:29 -0700557 packed.append(util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700558 length = sum([len(x) for x in packed])
559 packed[0] = struct.pack("!H", length)
560 return ''.join(packed)
561
562 @staticmethod
563 def unpack(buf):
564 obj = group_desc_stats_entry()
565 if type(buf) == loxi.generic_util.OFReader:
566 reader = buf
567 else:
568 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700569 _length = reader.read("!H")[0]
Rich Lane6f4978c2013-10-20 21:33:52 -0700570 obj.group_type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700571 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700572 obj.group_id = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700573 obj.buckets = common.unpack_list_bucket(reader)
574 return obj
575
576 def __eq__(self, other):
577 if type(self) != type(other): return False
Rich Lane6f4978c2013-10-20 21:33:52 -0700578 if self.group_type != other.group_type: return False
Rich Lanec2ee4b82013-04-24 17:12:38 -0700579 if self.group_id != other.group_id: return False
580 if self.buckets != other.buckets: return False
581 return True
582
583 def __ne__(self, other):
584 return not self.__eq__(other)
585
586 def show(self):
587 import loxi.pp
588 return loxi.pp.pp(self)
589
590 def pretty_print(self, q):
591 q.text("group_desc_stats_entry {")
592 with q.group():
593 with q.indent(2):
594 q.breakable()
Rich Lane6f4978c2013-10-20 21:33:52 -0700595 q.text("group_type = ");
596 q.text("%#x" % self.group_type)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700597 q.text(","); q.breakable()
598 q.text("group_id = ");
599 q.text("%#x" % self.group_id)
600 q.text(","); q.breakable()
601 q.text("buckets = ");
602 q.pp(self.buckets)
603 q.breakable()
604 q.text('}')
605
606class group_stats_entry(object):
607
608 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
609 if group_id != None:
610 self.group_id = group_id
611 else:
612 self.group_id = 0
613 if ref_count != None:
614 self.ref_count = ref_count
615 else:
616 self.ref_count = 0
617 if packet_count != None:
618 self.packet_count = packet_count
619 else:
620 self.packet_count = 0
621 if byte_count != None:
622 self.byte_count = byte_count
623 else:
624 self.byte_count = 0
625 if bucket_stats != None:
626 self.bucket_stats = bucket_stats
627 else:
628 self.bucket_stats = []
629 return
630
631 def pack(self):
632 packed = []
633 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
634 packed.append('\x00' * 2)
635 packed.append(struct.pack("!L", self.group_id))
636 packed.append(struct.pack("!L", self.ref_count))
637 packed.append('\x00' * 4)
638 packed.append(struct.pack("!Q", self.packet_count))
639 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700640 packed.append(util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700641 length = sum([len(x) for x in packed])
642 packed[0] = struct.pack("!H", length)
643 return ''.join(packed)
644
645 @staticmethod
646 def unpack(buf):
647 obj = group_stats_entry()
648 if type(buf) == loxi.generic_util.OFReader:
649 reader = buf
650 else:
651 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700652 _length = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700653 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700654 obj.group_id = reader.read("!L")[0]
655 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700656 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700657 obj.packet_count = reader.read("!Q")[0]
658 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700659 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
660 return obj
661
662 def __eq__(self, other):
663 if type(self) != type(other): return False
664 if self.group_id != other.group_id: return False
665 if self.ref_count != other.ref_count: return False
666 if self.packet_count != other.packet_count: return False
667 if self.byte_count != other.byte_count: return False
668 if self.bucket_stats != other.bucket_stats: return False
669 return True
670
671 def __ne__(self, other):
672 return not self.__eq__(other)
673
674 def show(self):
675 import loxi.pp
676 return loxi.pp.pp(self)
677
678 def pretty_print(self, q):
679 q.text("group_stats_entry {")
680 with q.group():
681 with q.indent(2):
682 q.breakable()
683 q.text("group_id = ");
684 q.text("%#x" % self.group_id)
685 q.text(","); q.breakable()
686 q.text("ref_count = ");
687 q.text("%#x" % self.ref_count)
688 q.text(","); q.breakable()
689 q.text("packet_count = ");
690 q.text("%#x" % self.packet_count)
691 q.text(","); q.breakable()
692 q.text("byte_count = ");
693 q.text("%#x" % self.byte_count)
694 q.text(","); q.breakable()
695 q.text("bucket_stats = ");
696 q.pp(self.bucket_stats)
697 q.breakable()
698 q.text('}')
699
700class match_v2(object):
701 type = 0
702
703 def __init__(self, in_port=None, wildcards=None, eth_src=None, eth_src_mask=None, eth_dst=None, eth_dst_mask=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_src_mask=None, ipv4_dst=None, ipv4_dst_mask=None, tcp_src=None, tcp_dst=None, mpls_label=None, mpls_tc=None, metadata=None, metadata_mask=None):
704 if in_port != None:
705 self.in_port = in_port
706 else:
707 self.in_port = 0
708 if wildcards != None:
709 self.wildcards = wildcards
710 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700711 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700712 if eth_src != None:
713 self.eth_src = eth_src
714 else:
715 self.eth_src = [0,0,0,0,0,0]
716 if eth_src_mask != None:
717 self.eth_src_mask = eth_src_mask
718 else:
719 self.eth_src_mask = [0,0,0,0,0,0]
720 if eth_dst != None:
721 self.eth_dst = eth_dst
722 else:
723 self.eth_dst = [0,0,0,0,0,0]
724 if eth_dst_mask != None:
725 self.eth_dst_mask = eth_dst_mask
726 else:
727 self.eth_dst_mask = [0,0,0,0,0,0]
728 if vlan_vid != None:
729 self.vlan_vid = vlan_vid
730 else:
731 self.vlan_vid = 0
732 if vlan_pcp != None:
733 self.vlan_pcp = vlan_pcp
734 else:
735 self.vlan_pcp = 0
736 if eth_type != None:
737 self.eth_type = eth_type
738 else:
739 self.eth_type = 0
740 if ip_dscp != None:
741 self.ip_dscp = ip_dscp
742 else:
743 self.ip_dscp = 0
744 if ip_proto != None:
745 self.ip_proto = ip_proto
746 else:
747 self.ip_proto = 0
748 if ipv4_src != None:
749 self.ipv4_src = ipv4_src
750 else:
751 self.ipv4_src = 0
752 if ipv4_src_mask != None:
753 self.ipv4_src_mask = ipv4_src_mask
754 else:
755 self.ipv4_src_mask = 0
756 if ipv4_dst != None:
757 self.ipv4_dst = ipv4_dst
758 else:
759 self.ipv4_dst = 0
760 if ipv4_dst_mask != None:
761 self.ipv4_dst_mask = ipv4_dst_mask
762 else:
763 self.ipv4_dst_mask = 0
764 if tcp_src != None:
765 self.tcp_src = tcp_src
766 else:
767 self.tcp_src = 0
768 if tcp_dst != None:
769 self.tcp_dst = tcp_dst
770 else:
771 self.tcp_dst = 0
772 if mpls_label != None:
773 self.mpls_label = mpls_label
774 else:
775 self.mpls_label = 0
776 if mpls_tc != None:
777 self.mpls_tc = mpls_tc
778 else:
779 self.mpls_tc = 0
780 if metadata != None:
781 self.metadata = metadata
782 else:
783 self.metadata = 0
784 if metadata_mask != None:
785 self.metadata_mask = metadata_mask
786 else:
787 self.metadata_mask = 0
788 return
789
790 def pack(self):
791 packed = []
792 packed.append(struct.pack("!H", self.type))
793 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700794 packed.append(util.pack_port_no(self.in_port))
795 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700796 packed.append(struct.pack("!6B", *self.eth_src))
797 packed.append(struct.pack("!6B", *self.eth_src_mask))
798 packed.append(struct.pack("!6B", *self.eth_dst))
799 packed.append(struct.pack("!6B", *self.eth_dst_mask))
800 packed.append(struct.pack("!H", self.vlan_vid))
801 packed.append(struct.pack("!B", self.vlan_pcp))
802 packed.append('\x00' * 1)
803 packed.append(struct.pack("!H", self.eth_type))
804 packed.append(struct.pack("!B", self.ip_dscp))
805 packed.append(struct.pack("!B", self.ip_proto))
806 packed.append(struct.pack("!L", self.ipv4_src))
807 packed.append(struct.pack("!L", self.ipv4_src_mask))
808 packed.append(struct.pack("!L", self.ipv4_dst))
809 packed.append(struct.pack("!L", self.ipv4_dst_mask))
810 packed.append(struct.pack("!H", self.tcp_src))
811 packed.append(struct.pack("!H", self.tcp_dst))
812 packed.append(struct.pack("!L", self.mpls_label))
813 packed.append(struct.pack("!B", self.mpls_tc))
814 packed.append('\x00' * 3)
815 packed.append(struct.pack("!Q", self.metadata))
816 packed.append(struct.pack("!Q", self.metadata_mask))
817 length = sum([len(x) for x in packed])
818 packed[1] = struct.pack("!H", length)
819 return ''.join(packed)
820
821 @staticmethod
822 def unpack(buf):
823 obj = match_v2()
824 if type(buf) == loxi.generic_util.OFReader:
825 reader = buf
826 else:
827 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700828 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700829 assert(_type == 0)
Dan Talaycof6202252013-07-02 01:00:29 -0700830 _length = reader.read("!H")[0]
831 obj.in_port = util.unpack_port_no(reader)
832 obj.wildcards = util.unpack_wc_bmap(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700833 obj.eth_src = list(reader.read('!6B'))
834 obj.eth_src_mask = list(reader.read('!6B'))
835 obj.eth_dst = list(reader.read('!6B'))
836 obj.eth_dst_mask = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700837 obj.vlan_vid = reader.read("!H")[0]
838 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700839 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700840 obj.eth_type = reader.read("!H")[0]
841 obj.ip_dscp = reader.read("!B")[0]
842 obj.ip_proto = reader.read("!B")[0]
843 obj.ipv4_src = reader.read("!L")[0]
844 obj.ipv4_src_mask = reader.read("!L")[0]
845 obj.ipv4_dst = reader.read("!L")[0]
846 obj.ipv4_dst_mask = reader.read("!L")[0]
847 obj.tcp_src = reader.read("!H")[0]
848 obj.tcp_dst = reader.read("!H")[0]
849 obj.mpls_label = reader.read("!L")[0]
850 obj.mpls_tc = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700851 reader.skip(3)
Dan Talaycof6202252013-07-02 01:00:29 -0700852 obj.metadata = reader.read("!Q")[0]
853 obj.metadata_mask = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700854 return obj
855
856 def __eq__(self, other):
857 if type(self) != type(other): return False
858 if self.in_port != other.in_port: return False
859 if self.wildcards != other.wildcards: return False
860 if self.eth_src != other.eth_src: return False
861 if self.eth_src_mask != other.eth_src_mask: return False
862 if self.eth_dst != other.eth_dst: return False
863 if self.eth_dst_mask != other.eth_dst_mask: return False
864 if self.vlan_vid != other.vlan_vid: return False
865 if self.vlan_pcp != other.vlan_pcp: return False
866 if self.eth_type != other.eth_type: return False
867 if self.ip_dscp != other.ip_dscp: return False
868 if self.ip_proto != other.ip_proto: return False
869 if self.ipv4_src != other.ipv4_src: return False
870 if self.ipv4_src_mask != other.ipv4_src_mask: return False
871 if self.ipv4_dst != other.ipv4_dst: return False
872 if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
873 if self.tcp_src != other.tcp_src: return False
874 if self.tcp_dst != other.tcp_dst: return False
875 if self.mpls_label != other.mpls_label: return False
876 if self.mpls_tc != other.mpls_tc: return False
877 if self.metadata != other.metadata: return False
878 if self.metadata_mask != other.metadata_mask: return False
879 return True
880
881 def __ne__(self, other):
882 return not self.__eq__(other)
883
884 def show(self):
885 import loxi.pp
886 return loxi.pp.pp(self)
887
888 def pretty_print(self, q):
889 q.text("match_v2 {")
890 with q.group():
891 with q.indent(2):
892 q.breakable()
893 q.text("in_port = ");
894 q.text(util.pretty_port(self.in_port))
895 q.text(","); q.breakable()
896 q.text("wildcards = ");
897 q.text(util.pretty_wildcards(self.wildcards))
898 q.text(","); q.breakable()
899 q.text("eth_src = ");
900 q.text(util.pretty_mac(self.eth_src))
901 q.text(","); q.breakable()
902 q.text("eth_src_mask = ");
903 q.text(util.pretty_mac(self.eth_src_mask))
904 q.text(","); q.breakable()
905 q.text("eth_dst = ");
906 q.text(util.pretty_mac(self.eth_dst))
907 q.text(","); q.breakable()
908 q.text("eth_dst_mask = ");
909 q.text(util.pretty_mac(self.eth_dst_mask))
910 q.text(","); q.breakable()
911 q.text("vlan_vid = ");
912 q.text("%#x" % self.vlan_vid)
913 q.text(","); q.breakable()
914 q.text("vlan_pcp = ");
915 q.text("%#x" % self.vlan_pcp)
916 q.text(","); q.breakable()
917 q.text("eth_type = ");
918 q.text("%#x" % self.eth_type)
919 q.text(","); q.breakable()
920 q.text("ip_dscp = ");
921 q.text("%#x" % self.ip_dscp)
922 q.text(","); q.breakable()
923 q.text("ip_proto = ");
924 q.text("%#x" % self.ip_proto)
925 q.text(","); q.breakable()
926 q.text("ipv4_src = ");
927 q.text(util.pretty_ipv4(self.ipv4_src))
928 q.text(","); q.breakable()
929 q.text("ipv4_src_mask = ");
930 q.text(util.pretty_ipv4(self.ipv4_src_mask))
931 q.text(","); q.breakable()
932 q.text("ipv4_dst = ");
933 q.text(util.pretty_ipv4(self.ipv4_dst))
934 q.text(","); q.breakable()
935 q.text("ipv4_dst_mask = ");
936 q.text(util.pretty_ipv4(self.ipv4_dst_mask))
937 q.text(","); q.breakable()
938 q.text("tcp_src = ");
939 q.text("%#x" % self.tcp_src)
940 q.text(","); q.breakable()
941 q.text("tcp_dst = ");
942 q.text("%#x" % self.tcp_dst)
943 q.text(","); q.breakable()
944 q.text("mpls_label = ");
945 q.text("%#x" % self.mpls_label)
946 q.text(","); q.breakable()
947 q.text("mpls_tc = ");
948 q.text("%#x" % self.mpls_tc)
949 q.text(","); q.breakable()
950 q.text("metadata = ");
951 q.text("%#x" % self.metadata)
952 q.text(","); q.breakable()
953 q.text("metadata_mask = ");
954 q.text("%#x" % self.metadata_mask)
955 q.breakable()
956 q.text('}')
957
958class packet_queue(object):
959
960 def __init__(self, queue_id=None, properties=None):
961 if queue_id != None:
962 self.queue_id = queue_id
963 else:
964 self.queue_id = 0
965 if properties != None:
966 self.properties = properties
967 else:
968 self.properties = []
969 return
970
971 def pack(self):
972 packed = []
973 packed.append(struct.pack("!L", self.queue_id))
974 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
975 packed.append('\x00' * 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700976 packed.append(util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700977 length = sum([len(x) for x in packed])
978 packed[1] = struct.pack("!H", length)
979 return ''.join(packed)
980
981 @staticmethod
982 def unpack(buf):
983 obj = packet_queue()
984 if type(buf) == loxi.generic_util.OFReader:
985 reader = buf
986 else:
987 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700988 obj.queue_id = reader.read("!L")[0]
989 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700990 reader.skip(2)
991 obj.properties = common.unpack_list_queue_prop(reader)
992 return obj
993
994 def __eq__(self, other):
995 if type(self) != type(other): return False
996 if self.queue_id != other.queue_id: return False
997 if self.properties != other.properties: return False
998 return True
999
1000 def __ne__(self, other):
1001 return not self.__eq__(other)
1002
1003 def show(self):
1004 import loxi.pp
1005 return loxi.pp.pp(self)
1006
1007 def pretty_print(self, q):
1008 q.text("packet_queue {")
1009 with q.group():
1010 with q.indent(2):
1011 q.breakable()
1012 q.text("queue_id = ");
1013 q.text("%#x" % self.queue_id)
1014 q.text(","); q.breakable()
1015 q.text("properties = ");
1016 q.pp(self.properties)
1017 q.breakable()
1018 q.text('}')
1019
1020class port_desc(object):
1021
1022 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):
1023 if port_no != None:
1024 self.port_no = port_no
1025 else:
1026 self.port_no = 0
1027 if hw_addr != None:
1028 self.hw_addr = hw_addr
1029 else:
1030 self.hw_addr = [0,0,0,0,0,0]
1031 if name != None:
1032 self.name = name
1033 else:
1034 self.name = ""
1035 if config != None:
1036 self.config = config
1037 else:
1038 self.config = 0
1039 if state != None:
1040 self.state = state
1041 else:
1042 self.state = 0
1043 if curr != None:
1044 self.curr = curr
1045 else:
1046 self.curr = 0
1047 if advertised != None:
1048 self.advertised = advertised
1049 else:
1050 self.advertised = 0
1051 if supported != None:
1052 self.supported = supported
1053 else:
1054 self.supported = 0
1055 if peer != None:
1056 self.peer = peer
1057 else:
1058 self.peer = 0
1059 if curr_speed != None:
1060 self.curr_speed = curr_speed
1061 else:
1062 self.curr_speed = 0
1063 if max_speed != None:
1064 self.max_speed = max_speed
1065 else:
1066 self.max_speed = 0
1067 return
1068
1069 def pack(self):
1070 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001071 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001072 packed.append('\x00' * 4)
1073 packed.append(struct.pack("!6B", *self.hw_addr))
1074 packed.append('\x00' * 2)
1075 packed.append(struct.pack("!16s", self.name))
1076 packed.append(struct.pack("!L", self.config))
1077 packed.append(struct.pack("!L", self.state))
1078 packed.append(struct.pack("!L", self.curr))
1079 packed.append(struct.pack("!L", self.advertised))
1080 packed.append(struct.pack("!L", self.supported))
1081 packed.append(struct.pack("!L", self.peer))
1082 packed.append(struct.pack("!L", self.curr_speed))
1083 packed.append(struct.pack("!L", self.max_speed))
1084 return ''.join(packed)
1085
1086 @staticmethod
1087 def unpack(buf):
1088 obj = port_desc()
1089 if type(buf) == loxi.generic_util.OFReader:
1090 reader = buf
1091 else:
1092 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001093 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001094 reader.skip(4)
1095 obj.hw_addr = list(reader.read('!6B'))
1096 reader.skip(2)
1097 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001098 obj.config = reader.read("!L")[0]
1099 obj.state = reader.read("!L")[0]
1100 obj.curr = reader.read("!L")[0]
1101 obj.advertised = reader.read("!L")[0]
1102 obj.supported = reader.read("!L")[0]
1103 obj.peer = reader.read("!L")[0]
1104 obj.curr_speed = reader.read("!L")[0]
1105 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001106 return obj
1107
1108 def __eq__(self, other):
1109 if type(self) != type(other): return False
1110 if self.port_no != other.port_no: return False
1111 if self.hw_addr != other.hw_addr: return False
1112 if self.name != other.name: return False
1113 if self.config != other.config: return False
1114 if self.state != other.state: return False
1115 if self.curr != other.curr: return False
1116 if self.advertised != other.advertised: return False
1117 if self.supported != other.supported: return False
1118 if self.peer != other.peer: return False
1119 if self.curr_speed != other.curr_speed: return False
1120 if self.max_speed != other.max_speed: return False
1121 return True
1122
1123 def __ne__(self, other):
1124 return not self.__eq__(other)
1125
1126 def show(self):
1127 import loxi.pp
1128 return loxi.pp.pp(self)
1129
1130 def pretty_print(self, q):
1131 q.text("port_desc {")
1132 with q.group():
1133 with q.indent(2):
1134 q.breakable()
1135 q.text("port_no = ");
1136 q.text(util.pretty_port(self.port_no))
1137 q.text(","); q.breakable()
1138 q.text("hw_addr = ");
1139 q.text(util.pretty_mac(self.hw_addr))
1140 q.text(","); q.breakable()
1141 q.text("name = ");
1142 q.pp(self.name)
1143 q.text(","); q.breakable()
1144 q.text("config = ");
1145 q.text("%#x" % self.config)
1146 q.text(","); q.breakable()
1147 q.text("state = ");
1148 q.text("%#x" % self.state)
1149 q.text(","); q.breakable()
1150 q.text("curr = ");
1151 q.text("%#x" % self.curr)
1152 q.text(","); q.breakable()
1153 q.text("advertised = ");
1154 q.text("%#x" % self.advertised)
1155 q.text(","); q.breakable()
1156 q.text("supported = ");
1157 q.text("%#x" % self.supported)
1158 q.text(","); q.breakable()
1159 q.text("peer = ");
1160 q.text("%#x" % self.peer)
1161 q.text(","); q.breakable()
1162 q.text("curr_speed = ");
1163 q.text("%#x" % self.curr_speed)
1164 q.text(","); q.breakable()
1165 q.text("max_speed = ");
1166 q.text("%#x" % self.max_speed)
1167 q.breakable()
1168 q.text('}')
1169
1170class port_stats_entry(object):
1171
1172 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):
1173 if port_no != None:
1174 self.port_no = port_no
1175 else:
1176 self.port_no = 0
1177 if rx_packets != None:
1178 self.rx_packets = rx_packets
1179 else:
1180 self.rx_packets = 0
1181 if tx_packets != None:
1182 self.tx_packets = tx_packets
1183 else:
1184 self.tx_packets = 0
1185 if rx_bytes != None:
1186 self.rx_bytes = rx_bytes
1187 else:
1188 self.rx_bytes = 0
1189 if tx_bytes != None:
1190 self.tx_bytes = tx_bytes
1191 else:
1192 self.tx_bytes = 0
1193 if rx_dropped != None:
1194 self.rx_dropped = rx_dropped
1195 else:
1196 self.rx_dropped = 0
1197 if tx_dropped != None:
1198 self.tx_dropped = tx_dropped
1199 else:
1200 self.tx_dropped = 0
1201 if rx_errors != None:
1202 self.rx_errors = rx_errors
1203 else:
1204 self.rx_errors = 0
1205 if tx_errors != None:
1206 self.tx_errors = tx_errors
1207 else:
1208 self.tx_errors = 0
1209 if rx_frame_err != None:
1210 self.rx_frame_err = rx_frame_err
1211 else:
1212 self.rx_frame_err = 0
1213 if rx_over_err != None:
1214 self.rx_over_err = rx_over_err
1215 else:
1216 self.rx_over_err = 0
1217 if rx_crc_err != None:
1218 self.rx_crc_err = rx_crc_err
1219 else:
1220 self.rx_crc_err = 0
1221 if collisions != None:
1222 self.collisions = collisions
1223 else:
1224 self.collisions = 0
1225 return
1226
1227 def pack(self):
1228 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001229 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001230 packed.append('\x00' * 4)
1231 packed.append(struct.pack("!Q", self.rx_packets))
1232 packed.append(struct.pack("!Q", self.tx_packets))
1233 packed.append(struct.pack("!Q", self.rx_bytes))
1234 packed.append(struct.pack("!Q", self.tx_bytes))
1235 packed.append(struct.pack("!Q", self.rx_dropped))
1236 packed.append(struct.pack("!Q", self.tx_dropped))
1237 packed.append(struct.pack("!Q", self.rx_errors))
1238 packed.append(struct.pack("!Q", self.tx_errors))
1239 packed.append(struct.pack("!Q", self.rx_frame_err))
1240 packed.append(struct.pack("!Q", self.rx_over_err))
1241 packed.append(struct.pack("!Q", self.rx_crc_err))
1242 packed.append(struct.pack("!Q", self.collisions))
1243 return ''.join(packed)
1244
1245 @staticmethod
1246 def unpack(buf):
1247 obj = port_stats_entry()
1248 if type(buf) == loxi.generic_util.OFReader:
1249 reader = buf
1250 else:
1251 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001252 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001253 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001254 obj.rx_packets = reader.read("!Q")[0]
1255 obj.tx_packets = reader.read("!Q")[0]
1256 obj.rx_bytes = reader.read("!Q")[0]
1257 obj.tx_bytes = reader.read("!Q")[0]
1258 obj.rx_dropped = reader.read("!Q")[0]
1259 obj.tx_dropped = reader.read("!Q")[0]
1260 obj.rx_errors = reader.read("!Q")[0]
1261 obj.tx_errors = reader.read("!Q")[0]
1262 obj.rx_frame_err = reader.read("!Q")[0]
1263 obj.rx_over_err = reader.read("!Q")[0]
1264 obj.rx_crc_err = reader.read("!Q")[0]
1265 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001266 return obj
1267
1268 def __eq__(self, other):
1269 if type(self) != type(other): return False
1270 if self.port_no != other.port_no: return False
1271 if self.rx_packets != other.rx_packets: return False
1272 if self.tx_packets != other.tx_packets: return False
1273 if self.rx_bytes != other.rx_bytes: return False
1274 if self.tx_bytes != other.tx_bytes: return False
1275 if self.rx_dropped != other.rx_dropped: return False
1276 if self.tx_dropped != other.tx_dropped: return False
1277 if self.rx_errors != other.rx_errors: return False
1278 if self.tx_errors != other.tx_errors: return False
1279 if self.rx_frame_err != other.rx_frame_err: return False
1280 if self.rx_over_err != other.rx_over_err: return False
1281 if self.rx_crc_err != other.rx_crc_err: return False
1282 if self.collisions != other.collisions: return False
1283 return True
1284
1285 def __ne__(self, other):
1286 return not self.__eq__(other)
1287
1288 def show(self):
1289 import loxi.pp
1290 return loxi.pp.pp(self)
1291
1292 def pretty_print(self, q):
1293 q.text("port_stats_entry {")
1294 with q.group():
1295 with q.indent(2):
1296 q.breakable()
1297 q.text("port_no = ");
1298 q.text(util.pretty_port(self.port_no))
1299 q.text(","); q.breakable()
1300 q.text("rx_packets = ");
1301 q.text("%#x" % self.rx_packets)
1302 q.text(","); q.breakable()
1303 q.text("tx_packets = ");
1304 q.text("%#x" % self.tx_packets)
1305 q.text(","); q.breakable()
1306 q.text("rx_bytes = ");
1307 q.text("%#x" % self.rx_bytes)
1308 q.text(","); q.breakable()
1309 q.text("tx_bytes = ");
1310 q.text("%#x" % self.tx_bytes)
1311 q.text(","); q.breakable()
1312 q.text("rx_dropped = ");
1313 q.text("%#x" % self.rx_dropped)
1314 q.text(","); q.breakable()
1315 q.text("tx_dropped = ");
1316 q.text("%#x" % self.tx_dropped)
1317 q.text(","); q.breakable()
1318 q.text("rx_errors = ");
1319 q.text("%#x" % self.rx_errors)
1320 q.text(","); q.breakable()
1321 q.text("tx_errors = ");
1322 q.text("%#x" % self.tx_errors)
1323 q.text(","); q.breakable()
1324 q.text("rx_frame_err = ");
1325 q.text("%#x" % self.rx_frame_err)
1326 q.text(","); q.breakable()
1327 q.text("rx_over_err = ");
1328 q.text("%#x" % self.rx_over_err)
1329 q.text(","); q.breakable()
1330 q.text("rx_crc_err = ");
1331 q.text("%#x" % self.rx_crc_err)
1332 q.text(","); q.breakable()
1333 q.text("collisions = ");
1334 q.text("%#x" % self.collisions)
1335 q.breakable()
1336 q.text('}')
1337
1338class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001339 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001340
1341 def __init__(self, rate=None):
1342 if rate != None:
1343 self.rate = rate
1344 else:
1345 self.rate = 0
1346 return
1347
1348 def pack(self):
1349 packed = []
1350 packed.append(struct.pack("!H", self.type))
1351 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1352 packed.append('\x00' * 4)
1353 packed.append(struct.pack("!H", self.rate))
1354 packed.append('\x00' * 6)
1355 length = sum([len(x) for x in packed])
1356 packed[1] = struct.pack("!H", length)
1357 return ''.join(packed)
1358
1359 @staticmethod
1360 def unpack(buf):
1361 obj = queue_prop_min_rate()
1362 if type(buf) == loxi.generic_util.OFReader:
1363 reader = buf
1364 else:
1365 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001366 _type = reader.read("!H")[0]
1367 assert(_type == 1)
1368 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001369 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001370 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001371 reader.skip(6)
1372 return obj
1373
1374 def __eq__(self, other):
1375 if type(self) != type(other): return False
1376 if self.rate != other.rate: 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_prop_min_rate {")
1388 with q.group():
1389 with q.indent(2):
1390 q.breakable()
1391 q.text("rate = ");
1392 q.text("%#x" % self.rate)
1393 q.breakable()
1394 q.text('}')
1395
1396class queue_stats_entry(object):
1397
1398 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1399 if port_no != None:
1400 self.port_no = port_no
1401 else:
1402 self.port_no = 0
1403 if queue_id != None:
1404 self.queue_id = queue_id
1405 else:
1406 self.queue_id = 0
1407 if tx_bytes != None:
1408 self.tx_bytes = tx_bytes
1409 else:
1410 self.tx_bytes = 0
1411 if tx_packets != None:
1412 self.tx_packets = tx_packets
1413 else:
1414 self.tx_packets = 0
1415 if tx_errors != None:
1416 self.tx_errors = tx_errors
1417 else:
1418 self.tx_errors = 0
1419 return
1420
1421 def pack(self):
1422 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001423 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001424 packed.append(struct.pack("!L", self.queue_id))
1425 packed.append(struct.pack("!Q", self.tx_bytes))
1426 packed.append(struct.pack("!Q", self.tx_packets))
1427 packed.append(struct.pack("!Q", self.tx_errors))
1428 return ''.join(packed)
1429
1430 @staticmethod
1431 def unpack(buf):
1432 obj = queue_stats_entry()
1433 if type(buf) == loxi.generic_util.OFReader:
1434 reader = buf
1435 else:
1436 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001437 obj.port_no = util.unpack_port_no(reader)
1438 obj.queue_id = reader.read("!L")[0]
1439 obj.tx_bytes = reader.read("!Q")[0]
1440 obj.tx_packets = reader.read("!Q")[0]
1441 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001442 return obj
1443
1444 def __eq__(self, other):
1445 if type(self) != type(other): return False
1446 if self.port_no != other.port_no: return False
1447 if self.queue_id != other.queue_id: return False
1448 if self.tx_bytes != other.tx_bytes: return False
1449 if self.tx_packets != other.tx_packets: return False
1450 if self.tx_errors != other.tx_errors: return False
1451 return True
1452
1453 def __ne__(self, other):
1454 return not self.__eq__(other)
1455
1456 def show(self):
1457 import loxi.pp
1458 return loxi.pp.pp(self)
1459
1460 def pretty_print(self, q):
1461 q.text("queue_stats_entry {")
1462 with q.group():
1463 with q.indent(2):
1464 q.breakable()
1465 q.text("port_no = ");
1466 q.text(util.pretty_port(self.port_no))
1467 q.text(","); q.breakable()
1468 q.text("queue_id = ");
1469 q.text("%#x" % self.queue_id)
1470 q.text(","); q.breakable()
1471 q.text("tx_bytes = ");
1472 q.text("%#x" % self.tx_bytes)
1473 q.text(","); q.breakable()
1474 q.text("tx_packets = ");
1475 q.text("%#x" % self.tx_packets)
1476 q.text(","); q.breakable()
1477 q.text("tx_errors = ");
1478 q.text("%#x" % self.tx_errors)
1479 q.breakable()
1480 q.text('}')
1481
1482class table_stats_entry(object):
1483
1484 def __init__(self, table_id=None, name=None, wildcards=None, match=None, instructions=None, write_actions=None, apply_actions=None, config=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
1485 if table_id != None:
1486 self.table_id = table_id
1487 else:
1488 self.table_id = 0
1489 if name != None:
1490 self.name = name
1491 else:
1492 self.name = ""
1493 if wildcards != None:
1494 self.wildcards = wildcards
1495 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001496 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001497 if match != None:
1498 self.match = match
1499 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001500 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001501 if instructions != None:
1502 self.instructions = instructions
1503 else:
1504 self.instructions = 0
1505 if write_actions != None:
1506 self.write_actions = write_actions
1507 else:
1508 self.write_actions = 0
1509 if apply_actions != None:
1510 self.apply_actions = apply_actions
1511 else:
1512 self.apply_actions = 0
1513 if config != None:
1514 self.config = config
1515 else:
1516 self.config = 0
1517 if max_entries != None:
1518 self.max_entries = max_entries
1519 else:
1520 self.max_entries = 0
1521 if active_count != None:
1522 self.active_count = active_count
1523 else:
1524 self.active_count = 0
1525 if lookup_count != None:
1526 self.lookup_count = lookup_count
1527 else:
1528 self.lookup_count = 0
1529 if matched_count != None:
1530 self.matched_count = matched_count
1531 else:
1532 self.matched_count = 0
1533 return
1534
1535 def pack(self):
1536 packed = []
1537 packed.append(struct.pack("!B", self.table_id))
1538 packed.append('\x00' * 7)
1539 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001540 packed.append(util.pack_wc_bmap(self.wildcards))
1541 packed.append(util.pack_match_bmap(self.match))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001542 packed.append(struct.pack("!L", self.instructions))
1543 packed.append(struct.pack("!L", self.write_actions))
1544 packed.append(struct.pack("!L", self.apply_actions))
1545 packed.append(struct.pack("!L", self.config))
1546 packed.append(struct.pack("!L", self.max_entries))
1547 packed.append(struct.pack("!L", self.active_count))
1548 packed.append(struct.pack("!Q", self.lookup_count))
1549 packed.append(struct.pack("!Q", self.matched_count))
1550 return ''.join(packed)
1551
1552 @staticmethod
1553 def unpack(buf):
1554 obj = table_stats_entry()
1555 if type(buf) == loxi.generic_util.OFReader:
1556 reader = buf
1557 else:
1558 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001559 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001560 reader.skip(7)
1561 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001562 obj.wildcards = util.unpack_wc_bmap(reader)
1563 obj.match = util.unpack_match_bmap(reader)
1564 obj.instructions = reader.read("!L")[0]
1565 obj.write_actions = reader.read("!L")[0]
1566 obj.apply_actions = reader.read("!L")[0]
1567 obj.config = reader.read("!L")[0]
1568 obj.max_entries = reader.read("!L")[0]
1569 obj.active_count = reader.read("!L")[0]
1570 obj.lookup_count = reader.read("!Q")[0]
1571 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001572 return obj
1573
1574 def __eq__(self, other):
1575 if type(self) != type(other): return False
1576 if self.table_id != other.table_id: return False
1577 if self.name != other.name: return False
1578 if self.wildcards != other.wildcards: return False
1579 if self.match != other.match: return False
1580 if self.instructions != other.instructions: return False
1581 if self.write_actions != other.write_actions: return False
1582 if self.apply_actions != other.apply_actions: return False
1583 if self.config != other.config: return False
1584 if self.max_entries != other.max_entries: return False
1585 if self.active_count != other.active_count: return False
1586 if self.lookup_count != other.lookup_count: return False
1587 if self.matched_count != other.matched_count: return False
1588 return True
1589
1590 def __ne__(self, other):
1591 return not self.__eq__(other)
1592
1593 def show(self):
1594 import loxi.pp
1595 return loxi.pp.pp(self)
1596
1597 def pretty_print(self, q):
1598 q.text("table_stats_entry {")
1599 with q.group():
1600 with q.indent(2):
1601 q.breakable()
1602 q.text("table_id = ");
1603 q.text("%#x" % self.table_id)
1604 q.text(","); q.breakable()
1605 q.text("name = ");
1606 q.pp(self.name)
1607 q.text(","); q.breakable()
1608 q.text("wildcards = ");
1609 q.text(util.pretty_wildcards(self.wildcards))
1610 q.text(","); q.breakable()
1611 q.text("match = ");
1612 q.pp(self.match)
1613 q.text(","); q.breakable()
1614 q.text("instructions = ");
1615 q.text("%#x" % self.instructions)
1616 q.text(","); q.breakable()
1617 q.text("write_actions = ");
1618 q.text("%#x" % self.write_actions)
1619 q.text(","); q.breakable()
1620 q.text("apply_actions = ");
1621 q.text("%#x" % self.apply_actions)
1622 q.text(","); q.breakable()
1623 q.text("config = ");
1624 q.text("%#x" % self.config)
1625 q.text(","); q.breakable()
1626 q.text("max_entries = ");
1627 q.text("%#x" % self.max_entries)
1628 q.text(","); q.breakable()
1629 q.text("active_count = ");
1630 q.text("%#x" % self.active_count)
1631 q.text(","); q.breakable()
1632 q.text("lookup_count = ");
1633 q.text("%#x" % self.lookup_count)
1634 q.text(","); q.breakable()
1635 q.text("matched_count = ");
1636 q.text("%#x" % self.matched_count)
1637 q.breakable()
1638 q.text('}')
1639
1640
1641match = match_v2