blob: caf1a62736d9c902959786889f74be2e0bdc4ff4 [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
37function dissect_one(buf, pkt, root)
38 -- create subtree for of
39 local subtree = root:add(p_of, buf(0))
40 -- add protocol fields to subtree
41 subtree:add(f_version, buf(0,1))
42 subtree:add(f_type, buf(1,1))
43 subtree:add(f_length, buf(2,2))
44 subtree:add(f_xid, buf(4,4))
45
46 local type_val = buf(1,1):uint()
47end
48
49-- of dissector function
50function p_of.dissector (buf, pkt, root)
51 pkt.cols.protocol = p_of.name
52
53 local offset = 0
54 repeat
55 if buf:len() - offset >= 4 then
56 msg_len = buf(offset+2,2):uint()
57 if offset + msg_len > buf:len() then
58 -- we don't have all the data we need yet
59 pkt.desegment_len = offset + msg_len - buf:len()
60 return
61 end
62
63 dissect_one(buf(offset, msg_len), pkt, root)
64 offset = offset + msg_len
65 else
66 -- we don't have all of length field yet
67 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
68 return
69 end
70 until offset >= buf:len()
71end
72
73-- Initialization routine
74function p_of.init()
75end
76
77-- register a chained dissector for port 8002
78local tcp_dissector_table = DissectorTable.get("tcp.port")
79tcp_dissector_table:add(6633, p_of)