move OXM definitions into the input files

This makes the rest of the code simpler, and makes it easier to add new OXM
types in extensions.
diff --git a/loxi_front_end/match.py b/loxi_front_end/match.py
index 4ab3126..abb70ac 100644
--- a/loxi_front_end/match.py
+++ b/loxi_front_end/match.py
@@ -465,24 +465,32 @@
                 print "Key %s not found in match struct, v %s" % (key, match_v)
                 sys.exit(1)
 
-    # Check oxm list and the list above
-    for key in oxm.oxm_types:
+    # Generate list of OXM names from the unified classes
+    oxm_names = [x[7:] for x in of_g.unified.keys() if
+                 x.startswith('of_oxm_') and
+                 x.find('masked') < 0 and
+                 x.find('header') < 0]
+
+    # Check that all OXMs are in the match members
+    for key in oxm_names:
         if not key in of_match_members:
             if not (key.find("_masked") > 0):
-                debug("Key %s in oxm.oxm_types, not of_match_members" % key)
+                debug("Key %s in OXM, not of_match_members" % key)
                 sys.exit(1)
             if not key[:-7] in of_match_members:
-                debug("Key %s in oxm.oxm_types, but %s not in of_match_members"
+                debug("Key %s in OXM, but %s not in of_match_members"
                       % (key, key[:-7]))
                 sys.exit(1)
 
+    # Check that all match members are in the OXMs
     for key in of_match_members:
-        if not key in oxm.oxm_types:
-            debug("Key %s in of_match_members, not in oxm.oxm_types" % key)
+        if not key in oxm_names:
+            debug("Key %s in of_match_members, not in OXM" % key)
             sys.exit(1)
-        if of_match_members[key]["m_type"] != oxm.oxm_types[key]:
+        oxm_type = of_g.unified['of_oxm_%s' % key]['union']['value']['m_type']
+        if of_match_members[key]["m_type"] != oxm_type:
             debug("Type mismatch for key %s in oxm data: %s vs %s" %
-                  (key, of_match_members[key]["m_type"], oxm.oxm_types[key]))
+                  (key, of_match_members[key]["m_type"], oxm_type))
             sys.exit(1)
 
 
diff --git a/loxi_front_end/oxm.py b/loxi_front_end/oxm.py
index ba5c072..4327fd4 100644
--- a/loxi_front_end/oxm.py
+++ b/loxi_front_end/oxm.py
@@ -25,84 +25,6 @@
 # EPL for the specific language governing permissions and limitations
 # under the EPL.
 
-import of_g
-
-oxm_types = dict(
-    in_port               = "of_port_no_t",
-    in_port_masked        = "of_port_no_t",
-    in_phy_port           = "of_port_no_t",
-    in_phy_port_masked    = "of_port_no_t",
-    metadata              = "uint64_t",
-    metadata_masked       = "uint64_t",
-    eth_dst               = "of_mac_addr_t",
-    eth_dst_masked        = "of_mac_addr_t",
-    eth_src               = "of_mac_addr_t",
-    eth_src_masked        = "of_mac_addr_t",
-    eth_type              = "uint16_t",
-    eth_type_masked       = "uint16_t",
-    vlan_vid              = "uint16_t",
-    vlan_vid_masked       = "uint16_t",
-    vlan_pcp              = "uint8_t",
-    vlan_pcp_masked       = "uint8_t",
-    ip_dscp               = "uint8_t",
-    ip_dscp_masked        = "uint8_t",
-    ip_ecn                = "uint8_t",
-    ip_ecn_masked         = "uint8_t",
-    ip_proto              = "uint8_t",
-    ip_proto_masked       = "uint8_t",
-    ipv4_src              = "uint32_t",
-    ipv4_src_masked       = "uint32_t",
-    ipv4_dst              = "uint32_t",
-    ipv4_dst_masked       = "uint32_t",
-    tcp_src               = "uint16_t",
-    tcp_src_masked        = "uint16_t",
-    tcp_dst               = "uint16_t",
-    tcp_dst_masked        = "uint16_t",
-    udp_src               = "uint16_t",
-    udp_src_masked        = "uint16_t",
-    udp_dst               = "uint16_t",
-    udp_dst_masked        = "uint16_t",
-    sctp_src              = "uint16_t",
-    sctp_src_masked       = "uint16_t",
-    sctp_dst              = "uint16_t",
-    sctp_dst_masked       = "uint16_t",
-    icmpv4_type           = "uint8_t",
-    icmpv4_type_masked    = "uint8_t",
-    icmpv4_code           = "uint8_t",
-    icmpv4_code_masked    = "uint8_t",
-    arp_op                = "uint16_t",
-    arp_op_masked         = "uint16_t",
-    arp_spa               = "uint32_t",
-    arp_spa_masked        = "uint32_t",
-    arp_tpa               = "uint32_t",
-    arp_tpa_masked        = "uint32_t",
-    arp_sha               = "of_mac_addr_t",
-    arp_sha_masked        = "of_mac_addr_t",
-    arp_tha               = "of_mac_addr_t",
-    arp_tha_masked        = "of_mac_addr_t",
-    ipv6_src              = "of_ipv6_t",
-    ipv6_src_masked       = "of_ipv6_t",
-    ipv6_dst              = "of_ipv6_t",
-    ipv6_dst_masked       = "of_ipv6_t",
-    ipv6_flabel           = "uint32_t",
-    ipv6_flabel_masked    = "uint32_t",
-    icmpv6_type           = "uint8_t",
-    icmpv6_type_masked    = "uint8_t",
-    icmpv6_code           = "uint8_t",
-    icmpv6_code_masked    = "uint8_t",
-    ipv6_nd_target        = "of_ipv6_t",
-    ipv6_nd_target_masked = "of_ipv6_t",
-    ipv6_nd_sll           = "of_mac_addr_t",
-    ipv6_nd_sll_masked    = "of_mac_addr_t",
-    ipv6_nd_tll           = "of_mac_addr_t",
-    ipv6_nd_tll_masked    = "of_mac_addr_t",
-    mpls_label            = "uint32_t",
-    mpls_label_masked     = "uint32_t",
-    mpls_tc               = "uint8_t",
-    mpls_tc_masked        = "uint8_t"
-    # FIXME Add 1.3 oxm elts
-    )
-
 oxm_wire_type = dict(
     in_port               = (0 << 1),
     in_port_masked        = (0 << 1) + 1,
@@ -178,51 +100,3 @@
     mpls_tc_masked        = (35 << 1) + 1
     # FIXME Add 1.3 oxm elts
 )
