Doing virtual classes the right way
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index e92ebf2..5c02e06 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -55,17 +55,6 @@
else:
return "read_" + m.oftype.replace(')', '').replace('(', '_')
-def get_peeker(version, cls, m):
- """
- Decide on a peeker function to use for the given field
- """
- ofproto = loxi_globals.ir[version]
- enum = ofproto.enum_by_name(m.oftype)
- if enum and 'wire_type' in enum.params:
- return "peek_" + enum.params['wire_type']
- else:
- return "peek_" + m.oftype.replace(')', '').replace('(', '_')
-
def get_field_info(version, cls, name, oftype):
"""
Decide on a Wireshark type and base for a given field.
diff --git a/wireshark_gen/templates/_ofclass_dissector.lua b/wireshark_gen/templates/_ofclass_dissector.lua
index fbb9f6a..d9fb5cb 100644
--- a/wireshark_gen/templates/_ofclass_dissector.lua
+++ b/wireshark_gen/templates/_ofclass_dissector.lua
@@ -26,7 +26,7 @@
:: # under the EPL.
::
:: from loxi_ir import *
-:: from wireshark_gen import make_field_name, get_reader, get_peeker
+:: from wireshark_gen import make_field_name, get_reader
:: attrs = []
:: if ofclass.virtual: attrs.append("virtual")
:: if ofclass.superclass: attrs.append("child")
@@ -43,18 +43,25 @@
:: if ofclass.virtual:
:: discriminator_name = make_field_name(version, ofclass.name, ofclass.discriminator.name)
:: #endif
+:: offset = 0
:: for m in ofclass.members:
:: if isinstance(m, OFPadMember):
+:: if not ofclass.virtual:
reader.skip(${m.length})
+:: #endif
:: continue
:: #endif
:: field_name = make_field_name(version, ofclass.name, m.name)
:: reader_name = get_reader(version, ofclass, m)
-:: peeker_name = get_peeker(version, ofclass, m)
+:: if ofclass.virtual:
+:: var_len = m.length
:: if (field_name == discriminator_name):
- return ${peeker_name}(reader, ${version.wire_version}, subtree, '${field_name}')
+ return ${ofclass.name}_v${version.wire_version}_dissectors[reader.peek(${offset},${var_len}):uint()](reader, subtree)
:: break
:: else:
+:: offset = offset + var_len
+:: #endif
+:: else:
${reader_name}(reader, ${version.wire_version}, subtree, '${field_name}')
:: #endif
:: #endfor
diff --git a/wireshark_gen/templates/_oftype_readers.lua b/wireshark_gen/templates/_oftype_readers.lua
index e9eb9fa..9a5e4fa 100644
--- a/wireshark_gen/templates/_oftype_readers.lua
+++ b/wireshark_gen/templates/_oftype_readers.lua
@@ -51,32 +51,6 @@
end
end
-function peek_scalar(reader, subtree, field_name, length)
- return reader.read(length):uint()
-end
-
-function peek_uint8_t(reader, version, subtree, field_name)
- return peek_scalar(reader, subtree, field_name, 1)
-end
-
-function peek_uint16_t(reader, version, subtree, field_name)
- return peek_scalar(reader, subtree, field_name, 2)
-end
-
-function peek_uint32_t(reader, version, subtree, field_name)
- return peek_scalar(reader, subtree, field_name, 4)
-end
-
-function peek_uint64_t(reader, version, subtree, field_name)
- return peek_scalar(reader, subtree, field_name, 8)
-end
-
-function peek_of_octets_t(reader, version, subtree, field_name)
- if not reader.is_empty() then
- return reader.peek_all()
- end
-end
-
function read_list_of_hello_elem_t(reader, version, subtree, field_name)
-- TODO
end
@@ -131,14 +105,6 @@
end
end
-function peek_of_fm_cmd_t(reader, version, subtree, field_name)
- if version == 1 then
- return peek_scalar(reader, subtree, field_name, 2)
- else
- return peek_scalar(reader, subtree, field_name, 1)
- end
-end
-
function read_list_of_action_t(reader, version, subtree, field_name)
if reader.is_empty() then
return
diff --git a/wireshark_gen/templates/openflow.lua b/wireshark_gen/templates/openflow.lua
index 12520ce..09ebcc4 100644
--- a/wireshark_gen/templates/openflow.lua
+++ b/wireshark_gen/templates/openflow.lua
@@ -84,52 +84,30 @@
:: for ofclass in ofproto.classes:
:: if ofclass.virtual:
${ofclass.name}_v${version.wire_version}_dissectors = {}
-${ofclass.name}_v${version.wire_version}_dissectors_virtual = {}
:: #endif
:: #endfor
:: #endfor
-:: virtual_classes = []
-
--- Dissectors for each class
:: for version, ofproto in ir.items():
:: for ofclass in ofproto.classes:
:: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version)
-:: name_virtual = '%s_v%d_dissectors' % (ofclass.name, version.wire_version)
:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
:: if ofclass.superclass:
:: discriminator = ofclass.superclass.discriminator
:: discriminator_value = ofclass.member_by_name(discriminator.name).value
-:: if ofclass.virtual:
-:: if discriminator_value not in virtual_classes:
-:: virtual_classes.append(discriminator_value)
-:: #endif
-${ofclass.superclass.name}_v${version.wire_version}_dissectors_virtual[${discriminator_value}] = ${name_virtual}
-:: #endif
${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name}
:: #endif
:: #endfor
:: #endfor
-local virtual_classes = {
-:: for classes in virtual_classes:
- [${classes}] = ${classes},
-:: #endfor
-}
-
local of_message_dissectors = {
:: for version in ir:
[${version.wire_version}] = of_header_v${version.wire_version}_dissectors,
:: #endfor
}
-local of_message_dissectors_virtual = {
-:: for version in ir:
- [${version.wire_version}] = of_header_v${version.wire_version}_dissectors_virtual,
-:: #endfor
-}
-
local of_oxm_dissectors = {
:: for version in ir:
[${version.wire_version}] = of_oxm_v${version.wire_version}_dissectors,
@@ -202,17 +180,12 @@
local version_val = buf(0,1):uint()
local type_val = buf(1,1):uint()
- local virtual_reader = OFReader.new(buf)
-
local protocol = "OF ?"
if openflow_versions[version_val] then
protocol = "OF " .. openflow_versions[version_val]
end
- if virtual_classes[type_val] then
- info = of_message_dissectors_virtual[version_val][type_val][of_message_dissectors[version_val][type_val](virtual_reader, subtree)](reader, subtree)
- else
- info = of_message_dissectors[version_val][type_val](reader, subtree)
- end
+
+ info = of_message_dissectors[version_val][type_val](reader, subtree)
return protocol, info
end