blob: 481b686db76089a75f566372d019de6d12c6b529 [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# Automatically generated by LOXI from template common.py
6# Do not modify
7
8import sys
9import struct
10import action
11import const
12import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070013import loxi.generic_util
14
Rich Laneb658ddd2013-03-12 10:15:10 -070015
16# HACK make this module visible as 'common' to simplify code generation
17common = sys.modules[__name__]
18
Rich Lanec2ee4b82013-04-24 17:12:38 -070019def unpack_list_flow_stats_entry(reader):
20 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -070021
Rich Lanec2ee4b82013-04-24 17:12:38 -070022def unpack_list_queue_prop(reader):
23 def deserializer(reader, typ):
24 if typ == const.OFPQT_MIN_RATE:
25 return queue_prop_min_rate.unpack(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -070026 else:
Rich Lanec2ee4b82013-04-24 17:12:38 -070027 raise loxi.ProtocolError("unknown queue prop %d" % typ)
28 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
Rich Laneb658ddd2013-03-12 10:15:10 -070029
Rich Lanec2ee4b82013-04-24 17:12:38 -070030def unpack_list_packet_queue(reader):
31 def wrapper(reader):
32 length, = reader.peek('!4xH')
33 return packet_queue.unpack(reader.slice(length))
34 return loxi.generic_util.unpack_list(reader, wrapper)
35
36def unpack_list_hello_elem(reader):
37 def deserializer(reader, typ):
38 if typ == const.OFPHET_VERSIONBITMAP:
39 return hello_elem_versionbitmap.unpack(reader)
40 else:
41 return None
42 return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
43
44def unpack_list_bucket(reader):
45 return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
46
47def unpack_list_group_desc_stats_entry(reader):
48 return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
49
50def unpack_list_group_stats_entry(reader):
51 return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
52
53def unpack_list_meter_stats(reader):
54 def wrapper(reader):
55 length, = reader.peek('!4xH')
56 return meter_stats.unpack(reader.slice(length))
57 return loxi.generic_util.unpack_list(reader, wrapper)
Rich Laneb658ddd2013-03-12 10:15:10 -070058
59class bsn_interface(object):
60
Rich Lanec2ee4b82013-04-24 17:12:38 -070061 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070062 if hw_addr != None:
63 self.hw_addr = hw_addr
64 else:
65 self.hw_addr = [0,0,0,0,0,0]
Rich Laneb658ddd2013-03-12 10:15:10 -070066 if name != None:
67 self.name = name
68 else:
69 self.name = ""
70 if ipv4_addr != None:
71 self.ipv4_addr = ipv4_addr
72 else:
73 self.ipv4_addr = 0
74 if ipv4_netmask != None:
75 self.ipv4_netmask = ipv4_netmask
76 else:
77 self.ipv4_netmask = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -070078 return
Rich Laneb658ddd2013-03-12 10:15:10 -070079
80 def pack(self):
81 packed = []
82 packed.append(struct.pack("!6B", *self.hw_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -070083 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -070084 packed.append(struct.pack("!16s", self.name))
85 packed.append(struct.pack("!L", self.ipv4_addr))
86 packed.append(struct.pack("!L", self.ipv4_netmask))
87 return ''.join(packed)
88
89 @staticmethod
90 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -070091 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070092 if type(buf) == loxi.generic_util.OFReader:
93 reader = buf
94 else:
95 reader = loxi.generic_util.OFReader(buf)
96 obj.hw_addr = list(reader.read('!6B'))
97 reader.skip(2)
98 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -070099 obj.ipv4_addr = reader.read("!L")[0]
100 obj.ipv4_netmask = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700101 return obj
102
103 def __eq__(self, other):
104 if type(self) != type(other): return False
105 if self.hw_addr != other.hw_addr: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700106 if self.name != other.name: return False
107 if self.ipv4_addr != other.ipv4_addr: return False
108 if self.ipv4_netmask != other.ipv4_netmask: return False
109 return True
110
111 def __ne__(self, other):
112 return not self.__eq__(other)
113
114 def show(self):
115 import loxi.pp
116 return loxi.pp.pp(self)
117
118 def pretty_print(self, q):
119 q.text("bsn_interface {")
120 with q.group():
121 with q.indent(2):
122 q.breakable()
123 q.text("hw_addr = ");
124 q.text(util.pretty_mac(self.hw_addr))
125 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700126 q.text("name = ");
127 q.pp(self.name)
128 q.text(","); q.breakable()
129 q.text("ipv4_addr = ");
130 q.text(util.pretty_ipv4(self.ipv4_addr))
131 q.text(","); q.breakable()
132 q.text("ipv4_netmask = ");
133 q.text(util.pretty_ipv4(self.ipv4_netmask))
134 q.breakable()
135 q.text('}')
136
Dan Talaycof6202252013-07-02 01:00:29 -0700137class bsn_vport_q_in_q(object):
138 type = 0
139
Kiran Poola150d8b02013-09-20 13:30:39 -0700140 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 -0700141 if port_no != None:
142 self.port_no = port_no
143 else:
144 self.port_no = 0
145 if ingress_tpid != None:
146 self.ingress_tpid = ingress_tpid
147 else:
148 self.ingress_tpid = 0
149 if ingress_vlan_id != None:
150 self.ingress_vlan_id = ingress_vlan_id
151 else:
152 self.ingress_vlan_id = 0
153 if egress_tpid != None:
154 self.egress_tpid = egress_tpid
155 else:
156 self.egress_tpid = 0
157 if egress_vlan_id != None:
158 self.egress_vlan_id = egress_vlan_id
159 else:
160 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700161 if if_name != None:
162 self.if_name = if_name
163 else:
164 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700165 return
166
167 def pack(self):
168 packed = []
169 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700170 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700171 packed.append(struct.pack("!L", self.port_no))
172 packed.append(struct.pack("!H", self.ingress_tpid))
173 packed.append(struct.pack("!H", self.ingress_vlan_id))
174 packed.append(struct.pack("!H", self.egress_tpid))
175 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700176 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700177 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700178 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700179 return ''.join(packed)
180
181 @staticmethod
182 def unpack(buf):
183 obj = bsn_vport_q_in_q()
184 if type(buf) == loxi.generic_util.OFReader:
185 reader = buf
186 else:
187 reader = loxi.generic_util.OFReader(buf)
188 _type = reader.read("!H")[0]
189 assert(_type == 0)
190 _length = reader.read("!H")[0]
191 obj.port_no = reader.read("!L")[0]
192 obj.ingress_tpid = reader.read("!H")[0]
193 obj.ingress_vlan_id = reader.read("!H")[0]
194 obj.egress_tpid = reader.read("!H")[0]
195 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700196 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700197 return obj
198
199 def __eq__(self, other):
200 if type(self) != type(other): return False
201 if self.port_no != other.port_no: return False
202 if self.ingress_tpid != other.ingress_tpid: return False
203 if self.ingress_vlan_id != other.ingress_vlan_id: return False
204 if self.egress_tpid != other.egress_tpid: return False
205 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700206 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700207 return True
208
209 def __ne__(self, other):
210 return not self.__eq__(other)
211
212 def show(self):
213 import loxi.pp
214 return loxi.pp.pp(self)
215
216 def pretty_print(self, q):
217 q.text("bsn_vport_q_in_q {")
218 with q.group():
219 with q.indent(2):
220 q.breakable()
221 q.text("port_no = ");
222 q.text("%#x" % self.port_no)
223 q.text(","); q.breakable()
224 q.text("ingress_tpid = ");
225 q.text("%#x" % self.ingress_tpid)
226 q.text(","); q.breakable()
227 q.text("ingress_vlan_id = ");
228 q.text("%#x" % self.ingress_vlan_id)
229 q.text(","); q.breakable()
230 q.text("egress_tpid = ");
231 q.text("%#x" % self.egress_tpid)
232 q.text(","); q.breakable()
233 q.text("egress_vlan_id = ");
234 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700235 q.text(","); q.breakable()
236 q.text("if_name = ");
237 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700238 q.breakable()
239 q.text('}')
240
Rich Laneb658ddd2013-03-12 10:15:10 -0700241class flow_stats_entry(object):
242
Rich Lanec2ee4b82013-04-24 17:12:38 -0700243 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 -0700244 if table_id != None:
245 self.table_id = table_id
246 else:
247 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700248 if match != None:
249 self.match = match
250 else:
251 self.match = common.match()
252 if duration_sec != None:
253 self.duration_sec = duration_sec
254 else:
255 self.duration_sec = 0
256 if duration_nsec != None:
257 self.duration_nsec = duration_nsec
258 else:
259 self.duration_nsec = 0
260 if priority != None:
261 self.priority = priority
262 else:
263 self.priority = 0
264 if idle_timeout != None:
265 self.idle_timeout = idle_timeout
266 else:
267 self.idle_timeout = 0
268 if hard_timeout != None:
269 self.hard_timeout = hard_timeout
270 else:
271 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700272 if cookie != None:
273 self.cookie = cookie
274 else:
275 self.cookie = 0
276 if packet_count != None:
277 self.packet_count = packet_count
278 else:
279 self.packet_count = 0
280 if byte_count != None:
281 self.byte_count = byte_count
282 else:
283 self.byte_count = 0
284 if actions != None:
285 self.actions = actions
286 else:
287 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700288 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700289
290 def pack(self):
291 packed = []
292 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
293 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700294 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700295 packed.append(self.match.pack())
296 packed.append(struct.pack("!L", self.duration_sec))
297 packed.append(struct.pack("!L", self.duration_nsec))
298 packed.append(struct.pack("!H", self.priority))
299 packed.append(struct.pack("!H", self.idle_timeout))
300 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700301 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700302 packed.append(struct.pack("!Q", self.cookie))
303 packed.append(struct.pack("!Q", self.packet_count))
304 packed.append(struct.pack("!Q", self.byte_count))
Dan Talaycof6202252013-07-02 01:00:29 -0700305 packed.append(util.pack_list(self.actions))
Rich Laneb658ddd2013-03-12 10:15:10 -0700306 length = sum([len(x) for x in packed])
307 packed[0] = struct.pack("!H", length)
308 return ''.join(packed)
309
310 @staticmethod
311 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700312 obj = flow_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700313 if type(buf) == loxi.generic_util.OFReader:
314 reader = buf
315 else:
316 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700317 _length = reader.read("!H")[0]
318 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700319 reader.skip(1)
320 obj.match = common.match.unpack(reader)
Dan Talaycof6202252013-07-02 01:00:29 -0700321 obj.duration_sec = reader.read("!L")[0]
322 obj.duration_nsec = reader.read("!L")[0]
323 obj.priority = reader.read("!H")[0]
324 obj.idle_timeout = reader.read("!H")[0]
325 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700326 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700327 obj.cookie = reader.read("!Q")[0]
328 obj.packet_count = reader.read("!Q")[0]
329 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700330 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700331 return obj
332
333 def __eq__(self, other):
334 if type(self) != type(other): return False
335 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700336 if self.match != other.match: return False
337 if self.duration_sec != other.duration_sec: return False
338 if self.duration_nsec != other.duration_nsec: return False
339 if self.priority != other.priority: return False
340 if self.idle_timeout != other.idle_timeout: return False
341 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700342 if self.cookie != other.cookie: return False
343 if self.packet_count != other.packet_count: return False
344 if self.byte_count != other.byte_count: return False
345 if self.actions != other.actions: return False
346 return True
347
348 def __ne__(self, other):
349 return not self.__eq__(other)
350
351 def show(self):
352 import loxi.pp
353 return loxi.pp.pp(self)
354
355 def pretty_print(self, q):
356 q.text("flow_stats_entry {")
357 with q.group():
358 with q.indent(2):
359 q.breakable()
360 q.text("table_id = ");
361 q.text("%#x" % self.table_id)
362 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700363 q.text("match = ");
364 q.pp(self.match)
365 q.text(","); q.breakable()
366 q.text("duration_sec = ");
367 q.text("%#x" % self.duration_sec)
368 q.text(","); q.breakable()
369 q.text("duration_nsec = ");
370 q.text("%#x" % self.duration_nsec)
371 q.text(","); q.breakable()
372 q.text("priority = ");
373 q.text("%#x" % self.priority)
374 q.text(","); q.breakable()
375 q.text("idle_timeout = ");
376 q.text("%#x" % self.idle_timeout)
377 q.text(","); q.breakable()
378 q.text("hard_timeout = ");
379 q.text("%#x" % self.hard_timeout)
380 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700381 q.text("cookie = ");
382 q.text("%#x" % self.cookie)
383 q.text(","); q.breakable()
384 q.text("packet_count = ");
385 q.text("%#x" % self.packet_count)
386 q.text(","); q.breakable()
387 q.text("byte_count = ");
388 q.text("%#x" % self.byte_count)
389 q.text(","); q.breakable()
390 q.text("actions = ");
391 q.pp(self.actions)
392 q.breakable()
393 q.text('}')
394
395class match_v1(object):
396
Rich Lanefe600f52013-07-09 13:22:32 -0700397 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 -0700398 if wildcards != None:
399 self.wildcards = wildcards
400 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700401 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -0700402 if in_port != None:
403 self.in_port = in_port
404 else:
405 self.in_port = 0
406 if eth_src != None:
407 self.eth_src = eth_src
408 else:
409 self.eth_src = [0,0,0,0,0,0]
410 if eth_dst != None:
411 self.eth_dst = eth_dst
412 else:
413 self.eth_dst = [0,0,0,0,0,0]
414 if vlan_vid != None:
415 self.vlan_vid = vlan_vid
416 else:
417 self.vlan_vid = 0
418 if vlan_pcp != None:
419 self.vlan_pcp = vlan_pcp
420 else:
421 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700422 if eth_type != None:
423 self.eth_type = eth_type
424 else:
425 self.eth_type = 0
426 if ip_dscp != None:
427 self.ip_dscp = ip_dscp
428 else:
429 self.ip_dscp = 0
430 if ip_proto != None:
431 self.ip_proto = ip_proto
432 else:
433 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700434 if ipv4_src != None:
435 self.ipv4_src = ipv4_src
436 else:
437 self.ipv4_src = 0
438 if ipv4_dst != None:
439 self.ipv4_dst = ipv4_dst
440 else:
441 self.ipv4_dst = 0
442 if tcp_src != None:
443 self.tcp_src = tcp_src
444 else:
445 self.tcp_src = 0
446 if tcp_dst != None:
447 self.tcp_dst = tcp_dst
448 else:
449 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700450 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700451
452 def pack(self):
453 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700454 packed.append(util.pack_wc_bmap(self.wildcards))
455 packed.append(util.pack_port_no(self.in_port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700456 packed.append(struct.pack("!6B", *self.eth_src))
457 packed.append(struct.pack("!6B", *self.eth_dst))
458 packed.append(struct.pack("!H", self.vlan_vid))
459 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700460 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700461 packed.append(struct.pack("!H", self.eth_type))
462 packed.append(struct.pack("!B", self.ip_dscp))
463 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanefe600f52013-07-09 13:22:32 -0700464 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700465 packed.append(struct.pack("!L", self.ipv4_src))
466 packed.append(struct.pack("!L", self.ipv4_dst))
467 packed.append(struct.pack("!H", self.tcp_src))
468 packed.append(struct.pack("!H", self.tcp_dst))
469 return ''.join(packed)
470
471 @staticmethod
472 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700473 obj = match_v1()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700474 if type(buf) == loxi.generic_util.OFReader:
475 reader = buf
476 else:
477 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700478 obj.wildcards = util.unpack_wc_bmap(reader)
479 obj.in_port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700480 obj.eth_src = list(reader.read('!6B'))
481 obj.eth_dst = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700482 obj.vlan_vid = reader.read("!H")[0]
483 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700484 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700485 obj.eth_type = reader.read("!H")[0]
486 obj.ip_dscp = reader.read("!B")[0]
487 obj.ip_proto = reader.read("!B")[0]
Rich Lanefe600f52013-07-09 13:22:32 -0700488 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700489 obj.ipv4_src = reader.read("!L")[0]
490 obj.ipv4_dst = reader.read("!L")[0]
491 obj.tcp_src = reader.read("!H")[0]
492 obj.tcp_dst = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700493 return obj
494
495 def __eq__(self, other):
496 if type(self) != type(other): return False
497 if self.wildcards != other.wildcards: return False
498 if self.in_port != other.in_port: return False
499 if self.eth_src != other.eth_src: return False
500 if self.eth_dst != other.eth_dst: return False
501 if self.vlan_vid != other.vlan_vid: return False
502 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700503 if self.eth_type != other.eth_type: return False
504 if self.ip_dscp != other.ip_dscp: return False
505 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700506 if self.ipv4_src != other.ipv4_src: return False
507 if self.ipv4_dst != other.ipv4_dst: return False
508 if self.tcp_src != other.tcp_src: return False
509 if self.tcp_dst != other.tcp_dst: return False
510 return True
511
512 def __ne__(self, other):
513 return not self.__eq__(other)
514
515 def show(self):
516 import loxi.pp
517 return loxi.pp.pp(self)
518
519 def pretty_print(self, q):
520 q.text("match_v1 {")
521 with q.group():
522 with q.indent(2):
523 q.breakable()
524 q.text("wildcards = ");
525 q.text(util.pretty_wildcards(self.wildcards))
526 q.text(","); q.breakable()
527 q.text("in_port = ");
528 q.text(util.pretty_port(self.in_port))
529 q.text(","); q.breakable()
530 q.text("eth_src = ");
531 q.text(util.pretty_mac(self.eth_src))
532 q.text(","); q.breakable()
533 q.text("eth_dst = ");
534 q.text(util.pretty_mac(self.eth_dst))
535 q.text(","); q.breakable()
536 q.text("vlan_vid = ");
537 q.text("%#x" % self.vlan_vid)
538 q.text(","); q.breakable()
539 q.text("vlan_pcp = ");
540 q.text("%#x" % self.vlan_pcp)
541 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700542 q.text("eth_type = ");
543 q.text("%#x" % self.eth_type)
544 q.text(","); q.breakable()
545 q.text("ip_dscp = ");
546 q.text("%#x" % self.ip_dscp)
547 q.text(","); q.breakable()
548 q.text("ip_proto = ");
549 q.text("%#x" % self.ip_proto)
550 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700551 q.text("ipv4_src = ");
552 q.text(util.pretty_ipv4(self.ipv4_src))
553 q.text(","); q.breakable()
554 q.text("ipv4_dst = ");
555 q.text(util.pretty_ipv4(self.ipv4_dst))
556 q.text(","); q.breakable()
557 q.text("tcp_src = ");
558 q.text("%#x" % self.tcp_src)
559 q.text(","); q.breakable()
560 q.text("tcp_dst = ");
561 q.text("%#x" % self.tcp_dst)
562 q.breakable()
563 q.text('}')
564
Rich Laneb658ddd2013-03-12 10:15:10 -0700565class packet_queue(object):
566
Rich Lanec2ee4b82013-04-24 17:12:38 -0700567 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700568 if queue_id != None:
569 self.queue_id = queue_id
570 else:
571 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700572 if properties != None:
573 self.properties = properties
574 else:
575 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700576 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700577
578 def pack(self):
579 packed = []
580 packed.append(struct.pack("!L", self.queue_id))
581 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700582 packed.append('\x00' * 2)
Dan Talaycof6202252013-07-02 01:00:29 -0700583 packed.append(util.pack_list(self.properties))
Rich Laneb658ddd2013-03-12 10:15:10 -0700584 length = sum([len(x) for x in packed])
585 packed[1] = struct.pack("!H", length)
586 return ''.join(packed)
587
588 @staticmethod
589 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700590 obj = packet_queue()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700591 if type(buf) == loxi.generic_util.OFReader:
592 reader = buf
593 else:
594 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700595 obj.queue_id = reader.read("!L")[0]
596 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700597 reader.skip(2)
598 obj.properties = common.unpack_list_queue_prop(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700599 return obj
600
601 def __eq__(self, other):
602 if type(self) != type(other): return False
603 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700604 if self.properties != other.properties: return False
605 return True
606
607 def __ne__(self, other):
608 return not self.__eq__(other)
609
610 def show(self):
611 import loxi.pp
612 return loxi.pp.pp(self)
613
614 def pretty_print(self, q):
615 q.text("packet_queue {")
616 with q.group():
617 with q.indent(2):
618 q.breakable()
619 q.text("queue_id = ");
620 q.text("%#x" % self.queue_id)
621 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700622 q.text("properties = ");
623 q.pp(self.properties)
624 q.breakable()
625 q.text('}')
626
627class port_desc(object):
628
629 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
630 if port_no != None:
631 self.port_no = port_no
632 else:
633 self.port_no = 0
634 if hw_addr != None:
635 self.hw_addr = hw_addr
636 else:
637 self.hw_addr = [0,0,0,0,0,0]
638 if name != None:
639 self.name = name
640 else:
641 self.name = ""
642 if config != None:
643 self.config = config
644 else:
645 self.config = 0
646 if state != None:
647 self.state = state
648 else:
649 self.state = 0
650 if curr != None:
651 self.curr = curr
652 else:
653 self.curr = 0
654 if advertised != None:
655 self.advertised = advertised
656 else:
657 self.advertised = 0
658 if supported != None:
659 self.supported = supported
660 else:
661 self.supported = 0
662 if peer != None:
663 self.peer = peer
664 else:
665 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700666 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700667
668 def pack(self):
669 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700670 packed.append(util.pack_port_no(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -0700671 packed.append(struct.pack("!6B", *self.hw_addr))
672 packed.append(struct.pack("!16s", self.name))
673 packed.append(struct.pack("!L", self.config))
674 packed.append(struct.pack("!L", self.state))
675 packed.append(struct.pack("!L", self.curr))
676 packed.append(struct.pack("!L", self.advertised))
677 packed.append(struct.pack("!L", self.supported))
678 packed.append(struct.pack("!L", self.peer))
679 return ''.join(packed)
680
681 @staticmethod
682 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700683 obj = port_desc()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700684 if type(buf) == loxi.generic_util.OFReader:
685 reader = buf
686 else:
687 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700688 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700689 obj.hw_addr = list(reader.read('!6B'))
690 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700691 obj.config = reader.read("!L")[0]
692 obj.state = reader.read("!L")[0]
693 obj.curr = reader.read("!L")[0]
694 obj.advertised = reader.read("!L")[0]
695 obj.supported = reader.read("!L")[0]
696 obj.peer = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700697 return obj
698
699 def __eq__(self, other):
700 if type(self) != type(other): return False
701 if self.port_no != other.port_no: return False
702 if self.hw_addr != other.hw_addr: return False
703 if self.name != other.name: return False
704 if self.config != other.config: return False
705 if self.state != other.state: return False
706 if self.curr != other.curr: return False
707 if self.advertised != other.advertised: return False
708 if self.supported != other.supported: return False
709 if self.peer != other.peer: return False
710 return True
711
712 def __ne__(self, other):
713 return not self.__eq__(other)
714
715 def show(self):
716 import loxi.pp
717 return loxi.pp.pp(self)
718
719 def pretty_print(self, q):
720 q.text("port_desc {")
721 with q.group():
722 with q.indent(2):
723 q.breakable()
724 q.text("port_no = ");
725 q.text(util.pretty_port(self.port_no))
726 q.text(","); q.breakable()
727 q.text("hw_addr = ");
728 q.text(util.pretty_mac(self.hw_addr))
729 q.text(","); q.breakable()
730 q.text("name = ");
731 q.pp(self.name)
732 q.text(","); q.breakable()
733 q.text("config = ");
734 q.text("%#x" % self.config)
735 q.text(","); q.breakable()
736 q.text("state = ");
737 q.text("%#x" % self.state)
738 q.text(","); q.breakable()
739 q.text("curr = ");
740 q.text("%#x" % self.curr)
741 q.text(","); q.breakable()
742 q.text("advertised = ");
743 q.text("%#x" % self.advertised)
744 q.text(","); q.breakable()
745 q.text("supported = ");
746 q.text("%#x" % self.supported)
747 q.text(","); q.breakable()
748 q.text("peer = ");
749 q.text("%#x" % self.peer)
750 q.breakable()
751 q.text('}')
752
753class port_stats_entry(object):
754
Rich Lanec2ee4b82013-04-24 17:12:38 -0700755 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 -0700756 if port_no != None:
757 self.port_no = port_no
758 else:
759 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700760 if rx_packets != None:
761 self.rx_packets = rx_packets
762 else:
763 self.rx_packets = 0
764 if tx_packets != None:
765 self.tx_packets = tx_packets
766 else:
767 self.tx_packets = 0
768 if rx_bytes != None:
769 self.rx_bytes = rx_bytes
770 else:
771 self.rx_bytes = 0
772 if tx_bytes != None:
773 self.tx_bytes = tx_bytes
774 else:
775 self.tx_bytes = 0
776 if rx_dropped != None:
777 self.rx_dropped = rx_dropped
778 else:
779 self.rx_dropped = 0
780 if tx_dropped != None:
781 self.tx_dropped = tx_dropped
782 else:
783 self.tx_dropped = 0
784 if rx_errors != None:
785 self.rx_errors = rx_errors
786 else:
787 self.rx_errors = 0
788 if tx_errors != None:
789 self.tx_errors = tx_errors
790 else:
791 self.tx_errors = 0
792 if rx_frame_err != None:
793 self.rx_frame_err = rx_frame_err
794 else:
795 self.rx_frame_err = 0
796 if rx_over_err != None:
797 self.rx_over_err = rx_over_err
798 else:
799 self.rx_over_err = 0
800 if rx_crc_err != None:
801 self.rx_crc_err = rx_crc_err
802 else:
803 self.rx_crc_err = 0
804 if collisions != None:
805 self.collisions = collisions
806 else:
807 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700808 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700809
810 def pack(self):
811 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700812 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700813 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700814 packed.append(struct.pack("!Q", self.rx_packets))
815 packed.append(struct.pack("!Q", self.tx_packets))
816 packed.append(struct.pack("!Q", self.rx_bytes))
817 packed.append(struct.pack("!Q", self.tx_bytes))
818 packed.append(struct.pack("!Q", self.rx_dropped))
819 packed.append(struct.pack("!Q", self.tx_dropped))
820 packed.append(struct.pack("!Q", self.rx_errors))
821 packed.append(struct.pack("!Q", self.tx_errors))
822 packed.append(struct.pack("!Q", self.rx_frame_err))
823 packed.append(struct.pack("!Q", self.rx_over_err))
824 packed.append(struct.pack("!Q", self.rx_crc_err))
825 packed.append(struct.pack("!Q", self.collisions))
826 return ''.join(packed)
827
828 @staticmethod
829 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700830 obj = port_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700831 if type(buf) == loxi.generic_util.OFReader:
832 reader = buf
833 else:
834 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700835 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700836 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700837 obj.rx_packets = reader.read("!Q")[0]
838 obj.tx_packets = reader.read("!Q")[0]
839 obj.rx_bytes = reader.read("!Q")[0]
840 obj.tx_bytes = reader.read("!Q")[0]
841 obj.rx_dropped = reader.read("!Q")[0]
842 obj.tx_dropped = reader.read("!Q")[0]
843 obj.rx_errors = reader.read("!Q")[0]
844 obj.tx_errors = reader.read("!Q")[0]
845 obj.rx_frame_err = reader.read("!Q")[0]
846 obj.rx_over_err = reader.read("!Q")[0]
847 obj.rx_crc_err = reader.read("!Q")[0]
848 obj.collisions = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700849 return obj
850
851 def __eq__(self, other):
852 if type(self) != type(other): return False
853 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700854 if self.rx_packets != other.rx_packets: return False
855 if self.tx_packets != other.tx_packets: return False
856 if self.rx_bytes != other.rx_bytes: return False
857 if self.tx_bytes != other.tx_bytes: return False
858 if self.rx_dropped != other.rx_dropped: return False
859 if self.tx_dropped != other.tx_dropped: return False
860 if self.rx_errors != other.rx_errors: return False
861 if self.tx_errors != other.tx_errors: return False
862 if self.rx_frame_err != other.rx_frame_err: return False
863 if self.rx_over_err != other.rx_over_err: return False
864 if self.rx_crc_err != other.rx_crc_err: return False
865 if self.collisions != other.collisions: return False
866 return True
867
868 def __ne__(self, other):
869 return not self.__eq__(other)
870
871 def show(self):
872 import loxi.pp
873 return loxi.pp.pp(self)
874
875 def pretty_print(self, q):
876 q.text("port_stats_entry {")
877 with q.group():
878 with q.indent(2):
879 q.breakable()
880 q.text("port_no = ");
881 q.text(util.pretty_port(self.port_no))
882 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700883 q.text("rx_packets = ");
884 q.text("%#x" % self.rx_packets)
885 q.text(","); q.breakable()
886 q.text("tx_packets = ");
887 q.text("%#x" % self.tx_packets)
888 q.text(","); q.breakable()
889 q.text("rx_bytes = ");
890 q.text("%#x" % self.rx_bytes)
891 q.text(","); q.breakable()
892 q.text("tx_bytes = ");
893 q.text("%#x" % self.tx_bytes)
894 q.text(","); q.breakable()
895 q.text("rx_dropped = ");
896 q.text("%#x" % self.rx_dropped)
897 q.text(","); q.breakable()
898 q.text("tx_dropped = ");
899 q.text("%#x" % self.tx_dropped)
900 q.text(","); q.breakable()
901 q.text("rx_errors = ");
902 q.text("%#x" % self.rx_errors)
903 q.text(","); q.breakable()
904 q.text("tx_errors = ");
905 q.text("%#x" % self.tx_errors)
906 q.text(","); q.breakable()
907 q.text("rx_frame_err = ");
908 q.text("%#x" % self.rx_frame_err)
909 q.text(","); q.breakable()
910 q.text("rx_over_err = ");
911 q.text("%#x" % self.rx_over_err)
912 q.text(","); q.breakable()
913 q.text("rx_crc_err = ");
914 q.text("%#x" % self.rx_crc_err)
915 q.text(","); q.breakable()
916 q.text("collisions = ");
917 q.text("%#x" % self.collisions)
918 q.breakable()
919 q.text('}')
920
921class queue_prop_min_rate(object):
Dan Talaycof6202252013-07-02 01:00:29 -0700922 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -0700923
Rich Lanec2ee4b82013-04-24 17:12:38 -0700924 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700925 if rate != None:
926 self.rate = rate
927 else:
928 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700929 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700930
931 def pack(self):
932 packed = []
933 packed.append(struct.pack("!H", self.type))
934 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700935 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700936 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700937 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700938 length = sum([len(x) for x in packed])
939 packed[1] = struct.pack("!H", length)
940 return ''.join(packed)
941
942 @staticmethod
943 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700944 obj = queue_prop_min_rate()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700945 if type(buf) == loxi.generic_util.OFReader:
946 reader = buf
947 else:
948 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700949 _type = reader.read("!H")[0]
950 assert(_type == 1)
951 _len = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700952 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700953 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700954 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700955 return obj
956
957 def __eq__(self, other):
958 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700959 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700960 return True
961
962 def __ne__(self, other):
963 return not self.__eq__(other)
964
965 def show(self):
966 import loxi.pp
967 return loxi.pp.pp(self)
968
969 def pretty_print(self, q):
970 q.text("queue_prop_min_rate {")
971 with q.group():
972 with q.indent(2):
973 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700974 q.text("rate = ");
975 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -0700976 q.breakable()
977 q.text('}')
978
979class queue_stats_entry(object):
980
Rich Lanec2ee4b82013-04-24 17:12:38 -0700981 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 -0700982 if port_no != None:
983 self.port_no = port_no
984 else:
985 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700986 if queue_id != None:
987 self.queue_id = queue_id
988 else:
989 self.queue_id = 0
990 if tx_bytes != None:
991 self.tx_bytes = tx_bytes
992 else:
993 self.tx_bytes = 0
994 if tx_packets != None:
995 self.tx_packets = tx_packets
996 else:
997 self.tx_packets = 0
998 if tx_errors != None:
999 self.tx_errors = tx_errors
1000 else:
1001 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001002 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001003
1004 def pack(self):
1005 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001006 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001007 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07001008 packed.append(struct.pack("!L", self.queue_id))
1009 packed.append(struct.pack("!Q", self.tx_bytes))
1010 packed.append(struct.pack("!Q", self.tx_packets))
1011 packed.append(struct.pack("!Q", self.tx_errors))
1012 return ''.join(packed)
1013
1014 @staticmethod
1015 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001016 obj = queue_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001017 if type(buf) == loxi.generic_util.OFReader:
1018 reader = buf
1019 else:
1020 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001021 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001022 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -07001023 obj.queue_id = reader.read("!L")[0]
1024 obj.tx_bytes = reader.read("!Q")[0]
1025 obj.tx_packets = reader.read("!Q")[0]
1026 obj.tx_errors = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001027 return obj
1028
1029 def __eq__(self, other):
1030 if type(self) != type(other): return False
1031 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001032 if self.queue_id != other.queue_id: return False
1033 if self.tx_bytes != other.tx_bytes: return False
1034 if self.tx_packets != other.tx_packets: return False
1035 if self.tx_errors != other.tx_errors: return False
1036 return True
1037
1038 def __ne__(self, other):
1039 return not self.__eq__(other)
1040
1041 def show(self):
1042 import loxi.pp
1043 return loxi.pp.pp(self)
1044
1045 def pretty_print(self, q):
1046 q.text("queue_stats_entry {")
1047 with q.group():
1048 with q.indent(2):
1049 q.breakable()
1050 q.text("port_no = ");
1051 q.text(util.pretty_port(self.port_no))
1052 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001053 q.text("queue_id = ");
1054 q.text("%#x" % self.queue_id)
1055 q.text(","); q.breakable()
1056 q.text("tx_bytes = ");
1057 q.text("%#x" % self.tx_bytes)
1058 q.text(","); q.breakable()
1059 q.text("tx_packets = ");
1060 q.text("%#x" % self.tx_packets)
1061 q.text(","); q.breakable()
1062 q.text("tx_errors = ");
1063 q.text("%#x" % self.tx_errors)
1064 q.breakable()
1065 q.text('}')
1066
1067class table_stats_entry(object):
1068
Rich Lanec2ee4b82013-04-24 17:12:38 -07001069 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 -07001070 if table_id != None:
1071 self.table_id = table_id
1072 else:
1073 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001074 if name != None:
1075 self.name = name
1076 else:
1077 self.name = ""
1078 if wildcards != None:
1079 self.wildcards = wildcards
1080 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001081 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -07001082 if max_entries != None:
1083 self.max_entries = max_entries
1084 else:
1085 self.max_entries = 0
1086 if active_count != None:
1087 self.active_count = active_count
1088 else:
1089 self.active_count = 0
1090 if lookup_count != None:
1091 self.lookup_count = lookup_count
1092 else:
1093 self.lookup_count = 0
1094 if matched_count != None:
1095 self.matched_count = matched_count
1096 else:
1097 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001098 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001099
1100 def pack(self):
1101 packed = []
1102 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001103 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001104 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001105 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Laneb658ddd2013-03-12 10:15:10 -07001106 packed.append(struct.pack("!L", self.max_entries))
1107 packed.append(struct.pack("!L", self.active_count))
1108 packed.append(struct.pack("!Q", self.lookup_count))
1109 packed.append(struct.pack("!Q", self.matched_count))
1110 return ''.join(packed)
1111
1112 @staticmethod
1113 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001114 obj = table_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001115 if type(buf) == loxi.generic_util.OFReader:
1116 reader = buf
1117 else:
1118 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -07001119 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001120 reader.skip(3)
1121 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001122 obj.wildcards = util.unpack_wc_bmap(reader)
1123 obj.max_entries = reader.read("!L")[0]
1124 obj.active_count = reader.read("!L")[0]
1125 obj.lookup_count = reader.read("!Q")[0]
1126 obj.matched_count = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001127 return obj
1128
1129 def __eq__(self, other):
1130 if type(self) != type(other): return False
1131 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001132 if self.name != other.name: return False
1133 if self.wildcards != other.wildcards: return False
1134 if self.max_entries != other.max_entries: return False
1135 if self.active_count != other.active_count: return False
1136 if self.lookup_count != other.lookup_count: return False
1137 if self.matched_count != other.matched_count: return False
1138 return True
1139
1140 def __ne__(self, other):
1141 return not self.__eq__(other)
1142
1143 def show(self):
1144 import loxi.pp
1145 return loxi.pp.pp(self)
1146
1147 def pretty_print(self, q):
1148 q.text("table_stats_entry {")
1149 with q.group():
1150 with q.indent(2):
1151 q.breakable()
1152 q.text("table_id = ");
1153 q.text("%#x" % self.table_id)
1154 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001155 q.text("name = ");
1156 q.pp(self.name)
1157 q.text(","); q.breakable()
1158 q.text("wildcards = ");
1159 q.text(util.pretty_wildcards(self.wildcards))
1160 q.text(","); q.breakable()
1161 q.text("max_entries = ");
1162 q.text("%#x" % self.max_entries)
1163 q.text(","); q.breakable()
1164 q.text("active_count = ");
1165 q.text("%#x" % self.active_count)
1166 q.text(","); q.breakable()
1167 q.text("lookup_count = ");
1168 q.text("%#x" % self.lookup_count)
1169 q.text(","); q.breakable()
1170 q.text("matched_count = ");
1171 q.text("%#x" % self.matched_count)
1172 q.breakable()
1173 q.text('}')
1174
Rich Lanec2ee4b82013-04-24 17:12:38 -07001175
1176match = match_v1