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