blob: 98eb15804a7b158248c70be99e8a4e900432fcd1 [file] [log] [blame]
Nathan Knuth418fdc82016-09-16 22:51:15 -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.
4# See the file LICENSE.pyloxi which should have been included in the source distribution
5
6# Automatically generated by LOXI from template module.py
7# Do not modify
8
9import struct
10import loxi
11import util
12import loxi.generic_util
13
14import sys
15ofp = sys.modules['loxi.of10']
16
17class bsn_interface(loxi.OFObject):
18
19 def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
20 if hw_addr != None:
21 self.hw_addr = hw_addr
22 else:
23 self.hw_addr = [0,0,0,0,0,0]
24 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
36 return
37
38 def pack(self):
39 packed = []
40 packed.append(struct.pack("!6B", *self.hw_addr))
41 packed.append('\x00' * 2)
42 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
48 def unpack(reader):
49 obj = bsn_interface()
50 obj.hw_addr = list(reader.read('!6B'))
51 reader.skip(2)
52 obj.name = reader.read("!16s")[0].rstrip("\x00")
53 obj.ipv4_addr = reader.read("!L")[0]
54 obj.ipv4_netmask = reader.read("!L")[0]
55 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
60 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
65 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()
73 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
84
85class bsn_vport(loxi.OFObject):
86 subtypes = {}
87
88
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
104 @staticmethod
105 def unpack(reader):
106 subtype, = reader.peek('!H', 0)
107 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, 4)
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('}')
130
131
132class bsn_vport_l2gre(bsn_vport):
133 type = 1
134
135 def __init__(self, flags=None, port_no=None, loopback_port_no=None, local_mac=None, nh_mac=None, src_ip=None, dst_ip=None, dscp=None, ttl=None, vpn=None, rate_limit=None, if_name=None):
136 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
144 if loopback_port_no != None:
145 self.loopback_port_no = loopback_port_no
146 else:
147 self.loopback_port_no = 0
148 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 rate_limit != None:
177 self.rate_limit = rate_limit
178 else:
179 self.rate_limit = 0
180 if if_name != None:
181 self.if_name = if_name
182 else:
183 self.if_name = ""
184 return
185
186 def pack(self):
187 packed = []
188 packed.append(struct.pack("!H", self.type))
189 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
190 packed.append(struct.pack("!L", self.flags))
191 packed.append(util.pack_port_no(self.port_no))
192 packed.append(util.pack_port_no(self.loopback_port_no))
193 packed.append(struct.pack("!6B", *self.local_mac))
194 packed.append(struct.pack("!6B", *self.nh_mac))
195 packed.append(struct.pack("!L", self.src_ip))
196 packed.append(struct.pack("!L", self.dst_ip))
197 packed.append(struct.pack("!B", self.dscp))
198 packed.append(struct.pack("!B", self.ttl))
199 packed.append('\x00' * 2)
200 packed.append(struct.pack("!L", self.vpn))
201 packed.append(struct.pack("!L", self.rate_limit))
202 packed.append(struct.pack("!16s", self.if_name))
203 length = sum([len(x) for x in packed])
204 packed[1] = struct.pack("!H", length)
205 return ''.join(packed)
206
207 @staticmethod
208 def unpack(reader):
209 obj = bsn_vport_l2gre()
210 _type = reader.read("!H")[0]
211 assert(_type == 1)
212 _length = reader.read("!H")[0]
213 orig_reader = reader
214 reader = orig_reader.slice(_length, 4)
215 obj.flags = reader.read("!L")[0]
216 obj.port_no = util.unpack_port_no(reader)
217 obj.loopback_port_no = util.unpack_port_no(reader)
218 obj.local_mac = list(reader.read('!6B'))
219 obj.nh_mac = list(reader.read('!6B'))
220 obj.src_ip = reader.read("!L")[0]
221 obj.dst_ip = reader.read("!L")[0]
222 obj.dscp = reader.read("!B")[0]
223 obj.ttl = reader.read("!B")[0]
224 reader.skip(2)
225 obj.vpn = reader.read("!L")[0]
226 obj.rate_limit = reader.read("!L")[0]
227 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
228 return obj
229
230 def __eq__(self, other):
231 if type(self) != type(other): return False
232 if self.flags != other.flags: return False
233 if self.port_no != other.port_no: return False
234 if self.loopback_port_no != other.loopback_port_no: return False
235 if self.local_mac != other.local_mac: return False
236 if self.nh_mac != other.nh_mac: return False
237 if self.src_ip != other.src_ip: return False
238 if self.dst_ip != other.dst_ip: return False
239 if self.dscp != other.dscp: return False
240 if self.ttl != other.ttl: return False
241 if self.vpn != other.vpn: return False
242 if self.rate_limit != other.rate_limit: return False
243 if self.if_name != other.if_name: return False
244 return True
245
246 def pretty_print(self, q):
247 q.text("bsn_vport_l2gre {")
248 with q.group():
249 with q.indent(2):
250 q.breakable()
251 q.text("flags = ");
252 q.text("%#x" % self.flags)
253 q.text(","); q.breakable()
254 q.text("port_no = ");
255 q.text(util.pretty_port(self.port_no))
256 q.text(","); q.breakable()
257 q.text("loopback_port_no = ");
258 q.text(util.pretty_port(self.loopback_port_no))
259 q.text(","); q.breakable()
260 q.text("local_mac = ");
261 q.text(util.pretty_mac(self.local_mac))
262 q.text(","); q.breakable()
263 q.text("nh_mac = ");
264 q.text(util.pretty_mac(self.nh_mac))
265 q.text(","); q.breakable()
266 q.text("src_ip = ");
267 q.text(util.pretty_ipv4(self.src_ip))
268 q.text(","); q.breakable()
269 q.text("dst_ip = ");
270 q.text(util.pretty_ipv4(self.dst_ip))
271 q.text(","); q.breakable()
272 q.text("dscp = ");
273 q.text("%#x" % self.dscp)
274 q.text(","); q.breakable()
275 q.text("ttl = ");
276 q.text("%#x" % self.ttl)
277 q.text(","); q.breakable()
278 q.text("vpn = ");
279 q.text("%#x" % self.vpn)
280 q.text(","); q.breakable()
281 q.text("rate_limit = ");
282 q.text("%#x" % self.rate_limit)
283 q.text(","); q.breakable()
284 q.text("if_name = ");
285 q.pp(self.if_name)
286 q.breakable()
287 q.text('}')
288
289bsn_vport.subtypes[1] = bsn_vport_l2gre
290
291class bsn_vport_q_in_q(bsn_vport):
292 type = 0
293
294 def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None, if_name=None):
295 if port_no != None:
296 self.port_no = port_no
297 else:
298 self.port_no = 0
299 if ingress_tpid != None:
300 self.ingress_tpid = ingress_tpid
301 else:
302 self.ingress_tpid = 0
303 if ingress_vlan_id != None:
304 self.ingress_vlan_id = ingress_vlan_id
305 else:
306 self.ingress_vlan_id = 0
307 if egress_tpid != None:
308 self.egress_tpid = egress_tpid
309 else:
310 self.egress_tpid = 0
311 if egress_vlan_id != None:
312 self.egress_vlan_id = egress_vlan_id
313 else:
314 self.egress_vlan_id = 0
315 if if_name != None:
316 self.if_name = if_name
317 else:
318 self.if_name = ""
319 return
320
321 def pack(self):
322 packed = []
323 packed.append(struct.pack("!H", self.type))
324 packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
325 packed.append(struct.pack("!L", self.port_no))
326 packed.append(struct.pack("!H", self.ingress_tpid))
327 packed.append(struct.pack("!H", self.ingress_vlan_id))
328 packed.append(struct.pack("!H", self.egress_tpid))
329 packed.append(struct.pack("!H", self.egress_vlan_id))
330 packed.append(struct.pack("!16s", self.if_name))
331 length = sum([len(x) for x in packed])
332 packed[1] = struct.pack("!H", length)
333 return ''.join(packed)
334
335 @staticmethod
336 def unpack(reader):
337 obj = bsn_vport_q_in_q()
338 _type = reader.read("!H")[0]
339 assert(_type == 0)
340 _length = reader.read("!H")[0]
341 orig_reader = reader
342 reader = orig_reader.slice(_length, 4)
343 obj.port_no = reader.read("!L")[0]
344 obj.ingress_tpid = reader.read("!H")[0]
345 obj.ingress_vlan_id = reader.read("!H")[0]
346 obj.egress_tpid = reader.read("!H")[0]
347 obj.egress_vlan_id = reader.read("!H")[0]
348 obj.if_name = reader.read("!16s")[0].rstrip("\x00")
349 return obj
350
351 def __eq__(self, other):
352 if type(self) != type(other): return False
353 if self.port_no != other.port_no: return False
354 if self.ingress_tpid != other.ingress_tpid: return False
355 if self.ingress_vlan_id != other.ingress_vlan_id: return False
356 if self.egress_tpid != other.egress_tpid: return False
357 if self.egress_vlan_id != other.egress_vlan_id: return False
358 if self.if_name != other.if_name: return False
359 return True
360
361 def pretty_print(self, q):
362 q.text("bsn_vport_q_in_q {")
363 with q.group():
364 with q.indent(2):
365 q.breakable()
366 q.text("port_no = ");
367 q.text("%#x" % self.port_no)
368 q.text(","); q.breakable()
369 q.text("ingress_tpid = ");
370 q.text("%#x" % self.ingress_tpid)
371 q.text(","); q.breakable()
372 q.text("ingress_vlan_id = ");
373 q.text("%#x" % self.ingress_vlan_id)
374 q.text(","); q.breakable()
375 q.text("egress_tpid = ");
376 q.text("%#x" % self.egress_tpid)
377 q.text(","); q.breakable()
378 q.text("egress_vlan_id = ");
379 q.text("%#x" % self.egress_vlan_id)
380 q.text(","); q.breakable()
381 q.text("if_name = ");
382 q.pp(self.if_name)
383 q.breakable()
384 q.text('}')
385
386bsn_vport.subtypes[0] = bsn_vport_q_in_q
387
388class flow_stats_entry(loxi.OFObject):
389
390 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):
391 if table_id != None:
392 self.table_id = table_id
393 else:
394 self.table_id = 0
395 if match != None:
396 self.match = match
397 else:
398 self.match = ofp.match()
399 if duration_sec != None:
400 self.duration_sec = duration_sec
401 else:
402 self.duration_sec = 0
403 if duration_nsec != None:
404 self.duration_nsec = duration_nsec
405 else:
406 self.duration_nsec = 0
407 if priority != None:
408 self.priority = priority
409 else:
410 self.priority = 0
411 if idle_timeout != None:
412 self.idle_timeout = idle_timeout
413 else:
414 self.idle_timeout = 0
415 if hard_timeout != None:
416 self.hard_timeout = hard_timeout
417 else:
418 self.hard_timeout = 0
419 if cookie != None:
420 self.cookie = cookie
421 else:
422 self.cookie = 0
423 if packet_count != None:
424 self.packet_count = packet_count
425 else:
426 self.packet_count = 0
427 if byte_count != None:
428 self.byte_count = byte_count
429 else:
430 self.byte_count = 0
431 if actions != None:
432 self.actions = actions
433 else:
434 self.actions = []
435 return
436
437 def pack(self):
438 packed = []
439 packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
440 packed.append(struct.pack("!B", self.table_id))
441 packed.append('\x00' * 1)
442 packed.append(self.match.pack())
443 packed.append(struct.pack("!L", self.duration_sec))
444 packed.append(struct.pack("!L", self.duration_nsec))
445 packed.append(struct.pack("!H", self.priority))
446 packed.append(struct.pack("!H", self.idle_timeout))
447 packed.append(struct.pack("!H", self.hard_timeout))
448 packed.append('\x00' * 6)
449 packed.append(struct.pack("!Q", self.cookie))
450 packed.append(struct.pack("!Q", self.packet_count))
451 packed.append(struct.pack("!Q", self.byte_count))
452 packed.append(loxi.generic_util.pack_list(self.actions))
453 length = sum([len(x) for x in packed])
454 packed[0] = struct.pack("!H", length)
455 return ''.join(packed)
456
457 @staticmethod
458 def unpack(reader):
459 obj = flow_stats_entry()
460 _length = reader.read("!H")[0]
461 orig_reader = reader
462 reader = orig_reader.slice(_length, 2)
463 obj.table_id = reader.read("!B")[0]
464 reader.skip(1)
465 obj.match = ofp.match.unpack(reader)
466 obj.duration_sec = reader.read("!L")[0]
467 obj.duration_nsec = reader.read("!L")[0]
468 obj.priority = reader.read("!H")[0]
469 obj.idle_timeout = reader.read("!H")[0]
470 obj.hard_timeout = reader.read("!H")[0]
471 reader.skip(6)
472 obj.cookie = reader.read("!Q")[0]
473 obj.packet_count = reader.read("!Q")[0]
474 obj.byte_count = reader.read("!Q")[0]
475 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
476 return obj
477
478 def __eq__(self, other):
479 if type(self) != type(other): return False
480 if self.table_id != other.table_id: return False
481 if self.match != other.match: return False
482 if self.duration_sec != other.duration_sec: return False
483 if self.duration_nsec != other.duration_nsec: return False
484 if self.priority != other.priority: return False
485 if self.idle_timeout != other.idle_timeout: return False
486 if self.hard_timeout != other.hard_timeout: return False
487 if self.cookie != other.cookie: return False
488 if self.packet_count != other.packet_count: return False
489 if self.byte_count != other.byte_count: return False
490 if self.actions != other.actions: return False
491 return True
492
493 def pretty_print(self, q):
494 q.text("flow_stats_entry {")
495 with q.group():
496 with q.indent(2):
497 q.breakable()
498 q.text("table_id = ");
499 q.text("%#x" % self.table_id)
500 q.text(","); q.breakable()
501 q.text("match = ");
502 q.pp(self.match)
503 q.text(","); q.breakable()
504 q.text("duration_sec = ");
505 q.text("%#x" % self.duration_sec)
506 q.text(","); q.breakable()
507 q.text("duration_nsec = ");
508 q.text("%#x" % self.duration_nsec)
509 q.text(","); q.breakable()
510 q.text("priority = ");
511 q.text("%#x" % self.priority)
512 q.text(","); q.breakable()
513 q.text("idle_timeout = ");
514 q.text("%#x" % self.idle_timeout)
515 q.text(","); q.breakable()
516 q.text("hard_timeout = ");
517 q.text("%#x" % self.hard_timeout)
518 q.text(","); q.breakable()
519 q.text("cookie = ");
520 q.text("%#x" % self.cookie)
521 q.text(","); q.breakable()
522 q.text("packet_count = ");
523 q.text("%#x" % self.packet_count)
524 q.text(","); q.breakable()
525 q.text("byte_count = ");
526 q.text("%#x" % self.byte_count)
527 q.text(","); q.breakable()
528 q.text("actions = ");
529 q.pp(self.actions)
530 q.breakable()
531 q.text('}')
532
533
534class match_v1(loxi.OFObject):
535
536 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):
537 if wildcards != None:
538 self.wildcards = wildcards
539 else:
540 self.wildcards = util.init_wc_bmap()
541 if in_port != None:
542 self.in_port = in_port
543 else:
544 self.in_port = 0
545 if eth_src != None:
546 self.eth_src = eth_src
547 else:
548 self.eth_src = [0,0,0,0,0,0]
549 if eth_dst != None:
550 self.eth_dst = eth_dst
551 else:
552 self.eth_dst = [0,0,0,0,0,0]
553 if vlan_vid != None:
554 self.vlan_vid = vlan_vid
555 else:
556 self.vlan_vid = 0
557 if vlan_pcp != None:
558 self.vlan_pcp = vlan_pcp
559 else:
560 self.vlan_pcp = 0
561 if eth_type != None:
562 self.eth_type = eth_type
563 else:
564 self.eth_type = 0
565 if ip_dscp != None:
566 self.ip_dscp = ip_dscp
567 else:
568 self.ip_dscp = 0
569 if ip_proto != None:
570 self.ip_proto = ip_proto
571 else:
572 self.ip_proto = 0
573 if ipv4_src != None:
574 self.ipv4_src = ipv4_src
575 else:
576 self.ipv4_src = 0
577 if ipv4_dst != None:
578 self.ipv4_dst = ipv4_dst
579 else:
580 self.ipv4_dst = 0
581 if tcp_src != None:
582 self.tcp_src = tcp_src
583 else:
584 self.tcp_src = 0
585 if tcp_dst != None:
586 self.tcp_dst = tcp_dst
587 else:
588 self.tcp_dst = 0
589 return
590
591 def pack(self):
592 packed = []
593 packed.append(util.pack_wc_bmap(self.wildcards))
594 packed.append(util.pack_port_no(self.in_port))
595 packed.append(struct.pack("!6B", *self.eth_src))
596 packed.append(struct.pack("!6B", *self.eth_dst))
597 packed.append(struct.pack("!H", self.vlan_vid))
598 packed.append(struct.pack("!B", self.vlan_pcp))
599 packed.append('\x00' * 1)
600 packed.append(struct.pack("!H", self.eth_type))
601 packed.append(struct.pack("!B", self.ip_dscp))
602 packed.append(struct.pack("!B", self.ip_proto))
603 packed.append('\x00' * 2)
604 packed.append(struct.pack("!L", self.ipv4_src))
605 packed.append(struct.pack("!L", self.ipv4_dst))
606 packed.append(struct.pack("!H", self.tcp_src))
607 packed.append(struct.pack("!H", self.tcp_dst))
608 return ''.join(packed)
609
610 @staticmethod
611 def unpack(reader):
612 obj = match_v1()
613 obj.wildcards = util.unpack_wc_bmap(reader)
614 obj.in_port = util.unpack_port_no(reader)
615 obj.eth_src = list(reader.read('!6B'))
616 obj.eth_dst = list(reader.read('!6B'))
617 obj.vlan_vid = reader.read("!H")[0]
618 obj.vlan_pcp = reader.read("!B")[0]
619 reader.skip(1)
620 obj.eth_type = reader.read("!H")[0]
621 obj.ip_dscp = reader.read("!B")[0]
622 obj.ip_proto = reader.read("!B")[0]
623 reader.skip(2)
624 obj.ipv4_src = reader.read("!L")[0]
625 obj.ipv4_dst = reader.read("!L")[0]
626 obj.tcp_src = reader.read("!H")[0]
627 obj.tcp_dst = reader.read("!H")[0]
628 return obj
629
630 def __eq__(self, other):
631 if type(self) != type(other): return False
632 if self.wildcards != other.wildcards: return False
633 if self.in_port != other.in_port: return False
634 if self.eth_src != other.eth_src: return False
635 if self.eth_dst != other.eth_dst: return False
636 if self.vlan_vid != other.vlan_vid: return False
637 if self.vlan_pcp != other.vlan_pcp: return False
638 if self.eth_type != other.eth_type: return False
639 if self.ip_dscp != other.ip_dscp: return False
640 if self.ip_proto != other.ip_proto: return False
641 if self.ipv4_src != other.ipv4_src: return False
642 if self.ipv4_dst != other.ipv4_dst: return False
643 if self.tcp_src != other.tcp_src: return False
644 if self.tcp_dst != other.tcp_dst: return False
645 return True
646
647 def pretty_print(self, q):
648 q.text("match_v1 {")
649 with q.group():
650 with q.indent(2):
651 q.breakable()
652 q.text("wildcards = ");
653 q.text(util.pretty_wildcards(self.wildcards))
654 q.text(","); q.breakable()
655 q.text("in_port = ");
656 q.text(util.pretty_port(self.in_port))
657 q.text(","); q.breakable()
658 q.text("eth_src = ");
659 q.text(util.pretty_mac(self.eth_src))
660 q.text(","); q.breakable()
661 q.text("eth_dst = ");
662 q.text(util.pretty_mac(self.eth_dst))
663 q.text(","); q.breakable()
664 q.text("vlan_vid = ");
665 q.text("%#x" % self.vlan_vid)
666 q.text(","); q.breakable()
667 q.text("vlan_pcp = ");
668 q.text("%#x" % self.vlan_pcp)
669 q.text(","); q.breakable()
670 q.text("eth_type = ");
671 q.text("%#x" % self.eth_type)
672 q.text(","); q.breakable()
673 q.text("ip_dscp = ");
674 q.text("%#x" % self.ip_dscp)
675 q.text(","); q.breakable()
676 q.text("ip_proto = ");
677 q.text("%#x" % self.ip_proto)
678 q.text(","); q.breakable()
679 q.text("ipv4_src = ");
680 q.text(util.pretty_ipv4(self.ipv4_src))
681 q.text(","); q.breakable()
682 q.text("ipv4_dst = ");
683 q.text(util.pretty_ipv4(self.ipv4_dst))
684 q.text(","); q.breakable()
685 q.text("tcp_src = ");
686 q.text("%#x" % self.tcp_src)
687 q.text(","); q.breakable()
688 q.text("tcp_dst = ");
689 q.text("%#x" % self.tcp_dst)
690 q.breakable()
691 q.text('}')
692
693
694class packet_queue(loxi.OFObject):
695
696 def __init__(self, queue_id=None, properties=None):
697 if queue_id != None:
698 self.queue_id = queue_id
699 else:
700 self.queue_id = 0
701 if properties != None:
702 self.properties = properties
703 else:
704 self.properties = []
705 return
706
707 def pack(self):
708 packed = []
709 packed.append(struct.pack("!L", self.queue_id))
710 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
711 packed.append('\x00' * 2)
712 packed.append(loxi.generic_util.pack_list(self.properties))
713 length = sum([len(x) for x in packed])
714 packed[1] = struct.pack("!H", length)
715 return ''.join(packed)
716
717 @staticmethod
718 def unpack(reader):
719 obj = packet_queue()
720 obj.queue_id = reader.read("!L")[0]
721 _len = reader.read("!H")[0]
722 orig_reader = reader
723 reader = orig_reader.slice(_len, 6)
724 reader.skip(2)
725 obj.properties = loxi.generic_util.unpack_list(reader, ofp.common.queue_prop.unpack)
726 return obj
727
728 def __eq__(self, other):
729 if type(self) != type(other): return False
730 if self.queue_id != other.queue_id: return False
731 if self.properties != other.properties: return False
732 return True
733
734 def pretty_print(self, q):
735 q.text("packet_queue {")
736 with q.group():
737 with q.indent(2):
738 q.breakable()
739 q.text("queue_id = ");
740 q.text("%#x" % self.queue_id)
741 q.text(","); q.breakable()
742 q.text("properties = ");
743 q.pp(self.properties)
744 q.breakable()
745 q.text('}')
746
747
748class port_desc(loxi.OFObject):
749
750 def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
751 if port_no != None:
752 self.port_no = port_no
753 else:
754 self.port_no = 0
755 if hw_addr != None:
756 self.hw_addr = hw_addr
757 else:
758 self.hw_addr = [0,0,0,0,0,0]
759 if name != None:
760 self.name = name
761 else:
762 self.name = ""
763 if config != None:
764 self.config = config
765 else:
766 self.config = 0
767 if state != None:
768 self.state = state
769 else:
770 self.state = 0
771 if curr != None:
772 self.curr = curr
773 else:
774 self.curr = 0
775 if advertised != None:
776 self.advertised = advertised
777 else:
778 self.advertised = 0
779 if supported != None:
780 self.supported = supported
781 else:
782 self.supported = 0
783 if peer != None:
784 self.peer = peer
785 else:
786 self.peer = 0
787 return
788
789 def pack(self):
790 packed = []
791 packed.append(util.pack_port_no(self.port_no))
792 packed.append(struct.pack("!6B", *self.hw_addr))
793 packed.append(struct.pack("!16s", self.name))
794 packed.append(struct.pack("!L", self.config))
795 packed.append(struct.pack("!L", self.state))
796 packed.append(struct.pack("!L", self.curr))
797 packed.append(struct.pack("!L", self.advertised))
798 packed.append(struct.pack("!L", self.supported))
799 packed.append(struct.pack("!L", self.peer))
800 return ''.join(packed)
801
802 @staticmethod
803 def unpack(reader):
804 obj = port_desc()
805 obj.port_no = util.unpack_port_no(reader)
806 obj.hw_addr = list(reader.read('!6B'))
807 obj.name = reader.read("!16s")[0].rstrip("\x00")
808 obj.config = reader.read("!L")[0]
809 obj.state = reader.read("!L")[0]
810 obj.curr = reader.read("!L")[0]
811 obj.advertised = reader.read("!L")[0]
812 obj.supported = reader.read("!L")[0]
813 obj.peer = reader.read("!L")[0]
814 return obj
815
816 def __eq__(self, other):
817 if type(self) != type(other): return False
818 if self.port_no != other.port_no: return False
819 if self.hw_addr != other.hw_addr: return False
820 if self.name != other.name: return False
821 if self.config != other.config: return False
822 if self.state != other.state: return False
823 if self.curr != other.curr: return False
824 if self.advertised != other.advertised: return False
825 if self.supported != other.supported: return False
826 if self.peer != other.peer: return False
827 return True
828
829 def pretty_print(self, q):
830 q.text("port_desc {")
831 with q.group():
832 with q.indent(2):
833 q.breakable()
834 q.text("port_no = ");
835 q.text(util.pretty_port(self.port_no))
836 q.text(","); q.breakable()
837 q.text("hw_addr = ");
838 q.text(util.pretty_mac(self.hw_addr))
839 q.text(","); q.breakable()
840 q.text("name = ");
841 q.pp(self.name)
842 q.text(","); q.breakable()
843 q.text("config = ");
844 q.text("%#x" % self.config)
845 q.text(","); q.breakable()
846 q.text("state = ");
847 q.text("%#x" % self.state)
848 q.text(","); q.breakable()
849 q.text("curr = ");
850 q.text("%#x" % self.curr)
851 q.text(","); q.breakable()
852 q.text("advertised = ");
853 q.text("%#x" % self.advertised)
854 q.text(","); q.breakable()
855 q.text("supported = ");
856 q.text("%#x" % self.supported)
857 q.text(","); q.breakable()
858 q.text("peer = ");
859 q.text("%#x" % self.peer)
860 q.breakable()
861 q.text('}')
862
863
864class port_stats_entry(loxi.OFObject):
865
866 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):
867 if port_no != None:
868 self.port_no = port_no
869 else:
870 self.port_no = 0
871 if rx_packets != None:
872 self.rx_packets = rx_packets
873 else:
874 self.rx_packets = 0
875 if tx_packets != None:
876 self.tx_packets = tx_packets
877 else:
878 self.tx_packets = 0
879 if rx_bytes != None:
880 self.rx_bytes = rx_bytes
881 else:
882 self.rx_bytes = 0
883 if tx_bytes != None:
884 self.tx_bytes = tx_bytes
885 else:
886 self.tx_bytes = 0
887 if rx_dropped != None:
888 self.rx_dropped = rx_dropped
889 else:
890 self.rx_dropped = 0
891 if tx_dropped != None:
892 self.tx_dropped = tx_dropped
893 else:
894 self.tx_dropped = 0
895 if rx_errors != None:
896 self.rx_errors = rx_errors
897 else:
898 self.rx_errors = 0
899 if tx_errors != None:
900 self.tx_errors = tx_errors
901 else:
902 self.tx_errors = 0
903 if rx_frame_err != None:
904 self.rx_frame_err = rx_frame_err
905 else:
906 self.rx_frame_err = 0
907 if rx_over_err != None:
908 self.rx_over_err = rx_over_err
909 else:
910 self.rx_over_err = 0
911 if rx_crc_err != None:
912 self.rx_crc_err = rx_crc_err
913 else:
914 self.rx_crc_err = 0
915 if collisions != None:
916 self.collisions = collisions
917 else:
918 self.collisions = 0
919 return
920
921 def pack(self):
922 packed = []
923 packed.append(util.pack_port_no(self.port_no))
924 packed.append('\x00' * 6)
925 packed.append(struct.pack("!Q", self.rx_packets))
926 packed.append(struct.pack("!Q", self.tx_packets))
927 packed.append(struct.pack("!Q", self.rx_bytes))
928 packed.append(struct.pack("!Q", self.tx_bytes))
929 packed.append(struct.pack("!Q", self.rx_dropped))
930 packed.append(struct.pack("!Q", self.tx_dropped))
931 packed.append(struct.pack("!Q", self.rx_errors))
932 packed.append(struct.pack("!Q", self.tx_errors))
933 packed.append(struct.pack("!Q", self.rx_frame_err))
934 packed.append(struct.pack("!Q", self.rx_over_err))
935 packed.append(struct.pack("!Q", self.rx_crc_err))
936 packed.append(struct.pack("!Q", self.collisions))
937 return ''.join(packed)
938
939 @staticmethod
940 def unpack(reader):
941 obj = port_stats_entry()
942 obj.port_no = util.unpack_port_no(reader)
943 reader.skip(6)
944 obj.rx_packets = reader.read("!Q")[0]
945 obj.tx_packets = reader.read("!Q")[0]
946 obj.rx_bytes = reader.read("!Q")[0]
947 obj.tx_bytes = reader.read("!Q")[0]
948 obj.rx_dropped = reader.read("!Q")[0]
949 obj.tx_dropped = reader.read("!Q")[0]
950 obj.rx_errors = reader.read("!Q")[0]
951 obj.tx_errors = reader.read("!Q")[0]
952 obj.rx_frame_err = reader.read("!Q")[0]
953 obj.rx_over_err = reader.read("!Q")[0]
954 obj.rx_crc_err = reader.read("!Q")[0]
955 obj.collisions = reader.read("!Q")[0]
956 return obj
957
958 def __eq__(self, other):
959 if type(self) != type(other): return False
960 if self.port_no != other.port_no: return False
961 if self.rx_packets != other.rx_packets: return False
962 if self.tx_packets != other.tx_packets: return False
963 if self.rx_bytes != other.rx_bytes: return False
964 if self.tx_bytes != other.tx_bytes: return False
965 if self.rx_dropped != other.rx_dropped: return False
966 if self.tx_dropped != other.tx_dropped: return False
967 if self.rx_errors != other.rx_errors: return False
968 if self.tx_errors != other.tx_errors: return False
969 if self.rx_frame_err != other.rx_frame_err: return False
970 if self.rx_over_err != other.rx_over_err: return False
971 if self.rx_crc_err != other.rx_crc_err: return False
972 if self.collisions != other.collisions: return False
973 return True
974
975 def pretty_print(self, q):
976 q.text("port_stats_entry {")
977 with q.group():
978 with q.indent(2):
979 q.breakable()
980 q.text("port_no = ");
981 q.text(util.pretty_port(self.port_no))
982 q.text(","); q.breakable()
983 q.text("rx_packets = ");
984 q.text("%#x" % self.rx_packets)
985 q.text(","); q.breakable()
986 q.text("tx_packets = ");
987 q.text("%#x" % self.tx_packets)
988 q.text(","); q.breakable()
989 q.text("rx_bytes = ");
990 q.text("%#x" % self.rx_bytes)
991 q.text(","); q.breakable()
992 q.text("tx_bytes = ");
993 q.text("%#x" % self.tx_bytes)
994 q.text(","); q.breakable()
995 q.text("rx_dropped = ");
996 q.text("%#x" % self.rx_dropped)
997 q.text(","); q.breakable()
998 q.text("tx_dropped = ");
999 q.text("%#x" % self.tx_dropped)
1000 q.text(","); q.breakable()
1001 q.text("rx_errors = ");
1002 q.text("%#x" % self.rx_errors)
1003 q.text(","); q.breakable()
1004 q.text("tx_errors = ");
1005 q.text("%#x" % self.tx_errors)
1006 q.text(","); q.breakable()
1007 q.text("rx_frame_err = ");
1008 q.text("%#x" % self.rx_frame_err)
1009 q.text(","); q.breakable()
1010 q.text("rx_over_err = ");
1011 q.text("%#x" % self.rx_over_err)
1012 q.text(","); q.breakable()
1013 q.text("rx_crc_err = ");
1014 q.text("%#x" % self.rx_crc_err)
1015 q.text(","); q.breakable()
1016 q.text("collisions = ");
1017 q.text("%#x" % self.collisions)
1018 q.breakable()
1019 q.text('}')
1020
1021
1022class queue_prop(loxi.OFObject):
1023 subtypes = {}
1024
1025
1026 def __init__(self, type=None):
1027 if type != None:
1028 self.type = type
1029 else:
1030 self.type = 0
1031 return
1032
1033 def pack(self):
1034 packed = []
1035 packed.append(struct.pack("!H", self.type))
1036 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1037 packed.append('\x00' * 4)
1038 length = sum([len(x) for x in packed])
1039 packed[1] = struct.pack("!H", length)
1040 return ''.join(packed)
1041
1042 @staticmethod
1043 def unpack(reader):
1044 subtype, = reader.peek('!H', 0)
1045 subclass = queue_prop.subtypes.get(subtype)
1046 if subclass:
1047 return subclass.unpack(reader)
1048
1049 obj = queue_prop()
1050 obj.type = reader.read("!H")[0]
1051 _len = reader.read("!H")[0]
1052 orig_reader = reader
1053 reader = orig_reader.slice(_len, 4)
1054 reader.skip(4)
1055 return obj
1056
1057 def __eq__(self, other):
1058 if type(self) != type(other): return False
1059 if self.type != other.type: return False
1060 return True
1061
1062 def pretty_print(self, q):
1063 q.text("queue_prop {")
1064 with q.group():
1065 with q.indent(2):
1066 q.breakable()
1067 q.breakable()
1068 q.text('}')
1069
1070
1071class queue_prop_min_rate(queue_prop):
1072 type = 1
1073
1074 def __init__(self, rate=None):
1075 if rate != None:
1076 self.rate = rate
1077 else:
1078 self.rate = 0
1079 return
1080
1081 def pack(self):
1082 packed = []
1083 packed.append(struct.pack("!H", self.type))
1084 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
1085 packed.append('\x00' * 4)
1086 packed.append(struct.pack("!H", self.rate))
1087 packed.append('\x00' * 6)
1088 length = sum([len(x) for x in packed])
1089 packed[1] = struct.pack("!H", length)
1090 return ''.join(packed)
1091
1092 @staticmethod
1093 def unpack(reader):
1094 obj = queue_prop_min_rate()
1095 _type = reader.read("!H")[0]
1096 assert(_type == 1)
1097 _len = reader.read("!H")[0]
1098 orig_reader = reader
1099 reader = orig_reader.slice(_len, 4)
1100 reader.skip(4)
1101 obj.rate = reader.read("!H")[0]
1102 reader.skip(6)
1103 return obj
1104
1105 def __eq__(self, other):
1106 if type(self) != type(other): return False
1107 if self.rate != other.rate: return False
1108 return True
1109
1110 def pretty_print(self, q):
1111 q.text("queue_prop_min_rate {")
1112 with q.group():
1113 with q.indent(2):
1114 q.breakable()
1115 q.text("rate = ");
1116 q.text("%#x" % self.rate)
1117 q.breakable()
1118 q.text('}')
1119
1120queue_prop.subtypes[1] = queue_prop_min_rate
1121
1122class queue_stats_entry(loxi.OFObject):
1123
1124 def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
1125 if port_no != None:
1126 self.port_no = port_no
1127 else:
1128 self.port_no = 0
1129 if queue_id != None:
1130 self.queue_id = queue_id
1131 else:
1132 self.queue_id = 0
1133 if tx_bytes != None:
1134 self.tx_bytes = tx_bytes
1135 else:
1136 self.tx_bytes = 0
1137 if tx_packets != None:
1138 self.tx_packets = tx_packets
1139 else:
1140 self.tx_packets = 0
1141 if tx_errors != None:
1142 self.tx_errors = tx_errors
1143 else:
1144 self.tx_errors = 0
1145 return
1146
1147 def pack(self):
1148 packed = []
1149 packed.append(util.pack_port_no(self.port_no))
1150 packed.append('\x00' * 2)
1151 packed.append(struct.pack("!L", self.queue_id))
1152 packed.append(struct.pack("!Q", self.tx_bytes))
1153 packed.append(struct.pack("!Q", self.tx_packets))
1154 packed.append(struct.pack("!Q", self.tx_errors))
1155 return ''.join(packed)
1156
1157 @staticmethod
1158 def unpack(reader):
1159 obj = queue_stats_entry()
1160 obj.port_no = util.unpack_port_no(reader)
1161 reader.skip(2)
1162 obj.queue_id = reader.read("!L")[0]
1163 obj.tx_bytes = reader.read("!Q")[0]
1164 obj.tx_packets = reader.read("!Q")[0]
1165 obj.tx_errors = reader.read("!Q")[0]
1166 return obj
1167
1168 def __eq__(self, other):
1169 if type(self) != type(other): return False
1170 if self.port_no != other.port_no: return False
1171 if self.queue_id != other.queue_id: return False
1172 if self.tx_bytes != other.tx_bytes: return False
1173 if self.tx_packets != other.tx_packets: return False
1174 if self.tx_errors != other.tx_errors: return False
1175 return True
1176
1177 def pretty_print(self, q):
1178 q.text("queue_stats_entry {")
1179 with q.group():
1180 with q.indent(2):
1181 q.breakable()
1182 q.text("port_no = ");
1183 q.text(util.pretty_port(self.port_no))
1184 q.text(","); q.breakable()
1185 q.text("queue_id = ");
1186 q.text("%#x" % self.queue_id)
1187 q.text(","); q.breakable()
1188 q.text("tx_bytes = ");
1189 q.text("%#x" % self.tx_bytes)
1190 q.text(","); q.breakable()
1191 q.text("tx_packets = ");
1192 q.text("%#x" % self.tx_packets)
1193 q.text(","); q.breakable()
1194 q.text("tx_errors = ");
1195 q.text("%#x" % self.tx_errors)
1196 q.breakable()
1197 q.text('}')
1198
1199
1200class table_stats_entry(loxi.OFObject):
1201
1202 def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
1203 if table_id != None:
1204 self.table_id = table_id
1205 else:
1206 self.table_id = 0
1207 if name != None:
1208 self.name = name
1209 else:
1210 self.name = ""
1211 if wildcards != None:
1212 self.wildcards = wildcards
1213 else:
1214 self.wildcards = util.init_wc_bmap()
1215 if max_entries != None:
1216 self.max_entries = max_entries
1217 else:
1218 self.max_entries = 0
1219 if active_count != None:
1220 self.active_count = active_count
1221 else:
1222 self.active_count = 0
1223 if lookup_count != None:
1224 self.lookup_count = lookup_count
1225 else:
1226 self.lookup_count = 0
1227 if matched_count != None:
1228 self.matched_count = matched_count
1229 else:
1230 self.matched_count = 0
1231 return
1232
1233 def pack(self):
1234 packed = []
1235 packed.append(struct.pack("!B", self.table_id))
1236 packed.append('\x00' * 3)
1237 packed.append(struct.pack("!32s", self.name))
1238 packed.append(util.pack_wc_bmap(self.wildcards))
1239 packed.append(struct.pack("!L", self.max_entries))
1240 packed.append(struct.pack("!L", self.active_count))
1241 packed.append(struct.pack("!Q", self.lookup_count))
1242 packed.append(struct.pack("!Q", self.matched_count))
1243 return ''.join(packed)
1244
1245 @staticmethod
1246 def unpack(reader):
1247 obj = table_stats_entry()
1248 obj.table_id = reader.read("!B")[0]
1249 reader.skip(3)
1250 obj.name = reader.read("!32s")[0].rstrip("\x00")
1251 obj.wildcards = util.unpack_wc_bmap(reader)
1252 obj.max_entries = reader.read("!L")[0]
1253 obj.active_count = reader.read("!L")[0]
1254 obj.lookup_count = reader.read("!Q")[0]
1255 obj.matched_count = reader.read("!Q")[0]
1256 return obj
1257
1258 def __eq__(self, other):
1259 if type(self) != type(other): return False
1260 if self.table_id != other.table_id: return False
1261 if self.name != other.name: return False
1262 if self.wildcards != other.wildcards: return False
1263 if self.max_entries != other.max_entries: return False
1264 if self.active_count != other.active_count: return False
1265 if self.lookup_count != other.lookup_count: return False
1266 if self.matched_count != other.matched_count: return False
1267 return True
1268
1269 def pretty_print(self, q):
1270 q.text("table_stats_entry {")
1271 with q.group():
1272 with q.indent(2):
1273 q.breakable()
1274 q.text("table_id = ");
1275 q.text("%#x" % self.table_id)
1276 q.text(","); q.breakable()
1277 q.text("name = ");
1278 q.pp(self.name)
1279 q.text(","); q.breakable()
1280 q.text("wildcards = ");
1281 q.text(util.pretty_wildcards(self.wildcards))
1282 q.text(","); q.breakable()
1283 q.text("max_entries = ");
1284 q.text("%#x" % self.max_entries)
1285 q.text(","); q.breakable()
1286 q.text("active_count = ");
1287 q.text("%#x" % self.active_count)
1288 q.text(","); q.breakable()
1289 q.text("lookup_count = ");
1290 q.text("%#x" % self.lookup_count)
1291 q.text(","); q.breakable()
1292 q.text("matched_count = ");
1293 q.text("%#x" % self.matched_count)
1294 q.breakable()
1295 q.text('}')
1296
1297
1298
1299match = match_v1