diff --git a/src/python/loxi/of13/message.py b/src/python/loxi/of13/message.py
index 9de2440..2737bd1 100644
--- a/src/python/loxi/of13/message.py
+++ b/src/python/loxi/of13/message.py
@@ -3,31 +3,59 @@
 # Copyright (c) 2012, 2013 Big Switch Networks, Inc.
 # See the file LICENSE.pyloxi which should have been included in the source distribution
 
-# Automatically generated by LOXI from template 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 meter_band # for unpack_list
+import action
+import instruction
+import oxm
+import action_id
+import instruction_id
+import meter_band
 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 = 4
     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:
@@ -44,6 +72,7 @@
             self.flow_count = flow_count
         else:
             self.flow_count = 0
+        return
 
     def pack(self):
         packed = []
@@ -63,18 +92,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 == 4)
         _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)
@@ -88,8 +114,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
@@ -97,16 +121,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():
@@ -132,13 +146,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 = 4
     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:
@@ -167,6 +200,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -190,18 +224,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 == 4)
         _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)
@@ -219,8 +250,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
@@ -231,16 +260,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():
@@ -275,12 +294,17 @@
             q.breakable()
         q.text('}')
 
-class async_get_reply(Message):
+stats_request.subtypes[2] = aggregate_stats_request
+
+class async_get_reply(message):
     version = 4
     type = 27
 
     def __init__(self, xid=None, packet_in_mask_equal_master=None, packet_in_mask_slave=None, port_status_mask_equal_master=None, port_status_mask_slave=None, flow_removed_mask_equal_master=None, flow_removed_mask_slave=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if packet_in_mask_equal_master != None:
             self.packet_in_mask_equal_master = packet_in_mask_equal_master
         else:
@@ -305,6 +329,7 @@
             self.flow_removed_mask_slave = flow_removed_mask_slave
         else:
             self.flow_removed_mask_slave = 0
+        return
 
     def pack(self):
         packed = []
@@ -323,18 +348,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 = async_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 == 4)
         _type = reader.read("!B")[0]
         assert(_type == 27)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.packet_in_mask_equal_master = reader.read("!L")[0]
         obj.packet_in_mask_slave = reader.read("!L")[0]
@@ -346,8 +368,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.packet_in_mask_equal_master != other.packet_in_mask_equal_master: return False
         if self.packet_in_mask_slave != other.packet_in_mask_slave: return False
@@ -357,16 +377,6 @@
         if self.flow_removed_mask_slave != other.flow_removed_mask_slave: 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("async_get_reply {")
         with q.group():
@@ -398,12 +408,17 @@
             q.breakable()
         q.text('}')
 
-class async_get_request(Message):
+message.subtypes[27] = async_get_reply
+
+class async_get_request(message):
     version = 4
     type = 26
 
     def __init__(self, xid=None, packet_in_mask_equal_master=None, packet_in_mask_slave=None, port_status_mask_equal_master=None, port_status_mask_slave=None, flow_removed_mask_equal_master=None, flow_removed_mask_slave=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if packet_in_mask_equal_master != None:
             self.packet_in_mask_equal_master = packet_in_mask_equal_master
         else:
@@ -428,6 +443,7 @@
             self.flow_removed_mask_slave = flow_removed_mask_slave
         else:
             self.flow_removed_mask_slave = 0
+        return
 
     def pack(self):
         packed = []
@@ -446,18 +462,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 = async_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 == 4)
         _type = reader.read("!B")[0]
         assert(_type == 26)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.packet_in_mask_equal_master = reader.read("!L")[0]
         obj.packet_in_mask_slave = reader.read("!L")[0]
@@ -469,8 +482,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.packet_in_mask_equal_master != other.packet_in_mask_equal_master: return False
         if self.packet_in_mask_slave != other.packet_in_mask_slave: return False
@@ -480,16 +491,6 @@
         if self.flow_removed_mask_slave != other.flow_removed_mask_slave: 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("async_get_request {")
         with q.group():
@@ -521,12 +522,17 @@
             q.breakable()
         q.text('}')
 
-class async_set(Message):
+message.subtypes[26] = async_get_request
+
+class async_set(message):
     version = 4
     type = 28
 
     def __init__(self, xid=None, packet_in_mask_equal_master=None, packet_in_mask_slave=None, port_status_mask_equal_master=None, port_status_mask_slave=None, flow_removed_mask_equal_master=None, flow_removed_mask_slave=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if packet_in_mask_equal_master != None:
             self.packet_in_mask_equal_master = packet_in_mask_equal_master
         else:
@@ -551,6 +557,7 @@
             self.flow_removed_mask_slave = flow_removed_mask_slave
         else:
             self.flow_removed_mask_slave = 0
+        return
 
     def pack(self):
         packed = []
@@ -569,18 +576,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 = async_set()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _type = reader.read("!B")[0]
         assert(_type == 28)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.packet_in_mask_equal_master = reader.read("!L")[0]
         obj.packet_in_mask_slave = reader.read("!L")[0]
@@ -592,8 +596,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.packet_in_mask_equal_master != other.packet_in_mask_equal_master: return False
         if self.packet_in_mask_slave != other.packet_in_mask_slave: return False
@@ -603,16 +605,6 @@
         if self.flow_removed_mask_slave != other.flow_removed_mask_slave: 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("async_set {")
         with q.group():
@@ -644,13 +636,32 @@
             q.breakable()
         q.text('}')
 
-class bad_action_error_msg(Message):
+message.subtypes[28] = async_set
+
+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 = 4
     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:
@@ -659,6 +670,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -674,18 +686,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 == 4)
         _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)
@@ -695,23 +704,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():
@@ -731,13 +728,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 = 4
     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:
@@ -746,6 +748,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -761,18 +764,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 == 4)
         _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)
@@ -782,23 +782,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():
@@ -818,13 +806,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 = 4
     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:
@@ -833,6 +826,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -848,18 +842,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 == 4)
         _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)
@@ -869,23 +860,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():
@@ -905,13 +884,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 = 4
     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:
@@ -920,6 +904,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -935,18 +920,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 == 4)
         _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)
@@ -956,23 +938,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():
@@ -992,12 +962,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_reply(Message):
+error_msg.subtypes[1] = bad_request_error_msg
+
+class barrier_reply(message):
     version = 4
     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 = []
@@ -1010,38 +986,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 == 4)
         _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():
@@ -1055,12 +1016,18 @@
             q.breakable()
         q.text('}')
 
-class barrier_request(Message):
+message.subtypes[21] = barrier_reply
+
+class barrier_request(message):
     version = 4
     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 = []
@@ -1073,38 +1040,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 == 4)
         _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():
@@ -1118,18 +1070,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 = 4
     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 = []
@@ -1145,18 +1131,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 == 4)
         _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)
@@ -1167,22 +1150,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():
@@ -1199,14 +1170,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 = 4
     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 = []
@@ -1221,18 +1198,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 == 4)
         _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)
@@ -1242,21 +1216,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():
@@ -1270,18 +1232,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 = 4
     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 = []
@@ -1297,18 +1265,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 == 4)
         _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)
@@ -1319,22 +1284,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():
@@ -1351,14 +1304,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 = 4
     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 = []
@@ -1373,18 +1332,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 == 4)
         _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)
@@ -1394,21 +1350,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():
@@ -1422,14 +1366,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 = 4
     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:
@@ -1438,6 +1387,7 @@
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -1454,18 +1404,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 == 4)
         _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)
@@ -1477,23 +1424,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():
@@ -1513,18 +1448,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 = 4
     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 = []
@@ -1540,18 +1481,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 == 4)
         _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)
@@ -1562,22 +1500,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():
@@ -1594,14 +1520,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_flow_idle(Message):
+bsn_header.subtypes[18] = bsn_bw_enable_set_request
+
+class bsn_flow_idle(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 40
 
     def __init__(self, xid=None, cookie=None, priority=None, table_id=None, match=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if cookie != None:
             self.cookie = cookie
         else:
@@ -1618,6 +1549,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -1637,18 +1569,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_flow_idle()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -1663,8 +1592,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
@@ -1672,16 +1599,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("bsn_flow_idle {")
         with q.group():
@@ -1707,18 +1624,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_flow_idle_enable_get_reply(Message):
+bsn_header.subtypes[40] = bsn_flow_idle
+
+class bsn_flow_idle_enable_get_reply(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 39
 
     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 = []
@@ -1734,18 +1657,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_flow_idle_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 == 4)
         _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)
@@ -1756,22 +1676,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_flow_idle_enable_get_reply {")
         with q.group():
@@ -1788,14 +1696,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_flow_idle_enable_get_request(Message):
+bsn_header.subtypes[39] = bsn_flow_idle_enable_get_reply
+
+class bsn_flow_idle_enable_get_request(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 38
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -1810,18 +1724,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_flow_idle_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 == 4)
         _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)
@@ -1831,21 +1742,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_flow_idle_enable_get_request {")
         with q.group():
@@ -1859,14 +1758,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_flow_idle_enable_set_reply(Message):
+bsn_header.subtypes[38] = bsn_flow_idle_enable_get_request
+
+class bsn_flow_idle_enable_set_reply(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 37
 
     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:
@@ -1875,6 +1779,7 @@
             self.status = status
         else:
             self.status = 0
+        return
 
     def pack(self):
         packed = []
@@ -1891,18 +1796,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_flow_idle_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 == 4)
         _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)
@@ -1914,23 +1816,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_flow_idle_enable_set_reply {")
         with q.group():
@@ -1950,18 +1840,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_flow_idle_enable_set_request(Message):
+bsn_header.subtypes[37] = bsn_flow_idle_enable_set_reply
+
+class bsn_flow_idle_enable_set_request(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 36
 
     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 = []
@@ -1977,18 +1873,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_flow_idle_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 == 4)
         _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)
@@ -1999,22 +1892,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_flow_idle_enable_set_request {")
         with q.group():
@@ -2031,18 +1912,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_get_interfaces_reply(Message):
+bsn_header.subtypes[36] = bsn_flow_idle_enable_set_request
+
+class bsn_get_interfaces_reply(bsn_header):
     version = 4
     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 = []
@@ -2052,24 +1939,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 == 4)
         _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)
@@ -2080,22 +1964,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():
@@ -2112,14 +1984,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 = 4
     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 = []
@@ -2134,18 +2012,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 == 4)
         _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)
@@ -2155,21 +2030,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():
@@ -2183,18 +2046,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 = 4
     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 = []
@@ -2211,18 +2080,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 == 4)
         _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)
@@ -2234,22 +2100,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():
@@ -2266,18 +2120,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 = 4
     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 = []
@@ -2294,18 +2154,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 == 4)
         _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)
@@ -2317,22 +2174,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():
@@ -2349,14 +2194,153 @@
             q.breakable()
         q.text('}')
 
-class bsn_lacp_convergence_notif(Message):
+bsn_header.subtypes[4] = bsn_get_mirroring_request
+
+class bsn_get_switch_pipeline_reply(bsn_header):
+    version = 4
+    type = 4
+    experimenter = 6035143
+    subtype = 52
+
+    def __init__(self, xid=None, pipeline=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if pipeline != None:
+            self.pipeline = pipeline
+        else:
+            self.pipeline = ""
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!256s", self.pipeline))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_get_switch_pipeline_reply()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 52)
+        obj.pipeline = reader.read("!256s")[0].rstrip("\x00")
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        if self.pipeline != other.pipeline: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_get_switch_pipeline_reply {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("pipeline = ");
+                q.pp(self.pipeline)
+            q.breakable()
+        q.text('}')
+
+bsn_header.subtypes[52] = bsn_get_switch_pipeline_reply
+
+class bsn_get_switch_pipeline_request(bsn_header):
+    version = 4
+    type = 4
+    experimenter = 6035143
+    subtype = 51
+
+    def __init__(self, xid=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_get_switch_pipeline_request()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 51)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_get_switch_pipeline_request {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+            q.breakable()
+        q.text('}')
+
+bsn_header.subtypes[51] = bsn_get_switch_pipeline_request
+
+class bsn_lacp_convergence_notif(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 43
 
     def __init__(self, xid=None, convergence_status=None, port_no=None, actor_sys_priority=None, actor_sys_mac=None, actor_port_priority=None, actor_port_num=None, actor_key=None, partner_sys_priority=None, partner_sys_mac=None, partner_port_priority=None, partner_port_num=None, partner_key=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if convergence_status != None:
             self.convergence_status = convergence_status
         else:
@@ -2405,6 +2389,7 @@
             self.partner_key = partner_key
         else:
             self.partner_key = 0
+        return
 
     def pack(self):
         packed = []
@@ -2432,18 +2417,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_lacp_convergence_notif()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -2466,8 +2448,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.convergence_status != other.convergence_status: return False
         if self.port_no != other.port_no: return False
@@ -2483,16 +2463,6 @@
         if self.partner_key != other.partner_key: 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_lacp_convergence_notif {")
         with q.group():
@@ -2542,7 +2512,37 @@
             q.breakable()
         q.text('}')
 
-class bsn_lacp_stats_reply(Message):
+bsn_header.subtypes[43] = bsn_lacp_convergence_notif
+
+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 bsn_lacp_stats_reply(bsn_stats_reply):
     version = 4
     type = 19
     stats_type = 65535
@@ -2550,7 +2550,10 @@
     subtype = 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:
@@ -2559,6 +2562,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -2571,24 +2575,21 @@
         packed.append('\x00' * 4)
         packed.append(struct.pack("!L", self.experimenter))
         packed.append(struct.pack("!L", self.subtype))
-        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 = bsn_lacp_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 == 4)
         _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 == 65535)
@@ -2603,23 +2604,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("bsn_lacp_stats_reply {")
         with q.group():
@@ -2639,7 +2628,37 @@
             q.breakable()
         q.text('}')
 
-class bsn_lacp_stats_request(Message):
+bsn_stats_reply.subtypes[1] = bsn_lacp_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_lacp_stats_request(bsn_stats_request):
     version = 4
     type = 18
     stats_type = 65535
@@ -2647,11 +2666,15 @@
     subtype = 1
 
     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 = []
@@ -2669,18 +2692,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_lacp_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 == 4)
         _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 == 65535)
@@ -2694,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("bsn_lacp_stats_request {")
         with q.group():
@@ -2726,14 +2734,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_pdu_rx_reply(Message):
+bsn_stats_request.subtypes[1] = bsn_lacp_stats_request
+
+class bsn_pdu_rx_reply(bsn_header):
     version = 4
     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:
@@ -2746,6 +2759,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -2763,18 +2777,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 == 4)
         _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)
