update pyloxi to 026ff024585f1588a7f11fa4c1a9a48d44dc098d
diff --git a/src/python/loxi/of10/action.py b/src/python/loxi/of10/action.py
index 6a3abfb..38b674c 100644
--- a/src/python/loxi/of10/action.py
+++ b/src/python/loxi/of10/action.py
@@ -3,27 +3,59 @@
 # Copyright (c) 2012, 2013 Big Switch Networks, Inc.
 # See the file LICENSE.pyloxi which should have been included in the source distribution
 
-# Automatically generated by LOXI from template action.py
+# Automatically generated by LOXI from template module.py
 # Do not modify
 
 import struct
+import loxi
 import const
+import common
+import action
 import util
 import loxi.generic_util
-import loxi
 
-def unpack_list(reader):
-    def deserializer(reader, typ):
-        parser = parsers.get(typ)
-        if not parser: raise loxi.ProtocolError("unknown action type %d" % typ)
-        return parser(reader)
-    return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+class action(loxi.OFObject):
+    subtypes = {}
 
-class Action(object):
-    type = None # override in subclass
-    pass
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 0)
+        try:
+            subclass = action.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown action subtype %#x" % subtype)
+        return subclass.unpack(reader)
 
-class bsn_mirror(Action):
+
+class experimenter(action):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 4)
+        try:
+            subclass = experimenter.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown experimenter action subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+action.subtypes[65535] = experimenter
+
+class bsn(experimenter):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 8)
+        try:
+            subclass = bsn.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn experimenter action subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter.subtypes[6035143] = bsn
+
+class bsn_mirror(bsn):
     type = 65535
     experimenter = 6035143
     subtype = 1
@@ -58,15 +90,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = bsn_mirror()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 65535)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
         _subtype = reader.read("!L")[0]
@@ -84,13 +114,6 @@
         if self.copy_stage != other.copy_stage: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_mirror {")
         with q.group():
@@ -107,7 +130,9 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_tunnel_dst(Action):
+bsn.subtypes[1] = bsn_mirror
+
+class bsn_set_tunnel_dst(bsn):
     type = 65535
     experimenter = 6035143
     subtype = 2
@@ -131,15 +156,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = bsn_set_tunnel_dst()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 65535)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
         _subtype = reader.read("!L")[0]
@@ -152,13 +175,6 @@
         if self.dst != other.dst: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_tunnel_dst {")
         with q.group():
@@ -169,7 +185,9 @@
             q.breakable()
         q.text('}')
 
-class enqueue(Action):
+bsn.subtypes[2] = bsn_set_tunnel_dst
+
+class enqueue(action):
     type = 11
 
     def __init__(self, port=None, queue_id=None):
@@ -195,15 +213,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = enqueue()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 11)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.port = util.unpack_port_no(reader)
         reader.skip(6)
         obj.queue_id = reader.read("!L")[0]
@@ -215,13 +231,6 @@
         if self.queue_id != other.queue_id: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("enqueue {")
         with q.group():
@@ -235,7 +244,23 @@
             q.breakable()
         q.text('}')
 
-class nicira_dec_ttl(Action):
+action.subtypes[11] = enqueue
+
+class nicira(experimenter):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 8)
+        try:
+            subclass = nicira.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown nicira experimenter action subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter.subtypes[8992] = nicira
+
+class nicira_dec_ttl(nicira):
     type = 65535
     experimenter = 8992
     subtype = 18
@@ -256,15 +281,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = nicira_dec_ttl()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 65535)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 8992)
         _subtype = reader.read("!H")[0]
@@ -277,13 +300,6 @@
         if type(self) != type(other): return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("nicira_dec_ttl {")
         with q.group():
@@ -292,7 +308,9 @@
             q.breakable()
         q.text('}')
 
-class output(Action):
+nicira.subtypes[18] = nicira_dec_ttl
+
+class output(action):
     type = 0
 
     def __init__(self, port=None, max_len=None):
@@ -317,15 +335,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = output()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 0)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.port = util.unpack_port_no(reader)
         obj.max_len = reader.read("!H")[0]
         return obj
@@ -336,13 +352,6 @@
         if self.max_len != other.max_len: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("output {")
         with q.group():
@@ -356,7 +365,9 @@
             q.breakable()
         q.text('}')
 
-class set_dl_dst(Action):
+action.subtypes[0] = output
+
+class set_dl_dst(action):
     type = 5
 
     def __init__(self, dl_addr=None):
@@ -377,15 +388,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_dl_dst()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 5)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.dl_addr = list(reader.read('!6B'))
         reader.skip(6)
         return obj
@@ -395,13 +404,6 @@
         if self.dl_addr != other.dl_addr: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_dl_dst {")
         with q.group():
@@ -412,7 +414,9 @@
             q.breakable()
         q.text('}')
 
-class set_dl_src(Action):
+action.subtypes[5] = set_dl_dst
+
+class set_dl_src(action):
     type = 4
 
     def __init__(self, dl_addr=None):
@@ -433,15 +437,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_dl_src()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 4)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.dl_addr = list(reader.read('!6B'))
         reader.skip(6)
         return obj
@@ -451,13 +453,6 @@
         if self.dl_addr != other.dl_addr: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_dl_src {")
         with q.group():
@@ -468,7 +463,9 @@
             q.breakable()
         q.text('}')
 
-class set_nw_dst(Action):
+action.subtypes[4] = set_dl_src
+
+class set_nw_dst(action):
     type = 7
 
     def __init__(self, nw_addr=None):
@@ -488,15 +485,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_nw_dst()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 7)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.nw_addr = reader.read("!L")[0]
         return obj
 
@@ -505,13 +500,6 @@
         if self.nw_addr != other.nw_addr: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_nw_dst {")
         with q.group():
@@ -522,7 +510,9 @@
             q.breakable()
         q.text('}')
 
-class set_nw_src(Action):
+action.subtypes[7] = set_nw_dst
+
+class set_nw_src(action):
     type = 6
 
     def __init__(self, nw_addr=None):
@@ -542,15 +532,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_nw_src()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 6)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.nw_addr = reader.read("!L")[0]
         return obj
 
@@ -559,13 +547,6 @@
         if self.nw_addr != other.nw_addr: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_nw_src {")
         with q.group():
@@ -576,7 +557,9 @@
             q.breakable()
         q.text('}')
 
-class set_nw_tos(Action):
+action.subtypes[6] = set_nw_src
+
+class set_nw_tos(action):
     type = 8
 
     def __init__(self, nw_tos=None):
@@ -597,15 +580,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_nw_tos()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 8)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.nw_tos = reader.read("!B")[0]
         reader.skip(3)
         return obj
@@ -615,13 +596,6 @@
         if self.nw_tos != other.nw_tos: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_nw_tos {")
         with q.group():
@@ -632,7 +606,9 @@
             q.breakable()
         q.text('}')
 
-class set_tp_dst(Action):
+action.subtypes[8] = set_nw_tos
+
+class set_tp_dst(action):
     type = 10
 
     def __init__(self, tp_port=None):
@@ -653,15 +629,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_tp_dst()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 10)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.tp_port = reader.read("!H")[0]
         reader.skip(2)
         return obj
@@ -671,13 +645,6 @@
         if self.tp_port != other.tp_port: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_tp_dst {")
         with q.group():
@@ -688,7 +655,9 @@
             q.breakable()
         q.text('}')
 
-class set_tp_src(Action):
+action.subtypes[10] = set_tp_dst
+
+class set_tp_src(action):
     type = 9
 
     def __init__(self, tp_port=None):
@@ -709,15 +678,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_tp_src()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 9)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.tp_port = reader.read("!H")[0]
         reader.skip(2)
         return obj
@@ -727,13 +694,6 @@
         if self.tp_port != other.tp_port: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_tp_src {")
         with q.group():
@@ -744,7 +704,9 @@
             q.breakable()
         q.text('}')
 
-class set_vlan_pcp(Action):
+action.subtypes[9] = set_tp_src
+
+class set_vlan_pcp(action):
     type = 2
 
     def __init__(self, vlan_pcp=None):
@@ -765,15 +727,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_vlan_pcp()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 2)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.vlan_pcp = reader.read("!B")[0]
         reader.skip(3)
         return obj
@@ -783,13 +743,6 @@
         if self.vlan_pcp != other.vlan_pcp: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_vlan_pcp {")
         with q.group():
@@ -800,7 +753,9 @@
             q.breakable()
         q.text('}')
 
-class set_vlan_vid(Action):
+action.subtypes[2] = set_vlan_pcp
+
+class set_vlan_vid(action):
     type = 1
 
     def __init__(self, vlan_vid=None):
@@ -821,15 +776,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = set_vlan_vid()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 1)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.vlan_vid = reader.read("!H")[0]
         reader.skip(2)
         return obj
@@ -839,13 +792,6 @@
         if self.vlan_vid != other.vlan_vid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_vlan_vid {")
         with q.group():
@@ -856,7 +802,9 @@
             q.breakable()
         q.text('}')
 
-class strip_vlan(Action):
+action.subtypes[1] = set_vlan_vid
+
+class strip_vlan(action):
     type = 3
 
     def __init__(self):
@@ -872,15 +820,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = strip_vlan()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 3)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
         return obj
 
@@ -888,13 +834,6 @@
         if type(self) != type(other): return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("strip_vlan {")
         with q.group():
@@ -903,43 +842,6 @@
             q.breakable()
         q.text('}')
 
+action.subtypes[3] = strip_vlan
 
