| :: # Copyright 2013, Big Switch Networks, Inc. |
| :: # |
| :: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| :: # the following special exception: |
| :: # |
| :: # LOXI Exception |
| :: # |
| :: # As a special exception to the terms of the EPL, you may distribute libraries |
| :: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| :: # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| :: # from the LoxiGen Libraries and the notice provided below is (i) included in |
| :: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| :: # documentation for the LoxiGen Libraries, if distributed in binary form. |
| :: # |
| :: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| :: # |
| :: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| :: # a copy of the EPL at: |
| :: # |
| :: # http://www.eclipse.org/legal/epl-v10.html |
| :: # |
| :: # Unless required by applicable law or agreed to in writing, software |
| :: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| :: # EPL for the specific language governing permissions and limitations |
| :: # under the EPL. |
| :: |
| :: import of_g |
| :: ir = of_g.ir |
| :: include('_copyright.lua') |
| |
| :: include('_ofreader.lua') |
| |
| :: include('_oftype_readers.lua') |
| |
| p_of = Proto ("of", "OpenFlow") |
| |
| local openflow_versions = { |
| :: for (version, name) in of_g.param_version_names.items(): |
| [${version}] = "${name}", |
| :: #endfor |
| } |
| |
| :: for version, ofproto in ir.items(): |
| :: for enum in ofproto.enums: |
| local enum_v${version}_${enum.name} = { |
| :: for (name, value) in enum.values: |
| [${value}] = "${name}", |
| :: #endfor |
| } |
| |
| :: #endfor |
| |
| :: #endfor |
| |
| fields = {} |
| :: for field in fields: |
| fields[${repr(field.fullname)}] = ProtoField.new("${field.name}", "${field.fullname}", "FT_${field.type}", nil, "BASE_${field.base}") |
| :: #endfor |
| |
| p_of.fields = { |
| :: for field in fields: |
| fields[${repr(field.fullname)}], |
| :: #endfor |
| } |
| |
| -- Subclass maps for virtual classes |
| :: for version, ofproto in ir.items(): |
| :: for ofclass in ofproto.classes: |
| :: if ofclass.virtual: |
| ${ofclass.name}_v${version}_dissectors = {} |
| :: #endif |
| :: #endfor |
| :: #endfor |
| |
| --- Dissectors for each class |
| |
| :: for version, ofproto in ir.items(): |
| :: for ofclass in ofproto.classes: |
| :: name = 'dissect_%s_v%d' % (ofclass.name, version) |
| :: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version) |
| :: if ofclass.superclass: |
| :: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator |
| :: discriminator_value = ofclass.member_by_name(discriminator.name).value |
| ${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name} |
| |
| :: #endif |
| :: #endfor |
| :: #endfor |
| |
| local of_message_dissectors = { |
| :: for version in ir: |
| [${version}] = of_header_v${version}_dissectors, |
| :: #endfor |
| } |
| |
| function dissect_of_message(buf, root) |
| local reader = OFReader.new(buf) |
| local subtree = root:add(p_of, buf(0)) |
| local version_val = buf(0,1):uint() |
| local type_val = buf(1,1):uint() |
| |
| local protocol = "OF ?" |
| if openflow_versions[version_val] then |
| protocol = "OF " .. openflow_versions[version_val] |
| end |
| |
| local info = "unknown" |
| if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then |
| info = of_message_dissectors[version_val][type_val](reader, subtree) |
| end |
| |
| return protocol, info |
| end |
| |
| -- of dissector function |
| function p_of.dissector (buf, pkt, root) |
| local offset = 0 |
| repeat |
| if buf:len() - offset >= 4 then |
| msg_len = buf(offset+2,2):uint() |
| if offset + msg_len > buf:len() then |
| -- we don't have all the data we need yet |
| pkt.desegment_len = offset + msg_len - buf:len() |
| return |
| end |
| |
| protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| |
| if offset == 0 then |
| pkt.cols.protocol:clear() |
| pkt.cols.info:clear() |
| else |
| pkt.cols.protocol:prepend(" + ") |
| pkt.cols.info:prepend(" + ") |
| end |
| pkt.cols.protocol:append(protocol) |
| pkt.cols.info:append(info) |
| offset = offset + msg_len |
| else |
| -- we don't have all of length field yet |
| pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| return |
| end |
| until offset >= buf:len() |
| end |
| |
| -- Initialization routine |
| function p_of.init() |
| end |
| |
| -- register a chained dissector for OpenFlow port numbers |
| local tcp_dissector_table = DissectorTable.get("tcp.port") |
| tcp_dissector_table:add(6633, p_of) |
| tcp_dissector_table:add(6653, p_of) |