blob: 8d9a0eee42d386af972d78f1bc123a47fe9ddeab [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 Lane7dcdf022013-12-11 14:45:27 -08005
6# Automatically generated by LOXI from template module.py
Rich Lanec2ee4b82013-04-24 17:12:38 -07007# Do not modify
8
Rich Lanec2ee4b82013-04-24 17:12:38 -07009import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Lanec2ee4b82013-04-24 17:12:38 -070011import const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
14import instruction
Rich Lanec2ee4b82013-04-24 17:12:38 -070015import util
16import loxi.generic_util
17
Rich Lane7dcdf022013-12-11 14:45:27 -080018class bsn_interface(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -070019
20 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
21 if hw_addr != None:
22 self.hw_addr = hw_addr
23 else:
24 self.hw_addr = [0,0,0,0,0,0]
25 if name != None:
26 self.name = name
27 else:
28 self.name = ""
29 if ipv4_addr != None:
30 self.ipv4_addr = ipv4_addr
31 else:
32 self.ipv4_addr = 0
33 if ipv4_netmask != None:
34 self.ipv4_netmask = ipv4_netmask
35 else:
36 self.ipv4_netmask = 0
37 return
38
39 def pack(self):
40 packed = []
41 packed.append(struct.pack("!6B", *self.hw_addr))
42 packed.append('\x00' * 2)
43 packed.append(struct.pack("!16s", self.name))
44 packed.append(struct.pack("!L", self.ipv4_addr))
45 packed.append(struct.pack("!L", self.ipv4_netmask))
46 return ''.join(packed)
47
48 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080049 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -070050 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070051 obj.hw_addr = list(reader.read('!6B'))
52 reader.skip(2)
53 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -070054 obj.ipv4_addr = reader.read("!L")[0]
55 obj.ipv4_netmask = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -070056 return obj
57
58 def __eq__(self, other):
59 if type(self) != type(other): return False
60 if self.hw_addr != other.hw_addr: return False
61 if self.name != other.name: return False
62 if self.ipv4_addr != other.ipv4_addr: return False
63 if self.ipv4_netmask != other.ipv4_netmask: return False
64 return True
65
Rich Lanec2ee4b82013-04-24 17:12:38 -070066 def pretty_print(self, q):
67 q.text("bsn_interface {")
68 with q.group():
69 with q.indent(2):
70 q.breakable()
71 q.text("hw_addr = ");
72 q.text(util.pretty_mac(self.hw_addr))
73 q.text(","); q.breakable()
74 q.text("name = ");
75 q.pp(self.name)
76 q.text(","); q.breakable()
77 q.text("ipv4_addr = ");
78 q.text(util.pretty_ipv4(self.ipv4_addr))
79 q.text(","); q.breakable()
80 q.text("ipv4_netmask = ");
81 q.text(util.pretty_ipv4(self.ipv4_netmask))
82 q.breakable()
83 q.text('}')
84
Rich Lane7dcdf022013-12-11 14:45:27 -080085
86class bsn_vport(loxi.OFObject):
87 subtypes = {}
88
Rich Lane95f7fc92014-01-27 17:08:16 -080089
90 def __init__(self, type=None):
91 if type != None:
92 self.type = type
93 else:
94 self.type = 0
95 return
96
97 def pack(self):
98 packed = []
99 packed.append(struct.pack("!H", self.type))
100 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
101 length = sum([len(x) for x in packed])
102 packed[1] = struct.pack("!H", length)
103 return ''.join(packed)
104
Rich Lane7dcdf022013-12-11 14:45:27 -0800105 @staticmethod
106 def unpack(reader):
107 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -0800108 subclass = bsn_vport.subtypes.get(subtype)
109 if subclass:
110 return subclass.unpack(reader)
111
112 obj = bsn_vport()
113 obj.type = reader.read("!H")[0]
114 _length = reader.read("!H")[0]
115 orig_reader = reader
116 reader = orig_reader.slice(_length - (2 + 2))
117 return obj
118
119 def __eq__(self, other):
120 if type(self) != type(other): return False
121 if self.type != other.type: return False
122 return True
123
124 def pretty_print(self, q):
125 q.text("bsn_vport {")
126 with q.group():
127 with q.indent(2):
128 q.breakable()
129 q.breakable()
130 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800131
132
Rich Lane93b33132014-04-21 12:20:58 -0700133class bsn_vport_l2gre(bsn_vport):
134 type = 1
135
Rich Lanef9530c42014-09-15 09:59:43 -0700136 def __init__(self, flags=None, port_no=None, loopback_port_no=None, local_mac=None, nh_mac=None, src_ip=None, dst_ip=None, dscp=None, ttl=None, vpn=None, rate_limit=None, if_name=None):
Rich Lane93b33132014-04-21 12:20:58 -0700137 if flags != None:
138 self.flags = flags
139 else:
140 self.flags = 0
141 if port_no != None:
142 self.port_no = port_no
143 else:
144 self.port_no = 0
Rich Lane5587ab12014-06-30 11:19:09 -0700145 if loopback_port_no != None:
146 self.loopback_port_no = loopback_port_no
147 else:
148 self.loopback_port_no = 0
Rich Lane93b33132014-04-21 12:20:58 -0700149 if local_mac != None:
150 self.local_mac = local_mac
151 else:
152 self.local_mac = [0,0,0,0,0,0]
153 if nh_mac != None:
154 self.nh_mac = nh_mac
155 else:
156 self.nh_mac = [0,0,0,0,0,0]
157 if src_ip != None:
158 self.src_ip = src_ip
159 else:
160 self.src_ip = 0
161 if dst_ip != None:
162 self.dst_ip = dst_ip
163 else:
164 self.dst_ip = 0
165 if dscp != None:
166 self.dscp = dscp
167 else:
168 self.dscp = 0
169 if ttl != None:
170 self.ttl = ttl
171 else:
172 self.ttl = 0
173 if vpn != None:
174 self.vpn = vpn
175 else:
176 self.vpn = 0
Rich Lanef9530c42014-09-15 09:59:43 -0700177 if rate_limit != None:
178 self.rate_limit = rate_limit
179 else:
180 self.rate_limit = 0
Rich Lane93b33132014-04-21 12:20:58 -0700181 if if_name != None:
182 self.if_name = if_name
183 else:
184 self.if_name = ""
185 return
186
187 def pack(self):
188 packed = []
189 packed.append(struct.pack("!H", self.type))
190 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
191 packed.append(struct.pack("!L", self.flags))
192 packed.append(util.pack_port_no(self.port_no))
Rich Lane5587ab12014-06-30 11:19:09 -0700193 packed.append(util.pack_port_no(self.loopback_port_no))
Rich Lane93b33132014-04-21 12:20:58 -0700194 packed.append(struct.pack("!6B", *self.local_mac))
195 packed.append(struct.pack("!6B", *self.nh_mac))
196 packed.append(struct.pack("!L", self.src_ip))
197 packed.append(struct.pack("!L", self.dst_ip))
198 packed.append(struct.pack("!B", self.dscp))
199 packed.append(struct.pack("!B", self.ttl))
200 packed.append('\x00' * 2)
201 packed.append(struct.pack("!L", self.vpn))
Rich Lanef9530c42014-09-15 09:59:43 -0700202 packed.append(struct.pack("!L", self.rate_limit))
Rich Lane93b33132014-04-21 12:20:58 -0700203 packed.append(struct.pack("!16s", self.if_name))
204 length = sum([len(x) for x in packed])
205 packed[1] = struct.pack("!H", length)
206 return ''.join(packed)
207
208 @staticmethod
209 def unpack(reader):
210 obj = bsn_vport_l2gre()
211 _type = reader.read("!H")[0]
212 assert(_type == 1)
213 _length = reader.read("!H")[0]
214 orig_reader = reader
215 reader = orig_reader.slice(_length - (2 + 2))
216 obj.flags = reader.read("!L")[0]
217 obj.port_no = util.unpack_port_no(reader)
Rich Lane5587ab12014-06-30 11:19:09 -0700218 obj.loopback_port_no = util.unpack_port_no(reader)
Rich Lane93b33132014-04-21 12:20:58 -0700219 obj.local_mac = list(reader.read('!6B'))
220 obj.nh_mac = list(reader.read('!6B'))
221 obj.src_ip = reader.read("!L")[0]
222 obj.dst_ip = reader.read("!L")[0]
223 obj.dscp = reader.read("!B")[0]
224 obj.ttl = reader.read("!B")[0]
225 reader.skip(2)
226 obj.vpn = reader.read("!L")[0]
Rich Lanef9530c42014-09-15 09:59:43 -0700227 obj.rate_limit = reader.read("!L")[0]
Rich Lane93b33132014-04-21 12:20:58 -0700228 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
229 return obj
230
231 def __eq__(self, other):
232 if type(self) != type(other): return False
233 if self.flags != other.flags: return False
234 if self.port_no != other.port_no: return False
Rich Lane5587ab12014-06-30 11:19:09 -0700235 if self.loopback_port_no != other.loopback_port_no: return False
Rich Lane93b33132014-04-21 12:20:58 -0700236 if self.local_mac != other.local_mac: return False
237 if self.nh_mac != other.nh_mac: return False
238 if self.src_ip != other.src_ip: return False
239 if self.dst_ip != other.dst_ip: return False
240 if self.dscp != other.dscp: return False
241 if self.ttl != other.ttl: return False
242 if self.vpn != other.vpn: return False
Rich Lanef9530c42014-09-15 09:59:43 -0700243 if self.rate_limit != other.rate_limit: return False
Rich Lane93b33132014-04-21 12:20:58 -0700244 if self.if_name != other.if_name: return False
245 return True
246
247 def pretty_print(self, q):
248 q.text("bsn_vport_l2gre {")
249 with q.group():
250 with q.indent(2):
251 q.breakable()
252 q.text("flags = ");
253 q.text("%#x" % self.flags)
254 q.text(","); q.breakable()
255 q.text("port_no = ");
256 q.text(util.pretty_port(self.port_no))
257 q.text(","); q.breakable()
Rich Lane5587ab12014-06-30 11:19:09 -0700258 q.text("loopback_port_no = ");
259 q.text(util.pretty_port(self.loopback_port_no))
260 q.text(","); q.breakable()
Rich Lane93b33132014-04-21 12:20:58 -0700261 q.text("local_mac = ");
262 q.text(util.pretty_mac(self.local_mac))
263 q.text(","); q.breakable()
264 q.text("nh_mac = ");
265 q.text(util.pretty_mac(self.nh_mac))
266 q.text(","); q.breakable()
267 q.text("src_ip = ");
268 q.text(util.pretty_ipv4(self.src_ip))
269 q.text(","); q.breakable()
270 q.text("dst_ip = ");
271 q.text(util.pretty_ipv4(self.dst_ip))
272 q.text(","); q.breakable()
273 q.text("dscp = ");
274 q.text("%#x" % self.dscp)
275 q.text(","); q.breakable()
276 q.text("ttl = ");
277 q.text("%#x" % self.ttl)
278 q.text(","); q.breakable()
279 q.text("vpn = ");
280 q.text("%#x" % self.vpn)
281 q.text(","); q.breakable()
Rich Lanef9530c42014-09-15 09:59:43 -0700282 q.text("rate_limit = ");
283 q.text("%#x" % self.rate_limit)
284 q.text(","); q.breakable()
Rich Lane93b33132014-04-21 12:20:58 -0700285 q.text("if_name = ");
286 q.pp(self.if_name)
287 q.breakable()
288 q.text('}')
289
290bsn_vport.subtypes[1] = bsn_vport_l2gre
291
Rich Lane7dcdf022013-12-11 14:45:27 -0800292class bsn_vport_q_in_q(bsn_vport):
Dan Talaycof6202252013-07-02 01:00:29 -0700293 type = 0
294
Kiran Poola150d8b02013-09-20 13:30:39 -0700295 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 -0700296 if port_no != None:
297 self.port_no = port_no
298 else:
299 self.port_no = 0
300 if ingress_tpid != None:
301 self.ingress_tpid = ingress_tpid
302 else:
303 self.ingress_tpid = 0
304 if ingress_vlan_id != None:
305 self.ingress_vlan_id = ingress_vlan_id
306 else:
307 self.ingress_vlan_id = 0
308 if egress_tpid != None:
309 self.egress_tpid = egress_tpid
310 else:
311 self.egress_tpid = 0
312 if egress_vlan_id != None:
313 self.egress_vlan_id = egress_vlan_id
314 else:
315 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700316 if if_name != None:
317 self.if_name = if_name
318 else:
319 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700320 return
321
322 def pack(self):
323 packed = []
324 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700325 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700326 packed.append(struct.pack("!L", self.port_no))
327 packed.append(struct.pack("!H", self.ingress_tpid))
328 packed.append(struct.pack("!H", self.ingress_vlan_id))
329 packed.append(struct.pack("!H", self.egress_tpid))
330 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700331 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700332 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700333 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700334 return ''.join(packed)
335
336 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800337 def unpack(reader):
Dan Talaycof6202252013-07-02 01:00:29 -0700338 obj = bsn_vport_q_in_q()
Dan Talaycof6202252013-07-02 01:00:29 -0700339 _type = reader.read("!H")[0]
340 assert(_type == 0)
341 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800342 orig_reader = reader
343 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700344 obj.port_no = reader.read("!L")[0]
345 obj.ingress_tpid = reader.read("!H")[0]
346 obj.ingress_vlan_id = reader.read("!H")[0]
347 obj.egress_tpid = reader.read("!H")[0]
348 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700349 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700350 return obj
351
352 def __eq__(self, other):
353 if type(self) != type(other): return False
354 if self.port_no != other.port_no: return False
355 if self.ingress_tpid != other.ingress_tpid: return False
356 if self.ingress_vlan_id != other.ingress_vlan_id: return False
357 if self.egress_tpid != other.egress_tpid: return False
358 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700359 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700360 return True
361
Dan Talaycof6202252013-07-02 01:00:29 -0700362 def pretty_print(self, q):
363 q.text("bsn_vport_q_in_q {")
364 with q.group():
365 with q.indent(2):
366 q.breakable()
367 q.text("port_no = ");
368 q.text("%#x" % self.port_no)
369 q.text(","); q.breakable()
370 q.text("ingress_tpid = ");
371 q.text("%#x" % self.ingress_tpid)
372 q.text(","); q.breakable()
373 q.text("ingress_vlan_id = ");
374 q.text("%#x" % self.ingress_vlan_id)
375 q.text(","); q.breakable()
376 q.text("egress_tpid = ");
377 q.text("%#x" % self.egress_tpid)
378 q.text(","); q.breakable()
379 q.text("egress_vlan_id = ");
380 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700381 q.text(","); q.breakable()
382 q.text("if_name = ");
383 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700384 q.breakable()
385 q.text('}')
386
Rich Lane7dcdf022013-12-11 14:45:27 -0800387bsn_vport.subtypes[0] = bsn_vport_q_in_q
388
389class bucket(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700390
391 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
392 if weight != None:
393 self.weight = weight
394 else:
395 self.weight = 0
396 if watch_port != None:
397 self.watch_port = watch_port
398 else:
399 self.watch_port = 0
400 if watch_group != None:
401 self.watch_group = watch_group
402 else:
403 self.watch_group = 0
404 if actions != None:
405 self.actions = actions
406 else:
407 self.actions = []
408 return
409
410 def pack(self):
411 packed = []
412 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
413 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700414 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700415 packed.append(struct.pack("!L", self.watch_group))
416 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800417 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700418 length = sum([len(x) for x in packed])
419 packed[0] = struct.pack("!H", length)
420 return ''.join(packed)
421
422 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800423 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700424 obj = bucket()
Dan Talaycof6202252013-07-02 01:00:29 -0700425 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800426 orig_reader = reader
427 reader = orig_reader.slice(_len - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700428 obj.weight = reader.read("!H")[0]
429 obj.watch_port = util.unpack_port_no(reader)
430 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700431 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800432 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700433 return obj
434
435 def __eq__(self, other):
436 if type(self) != type(other): return False
437 if self.weight != other.weight: return False
438 if self.watch_port != other.watch_port: return False
439 if self.watch_group != other.watch_group: return False
440 if self.actions != other.actions: return False
441 return True
442
Rich Lanec2ee4b82013-04-24 17:12:38 -0700443 def pretty_print(self, q):
444 q.text("bucket {")
445 with q.group():
446 with q.indent(2):
447 q.breakable()
448 q.text("weight = ");
449 q.text("%#x" % self.weight)
450 q.text(","); q.breakable()
451 q.text("watch_port = ");
452 q.text(util.pretty_port(self.watch_port))
453 q.text(","); q.breakable()
454 q.text("watch_group = ");
455 q.text("%#x" % self.watch_group)
456 q.text(","); q.breakable()
457 q.text("actions = ");
458 q.pp(self.actions)
459 q.breakable()
460 q.text('}')
461
Rich Lane7dcdf022013-12-11 14:45:27 -0800462
463class bucket_counter(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700464
465 def __init__(self, packet_count=None, byte_count=None):
466 if packet_count != None:
467 self.packet_count = packet_count
468 else:
469 self.packet_count = 0
470 if byte_count != None:
471 self.byte_count = byte_count
472 else:
473 self.byte_count = 0
474 return
475
476 def pack(self):
477 packed = []
478 packed.append(struct.pack("!Q", self.packet_count))
479 packed.append(struct.pack("!Q", self.byte_count))
480 return ''.join(packed)
481
482 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800483 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700484 obj = bucket_counter()
Dan Talaycof6202252013-07-02 01:00:29 -0700485 obj.packet_count = reader.read("!Q")[0]
486 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700487 return obj
488
489 def __eq__(self, other):
490 if type(self) != type(other): return False
491 if self.packet_count != other.packet_count: return False
492 if self.byte_count != other.byte_count: return False
493 return True
494
Rich Lanec2ee4b82013-04-24 17:12:38 -0700495 def pretty_print(self, q):
496 q.text("bucket_counter {")
497 with q.group():
498 with q.indent(2):
499 q.breakable()
500 q.text("packet_count = ");
501 q.text("%#x" % self.packet_count)
502 q.text(","); q.breakable()
503 q.text("byte_count = ");
504 q.text("%#x" % self.byte_count)
505 q.breakable()
506 q.text('}')
507
Rich Lane7dcdf022013-12-11 14:45:27 -0800508
509class flow_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700510
511 def __init__(self, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, match=None, instructions=None):
512 if table_id != None:
513 self.table_id = table_id
514 else:
515 self.table_id = 0
516 if duration_sec != None:
517 self.duration_sec = duration_sec
518 else:
519 self.duration_sec = 0
520 if duration_nsec != None:
521 self.duration_nsec = duration_nsec
522 else:
523 self.duration_nsec = 0
524 if priority != None:
525 self.priority = priority
526 else:
527 self.priority = 0
528 if idle_timeout != None:
529 self.idle_timeout = idle_timeout
530 else:
531 self.idle_timeout = 0
532 if hard_timeout != None:
533 self.hard_timeout = hard_timeout
534 else:
535 self.hard_timeout = 0
536 if cookie != None:
537 self.cookie = cookie
538 else:
539 self.cookie = 0
540 if packet_count != None:
541 self.packet_count = packet_count
542 else:
543 self.packet_count = 0
544 if byte_count != None:
545 self.byte_count = byte_count
546 else:
547 self.byte_count = 0
548 if match != None:
549 self.match = match
550 else:
551 self.match = common.match()
552 if instructions != None:
553 self.instructions = instructions
554 else:
555 self.instructions = []
556 return
557
558 def pack(self):
559 packed = []
560 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
561 packed.append(struct.pack("!B", self.table_id))
562 packed.append('\x00' * 1)
563 packed.append(struct.pack("!L", self.duration_sec))
564 packed.append(struct.pack("!L", self.duration_nsec))
565 packed.append(struct.pack("!H", self.priority))
566 packed.append(struct.pack("!H", self.idle_timeout))
567 packed.append(struct.pack("!H", self.hard_timeout))
568 packed.append('\x00' * 6)
569 packed.append(struct.pack("!Q", self.cookie))
570 packed.append(struct.pack("!Q", self.packet_count))
571 packed.append(struct.pack("!Q", self.byte_count))
572 packed.append(self.match.pack())
Rich Lane7dcdf022013-12-11 14:45:27 -0800573 packed.append(loxi.generic_util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700574 length = sum([len(x) for x in packed])
575 packed[0] = struct.pack("!H", length)
576 return ''.join(packed)
577
578 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800579 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700580 obj = flow_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700581 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800582 orig_reader = reader
583 reader = orig_reader.slice(_length - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700584 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700585 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700586 obj.duration_sec = reader.read("!L")[0]
587 obj.duration_nsec = reader.read("!L")[0]
588 obj.priority = reader.read("!H")[0]
589 obj.idle_timeout = reader.read("!H")[0]
590 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700591 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700592 obj.cookie = reader.read("!Q")[0]
593 obj.packet_count = reader.read("!Q")[0]
594 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700595 obj.match = common.match.unpack(reader)
Rich Lane7dcdf022013-12-11 14:45:27 -0800596 obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700597 return obj
598
599 def __eq__(self, other):
600 if type(self) != type(other): return False
601 if self.table_id != other.table_id: return False
602 if self.duration_sec != other.duration_sec: return False
603 if self.duration_nsec != other.duration_nsec: return False
604 if self.priority != other.priority: return False
605 if self.idle_timeout != other.idle_timeout: return False
606 if self.hard_timeout != other.hard_timeout: return False
607 if self.cookie != other.cookie: return False
608 if self.packet_count != other.packet_count: return False
609 if self.byte_count != other.byte_count: return False
610 if self.match != other.match: return False
611 if self.instructions != other.instructions: return False
612 return True
613
Rich Lanec2ee4b82013-04-24 17:12:38 -0700614 def pretty_print(self, q):
615 q.text("flow_stats_entry {")
616 with q.group():
617 with q.indent(2):
618 q.breakable()
619 q.text("table_id = ");
620 q.text("%#x" % self.table_id)
621 q.text(","); q.breakable()
622 q.text("duration_sec = ");
623 q.text("%#x" % self.duration_sec)
624 q.text(","); q.breakable()
625 q.text("duration_nsec = ");
626 q.text("%#x" % self.duration_nsec)
627 q.text(","); q.breakable()
628 q.text("priority = ");
629 q.text("%#x" % self.priority)
630 q.text(","); q.breakable()
631 q.text("idle_timeout = ");
632 q.text("%#x" % self.idle_timeout)
633 q.text(","); q.breakable()
634 q.text("hard_timeout = ");
635 q.text("%#x" % self.hard_timeout)
636 q.text(","); q.breakable()
637 q.text("cookie = ");
638 q.text("%#x" % self.cookie)
639 q.text(","); q.breakable()
640 q.text("packet_count = ");
641 q.text("%#x" % self.packet_count)
642 q.text(","); q.breakable()
643 q.text("byte_count = ");
644 q.text("%#x" % self.byte_count)
645 q.text(","); q.breakable()
646 q.text("match = ");
647 q.pp(self.match)
648 q.text(","); q.breakable()
649 q.text("instructions = ");
650 q.pp(self.instructions)
651 q.breakable()
652 q.text('}')
653
Rich Lane7dcdf022013-12-11 14:45:27 -0800654
655class group_desc_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700656
Rich Lane6f4978c2013-10-20 21:33:52 -0700657 def __init__(self, group_type=None, group_id=None, buckets=None):
658 if group_type != None:
659 self.group_type = group_type
Rich Lanec2ee4b82013-04-24 17:12:38 -0700660 else:
Rich Lane6f4978c2013-10-20 21:33:52 -0700661 self.group_type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700662 if group_id != None:
663 self.group_id = group_id
664 else:
665 self.group_id = 0
666 if buckets != None:
667 self.buckets = buckets
668 else:
669 self.buckets = []
670 return
671
672 def pack(self):
673 packed = []
674 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
Rich Lane6f4978c2013-10-20 21:33:52 -0700675 packed.append(struct.pack("!B", self.group_type))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700676 packed.append('\x00' * 1)
677 packed.append(struct.pack("!L", self.group_id))
Rich Lane7dcdf022013-12-11 14:45:27 -0800678 packed.append(loxi.generic_util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700679 length = sum([len(x) for x in packed])
680 packed[0] = struct.pack("!H", length)
681 return ''.join(packed)
682
683 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800684 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700685 obj = group_desc_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700686 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800687 orig_reader = reader
688 reader = orig_reader.slice(_length - (0 + 2))
Rich Lane6f4978c2013-10-20 21:33:52 -0700689 obj.group_type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700690 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700691 obj.group_id = reader.read("!L")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800692 obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700693 return obj
694
695 def __eq__(self, other):
696 if type(self) != type(other): return False
Rich Lane6f4978c2013-10-20 21:33:52 -0700697 if self.group_type != other.group_type: return False
Rich Lanec2ee4b82013-04-24 17:12:38 -0700698 if self.group_id != other.group_id: return False
699 if self.buckets != other.buckets: return False
700 return True
701
Rich Lanec2ee4b82013-04-24 17:12:38 -0700702 def pretty_print(self, q):
703 q.text("group_desc_stats_entry {")
704 with q.group():
705 with q.indent(2):
706 q.breakable()
Rich Lane6f4978c2013-10-20 21:33:52 -0700707 q.text("group_type = ");
708 q.text("%#x" % self.group_type)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700709 q.text(","); q.breakable()
710 q.text("group_id = ");
711 q.text("%#x" % self.group_id)
712 q.text(","); q.breakable()
713 q.text("buckets = ");
714 q.pp(self.buckets)
715 q.breakable()
716 q.text('}')
717
Rich Lane7dcdf022013-12-11 14:45:27 -0800718
719class group_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700720
721 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
722 if group_id != None:
723 self.group_id = group_id
724 else:
725 self.group_id = 0
726 if ref_count != None:
727 self.ref_count = ref_count
728 else:
729 self.ref_count = 0
730 if packet_count != None:
731 self.packet_count = packet_count
732 else:
733 self.packet_count = 0
734 if byte_count != None:
735 self.byte_count = byte_count
736 else:
737 self.byte_count = 0
738 if bucket_stats != None:
739 self.bucket_stats = bucket_stats
740 else:
741 self.bucket_stats = []
742 return
743
744 def pack(self):
745 packed = []
746 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
747 packed.append('\x00' * 2)
748 packed.append(struct.pack("!L", self.group_id))
749 packed.append(struct.pack("!L", self.ref_count))
750 packed.append('\x00' * 4)
751 packed.append(struct.pack("!Q", self.packet_count))
752 packed.append(struct.pack("!Q", self.byte_count))
Rich Lane7dcdf022013-12-11 14:45:27 -0800753 packed.append(loxi.generic_util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700754 length = sum([len(x) for x in packed])
755 packed[0] = struct.pack("!H", length)
756 return ''.join(packed)
757
758 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800759 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700760 obj = group_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700761 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800762 orig_reader = reader
763 reader = orig_reader.slice(_length - (0 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700764 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700765 obj.group_id = reader.read("!L")[0]
766 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700767 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700768 obj.packet_count = reader.read("!Q")[0]
769 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700770 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
771 return obj
772
773 def __eq__(self, other):
774 if type(self) != type(other): return False
775 if self.group_id != other.group_id: return False
776 if self.ref_count != other.ref_count: return False
777 if self.packet_count != other.packet_count: return False
778 if self.byte_count != other.byte_count: return False
779 if self.bucket_stats != other.bucket_stats: return False
780 return True
781
Rich Lanec2ee4b82013-04-24 17:12:38 -0700782 def pretty_print(self, q):
783 q.text("group_stats_entry {")
784 with q.group():
785 with q.indent(2):
786 q.breakable()
787 q.text("group_id = ");
788 q.text("%#x" % self.group_id)
789 q.text(","); q.breakable()
790 q.text("ref_count = ");
791 q.text("%#x" % self.ref_count)
792 q.text(","); q.breakable()
793 q.text("packet_count = ");
794 q.text("%#x" % self.packet_count)
795 q.text(","); q.breakable()
796 q.text("byte_count = ");
797 q.text("%#x" % self.byte_count)
798 q.text(","); q.breakable()
799 q.text("bucket_stats = ");
800 q.pp(self.bucket_stats)
801 q.breakable()
802 q.text('}')
803
Rich Lane7dcdf022013-12-11 14:45:27 -0800804
805class match_v2(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700806 type = 0
807
808 def __init__(self, in_port=None, wildcards=None, eth_src=None, eth_src_mask=None, eth_dst=None, eth_dst_mask=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_src_mask=None, ipv4_dst=None, ipv4_dst_mask=None, tcp_src=None, tcp_dst=None, mpls_label=None, mpls_tc=None, metadata=None, metadata_mask=None):
809 if in_port != None:
810 self.in_port = in_port
811 else:
812 self.in_port = 0
813 if wildcards != None:
814 self.wildcards = wildcards
815 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700816 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700817 if eth_src != None:
818 self.eth_src = eth_src
819 else:
820 self.eth_src = [0,0,0,0,0,0]
821 if eth_src_mask != None:
822 self.eth_src_mask = eth_src_mask
823 else:
824 self.eth_src_mask = [0,0,0,0,0,0]
825 if eth_dst != None:
826 self.eth_dst = eth_dst
827 else:
828 self.eth_dst = [0,0,0,0,0,0]
829 if eth_dst_mask != None:
830 self.eth_dst_mask = eth_dst_mask
831 else:
832 self.eth_dst_mask = [0,0,0,0,0,0]
833 if vlan_vid != None:
834 self.vlan_vid = vlan_vid
835 else:
836 self.vlan_vid = 0
837 if vlan_pcp != None:
838 self.vlan_pcp = vlan_pcp
839 else:
840 self.vlan_pcp = 0
841 if eth_type != None:
842 self.eth_type = eth_type
843 else:
844 self.eth_type = 0
845 if ip_dscp != None:
846 self.ip_dscp = ip_dscp
847 else:
848 self.ip_dscp = 0
849 if ip_proto != None:
850 self.ip_proto = ip_proto
851 else:
852 self.ip_proto = 0
853 if ipv4_src != None:
854 self.ipv4_src = ipv4_src
855 else:
856 self.ipv4_src = 0
857 if ipv4_src_mask != None:
858 self.ipv4_src_mask = ipv4_src_mask
859 else:
860 self.ipv4_src_mask = 0
861 if ipv4_dst != None:
862 self.ipv4_dst = ipv4_dst
863 else:
864 self.ipv4_dst = 0
865 if ipv4_dst_mask != None:
866 self.ipv4_dst_mask = ipv4_dst_mask
867 else:
868 self.ipv4_dst_mask = 0
869 if tcp_src != None:
870 self.tcp_src = tcp_src
871 else:
872 self.tcp_src = 0
873 if tcp_dst != None:
874 self.tcp_dst = tcp_dst
875 else:
876 self.tcp_dst = 0
877 if mpls_label != None:
878 self.mpls_label = mpls_label
879 else:
880 self.mpls_label = 0
881 if mpls_tc != None:
882 self.mpls_tc = mpls_tc
883 else:
884 self.mpls_tc = 0
885 if metadata != None:
886 self.metadata = metadata
887 else:
888 self.metadata = 0
889 if metadata_mask != None:
890 self.metadata_mask = metadata_mask
891 else:
892 self.metadata_mask = 0
893 return
894
895 def pack(self):
896 packed = []
897 packed.append(struct.pack("!H", self.type))
898 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700899 packed.append(util.pack_port_no(self.in_port))
900 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700901 packed.append(struct.pack("!6B", *self.eth_src))
902 packed.append(struct.pack("!6B", *self.eth_src_mask))
903 packed.append(struct.pack("!6B", *self.eth_dst))
904 packed.append(struct.pack("!6B", *self.eth_dst_mask))
905 packed.append(struct.pack("!H", self.vlan_vid))
906 packed.append(struct.pack("!B", self.vlan_pcp))
907 packed.append('\x00' * 1)
908 packed.append(struct.pack("!H", self.eth_type))
909 packed.append(struct.pack("!B", self.ip_dscp))
910 packed.append(struct.pack("!B", self.ip_proto))
911 packed.append(struct.pack("!L", self.ipv4_src))
912 packed.append(struct.pack("!L", self.ipv4_src_mask))
913 packed.append(struct.pack("!L", self.ipv4_dst))
914 packed.append(struct.pack("!L", self.ipv4_dst_mask))
915 packed.append(struct.pack("!H", self.tcp_src))
916 packed.append(struct.pack("!H", self.tcp_dst))
917 packed.append(struct.pack("!L", self.mpls_label))
918 packed.append(struct.pack("!B", self.mpls_tc))
919 packed.append('\x00' * 3)
920 packed.append(struct.pack("!Q", self.metadata))
921 packed.append(struct.pack("!Q", self.metadata_mask))
922 length = sum([len(x) for x in packed])
923 packed[1] = struct.pack("!H", length)
924 return ''.join(packed)
925
926 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800927 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700928 obj = match_v2()
Dan Talaycof6202252013-07-02 01:00:29 -0700929 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700930 assert(_type == 0)
Dan Talaycof6202252013-07-02 01:00:29 -0700931 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800932 orig_reader = reader
933 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700934 obj.in_port = util.unpack_port_no(reader)
935 obj.wildcards = util.unpack_wc_bmap(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700936 obj.eth_src = list(reader.read('!6B'))
937 obj.eth_src_mask = list(reader.read('!6B'))
938 obj.eth_dst = list(reader.read('!6B'))
939 obj.eth_dst_mask = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700940 obj.vlan_vid = reader.read("!H")[0]
941 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700942 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700943 obj.eth_type = reader.read("!H")[0]
944 obj.ip_dscp = reader.read("!B")[0]
945 obj.ip_proto = reader.read("!B")[0]
946 obj.ipv4_src = reader.read("!L")[0]
947 obj.ipv4_src_mask = reader.read("!L")[0]
948 obj.ipv4_dst = reader.read("!L")[0]
949 obj.ipv4_dst_mask = reader.read("!L")[0]
950 obj.tcp_src = reader.read("!H")[0]
951 obj.tcp_dst = reader.read("!H")[0]
952 obj.mpls_label = reader.read("!L")[0]
953 obj.mpls_tc = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700954 reader.skip(3)
Dan Talaycof6202252013-07-02 01:00:29 -0700955 obj.metadata = reader.read("!Q")[0]
956 obj.metadata_mask = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700957 return obj
958
959 def __eq__(self, other):
960 if type(self) != type(other): return False
961 if self.in_port != other.in_port: return False
962 if self.wildcards != other.wildcards: return False
963 if self.eth_src != other.eth_src: return False
964 if self.eth_src_mask != other.eth_src_mask: return False
965 if self.eth_dst != other.eth_dst: return False
966 if self.eth_dst_mask != other.eth_dst_mask: return False
967 if self.vlan_vid != other.vlan_vid: return False
968 if self.vlan_pcp != other.vlan_pcp: return False
969 if self.eth_type != other.eth_type: return False
970 if self.ip_dscp != other.ip_dscp: return False
971 if self.ip_proto != other.ip_proto: return False
972 if self.ipv4_src != other.ipv4_src: return False
973 if self.ipv4_src_mask != other.ipv4_src_mask: return False
974 if self.ipv4_dst != other.ipv4_dst: return False
975 if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
976 if self.tcp_src != other.tcp_src: return False
977 if self.tcp_dst != other.tcp_dst: return False
978 if self.mpls_label != other.mpls_label: return False
979 if self.mpls_tc != other.mpls_tc: return False
980 if self.metadata != other.metadata: return False
981 if self.metadata_mask != other.metadata_mask: return False
982 return True
983
Rich Lanec2ee4b82013-04-24 17:12:38 -0700984 def pretty_print(self, q):
985 q.text("match_v2 {")
986 with q.group():
987 with q.indent(2):
988 q.breakable()
989 q.text("in_port = ");
990 q.text(util.pretty_port(self.in_port))
991 q.text(","); q.breakable()
992 q.text("wildcards = ");
993 q.text(util.pretty_wildcards(self.wildcards))
994 q.text(","); q.breakable()
995 q.text("eth_src = ");
996 q.text(util.pretty_mac(self.eth_src))
997 q.text(","); q.breakable()
998 q.text("eth_src_mask = ");
999 q.text(util.pretty_mac(self.eth_src_mask))
1000 q.text(","); q.breakable()
1001 q.text("eth_dst = ");
1002 q.text(util.pretty_mac(self.eth_dst))
1003 q.text(","); q.breakable()
1004 q.text("eth_dst_mask = ");
1005 q.text(util.pretty_mac(self.eth_dst_mask))
1006 q.text(","); q.breakable()
1007 q.text("vlan_vid = ");
1008 q.text("%#x" % self.vlan_vid)
1009 q.text(","); q.breakable()
1010 q.text("vlan_pcp = ");
1011 q.text("%#x" % self.vlan_pcp)
1012 q.text(","); q.breakable()
1013 q.text("eth_type = ");
1014 q.text("%#x" % self.eth_type)
1015 q.text(","); q.breakable()
1016 q.text("ip_dscp = ");
1017 q.text("%#x" % self.ip_dscp)
1018 q.text(","); q.breakable()
1019 q.text("ip_proto = ");
1020 q.text("%#x" % self.ip_proto)
1021 q.text(","); q.breakable()
1022 q.text("ipv4_src = ");
1023 q.text(util.pretty_ipv4(self.ipv4_src))
1024 q.text(","); q.breakable()
1025 q.text("ipv4_src_mask = ");
1026 q.text(util.pretty_ipv4(self.ipv4_src_mask))
1027 q.text(","); q.breakable()
1028 q.text("ipv4_dst = ");
1029 q.text(util.pretty_ipv4(self.ipv4_dst))
1030 q.text(","); q.breakable()
1031 q.text("ipv4_dst_mask = ");
1032 q.text(util.pretty_ipv4(self.ipv4_dst_mask))
1033 q.text(","); q.breakable()
1034 q.text("tcp_src = ");
1035 q.text("%#x" % self.tcp_src)
1036 q.text(","); q.breakable()
1037 q.text("tcp_dst = ");
1038 q.text("%#x" % self.tcp_dst)
1039 q.text(","); q.breakable()
1040 q.text("mpls_label = ");
1041 q.text("%#x" % self.mpls_label)
1042 q.text(","); q.breakable()
1043 q.text("mpls_tc = ");
1044 q.text("%#x" % self.mpls_tc)
1045 q.text(","); q.breakable()
1046 q.text("metadata = ");
1047 q.text("%#x" % self.metadata)
1048 q.text(","); q.breakable()
1049 q.text("metadata_mask = ");
1050 q.text("%#x" % self.metadata_mask)
1051 q.breakable()
1052 q.text('}')
1053
Rich Lane7dcdf022013-12-11 14:45:27 -08001054
1055class packet_queue(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001056
1057 def __init__(self, queue_id=None, properties=None):
1058 if queue_id != None:
1059 self.queue_id = queue_id
1060 else:
1061 self.queue_id = 0
1062 if properties != None:
1063 self.properties = properties
1064 else:
1065 self.properties = []
1066 return
1067
1068 def pack(self):
1069 packed = []
1070 packed.append(struct.pack("!L", self.queue_id))
1071 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1072 packed.append('\x00' * 2)
Rich Lane7dcdf022013-12-11 14:45:27 -08001073 packed.append(loxi.generic_util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001074 length = sum([len(x) for x in packed])
1075 packed[1] = struct.pack("!H", length)
1076 return ''.join(packed)
1077
1078 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001079 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001080 obj = packet_queue()
Dan Talaycof6202252013-07-02 01:00:29 -07001081 obj.queue_id = reader.read("!L")[0]
1082 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001083 orig_reader = reader
1084 reader = orig_reader.slice(_len - (4 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001085 reader.skip(2)
Rich Lane7dcdf022013-12-11 14:45:27 -08001086 obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001087 return obj
1088
1089 def __eq__(self, other):
1090 if type(self) != type(other): return False
1091 if self.queue_id != other.queue_id: return False
1092 if self.properties != other.properties: return False
1093 return True
1094
Rich Lanec2ee4b82013-04-24 17:12:38 -07001095 def pretty_print(self, q):
1096 q.text("packet_queue {")
1097 with q.group():
1098 with q.indent(2):
1099 q.breakable()
1100 q.text("queue_id = ");
1101 q.text("%#x" % self.queue_id)
1102 q.text(","); q.breakable()
1103 q.text("properties = ");
1104 q.pp(self.properties)
1105 q.breakable()
1106 q.text('}')
1107
Rich Lane7dcdf022013-12-11 14:45:27 -08001108
1109class port_desc(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001110
1111 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None, curr_speed=None, max_speed=None):
1112 if port_no != None:
1113 self.port_no = port_no
1114 else:
1115 self.port_no = 0
1116 if hw_addr != None:
1117 self.hw_addr = hw_addr
1118 else:
1119 self.hw_addr = [0,0,0,0,0,0]
1120 if name != None:
1121 self.name = name
1122 else:
1123 self.name = ""
1124 if config != None:
1125 self.config = config
1126 else:
1127 self.config = 0
1128 if state != None:
1129 self.state = state
1130 else:
1131 self.state = 0
1132 if curr != None:
1133 self.curr = curr
1134 else:
1135 self.curr = 0
1136 if advertised != None:
1137 self.advertised = advertised
1138 else:
1139 self.advertised = 0
1140 if supported != None:
1141 self.supported = supported
1142 else:
1143 self.supported = 0
1144 if peer != None:
1145 self.peer = peer
1146 else:
1147 self.peer = 0
1148 if curr_speed != None:
1149 self.curr_speed = curr_speed
1150 else:
1151 self.curr_speed = 0
1152 if max_speed != None:
1153 self.max_speed = max_speed
1154 else:
1155 self.max_speed = 0
1156 return
1157
1158 def pack(self):
1159 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001160 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001161 packed.append('\x00' * 4)
1162 packed.append(struct.pack("!6B", *self.hw_addr))
1163 packed.append('\x00' * 2)
1164 packed.append(struct.pack("!16s", self.name))
1165 packed.append(struct.pack("!L", self.config))
1166 packed.append(struct.pack("!L", self.state))
1167 packed.append(struct.pack("!L", self.curr))
1168 packed.append(struct.pack("!L", self.advertised))
1169 packed.append(struct.pack("!L", self.supported))
1170 packed.append(struct.pack("!L", self.peer))
1171 packed.append(struct.pack("!L", self.curr_speed))
1172 packed.append(struct.pack("!L", self.max_speed))
1173 return ''.join(packed)
1174
1175 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001176 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001177 obj = port_desc()
Dan Talaycof6202252013-07-02 01:00:29 -07001178 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001179 reader.skip(4)
1180 obj.hw_addr = list(reader.read('!6B'))
1181 reader.skip(2)
1182 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001183 obj.config = reader.read("!L")[0]
1184 obj.state = reader.read("!L")[0]
1185 obj.curr = reader.read("!L")[0]
1186 obj.advertised = reader.read("!L")[0]
1187 obj.supported = reader.read("!L")[0]
1188 obj.peer = reader.read("!L")[0]
1189 obj.curr_speed = reader.read("!L")[0]
1190 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001191 return obj
1192
1193 def __eq__(self, other):
1194 if type(self) != type(other): return False
1195 if self.port_no != other.port_no: return False
1196 if self.hw_addr != other.hw_addr: return False
1197 if self.name != other.name: return False
1198 if self.config != other.config: return False
1199 if self.state != other.state: return False
1200 if self.curr != other.curr: return False
1201 if self.advertised != other.advertised: return False
1202 if self.supported != other.supported: return False
1203 if self.peer != other.peer: return False
1204 if self.curr_speed != other.curr_speed: return False
1205 if self.max_speed != other.max_speed: return False
1206 return True
1207
Rich Lanec2ee4b82013-04-24 17:12:38 -07001208 def pretty_print(self, q):
1209 q.text("port_desc {")
1210 with q.group():
1211 with q.indent(2):
1212 q.breakable()
1213 q.text("port_no = ");
1214 q.text(util.pretty_port(self.port_no))
1215 q.text(","); q.breakable()
1216 q.text("hw_addr = ");
1217 q.text(util.pretty_mac(self.hw_addr))
1218 q.text(","); q.breakable()
1219 q.text("name = ");
1220 q.pp(self.name)
1221 q.text(","); q.breakable()
1222 q.text("config = ");
1223 q.text("%#x" % self.config)
1224 q.text(","); q.breakable()
1225 q.text("state = ");
1226 q.text("%#x" % self.state)
1227 q.text(","); q.breakable()
1228 q.text("curr = ");
1229 q.text("%#x" % self.curr)
1230 q.text(","); q.breakable()
1231 q.text("advertised = ");
1232 q.text("%#x" % self.advertised)
1233 q.text(","); q.breakable()
1234 q.text("supported = ");
1235 q.text("%#x" % self.supported)
1236 q.text(","); q.breakable()
1237 q.text("peer = ");
1238 q.text("%#x" % self.peer)
1239 q.text(","); q.breakable()
1240 q.text("curr_speed = ");
1241 q.text("%#x" % self.curr_speed)
1242 q.text(","); q.breakable()
1243 q.text("max_speed = ");
1244 q.text("%#x" % self.max_speed)
1245 q.breakable()
1246 q.text('}')
1247
Rich Lane7dcdf022013-12-11 14:45:27 -08001248
1249class port_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001250
1251 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):
1252 if port_no != None:
1253 self.port_no = port_no
1254 else:
1255 self.port_no = 0
1256 if rx_packets != None:
1257 self.rx_packets = rx_packets
1258 else:
1259 self.rx_packets = 0
1260 if tx_packets != None:
1261 self.tx_packets = tx_packets
1262 else:
1263 self.tx_packets = 0
1264 if rx_bytes != None:
1265 self.rx_bytes = rx_bytes
1266 else:
1267 self.rx_bytes = 0
1268 if tx_bytes != None:
1269 self.tx_bytes = tx_bytes
1270 else:
1271 self.tx_bytes = 0
1272 if rx_dropped != None:
1273 self.rx_dropped = rx_dropped
1274 else:
1275 self.rx_dropped = 0
1276 if tx_dropped != None:
1277 self.tx_dropped = tx_dropped
1278 else:
1279 self.tx_dropped = 0
1280 if rx_errors != None:
1281 self.rx_errors = rx_errors
1282 else:
1283 self.rx_errors = 0
1284 if tx_errors != None:
1285 self.tx_errors = tx_errors
1286 else:
1287 self.tx_errors = 0
1288 if rx_frame_err != None:
1289 self.rx_frame_err = rx_frame_err
1290 else:
1291 self.rx_frame_err = 0
1292 if rx_over_err != None:
1293 self.rx_over_err = rx_over_err
1294 else:
1295 self.rx_over_err = 0
1296 if rx_crc_err != None:
1297 self.rx_crc_err = rx_crc_err
1298 else:
1299 self.rx_crc_err = 0
1300 if collisions != None:
1301 self.collisions = collisions
1302 else:
1303 self.collisions = 0
1304 return
1305
1306 def pack(self):
1307 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001308 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001309 packed.append('\x00' * 4)
1310 packed.append(struct.pack("!Q", self.rx_packets))
1311 packed.append(struct.pack("!Q", self.tx_packets))
1312 packed.append(struct.pack("!Q", self.rx_bytes))
1313 packed.append(struct.pack("!Q", self.tx_bytes))
1314 packed.append(struct.pack("!Q", self.rx_dropped))
1315 packed.append(struct.pack("!Q", self.tx_dropped))
1316 packed.append(struct.pack("!Q", self.rx_errors))
1317 packed.append(struct.pack("!Q", self.tx_errors))
1318 packed.append(struct.pack("!Q", self.rx_frame_err))
1319 packed.append(struct.pack("!Q", self.rx_over_err))
1320 packed.append(struct.pack("!Q", self.rx_crc_err))
1321 packed.append(struct.pack("!Q", self.collisions))
1322 return ''.join(packed)
1323
1324 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001325 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001326 obj = port_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001327 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001328 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001329 obj.rx_packets = reader.read("!Q")[0]
1330 obj.tx_packets = reader.read("!Q")[0]
1331 obj.rx_bytes = reader.read("!Q")[0]
1332 obj.tx_bytes = reader.read("!Q")[0]
1333 obj.rx_dropped = reader.read("!Q")[0]
1334 obj.tx_dropped = reader.read("!Q")[0]
1335 obj.rx_errors = reader.read("!Q")[0]
1336 obj.tx_errors = reader.read("!Q")[0]
1337 obj.rx_frame_err = reader.read("!Q")[0]
1338 obj.rx_over_err = reader.read("!Q")[0]
1339 obj.rx_crc_err = reader.read("!Q")[0]
1340 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001341 return obj
1342
1343 def __eq__(self, other):
1344 if type(self) != type(other): return False
1345 if self.port_no != other.port_no: return False
1346 if self.rx_packets != other.rx_packets: return False
1347 if self.tx_packets != other.tx_packets: return False
1348 if self.rx_bytes != other.rx_bytes: return False
1349 if self.tx_bytes != other.tx_bytes: return False
1350 if self.rx_dropped != other.rx_dropped: return False
1351 if self.tx_dropped != other.tx_dropped: return False
1352 if self.rx_errors != other.rx_errors: return False
1353 if self.tx_errors != other.tx_errors: return False
1354 if self.rx_frame_err != other.rx_frame_err: return False
1355 if self.rx_over_err != other.rx_over_err: return False
1356 if self.rx_crc_err != other.rx_crc_err: return False
1357 if self.collisions != other.collisions: return False
1358 return True
1359
Rich Lanec2ee4b82013-04-24 17:12:38 -07001360 def pretty_print(self, q):
1361 q.text("port_stats_entry {")
1362 with q.group():
1363 with q.indent(2):
1364 q.breakable()
1365 q.text("port_no = ");
1366 q.text(util.pretty_port(self.port_no))
1367 q.text(","); q.breakable()
1368 q.text("rx_packets = ");
1369 q.text("%#x" % self.rx_packets)
1370 q.text(","); q.breakable()
1371 q.text("tx_packets = ");
1372 q.text("%#x" % self.tx_packets)
1373 q.text(","); q.breakable()
1374 q.text("rx_bytes = ");
1375 q.text("%#x" % self.rx_bytes)
1376 q.text(","); q.breakable()
1377 q.text("tx_bytes = ");
1378 q.text("%#x" % self.tx_bytes)
1379 q.text(","); q.breakable()
1380 q.text("rx_dropped = ");
1381 q.text("%#x" % self.rx_dropped)
1382 q.text(","); q.breakable()
1383 q.text("tx_dropped = ");
1384 q.text("%#x" % self.tx_dropped)
1385 q.text(","); q.breakable()
1386 q.text("rx_errors = ");
1387 q.text("%#x" % self.rx_errors)
1388 q.text(","); q.breakable()
1389 q.text("tx_errors = ");
1390 q.text("%#x" % self.tx_errors)
1391 q.text(","); q.breakable()
1392 q.text("rx_frame_err = ");
1393 q.text("%#x" % self.rx_frame_err)
1394 q.text(","); q.breakable()
1395 q.text("rx_over_err = ");
1396 q.text("%#x" % self.rx_over_err)
1397 q.text(","); q.breakable()
1398 q.text("rx_crc_err = ");
1399 q.text("%#x" % self.rx_crc_err)
1400 q.text(","); q.breakable()
1401 q.text("collisions = ");
1402 q.text("%#x" % self.collisions)
1403 q.breakable()
1404 q.text('}')
1405
Rich Lane7dcdf022013-12-11 14:45:27 -08001406
1407class queue_prop(loxi.OFObject):
1408 subtypes = {}
1409
Rich Lane95f7fc92014-01-27 17:08:16 -08001410
1411 def __init__(self, type=None):
1412 if type != None:
1413 self.type = type
1414 else:
1415 self.type = 0
1416 return
1417
1418 def pack(self):
1419 packed = []
1420 packed.append(struct.pack("!H", self.type))
1421 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1422 packed.append('\x00' * 4)
1423 length = sum([len(x) for x in packed])
1424 packed[1] = struct.pack("!H", length)
1425 return ''.join(packed)
1426
Rich Lane7dcdf022013-12-11 14:45:27 -08001427 @staticmethod
1428 def unpack(reader):
1429 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -08001430 subclass = queue_prop.subtypes.get(subtype)
1431 if subclass:
1432 return subclass.unpack(reader)
1433
1434 obj = queue_prop()
1435 obj.type = reader.read("!H")[0]
1436 _len = reader.read("!H")[0]
1437 orig_reader = reader
1438 reader = orig_reader.slice(_len - (2 + 2))
1439 reader.skip(4)
1440 return obj
1441
1442 def __eq__(self, other):
1443 if type(self) != type(other): return False
1444 if self.type != other.type: return False
1445 return True
1446
1447 def pretty_print(self, q):
1448 q.text("queue_prop {")
1449 with q.group():
1450 with q.indent(2):
1451 q.breakable()
1452 q.breakable()
1453 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -08001454
1455
1456class queue_prop_min_rate(queue_prop):
Dan Talaycof6202252013-07-02 01:00:29 -07001457 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001458
1459 def __init__(self, rate=None):
1460 if rate != None:
1461 self.rate = rate
1462 else:
1463 self.rate = 0
1464 return
1465
1466 def pack(self):
1467 packed = []
1468 packed.append(struct.pack("!H", self.type))
1469 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1470 packed.append('\x00' * 4)
1471 packed.append(struct.pack("!H", self.rate))
1472 packed.append('\x00' * 6)
1473 length = sum([len(x) for x in packed])
1474 packed[1] = struct.pack("!H", length)
1475 return ''.join(packed)
1476
1477 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001478 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001479 obj = queue_prop_min_rate()
Dan Talaycof6202252013-07-02 01:00:29 -07001480 _type = reader.read("!H")[0]
1481 assert(_type == 1)
1482 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001483 orig_reader = reader
1484 reader = orig_reader.slice(_len - (2 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001485 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001486 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001487 reader.skip(6)
1488 return obj
1489
1490 def __eq__(self, other):
1491 if type(self) != type(other): return False
1492 if self.rate != other.rate: return False
1493 return True
1494
Rich Lanec2ee4b82013-04-24 17:12:38 -07001495 def pretty_print(self, q):
1496 q.text("queue_prop_min_rate {")
1497 with q.group():
1498 with q.indent(2):
1499 q.breakable()
1500 q.text("rate = ");
1501 q.text("%#x" % self.rate)
1502 q.breakable()
1503 q.text('}')
1504
Rich Lane7dcdf022013-12-11 14:45:27 -08001505queue_prop.subtypes[1] = queue_prop_min_rate
1506
1507class queue_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001508
1509 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1510 if port_no != None:
1511 self.port_no = port_no
1512 else:
1513 self.port_no = 0
1514 if queue_id != None:
1515 self.queue_id = queue_id
1516 else:
1517 self.queue_id = 0
1518 if tx_bytes != None:
1519 self.tx_bytes = tx_bytes
1520 else:
1521 self.tx_bytes = 0
1522 if tx_packets != None:
1523 self.tx_packets = tx_packets
1524 else:
1525 self.tx_packets = 0
1526 if tx_errors != None:
1527 self.tx_errors = tx_errors
1528 else:
1529 self.tx_errors = 0
1530 return
1531
1532 def pack(self):
1533 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001534 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001535 packed.append(struct.pack("!L", self.queue_id))
1536 packed.append(struct.pack("!Q", self.tx_bytes))
1537 packed.append(struct.pack("!Q", self.tx_packets))
1538 packed.append(struct.pack("!Q", self.tx_errors))
1539 return ''.join(packed)
1540
1541 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001542 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001543 obj = queue_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001544 obj.port_no = util.unpack_port_no(reader)
1545 obj.queue_id = reader.read("!L")[0]
1546 obj.tx_bytes = reader.read("!Q")[0]
1547 obj.tx_packets = reader.read("!Q")[0]
1548 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001549 return obj
1550
1551 def __eq__(self, other):
1552 if type(self) != type(other): return False
1553 if self.port_no != other.port_no: return False
1554 if self.queue_id != other.queue_id: return False
1555 if self.tx_bytes != other.tx_bytes: return False
1556 if self.tx_packets != other.tx_packets: return False
1557 if self.tx_errors != other.tx_errors: return False
1558 return True
1559
Rich Lanec2ee4b82013-04-24 17:12:38 -07001560 def pretty_print(self, q):
1561 q.text("queue_stats_entry {")
1562 with q.group():
1563 with q.indent(2):
1564 q.breakable()
1565 q.text("port_no = ");
1566 q.text(util.pretty_port(self.port_no))
1567 q.text(","); q.breakable()
1568 q.text("queue_id = ");
1569 q.text("%#x" % self.queue_id)
1570 q.text(","); q.breakable()
1571 q.text("tx_bytes = ");
1572 q.text("%#x" % self.tx_bytes)
1573 q.text(","); q.breakable()
1574 q.text("tx_packets = ");
1575 q.text("%#x" % self.tx_packets)
1576 q.text(","); q.breakable()
1577 q.text("tx_errors = ");
1578 q.text("%#x" % self.tx_errors)
1579 q.breakable()
1580 q.text('}')
1581
Rich Lane7dcdf022013-12-11 14:45:27 -08001582
1583class table_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001584
1585 def __init__(self, table_id=None, name=None, wildcards=None, match=None, instructions=None, write_actions=None, apply_actions=None, config=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
1586 if table_id != None:
1587 self.table_id = table_id
1588 else:
1589 self.table_id = 0
1590 if name != None:
1591 self.name = name
1592 else:
1593 self.name = ""
1594 if wildcards != None:
1595 self.wildcards = wildcards
1596 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001597 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001598 if match != None:
1599 self.match = match
1600 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001601 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001602 if instructions != None:
1603 self.instructions = instructions
1604 else:
1605 self.instructions = 0
1606 if write_actions != None:
1607 self.write_actions = write_actions
1608 else:
1609 self.write_actions = 0
1610 if apply_actions != None:
1611 self.apply_actions = apply_actions
1612 else:
1613 self.apply_actions = 0
1614 if config != None:
1615 self.config = config
1616 else:
1617 self.config = 0
1618 if max_entries != None:
1619 self.max_entries = max_entries
1620 else:
1621 self.max_entries = 0
1622 if active_count != None:
1623 self.active_count = active_count
1624 else:
1625 self.active_count = 0
1626 if lookup_count != None:
1627 self.lookup_count = lookup_count
1628 else:
1629 self.lookup_count = 0
1630 if matched_count != None:
1631 self.matched_count = matched_count
1632 else:
1633 self.matched_count = 0
1634 return
1635
1636 def pack(self):
1637 packed = []
1638 packed.append(struct.pack("!B", self.table_id))
1639 packed.append('\x00' * 7)
1640 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001641 packed.append(util.pack_wc_bmap(self.wildcards))
1642 packed.append(util.pack_match_bmap(self.match))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001643 packed.append(struct.pack("!L", self.instructions))
1644 packed.append(struct.pack("!L", self.write_actions))
1645 packed.append(struct.pack("!L", self.apply_actions))
1646 packed.append(struct.pack("!L", self.config))
1647 packed.append(struct.pack("!L", self.max_entries))
1648 packed.append(struct.pack("!L", self.active_count))
1649 packed.append(struct.pack("!Q", self.lookup_count))
1650 packed.append(struct.pack("!Q", self.matched_count))
1651 return ''.join(packed)
1652
1653 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001654 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001655 obj = table_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001656 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001657 reader.skip(7)
1658 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001659 obj.wildcards = util.unpack_wc_bmap(reader)
1660 obj.match = util.unpack_match_bmap(reader)
1661 obj.instructions = reader.read("!L")[0]
1662 obj.write_actions = reader.read("!L")[0]
1663 obj.apply_actions = reader.read("!L")[0]
1664 obj.config = reader.read("!L")[0]
1665 obj.max_entries = reader.read("!L")[0]
1666 obj.active_count = reader.read("!L")[0]
1667 obj.lookup_count = reader.read("!Q")[0]
1668 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001669 return obj
1670
1671 def __eq__(self, other):
1672 if type(self) != type(other): return False
1673 if self.table_id != other.table_id: return False
1674 if self.name != other.name: return False
1675 if self.wildcards != other.wildcards: return False
1676 if self.match != other.match: return False
1677 if self.instructions != other.instructions: return False
1678 if self.write_actions != other.write_actions: return False
1679 if self.apply_actions != other.apply_actions: return False
1680 if self.config != other.config: return False
1681 if self.max_entries != other.max_entries: return False
1682 if self.active_count != other.active_count: return False
1683 if self.lookup_count != other.lookup_count: return False
1684 if self.matched_count != other.matched_count: return False
1685 return True
1686
Rich Lanec2ee4b82013-04-24 17:12:38 -07001687 def pretty_print(self, q):
1688 q.text("table_stats_entry {")
1689 with q.group():
1690 with q.indent(2):
1691 q.breakable()
1692 q.text("table_id = ");
1693 q.text("%#x" % self.table_id)
1694 q.text(","); q.breakable()
1695 q.text("name = ");
1696 q.pp(self.name)
1697 q.text(","); q.breakable()
1698 q.text("wildcards = ");
1699 q.text(util.pretty_wildcards(self.wildcards))
1700 q.text(","); q.breakable()
1701 q.text("match = ");
1702 q.pp(self.match)
1703 q.text(","); q.breakable()
1704 q.text("instructions = ");
1705 q.text("%#x" % self.instructions)
1706 q.text(","); q.breakable()
1707 q.text("write_actions = ");
1708 q.text("%#x" % self.write_actions)
1709 q.text(","); q.breakable()
1710 q.text("apply_actions = ");
1711 q.text("%#x" % self.apply_actions)
1712 q.text(","); q.breakable()
1713 q.text("config = ");
1714 q.text("%#x" % self.config)
1715 q.text(","); q.breakable()
1716 q.text("max_entries = ");
1717 q.text("%#x" % self.max_entries)
1718 q.text(","); q.breakable()
1719 q.text("active_count = ");
1720 q.text("%#x" % self.active_count)
1721 q.text(","); q.breakable()
1722 q.text("lookup_count = ");
1723 q.text("%#x" % self.lookup_count)
1724 q.text(","); q.breakable()
1725 q.text("matched_count = ");
1726 q.text("%#x" % self.matched_count)
1727 q.breakable()
1728 q.text('}')
1729
1730
Rich Lane7dcdf022013-12-11 14:45:27 -08001731
Rich Lanec2ee4b82013-04-24 17:12:38 -07001732match = match_v2