-def parse_experimenter(reader):
-    experimenter, = reader.peek("!4xL")
-    if experimenter == 0x005c16c7: # Big Switch Networks
-        subtype, = reader.peek("!8xL")
-    elif experimenter == 0x00002320: # Nicira
-        subtype, = reader.peek("!8xH")
-    else:
-        raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
 
-    if subtype in experimenter_parsers[experimenter]:
-        return experimenter_parsers[experimenter][subtype](reader)
-    else:
-        raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
-
-parsers = {
-    const.OFPAT_OUTPUT : output.unpack,
-    const.OFPAT_SET_VLAN_VID : set_vlan_vid.unpack,
-    const.OFPAT_SET_VLAN_PCP : set_vlan_pcp.unpack,
-    const.OFPAT_STRIP_VLAN : strip_vlan.unpack,
-    const.OFPAT_SET_DL_SRC : set_dl_src.unpack,
-    const.OFPAT_SET_DL_DST : set_dl_dst.unpack,
-    const.OFPAT_SET_NW_SRC : set_nw_src.unpack,
-    const.OFPAT_SET_NW_DST : set_nw_dst.unpack,
-    const.OFPAT_SET_NW_TOS : set_nw_tos.unpack,
-    const.OFPAT_SET_TP_SRC : set_tp_src.unpack,
-    const.OFPAT_SET_TP_DST : set_tp_dst.unpack,
-    const.OFPAT_ENQUEUE : enqueue.unpack,
-    const.OFPAT_EXPERIMENTER : parse_experimenter,
-}
-
-experimenter_parsers = {
-    8992 : {
-        18: nicira_dec_ttl.unpack,
-    },
-    6035143 : {
-        1: bsn_mirror.unpack,
-        2: bsn_set_tunnel_dst.unpack,
-    },
-}
diff --git a/src/python/loxi/of10/common.py b/src/python/loxi/of10/common.py
index 481b686..ec788ed 100644
--- a/src/python/loxi/of10/common.py
+++ b/src/python/loxi/of10/common.py
@@ -2,61 +2,19 @@
 # Copyright (c) 2011, 2012 Open Networking Foundation
 # Copyright (c) 2012, 2013 Big Switch Networks, Inc.
 # See the file LICENSE.pyloxi which should have been included in the source distribution
-# Automatically generated by LOXI from template common.py
+
+# Automatically generated by LOXI from template module.py
 # Do not modify
 
-import sys
 import struct
-import action
+import loxi
 import const
+import common
+import action
 import util
 import loxi.generic_util
 
-
-# HACK make this module visible as 'common' to simplify code generation
-common = sys.modules[__name__]
-
-def unpack_list_flow_stats_entry(reader):
-    return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
-
-def unpack_list_queue_prop(reader):
-    def deserializer(reader, typ):
-        if typ == const.OFPQT_MIN_RATE:
-            return queue_prop_min_rate.unpack(reader)
-        else:
-            raise loxi.ProtocolError("unknown queue prop %d" % typ)
-    return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
-
-def unpack_list_packet_queue(reader):
-    def wrapper(reader):
-        length, = reader.peek('!4xH')
-        return packet_queue.unpack(reader.slice(length))
-    return loxi.generic_util.unpack_list(reader, wrapper)
-
-def unpack_list_hello_elem(reader):
-    def deserializer(reader, typ):
-        if typ == const.OFPHET_VERSIONBITMAP:
-            return hello_elem_versionbitmap.unpack(reader)
-        else:
-            return None
-    return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
-
-def unpack_list_bucket(reader):
-    return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
-
-def unpack_list_group_desc_stats_entry(reader):
-    return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
-
-def unpack_list_group_stats_entry(reader):
-    return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
-
-def unpack_list_meter_stats(reader):
-    def wrapper(reader):
-        length, = reader.peek('!4xH')
-        return meter_stats.unpack(reader.slice(length))
-    return loxi.generic_util.unpack_list(reader, wrapper)
-
-class bsn_interface(object):
+class bsn_interface(loxi.OFObject):
 
     def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None):
         if hw_addr != None:
@@ -87,12 +45,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = bsn_interface()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.hw_addr = list(reader.read('!6B'))
         reader.skip(2)
         obj.name = reader.read("!16s")[0].rstrip("\x00")
@@ -108,13 +62,6 @@
         if self.ipv4_netmask != other.ipv4_netmask: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_interface {")
         with q.group():
@@ -134,7 +81,21 @@
             q.breakable()
         q.text('}')
 
-class bsn_vport_q_in_q(object):
+
+class bsn_vport(loxi.OFObject):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 0)
+        try:
+            subclass = bsn_vport.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn_vport subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+
+class bsn_vport_q_in_q(bsn_vport):
     type = 0
 
     def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None, if_name=None):
@@ -179,15 +140,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = bsn_vport_q_in_q()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 0)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.port_no = reader.read("!L")[0]
         obj.ingress_tpid = reader.read("!H")[0]
         obj.ingress_vlan_id = reader.read("!H")[0]
@@ -206,13 +165,6 @@
         if self.if_name != other.if_name: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_vport_q_in_q {")
         with q.group():
@@ -238,7 +190,9 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_entry(object):
+bsn_vport.subtypes[0] = bsn_vport_q_in_q
+
+class flow_stats_entry(loxi.OFObject):
 
     def __init__(self, table_id=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, actions=None):
         if table_id != None:
@@ -302,19 +256,17 @@
         packed.append(struct.pack("!Q", self.cookie))
         packed.append(struct.pack("!Q", self.packet_count))
         packed.append(struct.pack("!Q", self.byte_count))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[0] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = flow_stats_entry()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (0 + 2))
         obj.table_id = reader.read("!B")[0]
         reader.skip(1)
         obj.match = common.match.unpack(reader)
@@ -327,7 +279,7 @@
         obj.cookie = reader.read("!Q")[0]
         obj.packet_count = reader.read("!Q")[0]
         obj.byte_count = reader.read("!Q")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
@@ -345,13 +297,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_stats_entry {")
         with q.group():
@@ -392,7 +337,8 @@
             q.breakable()
         q.text('}')
 
-class match_v1(object):
+
+class match_v1(loxi.OFObject):
 
     def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
         if wildcards != None:
@@ -469,12 +415,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = match_v1()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.wildcards = util.unpack_wc_bmap(reader)
         obj.in_port = util.unpack_port_no(reader)
         obj.eth_src = list(reader.read('!6B'))
@@ -509,13 +451,6 @@
         if self.tcp_dst != other.tcp_dst: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("match_v1 {")
         with q.group():
@@ -562,7 +497,8 @@
             q.breakable()
         q.text('}')
 
-class packet_queue(object):
+
+class packet_queue(loxi.OFObject):
 
     def __init__(self, queue_id=None, properties=None):
         if queue_id != None:
@@ -580,22 +516,20 @@
         packed.append(struct.pack("!L", self.queue_id))
         packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
         packed.append('\x00' * 2)
-        packed.append(util.pack_list(self.properties))
+        packed.append(loxi.generic_util.pack_list(self.properties))
         length = sum([len(x) for x in packed])
         packed[1] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = packet_queue()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.queue_id = reader.read("!L")[0]
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (4 + 2))
         reader.skip(2)
-        obj.properties = common.unpack_list_queue_prop(reader)
+        obj.properties = loxi.generic_util.unpack_list(reader, common.queue_prop.unpack)
         return obj
 
     def __eq__(self, other):
@@ -604,13 +538,6 @@
         if self.properties != other.properties: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("packet_queue {")
         with q.group():
@@ -624,7 +551,8 @@
             q.breakable()
         q.text('}')
 
-class port_desc(object):
+
+class port_desc(loxi.OFObject):
 
     def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
         if port_no != None:
@@ -679,12 +607,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = port_desc()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.port_no = util.unpack_port_no(reader)
         obj.hw_addr = list(reader.read('!6B'))
         obj.name = reader.read("!16s")[0].rstrip("\x00")
@@ -709,13 +633,6 @@
         if self.peer != other.peer: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_desc {")
         with q.group():
@@ -750,7 +667,8 @@
             q.breakable()
         q.text('}')
 
-class port_stats_entry(object):
+
+class port_stats_entry(loxi.OFObject):
 
     def __init__(self, port_no=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None):
         if port_no != None:
@@ -826,12 +744,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = port_stats_entry()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.port_no = util.unpack_port_no(reader)
         reader.skip(6)
         obj.rx_packets = reader.read("!Q")[0]
@@ -865,13 +779,6 @@
         if self.collisions != other.collisions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_stats_entry {")
         with q.group():
@@ -918,7 +825,21 @@
             q.breakable()
         q.text('}')
 
-class queue_prop_min_rate(object):
+
+class queue_prop(loxi.OFObject):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 0)
+        try:
+            subclass = queue_prop.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown queue_prop subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+
+class queue_prop_min_rate(queue_prop):
     type = 1
 
     def __init__(self, rate=None):
@@ -940,15 +861,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = queue_prop_min_rate()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 1)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
         obj.rate = reader.read("!H")[0]
         reader.skip(6)