@@ -2787,24 +2798,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():
@@ -2827,14 +2826,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 = 4
     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:
@@ -2851,6 +2855,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -2870,18 +2875,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 == 4)
         _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)
@@ -2896,8 +2898,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
@@ -2905,16 +2905,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():
@@ -2940,14 +2930,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 = 4
     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:
@@ -2956,6 +2951,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -2972,18 +2968,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 == 4)
         _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)
@@ -2995,23 +2988,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():
@@ -3031,14 +3012,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 = 4
     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:
@@ -3051,6 +3037,7 @@
             self.slot_num = slot_num
         else:
             self.slot_num = 0
+        return
 
     def pack(self):
         packed = []
@@ -3068,18 +3055,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 == 4)
         _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)
@@ -3092,24 +3076,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():
@@ -3132,14 +3104,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 = 4
     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:
@@ -3156,6 +3133,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -3175,18 +3153,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 == 4)
         _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)
@@ -3201,8 +3176,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
@@ -3210,16 +3183,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():
@@ -3245,14 +3208,195 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_lacp_reply(Message):
+bsn_header.subtypes[31] = bsn_pdu_tx_request
+
+class bsn_port_counter_stats_reply(bsn_stats_reply):
+    version = 4
+    type = 19
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 8
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        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(reader):
+        obj = bsn_port_counter_stats_reply()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 8)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.bsn_port_counter_stats_entry.unpack)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): 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 pretty_print(self, q):
+        q.text("bsn_port_counter_stats_reply {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("entries = ");
+                q.pp(self.entries)
+            q.breakable()
+        q.text('}')
+
+bsn_stats_reply.subtypes[8] = bsn_port_counter_stats_reply
+
+class bsn_port_counter_stats_request(bsn_stats_request):
+    version = 4
+    type = 18
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 8
+
+    def __init__(self, xid=None, flags=None, port_no=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(util.pack_port_no(self.port_no))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_port_counter_stats_request()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 8)
+        obj.port_no = util.unpack_port_no(reader)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): 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 pretty_print(self, q):
+        q.text("bsn_port_counter_stats_request {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("port_no = ");
+                q.text(util.pretty_port(self.port_no))
+            q.breakable()
+        q.text('}')
+
+bsn_stats_request.subtypes[8] = bsn_port_counter_stats_request
+
+class bsn_set_lacp_reply(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 42
 
     def __init__(self, xid=None, status=None, port_no=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if status != None:
             self.status = status
         else:
@@ -3261,6 +3405,7 @@
             self.port_no = port_no
         else:
             self.port_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -3277,18 +3422,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_lacp_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -3300,23 +3442,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.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("bsn_set_lacp_reply {")
         with q.group():
@@ -3336,14 +3466,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_lacp_request(Message):
+bsn_header.subtypes[42] = bsn_set_lacp_reply
+
+class bsn_set_lacp_request(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 41
 
     def __init__(self, xid=None, enabled=None, port_no=None, actor_sys_priority=None, actor_sys_mac=None, actor_port_priority=None, actor_port_num=None, actor_key=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if enabled != None:
             self.enabled = enabled
         else:
@@ -3372,6 +3507,7 @@
             self.actor_key = actor_key
         else:
             self.actor_key = 0
+        return
 
     def pack(self):
         packed = []
@@ -3394,18 +3530,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_lacp_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -3423,8 +3556,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.port_no != other.port_no: return False
@@ -3435,16 +3566,6 @@
         if self.actor_key != other.actor_key: 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_lacp_request {")
         with q.group():
@@ -3479,18 +3600,24 @@
             q.breakable()
         q.text('}')
 
-class bsn_set_mirroring(Message):
+bsn_header.subtypes[41] = bsn_set_lacp_request
+
+class bsn_set_mirroring(bsn_header):
     version = 4
     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 = []
@@ -3507,18 +3634,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 == 4)
         _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)
@@ -3530,22 +3654,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():
@@ -3562,18 +3674,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 = 4
     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 = []
@@ -3589,18 +3707,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 == 4)
         _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)
@@ -3611,22 +3726,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():
@@ -3643,14 +3746,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 = 4
     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:
@@ -3671,6 +3779,7 @@
             self.cookie = cookie
         else:
             self.cookie = 0
+        return
 
     def pack(self):
         packed = []
@@ -3691,18 +3800,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 == 4)
         _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)
@@ -3718,8 +3824,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
@@ -3728,16 +3832,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():
@@ -3766,18 +3860,334 @@
             q.breakable()
         q.text('}')
 
-class bsn_time_reply(Message):
+bsn_header.subtypes[11] = bsn_set_pktin_suppression_request
+
+class bsn_set_switch_pipeline_reply(bsn_header):
+    version = 4
+    type = 4
+    experimenter = 6035143
+    subtype = 54
+
+    def __init__(self, xid=None, status=None):
+        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 = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!L", self.status))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_set_switch_pipeline_reply()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 54)
+        obj.status = reader.read("!L")[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        if self.status != other.status: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_set_switch_pipeline_reply {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("status = ");
+                q.text("%#x" % self.status)
+            q.breakable()
+        q.text('}')
+
+bsn_header.subtypes[54] = bsn_set_switch_pipeline_reply
+
+class bsn_set_switch_pipeline_request(bsn_header):
+    version = 4
+    type = 4
+    experimenter = 6035143
+    subtype = 53
+
+    def __init__(self, xid=None, pipeline=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if pipeline != None:
+            self.pipeline = pipeline
+        else:
+            self.pipeline = ""
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!256s", self.pipeline))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_set_switch_pipeline_request()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 53)
+        obj.pipeline = reader.read("!256s")[0].rstrip("\x00")
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        if self.pipeline != other.pipeline: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_set_switch_pipeline_request {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("pipeline = ");
+                q.pp(self.pipeline)
+            q.breakable()
+        q.text('}')
+
+bsn_header.subtypes[53] = bsn_set_switch_pipeline_request
+
+class bsn_switch_pipeline_stats_reply(bsn_stats_reply):
+    version = 4
+    type = 19
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 6
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        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(reader):
+        obj = bsn_switch_pipeline_stats_reply()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 6)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.bsn_switch_pipeline_stats_entry.unpack)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): 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 pretty_print(self, q):
+        q.text("bsn_switch_pipeline_stats_reply {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("entries = ");
+                q.pp(self.entries)
+            q.breakable()
+        q.text('}')
+
+bsn_stats_reply.subtypes[6] = bsn_switch_pipeline_stats_reply
+
+class bsn_switch_pipeline_stats_request(bsn_stats_request):
+    version = 4
+    type = 18
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 6
+
+    def __init__(self, xid=None, flags=None):
+        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 = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_switch_pipeline_stats_request()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 6)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        if self.flags != other.flags: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_switch_pipeline_stats_request {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+            q.breakable()
+        q.text('}')
+
+bsn_stats_request.subtypes[6] = bsn_switch_pipeline_stats_request
+
+class bsn_time_reply(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 45
 
     def __init__(self, xid=None, time_ms=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if time_ms != None:
             self.time_ms = time_ms
         else:
             self.time_ms = 0
+        return
 
     def pack(self):
         packed = []
@@ -3793,18 +4203,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_time_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -3815,22 +4222,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.time_ms != other.time_ms: 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_time_reply {")
         with q.group():
@@ -3847,14 +4242,20 @@
             q.breakable()
         q.text('}')
 
-class bsn_time_request(Message):
+bsn_header.subtypes[45] = bsn_time_reply
+
+class bsn_time_request(bsn_header):
     version = 4
     type = 4
     experimenter = 6035143
     subtype = 44
 
     def __init__(self, xid=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        return
 
     def pack(self):
         packed = []
@@ -3869,18 +4270,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_time_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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)
@@ -3890,21 +4288,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_time_request {")
         with q.group():
@@ -3918,14 +4304,19 @@
             q.breakable()
         q.text('}')
 
-class bsn_virtual_port_create_reply(Message):
+bsn_header.subtypes[44] = bsn_time_request
+
+class bsn_virtual_port_create_reply(bsn_header):
     version = 4
     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:
@@ -3934,6 +4325,7 @@
             self.vport_no = vport_no
         else:
             self.vport_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -3950,18 +4342,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 == 4)
         _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)
@@ -3973,23 +4362,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():
@@ -4009,18 +4386,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 = 4
     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 = []
@@ -4036,18 +4419,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 == 4)
         _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)
@@ -4058,22 +4438,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():
@@ -4090,18 +4458,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 = 4
     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 = []
@@ -4117,18 +4491,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 == 4)
         _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)
