py_gen: adapt to of_g removal / new ir model
diff --git a/lang_python.py b/lang_python.py
index e3e6e60..f40cecc 100644
--- a/lang_python.py
+++ b/lang_python.py
@@ -62,6 +62,8 @@
 """
 
 import os
+from loxi_globals import OFVersions
+import loxi_globals
 import loxi_utils.loxi_utils as loxi_utils
 import py_gen
 import py_gen.util
@@ -101,7 +103,7 @@
     targets['%s/%s/__init__.py' % (prefix, subdir)] = make_gen('init', version)
     for module in modules[version]:
         filename = '%s/%s/%s.py' % (prefix, subdir, module)
-        targets[filename] = make_gen(module, version)
+        targets[filename] = make_gen(module, OFVersions.from_wire(version))
 
 def generate(install_dir):
     py_gen.codegen.init()
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index 3c98333..7cd068f 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -26,9 +26,8 @@
 # under the EPL.
 
 from collections import namedtuple
+import loxi_globals
 import struct
-import of_g
-import loxi_front_end.type_maps as type_maps
 import template_utils
 import loxi_utils.loxi_utils as utils
 import util
@@ -58,7 +57,7 @@
 # HACK the oftype member attribute is replaced with an OFType instance
 def build_ofclasses(version):
     ofclasses = []
-    for ofclass in of_g.ir[version].classes:
+    for ofclass in loxi_globals.ir[version].classes:
         cls = ofclass.name
         if ofclass.virtual:
             continue
@@ -82,7 +81,10 @@
                     members.append(OFTypeMember(
                         name=m.name,
                         oftype=m.oftype,
-                        value=version))
+                        value=version.wire_version,
+                        base_length=m.base_length,
+                        is_fixed_length=m.is_fixed_length,
+                        offset=m.offset))
                     type_members.append(members[-1])
                 else:
                     members.append(m)
@@ -92,8 +94,8 @@
                       pyname=generate_pyname(cls),
                       members=members,
                       type_members=type_members,
-                      min_length=of_g.base_length[(cls, version)],
-                      is_fixed_length=(cls, version) in of_g.is_fixed_length,
+                      min_length=ofclass.base_length,
+                      is_fixed_length=ofclass.is_fixed_length,
                       has_internal_alignment=cls == 'of_action_set_field',
                       has_external_alignment=cls == 'of_match_v3'))
     return ofclasses
@@ -123,7 +125,7 @@
 
 def generate_const(out, name, version):
     util.render_template(out, 'const.py', version=version,
-                         enums=of_g.ir[version].enums)
+                         enums=loxi_globals.ir[version].enums)
 
 def generate_instruction(out, name, version):
     ofclasses = [x for x in ofclasses_by_version[version]
@@ -147,5 +149,5 @@
     util.render_template(out, 'util.py', version=version)
 
 def init():
-    for version in of_g.supported_wire_protos:
+    for version in loxi_globals.OFVersions.target_versions:
         ofclasses_by_version[version] = build_ofclasses(version)
diff --git a/py_gen/oftype.py b/py_gen/oftype.py
index c378cea..b4c34f5 100644
--- a/py_gen/oftype.py
+++ b/py_gen/oftype.py
@@ -28,7 +28,6 @@
 from collections import namedtuple
 
 import loxi_utils.loxi_utils as loxi_utils
-import of_g
 
 OFTypeData = namedtuple("OFTypeData", ["init", "pack", "unpack"])
 
diff --git a/py_gen/templates/_pretty_print.py b/py_gen/templates/_pretty_print.py
index 74e6d79..c8c7770 100644
--- a/py_gen/templates/_pretty_print.py
+++ b/py_gen/templates/_pretty_print.py
@@ -24,6 +24,7 @@
 :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
+:: from loxi_globals import OFVersions
 :: import loxi_utils.loxi_utils as loxi_utils
 ::
         q.text("${ofclass.pyname} {")
@@ -49,7 +50,7 @@
                 q.text(util.pretty_mac(self.${m.name}))
 :: elif m.oftype == 'of_ipv4_t':
                 q.text(util.pretty_ipv4(self.${m.name}))
-:: elif m.oftype == 'of_wc_bmap_t' and version in [1,2]:
+:: elif m.oftype == 'of_wc_bmap_t' and version in OFVersions.from_strings("1.0", "1.1"):
                 q.text(util.pretty_wildcards(self.${m.name}))
 :: elif m.oftype == 'of_port_no_t':
                 q.text(util.pretty_port(self.${m.name}))
diff --git a/py_gen/templates/action.py b/py_gen/templates/action.py
index fcfd9a5..92c4e26 100644
--- a/py_gen/templates/action.py
+++ b/py_gen/templates/action.py
@@ -26,7 +26,7 @@
 :: # under the EPL.
 ::
 :: import itertools
-:: import of_g
+:: from loxi_globals import OFVersions
 :: import py_gen.util as util
 :: include('_copyright.py')
 
@@ -37,7 +37,7 @@
 import util
 import loxi.generic_util
 import loxi
-:: if version >= 3:
+:: if version >= OFVersions.VERSION_1_2:
 import oxm # for unpack
 :: #endif
 
diff --git a/py_gen/templates/common.py b/py_gen/templates/common.py
index 1ab2f68..76ae631 100644
--- a/py_gen/templates/common.py
+++ b/py_gen/templates/common.py
@@ -26,23 +26,23 @@
 :: # under the EPL.
 ::
 :: include('_copyright.py')
-
+:: from loxi_globals import OFVersions
 :: include('_autogen.py')
 
 import sys
 import struct
 import action
-:: if version >= 2:
+:: if version >= OFVersions.VERSION_1_1:
 import instruction # for unpack_list
 :: #endif
-:: if version >= 4:
+:: if version >= OFVersions.VERSION_1_3:
 import meter_band # for unpack_list
 :: #endif
 import const
 import util
 import loxi.generic_util
 
-:: if version >= 3:
+:: if version >= OFVersions.VERSION_1_2:
 import oxm
 :: #endif
 
@@ -94,13 +94,13 @@
 
 :: #endfor
 
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
 match = match_v1
-:: elif version == 2:
+:: elif version == OFVersions.VERSION_1_1:
 match = match_v2
-:: elif version == 3:
+:: elif version == OFVersions.VERSION_1_2:
 match = match_v3
-:: elif version == 4:
+:: elif version == OFVersions.VERSION_1_3:
 :: # HACK
 match = match_v3
 :: #endif
diff --git a/py_gen/templates/const.py b/py_gen/templates/const.py
index 4567d56..d1c00f9 100644
--- a/py_gen/templates/const.py
+++ b/py_gen/templates/const.py
@@ -24,6 +24,7 @@
 :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
+:: from loxi_globals import OFVersions
 ::
 :: blacklisted_map_groups = ['macro_definitions']
 :: blacklisted_map_idents = ['OFPFW_NW_DST_BITS', 'OFPFW_NW_SRC_BITS',
@@ -34,12 +35,12 @@
 
 :: include('_autogen.py')
 
-OFP_VERSION = ${version}
+OFP_VERSION = ${version.wire_version}
 
 :: for enum in sorted(enums, key=lambda enum: enum.name):
 # Identifiers from group ${enum.name}
 ::    for (ident, value) in enum.values:
-::        if version == 1 and ident.startswith('OFPP_'):
+::        if version == OFVersions.VERSION_1_0 and ident.startswith('OFPP_'):
 ::        # HACK loxi converts these to 32-bit
 ${ident} = ${"%#x" % (value & 0xffff)}
 ::        else:
@@ -52,7 +53,7 @@
 ::        for (ident, value) in enum.values:
 ::            if ident in blacklisted_map_idents:
 ::                pass
-::            elif version == 1 and ident.startswith('OFPP_'):
+::            elif version == OFVersions.VERSION_1_0 and ident.startswith('OFPP_'):
 ::                # HACK loxi converts these to 32-bit
     ${"%#x" % (value & 0xffff)}: ${repr(ident)},
 ::        else:
diff --git a/py_gen/templates/instruction.py b/py_gen/templates/instruction.py
index 88b0f89..978e38b 100644
--- a/py_gen/templates/instruction.py
+++ b/py_gen/templates/instruction.py
@@ -26,7 +26,6 @@
 :: # under the EPL.
 ::
 :: import itertools
-:: import of_g
 :: import py_gen.util as util
 :: include('_copyright.py')
 
diff --git a/py_gen/templates/message.py b/py_gen/templates/message.py
index c8e31c9..96b68cc 100644
--- a/py_gen/templates/message.py
+++ b/py_gen/templates/message.py
@@ -26,7 +26,8 @@
 :: # under the EPL.
 ::
 :: import itertools
-:: import of_g
+:: from loxi_globals import OFVersions
+:: import loxi_globals
 :: import py_gen.util as util
 :: import py_gen.oftype
 :: include('_copyright.py')
@@ -38,10 +39,10 @@
 import const
 import common
 import action # for unpack_list
-:: if version >= 2:
+:: if version >= OFVersions.VERSION_1_1:
 import instruction # for unpack_list
 :: #endif
-:: if version >= 4:
+:: if version >= OFVersions.VERSION_1_3:
 import meter_band # for unpack_list
 :: #endif
 import util
@@ -132,9 +133,9 @@
         raise loxi.ProtocolError("unexpected error type %u" % err_type)
 
 def parse_flow_mod(buf):
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
 :: offset = 57
-:: elif version >= 2:
+:: elif version >= OFVersions.VERSION_1_1:
 :: offset = 25
 :: #endif
     if len(buf) < ${offset} + 1:
@@ -202,18 +203,18 @@
     const.OFPET_FLOW_MOD_FAILED : flow_mod_failed_error_msg.unpack,
     const.OFPET_PORT_MOD_FAILED : port_mod_failed_error_msg.unpack,
     const.OFPET_QUEUE_OP_FAILED : queue_op_failed_error_msg.unpack,
-:: if version >= of_g.VERSION_1_1:
+:: if version >= OFVersions.VERSION_1_1:
     const.OFPET_BAD_INSTRUCTION : bad_instruction_error_msg.unpack,
     const.OFPET_BAD_MATCH : bad_match_error_msg.unpack,
     const.OFPET_GROUP_MOD_FAILED : group_mod_failed_error_msg.unpack,
     const.OFPET_TABLE_MOD_FAILED : table_mod_failed_error_msg.unpack,
     const.OFPET_SWITCH_CONFIG_FAILED : switch_config_failed_error_msg.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_2:
+:: if version >= OFVersions.VERSION_1_2:
     const.OFPET_ROLE_REQUEST_FAILED : role_request_failed_error_msg.unpack,
     const.OFPET_EXPERIMENTER : experimenter_error_msg.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_3:
+:: if version >= OFVersions.VERSION_1_3:
     const.OFPET_METER_MOD_FAILED : meter_mod_failed_error_msg.unpack,
     const.OFPET_TABLE_FEATURES_FAILED : table_features_failed_error_msg.unpack,
 :: #endif
@@ -234,14 +235,14 @@
     const.OFPST_TABLE : table_stats_reply.unpack,
     const.OFPST_PORT : port_stats_reply.unpack,
     const.OFPST_QUEUE : queue_stats_reply.unpack,
-:: if version >= of_g.VERSION_1_1:
+:: if version >= OFVersions.VERSION_1_1:
     const.OFPST_GROUP : group_stats_reply.unpack,
     const.OFPST_GROUP_DESC : group_desc_stats_reply.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_2:
+:: if version >= OFVersions.VERSION_1_2:
     const.OFPST_GROUP_FEATURES : group_features_stats_reply.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_3:
+:: if version >= OFVersions.VERSION_1_3:
     const.OFPST_METER : meter_stats_reply.unpack,
     const.OFPST_METER_CONFIG : meter_config_stats_reply.unpack,
     const.OFPST_METER_FEATURES : meter_features_stats_reply.unpack,
@@ -257,14 +258,14 @@
     const.OFPST_TABLE : table_stats_request.unpack,
     const.OFPST_PORT : port_stats_request.unpack,
     const.OFPST_QUEUE : queue_stats_request.unpack,
-:: if version >= of_g.VERSION_1_1:
+:: if version >= OFVersions.VERSION_1_1:
     const.OFPST_GROUP : group_stats_request.unpack,
     const.OFPST_GROUP_DESC : group_desc_stats_request.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_2:
+:: if version >= OFVersions.VERSION_1_2:
     const.OFPST_GROUP_FEATURES : group_features_stats_request.unpack,
 :: #endif
-:: if version >= of_g.VERSION_1_3:
+:: if version >= OFVersions.VERSION_1_3:
     const.OFPST_METER : meter_stats_request.unpack,
     const.OFPST_METER_CONFIG : meter_config_stats_request.unpack,
     const.OFPST_METER_FEATURES : meter_features_stats_request.unpack,
diff --git a/py_gen/templates/meter_band.py b/py_gen/templates/meter_band.py
index eeb9ff2..37cc6d9 100644
--- a/py_gen/templates/meter_band.py
+++ b/py_gen/templates/meter_band.py
@@ -26,7 +26,6 @@
 :: # under the EPL.
 ::
 :: import itertools
-:: import of_g
 :: import py_gen.util as util
 :: include('_copyright.py')
 
diff --git a/py_gen/templates/oxm.py b/py_gen/templates/oxm.py
index 50eb4bd..ecb52ac 100644
--- a/py_gen/templates/oxm.py
+++ b/py_gen/templates/oxm.py
@@ -26,7 +26,6 @@
 :: # under the EPL.
 ::
 :: import itertools
-:: import of_g
 :: import py_gen.oftype
 :: include('_copyright.py')
 
diff --git a/py_gen/templates/toplevel_init.py b/py_gen/templates/toplevel_init.py
index b0ee86d..b170bd8 100644
--- a/py_gen/templates/toplevel_init.py
+++ b/py_gen/templates/toplevel_init.py
@@ -25,12 +25,15 @@
 :: # EPL for the specific language governing permissions and limitations
 :: # under the EPL.
 ::
-:: import of_g
 :: include('_copyright.py')
-
+:: import loxi_globals
 :: include('_autogen.py')
 
-version_names = ${repr(of_g.param_version_names)}
+version_names = {
+:: for v in loxi_globals.OFVersions.all_supported:
+    ${v.wire_version}: "${v.version}",
+:: #endfor
+}
 
 def protocol(ver):
     """