@@ -959,13 +878,6 @@
         if self.rate != other.rate: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_prop_min_rate {")
         with q.group():
@@ -976,7 +888,9 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_entry(object):
+queue_prop.subtypes[1] = queue_prop_min_rate
+
+class queue_stats_entry(loxi.OFObject):
 
     def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
         if port_no != None:
@@ -1012,12 +926,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = queue_stats_entry()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.port_no = util.unpack_port_no(reader)
         reader.skip(2)
         obj.queue_id = reader.read("!L")[0]
@@ -1035,13 +945,6 @@
         if self.tx_errors != other.tx_errors: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_stats_entry {")
         with q.group():
@@ -1064,7 +967,8 @@
             q.breakable()
         q.text('}')
 
-class table_stats_entry(object):
+
+class table_stats_entry(loxi.OFObject):
 
     def __init__(self, table_id=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
         if table_id != None:
@@ -1110,12 +1014,8 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = table_stats_entry()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         obj.table_id = reader.read("!B")[0]
         reader.skip(3)
         obj.name = reader.read("!32s")[0].rstrip("\x00")
@@ -1137,13 +1037,6 @@
         if self.matched_count != other.matched_count: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("table_stats_entry {")
         with q.group():
@@ -1173,4 +1066,5 @@
         q.text('}')
 
 
+
 match = match_v1
diff --git a/src/python/loxi/of10/message.py b/src/python/loxi/of10/message.py
index 9b12a07..bbf774a 100644
--- a/src/python/loxi/of10/message.py
+++ b/src/python/loxi/of10/message.py
@@ -3,29 +3,54 @@
 # Copyright (c) 2012, 2013 Big Switch Networks, Inc.
 # See the file LICENSE.pyloxi which should have been included in the source distribution
 
-# Automatically generated by LOXI from template message.py
+# Automatically generated by LOXI from template module.py
 # Do not modify
 
 import struct
 import loxi
 import const
 import common
-import action # for unpack_list
+import action
 import util
 import loxi.generic_util
 
-class Message(object):
-    version = const.OFP_VERSION
-    type = None # override in subclass
-    xid = None
+class message(loxi.OFObject):
+    subtypes = {}
 
-class aggregate_stats_reply(Message):
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('B', 1)
+        try:
+            subclass = message.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+
+class stats_reply(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 8)
+        try:
+            subclass = stats_reply.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown stats_reply message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[17] = stats_reply
+
+class aggregate_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 2
 
     def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -42,6 +67,7 @@
             self.flow_count = flow_count
         else:
             self.flow_count = 0
+        return
 
     def pack(self):
         packed = []
@@ -60,18 +86,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = aggregate_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 2)
@@ -84,8 +107,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.packet_count != other.packet_count: return False
@@ -93,16 +114,6 @@
         if self.flow_count != other.flow_count: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("aggregate_stats_reply {")
         with q.group():
@@ -128,13 +139,32 @@
             q.breakable()
         q.text('}')
 
-class aggregate_stats_request(Message):
+stats_reply.subtypes[2] = aggregate_stats_reply
+
+class stats_request(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 8)
+        try:
+            subclass = stats_request.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown stats_request message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[16] = stats_request
+
+class aggregate_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 2
 
     def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -151,6 +181,7 @@
             self.out_port = out_port
         else:
             self.out_port = 0
+        return
 
     def pack(self):
         packed = []
@@ -169,18 +200,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = aggregate_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 2)
@@ -193,8 +221,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.match != other.match: return False
@@ -202,16 +228,6 @@
         if self.out_port != other.out_port: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("aggregate_stats_request {")
         with q.group():
@@ -237,13 +253,32 @@
             q.breakable()
         q.text('}')
 
-class bad_action_error_msg(Message):
+stats_request.subtypes[2] = aggregate_stats_request
+
+class error_msg(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 8)
+        try:
+            subclass = error_msg.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown error_msg message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[1] = error_msg
+
+class bad_action_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 2
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -252,6 +287,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -267,18 +303,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bad_action_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 2)
@@ -288,23 +321,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bad_action_error_msg {")
         with q.group():
@@ -324,13 +345,18 @@
             q.breakable()
         q.text('}')
 
-class bad_request_error_msg(Message):
+error_msg.subtypes[2] = bad_action_error_msg
+
+class bad_request_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 1
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -339,6 +365,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -354,18 +381,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bad_request_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 1)
@@ -375,23 +399,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bad_request_error_msg {")
         with q.group():
@@ -411,12 +423,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_reply(Message):
+error_msg.subtypes[1] = bad_request_error_msg
+
+class barrier_reply(message):
     version = 1
     type = 19
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -429,38 +447,23 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = barrier_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 19)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("barrier_reply {")
         with q.group():
@@ -474,12 +477,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_request(Message):
+message.subtypes[19] = barrier_reply
+
+class barrier_request(message):
     version = 1
     type = 18
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -492,38 +501,23 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = barrier_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 18)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("barrier_request {")
         with q.group():
