update pyloxi to 026ff024585f1588a7f11fa4c1a9a48d44dc098d
diff --git a/src/python/loxi/of11/message.py b/src/python/loxi/of11/message.py
index 0566f03..7e2b111 100644
--- a/src/python/loxi/of11/message.py
+++ b/src/python/loxi/of11/message.py
@@ -3,30 +3,55 @@
 # 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 instruction # for unpack_list
+import action
+import instruction
 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[19] = stats_reply
+
+class aggregate_stats_reply(stats_reply):
     version = 2
     type = 19
     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:
@@ -43,6 +68,7 @@
             self.flow_count = flow_count
         else:
             self.flow_count = 0
+        return
 
     def pack(self):
         packed = []
@@ -62,18 +88,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 2)
@@ -87,8 +110,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
@@ -96,16 +117,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():
@@ -131,13 +142,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[18] = stats_request
+
+class aggregate_stats_request(stats_request):
     version = 2
     type = 18
     stats_type = 2
 
     def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -166,6 +196,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -189,18 +220,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 2)
@@ -218,8 +246,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.table_id != other.table_id: return False
@@ -230,16 +256,6 @@
         if self.match != other.match: 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():
@@ -274,13 +290,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 = 2
     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:
@@ -289,6 +324,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -304,18 +340,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 == 2)
         _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)
@@ -325,23 +358,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():
@@ -361,13 +382,18 @@
             q.breakable()
         q.text('}')
 
-class bad_instruction_error_msg(Message):
+error_msg.subtypes[2] = bad_action_error_msg
+
+class bad_instruction_error_msg(error_msg):
     version = 2
     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:
@@ -376,6 +402,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -391,18 +418,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_instruction_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 == 2)
         _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)
@@ -412,23 +436,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_instruction_error_msg {")
         with q.group():
@@ -448,13 +460,18 @@
             q.breakable()
         q.text('}')
 
-class bad_match_error_msg(Message):
+error_msg.subtypes[3] = bad_instruction_error_msg
+
+class bad_match_error_msg(error_msg):
     version = 2
     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:
@@ -463,6 +480,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -478,18 +496,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_match_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 == 2)
         _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)
@@ -499,23 +514,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_match_error_msg {")
         with q.group():
@@ -535,13 +538,18 @@
             q.breakable()
         q.text('}')
 
-class bad_request_error_msg(Message):
+error_msg.subtypes[4] = bad_match_error_msg
+
+class bad_request_error_msg(error_msg):
     version = 2
     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:
@@ -550,6 +558,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -565,18 +574,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 == 2)
         _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)
@@ -586,23 +592,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():
@@ -622,12 +616,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_reply(Message):
+error_msg.subtypes[1] = bad_request_error_msg
+
+class barrier_reply(message):
     version = 2
     type = 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,38 +640,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 == 2)
         _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]
         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():
@@ -685,12 +670,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_request(Message):
+message.subtypes[21] = barrier_reply
+
+class barrier_request(message):
     version = 2
     type = 20
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -703,38 +694,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 == 2)
         _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]
         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():
@@ -748,18 +724,52 @@
             q.breakable()
         q.text('}')
 
-class bsn_bw_clear_data_reply(Message):
+message.subtypes[20] = 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 = 2
     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 = []
@@ -775,18 +785,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 == 2)
         _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)
@@ -797,22 +804,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():
@@ -829,14 +824,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 = 2
     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 = []
@@ -851,18 +852,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 == 2)
         _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)
@@ -872,21 +870,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():
@@ -900,18 +886,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 = 2
     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 = []
@@ -927,18 +919,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 == 2)
         _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)
@@ -949,22 +938,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():
@@ -981,14 +958,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 = 2
     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 = []
@@ -1003,18 +986,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 == 2)
         _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)
@@ -1024,21 +1004,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():
@@ -1052,14 +1020,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 = 2
     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:
@@ -1068,6 +1041,7 @@
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -1084,18 +1058,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 == 2)
         _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)
@@ -1107,23 +1078,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():
@@ -1143,18 +1102,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 = 2
     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 = []
@@ -1170,18 +1135,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 == 2)
         _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)
@@ -1192,22 +1154,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():
@@ -1224,18 +1174,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 = 2
     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 = []
@@ -1245,24 +1201,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 == 2)
         _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)
@@ -1273,22 +1226,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():
@@ -1305,14 +1246,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 = 2
     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 = []
