blob: 931843d2df5c5ccd79a52095787aafbdb18d066e [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::
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080028:: import loxi_globals
29:: ir = loxi_globals.ir
Rich Laneeb10d162013-10-01 21:15:35 -070030:: include('_copyright.lua')
Rich Lane422d1b12013-06-04 13:09:17 -070031
Rich Lane9331e022013-11-20 12:41:25 -080032-- Copy this file to your wireshark plugin directory:
33-- Linux / OS X: ~/.wireshark/plugins/
34-- Windows: C:\Documents and Settings\<username>\Application Data\Wireshark\plugins\
35-- You may need to create the directory.
36
37-- The latest version of this dissector is always available at:
38-- http://www.projectfloodlight.org/openflow.lua
39
Rich Lane872b95a2013-06-17 18:39:14 -070040:: include('_ofreader.lua')
41
Rich Lane7708c182013-10-01 23:27:27 -070042:: include('_oftype_readers.lua')
43
Rich Lane422d1b12013-06-04 13:09:17 -070044p_of = Proto ("of", "OpenFlow")
45
Rich Lane972be332013-06-04 13:36:48 -070046local openflow_versions = {
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080047:: for version in loxi_globals.OFVersions.all_supported:
48 [${version.wire_version}] = "${version.version}",
Rich Lane972be332013-06-04 13:36:48 -070049:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070050}
51
Rich Lane972be332013-06-04 13:36:48 -070052:: for version, ofproto in ir.items():
53:: for enum in ofproto.enums:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080054local enum_v${version.wire_version}_${enum.name} = {
Rich Lane972be332013-06-04 13:36:48 -070055:: for (name, value) in enum.values:
56 [${value}] = "${name}",
57:: #endfor
58}
59
60:: #endfor
61
62:: #endfor
63
Tomasz635e20a2013-10-23 16:14:29 -070064
Rich Lane364e0292013-10-01 21:05:57 -070065fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070066:: for field in fields:
Rich Lane4df40f32013-10-08 15:40:39 -070067:: if field.type in ["uint8", "uint16", "uint32", "uint64"]:
Rich Lane52452662013-10-25 13:34:42 -070068fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base}, ${field.enum_table})
Rich Lane4df40f32013-10-08 15:40:39 -070069:: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]:
70fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}")
71:: else:
72:: raise NotImplementedError("unknown Wireshark type " + field.type)
73:: #endif
Rich Laneb014bcf2013-06-19 11:14:11 -070074:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070075
76p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070077:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070078 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070079:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070080}
81
Rich Lane4bbdcf52013-10-01 22:07:35 -070082-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070083:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070084:: for ofclass in ofproto.classes:
85:: if ofclass.virtual:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080086${ofclass.name}_v${version.wire_version}_dissectors = {}
Rich Lane4bbdcf52013-10-01 22:07:35 -070087:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070088:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070089:: #endfor
90
Tomasza19e9d22013-12-08 11:18:11 -080091--- Dissectors for each class
Rich Lane96641df2013-06-10 13:36:35 -070092:: for version, ofproto in ir.items():
93:: for ofclass in ofproto.classes:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080094:: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version)
Rich Lane7708c182013-10-01 23:27:27 -070095:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
Rich Lane4bbdcf52013-10-01 22:07:35 -070096:: if ofclass.superclass:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080097:: discriminator = ofclass.superclass.discriminator
Rich Lane586864e2013-10-01 23:26:35 -070098:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080099${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -0700100
101:: #endif
102:: #endfor
103:: #endfor
104
Rich Lane4bbdcf52013-10-01 22:07:35 -0700105local of_message_dissectors = {
106:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800107 [${version.wire_version}] = of_header_v${version.wire_version}_dissectors,
Rich Lane4bbdcf52013-10-01 22:07:35 -0700108:: #endfor
109}
110
Tomasz742c2ba2013-10-24 22:35:45 -0700111local of_oxm_dissectors = {
112:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800113 [${version.wire_version}] = of_oxm_v${version.wire_version}_dissectors,
Tomasz742c2ba2013-10-24 22:35:45 -0700114:: #endfor
115}
116
117local of_action_dissectors = {
118:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800119 [${version.wire_version}] = of_action_v${version.wire_version}_dissectors,
Tomasz742c2ba2013-10-24 22:35:45 -0700120:: #endfor
121}
122
123local of_instruction_dissectors = {
124:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800125 [${version.wire_version}] = of_instruction_v${version.wire_version}_dissectors,
Tomasz742c2ba2013-10-24 22:35:45 -0700126:: #endfor
127}
128
Tomasza17a6692013-10-30 17:34:18 -0700129local of_bucket_dissectors = {
130:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800131 [${version.wire_version}] = dissect_of_bucket_v${version.wire_version},
Tomasza17a6692013-10-30 17:34:18 -0700132:: #endfor
133}
134
Tomaszc595d5b2013-11-02 13:30:32 -0700135local of_port_desc_dissectors = {
136:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800137 [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version},
Tomaszc595d5b2013-11-02 13:30:32 -0700138:: #endfor
139}
140
141local of_stats_reply_dissectors = {
142:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800143 [${version.wire_version}] = of_stats_reply_v${version.wire_version}_dissectors,
Tomaszc595d5b2013-11-02 13:30:32 -0700144:: #endfor
145}
146
147local of_stats_request_dissectors = {
148:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800149 [${version.wire_version}] = of_stats_request_v${version.wire_version}_dissectors,
Tomaszc595d5b2013-11-02 13:30:32 -0700150:: #endfor
151}
152
153local of_flow_stats_entry_dissectors = {
154:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800155 [${version.wire_version}] = dissect_of_flow_stats_entry_v${version.wire_version},
Tomaszc595d5b2013-11-02 13:30:32 -0700156:: #endfor
157}
158
159local of_port_stats_entry_dissectors = {
160:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800161 [${version.wire_version}] = dissect_of_port_stats_entry_v${version.wire_version},
Tomaszc595d5b2013-11-02 13:30:32 -0700162:: #endfor
163}
164
165local of_table_stats_entry_dissectors = {
166:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800167 [${version.wire_version}] = dissect_of_table_stats_entry_v${version.wire_version},
Tomaszc595d5b2013-11-02 13:30:32 -0700168:: #endfor
169}
170
171local of_queue_stats_entry_dissectors = {
172:: for version in ir:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -0800173 [${version.wire_version}] = dissect_of_queue_stats_entry_v${version.wire_version},
Tomaszc595d5b2013-11-02 13:30:32 -0700174:: #endfor
175}
176
Rich Lane96641df2013-06-10 13:36:35 -0700177function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -0700178 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -0700179 local subtree = root:add(p_of, buf(0))
Rich Lane96641df2013-06-10 13:36:35 -0700180 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700181 local type_val = buf(1,1):uint()
Rich Laneb017c732013-10-02 14:05:01 -0700182
183 local protocol = "OF ?"
184 if openflow_versions[version_val] then
185 protocol = "OF " .. openflow_versions[version_val]
Rich Lane96641df2013-06-10 13:36:35 -0700186 end
Tomasz3f1b1f92013-12-10 01:58:10 -0800187
Tomasz4b523342013-12-10 02:02:49 -0800188 local info = "unknown"
Tomasz3f1b1f92013-12-10 01:58:10 -0800189 info = of_message_dissectors[version_val][type_val](reader, subtree)
Rich Laneb017c732013-10-02 14:05:01 -0700190
191 return protocol, info
Rich Lane422d1b12013-06-04 13:09:17 -0700192end
193
Tomasz742c2ba2013-10-24 22:35:45 -0700194function dissect_of_oxm(reader, subtree, version_val)
Tomasze0584352013-10-23 16:43:26 -0700195 local type_val = reader.peek(0,4):uint()
Tomasze0584352013-10-23 16:43:26 -0700196 local info = "unknown"
Tomasz742c2ba2013-10-24 22:35:45 -0700197 if of_oxm_dissectors[version_val] and of_oxm_dissectors[version_val][type_val] then
198 info = of_oxm_dissectors[version_val][type_val](reader, subtree)
Tomasze0584352013-10-23 16:43:26 -0700199 end
200
201 return info
202end
Tomasz742c2ba2013-10-24 22:35:45 -0700203
204function dissect_of_action(reader, subtree, version_val)
205 local type_val = reader.peek(0,2):uint()
206 local info = "unknown"
207 if of_action_dissectors[version_val] and of_action_dissectors[version_val][type_val] then
208 info = of_action_dissectors[version_val][type_val](reader, subtree)
209 end
210
211 return info
212end
213
214function dissect_of_instruction(reader, subtree, version_val)
215 local type_val = reader.peek(0,2):uint()
216 local info = "unknown"
217 if of_instruction_dissectors[version_val] and of_instruction_dissectors[version_val][type_val] then
218 info = of_instruction_dissectors[version_val][type_val](reader, subtree)
219 end
220
221 return info
222end
223
Tomasza17a6692013-10-30 17:34:18 -0700224function dissect_of_bucket(reader, subtree, version_val)
225 local info = "unknown"
226 if of_bucket_dissectors[version_val] then
227 info = of_bucket_dissectors[version_val](reader, subtree)
228 end
229
230 return info
231end
232
Tomaszc595d5b2013-11-02 13:30:32 -0700233function dissect_of_port_desc(reader, subtree, version_val)
234 local info = "unknown"
235 if of_port_desc_dissectors[version_val] then
236 info = of_port_desc_dissectors[version_val](reader, subtree)
237 end
238
239 return info
240end
241
242function dissect_of_flow_stats_entry(reader, subtree, version_val)
243 local info = "unknown"
244 if of_flow_stats_entry_dissectors[version_val] then
245 info = of_flow_stats_entry_dissectors[version_val](reader, subtree)
246 end
247
248 return info
249end
250
251function dissect_of_port_stats_entry(reader, subtree, version_val)
252 local info = "unknown"
253 if of_port_stats_entry_dissectors[version_val] then
254 info = of_port_stats_entry_dissectors[version_val](reader, subtree)
255 end
256
257 return info
258end
259
260function dissect_of_table_stats_entry(reader, subtree, version_val)
261 local info = "unknown"
262 if of_table_stats_entry_dissectors[version_val] then
263 info = of_table_stats_entry_dissectors[version_val](reader, subtree)
264 end
265
266 return info
267end
268
269function dissect_of_queue_stats_entry(reader, subtree, version_val)
270 local info = "unknown"
271 if of_queue_stats_entry_dissectors[version_val] then
272 info = of_queue_stats_entry_dissectors[version_val](reader, subtree)
273 end
274
275 return info
276end
277
Rich Lane422d1b12013-06-04 13:09:17 -0700278-- of dissector function
279function p_of.dissector (buf, pkt, root)
Rich Lane422d1b12013-06-04 13:09:17 -0700280 local offset = 0
281 repeat
282 if buf:len() - offset >= 4 then
283 msg_len = buf(offset+2,2):uint()
284 if offset + msg_len > buf:len() then
285 -- we don't have all the data we need yet
286 pkt.desegment_len = offset + msg_len - buf:len()
287 return
288 end
289
Rich Laneb017c732013-10-02 14:05:01 -0700290 protocol, info = dissect_of_message(buf(offset, msg_len), root)
291
292 if offset == 0 then
293 pkt.cols.protocol:clear()
294 pkt.cols.info:clear()
295 else
Rich Lane7b8eaa12013-10-02 14:55:35 -0700296 pkt.cols.protocol:append(" + ")
297 pkt.cols.info:append(" + ")
Rich Laneb017c732013-10-02 14:05:01 -0700298 end
299 pkt.cols.protocol:append(protocol)
300 pkt.cols.info:append(info)
Rich Lane422d1b12013-06-04 13:09:17 -0700301 offset = offset + msg_len
302 else
303 -- we don't have all of length field yet
304 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
305 return
306 end
307 until offset >= buf:len()
308end
309
310-- Initialization routine
311function p_of.init()
312end
313
Rich Lane88d3afc2013-10-01 21:07:22 -0700314-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700315local tcp_dissector_table = DissectorTable.get("tcp.port")
316tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700317tcp_dissector_table:add(6653, p_of)