blob: 08fb65d166c3baa020d1f4aefe6e62eb4fdd7e18 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # Copyright 2013, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
28:: include('_copyright.py')
29
30:: include('_autogen.py')
31
32import sys
33import struct
34import action
35import const
36import util
37
38# HACK make this module visible as 'common' to simplify code generation
39common = sys.modules[__name__]
40
41def unpack_list_flow_stats_entry(buf):
42 entries = []
43 offset = 0
44 while offset < len(buf):
45 length, = struct.unpack_from("!H", buf, offset)
46 if length == 0: raise loxi.ProtocolError("entry length is 0")
47 if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
48 entries.append(flow_stats_entry.unpack(buffer(buf, offset, length)))
49 offset += length
50 return entries
51
52def unpack_list_queue_prop(buf):
53 entries = []
54 offset = 0
55 while offset < len(buf):
56 type, length, = struct.unpack_from("!HH", buf, offset)
57 if length == 0: raise loxi.ProtocolError("entry length is 0")
58 if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
59 if type == const.OFPQT_MIN_RATE:
60 entry = queue_prop_min_rate.unpack(buffer(buf, offset, length))
61 else:
62 raise loxi.ProtocolError("unknown queue prop %d" % type)
63 entries.append(entry)
64 offset += length
65 return entries
66
67def unpack_list_packet_queue(buf):
68 entries = []
69 offset = 0
70 while offset < len(buf):
71 _, length, = struct.unpack_from("!LH", buf, offset)
72 if length == 0: raise loxi.ProtocolError("entry length is 0")
73 if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
74 entries.append(packet_queue.unpack(buffer(buf, offset, length)))
75 offset += length
76 return entries
77
78:: for ofclass in ofclasses:
79class ${ofclass.pyname}(object):
80:: for m in ofclass.type_members:
81 ${m.name} = ${m.value}
82:: #endfor
83
84 def __init__(self, ${', '.join(["%s=None" % m.name for m in ofclass.members])}):
85:: for m in ofclass.members:
86 if ${m.name} != None:
87 self.${m.name} = ${m.name}
88 else:
89 self.${m.name} = ${m.oftype.gen_init_expr()}
90:: #endfor
91
92 def pack(self):
93 packed = []
94:: include("_pack.py", ofclass=ofclass)
95 return ''.join(packed)
96
97 @staticmethod
98 def unpack(buf):
99 assert(len(buf) >= ${ofclass.min_length}) # Should be verified by caller
100 obj = ${ofclass.pyname}()
101:: include("_unpack.py", ofclass=ofclass)
102 return obj
103
104 def __eq__(self, other):
105 if type(self) != type(other): return False
106:: for m in ofclass.members:
107 if self.${m.name} != other.${m.name}: return False
108:: #endfor
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:: include('_pretty_print.py', ofclass=ofclass)
120
121:: if ofclass.name.startswith("of_match_v"):
122match = ${ofclass.pyname}
123
124:: #endif
125:: #endfor