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 | :: |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 28 | :: import of_g |
| 29 | :: ir = of_g.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 = { |
| 39 | :: for (version, name) in of_g.param_version_names.items(): |
| 40 | [${version}] = "${name}", |
| 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: |
| 46 | local enum_v${version}_${enum.name} = { |
| 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: |
| 78 | ${ofclass.name}_v${version}_dissectors = {} |
| 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: |
| 87 | :: name = 'dissect_%s_v%d' % (ofclass.name, 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: |
Rich Lane | 586864e | 2013-10-01 23:26:35 -0700 | [diff] [blame] | 90 | :: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator |
| 91 | :: discriminator_value = ofclass.member_by_name(discriminator.name).value |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 92 | ${ofclass.superclass}_v${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: |
| 100 | [${version}] = of_header_v${version}_dissectors, |
| 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: |
| 106 | [${version}] = of_oxm_v${version}_dissectors, |
| 107 | :: #endfor |
| 108 | } |
| 109 | |
| 110 | local of_action_dissectors = { |
| 111 | :: for version in ir: |
| 112 | [${version}] = of_action_v${version}_dissectors, |
| 113 | :: #endfor |
| 114 | } |
| 115 | |
| 116 | local of_instruction_dissectors = { |
| 117 | :: for version in ir: |
| 118 | [${version}] = of_instruction_v${version}_dissectors, |
| 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: |
| 124 | [${version}] = dissect_of_bucket_v${version}, |
| 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: |
| 130 | [${version}] = dissect_of_port_desc_v${version}, |
| 131 | :: #endfor |
| 132 | } |
| 133 | |
| 134 | local of_stats_reply_dissectors = { |
| 135 | :: for version in ir: |
| 136 | [${version}] = of_stats_reply_v${version}_dissectors, |
| 137 | :: #endfor |
| 138 | } |
| 139 | |
| 140 | local of_stats_request_dissectors = { |
| 141 | :: for version in ir: |
| 142 | [${version}] = of_stats_request_v${version}_dissectors, |
| 143 | :: #endfor |
| 144 | } |
| 145 | |
| 146 | local of_flow_stats_entry_dissectors = { |
| 147 | :: for version in ir: |
| 148 | [${version}] = dissect_of_flow_stats_entry_v${version}, |
| 149 | :: #endfor |
| 150 | } |
| 151 | |
| 152 | local of_port_stats_entry_dissectors = { |
| 153 | :: for version in ir: |
| 154 | [${version}] = dissect_of_port_stats_entry_v${version}, |
| 155 | :: #endfor |
| 156 | } |
| 157 | |
| 158 | local of_table_stats_entry_dissectors = { |
| 159 | :: for version in ir: |
| 160 | [${version}] = dissect_of_table_stats_entry_v${version}, |
| 161 | :: #endfor |
| 162 | } |
| 163 | |
| 164 | local of_queue_stats_entry_dissectors = { |
| 165 | :: for version in ir: |
| 166 | [${version}] = dissect_of_queue_stats_entry_v${version}, |
| 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" |
| 182 | if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then |
| 183 | info = of_message_dissectors[version_val][type_val](reader, subtree) |
| 184 | end |
| 185 | |
| 186 | return protocol, info |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 187 | end |
| 188 | |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 189 | function dissect_of_oxm(reader, subtree, version_val) |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 190 | local type_val = reader.peek(0,4):uint() |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 191 | local info = "unknown" |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 192 | if of_oxm_dissectors[version_val] and of_oxm_dissectors[version_val][type_val] then |
| 193 | info = of_oxm_dissectors[version_val][type_val](reader, subtree) |
Tomasz | e058435 | 2013-10-23 16:43:26 -0700 | [diff] [blame] | 194 | end |
| 195 | |
| 196 | return info |
| 197 | end |
Tomasz | 742c2ba | 2013-10-24 22:35:45 -0700 | [diff] [blame] | 198 | |
| 199 | function dissect_of_action(reader, subtree, version_val) |
| 200 | local type_val = reader.peek(0,2):uint() |
| 201 | local info = "unknown" |
| 202 | if of_action_dissectors[version_val] and of_action_dissectors[version_val][type_val] then |
| 203 | info = of_action_dissectors[version_val][type_val](reader, subtree) |
| 204 | end |
| 205 | |
| 206 | return info |
| 207 | end |
| 208 | |
| 209 | function dissect_of_instruction(reader, subtree, version_val) |
| 210 | local type_val = reader.peek(0,2):uint() |
| 211 | local info = "unknown" |
| 212 | if of_instruction_dissectors[version_val] and of_instruction_dissectors[version_val][type_val] then |
| 213 | info = of_instruction_dissectors[version_val][type_val](reader, subtree) |
| 214 | end |
| 215 | |
| 216 | return info |
| 217 | end |
| 218 | |
Tomasz | a17a669 | 2013-10-30 17:34:18 -0700 | [diff] [blame] | 219 | function dissect_of_bucket(reader, subtree, version_val) |
| 220 | local info = "unknown" |
| 221 | if of_bucket_dissectors[version_val] then |
| 222 | info = of_bucket_dissectors[version_val](reader, subtree) |
| 223 | end |
| 224 | |
| 225 | return info |
| 226 | end |
| 227 | |
Tomasz | c595d5b | 2013-11-02 13:30:32 -0700 | [diff] [blame] | 228 | function dissect_of_port_desc(reader, subtree, version_val) |
| 229 | local info = "unknown" |
| 230 | if of_port_desc_dissectors[version_val] then |
| 231 | info = of_port_desc_dissectors[version_val](reader, subtree) |
| 232 | end |
| 233 | |
| 234 | return info |
| 235 | end |
| 236 | |
| 237 | function dissect_of_flow_stats_entry(reader, subtree, version_val) |
| 238 | local info = "unknown" |
| 239 | if of_flow_stats_entry_dissectors[version_val] then |
| 240 | info = of_flow_stats_entry_dissectors[version_val](reader, subtree) |
| 241 | end |
| 242 | |
| 243 | return info |
| 244 | end |
| 245 | |
| 246 | function dissect_of_port_stats_entry(reader, subtree, version_val) |
| 247 | local info = "unknown" |
| 248 | if of_port_stats_entry_dissectors[version_val] then |
| 249 | info = of_port_stats_entry_dissectors[version_val](reader, subtree) |
| 250 | end |
| 251 | |
| 252 | return info |
| 253 | end |
| 254 | |
| 255 | function dissect_of_table_stats_entry(reader, subtree, version_val) |
| 256 | local info = "unknown" |
| 257 | if of_table_stats_entry_dissectors[version_val] then |
| 258 | info = of_table_stats_entry_dissectors[version_val](reader, subtree) |
| 259 | end |
| 260 | |
| 261 | return info |
| 262 | end |
| 263 | |
| 264 | function dissect_of_queue_stats_entry(reader, subtree, version_val) |
| 265 | local info = "unknown" |
| 266 | if of_queue_stats_entry_dissectors[version_val] then |
| 267 | info = of_queue_stats_entry_dissectors[version_val](reader, subtree) |
| 268 | end |
| 269 | |
| 270 | return info |
| 271 | end |
| 272 | |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 273 | -- of dissector function |
| 274 | function p_of.dissector (buf, pkt, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 275 | local offset = 0 |
| 276 | repeat |
| 277 | if buf:len() - offset >= 4 then |
| 278 | msg_len = buf(offset+2,2):uint() |
| 279 | if offset + msg_len > buf:len() then |
| 280 | -- we don't have all the data we need yet |
| 281 | pkt.desegment_len = offset + msg_len - buf:len() |
| 282 | return |
| 283 | end |
| 284 | |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 285 | protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| 286 | |
| 287 | if offset == 0 then |
| 288 | pkt.cols.protocol:clear() |
| 289 | pkt.cols.info:clear() |
| 290 | else |
Rich Lane | 7b8eaa1 | 2013-10-02 14:55:35 -0700 | [diff] [blame] | 291 | pkt.cols.protocol:append(" + ") |
| 292 | pkt.cols.info:append(" + ") |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame] | 293 | end |
| 294 | pkt.cols.protocol:append(protocol) |
| 295 | pkt.cols.info:append(info) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 296 | offset = offset + msg_len |
| 297 | else |
| 298 | -- we don't have all of length field yet |
| 299 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| 300 | return |
| 301 | end |
| 302 | until offset >= buf:len() |
| 303 | end |
| 304 | |
| 305 | -- Initialization routine |
| 306 | function p_of.init() |
| 307 | end |
| 308 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 309 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 310 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 311 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 312 | tcp_dissector_table:add(6653, p_of) |