-
-def add_oxm_classes_1_2(classes, version):
-    """
-    Add the OXM classes to object passed.  This is a dictionary
-    indexed by class name whose value is an array of member objects.
-    """
-    # First the parent class:
-    if version not in [of_g.VERSION_1_2, of_g.VERSION_1_3]:
-        return
-
-    members = []
-    classes["of_oxm"] = []
-    of_g.ordered_classes[version].append("of_oxm")
-    members.append(dict(name="type_len", m_type="uint32_t"))
-    classes["of_oxm_header"] = members
-    of_g.ordered_classes[version].append("of_oxm_header")
-
-    for oxm in oxm_types:
-        members = []
-        # Assert oxm_types[oxm] in of_base_types
-        m_type = oxm_types[oxm]
-        if m_type in of_g.of_mixed_types:
-            m_type = of_g.of_mixed_types[m_type][version]
-        # m_name = "value_" + of_g.of_base_types[m_type]["short_name"]
-        members.append(dict(name="type_len", m_type="uint32_t"))
-        # members.append(dict(name=m_name, m_type=oxm_types[oxm]))
-        members.append(dict(name="value", m_type=oxm_types[oxm]))
-        if oxm.find("_masked") > 0:
-            members.append(dict(name="value_mask", m_type=oxm_types[oxm]))
-
-        name = "of_oxm_" + oxm
-        of_g.ordered_classes[version].append(name)
-        classes[name] = members
-
-# /* Header for OXM experimenter match fields. */
-# struct ofp_oxm_experimenter_header {
-#     uint32_t oxm_header;        /* oxm_class = OFPXMC_EXPERIMENTER */
-#     uint32_t experimenter;      /* Experimenter ID which takes the same
-#                                    form as in struct ofp_experimenter_header. */
-# };
-
-
-# enum ofp_vlan_id {
-#     OFPVID_PRESENT = 0x1000,
-#     OFPVID_NONE    = 0x0000,
-# };
-
-# #define OFP_VLAN_NONE      OFPVID_NONE
diff --git a/loxigen.py b/loxigen.py
index d2212de..112fbf6 100755
--- a/loxigen.py
+++ b/loxigen.py
@@ -458,16 +458,6 @@
             ofprotocol.classes.sort(key=lambda ofclass: ofclass.name)
             of_g.ir[wire_version] = ofprotocol
 