@@ -4139,22 +4510,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():
@@ -4171,18 +4530,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 = 4
     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 = []
@@ -4198,18 +4563,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 == 4)
         _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)
@@ -4220,22 +4582,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():
@@ -4252,13 +4602,194 @@
             q.breakable()
         q.text('}')
 
-class desc_stats_reply(Message):
+bsn_header.subtypes[17] = bsn_virtual_port_remove_request
+
+class bsn_vlan_counter_stats_reply(bsn_stats_reply):
+    version = 4
+    type = 19
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 9
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        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(reader):
+        obj = bsn_vlan_counter_stats_reply()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 9)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.bsn_vlan_counter_stats_entry.unpack)
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): 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 pretty_print(self, q):
+        q.text("bsn_vlan_counter_stats_reply {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("entries = ");
+                q.pp(self.entries)
+            q.breakable()
+        q.text('}')
+
+bsn_stats_reply.subtypes[9] = bsn_vlan_counter_stats_reply
+
+class bsn_vlan_counter_stats_request(bsn_stats_request):
+    version = 4
+    type = 18
+    stats_type = 65535
+    experimenter = 6035143
+    subtype = 9
+
+    def __init__(self, xid=None, flags=None, vlan_vid=None):
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if vlan_vid != None:
+            self.vlan_vid = vlan_vid
+        else:
+            self.vlan_vid = 0
+        return
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.version))
+        packed.append(struct.pack("!B", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!H", self.stats_type))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append('\x00' * 4)
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!H", self.vlan_vid))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(reader):
+        obj = bsn_vlan_counter_stats_request()
+        _version = reader.read("!B")[0]
+        assert(_version == 4)
+        _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 == 65535)
+        obj.flags = reader.read("!H")[0]
+        reader.skip(4)
+        _experimenter = reader.read("!L")[0]
+        assert(_experimenter == 6035143)
+        _subtype = reader.read("!L")[0]
+        assert(_subtype == 9)
+        obj.vlan_vid = reader.read("!H")[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.xid != other.xid: return False
+        if self.flags != other.flags: return False
+        if self.vlan_vid != other.vlan_vid: return False
+        return True
+
+    def pretty_print(self, q):
+        q.text("bsn_vlan_counter_stats_request {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("xid = ");
+                if self.xid != None:
+                    q.text("%#x" % self.xid)
+                else:
+                    q.text('None')
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("vlan_vid = ");
+                q.text("%#x" % self.vlan_vid)
+            q.breakable()
+        q.text('}')
+
+bsn_stats_request.subtypes[9] = bsn_vlan_counter_stats_request
+
+class desc_stats_reply(stats_reply):
     version = 4
     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:
@@ -4283,6 +4814,7 @@
             self.dp_desc = dp_desc
         else:
             self.dp_desc = ""
+        return
 
     def pack(self):
         packed = []
@@ -4303,18 +4835,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 == 4)
         _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)
@@ -4329,8 +4858,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
@@ -4340,16 +4867,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():
@@ -4381,17 +4898,23 @@
             q.breakable()
         q.text('}')
 
-class desc_stats_request(Message):
+stats_reply.subtypes[0] = desc_stats_reply
+
+class desc_stats_request(stats_request):
     version = 4
     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 = []
@@ -4407,18 +4930,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 == 4)
         _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)
@@ -4428,22 +4948,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():
@@ -4460,16 +4968,22 @@
             q.breakable()
         q.text('}')
 
-class echo_reply(Message):
+stats_request.subtypes[0] = desc_stats_request
+
+class echo_reply(message):
     version = 4
     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 = []
@@ -4483,40 +4997,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 == 4)
         _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():
@@ -4533,16 +5032,22 @@
             q.breakable()
         q.text('}')
 
-class echo_request(Message):
+message.subtypes[3] = echo_reply
+
+class echo_request(message):
     version = 4
     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 = []
@@ -4556,40 +5061,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 == 4)
         _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():
@@ -4606,13 +5096,18 @@
             q.breakable()
         q.text('}')
 
-class experimenter_error_msg(Message):
+message.subtypes[2] = echo_request
+
+class experimenter_error_msg(error_msg):
     version = 4
     type = 1
     err_type = 65535
 
     def __init__(self, xid=None, subtype=None, experimenter=None, data=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if subtype != None:
             self.subtype = subtype
         else:
@@ -4625,6 +5120,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -4641,18 +5137,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 = experimenter_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 == 4)
         _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 == 65535)
@@ -4663,24 +5156,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.subtype != other.subtype: return False
         if self.experimenter != other.experimenter: 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("experimenter_error_msg {")
         with q.group():
@@ -4703,12 +5184,17 @@
             q.breakable()
         q.text('}')
 
-class features_reply(Message):
+error_msg.subtypes[65535] = experimenter_error_msg
+
+class features_reply(message):
     version = 4
     type = 6
 
     def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, auxiliary_id=None, capabilities=None, reserved=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if datapath_id != None:
             self.datapath_id = datapath_id
         else:
@@ -4733,6 +5219,7 @@
             self.reserved = reserved
         else:
             self.reserved = 0
+        return
 
     def pack(self):
         packed = []
@@ -4752,18 +5239,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 = 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 == 4)
         _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]
@@ -4776,8 +5260,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
@@ -4787,16 +5269,6 @@
         if self.reserved != other.reserved: 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():
@@ -4828,12 +5300,18 @@
             q.breakable()
         q.text('}')
 
-class features_request(Message):
+message.subtypes[6] = features_reply
+
+class features_request(message):
     version = 4
     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 = []
@@ -4846,38 +5324,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 == 4)
         _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():
@@ -4891,13 +5354,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 = 4
     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:
@@ -4946,6 +5428,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -4966,24 +5449,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 == 4)
         _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]