@@ -1327,18 +1274,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 == 2)
         _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)
@@ -1348,21 +1292,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():
@@ -1376,18 +1308,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_mirroring_reply(Message):
+bsn_header.subtypes[9] = bsn_get_interfaces_request
+
+class bsn_get_mirroring_reply(bsn_header):
     version = 2
     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 = []
@@ -1404,18 +1342,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 == 2)
         _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)
@@ -1427,22 +1362,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():
@@ -1459,18 +1382,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 = 2
     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 = []
@@ -1487,18 +1416,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 == 2)
         _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)
@@ -1510,22 +1436,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():
@@ -1542,14 +1456,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_rx_reply(Message):
+bsn_header.subtypes[4] = bsn_get_mirroring_request
+
+class bsn_pdu_rx_reply(bsn_header):
     version = 2
     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:
@@ -1562,6 +1481,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -1579,18 +1499,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 == 2)
         _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)
@@ -1603,24 +1520,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():
@@ -1643,14 +1548,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 = 2
     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:
@@ -1667,6 +1577,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -1686,18 +1597,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 == 2)
         _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)
@@ -1712,8 +1620,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
@@ -1721,16 +1627,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():
@@ -1756,14 +1652,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 = 2
     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:
@@ -1772,6 +1673,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -1788,18 +1690,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 == 2)
         _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,23 +1710,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():
@@ -1847,14 +1734,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 = 2
     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:
@@ -1867,6 +1759,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -1884,18 +1777,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 == 2)
         _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)
@@ -1908,24 +1798,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():
@@ -1948,14 +1826,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 = 2
     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:
@@ -1972,6 +1855,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -1991,18 +1875,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 == 2)
         _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)
@@ -2017,8 +1898,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
@@ -2026,16 +1905,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():
@@ -2061,18 +1930,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_mirroring(Message):
+bsn_header.subtypes[31] = bsn_pdu_tx_request
+
+class bsn_set_mirroring(bsn_header):
     version = 2
     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 = []
@@ -2089,18 +1964,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 == 2)
         _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)
@@ -2112,22 +1984,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():
@@ -2144,18 +2004,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 = 2
     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 = []
@@ -2171,18 +2037,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 == 2)
         _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)
@@ -2193,22 +2056,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():
@@ -2225,14 +2076,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 = 2
     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:
@@ -2253,6 +2109,7 @@
             self.cookie = cookie
         else:
             self.cookie = 0
+        return
 
     def pack(self):
         packed = []
@@ -2273,18 +2130,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 == 2)
         _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)
@@ -2300,8 +2154,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
@@ -2310,16 +2162,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():
@@ -2348,14 +2190,75 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_create_reply(Message):
+bsn_header.subtypes[11] = bsn_set_pktin_suppression_request
+
+class experimenter_stats_reply(stats_reply):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 16)
+        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', 16)
+        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 = 2
     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:
@@ -2364,6 +2267,7 @@
             self.vport_no = vport_no
         else:
             self.vport_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -2380,18 +2284,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 == 2)
         _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)
@@ -2403,23 +2304,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():
@@ -2439,18 +2328,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 = 2
     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 = []
@@ -2466,18 +2361,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 == 2)
         _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)
@@ -2488,22 +2380,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():
@@ -2520,18 +2400,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 = 2
     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 = []
@@ -2547,18 +2433,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 == 2)
         _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)
@@ -2569,22 +2452,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():
@@ -2601,18 +2472,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 = 2
     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 = []
@@ -2628,18 +2505,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 == 2)
         _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)
@@ -2650,22 +2524,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():
@@ -2682,13 +2544,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 = 2
     type = 19
     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:
@@ -2713,6 +2580,7 @@
             self.dp_desc = dp_desc
         else:
             self.dp_desc = ""
+        return
 
     def pack(self):
         packed = []
@@ -2733,18 +2601,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 0)
@@ -2759,8 +2624,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
@@ -2770,16 +2633,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():
@@ -2811,17 +2664,23 @@
             q.breakable()
         q.text('}')
 
-class desc_stats_request(Message):
+stats_reply.subtypes[0] = desc_stats_reply
+
+class desc_stats_request(stats_request):
     version = 2
     type = 18
     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 = []
@@ -2837,18 +2696,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 0)
@@ -2858,22 +2714,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():
@@ -2890,16 +2734,22 @@
             q.breakable()
         q.text('}')
 
