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") |
| 43 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 44 | local openflow_versions = { |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 45 | :: for version in loxi_globals.OFVersions.all_supported: |
| 46 | [${version.wire_version}] = "${version.version}", |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 47 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 50 | :: for version, ofproto in ir.items(): |
| 51 | :: for enum in ofproto.enums: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 52 | local enum_v${version.wire_version}_${enum.name} = { |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 53 | :: for (name, value) in enum.values: |
| 54 | [${value}] = "${name}", |
| 55 | :: #endfor |
| 56 | } |
| 57 | |
| 58 | :: #endfor |
| 59 | |
| 60 | :: #endfor |
| 61 | |
Tomasz | 635e20a | 2013-10-23 16:14:29 -0700 | [diff] [blame] | 62 | |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 63 | fields = {} |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 64 | :: for field in fields: |
Rich Lane | 4df40f3 | 2013-10-08 15:40:39 -0700 | [diff] [blame] | 65 | :: if field.type in ["uint8", "uint16", "uint32", "uint64"]: |
Rich Lane | 5245266 | 2013-10-25 13:34:42 -0700 | [diff] [blame] | 66 | 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] | 67 | :: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]: |
| 68 | fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}") |
| 69 | :: else: |
| 70 | :: raise NotImplementedError("unknown Wireshark type " + field.type) |
| 71 | :: #endif |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 72 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 73 | |
| 74 | p_of.fields = { |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 75 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 76 | fields[${repr(field.fullname)}], |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 77 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 80 | -- Subclass maps for virtual classes |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 81 | :: for version, ofproto in ir.items(): |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 82 | :: for ofclass in ofproto.classes: |
| 83 | :: if ofclass.virtual: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 84 | ${ofclass.name}_v${version.wire_version}_dissectors = {} |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 85 | :: #endif |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 86 | :: #endfor |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 87 | :: #endfor |
| 88 | |
Tomasz | a19e9d2 | 2013-12-08 11:18:11 -0800 | [diff] [blame] | 89 | --- Dissectors for each class |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 90 | :: for version, ofproto in ir.items(): |
| 91 | :: for ofclass in ofproto.classes: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 92 | :: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version) |
Rich Lane | 7708c18 | 2013-10-01 23:27:27 -0700 | [diff] [blame] | 93 | :: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version) |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 94 | :: if ofclass.superclass: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 95 | :: discriminator = ofclass.superclass.discriminator |
Rich Lane | 586864e | 2013-10-01 23:26:35 -0700 | [diff] [blame] | 96 | :: discriminator_value = ofclass.member_by_name(discriminator.name).value |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 97 | ${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name} |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 98 | |
| 99 | :: #endif |
| 100 | :: #endfor |
| 101 | :: #endfor |
| 102 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 103 | local of_message_dissectors = { |
| 104 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 105 | [${version.wire_version}] = dissect_of_header_v${version.wire_version}, |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 106 | :: #endfor |
| 107 | } |
| 108 | |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 109 | local of_oxm_dissectors = { |
| 110 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 111 | [${version.wire_version}] = dissect_of_oxm_v${version.wire_version}, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 112 | :: #endfor |
| 113 | } |
| 114 | |
| 115 | local of_action_dissectors = { |
| 116 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 117 | [${version.wire_version}] = dissect_of_action_v${version.wire_version}, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 118 | :: #endfor |
| 119 | } |
| 120 | |
| 121 | local of_instruction_dissectors = { |
| 122 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 123 | [${version.wire_version}] = dissect_of_instruction_v${version.wire_version}, |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 124 | :: #endfor |
| 125 | } |
| 126 | |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 127 | local of_bucket_dissectors = { |
| 128 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 129 | [${version.wire_version}] = dissect_of_bucket_v${version.wire_version}, |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 130 | :: #endfor |
| 131 | } |
| 132 | |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 133 | local of_port_desc_dissectors = { |
| 134 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 135 | [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 136 | :: #endfor |
| 137 | } |
| 138 | |
| 139 | local of_stats_reply_dissectors = { |
| 140 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 141 | [${version.wire_version}] = dissect_of_stats_reply_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 142 | :: #endfor |
| 143 | } |
| 144 | |
| 145 | local of_stats_request_dissectors = { |
| 146 | :: for version in ir: |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 147 | [${version.wire_version}] = dissect_of_stats_request_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 148 | :: #endfor |
| 149 | } |
| 150 | |
| 151 | local of_flow_stats_entry_dissectors = { |
| 152 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 153 | [${version.wire_version}] = dissect_of_flow_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 154 | :: #endfor |
| 155 | } |
| 156 | |
| 157 | local of_port_stats_entry_dissectors = { |
| 158 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 159 | [${version.wire_version}] = dissect_of_port_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 160 | :: #endfor |
| 161 | } |
| 162 | |
| 163 | local of_table_stats_entry_dissectors = { |
| 164 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 165 | [${version.wire_version}] = dissect_of_table_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 166 | :: #endfor |
| 167 | } |
| 168 | |
| 169 | local of_queue_stats_entry_dissectors = { |
| 170 | :: for version in ir: |
Andreas Wundsam | c2ce5fa | 2013-11-15 15:20:11 -0800 | [diff] [blame] | 171 | [${version.wire_version}] = dissect_of_queue_stats_entry_v${version.wire_version}, |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 172 | :: #endfor |
| 173 | } |
| 174 | |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 175 | :: include('_oftype_readers.lua') |
| 176 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 177 | function dissect_of_message(buf, root) |
Rich Lane | 93991e4 | 2013-10-01 22:24:51 -0700 | [diff] [blame] | 178 | local reader = OFReader.new(buf) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 179 | local subtree = root:add(p_of, buf(0)) |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 180 | local version_val = buf(0,1):uint() |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 181 | local type_val = buf(1,1):uint() |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 182 | |
| 183 | local protocol = "OF ?" |
| 184 | if openflow_versions[version_val] then |
| 185 | protocol = "OF " .. openflow_versions[version_val] |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 186 | end |
Tomasz | 3f1b1f9 | 2013-12-10 01:58:10 -0800 | [diff] [blame] | 187 | |
Tomasz | 4b52334 | 2013-12-10 02:02:49 -0800 | [diff] [blame] | 188 | local info = "unknown" |
Tomasz | 2663f4f | 2013-12-10 05:12:42 -0800 | [diff] [blame] | 189 | info = of_message_dissectors[version_val](reader, subtree) |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 190 | |
| 191 | return protocol, info |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 192 | end |
| 193 | |
| 194 | -- of dissector function |
| 195 | function p_of.dissector (buf, pkt, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 196 | local offset = 0 |
| 197 | repeat |
| 198 | if buf:len() - offset >= 4 then |
| 199 | msg_len = buf(offset+2,2):uint() |
| 200 | if offset + msg_len > buf:len() then |
| 201 | -- we don't have all the data we need yet |
| 202 | pkt.desegment_len = offset + msg_len - buf:len() |
| 203 | return |
| 204 | end |
| 205 | |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 206 | protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| 207 | |
| 208 | if offset == 0 then |
| 209 | pkt.cols.protocol:clear() |
| 210 | pkt.cols.info:clear() |
| 211 | else |
Rich Lane | 7b8eaa1 | 2013-10-02 14:55:35 -0700 | [diff] [blame] | 212 | pkt.cols.protocol:append(" + ") |
| 213 | pkt.cols.info:append(" + ") |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 214 | end |
| 215 | pkt.cols.protocol:append(protocol) |
| 216 | pkt.cols.info:append(info) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 217 | offset = offset + msg_len |
| 218 | else |
| 219 | -- we don't have all of length field yet |
| 220 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| 221 | return |
| 222 | end |
| 223 | until offset >= buf:len() |
| 224 | end |
| 225 | |
| 226 | -- Initialization routine |
| 227 | function p_of.init() |
| 228 | end |
| 229 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 230 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 231 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 232 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 233 | tcp_dissector_table:add(6653, p_of) |