wireshark_gen: generate enum usage from IR
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index 9bc3662..0ab5a95 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -35,7 +35,7 @@
templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
-DissectorField = namedtuple("DissectorField", ["fullname", "name", "type", "base"])
+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):
@@ -50,10 +50,14 @@
Returns (type, base)
"""
if oftype.startswith("list"):
- return "bytes", "NONE"
+ return "bytes", "NONE", "nil"
ofproto = of_g.ir[version]
+
enum = ofproto.enum_by_name(oftype)
+ if not enum and (cls, name) in field_info.class_field_to_enum:
+ enum_name = field_info.class_field_to_enum[(cls, name)]
+ enum = ofproto.enum_by_name(enum_name)
if enum:
field_type = "uint32"
@@ -76,7 +80,12 @@
print "WARN missing oftype_to_base for", oftype
field_base = "NONE"
- return field_type, field_base
+ if enum:
+ enum_table = 'enum_v%d_%s' % (version, enum.name)
+ else:
+ enum_table = 'nil'
+
+ return field_type, field_base, enum_table
def create_fields():
r = []
@@ -86,39 +95,13 @@
if isinstance(m, OFPadMember):
continue
fullname = make_field_name(wire_version, ofclass.name, m.name)
- field_type, field_base = get_field_info(wire_version, ofclass.name, m.name, m.oftype)
- r.append(DissectorField(fullname, m.name, field_type, field_base))
+ field_type, field_base, enum_table = get_field_info(wire_version, ofclass.name, m.name, m.oftype)
+ r.append(DissectorField(fullname, m.name, field_type, field_base, enum_table))
return r
-enum_tables = {
- 'of13.flow_mod.type': 'enum_v4_ofp_type',
- 'of13.error_msg.type': 'enum_v4_ofp_type',
- 'of13.stats_request.type': 'enum_v4_ofp_type',
- 'of13.stats_request.stats_type': 'enum_v4_ofp_stats_type',
- 'of13.stats_request.flags': 'enum_v4_ofp_stats_request_flags',
- 'of13.stats_reply.type': 'enum_v4_ofp_type',
- 'of13.stats_reply.stats_type': 'enum_v4_ofp_stats_type',
- 'of13.stats_reply.flags': 'enum_v4_ofp_stats_reply_flags',
- 'of13.flow_mod.table_id': 'enum_v4_ofp_table',
- 'of13.flow_mod._command': 'enum_v4_ofp_flow_mod_command',
- 'of13.flow_mod.out_port': 'enum_v4_ofp_port',
- 'of13.flow_mod.out_group': 'enum_v4_ofp_group',
- 'of13.error_msg.err_type': 'enum_v4_ofp_error_type',
- 'of13.port_mod.type': 'enum_v4_ofp_type',
- 'of13.hello.type': 'enum_v4_ofp_type',
- 'of13.features_request.type': 'enum_v4_ofp_type',
- 'of13.features_reply.type': 'enum_v4_ofp_type',
- 'of13.barrier_request.type': 'enum_v4_ofp_type',
- 'of13.barrier_reply.type': 'enum_v4_ofp_type',
- 'of13.echo_request.type': 'enum_v4_ofp_type',
- 'of13.echo_reply.type': 'enum_v4_ofp_type',
- 'of13.match_t.type': 'enum_v4_ofp_match_type'
-}
-
def generate(out, name):
context = {
'fields': create_fields(),
- 'enum_tables': enum_tables,
}
utils.render_template(out, "openflow.lua", [templates_dir], context)