blob: 5832779d04ba370ec186845f72a56dfea411c005 [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 Lane96641df2013-06-10 13:36:35 -070065:: for supercls in set(sorted(superclasses.values())):
66local ${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
85function dissect_of_message(buf, root)
Rich Lane422d1b12013-06-04 13:09:17 -070086 local subtree = root:add(p_of, buf(0))
Rich Lane364e0292013-10-01 21:05:57 -070087 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 Lane422d1b12013-06-04 13:09:17 -070091
Rich Lane96641df2013-06-10 13:36:35 -070092 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -070093 local type_val = buf(1,1):uint()
Rich Lane96641df2013-06-10 13:36:35 -070094 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
Rich Lanea08c93d2013-10-01 21:04:50 -070095 of_message_dissectors[version_val][type_val](buf, subtree)
Rich Lane96641df2013-06-10 13:36:35 -070096 end
Rich Lane422d1b12013-06-04 13:09:17 -070097end
98
99-- of dissector function
100function 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 Lane96641df2013-06-10 13:36:35 -0700113 dissect_of_message(buf(offset, msg_len), root)
Rich Lane422d1b12013-06-04 13:09:17 -0700114 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()
121end
122
123-- Initialization routine
124function p_of.init()
125end
126
Rich Lane88d3afc2013-10-01 21:07:22 -0700127-- register a chained dissector for OpenFlow port numbers
Rich Lane422d1b12013-06-04 13:09:17 -0700128local tcp_dissector_table = DissectorTable.get("tcp.port")
129tcp_dissector_table:add(6633, p_of)
Rich Lane88d3afc2013-10-01 21:07:22 -0700130tcp_dissector_table:add(6653, p_of)