blob: 1aa815abcd0cdfb71c1bc357fbcef80c40c61f8b [file] [log] [blame]
Rich Lane9cfa1652013-10-01 21:24:04 -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::
Rich Lane972be332013-06-04 13:36:48 -070028:: import of_g
29:: ir = of_g.ir
Rich Laneeb10d162013-10-01 21:15:35 -070030:: include('_copyright.lua')
Rich Lane422d1b12013-06-04 13:09:17 -070031
Rich Lane872b95a2013-06-17 18:39:14 -070032:: include('_ofreader.lua')
33
Rich Lane7708c182013-10-01 23:27:27 -070034:: include('_oftype_readers.lua')
35
Rich Lane422d1b12013-06-04 13:09:17 -070036p_of = Proto ("of", "OpenFlow")
37
Rich Lane972be332013-06-04 13:36:48 -070038local openflow_versions = {
39:: for (version, name) in of_g.param_version_names.items():
40 [${version}] = "${name}",
41:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070042}
43
Rich Lane972be332013-06-04 13:36:48 -070044:: for version, ofproto in ir.items():
45:: for enum in ofproto.enums:
46local enum_v${version}_${enum.name} = {
47:: for (name, value) in enum.values:
48 [${value}] = "${name}",
49:: #endfor
50}
51
52:: #endfor
53
54:: #endfor
55
Tomasz635e20a2013-10-23 16:14:29 -070056
Rich Lane364e0292013-10-01 21:05:57 -070057fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070058:: for field in fields:
Rich Lane4df40f32013-10-08 15:40:39 -070059:: if field.type in ["uint8", "uint16", "uint32", "uint64"]:
Rich Lane52452662013-10-25 13:34:42 -070060fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base}, ${field.enum_table})
Rich Lane4df40f32013-10-08 15:40:39 -070061:: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]:
62fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}")
63:: else:
64:: raise NotImplementedError("unknown Wireshark type " + field.type)
65:: #endif
Rich Laneb014bcf2013-06-19 11:14:11 -070066:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070067
68p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070069:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070070 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070071:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070072}
73
Rich Lane4bbdcf52013-10-01 22:07:35 -070074-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070075:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070076:: for ofclass in ofproto.classes:
77:: if ofclass.virtual:
78${ofclass.name}_v${version}_dissectors = {}
79:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070080:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070081:: #endfor
82
Rich Lane4bbdcf52013-10-01 22:07:35 -070083--- Dissectors for each class
84
Rich Lane96641df2013-06-10 13:36:35 -070085:: for version, ofproto in ir.items():
86:: for ofclass in ofproto.classes:
87:: name = 'dissect_%s_v%d' % (ofclass.name, version)
Rich Lane7708c182013-10-01 23:27:27 -070088:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
Rich Lane4bbdcf52013-10-01 22:07:35 -070089:: if ofclass.superclass:
Rich Lane586864e2013-10-01 23:26:35 -070090:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
91:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Rich Lane4bbdcf52013-10-01 22:07:35 -070092${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070093
94:: #endif
95:: #endfor
96:: #endfor
97
Rich Lane4bbdcf52013-10-01 22:07:35 -070098local of_message_dissectors = {
99:: for version in ir:
100 [${version}] = of_header_v${version}_dissectors,
101:: #endfor
102}
103
Tomasz742c2ba2013-10-24 22:35:45 -0700104local of_oxm_dissectors = {
105:: for version in ir:
106 [${version}] = of_oxm_v${version}_dissectors,
107:: #endfor
108}
109
110local of_action_dissectors = {
111:: for version in ir:
112 [${version}] = of_action_v${version}_dissectors,
113:: #endfor
114}
115
116local of_instruction_dissectors = {
117:: for version in ir:
118 [${version}] = of_instruction_v${version}_dissectors,
119:: #endfor
120}
121
Tomasza17a6692013-10-30 17:34:18 -0700122local of_bucket_dissectors = {
123:: for version in ir:
124 [${version}] = dissect_of_bucket_v${version},
125:: #endfor
126}
127
Tomaszc595d5b2013-11-02 13:30:32 -0700128local of_port_desc_dissectors = {
129:: for version in ir:
130 [${version}] = dissect_of_port_desc_v${version},
131:: #endfor
132}
133
134local of_stats_reply_dissectors = {
135:: for version in ir:
136 [${version}] = of_stats_reply_v${version}_dissectors,
137:: #endfor
138}
139
140local of_stats_request_dissectors = {
141:: for version in ir:
142 [${version}] = of_stats_request_v${version}_dissectors,
143:: #endfor
144}
145
146local of_flow_stats_entry_dissectors = {
147:: for version in ir:
148 [${version}] = dissect_of_flow_stats_entry_v${version},
149:: #endfor
150}
151
152local of_port_stats_entry_dissectors = {
153:: for version in ir:
154 [${version}] = dissect_of_port_stats_entry_v${version},
155:: #endfor
156}
157
158local of_table_stats_entry_dissectors = {
159:: for version in ir:
160 [${version}] = dissect_of_table_stats_entry_v${version},
161:: #endfor
162}
163
164local of_queue_stats_entry_dissectors = {
165:: for version in ir:
166 [${version}] = dissect_of_queue_stats_entry_v${version},
167:: #endfor
168}
169
Rich Lane96641df2013-06-10 13:36:35 -0700170function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -0700171 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -0700172 local subtree = root:add(p_of, buf(0))
Rich Lane96641df2013-06-10 13:36:35 -0700173 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700174 local type_val = buf(1,1):uint()
Rich Laneb017c732013-10-02 14:05:01 -0700175
176 local protocol = "OF ?"
177 if openflow_versions[version_val] then
178 protocol = "OF " .. openflow_versions[version_val]
Rich Lane96641df2013-06-10 13:36:35 -0700179 end
Rich Laneb017c732013-10-02 14:05:01 -0700180
181 local info = "unknown"
182 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
183 info = of_message_dissectors[version_val][type_val](reader, subtree)
184 end
185
186 return protocol, info
Rich Lane422d1b12013-06-04 13:09:17 -0700187end
188
Tomasz742c2ba2013-10-24 22:35:45 -0700189function dissect_of_oxm(reader, subtree, version_val)
Tomasze0584352013-10-23 16:43:26 -0700190 local type_val = reader.peek(0,4):uint()
Tomasze0584352013-10-23 16:43:26 -0700191 local info = "unknown"
Tomasz742c2ba2013-10-24 22:35:45 -0700192 if of_oxm_dissectors[version_val] and of_oxm_dissectors[version_val][type_val] then
193 info = of_oxm_dissectors[version_val][type_val](reader, subtree)
Tomasze0584352013-10-23 16:43:26 -0700194 end
195
196 return info
197end
Tomasz742c2ba2013-10-24 22:35:45 -0700198
199function dissect_of_action(reader, subtree, version_val)
200 local type_val = reader.peek(0,2):uint()
201 local info = "unknown"
202 if of_action_dissectors[version_val] and of_action_dissectors[version_val][type_val] then
203 info = of_action_dissectors[version_val][type_val](reader, subtree)
204 end
205
206 return info
207end
208
209function dissect_of_instruction(reader, subtree, version_val)
210 local type_val = reader.peek(0,2):uint()
211 local info = "unknown"
212 if of_instruction_dissectors[version_val] and of_instruction_dissectors[version_val][type_val] then
213 info = of_instruction_dissectors[version_val][type_val](reader, subtree)
214 end
215
216 return info
217end
218
Tomasza17a6692013-10-30 17:34:18 -0700219function dissect_of_bucket(reader, subtree, version_val)
220 local info = "unknown"
221 if of_bucket_dissectors[version_val] then
222 info = of_bucket_dissectors[version_val](reader, subtree)
223 end
224
225 return info
226end
227
Tomaszc595d5b2013-11-02 13:30:32 -0700228function dissect_of_port_desc(reader, subtree, version_val)
229 local info = "unknown"
230 if of_port_desc_dissectors[version_val] then
231 info = of_port_desc_dissectors[version_val](reader, subtree)
232 end
233
234 return info
235end
236
237function dissect_of_flow_stats_entry(reader, subtree, version_val)
238 local info = "unknown"
239 if of_flow_stats_entry_dissectors[version_val] then
240 info = of_flow_stats_entry_dissectors[version_val](reader, subtree)
241 end
242
243 return info
244end
245
246function dissect_of_port_stats_entry(reader, subtree, version_val)
247 local info = "unknown"
248 if of_port_stats_entry_dissectors[version_val] then
249 info = of_port_stats_entry_dissectors[version_val](reader, subtree)
250 end
251
252 return info
253end
254
255function dissect_of_table_stats_entry(reader, subtree, version_val)
256 local info = "unknown"
257 if of_table_stats_entry_dissectors[version_val] then
258 info = of_table_stats_entry_dissectors[version_val](reader, subtree)
259 end
260
261 return info
262end
263
264function dissect_of_queue_stats_entry(reader, subtree, version_val)
265 local info = "unknown"
266 if of_queue_stats_entry_dissectors[version_val] then
267 info = of_queue_stats_entry_dissectors[version_val](reader, subtree)
268 end
269
270 return info
271end
272
Rich Lane422d1b12013-06-04 13:09:17 -0700273-- of dissector function
274function p_of.dissector (buf, pkt, root)
Rich Lane422d1b12013-06-04 13:09:17 -0700275 local offset = 0
276 repeat
277 if buf:len() - offset >= 4 then
278 msg_len = buf(offset+2,2):uint()
279 if offset + msg_len > buf:len() then
280 -- we don't have all the data we need yet
281 pkt.desegment_len = offset + msg_len - buf:len()
282 return
283 end
284
Rich Laneb017c732013-10-02 14:05:01 -0700285 protocol, info = dissect_of_message(buf(offset, msg_len), root)
286
287 if offset == 0 then
288 pkt.cols.protocol:clear()
289 pkt.cols.info:clear()
290 else
Rich Lane7b8eaa12013-10-02 14:55:35 -0700291 pkt.cols.protocol:append(" + ")
292 pkt.cols.info:append(" + ")
Rich Laneb017c732013-10-02 14:05:01 -0700293 end
294 pkt.cols.protocol:append(protocol)
295 pkt.cols.info:append(info)
Rich Lane422d1b12013-06-04 13:09:17 -0700296 offset = offset + msg_len
297 else
298 -- we don't have all of length field yet
299 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
300 return
301 end
302 until offset >= buf:len()
303end
304
305-- Initialization routine
306function p_of.init()
307end
308
Rich Lane88d3afc2013-10-01 21:07:22 -0700309-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700310local tcp_dissector_table = DissectorTable.get("tcp.port")
311tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700312tcp_dissector_table:add(6653, p_of)