blob: 5ab11cd2eb654e51dab9c265c676d465d575bb09 [file] [log] [blame]
Rich Lane9cfa1652013-10-01 21:24:04 -07001:: # 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 Lane972be332013-06-04 13:36:48 -070028:: import of_g
29:: ir = of_g.ir
Rich Laneeb10d162013-10-01 21:15:35 -070030:: include('_copyright.lua')
Rich Lane422d1b12013-06-04 13:09:17 -070031
Rich Lane872b95a2013-06-17 18:39:14 -070032:: include('_ofreader.lua')
33
Rich Lane7708c182013-10-01 23:27:27 -070034:: include('_oftype_readers.lua')
35
Rich Lane422d1b12013-06-04 13:09:17 -070036p_of = Proto ("of", "OpenFlow")
37
Rich Lane972be332013-06-04 13:36:48 -070038local openflow_versions = {
39:: for (version, name) in of_g.param_version_names.items():
40 [${version}] = "${name}",
41:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070042}
43
Rich Lane972be332013-06-04 13:36:48 -070044:: for version, ofproto in ir.items():
45:: for enum in ofproto.enums:
46local 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
Tomasz635e20a2013-10-23 16:14:29 -070056
Rich Lane364e0292013-10-01 21:05:57 -070057fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070058:: for field in fields:
Rich Lane4df40f32013-10-08 15:40:39 -070059:: if field.type in ["uint8", "uint16", "uint32", "uint64"]:
Rich Lane52452662013-10-25 13:34:42 -070060fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base}, ${field.enum_table})
Rich Lane4df40f32013-10-08 15:40:39 -070061:: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]:
62fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}")
63:: else:
64:: raise NotImplementedError("unknown Wireshark type " + field.type)
65:: #endif
Rich Laneb014bcf2013-06-19 11:14:11 -070066:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070067
68p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070069:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070070 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070071:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070072}
73
Rich Lane4bbdcf52013-10-01 22:07:35 -070074-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070075:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070076:: for ofclass in ofproto.classes:
77:: if ofclass.virtual:
78${ofclass.name}_v${version}_dissectors = {}
79:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070080:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070081:: #endfor
82
Rich Lane4bbdcf52013-10-01 22:07:35 -070083--- Dissectors for each class
84
Rich Lane96641df2013-06-10 13:36:35 -070085:: for version, ofproto in ir.items():
86:: for ofclass in ofproto.classes:
87:: name = 'dissect_%s_v%d' % (ofclass.name, version)
Rich Lane7708c182013-10-01 23:27:27 -070088:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
Rich Lane4bbdcf52013-10-01 22:07:35 -070089:: if ofclass.superclass:
Rich Lane586864e2013-10-01 23:26:35 -070090:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
91:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Rich Lane4bbdcf52013-10-01 22:07:35 -070092${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070093
94:: #endif
95:: #endfor
96:: #endfor
97
Rich Lane4bbdcf52013-10-01 22:07:35 -070098local of_message_dissectors = {
99:: for version in ir:
100 [${version}] = of_header_v${version}_dissectors,
101:: #endfor
102}
103
Rich Lane96641df2013-06-10 13:36:35 -0700104function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -0700105 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -0700106 local subtree = root:add(p_of, buf(0))
Rich Lane96641df2013-06-10 13:36:35 -0700107 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700108 local type_val = buf(1,1):uint()
Rich Laneb017c732013-10-02 14:05:01 -0700109
110 local protocol = "OF ?"
111 if openflow_versions[version_val] then
112 protocol = "OF " .. openflow_versions[version_val]
Rich Lane96641df2013-06-10 13:36:35 -0700113 end
Rich Laneb017c732013-10-02 14:05:01 -0700114
115 local info = "unknown"
116 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
117 info = of_message_dissectors[version_val][type_val](reader, subtree)
118 end
119
120 return protocol, info
Rich Lane422d1b12013-06-04 13:09:17 -0700121end
122
Tomasze0584352013-10-23 16:43:26 -0700123function dissect_of_oxm_v3(reader, subtree)
124 local type_val = reader.peek(0,4):uint()
125
126 local info = "unknown"
127 if of_oxm_v3_dissectors[type_val] then
128 info = of_oxm_v3_dissectors[type_val](reader, subtree)
129 end
130
131 return info
132end
Rich Lane422d1b12013-06-04 13:09:17 -0700133-- of dissector function
134function p_of.dissector (buf, pkt, root)
Rich Lane422d1b12013-06-04 13:09:17 -0700135 local offset = 0
136 repeat
137 if buf:len() - offset >= 4 then
138 msg_len = buf(offset+2,2):uint()
139 if offset + msg_len > buf:len() then
140 -- we don't have all the data we need yet
141 pkt.desegment_len = offset + msg_len - buf:len()
142 return
143 end
144
Rich Laneb017c732013-10-02 14:05:01 -0700145 protocol, info = dissect_of_message(buf(offset, msg_len), root)
146
147 if offset == 0 then
148 pkt.cols.protocol:clear()
149 pkt.cols.info:clear()
150 else
Rich Lane7b8eaa12013-10-02 14:55:35 -0700151 pkt.cols.protocol:append(" + ")
152 pkt.cols.info:append(" + ")
Rich Laneb017c732013-10-02 14:05:01 -0700153 end
154 pkt.cols.protocol:append(protocol)
155 pkt.cols.info:append(info)
Rich Lane422d1b12013-06-04 13:09:17 -0700156 offset = offset + msg_len
157 else
158 -- we don't have all of length field yet
159 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
160 return
161 end
162 until offset >= buf:len()
163end
164
165-- Initialization routine
166function p_of.init()
167end
168
Rich Lane88d3afc2013-10-01 21:07:22 -0700169-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700170local tcp_dissector_table = DissectorTable.get("tcp.port")
171tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700172tcp_dissector_table:add(6653, p_of)