blob: 327bd96479e2e4b4329bca218fbfdbd10b60cca5 [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
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700141 def __init__(self, if_name=None, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None):
142 if if_name != None:
143 self.if_name = if_name
144 else:
145 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700146 if port_no != None:
147 self.port_no = port_no
148 else:
149 self.port_no = 0
150 if ingress_tpid != None:
151 self.ingress_tpid = ingress_tpid
152 else:
153 self.ingress_tpid = 0
154 if ingress_vlan_id != None:
155 self.ingress_vlan_id = ingress_vlan_id
156 else:
157 self.ingress_vlan_id = 0
158 if egress_tpid != None:
159 self.egress_tpid = egress_tpid
160 else:
161 self.egress_tpid = 0
162 if egress_vlan_id != None:
163 self.egress_vlan_id = egress_vlan_id
164 else:
165 self.egress_vlan_id = 0
166 return
167
168 def pack(self):
169 packed = []
170 packed.append(struct.pack("!H", self.type))
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700171 packed.append(struct.pack("!16s", self.if_name))
172 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
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))
178 length = sum([len(x) for x in packed])
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700179 packed[2] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700180 return ''.join(packed)
181
182 @staticmethod
183 def unpack(buf):
184 obj = bsn_vport_q_in_q()
185 if type(buf) == loxi.generic_util.OFReader:
186 reader = buf
187 else:
188 reader = loxi.generic_util.OFReader(buf)
189 _type = reader.read("!H")[0]
190 assert(_type == 0)
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700191 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700192 _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]
198 return obj
199
200 def __eq__(self, other):
201 if type(self) != type(other): return False
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700202 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700203 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
208 return True
209
210 def __ne__(self, other):
211 return not self.__eq__(other)
212
213 def show(self):
214 import loxi.pp
215 return loxi.pp.pp(self)
216
217 def pretty_print(self, q):
218 q.text("bsn_vport_q_in_q {")
219 with q.group():
220 with q.indent(2):
221 q.breakable()
Kiran Poolaae8fbf12013-09-19 16:32:32 -0700222 q.text("if_name = ");
223 q.pp(self.if_name)
224 q.text(","); q.breakable()
Dan Talaycof6202252013-07-02 01:00:29 -0700225 q.text("port_no = ");
226 q.text("%#x" % self.port_no)
227 q.text(","); q.breakable()
228 q.text("ingress_tpid = ");
229 q.text("%#x" % self.ingress_tpid)
230 q.text(","); q.breakable()
231 q.text("ingress_vlan_id = ");
232 q.text("%#x" % self.ingress_vlan_id)
233 q.text(","); q.breakable()
234 q.text("egress_tpid = ");
235 q.text("%#x" % self.egress_tpid)
236 q.text(","); q.breakable()
237 q.text("egress_vlan_id = ");
238 q.text("%#x" % self.egress_vlan_id)
239 q.breakable()
240 q.text('}')
241
Rich Laneb658ddd2013-03-12 10:15:10 -0700242class flow_stats_entry(object):
243
Rich Lanec2ee4b82013-04-24 17:12:38 -0700244 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 -0700245 if table_id != None:
246 self.table_id = table_id
247 else:
248 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700249 if match != None:
250 self.match = match
251 else:
252 self.match = common.match()
253 if duration_sec != None:
254 self.duration_sec = duration_sec
255 else:
256 self.duration_sec = 0
257 if duration_nsec != None:
258 self.duration_nsec = duration_nsec
259 else:
260 self.duration_nsec = 0
261 if priority != None:
262 self.priority = priority
263 else:
264 self.priority = 0
265 if idle_timeout != None:
266 self.idle_timeout = idle_timeout
267 else:
268 self.idle_timeout = 0
269 if hard_timeout != None:
270 self.hard_timeout = hard_timeout
271 else:
272 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700273 if cookie != None:
274 self.cookie = cookie
275 else:
276 self.cookie = 0
277 if packet_count != None:
278 self.packet_count = packet_count
279 else:
280 self.packet_count = 0
281 if byte_count != None:
282 self.byte_count = byte_count
283 else:
284 self.byte_count = 0
285 if actions != None:
286 self.actions = actions
287 else:
288 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700289 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700290
291 def pack(self):
292 packed = []
293 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
294 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700295 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700296 packed.append(self.match.pack())
297 packed.append(struct.pack("!L", self.duration_sec))
298 packed.append(struct.pack("!L", self.duration_nsec))
299 packed.append(struct.pack("!H", self.priority))
300 packed.append(struct.pack("!H", self.idle_timeout))
301 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700302 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700303 packed.append(struct.pack("!Q", self.cookie))
304 packed.append(struct.pack("!Q", self.packet_count))
305 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700306 packed.append(util.pack_list(self.actions))
Rich Laneb658ddd2013-03-12 10:15:10 -0700307 length = sum([len(x) for x in packed])
308 packed[0] = struct.pack("!H", length)
309 return ''.join(packed)
310
311 @staticmethod
312 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700313 obj = flow_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700314 if type(buf) == loxi.generic_util.OFReader:
315 reader = buf
316 else:
317 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700318 _length = reader.read("!H")[0]
319 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700320 reader.skip(1)
321 obj.match = common.match.unpack(reader)
Dan Talaycof6202252013-07-02 01:00:29 -0700322 obj.duration_sec = reader.read("!L")[0]
323 obj.duration_nsec = reader.read("!L")[0]
324 obj.priority = reader.read("!H")[0]
325 obj.idle_timeout = reader.read("!H")[0]
326 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700327 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700328 obj.cookie = reader.read("!Q")[0]
329 obj.packet_count = reader.read("!Q")[0]
330 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700331 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700332 return obj
333
334 def __eq__(self, other):
335 if type(self) != type(other): return False
336 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700337 if self.match != other.match: return False
338 if self.duration_sec != other.duration_sec: return False
339 if self.duration_nsec != other.duration_nsec: return False
340 if self.priority != other.priority: return False
341 if self.idle_timeout != other.idle_timeout: return False
342 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700343 if self.cookie != other.cookie: return False
344 if self.packet_count != other.packet_count: return False
345 if self.byte_count != other.byte_count: return False
346 if self.actions != other.actions: return False
347 return True
348
349 def __ne__(self, other):
350 return not self.__eq__(other)
351
352 def show(self):
353 import loxi.pp
354 return loxi.pp.pp(self)
355
356 def pretty_print(self, q):
357 q.text("flow_stats_entry {")
358 with q.group():
359 with q.indent(2):
360 q.breakable()
361 q.text("table_id = ");
362 q.text("%#x" % self.table_id)
363 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700364 q.text("match = ");
365 q.pp(self.match)
366 q.text(","); q.breakable()
367 q.text("duration_sec = ");
368 q.text("%#x" % self.duration_sec)
369 q.text(","); q.breakable()
370 q.text("duration_nsec = ");
371 q.text("%#x" % self.duration_nsec)
372 q.text(","); q.breakable()
373 q.text("priority = ");
374 q.text("%#x" % self.priority)
375 q.text(","); q.breakable()
376 q.text("idle_timeout = ");
377 q.text("%#x" % self.idle_timeout)
378 q.text(","); q.breakable()
379 q.text("hard_timeout = ");
380 q.text("%#x" % self.hard_timeout)
381 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700382 q.text("cookie = ");
383 q.text("%#x" % self.cookie)
384 q.text(","); q.breakable()
385 q.text("packet_count = ");
386 q.text("%#x" % self.packet_count)
387 q.text(","); q.breakable()
388 q.text("byte_count = ");
389 q.text("%#x" % self.byte_count)
390 q.text(","); q.breakable()
391 q.text("actions = ");
392 q.pp(self.actions)
393 q.breakable()
394 q.text('}')
395
396class match_v1(object):
397
Rich Lanefe600f52013-07-09 13:22:32 -0700398 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 -0700399 if wildcards != None:
400 self.wildcards = wildcards
401 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700402 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -0700403 if in_port != None:
404 self.in_port = in_port
405 else:
406 self.in_port = 0
407 if eth_src != None:
408 self.eth_src = eth_src
409 else:
410 self.eth_src = [0,0,0,0,0,0]
411 if eth_dst != None:
412 self.eth_dst = eth_dst
413 else:
414 self.eth_dst = [0,0,0,0,0,0]
415 if vlan_vid != None:
416 self.vlan_vid = vlan_vid
417 else:
418 self.vlan_vid = 0
419 if vlan_pcp != None:
420 self.vlan_pcp = vlan_pcp
421 else:
422 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700423 if eth_type != None:
424 self.eth_type = eth_type
425 else:
426 self.eth_type = 0
427 if ip_dscp != None:
428 self.ip_dscp = ip_dscp
429 else:
430 self.ip_dscp = 0
431 if ip_proto != None:
432 self.ip_proto = ip_proto
433 else:
434 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700435 if ipv4_src != None:
436 self.ipv4_src = ipv4_src
437 else:
438 self.ipv4_src = 0
439 if ipv4_dst != None:
440 self.ipv4_dst = ipv4_dst
441 else:
442 self.ipv4_dst = 0
443 if tcp_src != None:
444 self.tcp_src = tcp_src
445 else:
446 self.tcp_src = 0
447 if tcp_dst != None:
448 self.tcp_dst = tcp_dst
449 else:
450 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700451 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700452
453 def pack(self):
454 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700455 packed.append(util.pack_wc_bmap(self.wildcards))
456 packed.append(util.pack_port_no(self.in_port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700457 packed.append(struct.pack("!6B", *self.eth_src))
458 packed.append(struct.pack("!6B", *self.eth_dst))
459 packed.append(struct.pack("!H", self.vlan_vid))
460 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700461 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700462 packed.append(struct.pack("!H", self.eth_type))
463 packed.append(struct.pack("!B", self.ip_dscp))
464 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanefe600f52013-07-09 13:22:32 -0700465 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700466 packed.append(struct.pack("!L", self.ipv4_src))
467 packed.append(struct.pack("!L", self.ipv4_dst))
468 packed.append(struct.pack("!H", self.tcp_src))
469 packed.append(struct.pack("!H", self.tcp_dst))
470 return ''.join(packed)
471
472 @staticmethod
473 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700474 obj = match_v1()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700475 if type(buf) == loxi.generic_util.OFReader:
476 reader = buf
477 else:
478 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700479 obj.wildcards = util.unpack_wc_bmap(reader)
480 obj.in_port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700481 obj.eth_src = list(reader.read('!6B'))
482 obj.eth_dst = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700483 obj.vlan_vid = reader.read("!H")[0]
484 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700485 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700486 obj.eth_type = reader.read("!H")[0]
487 obj.ip_dscp = reader.read("!B")[0]
488 obj.ip_proto = reader.read("!B")[0]
Rich Lanefe600f52013-07-09 13:22:32 -0700489 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700490 obj.ipv4_src = reader.read("!L")[0]
491 obj.ipv4_dst = reader.read("!L")[0]
492 obj.tcp_src = reader.read("!H")[0]
493 obj.tcp_dst = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700494 return obj
495
496 def __eq__(self, other):
497 if type(self) != type(other): return False
498 if self.wildcards != other.wildcards: return False
499 if self.in_port != other.in_port: return False
500 if self.eth_src != other.eth_src: return False
501 if self.eth_dst != other.eth_dst: return False
502 if self.vlan_vid != other.vlan_vid: return False
503 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700504 if self.eth_type != other.eth_type: return False
505 if self.ip_dscp != other.ip_dscp: return False
506 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700507 if self.ipv4_src != other.ipv4_src: return False
508 if self.ipv4_dst != other.ipv4_dst: return False
509 if self.tcp_src != other.tcp_src: return False
510 if self.tcp_dst != other.tcp_dst: return False
511 return True
512
513 def __ne__(self, other):
514 return not self.__eq__(other)
515
516 def show(self):
517 import loxi.pp
518 return loxi.pp.pp(self)
519
520 def pretty_print(self, q):
521 q.text("match_v1 {")
522 with q.group():
523 with q.indent(2):
524 q.breakable()
525 q.text("wildcards = ");
526 q.text(util.pretty_wildcards(self.wildcards))
527 q.text(","); q.breakable()
528 q.text("in_port = ");
529 q.text(util.pretty_port(self.in_port))
530 q.text(","); q.breakable()
531 q.text("eth_src = ");
532 q.text(util.pretty_mac(self.eth_src))
533 q.text(","); q.breakable()
534 q.text("eth_dst = ");
535 q.text(util.pretty_mac(self.eth_dst))
536 q.text(","); q.breakable()
537 q.text("vlan_vid = ");
538 q.text("%#x" % self.vlan_vid)
539 q.text(","); q.breakable()
540 q.text("vlan_pcp = ");
541 q.text("%#x" % self.vlan_pcp)
542 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700543 q.text("eth_type = ");
544 q.text("%#x" % self.eth_type)
545 q.text(","); q.breakable()
546 q.text("ip_dscp = ");
547 q.text("%#x" % self.ip_dscp)
548 q.text(","); q.breakable()
549 q.text("ip_proto = ");
550 q.text("%#x" % self.ip_proto)
551 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700552 q.text("ipv4_src = ");
553 q.text(util.pretty_ipv4(self.ipv4_src))
554 q.text(","); q.breakable()
555 q.text("ipv4_dst = ");
556 q.text(util.pretty_ipv4(self.ipv4_dst))
557 q.text(","); q.breakable()
558 q.text("tcp_src = ");
559 q.text("%#x" % self.tcp_src)
560 q.text(","); q.breakable()
561 q.text("tcp_dst = ");
562 q.text("%#x" % self.tcp_dst)
563 q.breakable()
564 q.text('}')
565
Rich Laneb658ddd2013-03-12 10:15:10 -0700566class packet_queue(object):
567
Rich Lanec2ee4b82013-04-24 17:12:38 -0700568 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700569 if queue_id != None:
570 self.queue_id = queue_id
571 else:
572 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700573 if properties != None:
574 self.properties = properties
575 else:
576 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700577 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700578
579 def pack(self):
580 packed = []
581 packed.append(struct.pack("!L", self.queue_id))
582 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700583 packed.append('\x00' * 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700584 packed.append(util.pack_list(self.properties))
Rich Laneb658ddd2013-03-12 10:15:10 -0700585 length = sum([len(x) for x in packed])
586 packed[1] = struct.pack("!H", length)
587 return ''.join(packed)
588
589 @staticmethod
590 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700591 obj = packet_queue()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700592 if type(buf) == loxi.generic_util.OFReader:
593 reader = buf
594 else:
595 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700596 obj.queue_id = reader.read("!L")[0]
597 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700598 reader.skip(2)
599 obj.properties = common.unpack_list_queue_prop(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700600 return obj
601
602 def __eq__(self, other):
603 if type(self) != type(other): return False
604 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700605 if self.properties != other.properties: return False
606 return True
607
608 def __ne__(self, other):
609 return not self.__eq__(other)
610
611 def show(self):
612 import loxi.pp
613 return loxi.pp.pp(self)
614
615 def pretty_print(self, q):
616 q.text("packet_queue {")
617 with q.group():
618 with q.indent(2):
619 q.breakable()
620 q.text("queue_id = ");
621 q.text("%#x" % self.queue_id)
622 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700623 q.text("properties = ");
624 q.pp(self.properties)
625 q.breakable()
626 q.text('}')
627
628class port_desc(object):
629
630 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
631 if port_no != None:
632 self.port_no = port_no
633 else:
634 self.port_no = 0
635 if hw_addr != None:
636 self.hw_addr = hw_addr
637 else:
638 self.hw_addr = [0,0,0,0,0,0]
639 if name != None:
640 self.name = name
641 else:
642 self.name = ""
643 if config != None:
644 self.config = config
645 else:
646 self.config = 0
647 if state != None:
648 self.state = state
649 else:
650 self.state = 0
651 if curr != None:
652 self.curr = curr
653 else:
654 self.curr = 0
655 if advertised != None:
656 self.advertised = advertised
657 else:
658 self.advertised = 0
659 if supported != None:
660 self.supported = supported
661 else:
662 self.supported = 0
663 if peer != None:
664 self.peer = peer
665 else:
666 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700667 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700668
669 def pack(self):
670 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700671 packed.append(util.pack_port_no(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -0700672 packed.append(struct.pack("!6B", *self.hw_addr))
673 packed.append(struct.pack("!16s", self.name))
674 packed.append(struct.pack("!L", self.config))
675 packed.append(struct.pack("!L", self.state))
676 packed.append(struct.pack("!L", self.curr))
677 packed.append(struct.pack("!L", self.advertised))
678 packed.append(struct.pack("!L", self.supported))
679 packed.append(struct.pack("!L", self.peer))
680 return ''.join(packed)
681
682 @staticmethod
683 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700684 obj = port_desc()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700685 if type(buf) == loxi.generic_util.OFReader:
686 reader = buf
687 else:
688 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700689 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700690 obj.hw_addr = list(reader.read('!6B'))
691 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700692 obj.config = reader.read("!L")[0]
693 obj.state = reader.read("!L")[0]
694 obj.curr = reader.read("!L")[0]
695 obj.advertised = reader.read("!L")[0]
696 obj.supported = reader.read("!L")[0]
697 obj.peer = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700698 return obj
699
700 def __eq__(self, other):
701 if type(self) != type(other): return False
702 if self.port_no != other.port_no: return False
703 if self.hw_addr != other.hw_addr: return False
704 if self.name != other.name: return False
705 if self.config != other.config: return False
706 if self.state != other.state: return False
707 if self.curr != other.curr: return False
708 if self.advertised != other.advertised: return False
709 if self.supported != other.supported: return False
710 if self.peer != other.peer: return False
711 return True
712
713 def __ne__(self, other):
714 return not self.__eq__(other)
715
716 def show(self):
717 import loxi.pp
718 return loxi.pp.pp(self)
719
720 def pretty_print(self, q):
721 q.text("port_desc {")
722 with q.group():
723 with q.indent(2):
724 q.breakable()
725 q.text("port_no = ");
726 q.text(util.pretty_port(self.port_no))
727 q.text(","); q.breakable()
728 q.text("hw_addr = ");
729 q.text(util.pretty_mac(self.hw_addr))
730 q.text(","); q.breakable()
731 q.text("name = ");
732 q.pp(self.name)
733 q.text(","); q.breakable()
734 q.text("config = ");
735 q.text("%#x" % self.config)
736 q.text(","); q.breakable()
737 q.text("state = ");
738 q.text("%#x" % self.state)
739 q.text(","); q.breakable()
740 q.text("curr = ");
741 q.text("%#x" % self.curr)
742 q.text(","); q.breakable()
743 q.text("advertised = ");
744 q.text("%#x" % self.advertised)
745 q.text(","); q.breakable()
746 q.text("supported = ");
747 q.text("%#x" % self.supported)
748 q.text(","); q.breakable()
749 q.text("peer = ");
750 q.text("%#x" % self.peer)
751 q.breakable()
752 q.text('}')
753
754class port_stats_entry(object):
755
Rich Lanec2ee4b82013-04-24 17:12:38 -0700756 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 -0700757 if port_no != None:
758 self.port_no = port_no
759 else:
760 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700761 if rx_packets != None:
762 self.rx_packets = rx_packets
763 else:
764 self.rx_packets = 0
765 if tx_packets != None:
766 self.tx_packets = tx_packets
767 else:
768 self.tx_packets = 0
769 if rx_bytes != None:
770 self.rx_bytes = rx_bytes
771 else:
772 self.rx_bytes = 0
773 if tx_bytes != None:
774 self.tx_bytes = tx_bytes
775 else:
776 self.tx_bytes = 0
777 if rx_dropped != None:
778 self.rx_dropped = rx_dropped
779 else:
780 self.rx_dropped = 0
781 if tx_dropped != None:
782 self.tx_dropped = tx_dropped
783 else:
784 self.tx_dropped = 0
785 if rx_errors != None:
786 self.rx_errors = rx_errors
787 else:
788 self.rx_errors = 0
789 if tx_errors != None:
790 self.tx_errors = tx_errors
791 else:
792 self.tx_errors = 0
793 if rx_frame_err != None:
794 self.rx_frame_err = rx_frame_err
795 else:
796 self.rx_frame_err = 0
797 if rx_over_err != None:
798 self.rx_over_err = rx_over_err
799 else:
800 self.rx_over_err = 0
801 if rx_crc_err != None:
802 self.rx_crc_err = rx_crc_err
803 else:
804 self.rx_crc_err = 0
805 if collisions != None:
806 self.collisions = collisions
807 else:
808 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700809 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700810
811 def pack(self):
812 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700813 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700814 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700815 packed.append(struct.pack("!Q", self.rx_packets))
816 packed.append(struct.pack("!Q", self.tx_packets))
817 packed.append(struct.pack("!Q", self.rx_bytes))
818 packed.append(struct.pack("!Q", self.tx_bytes))
819 packed.append(struct.pack("!Q", self.rx_dropped))
820 packed.append(struct.pack("!Q", self.tx_dropped))
821 packed.append(struct.pack("!Q", self.rx_errors))
822 packed.append(struct.pack("!Q", self.tx_errors))
823 packed.append(struct.pack("!Q", self.rx_frame_err))
824 packed.append(struct.pack("!Q", self.rx_over_err))
825 packed.append(struct.pack("!Q", self.rx_crc_err))
826 packed.append(struct.pack("!Q", self.collisions))
827 return ''.join(packed)
828
829 @staticmethod
830 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700831 obj = port_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700832 if type(buf) == loxi.generic_util.OFReader:
833 reader = buf
834 else:
835 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700836 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700837 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700838 obj.rx_packets = reader.read("!Q")[0]
839 obj.tx_packets = reader.read("!Q")[0]
840 obj.rx_bytes = reader.read("!Q")[0]
841 obj.tx_bytes = reader.read("!Q")[0]
842 obj.rx_dropped = reader.read("!Q")[0]
843 obj.tx_dropped = reader.read("!Q")[0]
844 obj.rx_errors = reader.read("!Q")[0]
845 obj.tx_errors = reader.read("!Q")[0]
846 obj.rx_frame_err = reader.read("!Q")[0]
847 obj.rx_over_err = reader.read("!Q")[0]
848 obj.rx_crc_err = reader.read("!Q")[0]
849 obj.collisions = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700850 return obj
851
852 def __eq__(self, other):
853 if type(self) != type(other): return False
854 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700855 if self.rx_packets != other.rx_packets: return False
856 if self.tx_packets != other.tx_packets: return False
857 if self.rx_bytes != other.rx_bytes: return False
858 if self.tx_bytes != other.tx_bytes: return False
859 if self.rx_dropped != other.rx_dropped: return False
860 if self.tx_dropped != other.tx_dropped: return False
861 if self.rx_errors != other.rx_errors: return False
862 if self.tx_errors != other.tx_errors: return False
863 if self.rx_frame_err != other.rx_frame_err: return False
864 if self.rx_over_err != other.rx_over_err: return False
865 if self.rx_crc_err != other.rx_crc_err: return False
866 if self.collisions != other.collisions: return False
867 return True
868
869 def __ne__(self, other):
870 return not self.__eq__(other)
871
872 def show(self):
873 import loxi.pp
874 return loxi.pp.pp(self)
875
876 def pretty_print(self, q):
877 q.text("port_stats_entry {")
878 with q.group():
879 with q.indent(2):
880 q.breakable()
881 q.text("port_no = ");
882 q.text(util.pretty_port(self.port_no))
883 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700884 q.text("rx_packets = ");
885 q.text("%#x" % self.rx_packets)
886 q.text(","); q.breakable()
887 q.text("tx_packets = ");
888 q.text("%#x" % self.tx_packets)
889 q.text(","); q.breakable()
890 q.text("rx_bytes = ");
891 q.text("%#x" % self.rx_bytes)
892 q.text(","); q.breakable()
893 q.text("tx_bytes = ");
894 q.text("%#x" % self.tx_bytes)
895 q.text(","); q.breakable()
896 q.text("rx_dropped = ");
897 q.text("%#x" % self.rx_dropped)
898 q.text(","); q.breakable()
899 q.text("tx_dropped = ");
900 q.text("%#x" % self.tx_dropped)
901 q.text(","); q.breakable()
902 q.text("rx_errors = ");
903 q.text("%#x" % self.rx_errors)
904 q.text(","); q.breakable()
905 q.text("tx_errors = ");
906 q.text("%#x" % self.tx_errors)
907 q.text(","); q.breakable()
908 q.text("rx_frame_err = ");
909 q.text("%#x" % self.rx_frame_err)
910 q.text(","); q.breakable()
911 q.text("rx_over_err = ");
912 q.text("%#x" % self.rx_over_err)
913 q.text(","); q.breakable()
914 q.text("rx_crc_err = ");
915 q.text("%#x" % self.rx_crc_err)
916 q.text(","); q.breakable()
917 q.text("collisions = ");
918 q.text("%#x" % self.collisions)
919 q.breakable()
920 q.text('}')
921
922class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -0700923 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -0700924
Rich Lanec2ee4b82013-04-24 17:12:38 -0700925 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700926 if rate != None:
927 self.rate = rate
928 else:
929 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700930 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700931
932 def pack(self):
933 packed = []
934 packed.append(struct.pack("!H", self.type))
935 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700936 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700937 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700938 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700939 length = sum([len(x) for x in packed])
940 packed[1] = struct.pack("!H", length)
941 return ''.join(packed)
942
943 @staticmethod
944 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700945 obj = queue_prop_min_rate()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700946 if type(buf) == loxi.generic_util.OFReader:
947 reader = buf
948 else:
949 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700950 _type = reader.read("!H")[0]
951 assert(_type == 1)
952 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700953 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700954 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700955 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700956 return obj
957
958 def __eq__(self, other):
959 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700960 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700961 return True
962
963 def __ne__(self, other):
964 return not self.__eq__(other)
965
966 def show(self):
967 import loxi.pp
968 return loxi.pp.pp(self)
969
970 def pretty_print(self, q):
971 q.text("queue_prop_min_rate {")
972 with q.group():
973 with q.indent(2):
974 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700975 q.text("rate = ");
976 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -0700977 q.breakable()
978 q.text('}')
979
980class queue_stats_entry(object):
981
Rich Lanec2ee4b82013-04-24 17:12:38 -0700982 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 -0700983 if port_no != None:
984 self.port_no = port_no
985 else:
986 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700987 if queue_id != None:
988 self.queue_id = queue_id
989 else:
990 self.queue_id = 0
991 if tx_bytes != None:
992 self.tx_bytes = tx_bytes
993 else:
994 self.tx_bytes = 0
995 if tx_packets != None:
996 self.tx_packets = tx_packets
997 else:
998 self.tx_packets = 0
999 if tx_errors != None:
1000 self.tx_errors = tx_errors
1001 else:
1002 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001003 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001004
1005 def pack(self):
1006 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001007 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001008 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07001009 packed.append(struct.pack("!L", self.queue_id))
1010 packed.append(struct.pack("!Q", self.tx_bytes))
1011 packed.append(struct.pack("!Q", self.tx_packets))
1012 packed.append(struct.pack("!Q", self.tx_errors))
1013 return ''.join(packed)
1014
1015 @staticmethod
1016 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001017 obj = queue_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001018 if type(buf) == loxi.generic_util.OFReader:
1019 reader = buf
1020 else:
1021 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001022 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001023 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -07001024 obj.queue_id = reader.read("!L")[0]
1025 obj.tx_bytes = reader.read("!Q")[0]
1026 obj.tx_packets = reader.read("!Q")[0]
1027 obj.tx_errors = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001028 return obj
1029
1030 def __eq__(self, other):
1031 if type(self) != type(other): return False
1032 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001033 if self.queue_id != other.queue_id: return False
1034 if self.tx_bytes != other.tx_bytes: return False
1035 if self.tx_packets != other.tx_packets: return False
1036 if self.tx_errors != other.tx_errors: return False
1037 return True
1038
1039 def __ne__(self, other):
1040 return not self.__eq__(other)
1041
1042 def show(self):
1043 import loxi.pp
1044 return loxi.pp.pp(self)
1045
1046 def pretty_print(self, q):
1047 q.text("queue_stats_entry {")
1048 with q.group():
1049 with q.indent(2):
1050 q.breakable()
1051 q.text("port_no = ");
1052 q.text(util.pretty_port(self.port_no))
1053 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001054 q.text("queue_id = ");
1055 q.text("%#x" % self.queue_id)
1056 q.text(","); q.breakable()
1057 q.text("tx_bytes = ");
1058 q.text("%#x" % self.tx_bytes)
1059 q.text(","); q.breakable()
1060 q.text("tx_packets = ");
1061 q.text("%#x" % self.tx_packets)
1062 q.text(","); q.breakable()
1063 q.text("tx_errors = ");
1064 q.text("%#x" % self.tx_errors)
1065 q.breakable()
1066 q.text('}')
1067
1068class table_stats_entry(object):
1069
Rich Lanec2ee4b82013-04-24 17:12:38 -07001070 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 -07001071 if table_id != None:
1072 self.table_id = table_id
1073 else:
1074 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001075 if name != None:
1076 self.name = name
1077 else:
1078 self.name = ""
1079 if wildcards != None:
1080 self.wildcards = wildcards
1081 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001082 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -07001083 if max_entries != None:
1084 self.max_entries = max_entries
1085 else:
1086 self.max_entries = 0
1087 if active_count != None:
1088 self.active_count = active_count
1089 else:
1090 self.active_count = 0
1091 if lookup_count != None:
1092 self.lookup_count = lookup_count
1093 else:
1094 self.lookup_count = 0
1095 if matched_count != None:
1096 self.matched_count = matched_count
1097 else:
1098 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001099 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001100
1101 def pack(self):
1102 packed = []
1103 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001104 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001105 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001106 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Laneb658ddd2013-03-12 10:15:10 -07001107 packed.append(struct.pack("!L", self.max_entries))
1108 packed.append(struct.pack("!L", self.active_count))
1109 packed.append(struct.pack("!Q", self.lookup_count))
1110 packed.append(struct.pack("!Q", self.matched_count))
1111 return ''.join(packed)
1112
1113 @staticmethod
1114 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001115 obj = table_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001116 if type(buf) == loxi.generic_util.OFReader:
1117 reader = buf
1118 else:
1119 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001120 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001121 reader.skip(3)
1122 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001123 obj.wildcards = util.unpack_wc_bmap(reader)
1124 obj.max_entries = reader.read("!L")[0]
1125 obj.active_count = reader.read("!L")[0]
1126 obj.lookup_count = reader.read("!Q")[0]
1127 obj.matched_count = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001128 return obj
1129
1130 def __eq__(self, other):
1131 if type(self) != type(other): return False
1132 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001133 if self.name != other.name: return False
1134 if self.wildcards != other.wildcards: return False
1135 if self.max_entries != other.max_entries: return False
1136 if self.active_count != other.active_count: return False
1137 if self.lookup_count != other.lookup_count: return False
1138 if self.matched_count != other.matched_count: return False
1139 return True
1140
1141 def __ne__(self, other):
1142 return not self.__eq__(other)
1143
1144 def show(self):
1145 import loxi.pp
1146 return loxi.pp.pp(self)
1147
1148 def pretty_print(self, q):
1149 q.text("table_stats_entry {")
1150 with q.group():
1151 with q.indent(2):
1152 q.breakable()
1153 q.text("table_id = ");
1154 q.text("%#x" % self.table_id)
1155 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001156 q.text("name = ");
1157 q.pp(self.name)
1158 q.text(","); q.breakable()
1159 q.text("wildcards = ");
1160 q.text(util.pretty_wildcards(self.wildcards))
1161 q.text(","); q.breakable()
1162 q.text("max_entries = ");
1163 q.text("%#x" % self.max_entries)
1164 q.text(","); q.breakable()
1165 q.text("active_count = ");
1166 q.text("%#x" % self.active_count)
1167 q.text(","); q.breakable()
1168 q.text("lookup_count = ");
1169 q.text("%#x" % self.lookup_count)
1170 q.text(","); q.breakable()
1171 q.text("matched_count = ");
1172 q.text("%#x" % self.matched_count)
1173 q.breakable()
1174 q.text('}')
1175
Rich Lanec2ee4b82013-04-24 17:12:38 -07001176
1177match = match_v1