-class echo_reply(Message):
+stats_request.subtypes[0] = desc_stats_request
+
+class echo_reply(message):
     version = 2
     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 = []
@@ -2913,40 +2763,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 == 2)
         _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():
@@ -2963,16 +2798,22 @@
             q.breakable()
         q.text('}')
 
-class echo_request(Message):
+message.subtypes[3] = echo_reply
+
+class echo_request(message):
     version = 2
     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 = []
@@ -2986,40 +2827,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 == 2)
         _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():
@@ -3036,12 +2862,17 @@
             q.breakable()
         q.text('}')
 
-class features_reply(Message):
+message.subtypes[2] = echo_request
+
+class features_reply(message):
     version = 2
     type = 6
 
     def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, reserved=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:
@@ -3066,6 +2897,7 @@
             self.ports = ports
         else:
             self.ports = []
+        return
 
     def pack(self):
         packed = []
@@ -3079,24 +2911,21 @@
         packed.append('\x00' * 3)
         packed.append(struct.pack("!L", self.capabilities))
         packed.append(struct.pack("!L", self.reserved))
-        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 == 2)
         _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]
@@ -3109,8 +2938,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
@@ -3120,16 +2947,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():
@@ -3161,12 +2978,18 @@
             q.breakable()
         q.text('}')
 
-class features_request(Message):
+message.subtypes[6] = features_reply
+
+class features_request(message):
     version = 2
     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 = []
@@ -3179,38 +3002,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 == 2)
         _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():
@@ -3224,13 +3032,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('B', 25)
+        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 = 2
     type = 14
     _command = 0
 
     def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -3279,6 +3106,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -3299,24 +3127,21 @@
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 2)
         packed.append(self.match.pack())
-        packed.append(util.pack_list(self.instructions))
+        packed.append(loxi.generic_util.pack_list(self.instructions))
         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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.cookie_mask = reader.read("!Q")[0]
@@ -3332,13 +3157,11 @@
         obj.flags = reader.read("!H")[0]
         reader.skip(2)
         obj.match = common.match.unpack(reader)
-        obj.instructions = instruction.unpack_list(reader)
+        obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.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.cookie != other.cookie: return False
         if self.cookie_mask != other.cookie_mask: return False
@@ -3354,16 +3177,6 @@
         if self.instructions != other.instructions: 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():
@@ -3413,13 +3226,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete(Message):
+flow_mod.subtypes[0] = flow_add
+
+class flow_delete(flow_mod):
     version = 2
     type = 14
     _command = 3
 
     def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -3468,6 +3286,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -3488,24 +3307,21 @@
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 2)
         packed.append(self.match.pack())
-        packed.append(util.pack_list(self.instructions))
+        packed.append(loxi.generic_util.pack_list(self.instructions))
         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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.cookie_mask = reader.read("!Q")[0]
@@ -3521,13 +3337,11 @@
         obj.flags = reader.read("!H")[0]
         reader.skip(2)
         obj.match = common.match.unpack(reader)
-        obj.instructions = instruction.unpack_list(reader)
+        obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.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.cookie != other.cookie: return False
         if self.cookie_mask != other.cookie_mask: return False
@@ -3543,16 +3357,6 @@
         if self.instructions != other.instructions: 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():
@@ -3602,13 +3406,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete_strict(Message):
+flow_mod.subtypes[3] = flow_delete
+
+class flow_delete_strict(flow_mod):
     version = 2
     type = 14
     _command = 4
 
     def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -3657,6 +3466,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -3677,24 +3487,21 @@
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 2)
         packed.append(self.match.pack())
-        packed.append(util.pack_list(self.instructions))
+        packed.append(loxi.generic_util.pack_list(self.instructions))
         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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.cookie_mask = reader.read("!Q")[0]
@@ -3710,13 +3517,11 @@
         obj.flags = reader.read("!H")[0]
         reader.skip(2)
         obj.match = common.match.unpack(reader)
-        obj.instructions = instruction.unpack_list(reader)
+        obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.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.cookie != other.cookie: return False
         if self.cookie_mask != other.cookie_mask: return False
@@ -3732,16 +3537,6 @@
         if self.instructions != other.instructions: 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():
@@ -3791,13 +3586,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 = 2
     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:
@@ -3806,6 +3606,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -3821,18 +3622,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 == 2)
         _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)