@@ -537,18 +531,52 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_clear_data_reply(Message):
+message.subtypes[18] = barrier_request
+
+class experimenter(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 8)
+        try:
+            subclass = experimenter.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown experimenter message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[4] = experimenter
+
+class bsn_header(experimenter):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 12)
+        try:
+            subclass = bsn_header.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn_header experimenter message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter.subtypes[6035143] = bsn_header
+
+class bsn_bw_clear_data_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 22
 
     def __init__(self, xid=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -564,18 +592,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_clear_data_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -586,22 +611,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_clear_data_reply {")
         with q.group():
@@ -618,14 +631,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_clear_data_request(Message):
+bsn_header.subtypes[22] = bsn_bw_clear_data_reply
+
+class bsn_bw_clear_data_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 21
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -640,18 +659,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_clear_data_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -661,21 +677,9 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_clear_data_request {")
         with q.group():
@@ -689,18 +693,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_enable_get_reply(Message):
+bsn_header.subtypes[21] = bsn_bw_clear_data_request
+
+class bsn_bw_enable_get_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 20
 
     def __init__(self, xid=None, enabled=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if enabled != None:
             self.enabled = enabled
         else:
             self.enabled = 0
+        return
 
     def pack(self):
         packed = []
@@ -716,18 +726,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_enable_get_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -738,22 +745,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.enabled != other.enabled: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_enable_get_reply {")
         with q.group():
@@ -770,14 +765,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_enable_get_request(Message):
+bsn_header.subtypes[20] = bsn_bw_enable_get_reply
+
+class bsn_bw_enable_get_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 19
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -792,18 +793,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_enable_get_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -813,21 +811,9 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_enable_get_request {")
         with q.group():
@@ -841,14 +827,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_enable_set_reply(Message):
+bsn_header.subtypes[19] = bsn_bw_enable_get_request
+
+class bsn_bw_enable_set_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 23
 
     def __init__(self, xid=None, enable=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if enable != None:
             self.enable = enable
         else:
@@ -857,6 +848,7 @@
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -873,18 +865,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_enable_set_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -896,23 +885,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.enable != other.enable: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_enable_set_reply {")
         with q.group():
@@ -932,18 +909,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_enable_set_request(Message):
+bsn_header.subtypes[23] = bsn_bw_enable_set_reply
+
+class bsn_bw_enable_set_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 18
 
     def __init__(self, xid=None, enable=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if enable != None:
             self.enable = enable
         else:
             self.enable = 0
+        return
 
     def pack(self):
         packed = []
@@ -959,18 +942,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_bw_enable_set_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -981,22 +961,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.enable != other.enable: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_bw_enable_set_request {")
         with q.group():
@@ -1013,18 +981,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_interfaces_reply(Message):
+bsn_header.subtypes[18] = bsn_bw_enable_set_request
+
+class bsn_get_interfaces_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 10
 
     def __init__(self, xid=None, interfaces=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if interfaces != None:
             self.interfaces = interfaces
         else:
             self.interfaces = []
+        return
 
     def pack(self):
         packed = []
@@ -1034,24 +1008,21 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(struct.pack("!L", self.experimenter))
         packed.append(struct.pack("!L", self.subtype))
-        packed.append(util.pack_list(self.interfaces))
+        packed.append(loxi.generic_util.pack_list(self.interfaces))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_interfaces_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1062,22 +1033,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.interfaces != other.interfaces: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_interfaces_reply {")
         with q.group():
@@ -1094,14 +1053,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_interfaces_request(Message):
+bsn_header.subtypes[10] = bsn_get_interfaces_reply
+
+class bsn_get_interfaces_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 9
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -1116,18 +1081,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_interfaces_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1137,21 +1099,9 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_interfaces_request {")
         with q.group():
@@ -1165,14 +1115,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_ip_mask_reply(Message):
+bsn_header.subtypes[9] = bsn_get_interfaces_request
+
+class bsn_get_ip_mask_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 2
 
     def __init__(self, xid=None, index=None, mask=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if index != None:
             self.index = index
         else:
@@ -1181,6 +1136,7 @@
             self.mask = mask
         else:
             self.mask = 0
+        return
 
     def pack(self):
         packed = []
@@ -1198,18 +1154,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_ip_mask_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1222,23 +1175,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.index != other.index: return False
         if self.mask != other.mask: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_ip_mask_reply {")
         with q.group():
@@ -1258,18 +1199,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_ip_mask_request(Message):
+bsn_header.subtypes[2] = bsn_get_ip_mask_reply
+
+class bsn_get_ip_mask_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 1
 
     def __init__(self, xid=None, index=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if index != None:
             self.index = index
         else:
             self.index = 0
+        return
 
     def pack(self):
         packed = []
@@ -1286,18 +1233,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_ip_mask_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1309,22 +1253,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.index != other.index: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_ip_mask_request {")
         with q.group():
@@ -1341,14 +1273,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_l2_table_reply(Message):
+bsn_header.subtypes[1] = bsn_get_ip_mask_request
+
+class bsn_get_l2_table_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 14
 
     def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if l2_table_enable != None:
             self.l2_table_enable = l2_table_enable
         else:
@@ -1357,6 +1294,7 @@
             self.l2_table_priority = l2_table_priority
         else:
             self.l2_table_priority = 0
+        return
 
     def pack(self):
         packed = []
@@ -1375,18 +1313,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_l2_table_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1400,23 +1335,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.l2_table_enable != other.l2_table_enable: return False
         if self.l2_table_priority != other.l2_table_priority: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_l2_table_reply {")
         with q.group():
@@ -1436,14 +1359,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_l2_table_request(Message):
+bsn_header.subtypes[14] = bsn_get_l2_table_reply
+
+class bsn_get_l2_table_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 13
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -1458,18 +1387,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_l2_table_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1479,21 +1405,9 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_l2_table_request {")
         with q.group():
@@ -1507,18 +1421,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_mirroring_reply(Message):
+bsn_header.subtypes[13] = bsn_get_l2_table_request
+
+class bsn_get_mirroring_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 5
 
     def __init__(self, xid=None, report_mirror_ports=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if report_mirror_ports != None:
             self.report_mirror_ports = report_mirror_ports
         else:
             self.report_mirror_ports = 0
+        return
 
     def pack(self):
         packed = []
@@ -1535,18 +1455,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_mirroring_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1558,22 +1475,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.report_mirror_ports != other.report_mirror_ports: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_mirroring_reply {")
         with q.group():
@@ -1590,18 +1495,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_mirroring_request(Message):
+bsn_header.subtypes[5] = bsn_get_mirroring_reply
+
+class bsn_get_mirroring_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 4
 
     def __init__(self, xid=None, report_mirror_ports=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if report_mirror_ports != None:
             self.report_mirror_ports = report_mirror_ports
         else:
             self.report_mirror_ports = 0
+        return
 
     def pack(self):
         packed = []
@@ -1618,18 +1529,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_get_mirroring_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1641,22 +1549,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.report_mirror_ports != other.report_mirror_ports: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_get_mirroring_request {")
         with q.group():
@@ -1673,14 +1569,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_hybrid_get_reply(Message):
+bsn_header.subtypes[4] = bsn_get_mirroring_request
+
+class bsn_hybrid_get_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 28
 
     def __init__(self, xid=None, hybrid_enable=None, hybrid_version=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if hybrid_enable != None:
             self.hybrid_enable = hybrid_enable
         else:
@@ -1689,6 +1590,7 @@
             self.hybrid_version = hybrid_version
         else:
             self.hybrid_version = 0
+        return
 
     def pack(self):
         packed = []
@@ -1707,18 +1609,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_hybrid_get_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1732,23 +1631,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.hybrid_enable != other.hybrid_enable: return False
         if self.hybrid_version != other.hybrid_version: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_hybrid_get_reply {")
         with q.group():
@@ -1768,14 +1655,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_hybrid_get_request(Message):
+bsn_header.subtypes[28] = bsn_hybrid_get_reply
+
+class bsn_hybrid_get_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 27
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -1790,18 +1683,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_hybrid_get_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1811,21 +1701,9 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_hybrid_get_request {")
         with q.group():
@@ -1839,14 +1717,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_rx_reply(Message):
+bsn_header.subtypes[27] = bsn_hybrid_get_request
+
+class bsn_pdu_rx_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 34
 
     def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
@@ -1859,6 +1742,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -1876,18 +1760,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_pdu_rx_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -1900,24 +1781,12 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         if self.port_no != other.port_no: return False
         if self.slot_num != other.slot_num: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_pdu_rx_reply {")
         with q.group():
@@ -1940,14 +1809,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_rx_request(Message):
+bsn_header.subtypes[34] = bsn_pdu_rx_reply
+
+class bsn_pdu_rx_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 33
 
     def __init__(self, xid=None, timeout_ms=None, port_no=None, slot_num=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if timeout_ms != None:
             self.timeout_ms = timeout_ms
         else:
@@ -1964,6 +1838,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -1983,18 +1858,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_pdu_rx_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2009,8 +1881,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.timeout_ms != other.timeout_ms: return False
         if self.port_no != other.port_no: return False
@@ -2018,16 +1888,6 @@
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_pdu_rx_request {")
         with q.group():
@@ -2053,14 +1913,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_rx_timeout(Message):
+bsn_header.subtypes[33] = bsn_pdu_rx_request
+
+class bsn_pdu_rx_timeout(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 35
 
     def __init__(self, xid=None, port_no=None, slot_num=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if port_no != None:
             self.port_no = port_no
         else:
@@ -2069,6 +1934,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -2085,18 +1951,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_pdu_rx_timeout()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2108,23 +1971,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.port_no != other.port_no: return False
         if self.slot_num != other.slot_num: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_pdu_rx_timeout {")
         with q.group():
@@ -2144,14 +1995,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_tx_reply(Message):
+bsn_header.subtypes[35] = bsn_pdu_rx_timeout
+
+class bsn_pdu_tx_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 32
 
     def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
@@ -2164,6 +2020,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -2181,18 +2038,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_pdu_tx_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2205,24 +2059,12 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         if self.port_no != other.port_no: return False
         if self.slot_num != other.slot_num: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_pdu_tx_reply {")
         with q.group():
@@ -2245,14 +2087,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_tx_request(Message):
+bsn_header.subtypes[32] = bsn_pdu_tx_reply
+
+class bsn_pdu_tx_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 31
 
     def __init__(self, xid=None, tx_interval_ms=None, port_no=None, slot_num=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if tx_interval_ms != None:
             self.tx_interval_ms = tx_interval_ms
         else:
@@ -2269,6 +2116,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -2288,18 +2136,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_pdu_tx_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2314,8 +2159,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.tx_interval_ms != other.tx_interval_ms: return False
         if self.port_no != other.port_no: return False
@@ -2323,16 +2166,6 @@
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_pdu_tx_request {")
         with q.group():
@@ -2358,14 +2191,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_ip_mask(Message):
+bsn_header.subtypes[31] = bsn_pdu_tx_request
+
+class bsn_set_ip_mask(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 0
 
     def __init__(self, xid=None, index=None, mask=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if index != None:
             self.index = index
         else:
@@ -2374,6 +2212,7 @@
             self.mask = mask
         else:
             self.mask = 0
+        return
 
     def pack(self):
         packed = []
@@ -2391,18 +2230,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_ip_mask()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2415,23 +2251,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.index != other.index: return False
         if self.mask != other.mask: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_ip_mask {")
         with q.group():
@@ -2451,14 +2275,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_l2_table_reply(Message):
+bsn_header.subtypes[0] = bsn_set_ip_mask
+
+class bsn_set_l2_table_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 24
 
     def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if l2_table_enable != None:
             self.l2_table_enable = l2_table_enable
         else:
@@ -2471,6 +2300,7 @@
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -2489,18 +2319,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_l2_table_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2514,24 +2341,12 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.l2_table_enable != other.l2_table_enable: return False
         if self.l2_table_priority != other.l2_table_priority: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_l2_table_reply {")
         with q.group():
@@ -2554,14 +2369,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_l2_table_request(Message):
+bsn_header.subtypes[24] = bsn_set_l2_table_reply
+
+class bsn_set_l2_table_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 12
 
     def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if l2_table_enable != None:
             self.l2_table_enable = l2_table_enable
         else:
@@ -2570,6 +2390,7 @@
             self.l2_table_priority = l2_table_priority
         else:
             self.l2_table_priority = 0
+        return
 
     def pack(self):
         packed = []
@@ -2588,18 +2409,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_l2_table_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2613,23 +2431,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.l2_table_enable != other.l2_table_enable: return False
         if self.l2_table_priority != other.l2_table_priority: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_l2_table_request {")
         with q.group():
@@ -2649,18 +2455,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_mirroring(Message):
+bsn_header.subtypes[12] = bsn_set_l2_table_request
+
+class bsn_set_mirroring(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 3
 
     def __init__(self, xid=None, report_mirror_ports=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if report_mirror_ports != None:
             self.report_mirror_ports = report_mirror_ports
         else:
             self.report_mirror_ports = 0
+        return
 
     def pack(self):
         packed = []
@@ -2677,18 +2489,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_mirroring()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2700,22 +2509,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.report_mirror_ports != other.report_mirror_ports: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_mirroring {")
         with q.group():
@@ -2732,18 +2529,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_pktin_suppression_reply(Message):
+bsn_header.subtypes[3] = bsn_set_mirroring
+
+class bsn_set_pktin_suppression_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 25
 
     def __init__(self, xid=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -2759,18 +2562,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_pktin_suppression_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2781,22 +2581,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_pktin_suppression_reply {")
         with q.group():
@@ -2813,14 +2601,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_pktin_suppression_request(Message):
+bsn_header.subtypes[25] = bsn_set_pktin_suppression_reply
+
+class bsn_set_pktin_suppression_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 11
 
     def __init__(self, xid=None, enabled=None, idle_timeout=None, hard_timeout=None, priority=None, cookie=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if enabled != None:
             self.enabled = enabled
         else:
@@ -2841,6 +2634,7 @@
             self.cookie = cookie
         else:
             self.cookie = 0
+        return
 
     def pack(self):
         packed = []
@@ -2861,18 +2655,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_set_pktin_suppression_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2888,8 +2679,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.enabled != other.enabled: return False
         if self.idle_timeout != other.idle_timeout: return False
@@ -2898,16 +2687,6 @@
         if self.cookie != other.cookie: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_set_pktin_suppression_request {")
         with q.group():
@@ -2936,14 +2715,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_shell_command(Message):
+bsn_header.subtypes[11] = bsn_set_pktin_suppression_request
+
+class bsn_shell_command(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 6
 
     def __init__(self, xid=None, service=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if service != None:
             self.service = service
         else:
@@ -2952,6 +2736,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -2968,18 +2753,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_shell_command()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -2991,23 +2773,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.service != other.service: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_shell_command {")
         with q.group():
@@ -3027,18 +2797,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_shell_output(Message):
+bsn_header.subtypes[6] = bsn_shell_command
+
+class bsn_shell_output(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 7
 
     def __init__(self, xid=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if data != None:
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -3054,18 +2830,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_shell_output()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3076,22 +2849,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_shell_output {")
         with q.group():
@@ -3108,18 +2869,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_shell_status(Message):
+bsn_header.subtypes[7] = bsn_shell_output
+
+class bsn_shell_status(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 8
 
     def __init__(self, xid=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -3135,18 +2902,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_shell_status()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3157,22 +2921,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_shell_status {")
         with q.group():
@@ -3189,14 +2941,75 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_create_reply(Message):
+bsn_header.subtypes[8] = bsn_shell_status
+
+class experimenter_stats_reply(stats_reply):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 12)
+        try:
+            subclass = experimenter_stats_reply.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown experimenter_stats_reply stats_reply message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+stats_reply.subtypes[65535] = experimenter_stats_reply
+
+class bsn_stats_reply(experimenter_stats_reply):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 20)
+        try:
+            subclass = bsn_stats_reply.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn_stats_reply experimenter_stats_reply stats_reply message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter_stats_reply.subtypes[6035143] = bsn_stats_reply
+
+class experimenter_stats_request(stats_request):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 12)
+        try:
+            subclass = experimenter_stats_request.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown experimenter_stats_request stats_request message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+stats_request.subtypes[65535] = experimenter_stats_request
+
+class bsn_stats_request(experimenter_stats_request):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 20)
+        try:
+            subclass = bsn_stats_request.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn_stats_request experimenter_stats_request stats_request message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter_stats_request.subtypes[6035143] = bsn_stats_request
+
+class bsn_virtual_port_create_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 16
 
     def __init__(self, xid=None, status=None, vport_no=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
@@ -3205,6 +3018,7 @@
             self.vport_no = vport_no
         else:
             self.vport_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -3221,18 +3035,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_virtual_port_create_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3244,23 +3055,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         if self.vport_no != other.vport_no: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_virtual_port_create_reply {")
         with q.group():
@@ -3280,18 +3079,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_create_request(Message):
+bsn_header.subtypes[16] = bsn_virtual_port_create_reply
+
+class bsn_virtual_port_create_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 15
 
     def __init__(self, xid=None, vport=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if vport != None:
             self.vport = vport
         else:
             self.vport = common.bsn_vport_q_in_q()
+        return
 
     def pack(self):
         packed = []
@@ -3307,18 +3112,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_virtual_port_create_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3329,22 +3131,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.vport != other.vport: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_virtual_port_create_request {")
         with q.group():
@@ -3361,18 +3151,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_remove_reply(Message):
+bsn_header.subtypes[15] = bsn_virtual_port_create_request
+
+class bsn_virtual_port_remove_reply(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 26
 
     def __init__(self, xid=None, status=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -3388,18 +3184,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_virtual_port_remove_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3410,22 +3203,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.status != other.status: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_virtual_port_remove_reply {")
         with q.group():
@@ -3442,18 +3223,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_remove_request(Message):
+bsn_header.subtypes[26] = bsn_virtual_port_remove_reply
+
+class bsn_virtual_port_remove_request(bsn_header):
     version = 1
     type = 4
     experimenter = 6035143
     subtype = 17
 
     def __init__(self, xid=None, vport_no=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if vport_no != None:
             self.vport_no = vport_no
         else:
             self.vport_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -3469,18 +3256,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = bsn_virtual_port_remove_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
@@ -3491,22 +3275,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.vport_no != other.vport_no: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_virtual_port_remove_request {")
         with q.group():
@@ -3523,13 +3295,18 @@
             q.breakable()
         q.text('}')
 
-class desc_stats_reply(Message):
+bsn_header.subtypes[17] = bsn_virtual_port_remove_request
+
+class desc_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 0
 
     def __init__(self, xid=None, flags=None, mfr_desc=None, hw_desc=None, sw_desc=None, serial_num=None, dp_desc=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -3554,6 +3331,7 @@
             self.dp_desc = dp_desc
         else:
             self.dp_desc = ""
+        return
 
     def pack(self):
         packed = []
@@ -3573,18 +3351,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = desc_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 0)
@@ -3598,8 +3373,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.mfr_desc != other.mfr_desc: return False
@@ -3609,16 +3382,6 @@
         if self.dp_desc != other.dp_desc: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("desc_stats_reply {")
         with q.group():
@@ -3650,17 +3413,23 @@
             q.breakable()
         q.text('}')
 
-class desc_stats_request(Message):
+stats_reply.subtypes[0] = desc_stats_reply
+
+class desc_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 0
 
     def __init__(self, xid=None, flags=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
             self.flags = 0
+        return
 
     def pack(self):
         packed = []
@@ -3675,18 +3444,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = desc_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 0)
@@ -3695,22 +3461,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("desc_stats_request {")
         with q.group():
@@ -3727,16 +3481,22 @@
             q.breakable()
         q.text('}')
 
-class echo_reply(Message):
+stats_request.subtypes[0] = desc_stats_request
+
+class echo_reply(message):
     version = 1
     type = 3
 
     def __init__(self, xid=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if data != None:
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -3750,40 +3510,25 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = echo_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 3)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.data = str(reader.read_all())
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("echo_reply {")
         with q.group():
@@ -3800,16 +3545,22 @@
             q.breakable()
         q.text('}')
 
-class echo_request(Message):
+message.subtypes[3] = echo_reply
+
+class echo_request(message):
     version = 1
     type = 2
 
     def __init__(self, xid=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if data != None:
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -3823,40 +3574,25 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = echo_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 2)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.data = str(reader.read_all())
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("echo_request {")
         with q.group():
@@ -3873,12 +3609,17 @@
             q.breakable()
         q.text('}')
 
-class features_reply(Message):
+message.subtypes[2] = echo_request
+
+class features_reply(message):
     version = 1
     type = 6
 
     def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, actions=None, ports=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if datapath_id != None:
             self.datapath_id = datapath_id
         else:
@@ -3903,6 +3644,7 @@
             self.ports = ports
         else:
             self.ports = []
+        return
 
     def pack(self):
         packed = []
@@ -3916,24 +3658,21 @@
         packed.append('\x00' * 3)
         packed.append(struct.pack("!L", self.capabilities))
         packed.append(struct.pack("!L", self.actions))
-        packed.append(util.pack_list(self.ports))
+        packed.append(loxi.generic_util.pack_list(self.ports))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = features_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 6)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.datapath_id = reader.read("!Q")[0]
         obj.n_buffers = reader.read("!L")[0]
@@ -3946,8 +3685,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.datapath_id != other.datapath_id: return False
         if self.n_buffers != other.n_buffers: return False
@@ -3957,16 +3694,6 @@
         if self.ports != other.ports: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("features_reply {")
         with q.group():
@@ -3998,12 +3725,18 @@
             q.breakable()
         q.text('}')
 
-class features_request(Message):
+message.subtypes[6] = features_reply
+
+class features_request(message):
     version = 1
     type = 5
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -4016,38 +3749,23 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = features_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 5)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("features_request {")
         with q.group():
@@ -4061,13 +3779,32 @@
             q.breakable()
         q.text('}')
 
-class flow_add(Message):
+message.subtypes[5] = features_request
+
+class flow_mod(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 56)
+        try:
+            subclass = flow_mod.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown flow_mod message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[14] = flow_mod
+
+class flow_add(flow_mod):
     version = 1
     type = 14
     _command = 0
 
     def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4104,6 +3841,7 @@
             self.actions = actions
         else:
             self.actions = []
+        return
 
     def pack(self):
         packed = []
@@ -4120,24 +3858,21 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.out_port))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_add()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 14)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -4149,13 +3884,11 @@
         obj.buffer_id = reader.read("!L")[0]
         obj.out_port = util.unpack_port_no(reader)
         obj.flags = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -4168,16 +3901,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_add {")
         with q.group():
@@ -4218,13 +3941,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete(Message):
+flow_mod.subtypes[0] = flow_add
+
+class flow_delete(flow_mod):
     version = 1
     type = 14
     _command = 3
 
     def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4261,6 +3989,7 @@
             self.actions = actions
         else:
             self.actions = []
+        return
 
     def pack(self):
         packed = []
@@ -4277,24 +4006,21 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.out_port))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_delete()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 14)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -4306,13 +4032,11 @@
         obj.buffer_id = reader.read("!L")[0]
         obj.out_port = util.unpack_port_no(reader)
         obj.flags = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -4325,16 +4049,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_delete {")
         with q.group():
@@ -4375,13 +4089,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete_strict(Message):
+flow_mod.subtypes[3] = flow_delete
+
+class flow_delete_strict(flow_mod):
     version = 1
     type = 14
     _command = 4
 
     def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4418,6 +4137,7 @@
             self.actions = actions
         else:
             self.actions = []
+        return
 
     def pack(self):
         packed = []
@@ -4434,24 +4154,21 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.out_port))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_delete_strict()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 14)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -4463,13 +4180,11 @@
         obj.buffer_id = reader.read("!L")[0]
         obj.out_port = util.unpack_port_no(reader)
         obj.flags = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -4482,16 +4197,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_delete_strict {")
         with q.group():
@@ -4532,13 +4237,18 @@
             q.breakable()
         q.text('}')
 
-class flow_mod_failed_error_msg(Message):
+flow_mod.subtypes[4] = flow_delete_strict
+
+class flow_mod_failed_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 3
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -4547,6 +4257,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -4562,18 +4273,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_mod_failed_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 3)
@@ -4583,23 +4291,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_mod_failed_error_msg {")
         with q.group():
@@ -4619,13 +4315,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify(Message):
+error_msg.subtypes[3] = flow_mod_failed_error_msg
+
+class flow_modify(flow_mod):
     version = 1
     type = 14
     _command = 1
 
     def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4662,6 +4363,7 @@
             self.actions = actions
         else:
             self.actions = []
+        return
 
     def pack(self):
         packed = []
@@ -4678,24 +4380,21 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.out_port))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_modify()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 14)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -4707,13 +4406,11 @@
         obj.buffer_id = reader.read("!L")[0]
         obj.out_port = util.unpack_port_no(reader)
         obj.flags = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -4726,16 +4423,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_modify {")
         with q.group():
@@ -4776,13 +4463,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify_strict(Message):
+flow_mod.subtypes[1] = flow_modify
+
+class flow_modify_strict(flow_mod):
     version = 1
     type = 14
     _command = 2
 
     def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4819,6 +4511,7 @@
             self.actions = actions
         else:
             self.actions = []
+        return
 
     def pack(self):
         packed = []
@@ -4835,24 +4528,21 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.out_port))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_modify_strict()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 14)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -4864,13 +4554,11 @@
         obj.buffer_id = reader.read("!L")[0]
         obj.out_port = util.unpack_port_no(reader)
         obj.flags = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -4883,16 +4571,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_modify_strict {")
         with q.group():
@@ -4933,12 +4611,17 @@
             q.breakable()
         q.text('}')
 
-class flow_removed(Message):
+flow_mod.subtypes[2] = flow_modify_strict
+
+class flow_removed(message):
     version = 1
     type = 11
 
     def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if match != None:
             self.match = match
         else:
@@ -4975,6 +4658,7 @@
             self.byte_count = byte_count
         else:
             self.byte_count = 0
+        return
 
     def pack(self):
         packed = []
@@ -4998,18 +4682,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_removed()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 11)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.match = common.match.unpack(reader)
         obj.cookie = reader.read("!Q")[0]
@@ -5026,8 +4707,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.match != other.match: return False
         if self.cookie != other.cookie: return False
@@ -5040,16 +4719,6 @@
         if self.byte_count != other.byte_count: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_removed {")
         with q.group():
@@ -5090,13 +4759,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_reply(Message):
+message.subtypes[11] = flow_removed
+
+class flow_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 1
 
     def __init__(self, xid=None, flags=None, entries=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -5105,6 +4779,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -5114,50 +4789,35 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.entries))
+        packed.append(loxi.generic_util.pack_list(self.entries))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 1)
         obj.flags = reader.read("!H")[0]
-        obj.entries = common.unpack_list_flow_stats_entry(reader)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.flow_stats_entry.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.entries != other.entries: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_stats_reply {")
         with q.group():
@@ -5177,13 +4837,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_request(Message):
+stats_reply.subtypes[1] = flow_stats_reply
+
+class flow_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 1
 
     def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -5200,6 +4865,7 @@
             self.out_port = out_port
         else:
             self.out_port = 0
+        return
 
     def pack(self):
         packed = []
@@ -5218,18 +4884,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = flow_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 1)
@@ -5242,8 +4905,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.match != other.match: return False
@@ -5251,16 +4912,6 @@
         if self.out_port != other.out_port: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("flow_stats_request {")
         with q.group():
@@ -5286,12 +4937,17 @@
             q.breakable()
         q.text('}')
 
-class get_config_reply(Message):
+stats_request.subtypes[1] = flow_stats_request
+
+class get_config_reply(message):
     version = 1
     type = 8
 
     def __init__(self, xid=None, flags=None, miss_send_len=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -5300,6 +4956,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -5314,18 +4971,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = get_config_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 8)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.flags = reader.read("!H")[0]
         obj.miss_send_len = reader.read("!H")[0]
@@ -5333,23 +4987,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.miss_send_len != other.miss_send_len: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("get_config_reply {")
         with q.group():
@@ -5369,12 +5011,18 @@
             q.breakable()
         q.text('}')
 
-class get_config_request(Message):
+message.subtypes[8] = get_config_reply
+
+class get_config_request(message):
     version = 1
     type = 7
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -5387,38 +5035,23 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = get_config_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 7)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("get_config_request {")
         with q.group():
@@ -5432,12 +5065,18 @@
             q.breakable()
         q.text('}')
 
-class hello(Message):
+message.subtypes[7] = get_config_request
+
+class hello(message):
     version = 1
     type = 0
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -5450,38 +5089,23 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = hello()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 0)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("hello {")
         with q.group():
@@ -5495,13 +5119,18 @@
             q.breakable()
         q.text('}')
 
-class hello_failed_error_msg(Message):
+message.subtypes[0] = hello
+
+class hello_failed_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 0
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -5510,6 +5139,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5525,18 +5155,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = hello_failed_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 0)
@@ -5546,23 +5173,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("hello_failed_error_msg {")
         with q.group():
@@ -5582,18 +5197,38 @@
             q.breakable()
         q.text('}')
 
-class nicira_controller_role_reply(Message):
+error_msg.subtypes[0] = hello_failed_error_msg
+
+class nicira_header(experimenter):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 12)
+        try:
+            subclass = nicira_header.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown nicira_header experimenter message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter.subtypes[8992] = nicira_header
+
+class nicira_controller_role_reply(nicira_header):
     version = 1
     type = 4
     experimenter = 8992
     subtype = 11
 
     def __init__(self, xid=None, role=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if role != None:
             self.role = role
         else:
             self.role = 0
+        return
 
     def pack(self):
         packed = []
@@ -5609,18 +5244,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = nicira_controller_role_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 8992)
@@ -5631,22 +5263,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.role != other.role: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("nicira_controller_role_reply {")
         with q.group():
@@ -5663,18 +5283,24 @@
             q.breakable()
         q.text('}')
 
-class nicira_controller_role_request(Message):
+nicira_header.subtypes[11] = nicira_controller_role_reply
+
+class nicira_controller_role_request(nicira_header):
     version = 1
     type = 4
     experimenter = 8992
     subtype = 10
 
     def __init__(self, xid=None, role=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if role != None:
             self.role = role
         else:
             self.role = 0
+        return
 
     def pack(self):
         packed = []
@@ -5690,18 +5316,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = nicira_controller_role_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 4)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 8992)
@@ -5712,22 +5335,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.role != other.role: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("nicira_controller_role_request {")
         with q.group():
@@ -5744,12 +5355,17 @@
             q.breakable()
         q.text('}')
 
-class packet_in(Message):
+nicira_header.subtypes[10] = nicira_controller_role_request
+
+class packet_in(message):
     version = 1
     type = 10
 
     def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None, reason=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if buffer_id != None:
             self.buffer_id = buffer_id
         else:
@@ -5770,6 +5386,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5788,18 +5405,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = packet_in()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 10)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.buffer_id = reader.read("!L")[0]
         obj.total_len = reader.read("!H")[0]
@@ -5811,8 +5425,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.buffer_id != other.buffer_id: return False
         if self.total_len != other.total_len: return False
@@ -5821,16 +5433,6 @@
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("packet_in {")
         with q.group():
@@ -5859,12 +5461,17 @@
             q.breakable()
         q.text('}')
 
-class packet_out(Message):
+message.subtypes[10] = packet_in
+
+class packet_out(message):
     version = 1
     type = 13
 
     def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if buffer_id != None:
             self.buffer_id = buffer_id
         else:
@@ -5881,6 +5488,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5891,7 +5499,7 @@
         packed.append(struct.pack("!L", self.buffer_id))
         packed.append(util.pack_port_no(self.in_port))
         packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         packed[6] = struct.pack("!H", len(packed[-1]))
         packed.append(self.data)
         length = sum([len(x) for x in packed])
@@ -5899,30 +5507,25 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = packet_out()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 13)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.buffer_id = reader.read("!L")[0]
         obj.in_port = util.unpack_port_no(reader)
         _actions_len = reader.read("!H")[0]
-        obj.actions = action.unpack_list(reader.slice(_actions_len))
+        obj.actions = loxi.generic_util.unpack_list(reader.slice(_actions_len), action.action.unpack)
         obj.data = str(reader.read_all())
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.buffer_id != other.buffer_id: return False
         if self.in_port != other.in_port: return False
@@ -5930,16 +5533,6 @@
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("packet_out {")
         with q.group():
@@ -5965,12 +5558,17 @@
             q.breakable()
         q.text('}')
 
-class port_mod(Message):
+message.subtypes[13] = packet_out
+
+class port_mod(message):
     version = 1
     type = 15
 
     def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if port_no != None:
             self.port_no = port_no
         else:
@@ -5991,6 +5589,7 @@
             self.advertise = advertise
         else:
             self.advertise = 0
+        return
 
     def pack(self):
         packed = []
@@ -6009,18 +5608,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = port_mod()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 15)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.port_no = util.unpack_port_no(reader)
         obj.hw_addr = list(reader.read('!6B'))
@@ -6032,8 +5628,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.port_no != other.port_no: return False
         if self.hw_addr != other.hw_addr: return False
@@ -6042,16 +5636,6 @@
         if self.advertise != other.advertise: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_mod {")
         with q.group():
@@ -6080,13 +5664,18 @@
             q.breakable()
         q.text('}')
 
-class port_mod_failed_error_msg(Message):
+message.subtypes[15] = port_mod
+
+class port_mod_failed_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 4
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -6095,6 +5684,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -6110,18 +5700,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = port_mod_failed_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 4)
@@ -6131,23 +5718,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_mod_failed_error_msg {")
         with q.group():
@@ -6167,13 +5742,18 @@
             q.breakable()
         q.text('}')
 
-class port_stats_reply(Message):
+error_msg.subtypes[4] = port_mod_failed_error_msg
+
+class port_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 4
 
     def __init__(self, xid=None, flags=None, entries=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6182,6 +5762,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6191,24 +5772,21 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.entries))
+        packed.append(loxi.generic_util.pack_list(self.entries))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = port_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 4)
@@ -6218,23 +5796,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.entries != other.entries: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_stats_reply {")
         with q.group():
@@ -6254,13 +5820,18 @@
             q.breakable()
         q.text('}')
 
-class port_stats_request(Message):
+stats_reply.subtypes[4] = port_stats_reply
+
+class port_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 4
 
     def __init__(self, xid=None, flags=None, port_no=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6269,6 +5840,7 @@
             self.port_no = port_no
         else:
             self.port_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -6285,18 +5857,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = port_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 4)
@@ -6307,23 +5876,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.port_no != other.port_no: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_stats_request {")
         with q.group():
@@ -6343,12 +5900,17 @@
             q.breakable()
         q.text('}')
 
-class port_status(Message):
+stats_request.subtypes[4] = port_stats_request
+
+class port_status(message):
     version = 1
     type = 12
 
     def __init__(self, xid=None, reason=None, desc=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if reason != None:
             self.reason = reason
         else:
@@ -6357,6 +5919,7 @@
             self.desc = desc
         else:
             self.desc = common.port_desc()
+        return
 
     def pack(self):
         packed = []
@@ -6372,18 +5935,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = port_status()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 12)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.reason = reader.read("!B")[0]
         reader.skip(7)
@@ -6392,23 +5952,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.reason != other.reason: return False
         if self.desc != other.desc: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("port_status {")
         with q.group():
@@ -6428,12 +5976,17 @@
             q.breakable()
         q.text('}')
 
-class queue_get_config_reply(Message):
+message.subtypes[12] = port_status
+
+class queue_get_config_reply(message):
     version = 1
     type = 21
 
     def __init__(self, xid=None, port=None, queues=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if port != None:
             self.port = port
         else:
@@ -6442,6 +5995,7 @@
             self.queues = queues
         else:
             self.queues = []
+        return
 
     def pack(self):
         packed = []
@@ -6451,49 +6005,34 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(util.pack_port_no(self.port))
         packed.append('\x00' * 6)
-        packed.append(util.pack_list(self.queues))
+        packed.append(loxi.generic_util.pack_list(self.queues))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = queue_get_config_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 21)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.port = util.unpack_port_no(reader)
         reader.skip(6)
-        obj.queues = common.unpack_list_packet_queue(reader)
+        obj.queues = loxi.generic_util.unpack_list(reader, common.packet_queue.unpack)
         return obj
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.port != other.port: return False
         if self.queues != other.queues: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_get_config_reply {")
         with q.group():
@@ -6513,16 +6052,22 @@
             q.breakable()
         q.text('}')
 
-class queue_get_config_request(Message):
+message.subtypes[21] = queue_get_config_reply
+
+class queue_get_config_request(message):
     version = 1
     type = 20
 
     def __init__(self, xid=None, port=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if port != None:
             self.port = port
         else:
             self.port = 0
+        return
 
     def pack(self):
         packed = []
@@ -6537,18 +6082,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = queue_get_config_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 20)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.port = util.unpack_port_no(reader)
         reader.skip(2)
@@ -6556,22 +6098,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.port != other.port: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_get_config_request {")
         with q.group():
@@ -6588,13 +6118,18 @@
             q.breakable()
         q.text('}')
 
-class queue_op_failed_error_msg(Message):
+message.subtypes[20] = queue_get_config_request
+
+class queue_op_failed_error_msg(error_msg):
     version = 1
     type = 1
     err_type = 5
 
     def __init__(self, xid=None, code=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if code != None:
             self.code = code
         else:
@@ -6603,6 +6138,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -6618,18 +6154,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = queue_op_failed_error_msg()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 1)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _err_type = reader.read("!H")[0]
         assert(_err_type == 5)
@@ -6639,23 +6172,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.code != other.code: return False
         if self.data != other.data: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_op_failed_error_msg {")
         with q.group():
@@ -6675,13 +6196,18 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_reply(Message):
+error_msg.subtypes[5] = queue_op_failed_error_msg
+
+class queue_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 5
 
     def __init__(self, xid=None, flags=None, entries=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6690,6 +6216,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6699,24 +6226,21 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.entries))
+        packed.append(loxi.generic_util.pack_list(self.entries))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = queue_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 5)
@@ -6726,23 +6250,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.entries != other.entries: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_stats_reply {")
         with q.group():
@@ -6762,13 +6274,18 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_request(Message):
+stats_reply.subtypes[5] = queue_stats_reply
+
+class queue_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 5
 
     def __init__(self, xid=None, flags=None, port_no=None, queue_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6781,6 +6298,7 @@
             self.queue_id = queue_id
         else:
             self.queue_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -6798,18 +6316,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = queue_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 5)
@@ -6821,24 +6336,12 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.port_no != other.port_no: return False
         if self.queue_id != other.queue_id: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("queue_stats_request {")
         with q.group():
@@ -6861,12 +6364,17 @@
             q.breakable()
         q.text('}')
 
-class set_config(Message):
+stats_request.subtypes[5] = queue_stats_request
+
+class set_config(message):
     version = 1
     type = 9
 
     def __init__(self, xid=None, flags=None, miss_send_len=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6875,6 +6383,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -6889,18 +6398,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = set_config()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 9)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.flags = reader.read("!H")[0]
         obj.miss_send_len = reader.read("!H")[0]
@@ -6908,23 +6414,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.miss_send_len != other.miss_send_len: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("set_config {")
         with q.group():
@@ -6944,12 +6438,17 @@
             q.breakable()
         q.text('}')
 
-class table_mod(Message):
+message.subtypes[9] = set_config
+
+class table_mod(message):
     version = 1
     type = 22
 
     def __init__(self, xid=None, table_id=None, config=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if table_id != None:
             self.table_id = table_id
         else:
@@ -6958,6 +6457,7 @@
             self.config = config
         else:
             self.config = 0
+        return
 
     def pack(self):
         packed = []
@@ -6973,18 +6473,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = table_mod()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 22)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.table_id = reader.read("!B")[0]
         reader.skip(3)
@@ -6993,23 +6490,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.table_id != other.table_id: return False
         if self.config != other.config: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("table_mod {")
         with q.group():
@@ -7029,13 +6514,18 @@
             q.breakable()
         q.text('}')
 
-class table_stats_reply(Message):
+message.subtypes[22] = table_mod
+
+class table_stats_reply(stats_reply):
     version = 1
     type = 17
     stats_type = 3
 
     def __init__(self, xid=None, flags=None, entries=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -7044,6 +6534,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -7053,24 +6544,21 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
-        packed.append(util.pack_list(self.entries))
+        packed.append(loxi.generic_util.pack_list(self.entries))
         length = sum([len(x) for x in packed])
         packed[2] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = table_stats_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 17)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 3)
@@ -7080,23 +6568,11 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         if self.entries != other.entries: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("table_stats_reply {")
         with q.group():
@@ -7116,17 +6592,23 @@
             q.breakable()
         q.text('}')
 
-class table_stats_request(Message):
+stats_reply.subtypes[3] = table_stats_reply
+
+class table_stats_request(stats_request):
     version = 1
     type = 16
     stats_type = 3
 
     def __init__(self, xid=None, flags=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
             self.flags = 0
+        return
 
     def pack(self):
         packed = []
@@ -7141,18 +6623,15 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
-        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+    def unpack(reader):
         obj = table_stats_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 1)
         _type = reader.read("!B")[0]
         assert(_type == 16)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 3)
@@ -7161,22 +6640,10 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.flags != other.flags: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def __str__(self):
-        return self.show()
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("table_stats_request {")
         with q.group():
@@ -7193,6 +6660,8 @@
             q.breakable()
         q.text('}')
 
+stats_request.subtypes[3] = table_stats_request
+
 
 def parse_header(buf):
     if len(buf) < 8:
@@ -7205,211 +6674,4 @@
         raise loxi.ProtocolError("wrong OpenFlow version (expected %d, got %d)" % (const.OFP_VERSION, msg_ver))
     if len(buf) != msg_len:
         raise loxi.ProtocolError("incorrect message size")
-    if msg_type in parsers:
-        return parsers[msg_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected message type")
-
-def parse_error(buf):
-    if len(buf) < 8 + 2:
-        raise loxi.ProtocolError("message too short")
-    err_type, = struct.unpack_from("!H", buf, 8)
-    if err_type in error_msg_parsers:
-        return error_msg_parsers[err_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected error type %u" % err_type)
-
-def parse_flow_mod(buf):
-    if len(buf) < 57 + 1:
-        raise loxi.ProtocolError("message too short")
-    # Technically uint16_t for OF 1.0
-    cmd, = struct.unpack_from("!B", buf, 57)
-    if cmd in flow_mod_parsers:
-        return flow_mod_parsers[cmd](buf)
-    else:
-        raise loxi.ProtocolError("unexpected flow mod cmd %u" % cmd)
-
-def parse_group_mod(buf):
-    if len(buf) < 8 + 2:
-        raise loxi.ProtocolError("message too short")
-    cmd, = struct.unpack_from("!H", buf, 8)
-    if cmd in flow_mod_parsers:
-        return group_mod_parsers[cmd](buf)
-    else:
-        raise loxi.ProtocolError("unexpected group mod cmd %u" % cmd)
-
-def parse_stats_reply(buf):
-    if len(buf) < 8 + 2:
-        raise loxi.ProtocolError("message too short")
-    stats_type, = struct.unpack_from("!H", buf, 8)
-    if stats_type in stats_reply_parsers:
-        return stats_reply_parsers[stats_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
-
-def parse_stats_request(buf):
-    if len(buf) < 8 + 2:
-        raise loxi.ProtocolError("message too short")
-    stats_type, = struct.unpack_from("!H", buf, 8)
-    if stats_type in stats_request_parsers:
-        return stats_request_parsers[stats_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
-
-def parse_experimenter_stats_request(buf):
-    if len(buf) < 24:
-        raise loxi.ProtocolError("experimenter stats request message too short")
-
-    experimenter, exp_type = struct.unpack_from("!LL", buf, 16)
-
-    if experimenter in experimenter_stats_request_parsers and \
-            exp_type in experimenter_stats_request_parsers[experimenter]:
-        return experimenter_stats_request_parsers[experimenter][exp_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected stats request experimenter %#x exp_type %#x" % (experimenter, exp_type))
-
-def parse_experimenter_stats_reply(buf):
-    if len(buf) < 24:
-        raise loxi.ProtocolError("experimenter stats reply message too short")
-
-    experimenter, exp_type = struct.unpack_from("!LL", buf, 16)
-
-    if experimenter in experimenter_stats_reply_parsers and \
-            exp_type in experimenter_stats_reply_parsers[experimenter]:
-        return experimenter_stats_reply_parsers[experimenter][exp_type](buf)
-    else:
-        raise loxi.ProtocolError("unexpected stats reply experimenter %#x exp_type %#x" % (experimenter, exp_type))
-
-def parse_experimenter(buf):
-    if len(buf) < 16:
-        raise loxi.ProtocolError("experimenter message too short")
-
-    experimenter, = struct.unpack_from("!L", buf, 8)
-    if experimenter == 0x005c16c7: # Big Switch Networks
-        subtype, = struct.unpack_from("!L", buf, 12)
-    elif experimenter == 0x00002320: # Nicira
-        subtype, = struct.unpack_from("!L", buf, 12)
-    else:
-        raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
-
-    if subtype in experimenter_parsers[experimenter]:
-        return experimenter_parsers[experimenter][subtype](buf)
-    else:
-        raise loxi.ProtocolError("unexpected experimenter %#x subtype %#x" % (experimenter, subtype))
-
-parsers = {
-    const.OFPT_HELLO : hello.unpack,
-    const.OFPT_ERROR : parse_error,
-    const.OFPT_ECHO_REQUEST : echo_request.unpack,
-    const.OFPT_ECHO_REPLY : echo_reply.unpack,
-    const.OFPT_EXPERIMENTER : parse_experimenter,
-    const.OFPT_FEATURES_REQUEST : features_request.unpack,
-    const.OFPT_FEATURES_REPLY : features_reply.unpack,
-    const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
-    const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
-    const.OFPT_SET_CONFIG : set_config.unpack,
-    const.OFPT_PACKET_IN : packet_in.unpack,
-    const.OFPT_FLOW_REMOVED : flow_removed.unpack,
-    const.OFPT_PORT_STATUS : port_status.unpack,
-    const.OFPT_PACKET_OUT : packet_out.unpack,
-    const.OFPT_FLOW_MOD : parse_flow_mod,
-    const.OFPT_PORT_MOD : port_mod.unpack,
-    const.OFPT_STATS_REQUEST : parse_stats_request,
-    const.OFPT_STATS_REPLY : parse_stats_reply,
-    const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
-    const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
-    const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
-    const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
-    22 : table_mod.unpack,
-}
-
-error_msg_parsers = {
-    const.OFPET_HELLO_FAILED : hello_failed_error_msg.unpack,
-    const.OFPET_BAD_REQUEST : bad_request_error_msg.unpack,
-    const.OFPET_BAD_ACTION : bad_action_error_msg.unpack,
-    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,
-}
-
-flow_mod_parsers = {
-    const.OFPFC_ADD : flow_add.unpack,
-    const.OFPFC_MODIFY : flow_modify.unpack,
-    const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
-    const.OFPFC_DELETE : flow_delete.unpack,
-    const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
-}
-
-
-stats_reply_parsers = {
-    const.OFPST_DESC : desc_stats_reply.unpack,
-    const.OFPST_FLOW : flow_stats_reply.unpack,
-    const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
-    const.OFPST_TABLE : table_stats_reply.unpack,
-    const.OFPST_PORT : port_stats_reply.unpack,
-    const.OFPST_QUEUE : queue_stats_reply.unpack,
-    const.OFPST_EXPERIMENTER : parse_experimenter_stats_reply,
-}
-
-stats_request_parsers = {
-    const.OFPST_DESC : desc_stats_request.unpack,
-    const.OFPST_FLOW : flow_stats_request.unpack,
-    const.OFPST_AGGREGATE : aggregate_stats_request.unpack,
-    const.OFPST_TABLE : table_stats_request.unpack,
-    const.OFPST_PORT : port_stats_request.unpack,
-    const.OFPST_QUEUE : queue_stats_request.unpack,
-    const.OFPST_EXPERIMENTER : parse_experimenter_stats_request,
-}
-
-experimenter_parsers = {
-    8992 : {
-        11: nicira_controller_role_reply.unpack,
-        10: nicira_controller_role_request.unpack,
-    },
-    6035143 : {
-        22: bsn_bw_clear_data_reply.unpack,
-        21: bsn_bw_clear_data_request.unpack,
-        20: bsn_bw_enable_get_reply.unpack,
-        19: bsn_bw_enable_get_request.unpack,
-        23: bsn_bw_enable_set_reply.unpack,
-        18: bsn_bw_enable_set_request.unpack,
-        10: bsn_get_interfaces_reply.unpack,
-        9: bsn_get_interfaces_request.unpack,
-        2: bsn_get_ip_mask_reply.unpack,
-        1: bsn_get_ip_mask_request.unpack,
-        14: bsn_get_l2_table_reply.unpack,
-        13: bsn_get_l2_table_request.unpack,
-        5: bsn_get_mirroring_reply.unpack,
-        4: bsn_get_mirroring_request.unpack,
-        28: bsn_hybrid_get_reply.unpack,
-        27: bsn_hybrid_get_request.unpack,
-        34: bsn_pdu_rx_reply.unpack,
-        33: bsn_pdu_rx_request.unpack,
-        35: bsn_pdu_rx_timeout.unpack,
-        32: bsn_pdu_tx_reply.unpack,
-        31: bsn_pdu_tx_request.unpack,
-        0: bsn_set_ip_mask.unpack,
-        24: bsn_set_l2_table_reply.unpack,
-        12: bsn_set_l2_table_request.unpack,
-        3: bsn_set_mirroring.unpack,
-        25: bsn_set_pktin_suppression_reply.unpack,
-        11: bsn_set_pktin_suppression_request.unpack,
-        6: bsn_shell_command.unpack,
-        7: bsn_shell_output.unpack,
-        8: bsn_shell_status.unpack,
-        16: bsn_virtual_port_create_reply.unpack,
-        15: bsn_virtual_port_create_request.unpack,
-        26: bsn_virtual_port_remove_reply.unpack,
-        17: bsn_virtual_port_remove_request.unpack,
-    },
-}
-
-experimenter_stats_request_parsers = {
-    0x005c16c7: {
-    },
-}
-
-experimenter_stats_reply_parsers = {
-    0x005c16c7: {
-    },
-}
+    return message.unpack(loxi.generic_util.OFReader(buf))
diff --git a/src/python/loxi/of10/util.py b/src/python/loxi/of10/util.py
index 7997e38..a9b395f 100644
--- a/src/python/loxi/of10/util.py
+++ b/src/python/loxi/of10/util.py
@@ -5,9 +5,11 @@
 # Automatically generated by LOXI from template util.py
 # Do not modify
 
+import struct
 import loxi
 import const
-import struct
+import common
+import action
 
 def pretty_mac(mac):
     return ':'.join(["%02x" % x for x in mac])
@@ -74,9 +76,6 @@
 def unpack_match_bmap(reader):
     return reader.read("!L")[0]
 
-def pack_list(values):
-    return "".join([x.pack() for x in values])
-
 MASK64 = (1 << 64) - 1
 
 def pack_bitmap_128(value):
@@ -96,3 +95,13 @@
         i += 1
         x >>= 1
     return value
+
+def unpack_list_hello_elem(reader):
+    def deserializer(reader):
+        typ, length, = reader.peek('!HH')
+        reader = reader.slice(length)
+        try:
+            return common.hello_elem.unpack(reader)
+        except loxi.ProtocolError:
+            return None
+    return [x for x in loxi.generic_util.unpack_list(reader, deserializer) if x != None]