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 | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 34 | p_of = Proto ("of", "OpenFlow") |
| 35 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 36 | local openflow_versions = { |
| 37 | :: for (version, name) in of_g.param_version_names.items(): |
| 38 | [${version}] = "${name}", |
| 39 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame] | 42 | :: for version, ofproto in ir.items(): |
| 43 | :: for enum in ofproto.enums: |
| 44 | local enum_v${version}_${enum.name} = { |
| 45 | :: for (name, value) in enum.values: |
| 46 | [${value}] = "${name}", |
| 47 | :: #endfor |
| 48 | } |
| 49 | |
| 50 | :: #endfor |
| 51 | |
| 52 | :: #endfor |
| 53 | |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 54 | fields = {} |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 55 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 56 | 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] | 57 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 58 | |
| 59 | p_of.fields = { |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 60 | :: for field in fields: |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 61 | fields[${repr(field.fullname)}], |
Rich Lane | b014bcf | 2013-06-19 11:14:11 -0700 | [diff] [blame] | 62 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 65 | :: for supercls in set(sorted(superclasses.values())): |
| 66 | local ${supercls}_dissectors = { |
| 67 | :: for version, ofproto in ir.items(): |
| 68 | [${version}] = {}, |
| 69 | :: #endfor |
| 70 | } |
| 71 | :: #endfor |
| 72 | |
| 73 | :: for version, ofproto in ir.items(): |
| 74 | :: for ofclass in ofproto.classes: |
| 75 | :: name = 'dissect_%s_v%d' % (ofclass.name, version) |
| 76 | :: typeval = 0 |
| 77 | :: include('_ofclass_dissector.lua', name=name, ofclass=ofclass) |
| 78 | :: if ofclass.name in superclasses: |
| 79 | ${superclasses[ofclass.name]}_dissectors[${version}][${typeval}] = ${name} |
| 80 | |
| 81 | :: #endif |
| 82 | :: #endfor |
| 83 | :: #endfor |
| 84 | |
| 85 | function dissect_of_message(buf, root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 86 | local subtree = root:add(p_of, buf(0)) |
Rich Lane | 364e029 | 2013-10-01 21:05:57 -0700 | [diff] [blame] | 87 | subtree:add(fields['of10.header.version'], buf(0,1)) |
| 88 | subtree:add(fields['of10.header.type'], buf(1,1)) |
| 89 | subtree:add(fields['of10.header.length'], buf(2,2)) |
| 90 | subtree:add(fields['of10.header.xid'], buf(4,4)) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 91 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 92 | local version_val = buf(0,1):uint() |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 93 | local type_val = buf(1,1):uint() |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 94 | if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then |
Rich Lane | a08c93d | 2013-10-01 21:04:50 -0700 | [diff] [blame] | 95 | of_message_dissectors[version_val][type_val](buf, subtree) |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 96 | end |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 97 | end |
| 98 | |
| 99 | -- of dissector function |
| 100 | function p_of.dissector (buf, pkt, root) |
| 101 | pkt.cols.protocol = p_of.name |
| 102 | |
| 103 | local offset = 0 |
| 104 | repeat |
| 105 | if buf:len() - offset >= 4 then |
| 106 | msg_len = buf(offset+2,2):uint() |
| 107 | if offset + msg_len > buf:len() then |
| 108 | -- we don't have all the data we need yet |
| 109 | pkt.desegment_len = offset + msg_len - buf:len() |
| 110 | return |
| 111 | end |
| 112 | |
Rich Lane | 96641df | 2013-06-10 13:36:35 -0700 | [diff] [blame] | 113 | dissect_of_message(buf(offset, msg_len), root) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 114 | offset = offset + msg_len |
| 115 | else |
| 116 | -- we don't have all of length field yet |
| 117 | pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT |
| 118 | return |
| 119 | end |
| 120 | until offset >= buf:len() |
| 121 | end |
| 122 | |
| 123 | -- Initialization routine |
| 124 | function p_of.init() |
| 125 | end |
| 126 | |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 127 | -- register a chained dissector for OpenFlow port numbers |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 128 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 129 | tcp_dissector_table:add(6633, p_of) |
Rich Lane | 88d3afc | 2013-10-01 21:07:22 -0700 | [diff] [blame] | 130 | tcp_dissector_table:add(6653, p_of) |