@@ -4999,13 +5479,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
@@ -5021,16 +5499,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():
@@ -5080,13 +5548,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete(Message):
+flow_mod.subtypes[0] = flow_add
+
+class flow_delete(flow_mod):
     version = 4
     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:
@@ -5135,6 +5608,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -5155,24 +5629,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 == 4)
         _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]
@@ -5188,13 +5659,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
@@ -5210,16 +5679,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():
@@ -5269,13 +5728,18 @@
             q.breakable()
         q.text('}')
 
-class flow_delete_strict(Message):
+flow_mod.subtypes[3] = flow_delete
+
+class flow_delete_strict(flow_mod):
     version = 4
     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:
@@ -5324,6 +5788,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -5344,24 +5809,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 == 4)
         _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]
@@ -5377,13 +5839,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
@@ -5399,16 +5859,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():
@@ -5458,13 +5908,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 = 4
     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:
@@ -5473,6 +5928,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -5488,18 +5944,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 == 4)
         _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)
@@ -5509,23 +5962,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():
@@ -5545,13 +5986,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify(Message):
+error_msg.subtypes[5] = flow_mod_failed_error_msg
+
+class flow_modify(flow_mod):
     version = 4
     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:
@@ -5600,6 +6046,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -5620,24 +6067,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 == 4)
         _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]
@@ -5653,13 +6097,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
@@ -5675,16 +6117,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():
@@ -5734,13 +6166,18 @@
             q.breakable()
         q.text('}')
 
-class flow_modify_strict(Message):
+flow_mod.subtypes[1] = flow_modify
+
+class flow_modify_strict(flow_mod):
     version = 4
     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:
@@ -5789,6 +6226,7 @@
             self.instructions = instructions
         else:
             self.instructions = []
+        return
 
     def pack(self):
         packed = []
@@ -5809,24 +6247,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 == 4)
         _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]
@@ -5842,13 +6277,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
@@ -5864,16 +6297,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():
@@ -5923,12 +6346,17 @@
             q.breakable()
         q.text('}')
 
-class flow_removed(Message):
+flow_mod.subtypes[2] = flow_modify_strict
+
+class flow_removed(message):
     version = 4
     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, hard_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:
@@ -5973,6 +6401,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -5996,18 +6425,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 == 4)
         _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]
@@ -6024,8 +6450,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
@@ -6040,16 +6464,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():
@@ -6096,13 +6510,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_reply(Message):
+message.subtypes[11] = flow_removed
+
+class flow_stats_reply(stats_reply):
     version = 4
     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:
@@ -6111,6 +6530,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6121,51 +6541,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 == 4)
         _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():
@@ -6185,13 +6590,18 @@
             q.breakable()
         q.text('}')
 
-class flow_stats_request(Message):
+stats_reply.subtypes[1] = flow_stats_reply
+
+class flow_stats_request(stats_request):
     version = 4
     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:
@@ -6220,6 +6630,7 @@
             self.match = match
         else:
             self.match = common.match()
+        return
 
     def pack(self):
         packed = []
@@ -6243,18 +6654,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 == 4)
         _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)
@@ -6272,8 +6680,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
@@ -6284,16 +6690,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():
@@ -6328,12 +6724,17 @@
             q.breakable()
         q.text('}')
 
-class get_config_reply(Message):
+stats_request.subtypes[1] = flow_stats_request
+
+class get_config_reply(message):
     version = 4
     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:
@@ -6342,6 +6743,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -6356,18 +6758,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 == 4)
         _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]
@@ -6375,23 +6774,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():
@@ -6411,12 +6798,18 @@
             q.breakable()
         q.text('}')
 
-class get_config_request(Message):
+message.subtypes[8] = get_config_reply
+
+class get_config_request(message):
     version = 4
     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 = []
@@ -6429,38 +6822,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 == 4)
         _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():
@@ -6474,13 +6852,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 = 4
     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:
@@ -6493,6 +6890,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -6504,53 +6902,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 == 4)
         _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():
@@ -6573,13 +6956,18 @@
             q.breakable()
         q.text('}')
 
-class group_delete(Message):
+group_mod.subtypes[0] = group_add
+
+class group_delete(group_mod):
     version = 4
     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:
@@ -6592,6 +6980,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -6603,53 +6992,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 == 4)
         _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():
@@ -6672,13 +7046,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 = 4
     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:
@@ -6687,6 +7066,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -6697,51 +7077,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 == 4)
         _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():
@@ -6761,17 +7126,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 = 4
     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 = []
@@ -6787,18 +7158,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 == 4)
         _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)
@@ -6808,22 +7176,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():
@@ -6840,13 +7196,18 @@
             q.breakable()
         q.text('}')
 
-class group_features_stats_reply(Message):
+stats_request.subtypes[7] = group_desc_stats_request
+
+class group_features_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 8
 
     def __init__(self, xid=None, flags=None, types=None, capabilities=None, max_groups_all=None, max_groups_select=None, max_groups_indirect=None, max_groups_ff=None, actions_all=None, actions_select=None, actions_indirect=None, actions_ff=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -6891,6 +7252,7 @@
             self.actions_ff = actions_ff
         else:
             self.actions_ff = 0
+        return
 
     def pack(self):
         packed = []
@@ -6916,18 +7278,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_features_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 == 4)
         _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 == 8)
@@ -6947,8 +7306,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.types != other.types: return False
@@ -6963,16 +7320,6 @@
         if self.actions_ff != other.actions_ff: 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_features_stats_reply {")
         with q.group():
@@ -7019,17 +7366,23 @@
             q.breakable()
         q.text('}')
 
-class group_features_stats_request(Message):
+stats_reply.subtypes[8] = group_features_stats_reply
+
+class group_features_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 8
 
     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 = []
@@ -7045,18 +7398,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_features_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 == 4)
         _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 == 8)
@@ -7066,22 +7416,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_features_stats_request {")
         with q.group():
@@ -7098,13 +7436,18 @@
             q.breakable()
         q.text('}')
 
-class group_mod_failed_error_msg(Message):
+stats_request.subtypes[8] = group_features_stats_request
+
+class group_mod_failed_error_msg(error_msg):
     version = 4
     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:
@@ -7113,6 +7456,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -7128,18 +7472,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 == 4)
         _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)
@@ -7149,23 +7490,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():
@@ -7185,13 +7514,18 @@
             q.breakable()
         q.text('}')
 
-class group_modify(Message):
+error_msg.subtypes[6] = group_mod_failed_error_msg
+
+class group_modify(group_mod):
     version = 4
     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:
@@ -7204,6 +7538,7 @@
             self.buckets = buckets
         else:
             self.buckets = []
+        return
 
     def pack(self):
         packed = []
@@ -7215,53 +7550,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 == 4)
         _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():
@@ -7284,13 +7604,18 @@
             q.breakable()
         q.text('}')
 
-class group_stats_reply(Message):
+group_mod.subtypes[1] = group_modify
+
+class group_stats_reply(stats_reply):
     version = 4
     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:
@@ -7299,6 +7624,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -7309,51 +7635,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 == 4)
         _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():
@@ -7373,13 +7684,18 @@
             q.breakable()
         q.text('}')
 
-class group_stats_request(Message):
+stats_reply.subtypes[6] = group_stats_reply
+
+class group_stats_request(stats_request):
     version = 4
     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:
@@ -7388,6 +7704,7 @@
             self.group_id = group_id
         else:
             self.group_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -7405,18 +7722,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 == 4)
         _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)
