blob: 7d500e03e4f4091d24faef9c726c44f7876c854f [file] [log] [blame]
Rich Lane972be332013-06-04 13:36:48 -07001:: import of_g
2:: ir = of_g.ir
Rich Lane45dcae12013-06-04 13:07:41 -07003-- TODO copyright (GPL)
Rich Lane422d1b12013-06-04 13:09:17 -07004
Rich Lane872b95a2013-06-17 18:39:14 -07005:: include('_ofreader.lua')
6
Rich Lane422d1b12013-06-04 13:09:17 -07007p_of = Proto ("of", "OpenFlow")
8
Rich Lane972be332013-06-04 13:36:48 -07009local openflow_versions = {
10:: for (version, name) in of_g.param_version_names.items():
11 [${version}] = "${name}",
12:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070013}
14
Rich Lane972be332013-06-04 13:36:48 -070015:: for version, ofproto in ir.items():
16:: for enum in ofproto.enums:
17local enum_v${version}_${enum.name} = {
18:: for (name, value) in enum.values:
19 [${value}] = "${name}",
20:: #endfor
21}
22
23:: #endfor
24
25:: #endfor
26
Rich Lane364e0292013-10-01 21:05:57 -070027fields = {}
Rich Laneb014bcf2013-06-19 11:14:11 -070028:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070029fields[${repr(field.fullname)}] = ProtoField.new("${field.name}", "${field.fullname}", "FT_${field.type}", nil, "BASE_${field.base}")
Rich Laneb014bcf2013-06-19 11:14:11 -070030:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070031
32p_of.fields = {
Rich Laneb014bcf2013-06-19 11:14:11 -070033:: for field in fields:
Rich Lane364e0292013-10-01 21:05:57 -070034 fields[${repr(field.fullname)}],
Rich Laneb014bcf2013-06-19 11:14:11 -070035:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070036}
37
Rich Lane96641df2013-06-10 13:36:35 -070038:: for supercls in set(sorted(superclasses.values())):
39local ${supercls}_dissectors = {
40:: for version, ofproto in ir.items():
41 [${version}] = {},
42:: #endfor
43}
44:: #endfor
45
46:: for version, ofproto in ir.items():
47:: for ofclass in ofproto.classes:
48:: name = 'dissect_%s_v%d' % (ofclass.name, version)
49:: typeval = 0
50:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass)
51:: if ofclass.name in superclasses:
52${superclasses[ofclass.name]}_dissectors[${version}][${typeval}] = ${name}
53
54:: #endif
55:: #endfor
56:: #endfor
57
58function dissect_of_message(buf, root)
Rich Lane422d1b12013-06-04 13:09:17 -070059 local subtree = root:add(p_of, buf(0))
Rich Lane364e0292013-10-01 21:05:57 -070060 subtree:add(fields['of10.header.version'], buf(0,1))
61 subtree:add(fields['of10.header.type'], buf(1,1))
62 subtree:add(fields['of10.header.length'], buf(2,2))
63 subtree:add(fields['of10.header.xid'], buf(4,4))
Rich Lane422d1b12013-06-04 13:09:17 -070064
Rich Lane96641df2013-06-10 13:36:35 -070065 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -070066 local type_val = buf(1,1):uint()
Rich Lane96641df2013-06-10 13:36:35 -070067 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
Rich Lanea08c93d2013-10-01 21:04:50 -070068 of_message_dissectors[version_val][type_val](buf, subtree)
Rich Lane96641df2013-06-10 13:36:35 -070069 end
Rich Lane422d1b12013-06-04 13:09:17 -070070end
71
72-- of dissector function
73function p_of.dissector (buf, pkt, root)
74 pkt.cols.protocol = p_of.name
75
76 local offset = 0
77 repeat
78 if buf:len() - offset >= 4 then
79 msg_len = buf(offset+2,2):uint()
80 if offset + msg_len > buf:len() then
81 -- we don't have all the data we need yet
82 pkt.desegment_len = offset + msg_len - buf:len()
83 return
84 end
85
Rich Lane96641df2013-06-10 13:36:35 -070086 dissect_of_message(buf(offset, msg_len), root)
Rich Lane422d1b12013-06-04 13:09:17 -070087 offset = offset + msg_len
88 else
89 -- we don't have all of length field yet
90 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
91 return
92 end
93 until offset >= buf:len()
94end
95
96-- Initialization routine
97function p_of.init()
98end
99
100-- register a chained dissector for port 8002
101local tcp_dissector_table = DissectorTable.get("tcp.port")
102tcp_dissector_table:add(6633, p_of)