-def add_extra_classes():
-    """
-    Add classes that are generated by Python code instead of from the
-    input files.
-    """
-
-    for wire_version in [of_g.VERSION_1_2, of_g.VERSION_1_3]:
-        version_name = of_g.of_version_wire2name[wire_version]
-        oxm.add_oxm_classes_1_2(versions[version_name]['classes'], wire_version)
-
 def analyze_input():
     """
     Add information computed from the input, including offsets and
@@ -580,7 +570,6 @@
 
     initialize_versions()
     read_input()
-    add_extra_classes()
     analyze_input()
     unify_input()
     order_and_assign_object_ids()
diff --git a/openflow_input/oxm-1.2 b/openflow_input/oxm-1.2
new file mode 100644
index 0000000..a28d88b
--- /dev/null
+++ b/openflow_input/oxm-1.2
@@ -0,0 +1,435 @@
+// Copyright 2013, Big Switch Networks, Inc.
+//
+// LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+// the following special exception:
+//
+// LOXI Exception
+//
+// As a special exception to the terms of the EPL, you may distribute libraries
+// generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+// that copyright and licensing notices generated by LoxiGen are not altered or removed
+// from the LoxiGen Libraries and the notice provided below is (i) included in
+// the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+// documentation for the LoxiGen Libraries, if distributed in binary form.
+//
+// Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+//
+// You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+// a copy of the EPL at:
+//
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// EPL for the specific language governing permissions and limitations
+// under the EPL.
+//
+// Also derived from the OpenFlow header files which have these copyrights:
+// Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
+// Copyright (c) 2011, 2012 Open Networking Foundation
+
+#version 3
+#version 4
+
+/* TODO fix the C backend to not require this */
+struct of_oxm {
+    uint32_t type_len;
+};
+
+
+struct of_oxm_arp_op {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_arp_op_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_arp_sha {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_arp_sha_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_arp_spa {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_arp_spa_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_arp_tha {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_arp_tha_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_arp_tpa {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_arp_tpa_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_eth_dst {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_eth_dst_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_eth_src {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_eth_src_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_eth_type {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_eth_type_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_icmpv4_code {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_icmpv4_code_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_icmpv4_type {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_icmpv4_type_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_icmpv6_code {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_icmpv6_code_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_icmpv6_type {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_icmpv6_type_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_in_phy_port {
+    uint32_t type_len;
+    of_port_no_t value;
+};
+
+struct of_oxm_in_phy_port_masked {
+    uint32_t type_len;
+    of_port_no_t value;
+    of_port_no_t value_mask;
+};
+
+struct of_oxm_in_port {
+    uint32_t type_len;
+    of_port_no_t value;
+};
+
+struct of_oxm_in_port_masked {
+    uint32_t type_len;
+    of_port_no_t value;
+    of_port_no_t value_mask;
+};
+
+struct of_oxm_ip_dscp {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_ip_dscp_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_ip_ecn {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_ip_ecn_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_ip_proto {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_ip_proto_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_ipv4_dst {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_ipv4_dst_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_ipv4_src {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_ipv4_src_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_ipv6_dst {
+    uint32_t type_len;
+    of_ipv6_t value;
+};
+
+struct of_oxm_ipv6_dst_masked {
+    uint32_t type_len;
+    of_ipv6_t value;
+    of_ipv6_t value_mask;
+};
+
+struct of_oxm_ipv6_flabel {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_ipv6_flabel_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_ipv6_nd_sll {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_ipv6_nd_sll_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_ipv6_nd_target {
+    uint32_t type_len;
+    of_ipv6_t value;
+};
+
+struct of_oxm_ipv6_nd_target_masked {
+    uint32_t type_len;
+    of_ipv6_t value;
+    of_ipv6_t value_mask;
+};
+
+struct of_oxm_ipv6_nd_tll {
+    uint32_t type_len;
+    of_mac_addr_t value;
+};
+
+struct of_oxm_ipv6_nd_tll_masked {
+    uint32_t type_len;
+    of_mac_addr_t value;
+    of_mac_addr_t value_mask;
+};
+
+struct of_oxm_ipv6_src {
+    uint32_t type_len;
+    of_ipv6_t value;
+};
+
+struct of_oxm_ipv6_src_masked {
+    uint32_t type_len;
+    of_ipv6_t value;
+    of_ipv6_t value_mask;
+};
+
+struct of_oxm_metadata {
+    uint32_t type_len;
+    uint64_t value;
+};
+
+struct of_oxm_metadata_masked {
+    uint32_t type_len;
+    uint64_t value;
+    uint64_t value_mask;
+};
+
+struct of_oxm_mpls_label {
+    uint32_t type_len;
+    uint32_t value;
+};
+
+struct of_oxm_mpls_label_masked {
+    uint32_t type_len;
+    uint32_t value;
+    uint32_t value_mask;
+};
+
+struct of_oxm_mpls_tc {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_mpls_tc_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_sctp_dst {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_sctp_dst_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_sctp_src {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_sctp_src_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_tcp_dst {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_tcp_dst_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_tcp_src {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_tcp_src_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_udp_dst {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_udp_dst_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_udp_src {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_udp_src_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};
+
+struct of_oxm_vlan_pcp {
+    uint32_t type_len;
+    uint8_t value;
+};
+
+struct of_oxm_vlan_pcp_masked {
+    uint32_t type_len;
+    uint8_t value;
+    uint8_t value_mask;
+};
+
+struct of_oxm_vlan_vid {
+    uint32_t type_len;
+    uint16_t value;
+};
+
+struct of_oxm_vlan_vid_masked {
+    uint32_t type_len;
+    uint16_t value;
+    uint16_t value_mask;
+};