blob: 548edfdb137f69e4be270611901292c9683e3a81 [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
89 @staticmethod
90 def unpack(reader):
91 subtype, = reader.peek('!H', 0)
92 try:
93 subclass = bsn_vport.subtypes[subtype]
94 except KeyError:
95 raise loxi.ProtocolError("unknown bsn_vport subtype %#x" % subtype)
96 return subclass.unpack(reader)
97
98
99class bsn_vport_q_in_q(bsn_vport):
Dan Talaycof6202252013-07-02 01:00:29 -0700100 type = 0
101
Kiran Poola150d8b02013-09-20 13:30:39 -0700102 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 -0700103 if port_no != None:
104 self.port_no = port_no
105 else:
106 self.port_no = 0
107 if ingress_tpid != None:
108 self.ingress_tpid = ingress_tpid
109 else:
110 self.ingress_tpid = 0
111 if ingress_vlan_id != None:
112 self.ingress_vlan_id = ingress_vlan_id
113 else:
114 self.ingress_vlan_id = 0
115 if egress_tpid != None:
116 self.egress_tpid = egress_tpid
117 else:
118 self.egress_tpid = 0
119 if egress_vlan_id != None:
120 self.egress_vlan_id = egress_vlan_id
121 else:
122 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700123 if if_name != None:
124 self.if_name = if_name
125 else:
126 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700127 return
128
129 def pack(self):
130 packed = []
131 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700132 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700133 packed.append(struct.pack("!L", self.port_no))
134 packed.append(struct.pack("!H", self.ingress_tpid))
135 packed.append(struct.pack("!H", self.ingress_vlan_id))
136 packed.append(struct.pack("!H", self.egress_tpid))
137 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700138 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700139 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700140 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700141 return ''.join(packed)
142
143 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800144 def unpack(reader):
Dan Talaycof6202252013-07-02 01:00:29 -0700145 obj = bsn_vport_q_in_q()
Dan Talaycof6202252013-07-02 01:00:29 -0700146 _type = reader.read("!H")[0]
147 assert(_type == 0)
148 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800149 orig_reader = reader
150 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700151 obj.port_no = reader.read("!L")[0]
152 obj.ingress_tpid = reader.read("!H")[0]
153 obj.ingress_vlan_id = reader.read("!H")[0]
154 obj.egress_tpid = reader.read("!H")[0]
155 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700156 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700157 return obj
158
159 def __eq__(self, other):
160 if type(self) != type(other): return False
161 if self.port_no != other.port_no: return False
162 if self.ingress_tpid != other.ingress_tpid: return False
163 if self.ingress_vlan_id != other.ingress_vlan_id: return False
164 if self.egress_tpid != other.egress_tpid: return False
165 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700166 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700167 return True
168
Dan Talaycof6202252013-07-02 01:00:29 -0700169 def pretty_print(self, q):
170 q.text("bsn_vport_q_in_q {")
171 with q.group():
172 with q.indent(2):
173 q.breakable()
174 q.text("port_no = ");
175 q.text("%#x" % self.port_no)
176 q.text(","); q.breakable()
177 q.text("ingress_tpid = ");
178 q.text("%#x" % self.ingress_tpid)
179 q.text(","); q.breakable()
180 q.text("ingress_vlan_id = ");
181 q.text("%#x" % self.ingress_vlan_id)
182 q.text(","); q.breakable()
183 q.text("egress_tpid = ");
184 q.text("%#x" % self.egress_tpid)
185 q.text(","); q.breakable()
186 q.text("egress_vlan_id = ");
187 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700188 q.text(","); q.breakable()
189 q.text("if_name = ");
190 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700191 q.breakable()
192 q.text('}')
193
Rich Lane7dcdf022013-12-11 14:45:27 -0800194bsn_vport.subtypes[0] = bsn_vport_q_in_q
195
196class bucket(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700197
198 def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
199 if weight != None:
200 self.weight = weight
201 else:
202 self.weight = 0
203 if watch_port != None:
204 self.watch_port = watch_port
205 else:
206 self.watch_port = 0
207 if watch_group != None:
208 self.watch_group = watch_group
209 else:
210 self.watch_group = 0
211 if actions != None:
212 self.actions = actions
213 else:
214 self.actions = []
215 return
216
217 def pack(self):
218 packed = []
219 packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
220 packed.append(struct.pack("!H", self.weight))
Dan Talaycof6202252013-07-02 01:00:29 -0700221 packed.append(util.pack_port_no(self.watch_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700222 packed.append(struct.pack("!L", self.watch_group))
223 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800224 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700225 length = sum([len(x) for x in packed])
226 packed[0] = struct.pack("!H", length)
227 return ''.join(packed)
228
229 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800230 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700231 obj = bucket()
Dan Talaycof6202252013-07-02 01:00:29 -0700232 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800233 orig_reader = reader
234 reader = orig_reader.slice(_len - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700235 obj.weight = reader.read("!H")[0]
236 obj.watch_port = util.unpack_port_no(reader)
237 obj.watch_group = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700238 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800239 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700240 return obj
241
242 def __eq__(self, other):
243 if type(self) != type(other): return False
244 if self.weight != other.weight: return False
245 if self.watch_port != other.watch_port: return False
246 if self.watch_group != other.watch_group: return False
247 if self.actions != other.actions: return False
248 return True
249
Rich Lanec2ee4b82013-04-24 17:12:38 -0700250 def pretty_print(self, q):
251 q.text("bucket {")
252 with q.group():
253 with q.indent(2):
254 q.breakable()
255 q.text("weight = ");
256 q.text("%#x" % self.weight)
257 q.text(","); q.breakable()
258 q.text("watch_port = ");
259 q.text(util.pretty_port(self.watch_port))
260 q.text(","); q.breakable()
261 q.text("watch_group = ");
262 q.text("%#x" % self.watch_group)
263 q.text(","); q.breakable()
264 q.text("actions = ");
265 q.pp(self.actions)
266 q.breakable()
267 q.text('}')
268
Rich Lane7dcdf022013-12-11 14:45:27 -0800269
270class bucket_counter(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700271
272 def __init__(self, packet_count=None, byte_count=None):
273 if packet_count != None:
274 self.packet_count = packet_count
275 else:
276 self.packet_count = 0
277 if byte_count != None:
278 self.byte_count = byte_count
279 else:
280 self.byte_count = 0
281 return
282
283 def pack(self):
284 packed = []
285 packed.append(struct.pack("!Q", self.packet_count))
286 packed.append(struct.pack("!Q", self.byte_count))
287 return ''.join(packed)
288
289 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800290 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700291 obj = bucket_counter()
Dan Talaycof6202252013-07-02 01:00:29 -0700292 obj.packet_count = reader.read("!Q")[0]
293 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700294 return obj
295
296 def __eq__(self, other):
297 if type(self) != type(other): return False
298 if self.packet_count != other.packet_count: return False
299 if self.byte_count != other.byte_count: return False
300 return True
301
Rich Lanec2ee4b82013-04-24 17:12:38 -0700302 def pretty_print(self, q):
303 q.text("bucket_counter {")
304 with q.group():
305 with q.indent(2):
306 q.breakable()
307 q.text("packet_count = ");
308 q.text("%#x" % self.packet_count)
309 q.text(","); q.breakable()
310 q.text("byte_count = ");
311 q.text("%#x" % self.byte_count)
312 q.breakable()
313 q.text('}')
314
Rich Lane7dcdf022013-12-11 14:45:27 -0800315
316class flow_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700317
318 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):
319 if table_id != None:
320 self.table_id = table_id
321 else:
322 self.table_id = 0
323 if duration_sec != None:
324 self.duration_sec = duration_sec
325 else:
326 self.duration_sec = 0
327 if duration_nsec != None:
328 self.duration_nsec = duration_nsec
329 else:
330 self.duration_nsec = 0
331 if priority != None:
332 self.priority = priority
333 else:
334 self.priority = 0
335 if idle_timeout != None:
336 self.idle_timeout = idle_timeout
337 else:
338 self.idle_timeout = 0
339 if hard_timeout != None:
340 self.hard_timeout = hard_timeout
341 else:
342 self.hard_timeout = 0
343 if cookie != None:
344 self.cookie = cookie
345 else:
346 self.cookie = 0
347 if packet_count != None:
348 self.packet_count = packet_count
349 else:
350 self.packet_count = 0
351 if byte_count != None:
352 self.byte_count = byte_count
353 else:
354 self.byte_count = 0
355 if match != None:
356 self.match = match
357 else:
358 self.match = common.match()
359 if instructions != None:
360 self.instructions = instructions
361 else:
362 self.instructions = []
363 return
364
365 def pack(self):
366 packed = []
367 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
368 packed.append(struct.pack("!B", self.table_id))
369 packed.append('\x00' * 1)
370 packed.append(struct.pack("!L", self.duration_sec))
371 packed.append(struct.pack("!L", self.duration_nsec))
372 packed.append(struct.pack("!H", self.priority))
373 packed.append(struct.pack("!H", self.idle_timeout))
374 packed.append(struct.pack("!H", self.hard_timeout))
375 packed.append('\x00' * 6)
376 packed.append(struct.pack("!Q", self.cookie))
377 packed.append(struct.pack("!Q", self.packet_count))
378 packed.append(struct.pack("!Q", self.byte_count))
379 packed.append(self.match.pack())
Rich Lane7dcdf022013-12-11 14:45:27 -0800380 packed.append(loxi.generic_util.pack_list(self.instructions))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700381 length = sum([len(x) for x in packed])
382 packed[0] = struct.pack("!H", length)
383 return ''.join(packed)
384
385 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800386 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700387 obj = flow_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700388 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800389 orig_reader = reader
390 reader = orig_reader.slice(_length - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700391 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700392 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700393 obj.duration_sec = reader.read("!L")[0]
394 obj.duration_nsec = reader.read("!L")[0]
395 obj.priority = reader.read("!H")[0]
396 obj.idle_timeout = reader.read("!H")[0]
397 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700398 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700399 obj.cookie = reader.read("!Q")[0]
400 obj.packet_count = reader.read("!Q")[0]
401 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700402 obj.match = common.match.unpack(reader)
Rich Lane7dcdf022013-12-11 14:45:27 -0800403 obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700404 return obj
405
406 def __eq__(self, other):
407 if type(self) != type(other): return False
408 if self.table_id != other.table_id: return False
409 if self.duration_sec != other.duration_sec: return False
410 if self.duration_nsec != other.duration_nsec: return False
411 if self.priority != other.priority: return False
412 if self.idle_timeout != other.idle_timeout: return False
413 if self.hard_timeout != other.hard_timeout: return False
414 if self.cookie != other.cookie: return False
415 if self.packet_count != other.packet_count: return False
416 if self.byte_count != other.byte_count: return False
417 if self.match != other.match: return False
418 if self.instructions != other.instructions: return False
419 return True
420
Rich Lanec2ee4b82013-04-24 17:12:38 -0700421 def pretty_print(self, q):
422 q.text("flow_stats_entry {")
423 with q.group():
424 with q.indent(2):
425 q.breakable()
426 q.text("table_id = ");
427 q.text("%#x" % self.table_id)
428 q.text(","); q.breakable()
429 q.text("duration_sec = ");
430 q.text("%#x" % self.duration_sec)
431 q.text(","); q.breakable()
432 q.text("duration_nsec = ");
433 q.text("%#x" % self.duration_nsec)
434 q.text(","); q.breakable()
435 q.text("priority = ");
436 q.text("%#x" % self.priority)
437 q.text(","); q.breakable()
438 q.text("idle_timeout = ");
439 q.text("%#x" % self.idle_timeout)
440 q.text(","); q.breakable()
441 q.text("hard_timeout = ");
442 q.text("%#x" % self.hard_timeout)
443 q.text(","); q.breakable()
444 q.text("cookie = ");
445 q.text("%#x" % self.cookie)
446 q.text(","); q.breakable()
447 q.text("packet_count = ");
448 q.text("%#x" % self.packet_count)
449 q.text(","); q.breakable()
450 q.text("byte_count = ");
451 q.text("%#x" % self.byte_count)
452 q.text(","); q.breakable()
453 q.text("match = ");
454 q.pp(self.match)
455 q.text(","); q.breakable()
456 q.text("instructions = ");
457 q.pp(self.instructions)
458 q.breakable()
459 q.text('}')
460
Rich Lane7dcdf022013-12-11 14:45:27 -0800461
462class group_desc_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700463
Rich Lane6f4978c2013-10-20 21:33:52 -0700464 def __init__(self, group_type=None, group_id=None, buckets=None):
465 if group_type != None:
466 self.group_type = group_type
Rich Lanec2ee4b82013-04-24 17:12:38 -0700467 else:
Rich Lane6f4978c2013-10-20 21:33:52 -0700468 self.group_type = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700469 if group_id != None:
470 self.group_id = group_id
471 else:
472 self.group_id = 0
473 if buckets != None:
474 self.buckets = buckets
475 else:
476 self.buckets = []
477 return
478
479 def pack(self):
480 packed = []
481 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
Rich Lane6f4978c2013-10-20 21:33:52 -0700482 packed.append(struct.pack("!B", self.group_type))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700483 packed.append('\x00' * 1)
484 packed.append(struct.pack("!L", self.group_id))
Rich Lane7dcdf022013-12-11 14:45:27 -0800485 packed.append(loxi.generic_util.pack_list(self.buckets))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700486 length = sum([len(x) for x in packed])
487 packed[0] = struct.pack("!H", length)
488 return ''.join(packed)
489
490 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800491 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700492 obj = group_desc_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700493 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800494 orig_reader = reader
495 reader = orig_reader.slice(_length - (0 + 2))
Rich Lane6f4978c2013-10-20 21:33:52 -0700496 obj.group_type = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700497 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700498 obj.group_id = reader.read("!L")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800499 obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700500 return obj
501
502 def __eq__(self, other):
503 if type(self) != type(other): return False
Rich Lane6f4978c2013-10-20 21:33:52 -0700504 if self.group_type != other.group_type: return False
Rich Lanec2ee4b82013-04-24 17:12:38 -0700505 if self.group_id != other.group_id: return False
506 if self.buckets != other.buckets: return False
507 return True
508
Rich Lanec2ee4b82013-04-24 17:12:38 -0700509 def pretty_print(self, q):
510 q.text("group_desc_stats_entry {")
511 with q.group():
512 with q.indent(2):
513 q.breakable()
Rich Lane6f4978c2013-10-20 21:33:52 -0700514 q.text("group_type = ");
515 q.text("%#x" % self.group_type)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700516 q.text(","); q.breakable()
517 q.text("group_id = ");
518 q.text("%#x" % self.group_id)
519 q.text(","); q.breakable()
520 q.text("buckets = ");
521 q.pp(self.buckets)
522 q.breakable()
523 q.text('}')
524
Rich Lane7dcdf022013-12-11 14:45:27 -0800525
526class group_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700527
528 def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
529 if group_id != None:
530 self.group_id = group_id
531 else:
532 self.group_id = 0
533 if ref_count != None:
534 self.ref_count = ref_count
535 else:
536 self.ref_count = 0
537 if packet_count != None:
538 self.packet_count = packet_count
539 else:
540 self.packet_count = 0
541 if byte_count != None:
542 self.byte_count = byte_count
543 else:
544 self.byte_count = 0
545 if bucket_stats != None:
546 self.bucket_stats = bucket_stats
547 else:
548 self.bucket_stats = []
549 return
550
551 def pack(self):
552 packed = []
553 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
554 packed.append('\x00' * 2)
555 packed.append(struct.pack("!L", self.group_id))
556 packed.append(struct.pack("!L", self.ref_count))
557 packed.append('\x00' * 4)
558 packed.append(struct.pack("!Q", self.packet_count))
559 packed.append(struct.pack("!Q", self.byte_count))
Rich Lane7dcdf022013-12-11 14:45:27 -0800560 packed.append(loxi.generic_util.pack_list(self.bucket_stats))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700561 length = sum([len(x) for x in packed])
562 packed[0] = struct.pack("!H", length)
563 return ''.join(packed)
564
565 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800566 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700567 obj = group_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700568 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800569 orig_reader = reader
570 reader = orig_reader.slice(_length - (0 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700571 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700572 obj.group_id = reader.read("!L")[0]
573 obj.ref_count = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700574 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700575 obj.packet_count = reader.read("!Q")[0]
576 obj.byte_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700577 obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack)
578 return obj
579
580 def __eq__(self, other):
581 if type(self) != type(other): return False
582 if self.group_id != other.group_id: return False
583 if self.ref_count != other.ref_count: return False
584 if self.packet_count != other.packet_count: return False
585 if self.byte_count != other.byte_count: return False
586 if self.bucket_stats != other.bucket_stats: return False
587 return True
588
Rich Lanec2ee4b82013-04-24 17:12:38 -0700589 def pretty_print(self, q):
590 q.text("group_stats_entry {")
591 with q.group():
592 with q.indent(2):
593 q.breakable()
594 q.text("group_id = ");
595 q.text("%#x" % self.group_id)
596 q.text(","); q.breakable()
597 q.text("ref_count = ");
598 q.text("%#x" % self.ref_count)
599 q.text(","); q.breakable()
600 q.text("packet_count = ");
601 q.text("%#x" % self.packet_count)
602 q.text(","); q.breakable()
603 q.text("byte_count = ");
604 q.text("%#x" % self.byte_count)
605 q.text(","); q.breakable()
606 q.text("bucket_stats = ");
607 q.pp(self.bucket_stats)
608 q.breakable()
609 q.text('}')
610
Rich Lane7dcdf022013-12-11 14:45:27 -0800611
612class match_v2(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700613 type = 0
614
615 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):
616 if in_port != None:
617 self.in_port = in_port
618 else:
619 self.in_port = 0
620 if wildcards != None:
621 self.wildcards = wildcards
622 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700623 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700624 if eth_src != None:
625 self.eth_src = eth_src
626 else:
627 self.eth_src = [0,0,0,0,0,0]
628 if eth_src_mask != None:
629 self.eth_src_mask = eth_src_mask
630 else:
631 self.eth_src_mask = [0,0,0,0,0,0]
632 if eth_dst != None:
633 self.eth_dst = eth_dst
634 else:
635 self.eth_dst = [0,0,0,0,0,0]
636 if eth_dst_mask != None:
637 self.eth_dst_mask = eth_dst_mask
638 else:
639 self.eth_dst_mask = [0,0,0,0,0,0]
640 if vlan_vid != None:
641 self.vlan_vid = vlan_vid
642 else:
643 self.vlan_vid = 0
644 if vlan_pcp != None:
645 self.vlan_pcp = vlan_pcp
646 else:
647 self.vlan_pcp = 0
648 if eth_type != None:
649 self.eth_type = eth_type
650 else:
651 self.eth_type = 0
652 if ip_dscp != None:
653 self.ip_dscp = ip_dscp
654 else:
655 self.ip_dscp = 0
656 if ip_proto != None:
657 self.ip_proto = ip_proto
658 else:
659 self.ip_proto = 0
660 if ipv4_src != None:
661 self.ipv4_src = ipv4_src
662 else:
663 self.ipv4_src = 0
664 if ipv4_src_mask != None:
665 self.ipv4_src_mask = ipv4_src_mask
666 else:
667 self.ipv4_src_mask = 0
668 if ipv4_dst != None:
669 self.ipv4_dst = ipv4_dst
670 else:
671 self.ipv4_dst = 0
672 if ipv4_dst_mask != None:
673 self.ipv4_dst_mask = ipv4_dst_mask
674 else:
675 self.ipv4_dst_mask = 0
676 if tcp_src != None:
677 self.tcp_src = tcp_src
678 else:
679 self.tcp_src = 0
680 if tcp_dst != None:
681 self.tcp_dst = tcp_dst
682 else:
683 self.tcp_dst = 0
684 if mpls_label != None:
685 self.mpls_label = mpls_label
686 else:
687 self.mpls_label = 0
688 if mpls_tc != None:
689 self.mpls_tc = mpls_tc
690 else:
691 self.mpls_tc = 0
692 if metadata != None:
693 self.metadata = metadata
694 else:
695 self.metadata = 0
696 if metadata_mask != None:
697 self.metadata_mask = metadata_mask
698 else:
699 self.metadata_mask = 0
700 return
701
702 def pack(self):
703 packed = []
704 packed.append(struct.pack("!H", self.type))
705 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700706 packed.append(util.pack_port_no(self.in_port))
707 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700708 packed.append(struct.pack("!6B", *self.eth_src))
709 packed.append(struct.pack("!6B", *self.eth_src_mask))
710 packed.append(struct.pack("!6B", *self.eth_dst))
711 packed.append(struct.pack("!6B", *self.eth_dst_mask))
712 packed.append(struct.pack("!H", self.vlan_vid))
713 packed.append(struct.pack("!B", self.vlan_pcp))
714 packed.append('\x00' * 1)
715 packed.append(struct.pack("!H", self.eth_type))
716 packed.append(struct.pack("!B", self.ip_dscp))
717 packed.append(struct.pack("!B", self.ip_proto))
718 packed.append(struct.pack("!L", self.ipv4_src))
719 packed.append(struct.pack("!L", self.ipv4_src_mask))
720 packed.append(struct.pack("!L", self.ipv4_dst))
721 packed.append(struct.pack("!L", self.ipv4_dst_mask))
722 packed.append(struct.pack("!H", self.tcp_src))
723 packed.append(struct.pack("!H", self.tcp_dst))
724 packed.append(struct.pack("!L", self.mpls_label))
725 packed.append(struct.pack("!B", self.mpls_tc))
726 packed.append('\x00' * 3)
727 packed.append(struct.pack("!Q", self.metadata))
728 packed.append(struct.pack("!Q", self.metadata_mask))
729 length = sum([len(x) for x in packed])
730 packed[1] = struct.pack("!H", length)
731 return ''.join(packed)
732
733 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800734 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700735 obj = match_v2()
Dan Talaycof6202252013-07-02 01:00:29 -0700736 _type = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700737 assert(_type == 0)
Dan Talaycof6202252013-07-02 01:00:29 -0700738 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800739 orig_reader = reader
740 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700741 obj.in_port = util.unpack_port_no(reader)
742 obj.wildcards = util.unpack_wc_bmap(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700743 obj.eth_src = list(reader.read('!6B'))
744 obj.eth_src_mask = list(reader.read('!6B'))
745 obj.eth_dst = list(reader.read('!6B'))
746 obj.eth_dst_mask = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700747 obj.vlan_vid = reader.read("!H")[0]
748 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700749 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700750 obj.eth_type = reader.read("!H")[0]
751 obj.ip_dscp = reader.read("!B")[0]
752 obj.ip_proto = reader.read("!B")[0]
753 obj.ipv4_src = reader.read("!L")[0]
754 obj.ipv4_src_mask = reader.read("!L")[0]
755 obj.ipv4_dst = reader.read("!L")[0]
756 obj.ipv4_dst_mask = reader.read("!L")[0]
757 obj.tcp_src = reader.read("!H")[0]
758 obj.tcp_dst = reader.read("!H")[0]
759 obj.mpls_label = reader.read("!L")[0]
760 obj.mpls_tc = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700761 reader.skip(3)
Dan Talaycof6202252013-07-02 01:00:29 -0700762 obj.metadata = reader.read("!Q")[0]
763 obj.metadata_mask = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700764 return obj
765
766 def __eq__(self, other):
767 if type(self) != type(other): return False
768 if self.in_port != other.in_port: return False
769 if self.wildcards != other.wildcards: return False
770 if self.eth_src != other.eth_src: return False
771 if self.eth_src_mask != other.eth_src_mask: return False
772 if self.eth_dst != other.eth_dst: return False
773 if self.eth_dst_mask != other.eth_dst_mask: return False
774 if self.vlan_vid != other.vlan_vid: return False
775 if self.vlan_pcp != other.vlan_pcp: return False
776 if self.eth_type != other.eth_type: return False
777 if self.ip_dscp != other.ip_dscp: return False
778 if self.ip_proto != other.ip_proto: return False
779 if self.ipv4_src != other.ipv4_src: return False
780 if self.ipv4_src_mask != other.ipv4_src_mask: return False
781 if self.ipv4_dst != other.ipv4_dst: return False
782 if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
783 if self.tcp_src != other.tcp_src: return False
784 if self.tcp_dst != other.tcp_dst: return False
785 if self.mpls_label != other.mpls_label: return False
786 if self.mpls_tc != other.mpls_tc: return False
787 if self.metadata != other.metadata: return False
788 if self.metadata_mask != other.metadata_mask: return False
789 return True
790
Rich Lanec2ee4b82013-04-24 17:12:38 -0700791 def pretty_print(self, q):
792 q.text("match_v2 {")
793 with q.group():
794 with q.indent(2):
795 q.breakable()
796 q.text("in_port = ");
797 q.text(util.pretty_port(self.in_port))
798 q.text(","); q.breakable()
799 q.text("wildcards = ");
800 q.text(util.pretty_wildcards(self.wildcards))
801 q.text(","); q.breakable()
802 q.text("eth_src = ");
803 q.text(util.pretty_mac(self.eth_src))
804 q.text(","); q.breakable()
805 q.text("eth_src_mask = ");
806 q.text(util.pretty_mac(self.eth_src_mask))
807 q.text(","); q.breakable()
808 q.text("eth_dst = ");
809 q.text(util.pretty_mac(self.eth_dst))
810 q.text(","); q.breakable()
811 q.text("eth_dst_mask = ");
812 q.text(util.pretty_mac(self.eth_dst_mask))
813 q.text(","); q.breakable()
814 q.text("vlan_vid = ");
815 q.text("%#x" % self.vlan_vid)
816 q.text(","); q.breakable()
817 q.text("vlan_pcp = ");
818 q.text("%#x" % self.vlan_pcp)
819 q.text(","); q.breakable()
820 q.text("eth_type = ");
821 q.text("%#x" % self.eth_type)
822 q.text(","); q.breakable()
823 q.text("ip_dscp = ");
824 q.text("%#x" % self.ip_dscp)
825 q.text(","); q.breakable()
826 q.text("ip_proto = ");
827 q.text("%#x" % self.ip_proto)
828 q.text(","); q.breakable()
829 q.text("ipv4_src = ");
830 q.text(util.pretty_ipv4(self.ipv4_src))
831 q.text(","); q.breakable()
832 q.text("ipv4_src_mask = ");
833 q.text(util.pretty_ipv4(self.ipv4_src_mask))
834 q.text(","); q.breakable()
835 q.text("ipv4_dst = ");
836 q.text(util.pretty_ipv4(self.ipv4_dst))
837 q.text(","); q.breakable()
838 q.text("ipv4_dst_mask = ");
839 q.text(util.pretty_ipv4(self.ipv4_dst_mask))
840 q.text(","); q.breakable()
841 q.text("tcp_src = ");
842 q.text("%#x" % self.tcp_src)
843 q.text(","); q.breakable()
844 q.text("tcp_dst = ");
845 q.text("%#x" % self.tcp_dst)
846 q.text(","); q.breakable()
847 q.text("mpls_label = ");
848 q.text("%#x" % self.mpls_label)
849 q.text(","); q.breakable()
850 q.text("mpls_tc = ");
851 q.text("%#x" % self.mpls_tc)
852 q.text(","); q.breakable()
853 q.text("metadata = ");
854 q.text("%#x" % self.metadata)
855 q.text(","); q.breakable()
856 q.text("metadata_mask = ");
857 q.text("%#x" % self.metadata_mask)
858 q.breakable()
859 q.text('}')
860
Rich Lane7dcdf022013-12-11 14:45:27 -0800861
862class packet_queue(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700863
864 def __init__(self, queue_id=None, properties=None):
865 if queue_id != None:
866 self.queue_id = queue_id
867 else:
868 self.queue_id = 0
869 if properties != None:
870 self.properties = properties
871 else:
872 self.properties = []
873 return
874
875 def pack(self):
876 packed = []
877 packed.append(struct.pack("!L", self.queue_id))
878 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
879 packed.append('\x00' * 2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800880 packed.append(loxi.generic_util.pack_list(self.properties))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700881 length = sum([len(x) for x in packed])
882 packed[1] = struct.pack("!H", length)
883 return ''.join(packed)
884
885 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800886 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700887 obj = packet_queue()
Dan Talaycof6202252013-07-02 01:00:29 -0700888 obj.queue_id = reader.read("!L")[0]
889 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800890 orig_reader = reader
891 reader = orig_reader.slice(_len - (4 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700892 reader.skip(2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800893 obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700894 return obj
895
896 def __eq__(self, other):
897 if type(self) != type(other): return False
898 if self.queue_id != other.queue_id: return False
899 if self.properties != other.properties: return False
900 return True
901
Rich Lanec2ee4b82013-04-24 17:12:38 -0700902 def pretty_print(self, q):
903 q.text("packet_queue {")
904 with q.group():
905 with q.indent(2):
906 q.breakable()
907 q.text("queue_id = ");
908 q.text("%#x" % self.queue_id)
909 q.text(","); q.breakable()
910 q.text("properties = ");
911 q.pp(self.properties)
912 q.breakable()
913 q.text('}')
914
Rich Lane7dcdf022013-12-11 14:45:27 -0800915
916class port_desc(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700917
918 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):
919 if port_no != None:
920 self.port_no = port_no
921 else:
922 self.port_no = 0
923 if hw_addr != None:
924 self.hw_addr = hw_addr
925 else:
926 self.hw_addr = [0,0,0,0,0,0]
927 if name != None:
928 self.name = name
929 else:
930 self.name = ""
931 if config != None:
932 self.config = config
933 else:
934 self.config = 0
935 if state != None:
936 self.state = state
937 else:
938 self.state = 0
939 if curr != None:
940 self.curr = curr
941 else:
942 self.curr = 0
943 if advertised != None:
944 self.advertised = advertised
945 else:
946 self.advertised = 0
947 if supported != None:
948 self.supported = supported
949 else:
950 self.supported = 0
951 if peer != None:
952 self.peer = peer
953 else:
954 self.peer = 0
955 if curr_speed != None:
956 self.curr_speed = curr_speed
957 else:
958 self.curr_speed = 0
959 if max_speed != None:
960 self.max_speed = max_speed
961 else:
962 self.max_speed = 0
963 return
964
965 def pack(self):
966 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700967 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700968 packed.append('\x00' * 4)
969 packed.append(struct.pack("!6B", *self.hw_addr))
970 packed.append('\x00' * 2)
971 packed.append(struct.pack("!16s", self.name))
972 packed.append(struct.pack("!L", self.config))
973 packed.append(struct.pack("!L", self.state))
974 packed.append(struct.pack("!L", self.curr))
975 packed.append(struct.pack("!L", self.advertised))
976 packed.append(struct.pack("!L", self.supported))
977 packed.append(struct.pack("!L", self.peer))
978 packed.append(struct.pack("!L", self.curr_speed))
979 packed.append(struct.pack("!L", self.max_speed))
980 return ''.join(packed)
981
982 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800983 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -0700984 obj = port_desc()
Dan Talaycof6202252013-07-02 01:00:29 -0700985 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700986 reader.skip(4)
987 obj.hw_addr = list(reader.read('!6B'))
988 reader.skip(2)
989 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700990 obj.config = reader.read("!L")[0]
991 obj.state = reader.read("!L")[0]
992 obj.curr = reader.read("!L")[0]
993 obj.advertised = reader.read("!L")[0]
994 obj.supported = reader.read("!L")[0]
995 obj.peer = reader.read("!L")[0]
996 obj.curr_speed = reader.read("!L")[0]
997 obj.max_speed = reader.read("!L")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700998 return obj
999
1000 def __eq__(self, other):
1001 if type(self) != type(other): return False
1002 if self.port_no != other.port_no: return False
1003 if self.hw_addr != other.hw_addr: return False
1004 if self.name != other.name: return False
1005 if self.config != other.config: return False
1006 if self.state != other.state: return False
1007 if self.curr != other.curr: return False
1008 if self.advertised != other.advertised: return False
1009 if self.supported != other.supported: return False
1010 if self.peer != other.peer: return False
1011 if self.curr_speed != other.curr_speed: return False
1012 if self.max_speed != other.max_speed: return False
1013 return True
1014
Rich Lanec2ee4b82013-04-24 17:12:38 -07001015 def pretty_print(self, q):
1016 q.text("port_desc {")
1017 with q.group():
1018 with q.indent(2):
1019 q.breakable()
1020 q.text("port_no = ");
1021 q.text(util.pretty_port(self.port_no))
1022 q.text(","); q.breakable()
1023 q.text("hw_addr = ");
1024 q.text(util.pretty_mac(self.hw_addr))
1025 q.text(","); q.breakable()
1026 q.text("name = ");
1027 q.pp(self.name)
1028 q.text(","); q.breakable()
1029 q.text("config = ");
1030 q.text("%#x" % self.config)
1031 q.text(","); q.breakable()
1032 q.text("state = ");
1033 q.text("%#x" % self.state)
1034 q.text(","); q.breakable()
1035 q.text("curr = ");
1036 q.text("%#x" % self.curr)
1037 q.text(","); q.breakable()
1038 q.text("advertised = ");
1039 q.text("%#x" % self.advertised)
1040 q.text(","); q.breakable()
1041 q.text("supported = ");
1042 q.text("%#x" % self.supported)
1043 q.text(","); q.breakable()
1044 q.text("peer = ");
1045 q.text("%#x" % self.peer)
1046 q.text(","); q.breakable()
1047 q.text("curr_speed = ");
1048 q.text("%#x" % self.curr_speed)
1049 q.text(","); q.breakable()
1050 q.text("max_speed = ");
1051 q.text("%#x" % self.max_speed)
1052 q.breakable()
1053 q.text('}')
1054
Rich Lane7dcdf022013-12-11 14:45:27 -08001055
1056class port_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001057
1058 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):
1059 if port_no != None:
1060 self.port_no = port_no
1061 else:
1062 self.port_no = 0
1063 if rx_packets != None:
1064 self.rx_packets = rx_packets
1065 else:
1066 self.rx_packets = 0
1067 if tx_packets != None:
1068 self.tx_packets = tx_packets
1069 else:
1070 self.tx_packets = 0
1071 if rx_bytes != None:
1072 self.rx_bytes = rx_bytes
1073 else:
1074 self.rx_bytes = 0
1075 if tx_bytes != None:
1076 self.tx_bytes = tx_bytes
1077 else:
1078 self.tx_bytes = 0
1079 if rx_dropped != None:
1080 self.rx_dropped = rx_dropped
1081 else:
1082 self.rx_dropped = 0
1083 if tx_dropped != None:
1084 self.tx_dropped = tx_dropped
1085 else:
1086 self.tx_dropped = 0
1087 if rx_errors != None:
1088 self.rx_errors = rx_errors
1089 else:
1090 self.rx_errors = 0
1091 if tx_errors != None:
1092 self.tx_errors = tx_errors
1093 else:
1094 self.tx_errors = 0
1095 if rx_frame_err != None:
1096 self.rx_frame_err = rx_frame_err
1097 else:
1098 self.rx_frame_err = 0
1099 if rx_over_err != None:
1100 self.rx_over_err = rx_over_err
1101 else:
1102 self.rx_over_err = 0
1103 if rx_crc_err != None:
1104 self.rx_crc_err = rx_crc_err
1105 else:
1106 self.rx_crc_err = 0
1107 if collisions != None:
1108 self.collisions = collisions
1109 else:
1110 self.collisions = 0
1111 return
1112
1113 def pack(self):
1114 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001115 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001116 packed.append('\x00' * 4)
1117 packed.append(struct.pack("!Q", self.rx_packets))
1118 packed.append(struct.pack("!Q", self.tx_packets))
1119 packed.append(struct.pack("!Q", self.rx_bytes))
1120 packed.append(struct.pack("!Q", self.tx_bytes))
1121 packed.append(struct.pack("!Q", self.rx_dropped))
1122 packed.append(struct.pack("!Q", self.tx_dropped))
1123 packed.append(struct.pack("!Q", self.rx_errors))
1124 packed.append(struct.pack("!Q", self.tx_errors))
1125 packed.append(struct.pack("!Q", self.rx_frame_err))
1126 packed.append(struct.pack("!Q", self.rx_over_err))
1127 packed.append(struct.pack("!Q", self.rx_crc_err))
1128 packed.append(struct.pack("!Q", self.collisions))
1129 return ''.join(packed)
1130
1131 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001132 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001133 obj = port_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001134 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001135 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001136 obj.rx_packets = reader.read("!Q")[0]
1137 obj.tx_packets = reader.read("!Q")[0]
1138 obj.rx_bytes = reader.read("!Q")[0]
1139 obj.tx_bytes = reader.read("!Q")[0]
1140 obj.rx_dropped = reader.read("!Q")[0]
1141 obj.tx_dropped = reader.read("!Q")[0]
1142 obj.rx_errors = reader.read("!Q")[0]
1143 obj.tx_errors = reader.read("!Q")[0]
1144 obj.rx_frame_err = reader.read("!Q")[0]
1145 obj.rx_over_err = reader.read("!Q")[0]
1146 obj.rx_crc_err = reader.read("!Q")[0]
1147 obj.collisions = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001148 return obj
1149
1150 def __eq__(self, other):
1151 if type(self) != type(other): return False
1152 if self.port_no != other.port_no: return False
1153 if self.rx_packets != other.rx_packets: return False
1154 if self.tx_packets != other.tx_packets: return False
1155 if self.rx_bytes != other.rx_bytes: return False
1156 if self.tx_bytes != other.tx_bytes: return False
1157 if self.rx_dropped != other.rx_dropped: return False
1158 if self.tx_dropped != other.tx_dropped: return False
1159 if self.rx_errors != other.rx_errors: return False
1160 if self.tx_errors != other.tx_errors: return False
1161 if self.rx_frame_err != other.rx_frame_err: return False
1162 if self.rx_over_err != other.rx_over_err: return False
1163 if self.rx_crc_err != other.rx_crc_err: return False
1164 if self.collisions != other.collisions: return False
1165 return True
1166
Rich Lanec2ee4b82013-04-24 17:12:38 -07001167 def pretty_print(self, q):
1168 q.text("port_stats_entry {")
1169 with q.group():
1170 with q.indent(2):
1171 q.breakable()
1172 q.text("port_no = ");
1173 q.text(util.pretty_port(self.port_no))
1174 q.text(","); q.breakable()
1175 q.text("rx_packets = ");
1176 q.text("%#x" % self.rx_packets)
1177 q.text(","); q.breakable()
1178 q.text("tx_packets = ");
1179 q.text("%#x" % self.tx_packets)
1180 q.text(","); q.breakable()
1181 q.text("rx_bytes = ");
1182 q.text("%#x" % self.rx_bytes)
1183 q.text(","); q.breakable()
1184 q.text("tx_bytes = ");
1185 q.text("%#x" % self.tx_bytes)
1186 q.text(","); q.breakable()
1187 q.text("rx_dropped = ");
1188 q.text("%#x" % self.rx_dropped)
1189 q.text(","); q.breakable()
1190 q.text("tx_dropped = ");
1191 q.text("%#x" % self.tx_dropped)
1192 q.text(","); q.breakable()
1193 q.text("rx_errors = ");
1194 q.text("%#x" % self.rx_errors)
1195 q.text(","); q.breakable()
1196 q.text("tx_errors = ");
1197 q.text("%#x" % self.tx_errors)
1198 q.text(","); q.breakable()
1199 q.text("rx_frame_err = ");
1200 q.text("%#x" % self.rx_frame_err)
1201 q.text(","); q.breakable()
1202 q.text("rx_over_err = ");
1203 q.text("%#x" % self.rx_over_err)
1204 q.text(","); q.breakable()
1205 q.text("rx_crc_err = ");
1206 q.text("%#x" % self.rx_crc_err)
1207 q.text(","); q.breakable()
1208 q.text("collisions = ");
1209 q.text("%#x" % self.collisions)
1210 q.breakable()
1211 q.text('}')
1212
Rich Lane7dcdf022013-12-11 14:45:27 -08001213
1214class queue_prop(loxi.OFObject):
1215 subtypes = {}
1216
1217 @staticmethod
1218 def unpack(reader):
1219 subtype, = reader.peek('!H', 0)
1220 try:
1221 subclass = queue_prop.subtypes[subtype]
1222 except KeyError:
1223 raise loxi.ProtocolError("unknown queue_prop subtype %#x" % subtype)
1224 return subclass.unpack(reader)
1225
1226
1227class queue_prop_min_rate(queue_prop):
Dan Talaycof6202252013-07-02 01:00:29 -07001228 type = 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001229
1230 def __init__(self, rate=None):
1231 if rate != None:
1232 self.rate = rate
1233 else:
1234 self.rate = 0
1235 return
1236
1237 def pack(self):
1238 packed = []
1239 packed.append(struct.pack("!H", self.type))
1240 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1241 packed.append('\x00' * 4)
1242 packed.append(struct.pack("!H", self.rate))
1243 packed.append('\x00' * 6)
1244 length = sum([len(x) for x in packed])
1245 packed[1] = struct.pack("!H", length)
1246 return ''.join(packed)
1247
1248 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001249 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001250 obj = queue_prop_min_rate()
Dan Talaycof6202252013-07-02 01:00:29 -07001251 _type = reader.read("!H")[0]
1252 assert(_type == 1)
1253 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001254 orig_reader = reader
1255 reader = orig_reader.slice(_len - (2 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001256 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001257 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001258 reader.skip(6)
1259 return obj
1260
1261 def __eq__(self, other):
1262 if type(self) != type(other): return False
1263 if self.rate != other.rate: return False
1264 return True
1265
Rich Lanec2ee4b82013-04-24 17:12:38 -07001266 def pretty_print(self, q):
1267 q.text("queue_prop_min_rate {")
1268 with q.group():
1269 with q.indent(2):
1270 q.breakable()
1271 q.text("rate = ");
1272 q.text("%#x" % self.rate)
1273 q.breakable()
1274 q.text('}')
1275
Rich Lane7dcdf022013-12-11 14:45:27 -08001276queue_prop.subtypes[1] = queue_prop_min_rate
1277
1278class queue_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001279
1280 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1281 if port_no != None:
1282 self.port_no = port_no
1283 else:
1284 self.port_no = 0
1285 if queue_id != None:
1286 self.queue_id = queue_id
1287 else:
1288 self.queue_id = 0
1289 if tx_bytes != None:
1290 self.tx_bytes = tx_bytes
1291 else:
1292 self.tx_bytes = 0
1293 if tx_packets != None:
1294 self.tx_packets = tx_packets
1295 else:
1296 self.tx_packets = 0
1297 if tx_errors != None:
1298 self.tx_errors = tx_errors
1299 else:
1300 self.tx_errors = 0
1301 return
1302
1303 def pack(self):
1304 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001305 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001306 packed.append(struct.pack("!L", self.queue_id))
1307 packed.append(struct.pack("!Q", self.tx_bytes))
1308 packed.append(struct.pack("!Q", self.tx_packets))
1309 packed.append(struct.pack("!Q", self.tx_errors))
1310 return ''.join(packed)
1311
1312 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001313 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001314 obj = queue_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001315 obj.port_no = util.unpack_port_no(reader)
1316 obj.queue_id = reader.read("!L")[0]
1317 obj.tx_bytes = reader.read("!Q")[0]
1318 obj.tx_packets = reader.read("!Q")[0]
1319 obj.tx_errors = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001320 return obj
1321
1322 def __eq__(self, other):
1323 if type(self) != type(other): return False
1324 if self.port_no != other.port_no: return False
1325 if self.queue_id != other.queue_id: return False
1326 if self.tx_bytes != other.tx_bytes: return False
1327 if self.tx_packets != other.tx_packets: return False
1328 if self.tx_errors != other.tx_errors: return False
1329 return True
1330
Rich Lanec2ee4b82013-04-24 17:12:38 -07001331 def pretty_print(self, q):
1332 q.text("queue_stats_entry {")
1333 with q.group():
1334 with q.indent(2):
1335 q.breakable()
1336 q.text("port_no = ");
1337 q.text(util.pretty_port(self.port_no))
1338 q.text(","); q.breakable()
1339 q.text("queue_id = ");
1340 q.text("%#x" % self.queue_id)
1341 q.text(","); q.breakable()
1342 q.text("tx_bytes = ");
1343 q.text("%#x" % self.tx_bytes)
1344 q.text(","); q.breakable()
1345 q.text("tx_packets = ");
1346 q.text("%#x" % self.tx_packets)
1347 q.text(","); q.breakable()
1348 q.text("tx_errors = ");
1349 q.text("%#x" % self.tx_errors)
1350 q.breakable()
1351 q.text('}')
1352
Rich Lane7dcdf022013-12-11 14:45:27 -08001353
1354class table_stats_entry(loxi.OFObject):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001355
1356 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):
1357 if table_id != None:
1358 self.table_id = table_id
1359 else:
1360 self.table_id = 0
1361 if name != None:
1362 self.name = name
1363 else:
1364 self.name = ""
1365 if wildcards != None:
1366 self.wildcards = wildcards
1367 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001368 self.wildcards = util.init_wc_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001369 if match != None:
1370 self.match = match
1371 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001372 self.match = util.init_match_bmap()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001373 if instructions != None:
1374 self.instructions = instructions
1375 else:
1376 self.instructions = 0
1377 if write_actions != None:
1378 self.write_actions = write_actions
1379 else:
1380 self.write_actions = 0
1381 if apply_actions != None:
1382 self.apply_actions = apply_actions
1383 else:
1384 self.apply_actions = 0
1385 if config != None:
1386 self.config = config
1387 else:
1388 self.config = 0
1389 if max_entries != None:
1390 self.max_entries = max_entries
1391 else:
1392 self.max_entries = 0
1393 if active_count != None:
1394 self.active_count = active_count
1395 else:
1396 self.active_count = 0
1397 if lookup_count != None:
1398 self.lookup_count = lookup_count
1399 else:
1400 self.lookup_count = 0
1401 if matched_count != None:
1402 self.matched_count = matched_count
1403 else:
1404 self.matched_count = 0
1405 return
1406
1407 def pack(self):
1408 packed = []
1409 packed.append(struct.pack("!B", self.table_id))
1410 packed.append('\x00' * 7)
1411 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001412 packed.append(util.pack_wc_bmap(self.wildcards))
1413 packed.append(util.pack_match_bmap(self.match))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001414 packed.append(struct.pack("!L", self.instructions))
1415 packed.append(struct.pack("!L", self.write_actions))
1416 packed.append(struct.pack("!L", self.apply_actions))
1417 packed.append(struct.pack("!L", self.config))
1418 packed.append(struct.pack("!L", self.max_entries))
1419 packed.append(struct.pack("!L", self.active_count))
1420 packed.append(struct.pack("!Q", self.lookup_count))
1421 packed.append(struct.pack("!Q", self.matched_count))
1422 return ''.join(packed)
1423
1424 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001425 def unpack(reader):
Rich Lanec2ee4b82013-04-24 17:12:38 -07001426 obj = table_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001427 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001428 reader.skip(7)
1429 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001430 obj.wildcards = util.unpack_wc_bmap(reader)
1431 obj.match = util.unpack_match_bmap(reader)
1432 obj.instructions = reader.read("!L")[0]
1433 obj.write_actions = reader.read("!L")[0]
1434 obj.apply_actions = reader.read("!L")[0]
1435 obj.config = reader.read("!L")[0]
1436 obj.max_entries = reader.read("!L")[0]
1437 obj.active_count = reader.read("!L")[0]
1438 obj.lookup_count = reader.read("!Q")[0]
1439 obj.matched_count = reader.read("!Q")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001440 return obj
1441
1442 def __eq__(self, other):
1443 if type(self) != type(other): return False
1444 if self.table_id != other.table_id: return False
1445 if self.name != other.name: return False
1446 if self.wildcards != other.wildcards: return False
1447 if self.match != other.match: return False
1448 if self.instructions != other.instructions: return False
1449 if self.write_actions != other.write_actions: return False
1450 if self.apply_actions != other.apply_actions: return False
1451 if self.config != other.config: return False
1452 if self.max_entries != other.max_entries: return False
1453 if self.active_count != other.active_count: return False
1454 if self.lookup_count != other.lookup_count: return False
1455 if self.matched_count != other.matched_count: return False
1456 return True
1457
Rich Lanec2ee4b82013-04-24 17:12:38 -07001458 def pretty_print(self, q):
1459 q.text("table_stats_entry {")
1460 with q.group():
1461 with q.indent(2):
1462 q.breakable()
1463 q.text("table_id = ");
1464 q.text("%#x" % self.table_id)
1465 q.text(","); q.breakable()
1466 q.text("name = ");
1467 q.pp(self.name)
1468 q.text(","); q.breakable()
1469 q.text("wildcards = ");
1470 q.text(util.pretty_wildcards(self.wildcards))
1471 q.text(","); q.breakable()
1472 q.text("match = ");
1473 q.pp(self.match)
1474 q.text(","); q.breakable()
1475 q.text("instructions = ");
1476 q.text("%#x" % self.instructions)
1477 q.text(","); q.breakable()
1478 q.text("write_actions = ");
1479 q.text("%#x" % self.write_actions)
1480 q.text(","); q.breakable()
1481 q.text("apply_actions = ");
1482 q.text("%#x" % self.apply_actions)
1483 q.text(","); q.breakable()
1484 q.text("config = ");
1485 q.text("%#x" % self.config)
1486 q.text(","); q.breakable()
1487 q.text("max_entries = ");
1488 q.text("%#x" % self.max_entries)
1489 q.text(","); q.breakable()
1490 q.text("active_count = ");
1491 q.text("%#x" % self.active_count)
1492 q.text(","); q.breakable()
1493 q.text("lookup_count = ");
1494 q.text("%#x" % self.lookup_count)
1495 q.text(","); q.breakable()
1496 q.text("matched_count = ");
1497 q.text("%#x" % self.matched_count)
1498 q.breakable()
1499 q.text('}')
1500
1501
Rich Lane7dcdf022013-12-11 14:45:27 -08001502
Rich Lanec2ee4b82013-04-24 17:12:38 -07001503match = match_v2