blob: cad61a51452c59297f2bfd0da8dc0caeb8c2b95c [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 Lane422d1b12013-06-04 13:09:17 -070042p_of = Proto ("of", "OpenFlow")
43
Rich Lane972be332013-06-04 13:36:48 -070044local openflow_versions = {
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080045:: for version in loxi_globals.OFVersions.all_supported:
46 [${version.wire_version}] = "${version.version}",
Rich Lane972be332013-06-04 13:36:48 -070047:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070048}
49
Rich Lane972be332013-06-04 13:36:48 -070050:: for version, ofproto in ir.items():
51:: for enum in ofproto.enums:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080052local enum_v${version.wire_version}_${enum.name} = {
Rich Lane972be332013-06-04 13:36:48 -070053:: for (name, value) in enum.values:
54 [${value}] = "${name}",
55:: #endfor
56}
57
58:: #endfor
59
60:: #endfor
61
Tomasz635e20a2013-10-23 16:14:29 -070062
Rich Lane364e0292013-10-01 21:05:57 -070063fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070064:: for field in fields:
Rich Lane4df40f32013-10-08 15:40:39 -070065:: if field.type in ["uint8", "uint16", "uint32", "uint64"]:
Rich Lane52452662013-10-25 13:34:42 -070066fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base}, ${field.enum_table})
Rich Lane4df40f32013-10-08 15:40:39 -070067:: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]:
68fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}")
69:: else:
70:: raise NotImplementedError("unknown Wireshark type " + field.type)
71:: #endif
Rich Laneb014bcf2013-06-19 11:14:11 -070072:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070073
74p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070075:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070076 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070077:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070078}
79
Rich Lane4bbdcf52013-10-01 22:07:35 -070080-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070081:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070082:: for ofclass in ofproto.classes:
83:: if ofclass.virtual:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080084${ofclass.name}_v${version.wire_version}_dissectors = {}
Rich Lane4bbdcf52013-10-01 22:07:35 -070085:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070086:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070087:: #endfor
88
Tomasza19e9d22013-12-08 11:18:11 -080089--- Dissectors for each class
Rich Lane96641df2013-06-10 13:36:35 -070090:: for version, ofproto in ir.items():
91:: for ofclass in ofproto.classes:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080092:: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version)
Rich Lane7708c182013-10-01 23:27:27 -070093:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
Rich Lane4bbdcf52013-10-01 22:07:35 -070094:: if ofclass.superclass:
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080095:: discriminator = ofclass.superclass.discriminator
Rich Lane586864e2013-10-01 23:26:35 -070096:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Andreas Wundsamc2ce5fa2013-11-15 15:20:11 -080097${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070098
99:: #endif
100:: #endfor
101:: #endfor
102
Rich Lane4bbdcf52013-10-01 22:07:35 -0700103local of_message_dissectors = {
104:: for version in ir:
Tomasz2663f4f2013-12-10 05:12:42 -0800105 [${version.wire_version}] = dissect_of_header_v${version.wire_version},
Rich Lane4bbdcf52013-10-01 22:07:35 -0700106:: #endfor
107}
108
Tomasz359147c2013-12-17 18:34:20 -0800109local of_port_desc_dissectors = {
110:: for version in ir:
111 [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version},
112:: #endfor
113}
114
Tomasz742c2ba2013-10-24 22:35:45 -0700115local of_oxm_dissectors = {
116:: for version in ir:
Tomasz2663f4f2013-12-10 05:12:42 -0800117 [${version.wire_version}] = dissect_of_oxm_v${version.wire_version},
Tomasz742c2ba2013-10-24 22:35:45 -0700118:: #endfor
119}
120
Tomasz2663f4f2013-12-10 05:12:42 -0800121:: include('_oftype_readers.lua')
122
Rich Lane96641df2013-06-10 13:36:35 -0700123function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -0700124 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -0700125 local subtree = root:add(p_of, buf(0))
Rich Lane96641df2013-06-10 13:36:35 -0700126 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700127 local type_val = buf(1,1):uint()
Rich Laneb017c732013-10-02 14:05:01 -0700128
129 local protocol = "OF ?"
130 if openflow_versions[version_val] then
131 protocol = "OF " .. openflow_versions[version_val]
Rich Lane96641df2013-06-10 13:36:35 -0700132 end
Tomasz3f1b1f92013-12-10 01:58:10 -0800133
Tomasz4b523342013-12-10 02:02:49 -0800134 local info = "unknown"
Tomasz2663f4f2013-12-10 05:12:42 -0800135 info = of_message_dissectors[version_val](reader, subtree)
Rich Laneb017c732013-10-02 14:05:01 -0700136
137 return protocol, info
Rich Lane422d1b12013-06-04 13:09:17 -0700138end
139
140-- of dissector function
141function p_of.dissector (buf, pkt, root)
Rich Lane422d1b12013-06-04 13:09:17 -0700142 local offset = 0
143 repeat
144 if buf:len() - offset >= 4 then
145 msg_len = buf(offset+2,2):uint()
146 if offset + msg_len > buf:len() then
147 -- we don't have all the data we need yet
148 pkt.desegment_len = offset + msg_len - buf:len()
149 return
150 end
151
Rich Laneb017c732013-10-02 14:05:01 -0700152 protocol, info = dissect_of_message(buf(offset, msg_len), root)
153
154 if offset == 0 then
155 pkt.cols.protocol:clear()
156 pkt.cols.info:clear()
157 else
Rich Lane7b8eaa12013-10-02 14:55:35 -0700158 pkt.cols.protocol:append(" + ")
159 pkt.cols.info:append(" + ")
Rich Laneb017c732013-10-02 14:05:01 -0700160 end
161 pkt.cols.protocol:append(protocol)
162 pkt.cols.info:append(info)
Rich Lane422d1b12013-06-04 13:09:17 -0700163 offset = offset + msg_len
164 else
165 -- we don't have all of length field yet
166 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
167 return
168 end
169 until offset >= buf:len()
170end
171
172-- Initialization routine
173function p_of.init()
174end
175
Rich Lane88d3afc2013-10-01 21:07:22 -0700176-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700177local tcp_dissector_table = DissectorTable.get("tcp.port")
178tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700179tcp_dissector_table:add(6653, p_of)