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 | 7708c18 | 2013-10-01 23:27:27 -0700 | [diff] [blame] | 42 | :: include('_oftype_readers.lua') |
| 43 | |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 44 | p_of = Proto ("of", "OpenFlow") |
| 45 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 46 | local openflow_versions = { |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 47 | :: for version in loxi_globals.OFVersions.all_supported: |
| 48 | [${version.wire_version}] = "${version.version}", |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 49 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 52 | :: for version, ofproto in ir.items(): |
| 53 | :: for enum in ofproto.enums: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 54 | local enum_v${version.wire_version}_${enum.name} = { |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 55 | :: for (name, value) in enum.values: |
| 56 | [${value}] = "${name}", |
| 57 | :: #endfor |
| 58 | } |
| 59 | |
| 60 | :: #endfor |
| 61 | |
| 62 | :: #endfor |
| 63 | |
Tomasz | 635e20a | 2013-10-23 16:14:29 -0700 | [diff] [blame] | 64 | |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 65 | fields = {} |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 66 | :: for field in fields: |
Rich Lane | 4df40f3 | 2013-10-08 15:40:39 -0700 | [diff] [blame] | 67 | :: if field.type in ["uint8", "uint16", "uint32", "uint64"]: |
Rich Lane | 5245266 | 2013-10-25 13:34:42 -0700 | [diff] [blame] | 68 | 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] | 69 | :: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]: |
| 70 | fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}") |
| 71 | :: else: |
| 72 | :: raise NotImplementedError("unknown Wireshark type " + field.type) |
| 73 | :: #endif |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 74 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 75 | |
| 76 | p_of.fields = { |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 77 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 78 | fields[${repr(field.fullname)}], |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 79 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 82 | -- Subclass maps for virtual classes |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 83 | :: for version, ofproto in ir.items(): |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 84 | :: for ofclass in ofproto.classes: |
| 85 | :: if ofclass.virtual: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 86 | ${ofclass.name}_v${version.wire_version}_dissectors = {} |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 87 | :: #endif |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 88 | :: #endfor |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 89 | :: #endfor |
| 90 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 91 | --- Dissectors for each class |
| 92 | |
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: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 108 | [${version.wire_version}] = of_header_v${version.wire_version}_dissectors, |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 109 | :: #endfor |
| 110 | } |
| 111 | |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 112 | local of_oxm_dissectors = { |
| 113 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 114 | [${version.wire_version}] = of_oxm_v${version.wire_version}_dissectors, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 115 | :: #endfor |
| 116 | } |
| 117 | |
| 118 | local of_action_dissectors = { |
| 119 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 120 | [${version.wire_version}] = of_action_v${version.wire_version}_dissectors, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 121 | :: #endfor |
| 122 | } |
| 123 | |
| 124 | local of_instruction_dissectors = { |
| 125 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 126 | [${version.wire_version}] = of_instruction_v${version.wire_version}_dissectors, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 127 | :: #endfor |
| 128 | } |
| 129 | |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 130 | local of_bucket_dissectors = { |
| 131 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 132 | [${version.wire_version}] = dissect_of_bucket_v${version.wire_version}, |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 133 | :: #endfor |
| 134 | } |
| 135 | |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 136 | local of_port_desc_dissectors = { |
| 137 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 138 | [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 139 | :: #endfor |
| 140 | } |
| 141 | |
| 142 | local of_stats_reply_dissectors = { |
| 143 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 144 | [${version.wire_version}] = of_stats_reply_v${version.wire_version}_dissectors, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 145 | :: #endfor |
| 146 | } |
| 147 | |
| 148 | local of_stats_request_dissectors = { |
| 149 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 150 | [${version.wire_version}] = of_stats_request_v${version.wire_version}_dissectors, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 151 | :: #endfor |
| 152 | } |
| 153 | |
| 154 | local of_flow_stats_entry_dissectors = { |
| 155 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 156 | [${version.wire_version}] = dissect_of_flow_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 157 | :: #endfor |
| 158 | } |
| 159 | |
| 160 | local of_port_stats_entry_dissectors = { |
| 161 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 162 | [${version.wire_version}] = dissect_of_port_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 163 | :: #endfor |
| 164 | } |
| 165 | |
| 166 | local of_table_stats_entry_dissectors = { |
| 167 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 168 | [${version.wire_version}] = dissect_of_table_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 169 | :: #endfor |
| 170 | } |
| 171 | |
| 172 | local of_queue_stats_entry_dissectors = { |
| 173 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 174 | [${version.wire_version}] = dissect_of_queue_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 175 | :: #endfor |
| 176 | } |
| 177 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 178 | function dissect_of_message(buf, root) |
Rich Lane | 93991e4 | 2013-10-01 22:24:51 -0700 | [diff] [blame] | 179 | local reader = OFReader.new(buf) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 180 | local subtree = root:add(p_of, buf(0)) |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 181 | local version_val = buf(0,1):uint() |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 182 | local type_val = buf(1,1):uint() |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 183 | |
| 184 | local protocol = "OF ?" |
| 185 | if openflow_versions[version_val] then |
| 186 | protocol = "OF " .. openflow_versions[version_val] |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 187 | end |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 188 | |
| 189 | local info = "unknown" |
Tomasz | 771b08a | 2013-11-02 13:33:57 -0700 | [diff] [blame] | 190 | if type_val == 19 then |
| 191 | local stats_type = buf(8,2):uint() |
| 192 | info = of_stats_reply_dissectors[version_val][stats_type](reader,subtree) |
| 193 | elseif type_val == 18 then |
| 194 | local stats_type = buf(8,2):uint() |
| 195 | info = of_stats_request_dissectors[version_val][stats_type](reader,subtree) |
| 196 | elseif of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 197 | info = of_message_dissectors[version_val][type_val](reader, subtree) |
| 198 | end |
| 199 | |
| 200 | return protocol, info |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 201 | end |
| 202 | |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 203 | function dissect_of_oxm(reader, subtree, version_val) |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 204 | local type_val = reader.peek(0,4):uint() |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 205 | local info = "unknown" |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 206 | if of_oxm_dissectors[version_val] and of_oxm_dissectors[version_val][type_val] then |
| 207 | info = of_oxm_dissectors[version_val][type_val](reader, subtree) |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 208 | end |
| 209 | |
| 210 | return info |
| 211 | end |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 212 | |
| 213 | function dissect_of_action(reader, subtree, version_val) |
| 214 | local type_val = reader.peek(0,2):uint() |
| 215 | local info = "unknown" |
| 216 | if of_action_dissectors[version_val] and of_action_dissectors[version_val][type_val] then |
| 217 | info = of_action_dissectors[version_val][type_val](reader, subtree) |
| 218 | end |
| 219 | |
| 220 | return info |
| 221 | end |
| 222 | |
| 223 | function dissect_of_instruction(reader, subtree, version_val) |
| 224 | local type_val = reader.peek(0,2):uint() |
| 225 | local info = "unknown" |
| 226 | if of_instruction_dissectors[version_val] and of_instruction_dissectors[version_val][type_val] then |
| 227 | info = of_instruction_dissectors[version_val][type_val](reader, subtree) |
| 228 | end |
| 229 | |
| 230 | return info |
| 231 | end |
| 232 | |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 233 | function dissect_of_bucket(reader, subtree, version_val) |
| 234 | local info = "unknown" |
| 235 | if of_bucket_dissectors[version_val] then |
| 236 | info = of_bucket_dissectors[version_val](reader, subtree) |
| 237 | end |
| 238 | |
| 239 | return info |
| 240 | end |
| 241 | |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 242 | function dissect_of_port_desc(reader, subtree, version_val) |
| 243 | local info = "unknown" |
| 244 | if of_port_desc_dissectors[version_val] then |
| 245 | info = of_port_desc_dissectors[version_val](reader, subtree) |
| 246 | end |
| 247 | |
| 248 | return info |
| 249 | end |
| 250 | |
| 251 | function dissect_of_flow_stats_entry(reader, subtree, version_val) |
| 252 | local info = "unknown" |
| 253 | if of_flow_stats_entry_dissectors[version_val] then |
| 254 | info = of_flow_stats_entry_dissectors[version_val](reader, subtree) |
| 255 | end |
| 256 | |
| 257 | return info |
| 258 | end |
| 259 | |
| 260 | function dissect_of_port_stats_entry(reader, subtree, version_val) |
| 261 | local info = "unknown" |
| 262 | if of_port_stats_entry_dissectors[version_val] then |
| 263 | info = of_port_stats_entry_dissectors[version_val](reader, subtree) |
| 264 | end |
| 265 | |
| 266 | return info |
| 267 | end |
| 268 | |
| 269 | function dissect_of_table_stats_entry(reader, subtree, version_val) |
| 270 | local info = "unknown" |
| 271 | if of_table_stats_entry_dissectors[version_val] then |
| 272 | info = of_table_stats_entry_dissectors[version_val](reader, subtree) |
| 273 | end |
| 274 | |
| 275 | return info |
| 276 | end |
| 277 | |
| 278 | function dissect_of_queue_stats_entry(reader, subtree, version_val) |
| 279 | local info = "unknown" |
| 280 | if of_queue_stats_entry_dissectors[version_val] then |
| 281 | info = of_queue_stats_entry_dissectors[version_val](reader, subtree) |
| 282 | end |
| 283 | |
| 284 | return info |
| 285 | end |
| 286 | |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 287 | -- of dissector function |
| 288 | function p_of.dissector (buf, pkt, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 289 | local offset = 0 |
| 290 | repeat |
| 291 | if buf:len() - offset >= 4 then |
| 292 | msg_len = buf(offset+2,2):uint() |
| 293 | if offset + msg_len > buf:len() then |
| 294 | -- we don't have all the data we need yet |
| 295 | pkt.desegment_len = offset + msg_len - buf:len() |
| 296 | return |
| 297 | end |
| 298 | |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 299 | protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| 300 | |
| 301 | if offset == 0 then |
| 302 | pkt.cols.protocol:clear() |
| 303 | pkt.cols.info:clear() |
| 304 | else |
Rich Lane | 7b8eaa1 | 2013-10-02 14:55:35 -0700 | [diff] [blame] | 305 | pkt.cols.protocol:append(" + ") |
| 306 | pkt.cols.info:append(" + ") |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 307 | end |
| 308 | pkt.cols.protocol:append(protocol) |
| 309 | pkt.cols.info:append(info) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 310 | offset = offset + msg_len |
| 311 | else |
| 312 | -- we don't have all of length field yet |
| 313 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| 314 | return |
| 315 | end |
| 316 | until offset >= buf:len() |
| 317 | end |
| 318 | |
| 319 | -- Initialization routine |
| 320 | function p_of.init() |
| 321 | end |
| 322 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 323 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 324 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 325 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 326 | tcp_dissector_table:add(6653, p_of) |