wireshark: stub dissectors
diff --git a/wireshark_gen/__init__.py b/wireshark_gen/__init__.py
index e74f55e..89a8ba1 100644
--- a/wireshark_gen/__init__.py
+++ b/wireshark_gen/__init__.py
@@ -27,9 +27,50 @@
 
 import os
 import loxi_utils.loxi_utils as utils
+import loxi_front_end
+import of_g
 
 templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
 
+# TODO move into IR
+def create_superclass_map():
+    superclasses = {}
+    for supercls, subcls_set in loxi_front_end.type_maps.inheritance_map.items():
+        for subcls in subcls_set:
+            superclasses[supercls + '_' + subcls] = supercls
+
+    for version, versioned in loxi_front_end.type_maps.message_types.items():
+        for subcls in versioned:
+            superclasses['of_' + subcls] = 'of_message'
+
+    for version, versioned in loxi_front_end.type_maps.extension_message_subtype.items():
+        for experimenter, classes in versioned.items():
+            for cls in classes:
+                superclasses[cls] = 'of_experimenter_' + experimenter
+
+    for version, versioned in loxi_front_end.type_maps.extension_action_subtype.items():
+        for experimenter, classes in versioned.items():
+            for cls in classes:
+                superclasses[cls] = 'of_action_' + experimenter
+
+    for version, versioned in loxi_front_end.type_maps.stats_types.items():
+        for subcls in versioned:
+            superclasses['of_' + subcls + '_stats_request'] = 'of_stats_request'
+            superclasses['of_' + subcls + '_stats_reply'] = 'of_stats_reply'
+
+    for version, versioned in loxi_front_end.type_maps.flow_mod_types.items():
+        for subcls in versioned:
+            superclasses['of_flow_' + subcls] = 'of_flow_mod'
+
+    return superclasses
+
 def generate(out, name):
-    context = {}
+    superclasses = create_superclass_map()
+    all_classes = sorted(of_g.unified.keys())
+
+    for cls in all_classes:
+        if cls not in superclasses:
+            print cls + ": " + superclasses.get(cls, "NONE")
+
+    context = { 'superclasses': superclasses }
     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
new file mode 100644
index 0000000..d4bee01
--- /dev/null
+++ b/wireshark_gen/templates/_ofclass_dissector.lua
@@ -0,0 +1,15 @@
+:: from loxi_ir import *
+function ${name}(buf, root)
+:: for m in ofclass.members:
+:: if isinstance(m, OFTypeMember):
+    -- type ${m.name}
+:: elif isinstance(m, OFDataMember):
+    -- data ${m.name}
+:: elif isinstance(m, OFLengthMember):
+    -- length ${m.name}
+:: elif isinstance(m, OFPadMember):
+    -- pad
+:: #endif
+:: #endfor
+end
+
diff --git a/wireshark_gen/templates/openflow.lua b/wireshark_gen/templates/openflow.lua
index caf1a62..c098f56 100644
--- a/wireshark_gen/templates/openflow.lua
+++ b/wireshark_gen/templates/openflow.lua
@@ -34,7 +34,27 @@
     f_xid,
 }
 
-function dissect_one(buf, pkt, root)
+:: for supercls in set(sorted(superclasses.values())):
+local ${supercls}_dissectors = {
+:: for version, ofproto in ir.items():
+    [${version}] = {},
+:: #endfor
+}
+:: #endfor
+
+:: for version, ofproto in ir.items():
+:: for ofclass in ofproto.classes:
+:: name = 'dissect_%s_v%d' % (ofclass.name, version)
+:: typeval = 0
+:: include('_ofclass_dissector.lua', name=name, ofclass=ofclass)
+:: if ofclass.name in superclasses:
+${superclasses[ofclass.name]}_dissectors[${version}][${typeval}] = ${name}
+
+:: #endif
+:: #endfor
+:: #endfor
+
+function dissect_of_message(buf, root)
     -- create subtree for of
     local subtree = root:add(p_of, buf(0))
     -- add protocol fields to subtree
@@ -43,7 +63,11 @@
     subtree:add(f_length, buf(2,2))
     subtree:add(f_xid, buf(4,4))
 
+    local version_val = buf(0,1):uint()
     local type_val = buf(1,1):uint()
+    if of_message_dissectors[version_val] and of_message_dissectors[version_val][type_val] then
+        of_message_dissectors[version_val][type_val](buf, root)
+    end
 end
 
 -- of dissector function
@@ -60,7 +84,7 @@
                 return
             end
 
-            dissect_one(buf(offset, msg_len), pkt, root)
+            dissect_of_message(buf(offset, msg_len), root)
             offset = offset + msg_len
         else
             -- we don't have all of length field yet