blob: 99f1d3636760119d5dfb1e6e34d94dcc7b8e91aa [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 Lane5587ab12014-06-30 11:19:09 -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, 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
177 if if_name != None:
178 self.if_name = if_name
179 else:
180 self.if_name = ""
181 return
182
183 def pack(self):
184 packed = []
185 packed.append(struct.pack("!H", self.type))
186 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
187 packed.append(struct.pack("!L", self.flags))
188 packed.append(util.pack_port_no(self.port_no))
Rich Lane5587ab12014-06-30 11:19:09 -0700189 packed.append(util.pack_port_no(self.loopback_port_no))
Rich Lane93b33132014-04-21 12:20:58 -0700190 packed.append(struct.pack("!6B", *self.local_mac))
191 packed.append(struct.pack("!6B", *self.nh_mac))
192 packed.append(struct.pack("!L", self.src_ip))
193 packed.append(struct.pack("!L", self.dst_ip))
194 packed.append(struct.pack("!B", self.dscp))
195 packed.append(struct.pack("!B", self.ttl))
196 packed.append('\x00' * 2)
197 packed.append(struct.pack("!L", self.vpn))
198 packed.append(struct.pack("!16s", self.if_name))
199 length = sum([len(x) for x in packed])
200 packed[1] = struct.pack("!H", length)
201 return ''.join(packed)
202
203 @staticmethod
204 def unpack(reader):
205 obj = bsn_vport_l2gre()
206 _type = reader.read("!H")[0]
207 assert(_type == 1)
208 _length = reader.read("!H")[0]
209 orig_reader = reader
210 reader = orig_reader.slice(_length - (2 + 2))
211 obj.flags = reader.read("!L")[0]
212 obj.port_no = util.unpack_port_no(reader)
Rich Lane5587ab12014-06-30 11:19:09 -0700213 obj.loopback_port_no = util.unpack_port_no(reader)
Rich Lane93b33132014-04-21 12:20:58 -0700214 obj.local_mac = list(reader.read('!6B'))
215 obj.nh_mac = list(reader.read('!6B'))
216 obj.src_ip = reader.read("!L")[0]
217 obj.dst_ip = reader.read("!L")[0]
218 obj.dscp = reader.read("!B")[0]
219 obj.ttl = reader.read("!B")[0]
220 reader.skip(2)
221 obj.vpn = reader.read("!L")[0]
222 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
223 return obj
224
225 def __eq__(self, other):
226 if type(self) != type(other): return False
227 if self.flags != other.flags: return False
228 if self.port_no != other.port_no: return False
Rich Lane5587ab12014-06-30 11:19:09 -0700229 if self.loopback_port_no != other.loopback_port_no: return False
Rich Lane93b33132014-04-21 12:20:58 -0700230 if self.local_mac != other.local_mac: return False
231 if self.nh_mac != other.nh_mac: return False
232 if self.src_ip != other.src_ip: return False
233 if self.dst_ip != other.dst_ip: return False
234 if self.dscp != other.dscp: return False
235 if self.ttl != other.ttl: return False
236 if self.vpn != other.vpn: return False
237 if self.if_name != other.if_name: return False
238 return True
239
240 def pretty_print(self, q):
241 q.text("bsn_vport_l2gre {")
242 with q.group():
243 with q.indent(2):
244 q.breakable()
245 q.text("flags = ");
246 q.text("%#x" % self.flags)
247 q.text(","); q.breakable()
248 q.text("port_no = ");
249 q.text(util.pretty_port(self.port_no))
250 q.text(","); q.breakable()
Rich Lane5587ab12014-06-30 11:19:09 -0700251 q.text("loopback_port_no = ");
252 q.text(util.pretty_port(self.loopback_port_no))
253 q.text(","); q.breakable()
Rich Lane93b33132014-04-21 12:20:58 -0700254 q.text("local_mac = ");
255 q.text(util.pretty_mac(self.local_mac))
256 q.text(","); q.breakable()
257 q.text("nh_mac = ");
258 q.text(util.pretty_mac(self.nh_mac))
259 q.text(","); q.breakable()
260 q.text("src_ip = ");
261 q.text(util.pretty_ipv4(self.src_ip))
262 q.text(","); q.breakable()
263 q.text("dst_ip = ");
264 q.text(util.pretty_ipv4(self.dst_ip))
265 q.text(","); q.breakable()
266 q.text("dscp = ");
267 q.text("%#x" % self.dscp)
268 q.text(","); q.breakable()
269 q.text("ttl = ");
270 q.text("%#x" % self.ttl)
271 q.text(","); q.breakable()
272 q.text("vpn = ");
273 q.text("%#x" % self.vpn)
274 q.text(","); q.breakable()
275 q.text("if_name = ");
276 q.pp(self.if_name)
277 q.breakable()
278 q.text('}')
279
280bsn_vport.subtypes[1] = bsn_vport_l2gre
281
Rich Lane7dcdf022013-12-11 14:45:27 -0800282class bsn_vport_q_in_q(bsn_vport):
Dan Talaycof6202252013-07-02 01:00:29 -0700283 type = 0
284
Kiran Poola150d8b02013-09-20 13:30:39 -0700285 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 -0700286 if port_no != None:
287 self.port_no = port_no
288 else:
289 self.port_no = 0
290 if ingress_tpid != None:
291 self.ingress_tpid = ingress_tpid
292 else:
293 self.ingress_tpid = 0
294 if ingress_vlan_id != None:
295 self.ingress_vlan_id = ingress_vlan_id
296 else:
297 self.ingress_vlan_id = 0
298 if egress_tpid != None:
299 self.egress_tpid = egress_tpid
300 else:
301 self.egress_tpid = 0
302 if egress_vlan_id != None:
303 self.egress_vlan_id = egress_vlan_id
304 else:
305 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700306 if if_name != None:
307 self.if_name = if_name
308 else:
309 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700310 return
311
312 def pack(self):
313 packed = []
314 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700315 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700316 packed.append(struct.pack("!L", self.port_no))
317 packed.append(struct.pack("!H", self.ingress_tpid))
318 packed.append(struct.pack("!H", self.ingress_vlan_id))
319 packed.append(struct.pack("!H", self.egress_tpid))
320 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700321 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700322 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700323 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700324 return ''.join(packed)
325
326 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800327 def unpack(reader):
Dan Talaycof6202252013-07-02 01:00:29 -0700328 obj = bsn_vport_q_in_q()
Dan Talaycof6202252013-07-02 01:00:29 -0700329 _type = reader.read("!H")[0]
330 assert(_type == 0)
331 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800332 orig_reader = reader
333 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700334 obj.port_no = reader.read("!L")[0]
335 obj.ingress_tpid = reader.read("!H")[0]
336 obj.ingress_vlan_id = reader.read("!H")[0]
337 obj.egress_tpid = reader.read("!H")[0]
338 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700339 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700340 return obj
341
342 def __eq__(self, other):
343 if type(self) != type(other): return False
344 if self.port_no != other.port_no: return False
345 if self.ingress_tpid != other.ingress_tpid: return False
346 if self.ingress_vlan_id != other.ingress_vlan_id: return False
347 if self.egress_tpid != other.egress_tpid: return False
348 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700349 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700350 return True
351
Dan Talaycof6202252013-07-02 01:00:29 -0700352 def pretty_print(self, q):
353 q.text("bsn_vport_q_in_q {")
354 with q.group():
355 with q.indent(2):
356 q.breakable()
357 q.text("port_no = ");
358 q.text("%#x" % self.port_no)
359 q.text(","); q.breakable()
360 q.text("ingress_tpid = ");
361 q.text("%#x" % self.ingress_tpid)
362 q.text(","); q.breakable()
363 q.text("ingress_vlan_id = ");
364 q.text("%#x" % self.ingress_vlan_id)
365 q.text(","); q.breakable()
366 q.text("egress_tpid = ");
367 q.text("%#x" % self.egress_tpid)
368 q.text(","); q.breakable()
369 q.text("egress_vlan_id = ");
370 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700371 q.text(","); q.breakable()
372 q.text("if_name = ");
373 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700374 q.breakable()
375 q.text('}')
376
Rich Lane7dcdf022013-12-11 14:45:27 -0800377bsn_vport.subtypes[0] = bsn_vport_q_in_q
378
379class bucket(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700380
381 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
382 if weight != None:
383 self.weight = weight
384 else:
385 self.weight = 0
386 if watch_port != None:
387 self.watch_port = watch_port
388 else:
389 self.watch_port = 0
390 if watch_group != None:
391 self.watch_group = watch_group
392 else:
393 self.watch_group = 0
394 if actions != None:
395 self.actions = actions
396 else:
397 self.actions = []
398 return
399
400 def pack(self):
401 packed = []
402 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
403 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700404 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700405 packed.append(struct.pack("!L", self.watch_group))
406 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800407 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700408 length = sum([len(x) for x in packed])
409 packed[0] = struct.pack("!H", length)
410 return ''.join(packed)
411
412 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800413 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700414 obj = bucket()
Dan Talaycof6202252013-07-02 01:00:29 -0700415 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800416 orig_reader = reader
417 reader = orig_reader.slice(_len - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700418 obj.weight = reader.read("!H")[0]
419 obj.watch_port = util.unpack_port_no(reader)
420 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700421 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800422 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700423 return obj
424
425 def __eq__(self, other):
426 if type(self) != type(other): return False
427 if self.weight != other.weight: return False
428 if self.watch_port != other.watch_port: return False
429 if self.watch_group != other.watch_group: return False
430 if self.actions != other.actions: return False
431 return True
432
Rich Lanec2ee4b82013-04-24 17:12:38 -0700433 def pretty_print(self, q):
434 q.text("bucket {")
435 with q.group():
436 with q.indent(2):
437 q.breakable()
438 q.text("weight = ");
439 q.text("%#x" % self.weight)
440 q.text(","); q.breakable()
441 q.text("watch_port = ");
442 q.text(util.pretty_port(self.watch_port))
443 q.text(","); q.breakable()
444 q.text("watch_group = ");
445 q.text("%#x" % self.watch_group)
446 q.text(","); q.breakable()
447 q.text("actions = ");
448 q.pp(self.actions)
449 q.breakable()
450 q.text('}')
451
Rich Lane7dcdf022013-12-11 14:45:27 -0800452
453class bucket_counter(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700454
455 def __init__(self, packet_count=None, byte_count=None):
456 if packet_count != None:
457 self.packet_count = packet_count
458 else:
459 self.packet_count = 0
460 if byte_count != None:
461 self.byte_count = byte_count
462 else:
463 self.byte_count = 0
464 return
465
466 def pack(self):
467 packed = []
468 packed.append(struct.pack("!Q", self.packet_count))
469 packed.append(struct.pack("!Q", self.byte_count))
470 return ''.join(packed)
471
472 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800473 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700474 obj = bucket_counter()
Dan Talaycof6202252013-07-02 01:00:29 -0700475 obj.packet_count = reader.read("!Q")[0]
476 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700477 return obj
478
479 def __eq__(self, other):
480 if type(self) != type(other): return False
481 if self.packet_count != other.packet_count: return False
482 if self.byte_count != other.byte_count: return False
483 return True
484
Rich Lanec2ee4b82013-04-24 17:12:38 -0700485 def pretty_print(self, q):
486 q.text("bucket_counter {")
487 with q.group():
488 with q.indent(2):
489 q.breakable()
490 q.text("packet_count = ");
491 q.text("%#x" % self.packet_count)
492 q.text(","); q.breakable()
493 q.text("byte_count = ");
494 q.text("%#x" % self.byte_count)
495 q.breakable()
496 q.text('}')
497
Rich Lane7dcdf022013-12-11 14:45:27 -0800498
499class flow_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700500
501 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):
502 if table_id != None:
503 self.table_id = table_id
504 else:
505 self.table_id = 0
506 if duration_sec != None:
507 self.duration_sec = duration_sec
508 else:
509 self.duration_sec = 0
510 if duration_nsec != None:
511 self.duration_nsec = duration_nsec
512 else:
513 self.duration_nsec = 0
514 if priority != None:
515 self.priority = priority
516 else:
517 self.priority = 0
518 if idle_timeout != None:
519 self.idle_timeout = idle_timeout
520 else:
521 self.idle_timeout = 0
522 if hard_timeout != None:
523 self.hard_timeout = hard_timeout
524 else:
525 self.hard_timeout = 0
526 if cookie != None:
527 self.cookie = cookie
528 else:
529 self.cookie = 0
530 if packet_count != None:
531 self.packet_count = packet_count
532 else:
533 self.packet_count = 0
534 if byte_count != None:
535 self.byte_count = byte_count
536 else:
537 self.byte_count = 0
538 if match != None:
539 self.match = match
540 else:
541 self.match = common.match()
542 if instructions != None:
543 self.instructions = instructions
544 else:
545 self.instructions = []
546 return
547
548 def pack(self):
549 packed = []
550 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
551 packed.append(struct.pack("!B", self.table_id))
552 packed.append('\x00' * 1)
553 packed.append(struct.pack("!L", self.duration_sec))
554 packed.append(struct.pack("!L", self.duration_nsec))
555 packed.append(struct.pack("!H", self.priority))
556 packed.append(struct.pack("!H", self.idle_timeout))
557 packed.append(struct.pack("!H", self.hard_timeout))
558 packed.append('\x00' * 6)
559 packed.append(struct.pack("!Q", self.cookie))
560 packed.append(struct.pack("!Q", self.packet_count))
561 packed.append(struct.pack("!Q", self.byte_count))
562 packed.append(self.match.pack())
Rich Lane7dcdf022013-12-11 14:45:27 -0800563 packed.append(loxi.generic_util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700564 length = sum([len(x) for x in packed])
565 packed[0] = struct.pack("!H", length)
566 return ''.join(packed)
567
568 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800569 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700570 obj = flow_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700571 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800572 orig_reader = reader
573 reader = orig_reader.slice(_length - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700574 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700575 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700576 obj.duration_sec = reader.read("!L")[0]
577 obj.duration_nsec = reader.read("!L")[0]
578 obj.priority = reader.read("!H")[0]
579 obj.idle_timeout = reader.read("!H")[0]
580 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700581 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700582 obj.cookie = reader.read("!Q")[0]
583 obj.packet_count = reader.read("!Q")[0]
584 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700585 obj.match = common.match.unpack(reader)
Rich Lane7dcdf022013-12-11 14:45:27 -0800586 obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700587 return obj
588
589 def __eq__(self, other):
590 if type(self) != type(other): return False
591 if self.table_id != other.table_id: return False
592 if self.duration_sec != other.duration_sec: return False
593 if self.duration_nsec != other.duration_nsec: return False
594 if self.priority != other.priority: return False
595 if self.idle_timeout != other.idle_timeout: return False
596 if self.hard_timeout != other.hard_timeout: return False
597 if self.cookie != other.cookie: return False
598 if self.packet_count != other.packet_count: return False
599 if self.byte_count != other.byte_count: return False
600 if self.match != other.match: return False
601 if self.instructions != other.instructions: return False
602 return True
603
Rich Lanec2ee4b82013-04-24 17:12:38 -0700604 def pretty_print(self, q):
605 q.text("flow_stats_entry {")
606 with q.group():
607 with q.indent(2):
608 q.breakable()
609 q.text("table_id = ");
610 q.text("%#x" % self.table_id)
611 q.text(","); q.breakable()
612 q.text("duration_sec = ");
613 q.text("%#x" % self.duration_sec)
614 q.text(","); q.breakable()
615 q.text("duration_nsec = ");
616 q.text("%#x" % self.duration_nsec)
617 q.text(","); q.breakable()
618 q.text("priority = ");
619 q.text("%#x" % self.priority)
620 q.text(","); q.breakable()
621 q.text("idle_timeout = ");
622 q.text("%#x" % self.idle_timeout)
623 q.text(","); q.breakable()
624 q.text("hard_timeout = ");
625 q.text("%#x" % self.hard_timeout)
626 q.text(","); q.breakable()
627 q.text("cookie = ");
628 q.text("%#x" % self.cookie)
629 q.text(","); q.breakable()
630 q.text("packet_count = ");
631 q.text("%#x" % self.packet_count)
632 q.text(","); q.breakable()
633 q.text("byte_count = ");
634 q.text("%#x" % self.byte_count)
635 q.text(","); q.breakable()
636 q.text("match = ");
637 q.pp(self.match)
638 q.text(","); q.breakable()
639 q.text("instructions = ");
640 q.pp(self.instructions)
641 q.breakable()
642 q.text('}')
643
Rich Lane7dcdf022013-12-11 14:45:27 -0800644
645class group_desc_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700646
Rich Lane6f4978c2013-10-20 21:33:52 -0700647 def __init__(self, group_type=None, group_id=None, buckets=None):
648 if group_type != None:
649 self.group_type = group_type
Rich Lanec2ee4b82013-04-24 17:12:38 -0700650 else:
Rich Lane6f4978c2013-10-20 21:33:52 -0700651 self.group_type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700652 if group_id != None:
653 self.group_id = group_id
654 else:
655 self.group_id = 0
656 if buckets != None:
657 self.buckets = buckets
658 else:
659 self.buckets = []
660 return
661
662 def pack(self):
663 packed = []
664 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
Rich Lane6f4978c2013-10-20 21:33:52 -0700665 packed.append(struct.pack("!B", self.group_type))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700666 packed.append('\x00' * 1)
667 packed.append(struct.pack("!L", self.group_id))
Rich Lane7dcdf022013-12-11 14:45:27 -0800668 packed.append(loxi.generic_util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700669 length = sum([len(x) for x in packed])
670 packed[0] = struct.pack("!H", length)
671 return ''.join(packed)
672
673 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800674 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700675 obj = group_desc_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700676 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800677 orig_reader = reader
678 reader = orig_reader.slice(_length - (0 + 2))
Rich Lane6f4978c2013-10-20 21:33:52 -0700679 obj.group_type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700680 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700681 obj.group_id = reader.read("!L")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800682 obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700683 return obj
684
685 def __eq__(self, other):
686 if type(self) != type(other): return False
Rich Lane6f4978c2013-10-20 21:33:52 -0700687 if self.group_type != other.group_type: return False
Rich Lanec2ee4b82013-04-24 17:12:38 -0700688 if self.group_id != other.group_id: return False
689 if self.buckets != other.buckets: return False
690 return True
691
Rich Lanec2ee4b82013-04-24 17:12:38 -0700692 def pretty_print(self, q):
693 q.text("group_desc_stats_entry {")
694 with q.group():
695 with q.indent(2):
696 q.breakable()
Rich Lane6f4978c2013-10-20 21:33:52 -0700697 q.text("group_type = ");
698 q.text("%#x" % self.group_type)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700699 q.text(","); q.breakable()
700 q.text("group_id = ");
701 q.text("%#x" % self.group_id)
702 q.text(","); q.breakable()
703 q.text("buckets = ");
704 q.pp(self.buckets)
705 q.breakable()
706 q.text('}')
707
Rich Lane7dcdf022013-12-11 14:45:27 -0800708
709class group_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700710
711 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
712 if group_id != None:
713 self.group_id = group_id
714 else:
715 self.group_id = 0
716 if ref_count != None:
717 self.ref_count = ref_count
718 else:
719 self.ref_count = 0
720 if packet_count != None:
721 self.packet_count = packet_count
722 else:
723 self.packet_count = 0
724 if byte_count != None:
725 self.byte_count = byte_count
726 else:
727 self.byte_count = 0
728 if bucket_stats != None:
729 self.bucket_stats = bucket_stats
730 else:
731 self.bucket_stats = []
732 return
733
734 def pack(self):
735 packed = []
736 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
737 packed.append('\x00' * 2)
738 packed.append(struct.pack("!L", self.group_id))
739 packed.append(struct.pack("!L", self.ref_count))
740 packed.append('\x00' * 4)
741 packed.append(struct.pack("!Q", self.packet_count))
742 packed.append(struct.pack("!Q", self.byte_count))
Rich Lane7dcdf022013-12-11 14:45:27 -0800743 packed.append(loxi.generic_util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700744 length = sum([len(x) for x in packed])
745 packed[0] = struct.pack("!H", length)
746 return ''.join(packed)
747
748 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800749 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700750 obj = group_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700751 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800752 orig_reader = reader
753 reader = orig_reader.slice(_length - (0 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700754 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700755 obj.group_id = reader.read("!L")[0]
756 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700757 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700758 obj.packet_count = reader.read("!Q")[0]
759 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700760 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
761 return obj
762
763 def __eq__(self, other):
764 if type(self) != type(other): return False
765 if self.group_id != other.group_id: return False
766 if self.ref_count != other.ref_count: return False
767 if self.packet_count != other.packet_count: return False
768 if self.byte_count != other.byte_count: return False
769 if self.bucket_stats != other.bucket_stats: return False
770 return True
771
Rich Lanec2ee4b82013-04-24 17:12:38 -0700772 def pretty_print(self, q):
773 q.text("group_stats_entry {")
774 with q.group():
775 with q.indent(2):
776 q.breakable()
777 q.text("group_id = ");
778 q.text("%#x" % self.group_id)
779 q.text(","); q.breakable()
780 q.text("ref_count = ");
781 q.text("%#x" % self.ref_count)
782 q.text(","); q.breakable()
783 q.text("packet_count = ");
784 q.text("%#x" % self.packet_count)
785 q.text(","); q.breakable()
786 q.text("byte_count = ");
787 q.text("%#x" % self.byte_count)
788 q.text(","); q.breakable()
789 q.text("bucket_stats = ");
790 q.pp(self.bucket_stats)
791 q.breakable()
792 q.text('}')
793
Rich Lane7dcdf022013-12-11 14:45:27 -0800794
795class match_v2(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700796 type = 0
797
798 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):
799 if in_port != None:
800 self.in_port = in_port
801 else:
802 self.in_port = 0
803 if wildcards != None:
804 self.wildcards = wildcards
805 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700806 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700807 if eth_src != None:
808 self.eth_src = eth_src
809 else:
810 self.eth_src = [0,0,0,0,0,0]
811 if eth_src_mask != None:
812 self.eth_src_mask = eth_src_mask
813 else:
814 self.eth_src_mask = [0,0,0,0,0,0]
815 if eth_dst != None:
816 self.eth_dst = eth_dst
817 else:
818 self.eth_dst = [0,0,0,0,0,0]
819 if eth_dst_mask != None:
820 self.eth_dst_mask = eth_dst_mask
821 else:
822 self.eth_dst_mask = [0,0,0,0,0,0]
823 if vlan_vid != None:
824 self.vlan_vid = vlan_vid
825 else:
826 self.vlan_vid = 0
827 if vlan_pcp != None:
828 self.vlan_pcp = vlan_pcp
829 else:
830 self.vlan_pcp = 0
831 if eth_type != None:
832 self.eth_type = eth_type
833 else:
834 self.eth_type = 0
835 if ip_dscp != None:
836 self.ip_dscp = ip_dscp
837 else:
838 self.ip_dscp = 0
839 if ip_proto != None:
840 self.ip_proto = ip_proto
841 else:
842 self.ip_proto = 0
843 if ipv4_src != None:
844 self.ipv4_src = ipv4_src
845 else:
846 self.ipv4_src = 0
847 if ipv4_src_mask != None:
848 self.ipv4_src_mask = ipv4_src_mask
849 else:
850 self.ipv4_src_mask = 0
851 if ipv4_dst != None:
852 self.ipv4_dst = ipv4_dst
853 else:
854 self.ipv4_dst = 0
855 if ipv4_dst_mask != None:
856 self.ipv4_dst_mask = ipv4_dst_mask
857 else:
858 self.ipv4_dst_mask = 0
859 if tcp_src != None:
860 self.tcp_src = tcp_src
861 else:
862 self.tcp_src = 0
863 if tcp_dst != None:
864 self.tcp_dst = tcp_dst
865 else:
866 self.tcp_dst = 0
867 if mpls_label != None:
868 self.mpls_label = mpls_label
869 else:
870 self.mpls_label = 0
871 if mpls_tc != None:
872 self.mpls_tc = mpls_tc
873 else:
874 self.mpls_tc = 0
875 if metadata != None:
876 self.metadata = metadata
877 else:
878 self.metadata = 0
879 if metadata_mask != None:
880 self.metadata_mask = metadata_mask
881 else:
882 self.metadata_mask = 0
883 return
884
885 def pack(self):
886 packed = []
887 packed.append(struct.pack("!H", self.type))
888 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700889 packed.append(util.pack_port_no(self.in_port))
890 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700891 packed.append(struct.pack("!6B", *self.eth_src))
892 packed.append(struct.pack("!6B", *self.eth_src_mask))
893 packed.append(struct.pack("!6B", *self.eth_dst))
894 packed.append(struct.pack("!6B", *self.eth_dst_mask))
895 packed.append(struct.pack("!H", self.vlan_vid))
896 packed.append(struct.pack("!B", self.vlan_pcp))
897 packed.append('\x00' * 1)
898 packed.append(struct.pack("!H", self.eth_type))
899 packed.append(struct.pack("!B", self.ip_dscp))
900 packed.append(struct.pack("!B", self.ip_proto))
901 packed.append(struct.pack("!L", self.ipv4_src))
902 packed.append(struct.pack("!L", self.ipv4_src_mask))
903 packed.append(struct.pack("!L", self.ipv4_dst))
904 packed.append(struct.pack("!L", self.ipv4_dst_mask))
905 packed.append(struct.pack("!H", self.tcp_src))
906 packed.append(struct.pack("!H", self.tcp_dst))
907 packed.append(struct.pack("!L", self.mpls_label))
908 packed.append(struct.pack("!B", self.mpls_tc))
909 packed.append('\x00' * 3)
910 packed.append(struct.pack("!Q", self.metadata))
911 packed.append(struct.pack("!Q", self.metadata_mask))
912 length = sum([len(x) for x in packed])
913 packed[1] = struct.pack("!H", length)
914 return ''.join(packed)
915
916 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800917 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700918 obj = match_v2()
Dan Talaycof6202252013-07-02 01:00:29 -0700919 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700920 assert(_type == 0)
Dan Talaycof6202252013-07-02 01:00:29 -0700921 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800922 orig_reader = reader
923 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700924 obj.in_port = util.unpack_port_no(reader)
925 obj.wildcards = util.unpack_wc_bmap(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700926 obj.eth_src = list(reader.read('!6B'))
927 obj.eth_src_mask = list(reader.read('!6B'))
928 obj.eth_dst = list(reader.read('!6B'))
929 obj.eth_dst_mask = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700930 obj.vlan_vid = reader.read("!H")[0]
931 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700932 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700933 obj.eth_type = reader.read("!H")[0]
934 obj.ip_dscp = reader.read("!B")[0]
935 obj.ip_proto = reader.read("!B")[0]
936 obj.ipv4_src = reader.read("!L")[0]
937 obj.ipv4_src_mask = reader.read("!L")[0]
938 obj.ipv4_dst = reader.read("!L")[0]
939 obj.ipv4_dst_mask = reader.read("!L")[0]
940 obj.tcp_src = reader.read("!H")[0]
941 obj.tcp_dst = reader.read("!H")[0]
942 obj.mpls_label = reader.read("!L")[0]
943 obj.mpls_tc = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700944 reader.skip(3)
Dan Talaycof6202252013-07-02 01:00:29 -0700945 obj.metadata = reader.read("!Q")[0]
946 obj.metadata_mask = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700947 return obj
948
949 def __eq__(self, other):
950 if type(self) != type(other): return False
951 if self.in_port != other.in_port: return False
952 if self.wildcards != other.wildcards: return False
953 if self.eth_src != other.eth_src: return False
954 if self.eth_src_mask != other.eth_src_mask: return False
955 if self.eth_dst != other.eth_dst: return False
956 if self.eth_dst_mask != other.eth_dst_mask: return False
957 if self.vlan_vid != other.vlan_vid: return False
958 if self.vlan_pcp != other.vlan_pcp: return False
959 if self.eth_type != other.eth_type: return False
960 if self.ip_dscp != other.ip_dscp: return False
961 if self.ip_proto != other.ip_proto: return False
962 if self.ipv4_src != other.ipv4_src: return False
963 if self.ipv4_src_mask != other.ipv4_src_mask: return False
964 if self.ipv4_dst != other.ipv4_dst: return False
965 if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
966 if self.tcp_src != other.tcp_src: return False
967 if self.tcp_dst != other.tcp_dst: return False
968 if self.mpls_label != other.mpls_label: return False
969 if self.mpls_tc != other.mpls_tc: return False
970 if self.metadata != other.metadata: return False
971 if self.metadata_mask != other.metadata_mask: return False
972 return True
973
Rich Lanec2ee4b82013-04-24 17:12:38 -0700974 def pretty_print(self, q):
975 q.text("match_v2 {")
976 with q.group():
977 with q.indent(2):
978 q.breakable()
979 q.text("in_port = ");
980 q.text(util.pretty_port(self.in_port))
981 q.text(","); q.breakable()
982 q.text("wildcards = ");
983 q.text(util.pretty_wildcards(self.wildcards))
984 q.text(","); q.breakable()
985 q.text("eth_src = ");
986 q.text(util.pretty_mac(self.eth_src))
987 q.text(","); q.breakable()
988 q.text("eth_src_mask = ");
989 q.text(util.pretty_mac(self.eth_src_mask))
990 q.text(","); q.breakable()
991 q.text("eth_dst = ");
992 q.text(util.pretty_mac(self.eth_dst))
993 q.text(","); q.breakable()
994 q.text("eth_dst_mask = ");
995 q.text(util.pretty_mac(self.eth_dst_mask))
996 q.text(","); q.breakable()
997 q.text("vlan_vid = ");
998 q.text("%#x" % self.vlan_vid)
999 q.text(","); q.breakable()
1000 q.text("vlan_pcp = ");
1001 q.text("%#x" % self.vlan_pcp)
1002 q.text(","); q.breakable()
1003 q.text("eth_type = ");
1004 q.text("%#x" % self.eth_type)
1005 q.text(","); q.breakable()
1006 q.text("ip_dscp = ");
1007 q.text("%#x" % self.ip_dscp)
1008 q.text(","); q.breakable()
1009 q.text("ip_proto = ");
1010 q.text("%#x" % self.ip_proto)
1011 q.text(","); q.breakable()
1012 q.text("ipv4_src = ");
1013 q.text(util.pretty_ipv4(self.ipv4_src))
1014 q.text(","); q.breakable()
1015 q.text("ipv4_src_mask = ");
1016 q.text(util.pretty_ipv4(self.ipv4_src_mask))
1017 q.text(","); q.breakable()
1018 q.text("ipv4_dst = ");
1019 q.text(util.pretty_ipv4(self.ipv4_dst))
1020 q.text(","); q.breakable()
1021 q.text("ipv4_dst_mask = ");
1022 q.text(util.pretty_ipv4(self.ipv4_dst_mask))
1023 q.text(","); q.breakable()
1024 q.text("tcp_src = ");
1025 q.text("%#x" % self.tcp_src)
1026 q.text(","); q.breakable()
1027 q.text("tcp_dst = ");
1028 q.text("%#x" % self.tcp_dst)
1029 q.text(","); q.breakable()
1030 q.text("mpls_label = ");
1031 q.text("%#x" % self.mpls_label)
1032 q.text(","); q.breakable()
1033 q.text("mpls_tc = ");
1034 q.text("%#x" % self.mpls_tc)
1035 q.text(","); q.breakable()
1036 q.text("metadata = ");
1037 q.text("%#x" % self.metadata)
1038 q.text(","); q.breakable()
1039 q.text("metadata_mask = ");
1040 q.text("%#x" % self.metadata_mask)
1041 q.breakable()
1042 q.text('}')
1043
Rich Lane7dcdf022013-12-11 14:45:27 -08001044
1045class packet_queue(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001046
1047 def __init__(self, queue_id=None, properties=None):
1048 if queue_id != None:
1049 self.queue_id = queue_id
1050 else:
1051 self.queue_id = 0
1052 if properties != None:
1053 self.properties = properties
1054 else:
1055 self.properties = []
1056 return
1057
1058 def pack(self):
1059 packed = []
1060 packed.append(struct.pack("!L", self.queue_id))
1061 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1062 packed.append('\x00' * 2)
Rich Lane7dcdf022013-12-11 14:45:27 -08001063 packed.append(loxi.generic_util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001064 length = sum([len(x) for x in packed])
1065 packed[1] = struct.pack("!H", length)
1066 return ''.join(packed)
1067
1068 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001069 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001070 obj = packet_queue()
Dan Talaycof6202252013-07-02 01:00:29 -07001071 obj.queue_id = reader.read("!L")[0]
1072 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001073 orig_reader = reader
1074 reader = orig_reader.slice(_len - (4 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001075 reader.skip(2)
Rich Lane7dcdf022013-12-11 14:45:27 -08001076 obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001077 return obj
1078
1079 def __eq__(self, other):
1080 if type(self) != type(other): return False
1081 if self.queue_id != other.queue_id: return False
1082 if self.properties != other.properties: return False
1083 return True
1084
Rich Lanec2ee4b82013-04-24 17:12:38 -07001085 def pretty_print(self, q):
1086 q.text("packet_queue {")
1087 with q.group():
1088 with q.indent(2):
1089 q.breakable()
1090 q.text("queue_id = ");
1091 q.text("%#x" % self.queue_id)
1092 q.text(","); q.breakable()
1093 q.text("properties = ");
1094 q.pp(self.properties)
1095 q.breakable()
1096 q.text('}')
1097
Rich Lane7dcdf022013-12-11 14:45:27 -08001098
1099class port_desc(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001100
1101 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):
1102 if port_no != None:
1103 self.port_no = port_no
1104 else:
1105 self.port_no = 0
1106 if hw_addr != None:
1107 self.hw_addr = hw_addr
1108 else:
1109 self.hw_addr = [0,0,0,0,0,0]
1110 if name != None:
1111 self.name = name
1112 else:
1113 self.name = ""
1114 if config != None:
1115 self.config = config
1116 else:
1117 self.config = 0
1118 if state != None:
1119 self.state = state
1120 else:
1121 self.state = 0
1122 if curr != None:
1123 self.curr = curr
1124 else:
1125 self.curr = 0
1126 if advertised != None:
1127 self.advertised = advertised
1128 else:
1129 self.advertised = 0
1130 if supported != None:
1131 self.supported = supported
1132 else:
1133 self.supported = 0
1134 if peer != None:
1135 self.peer = peer
1136 else:
1137 self.peer = 0
1138 if curr_speed != None:
1139 self.curr_speed = curr_speed
1140 else:
1141 self.curr_speed = 0
1142 if max_speed != None:
1143 self.max_speed = max_speed
1144 else:
1145 self.max_speed = 0
1146 return
1147
1148 def pack(self):
1149 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001150 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001151 packed.append('\x00' * 4)
1152 packed.append(struct.pack("!6B", *self.hw_addr))
1153 packed.append('\x00' * 2)
1154 packed.append(struct.pack("!16s", self.name))
1155 packed.append(struct.pack("!L", self.config))
1156 packed.append(struct.pack("!L", self.state))
1157 packed.append(struct.pack("!L", self.curr))
1158 packed.append(struct.pack("!L", self.advertised))
1159 packed.append(struct.pack("!L", self.supported))
1160 packed.append(struct.pack("!L", self.peer))
1161 packed.append(struct.pack("!L", self.curr_speed))
1162 packed.append(struct.pack("!L", self.max_speed))
1163 return ''.join(packed)
1164
1165 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001166 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001167 obj = port_desc()
Dan Talaycof6202252013-07-02 01:00:29 -07001168 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001169 reader.skip(4)
1170 obj.hw_addr = list(reader.read('!6B'))
1171 reader.skip(2)
1172 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001173 obj.config = reader.read("!L")[0]
1174 obj.state = reader.read("!L")[0]
1175 obj.curr = reader.read("!L")[0]
1176 obj.advertised = reader.read("!L")[0]
1177 obj.supported = reader.read("!L")[0]
1178 obj.peer = reader.read("!L")[0]
1179 obj.curr_speed = reader.read("!L")[0]
1180 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001181 return obj
1182
1183 def __eq__(self, other):
1184 if type(self) != type(other): return False
1185 if self.port_no != other.port_no: return False
1186 if self.hw_addr != other.hw_addr: return False
1187 if self.name != other.name: return False
1188 if self.config != other.config: return False
1189 if self.state != other.state: return False
1190 if self.curr != other.curr: return False
1191 if self.advertised != other.advertised: return False
1192 if self.supported != other.supported: return False
1193 if self.peer != other.peer: return False
1194 if self.curr_speed != other.curr_speed: return False
1195 if self.max_speed != other.max_speed: return False
1196 return True
1197
Rich Lanec2ee4b82013-04-24 17:12:38 -07001198 def pretty_print(self, q):
1199 q.text("port_desc {")
1200 with q.group():
1201 with q.indent(2):
1202 q.breakable()
1203 q.text("port_no = ");
1204 q.text(util.pretty_port(self.port_no))
1205 q.text(","); q.breakable()
1206 q.text("hw_addr = ");
1207 q.text(util.pretty_mac(self.hw_addr))
1208 q.text(","); q.breakable()
1209 q.text("name = ");
1210 q.pp(self.name)
1211 q.text(","); q.breakable()
1212 q.text("config = ");
1213 q.text("%#x" % self.config)
1214 q.text(","); q.breakable()
1215 q.text("state = ");
1216 q.text("%#x" % self.state)
1217 q.text(","); q.breakable()
1218 q.text("curr = ");
1219 q.text("%#x" % self.curr)
1220 q.text(","); q.breakable()
1221 q.text("advertised = ");
1222 q.text("%#x" % self.advertised)
1223 q.text(","); q.breakable()
1224 q.text("supported = ");
1225 q.text("%#x" % self.supported)
1226 q.text(","); q.breakable()
1227 q.text("peer = ");
1228 q.text("%#x" % self.peer)
1229 q.text(","); q.breakable()
1230 q.text("curr_speed = ");
1231 q.text("%#x" % self.curr_speed)
1232 q.text(","); q.breakable()
1233 q.text("max_speed = ");
1234 q.text("%#x" % self.max_speed)
1235 q.breakable()
1236 q.text('}')
1237
Rich Lane7dcdf022013-12-11 14:45:27 -08001238
1239class port_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001240
1241 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):
1242 if port_no != None:
1243 self.port_no = port_no
1244 else:
1245 self.port_no = 0
1246 if rx_packets != None:
1247 self.rx_packets = rx_packets
1248 else:
1249 self.rx_packets = 0
1250 if tx_packets != None:
1251 self.tx_packets = tx_packets
1252 else:
1253 self.tx_packets = 0
1254 if rx_bytes != None:
1255 self.rx_bytes = rx_bytes
1256 else:
1257 self.rx_bytes = 0
1258 if tx_bytes != None:
1259 self.tx_bytes = tx_bytes
1260 else:
1261 self.tx_bytes = 0
1262 if rx_dropped != None:
1263 self.rx_dropped = rx_dropped
1264 else:
1265 self.rx_dropped = 0
1266 if tx_dropped != None:
1267 self.tx_dropped = tx_dropped
1268 else:
1269 self.tx_dropped = 0
1270 if rx_errors != None:
1271 self.rx_errors = rx_errors
1272 else:
1273 self.rx_errors = 0
1274 if tx_errors != None:
1275 self.tx_errors = tx_errors
1276 else:
1277 self.tx_errors = 0
1278 if rx_frame_err != None:
1279 self.rx_frame_err = rx_frame_err
1280 else:
1281 self.rx_frame_err = 0
1282 if rx_over_err != None:
1283 self.rx_over_err = rx_over_err
1284 else:
1285 self.rx_over_err = 0
1286 if rx_crc_err != None:
1287 self.rx_crc_err = rx_crc_err
1288 else:
1289 self.rx_crc_err = 0
1290 if collisions != None:
1291 self.collisions = collisions
1292 else:
1293 self.collisions = 0
1294 return
1295
1296 def pack(self):
1297 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001298 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001299 packed.append('\x00' * 4)
1300 packed.append(struct.pack("!Q", self.rx_packets))
1301 packed.append(struct.pack("!Q", self.tx_packets))
1302 packed.append(struct.pack("!Q", self.rx_bytes))
1303 packed.append(struct.pack("!Q", self.tx_bytes))
1304 packed.append(struct.pack("!Q", self.rx_dropped))
1305 packed.append(struct.pack("!Q", self.tx_dropped))
1306 packed.append(struct.pack("!Q", self.rx_errors))
1307 packed.append(struct.pack("!Q", self.tx_errors))
1308 packed.append(struct.pack("!Q", self.rx_frame_err))
1309 packed.append(struct.pack("!Q", self.rx_over_err))
1310 packed.append(struct.pack("!Q", self.rx_crc_err))
1311 packed.append(struct.pack("!Q", self.collisions))
1312 return ''.join(packed)
1313
1314 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001315 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001316 obj = port_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001317 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001318 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001319 obj.rx_packets = reader.read("!Q")[0]
1320 obj.tx_packets = reader.read("!Q")[0]
1321 obj.rx_bytes = reader.read("!Q")[0]
1322 obj.tx_bytes = reader.read("!Q")[0]
1323 obj.rx_dropped = reader.read("!Q")[0]
1324 obj.tx_dropped = reader.read("!Q")[0]
1325 obj.rx_errors = reader.read("!Q")[0]
1326 obj.tx_errors = reader.read("!Q")[0]
1327 obj.rx_frame_err = reader.read("!Q")[0]
1328 obj.rx_over_err = reader.read("!Q")[0]
1329 obj.rx_crc_err = reader.read("!Q")[0]
1330 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001331 return obj
1332
1333 def __eq__(self, other):
1334 if type(self) != type(other): return False
1335 if self.port_no != other.port_no: return False
1336 if self.rx_packets != other.rx_packets: return False
1337 if self.tx_packets != other.tx_packets: return False
1338 if self.rx_bytes != other.rx_bytes: return False
1339 if self.tx_bytes != other.tx_bytes: return False
1340 if self.rx_dropped != other.rx_dropped: return False
1341 if self.tx_dropped != other.tx_dropped: return False
1342 if self.rx_errors != other.rx_errors: return False
1343 if self.tx_errors != other.tx_errors: return False
1344 if self.rx_frame_err != other.rx_frame_err: return False
1345 if self.rx_over_err != other.rx_over_err: return False
1346 if self.rx_crc_err != other.rx_crc_err: return False
1347 if self.collisions != other.collisions: return False
1348 return True
1349
Rich Lanec2ee4b82013-04-24 17:12:38 -07001350 def pretty_print(self, q):
1351 q.text("port_stats_entry {")
1352 with q.group():
1353 with q.indent(2):
1354 q.breakable()
1355 q.text("port_no = ");
1356 q.text(util.pretty_port(self.port_no))
1357 q.text(","); q.breakable()
1358 q.text("rx_packets = ");
1359 q.text("%#x" % self.rx_packets)
1360 q.text(","); q.breakable()
1361 q.text("tx_packets = ");
1362 q.text("%#x" % self.tx_packets)
1363 q.text(","); q.breakable()
1364 q.text("rx_bytes = ");
1365 q.text("%#x" % self.rx_bytes)
1366 q.text(","); q.breakable()
1367 q.text("tx_bytes = ");
1368 q.text("%#x" % self.tx_bytes)
1369 q.text(","); q.breakable()
1370 q.text("rx_dropped = ");
1371 q.text("%#x" % self.rx_dropped)
1372 q.text(","); q.breakable()
1373 q.text("tx_dropped = ");
1374 q.text("%#x" % self.tx_dropped)
1375 q.text(","); q.breakable()
1376 q.text("rx_errors = ");
1377 q.text("%#x" % self.rx_errors)
1378 q.text(","); q.breakable()
1379 q.text("tx_errors = ");
1380 q.text("%#x" % self.tx_errors)
1381 q.text(","); q.breakable()
1382 q.text("rx_frame_err = ");
1383 q.text("%#x" % self.rx_frame_err)
1384 q.text(","); q.breakable()
1385 q.text("rx_over_err = ");
1386 q.text("%#x" % self.rx_over_err)
1387 q.text(","); q.breakable()
1388 q.text("rx_crc_err = ");
1389 q.text("%#x" % self.rx_crc_err)
1390 q.text(","); q.breakable()
1391 q.text("collisions = ");
1392 q.text("%#x" % self.collisions)
1393 q.breakable()
1394 q.text('}')
1395
Rich Lane7dcdf022013-12-11 14:45:27 -08001396
1397class queue_prop(loxi.OFObject):
1398 subtypes = {}
1399
Rich Lane95f7fc92014-01-27 17:08:16 -08001400
1401 def __init__(self, type=None):
1402 if type != None:
1403 self.type = type
1404 else:
1405 self.type = 0
1406 return
1407
1408 def pack(self):
1409 packed = []
1410 packed.append(struct.pack("!H", self.type))
1411 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1412 packed.append('\x00' * 4)
1413 length = sum([len(x) for x in packed])
1414 packed[1] = struct.pack("!H", length)
1415 return ''.join(packed)
1416
Rich Lane7dcdf022013-12-11 14:45:27 -08001417 @staticmethod
1418 def unpack(reader):
1419 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -08001420 subclass = queue_prop.subtypes.get(subtype)
1421 if subclass:
1422 return subclass.unpack(reader)
1423
1424 obj = queue_prop()
1425 obj.type = reader.read("!H")[0]
1426 _len = reader.read("!H")[0]
1427 orig_reader = reader
1428 reader = orig_reader.slice(_len - (2 + 2))
1429 reader.skip(4)
1430 return obj
1431
1432 def __eq__(self, other):
1433 if type(self) != type(other): return False
1434 if self.type != other.type: return False
1435 return True
1436
1437 def pretty_print(self, q):
1438 q.text("queue_prop {")
1439 with q.group():
1440 with q.indent(2):
1441 q.breakable()
1442 q.breakable()
1443 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -08001444
1445
1446class queue_prop_min_rate(queue_prop):
Dan Talaycof6202252013-07-02 01:00:29 -07001447 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001448
1449 def __init__(self, rate=None):
1450 if rate != None:
1451 self.rate = rate
1452 else:
1453 self.rate = 0
1454 return
1455
1456 def pack(self):
1457 packed = []
1458 packed.append(struct.pack("!H", self.type))
1459 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1460 packed.append('\x00' * 4)
1461 packed.append(struct.pack("!H", self.rate))
1462 packed.append('\x00' * 6)
1463 length = sum([len(x) for x in packed])
1464 packed[1] = struct.pack("!H", length)
1465 return ''.join(packed)
1466
1467 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001468 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001469 obj = queue_prop_min_rate()
Dan Talaycof6202252013-07-02 01:00:29 -07001470 _type = reader.read("!H")[0]
1471 assert(_type == 1)
1472 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001473 orig_reader = reader
1474 reader = orig_reader.slice(_len - (2 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001475 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001476 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001477 reader.skip(6)
1478 return obj
1479
1480 def __eq__(self, other):
1481 if type(self) != type(other): return False
1482 if self.rate != other.rate: return False
1483 return True
1484
Rich Lanec2ee4b82013-04-24 17:12:38 -07001485 def pretty_print(self, q):
1486 q.text("queue_prop_min_rate {")
1487 with q.group():
1488 with q.indent(2):
1489 q.breakable()
1490 q.text("rate = ");
1491 q.text("%#x" % self.rate)
1492 q.breakable()
1493 q.text('}')
1494
Rich Lane7dcdf022013-12-11 14:45:27 -08001495queue_prop.subtypes[1] = queue_prop_min_rate
1496
1497class queue_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001498
1499 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1500 if port_no != None:
1501 self.port_no = port_no
1502 else:
1503 self.port_no = 0
1504 if queue_id != None:
1505 self.queue_id = queue_id
1506 else:
1507 self.queue_id = 0
1508 if tx_bytes != None:
1509 self.tx_bytes = tx_bytes
1510 else:
1511 self.tx_bytes = 0
1512 if tx_packets != None:
1513 self.tx_packets = tx_packets
1514 else:
1515 self.tx_packets = 0
1516 if tx_errors != None:
1517 self.tx_errors = tx_errors
1518 else:
1519 self.tx_errors = 0
1520 return
1521
1522 def pack(self):
1523 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001524 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001525 packed.append(struct.pack("!L", self.queue_id))
1526 packed.append(struct.pack("!Q", self.tx_bytes))
1527 packed.append(struct.pack("!Q", self.tx_packets))
1528 packed.append(struct.pack("!Q", self.tx_errors))
1529 return ''.join(packed)
1530
1531 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001532 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001533 obj = queue_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001534 obj.port_no = util.unpack_port_no(reader)
1535 obj.queue_id = reader.read("!L")[0]
1536 obj.tx_bytes = reader.read("!Q")[0]
1537 obj.tx_packets = reader.read("!Q")[0]
1538 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001539 return obj
1540
1541 def __eq__(self, other):
1542 if type(self) != type(other): return False
1543 if self.port_no != other.port_no: return False
1544 if self.queue_id != other.queue_id: return False
1545 if self.tx_bytes != other.tx_bytes: return False
1546 if self.tx_packets != other.tx_packets: return False
1547 if self.tx_errors != other.tx_errors: return False
1548 return True
1549
Rich Lanec2ee4b82013-04-24 17:12:38 -07001550 def pretty_print(self, q):
1551 q.text("queue_stats_entry {")
1552 with q.group():
1553 with q.indent(2):
1554 q.breakable()
1555 q.text("port_no = ");
1556 q.text(util.pretty_port(self.port_no))
1557 q.text(","); q.breakable()
1558 q.text("queue_id = ");
1559 q.text("%#x" % self.queue_id)
1560 q.text(","); q.breakable()
1561 q.text("tx_bytes = ");
1562 q.text("%#x" % self.tx_bytes)
1563 q.text(","); q.breakable()
1564 q.text("tx_packets = ");
1565 q.text("%#x" % self.tx_packets)
1566 q.text(","); q.breakable()
1567 q.text("tx_errors = ");
1568 q.text("%#x" % self.tx_errors)
1569 q.breakable()
1570 q.text('}')
1571
Rich Lane7dcdf022013-12-11 14:45:27 -08001572
1573class table_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001574
1575 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):
1576 if table_id != None:
1577 self.table_id = table_id
1578 else:
1579 self.table_id = 0
1580 if name != None:
1581 self.name = name
1582 else:
1583 self.name = ""
1584 if wildcards != None:
1585 self.wildcards = wildcards
1586 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001587 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001588 if match != None:
1589 self.match = match
1590 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001591 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001592 if instructions != None:
1593 self.instructions = instructions
1594 else:
1595 self.instructions = 0
1596 if write_actions != None:
1597 self.write_actions = write_actions
1598 else:
1599 self.write_actions = 0
1600 if apply_actions != None:
1601 self.apply_actions = apply_actions
1602 else:
1603 self.apply_actions = 0
1604 if config != None:
1605 self.config = config
1606 else:
1607 self.config = 0
1608 if max_entries != None:
1609 self.max_entries = max_entries
1610 else:
1611 self.max_entries = 0
1612 if active_count != None:
1613 self.active_count = active_count
1614 else:
1615 self.active_count = 0
1616 if lookup_count != None:
1617 self.lookup_count = lookup_count
1618 else:
1619 self.lookup_count = 0
1620 if matched_count != None:
1621 self.matched_count = matched_count
1622 else:
1623 self.matched_count = 0
1624 return
1625
1626 def pack(self):
1627 packed = []
1628 packed.append(struct.pack("!B", self.table_id))
1629 packed.append('\x00' * 7)
1630 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001631 packed.append(util.pack_wc_bmap(self.wildcards))
1632 packed.append(util.pack_match_bmap(self.match))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001633 packed.append(struct.pack("!L", self.instructions))
1634 packed.append(struct.pack("!L", self.write_actions))
1635 packed.append(struct.pack("!L", self.apply_actions))
1636 packed.append(struct.pack("!L", self.config))
1637 packed.append(struct.pack("!L", self.max_entries))
1638 packed.append(struct.pack("!L", self.active_count))
1639 packed.append(struct.pack("!Q", self.lookup_count))
1640 packed.append(struct.pack("!Q", self.matched_count))
1641 return ''.join(packed)
1642
1643 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001644 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001645 obj = table_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001646 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001647 reader.skip(7)
1648 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001649 obj.wildcards = util.unpack_wc_bmap(reader)
1650 obj.match = util.unpack_match_bmap(reader)
1651 obj.instructions = reader.read("!L")[0]
1652 obj.write_actions = reader.read("!L")[0]
1653 obj.apply_actions = reader.read("!L")[0]
1654 obj.config = reader.read("!L")[0]
1655 obj.max_entries = reader.read("!L")[0]
1656 obj.active_count = reader.read("!L")[0]
1657 obj.lookup_count = reader.read("!Q")[0]
1658 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001659 return obj
1660
1661 def __eq__(self, other):
1662 if type(self) != type(other): return False
1663 if self.table_id != other.table_id: return False
1664 if self.name != other.name: return False
1665 if self.wildcards != other.wildcards: return False
1666 if self.match != other.match: return False
1667 if self.instructions != other.instructions: return False
1668 if self.write_actions != other.write_actions: return False
1669 if self.apply_actions != other.apply_actions: return False
1670 if self.config != other.config: return False
1671 if self.max_entries != other.max_entries: return False
1672 if self.active_count != other.active_count: return False
1673 if self.lookup_count != other.lookup_count: return False
1674 if self.matched_count != other.matched_count: return False
1675 return True
1676
Rich Lanec2ee4b82013-04-24 17:12:38 -07001677 def pretty_print(self, q):
1678 q.text("table_stats_entry {")
1679 with q.group():
1680 with q.indent(2):
1681 q.breakable()
1682 q.text("table_id = ");
1683 q.text("%#x" % self.table_id)
1684 q.text(","); q.breakable()
1685 q.text("name = ");
1686 q.pp(self.name)
1687 q.text(","); q.breakable()
1688 q.text("wildcards = ");
1689 q.text(util.pretty_wildcards(self.wildcards))
1690 q.text(","); q.breakable()
1691 q.text("match = ");
1692 q.pp(self.match)
1693 q.text(","); q.breakable()
1694 q.text("instructions = ");
1695 q.text("%#x" % self.instructions)
1696 q.text(","); q.breakable()
1697 q.text("write_actions = ");
1698 q.text("%#x" % self.write_actions)
1699 q.text(","); q.breakable()
1700 q.text("apply_actions = ");
1701 q.text("%#x" % self.apply_actions)
1702 q.text(","); q.breakable()
1703 q.text("config = ");
1704 q.text("%#x" % self.config)
1705 q.text(","); q.breakable()
1706 q.text("max_entries = ");
1707 q.text("%#x" % self.max_entries)
1708 q.text(","); q.breakable()
1709 q.text("active_count = ");
1710 q.text("%#x" % self.active_count)
1711 q.text(","); q.breakable()
1712 q.text("lookup_count = ");
1713 q.text("%#x" % self.lookup_count)
1714 q.text(","); q.breakable()
1715 q.text("matched_count = ");
1716 q.text("%#x" % self.matched_count)
1717 q.breakable()
1718 q.text('}')
1719
1720
Rich Lane7dcdf022013-12-11 14:45:27 -08001721
Rich Lanec2ee4b82013-04-24 17:12:38 -07001722match = match_v2