@@ -7428,23 +7742,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():
@@ -7464,16 +7766,22 @@
             q.breakable()
         q.text('}')
 
-class hello(Message):
+stats_request.subtypes[6] = group_stats_request
+
+class hello(message):
     version = 4
     type = 0
 
     def __init__(self, xid=None, elements=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if elements != None:
             self.elements = elements
         else:
             self.elements = []
+        return
 
     def pack(self):
         packed = []
@@ -7481,46 +7789,31 @@
         packed.append(struct.pack("!B", self.type))
         packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
         packed.append(struct.pack("!L", self.xid))
-        packed.append(util.pack_list(self.elements))
+        packed.append(loxi.generic_util.pack_list(self.elements))
         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 = hello()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _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]
-        obj.elements = common.unpack_list_hello_elem(reader)
+        obj.elements = util.unpack_list_hello_elem(reader)
         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.elements != other.elements: 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():
@@ -7537,13 +7830,18 @@
             q.breakable()
         q.text('}')
 
-class hello_failed_error_msg(Message):
+message.subtypes[0] = hello
+
+class hello_failed_error_msg(error_msg):
     version = 4
     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:
@@ -7552,6 +7850,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -7567,18 +7866,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 == 4)
         _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)
@@ -7588,23 +7884,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():
@@ -7624,13 +7908,18 @@
             q.breakable()
         q.text('}')
 
-class meter_config_stats_reply(Message):
+error_msg.subtypes[0] = hello_failed_error_msg
+
+class meter_config_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 10
 
     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:
@@ -7639,6 +7928,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -7649,51 +7939,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 = meter_config_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 == 4)
         _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 == 10)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = meter_band.unpack_list(reader)
+        obj.entries = loxi.generic_util.unpack_list(reader, meter_band.meter_band.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("meter_config_stats_reply {")
         with q.group():
@@ -7713,13 +7988,18 @@
             q.breakable()
         q.text('}')
 
-class meter_config_stats_request(Message):
+stats_reply.subtypes[10] = meter_config_stats_reply
+
+class meter_config_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 10
 
     def __init__(self, xid=None, flags=None, meter_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -7728,6 +8008,7 @@
             self.meter_id = meter_id
         else:
             self.meter_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -7745,18 +8026,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 = meter_config_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 == 4)
         _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 == 10)
@@ -7768,23 +8046,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.meter_id != other.meter_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("meter_config_stats_request {")
         with q.group():
@@ -7804,13 +8070,18 @@
             q.breakable()
         q.text('}')
 
-class meter_features_stats_reply(Message):
+stats_request.subtypes[10] = meter_config_stats_request
+
+class meter_features_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 11
 
     def __init__(self, xid=None, flags=None, features=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -7819,6 +8090,7 @@
             self.features = features
         else:
             self.features = common.meter_features()
+        return
 
     def pack(self):
         packed = []
@@ -7835,18 +8107,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 = meter_features_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 == 4)
         _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 == 11)
@@ -7857,23 +8126,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.features != other.features: 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("meter_features_stats_reply {")
         with q.group():
@@ -7893,17 +8150,23 @@
             q.breakable()
         q.text('}')
 
-class meter_features_stats_request(Message):
+stats_reply.subtypes[11] = meter_features_stats_reply
+
+class meter_features_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 11
 
     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 = []
@@ -7919,18 +8182,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 = meter_features_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 == 4)
         _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 == 11)
@@ -7940,22 +8200,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("meter_features_stats_request {")
         with q.group():
@@ -7972,12 +8220,17 @@
             q.breakable()
         q.text('}')
 
-class meter_mod(Message):
+stats_request.subtypes[11] = meter_features_stats_request
+
+class meter_mod(message):
     version = 4
     type = 29
 
     def __init__(self, xid=None, command=None, flags=None, meter_id=None, meters=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if command != None:
             self.command = command
         else:
@@ -7994,6 +8247,7 @@
             self.meters = meters
         else:
             self.meters = []
+        return
 
     def pack(self):
         packed = []
@@ -8004,35 +8258,30 @@
         packed.append(struct.pack("!H", self.command))
         packed.append(struct.pack("!H", self.flags))
         packed.append(struct.pack("!L", self.meter_id))
-        packed.append(util.pack_list(self.meters))
+        packed.append(loxi.generic_util.pack_list(self.meters))
         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 = meter_mod()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _type = reader.read("!B")[0]
         assert(_type == 29)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.command = reader.read("!H")[0]
         obj.flags = reader.read("!H")[0]
         obj.meter_id = reader.read("!L")[0]
-        obj.meters = meter_band.unpack_list(reader)
+        obj.meters = loxi.generic_util.unpack_list(reader, meter_band.meter_band.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.command != other.command: return False
         if self.flags != other.flags: return False
@@ -8040,16 +8289,6 @@
         if self.meters != other.meters: 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("meter_mod {")
         with q.group():
@@ -8075,13 +8314,18 @@
             q.breakable()
         q.text('}')
 
-class meter_mod_failed_error_msg(Message):
+message.subtypes[29] = meter_mod
+
+class meter_mod_failed_error_msg(error_msg):
     version = 4
     type = 1
     err_type = 12
 
     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:
@@ -8090,6 +8334,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -8105,18 +8350,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 = meter_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 == 4)
         _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 == 12)
@@ -8126,23 +8368,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("meter_mod_failed_error_msg {")
         with q.group():
@@ -8162,13 +8392,18 @@
             q.breakable()
         q.text('}')
 
-class meter_stats_reply(Message):
+error_msg.subtypes[12] = meter_mod_failed_error_msg
+
+class meter_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 9
 
     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:
@@ -8177,6 +8412,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -8187,51 +8423,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 = meter_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 == 4)
         _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 == 9)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = common.unpack_list_meter_stats(reader)
+        obj.entries = loxi.generic_util.unpack_list(reader, common.meter_stats.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("meter_stats_reply {")
         with q.group():
@@ -8251,13 +8472,18 @@
             q.breakable()
         q.text('}')
 
-class meter_stats_request(Message):
+stats_reply.subtypes[9] = meter_stats_reply
+
+class meter_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 9
 
     def __init__(self, xid=None, flags=None, meter_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if flags != None:
             self.flags = flags
         else:
@@ -8266,6 +8492,7 @@
             self.meter_id = meter_id
         else:
             self.meter_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -8283,18 +8510,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 = meter_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 == 4)
         _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 == 9)
@@ -8306,23 +8530,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.meter_id != other.meter_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("meter_stats_request {")
         with q.group():
@@ -8342,12 +8554,31 @@
             q.breakable()
         q.text('}')
 
-class packet_in(Message):
+stats_request.subtypes[9] = meter_stats_request
+
+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 = 4
     type = 10
 
     def __init__(self, xid=None, buffer_id=None, total_len=None, reason=None, table_id=None, cookie=None, match=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:
@@ -8376,6 +8607,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -8396,18 +8628,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 == 4)
         _type = reader.read("!B")[0]
         assert(_type == 10)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.buffer_id = reader.read("!L")[0]
         obj.total_len = reader.read("!H")[0]
@@ -8421,8 +8650,6 @@
 
     def __eq__(self, other):
         if type(self) != type(other): return False