@@ -3842,23 +3640,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():
@@ -3878,13 +3664,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify(Message):
+error_msg.subtypes[5] = flow_mod_failed_error_msg
+
+class flow_modify(flow_mod):
     version = 2
     type = 14
     _command = 1
 
     def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -3933,6 +3724,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -3953,24 +3745,21 @@
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 2)
         packed.append(self.match.pack())
-        packed.append(util.pack_list(self.instructions))
+        packed.append(loxi.generic_util.pack_list(self.instructions))
         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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.cookie_mask = reader.read("!Q")[0]
@@ -3986,13 +3775,11 @@
         obj.flags = reader.read("!H")[0]
         reader.skip(2)
         obj.match = common.match.unpack(reader)
-        obj.instructions = instruction.unpack_list(reader)
+        obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.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.cookie != other.cookie: return False
         if self.cookie_mask != other.cookie_mask: return False
@@ -4008,16 +3795,6 @@
         if self.instructions != other.instructions: 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():
@@ -4067,13 +3844,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify_strict(Message):
+flow_mod.subtypes[1] = flow_modify
+
+class flow_modify_strict(flow_mod):
     version = 2
     type = 14
     _command = 2
 
     def __init__(self, xid=None, cookie=None, cookie_mask=None, table_id=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, out_group=None, flags=None, match=None, instructions=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -4122,6 +3904,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -4142,24 +3925,21 @@
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 2)
         packed.append(self.match.pack())
-        packed.append(util.pack_list(self.instructions))
+        packed.append(loxi.generic_util.pack_list(self.instructions))
         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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.cookie_mask = reader.read("!Q")[0]
@@ -4175,13 +3955,11 @@
         obj.flags = reader.read("!H")[0]
         reader.skip(2)
         obj.match = common.match.unpack(reader)
-        obj.instructions = instruction.unpack_list(reader)
+        obj.instructions = loxi.generic_util.unpack_list(reader, instruction.instruction.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.cookie != other.cookie: return False
         if self.cookie_mask != other.cookie_mask: return False
@@ -4197,16 +3975,6 @@
         if self.instructions != other.instructions: 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():
@@ -4256,12 +4024,17 @@
             q.breakable()
         q.text('}')
 
-class flow_removed(Message):
+flow_mod.subtypes[2] = flow_modify_strict
+
+class flow_removed(message):
     version = 2
     type = 11
 
     def __init__(self, xid=None, cookie=None, priority=None, reason=None, table_id=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None, match=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -4302,6 +4075,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -4325,18 +4099,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 == 2)
         _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.cookie = reader.read("!Q")[0]
         obj.priority = reader.read("!H")[0]
@@ -4353,8 +4124,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.cookie != other.cookie: return False
         if self.priority != other.priority: return False
@@ -4368,16 +4137,6 @@
         if self.match != other.match: 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():
@@ -4421,13 +4180,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_reply(Message):
+message.subtypes[11] = flow_removed
+
+class flow_stats_reply(stats_reply):
     version = 2
     type = 19
     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:
@@ -4436,6 +4200,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -4446,51 +4211,36 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 1)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        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():
@@ -4510,13 +4260,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_request(Message):
+stats_reply.subtypes[1] = flow_stats_reply
+
+class flow_stats_request(stats_request):
     version = 2
     type = 18
     stats_type = 1
 
     def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -4545,6 +4300,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -4568,18 +4324,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 1)
@@ -4597,8 +4350,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.table_id != other.table_id: return False
@@ -4609,16 +4360,6 @@
         if self.match != other.match: 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():
@@ -4653,12 +4394,17 @@
             q.breakable()
         q.text('}')
 
-class get_config_reply(Message):
+stats_request.subtypes[1] = flow_stats_request
+
+class get_config_reply(message):
     version = 2
     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:
@@ -4667,6 +4413,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -4681,18 +4428,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 == 2)
         _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]
@@ -4700,23 +4444,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():
@@ -4736,12 +4468,18 @@
             q.breakable()
         q.text('}')
 
-class get_config_request(Message):
+message.subtypes[8] = get_config_reply
+
+class get_config_request(message):
     version = 2
     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 = []
@@ -4754,38 +4492,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 == 2)
         _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():
@@ -4799,13 +4522,32 @@
             q.breakable()
         q.text('}')
 
