wireshark: begin generating fields from IR
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index abf60c7..0395013 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -30,10 +30,11 @@
import loxi_utils.loxi_utils as utils
import loxi_front_end
import of_g
+from loxi_ir import *
templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
-DissectorField = namedtuple("DissectorField", ["name", "type", "base"])
+DissectorField = namedtuple("DissectorField", ["fullname", "name", "type", "base"])
# TODO move into IR
def create_superclass_map():
@@ -68,12 +69,20 @@
return superclasses
def create_fields():
- return [
- DissectorField("version", "UINT8", "DEC"),
- DissectorField("type", "UINT8", "DEC"),
- DissectorField("length", "UINT16", "DEC"),
- DissectorField("xid", "UINT32", "HEX"),
- ]
+ r = []
+ proto_names = { 1: 'of10', 2: 'of11', 3: 'of12', 4: 'of13' }
+ for wire_version, ofproto in of_g.ir.items():
+ for ofclass in ofproto.classes:
+ for m in ofclass.members:
+ if isinstance(m, OFPadMember):
+ continue
+ fullname = "%s.%s.%s" % (
+ proto_names[wire_version],
+ ofclass.name[3:],
+ m.name)
+ r.append(DissectorField(fullname, m.name, "UINT8", "DEC"))
+
+ return r
def generate(out, name):
superclasses = create_superclass_map()
diff --git a/wireshark_gen/templates/openflow.lua b/wireshark_gen/templates/openflow.lua
index e1b9319..7d500e0 100644
--- a/wireshark_gen/templates/openflow.lua
+++ b/wireshark_gen/templates/openflow.lua
@@ -24,13 +24,14 @@
:: #endfor
+fields = {}
:: for field in fields:
-f_${field.name} = ProtoField.new("${field.name}", "of.${field.name}", "FT_${field.type}", nil, "BASE_${field.base}")
+fields[${repr(field.fullname)}] = ProtoField.new("${field.name}", "${field.fullname}", "FT_${field.type}", nil, "BASE_${field.base}")
:: #endfor
p_of.fields = {
:: for field in fields:
- f_${field.name},
+ fields[${repr(field.fullname)}],
:: #endfor
}
@@ -55,13 +56,11 @@
:: #endfor
function dissect_of_message(buf, root)
- -- create subtree for of
local subtree = root:add(p_of, buf(0))
- -- add protocol fields to subtree
- subtree:add(f_version, buf(0,1))
- subtree:add(f_type, buf(1,1))
- subtree:add(f_length, buf(2,2))
- subtree:add(f_xid, buf(4,4))
+ subtree:add(fields['of10.header.version'], buf(0,1))
+ subtree:add(fields['of10.header.type'], buf(1,1))
+ subtree:add(fields['of10.header.length'], buf(2,2))
+ subtree:add(fields['of10.header.xid'], buf(4,4))
local version_val = buf(0,1):uint()
local type_val = buf(1,1):uint()