diff --git a/py_gen/templates/util.py b/py_gen/templates/util.py
index 1566e82..50a64db 100644
--- a/py_gen/templates/util.py
+++ b/py_gen/templates/util.py
@@ -26,7 +26,7 @@
 :: # under the EPL.
 ::
 :: include('_copyright.py')
-
+:: from loxi_globals import OFVersions
 :: include('_autogen.py')
 
 import loxi
@@ -52,7 +52,7 @@
         set_flags.append("%#x" % v)
     return '|'.join(set_flags) or '0'
 
-:: if version in [1,2]:
+:: if version in (OFVersions.VERSION_1_0, OFVersions.VERSION_1_1):
 def pretty_wildcards(v):
     if v == const.OFPFW_ALL:
         return 'OFPFW_ALL'
@@ -71,70 +71,70 @@
     return v
 
 def pack_port_no(value):
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
     return struct.pack("!H", value)
 :: else:
     return struct.pack("!L", value)
 :: #endif
 
 def unpack_port_no(reader):
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
     return reader.read("!H")[0]
 :: else:
     return reader.read("!L")[0]
 :: #endif
 
 def pack_fm_cmd(value):
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
     return struct.pack("!H", value)
 :: else:
     return struct.pack("!B", value)
 :: #endif
 
 def unpack_fm_cmd(reader):
