pyloxi: fix recursive TLVs

The TLV of_bsn_tlv_bucket contains a list of bsn_tlvs. Previously we'd import
all the other modules from each module, but we couldn't import ourselves. This
change makes all references to classes go through the ofp pointer which is set
to e.g. loxi.of10. Some magic is required because there's no easy way to get a
reference to your parent module or your own module.
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index f8a7211..9c741d2 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -109,5 +109,5 @@
         for name, ofclasses in modules.items():
             args = args_by_module.get(name, {})
             render(os.path.join(subdir, name + '.py'), template_name='module.py',
-                   version=version, ofclasses=ofclasses, modules=modules.keys(),
+                   version=version, ofclasses=ofclasses, subdir=subdir,
                    **args)
diff --git a/py_gen/oftype.py b/py_gen/oftype.py
index 3893865..76eebd0 100644
--- a/py_gen/oftype.py
+++ b/py_gen/oftype.py
@@ -110,7 +110,7 @@
     'of_oxm_t': OFTypeData(
         init='None',
         pack='%s.pack()',
-        unpack='oxm.oxm.unpack(%s)'),
+        unpack='ofp.oxm.oxm.unpack(%s)'),
 
     'of_checksum_128_t': OFTypeData(
         init='0',
@@ -144,11 +144,11 @@
 
 # Map from class name to Python class name
 embedded_structs = {
-    'of_match_t': 'common.match',
-    'of_port_desc_t': 'common.port_desc',
-    'of_meter_features_t': 'common.meter_features',
-    'of_bsn_vport_t': 'common.bsn_vport',
-    'of_table_desc_t': 'common.table_desc',
+    'of_match_t': 'ofp.match',
+    'of_port_desc_t': 'ofp.port_desc',
+    'of_meter_features_t': 'ofp.meter_features',
+    'of_bsn_vport_t': 'ofp.bsn_vport',
+    'of_table_desc_t': 'ofp.table_desc',
 }
 
 for (cls, pyclass) in embedded_structs.items():
@@ -198,7 +198,7 @@
         ofclass = ofproto.class_by_name(oftype_list_elem(oftype))
         assert ofclass, "No class named %r" % oftype_list_elem(oftype)
         module_name, class_name = py_gen.codegen.generate_pyname(ofclass)
-        return 'loxi.generic_util.unpack_list(%s, %s.%s.unpack)' % \
+        return 'loxi.generic_util.unpack_list(%s, ofp.%s.%s.unpack)' % \
             (reader_expr, module_name, class_name)
     else:
         return "loxi.unimplemented('unpack %s')" % oftype
diff --git a/py_gen/templates/_message_extra.py b/py_gen/templates/_message_extra.py
index 9fc2f5e..adfd0e7 100644
--- a/py_gen/templates/_message_extra.py
+++ b/py_gen/templates/_message_extra.py
@@ -32,8 +32,8 @@
 
 def parse_message(buf):
     msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
-    if msg_ver != const.OFP_VERSION and msg_type != const.OFPT_HELLO:
-        raise loxi.ProtocolError("wrong OpenFlow version (expected %d, got %d)" % (const.OFP_VERSION, msg_ver))
+    if msg_ver != ofp.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
+        raise loxi.ProtocolError("wrong OpenFlow version (expected %d, got %d)" % (ofp.OFP_VERSION, msg_ver))
     if len(buf) != msg_len:
         raise loxi.ProtocolError("incorrect message size")
     return message.unpack(loxi.generic_util.OFReader(buf))
diff --git a/py_gen/templates/module.py b/py_gen/templates/module.py
index 331044d..32baac9 100644
--- a/py_gen/templates/module.py
+++ b/py_gen/templates/module.py
@@ -33,13 +33,12 @@
 
 import struct
 import loxi
-import const
-:: for module in modules:
-import ${module}
-:: #endfor
 import util
 import loxi.generic_util
 
+import sys
+ofp = sys.modules['loxi.${subdir}']
+
 :: for ofclass in ofclasses:
 :: include('_ofclass.py', ofclass=ofclass)