blob: 9b8ea118fd9b2dac9835086fd1ccc84084048d89 [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:
81:: discriminator_value = 0
82${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
Rich Lane96641df2013-06-10 13:36:35 -070083
84:: #endif
85:: #endfor
86:: #endfor
87
Rich Lane4bbdcf52013-10-01 22:07:35 -070088local of_message_dissectors = {
89:: for version in ir:
90 [${version}] = of_header_v${version}_dissectors,
91:: #endfor
92}
93
Rich Lane96641df2013-06-10 13:36:35 -070094function dissect_of_message(buf, root)
Rich Lane93991e42013-10-01 22:24:51 -070095 local reader = OFReader.new(buf)
Rich Lane422d1b12013-06-04 13:09:17 -070096 local subtree = root:add(p_of, buf(0))
Rich Lane93991e42013-10-01 22:24:51 -070097 subtree:add(fields['of10.header.version'], reader.read(1))
98 subtree:add(fields['of10.header.type'], reader.read(1))
99 subtree:add(fields['of10.header.length'], reader.read(2))
100 subtree:add(fields['of10.header.xid'], reader.read(4))
Rich Lane422d1b12013-06-04 13:09:17 -0700101
Rich Lane96641df2013-06-10 13:36:35 -0700102 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -0700103 local type_val = buf(1,1):uint()
Rich Lane96641df2013-06-10 13:36:35 -0700104 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
Rich Lane93991e42013-10-01 22:24:51 -0700105 of_message_dissectors[version_val][type_val](reader, subtree)
Rich Lane96641df2013-06-10 13:36:35 -0700106 end
Rich Lane422d1b12013-06-04 13:09:17 -0700107end
108
109-- of dissector function
110function p_of.dissector (buf, pkt, root)
111 pkt.cols.protocol = p_of.name
112
113 local offset = 0
114 repeat
115 if buf:len() - offset >= 4 then
116 msg_len = buf(offset+2,2):uint()
117 if offset + msg_len > buf:len() then
118 -- we don't have all the data we need yet
119 pkt.desegment_len = offset + msg_len - buf:len()
120 return
121 end
122
Rich Lane96641df2013-06-10 13:36:35 -0700123 dissect_of_message(buf(offset, msg_len), root)
Rich Lane422d1b12013-06-04 13:09:17 -0700124 offset = offset + msg_len
125 else
126 -- we don't have all of length field yet
127 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
128 return
129 end
130 until offset >= buf:len()
131end
132
133-- Initialization routine
134function p_of.init()
135end
136
Rich Lane88d3afc2013-10-01 21:07:22 -0700137-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700138local tcp_dissector_table = DissectorTable.get("tcp.port")
139tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700140tcp_dissector_table:add(6653, p_of)