-:: if version == 1:
+:: if version == OFVersions.VERSION_1_0:
     return reader.read("!H")[0]
 :: else:
     return reader.read("!B")[0]
 :: #endif
 
 def init_wc_bmap():
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return const.OFPFW_ALL
 :: else:
     return 0
 :: #endif
 
 def pack_wc_bmap(value):
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return struct.pack("!L", value)
 :: else:
     return struct.pack("!Q", value)
 :: #endif
 
 def unpack_wc_bmap(reader):
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return reader.read("!L")[0]
 :: else:
     return reader.read("!Q")[0]
 :: #endif
 
 def init_match_bmap():
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return const.OFPFW_ALL
 :: else:
     return 0
 :: #endif
 
 def pack_match_bmap(value):
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return struct.pack("!L", value)
 :: else:
     return struct.pack("!Q", value)
 :: #endif
 
 def unpack_match_bmap(reader):
-:: if version <= 2:
+:: if version <= OFVersions.VERSION_1_1:
     return reader.read("!L")[0]
 :: else:
     return reader.read("!Q")[0]
diff --git a/py_gen/util.py b/py_gen/util.py
index 3913b9c..b405441 100644
--- a/py_gen/util.py
+++ b/py_gen/util.py
@@ -30,7 +30,7 @@
 """
 
 import os
-import of_g
+import loxi_globals
 import template_utils
 import loxi_utils.loxi_utils as utils
 
@@ -43,7 +43,7 @@
     template_utils.render_static(out, name, [templates_dir])
 
 def constant_for_value(version, group, value):
-    enums = of_g.ir[version].enums
+    enums = loxi_globals.ir[version].enums
     enum = [x for x in enums if x.name == group][0]
     for name, value2 in enum.values:
         if value == value2: