Rich Lane | 9cfa165 | 2013-10-01 21:24:04 -0700 | [diff] [blame] | 1 | :: # 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 Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 28 | :: import loxi_globals |
| 29 | :: ir = loxi_globals.ir |
Rich Lane | eb10d16 | 2013-10-01 21:15:35 -0700 | [diff] [blame] | 30 | :: include('_copyright.lua') |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 31 | |
Rich Lane | 9331e02 | 2013-11-20 12:41:25 -0800 | [diff] [blame] | 32 | -- 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 Lane | 872b95a | 2013-06-17 18:39:14 -0700 | [diff] [blame] | 40 | :: include('_ofreader.lua') |
| 41 | |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 42 | p_of = Proto ("of", "OpenFlow") |
tomaszklimczyk | 8d18d72 | 2014-01-19 23:17:05 -0800 | [diff] [blame] | 43 | ethernet_dissector = Dissector.get("eth") |
| 44 | |
| 45 | current_pkt = nil |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 46 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 47 | local openflow_versions = { |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 48 | :: for version in loxi_globals.OFVersions.all_supported: |
| 49 | [${version.wire_version}] = "${version.version}", |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 50 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 53 | :: for version, ofproto in ir.items(): |
| 54 | :: for enum in ofproto.enums: |
Rich Lane | 5f9931f | 2014-09-18 16:38:24 -0700 | [diff] [blame] | 55 | enum_v${version.wire_version}_${enum.name} = { |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 56 | :: for (name, value) in enum.values: |
| 57 | [${value}] = "${name}", |
| 58 | :: #endfor |
| 59 | } |
| 60 | |
| 61 | :: #endfor |
| 62 | |
| 63 | :: #endfor |
| 64 | |
Tomasz | 635e20a | 2013-10-23 16:14:29 -0700 | [diff] [blame] | 65 | |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 66 | fields = {} |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 67 | :: for field in fields: |
Rich Lane | 4df40f3 | 2013-10-08 15:40:39 -0700 | [diff] [blame] | 68 | :: if field.type in ["uint8", "uint16", "uint32", "uint64"]: |
Rich Lane | 5245266 | 2013-10-25 13:34:42 -0700 | [diff] [blame] | 69 | fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base}, ${field.enum_table}) |
Rich Lane | 4df40f3 | 2013-10-08 15:40:39 -0700 | [diff] [blame] | 70 | :: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]: |
| 71 | fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}") |
| 72 | :: else: |
| 73 | :: raise NotImplementedError("unknown Wireshark type " + field.type) |
| 74 | :: #endif |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 75 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 76 | |
| 77 | p_of.fields = { |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 78 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 79 | fields[${repr(field.fullname)}], |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 80 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 83 | -- Subclass maps for virtual classes |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 84 | :: for version, ofproto in ir.items(): |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 85 | :: for ofclass in ofproto.classes: |
| 86 | :: if ofclass.virtual: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 87 | ${ofclass.name}_v${version.wire_version}_dissectors = {} |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 88 | :: #endif |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 89 | :: #endfor |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 90 | :: #endfor |
| 91 | |
Tomasz | a19e9d2 | 2013-12-08 11:18:11 -0800 | [diff] [blame] | 92 | --- Dissectors for each class |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 93 | :: for version, ofproto in ir.items(): |
| 94 | :: for ofclass in ofproto.classes: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 95 | :: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version) |
Rich Lane | 7708c18 | 2013-10-01 23:27:27 -0700 | [diff] [blame] | 96 | :: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version) |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 97 | :: if ofclass.superclass: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 98 | :: discriminator = ofclass.superclass.discriminator |
Rich Lane | 586864e | 2013-10-01 23:26:35 -0700 | [diff] [blame] | 99 | :: discriminator_value = ofclass.member_by_name(discriminator.name).value |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 100 | ${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name} |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 101 | |
| 102 | :: #endif |
| 103 | :: #endfor |
| 104 | :: #endfor |
| 105 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 106 | local of_message_dissectors = { |
| 107 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 108 | [${version.wire_version}] = dissect_of_header_v${version.wire_version}, |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 109 | :: #endfor |
| 110 | } |
| 111 | |
Tomasz | 359147c | 2013-12-17 18:34:20 -0800 | [diff] [blame] | 112 | local of_port_desc_dissectors = { |
| 113 | :: for version in ir: |
| 114 | [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version}, |
| 115 | :: #endfor |
| 116 | } |
| 117 | |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 118 | local of_oxm_dissectors = { |
| 119 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 120 | [${version.wire_version}] = dissect_of_oxm_v${version.wire_version}, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 121 | :: #endfor |
| 122 | } |
| 123 | |
tomaszklimczyk | 8c83385 | 2014-01-19 23:18:12 -0800 | [diff] [blame] | 124 | local of_bsn_vport_q_in_q_dissectors = { |
| 125 | :: for version in ir: |
| 126 | [${version.wire_version}] = dissect_of_bsn_vport_q_in_q_v${version.wire_version}, |
| 127 | :: #endfor |
| 128 | } |
| 129 | |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 130 | :: include('_oftype_readers.lua') |
| 131 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 132 | function dissect_of_message(buf, root) |
Rich Lane | 93991e4 | 2013-10-01 22:24:51 -0700 | [diff] [blame] | 133 | local reader = OFReader.new(buf) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 134 | local subtree = root:add(p_of, buf(0)) |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 135 | local version_val = buf(0,1):uint() |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 136 | local type_val = buf(1,1):uint() |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 137 | |
| 138 | local protocol = "OF ?" |
| 139 | if openflow_versions[version_val] then |
| 140 | protocol = "OF " .. openflow_versions[version_val] |
tomaszklimczyk | 4f78cef | 2014-01-29 10:39:58 -0800 | [diff] [blame] | 141 | else |
| 142 | return "Unknown protocol", "Dissection error" |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 143 | end |
Tomasz | 3f1b1f9 | 2013-12-10 01:58:10 -0800 | [diff] [blame] | 144 | |
Tomasz | 4b52334 | 2013-12-10 02:02:49 -0800 | [diff] [blame] | 145 | local info = "unknown" |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 146 | info = of_message_dissectors[version_val](reader, subtree) |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 147 | |
| 148 | return protocol, info |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 149 | end |
| 150 | |
| 151 | -- of dissector function |
| 152 | function p_of.dissector (buf, pkt, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 153 | local offset = 0 |
tomaszklimczyk | 8d18d72 | 2014-01-19 23:17:05 -0800 | [diff] [blame] | 154 | current_pkt = pkt |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 155 | repeat |
| 156 | if buf:len() - offset >= 4 then |
Rich Lane | fba8f14 | 2014-06-06 16:24:14 -0700 | [diff] [blame] | 157 | local msg_version = buf(offset,1):uint() |
| 158 | local msg_type = buf(offset+1,1):uint() |
tomaszklimczyk | 9b13d9b | 2014-01-29 14:24:03 -0800 | [diff] [blame] | 159 | local msg_len = buf(offset+2,2):uint() |
| 160 | |
Rich Lane | fba8f14 | 2014-06-06 16:24:14 -0700 | [diff] [blame] | 161 | -- Detect obviously broken messages |
Rich Lane | 204d104 | 2014-12-01 15:28:44 -0800 | [diff] [blame] | 162 | if msg_version == 0 or msg_version > 5 then break end |
| 163 | if msg_type > 34 then break end |
Rich Lane | fba8f14 | 2014-06-06 16:24:14 -0700 | [diff] [blame] | 164 | if msg_len < 8 then break end |
tomaszklimczyk | 9b13d9b | 2014-01-29 14:24:03 -0800 | [diff] [blame] | 165 | |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 166 | if offset + msg_len > buf:len() then |
| 167 | -- we don't have all the data we need yet |
| 168 | pkt.desegment_len = offset + msg_len - buf:len() |
Rich Lane | e0eb286 | 2014-06-06 16:26:53 -0700 | [diff] [blame] | 169 | pkt.desegment_offset = offset |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 170 | return |
| 171 | end |
| 172 | |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 173 | protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| 174 | |
| 175 | if offset == 0 then |
| 176 | pkt.cols.protocol:clear() |
| 177 | pkt.cols.info:clear() |
| 178 | else |
Rich Lane | 7b8eaa1 | 2013-10-02 14:55:35 -0700 | [diff] [blame] | 179 | pkt.cols.protocol:append(" + ") |
| 180 | pkt.cols.info:append(" + ") |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 181 | end |
| 182 | pkt.cols.protocol:append(protocol) |
| 183 | pkt.cols.info:append(info) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 184 | offset = offset + msg_len |
| 185 | else |
| 186 | -- we don't have all of length field yet |
| 187 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
Rich Lane | e0eb286 | 2014-06-06 16:26:53 -0700 | [diff] [blame] | 188 | pkt.desegment_offset = offset |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 189 | return |
| 190 | end |
| 191 | until offset >= buf:len() |
| 192 | end |
| 193 | |
| 194 | -- Initialization routine |
| 195 | function p_of.init() |
| 196 | end |
| 197 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 198 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 199 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 200 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 201 | tcp_dissector_table:add(6653, p_of) |