Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame^] | 1 | :: import of_g |
| 2 | :: ir = of_g.ir |
Rich Lane | 45dcae1 | 2013-06-04 13:07:41 -0700 | [diff] [blame] | 3 | -- TODO copyright (GPL) |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 4 | |
| 5 | p_of = Proto ("of", "OpenFlow") |
| 6 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame^] | 7 | local openflow_versions = { |
| 8 | :: for (version, name) in of_g.param_version_names.items(): |
| 9 | [${version}] = "${name}", |
| 10 | :: #endfor |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 11 | } |
| 12 | |
Rich Lane | 972be33 | 2013-06-04 13:36:48 -0700 | [diff] [blame^] | 13 | :: for version, ofproto in ir.items(): |
| 14 | :: for enum in ofproto.enums: |
| 15 | local 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 | |
| 25 | local f_version = ProtoField.uint8("of.version", "Version", base.HEX, openflow_versions) |
| 26 | local f_type = ProtoField.uint8("of.type", "Type", base.HEX, enum_v1_ofp_type) |
| 27 | local f_length = ProtoField.uint16("of.length", "Length") |
Rich Lane | 422d1b1 | 2013-06-04 13:09:17 -0700 | [diff] [blame] | 28 | local f_xid = ProtoField.uint32("of.xid", "XID", base.HEX) |
| 29 | |
| 30 | p_of.fields = { |
| 31 | f_version, |
| 32 | f_type, |
| 33 | f_length, |
| 34 | f_xid, |
| 35 | } |
| 36 | |
| 37 | function 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() |
| 47 | end |
| 48 | |
| 49 | -- of dissector function |
| 50 | function 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() |
| 71 | end |
| 72 | |
| 73 | -- Initialization routine |
| 74 | function p_of.init() |
| 75 | end |
| 76 | |
| 77 | -- register a chained dissector for port 8002 |
| 78 | local tcp_dissector_table = DissectorTable.get("tcp.port") |
| 79 | tcp_dissector_table:add(6633, p_of) |