-        if self.version != other.version: return False
-        if self.type != other.type: return False
         if self.xid != other.xid: return False
         if self.buffer_id != other.buffer_id: return False
         if self.total_len != other.total_len: return False
@@ -8433,16 +8660,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():
@@ -8477,12 +8694,17 @@
             q.breakable()
         q.text('}')
 
-class packet_out(Message):
+message.subtypes[10] = packet_in
+
+class packet_out(message):
     version = 4
     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:
@@ -8499,6 +8721,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -8510,7 +8733,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])
@@ -8518,31 +8741,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 == 4)
         _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
@@ -8550,16 +8768,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():
@@ -8585,13 +8793,18 @@
             q.breakable()
         q.text('}')
 
-class port_desc_stats_reply(Message):
+message.subtypes[13] = packet_out
+
+class port_desc_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 13
 
     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:
@@ -8600,6 +8813,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -8610,24 +8824,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_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 == 4)
         _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 == 13)
@@ -8638,23 +8849,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_desc_stats_reply {")
         with q.group():
@@ -8674,17 +8873,23 @@
             q.breakable()
         q.text('}')
 
-class port_desc_stats_request(Message):
+stats_reply.subtypes[13] = port_desc_stats_reply
+
+class port_desc_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 13
 
     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 = []
@@ -8700,18 +8905,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_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 == 4)
         _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 == 13)
@@ -8721,22 +8923,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("port_desc_stats_request {")
         with q.group():
@@ -8753,12 +8943,17 @@
             q.breakable()
         q.text('}')
 
-class port_mod(Message):
+stats_request.subtypes[13] = port_desc_stats_request
+
+class port_mod(message):
     version = 4
     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:
@@ -8779,6 +8974,7 @@
             self.advertise = advertise
         else:
             self.advertise = 0
+        return
 
     def pack(self):
         packed = []
@@ -8799,18 +8995,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 == 4)
         _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)
@@ -8824,8 +9017,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
@@ -8834,16 +9025,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():
@@ -8872,13 +9053,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 = 4
     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:
@@ -8887,6 +9073,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -8902,18 +9089,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 == 4)
         _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)
@@ -8923,23 +9107,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():
@@ -8959,13 +9131,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 = 4
     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:
@@ -8974,6 +9151,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -8984,24 +9162,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 == 4)
         _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)
@@ -9012,23 +9187,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():
@@ -9048,13 +9211,18 @@
             q.breakable()
         q.text('}')
 
-class port_stats_request(Message):
+stats_reply.subtypes[4] = port_stats_reply
+
+class port_stats_request(stats_request):
     version = 4
     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:
@@ -9063,6 +9231,7 @@
             self.port_no = port_no
         else:
             self.port_no = 0
+        return
 
     def pack(self):
         packed = []
@@ -9080,18 +9249,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 == 4)
         _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)
@@ -9103,23 +9269,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():
@@ -9139,12 +9293,17 @@
             q.breakable()
         q.text('}')
 
-class port_status(Message):
+stats_request.subtypes[4] = port_stats_request
+
+class port_status(message):
     version = 4
     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:
@@ -9153,6 +9312,7 @@
             self.desc = desc
         else:
             self.desc = common.port_desc()
+        return
 
     def pack(self):
         packed = []
@@ -9168,18 +9328,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 == 4)
         _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)
@@ -9188,23 +9345,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():
@@ -9224,12 +9369,17 @@
             q.breakable()
         q.text('}')
 
-class queue_get_config_reply(Message):
+message.subtypes[12] = port_status
+
+class queue_get_config_reply(message):
     version = 4
     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:
@@ -9238,6 +9388,7 @@
             self.queues = queues
         else:
             self.queues = []
+        return
 
     def pack(self):
         packed = []
@@ -9247,49 +9398,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 == 4)
         _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():
@@ -9309,16 +9445,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 = 4
     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 = []
@@ -9333,18 +9475,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 == 4)
         _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)
@@ -9352,22 +9491,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():
@@ -9384,13 +9511,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 = 4
     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:
@@ -9399,6 +9531,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -9414,18 +9547,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 == 4)
         _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)
@@ -9435,23 +9565,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():
@@ -9471,13 +9589,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 = 4
     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:
@@ -9486,6 +9609,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -9496,24 +9620,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 == 4)
         _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)
@@ -9524,23 +9645,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():
@@ -9560,13 +9669,18 @@
             q.breakable()
         q.text('}')
 
-class queue_stats_request(Message):
+stats_reply.subtypes[5] = queue_stats_reply
+
+class queue_stats_request(stats_request):
     version = 4
     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:
@@ -9579,6 +9693,7 @@
             self.queue_id = queue_id
         else:
             self.queue_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -9596,18 +9711,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 == 4)
         _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)
@@ -9619,24 +9731,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():
@@ -9659,12 +9759,17 @@
             q.breakable()
         q.text('}')
 
-class role_reply(Message):
+stats_request.subtypes[5] = queue_stats_request
+
+class role_reply(message):
     version = 4
     type = 25
 
     def __init__(self, xid=None, role=None, generation_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if role != None:
             self.role = role
         else:
@@ -9673,6 +9778,7 @@
             self.generation_id = generation_id
         else:
             self.generation_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -9688,18 +9794,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 = role_reply()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _type = reader.read("!B")[0]
         assert(_type == 25)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.role = reader.read("!L")[0]
         reader.skip(4)
@@ -9708,23 +9811,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.role != other.role: return False
         if self.generation_id != other.generation_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("role_reply {")
         with q.group():
@@ -9744,12 +9835,17 @@
             q.breakable()
         q.text('}')
 
-class role_request(Message):
+message.subtypes[25] = role_reply
+
+class role_request(message):
     version = 4
     type = 24
 
     def __init__(self, xid=None, role=None, generation_id=None):
-        self.xid = xid
+        if xid != None:
+            self.xid = xid
+        else:
+            self.xid = None
         if role != None:
             self.role = role
         else:
@@ -9758,6 +9854,7 @@
             self.generation_id = generation_id
         else:
             self.generation_id = 0
+        return
 
     def pack(self):
         packed = []
@@ -9773,18 +9870,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 = role_request()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _version = reader.read("!B")[0]
         assert(_version == 4)
         _type = reader.read("!B")[0]
         assert(_type == 24)
         _length = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_length - (2 + 2))
         obj.xid = reader.read("!L")[0]
         obj.role = reader.read("!L")[0]
         reader.skip(4)
@@ -9793,23 +9887,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.role != other.role: return False
         if self.generation_id != other.generation_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("role_request {")
         with q.group():
@@ -9829,13 +9911,18 @@
             q.breakable()
         q.text('}')
 
-class role_request_failed_error_msg(Message):
+message.subtypes[24] = role_request
+
+class role_request_failed_error_msg(error_msg):
     version = 4
     type = 1
     err_type = 11
 
     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:
@@ -9844,6 +9931,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -9859,18 +9947,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 = role_request_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 == 4)
         _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 == 11)
@@ -9880,23 +9965,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("role_request_failed_error_msg {")
         with q.group():
@@ -9916,12 +9989,17 @@
             q.breakable()
         q.text('}')
 
-class set_config(Message):
+error_msg.subtypes[11] = role_request_failed_error_msg
+
+class set_config(message):
     version = 4
     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:
