blob: 5ea41867f8be6238f47a91ca22defa1e3eeaefcc [file] [log] [blame]
Rich Lane45dcae12013-06-04 13:07:41 -07001-- TODO copyright (GPL)
Rich Lane422d1b12013-06-04 13:09:17 -07002
3p_of = Proto ("of", "OpenFlow")
4
5local ofp_type = {
6 [0] = "HELLO",
7 [1] = "ECHO_REQUEST",
8 [2] = "ECHO_REPLY",
9 [3] = "ERROR",
10}
11
12local f_version = ProtoField.uint8("of.version", "Version", base.HEX)
13local f_type = ProtoField.uint8("of.type", "Type", base.HEX, ofp_type)
14local f_length = ProtoField.uint16("of.length", "Length", base.HEX)
15local f_xid = ProtoField.uint32("of.xid", "XID", base.HEX)
16
17p_of.fields = {
18 f_version,
19 f_type,
20 f_length,
21 f_xid,
22}
23
24function dissect_one(buf, pkt, root)
25 -- create subtree for of
26 local subtree = root:add(p_of, buf(0))
27 -- add protocol fields to subtree
28 subtree:add(f_version, buf(0,1))
29 subtree:add(f_type, buf(1,1))
30 subtree:add(f_length, buf(2,2))
31 subtree:add(f_xid, buf(4,4))
32
33 local type_val = buf(1,1):uint()
34end
35
36-- of dissector function
37function p_of.dissector (buf, pkt, root)
38 pkt.cols.protocol = p_of.name
39
40 local offset = 0
41 repeat
42 if buf:len() - offset >= 4 then
43 msg_len = buf(offset+2,2):uint()
44 if offset + msg_len > buf:len() then
45 -- we don't have all the data we need yet
46 pkt.desegment_len = offset + msg_len - buf:len()
47 return
48 end
49
50 dissect_one(buf(offset, msg_len), pkt, root)
51 offset = offset + msg_len
52 else
53 -- we don't have all of length field yet
54 pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
55 return
56 end
57 until offset >= buf:len()
58end
59
60-- Initialization routine
61function p_of.init()
62end
63
64-- register a chained dissector for port 8002
65local tcp_dissector_table = DissectorTable.get("tcp.port")
66tcp_dissector_table:add(6633, p_of)