-class group_add(Message):
+message.subtypes[7] = get_config_request
+
+class group_mod(message):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 8)
+        try:
+            subclass = group_mod.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown group_mod message subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+message.subtypes[15] = group_mod
+
+class group_add(group_mod):
     version = 2
     type = 15
     command = 0
 
     def __init__(self, xid=None, group_type=None, group_id=None, buckets=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if group_type != None:
             self.group_type = group_type
         else:
@@ -4818,6 +4560,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -4829,53 +4572,38 @@
         packed.append(struct.pack("!B", self.group_type))
         packed.append('\x00' * 1)
         packed.append(struct.pack("!L", self.group_id))
-        packed.append(util.pack_list(self.buckets))
+        packed.append(loxi.generic_util.pack_list(self.buckets))
         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 = group_add()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 2)
         _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]
         _command = reader.read("!H")[0]
         assert(_command == 0)
         obj.group_type = reader.read("!B")[0]
         reader.skip(1)
         obj.group_id = reader.read("!L")[0]
-        obj.buckets = common.unpack_list_bucket(reader)
+        obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.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.group_type != other.group_type: return False
         if self.group_id != other.group_id: return False
         if self.buckets != other.buckets: 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("group_add {")
         with q.group():
@@ -4898,13 +4626,18 @@
             q.breakable()
         q.text('}')
 
-class group_delete(Message):
+group_mod.subtypes[0] = group_add
+
+class group_delete(group_mod):
     version = 2
     type = 15
     command = 2
 
     def __init__(self, xid=None, group_type=None, group_id=None, buckets=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if group_type != None:
             self.group_type = group_type
         else:
@@ -4917,6 +4650,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -4928,53 +4662,38 @@
         packed.append(struct.pack("!B", self.group_type))
         packed.append('\x00' * 1)
         packed.append(struct.pack("!L", self.group_id))
-        packed.append(util.pack_list(self.buckets))
+        packed.append(loxi.generic_util.pack_list(self.buckets))
         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 = group_delete()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 2)
         _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]
         _command = reader.read("!H")[0]
         assert(_command == 2)
         obj.group_type = reader.read("!B")[0]
         reader.skip(1)
         obj.group_id = reader.read("!L")[0]
-        obj.buckets = common.unpack_list_bucket(reader)
+        obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.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.group_type != other.group_type: return False
         if self.group_id != other.group_id: return False
         if self.buckets != other.buckets: 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("group_delete {")
         with q.group():
@@ -4997,13 +4716,18 @@
             q.breakable()
         q.text('}')
 
-class group_desc_stats_reply(Message):
+group_mod.subtypes[2] = group_delete
+
+class group_desc_stats_reply(stats_reply):
     version = 2
     type = 19
     stats_type = 7
 
     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:
@@ -5012,6 +4736,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -5022,51 +4747,36 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 = group_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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 7)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = common.unpack_list_group_desc_stats_entry(reader)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.group_desc_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("group_desc_stats_reply {")
         with q.group():
@@ -5086,17 +4796,23 @@
             q.breakable()
         q.text('}')
 
-class group_desc_stats_request(Message):
+stats_reply.subtypes[7] = group_desc_stats_reply
+
+class group_desc_stats_request(stats_request):
     version = 2
     type = 18
     stats_type = 7
 
     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 = []
@@ -5112,18 +4828,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 = group_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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 7)
@@ -5133,22 +4846,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("group_desc_stats_request {")
         with q.group():
@@ -5165,13 +4866,18 @@
             q.breakable()
         q.text('}')
 
-class group_mod_failed_error_msg(Message):
+stats_request.subtypes[7] = group_desc_stats_request
+
+class group_mod_failed_error_msg(error_msg):
     version = 2
     type = 1
     err_type = 6
 
     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:
@@ -5180,6 +4886,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5195,18 +4902,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 = group_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 == 2)
         _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 == 6)
@@ -5216,23 +4920,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("group_mod_failed_error_msg {")
         with q.group():
@@ -5252,13 +4944,18 @@
             q.breakable()
         q.text('}')
 
-class group_modify(Message):
+error_msg.subtypes[6] = group_mod_failed_error_msg
+
+class group_modify(group_mod):
     version = 2
     type = 15
     command = 1
 
     def __init__(self, xid=None, group_type=None, group_id=None, buckets=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if group_type != None:
             self.group_type = group_type
         else:
@@ -5271,6 +4968,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -5282,53 +4980,38 @@
         packed.append(struct.pack("!B", self.group_type))
         packed.append('\x00' * 1)
         packed.append(struct.pack("!L", self.group_id))
-        packed.append(util.pack_list(self.buckets))
+        packed.append(loxi.generic_util.pack_list(self.buckets))
         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 = group_modify()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 2)
         _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]
         _command = reader.read("!H")[0]
         assert(_command == 1)
         obj.group_type = reader.read("!B")[0]
         reader.skip(1)
         obj.group_id = reader.read("!L")[0]