@@ -9930,6 +10008,7 @@
             self.miss_send_len = miss_send_len
         else:
             self.miss_send_len = 0
+        return
 
     def pack(self):
         packed = []
@@ -9944,18 +10023,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 == 4)
         _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]
@@ -9963,23 +10039,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():
@@ -9999,13 +10063,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 = 4
     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:
@@ -10014,6 +10083,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -10029,18 +10099,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 == 4)
         _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)
@@ -10050,23 +10117,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():
@@ -10086,13 +10141,18 @@
             q.breakable()
         q.text('}')
 
-class table_features_failed_error_msg(Message):
+error_msg.subtypes[10] = switch_config_failed_error_msg
+
+class table_features_failed_error_msg(error_msg):
     version = 4
     type = 1
     err_type = 13
 
     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:
@@ -10101,6 +10161,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -10116,18 +10177,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_features_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 == 4)
         _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 == 13)
@@ -10137,23 +10195,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_features_failed_error_msg {")
         with q.group():
@@ -10173,13 +10219,18 @@
             q.breakable()
         q.text('}')
 
-class table_features_stats_reply(Message):
+error_msg.subtypes[13] = table_features_failed_error_msg
+
+class table_features_stats_reply(stats_reply):
     version = 4
     type = 19
     stats_type = 12
 
     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:
@@ -10188,6 +10239,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -10198,51 +10250,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 = table_features_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 == 4)
         _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 == 12)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = loxi.unimplemented('unpack list(of_table_features_t)')
+        obj.entries = loxi.generic_util.unpack_list(reader, common.table_features.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("table_features_stats_reply {")
         with q.group():
@@ -10262,13 +10299,18 @@
             q.breakable()
         q.text('}')
 
-class table_features_stats_request(Message):
+stats_reply.subtypes[12] = table_features_stats_reply
+
+class table_features_stats_request(stats_request):
     version = 4
     type = 18
     stats_type = 12
 
     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:
@@ -10277,6 +10319,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -10287,51 +10330,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 = table_features_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 == 4)
         _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 == 12)
         obj.flags = reader.read("!H")[0]
         reader.skip(4)
-        obj.entries = loxi.unimplemented('unpack list(of_table_features_t)')
+        obj.entries = loxi.generic_util.unpack_list(reader, common.table_features.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("table_features_stats_request {")
         with q.group():
@@ -10351,12 +10379,17 @@
             q.breakable()
         q.text('}')
 
-class table_mod(Message):
+stats_request.subtypes[12] = table_features_stats_request
+
+class table_mod(message):
     version = 4
     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:
@@ -10365,6 +10398,7 @@
             self.config = config
         else:
             self.config = 0
+        return
 
     def pack(self):
         packed = []
@@ -10380,18 +10414,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 == 4)
         _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)
@@ -10400,23 +10431,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():
@@ -10436,13 +10455,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 = 4
     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:
@@ -10451,6 +10475,7 @@
             self.data = data
         else:
             self.data = ''
+        return
 
     def pack(self):
         packed = []
@@ -10466,18 +10491,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 == 4)
         _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)
@@ -10487,23 +10509,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():
@@ -10523,13 +10533,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 = 4
     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:
@@ -10538,6 +10553,7 @@
             self.entries = entries
         else:
             self.entries = []
+        return
 
     def pack(self):
         packed = []
@@ -10548,24 +10564,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 == 4)
         _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)
@@ -10576,23 +10589,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():
@@ -10612,17 +10613,23 @@
             q.breakable()
         q.text('}')
 
-class table_stats_request(Message):
+stats_reply.subtypes[3] = table_stats_reply
+
+class table_stats_request(stats_request):
     version = 4
     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 = []
@@ -10638,18 +10645,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 == 4)
         _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)
@@ -10659,22 +10663,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():
@@ -10691,6 +10683,8 @@
             q.breakable()
         q.text('}')
 
+stats_request.subtypes[3] = table_stats_request
+
 
 def parse_header(buf):
     if len(buf) < 8:
@@ -10703,244 +10697,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,
-    const.OFPT_ROLE_REQUEST : role_request.unpack,
-    const.OFPT_ROLE_REPLY : role_reply.unpack,
-    const.OFPT_GET_ASYNC_REQUEST : async_get_request.unpack,
-    const.OFPT_GET_ASYNC_REPLY : async_get_reply.unpack,
-    const.OFPT_SET_ASYNC : async_set.unpack,
-    const.OFPT_METER_MOD : meter_mod.unpack,
-}
-
-error_msg_parsers = {
-    const.OFPET_HELLO_FAILED : hello_failed_error_msg.unpack,
-    const.OFPET_BAD_REQUEST : bad_request_error_msg.unpack,
-    const.OFPET_BAD_ACTION : bad_action_error_msg.unpack,
-    const.OFPET_FLOW_MOD_FAILED : flow_mod_failed_error_msg.unpack,
-    const.OFPET_PORT_MOD_FAILED : port_mod_failed_error_msg.unpack,
-    const.OFPET_QUEUE_OP_FAILED : queue_op_failed_error_msg.unpack,
-    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,
-    const.OFPET_ROLE_REQUEST_FAILED : role_request_failed_error_msg.unpack,
-    const.OFPET_EXPERIMENTER : experimenter_error_msg.unpack,
-    const.OFPET_METER_MOD_FAILED : meter_mod_failed_error_msg.unpack,
-    const.OFPET_TABLE_FEATURES_FAILED : table_features_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,
-    const.OFPST_GROUP_FEATURES : group_features_stats_reply.unpack,
-    const.OFPST_METER : meter_stats_reply.unpack,
-    const.OFPST_METER_CONFIG : meter_config_stats_reply.unpack,
-    const.OFPST_METER_FEATURES : meter_features_stats_reply.unpack,
-    const.OFPST_TABLE_FEATURES : table_features_stats_reply.unpack,
-    const.OFPST_PORT_DESC : port_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,
-    const.OFPST_GROUP_FEATURES : group_features_stats_request.unpack,
-    const.OFPST_METER : meter_stats_request.unpack,
-    const.OFPST_METER_CONFIG : meter_config_stats_request.unpack,
-    const.OFPST_METER_FEATURES : meter_features_stats_request.unpack,
-    const.OFPST_TABLE_FEATURES : table_features_stats_request.unpack,
-    const.OFPST_PORT_DESC : port_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,
-        40: bsn_flow_idle.unpack,
-        39: bsn_flow_idle_enable_get_reply.unpack,
-        38: bsn_flow_idle_enable_get_request.unpack,
-        37: bsn_flow_idle_enable_set_reply.unpack,
-        36: bsn_flow_idle_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,
-        43: bsn_lacp_convergence_notif.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,
-        42: bsn_set_lacp_reply.unpack,
-        41: bsn_set_lacp_request.unpack,
-        3: bsn_set_mirroring.unpack,
-        25: bsn_set_pktin_suppression_reply.unpack,
-        11: bsn_set_pktin_suppression_request.unpack,
-        45: bsn_time_reply.unpack,
-        44: bsn_time_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: {
-        1: bsn_lacp_stats_request.unpack,
-    },
-}
-
-experimenter_stats_reply_parsers = {
-    0x005c16c7: {
-        1: bsn_lacp_stats_reply.unpack,
-    },
-}
+    return message.unpack(loxi.generic_util.OFReader(buf))
