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