-        obj.buckets = common.unpack_list_bucket(reader)
+        obj.buckets = loxi.generic_util.unpack_list(reader, common.bucket.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.group_type != other.group_type: return False
         if self.group_id != other.group_id: return False
         if self.buckets != other.buckets: 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("group_modify {")
         with q.group():
@@ -5351,13 +5034,18 @@
             q.breakable()
         q.text('}')
 
-class group_stats_reply(Message):
+group_mod.subtypes[1] = group_modify
+
+class group_stats_reply(stats_reply):
     version = 2
     type = 19
     stats_type = 6
 
     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:
@@ -5366,6 +5054,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -5376,51 +5065,36 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 = group_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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 6)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = common.unpack_list_group_stats_entry(reader)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.group_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("group_stats_reply {")
         with q.group():
@@ -5440,13 +5114,18 @@
             q.breakable()
         q.text('}')
 
-class group_stats_request(Message):
+stats_reply.subtypes[6] = group_stats_reply
+
+class group_stats_request(stats_request):
     version = 2
     type = 18
     stats_type = 6
 
     def __init__(self, xid=None, flags=None, group_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -5455,6 +5134,7 @@
             self.group_id = group_id
         else:
             self.group_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -5472,18 +5152,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 = group_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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 6)
@@ -5495,23 +5172,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.group_id != other.group_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("group_stats_request {")
         with q.group():
@@ -5531,12 +5196,18 @@
             q.breakable()
         q.text('}')
 
-class hello(Message):
+stats_request.subtypes[6] = group_stats_request
+
+class hello(message):
     version = 2
     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 = []
@@ -5549,38 +5220,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 == 2)
         _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():
@@ -5594,13 +5250,18 @@
             q.breakable()
         q.text('}')
 
-class hello_failed_error_msg(Message):
+message.subtypes[0] = hello
+
+class hello_failed_error_msg(error_msg):
     version = 2
     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:
@@ -5609,6 +5270,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5624,18 +5286,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 == 2)
         _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)
@@ -5645,23 +5304,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():
@@ -5681,12 +5328,31 @@
             q.breakable()
         q.text('}')
 
-class packet_in(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 packet_in(message):
     version = 2
     type = 10
 
     def __init__(self, xid=None, buffer_id=None, in_port=None, in_phy_port=None, total_len=None, reason=None, table_id=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:
@@ -5715,6 +5381,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5734,18 +5401,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 == 2)
         _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.in_port = util.unpack_port_no(reader)
@@ -5758,8 +5422,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.in_port != other.in_port: return False
@@ -5770,16 +5432,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():
@@ -5814,12 +5466,17 @@
             q.breakable()
         q.text('}')
 
-class packet_out(Message):
+message.subtypes[10] = packet_in
+
+class packet_out(message):
     version = 2
     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:
@@ -5836,6 +5493,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5847,7 +5505,7 @@
         packed.append(util.pack_port_no(self.in_port))
         packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
         packed.append('\x00' * 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])
@@ -5855,31 +5513,26 @@
         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 == 2)
         _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]
         reader.skip(6)
-        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
@@ -5887,16 +5540,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():
@@ -5922,12 +5565,17 @@
             q.breakable()
         q.text('}')
 
-class port_mod(Message):
+message.subtypes[13] = packet_out
+
+class port_mod(message):
     version = 2
     type = 16
 
     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:
@@ -5948,6 +5596,7 @@
             self.advertise = advertise
         else:
             self.advertise = 0
+        return
 
     def pack(self):
         packed = []
@@ -5968,18 +5617,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 == 2)
         _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]
         obj.port_no = util.unpack_port_no(reader)
         reader.skip(4)
@@ -5993,8 +5639,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
@@ -6003,16 +5647,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():
@@ -6041,13 +5675,18 @@
             q.breakable()
         q.text('}')
 
-class port_mod_failed_error_msg(Message):
+message.subtypes[16] = port_mod
+
+class port_mod_failed_error_msg(error_msg):
     version = 2
     type = 1
     err_type = 7
 
     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:
@@ -6056,6 +5695,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -6071,18 +5711,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 == 2)
         _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 == 7)
@@ -6092,23 +5729,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():
@@ -6128,13 +5753,18 @@
             q.breakable()
         q.text('}')
 
-class port_stats_reply(Message):
+error_msg.subtypes[7] = port_mod_failed_error_msg
+
+class port_stats_reply(stats_reply):
     version = 2
     type = 19
     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:
@@ -6143,6 +5773,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6153,24 +5784,21 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 4)
@@ -6181,23 +5809,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():
@@ -6217,13 +5833,18 @@
             q.breakable()
         q.text('}')
 
-class port_stats_request(Message):
+stats_reply.subtypes[4] = port_stats_reply
+
+class port_stats_request(stats_request):
     version = 2
     type = 18
     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:
@@ -6232,6 +5853,7 @@
             self.port_no = port_no
         else:
             self.port_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -6249,18 +5871,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 4)
@@ -6272,23 +5891,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():
@@ -6308,12 +5915,17 @@
             q.breakable()
         q.text('}')
 
-class port_status(Message):
+stats_request.subtypes[4] = port_stats_request
+
+class port_status(message):
     version = 2
     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:
@@ -6322,6 +5934,7 @@
             self.desc = desc
         else:
             self.desc = common.port_desc()
+        return
 
     def pack(self):
         packed = []
@@ -6337,18 +5950,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 == 2)
         _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)
@@ -6357,23 +5967,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():
@@ -6393,12 +5991,17 @@
             q.breakable()
         q.text('}')
 
-class queue_get_config_reply(Message):
+message.subtypes[12] = port_status
+
+class queue_get_config_reply(message):
     version = 2
     type = 23
 
     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:
@@ -6407,6 +6010,7 @@
             self.queues = queues
         else:
             self.queues = []
+        return
 
     def pack(self):
         packed = []
@@ -6416,49 +6020,34 @@
         packed.append(struct.pack("!L", self.xid))
         packed.append(util.pack_port_no(self.port))
         packed.append('\x00' * 4)
-        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 == 2)
         _type = reader.read("!B")[0]
         assert(_type == 23)
         _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(4)
-        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():
@@ -6478,16 +6067,22 @@
             q.breakable()
         q.text('}')
 
-class queue_get_config_request(Message):
+message.subtypes[23] = queue_get_config_reply
+
+class queue_get_config_request(message):
     version = 2
     type = 22
 
     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 = []
@@ -6502,18 +6097,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 == 2)
         _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.port = util.unpack_port_no(reader)
         reader.skip(4)
@@ -6521,22 +6113,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():
@@ -6553,13 +6133,18 @@
             q.breakable()
         q.text('}')
 
-class queue_op_failed_error_msg(Message):
+message.subtypes[22] = queue_get_config_request
+
+class queue_op_failed_error_msg(error_msg):
     version = 2
     type = 1
     err_type = 9
 
     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:
@@ -6568,6 +6153,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -6583,18 +6169,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 == 2)
         _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 == 9)
@@ -6604,23 +6187,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():
@@ -6640,13 +6211,18 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_reply(Message):
+error_msg.subtypes[9] = queue_op_failed_error_msg
+
+class queue_stats_reply(stats_reply):
     version = 2
     type = 19
     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:
@@ -6655,6 +6231,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6665,24 +6242,21 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 5)
@@ -6693,23 +6267,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():
@@ -6729,13 +6291,18 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_request(Message):
+stats_reply.subtypes[5] = queue_stats_reply
+
+class queue_stats_request(stats_request):
     version = 2
     type = 18
     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:
@@ -6748,6 +6315,7 @@
             self.queue_id = queue_id
         else:
             self.queue_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -6765,18 +6333,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 5)
@@ -6788,24 +6353,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():
@@ -6828,12 +6381,17 @@
             q.breakable()
         q.text('}')
 
-class set_config(Message):
+stats_request.subtypes[5] = queue_stats_request
+
+class set_config(message):
     version = 2
     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:
@@ -6842,6 +6400,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -6856,18 +6415,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 == 2)
         _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]
@@ -6875,23 +6431,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():
@@ -6911,13 +6455,18 @@
             q.breakable()
         q.text('}')
 
-class switch_config_failed_error_msg(Message):
+message.subtypes[9] = set_config
+
+class switch_config_failed_error_msg(error_msg):
     version = 2
     type = 1
     err_type = 10
 
     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:
