blob: c264e65c8e988422472f7e91c431919cacdcc510 [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2# Copyright (c) 2011, 2012 Open Networking Foundation
3# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
Dan Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Lanec2ee4b82013-04-24 17:12:38 -07005
6# Automatically generated by LOXI from template common.py
7# Do not modify
8
9import sys
10import struct
11import action
12import instruction # for unpack_list
13import const
14import util
15import loxi.generic_util
16
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_v2(object):
702 type = 0
703
704 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):
705 if in_port != None:
706 self.in_port = in_port
707 else:
708 self.in_port = 0
709 if wildcards != None:
710 self.wildcards = wildcards
711 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700712 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700713 if eth_src != None:
714 self.eth_src = eth_src
715 else:
716 self.eth_src = [0,0,0,0,0,0]
717 if eth_src_mask != None:
718 self.eth_src_mask = eth_src_mask
719 else:
720 self.eth_src_mask = [0,0,0,0,0,0]
721 if eth_dst != None:
722 self.eth_dst = eth_dst
723 else:
724 self.eth_dst = [0,0,0,0,0,0]
725 if eth_dst_mask != None:
726 self.eth_dst_mask = eth_dst_mask
727 else:
728 self.eth_dst_mask = [0,0,0,0,0,0]
729 if vlan_vid != None:
730 self.vlan_vid = vlan_vid
731 else:
732 self.vlan_vid = 0
733 if vlan_pcp != None:
734 self.vlan_pcp = vlan_pcp
735 else:
736 self.vlan_pcp = 0
737 if eth_type != None:
738 self.eth_type = eth_type
739 else:
740 self.eth_type = 0
741 if ip_dscp != None:
742 self.ip_dscp = ip_dscp
743 else:
744 self.ip_dscp = 0
745 if ip_proto != None:
746 self.ip_proto = ip_proto
747 else:
748 self.ip_proto = 0
749 if ipv4_src != None:
750 self.ipv4_src = ipv4_src
751 else:
752 self.ipv4_src = 0
753 if ipv4_src_mask != None:
754 self.ipv4_src_mask = ipv4_src_mask
755 else:
756 self.ipv4_src_mask = 0
757 if ipv4_dst != None:
758 self.ipv4_dst = ipv4_dst
759 else:
760 self.ipv4_dst = 0
761 if ipv4_dst_mask != None:
762 self.ipv4_dst_mask = ipv4_dst_mask
763 else:
764 self.ipv4_dst_mask = 0
765 if tcp_src != None:
766 self.tcp_src = tcp_src
767 else:
768 self.tcp_src = 0
769 if tcp_dst != None:
770 self.tcp_dst = tcp_dst
771 else:
772 self.tcp_dst = 0
773 if mpls_label != None:
774 self.mpls_label = mpls_label
775 else:
776 self.mpls_label = 0
777 if mpls_tc != None:
778 self.mpls_tc = mpls_tc
779 else:
780 self.mpls_tc = 0
781 if metadata != None:
782 self.metadata = metadata
783 else:
784 self.metadata = 0
785 if metadata_mask != None:
786 self.metadata_mask = metadata_mask
787 else:
788 self.metadata_mask = 0
789 return
790
791 def pack(self):
792 packed = []
793 packed.append(struct.pack("!H", self.type))
794 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700795 packed.append(util.pack_port_no(self.in_port))
796 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700797 packed.append(struct.pack("!6B", *self.eth_src))
798 packed.append(struct.pack("!6B", *self.eth_src_mask))
799 packed.append(struct.pack("!6B", *self.eth_dst))
800 packed.append(struct.pack("!6B", *self.eth_dst_mask))
801 packed.append(struct.pack("!H", self.vlan_vid))
802 packed.append(struct.pack("!B", self.vlan_pcp))
803 packed.append('\x00' * 1)
804 packed.append(struct.pack("!H", self.eth_type))
805 packed.append(struct.pack("!B", self.ip_dscp))
806 packed.append(struct.pack("!B", self.ip_proto))
807 packed.append(struct.pack("!L", self.ipv4_src))
808 packed.append(struct.pack("!L", self.ipv4_src_mask))
809 packed.append(struct.pack("!L", self.ipv4_dst))
810 packed.append(struct.pack("!L", self.ipv4_dst_mask))
811 packed.append(struct.pack("!H", self.tcp_src))
812 packed.append(struct.pack("!H", self.tcp_dst))
813 packed.append(struct.pack("!L", self.mpls_label))
814 packed.append(struct.pack("!B", self.mpls_tc))
815 packed.append('\x00' * 3)
816 packed.append(struct.pack("!Q", self.metadata))
817 packed.append(struct.pack("!Q", self.metadata_mask))
818 length = sum([len(x) for x in packed])
819 packed[1] = struct.pack("!H", length)
820 return ''.join(packed)
821
822 @staticmethod
823 def unpack(buf):
824 obj = match_v2()
825 if type(buf) == loxi.generic_util.OFReader:
826 reader = buf
827 else:
828 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700829 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700830 assert(_type == 0)
Dan Talaycof6202252013-07-02 01:00:29 -0700831 _length = reader.read("!H")[0]
832 obj.in_port = util.unpack_port_no(reader)
833 obj.wildcards = util.unpack_wc_bmap(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700834 obj.eth_src = list(reader.read('!6B'))
835 obj.eth_src_mask = list(reader.read('!6B'))
836 obj.eth_dst = list(reader.read('!6B'))
837 obj.eth_dst_mask = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700838 obj.vlan_vid = reader.read("!H")[0]
839 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700840 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700841 obj.eth_type = reader.read("!H")[0]
842 obj.ip_dscp = reader.read("!B")[0]
843 obj.ip_proto = reader.read("!B")[0]
844 obj.ipv4_src = reader.read("!L")[0]
845 obj.ipv4_src_mask = reader.read("!L")[0]
846 obj.ipv4_dst = reader.read("!L")[0]
847 obj.ipv4_dst_mask = reader.read("!L")[0]
848 obj.tcp_src = reader.read("!H")[0]
849 obj.tcp_dst = reader.read("!H")[0]
850 obj.mpls_label = reader.read("!L")[0]
851 obj.mpls_tc = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700852 reader.skip(3)
Dan Talaycof6202252013-07-02 01:00:29 -0700853 obj.metadata = reader.read("!Q")[0]
854 obj.metadata_mask = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700855 return obj
856
857 def __eq__(self, other):
858 if type(self) != type(other): return False
859 if self.in_port != other.in_port: return False
860 if self.wildcards != other.wildcards: return False
861 if self.eth_src != other.eth_src: return False
862 if self.eth_src_mask != other.eth_src_mask: return False
863 if self.eth_dst != other.eth_dst: return False
864 if self.eth_dst_mask != other.eth_dst_mask: return False
865 if self.vlan_vid != other.vlan_vid: return False
866 if self.vlan_pcp != other.vlan_pcp: return False
867 if self.eth_type != other.eth_type: return False
868 if self.ip_dscp != other.ip_dscp: return False
869 if self.ip_proto != other.ip_proto: return False
870 if self.ipv4_src != other.ipv4_src: return False
871 if self.ipv4_src_mask != other.ipv4_src_mask: return False
872 if self.ipv4_dst != other.ipv4_dst: return False
873 if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
874 if self.tcp_src != other.tcp_src: return False
875 if self.tcp_dst != other.tcp_dst: return False
876 if self.mpls_label != other.mpls_label: return False
877 if self.mpls_tc != other.mpls_tc: return False
878 if self.metadata != other.metadata: return False
879 if self.metadata_mask != other.metadata_mask: return False
880 return True
881
882 def __ne__(self, other):
883 return not self.__eq__(other)
884
885 def show(self):
886 import loxi.pp
887 return loxi.pp.pp(self)
888
889 def pretty_print(self, q):
890 q.text("match_v2 {")
891 with q.group():
892 with q.indent(2):
893 q.breakable()
894 q.text("in_port = ");
895 q.text(util.pretty_port(self.in_port))
896 q.text(","); q.breakable()
897 q.text("wildcards = ");
898 q.text(util.pretty_wildcards(self.wildcards))
899 q.text(","); q.breakable()
900 q.text("eth_src = ");
901 q.text(util.pretty_mac(self.eth_src))
902 q.text(","); q.breakable()
903 q.text("eth_src_mask = ");
904 q.text(util.pretty_mac(self.eth_src_mask))
905 q.text(","); q.breakable()
906 q.text("eth_dst = ");
907 q.text(util.pretty_mac(self.eth_dst))
908 q.text(","); q.breakable()
909 q.text("eth_dst_mask = ");
910 q.text(util.pretty_mac(self.eth_dst_mask))
911 q.text(","); q.breakable()
912 q.text("vlan_vid = ");
913 q.text("%#x" % self.vlan_vid)
914 q.text(","); q.breakable()
915 q.text("vlan_pcp = ");
916 q.text("%#x" % self.vlan_pcp)
917 q.text(","); q.breakable()
918 q.text("eth_type = ");
919 q.text("%#x" % self.eth_type)
920 q.text(","); q.breakable()
921 q.text("ip_dscp = ");
922 q.text("%#x" % self.ip_dscp)
923 q.text(","); q.breakable()
924 q.text("ip_proto = ");
925 q.text("%#x" % self.ip_proto)
926 q.text(","); q.breakable()
927 q.text("ipv4_src = ");
928 q.text(util.pretty_ipv4(self.ipv4_src))
929 q.text(","); q.breakable()
930 q.text("ipv4_src_mask = ");
931 q.text(util.pretty_ipv4(self.ipv4_src_mask))
932 q.text(","); q.breakable()
933 q.text("ipv4_dst = ");
934 q.text(util.pretty_ipv4(self.ipv4_dst))
935 q.text(","); q.breakable()
936 q.text("ipv4_dst_mask = ");
937 q.text(util.pretty_ipv4(self.ipv4_dst_mask))
938 q.text(","); q.breakable()
939 q.text("tcp_src = ");
940 q.text("%#x" % self.tcp_src)
941 q.text(","); q.breakable()
942 q.text("tcp_dst = ");
943 q.text("%#x" % self.tcp_dst)
944 q.text(","); q.breakable()
945 q.text("mpls_label = ");
946 q.text("%#x" % self.mpls_label)
947 q.text(","); q.breakable()
948 q.text("mpls_tc = ");
949 q.text("%#x" % self.mpls_tc)
950 q.text(","); q.breakable()
951 q.text("metadata = ");
952 q.text("%#x" % self.metadata)
953 q.text(","); q.breakable()
954 q.text("metadata_mask = ");
955 q.text("%#x" % self.metadata_mask)
956 q.breakable()
957 q.text('}')
958
959class packet_queue(object):
960
961 def __init__(self, queue_id=None, properties=None):
962 if queue_id != None:
963 self.queue_id = queue_id
964 else:
965 self.queue_id = 0
966 if properties != None:
967 self.properties = properties
968 else:
969 self.properties = []
970 return
971
972 def pack(self):
973 packed = []
974 packed.append(struct.pack("!L", self.queue_id))
975 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
976 packed.append('\x00' * 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700977 packed.append(util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700978 length = sum([len(x) for x in packed])
979 packed[1] = struct.pack("!H", length)
980 return ''.join(packed)
981
982 @staticmethod
983 def unpack(buf):
984 obj = packet_queue()
985 if type(buf) == loxi.generic_util.OFReader:
986 reader = buf
987 else:
988 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700989 obj.queue_id = reader.read("!L")[0]
990 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700991 reader.skip(2)
992 obj.properties = common.unpack_list_queue_prop(reader)
993 return obj
994
995 def __eq__(self, other):
996 if type(self) != type(other): return False
997 if self.queue_id != other.queue_id: return False
998 if self.properties != other.properties: return False
999 return True
1000
1001 def __ne__(self, other):
1002 return not self.__eq__(other)
1003
1004 def show(self):
1005 import loxi.pp
1006 return loxi.pp.pp(self)
1007
1008 def pretty_print(self, q):
1009 q.text("packet_queue {")
1010 with q.group():
1011 with q.indent(2):
1012 q.breakable()
1013 q.text("queue_id = ");
1014 q.text("%#x" % self.queue_id)
1015 q.text(","); q.breakable()
1016 q.text("properties = ");
1017 q.pp(self.properties)
1018 q.breakable()
1019 q.text('}')
1020
1021class port_desc(object):
1022
1023 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):
1024 if port_no != None:
1025 self.port_no = port_no
1026 else:
1027 self.port_no = 0
1028 if hw_addr != None:
1029 self.hw_addr = hw_addr
1030 else:
1031 self.hw_addr = [0,0,0,0,0,0]
1032 if name != None:
1033 self.name = name
1034 else:
1035 self.name = ""
1036 if config != None:
1037 self.config = config
1038 else:
1039 self.config = 0
1040 if state != None:
1041 self.state = state
1042 else:
1043 self.state = 0
1044 if curr != None:
1045 self.curr = curr
1046 else:
1047 self.curr = 0
1048 if advertised != None:
1049 self.advertised = advertised
1050 else:
1051 self.advertised = 0
1052 if supported != None:
1053 self.supported = supported
1054 else:
1055 self.supported = 0
1056 if peer != None:
1057 self.peer = peer
1058 else:
1059 self.peer = 0
1060 if curr_speed != None:
1061 self.curr_speed = curr_speed
1062 else:
1063 self.curr_speed = 0
1064 if max_speed != None:
1065 self.max_speed = max_speed
1066 else:
1067 self.max_speed = 0
1068 return
1069
1070 def pack(self):
1071 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001072 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001073 packed.append('\x00' * 4)
1074 packed.append(struct.pack("!6B", *self.hw_addr))
1075 packed.append('\x00' * 2)
1076 packed.append(struct.pack("!16s", self.name))
1077 packed.append(struct.pack("!L", self.config))
1078 packed.append(struct.pack("!L", self.state))
1079 packed.append(struct.pack("!L", self.curr))
1080 packed.append(struct.pack("!L", self.advertised))
1081 packed.append(struct.pack("!L", self.supported))
1082 packed.append(struct.pack("!L", self.peer))
1083 packed.append(struct.pack("!L", self.curr_speed))
1084 packed.append(struct.pack("!L", self.max_speed))
1085 return ''.join(packed)
1086
1087 @staticmethod
1088 def unpack(buf):
1089 obj = port_desc()
1090 if type(buf) == loxi.generic_util.OFReader:
1091 reader = buf
1092 else:
1093 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001094 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001095 reader.skip(4)
1096 obj.hw_addr = list(reader.read('!6B'))
1097 reader.skip(2)
1098 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001099 obj.config = reader.read("!L")[0]
1100 obj.state = reader.read("!L")[0]
1101 obj.curr = reader.read("!L")[0]
1102 obj.advertised = reader.read("!L")[0]
1103 obj.supported = reader.read("!L")[0]
1104 obj.peer = reader.read("!L")[0]
1105 obj.curr_speed = reader.read("!L")[0]
1106 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001107 return obj
1108
1109 def __eq__(self, other):
1110 if type(self) != type(other): return False
1111 if self.port_no != other.port_no: return False
1112 if self.hw_addr != other.hw_addr: return False
1113 if self.name != other.name: return False
1114 if self.config != other.config: return False
1115 if self.state != other.state: return False
1116 if self.curr != other.curr: return False
1117 if self.advertised != other.advertised: return False
1118 if self.supported != other.supported: return False
1119 if self.peer != other.peer: return False
1120 if self.curr_speed != other.curr_speed: return False
1121 if self.max_speed != other.max_speed: return False
1122 return True
1123
1124 def __ne__(self, other):
1125 return not self.__eq__(other)
1126
1127 def show(self):
1128 import loxi.pp
1129 return loxi.pp.pp(self)
1130
1131 def pretty_print(self, q):
1132 q.text("port_desc {")
1133 with q.group():
1134 with q.indent(2):
1135 q.breakable()
1136 q.text("port_no = ");
1137 q.text(util.pretty_port(self.port_no))
1138 q.text(","); q.breakable()
1139 q.text("hw_addr = ");
1140 q.text(util.pretty_mac(self.hw_addr))
1141 q.text(","); q.breakable()
1142 q.text("name = ");
1143 q.pp(self.name)
1144 q.text(","); q.breakable()
1145 q.text("config = ");
1146 q.text("%#x" % self.config)
1147 q.text(","); q.breakable()
1148 q.text("state = ");
1149 q.text("%#x" % self.state)
1150 q.text(","); q.breakable()
1151 q.text("curr = ");
1152 q.text("%#x" % self.curr)
1153 q.text(","); q.breakable()
1154 q.text("advertised = ");
1155 q.text("%#x" % self.advertised)
1156 q.text(","); q.breakable()
1157 q.text("supported = ");
1158 q.text("%#x" % self.supported)
1159 q.text(","); q.breakable()
1160 q.text("peer = ");
1161 q.text("%#x" % self.peer)
1162 q.text(","); q.breakable()
1163 q.text("curr_speed = ");
1164 q.text("%#x" % self.curr_speed)
1165 q.text(","); q.breakable()
1166 q.text("max_speed = ");
1167 q.text("%#x" % self.max_speed)
1168 q.breakable()
1169 q.text('}')
1170
1171class port_stats_entry(object):
1172
1173 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):
1174 if port_no != None:
1175 self.port_no = port_no
1176 else:
1177 self.port_no = 0
1178 if rx_packets != None:
1179 self.rx_packets = rx_packets
1180 else:
1181 self.rx_packets = 0
1182 if tx_packets != None:
1183 self.tx_packets = tx_packets
1184 else:
1185 self.tx_packets = 0
1186 if rx_bytes != None:
1187 self.rx_bytes = rx_bytes
1188 else:
1189 self.rx_bytes = 0
1190 if tx_bytes != None:
1191 self.tx_bytes = tx_bytes
1192 else:
1193 self.tx_bytes = 0
1194 if rx_dropped != None:
1195 self.rx_dropped = rx_dropped
1196 else:
1197 self.rx_dropped = 0
1198 if tx_dropped != None:
1199 self.tx_dropped = tx_dropped
1200 else:
1201 self.tx_dropped = 0
1202 if rx_errors != None:
1203 self.rx_errors = rx_errors
1204 else:
1205 self.rx_errors = 0
1206 if tx_errors != None:
1207 self.tx_errors = tx_errors
1208 else:
1209 self.tx_errors = 0
1210 if rx_frame_err != None:
1211 self.rx_frame_err = rx_frame_err
1212 else:
1213 self.rx_frame_err = 0
1214 if rx_over_err != None:
1215 self.rx_over_err = rx_over_err
1216 else:
1217 self.rx_over_err = 0
1218 if rx_crc_err != None:
1219 self.rx_crc_err = rx_crc_err
1220 else:
1221 self.rx_crc_err = 0
1222 if collisions != None:
1223 self.collisions = collisions
1224 else:
1225 self.collisions = 0
1226 return
1227
1228 def pack(self):
1229 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001230 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001231 packed.append('\x00' * 4)
1232 packed.append(struct.pack("!Q", self.rx_packets))
1233 packed.append(struct.pack("!Q", self.tx_packets))
1234 packed.append(struct.pack("!Q", self.rx_bytes))
1235 packed.append(struct.pack("!Q", self.tx_bytes))
1236 packed.append(struct.pack("!Q", self.rx_dropped))
1237 packed.append(struct.pack("!Q", self.tx_dropped))
1238 packed.append(struct.pack("!Q", self.rx_errors))
1239 packed.append(struct.pack("!Q", self.tx_errors))
1240 packed.append(struct.pack("!Q", self.rx_frame_err))
1241 packed.append(struct.pack("!Q", self.rx_over_err))
1242 packed.append(struct.pack("!Q", self.rx_crc_err))
1243 packed.append(struct.pack("!Q", self.collisions))
1244 return ''.join(packed)
1245
1246 @staticmethod
1247 def unpack(buf):
1248 obj = port_stats_entry()
1249 if type(buf) == loxi.generic_util.OFReader:
1250 reader = buf
1251 else:
1252 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001253 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001254 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001255 obj.rx_packets = reader.read("!Q")[0]
1256 obj.tx_packets = reader.read("!Q")[0]
1257 obj.rx_bytes = reader.read("!Q")[0]
1258 obj.tx_bytes = reader.read("!Q")[0]
1259 obj.rx_dropped = reader.read("!Q")[0]
1260 obj.tx_dropped = reader.read("!Q")[0]
1261 obj.rx_errors = reader.read("!Q")[0]
1262 obj.tx_errors = reader.read("!Q")[0]
1263 obj.rx_frame_err = reader.read("!Q")[0]
1264 obj.rx_over_err = reader.read("!Q")[0]
1265 obj.rx_crc_err = reader.read("!Q")[0]
1266 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001267 return obj
1268
1269 def __eq__(self, other):
1270 if type(self) != type(other): return False
1271 if self.port_no != other.port_no: return False
1272 if self.rx_packets != other.rx_packets: return False
1273 if self.tx_packets != other.tx_packets: return False
1274 if self.rx_bytes != other.rx_bytes: return False
1275 if self.tx_bytes != other.tx_bytes: return False
1276 if self.rx_dropped != other.rx_dropped: return False
1277 if self.tx_dropped != other.tx_dropped: return False
1278 if self.rx_errors != other.rx_errors: return False
1279 if self.tx_errors != other.tx_errors: return False
1280 if self.rx_frame_err != other.rx_frame_err: return False
1281 if self.rx_over_err != other.rx_over_err: return False
1282 if self.rx_crc_err != other.rx_crc_err: return False
1283 if self.collisions != other.collisions: return False
1284 return True
1285
1286 def __ne__(self, other):
1287 return not self.__eq__(other)
1288
1289 def show(self):
1290 import loxi.pp
1291 return loxi.pp.pp(self)
1292
1293 def pretty_print(self, q):
1294 q.text("port_stats_entry {")
1295 with q.group():
1296 with q.indent(2):
1297 q.breakable()
1298 q.text("port_no = ");
1299 q.text(util.pretty_port(self.port_no))
1300 q.text(","); q.breakable()
1301 q.text("rx_packets = ");
1302 q.text("%#x" % self.rx_packets)
1303 q.text(","); q.breakable()
1304 q.text("tx_packets = ");
1305 q.text("%#x" % self.tx_packets)
1306 q.text(","); q.breakable()
1307 q.text("rx_bytes = ");
1308 q.text("%#x" % self.rx_bytes)
1309 q.text(","); q.breakable()
1310 q.text("tx_bytes = ");
1311 q.text("%#x" % self.tx_bytes)
1312 q.text(","); q.breakable()
1313 q.text("rx_dropped = ");
1314 q.text("%#x" % self.rx_dropped)
1315 q.text(","); q.breakable()
1316 q.text("tx_dropped = ");
1317 q.text("%#x" % self.tx_dropped)
1318 q.text(","); q.breakable()
1319 q.text("rx_errors = ");
1320 q.text("%#x" % self.rx_errors)
1321 q.text(","); q.breakable()
1322 q.text("tx_errors = ");
1323 q.text("%#x" % self.tx_errors)
1324 q.text(","); q.breakable()
1325 q.text("rx_frame_err = ");
1326 q.text("%#x" % self.rx_frame_err)
1327 q.text(","); q.breakable()
1328 q.text("rx_over_err = ");
1329 q.text("%#x" % self.rx_over_err)
1330 q.text(","); q.breakable()
1331 q.text("rx_crc_err = ");
1332 q.text("%#x" % self.rx_crc_err)
1333 q.text(","); q.breakable()
1334 q.text("collisions = ");
1335 q.text("%#x" % self.collisions)
1336 q.breakable()
1337 q.text('}')
1338
1339class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -07001340 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001341
1342 def __init__(self, rate=None):
1343 if rate != None:
1344 self.rate = rate
1345 else:
1346 self.rate = 0
1347 return
1348
1349 def pack(self):
1350 packed = []
1351 packed.append(struct.pack("!H", self.type))
1352 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1353 packed.append('\x00' * 4)
1354 packed.append(struct.pack("!H", self.rate))
1355 packed.append('\x00' * 6)
1356 length = sum([len(x) for x in packed])
1357 packed[1] = struct.pack("!H", length)
1358 return ''.join(packed)
1359
1360 @staticmethod
1361 def unpack(buf):
1362 obj = queue_prop_min_rate()
1363 if type(buf) == loxi.generic_util.OFReader:
1364 reader = buf
1365 else:
1366 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001367 _type = reader.read("!H")[0]
1368 assert(_type == 1)
1369 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001370 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001371 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001372 reader.skip(6)
1373 return obj
1374
1375 def __eq__(self, other):
1376 if type(self) != type(other): return False
1377 if self.rate != other.rate: return False
1378 return True
1379
1380 def __ne__(self, other):
1381 return not self.__eq__(other)
1382
1383 def show(self):
1384 import loxi.pp
1385 return loxi.pp.pp(self)
1386
1387 def pretty_print(self, q):
1388 q.text("queue_prop_min_rate {")
1389 with q.group():
1390 with q.indent(2):
1391 q.breakable()
1392 q.text("rate = ");
1393 q.text("%#x" % self.rate)
1394 q.breakable()
1395 q.text('}')
1396
1397class queue_stats_entry(object):
1398
1399 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1400 if port_no != None:
1401 self.port_no = port_no
1402 else:
1403 self.port_no = 0
1404 if queue_id != None:
1405 self.queue_id = queue_id
1406 else:
1407 self.queue_id = 0
1408 if tx_bytes != None:
1409 self.tx_bytes = tx_bytes
1410 else:
1411 self.tx_bytes = 0
1412 if tx_packets != None:
1413 self.tx_packets = tx_packets
1414 else:
1415 self.tx_packets = 0
1416 if tx_errors != None:
1417 self.tx_errors = tx_errors
1418 else:
1419 self.tx_errors = 0
1420 return
1421
1422 def pack(self):
1423 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001424 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001425 packed.append(struct.pack("!L", self.queue_id))
1426 packed.append(struct.pack("!Q", self.tx_bytes))
1427 packed.append(struct.pack("!Q", self.tx_packets))
1428 packed.append(struct.pack("!Q", self.tx_errors))
1429 return ''.join(packed)
1430
1431 @staticmethod
1432 def unpack(buf):
1433 obj = queue_stats_entry()
1434 if type(buf) == loxi.generic_util.OFReader:
1435 reader = buf
1436 else:
1437 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001438 obj.port_no = util.unpack_port_no(reader)
1439 obj.queue_id = reader.read("!L")[0]
1440 obj.tx_bytes = reader.read("!Q")[0]
1441 obj.tx_packets = reader.read("!Q")[0]
1442 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001443 return obj
1444
1445 def __eq__(self, other):
1446 if type(self) != type(other): return False
1447 if self.port_no != other.port_no: return False
1448 if self.queue_id != other.queue_id: return False
1449 if self.tx_bytes != other.tx_bytes: return False
1450 if self.tx_packets != other.tx_packets: return False
1451 if self.tx_errors != other.tx_errors: return False
1452 return True
1453
1454 def __ne__(self, other):
1455 return not self.__eq__(other)
1456
1457 def show(self):
1458 import loxi.pp
1459 return loxi.pp.pp(self)
1460
1461 def pretty_print(self, q):
1462 q.text("queue_stats_entry {")
1463 with q.group():
1464 with q.indent(2):
1465 q.breakable()
1466 q.text("port_no = ");
1467 q.text(util.pretty_port(self.port_no))
1468 q.text(","); q.breakable()
1469 q.text("queue_id = ");
1470 q.text("%#x" % self.queue_id)
1471 q.text(","); q.breakable()
1472 q.text("tx_bytes = ");
1473 q.text("%#x" % self.tx_bytes)
1474 q.text(","); q.breakable()
1475 q.text("tx_packets = ");
1476 q.text("%#x" % self.tx_packets)
1477 q.text(","); q.breakable()
1478 q.text("tx_errors = ");
1479 q.text("%#x" % self.tx_errors)
1480 q.breakable()
1481 q.text('}')
1482
1483class table_stats_entry(object):
1484
1485 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):
1486 if table_id != None:
1487 self.table_id = table_id
1488 else:
1489 self.table_id = 0
1490 if name != None:
1491 self.name = name
1492 else:
1493 self.name = ""
1494 if wildcards != None:
1495 self.wildcards = wildcards
1496 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001497 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001498 if match != None:
1499 self.match = match
1500 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001501 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001502 if instructions != None:
1503 self.instructions = instructions
1504 else:
1505 self.instructions = 0
1506 if write_actions != None:
1507 self.write_actions = write_actions
1508 else:
1509 self.write_actions = 0
1510 if apply_actions != None:
1511 self.apply_actions = apply_actions
1512 else:
1513 self.apply_actions = 0
1514 if config != None:
1515 self.config = config
1516 else:
1517 self.config = 0
1518 if max_entries != None:
1519 self.max_entries = max_entries
1520 else:
1521 self.max_entries = 0
1522 if active_count != None:
1523 self.active_count = active_count
1524 else:
1525 self.active_count = 0
1526 if lookup_count != None:
1527 self.lookup_count = lookup_count
1528 else:
1529 self.lookup_count = 0
1530 if matched_count != None:
1531 self.matched_count = matched_count
1532 else:
1533 self.matched_count = 0
1534 return
1535
1536 def pack(self):
1537 packed = []
1538 packed.append(struct.pack("!B", self.table_id))
1539 packed.append('\x00' * 7)
1540 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001541 packed.append(util.pack_wc_bmap(self.wildcards))
1542 packed.append(util.pack_match_bmap(self.match))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001543 packed.append(struct.pack("!L", self.instructions))
1544 packed.append(struct.pack("!L", self.write_actions))
1545 packed.append(struct.pack("!L", self.apply_actions))
1546 packed.append(struct.pack("!L", self.config))
1547 packed.append(struct.pack("!L", self.max_entries))
1548 packed.append(struct.pack("!L", self.active_count))
1549 packed.append(struct.pack("!Q", self.lookup_count))
1550 packed.append(struct.pack("!Q", self.matched_count))
1551 return ''.join(packed)
1552
1553 @staticmethod
1554 def unpack(buf):
1555 obj = table_stats_entry()
1556 if type(buf) == loxi.generic_util.OFReader:
1557 reader = buf
1558 else:
1559 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001560 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001561 reader.skip(7)
1562 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001563 obj.wildcards = util.unpack_wc_bmap(reader)
1564 obj.match = util.unpack_match_bmap(reader)
1565 obj.instructions = reader.read("!L")[0]
1566 obj.write_actions = reader.read("!L")[0]
1567 obj.apply_actions = reader.read("!L")[0]
1568 obj.config = reader.read("!L")[0]
1569 obj.max_entries = reader.read("!L")[0]
1570 obj.active_count = reader.read("!L")[0]
1571 obj.lookup_count = reader.read("!Q")[0]
1572 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001573 return obj
1574
1575 def __eq__(self, other):
1576 if type(self) != type(other): return False
1577 if self.table_id != other.table_id: return False
1578 if self.name != other.name: return False
1579 if self.wildcards != other.wildcards: return False
1580 if self.match != other.match: return False
1581 if self.instructions != other.instructions: return False
1582 if self.write_actions != other.write_actions: return False
1583 if self.apply_actions != other.apply_actions: return False
1584 if self.config != other.config: return False
1585 if self.max_entries != other.max_entries: return False
1586 if self.active_count != other.active_count: return False
1587 if self.lookup_count != other.lookup_count: return False
1588 if self.matched_count != other.matched_count: return False
1589 return True
1590
1591 def __ne__(self, other):
1592 return not self.__eq__(other)
1593
1594 def show(self):
1595 import loxi.pp
1596 return loxi.pp.pp(self)
1597
1598 def pretty_print(self, q):
1599 q.text("table_stats_entry {")
1600 with q.group():
1601 with q.indent(2):
1602 q.breakable()
1603 q.text("table_id = ");
1604 q.text("%#x" % self.table_id)
1605 q.text(","); q.breakable()
1606 q.text("name = ");
1607 q.pp(self.name)
1608 q.text(","); q.breakable()
1609 q.text("wildcards = ");
1610 q.text(util.pretty_wildcards(self.wildcards))
1611 q.text(","); q.breakable()
1612 q.text("match = ");
1613 q.pp(self.match)
1614 q.text(","); q.breakable()
1615 q.text("instructions = ");
1616 q.text("%#x" % self.instructions)
1617 q.text(","); q.breakable()
1618 q.text("write_actions = ");
1619 q.text("%#x" % self.write_actions)
1620 q.text(","); q.breakable()
1621 q.text("apply_actions = ");
1622 q.text("%#x" % self.apply_actions)
1623 q.text(","); q.breakable()
1624 q.text("config = ");
1625 q.text("%#x" % self.config)
1626 q.text(","); q.breakable()
1627 q.text("max_entries = ");
1628 q.text("%#x" % self.max_entries)
1629 q.text(","); q.breakable()
1630 q.text("active_count = ");
1631 q.text("%#x" % self.active_count)
1632 q.text(","); q.breakable()
1633 q.text("lookup_count = ");
1634 q.text("%#x" % self.lookup_count)
1635 q.text(","); q.breakable()
1636 q.text("matched_count = ");
1637 q.text("%#x" % self.matched_count)
1638 q.breakable()
1639 q.text('}')
1640
1641
1642match = match_v2