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 | |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 56 | fields = {} |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 57 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 58 | fields[${repr(field.fullname)}] = ProtoField.new("${field.name}", "${field.fullname}", "FT_${field.type}", nil, "BASE_${field.base}") |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 59 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 60 | |
| 61 | p_of.fields = { |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 62 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 63 | fields[${repr(field.fullname)}], |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 64 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 67 | -- Subclass maps for virtual classes |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 68 | :: for version, ofproto in ir.items(): |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 69 | :: for ofclass in ofproto.classes: |
| 70 | :: if ofclass.virtual: |
| 71 | ${ofclass.name}_v${version}_dissectors = {} |
| 72 | :: #endif |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 73 | :: #endfor |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 74 | :: #endfor |
| 75 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 76 | --- Dissectors for each class |
| 77 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 78 | :: for version, ofproto in ir.items(): |
| 79 | :: for ofclass in ofproto.classes: |
| 80 | :: name = 'dissect_%s_v%d' % (ofclass.name, version) |
Rich Lane | 7708c18 | 2013-10-01 23:27:27 -0700 | [diff] [blame] | 81 | :: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version) |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 82 | :: if ofclass.superclass: |
Rich Lane | 586864e | 2013-10-01 23:26:35 -0700 | [diff] [blame] | 83 | :: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator |
| 84 | :: discriminator_value = ofclass.member_by_name(discriminator.name).value |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 85 | ${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name} |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 86 | |
| 87 | :: #endif |
| 88 | :: #endfor |
| 89 | :: #endfor |
| 90 | |
Rich Lane | 4bbdcf5 | 2013-10-01 22:07:35 -0700 | [diff] [blame] | 91 | local of_message_dissectors = { |
| 92 | :: for version in ir: |
| 93 | [${version}] = of_header_v${version}_dissectors, |
| 94 | :: #endfor |
| 95 | } |
| 96 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 97 | function dissect_of_message(buf, root) |
Rich Lane | 93991e4 | 2013-10-01 22:24:51 -0700 | [diff] [blame] | 98 | local reader = OFReader.new(buf) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 99 | local subtree = root:add(p_of, buf(0)) |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 100 | local version_val = buf(0,1):uint() |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 101 | local type_val = buf(1,1):uint() |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame^] | 102 | |
| 103 | local protocol = "OF ?" |
| 104 | if openflow_versions[version_val] then |
| 105 | protocol = "OF " .. openflow_versions[version_val] |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 106 | end |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame^] | 107 | |
| 108 | local info = "unknown" |
| 109 | if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then |
| 110 | info = of_message_dissectors[version_val][type_val](reader, subtree) |
| 111 | end |
| 112 | |
| 113 | return protocol, info |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 114 | end |
| 115 | |
| 116 | -- of dissector function |
| 117 | function p_of.dissector (buf, pkt, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 118 | local offset = 0 |
| 119 | repeat |
| 120 | if buf:len() - offset >= 4 then |
| 121 | msg_len = buf(offset+2,2):uint() |
| 122 | if offset + msg_len > buf:len() then |
| 123 | -- we don't have all the data we need yet |
| 124 | pkt.desegment_len = offset + msg_len - buf:len() |
| 125 | return |
| 126 | end |
| 127 | |
Rich Lane | b017c73 | 2013-10-02 14:05:01 -0700 | [diff] [blame^] | 128 | protocol, info = dissect_of_message(buf(offset, msg_len), root) |
| 129 | |
| 130 | if offset == 0 then |
| 131 | pkt.cols.protocol:clear() |
| 132 | pkt.cols.info:clear() |
| 133 | else |
| 134 | pkt.cols.protocol:prepend(" + ") |
| 135 | pkt.cols.info:prepend(" + ") |
| 136 | end |
| 137 | pkt.cols.protocol:append(protocol) |
| 138 | pkt.cols.info:append(info) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 139 | offset = offset + msg_len |
| 140 | else |
| 141 | -- we don't have all of length field yet |
| 142 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| 143 | return |
| 144 | end |
| 145 | until offset >= buf:len() |
| 146 | end |
| 147 | |
| 148 | -- Initialization routine |
| 149 | function p_of.init() |
| 150 | end |
| 151 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 152 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 153 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 154 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 155 | tcp_dissector_table:add(6653, p_of) |