blob: 120dfa349adf5667bd30b83d1f1dd9acc3576f57 [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 Lane422d1b12013-06-04 13:09:17 -070034p_of = Proto ("of", "OpenFlow")
35
Rich Lane972be332013-06-04 13:36:48 -070036local openflow_versions = {
37:: for (version, name) in of_g.param_version_names.items():
38 [${version}] = "${name}",
39:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070040}
41
Rich Lane972be332013-06-04 13:36:48 -070042:: for version, ofproto in ir.items():
43:: for enum in ofproto.enums:
44local 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 Lane364e0292013-10-01 21:05:57 -070054fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070055:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070056fields[${repr(field.fullname)}] = ProtoField.new("${field.name}", "${field.fullname}", "FT_${field.type}", nil, "BASE_${field.base}")
Rich Laneb014bcf2013-06-19 11:14:11 -070057:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070058
59p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070060:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070061 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070062:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070063}
64
Rich Lane4bbdcf52013-10-01 22:07:35 -070065-- Subclass maps for virtual classes
Rich Lane96641df2013-06-10 13:36:35 -070066:: for version, ofproto in ir.items():
Rich Lane4bbdcf52013-10-01 22:07:35 -070067:: for ofclass in ofproto.classes:
68:: if ofclass.virtual:
69${ofclass.name}_v${version}_dissectors = {}
70:: #endif
Rich Lane96641df2013-06-10 13:36:35 -070071:: #endfor
Rich Lane96641df2013-06-10 13:36:35 -070072:: #endfor
73
Rich Lane4bbdcf52013-10-01 22:07:35 -070074--- Dissectors for each class
75
Rich Lane96641df2013-06-10 13:36:35 -070076:: for version, ofproto in ir.items():
77:: for ofclass in ofproto.classes:
78:: name = 'dissect_%s_v%d' % (ofclass.name, version)
Rich Lane96641df2013-06-10 13:36:35 -070079:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass)
Rich Lane4bbdcf52013-10-01 22:07:35 -070080:: if ofclass.superclass:
Rich Lane586864e2013-10-01 23:26:35 -070081:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
82:: discriminator_value = ofclass.member_by_name(discriminator.name).value
Rich Lane4bbdcf52013-10-01 22:07:35 -070083${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070084
85:: #endif
86:: #endfor
87:: #endfor
88
Rich Lane4bbdcf52013-10-01 22:07:35 -070089local of_message_dissectors = {
90:: for version in ir:
91 [${version}] = of_header_v${version}_dissectors,
92:: #endfor
93}
94
Rich Lane96641df2013-06-10 13:36:35 -070095function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -070096 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -070097 local subtree = root:add(p_of, buf(0))
Rich Lane93991e42013-10-01 22:24:51 -070098 subtree:add(fields['of10.header.version'], reader.read(1))
99 subtree:add(fields['of10.header.type'], reader.read(1))
100 subtree:add(fields['of10.header.length'], reader.read(2))
101 subtree:add(fields['of10.header.xid'], reader.read(4))
Rich Lane422d1b12013-06-04 13:09:17 -0700102
Rich Lane96641df2013-06-10 13:36:35 -0700103 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700104 local type_val = buf(1,1):uint()
Rich Lane96641df2013-06-10 13:36:35 -0700105 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
Rich Lane93991e42013-10-01 22:24:51 -0700106 of_message_dissectors[version_val][type_val](reader, subtree)
Rich Lane96641df2013-06-10 13:36:35 -0700107 end
Rich Lane422d1b12013-06-04 13:09:17 -0700108end
109
110-- of dissector function
111function p_of.dissector (buf, pkt, root)
112 pkt.cols.protocol = p_of.name
113
114 local offset = 0
115 repeat
116 if buf:len() - offset >= 4 then
117 msg_len = buf(offset+2,2):uint()
118 if offset + msg_len > buf:len() then
119 -- we don't have all the data we need yet
120 pkt.desegment_len = offset + msg_len - buf:len()
121 return
122 end
123
Rich Lane96641df2013-06-10 13:36:35 -0700124 dissect_of_message(buf(offset, msg_len), root)
Rich Lane422d1b12013-06-04 13:09:17 -0700125 offset = offset + msg_len
126 else
127 -- we don't have all of length field yet
128 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
129 return
130 end
131 until offset >= buf:len()
132end
133
134-- Initialization routine
135function p_of.init()
136end
137
Rich Lane88d3afc2013-10-01 21:07:22 -0700138-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700139local tcp_dissector_table = DissectorTable.get("tcp.port")
140tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700141tcp_dissector_table:add(6653, p_of)