wireshark_gen: adapt to new of_g
diff --git a/lang_wireshark.py b/lang_wireshark.py
index 3e862d2..525b241 100644
--- a/lang_wireshark.py
+++ b/lang_wireshark.py
@@ -38,5 +38,5 @@
import wireshark_gen
-def generate():
- wireshark_gen.generate()
+def generate(install_dir):
+ wireshark_gen.generate(install_dir)
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index 1225131..ee63a22 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -29,17 +29,18 @@
from collections import namedtuple
import loxi_utils.loxi_utils as utils
import loxi_front_end
-import of_g
+import loxi_globals
from loxi_ir import *
import field_info
+import template_utils
templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
DissectorField = namedtuple("DissectorField", ["fullname", "name", "type", "base", "enum_table"])
proto_names = { 1: 'of10', 2: 'of11', 3: 'of12', 4: 'of13' }
-def make_field_name(wire_version, ofclass_name, member_name):
- return "%s.%s.%s" % (proto_names[wire_version],
+def make_field_name(version, ofclass_name, member_name):
+ return "%s.%s.%s" % (proto_names[version.wire_version],
ofclass_name[3:],
member_name)
@@ -47,7 +48,7 @@
"""
Decide on a reader function to use for the given field
"""
- ofproto = of_g.ir[version]
+ ofproto = loxi_globals.ir[version]
enum = ofproto.enum_by_name(m.oftype)
if enum and 'wire_type' in enum.params:
return "read_" + enum.params['wire_type']
@@ -63,7 +64,7 @@
if oftype.startswith("list"):
return "bytes", "NONE", "nil"
- ofproto = of_g.ir[version]
+ ofproto = loxi_globals.ir[version]
enum = ofproto.enum_by_name(oftype)
if not enum and (cls, name) in field_info.class_field_to_enum:
@@ -92,7 +93,7 @@
field_base = "NONE"
if enum:
- enum_table = 'enum_v%d_%s' % (version, enum.name)
+ enum_table = 'enum_v%d_%s' % (version.wire_version, enum.name)
else:
enum_table = 'nil'
@@ -100,21 +101,21 @@
def create_fields():
r = []
- for wire_version, ofproto in of_g.ir.items():
+ for version, ofproto in loxi_globals.ir.items():
for ofclass in ofproto.classes:
for m in ofclass.members:
if isinstance(m, OFPadMember):
continue
- fullname = make_field_name(wire_version, ofclass.name, m.name)
- field_type, field_base, enum_table = get_field_info(wire_version, ofclass.name, m.name, m.oftype)
+ fullname = make_field_name(version, ofclass.name, m.name)
+ field_type, field_base, enum_table = get_field_info(version, ofclass.name, m.name, m.oftype)
r.append(DissectorField(fullname, m.name, field_type, field_base, enum_table))
return r
-def generate():
+def generate(install_dir):
context = {
'fields': create_fields(),
}
- with utils.open_output('openflow.lua') as out:
- utils.render_template(out, "openflow.lua", [templates_dir], context)
+ with template_utils.open_output(install_dir, 'openflow.lua') as out:
+ template_utils.render_template(out, "openflow.lua", [templates_dir], context)
diff --git a/wireshark_gen/templates/_ofclass_dissector.lua b/wireshark_gen/templates/_ofclass_dissector.lua
index 4aef886..0eb45eb 100644
--- a/wireshark_gen/templates/_ofclass_dissector.lua
+++ b/wireshark_gen/templates/_ofclass_dissector.lua
@@ -33,7 +33,7 @@
:: if not ofclass.superclass: attrs.append("top-level")
-- ${' '.join(attrs)} class ${ofclass.name}
:: if ofclass.superclass:
--- Child of ${ofclass.superclass}
+-- Child of ${ofclass.superclass.name}
:: #endif
:: if ofclass.virtual:
-- Discriminator is ${ofclass.discriminator.name}
@@ -46,7 +46,7 @@
:: #endif
:: field_name = make_field_name(version, ofclass.name, m.name)
:: reader_name = get_reader(version, ofclass, m)
- ${reader_name}(reader, ${version}, subtree, '${field_name}')
+ ${reader_name}(reader, ${version.wire_version}, subtree, '${field_name}')
:: #endfor
return '${ofclass.name}'
end
diff --git a/wireshark_gen/templates/openflow.lua b/wireshark_gen/templates/openflow.lua
index 841e502..7113281 100644
--- a/wireshark_gen/templates/openflow.lua
+++ b/wireshark_gen/templates/openflow.lua
@@ -25,8 +25,8 @@
:: # EPL for the specific language governing permissions and limitations
:: # under the EPL.
::
-:: import of_g
-:: ir = of_g.ir
+:: import loxi_globals
+:: ir = loxi_globals.ir
:: include('_copyright.lua')
:: include('_ofreader.lua')
@@ -36,14 +36,14 @@
p_of = Proto ("of", "OpenFlow")
local openflow_versions = {
-:: for (version, name) in of_g.param_version_names.items():
- [${version}] = "${name}",
+:: for version in loxi_globals.OFVersions.all_supported:
+ [${version.wire_version}] = "${version.version}",
:: #endfor
}
:: for version, ofproto in ir.items():
:: for enum in ofproto.enums:
-local enum_v${version}_${enum.name} = {
+local enum_v${version.wire_version}_${enum.name} = {
:: for (name, value) in enum.values:
[${value}] = "${name}",
:: #endfor
@@ -75,7 +75,7 @@
:: for version, ofproto in ir.items():
:: for ofclass in ofproto.classes:
:: if ofclass.virtual:
-${ofclass.name}_v${version}_dissectors = {}
+${ofclass.name}_v${version.wire_version}_dissectors = {}
:: #endif
:: #endfor
:: #endfor
@@ -84,12 +84,12 @@
:: for version, ofproto in ir.items():
:: for ofclass in ofproto.classes:
-:: name = 'dissect_%s_v%d' % (ofclass.name, version)
+:: name = 'dissect_%s_v%d' % (ofclass.name, version.wire_version)
:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass, version=version)
:: if ofclass.superclass:
-:: discriminator = ofproto.class_by_name(ofclass.superclass).discriminator
+:: discriminator = ofclass.superclass.discriminator
:: discriminator_value = ofclass.member_by_name(discriminator.name).value
-${ofclass.superclass}_v${version}_dissectors[${discriminator_value}] = ${name}
+${ofclass.superclass.name}_v${version.wire_version}_dissectors[${discriminator_value}] = ${name}
:: #endif
:: #endfor
@@ -97,73 +97,73 @@
local of_message_dissectors = {
:: for version in ir:
- [${version}] = of_header_v${version}_dissectors,
+ [${version.wire_version}] = of_header_v${version.wire_version}_dissectors,
:: #endfor
}
local of_oxm_dissectors = {
:: for version in ir:
- [${version}] = of_oxm_v${version}_dissectors,
+ [${version.wire_version}] = of_oxm_v${version.wire_version}_dissectors,
:: #endfor
}
local of_action_dissectors = {
:: for version in ir:
- [${version}] = of_action_v${version}_dissectors,
+ [${version.wire_version}] = of_action_v${version.wire_version}_dissectors,
:: #endfor
}
local of_instruction_dissectors = {
:: for version in ir:
- [${version}] = of_instruction_v${version}_dissectors,
+ [${version.wire_version}] = of_instruction_v${version.wire_version}_dissectors,
:: #endfor
}
local of_bucket_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_bucket_v${version},
+ [${version.wire_version}] = dissect_of_bucket_v${version.wire_version},
:: #endfor
}
local of_port_desc_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_port_desc_v${version},
+ [${version.wire_version}] = dissect_of_port_desc_v${version.wire_version},
:: #endfor
}
local of_stats_reply_dissectors = {
:: for version in ir:
- [${version}] = of_stats_reply_v${version}_dissectors,
+ [${version.wire_version}] = of_stats_reply_v${version.wire_version}_dissectors,
:: #endfor
}
local of_stats_request_dissectors = {
:: for version in ir:
- [${version}] = of_stats_request_v${version}_dissectors,
+ [${version.wire_version}] = of_stats_request_v${version.wire_version}_dissectors,
:: #endfor
}
local of_flow_stats_entry_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_flow_stats_entry_v${version},
+ [${version.wire_version}] = dissect_of_flow_stats_entry_v${version.wire_version},
:: #endfor
}
local of_port_stats_entry_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_port_stats_entry_v${version},
+ [${version.wire_version}] = dissect_of_port_stats_entry_v${version.wire_version},
:: #endfor
}
local of_table_stats_entry_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_table_stats_entry_v${version},
+ [${version.wire_version}] = dissect_of_table_stats_entry_v${version.wire_version},
:: #endfor
}
local of_queue_stats_entry_dissectors = {
:: for version in ir:
- [${version}] = dissect_of_queue_stats_entry_v${version},
+ [${version.wire_version}] = dissect_of_queue_stats_entry_v${version.wire_version},
:: #endfor
}