blob: 28b079ace1f2d312b9cc06ca8957926113cef4bc [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 Laneb658ddd2013-03-12 10:15:10 -07005
6# Automatically generated by LOXI from template common.py
7# Do not modify
8
9import sys
10import struct
11import action
12import const
13import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070014import loxi.generic_util
15
Rich Laneb658ddd2013-03-12 10:15:10 -070016
17# HACK make this module visible as 'common' to simplify code generation
18common = sys.modules[__name__]
19
Rich Lanec2ee4b82013-04-24 17:12:38 -070020def unpack_list_flow_stats_entry(reader):
21 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -070022
Rich Lanec2ee4b82013-04-24 17:12:38 -070023def 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)
Rich Laneb658ddd2013-03-12 10:15:10 -070027 else:
Rich Lanec2ee4b82013-04-24 17:12:38 -070028 raise loxi.ProtocolError("unknown queue prop %d" % typ)
29 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
Rich Laneb658ddd2013-03-12 10:15:10 -070030
Rich Lanec2ee4b82013-04-24 17:12:38 -070031def 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)
Rich Laneb658ddd2013-03-12 10:15:10 -070059
60class bsn_interface(object):
61
Rich Lanec2ee4b82013-04-24 17:12:38 -070062 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070063 if hw_addr != None:
64 self.hw_addr = hw_addr
65 else:
66 self.hw_addr = [0,0,0,0,0,0]
Rich Laneb658ddd2013-03-12 10:15:10 -070067 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
Rich Lanec2ee4b82013-04-24 17:12:38 -070079 return
Rich Laneb658ddd2013-03-12 10:15:10 -070080
81 def pack(self):
82 packed = []
83 packed.append(struct.pack("!6B", *self.hw_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -070084 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -070085 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):
Rich Laneb658ddd2013-03-12 10:15:10 -070092 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070093 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 Laneb658ddd2013-03-12 10:15:10 -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
Rich Laneb658ddd2013-03-12 10:15:10 -0700107 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()
Rich Laneb658ddd2013-03-12 10:15:10 -0700127 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
141 def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None):
142 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
162 return
163
164 def pack(self):
165 packed = []
166 packed.append(struct.pack("!H", self.type))
167 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
168 packed.append(struct.pack("!L", self.port_no))
169 packed.append(struct.pack("!H", self.ingress_tpid))
170 packed.append(struct.pack("!H", self.ingress_vlan_id))
171 packed.append(struct.pack("!H", self.egress_tpid))
172 packed.append(struct.pack("!H", self.egress_vlan_id))
173 length = sum([len(x) for x in packed])
174 packed[1] = struct.pack("!H", length)
175 return ''.join(packed)
176
177 @staticmethod
178 def unpack(buf):
179 obj = bsn_vport_q_in_q()
180 if type(buf) == loxi.generic_util.OFReader:
181 reader = buf
182 else:
183 reader = loxi.generic_util.OFReader(buf)
184 _type = reader.read("!H")[0]
185 assert(_type == 0)
186 _length = reader.read("!H")[0]
187 obj.port_no = reader.read("!L")[0]
188 obj.ingress_tpid = reader.read("!H")[0]
189 obj.ingress_vlan_id = reader.read("!H")[0]
190 obj.egress_tpid = reader.read("!H")[0]
191 obj.egress_vlan_id = reader.read("!H")[0]
192 return obj
193
194 def __eq__(self, other):
195 if type(self) != type(other): return False
196 if self.port_no != other.port_no: return False
197 if self.ingress_tpid != other.ingress_tpid: return False
198 if self.ingress_vlan_id != other.ingress_vlan_id: return False
199 if self.egress_tpid != other.egress_tpid: return False
200 if self.egress_vlan_id != other.egress_vlan_id: return False
201 return True
202
203 def __ne__(self, other):
204 return not self.__eq__(other)
205
206 def show(self):
207 import loxi.pp
208 return loxi.pp.pp(self)
209
210 def pretty_print(self, q):
211 q.text("bsn_vport_q_in_q {")
212 with q.group():
213 with q.indent(2):
214 q.breakable()
215 q.text("port_no = ");
216 q.text("%#x" % self.port_no)
217 q.text(","); q.breakable()
218 q.text("ingress_tpid = ");
219 q.text("%#x" % self.ingress_tpid)
220 q.text(","); q.breakable()
221 q.text("ingress_vlan_id = ");
222 q.text("%#x" % self.ingress_vlan_id)
223 q.text(","); q.breakable()
224 q.text("egress_tpid = ");
225 q.text("%#x" % self.egress_tpid)
226 q.text(","); q.breakable()
227 q.text("egress_vlan_id = ");
228 q.text("%#x" % self.egress_vlan_id)
229 q.breakable()
230 q.text('}')
231
Rich Laneb658ddd2013-03-12 10:15:10 -0700232class flow_stats_entry(object):
233
Rich Lanec2ee4b82013-04-24 17:12:38 -0700234 def __init__(self, table_id=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, actions=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700235 if table_id != None:
236 self.table_id = table_id
237 else:
238 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700239 if match != None:
240 self.match = match
241 else:
242 self.match = common.match()
243 if duration_sec != None:
244 self.duration_sec = duration_sec
245 else:
246 self.duration_sec = 0
247 if duration_nsec != None:
248 self.duration_nsec = duration_nsec
249 else:
250 self.duration_nsec = 0
251 if priority != None:
252 self.priority = priority
253 else:
254 self.priority = 0
255 if idle_timeout != None:
256 self.idle_timeout = idle_timeout
257 else:
258 self.idle_timeout = 0
259 if hard_timeout != None:
260 self.hard_timeout = hard_timeout
261 else:
262 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700263 if cookie != None:
264 self.cookie = cookie
265 else:
266 self.cookie = 0
267 if packet_count != None:
268 self.packet_count = packet_count
269 else:
270 self.packet_count = 0
271 if byte_count != None:
272 self.byte_count = byte_count
273 else:
274 self.byte_count = 0
275 if actions != None:
276 self.actions = actions
277 else:
278 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700279 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700280
281 def pack(self):
282 packed = []
283 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
284 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700285 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700286 packed.append(self.match.pack())
287 packed.append(struct.pack("!L", self.duration_sec))
288 packed.append(struct.pack("!L", self.duration_nsec))
289 packed.append(struct.pack("!H", self.priority))
290 packed.append(struct.pack("!H", self.idle_timeout))
291 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700292 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700293 packed.append(struct.pack("!Q", self.cookie))
294 packed.append(struct.pack("!Q", self.packet_count))
295 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700296 packed.append(util.pack_list(self.actions))
Rich Laneb658ddd2013-03-12 10:15:10 -0700297 length = sum([len(x) for x in packed])
298 packed[0] = struct.pack("!H", length)
299 return ''.join(packed)
300
301 @staticmethod
302 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700303 obj = flow_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700304 if type(buf) == loxi.generic_util.OFReader:
305 reader = buf
306 else:
307 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700308 _length = reader.read("!H")[0]
309 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700310 reader.skip(1)
311 obj.match = common.match.unpack(reader)
Dan Talaycof6202252013-07-02 01:00:29 -0700312 obj.duration_sec = reader.read("!L")[0]
313 obj.duration_nsec = reader.read("!L")[0]
314 obj.priority = reader.read("!H")[0]
315 obj.idle_timeout = reader.read("!H")[0]
316 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700317 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700318 obj.cookie = reader.read("!Q")[0]
319 obj.packet_count = reader.read("!Q")[0]
320 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700321 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700322 return obj
323
324 def __eq__(self, other):
325 if type(self) != type(other): return False
326 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700327 if self.match != other.match: return False
328 if self.duration_sec != other.duration_sec: return False
329 if self.duration_nsec != other.duration_nsec: return False
330 if self.priority != other.priority: return False
331 if self.idle_timeout != other.idle_timeout: return False
332 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700333 if self.cookie != other.cookie: return False
334 if self.packet_count != other.packet_count: return False
335 if self.byte_count != other.byte_count: return False
336 if self.actions != other.actions: return False
337 return True
338
339 def __ne__(self, other):
340 return not self.__eq__(other)
341
342 def show(self):
343 import loxi.pp
344 return loxi.pp.pp(self)
345
346 def pretty_print(self, q):
347 q.text("flow_stats_entry {")
348 with q.group():
349 with q.indent(2):
350 q.breakable()
351 q.text("table_id = ");
352 q.text("%#x" % self.table_id)
353 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700354 q.text("match = ");
355 q.pp(self.match)
356 q.text(","); q.breakable()
357 q.text("duration_sec = ");
358 q.text("%#x" % self.duration_sec)
359 q.text(","); q.breakable()
360 q.text("duration_nsec = ");
361 q.text("%#x" % self.duration_nsec)
362 q.text(","); q.breakable()
363 q.text("priority = ");
364 q.text("%#x" % self.priority)
365 q.text(","); q.breakable()
366 q.text("idle_timeout = ");
367 q.text("%#x" % self.idle_timeout)
368 q.text(","); q.breakable()
369 q.text("hard_timeout = ");
370 q.text("%#x" % self.hard_timeout)
371 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700372 q.text("cookie = ");
373 q.text("%#x" % self.cookie)
374 q.text(","); q.breakable()
375 q.text("packet_count = ");
376 q.text("%#x" % self.packet_count)
377 q.text(","); q.breakable()
378 q.text("byte_count = ");
379 q.text("%#x" % self.byte_count)
380 q.text(","); q.breakable()
381 q.text("actions = ");
382 q.pp(self.actions)
383 q.breakable()
384 q.text('}')
385
386class match_v1(object):
387
Rich Lanefe600f52013-07-09 13:22:32 -0700388 def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700389 if wildcards != None:
390 self.wildcards = wildcards
391 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700392 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -0700393 if in_port != None:
394 self.in_port = in_port
395 else:
396 self.in_port = 0
397 if eth_src != None:
398 self.eth_src = eth_src
399 else:
400 self.eth_src = [0,0,0,0,0,0]
401 if eth_dst != None:
402 self.eth_dst = eth_dst
403 else:
404 self.eth_dst = [0,0,0,0,0,0]
405 if vlan_vid != None:
406 self.vlan_vid = vlan_vid
407 else:
408 self.vlan_vid = 0
409 if vlan_pcp != None:
410 self.vlan_pcp = vlan_pcp
411 else:
412 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700413 if eth_type != None:
414 self.eth_type = eth_type
415 else:
416 self.eth_type = 0
417 if ip_dscp != None:
418 self.ip_dscp = ip_dscp
419 else:
420 self.ip_dscp = 0
421 if ip_proto != None:
422 self.ip_proto = ip_proto
423 else:
424 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700425 if ipv4_src != None:
426 self.ipv4_src = ipv4_src
427 else:
428 self.ipv4_src = 0
429 if ipv4_dst != None:
430 self.ipv4_dst = ipv4_dst
431 else:
432 self.ipv4_dst = 0
433 if tcp_src != None:
434 self.tcp_src = tcp_src
435 else:
436 self.tcp_src = 0
437 if tcp_dst != None:
438 self.tcp_dst = tcp_dst
439 else:
440 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700441 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700442
443 def pack(self):
444 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700445 packed.append(util.pack_wc_bmap(self.wildcards))
446 packed.append(util.pack_port_no(self.in_port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700447 packed.append(struct.pack("!6B", *self.eth_src))
448 packed.append(struct.pack("!6B", *self.eth_dst))
449 packed.append(struct.pack("!H", self.vlan_vid))
450 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700451 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700452 packed.append(struct.pack("!H", self.eth_type))
453 packed.append(struct.pack("!B", self.ip_dscp))
454 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanefe600f52013-07-09 13:22:32 -0700455 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700456 packed.append(struct.pack("!L", self.ipv4_src))
457 packed.append(struct.pack("!L", self.ipv4_dst))
458 packed.append(struct.pack("!H", self.tcp_src))
459 packed.append(struct.pack("!H", self.tcp_dst))
460 return ''.join(packed)
461
462 @staticmethod
463 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700464 obj = match_v1()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700465 if type(buf) == loxi.generic_util.OFReader:
466 reader = buf
467 else:
468 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700469 obj.wildcards = util.unpack_wc_bmap(reader)
470 obj.in_port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700471 obj.eth_src = list(reader.read('!6B'))
472 obj.eth_dst = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700473 obj.vlan_vid = reader.read("!H")[0]
474 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700475 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700476 obj.eth_type = reader.read("!H")[0]
477 obj.ip_dscp = reader.read("!B")[0]
478 obj.ip_proto = reader.read("!B")[0]
Rich Lanefe600f52013-07-09 13:22:32 -0700479 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700480 obj.ipv4_src = reader.read("!L")[0]
481 obj.ipv4_dst = reader.read("!L")[0]
482 obj.tcp_src = reader.read("!H")[0]
483 obj.tcp_dst = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700484 return obj
485
486 def __eq__(self, other):
487 if type(self) != type(other): return False
488 if self.wildcards != other.wildcards: return False
489 if self.in_port != other.in_port: return False
490 if self.eth_src != other.eth_src: return False
491 if self.eth_dst != other.eth_dst: return False
492 if self.vlan_vid != other.vlan_vid: return False
493 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700494 if self.eth_type != other.eth_type: return False
495 if self.ip_dscp != other.ip_dscp: return False
496 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700497 if self.ipv4_src != other.ipv4_src: return False
498 if self.ipv4_dst != other.ipv4_dst: return False
499 if self.tcp_src != other.tcp_src: return False
500 if self.tcp_dst != other.tcp_dst: return False
501 return True
502
503 def __ne__(self, other):
504 return not self.__eq__(other)
505
506 def show(self):
507 import loxi.pp
508 return loxi.pp.pp(self)
509
510 def pretty_print(self, q):
511 q.text("match_v1 {")
512 with q.group():
513 with q.indent(2):
514 q.breakable()
515 q.text("wildcards = ");
516 q.text(util.pretty_wildcards(self.wildcards))
517 q.text(","); q.breakable()
518 q.text("in_port = ");
519 q.text(util.pretty_port(self.in_port))
520 q.text(","); q.breakable()
521 q.text("eth_src = ");
522 q.text(util.pretty_mac(self.eth_src))
523 q.text(","); q.breakable()
524 q.text("eth_dst = ");
525 q.text(util.pretty_mac(self.eth_dst))
526 q.text(","); q.breakable()
527 q.text("vlan_vid = ");
528 q.text("%#x" % self.vlan_vid)
529 q.text(","); q.breakable()
530 q.text("vlan_pcp = ");
531 q.text("%#x" % self.vlan_pcp)
532 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700533 q.text("eth_type = ");
534 q.text("%#x" % self.eth_type)
535 q.text(","); q.breakable()
536 q.text("ip_dscp = ");
537 q.text("%#x" % self.ip_dscp)
538 q.text(","); q.breakable()
539 q.text("ip_proto = ");
540 q.text("%#x" % self.ip_proto)
541 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700542 q.text("ipv4_src = ");
543 q.text(util.pretty_ipv4(self.ipv4_src))
544 q.text(","); q.breakable()
545 q.text("ipv4_dst = ");
546 q.text(util.pretty_ipv4(self.ipv4_dst))
547 q.text(","); q.breakable()
548 q.text("tcp_src = ");
549 q.text("%#x" % self.tcp_src)
550 q.text(","); q.breakable()
551 q.text("tcp_dst = ");
552 q.text("%#x" % self.tcp_dst)
553 q.breakable()
554 q.text('}')
555
Rich Laneb658ddd2013-03-12 10:15:10 -0700556class packet_queue(object):
557
Rich Lanec2ee4b82013-04-24 17:12:38 -0700558 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700559 if queue_id != None:
560 self.queue_id = queue_id
561 else:
562 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700563 if properties != None:
564 self.properties = properties
565 else:
566 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700567 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700568
569 def pack(self):
570 packed = []
571 packed.append(struct.pack("!L", self.queue_id))
572 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700573 packed.append('\x00' * 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700574 packed.append(util.pack_list(self.properties))
Rich Laneb658ddd2013-03-12 10:15:10 -0700575 length = sum([len(x) for x in packed])
576 packed[1] = struct.pack("!H", length)
577 return ''.join(packed)
578
579 @staticmethod
580 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700581 obj = packet_queue()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700582 if type(buf) == loxi.generic_util.OFReader:
583 reader = buf
584 else:
585 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700586 obj.queue_id = reader.read("!L")[0]
587 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700588 reader.skip(2)
589 obj.properties = common.unpack_list_queue_prop(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700590 return obj
591
592 def __eq__(self, other):
593 if type(self) != type(other): return False
594 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700595 if self.properties != other.properties: return False
596 return True
597
598 def __ne__(self, other):
599 return not self.__eq__(other)
600
601 def show(self):
602 import loxi.pp
603 return loxi.pp.pp(self)
604
605 def pretty_print(self, q):
606 q.text("packet_queue {")
607 with q.group():
608 with q.indent(2):
609 q.breakable()
610 q.text("queue_id = ");
611 q.text("%#x" % self.queue_id)
612 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700613 q.text("properties = ");
614 q.pp(self.properties)
615 q.breakable()
616 q.text('}')
617
618class port_desc(object):
619
620 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
621 if port_no != None:
622 self.port_no = port_no
623 else:
624 self.port_no = 0
625 if hw_addr != None:
626 self.hw_addr = hw_addr
627 else:
628 self.hw_addr = [0,0,0,0,0,0]
629 if name != None:
630 self.name = name
631 else:
632 self.name = ""
633 if config != None:
634 self.config = config
635 else:
636 self.config = 0
637 if state != None:
638 self.state = state
639 else:
640 self.state = 0
641 if curr != None:
642 self.curr = curr
643 else:
644 self.curr = 0
645 if advertised != None:
646 self.advertised = advertised
647 else:
648 self.advertised = 0
649 if supported != None:
650 self.supported = supported
651 else:
652 self.supported = 0
653 if peer != None:
654 self.peer = peer
655 else:
656 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700657 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700658
659 def pack(self):
660 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700661 packed.append(util.pack_port_no(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -0700662 packed.append(struct.pack("!6B", *self.hw_addr))
663 packed.append(struct.pack("!16s", self.name))
664 packed.append(struct.pack("!L", self.config))
665 packed.append(struct.pack("!L", self.state))
666 packed.append(struct.pack("!L", self.curr))
667 packed.append(struct.pack("!L", self.advertised))
668 packed.append(struct.pack("!L", self.supported))
669 packed.append(struct.pack("!L", self.peer))
670 return ''.join(packed)
671
672 @staticmethod
673 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700674 obj = port_desc()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700675 if type(buf) == loxi.generic_util.OFReader:
676 reader = buf
677 else:
678 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700679 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700680 obj.hw_addr = list(reader.read('!6B'))
681 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700682 obj.config = reader.read("!L")[0]
683 obj.state = reader.read("!L")[0]
684 obj.curr = reader.read("!L")[0]
685 obj.advertised = reader.read("!L")[0]
686 obj.supported = reader.read("!L")[0]
687 obj.peer = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700688 return obj
689
690 def __eq__(self, other):
691 if type(self) != type(other): return False
692 if self.port_no != other.port_no: return False
693 if self.hw_addr != other.hw_addr: return False
694 if self.name != other.name: return False
695 if self.config != other.config: return False
696 if self.state != other.state: return False
697 if self.curr != other.curr: return False
698 if self.advertised != other.advertised: return False
699 if self.supported != other.supported: return False
700 if self.peer != other.peer: return False
701 return True
702
703 def __ne__(self, other):
704 return not self.__eq__(other)
705
706 def show(self):
707 import loxi.pp
708 return loxi.pp.pp(self)
709
710 def pretty_print(self, q):
711 q.text("port_desc {")
712 with q.group():
713 with q.indent(2):
714 q.breakable()
715 q.text("port_no = ");
716 q.text(util.pretty_port(self.port_no))
717 q.text(","); q.breakable()
718 q.text("hw_addr = ");
719 q.text(util.pretty_mac(self.hw_addr))
720 q.text(","); q.breakable()
721 q.text("name = ");
722 q.pp(self.name)
723 q.text(","); q.breakable()
724 q.text("config = ");
725 q.text("%#x" % self.config)
726 q.text(","); q.breakable()
727 q.text("state = ");
728 q.text("%#x" % self.state)
729 q.text(","); q.breakable()
730 q.text("curr = ");
731 q.text("%#x" % self.curr)
732 q.text(","); q.breakable()
733 q.text("advertised = ");
734 q.text("%#x" % self.advertised)
735 q.text(","); q.breakable()
736 q.text("supported = ");
737 q.text("%#x" % self.supported)
738 q.text(","); q.breakable()
739 q.text("peer = ");
740 q.text("%#x" % self.peer)
741 q.breakable()
742 q.text('}')
743
744class port_stats_entry(object):
745
Rich Lanec2ee4b82013-04-24 17:12:38 -0700746 def __init__(self, port_no=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700747 if port_no != None:
748 self.port_no = port_no
749 else:
750 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700751 if rx_packets != None:
752 self.rx_packets = rx_packets
753 else:
754 self.rx_packets = 0
755 if tx_packets != None:
756 self.tx_packets = tx_packets
757 else:
758 self.tx_packets = 0
759 if rx_bytes != None:
760 self.rx_bytes = rx_bytes
761 else:
762 self.rx_bytes = 0
763 if tx_bytes != None:
764 self.tx_bytes = tx_bytes
765 else:
766 self.tx_bytes = 0
767 if rx_dropped != None:
768 self.rx_dropped = rx_dropped
769 else:
770 self.rx_dropped = 0
771 if tx_dropped != None:
772 self.tx_dropped = tx_dropped
773 else:
774 self.tx_dropped = 0
775 if rx_errors != None:
776 self.rx_errors = rx_errors
777 else:
778 self.rx_errors = 0
779 if tx_errors != None:
780 self.tx_errors = tx_errors
781 else:
782 self.tx_errors = 0
783 if rx_frame_err != None:
784 self.rx_frame_err = rx_frame_err
785 else:
786 self.rx_frame_err = 0
787 if rx_over_err != None:
788 self.rx_over_err = rx_over_err
789 else:
790 self.rx_over_err = 0
791 if rx_crc_err != None:
792 self.rx_crc_err = rx_crc_err
793 else:
794 self.rx_crc_err = 0
795 if collisions != None:
796 self.collisions = collisions
797 else:
798 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700799 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700800
801 def pack(self):
802 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700803 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700804 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700805 packed.append(struct.pack("!Q", self.rx_packets))
806 packed.append(struct.pack("!Q", self.tx_packets))
807 packed.append(struct.pack("!Q", self.rx_bytes))
808 packed.append(struct.pack("!Q", self.tx_bytes))
809 packed.append(struct.pack("!Q", self.rx_dropped))
810 packed.append(struct.pack("!Q", self.tx_dropped))
811 packed.append(struct.pack("!Q", self.rx_errors))
812 packed.append(struct.pack("!Q", self.tx_errors))
813 packed.append(struct.pack("!Q", self.rx_frame_err))
814 packed.append(struct.pack("!Q", self.rx_over_err))
815 packed.append(struct.pack("!Q", self.rx_crc_err))
816 packed.append(struct.pack("!Q", self.collisions))
817 return ''.join(packed)
818
819 @staticmethod
820 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700821 obj = port_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700822 if type(buf) == loxi.generic_util.OFReader:
823 reader = buf
824 else:
825 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700826 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700827 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700828 obj.rx_packets = reader.read("!Q")[0]
829 obj.tx_packets = reader.read("!Q")[0]
830 obj.rx_bytes = reader.read("!Q")[0]
831 obj.tx_bytes = reader.read("!Q")[0]
832 obj.rx_dropped = reader.read("!Q")[0]
833 obj.tx_dropped = reader.read("!Q")[0]
834 obj.rx_errors = reader.read("!Q")[0]
835 obj.tx_errors = reader.read("!Q")[0]
836 obj.rx_frame_err = reader.read("!Q")[0]
837 obj.rx_over_err = reader.read("!Q")[0]
838 obj.rx_crc_err = reader.read("!Q")[0]
839 obj.collisions = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700840 return obj
841
842 def __eq__(self, other):
843 if type(self) != type(other): return False
844 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700845 if self.rx_packets != other.rx_packets: return False
846 if self.tx_packets != other.tx_packets: return False
847 if self.rx_bytes != other.rx_bytes: return False
848 if self.tx_bytes != other.tx_bytes: return False
849 if self.rx_dropped != other.rx_dropped: return False
850 if self.tx_dropped != other.tx_dropped: return False
851 if self.rx_errors != other.rx_errors: return False
852 if self.tx_errors != other.tx_errors: return False
853 if self.rx_frame_err != other.rx_frame_err: return False
854 if self.rx_over_err != other.rx_over_err: return False
855 if self.rx_crc_err != other.rx_crc_err: return False
856 if self.collisions != other.collisions: return False
857 return True
858
859 def __ne__(self, other):
860 return not self.__eq__(other)
861
862 def show(self):
863 import loxi.pp
864 return loxi.pp.pp(self)
865
866 def pretty_print(self, q):
867 q.text("port_stats_entry {")
868 with q.group():
869 with q.indent(2):
870 q.breakable()
871 q.text("port_no = ");
872 q.text(util.pretty_port(self.port_no))
873 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700874 q.text("rx_packets = ");
875 q.text("%#x" % self.rx_packets)
876 q.text(","); q.breakable()
877 q.text("tx_packets = ");
878 q.text("%#x" % self.tx_packets)
879 q.text(","); q.breakable()
880 q.text("rx_bytes = ");
881 q.text("%#x" % self.rx_bytes)
882 q.text(","); q.breakable()
883 q.text("tx_bytes = ");
884 q.text("%#x" % self.tx_bytes)
885 q.text(","); q.breakable()
886 q.text("rx_dropped = ");
887 q.text("%#x" % self.rx_dropped)
888 q.text(","); q.breakable()
889 q.text("tx_dropped = ");
890 q.text("%#x" % self.tx_dropped)
891 q.text(","); q.breakable()
892 q.text("rx_errors = ");
893 q.text("%#x" % self.rx_errors)
894 q.text(","); q.breakable()
895 q.text("tx_errors = ");
896 q.text("%#x" % self.tx_errors)
897 q.text(","); q.breakable()
898 q.text("rx_frame_err = ");
899 q.text("%#x" % self.rx_frame_err)
900 q.text(","); q.breakable()
901 q.text("rx_over_err = ");
902 q.text("%#x" % self.rx_over_err)
903 q.text(","); q.breakable()
904 q.text("rx_crc_err = ");
905 q.text("%#x" % self.rx_crc_err)
906 q.text(","); q.breakable()
907 q.text("collisions = ");
908 q.text("%#x" % self.collisions)
909 q.breakable()
910 q.text('}')
911
912class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -0700913 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -0700914
Rich Lanec2ee4b82013-04-24 17:12:38 -0700915 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700916 if rate != None:
917 self.rate = rate
918 else:
919 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700920 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700921
922 def pack(self):
923 packed = []
924 packed.append(struct.pack("!H", self.type))
925 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700926 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700927 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700928 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700929 length = sum([len(x) for x in packed])
930 packed[1] = struct.pack("!H", length)
931 return ''.join(packed)
932
933 @staticmethod
934 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700935 obj = queue_prop_min_rate()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700936 if type(buf) == loxi.generic_util.OFReader:
937 reader = buf
938 else:
939 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700940 _type = reader.read("!H")[0]
941 assert(_type == 1)
942 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700943 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700944 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700945 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700946 return obj
947
948 def __eq__(self, other):
949 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700950 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700951 return True
952
953 def __ne__(self, other):
954 return not self.__eq__(other)
955
956 def show(self):
957 import loxi.pp
958 return loxi.pp.pp(self)
959
960 def pretty_print(self, q):
961 q.text("queue_prop_min_rate {")
962 with q.group():
963 with q.indent(2):
964 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700965 q.text("rate = ");
966 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -0700967 q.breakable()
968 q.text('}')
969
970class queue_stats_entry(object):
971
Rich Lanec2ee4b82013-04-24 17:12:38 -0700972 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700973 if port_no != None:
974 self.port_no = port_no
975 else:
976 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700977 if queue_id != None:
978 self.queue_id = queue_id
979 else:
980 self.queue_id = 0
981 if tx_bytes != None:
982 self.tx_bytes = tx_bytes
983 else:
984 self.tx_bytes = 0
985 if tx_packets != None:
986 self.tx_packets = tx_packets
987 else:
988 self.tx_packets = 0
989 if tx_errors != None:
990 self.tx_errors = tx_errors
991 else:
992 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700993 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700994
995 def pack(self):
996 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700997 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700998 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700999 packed.append(struct.pack("!L", self.queue_id))
1000 packed.append(struct.pack("!Q", self.tx_bytes))
1001 packed.append(struct.pack("!Q", self.tx_packets))
1002 packed.append(struct.pack("!Q", self.tx_errors))
1003 return ''.join(packed)
1004
1005 @staticmethod
1006 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001007 obj = queue_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001008 if type(buf) == loxi.generic_util.OFReader:
1009 reader = buf
1010 else:
1011 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001012 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001013 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -07001014 obj.queue_id = reader.read("!L")[0]
1015 obj.tx_bytes = reader.read("!Q")[0]
1016 obj.tx_packets = reader.read("!Q")[0]
1017 obj.tx_errors = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001018 return obj
1019
1020 def __eq__(self, other):
1021 if type(self) != type(other): return False
1022 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001023 if self.queue_id != other.queue_id: return False
1024 if self.tx_bytes != other.tx_bytes: return False
1025 if self.tx_packets != other.tx_packets: return False
1026 if self.tx_errors != other.tx_errors: return False
1027 return True
1028
1029 def __ne__(self, other):
1030 return not self.__eq__(other)
1031
1032 def show(self):
1033 import loxi.pp
1034 return loxi.pp.pp(self)
1035
1036 def pretty_print(self, q):
1037 q.text("queue_stats_entry {")
1038 with q.group():
1039 with q.indent(2):
1040 q.breakable()
1041 q.text("port_no = ");
1042 q.text(util.pretty_port(self.port_no))
1043 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001044 q.text("queue_id = ");
1045 q.text("%#x" % self.queue_id)
1046 q.text(","); q.breakable()
1047 q.text("tx_bytes = ");
1048 q.text("%#x" % self.tx_bytes)
1049 q.text(","); q.breakable()
1050 q.text("tx_packets = ");
1051 q.text("%#x" % self.tx_packets)
1052 q.text(","); q.breakable()
1053 q.text("tx_errors = ");
1054 q.text("%#x" % self.tx_errors)
1055 q.breakable()
1056 q.text('}')
1057
1058class table_stats_entry(object):
1059
Rich Lanec2ee4b82013-04-24 17:12:38 -07001060 def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001061 if table_id != None:
1062 self.table_id = table_id
1063 else:
1064 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001065 if name != None:
1066 self.name = name
1067 else:
1068 self.name = ""
1069 if wildcards != None:
1070 self.wildcards = wildcards
1071 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001072 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -07001073 if max_entries != None:
1074 self.max_entries = max_entries
1075 else:
1076 self.max_entries = 0
1077 if active_count != None:
1078 self.active_count = active_count
1079 else:
1080 self.active_count = 0
1081 if lookup_count != None:
1082 self.lookup_count = lookup_count
1083 else:
1084 self.lookup_count = 0
1085 if matched_count != None:
1086 self.matched_count = matched_count
1087 else:
1088 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001089 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001090
1091 def pack(self):
1092 packed = []
1093 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001094 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001095 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001096 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Laneb658ddd2013-03-12 10:15:10 -07001097 packed.append(struct.pack("!L", self.max_entries))
1098 packed.append(struct.pack("!L", self.active_count))
1099 packed.append(struct.pack("!Q", self.lookup_count))
1100 packed.append(struct.pack("!Q", self.matched_count))
1101 return ''.join(packed)
1102
1103 @staticmethod
1104 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001105 obj = table_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001106 if type(buf) == loxi.generic_util.OFReader:
1107 reader = buf
1108 else:
1109 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001110 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001111 reader.skip(3)
1112 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001113 obj.wildcards = util.unpack_wc_bmap(reader)
1114 obj.max_entries = reader.read("!L")[0]
1115 obj.active_count = reader.read("!L")[0]
1116 obj.lookup_count = reader.read("!Q")[0]
1117 obj.matched_count = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001118 return obj
1119
1120 def __eq__(self, other):
1121 if type(self) != type(other): return False
1122 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001123 if self.name != other.name: return False
1124 if self.wildcards != other.wildcards: return False
1125 if self.max_entries != other.max_entries: return False
1126 if self.active_count != other.active_count: return False
1127 if self.lookup_count != other.lookup_count: return False
1128 if self.matched_count != other.matched_count: return False
1129 return True
1130
1131 def __ne__(self, other):
1132 return not self.__eq__(other)
1133
1134 def show(self):
1135 import loxi.pp
1136 return loxi.pp.pp(self)
1137
1138 def pretty_print(self, q):
1139 q.text("table_stats_entry {")
1140 with q.group():
1141 with q.indent(2):
1142 q.breakable()
1143 q.text("table_id = ");
1144 q.text("%#x" % self.table_id)
1145 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001146 q.text("name = ");
1147 q.pp(self.name)
1148 q.text(","); q.breakable()
1149 q.text("wildcards = ");
1150 q.text(util.pretty_wildcards(self.wildcards))
1151 q.text(","); q.breakable()
1152 q.text("max_entries = ");
1153 q.text("%#x" % self.max_entries)
1154 q.text(","); q.breakable()
1155 q.text("active_count = ");
1156 q.text("%#x" % self.active_count)
1157 q.text(","); q.breakable()
1158 q.text("lookup_count = ");
1159 q.text("%#x" % self.lookup_count)
1160 q.text(","); q.breakable()
1161 q.text("matched_count = ");
1162 q.text("%#x" % self.matched_count)
1163 q.breakable()
1164 q.text('}')
1165
Rich Lanec2ee4b82013-04-24 17:12:38 -07001166
1167match = match_v1