blob: cfee494bbd440a62d960278b6d79b161285949e1 [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.
Rich Laneb658ddd2013-03-12 10:15:10 -07004
5# Automatically generated by LOXI from template common.py
6# Do not modify
7
8import sys
9import struct
10import action
11import const
12import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070013import loxi.generic_util
14
Rich Laneb658ddd2013-03-12 10:15:10 -070015
16# HACK make this module visible as 'common' to simplify code generation
17common = sys.modules[__name__]
18
Rich Lanec2ee4b82013-04-24 17:12:38 -070019def unpack_list_flow_stats_entry(reader):
20 return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -070021
Rich Lanec2ee4b82013-04-24 17:12:38 -070022def unpack_list_queue_prop(reader):
23 def deserializer(reader, typ):
24 if typ == const.OFPQT_MIN_RATE:
25 return queue_prop_min_rate.unpack(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -070026 else:
Rich Lanec2ee4b82013-04-24 17:12:38 -070027 raise loxi.ProtocolError("unknown queue prop %d" % typ)
28 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
Rich Laneb658ddd2013-03-12 10:15:10 -070029
Rich Lanec2ee4b82013-04-24 17:12:38 -070030def unpack_list_packet_queue(reader):
31 def wrapper(reader):
32 length, = reader.peek('!4xH')
33 return packet_queue.unpack(reader.slice(length))
34 return loxi.generic_util.unpack_list(reader, wrapper)
35
36def unpack_list_hello_elem(reader):
37 def deserializer(reader, typ):
38 if typ == const.OFPHET_VERSIONBITMAP:
39 return hello_elem_versionbitmap.unpack(reader)
40 else:
41 return None
42 return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
43
44def unpack_list_bucket(reader):
45 return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
46
47def unpack_list_group_desc_stats_entry(reader):
48 return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
49
50def unpack_list_group_stats_entry(reader):
51 return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
52
53def unpack_list_meter_stats(reader):
54 def wrapper(reader):
55 length, = reader.peek('!4xH')
56 return meter_stats.unpack(reader.slice(length))
57 return loxi.generic_util.unpack_list(reader, wrapper)
Rich Laneb658ddd2013-03-12 10:15:10 -070058
59class bsn_interface(object):
60
Rich Lanec2ee4b82013-04-24 17:12:38 -070061 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070062 if hw_addr != None:
63 self.hw_addr = hw_addr
64 else:
65 self.hw_addr = [0,0,0,0,0,0]
Rich Laneb658ddd2013-03-12 10:15:10 -070066 if name != None:
67 self.name = name
68 else:
69 self.name = ""
70 if ipv4_addr != None:
71 self.ipv4_addr = ipv4_addr
72 else:
73 self.ipv4_addr = 0
74 if ipv4_netmask != None:
75 self.ipv4_netmask = ipv4_netmask
76 else:
77 self.ipv4_netmask = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -070078 return
Rich Laneb658ddd2013-03-12 10:15:10 -070079
80 def pack(self):
81 packed = []
82 packed.append(struct.pack("!6B", *self.hw_addr))
Rich Lanec2ee4b82013-04-24 17:12:38 -070083 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -070084 packed.append(struct.pack("!16s", self.name))
85 packed.append(struct.pack("!L", self.ipv4_addr))
86 packed.append(struct.pack("!L", self.ipv4_netmask))
87 return ''.join(packed)
88
89 @staticmethod
90 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -070091 obj = bsn_interface()
Rich Lanec2ee4b82013-04-24 17:12:38 -070092 if type(buf) == loxi.generic_util.OFReader:
93 reader = buf
94 else:
95 reader = loxi.generic_util.OFReader(buf)
96 obj.hw_addr = list(reader.read('!6B'))
97 reader.skip(2)
98 obj.name = reader.read("!16s")[0].rstrip("\x00")
99 obj.ipv4_addr = reader.read('!L')[0]
100 obj.ipv4_netmask = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700101 return obj
102
103 def __eq__(self, other):
104 if type(self) != type(other): return False
105 if self.hw_addr != other.hw_addr: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700106 if self.name != other.name: return False
107 if self.ipv4_addr != other.ipv4_addr: return False
108 if self.ipv4_netmask != other.ipv4_netmask: return False
109 return True
110
111 def __ne__(self, other):
112 return not self.__eq__(other)
113
114 def show(self):
115 import loxi.pp
116 return loxi.pp.pp(self)
117
118 def pretty_print(self, q):
119 q.text("bsn_interface {")
120 with q.group():
121 with q.indent(2):
122 q.breakable()
123 q.text("hw_addr = ");
124 q.text(util.pretty_mac(self.hw_addr))
125 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700126 q.text("name = ");
127 q.pp(self.name)
128 q.text(","); q.breakable()
129 q.text("ipv4_addr = ");
130 q.text(util.pretty_ipv4(self.ipv4_addr))
131 q.text(","); q.breakable()
132 q.text("ipv4_netmask = ");
133 q.text(util.pretty_ipv4(self.ipv4_netmask))
134 q.breakable()
135 q.text('}')
136
137class flow_stats_entry(object):
138
Rich Lanec2ee4b82013-04-24 17:12:38 -0700139 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 -0700140 if table_id != None:
141 self.table_id = table_id
142 else:
143 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700144 if match != None:
145 self.match = match
146 else:
147 self.match = common.match()
148 if duration_sec != None:
149 self.duration_sec = duration_sec
150 else:
151 self.duration_sec = 0
152 if duration_nsec != None:
153 self.duration_nsec = duration_nsec
154 else:
155 self.duration_nsec = 0
156 if priority != None:
157 self.priority = priority
158 else:
159 self.priority = 0
160 if idle_timeout != None:
161 self.idle_timeout = idle_timeout
162 else:
163 self.idle_timeout = 0
164 if hard_timeout != None:
165 self.hard_timeout = hard_timeout
166 else:
167 self.hard_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700168 if cookie != None:
169 self.cookie = cookie
170 else:
171 self.cookie = 0
172 if packet_count != None:
173 self.packet_count = packet_count
174 else:
175 self.packet_count = 0
176 if byte_count != None:
177 self.byte_count = byte_count
178 else:
179 self.byte_count = 0
180 if actions != None:
181 self.actions = actions
182 else:
183 self.actions = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700184 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700185
186 def pack(self):
187 packed = []
188 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
189 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700190 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700191 packed.append(self.match.pack())
192 packed.append(struct.pack("!L", self.duration_sec))
193 packed.append(struct.pack("!L", self.duration_nsec))
194 packed.append(struct.pack("!H", self.priority))
195 packed.append(struct.pack("!H", self.idle_timeout))
196 packed.append(struct.pack("!H", self.hard_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700197 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700198 packed.append(struct.pack("!Q", self.cookie))
199 packed.append(struct.pack("!Q", self.packet_count))
200 packed.append(struct.pack("!Q", self.byte_count))
201 packed.append("".join([x.pack() for x in self.actions]))
202 length = sum([len(x) for x in packed])
203 packed[0] = struct.pack("!H", length)
204 return ''.join(packed)
205
206 @staticmethod
207 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700208 obj = flow_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700209 if type(buf) == loxi.generic_util.OFReader:
210 reader = buf
211 else:
212 reader = loxi.generic_util.OFReader(buf)
213 _length = reader.read('!H')[0]
214 obj.table_id = reader.read('!B')[0]
215 reader.skip(1)
216 obj.match = common.match.unpack(reader)
217 obj.duration_sec = reader.read('!L')[0]
218 obj.duration_nsec = reader.read('!L')[0]
219 obj.priority = reader.read('!H')[0]
220 obj.idle_timeout = reader.read('!H')[0]
221 obj.hard_timeout = reader.read('!H')[0]
222 reader.skip(6)
223 obj.cookie = reader.read('!Q')[0]
224 obj.packet_count = reader.read('!Q')[0]
225 obj.byte_count = reader.read('!Q')[0]
226 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700227 return obj
228
229 def __eq__(self, other):
230 if type(self) != type(other): return False
231 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700232 if self.match != other.match: return False
233 if self.duration_sec != other.duration_sec: return False
234 if self.duration_nsec != other.duration_nsec: return False
235 if self.priority != other.priority: return False
236 if self.idle_timeout != other.idle_timeout: return False
237 if self.hard_timeout != other.hard_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700238 if self.cookie != other.cookie: return False
239 if self.packet_count != other.packet_count: return False
240 if self.byte_count != other.byte_count: return False
241 if self.actions != other.actions: return False
242 return True
243
244 def __ne__(self, other):
245 return not self.__eq__(other)
246
247 def show(self):
248 import loxi.pp
249 return loxi.pp.pp(self)
250
251 def pretty_print(self, q):
252 q.text("flow_stats_entry {")
253 with q.group():
254 with q.indent(2):
255 q.breakable()
256 q.text("table_id = ");
257 q.text("%#x" % self.table_id)
258 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700259 q.text("match = ");
260 q.pp(self.match)
261 q.text(","); q.breakable()
262 q.text("duration_sec = ");
263 q.text("%#x" % self.duration_sec)
264 q.text(","); q.breakable()
265 q.text("duration_nsec = ");
266 q.text("%#x" % self.duration_nsec)
267 q.text(","); q.breakable()
268 q.text("priority = ");
269 q.text("%#x" % self.priority)
270 q.text(","); q.breakable()
271 q.text("idle_timeout = ");
272 q.text("%#x" % self.idle_timeout)
273 q.text(","); q.breakable()
274 q.text("hard_timeout = ");
275 q.text("%#x" % self.hard_timeout)
276 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700277 q.text("cookie = ");
278 q.text("%#x" % self.cookie)
279 q.text(","); q.breakable()
280 q.text("packet_count = ");
281 q.text("%#x" % self.packet_count)
282 q.text(","); q.breakable()
283 q.text("byte_count = ");
284 q.text("%#x" % self.byte_count)
285 q.text(","); q.breakable()
286 q.text("actions = ");
287 q.pp(self.actions)
288 q.breakable()
289 q.text('}')
290
291class match_v1(object):
292
Rich Lanec2ee4b82013-04-24 17:12:38 -0700293 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 -0700294 if wildcards != None:
295 self.wildcards = wildcards
296 else:
297 self.wildcards = const.OFPFW_ALL
298 if in_port != None:
299 self.in_port = in_port
300 else:
301 self.in_port = 0
302 if eth_src != None:
303 self.eth_src = eth_src
304 else:
305 self.eth_src = [0,0,0,0,0,0]
306 if eth_dst != None:
307 self.eth_dst = eth_dst
308 else:
309 self.eth_dst = [0,0,0,0,0,0]
310 if vlan_vid != None:
311 self.vlan_vid = vlan_vid
312 else:
313 self.vlan_vid = 0
314 if vlan_pcp != None:
315 self.vlan_pcp = vlan_pcp
316 else:
317 self.vlan_pcp = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700318 if eth_type != None:
319 self.eth_type = eth_type
320 else:
321 self.eth_type = 0
322 if ip_dscp != None:
323 self.ip_dscp = ip_dscp
324 else:
325 self.ip_dscp = 0
326 if ip_proto != None:
327 self.ip_proto = ip_proto
328 else:
329 self.ip_proto = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700330 if ipv4_src != None:
331 self.ipv4_src = ipv4_src
332 else:
333 self.ipv4_src = 0
334 if ipv4_dst != None:
335 self.ipv4_dst = ipv4_dst
336 else:
337 self.ipv4_dst = 0
338 if tcp_src != None:
339 self.tcp_src = tcp_src
340 else:
341 self.tcp_src = 0
342 if tcp_dst != None:
343 self.tcp_dst = tcp_dst
344 else:
345 self.tcp_dst = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700346 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700347
348 def pack(self):
349 packed = []
350 packed.append(struct.pack("!L", self.wildcards))
351 packed.append(struct.pack("!H", self.in_port))
352 packed.append(struct.pack("!6B", *self.eth_src))
353 packed.append(struct.pack("!6B", *self.eth_dst))
354 packed.append(struct.pack("!H", self.vlan_vid))
355 packed.append(struct.pack("!B", self.vlan_pcp))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700356 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700357 packed.append(struct.pack("!H", self.eth_type))
358 packed.append(struct.pack("!B", self.ip_dscp))
359 packed.append(struct.pack("!B", self.ip_proto))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700360 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700361 packed.append(struct.pack("!L", self.ipv4_src))
362 packed.append(struct.pack("!L", self.ipv4_dst))
363 packed.append(struct.pack("!H", self.tcp_src))
364 packed.append(struct.pack("!H", self.tcp_dst))
365 return ''.join(packed)
366
367 @staticmethod
368 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700369 obj = match_v1()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700370 if type(buf) == loxi.generic_util.OFReader:
371 reader = buf
372 else:
373 reader = loxi.generic_util.OFReader(buf)
374 obj.wildcards = reader.read('!L')[0]
375 obj.in_port = reader.read('!H')[0]
376 obj.eth_src = list(reader.read('!6B'))
377 obj.eth_dst = list(reader.read('!6B'))
378 obj.vlan_vid = reader.read('!H')[0]
379 obj.vlan_pcp = reader.read('!B')[0]
380 reader.skip(1)
381 obj.eth_type = reader.read('!H')[0]
382 obj.ip_dscp = reader.read('!B')[0]
383 obj.ip_proto = reader.read('!B')[0]
384 reader.skip(2)
385 obj.ipv4_src = reader.read('!L')[0]
386 obj.ipv4_dst = reader.read('!L')[0]
387 obj.tcp_src = reader.read('!H')[0]
388 obj.tcp_dst = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700389 return obj
390
391 def __eq__(self, other):
392 if type(self) != type(other): return False
393 if self.wildcards != other.wildcards: return False
394 if self.in_port != other.in_port: return False
395 if self.eth_src != other.eth_src: return False
396 if self.eth_dst != other.eth_dst: return False
397 if self.vlan_vid != other.vlan_vid: return False
398 if self.vlan_pcp != other.vlan_pcp: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700399 if self.eth_type != other.eth_type: return False
400 if self.ip_dscp != other.ip_dscp: return False
401 if self.ip_proto != other.ip_proto: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700402 if self.ipv4_src != other.ipv4_src: return False
403 if self.ipv4_dst != other.ipv4_dst: return False
404 if self.tcp_src != other.tcp_src: return False
405 if self.tcp_dst != other.tcp_dst: return False
406 return True
407
408 def __ne__(self, other):
409 return not self.__eq__(other)
410
411 def show(self):
412 import loxi.pp
413 return loxi.pp.pp(self)
414
415 def pretty_print(self, q):
416 q.text("match_v1 {")
417 with q.group():
418 with q.indent(2):
419 q.breakable()
420 q.text("wildcards = ");
421 q.text(util.pretty_wildcards(self.wildcards))
422 q.text(","); q.breakable()
423 q.text("in_port = ");
424 q.text(util.pretty_port(self.in_port))
425 q.text(","); q.breakable()
426 q.text("eth_src = ");
427 q.text(util.pretty_mac(self.eth_src))
428 q.text(","); q.breakable()
429 q.text("eth_dst = ");
430 q.text(util.pretty_mac(self.eth_dst))
431 q.text(","); q.breakable()
432 q.text("vlan_vid = ");
433 q.text("%#x" % self.vlan_vid)
434 q.text(","); q.breakable()
435 q.text("vlan_pcp = ");
436 q.text("%#x" % self.vlan_pcp)
437 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700438 q.text("eth_type = ");
439 q.text("%#x" % self.eth_type)
440 q.text(","); q.breakable()
441 q.text("ip_dscp = ");
442 q.text("%#x" % self.ip_dscp)
443 q.text(","); q.breakable()
444 q.text("ip_proto = ");
445 q.text("%#x" % self.ip_proto)
446 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700447 q.text("ipv4_src = ");
448 q.text(util.pretty_ipv4(self.ipv4_src))
449 q.text(","); q.breakable()
450 q.text("ipv4_dst = ");
451 q.text(util.pretty_ipv4(self.ipv4_dst))
452 q.text(","); q.breakable()
453 q.text("tcp_src = ");
454 q.text("%#x" % self.tcp_src)
455 q.text(","); q.breakable()
456 q.text("tcp_dst = ");
457 q.text("%#x" % self.tcp_dst)
458 q.breakable()
459 q.text('}')
460
Rich Laneb658ddd2013-03-12 10:15:10 -0700461class packet_queue(object):
462
Rich Lanec2ee4b82013-04-24 17:12:38 -0700463 def __init__(self, queue_id=None, properties=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700464 if queue_id != None:
465 self.queue_id = queue_id
466 else:
467 self.queue_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700468 if properties != None:
469 self.properties = properties
470 else:
471 self.properties = []
Rich Lanec2ee4b82013-04-24 17:12:38 -0700472 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700473
474 def pack(self):
475 packed = []
476 packed.append(struct.pack("!L", self.queue_id))
477 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700478 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700479 packed.append("".join([x.pack() for x in self.properties]))
480 length = sum([len(x) for x in packed])
481 packed[1] = struct.pack("!H", length)
482 return ''.join(packed)
483
484 @staticmethod
485 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700486 obj = packet_queue()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700487 if type(buf) == loxi.generic_util.OFReader:
488 reader = buf
489 else:
490 reader = loxi.generic_util.OFReader(buf)
491 obj.queue_id = reader.read('!L')[0]
492 _len = reader.read('!H')[0]
493 reader.skip(2)
494 obj.properties = common.unpack_list_queue_prop(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -0700495 return obj
496
497 def __eq__(self, other):
498 if type(self) != type(other): return False
499 if self.queue_id != other.queue_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700500 if self.properties != other.properties: return False
501 return True
502
503 def __ne__(self, other):
504 return not self.__eq__(other)
505
506 def show(self):
507 import loxi.pp
508 return loxi.pp.pp(self)
509
510 def pretty_print(self, q):
511 q.text("packet_queue {")
512 with q.group():
513 with q.indent(2):
514 q.breakable()
515 q.text("queue_id = ");
516 q.text("%#x" % self.queue_id)
517 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700518 q.text("properties = ");
519 q.pp(self.properties)
520 q.breakable()
521 q.text('}')
522
523class port_desc(object):
524
525 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
526 if port_no != None:
527 self.port_no = port_no
528 else:
529 self.port_no = 0
530 if hw_addr != None:
531 self.hw_addr = hw_addr
532 else:
533 self.hw_addr = [0,0,0,0,0,0]
534 if name != None:
535 self.name = name
536 else:
537 self.name = ""
538 if config != None:
539 self.config = config
540 else:
541 self.config = 0
542 if state != None:
543 self.state = state
544 else:
545 self.state = 0
546 if curr != None:
547 self.curr = curr
548 else:
549 self.curr = 0
550 if advertised != None:
551 self.advertised = advertised
552 else:
553 self.advertised = 0
554 if supported != None:
555 self.supported = supported
556 else:
557 self.supported = 0
558 if peer != None:
559 self.peer = peer
560 else:
561 self.peer = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700562 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700563
564 def pack(self):
565 packed = []
566 packed.append(struct.pack("!H", self.port_no))
567 packed.append(struct.pack("!6B", *self.hw_addr))
568 packed.append(struct.pack("!16s", self.name))
569 packed.append(struct.pack("!L", self.config))
570 packed.append(struct.pack("!L", self.state))
571 packed.append(struct.pack("!L", self.curr))
572 packed.append(struct.pack("!L", self.advertised))
573 packed.append(struct.pack("!L", self.supported))
574 packed.append(struct.pack("!L", self.peer))
575 return ''.join(packed)
576
577 @staticmethod
578 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700579 obj = port_desc()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700580 if type(buf) == loxi.generic_util.OFReader:
581 reader = buf
582 else:
583 reader = loxi.generic_util.OFReader(buf)
584 obj.port_no = reader.read('!H')[0]
585 obj.hw_addr = list(reader.read('!6B'))
586 obj.name = reader.read("!16s")[0].rstrip("\x00")
587 obj.config = reader.read('!L')[0]
588 obj.state = reader.read('!L')[0]
589 obj.curr = reader.read('!L')[0]
590 obj.advertised = reader.read('!L')[0]
591 obj.supported = reader.read('!L')[0]
592 obj.peer = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700593 return obj
594
595 def __eq__(self, other):
596 if type(self) != type(other): return False
597 if self.port_no != other.port_no: return False
598 if self.hw_addr != other.hw_addr: return False
599 if self.name != other.name: return False
600 if self.config != other.config: return False
601 if self.state != other.state: return False
602 if self.curr != other.curr: return False
603 if self.advertised != other.advertised: return False
604 if self.supported != other.supported: return False
605 if self.peer != other.peer: return False
606 return True
607
608 def __ne__(self, other):
609 return not self.__eq__(other)
610
611 def show(self):
612 import loxi.pp
613 return loxi.pp.pp(self)
614
615 def pretty_print(self, q):
616 q.text("port_desc {")
617 with q.group():
618 with q.indent(2):
619 q.breakable()
620 q.text("port_no = ");
621 q.text(util.pretty_port(self.port_no))
622 q.text(","); q.breakable()
623 q.text("hw_addr = ");
624 q.text(util.pretty_mac(self.hw_addr))
625 q.text(","); q.breakable()
626 q.text("name = ");
627 q.pp(self.name)
628 q.text(","); q.breakable()
629 q.text("config = ");
630 q.text("%#x" % self.config)
631 q.text(","); q.breakable()
632 q.text("state = ");
633 q.text("%#x" % self.state)
634 q.text(","); q.breakable()
635 q.text("curr = ");
636 q.text("%#x" % self.curr)
637 q.text(","); q.breakable()
638 q.text("advertised = ");
639 q.text("%#x" % self.advertised)
640 q.text(","); q.breakable()
641 q.text("supported = ");
642 q.text("%#x" % self.supported)
643 q.text(","); q.breakable()
644 q.text("peer = ");
645 q.text("%#x" % self.peer)
646 q.breakable()
647 q.text('}')
648
649class port_stats_entry(object):
650
Rich Lanec2ee4b82013-04-24 17:12:38 -0700651 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 -0700652 if port_no != None:
653 self.port_no = port_no
654 else:
655 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700656 if rx_packets != None:
657 self.rx_packets = rx_packets
658 else:
659 self.rx_packets = 0
660 if tx_packets != None:
661 self.tx_packets = tx_packets
662 else:
663 self.tx_packets = 0
664 if rx_bytes != None:
665 self.rx_bytes = rx_bytes
666 else:
667 self.rx_bytes = 0
668 if tx_bytes != None:
669 self.tx_bytes = tx_bytes
670 else:
671 self.tx_bytes = 0
672 if rx_dropped != None:
673 self.rx_dropped = rx_dropped
674 else:
675 self.rx_dropped = 0
676 if tx_dropped != None:
677 self.tx_dropped = tx_dropped
678 else:
679 self.tx_dropped = 0
680 if rx_errors != None:
681 self.rx_errors = rx_errors
682 else:
683 self.rx_errors = 0
684 if tx_errors != None:
685 self.tx_errors = tx_errors
686 else:
687 self.tx_errors = 0
688 if rx_frame_err != None:
689 self.rx_frame_err = rx_frame_err
690 else:
691 self.rx_frame_err = 0
692 if rx_over_err != None:
693 self.rx_over_err = rx_over_err
694 else:
695 self.rx_over_err = 0
696 if rx_crc_err != None:
697 self.rx_crc_err = rx_crc_err
698 else:
699 self.rx_crc_err = 0
700 if collisions != None:
701 self.collisions = collisions
702 else:
703 self.collisions = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700704 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700705
706 def pack(self):
707 packed = []
708 packed.append(struct.pack("!H", self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700709 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700710 packed.append(struct.pack("!Q", self.rx_packets))
711 packed.append(struct.pack("!Q", self.tx_packets))
712 packed.append(struct.pack("!Q", self.rx_bytes))
713 packed.append(struct.pack("!Q", self.tx_bytes))
714 packed.append(struct.pack("!Q", self.rx_dropped))
715 packed.append(struct.pack("!Q", self.tx_dropped))
716 packed.append(struct.pack("!Q", self.rx_errors))
717 packed.append(struct.pack("!Q", self.tx_errors))
718 packed.append(struct.pack("!Q", self.rx_frame_err))
719 packed.append(struct.pack("!Q", self.rx_over_err))
720 packed.append(struct.pack("!Q", self.rx_crc_err))
721 packed.append(struct.pack("!Q", self.collisions))
722 return ''.join(packed)
723
724 @staticmethod
725 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700726 obj = port_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700727 if type(buf) == loxi.generic_util.OFReader:
728 reader = buf
729 else:
730 reader = loxi.generic_util.OFReader(buf)
731 obj.port_no = reader.read('!H')[0]
732 reader.skip(6)
733 obj.rx_packets = reader.read('!Q')[0]
734 obj.tx_packets = reader.read('!Q')[0]
735 obj.rx_bytes = reader.read('!Q')[0]
736 obj.tx_bytes = reader.read('!Q')[0]
737 obj.rx_dropped = reader.read('!Q')[0]
738 obj.tx_dropped = reader.read('!Q')[0]
739 obj.rx_errors = reader.read('!Q')[0]
740 obj.tx_errors = reader.read('!Q')[0]
741 obj.rx_frame_err = reader.read('!Q')[0]
742 obj.rx_over_err = reader.read('!Q')[0]
743 obj.rx_crc_err = reader.read('!Q')[0]
744 obj.collisions = reader.read('!Q')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700745 return obj
746
747 def __eq__(self, other):
748 if type(self) != type(other): return False
749 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700750 if self.rx_packets != other.rx_packets: return False
751 if self.tx_packets != other.tx_packets: return False
752 if self.rx_bytes != other.rx_bytes: return False
753 if self.tx_bytes != other.tx_bytes: return False
754 if self.rx_dropped != other.rx_dropped: return False
755 if self.tx_dropped != other.tx_dropped: return False
756 if self.rx_errors != other.rx_errors: return False
757 if self.tx_errors != other.tx_errors: return False
758 if self.rx_frame_err != other.rx_frame_err: return False
759 if self.rx_over_err != other.rx_over_err: return False
760 if self.rx_crc_err != other.rx_crc_err: return False
761 if self.collisions != other.collisions: return False
762 return True
763
764 def __ne__(self, other):
765 return not self.__eq__(other)
766
767 def show(self):
768 import loxi.pp
769 return loxi.pp.pp(self)
770
771 def pretty_print(self, q):
772 q.text("port_stats_entry {")
773 with q.group():
774 with q.indent(2):
775 q.breakable()
776 q.text("port_no = ");
777 q.text(util.pretty_port(self.port_no))
778 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700779 q.text("rx_packets = ");
780 q.text("%#x" % self.rx_packets)
781 q.text(","); q.breakable()
782 q.text("tx_packets = ");
783 q.text("%#x" % self.tx_packets)
784 q.text(","); q.breakable()
785 q.text("rx_bytes = ");
786 q.text("%#x" % self.rx_bytes)
787 q.text(","); q.breakable()
788 q.text("tx_bytes = ");
789 q.text("%#x" % self.tx_bytes)
790 q.text(","); q.breakable()
791 q.text("rx_dropped = ");
792 q.text("%#x" % self.rx_dropped)
793 q.text(","); q.breakable()
794 q.text("tx_dropped = ");
795 q.text("%#x" % self.tx_dropped)
796 q.text(","); q.breakable()
797 q.text("rx_errors = ");
798 q.text("%#x" % self.rx_errors)
799 q.text(","); q.breakable()
800 q.text("tx_errors = ");
801 q.text("%#x" % self.tx_errors)
802 q.text(","); q.breakable()
803 q.text("rx_frame_err = ");
804 q.text("%#x" % self.rx_frame_err)
805 q.text(","); q.breakable()
806 q.text("rx_over_err = ");
807 q.text("%#x" % self.rx_over_err)
808 q.text(","); q.breakable()
809 q.text("rx_crc_err = ");
810 q.text("%#x" % self.rx_crc_err)
811 q.text(","); q.breakable()
812 q.text("collisions = ");
813 q.text("%#x" % self.collisions)
814 q.breakable()
815 q.text('}')
816
817class queue_prop_min_rate(object):
818 type = const.OFPQT_MIN_RATE
819
Rich Lanec2ee4b82013-04-24 17:12:38 -0700820 def __init__(self, rate=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700821 if rate != None:
822 self.rate = rate
823 else:
824 self.rate = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700825 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700826
827 def pack(self):
828 packed = []
829 packed.append(struct.pack("!H", self.type))
830 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
Rich Lanec2ee4b82013-04-24 17:12:38 -0700831 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -0700832 packed.append(struct.pack("!H", self.rate))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700833 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700834 length = sum([len(x) for x in packed])
835 packed[1] = struct.pack("!H", length)
836 return ''.join(packed)
837
838 @staticmethod
839 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700840 obj = queue_prop_min_rate()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700841 if type(buf) == loxi.generic_util.OFReader:
842 reader = buf
843 else:
844 reader = loxi.generic_util.OFReader(buf)
845 _type = reader.read('!H')[0]
846 assert(_type == const.OFPQT_MIN_RATE)
847 _len = reader.read('!H')[0]
848 reader.skip(4)
849 obj.rate = reader.read('!H')[0]
850 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -0700851 return obj
852
853 def __eq__(self, other):
854 if type(self) != type(other): return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700855 if self.rate != other.rate: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700856 return True
857
858 def __ne__(self, other):
859 return not self.__eq__(other)
860
861 def show(self):
862 import loxi.pp
863 return loxi.pp.pp(self)
864
865 def pretty_print(self, q):
866 q.text("queue_prop_min_rate {")
867 with q.group():
868 with q.indent(2):
869 q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700870 q.text("rate = ");
871 q.text("%#x" % self.rate)
Rich Laneb658ddd2013-03-12 10:15:10 -0700872 q.breakable()
873 q.text('}')
874
875class queue_stats_entry(object):
876
Rich Lanec2ee4b82013-04-24 17:12:38 -0700877 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 -0700878 if port_no != None:
879 self.port_no = port_no
880 else:
881 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700882 if queue_id != None:
883 self.queue_id = queue_id
884 else:
885 self.queue_id = 0
886 if tx_bytes != None:
887 self.tx_bytes = tx_bytes
888 else:
889 self.tx_bytes = 0
890 if tx_packets != None:
891 self.tx_packets = tx_packets
892 else:
893 self.tx_packets = 0
894 if tx_errors != None:
895 self.tx_errors = tx_errors
896 else:
897 self.tx_errors = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700898 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700899
900 def pack(self):
901 packed = []
902 packed.append(struct.pack("!H", self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700903 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -0700904 packed.append(struct.pack("!L", self.queue_id))
905 packed.append(struct.pack("!Q", self.tx_bytes))
906 packed.append(struct.pack("!Q", self.tx_packets))
907 packed.append(struct.pack("!Q", self.tx_errors))
908 return ''.join(packed)
909
910 @staticmethod
911 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -0700912 obj = queue_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700913 if type(buf) == loxi.generic_util.OFReader:
914 reader = buf
915 else:
916 reader = loxi.generic_util.OFReader(buf)
917 obj.port_no = reader.read('!H')[0]
918 reader.skip(2)
919 obj.queue_id = reader.read('!L')[0]
920 obj.tx_bytes = reader.read('!Q')[0]
921 obj.tx_packets = reader.read('!Q')[0]
922 obj.tx_errors = reader.read('!Q')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700923 return obj
924
925 def __eq__(self, other):
926 if type(self) != type(other): return False
927 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700928 if self.queue_id != other.queue_id: return False
929 if self.tx_bytes != other.tx_bytes: return False
930 if self.tx_packets != other.tx_packets: return False
931 if self.tx_errors != other.tx_errors: return False
932 return True
933
934 def __ne__(self, other):
935 return not self.__eq__(other)
936
937 def show(self):
938 import loxi.pp
939 return loxi.pp.pp(self)
940
941 def pretty_print(self, q):
942 q.text("queue_stats_entry {")
943 with q.group():
944 with q.indent(2):
945 q.breakable()
946 q.text("port_no = ");
947 q.text(util.pretty_port(self.port_no))
948 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700949 q.text("queue_id = ");
950 q.text("%#x" % self.queue_id)
951 q.text(","); q.breakable()
952 q.text("tx_bytes = ");
953 q.text("%#x" % self.tx_bytes)
954 q.text(","); q.breakable()
955 q.text("tx_packets = ");
956 q.text("%#x" % self.tx_packets)
957 q.text(","); q.breakable()
958 q.text("tx_errors = ");
959 q.text("%#x" % self.tx_errors)
960 q.breakable()
961 q.text('}')
962
963class table_stats_entry(object):
964
Rich Lanec2ee4b82013-04-24 17:12:38 -0700965 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 -0700966 if table_id != None:
967 self.table_id = table_id
968 else:
969 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700970 if name != None:
971 self.name = name
972 else:
973 self.name = ""
974 if wildcards != None:
975 self.wildcards = wildcards
976 else:
977 self.wildcards = const.OFPFW_ALL
978 if max_entries != None:
979 self.max_entries = max_entries
980 else:
981 self.max_entries = 0
982 if active_count != None:
983 self.active_count = active_count
984 else:
985 self.active_count = 0
986 if lookup_count != None:
987 self.lookup_count = lookup_count
988 else:
989 self.lookup_count = 0
990 if matched_count != None:
991 self.matched_count = matched_count
992 else:
993 self.matched_count = 0
Rich Lanec2ee4b82013-04-24 17:12:38 -0700994 return
Rich Laneb658ddd2013-03-12 10:15:10 -0700995
996 def pack(self):
997 packed = []
998 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700999 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001000 packed.append(struct.pack("!32s", self.name))
1001 packed.append(struct.pack("!L", self.wildcards))
1002 packed.append(struct.pack("!L", self.max_entries))
1003 packed.append(struct.pack("!L", self.active_count))
1004 packed.append(struct.pack("!Q", self.lookup_count))
1005 packed.append(struct.pack("!Q", self.matched_count))
1006 return ''.join(packed)
1007
1008 @staticmethod
1009 def unpack(buf):
Rich Laneb658ddd2013-03-12 10:15:10 -07001010 obj = table_stats_entry()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001011 if type(buf) == loxi.generic_util.OFReader:
1012 reader = buf
1013 else:
1014 reader = loxi.generic_util.OFReader(buf)
1015 obj.table_id = reader.read('!B')[0]
1016 reader.skip(3)
1017 obj.name = reader.read("!32s")[0].rstrip("\x00")
1018 obj.wildcards = reader.read('!L')[0]
1019 obj.max_entries = reader.read('!L')[0]
1020 obj.active_count = reader.read('!L')[0]
1021 obj.lookup_count = reader.read('!Q')[0]
1022 obj.matched_count = reader.read('!Q')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001023 return obj
1024
1025 def __eq__(self, other):
1026 if type(self) != type(other): return False
1027 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001028 if self.name != other.name: return False
1029 if self.wildcards != other.wildcards: return False
1030 if self.max_entries != other.max_entries: return False
1031 if self.active_count != other.active_count: return False
1032 if self.lookup_count != other.lookup_count: return False
1033 if self.matched_count != other.matched_count: return False
1034 return True
1035
1036 def __ne__(self, other):
1037 return not self.__eq__(other)
1038
1039 def show(self):
1040 import loxi.pp
1041 return loxi.pp.pp(self)
1042
1043 def pretty_print(self, q):
1044 q.text("table_stats_entry {")
1045 with q.group():
1046 with q.indent(2):
1047 q.breakable()
1048 q.text("table_id = ");
1049 q.text("%#x" % self.table_id)
1050 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001051 q.text("name = ");
1052 q.pp(self.name)
1053 q.text(","); q.breakable()
1054 q.text("wildcards = ");
1055 q.text(util.pretty_wildcards(self.wildcards))
1056 q.text(","); q.breakable()
1057 q.text("max_entries = ");
1058 q.text("%#x" % self.max_entries)
1059 q.text(","); q.breakable()
1060 q.text("active_count = ");
1061 q.text("%#x" % self.active_count)
1062 q.text(","); q.breakable()
1063 q.text("lookup_count = ");
1064 q.text("%#x" % self.lookup_count)
1065 q.text(","); q.breakable()
1066 q.text("matched_count = ");
1067 q.text("%#x" % self.matched_count)
1068 q.breakable()
1069 q.text('}')
1070
Rich Lanec2ee4b82013-04-24 17:12:38 -07001071
1072match = match_v1