@@ -6926,6 +6475,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -6941,18 +6491,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 = switch_config_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 == 2)
         _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 == 10)
@@ -6962,23 +6509,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("switch_config_failed_error_msg {")
         with q.group():
@@ -6998,12 +6533,17 @@
             q.breakable()
         q.text('}')
 
-class table_mod(Message):
+error_msg.subtypes[10] = switch_config_failed_error_msg
+
+class table_mod(message):
     version = 2
     type = 17
 
     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:
@@ -7012,6 +6552,7 @@
             self.config = config
         else:
             self.config = 0
+        return
 
     def pack(self):
         packed = []
@@ -7027,18 +6568,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 == 2)
         _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]
         obj.table_id = reader.read("!B")[0]
         reader.skip(3)
@@ -7047,23 +6585,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():
@@ -7083,13 +6609,18 @@
             q.breakable()
         q.text('}')
 
-class table_mod_failed_error_msg(Message):
+message.subtypes[17] = table_mod
+
+class table_mod_failed_error_msg(error_msg):
     version = 2
     type = 1
     err_type = 8
 
     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:
@@ -7098,6 +6629,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -7113,18 +6645,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_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 == 2)
         _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 == 8)
@@ -7134,23 +6663,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("table_mod_failed_error_msg {")
         with q.group():
@@ -7170,13 +6687,18 @@
             q.breakable()
         q.text('}')
 
-class table_stats_reply(Message):
+error_msg.subtypes[8] = table_mod_failed_error_msg
+
+class table_stats_reply(stats_reply):
     version = 2
     type = 19
     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:
@@ -7185,6 +6707,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -7195,24 +6718,21 @@
         packed.append(struct.pack("!H", self.stats_type))
         packed.append(struct.pack("!H", self.flags))
         packed.append('\x00' * 4)
-        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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 3)
@@ -7223,23 +6743,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():
@@ -7259,17 +6767,23 @@
             q.breakable()
         q.text('}')
 
-class table_stats_request(Message):
+stats_reply.subtypes[3] = table_stats_reply
+
+class table_stats_request(stats_request):
     version = 2
     type = 18
     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 = []
@@ -7285,18 +6799,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 == 2)
         _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]
         _stats_type = reader.read("!H")[0]
         assert(_stats_type == 3)
@@ -7306,22 +6817,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():
@@ -7338,6 +6837,8 @@
             q.breakable()
         q.text('}')
 
+stats_request.subtypes[3] = table_stats_request
+
 
 def parse_header(buf):
     if len(buf) < 8:
@@ -7350,210 +6851,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) < 25 + 1:
-        raise loxi.ProtocolError("message too short")
-    # Technically uint16_t for OF 1.0
-    cmd, = struct.unpack_from("!B", buf, 25)
-    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_GROUP_MOD : parse_group_mod,
-    const.OFPT_PORT_MOD : port_mod.unpack,
-    const.OFPT_TABLE_MOD : table_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,
-}
-
-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,
-    const.OFPET_BAD_INSTRUCTION : bad_instruction_error_msg.unpack,
-    const.OFPET_BAD_MATCH : bad_match_error_msg.unpack,
-    const.OFPET_GROUP_MOD_FAILED : group_mod_failed_error_msg.unpack,
-    const.OFPET_TABLE_MOD_FAILED : table_mod_failed_error_msg.unpack,
-    const.OFPET_SWITCH_CONFIG_FAILED : switch_config_failed_error_msg.unpack,
-}
-
-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,
-}
-
-group_mod_parsers = {
-    const.OFPGC_ADD : group_add.unpack,
-    const.OFPGC_MODIFY : group_modify.unpack,
-    const.OFPGC_DELETE : group_delete.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,
-    const.OFPST_GROUP : group_stats_reply.unpack,
-    const.OFPST_GROUP_DESC : group_desc_stats_reply.unpack,
-}
-
-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,
-    const.OFPST_GROUP : group_stats_request.unpack,
-    const.OFPST_GROUP_DESC : group_desc_stats_request.unpack,
-}
-
-experimenter_parsers = {
-    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,
-        5: bsn_get_mirroring_reply.unpack,
-        4: bsn_get_mirroring_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,
-        3: bsn_set_mirroring.unpack,
-        25: bsn_set_pktin_suppression_reply.unpack,
-        11: bsn_set_pktin_suppression_request.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))