blob: 90c05e33a21ea68311e2a9d425db3af96290eaec [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 Laneb658ddd2013-03-12 10:15:10 -07007# Do not modify
8
Rich Laneb658ddd2013-03-12 10:15:10 -07009import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Laneb658ddd2013-03-12 10:15:10 -070011import const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
Rich Laneb658ddd2013-03-12 10:15:10 -070014import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070015import loxi.generic_util
16
Rich Lane7dcdf022013-12-11 14:45:27 -080017class bsn_interface(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -070018
Rich Lanec2ee4b82013-04-24 17:12:38 -070019 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070020 if hw_addr != None:
21 self.hw_addr = hw_addr
22 else:
23 self.hw_addr = [0,0,0,0,0,0]
Rich Laneb658ddd2013-03-12 10:15:10 -070024 if name != None:
25 self.name = name
26 else:
27 self.name = ""
28 if ipv4_addr != None:
29 self.ipv4_addr = ipv4_addr
30 else:
31 self.ipv4_addr = 0
32 if ipv4_netmask != None:
33 self.ipv4_netmask = ipv4_netmask
34 else:
35 self.ipv4_netmask = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -070036 return
Rich Laneb658ddd2013-03-12 10:15:10 -070037
38 def pack(self):
39 packed = []
40 packed.append(struct.pack("!6B", *self.hw_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -070041 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -070042 packed.append(struct.pack("!16s", self.name))
43 packed.append(struct.pack("!L", self.ipv4_addr))
44 packed.append(struct.pack("!L", self.ipv4_netmask))
45 return ''.join(packed)
46
47 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080048 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -070049 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070050 obj.hw_addr = list(reader.read('!6B'))
51 reader.skip(2)
52 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -070053 obj.ipv4_addr = reader.read("!L")[0]
54 obj.ipv4_netmask = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -070055 return obj
56
57 def __eq__(self, other):
58 if type(self) != type(other): return False
59 if self.hw_addr != other.hw_addr: return False
Rich Laneb658ddd2013-03-12 10:15:10 -070060 if self.name != other.name: return False
61 if self.ipv4_addr != other.ipv4_addr: return False
62 if self.ipv4_netmask != other.ipv4_netmask: return False
63 return True
64
Rich Laneb658ddd2013-03-12 10:15:10 -070065 def pretty_print(self, q):
66 q.text("bsn_interface {")
67 with q.group():
68 with q.indent(2):
69 q.breakable()
70 q.text("hw_addr = ");
71 q.text(util.pretty_mac(self.hw_addr))
72 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -070073 q.text("name = ");
74 q.pp(self.name)
75 q.text(","); q.breakable()
76 q.text("ipv4_addr = ");
77 q.text(util.pretty_ipv4(self.ipv4_addr))
78 q.text(","); q.breakable()
79 q.text("ipv4_netmask = ");
80 q.text(util.pretty_ipv4(self.ipv4_netmask))
81 q.breakable()
82 q.text('}')
83
Rich Lane7dcdf022013-12-11 14:45:27 -080084
85class bsn_vport(loxi.OFObject):
86 subtypes = {}
87
Rich Lane95f7fc92014-01-27 17:08:16 -080088
89 def __init__(self, type=None):
90 if type != None:
91 self.type = type
92 else:
93 self.type = 0
94 return
95
96 def pack(self):
97 packed = []
98 packed.append(struct.pack("!H", self.type))
99 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
100 length = sum([len(x) for x in packed])
101 packed[1] = struct.pack("!H", length)
102 return ''.join(packed)
103
Rich Lane7dcdf022013-12-11 14:45:27 -0800104 @staticmethod
105 def unpack(reader):
106 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -0800107 subclass = bsn_vport.subtypes.get(subtype)
108 if subclass:
109 return subclass.unpack(reader)
110
111 obj = bsn_vport()
112 obj.type = reader.read("!H")[0]
113 _length = reader.read("!H")[0]
114 orig_reader = reader
115 reader = orig_reader.slice(_length - (2 + 2))
116 return obj
117
118 def __eq__(self, other):
119 if type(self) != type(other): return False
120 if self.type != other.type: return False
121 return True
122
123 def pretty_print(self, q):
124 q.text("bsn_vport {")
125 with q.group():
126 with q.indent(2):
127 q.breakable()
128 q.breakable()
129 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800130
131
Rich Lane93b33132014-04-21 12:20:58 -0700132class bsn_vport_l2gre(bsn_vport):
133 type = 1
134
Rich Lane5587ab12014-06-30 11:19:09 -0700135 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 -0700136 if flags != None:
137 self.flags = flags
138 else:
139 self.flags = 0
140 if port_no != None:
141 self.port_no = port_no
142 else:
143 self.port_no = 0
Rich Lane5587ab12014-06-30 11:19:09 -0700144 if loopback_port_no != None:
145 self.loopback_port_no = loopback_port_no
146 else:
147 self.loopback_port_no = 0
Rich Lane93b33132014-04-21 12:20:58 -0700148 if local_mac != None:
149 self.local_mac = local_mac
150 else:
151 self.local_mac = [0,0,0,0,0,0]
152 if nh_mac != None:
153 self.nh_mac = nh_mac
154 else:
155 self.nh_mac = [0,0,0,0,0,0]
156 if src_ip != None:
157 self.src_ip = src_ip
158 else:
159 self.src_ip = 0
160 if dst_ip != None:
161 self.dst_ip = dst_ip
162 else:
163 self.dst_ip = 0
164 if dscp != None:
165 self.dscp = dscp
166 else:
167 self.dscp = 0
168 if ttl != None:
169 self.ttl = ttl
170 else:
171 self.ttl = 0
172 if vpn != None:
173 self.vpn = vpn
174 else:
175 self.vpn = 0
176 if if_name != None:
177 self.if_name = if_name
178 else:
179 self.if_name = ""
180 return
181
182 def pack(self):
183 packed = []
184 packed.append(struct.pack("!H", self.type))
185 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
186 packed.append(struct.pack("!L", self.flags))
187 packed.append(util.pack_port_no(self.port_no))
Rich Lane5587ab12014-06-30 11:19:09 -0700188 packed.append(util.pack_port_no(self.loopback_port_no))
Rich Lane93b33132014-04-21 12:20:58 -0700189 packed.append(struct.pack("!6B", *self.local_mac))
190 packed.append(struct.pack("!6B", *self.nh_mac))
191 packed.append(struct.pack("!L", self.src_ip))
192 packed.append(struct.pack("!L", self.dst_ip))
193 packed.append(struct.pack("!B", self.dscp))
194 packed.append(struct.pack("!B", self.ttl))
195 packed.append('\x00' * 2)
196 packed.append(struct.pack("!L", self.vpn))
197 packed.append(struct.pack("!16s", self.if_name))
198 length = sum([len(x) for x in packed])
199 packed[1] = struct.pack("!H", length)
200 return ''.join(packed)
201
202 @staticmethod
203 def unpack(reader):
204 obj = bsn_vport_l2gre()
205 _type = reader.read("!H")[0]
206 assert(_type == 1)
207 _length = reader.read("!H")[0]
208 orig_reader = reader
209 reader = orig_reader.slice(_length - (2 + 2))
210 obj.flags = reader.read("!L")[0]
211 obj.port_no = util.unpack_port_no(reader)
Rich Lane5587ab12014-06-30 11:19:09 -0700212 obj.loopback_port_no = util.unpack_port_no(reader)
Rich Lane93b33132014-04-21 12:20:58 -0700213 obj.local_mac = list(reader.read('!6B'))
214 obj.nh_mac = list(reader.read('!6B'))
215 obj.src_ip = reader.read("!L")[0]
216 obj.dst_ip = reader.read("!L")[0]
217 obj.dscp = reader.read("!B")[0]
218 obj.ttl = reader.read("!B")[0]
219 reader.skip(2)
220 obj.vpn = reader.read("!L")[0]
221 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
222 return obj
223
224 def __eq__(self, other):
225 if type(self) != type(other): return False
226 if self.flags != other.flags: return False
227 if self.port_no != other.port_no: return False
Rich Lane5587ab12014-06-30 11:19:09 -0700228 if self.loopback_port_no != other.loopback_port_no: return False
Rich Lane93b33132014-04-21 12:20:58 -0700229 if self.local_mac != other.local_mac: return False
230 if self.nh_mac != other.nh_mac: return False
231 if self.src_ip != other.src_ip: return False
232 if self.dst_ip != other.dst_ip: return False
233 if self.dscp != other.dscp: return False
234 if self.ttl != other.ttl: return False
235 if self.vpn != other.vpn: return False
236 if self.if_name != other.if_name: return False
237 return True
238
239 def pretty_print(self, q):
240 q.text("bsn_vport_l2gre {")
241 with q.group():
242 with q.indent(2):
243 q.breakable()
244 q.text("flags = ");
245 q.text("%#x" % self.flags)
246 q.text(","); q.breakable()
247 q.text("port_no = ");
248 q.text(util.pretty_port(self.port_no))
249 q.text(","); q.breakable()
Rich Lane5587ab12014-06-30 11:19:09 -0700250 q.text("loopback_port_no = ");
251 q.text(util.pretty_port(self.loopback_port_no))
252 q.text(","); q.breakable()
Rich Lane93b33132014-04-21 12:20:58 -0700253 q.text("local_mac = ");
254 q.text(util.pretty_mac(self.local_mac))
255 q.text(","); q.breakable()
256 q.text("nh_mac = ");
257 q.text(util.pretty_mac(self.nh_mac))
258 q.text(","); q.breakable()
259 q.text("src_ip = ");
260 q.text(util.pretty_ipv4(self.src_ip))
261 q.text(","); q.breakable()
262 q.text("dst_ip = ");
263 q.text(util.pretty_ipv4(self.dst_ip))
264 q.text(","); q.breakable()
265 q.text("dscp = ");
266 q.text("%#x" % self.dscp)
267 q.text(","); q.breakable()
268 q.text("ttl = ");
269 q.text("%#x" % self.ttl)
270 q.text(","); q.breakable()
271 q.text("vpn = ");
272 q.text("%#x" % self.vpn)
273 q.text(","); q.breakable()
274 q.text("if_name = ");
275 q.pp(self.if_name)
276 q.breakable()
277 q.text('}')
278
279bsn_vport.subtypes[1] = bsn_vport_l2gre
280
Rich Lane7dcdf022013-12-11 14:45:27 -0800281class bsn_vport_q_in_q(bsn_vport):
Dan Talaycof6202252013-07-02 01:00:29 -0700282 type = 0
283
Kiran Poola150d8b02013-09-20 13:30:39 -0700284 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 -0700285 if port_no != None:
286 self.port_no = port_no
287 else:
288 self.port_no = 0
289 if ingress_tpid != None:
290 self.ingress_tpid = ingress_tpid
291 else:
292 self.ingress_tpid = 0
293 if ingress_vlan_id != None:
294 self.ingress_vlan_id = ingress_vlan_id
295 else:
296 self.ingress_vlan_id = 0
297 if egress_tpid != None:
298 self.egress_tpid = egress_tpid
299 else:
300 self.egress_tpid = 0
301 if egress_vlan_id != None:
302 self.egress_vlan_id = egress_vlan_id
303 else:
304 self.egress_vlan_id = 0
Kiran Poola150d8b02013-09-20 13:30:39 -0700305 if if_name != None:
306 self.if_name = if_name
307 else:
308 self.if_name = ""
Dan Talaycof6202252013-07-02 01:00:29 -0700309 return
310
311 def pack(self):
312 packed = []
313 packed.append(struct.pack("!H", self.type))
Kiran Poola150d8b02013-09-20 13:30:39 -0700314 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
Dan Talaycof6202252013-07-02 01:00:29 -0700315 packed.append(struct.pack("!L", self.port_no))
316 packed.append(struct.pack("!H", self.ingress_tpid))
317 packed.append(struct.pack("!H", self.ingress_vlan_id))
318 packed.append(struct.pack("!H", self.egress_tpid))
319 packed.append(struct.pack("!H", self.egress_vlan_id))
Kiran Poola150d8b02013-09-20 13:30:39 -0700320 packed.append(struct.pack("!16s", self.if_name))
Dan Talaycof6202252013-07-02 01:00:29 -0700321 length = sum([len(x) for x in packed])
Kiran Poola150d8b02013-09-20 13:30:39 -0700322 packed[1] = struct.pack("!H", length)
Dan Talaycof6202252013-07-02 01:00:29 -0700323 return ''.join(packed)
324
325 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800326 def unpack(reader):
Dan Talaycof6202252013-07-02 01:00:29 -0700327 obj = bsn_vport_q_in_q()
Dan Talaycof6202252013-07-02 01:00:29 -0700328 _type = reader.read("!H")[0]
329 assert(_type == 0)
330 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800331 orig_reader = reader
332 reader = orig_reader.slice(_length - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700333 obj.port_no = reader.read("!L")[0]
334 obj.ingress_tpid = reader.read("!H")[0]
335 obj.ingress_vlan_id = reader.read("!H")[0]
336 obj.egress_tpid = reader.read("!H")[0]
337 obj.egress_vlan_id = reader.read("!H")[0]
Kiran Poola150d8b02013-09-20 13:30:39 -0700338 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700339 return obj
340
341 def __eq__(self, other):
342 if type(self) != type(other): return False
343 if self.port_no != other.port_no: return False
344 if self.ingress_tpid != other.ingress_tpid: return False
345 if self.ingress_vlan_id != other.ingress_vlan_id: return False
346 if self.egress_tpid != other.egress_tpid: return False
347 if self.egress_vlan_id != other.egress_vlan_id: return False
Kiran Poola150d8b02013-09-20 13:30:39 -0700348 if self.if_name != other.if_name: return False
Dan Talaycof6202252013-07-02 01:00:29 -0700349 return True
350
Dan Talaycof6202252013-07-02 01:00:29 -0700351 def pretty_print(self, q):
352 q.text("bsn_vport_q_in_q {")
353 with q.group():
354 with q.indent(2):
355 q.breakable()
356 q.text("port_no = ");
357 q.text("%#x" % self.port_no)
358 q.text(","); q.breakable()
359 q.text("ingress_tpid = ");
360 q.text("%#x" % self.ingress_tpid)
361 q.text(","); q.breakable()
362 q.text("ingress_vlan_id = ");
363 q.text("%#x" % self.ingress_vlan_id)
364 q.text(","); q.breakable()
365 q.text("egress_tpid = ");
366 q.text("%#x" % self.egress_tpid)
367 q.text(","); q.breakable()
368 q.text("egress_vlan_id = ");
369 q.text("%#x" % self.egress_vlan_id)
Kiran Poola150d8b02013-09-20 13:30:39 -0700370 q.text(","); q.breakable()
371 q.text("if_name = ");
372 q.pp(self.if_name)
Dan Talaycof6202252013-07-02 01:00:29 -0700373 q.breakable()
374 q.text('}')
375
Rich Lane7dcdf022013-12-11 14:45:27 -0800376bsn_vport.subtypes[0] = bsn_vport_q_in_q
377
378class flow_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700379
Rich Lanec2ee4b82013-04-24 17:12:38 -0700380 def __init__(self, table_id=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, actions=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700381 if table_id != None:
382 self.table_id = table_id
383 else:
384 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700385 if match != None:
386 self.match = match
387 else:
388 self.match = common.match()
389 if duration_sec != None:
390 self.duration_sec = duration_sec
391 else:
392 self.duration_sec = 0
393 if duration_nsec != None:
394 self.duration_nsec = duration_nsec
395 else:
396 self.duration_nsec = 0
397 if priority != None:
398 self.priority = priority
399 else:
400 self.priority = 0
401 if idle_timeout != None:
402 self.idle_timeout = idle_timeout
403 else:
404 self.idle_timeout = 0
405 if hard_timeout != None:
406 self.hard_timeout = hard_timeout
407 else:
408 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700409 if cookie != None:
410 self.cookie = cookie
411 else:
412 self.cookie = 0
413 if packet_count != None:
414 self.packet_count = packet_count
415 else:
416 self.packet_count = 0
417 if byte_count != None:
418 self.byte_count = byte_count
419 else:
420 self.byte_count = 0
421 if actions != None:
422 self.actions = actions
423 else:
424 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700425 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700426
427 def pack(self):
428 packed = []
429 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
430 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700431 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700432 packed.append(self.match.pack())
433 packed.append(struct.pack("!L", self.duration_sec))
434 packed.append(struct.pack("!L", self.duration_nsec))
435 packed.append(struct.pack("!H", self.priority))
436 packed.append(struct.pack("!H", self.idle_timeout))
437 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700438 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700439 packed.append(struct.pack("!Q", self.cookie))
440 packed.append(struct.pack("!Q", self.packet_count))
441 packed.append(struct.pack("!Q", self.byte_count))
Rich Lane7dcdf022013-12-11 14:45:27 -0800442 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneb658ddd2013-03-12 10:15:10 -0700443 length = sum([len(x) for x in packed])
444 packed[0] = struct.pack("!H", length)
445 return ''.join(packed)
446
447 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800448 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700449 obj = flow_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700450 _length = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800451 orig_reader = reader
452 reader = orig_reader.slice(_length - (0 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700453 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700454 reader.skip(1)
455 obj.match = common.match.unpack(reader)
Dan Talaycof6202252013-07-02 01:00:29 -0700456 obj.duration_sec = reader.read("!L")[0]
457 obj.duration_nsec = reader.read("!L")[0]
458 obj.priority = reader.read("!H")[0]
459 obj.idle_timeout = reader.read("!H")[0]
460 obj.hard_timeout = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700461 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700462 obj.cookie = reader.read("!Q")[0]
463 obj.packet_count = reader.read("!Q")[0]
464 obj.byte_count = reader.read("!Q")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800465 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -0700466 return obj
467
468 def __eq__(self, other):
469 if type(self) != type(other): return False
470 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700471 if self.match != other.match: return False
472 if self.duration_sec != other.duration_sec: return False
473 if self.duration_nsec != other.duration_nsec: return False
474 if self.priority != other.priority: return False
475 if self.idle_timeout != other.idle_timeout: return False
476 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700477 if self.cookie != other.cookie: return False
478 if self.packet_count != other.packet_count: return False
479 if self.byte_count != other.byte_count: return False
480 if self.actions != other.actions: return False
481 return True
482
Rich Laneb658ddd2013-03-12 10:15:10 -0700483 def pretty_print(self, q):
484 q.text("flow_stats_entry {")
485 with q.group():
486 with q.indent(2):
487 q.breakable()
488 q.text("table_id = ");
489 q.text("%#x" % self.table_id)
490 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700491 q.text("match = ");
492 q.pp(self.match)
493 q.text(","); q.breakable()
494 q.text("duration_sec = ");
495 q.text("%#x" % self.duration_sec)
496 q.text(","); q.breakable()
497 q.text("duration_nsec = ");
498 q.text("%#x" % self.duration_nsec)
499 q.text(","); q.breakable()
500 q.text("priority = ");
501 q.text("%#x" % self.priority)
502 q.text(","); q.breakable()
503 q.text("idle_timeout = ");
504 q.text("%#x" % self.idle_timeout)
505 q.text(","); q.breakable()
506 q.text("hard_timeout = ");
507 q.text("%#x" % self.hard_timeout)
508 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700509 q.text("cookie = ");
510 q.text("%#x" % self.cookie)
511 q.text(","); q.breakable()
512 q.text("packet_count = ");
513 q.text("%#x" % self.packet_count)
514 q.text(","); q.breakable()
515 q.text("byte_count = ");
516 q.text("%#x" % self.byte_count)
517 q.text(","); q.breakable()
518 q.text("actions = ");
519 q.pp(self.actions)
520 q.breakable()
521 q.text('}')
522
Rich Lane7dcdf022013-12-11 14:45:27 -0800523
524class match_v1(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700525
Rich Lanefe600f52013-07-09 13:22:32 -0700526 def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700527 if wildcards != None:
528 self.wildcards = wildcards
529 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700530 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -0700531 if in_port != None:
532 self.in_port = in_port
533 else:
534 self.in_port = 0
535 if eth_src != None:
536 self.eth_src = eth_src
537 else:
538 self.eth_src = [0,0,0,0,0,0]
539 if eth_dst != None:
540 self.eth_dst = eth_dst
541 else:
542 self.eth_dst = [0,0,0,0,0,0]
543 if vlan_vid != None:
544 self.vlan_vid = vlan_vid
545 else:
546 self.vlan_vid = 0
547 if vlan_pcp != None:
548 self.vlan_pcp = vlan_pcp
549 else:
550 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700551 if eth_type != None:
552 self.eth_type = eth_type
553 else:
554 self.eth_type = 0
555 if ip_dscp != None:
556 self.ip_dscp = ip_dscp
557 else:
558 self.ip_dscp = 0
559 if ip_proto != None:
560 self.ip_proto = ip_proto
561 else:
562 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700563 if ipv4_src != None:
564 self.ipv4_src = ipv4_src
565 else:
566 self.ipv4_src = 0
567 if ipv4_dst != None:
568 self.ipv4_dst = ipv4_dst
569 else:
570 self.ipv4_dst = 0
571 if tcp_src != None:
572 self.tcp_src = tcp_src
573 else:
574 self.tcp_src = 0
575 if tcp_dst != None:
576 self.tcp_dst = tcp_dst
577 else:
578 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700579 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700580
581 def pack(self):
582 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700583 packed.append(util.pack_wc_bmap(self.wildcards))
584 packed.append(util.pack_port_no(self.in_port))
Rich Laneb658ddd2013-03-12 10:15:10 -0700585 packed.append(struct.pack("!6B", *self.eth_src))
586 packed.append(struct.pack("!6B", *self.eth_dst))
587 packed.append(struct.pack("!H", self.vlan_vid))
588 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700589 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700590 packed.append(struct.pack("!H", self.eth_type))
591 packed.append(struct.pack("!B", self.ip_dscp))
592 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanefe600f52013-07-09 13:22:32 -0700593 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700594 packed.append(struct.pack("!L", self.ipv4_src))
595 packed.append(struct.pack("!L", self.ipv4_dst))
596 packed.append(struct.pack("!H", self.tcp_src))
597 packed.append(struct.pack("!H", self.tcp_dst))
598 return ''.join(packed)
599
600 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800601 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700602 obj = match_v1()
Dan Talaycof6202252013-07-02 01:00:29 -0700603 obj.wildcards = util.unpack_wc_bmap(reader)
604 obj.in_port = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700605 obj.eth_src = list(reader.read('!6B'))
606 obj.eth_dst = list(reader.read('!6B'))
Dan Talaycof6202252013-07-02 01:00:29 -0700607 obj.vlan_vid = reader.read("!H")[0]
608 obj.vlan_pcp = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -0700609 reader.skip(1)
Dan Talaycof6202252013-07-02 01:00:29 -0700610 obj.eth_type = reader.read("!H")[0]
611 obj.ip_dscp = reader.read("!B")[0]
612 obj.ip_proto = reader.read("!B")[0]
Rich Lanefe600f52013-07-09 13:22:32 -0700613 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -0700614 obj.ipv4_src = reader.read("!L")[0]
615 obj.ipv4_dst = reader.read("!L")[0]
616 obj.tcp_src = reader.read("!H")[0]
617 obj.tcp_dst = reader.read("!H")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700618 return obj
619
620 def __eq__(self, other):
621 if type(self) != type(other): return False
622 if self.wildcards != other.wildcards: return False
623 if self.in_port != other.in_port: return False
624 if self.eth_src != other.eth_src: return False
625 if self.eth_dst != other.eth_dst: return False
626 if self.vlan_vid != other.vlan_vid: return False
627 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700628 if self.eth_type != other.eth_type: return False
629 if self.ip_dscp != other.ip_dscp: return False
630 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700631 if self.ipv4_src != other.ipv4_src: return False
632 if self.ipv4_dst != other.ipv4_dst: return False
633 if self.tcp_src != other.tcp_src: return False
634 if self.tcp_dst != other.tcp_dst: return False
635 return True
636
Rich Laneb658ddd2013-03-12 10:15:10 -0700637 def pretty_print(self, q):
638 q.text("match_v1 {")
639 with q.group():
640 with q.indent(2):
641 q.breakable()
642 q.text("wildcards = ");
643 q.text(util.pretty_wildcards(self.wildcards))
644 q.text(","); q.breakable()
645 q.text("in_port = ");
646 q.text(util.pretty_port(self.in_port))
647 q.text(","); q.breakable()
648 q.text("eth_src = ");
649 q.text(util.pretty_mac(self.eth_src))
650 q.text(","); q.breakable()
651 q.text("eth_dst = ");
652 q.text(util.pretty_mac(self.eth_dst))
653 q.text(","); q.breakable()
654 q.text("vlan_vid = ");
655 q.text("%#x" % self.vlan_vid)
656 q.text(","); q.breakable()
657 q.text("vlan_pcp = ");
658 q.text("%#x" % self.vlan_pcp)
659 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700660 q.text("eth_type = ");
661 q.text("%#x" % self.eth_type)
662 q.text(","); q.breakable()
663 q.text("ip_dscp = ");
664 q.text("%#x" % self.ip_dscp)
665 q.text(","); q.breakable()
666 q.text("ip_proto = ");
667 q.text("%#x" % self.ip_proto)
668 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700669 q.text("ipv4_src = ");
670 q.text(util.pretty_ipv4(self.ipv4_src))
671 q.text(","); q.breakable()
672 q.text("ipv4_dst = ");
673 q.text(util.pretty_ipv4(self.ipv4_dst))
674 q.text(","); q.breakable()
675 q.text("tcp_src = ");
676 q.text("%#x" % self.tcp_src)
677 q.text(","); q.breakable()
678 q.text("tcp_dst = ");
679 q.text("%#x" % self.tcp_dst)
680 q.breakable()
681 q.text('}')
682
Rich Lane7dcdf022013-12-11 14:45:27 -0800683
684class packet_queue(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700685
Rich Lanec2ee4b82013-04-24 17:12:38 -0700686 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700687 if queue_id != None:
688 self.queue_id = queue_id
689 else:
690 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700691 if properties != None:
692 self.properties = properties
693 else:
694 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700695 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700696
697 def pack(self):
698 packed = []
699 packed.append(struct.pack("!L", self.queue_id))
700 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700701 packed.append('\x00' * 2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800702 packed.append(loxi.generic_util.pack_list(self.properties))
Rich Laneb658ddd2013-03-12 10:15:10 -0700703 length = sum([len(x) for x in packed])
704 packed[1] = struct.pack("!H", length)
705 return ''.join(packed)
706
707 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800708 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700709 obj = packet_queue()
Dan Talaycof6202252013-07-02 01:00:29 -0700710 obj.queue_id = reader.read("!L")[0]
711 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800712 orig_reader = reader
713 reader = orig_reader.slice(_len - (4 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700714 reader.skip(2)
Rich Lane7dcdf022013-12-11 14:45:27 -0800715 obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -0700716 return obj
717
718 def __eq__(self, other):
719 if type(self) != type(other): return False
720 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700721 if self.properties != other.properties: return False
722 return True
723
Rich Laneb658ddd2013-03-12 10:15:10 -0700724 def pretty_print(self, q):
725 q.text("packet_queue {")
726 with q.group():
727 with q.indent(2):
728 q.breakable()
729 q.text("queue_id = ");
730 q.text("%#x" % self.queue_id)
731 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700732 q.text("properties = ");
733 q.pp(self.properties)
734 q.breakable()
735 q.text('}')
736
Rich Lane7dcdf022013-12-11 14:45:27 -0800737
738class port_desc(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700739
740 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
741 if port_no != None:
742 self.port_no = port_no
743 else:
744 self.port_no = 0
745 if hw_addr != None:
746 self.hw_addr = hw_addr
747 else:
748 self.hw_addr = [0,0,0,0,0,0]
749 if name != None:
750 self.name = name
751 else:
752 self.name = ""
753 if config != None:
754 self.config = config
755 else:
756 self.config = 0
757 if state != None:
758 self.state = state
759 else:
760 self.state = 0
761 if curr != None:
762 self.curr = curr
763 else:
764 self.curr = 0
765 if advertised != None:
766 self.advertised = advertised
767 else:
768 self.advertised = 0
769 if supported != None:
770 self.supported = supported
771 else:
772 self.supported = 0
773 if peer != None:
774 self.peer = peer
775 else:
776 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700777 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700778
779 def pack(self):
780 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700781 packed.append(util.pack_port_no(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -0700782 packed.append(struct.pack("!6B", *self.hw_addr))
783 packed.append(struct.pack("!16s", self.name))
784 packed.append(struct.pack("!L", self.config))
785 packed.append(struct.pack("!L", self.state))
786 packed.append(struct.pack("!L", self.curr))
787 packed.append(struct.pack("!L", self.advertised))
788 packed.append(struct.pack("!L", self.supported))
789 packed.append(struct.pack("!L", self.peer))
790 return ''.join(packed)
791
792 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800793 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700794 obj = port_desc()
Dan Talaycof6202252013-07-02 01:00:29 -0700795 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700796 obj.hw_addr = list(reader.read('!6B'))
797 obj.name = reader.read("!16s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -0700798 obj.config = reader.read("!L")[0]
799 obj.state = reader.read("!L")[0]
800 obj.curr = reader.read("!L")[0]
801 obj.advertised = reader.read("!L")[0]
802 obj.supported = reader.read("!L")[0]
803 obj.peer = reader.read("!L")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700804 return obj
805
806 def __eq__(self, other):
807 if type(self) != type(other): return False
808 if self.port_no != other.port_no: return False
809 if self.hw_addr != other.hw_addr: return False
810 if self.name != other.name: return False
811 if self.config != other.config: return False
812 if self.state != other.state: return False
813 if self.curr != other.curr: return False
814 if self.advertised != other.advertised: return False
815 if self.supported != other.supported: return False
816 if self.peer != other.peer: return False
817 return True
818
Rich Laneb658ddd2013-03-12 10:15:10 -0700819 def pretty_print(self, q):
820 q.text("port_desc {")
821 with q.group():
822 with q.indent(2):
823 q.breakable()
824 q.text("port_no = ");
825 q.text(util.pretty_port(self.port_no))
826 q.text(","); q.breakable()
827 q.text("hw_addr = ");
828 q.text(util.pretty_mac(self.hw_addr))
829 q.text(","); q.breakable()
830 q.text("name = ");
831 q.pp(self.name)
832 q.text(","); q.breakable()
833 q.text("config = ");
834 q.text("%#x" % self.config)
835 q.text(","); q.breakable()
836 q.text("state = ");
837 q.text("%#x" % self.state)
838 q.text(","); q.breakable()
839 q.text("curr = ");
840 q.text("%#x" % self.curr)
841 q.text(","); q.breakable()
842 q.text("advertised = ");
843 q.text("%#x" % self.advertised)
844 q.text(","); q.breakable()
845 q.text("supported = ");
846 q.text("%#x" % self.supported)
847 q.text(","); q.breakable()
848 q.text("peer = ");
849 q.text("%#x" % self.peer)
850 q.breakable()
851 q.text('}')
852
Rich Lane7dcdf022013-12-11 14:45:27 -0800853
854class port_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -0700855
Rich Lanec2ee4b82013-04-24 17:12:38 -0700856 def __init__(self, port_no=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700857 if port_no != None:
858 self.port_no = port_no
859 else:
860 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700861 if rx_packets != None:
862 self.rx_packets = rx_packets
863 else:
864 self.rx_packets = 0
865 if tx_packets != None:
866 self.tx_packets = tx_packets
867 else:
868 self.tx_packets = 0
869 if rx_bytes != None:
870 self.rx_bytes = rx_bytes
871 else:
872 self.rx_bytes = 0
873 if tx_bytes != None:
874 self.tx_bytes = tx_bytes
875 else:
876 self.tx_bytes = 0
877 if rx_dropped != None:
878 self.rx_dropped = rx_dropped
879 else:
880 self.rx_dropped = 0
881 if tx_dropped != None:
882 self.tx_dropped = tx_dropped
883 else:
884 self.tx_dropped = 0
885 if rx_errors != None:
886 self.rx_errors = rx_errors
887 else:
888 self.rx_errors = 0
889 if tx_errors != None:
890 self.tx_errors = tx_errors
891 else:
892 self.tx_errors = 0
893 if rx_frame_err != None:
894 self.rx_frame_err = rx_frame_err
895 else:
896 self.rx_frame_err = 0
897 if rx_over_err != None:
898 self.rx_over_err = rx_over_err
899 else:
900 self.rx_over_err = 0
901 if rx_crc_err != None:
902 self.rx_crc_err = rx_crc_err
903 else:
904 self.rx_crc_err = 0
905 if collisions != None:
906 self.collisions = collisions
907 else:
908 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700909 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700910
911 def pack(self):
912 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -0700913 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700914 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700915 packed.append(struct.pack("!Q", self.rx_packets))
916 packed.append(struct.pack("!Q", self.tx_packets))
917 packed.append(struct.pack("!Q", self.rx_bytes))
918 packed.append(struct.pack("!Q", self.tx_bytes))
919 packed.append(struct.pack("!Q", self.rx_dropped))
920 packed.append(struct.pack("!Q", self.tx_dropped))
921 packed.append(struct.pack("!Q", self.rx_errors))
922 packed.append(struct.pack("!Q", self.tx_errors))
923 packed.append(struct.pack("!Q", self.rx_frame_err))
924 packed.append(struct.pack("!Q", self.rx_over_err))
925 packed.append(struct.pack("!Q", self.rx_crc_err))
926 packed.append(struct.pack("!Q", self.collisions))
927 return ''.join(packed)
928
929 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800930 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -0700931 obj = port_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -0700932 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -0700933 reader.skip(6)
Dan Talaycof6202252013-07-02 01:00:29 -0700934 obj.rx_packets = reader.read("!Q")[0]
935 obj.tx_packets = reader.read("!Q")[0]
936 obj.rx_bytes = reader.read("!Q")[0]
937 obj.tx_bytes = reader.read("!Q")[0]
938 obj.rx_dropped = reader.read("!Q")[0]
939 obj.tx_dropped = reader.read("!Q")[0]
940 obj.rx_errors = reader.read("!Q")[0]
941 obj.tx_errors = reader.read("!Q")[0]
942 obj.rx_frame_err = reader.read("!Q")[0]
943 obj.rx_over_err = reader.read("!Q")[0]
944 obj.rx_crc_err = reader.read("!Q")[0]
945 obj.collisions = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700946 return obj
947
948 def __eq__(self, other):
949 if type(self) != type(other): return False
950 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700951 if self.rx_packets != other.rx_packets: return False
952 if self.tx_packets != other.tx_packets: return False
953 if self.rx_bytes != other.rx_bytes: return False
954 if self.tx_bytes != other.tx_bytes: return False
955 if self.rx_dropped != other.rx_dropped: return False
956 if self.tx_dropped != other.tx_dropped: return False
957 if self.rx_errors != other.rx_errors: return False
958 if self.tx_errors != other.tx_errors: return False
959 if self.rx_frame_err != other.rx_frame_err: return False
960 if self.rx_over_err != other.rx_over_err: return False
961 if self.rx_crc_err != other.rx_crc_err: return False
962 if self.collisions != other.collisions: return False
963 return True
964
Rich Laneb658ddd2013-03-12 10:15:10 -0700965 def pretty_print(self, q):
966 q.text("port_stats_entry {")
967 with q.group():
968 with q.indent(2):
969 q.breakable()
970 q.text("port_no = ");
971 q.text(util.pretty_port(self.port_no))
972 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700973 q.text("rx_packets = ");
974 q.text("%#x" % self.rx_packets)
975 q.text(","); q.breakable()
976 q.text("tx_packets = ");
977 q.text("%#x" % self.tx_packets)
978 q.text(","); q.breakable()
979 q.text("rx_bytes = ");
980 q.text("%#x" % self.rx_bytes)
981 q.text(","); q.breakable()
982 q.text("tx_bytes = ");
983 q.text("%#x" % self.tx_bytes)
984 q.text(","); q.breakable()
985 q.text("rx_dropped = ");
986 q.text("%#x" % self.rx_dropped)
987 q.text(","); q.breakable()
988 q.text("tx_dropped = ");
989 q.text("%#x" % self.tx_dropped)
990 q.text(","); q.breakable()
991 q.text("rx_errors = ");
992 q.text("%#x" % self.rx_errors)
993 q.text(","); q.breakable()
994 q.text("tx_errors = ");
995 q.text("%#x" % self.tx_errors)
996 q.text(","); q.breakable()
997 q.text("rx_frame_err = ");
998 q.text("%#x" % self.rx_frame_err)
999 q.text(","); q.breakable()
1000 q.text("rx_over_err = ");
1001 q.text("%#x" % self.rx_over_err)
1002 q.text(","); q.breakable()
1003 q.text("rx_crc_err = ");
1004 q.text("%#x" % self.rx_crc_err)
1005 q.text(","); q.breakable()
1006 q.text("collisions = ");
1007 q.text("%#x" % self.collisions)
1008 q.breakable()
1009 q.text('}')
1010
Rich Lane7dcdf022013-12-11 14:45:27 -08001011
1012class queue_prop(loxi.OFObject):
1013 subtypes = {}
1014
Rich Lane95f7fc92014-01-27 17:08:16 -08001015
1016 def __init__(self, type=None):
1017 if type != None:
1018 self.type = type
1019 else:
1020 self.type = 0
1021 return
1022
1023 def pack(self):
1024 packed = []
1025 packed.append(struct.pack("!H", self.type))
1026 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1027 packed.append('\x00' * 4)
1028 length = sum([len(x) for x in packed])
1029 packed[1] = struct.pack("!H", length)
1030 return ''.join(packed)
1031
Rich Lane7dcdf022013-12-11 14:45:27 -08001032 @staticmethod
1033 def unpack(reader):
1034 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -08001035 subclass = queue_prop.subtypes.get(subtype)
1036 if subclass:
1037 return subclass.unpack(reader)
1038
1039 obj = queue_prop()
1040 obj.type = reader.read("!H")[0]
1041 _len = reader.read("!H")[0]
1042 orig_reader = reader
1043 reader = orig_reader.slice(_len - (2 + 2))
1044 reader.skip(4)
1045 return obj
1046
1047 def __eq__(self, other):
1048 if type(self) != type(other): return False
1049 if self.type != other.type: return False
1050 return True
1051
1052 def pretty_print(self, q):
1053 q.text("queue_prop {")
1054 with q.group():
1055 with q.indent(2):
1056 q.breakable()
1057 q.breakable()
1058 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -08001059
1060
1061class queue_prop_min_rate(queue_prop):
Dan Talaycof6202252013-07-02 01:00:29 -07001062 type = 1
Rich Laneb658ddd2013-03-12 10:15:10 -07001063
Rich Lanec2ee4b82013-04-24 17:12:38 -07001064 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001065 if rate != None:
1066 self.rate = rate
1067 else:
1068 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001069 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001070
1071 def pack(self):
1072 packed = []
1073 packed.append(struct.pack("!H", self.type))
1074 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -07001075 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -07001076 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001077 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -07001078 length = sum([len(x) for x in packed])
1079 packed[1] = struct.pack("!H", length)
1080 return ''.join(packed)
1081
1082 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001083 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001084 obj = queue_prop_min_rate()
Dan Talaycof6202252013-07-02 01:00:29 -07001085 _type = reader.read("!H")[0]
1086 assert(_type == 1)
1087 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -08001088 orig_reader = reader
1089 reader = orig_reader.slice(_len - (2 + 2))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001090 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -07001091 obj.rate = reader.read("!H")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001092 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -07001093 return obj
1094
1095 def __eq__(self, other):
1096 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001097 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001098 return True
1099
Rich Laneb658ddd2013-03-12 10:15:10 -07001100 def pretty_print(self, q):
1101 q.text("queue_prop_min_rate {")
1102 with q.group():
1103 with q.indent(2):
1104 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001105 q.text("rate = ");
1106 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -07001107 q.breakable()
1108 q.text('}')
1109
Rich Lane7dcdf022013-12-11 14:45:27 -08001110queue_prop.subtypes[1] = queue_prop_min_rate
1111
1112class queue_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -07001113
Rich Lanec2ee4b82013-04-24 17:12:38 -07001114 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001115 if port_no != None:
1116 self.port_no = port_no
1117 else:
1118 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001119 if queue_id != None:
1120 self.queue_id = queue_id
1121 else:
1122 self.queue_id = 0
1123 if tx_bytes != None:
1124 self.tx_bytes = tx_bytes
1125 else:
1126 self.tx_bytes = 0
1127 if tx_packets != None:
1128 self.tx_packets = tx_packets
1129 else:
1130 self.tx_packets = 0
1131 if tx_errors != None:
1132 self.tx_errors = tx_errors
1133 else:
1134 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001135 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001136
1137 def pack(self):
1138 packed = []
Dan Talaycof6202252013-07-02 01:00:29 -07001139 packed.append(util.pack_port_no(self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001140 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07001141 packed.append(struct.pack("!L", self.queue_id))
1142 packed.append(struct.pack("!Q", self.tx_bytes))
1143 packed.append(struct.pack("!Q", self.tx_packets))
1144 packed.append(struct.pack("!Q", self.tx_errors))
1145 return ''.join(packed)
1146
1147 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001148 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001149 obj = queue_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001150 obj.port_no = util.unpack_port_no(reader)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001151 reader.skip(2)
Dan Talaycof6202252013-07-02 01:00:29 -07001152 obj.queue_id = reader.read("!L")[0]
1153 obj.tx_bytes = reader.read("!Q")[0]
1154 obj.tx_packets = reader.read("!Q")[0]
1155 obj.tx_errors = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001156 return obj
1157
1158 def __eq__(self, other):
1159 if type(self) != type(other): return False
1160 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001161 if self.queue_id != other.queue_id: return False
1162 if self.tx_bytes != other.tx_bytes: return False
1163 if self.tx_packets != other.tx_packets: return False
1164 if self.tx_errors != other.tx_errors: return False
1165 return True
1166
Rich Laneb658ddd2013-03-12 10:15:10 -07001167 def pretty_print(self, q):
1168 q.text("queue_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()
Rich Laneb658ddd2013-03-12 10:15:10 -07001175 q.text("queue_id = ");
1176 q.text("%#x" % self.queue_id)
1177 q.text(","); q.breakable()
1178 q.text("tx_bytes = ");
1179 q.text("%#x" % self.tx_bytes)
1180 q.text(","); q.breakable()
1181 q.text("tx_packets = ");
1182 q.text("%#x" % self.tx_packets)
1183 q.text(","); q.breakable()
1184 q.text("tx_errors = ");
1185 q.text("%#x" % self.tx_errors)
1186 q.breakable()
1187 q.text('}')
1188
Rich Lane7dcdf022013-12-11 14:45:27 -08001189
1190class table_stats_entry(loxi.OFObject):
Rich Laneb658ddd2013-03-12 10:15:10 -07001191
Rich Lanec2ee4b82013-04-24 17:12:38 -07001192 def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001193 if table_id != None:
1194 self.table_id = table_id
1195 else:
1196 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001197 if name != None:
1198 self.name = name
1199 else:
1200 self.name = ""
1201 if wildcards != None:
1202 self.wildcards = wildcards
1203 else:
Dan Talaycof6202252013-07-02 01:00:29 -07001204 self.wildcards = util.init_wc_bmap()
Rich Laneb658ddd2013-03-12 10:15:10 -07001205 if max_entries != None:
1206 self.max_entries = max_entries
1207 else:
1208 self.max_entries = 0
1209 if active_count != None:
1210 self.active_count = active_count
1211 else:
1212 self.active_count = 0
1213 if lookup_count != None:
1214 self.lookup_count = lookup_count
1215 else:
1216 self.lookup_count = 0
1217 if matched_count != None:
1218 self.matched_count = matched_count
1219 else:
1220 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -07001221 return
Rich Laneb658ddd2013-03-12 10:15:10 -07001222
1223 def pack(self):
1224 packed = []
1225 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001226 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001227 packed.append(struct.pack("!32s", self.name))
Dan Talaycof6202252013-07-02 01:00:29 -07001228 packed.append(util.pack_wc_bmap(self.wildcards))
Rich Laneb658ddd2013-03-12 10:15:10 -07001229 packed.append(struct.pack("!L", self.max_entries))
1230 packed.append(struct.pack("!L", self.active_count))
1231 packed.append(struct.pack("!Q", self.lookup_count))
1232 packed.append(struct.pack("!Q", self.matched_count))
1233 return ''.join(packed)
1234
1235 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -08001236 def unpack(reader):
Rich Laneb658ddd2013-03-12 10:15:10 -07001237 obj = table_stats_entry()
Dan Talaycof6202252013-07-02 01:00:29 -07001238 obj.table_id = reader.read("!B")[0]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001239 reader.skip(3)
1240 obj.name = reader.read("!32s")[0].rstrip("\x00")
Dan Talaycof6202252013-07-02 01:00:29 -07001241 obj.wildcards = util.unpack_wc_bmap(reader)
1242 obj.max_entries = reader.read("!L")[0]
1243 obj.active_count = reader.read("!L")[0]
1244 obj.lookup_count = reader.read("!Q")[0]
1245 obj.matched_count = reader.read("!Q")[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001246 return obj
1247
1248 def __eq__(self, other):
1249 if type(self) != type(other): return False
1250 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001251 if self.name != other.name: return False
1252 if self.wildcards != other.wildcards: return False
1253 if self.max_entries != other.max_entries: return False
1254 if self.active_count != other.active_count: return False
1255 if self.lookup_count != other.lookup_count: return False
1256 if self.matched_count != other.matched_count: return False
1257 return True
1258
Rich Laneb658ddd2013-03-12 10:15:10 -07001259 def pretty_print(self, q):
1260 q.text("table_stats_entry {")
1261 with q.group():
1262 with q.indent(2):
1263 q.breakable()
1264 q.text("table_id = ");
1265 q.text("%#x" % self.table_id)
1266 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001267 q.text("name = ");
1268 q.pp(self.name)
1269 q.text(","); q.breakable()
1270 q.text("wildcards = ");
1271 q.text(util.pretty_wildcards(self.wildcards))
1272 q.text(","); q.breakable()
1273 q.text("max_entries = ");
1274 q.text("%#x" % self.max_entries)
1275 q.text(","); q.breakable()
1276 q.text("active_count = ");
1277 q.text("%#x" % self.active_count)
1278 q.text(","); q.breakable()
1279 q.text("lookup_count = ");
1280 q.text("%#x" % self.lookup_count)
1281 q.text(","); q.breakable()
1282 q.text("matched_count = ");
1283 q.text("%#x" % self.matched_count)
1284 q.breakable()
1285 q.text('}')
1286
Rich Lanec2ee4b82013-04-24 17:12:38 -07001287
Rich Lane7dcdf022013-12-11 14:45:27 -08001288
Rich Lanec2ee4b82013-04-24 17:12:38 -07001289match = match_v1