blob: 1b1bc8a8b26099ff39d462bb57223a5545d2c323 [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
Rich Lane364e0292013-10-01 21:05:57 -070056fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070057:: for field in fields:
Rich Lane4df40f32013-10-08 15:40:39 -070058:: if field.type in ["uint8", "uint16", "uint32", "uint64"]:
59fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}", base.${field.base})
60:: elif field.type in ["ipv4", "ipv6", "ether", "bytes", "stringz"]:
61fields[${repr(field.fullname)}] = ProtoField.${field.type}("${field.fullname}", "${field.name}")
62:: else:
63:: raise NotImplementedError("unknown Wireshark type " + field.type)
64:: #endif
Rich Laneb014bcf2013-06-19 11:14:11 -070065:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070066
67p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070068:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070069 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070070:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070071}
72
Rich Lane4bbdcf52013-10-01 22:07:35 -070073-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070074:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070075:: for ofclass in ofproto.classes:
76:: if ofclass.virtual:
77${ofclass.name}_v${version}_dissectors = {}
78:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070079:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070080:: #endfor
81
Rich Lane4bbdcf52013-10-01 22:07:35 -070082--- Dissectors for each class
83
Rich Lane96641df2013-06-10 13:36:35 -070084:: for version, ofproto in ir.items():
85:: for ofclass in ofproto.classes:
86:: name = 'dissect_%s_v%d' % (ofclass.name, version)
Rich Lane7708c182013-10-01 23:27:27 -070087:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
Rich Lane4bbdcf52013-10-01 22:07:35 -070088:: if ofclass.superclass:
Rich Lane586864e2013-10-01 23:26:35 -070089:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
90:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Rich Lane4bbdcf52013-10-01 22:07:35 -070091${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070092
93:: #endif
94:: #endfor
95:: #endfor
96
Rich Lane4bbdcf52013-10-01 22:07:35 -070097local of_message_dissectors = {
98:: for version in ir:
99 [${version}] = of_header_v${version}_dissectors,
100:: #endfor
101}
102
Rich Lane96641df2013-06-10 13:36:35 -0700103function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -0700104 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -0700105 local subtree = root:add(p_of, buf(0))
Rich Lane96641df2013-06-10 13:36:35 -0700106 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700107 local type_val = buf(1,1):uint()
Rich Laneb017c732013-10-02 14:05:01 -0700108
109 local protocol = "OF ?"
110 if openflow_versions[version_val] then
111 protocol = "OF " .. openflow_versions[version_val]
Rich Lane96641df2013-06-10 13:36:35 -0700112 end
Rich Laneb017c732013-10-02 14:05:01 -0700113
114 local info = "unknown"
115 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
116 info = of_message_dissectors[version_val][type_val](reader, subtree)
117 end
118
119 return protocol, info
Rich Lane422d1b12013-06-04 13:09:17 -0700120end
121
122-- of dissector function
123function p_of.dissector (buf, pkt, root)
Rich Lane422d1b12013-06-04 13:09:17 -0700124 local offset = 0
125 repeat
126 if buf:len() - offset >= 4 then
127 msg_len = buf(offset+2,2):uint()
128 if offset + msg_len > buf:len() then
129 -- we don't have all the data we need yet
130 pkt.desegment_len = offset + msg_len - buf:len()
131 return
132 end
133
Rich Laneb017c732013-10-02 14:05:01 -0700134 protocol, info = dissect_of_message(buf(offset, msg_len), root)
135
136 if offset == 0 then
137 pkt.cols.protocol:clear()
138 pkt.cols.info:clear()
139 else
Rich Lane7b8eaa12013-10-02 14:55:35 -0700140 pkt.cols.protocol:append(" + ")
141 pkt.cols.info:append(" + ")
Rich Laneb017c732013-10-02 14:05:01 -0700142 end
143 pkt.cols.protocol:append(protocol)
144 pkt.cols.info:append(info)
Rich Lane422d1b12013-06-04 13:09:17 -0700145 offset = offset + msg_len
146 else
147 -- we don't have all of length field yet
148 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
149 return
150 end
151 until offset >= buf:len()
152end
153
154-- Initialization routine
155function p_of.init()
156end
157
Rich Lane88d3afc2013-10-01 21:07:22 -0700158-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700159local tcp_dissector_table = DissectorTable.get("tcp.port")
160tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700161tcp_dissector_table:add(6653, p_of)