py_gen: adapt to of_g removal / new ir model
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]