blob: c098f5655ad1a2a5158ff9191157d8e41f3dc472 [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
5p_of = Proto ("of", "OpenFlow")
6
Rich Lane972be332013-06-04 13:36:48 -07007local openflow_versions = {
8:: for (version, name) in of_g.param_version_names.items():
9 [${version}] = "${name}",
10:: #endfor
Rich Lane422d1b12013-06-04 13:09:17 -070011}
12
Rich Lane972be332013-06-04 13:36:48 -070013:: for version, ofproto in ir.items():
14:: for enum in ofproto.enums:
15local enum_v${version}_${enum.name} = {
16:: for (name, value) in enum.values:
17 [${value}] = "${name}",
18:: #endfor
19}
20
21:: #endfor
22
23:: #endfor
24
25local f_version = ProtoField.uint8("of.version", "Version", base.HEX, openflow_versions)
26local f_type = ProtoField.uint8("of.type", "Type", base.HEX, enum_v1_ofp_type)
27local f_length = ProtoField.uint16("of.length", "Length")
Rich Lane422d1b12013-06-04 13:09:17 -070028local f_xid = ProtoField.uint32("of.xid", "XID", base.HEX)
29
30p_of.fields = {
31 f_version,
32 f_type,
33 f_length,
34 f_xid,
35}
36
Rich Lane96641df2013-06-10 13:36:35 -070037:: for supercls in set(sorted(superclasses.values())):
38local ${supercls}_dissectors = {
39:: for version, ofproto in ir.items():
40 [${version}] = {},
41:: #endfor
42}
43:: #endfor
44
45:: for version, ofproto in ir.items():
46:: for ofclass in ofproto.classes:
47:: name = 'dissect_%s_v%d' % (ofclass.name, version)
48:: typeval = 0
49:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass)
50:: if ofclass.name in superclasses:
51${superclasses[ofclass.name]}_dissectors[${version}][${typeval}] = ${name}
52
53:: #endif
54:: #endfor
55:: #endfor
56
57function dissect_of_message(buf, root)
Rich Lane422d1b12013-06-04 13:09:17 -070058 -- create subtree for of
59 local subtree = root:add(p_of, buf(0))
60 -- add protocol fields to subtree
61 subtree:add(f_version, buf(0,1))
62 subtree:add(f_type, buf(1,1))
63 subtree:add(f_length, buf(2,2))
64 subtree:add(f_xid, buf(4,4))
65
Rich Lane96641df2013-06-10 13:36:35 -070066 local version_val = buf(0,1):uint()
Rich Lane422d1b12013-06-04 13:09:17 -070067 local type_val = buf(1,1):uint()
Rich Lane96641df2013-06-10 13:36:35 -070068 if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
69 of_message_dissectors[version_val][type_val](buf, root)
70 end
Rich Lane422d1b12013-06-04 13:09:17 -070071end
72
73-- of dissector function
74function p_of.dissector (buf, pkt, root)
75 pkt.cols.protocol = p_of.name
76
77 local offset = 0
78 repeat
79 if buf:len() - offset >= 4 then
80 msg_len = buf(offset+2,2):uint()
81 if offset + msg_len > buf:len() then
82 -- we don't have all the data we need yet
83 pkt.desegment_len = offset + msg_len - buf:len()
84 return
85 end
86
Rich Lane96641df2013-06-10 13:36:35 -070087 dissect_of_message(buf(offset, msg_len), root)
Rich Lane422d1b12013-06-04 13:09:17 -070088 offset = offset + msg_len
89 else
90 -- we don't have all of length field yet
91 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
92 return
93 end
94 until offset >= buf:len()
95end
96
97-- Initialization routine
98function p_of.init()
99end
100
101-- register a chained dissector for port 8002
102local tcp_dissector_table = DissectorTable.get("tcp.port")
103tcp_dissector_table:add(6633, p_of)