Rich Lane | 45dcae1 | 2013-06-04 13:07:41 -0700 | [diff] [blame] | 1 | -- TODO copyright (GPL) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame^] | 2 | |
| 3 | p_of = Proto ("of", "OpenFlow") |
| 4 | |
| 5 | local ofp_type = { |
| 6 | [0] = "HELLO", |
| 7 | [1] = "ECHO_REQUEST", |
| 8 | [2] = "ECHO_REPLY", |
| 9 | [3] = "ERROR", |
| 10 | } |
| 11 | |
| 12 | local f_version = ProtoField.uint8("of.version", "Version", base.HEX) |
| 13 | local f_type = ProtoField.uint8("of.type", "Type", base.HEX, ofp_type) |
| 14 | local f_length = ProtoField.uint16("of.length", "Length", base.HEX) |
| 15 | local f_xid = ProtoField.uint32("of.xid", "XID", base.HEX) |
| 16 | |
| 17 | p_of.fields = { |
| 18 | f_version, |
| 19 | f_type, |
| 20 | f_length, |
| 21 | f_xid, |
| 22 | } |
| 23 | |
| 24 | function 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() |
| 34 | end |
| 35 | |
| 36 | -- of dissector function |
| 37 | function 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() |
| 58 | end |
| 59 | |
| 60 | -- Initialization routine |
| 61 | function p_of.init() |
| 62 | end |
| 63 | |
| 64 | -- register a chained dissector for port 8002 |
| 65 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 66 | tcp_dissector_table:add(6633, p_of) |