diff --git a/src/python/loxi/__init__.py b/src/python/loxi/__init__.py
new file mode 100644
index 0000000..9fcc9bf
--- /dev/null
+++ b/src/python/loxi/__init__.py
@@ -0,0 +1,33 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template toplevel_init.py
+# Do not modify
+
+def protocol(ver):
+    """
+    Import and return the protocol module for the given wire version.
+    """
+    if ver == 1:
+        import of10
+        return of10
+    else:
+        raise ValueError
+
+class ProtocolError(Exception):
+    """
+    Raised when failing to deserialize an invalid OpenFlow message.
+    """
+    pass
diff --git a/src/python/loxi/of10/__init__.py b/src/python/loxi/of10/__init__.py
new file mode 100644
index 0000000..9b3bf53
--- /dev/null
+++ b/src/python/loxi/of10/__init__.py
@@ -0,0 +1,22 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template init.py
+# Do not modify
+
+import action, common, const, message
+from const import *
+from common import *
+from loxi import ProtocolError
diff --git a/src/python/loxi/of10/action.py b/src/python/loxi/of10/action.py
new file mode 100644
index 0000000..c6129a5
--- /dev/null
+++ b/src/python/loxi/of10/action.py
@@ -0,0 +1,1029 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template action.py
+# Do not modify
+
+import struct
+import const
+import util
+import loxi
+
+def unpack_list(buf):
+    if len(buf) % 8 != 0: raise loxi.ProtocolError("action list length not a multiple of 8")
+    actions = []
+    offset = 0
+    while offset < len(buf):
+        type, length = struct.unpack_from("!HH", buf, offset)
+        if length == 0: raise loxi.ProtocolError("action length is 0")
+        if length % 8 != 0: raise loxi.ProtocolError("action length not a multiple of 8")
+        if offset + length > len(buf): raise loxi.ProtocolError("action length overruns list length")
+        parser = parsers.get(type)
+        if not parser: raise loxi.ProtocolError("unknown action type %d" % type)
+        actions.append(parser(buffer(buf, offset, length)))
+        offset += length
+    return actions
+
+class Action(object):
+    type = None # override in subclass
+    pass
+
+class bsn_mirror(Action):
+    type = const.OFPAT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 1
+
+    def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None, pad=None):
+        if dest_port != None:
+            self.dest_port = dest_port
+        else:
+            self.dest_port = 0
+        if vlan_tag != None:
+            self.vlan_tag = vlan_tag
+        else:
+            self.vlan_tag = 0
+        if copy_stage != None:
+            self.copy_stage = copy_stage
+        else:
+            self.copy_stage = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!L", self.dest_port))
+        packed.append(struct.pack("!L", self.vlan_tag))
+        packed.append(struct.pack("!B", self.copy_stage))
+        packed.append(struct.pack("!3B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = bsn_mirror()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 24: raise loxi.ProtocolError("bsn_mirror length is %d, should be 24" % _length)
+        experimenter = struct.unpack_from('!L', buf, 4)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 8)[0]
+        assert(subtype == 1)
+        obj.dest_port = struct.unpack_from('!L', buf, 12)[0]
+        obj.vlan_tag = struct.unpack_from('!L', buf, 16)[0]
+        obj.copy_stage = struct.unpack_from('!B', buf, 20)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 21))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.dest_port != other.dest_port: return False
+        if self.vlan_tag != other.vlan_tag: return False
+        if self.copy_stage != other.copy_stage: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_mirror {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("dest_port = ");
+                q.text("%#x" % self.dest_port)
+                q.text(","); q.breakable()
+                q.text("vlan_tag = ");
+                q.text("%#x" % self.vlan_tag)
+                q.text(","); q.breakable()
+                q.text("copy_stage = ");
+                q.text("%#x" % self.copy_stage)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class bsn_set_tunnel_dst(Action):
+    type = const.OFPAT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 2
+
+    def __init__(self, dst=None):
+        if dst != None:
+            self.dst = dst
+        else:
+            self.dst = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!L", self.subtype))
+        packed.append(struct.pack("!L", self.dst))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = bsn_set_tunnel_dst()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("bsn_set_tunnel_dst length is %d, should be 16" % _length)
+        experimenter = struct.unpack_from('!L', buf, 4)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 8)[0]
+        assert(subtype == 2)
+        obj.dst = struct.unpack_from('!L', buf, 12)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.dst != other.dst: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_set_tunnel_dst {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("dst = ");
+                q.text("%#x" % self.dst)
+            q.breakable()
+        q.text('}')
+
+class enqueue(Action):
+    type = const.OFPAT_ENQUEUE
+
+    def __init__(self, port=None, pad=None, queue_id=None):
+        if port != None:
+            self.port = port
+        else:
+            self.port = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+        if queue_id != None:
+            self.queue_id = queue_id
+        else:
+            self.queue_id = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!H", self.port))
+        packed.append(struct.pack("!6B", *self.pad))
+        packed.append(struct.pack("!L", self.queue_id))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = enqueue()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_ENQUEUE)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("enqueue length is %d, should be 16" % _length)
+        obj.port = struct.unpack_from('!H', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!6B', buf, 6))
+        obj.queue_id = struct.unpack_from('!L', buf, 12)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.port != other.port: return False
+        if self.pad != other.pad: return False
+        if self.queue_id != other.queue_id: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("enqueue {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("port = ");
+                q.text(util.pretty_port(self.port))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("queue_id = ");
+                q.text("%#x" % self.queue_id)
+            q.breakable()
+        q.text('}')
+
+class nicira_dec_ttl(Action):
+    type = const.OFPAT_VENDOR
+    experimenter = 0x2320
+    subtype = 18
+
+    def __init__(self, pad=None, pad2=None):
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if pad2 != None:
+            self.pad2 = pad2
+        else:
+            self.pad2 = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!L", self.experimenter))
+        packed.append(struct.pack("!H", self.subtype))
+        packed.append(struct.pack("!H", self.pad))
+        packed.append(struct.pack("!L", self.pad2))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = nicira_dec_ttl()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("nicira_dec_ttl length is %d, should be 16" % _length)
+        experimenter = struct.unpack_from('!L', buf, 4)[0]
+        assert(experimenter == 0x2320)
+        subtype = struct.unpack_from('!H', buf, 8)[0]
+        assert(subtype == 18)
+        obj.pad = struct.unpack_from('!H', buf, 10)[0]
+        obj.pad2 = struct.unpack_from('!L', buf, 12)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.pad != other.pad: return False
+        if self.pad2 != other.pad2: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("nicira_dec_ttl {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("pad2 = ");
+                q.text("%#x" % self.pad2)
+            q.breakable()
+        q.text('}')
+
+class output(Action):
+    type = const.OFPAT_OUTPUT
+
+    def __init__(self, port=None, max_len=None):
+        if port != None:
+            self.port = port
+        else:
+            self.port = 0
+        if max_len != None:
+            self.max_len = max_len
+        else:
+            self.max_len = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!H", self.port))
+        packed.append(struct.pack("!H", self.max_len))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = output()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_OUTPUT)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("output length is %d, should be 8" % _length)
+        obj.port = struct.unpack_from('!H', buf, 4)[0]
+        obj.max_len = struct.unpack_from('!H', buf, 6)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.port != other.port: return False
+        if self.max_len != other.max_len: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("output {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("port = ");
+                q.text(util.pretty_port(self.port))
+                q.text(","); q.breakable()
+                q.text("max_len = ");
+                q.text("%#x" % self.max_len)
+            q.breakable()
+        q.text('}')
+
+class set_dl_dst(Action):
+    type = const.OFPAT_SET_DL_DST
+
+    def __init__(self, dl_addr=None, pad=None):
+        if dl_addr != None:
+            self.dl_addr = dl_addr
+        else:
+            self.dl_addr = [0,0,0,0,0,0]
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!6B", *self.dl_addr))
+        packed.append(struct.pack("!6B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_dl_dst()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_DL_DST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("set_dl_dst length is %d, should be 16" % _length)
+        obj.dl_addr = list(struct.unpack_from('!6B', buf, 4))
+        obj.pad = list(struct.unpack_from('!6B', buf, 10))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.dl_addr != other.dl_addr: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_dl_dst {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("dl_addr = ");
+                q.text(util.pretty_mac(self.dl_addr))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_dl_src(Action):
+    type = const.OFPAT_SET_DL_SRC
+
+    def __init__(self, dl_addr=None, pad=None):
+        if dl_addr != None:
+            self.dl_addr = dl_addr
+        else:
+            self.dl_addr = [0,0,0,0,0,0]
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!6B", *self.dl_addr))
+        packed.append(struct.pack("!6B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_dl_src()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_DL_SRC)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("set_dl_src length is %d, should be 16" % _length)
+        obj.dl_addr = list(struct.unpack_from('!6B', buf, 4))
+        obj.pad = list(struct.unpack_from('!6B', buf, 10))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.dl_addr != other.dl_addr: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_dl_src {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("dl_addr = ");
+                q.text(util.pretty_mac(self.dl_addr))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_nw_dst(Action):
+    type = const.OFPAT_SET_NW_DST
+
+    def __init__(self, nw_addr=None):
+        if nw_addr != None:
+            self.nw_addr = nw_addr
+        else:
+            self.nw_addr = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!L", self.nw_addr))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_nw_dst()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_NW_DST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_nw_dst length is %d, should be 8" % _length)
+        obj.nw_addr = struct.unpack_from('!L', buf, 4)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.nw_addr != other.nw_addr: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_nw_dst {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("nw_addr = ");
+                q.text("%#x" % self.nw_addr)
+            q.breakable()
+        q.text('}')
+
+class set_nw_src(Action):
+    type = const.OFPAT_SET_NW_SRC
+
+    def __init__(self, nw_addr=None):
+        if nw_addr != None:
+            self.nw_addr = nw_addr
+        else:
+            self.nw_addr = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!L", self.nw_addr))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_nw_src()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_NW_SRC)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_nw_src length is %d, should be 8" % _length)
+        obj.nw_addr = struct.unpack_from('!L', buf, 4)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.nw_addr != other.nw_addr: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_nw_src {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("nw_addr = ");
+                q.text("%#x" % self.nw_addr)
+            q.breakable()
+        q.text('}')
+
+class set_nw_tos(Action):
+    type = const.OFPAT_SET_NW_TOS
+
+    def __init__(self, nw_tos=None, pad=None):
+        if nw_tos != None:
+            self.nw_tos = nw_tos
+        else:
+            self.nw_tos = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!B", self.nw_tos))
+        packed.append(struct.pack("!3B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_nw_tos()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_NW_TOS)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_nw_tos length is %d, should be 8" % _length)
+        obj.nw_tos = struct.unpack_from('!B', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 5))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.nw_tos != other.nw_tos: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_nw_tos {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("nw_tos = ");
+                q.text("%#x" % self.nw_tos)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_tp_dst(Action):
+    type = const.OFPAT_SET_TP_DST
+
+    def __init__(self, tp_port=None, pad=None):
+        if tp_port != None:
+            self.tp_port = tp_port
+        else:
+            self.tp_port = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!H", self.tp_port))
+        packed.append(struct.pack("!2B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_tp_dst()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_TP_DST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_tp_dst length is %d, should be 8" % _length)
+        obj.tp_port = struct.unpack_from('!H', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 6))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.tp_port != other.tp_port: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_tp_dst {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("tp_port = ");
+                q.text("%#x" % self.tp_port)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_tp_src(Action):
+    type = const.OFPAT_SET_TP_SRC
+
+    def __init__(self, tp_port=None, pad=None):
+        if tp_port != None:
+            self.tp_port = tp_port
+        else:
+            self.tp_port = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!H", self.tp_port))
+        packed.append(struct.pack("!2B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_tp_src()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_TP_SRC)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_tp_src length is %d, should be 8" % _length)
+        obj.tp_port = struct.unpack_from('!H', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 6))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.tp_port != other.tp_port: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_tp_src {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("tp_port = ");
+                q.text("%#x" % self.tp_port)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_vlan_pcp(Action):
+    type = const.OFPAT_SET_VLAN_PCP
+
+    def __init__(self, vlan_pcp=None, pad=None):
+        if vlan_pcp != None:
+            self.vlan_pcp = vlan_pcp
+        else:
+            self.vlan_pcp = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!B", self.vlan_pcp))
+        packed.append(struct.pack("!3B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_vlan_pcp()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_VLAN_PCP)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_vlan_pcp length is %d, should be 8" % _length)
+        obj.vlan_pcp = struct.unpack_from('!B', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 5))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.vlan_pcp != other.vlan_pcp: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_vlan_pcp {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("vlan_pcp = ");
+                q.text("%#x" % self.vlan_pcp)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class set_vlan_vid(Action):
+    type = const.OFPAT_SET_VLAN_VID
+
+    def __init__(self, vlan_vid=None, pad=None):
+        if vlan_vid != None:
+            self.vlan_vid = vlan_vid
+        else:
+            self.vlan_vid = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!H", self.vlan_vid))
+        packed.append(struct.pack("!2B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = set_vlan_vid()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_SET_VLAN_VID)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("set_vlan_vid length is %d, should be 8" % _length)
+        obj.vlan_vid = struct.unpack_from('!H', buf, 4)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 6))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.vlan_vid != other.vlan_vid: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("set_vlan_vid {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("vlan_vid = ");
+                q.text("%#x" % self.vlan_vid)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class strip_vlan(Action):
+    type = const.OFPAT_STRIP_VLAN
+
+    def __init__(self, pad=None):
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!4B", *self.pad))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        obj = strip_vlan()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPAT_STRIP_VLAN)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("strip_vlan length is %d, should be 8" % _length)
+        obj.pad = list(struct.unpack_from('!4B', buf, 4))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.type != other.type: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("strip_vlan {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+
+def parse_vendor(buf):
+    if len(buf) < 16:
+        raise loxi.ProtocolError("experimenter action too short")
+
+    experimenter, = struct.unpack_from("!L", buf, 4)
+    if experimenter == 0x005c16c7: # Big Switch Networks
+        subtype, = struct.unpack_from("!L", buf, 8)
+    elif experimenter == 0x00002320: # Nicira
+        subtype, = struct.unpack_from("!H", buf, 8)
+    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 BSN experimenter subtype %#x" % subtype)
+
+parsers = {
+    const.OFPAT_ENQUEUE : enqueue.unpack,
+    const.OFPAT_OUTPUT : output.unpack,
+    const.OFPAT_SET_DL_DST : set_dl_dst.unpack,
+    const.OFPAT_SET_DL_SRC : set_dl_src.unpack,
+    const.OFPAT_SET_NW_DST : set_nw_dst.unpack,
+    const.OFPAT_SET_NW_SRC : set_nw_src.unpack,
+    const.OFPAT_SET_NW_TOS : set_nw_tos.unpack,
+    const.OFPAT_SET_TP_DST : set_tp_dst.unpack,
+    const.OFPAT_SET_TP_SRC : set_tp_src.unpack,
+    const.OFPAT_SET_VLAN_PCP : set_vlan_pcp.unpack,
+    const.OFPAT_SET_VLAN_VID : set_vlan_vid.unpack,
+    const.OFPAT_STRIP_VLAN : strip_vlan.unpack,
+    const.OFPAT_VENDOR : parse_vendor,
+}
+
+experimenter_parsers = {
+    0x2320 : {
+        18: nicira_dec_ttl.unpack,
+    },
+    0x5c16c7 : {
+        1: bsn_mirror.unpack,
+        2: bsn_set_tunnel_dst.unpack,
+    },
+}
diff --git a/src/python/loxi/of10/common.py b/src/python/loxi/of10/common.py
new file mode 100644
index 0000000..07c41d0
--- /dev/null
+++ b/src/python/loxi/of10/common.py
@@ -0,0 +1,1136 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template common.py
+# Do not modify
+
+import sys
+import struct
+import action
+import const
+import util
+
+# HACK make this module visible as 'common' to simplify code generation
+common = sys.modules[__name__]
+
+def unpack_list_flow_stats_entry(buf):
+    entries = []
+    offset = 0
+    while offset < len(buf):
+        length, = struct.unpack_from("!H", buf, offset)
+        if length == 0: raise loxi.ProtocolError("entry length is 0")
+        if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+        entries.append(flow_stats_entry.unpack(buffer(buf, offset, length)))
+        offset += length
+    return entries
+
+def unpack_list_queue_prop(buf):
+    entries = []
+    offset = 0
+    while offset < len(buf):
+        type, length, = struct.unpack_from("!HH", buf, offset)
+        if length == 0: raise loxi.ProtocolError("entry length is 0")
+        if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+        if type == const.OFPQT_MIN_RATE:
+            entry = queue_prop_min_rate.unpack(buffer(buf, offset, length))
+        else:
+            raise loxi.ProtocolError("unknown queue prop %d" % type)
+        entries.append(entry)
+        offset += length
+    return entries
+
+def unpack_list_packet_queue(buf):
+    entries = []
+    offset = 0
+    while offset < len(buf):
+        _, length, = struct.unpack_from("!LH", buf, offset)
+        if length == 0: raise loxi.ProtocolError("entry length is 0")
+        if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+        entries.append(packet_queue.unpack(buffer(buf, offset, length)))
+        offset += length
+    return entries
+
+class bsn_interface(object):
+
+    def __init__(self, hw_addr=None, pad=None, name=None, ipv4_addr=None, ipv4_netmask=None):
+        if hw_addr != None:
+            self.hw_addr = hw_addr
+        else:
+            self.hw_addr = [0,0,0,0,0,0]
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if name != None:
+            self.name = name
+        else:
+            self.name = ""
+        if ipv4_addr != None:
+            self.ipv4_addr = ipv4_addr
+        else:
+            self.ipv4_addr = 0
+        if ipv4_netmask != None:
+            self.ipv4_netmask = ipv4_netmask
+        else:
+            self.ipv4_netmask = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!6B", *self.hw_addr))
+        packed.append(struct.pack("!H", self.pad))
+        packed.append(struct.pack("!16s", self.name))
+        packed.append(struct.pack("!L", self.ipv4_addr))
+        packed.append(struct.pack("!L", self.ipv4_netmask))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 32) # Should be verified by caller
+        obj = bsn_interface()
+        obj.hw_addr = list(struct.unpack_from('!6B', buf, 0))
+        obj.pad = struct.unpack_from('!H', buf, 6)[0]
+        obj.name = str(buffer(buf, 8, 16)).rstrip("\x00")
+        obj.ipv4_addr = struct.unpack_from('!L', buf, 24)[0]
+        obj.ipv4_netmask = struct.unpack_from('!L', buf, 28)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.hw_addr != other.hw_addr: return False
+        if self.pad != other.pad: return False
+        if self.name != other.name: return False
+        if self.ipv4_addr != other.ipv4_addr: return False
+        if self.ipv4_netmask != other.ipv4_netmask: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_interface {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("hw_addr = ");
+                q.text(util.pretty_mac(self.hw_addr))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("name = ");
+                q.pp(self.name)
+                q.text(","); q.breakable()
+                q.text("ipv4_addr = ");
+                q.text(util.pretty_ipv4(self.ipv4_addr))
+                q.text(","); q.breakable()
+                q.text("ipv4_netmask = ");
+                q.text(util.pretty_ipv4(self.ipv4_netmask))
+            q.breakable()
+        q.text('}')
+
+class flow_stats_entry(object):
+
+    def __init__(self, table_id=None, pad=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, pad2=None, cookie=None, packet_count=None, byte_count=None, actions=None):
+        if table_id != None:
+            self.table_id = table_id
+        else:
+            self.table_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if duration_sec != None:
+            self.duration_sec = duration_sec
+        else:
+            self.duration_sec = 0
+        if duration_nsec != None:
+            self.duration_nsec = duration_nsec
+        else:
+            self.duration_nsec = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if pad2 != None:
+            self.pad2 = pad2
+        else:
+            self.pad2 = [0,0,0,0,0,0]
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if packet_count != None:
+            self.packet_count = packet_count
+        else:
+            self.packet_count = 0
+        if byte_count != None:
+            self.byte_count = byte_count
+        else:
+            self.byte_count = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
+        packed.append(struct.pack("!B", self.table_id))
+        packed.append(struct.pack("!B", self.pad))
+        packed.append(self.match.pack())
+        packed.append(struct.pack("!L", self.duration_sec))
+        packed.append(struct.pack("!L", self.duration_nsec))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!6B", *self.pad2))
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!Q", self.packet_count))
+        packed.append(struct.pack("!Q", self.byte_count))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[0] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 88) # Should be verified by caller
+        obj = flow_stats_entry()
+        _length = struct.unpack_from('!H', buf, 0)[0]
+        assert(_length == len(buf))
+        if _length < 88: raise loxi.ProtocolError("flow_stats_entry length is %d, should be at least 88" % _length)
+        obj.table_id = struct.unpack_from('!B', buf, 2)[0]
+        obj.pad = struct.unpack_from('!B', buf, 3)[0]
+        obj.match = common.match.unpack(buffer(buf, 4))
+        obj.duration_sec = struct.unpack_from('!L', buf, 44)[0]
+        obj.duration_nsec = struct.unpack_from('!L', buf, 48)[0]
+        obj.priority = struct.unpack_from('!H', buf, 52)[0]
+        obj.idle_timeout = struct.unpack_from('!H', buf, 54)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 56)[0]
+        obj.pad2 = list(struct.unpack_from('!6B', buf, 58))
+        obj.cookie = struct.unpack_from('!Q', buf, 64)[0]
+        obj.packet_count = struct.unpack_from('!Q', buf, 72)[0]
+        obj.byte_count = struct.unpack_from('!Q', buf, 80)[0]
+        obj.actions = action.unpack_list(buffer(buf, 88))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.table_id != other.table_id: return False
+        if self.pad != other.pad: return False
+        if self.match != other.match: return False
+        if self.duration_sec != other.duration_sec: return False
+        if self.duration_nsec != other.duration_nsec: return False
+        if self.priority != other.priority: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.pad2 != other.pad2: return False
+        if self.cookie != other.cookie: return False
+        if self.packet_count != other.packet_count: return False
+        if self.byte_count != other.byte_count: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_stats_entry {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("table_id = ");
+                q.text("%#x" % self.table_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("duration_sec = ");
+                q.text("%#x" % self.duration_sec)
+                q.text(","); q.breakable()
+                q.text("duration_nsec = ");
+                q.text("%#x" % self.duration_nsec)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("pad2 = ");
+                q.pp(self.pad2)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("packet_count = ");
+                q.text("%#x" % self.packet_count)
+                q.text(","); q.breakable()
+                q.text("byte_count = ");
+                q.text("%#x" % self.byte_count)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class match_v1(object):
+
+    def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, pad1=None, eth_type=None, ip_dscp=None, ip_proto=None, pad2=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
+        if wildcards != None:
+            self.wildcards = wildcards
+        else:
+            self.wildcards = const.OFPFW_ALL
+        if in_port != None:
+            self.in_port = in_port
+        else:
+            self.in_port = 0
+        if eth_src != None:
+            self.eth_src = eth_src
+        else:
+            self.eth_src = [0,0,0,0,0,0]
+        if eth_dst != None:
+            self.eth_dst = eth_dst
+        else:
+            self.eth_dst = [0,0,0,0,0,0]
+        if vlan_vid != None:
+            self.vlan_vid = vlan_vid
+        else:
+            self.vlan_vid = 0
+        if vlan_pcp != None:
+            self.vlan_pcp = vlan_pcp
+        else:
+            self.vlan_pcp = 0
+        if pad1 != None:
+            self.pad1 = pad1
+        else:
+            self.pad1 = 0
+        if eth_type != None:
+            self.eth_type = eth_type
+        else:
+            self.eth_type = 0
+        if ip_dscp != None:
+            self.ip_dscp = ip_dscp
+        else:
+            self.ip_dscp = 0
+        if ip_proto != None:
+            self.ip_proto = ip_proto
+        else:
+            self.ip_proto = 0
+        if pad2 != None:
+            self.pad2 = pad2
+        else:
+            self.pad2 = [0,0]
+        if ipv4_src != None:
+            self.ipv4_src = ipv4_src
+        else:
+            self.ipv4_src = 0
+        if ipv4_dst != None:
+            self.ipv4_dst = ipv4_dst
+        else:
+            self.ipv4_dst = 0
+        if tcp_src != None:
+            self.tcp_src = tcp_src
+        else:
+            self.tcp_src = 0
+        if tcp_dst != None:
+            self.tcp_dst = tcp_dst
+        else:
+            self.tcp_dst = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!L", self.wildcards))
+        packed.append(struct.pack("!H", self.in_port))
+        packed.append(struct.pack("!6B", *self.eth_src))
+        packed.append(struct.pack("!6B", *self.eth_dst))
+        packed.append(struct.pack("!H", self.vlan_vid))
+        packed.append(struct.pack("!B", self.vlan_pcp))
+        packed.append(struct.pack("!B", self.pad1))
+        packed.append(struct.pack("!H", self.eth_type))
+        packed.append(struct.pack("!B", self.ip_dscp))
+        packed.append(struct.pack("!B", self.ip_proto))
+        packed.append(struct.pack("!2B", *self.pad2))
+        packed.append(struct.pack("!L", self.ipv4_src))
+        packed.append(struct.pack("!L", self.ipv4_dst))
+        packed.append(struct.pack("!H", self.tcp_src))
+        packed.append(struct.pack("!H", self.tcp_dst))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 40) # Should be verified by caller
+        obj = match_v1()
+        obj.wildcards = struct.unpack_from('!L', buf, 0)[0]
+        obj.in_port = struct.unpack_from('!H', buf, 4)[0]
+        obj.eth_src = list(struct.unpack_from('!6B', buf, 6))
+        obj.eth_dst = list(struct.unpack_from('!6B', buf, 12))
+        obj.vlan_vid = struct.unpack_from('!H', buf, 18)[0]
+        obj.vlan_pcp = struct.unpack_from('!B', buf, 20)[0]
+        obj.pad1 = struct.unpack_from('!B', buf, 21)[0]
+        obj.eth_type = struct.unpack_from('!H', buf, 22)[0]
+        obj.ip_dscp = struct.unpack_from('!B', buf, 24)[0]
+        obj.ip_proto = struct.unpack_from('!B', buf, 25)[0]
+        obj.pad2 = list(struct.unpack_from('!2B', buf, 26))
+        obj.ipv4_src = struct.unpack_from('!L', buf, 28)[0]
+        obj.ipv4_dst = struct.unpack_from('!L', buf, 32)[0]
+        obj.tcp_src = struct.unpack_from('!H', buf, 36)[0]
+        obj.tcp_dst = struct.unpack_from('!H', buf, 38)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.wildcards != other.wildcards: return False
+        if self.in_port != other.in_port: return False
+        if self.eth_src != other.eth_src: return False
+        if self.eth_dst != other.eth_dst: return False
+        if self.vlan_vid != other.vlan_vid: return False
+        if self.vlan_pcp != other.vlan_pcp: return False
+        if self.pad1 != other.pad1: return False
+        if self.eth_type != other.eth_type: return False
+        if self.ip_dscp != other.ip_dscp: return False
+        if self.ip_proto != other.ip_proto: return False
+        if self.pad2 != other.pad2: return False
+        if self.ipv4_src != other.ipv4_src: return False
+        if self.ipv4_dst != other.ipv4_dst: return False
+        if self.tcp_src != other.tcp_src: return False
+        if self.tcp_dst != other.tcp_dst: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("match_v1 {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("wildcards = ");
+                q.text(util.pretty_wildcards(self.wildcards))
+                q.text(","); q.breakable()
+                q.text("in_port = ");
+                q.text(util.pretty_port(self.in_port))
+                q.text(","); q.breakable()
+                q.text("eth_src = ");
+                q.text(util.pretty_mac(self.eth_src))
+                q.text(","); q.breakable()
+                q.text("eth_dst = ");
+                q.text(util.pretty_mac(self.eth_dst))
+                q.text(","); q.breakable()
+                q.text("vlan_vid = ");
+                q.text("%#x" % self.vlan_vid)
+                q.text(","); q.breakable()
+                q.text("vlan_pcp = ");
+                q.text("%#x" % self.vlan_pcp)
+                q.text(","); q.breakable()
+                q.text("pad1 = ");
+                q.text("%#x" % self.pad1)
+                q.text(","); q.breakable()
+                q.text("eth_type = ");
+                q.text("%#x" % self.eth_type)
+                q.text(","); q.breakable()
+                q.text("ip_dscp = ");
+                q.text("%#x" % self.ip_dscp)
+                q.text(","); q.breakable()
+                q.text("ip_proto = ");
+                q.text("%#x" % self.ip_proto)
+                q.text(","); q.breakable()
+                q.text("pad2 = ");
+                q.pp(self.pad2)
+                q.text(","); q.breakable()
+                q.text("ipv4_src = ");
+                q.text(util.pretty_ipv4(self.ipv4_src))
+                q.text(","); q.breakable()
+                q.text("ipv4_dst = ");
+                q.text(util.pretty_ipv4(self.ipv4_dst))
+                q.text(","); q.breakable()
+                q.text("tcp_src = ");
+                q.text("%#x" % self.tcp_src)
+                q.text(","); q.breakable()
+                q.text("tcp_dst = ");
+                q.text("%#x" % self.tcp_dst)
+            q.breakable()
+        q.text('}')
+
+match = match_v1
+
+class packet_queue(object):
+
+    def __init__(self, queue_id=None, pad=None, properties=None):
+        if queue_id != None:
+            self.queue_id = queue_id
+        else:
+            self.queue_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+        if properties != None:
+            self.properties = properties
+        else:
+            self.properties = []
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!L", self.queue_id))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!2B", *self.pad))
+        packed.append("".join([x.pack() for x in self.properties]))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 8) # Should be verified by caller
+        obj = packet_queue()
+        obj.queue_id = struct.unpack_from('!L', buf, 0)[0]
+        _length = struct.unpack_from('!H', buf, 4)[0]
+        assert(_length == len(buf))
+        if _length < 8: raise loxi.ProtocolError("packet_queue length is %d, should be at least 8" % _length)
+        obj.pad = list(struct.unpack_from('!2B', buf, 6))
+        obj.properties = common.unpack_list_queue_prop(buffer(buf, 8))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.queue_id != other.queue_id: return False
+        if self.pad != other.pad: return False
+        if self.properties != other.properties: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("packet_queue {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("queue_id = ");
+                q.text("%#x" % self.queue_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("properties = ");
+                q.pp(self.properties)
+            q.breakable()
+        q.text('}')
+
+class port_desc(object):
+
+    def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if hw_addr != None:
+            self.hw_addr = hw_addr
+        else:
+            self.hw_addr = [0,0,0,0,0,0]
+        if name != None:
+            self.name = name
+        else:
+            self.name = ""
+        if config != None:
+            self.config = config
+        else:
+            self.config = 0
+        if state != None:
+            self.state = state
+        else:
+            self.state = 0
+        if curr != None:
+            self.curr = curr
+        else:
+            self.curr = 0
+        if advertised != None:
+            self.advertised = advertised
+        else:
+            self.advertised = 0
+        if supported != None:
+            self.supported = supported
+        else:
+            self.supported = 0
+        if peer != None:
+            self.peer = peer
+        else:
+            self.peer = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.port_no))
+        packed.append(struct.pack("!6B", *self.hw_addr))
+        packed.append(struct.pack("!16s", self.name))
+        packed.append(struct.pack("!L", self.config))
+        packed.append(struct.pack("!L", self.state))
+        packed.append(struct.pack("!L", self.curr))
+        packed.append(struct.pack("!L", self.advertised))
+        packed.append(struct.pack("!L", self.supported))
+        packed.append(struct.pack("!L", self.peer))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 48) # Should be verified by caller
+        obj = port_desc()
+        obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+        obj.hw_addr = list(struct.unpack_from('!6B', buf, 2))
+        obj.name = str(buffer(buf, 8, 16)).rstrip("\x00")
+        obj.config = struct.unpack_from('!L', buf, 24)[0]
+        obj.state = struct.unpack_from('!L', buf, 28)[0]
+        obj.curr = struct.unpack_from('!L', buf, 32)[0]
+        obj.advertised = struct.unpack_from('!L', buf, 36)[0]
+        obj.supported = struct.unpack_from('!L', buf, 40)[0]
+        obj.peer = struct.unpack_from('!L', buf, 44)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.port_no != other.port_no: return False
+        if self.hw_addr != other.hw_addr: return False
+        if self.name != other.name: return False
+        if self.config != other.config: return False
+        if self.state != other.state: return False
+        if self.curr != other.curr: return False
+        if self.advertised != other.advertised: return False
+        if self.supported != other.supported: return False
+        if self.peer != other.peer: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("port_desc {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("port_no = ");
+                q.text(util.pretty_port(self.port_no))
+                q.text(","); q.breakable()
+                q.text("hw_addr = ");
+                q.text(util.pretty_mac(self.hw_addr))
+                q.text(","); q.breakable()
+                q.text("name = ");
+                q.pp(self.name)
+                q.text(","); q.breakable()
+                q.text("config = ");
+                q.text("%#x" % self.config)
+                q.text(","); q.breakable()
+                q.text("state = ");
+                q.text("%#x" % self.state)
+                q.text(","); q.breakable()
+                q.text("curr = ");
+                q.text("%#x" % self.curr)
+                q.text(","); q.breakable()
+                q.text("advertised = ");
+                q.text("%#x" % self.advertised)
+                q.text(","); q.breakable()
+                q.text("supported = ");
+                q.text("%#x" % self.supported)
+                q.text(","); q.breakable()
+                q.text("peer = ");
+                q.text("%#x" % self.peer)
+            q.breakable()
+        q.text('}')
+
+class port_stats_entry(object):
+
+    def __init__(self, port_no=None, pad=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None):
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+        if rx_packets != None:
+            self.rx_packets = rx_packets
+        else:
+            self.rx_packets = 0
+        if tx_packets != None:
+            self.tx_packets = tx_packets
+        else:
+            self.tx_packets = 0
+        if rx_bytes != None:
+            self.rx_bytes = rx_bytes
+        else:
+            self.rx_bytes = 0
+        if tx_bytes != None:
+            self.tx_bytes = tx_bytes
+        else:
+            self.tx_bytes = 0
+        if rx_dropped != None:
+            self.rx_dropped = rx_dropped
+        else:
+            self.rx_dropped = 0
+        if tx_dropped != None:
+            self.tx_dropped = tx_dropped
+        else:
+            self.tx_dropped = 0
+        if rx_errors != None:
+            self.rx_errors = rx_errors
+        else:
+            self.rx_errors = 0
+        if tx_errors != None:
+            self.tx_errors = tx_errors
+        else:
+            self.tx_errors = 0
+        if rx_frame_err != None:
+            self.rx_frame_err = rx_frame_err
+        else:
+            self.rx_frame_err = 0
+        if rx_over_err != None:
+            self.rx_over_err = rx_over_err
+        else:
+            self.rx_over_err = 0
+        if rx_crc_err != None:
+            self.rx_crc_err = rx_crc_err
+        else:
+            self.rx_crc_err = 0
+        if collisions != None:
+            self.collisions = collisions
+        else:
+            self.collisions = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.port_no))
+        packed.append(struct.pack("!6B", *self.pad))
+        packed.append(struct.pack("!Q", self.rx_packets))
+        packed.append(struct.pack("!Q", self.tx_packets))
+        packed.append(struct.pack("!Q", self.rx_bytes))
+        packed.append(struct.pack("!Q", self.tx_bytes))
+        packed.append(struct.pack("!Q", self.rx_dropped))
+        packed.append(struct.pack("!Q", self.tx_dropped))
+        packed.append(struct.pack("!Q", self.rx_errors))
+        packed.append(struct.pack("!Q", self.tx_errors))
+        packed.append(struct.pack("!Q", self.rx_frame_err))
+        packed.append(struct.pack("!Q", self.rx_over_err))
+        packed.append(struct.pack("!Q", self.rx_crc_err))
+        packed.append(struct.pack("!Q", self.collisions))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 104) # Should be verified by caller
+        obj = port_stats_entry()
+        obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+        obj.pad = list(struct.unpack_from('!6B', buf, 2))
+        obj.rx_packets = struct.unpack_from('!Q', buf, 8)[0]
+        obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0]
+        obj.rx_bytes = struct.unpack_from('!Q', buf, 24)[0]
+        obj.tx_bytes = struct.unpack_from('!Q', buf, 32)[0]
+        obj.rx_dropped = struct.unpack_from('!Q', buf, 40)[0]
+        obj.tx_dropped = struct.unpack_from('!Q', buf, 48)[0]
+        obj.rx_errors = struct.unpack_from('!Q', buf, 56)[0]
+        obj.tx_errors = struct.unpack_from('!Q', buf, 64)[0]
+        obj.rx_frame_err = struct.unpack_from('!Q', buf, 72)[0]
+        obj.rx_over_err = struct.unpack_from('!Q', buf, 80)[0]
+        obj.rx_crc_err = struct.unpack_from('!Q', buf, 88)[0]
+        obj.collisions = struct.unpack_from('!Q', buf, 96)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.port_no != other.port_no: return False
+        if self.pad != other.pad: return False
+        if self.rx_packets != other.rx_packets: return False
+        if self.tx_packets != other.tx_packets: return False
+        if self.rx_bytes != other.rx_bytes: return False
+        if self.tx_bytes != other.tx_bytes: return False
+        if self.rx_dropped != other.rx_dropped: return False
+        if self.tx_dropped != other.tx_dropped: return False
+        if self.rx_errors != other.rx_errors: return False
+        if self.tx_errors != other.tx_errors: return False
+        if self.rx_frame_err != other.rx_frame_err: return False
+        if self.rx_over_err != other.rx_over_err: return False
+        if self.rx_crc_err != other.rx_crc_err: return False
+        if self.collisions != other.collisions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("port_stats_entry {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("port_no = ");
+                q.text(util.pretty_port(self.port_no))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("rx_packets = ");
+                q.text("%#x" % self.rx_packets)
+                q.text(","); q.breakable()
+                q.text("tx_packets = ");
+                q.text("%#x" % self.tx_packets)
+                q.text(","); q.breakable()
+                q.text("rx_bytes = ");
+                q.text("%#x" % self.rx_bytes)
+                q.text(","); q.breakable()
+                q.text("tx_bytes = ");
+                q.text("%#x" % self.tx_bytes)
+                q.text(","); q.breakable()
+                q.text("rx_dropped = ");
+                q.text("%#x" % self.rx_dropped)
+                q.text(","); q.breakable()
+                q.text("tx_dropped = ");
+                q.text("%#x" % self.tx_dropped)
+                q.text(","); q.breakable()
+                q.text("rx_errors = ");
+                q.text("%#x" % self.rx_errors)
+                q.text(","); q.breakable()
+                q.text("tx_errors = ");
+                q.text("%#x" % self.tx_errors)
+                q.text(","); q.breakable()
+                q.text("rx_frame_err = ");
+                q.text("%#x" % self.rx_frame_err)
+                q.text(","); q.breakable()
+                q.text("rx_over_err = ");
+                q.text("%#x" % self.rx_over_err)
+                q.text(","); q.breakable()
+                q.text("rx_crc_err = ");
+                q.text("%#x" % self.rx_crc_err)
+                q.text(","); q.breakable()
+                q.text("collisions = ");
+                q.text("%#x" % self.collisions)
+            q.breakable()
+        q.text('}')
+
+class queue_prop_min_rate(object):
+    type = const.OFPQT_MIN_RATE
+
+    def __init__(self, pad=None, rate=None, pad2=None):
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0]
+        if rate != None:
+            self.rate = rate
+        else:
+            self.rate = 0
+        if pad2 != None:
+            self.pad2 = pad2
+        else:
+            self.pad2 = [0,0,0,0,0,0]
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.type))
+        packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+        packed.append(struct.pack("!4B", *self.pad))
+        packed.append(struct.pack("!H", self.rate))
+        packed.append(struct.pack("!6B", *self.pad2))
+        length = sum([len(x) for x in packed])
+        packed[1] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 16) # Should be verified by caller
+        obj = queue_prop_min_rate()
+        type = struct.unpack_from('!H', buf, 0)[0]
+        assert(type == const.OFPQT_MIN_RATE)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("queue_prop_min_rate length is %d, should be 16" % _length)
+        obj.pad = list(struct.unpack_from('!4B', buf, 4))
+        obj.rate = struct.unpack_from('!H', buf, 8)[0]
+        obj.pad2 = list(struct.unpack_from('!6B', buf, 10))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.pad != other.pad: return False
+        if self.rate != other.rate: return False
+        if self.pad2 != other.pad2: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("queue_prop_min_rate {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("rate = ");
+                q.text("%#x" % self.rate)
+                q.text(","); q.breakable()
+                q.text("pad2 = ");
+                q.pp(self.pad2)
+            q.breakable()
+        q.text('}')
+
+class queue_stats_entry(object):
+
+    def __init__(self, port_no=None, pad=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+        if queue_id != None:
+            self.queue_id = queue_id
+        else:
+            self.queue_id = 0
+        if tx_bytes != None:
+            self.tx_bytes = tx_bytes
+        else:
+            self.tx_bytes = 0
+        if tx_packets != None:
+            self.tx_packets = tx_packets
+        else:
+            self.tx_packets = 0
+        if tx_errors != None:
+            self.tx_errors = tx_errors
+        else:
+            self.tx_errors = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!H", self.port_no))
+        packed.append(struct.pack("!2B", *self.pad))
+        packed.append(struct.pack("!L", self.queue_id))
+        packed.append(struct.pack("!Q", self.tx_bytes))
+        packed.append(struct.pack("!Q", self.tx_packets))
+        packed.append(struct.pack("!Q", self.tx_errors))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 32) # Should be verified by caller
+        obj = queue_stats_entry()
+        obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 2))
+        obj.queue_id = struct.unpack_from('!L', buf, 4)[0]
+        obj.tx_bytes = struct.unpack_from('!Q', buf, 8)[0]
+        obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0]
+        obj.tx_errors = struct.unpack_from('!Q', buf, 24)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.port_no != other.port_no: return False
+        if self.pad != other.pad: return False
+        if self.queue_id != other.queue_id: return False
+        if self.tx_bytes != other.tx_bytes: return False
+        if self.tx_packets != other.tx_packets: return False
+        if self.tx_errors != other.tx_errors: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("queue_stats_entry {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("port_no = ");
+                q.text(util.pretty_port(self.port_no))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("queue_id = ");
+                q.text("%#x" % self.queue_id)
+                q.text(","); q.breakable()
+                q.text("tx_bytes = ");
+                q.text("%#x" % self.tx_bytes)
+                q.text(","); q.breakable()
+                q.text("tx_packets = ");
+                q.text("%#x" % self.tx_packets)
+                q.text(","); q.breakable()
+                q.text("tx_errors = ");
+                q.text("%#x" % self.tx_errors)
+            q.breakable()
+        q.text('}')
+
+class table_stats_entry(object):
+
+    def __init__(self, table_id=None, pad=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
+        if table_id != None:
+            self.table_id = table_id
+        else:
+            self.table_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+        if name != None:
+            self.name = name
+        else:
+            self.name = ""
+        if wildcards != None:
+            self.wildcards = wildcards
+        else:
+            self.wildcards = const.OFPFW_ALL
+        if max_entries != None:
+            self.max_entries = max_entries
+        else:
+            self.max_entries = 0
+        if active_count != None:
+            self.active_count = active_count
+        else:
+            self.active_count = 0
+        if lookup_count != None:
+            self.lookup_count = lookup_count
+        else:
+            self.lookup_count = 0
+        if matched_count != None:
+            self.matched_count = matched_count
+        else:
+            self.matched_count = 0
+
+    def pack(self):
+        packed = []
+        packed.append(struct.pack("!B", self.table_id))
+        packed.append(struct.pack("!3B", *self.pad))
+        packed.append(struct.pack("!32s", self.name))
+        packed.append(struct.pack("!L", self.wildcards))
+        packed.append(struct.pack("!L", self.max_entries))
+        packed.append(struct.pack("!L", self.active_count))
+        packed.append(struct.pack("!Q", self.lookup_count))
+        packed.append(struct.pack("!Q", self.matched_count))
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        assert(len(buf) >= 64) # Should be verified by caller
+        obj = table_stats_entry()
+        obj.table_id = struct.unpack_from('!B', buf, 0)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 1))
+        obj.name = str(buffer(buf, 4, 32)).rstrip("\x00")
+        obj.wildcards = struct.unpack_from('!L', buf, 36)[0]
+        obj.max_entries = struct.unpack_from('!L', buf, 40)[0]
+        obj.active_count = struct.unpack_from('!L', buf, 44)[0]
+        obj.lookup_count = struct.unpack_from('!Q', buf, 48)[0]
+        obj.matched_count = struct.unpack_from('!Q', buf, 56)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.table_id != other.table_id: return False
+        if self.pad != other.pad: return False
+        if self.name != other.name: return False
+        if self.wildcards != other.wildcards: return False
+        if self.max_entries != other.max_entries: return False
+        if self.active_count != other.active_count: return False
+        if self.lookup_count != other.lookup_count: return False
+        if self.matched_count != other.matched_count: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("table_stats_entry {")
+        with q.group():
+            with q.indent(2):
+                q.breakable()
+                q.text("table_id = ");
+                q.text("%#x" % self.table_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("name = ");
+                q.pp(self.name)
+                q.text(","); q.breakable()
+                q.text("wildcards = ");
+                q.text(util.pretty_wildcards(self.wildcards))
+                q.text(","); q.breakable()
+                q.text("max_entries = ");
+                q.text("%#x" % self.max_entries)
+                q.text(","); q.breakable()
+                q.text("active_count = ");
+                q.text("%#x" % self.active_count)
+                q.text(","); q.breakable()
+                q.text("lookup_count = ");
+                q.text("%#x" % self.lookup_count)
+                q.text(","); q.breakable()
+                q.text("matched_count = ");
+                q.text("%#x" % self.matched_count)
+            q.breakable()
+        q.text('}')
+
diff --git a/src/python/loxi/of10/const.py b/src/python/loxi/of10/const.py
new file mode 100644
index 0000000..e269071
--- /dev/null
+++ b/src/python/loxi/of10/const.py
@@ -0,0 +1,476 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template const.py
+# Do not modify
+
+OFP_VERSION = 1
+
+# Identifiers from group macro_definitions
+OFP_FLOW_PERMANENT = 0
+OFP_ETH_ALEN = 6
+OFP_MAX_PORT_NAME_LEN = 16
+OFP_MAX_TABLE_NAME_LEN = 32
+SERIAL_NUM_LEN = 32
+OFPFW_ICMP_TYPE = (1 << 6)
+OFPFW_ICMP_CODE = (1 << 7)
+OFP_DEFAULT_MISS_SEND_LEN = 128
+DESC_STR_LEN = 256
+OFP_DL_TYPE_NOT_ETH_TYPE = 0x05ff
+OFP_DL_TYPE_ETH2_CUTOFF = 0x0600
+OFP_TCP_PORT = 6633
+OFP_SSL_PORT = 6633
+OFP_DEFAULT_PRIORITY = 0x8000
+OFPQ_MIN_RATE_UNCFG = 0xffff
+OFP_VLAN_NONE = 0xffff
+OFPQ_ALL = 0xffffffff
+
+# Identifiers from group ofp_action_type
+OFPAT_OUTPUT = 0
+OFPAT_SET_VLAN_VID = 1
+OFPAT_SET_VLAN_PCP = 2
+OFPAT_STRIP_VLAN = 3
+OFPAT_SET_DL_SRC = 4
+OFPAT_SET_DL_DST = 5
+OFPAT_SET_NW_SRC = 6
+OFPAT_SET_NW_DST = 7
+OFPAT_SET_NW_TOS = 8
+OFPAT_SET_TP_SRC = 9
+OFPAT_SET_TP_DST = 10
+OFPAT_ENQUEUE = 11
+OFPAT_VENDOR = 0xffff
+
+ofp_action_type_map = {
+    0: 'OFPAT_OUTPUT',
+    1: 'OFPAT_SET_VLAN_VID',
+    2: 'OFPAT_SET_VLAN_PCP',
+    3: 'OFPAT_STRIP_VLAN',
+    4: 'OFPAT_SET_DL_SRC',
+    5: 'OFPAT_SET_DL_DST',
+    6: 'OFPAT_SET_NW_SRC',
+    7: 'OFPAT_SET_NW_DST',
+    8: 'OFPAT_SET_NW_TOS',
+    9: 'OFPAT_SET_TP_SRC',
+    10: 'OFPAT_SET_TP_DST',
+    11: 'OFPAT_ENQUEUE',
+    0xffff: 'OFPAT_VENDOR',
+}
+
+# Identifiers from group ofp_bad_action_code
+OFPBAC_BAD_TYPE = 0
+OFPBAC_BAD_LEN = 1
+OFPBAC_BAD_VENDOR = 2
+OFPBAC_BAD_VENDOR_TYPE = 3
+OFPBAC_BAD_OUT_PORT = 4
+OFPBAC_BAD_ARGUMENT = 5
+OFPBAC_EPERM = 6
+OFPBAC_TOO_MANY = 7
+OFPBAC_BAD_QUEUE = 8
+
+ofp_bad_action_code_map = {
+    0: 'OFPBAC_BAD_TYPE',
+    1: 'OFPBAC_BAD_LEN',
+    2: 'OFPBAC_BAD_VENDOR',
+    3: 'OFPBAC_BAD_VENDOR_TYPE',
+    4: 'OFPBAC_BAD_OUT_PORT',
+    5: 'OFPBAC_BAD_ARGUMENT',
+    6: 'OFPBAC_EPERM',
+    7: 'OFPBAC_TOO_MANY',
+    8: 'OFPBAC_BAD_QUEUE',
+}
+
+# Identifiers from group ofp_bad_request_code
+OFPBRC_BAD_VERSION = 0
+OFPBRC_BAD_TYPE = 1
+OFPBRC_BAD_STAT = 2
+OFPBRC_BAD_VENDOR = 3
+OFPBRC_BAD_SUBTYPE = 4
+OFPBRC_EPERM = 5
+OFPBRC_BAD_LEN = 6
+OFPBRC_BUFFER_EMPTY = 7
+OFPBRC_BUFFER_UNKNOWN = 8
+
+ofp_bad_request_code_map = {
+    0: 'OFPBRC_BAD_VERSION',
+    1: 'OFPBRC_BAD_TYPE',
+    2: 'OFPBRC_BAD_STAT',
+    3: 'OFPBRC_BAD_VENDOR',
+    4: 'OFPBRC_BAD_SUBTYPE',
+    5: 'OFPBRC_EPERM',
+    6: 'OFPBRC_BAD_LEN',
+    7: 'OFPBRC_BUFFER_EMPTY',
+    8: 'OFPBRC_BUFFER_UNKNOWN',
+}
+
+# Identifiers from group ofp_capabilities
+OFPC_FLOW_STATS = 1 << 0
+OFPC_TABLE_STATS = 1 << 1
+OFPC_PORT_STATS = 1 << 2
+OFPC_STP = 1 << 3
+OFPC_RESERVED = 1 << 4
+OFPC_IP_REASM = 1 << 5
+OFPC_QUEUE_STATS = 1 << 6
+OFPC_ARP_MATCH_IP = 1 << 7
+
+ofp_capabilities_map = {
+    1 << 0: 'OFPC_FLOW_STATS',
+    1 << 1: 'OFPC_TABLE_STATS',
+    1 << 2: 'OFPC_PORT_STATS',
+    1 << 3: 'OFPC_STP',
+    1 << 4: 'OFPC_RESERVED',
+    1 << 5: 'OFPC_IP_REASM',
+    1 << 6: 'OFPC_QUEUE_STATS',
+    1 << 7: 'OFPC_ARP_MATCH_IP',
+}
+
+# Identifiers from group ofp_config_flags
+OFPC_FRAG_NORMAL = 0
+OFPC_FRAG_DROP = 1
+OFPC_FRAG_REASM = 2
+OFPC_FRAG_MASK = 3
+
+ofp_config_flags_map = {
+    0: 'OFPC_FRAG_NORMAL',
+    1: 'OFPC_FRAG_DROP',
+    2: 'OFPC_FRAG_REASM',
+    3: 'OFPC_FRAG_MASK',
+}
+
+# Identifiers from group ofp_error_type
+OFPET_HELLO_FAILED = 0
+OFPET_BAD_REQUEST = 1
+OFPET_BAD_ACTION = 2
+OFPET_FLOW_MOD_FAILED = 3
+OFPET_PORT_MOD_FAILED = 4
+OFPET_QUEUE_OP_FAILED = 5
+
+ofp_error_type_map = {
+    0: 'OFPET_HELLO_FAILED',
+    1: 'OFPET_BAD_REQUEST',
+    2: 'OFPET_BAD_ACTION',
+    3: 'OFPET_FLOW_MOD_FAILED',
+    4: 'OFPET_PORT_MOD_FAILED',
+    5: 'OFPET_QUEUE_OP_FAILED',
+}
+
+# Identifiers from group ofp_flow_mod_command
+OFPFC_ADD = 0
+OFPFC_MODIFY = 1
+OFPFC_MODIFY_STRICT = 2
+OFPFC_DELETE = 3
+OFPFC_DELETE_STRICT = 4
+
+ofp_flow_mod_command_map = {
+    0: 'OFPFC_ADD',
+    1: 'OFPFC_MODIFY',
+    2: 'OFPFC_MODIFY_STRICT',
+    3: 'OFPFC_DELETE',
+    4: 'OFPFC_DELETE_STRICT',
+}
+
+# Identifiers from group ofp_flow_mod_failed_code
+OFPFMFC_ALL_TABLES_FULL = 0
+OFPFMFC_OVERLAP = 1
+OFPFMFC_EPERM = 2
+OFPFMFC_BAD_EMERG_TIMEOUT = 3
+OFPFMFC_BAD_COMMAND = 4
+OFPFMFC_UNSUPPORTED = 5
+
+ofp_flow_mod_failed_code_map = {
+    0: 'OFPFMFC_ALL_TABLES_FULL',
+    1: 'OFPFMFC_OVERLAP',
+    2: 'OFPFMFC_EPERM',
+    3: 'OFPFMFC_BAD_EMERG_TIMEOUT',
+    4: 'OFPFMFC_BAD_COMMAND',
+    5: 'OFPFMFC_UNSUPPORTED',
+}
+
+# Identifiers from group ofp_flow_mod_flags
+OFPFF_SEND_FLOW_REM = 1 << 0
+OFPFF_CHECK_OVERLAP = 1 << 1
+OFPFF_EMERG = 1 << 2
+
+ofp_flow_mod_flags_map = {
+    1 << 0: 'OFPFF_SEND_FLOW_REM',
+    1 << 1: 'OFPFF_CHECK_OVERLAP',
+    1 << 2: 'OFPFF_EMERG',
+}
+
+# Identifiers from group ofp_flow_removed_reason
+OFPRR_IDLE_TIMEOUT = 0
+OFPRR_HARD_TIMEOUT = 1
+OFPRR_DELETE = 2
+
+ofp_flow_removed_reason_map = {
+    0: 'OFPRR_IDLE_TIMEOUT',
+    1: 'OFPRR_HARD_TIMEOUT',
+    2: 'OFPRR_DELETE',
+}
+
+# Identifiers from group ofp_flow_wildcards
+OFPFW_IN_PORT = 1 << 0
+OFPFW_DL_VLAN = 1 << 1
+OFPFW_DL_SRC = 1 << 2
+OFPFW_NW_DST_BITS = 6
+OFPFW_NW_SRC_BITS = 6
+OFPFW_NW_SRC_SHIFT = 8
+OFPFW_DL_DST = 1 << 3
+OFPFW_NW_DST_SHIFT = 14
+OFPFW_DL_TYPE = 1 << 4
+OFPFW_NW_PROTO = 1 << 5
+OFPFW_TP_SRC = 1 << 6
+OFPFW_TP_DST = 1 << 7
+OFPFW_NW_SRC_ALL = 32 << (8)
+OFPFW_NW_SRC_MASK = ((1 << (6)) - 1) << (8)
+OFPFW_NW_DST_ALL = 32 << (14)
+OFPFW_NW_DST_MASK = ((1 << (6)) - 1) << (14)
+OFPFW_DL_VLAN_PCP = 1 << 20
+OFPFW_NW_TOS = 1 << 21
+OFPFW_ALL = ((1 << 22) - 1)
+
+ofp_flow_wildcards_map = {
+    1 << 0: 'OFPFW_IN_PORT',
+    1 << 1: 'OFPFW_DL_VLAN',
+    1 << 2: 'OFPFW_DL_SRC',
+    1 << 3: 'OFPFW_DL_DST',
+    1 << 4: 'OFPFW_DL_TYPE',
+    1 << 5: 'OFPFW_NW_PROTO',
+    1 << 6: 'OFPFW_TP_SRC',
+    1 << 7: 'OFPFW_TP_DST',
+    1 << 20: 'OFPFW_DL_VLAN_PCP',
+    1 << 21: 'OFPFW_NW_TOS',
+}
+
+# Identifiers from group ofp_hello_failed_code
+OFPHFC_INCOMPATIBLE = 0
+OFPHFC_EPERM = 1
+
+ofp_hello_failed_code_map = {
+    0: 'OFPHFC_INCOMPATIBLE',
+    1: 'OFPHFC_EPERM',
+}
+
+# Identifiers from group ofp_packet_in_reason
+OFPR_NO_MATCH = 0
+OFPR_ACTION = 1
+
+ofp_packet_in_reason_map = {
+    0: 'OFPR_NO_MATCH',
+    1: 'OFPR_ACTION',
+}
+
+# Identifiers from group ofp_port
+OFPP_MAX = 0xff00
+OFPP_IN_PORT = 0xfff8
+OFPP_TABLE = 0xfff9
+OFPP_NORMAL = 0xfffa
+OFPP_FLOOD = 0xfffb
+OFPP_ALL = 0xfffc
+OFPP_CONTROLLER = 0xfffd
+OFPP_LOCAL = 0xfffe
+OFPP_NONE = 0xffff
+
+ofp_port_map = {
+    0xff00: 'OFPP_MAX',
+    0xfff8: 'OFPP_IN_PORT',
+    0xfff9: 'OFPP_TABLE',
+    0xfffa: 'OFPP_NORMAL',
+    0xfffb: 'OFPP_FLOOD',
+    0xfffc: 'OFPP_ALL',
+    0xfffd: 'OFPP_CONTROLLER',
+    0xfffe: 'OFPP_LOCAL',
+    0xffff: 'OFPP_NONE',
+}
+
+# Identifiers from group ofp_port_config
+OFPPC_PORT_DOWN = 1 << 0
+OFPPC_NO_STP = 1 << 1
+OFPPC_NO_RECV = 1 << 2
+OFPPC_NO_RECV_STP = 1 << 3
+OFPPC_NO_FLOOD = 1 << 4
+OFPPC_NO_FWD = 1 << 5
+OFPPC_NO_PACKET_IN = 1 << 6
+
+ofp_port_config_map = {
+    1 << 0: 'OFPPC_PORT_DOWN',
+    1 << 1: 'OFPPC_NO_STP',
+    1 << 2: 'OFPPC_NO_RECV',
+    1 << 3: 'OFPPC_NO_RECV_STP',
+    1 << 4: 'OFPPC_NO_FLOOD',
+    1 << 5: 'OFPPC_NO_FWD',
+    1 << 6: 'OFPPC_NO_PACKET_IN',
+}
+
+# Identifiers from group ofp_port_features
+OFPPF_10MB_HD = 1 << 0
+OFPPF_10MB_FD = 1 << 1
+OFPPF_100MB_HD = 1 << 2
+OFPPF_100MB_FD = 1 << 3
+OFPPF_1GB_HD = 1 << 4
+OFPPF_1GB_FD = 1 << 5
+OFPPF_10GB_FD = 1 << 6
+OFPPF_COPPER = 1 << 7
+OFPPF_FIBER = 1 << 8
+OFPPF_AUTONEG = 1 << 9
+OFPPF_PAUSE = 1 << 10
+OFPPF_PAUSE_ASYM = 1 << 11
+
+ofp_port_features_map = {
+    1 << 0: 'OFPPF_10MB_HD',
+    1 << 1: 'OFPPF_10MB_FD',
+    1 << 2: 'OFPPF_100MB_HD',
+    1 << 3: 'OFPPF_100MB_FD',
+    1 << 4: 'OFPPF_1GB_HD',
+    1 << 5: 'OFPPF_1GB_FD',
+    1 << 6: 'OFPPF_10GB_FD',
+    1 << 7: 'OFPPF_COPPER',
+    1 << 8: 'OFPPF_FIBER',
+    1 << 9: 'OFPPF_AUTONEG',
+    1 << 10: 'OFPPF_PAUSE',
+    1 << 11: 'OFPPF_PAUSE_ASYM',
+}
+
+# Identifiers from group ofp_port_mod_failed_code
+OFPPMFC_BAD_PORT = 0
+OFPPMFC_BAD_HW_ADDR = 1
+
+ofp_port_mod_failed_code_map = {
+    0: 'OFPPMFC_BAD_PORT',
+    1: 'OFPPMFC_BAD_HW_ADDR',
+}
+
+# Identifiers from group ofp_port_reason
+OFPPR_ADD = 0
+OFPPR_DELETE = 1
+OFPPR_MODIFY = 2
+
+ofp_port_reason_map = {
+    0: 'OFPPR_ADD',
+    1: 'OFPPR_DELETE',
+    2: 'OFPPR_MODIFY',
+}
+
+# Identifiers from group ofp_port_state
+OFPPS_STP_LISTEN = 0 << 8
+OFPPS_LINK_DOWN = 1 << 0
+OFPPS_STP_LEARN = 1 << 8
+OFPPS_STP_FORWARD = 2 << 8
+OFPPS_STP_BLOCK = 3 << 8
+OFPPS_STP_MASK = 3 << 8
+
+ofp_port_state_map = {
+    0 << 8: 'OFPPS_STP_LISTEN',
+    1 << 0: 'OFPPS_LINK_DOWN',
+    1 << 8: 'OFPPS_STP_LEARN',
+    2 << 8: 'OFPPS_STP_FORWARD',
+    3 << 8: 'OFPPS_STP_BLOCK',
+    3 << 8: 'OFPPS_STP_MASK',
+}
+
+# Identifiers from group ofp_queue_op_failed_code
+OFPQOFC_BAD_PORT = 0
+OFPQOFC_BAD_QUEUE = 1
+OFPQOFC_EPERM = 2
+
+ofp_queue_op_failed_code_map = {
+    0: 'OFPQOFC_BAD_PORT',
+    1: 'OFPQOFC_BAD_QUEUE',
+    2: 'OFPQOFC_EPERM',
+}
+
+# Identifiers from group ofp_queue_properties
+OFPQT_NONE = 0
+OFPQT_MIN_RATE = 1
+
+ofp_queue_properties_map = {
+    0: 'OFPQT_NONE',
+    1: 'OFPQT_MIN_RATE',
+}
+
+# Identifiers from group ofp_stats_reply_flags
+OFPSF_REPLY_MORE = 1 << 0
+
+ofp_stats_reply_flags_map = {
+    1 << 0: 'OFPSF_REPLY_MORE',
+}
+
+# Identifiers from group ofp_stats_types
+OFPST_DESC = 0
+OFPST_FLOW = 1
+OFPST_AGGREGATE = 2
+OFPST_TABLE = 3
+OFPST_PORT = 4
+OFPST_QUEUE = 5
+OFPST_VENDOR = 0xffff
+
+ofp_stats_types_map = {
+    0: 'OFPST_DESC',
+    1: 'OFPST_FLOW',
+    2: 'OFPST_AGGREGATE',
+    3: 'OFPST_TABLE',
+    4: 'OFPST_PORT',
+    5: 'OFPST_QUEUE',
+    0xffff: 'OFPST_VENDOR',
+}
+
+# Identifiers from group ofp_type
+OFPT_HELLO = 0
+OFPT_ERROR = 1
+OFPT_ECHO_REQUEST = 2
+OFPT_ECHO_REPLY = 3
+OFPT_VENDOR = 4
+OFPT_FEATURES_REQUEST = 5
+OFPT_FEATURES_REPLY = 6
+OFPT_GET_CONFIG_REQUEST = 7
+OFPT_GET_CONFIG_REPLY = 8
+OFPT_SET_CONFIG = 9
+OFPT_PACKET_IN = 10
+OFPT_FLOW_REMOVED = 11
+OFPT_PORT_STATUS = 12
+OFPT_PACKET_OUT = 13
+OFPT_FLOW_MOD = 14
+OFPT_PORT_MOD = 15
+OFPT_STATS_REQUEST = 16
+OFPT_STATS_REPLY = 17
+OFPT_BARRIER_REQUEST = 18
+OFPT_BARRIER_REPLY = 19
+OFPT_QUEUE_GET_CONFIG_REQUEST = 20
+OFPT_QUEUE_GET_CONFIG_REPLY = 21
+
+ofp_type_map = {
+    0: 'OFPT_HELLO',
+    1: 'OFPT_ERROR',
+    2: 'OFPT_ECHO_REQUEST',
+    3: 'OFPT_ECHO_REPLY',
+    4: 'OFPT_VENDOR',
+    5: 'OFPT_FEATURES_REQUEST',
+    6: 'OFPT_FEATURES_REPLY',
+    7: 'OFPT_GET_CONFIG_REQUEST',
+    8: 'OFPT_GET_CONFIG_REPLY',
+    9: 'OFPT_SET_CONFIG',
+    10: 'OFPT_PACKET_IN',
+    11: 'OFPT_FLOW_REMOVED',
+    12: 'OFPT_PORT_STATUS',
+    13: 'OFPT_PACKET_OUT',
+    14: 'OFPT_FLOW_MOD',
+    15: 'OFPT_PORT_MOD',
+    16: 'OFPT_STATS_REQUEST',
+    17: 'OFPT_STATS_REPLY',
+    18: 'OFPT_BARRIER_REQUEST',
+    19: 'OFPT_BARRIER_REPLY',
+    20: 'OFPT_QUEUE_GET_CONFIG_REQUEST',
+    21: 'OFPT_QUEUE_GET_CONFIG_REPLY',
+}
+
diff --git a/src/python/loxi/of10/message.py b/src/python/loxi/of10/message.py
new file mode 100644
index 0000000..d80dac3
--- /dev/null
+++ b/src/python/loxi/of10/message.py
@@ -0,0 +1,5098 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template message.py
+# Do not modify
+
+import struct
+import loxi
+import const
+import common
+import action # for unpack_list
+import util
+
+class Message(object):
+    version = const.OFP_VERSION
+    type = None # override in subclass
+    xid = None
+
+class aggregate_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_AGGREGATE
+
+    def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None, pad=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if packet_count != None:
+            self.packet_count = packet_count
+        else:
+            self.packet_count = 0
+        if byte_count != None:
+            self.byte_count = byte_count
+        else:
+            self.byte_count = 0
+        if flow_count != None:
+            self.flow_count = flow_count
+        else:
+            self.flow_count = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0]
+
+    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(struct.pack("!Q", self.packet_count))
+        packed.append(struct.pack("!Q", self.byte_count))
+        packed.append(struct.pack("!L", self.flow_count))
+        packed.append(struct.pack("!4B", *self.pad))
+        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")
+        obj = aggregate_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 36: raise loxi.ProtocolError("aggregate_stats_reply length is %d, should be 36" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_AGGREGATE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.packet_count = struct.unpack_from('!Q', buf, 12)[0]
+        obj.byte_count = struct.unpack_from('!Q', buf, 20)[0]
+        obj.flow_count = struct.unpack_from('!L', buf, 28)[0]
+        obj.pad = list(struct.unpack_from('!4B', buf, 32))
+        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.packet_count != other.packet_count: return False
+        if self.byte_count != other.byte_count: return False
+        if self.flow_count != other.flow_count: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("packet_count = ");
+                q.text("%#x" % self.packet_count)
+                q.text(","); q.breakable()
+                q.text("byte_count = ");
+                q.text("%#x" % self.byte_count)
+                q.text(","); q.breakable()
+                q.text("flow_count = ");
+                q.text("%#x" % self.flow_count)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class aggregate_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_AGGREGATE
+
+    def __init__(self, xid=None, flags=None, match=None, table_id=None, pad=None, out_port=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if table_id != None:
+            self.table_id = table_id
+        else:
+            self.table_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+
+    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(self.match.pack())
+        packed.append(struct.pack("!B", self.table_id))
+        packed.append(struct.pack("!B", self.pad))
+        packed.append(struct.pack("!H", self.out_port))
+        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")
+        obj = aggregate_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 56: raise loxi.ProtocolError("aggregate_stats_request length is %d, should be 56" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_AGGREGATE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.match = common.match.unpack(buffer(buf, 12))
+        obj.table_id = struct.unpack_from('!B', buf, 52)[0]
+        obj.pad = struct.unpack_from('!B', buf, 53)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 54)[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
+        if self.flags != other.flags: return False
+        if self.match != other.match: return False
+        if self.table_id != other.table_id: return False
+        if self.pad != other.pad: return False
+        if self.out_port != other.out_port: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("aggregate_stats_request {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("table_id = ");
+                q.text("%#x" % self.table_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+            q.breakable()
+        q.text('}')
+
+class barrier_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_BARRIER_REPLY
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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))
+        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")
+        obj = barrier_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_BARRIER_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("barrier_reply length is %d, should be 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[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():
+            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('}')
+
+class barrier_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_BARRIER_REQUEST
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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))
+        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")
+        obj = barrier_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_BARRIER_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("barrier_request length is %d, should be 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[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():
+            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('}')
+
+class bsn_get_interfaces_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 10
+
+    def __init__(self, xid=None, interfaces=None):
+        self.xid = xid
+        if interfaces != None:
+            self.interfaces = interfaces
+        else:
+            self.interfaces = []
+
+    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("".join([x.pack() for x in 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")
+        obj = bsn_get_interfaces_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("bsn_get_interfaces_reply length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 10)
+        obj.interfaces = util.unpack_array(common.bsn_interface.unpack, 32, buffer(buf, 16))
+        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.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():
+            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("interfaces = ");
+                q.pp(self.interfaces)
+            q.breakable()
+        q.text('}')
+
+class bsn_get_interfaces_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 9
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = bsn_get_interfaces_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("bsn_get_interfaces_request length is %d, should be 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 9)
+        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("bsn_get_interfaces_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('}')
+
+class bsn_get_ip_mask_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 2
+
+    def __init__(self, xid=None, index=None, pad=None, mask=None):
+        self.xid = xid
+        if index != None:
+            self.index = index
+        else:
+            self.index = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+        if mask != None:
+            self.mask = mask
+        else:
+            self.mask = 0
+
+    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("!B", self.index))
+        packed.append(struct.pack("!3B", *self.pad))
+        packed.append(struct.pack("!L", self.mask))
+        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")
+        obj = bsn_get_ip_mask_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 24: raise loxi.ProtocolError("bsn_get_ip_mask_reply length is %d, should be 24" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 2)
+        obj.index = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 17))
+        obj.mask = struct.unpack_from('!L', buf, 20)[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
+        if self.index != other.index: return False
+        if self.pad != other.pad: return False
+        if self.mask != other.mask: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_get_ip_mask_reply {")
+        with q.group():
+            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("index = ");
+                q.text("%#x" % self.index)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("mask = ");
+                q.text("%#x" % self.mask)
+            q.breakable()
+        q.text('}')
+
+class bsn_get_ip_mask_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 1
+
+    def __init__(self, xid=None, index=None, pad=None):
+        self.xid = xid
+        if index != None:
+            self.index = index
+        else:
+            self.index = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0,0]
+
+    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("!B", self.index))
+        packed.append(struct.pack("!7B", *self.pad))
+        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")
+        obj = bsn_get_ip_mask_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 24: raise loxi.ProtocolError("bsn_get_ip_mask_request length is %d, should be 24" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 1)
+        obj.index = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!7B', buf, 17))
+        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.index != other.index: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_get_ip_mask_request {")
+        with q.group():
+            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("index = ");
+                q.text("%#x" % self.index)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class bsn_get_mirroring_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 5
+
+    def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+        self.xid = xid
+        if report_mirror_ports != None:
+            self.report_mirror_ports = report_mirror_ports
+        else:
+            self.report_mirror_ports = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    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("!B", self.report_mirror_ports))
+        packed.append(struct.pack("!3B", *self.pad))
+        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")
+        obj = bsn_get_mirroring_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("bsn_get_mirroring_reply length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 5)
+        obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 17))
+        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.report_mirror_ports != other.report_mirror_ports: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("report_mirror_ports = ");
+                q.text("%#x" % self.report_mirror_ports)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class bsn_get_mirroring_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 4
+
+    def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+        self.xid = xid
+        if report_mirror_ports != None:
+            self.report_mirror_ports = report_mirror_ports
+        else:
+            self.report_mirror_ports = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    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("!B", self.report_mirror_ports))
+        packed.append(struct.pack("!3B", *self.pad))
+        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")
+        obj = bsn_get_mirroring_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("bsn_get_mirroring_request length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 4)
+        obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 17))
+        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.report_mirror_ports != other.report_mirror_ports: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("report_mirror_ports = ");
+                q.text("%#x" % self.report_mirror_ports)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class bsn_set_ip_mask(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 0
+
+    def __init__(self, xid=None, index=None, pad=None, mask=None):
+        self.xid = xid
+        if index != None:
+            self.index = index
+        else:
+            self.index = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+        if mask != None:
+            self.mask = mask
+        else:
+            self.mask = 0
+
+    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("!B", self.index))
+        packed.append(struct.pack("!3B", *self.pad))
+        packed.append(struct.pack("!L", self.mask))
+        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")
+        obj = bsn_set_ip_mask()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 24: raise loxi.ProtocolError("bsn_set_ip_mask length is %d, should be 24" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 0)
+        obj.index = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 17))
+        obj.mask = struct.unpack_from('!L', buf, 20)[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
+        if self.index != other.index: return False
+        if self.pad != other.pad: return False
+        if self.mask != other.mask: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_set_ip_mask {")
+        with q.group():
+            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("index = ");
+                q.text("%#x" % self.index)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("mask = ");
+                q.text("%#x" % self.mask)
+            q.breakable()
+        q.text('}')
+
+class bsn_set_mirroring(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 3
+
+    def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+        self.xid = xid
+        if report_mirror_ports != None:
+            self.report_mirror_ports = report_mirror_ports
+        else:
+            self.report_mirror_ports = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+
+    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("!B", self.report_mirror_ports))
+        packed.append(struct.pack("!3B", *self.pad))
+        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")
+        obj = bsn_set_mirroring()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("bsn_set_mirroring length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 3)
+        obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 17))
+        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.report_mirror_ports != other.report_mirror_ports: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("report_mirror_ports = ");
+                q.text("%#x" % self.report_mirror_ports)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class bsn_shell_command(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 6
+
+    def __init__(self, xid=None, service=None, data=None):
+        self.xid = xid
+        if service != None:
+            self.service = service
+        else:
+            self.service = 0
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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.service))
+        packed.append(self.data)
+        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")
+        obj = bsn_shell_command()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 20: raise loxi.ProtocolError("bsn_shell_command length is %d, should be at least 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 6)
+        obj.service = struct.unpack_from('!L', buf, 16)[0]
+        obj.data = buf[20:]
+        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.service != other.service: return False
+        if self.data != other.data: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_shell_command {")
+        with q.group():
+            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("service = ");
+                q.text("%#x" % self.service)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class bsn_shell_output(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 7
+
+    def __init__(self, xid=None, data=None):
+        self.xid = xid
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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(self.data)
+        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")
+        obj = bsn_shell_output()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("bsn_shell_output length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 7)
+        obj.data = buf[16:]
+        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("bsn_shell_output {")
+        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("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class bsn_shell_status(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x5c16c7
+    subtype = 8
+
+    def __init__(self, xid=None, status=None):
+        self.xid = xid
+        if status != None:
+            self.status = status
+        else:
+            self.status = 0
+
+    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(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = bsn_shell_status()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("bsn_shell_status length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x5c16c7)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 8)
+        obj.status = struct.unpack_from('!L', buf, 16)[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
+        if self.status != other.status: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("bsn_shell_status {")
+        with q.group():
+            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('}')
+
+class desc_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_DESC
+
+    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 flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if mfr_desc != None:
+            self.mfr_desc = mfr_desc
+        else:
+            self.mfr_desc = ""
+        if hw_desc != None:
+            self.hw_desc = hw_desc
+        else:
+            self.hw_desc = ""
+        if sw_desc != None:
+            self.sw_desc = sw_desc
+        else:
+            self.sw_desc = ""
+        if serial_num != None:
+            self.serial_num = serial_num
+        else:
+            self.serial_num = ""
+        if dp_desc != None:
+            self.dp_desc = dp_desc
+        else:
+            self.dp_desc = ""
+
+    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(struct.pack("!256s", self.mfr_desc))
+        packed.append(struct.pack("!256s", self.hw_desc))
+        packed.append(struct.pack("!256s", self.sw_desc))
+        packed.append(struct.pack("!32s", self.serial_num))
+        packed.append(struct.pack("!256s", self.dp_desc))
+        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")
+        obj = desc_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 1068: raise loxi.ProtocolError("desc_stats_reply length is %d, should be 1068" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_DESC)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.mfr_desc = str(buffer(buf, 12, 256)).rstrip("\x00")
+        obj.hw_desc = str(buffer(buf, 268, 256)).rstrip("\x00")
+        obj.sw_desc = str(buffer(buf, 524, 256)).rstrip("\x00")
+        obj.serial_num = str(buffer(buf, 780, 32)).rstrip("\x00")
+        obj.dp_desc = str(buffer(buf, 812, 256)).rstrip("\x00")
+        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.mfr_desc != other.mfr_desc: return False
+        if self.hw_desc != other.hw_desc: return False
+        if self.sw_desc != other.sw_desc: return False
+        if self.serial_num != other.serial_num: return False
+        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():
+            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("mfr_desc = ");
+                q.pp(self.mfr_desc)
+                q.text(","); q.breakable()
+                q.text("hw_desc = ");
+                q.pp(self.hw_desc)
+                q.text(","); q.breakable()
+                q.text("sw_desc = ");
+                q.pp(self.sw_desc)
+                q.text(","); q.breakable()
+                q.text("serial_num = ");
+                q.pp(self.serial_num)
+                q.text(","); q.breakable()
+                q.text("dp_desc = ");
+                q.pp(self.dp_desc)
+            q.breakable()
+        q.text('}')
+
+class desc_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_DESC
+
+    def __init__(self, xid=None, flags=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+
+    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))
+        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")
+        obj = desc_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 12: raise loxi.ProtocolError("desc_stats_request length is %d, should be 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_DESC)
+        obj.flags = struct.unpack_from('!H', buf, 10)[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
+        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():
+            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('}')
+
+class echo_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_ECHO_REPLY
+
+    def __init__(self, xid=None, data=None):
+        self.xid = xid
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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(self.data)
+        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")
+        obj = echo_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_ECHO_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 8: raise loxi.ProtocolError("echo_reply length is %d, should be at least 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.data = buf[8:]
+        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():
+            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("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class echo_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_ECHO_REQUEST
+
+    def __init__(self, xid=None, data=None):
+        self.xid = xid
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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(self.data)
+        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")
+        obj = echo_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_ECHO_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 8: raise loxi.ProtocolError("echo_request length is %d, should be at least 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.data = buf[8:]
+        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():
+            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("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class error_msg(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_ERROR
+
+    def __init__(self, xid=None, err_type=None, code=None, data=None):
+        self.xid = xid
+        if err_type != None:
+            self.err_type = err_type
+        else:
+            self.err_type = 0
+        if code != None:
+            self.code = code
+        else:
+            self.code = 0
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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.err_type))
+        packed.append(struct.pack("!H", self.code))
+        packed.append(self.data)
+        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")
+        obj = error_msg()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_ERROR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 12: raise loxi.ProtocolError("error_msg length is %d, should be at least 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.err_type = struct.unpack_from('!H', buf, 8)[0]
+        obj.code = struct.unpack_from('!H', buf, 10)[0]
+        obj.data = buf[12:]
+        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.err_type != other.err_type: 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("error_msg {")
+        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("err_type = ");
+                q.text("%#x" % self.err_type)
+                q.text(","); q.breakable()
+                q.text("code = ");
+                q.text("%#x" % self.code)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class experimenter_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_VENDOR
+
+    def __init__(self, xid=None, flags=None, experimenter=None, data=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if experimenter != None:
+            self.experimenter = experimenter
+        else:
+            self.experimenter = 0
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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(struct.pack("!L", self.experimenter))
+        packed.append(self.data)
+        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")
+        obj = experimenter_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("experimenter_stats_reply length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_VENDOR)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.experimenter = struct.unpack_from('!L', buf, 12)[0]
+        obj.data = buf[16:]
+        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.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_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("experimenter = ");
+                q.text("%#x" % self.experimenter)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class experimenter_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_VENDOR
+
+    def __init__(self, xid=None, flags=None, experimenter=None, data=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if experimenter != None:
+            self.experimenter = experimenter
+        else:
+            self.experimenter = 0
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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(struct.pack("!L", self.experimenter))
+        packed.append(self.data)
+        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")
+        obj = experimenter_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("experimenter_stats_request length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_VENDOR)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.experimenter = struct.unpack_from('!L', buf, 12)[0]
+        obj.data = buf[16:]
+        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.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_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("experimenter = ");
+                q.text("%#x" % self.experimenter)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class features_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FEATURES_REPLY
+
+    def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, pad=None, capabilities=None, actions=None, ports=None):
+        self.xid = xid
+        if datapath_id != None:
+            self.datapath_id = datapath_id
+        else:
+            self.datapath_id = 0
+        if n_buffers != None:
+            self.n_buffers = n_buffers
+        else:
+            self.n_buffers = 0
+        if n_tables != None:
+            self.n_tables = n_tables
+        else:
+            self.n_tables = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+        if capabilities != None:
+            self.capabilities = capabilities
+        else:
+            self.capabilities = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = 0
+        if ports != None:
+            self.ports = ports
+        else:
+            self.ports = []
+
+    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("!Q", self.datapath_id))
+        packed.append(struct.pack("!L", self.n_buffers))
+        packed.append(struct.pack("!B", self.n_tables))
+        packed.append(struct.pack("!3B", *self.pad))
+        packed.append(struct.pack("!L", self.capabilities))
+        packed.append(struct.pack("!L", self.actions))
+        packed.append("".join([x.pack() for x in self.ports]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = features_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FEATURES_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 32: raise loxi.ProtocolError("features_reply length is %d, should be at least 32" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.datapath_id = struct.unpack_from('!Q', buf, 8)[0]
+        obj.n_buffers = struct.unpack_from('!L', buf, 16)[0]
+        obj.n_tables = struct.unpack_from('!B', buf, 20)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 21))
+        obj.capabilities = struct.unpack_from('!L', buf, 24)[0]
+        obj.actions = struct.unpack_from('!L', buf, 28)[0]
+        obj.ports = util.unpack_array(common.port_desc.unpack, 48, buffer(buf, 32))
+        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.datapath_id != other.datapath_id: return False
+        if self.n_buffers != other.n_buffers: return False
+        if self.n_tables != other.n_tables: return False
+        if self.pad != other.pad: return False
+        if self.capabilities != other.capabilities: return False
+        if self.actions != other.actions: return False
+        if self.ports != other.ports: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("features_reply {")
+        with q.group():
+            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("datapath_id = ");
+                q.text("%#x" % self.datapath_id)
+                q.text(","); q.breakable()
+                q.text("n_buffers = ");
+                q.text("%#x" % self.n_buffers)
+                q.text(","); q.breakable()
+                q.text("n_tables = ");
+                q.text("%#x" % self.n_tables)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("capabilities = ");
+                q.text("%#x" % self.capabilities)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.text("%#x" % self.actions)
+                q.text(","); q.breakable()
+                q.text("ports = ");
+                q.pp(self.ports)
+            q.breakable()
+        q.text('}')
+
+class features_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FEATURES_REQUEST
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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))
+        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")
+        obj = features_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FEATURES_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("features_request length is %d, should be 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[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():
+            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('}')
+
+class flow_add(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_MOD
+    _command = const.OFPFC_ADD
+
+    def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self._command))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.out_port))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = flow_add()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 72: raise loxi.ProtocolError("flow_add length is %d, should be at least 72" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        _command = struct.unpack_from('!H', buf, 56)[0]
+        assert(_command == const.OFPFC_ADD)
+        obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+        obj.priority = struct.unpack_from('!H', buf, 62)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+        obj.flags = struct.unpack_from('!H', buf, 70)[0]
+        obj.actions = action.unpack_list(buffer(buf, 72))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.priority != other.priority: return False
+        if self.buffer_id != other.buffer_id: return False
+        if self.out_port != other.out_port: return False
+        if self.flags != other.flags: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_add {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class flow_delete(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_MOD
+    _command = const.OFPFC_DELETE
+
+    def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self._command))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.out_port))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = flow_delete()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 72: raise loxi.ProtocolError("flow_delete length is %d, should be at least 72" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        _command = struct.unpack_from('!H', buf, 56)[0]
+        assert(_command == const.OFPFC_DELETE)
+        obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+        obj.priority = struct.unpack_from('!H', buf, 62)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+        obj.flags = struct.unpack_from('!H', buf, 70)[0]
+        obj.actions = action.unpack_list(buffer(buf, 72))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.priority != other.priority: return False
+        if self.buffer_id != other.buffer_id: return False
+        if self.out_port != other.out_port: return False
+        if self.flags != other.flags: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_delete {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class flow_delete_strict(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_MOD
+    _command = const.OFPFC_DELETE_STRICT
+
+    def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self._command))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.out_port))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = flow_delete_strict()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 72: raise loxi.ProtocolError("flow_delete_strict length is %d, should be at least 72" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        _command = struct.unpack_from('!H', buf, 56)[0]
+        assert(_command == const.OFPFC_DELETE_STRICT)
+        obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+        obj.priority = struct.unpack_from('!H', buf, 62)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+        obj.flags = struct.unpack_from('!H', buf, 70)[0]
+        obj.actions = action.unpack_list(buffer(buf, 72))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.priority != other.priority: return False
+        if self.buffer_id != other.buffer_id: return False
+        if self.out_port != other.out_port: return False
+        if self.flags != other.flags: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_delete_strict {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class flow_modify(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_MOD
+    _command = const.OFPFC_MODIFY
+
+    def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self._command))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.out_port))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = flow_modify()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 72: raise loxi.ProtocolError("flow_modify length is %d, should be at least 72" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        _command = struct.unpack_from('!H', buf, 56)[0]
+        assert(_command == const.OFPFC_MODIFY)
+        obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+        obj.priority = struct.unpack_from('!H', buf, 62)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+        obj.flags = struct.unpack_from('!H', buf, 70)[0]
+        obj.actions = action.unpack_list(buffer(buf, 72))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.priority != other.priority: return False
+        if self.buffer_id != other.buffer_id: return False
+        if self.out_port != other.out_port: return False
+        if self.flags != other.flags: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_modify {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class flow_modify_strict(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_MOD
+    _command = const.OFPFC_MODIFY_STRICT
+
+    def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if hard_timeout != None:
+            self.hard_timeout = hard_timeout
+        else:
+            self.hard_timeout = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self._command))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!H", self.hard_timeout))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.out_port))
+        packed.append(struct.pack("!H", self.flags))
+        packed.append("".join([x.pack() for x in self.actions]))
+        length = sum([len(x) for x in packed])
+        packed[2] = struct.pack("!H", length)
+        return ''.join(packed)
+
+    @staticmethod
+    def unpack(buf):
+        if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+        obj = flow_modify_strict()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 72: raise loxi.ProtocolError("flow_modify_strict length is %d, should be at least 72" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        _command = struct.unpack_from('!H', buf, 56)[0]
+        assert(_command == const.OFPFC_MODIFY_STRICT)
+        obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+        obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+        obj.priority = struct.unpack_from('!H', buf, 62)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+        obj.flags = struct.unpack_from('!H', buf, 70)[0]
+        obj.actions = action.unpack_list(buffer(buf, 72))
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.hard_timeout != other.hard_timeout: return False
+        if self.priority != other.priority: return False
+        if self.buffer_id != other.buffer_id: return False
+        if self.out_port != other.out_port: return False
+        if self.flags != other.flags: return False
+        if self.actions != other.actions: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_modify_strict {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("hard_timeout = ");
+                q.text("%#x" % self.hard_timeout)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+                q.text(","); q.breakable()
+                q.text("flags = ");
+                q.text("%#x" % self.flags)
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+            q.breakable()
+        q.text('}')
+
+class flow_removed(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_FLOW_REMOVED
+
+    def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, pad=None, duration_sec=None, duration_nsec=None, idle_timeout=None, pad2=None, packet_count=None, byte_count=None):
+        self.xid = xid
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if cookie != None:
+            self.cookie = cookie
+        else:
+            self.cookie = 0
+        if priority != None:
+            self.priority = priority
+        else:
+            self.priority = 0
+        if reason != None:
+            self.reason = reason
+        else:
+            self.reason = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if duration_sec != None:
+            self.duration_sec = duration_sec
+        else:
+            self.duration_sec = 0
+        if duration_nsec != None:
+            self.duration_nsec = duration_nsec
+        else:
+            self.duration_nsec = 0
+        if idle_timeout != None:
+            self.idle_timeout = idle_timeout
+        else:
+            self.idle_timeout = 0
+        if pad2 != None:
+            self.pad2 = pad2
+        else:
+            self.pad2 = [0,0]
+        if packet_count != None:
+            self.packet_count = packet_count
+        else:
+            self.packet_count = 0
+        if byte_count != None:
+            self.byte_count = byte_count
+        else:
+            self.byte_count = 0
+
+    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(self.match.pack())
+        packed.append(struct.pack("!Q", self.cookie))
+        packed.append(struct.pack("!H", self.priority))
+        packed.append(struct.pack("!B", self.reason))
+        packed.append(struct.pack("!B", self.pad))
+        packed.append(struct.pack("!L", self.duration_sec))
+        packed.append(struct.pack("!L", self.duration_nsec))
+        packed.append(struct.pack("!H", self.idle_timeout))
+        packed.append(struct.pack("!2B", *self.pad2))
+        packed.append(struct.pack("!Q", self.packet_count))
+        packed.append(struct.pack("!Q", self.byte_count))
+        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")
+        obj = flow_removed()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_FLOW_REMOVED)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 88: raise loxi.ProtocolError("flow_removed length is %d, should be 88" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.match = common.match.unpack(buffer(buf, 8))
+        obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+        obj.priority = struct.unpack_from('!H', buf, 56)[0]
+        obj.reason = struct.unpack_from('!B', buf, 58)[0]
+        obj.pad = struct.unpack_from('!B', buf, 59)[0]
+        obj.duration_sec = struct.unpack_from('!L', buf, 60)[0]
+        obj.duration_nsec = struct.unpack_from('!L', buf, 64)[0]
+        obj.idle_timeout = struct.unpack_from('!H', buf, 68)[0]
+        obj.pad2 = list(struct.unpack_from('!2B', buf, 70))
+        obj.packet_count = struct.unpack_from('!Q', buf, 72)[0]
+        obj.byte_count = struct.unpack_from('!Q', buf, 80)[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
+        if self.match != other.match: return False
+        if self.cookie != other.cookie: return False
+        if self.priority != other.priority: return False
+        if self.reason != other.reason: return False
+        if self.pad != other.pad: return False
+        if self.duration_sec != other.duration_sec: return False
+        if self.duration_nsec != other.duration_nsec: return False
+        if self.idle_timeout != other.idle_timeout: return False
+        if self.pad2 != other.pad2: return False
+        if self.packet_count != other.packet_count: return False
+        if self.byte_count != other.byte_count: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_removed {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("cookie = ");
+                q.text("%#x" % self.cookie)
+                q.text(","); q.breakable()
+                q.text("priority = ");
+                q.text("%#x" % self.priority)
+                q.text(","); q.breakable()
+                q.text("reason = ");
+                q.text("%#x" % self.reason)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("duration_sec = ");
+                q.text("%#x" % self.duration_sec)
+                q.text(","); q.breakable()
+                q.text("duration_nsec = ");
+                q.text("%#x" % self.duration_nsec)
+                q.text(","); q.breakable()
+                q.text("idle_timeout = ");
+                q.text("%#x" % self.idle_timeout)
+                q.text(","); q.breakable()
+                q.text("pad2 = ");
+                q.pp(self.pad2)
+                q.text(","); q.breakable()
+                q.text("packet_count = ");
+                q.text("%#x" % self.packet_count)
+                q.text(","); q.breakable()
+                q.text("byte_count = ");
+                q.text("%#x" % self.byte_count)
+            q.breakable()
+        q.text('}')
+
+class flow_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_FLOW
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+
+    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("".join([x.pack() for x in 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")
+        obj = flow_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 12: raise loxi.ProtocolError("flow_stats_reply length is %d, should be at least 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_FLOW)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.entries = common.unpack_list_flow_stats_entry(buffer(buf, 12))
+        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():
+            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('}')
+
+class flow_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_FLOW
+
+    def __init__(self, xid=None, flags=None, match=None, table_id=None, pad=None, out_port=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if match != None:
+            self.match = match
+        else:
+            self.match = common.match()
+        if table_id != None:
+            self.table_id = table_id
+        else:
+            self.table_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if out_port != None:
+            self.out_port = out_port
+        else:
+            self.out_port = 0
+
+    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(self.match.pack())
+        packed.append(struct.pack("!B", self.table_id))
+        packed.append(struct.pack("!B", self.pad))
+        packed.append(struct.pack("!H", self.out_port))
+        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")
+        obj = flow_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 56: raise loxi.ProtocolError("flow_stats_request length is %d, should be 56" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_FLOW)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.match = common.match.unpack(buffer(buf, 12))
+        obj.table_id = struct.unpack_from('!B', buf, 52)[0]
+        obj.pad = struct.unpack_from('!B', buf, 53)[0]
+        obj.out_port = struct.unpack_from('!H', buf, 54)[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
+        if self.flags != other.flags: return False
+        if self.match != other.match: return False
+        if self.table_id != other.table_id: return False
+        if self.pad != other.pad: return False
+        if self.out_port != other.out_port: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("flow_stats_request {")
+        with q.group():
+            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("match = ");
+                q.pp(self.match)
+                q.text(","); q.breakable()
+                q.text("table_id = ");
+                q.text("%#x" % self.table_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("out_port = ");
+                q.text(util.pretty_port(self.out_port))
+            q.breakable()
+        q.text('}')
+
+class get_config_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_GET_CONFIG_REPLY
+
+    def __init__(self, xid=None, flags=None, miss_send_len=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if miss_send_len != None:
+            self.miss_send_len = miss_send_len
+        else:
+            self.miss_send_len = 0
+
+    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.flags))
+        packed.append(struct.pack("!H", self.miss_send_len))
+        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")
+        obj = get_config_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_GET_CONFIG_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 12: raise loxi.ProtocolError("get_config_reply length is %d, should be 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.flags = struct.unpack_from('!H', buf, 8)[0]
+        obj.miss_send_len = struct.unpack_from('!H', buf, 10)[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
+        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():
+            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("miss_send_len = ");
+                q.text("%#x" % self.miss_send_len)
+            q.breakable()
+        q.text('}')
+
+class get_config_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_GET_CONFIG_REQUEST
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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))
+        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")
+        obj = get_config_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_GET_CONFIG_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("get_config_request length is %d, should be 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[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():
+            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('}')
+
+class hello(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_HELLO
+
+    def __init__(self, xid=None):
+        self.xid = xid
+
+    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))
+        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")
+        obj = hello()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_HELLO)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 8: raise loxi.ProtocolError("hello length is %d, should be 8" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        return obj
+
+    def __eq__(self, other):
+        if type(self) != type(other): return False
+        if self.version != other.version: return False
+        if self.type != other.type: return False
+        if self.xid != other.xid: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("hello {")
+        with q.group():
+            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('}')
+
+class nicira_controller_role_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x2320
+    subtype = 11
+
+    def __init__(self, xid=None, role=None):
+        self.xid = xid
+        if role != None:
+            self.role = role
+        else:
+            self.role = 0
+
+    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.role))
+        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")
+        obj = nicira_controller_role_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("nicira_controller_role_reply length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x2320)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 11)
+        obj.role = struct.unpack_from('!L', buf, 16)[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
+        if self.role != other.role: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("nicira_controller_role_reply {")
+        with q.group():
+            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("role = ");
+                q.text("%#x" % self.role)
+            q.breakable()
+        q.text('}')
+
+class nicira_controller_role_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_VENDOR
+    experimenter = 0x2320
+    subtype = 10
+
+    def __init__(self, xid=None, role=None):
+        self.xid = xid
+        if role != None:
+            self.role = role
+        else:
+            self.role = 0
+
+    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.role))
+        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")
+        obj = nicira_controller_role_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_VENDOR)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("nicira_controller_role_request length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        experimenter = struct.unpack_from('!L', buf, 8)[0]
+        assert(experimenter == 0x2320)
+        subtype = struct.unpack_from('!L', buf, 12)[0]
+        assert(subtype == 10)
+        obj.role = struct.unpack_from('!L', buf, 16)[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
+        if self.role != other.role: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __str__(self):
+        return self.show()
+
+    def show(self):
+        import loxi.pp
+        return loxi.pp.pp(self)
+
+    def pretty_print(self, q):
+        q.text("nicira_controller_role_request {")
+        with q.group():
+            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("role = ");
+                q.text("%#x" % self.role)
+            q.breakable()
+        q.text('}')
+
+class packet_in(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_PACKET_IN
+
+    def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None, reason=None, pad=None, data=None):
+        self.xid = xid
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if total_len != None:
+            self.total_len = total_len
+        else:
+            self.total_len = 0
+        if in_port != None:
+            self.in_port = in_port
+        else:
+            self.in_port = 0
+        if reason != None:
+            self.reason = reason
+        else:
+            self.reason = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = 0
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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.buffer_id))
+        packed.append(struct.pack("!H", self.total_len))
+        packed.append(struct.pack("!H", self.in_port))
+        packed.append(struct.pack("!B", self.reason))
+        packed.append(struct.pack("!B", self.pad))
+        packed.append(self.data)
+        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")
+        obj = packet_in()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_PACKET_IN)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 18: raise loxi.ProtocolError("packet_in length is %d, should be at least 18" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 8)[0]
+        obj.total_len = struct.unpack_from('!H', buf, 12)[0]
+        obj.in_port = struct.unpack_from('!H', buf, 14)[0]
+        obj.reason = struct.unpack_from('!B', buf, 16)[0]
+        obj.pad = struct.unpack_from('!B', buf, 17)[0]
+        obj.data = buf[18:]
+        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.total_len != other.total_len: return False
+        if self.in_port != other.in_port: return False
+        if self.reason != other.reason: return False
+        if self.pad != other.pad: 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("packet_in {")
+        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("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("total_len = ");
+                q.text("%#x" % self.total_len)
+                q.text(","); q.breakable()
+                q.text("in_port = ");
+                q.text(util.pretty_port(self.in_port))
+                q.text(","); q.breakable()
+                q.text("reason = ");
+                q.text("%#x" % self.reason)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.text("%#x" % self.pad)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class packet_out(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_PACKET_OUT
+
+    def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
+        self.xid = xid
+        if buffer_id != None:
+            self.buffer_id = buffer_id
+        else:
+            self.buffer_id = 0
+        if in_port != None:
+            self.in_port = in_port
+        else:
+            self.in_port = 0
+        if actions != None:
+            self.actions = actions
+        else:
+            self.actions = []
+        if data != None:
+            self.data = data
+        else:
+            self.data = ""
+
+    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 3
+        packed.append(struct.pack("!L", self.xid))
+        packed.append(struct.pack("!L", self.buffer_id))
+        packed.append(struct.pack("!H", self.in_port))
+        packed_actions = "".join([x.pack() for x in self.actions])
+        packed.append(struct.pack("!H", len(packed_actions)))
+        packed.append(packed_actions)
+        packed.append(self.data)
+        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")
+        obj = packet_out()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_PACKET_OUT)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("packet_out length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.buffer_id = struct.unpack_from('!L', buf, 8)[0]
+        obj.in_port = struct.unpack_from('!H', buf, 12)[0]
+        actions_len = struct.unpack_from('!H', buf, 14)[0]
+        obj.actions = action.unpack_list(buffer(buf, 16, actions_len))
+        obj.data = str(buffer(buf, 16+actions_len))
+        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
+        if self.actions != other.actions: 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("packet_out {")
+        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("buffer_id = ");
+                q.text("%#x" % self.buffer_id)
+                q.text(","); q.breakable()
+                q.text("in_port = ");
+                q.text(util.pretty_port(self.in_port))
+                q.text(","); q.breakable()
+                q.text("actions = ");
+                q.pp(self.actions)
+                q.text(","); q.breakable()
+                q.text("data = ");
+                q.pp(self.data)
+            q.breakable()
+        q.text('}')
+
+class port_mod(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_PORT_MOD
+
+    def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None, pad=None):
+        self.xid = xid
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if hw_addr != None:
+            self.hw_addr = hw_addr
+        else:
+            self.hw_addr = [0,0,0,0,0,0]
+        if config != None:
+            self.config = config
+        else:
+            self.config = 0
+        if mask != None:
+            self.mask = mask
+        else:
+            self.mask = 0
+        if advertise != None:
+            self.advertise = advertise
+        else:
+            self.advertise = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0]
+
+    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.port_no))
+        packed.append(struct.pack("!6B", *self.hw_addr))
+        packed.append(struct.pack("!L", self.config))
+        packed.append(struct.pack("!L", self.mask))
+        packed.append(struct.pack("!L", self.advertise))
+        packed.append(struct.pack("!4B", *self.pad))
+        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")
+        obj = port_mod()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_PORT_MOD)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 32: raise loxi.ProtocolError("port_mod length is %d, should be 32" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.port_no = struct.unpack_from('!H', buf, 8)[0]
+        obj.hw_addr = list(struct.unpack_from('!6B', buf, 10))
+        obj.config = struct.unpack_from('!L', buf, 16)[0]
+        obj.mask = struct.unpack_from('!L', buf, 20)[0]
+        obj.advertise = struct.unpack_from('!L', buf, 24)[0]
+        obj.pad = list(struct.unpack_from('!4B', buf, 28))
+        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_no != other.port_no: return False
+        if self.hw_addr != other.hw_addr: return False
+        if self.config != other.config: return False
+        if self.mask != other.mask: return False
+        if self.advertise != other.advertise: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("port_no = ");
+                q.text(util.pretty_port(self.port_no))
+                q.text(","); q.breakable()
+                q.text("hw_addr = ");
+                q.text(util.pretty_mac(self.hw_addr))
+                q.text(","); q.breakable()
+                q.text("config = ");
+                q.text("%#x" % self.config)
+                q.text(","); q.breakable()
+                q.text("mask = ");
+                q.text("%#x" % self.mask)
+                q.text(","); q.breakable()
+                q.text("advertise = ");
+                q.text("%#x" % self.advertise)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class port_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_PORT
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+
+    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("".join([x.pack() for x in 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")
+        obj = port_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 12: raise loxi.ProtocolError("port_stats_reply length is %d, should be at least 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_PORT)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.entries = util.unpack_array(common.port_stats_entry.unpack, 104, buffer(buf, 12))
+        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("port_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('}')
+
+class port_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_PORT
+
+    def __init__(self, xid=None, flags=None, port_no=None, pad=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+
+    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(struct.pack("!H", self.port_no))
+        packed.append(struct.pack("!6B", *self.pad))
+        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")
+        obj = port_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("port_stats_request length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_PORT)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.port_no = struct.unpack_from('!H', buf, 12)[0]
+        obj.pad = list(struct.unpack_from('!6B', buf, 14))
+        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.port_no != other.port_no: return False
+        if self.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class port_status(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_PORT_STATUS
+
+    def __init__(self, xid=None, reason=None, pad=None, desc=None):
+        self.xid = xid
+        if reason != None:
+            self.reason = reason
+        else:
+            self.reason = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0,0]
+        if desc != None:
+            self.desc = desc
+        else:
+            self.desc = common.port_desc()
+
+    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("!B", self.reason))
+        packed.append(struct.pack("!7B", *self.pad))
+        packed.append(self.desc.pack())
+        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")
+        obj = port_status()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_PORT_STATUS)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 64: raise loxi.ProtocolError("port_status length is %d, should be 64" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.reason = struct.unpack_from('!B', buf, 8)[0]
+        obj.pad = list(struct.unpack_from('!7B', buf, 9))
+        obj.desc = common.port_desc.unpack(buffer(buf, 16))
+        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.reason != other.reason: return False
+        if self.pad != other.pad: 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():
+            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("reason = ");
+                q.text("%#x" % self.reason)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("desc = ");
+                q.pp(self.desc)
+            q.breakable()
+        q.text('}')
+
+class queue_get_config_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_QUEUE_GET_CONFIG_REPLY
+
+    def __init__(self, xid=None, port=None, pad=None, queues=None):
+        self.xid = xid
+        if port != None:
+            self.port = port
+        else:
+            self.port = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0,0,0,0]
+        if queues != None:
+            self.queues = queues
+        else:
+            self.queues = []
+
+    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.port))
+        packed.append(struct.pack("!6B", *self.pad))
+        packed.append("".join([x.pack() for x in 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")
+        obj = queue_get_config_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_QUEUE_GET_CONFIG_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 16: raise loxi.ProtocolError("queue_get_config_reply length is %d, should be at least 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.port = struct.unpack_from('!H', buf, 8)[0]
+        obj.pad = list(struct.unpack_from('!6B', buf, 10))
+        obj.queues = common.unpack_list_packet_queue(buffer(buf, 16))
+        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.pad != other.pad: 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():
+            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("port = ");
+                q.text(util.pretty_port(self.port))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("queues = ");
+                q.pp(self.queues)
+            q.breakable()
+        q.text('}')
+
+class queue_get_config_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_QUEUE_GET_CONFIG_REQUEST
+
+    def __init__(self, xid=None, port=None, pad=None):
+        self.xid = xid
+        if port != None:
+            self.port = port
+        else:
+            self.port = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+
+    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.port))
+        packed.append(struct.pack("!2B", *self.pad))
+        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")
+        obj = queue_get_config_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_QUEUE_GET_CONFIG_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 12: raise loxi.ProtocolError("queue_get_config_request length is %d, should be 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.port = struct.unpack_from('!H', buf, 8)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 10))
+        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.pad != other.pad: return False
+        return True
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    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():
+            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("port = ");
+                q.text(util.pretty_port(self.port))
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+            q.breakable()
+        q.text('}')
+
+class queue_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_QUEUE
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+
+    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("".join([x.pack() for x in 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")
+        obj = queue_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 12: raise loxi.ProtocolError("queue_stats_reply length is %d, should be at least 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_QUEUE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.entries = util.unpack_array(common.queue_stats_entry.unpack, 32, buffer(buf, 12))
+        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("queue_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('}')
+
+class queue_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_QUEUE
+
+    def __init__(self, xid=None, flags=None, port_no=None, pad=None, queue_id=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if port_no != None:
+            self.port_no = port_no
+        else:
+            self.port_no = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0]
+        if queue_id != None:
+            self.queue_id = queue_id
+        else:
+            self.queue_id = 0
+
+    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(struct.pack("!H", self.port_no))
+        packed.append(struct.pack("!2B", *self.pad))
+        packed.append(struct.pack("!L", self.queue_id))
+        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")
+        obj = queue_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 20: raise loxi.ProtocolError("queue_stats_request length is %d, should be 20" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_QUEUE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.port_no = struct.unpack_from('!H', buf, 12)[0]
+        obj.pad = list(struct.unpack_from('!2B', buf, 14))
+        obj.queue_id = struct.unpack_from('!L', buf, 16)[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
+        if self.flags != other.flags: return False
+        if self.port_no != other.port_no: return False
+        if self.pad != other.pad: 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():
+            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.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("queue_id = ");
+                q.text("%#x" % self.queue_id)
+            q.breakable()
+        q.text('}')
+
+class set_config(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_SET_CONFIG
+
+    def __init__(self, xid=None, flags=None, miss_send_len=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if miss_send_len != None:
+            self.miss_send_len = miss_send_len
+        else:
+            self.miss_send_len = 0
+
+    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.flags))
+        packed.append(struct.pack("!H", self.miss_send_len))
+        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")
+        obj = set_config()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_SET_CONFIG)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 12: raise loxi.ProtocolError("set_config length is %d, should be 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.flags = struct.unpack_from('!H', buf, 8)[0]
+        obj.miss_send_len = struct.unpack_from('!H', buf, 10)[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
+        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():
+            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("miss_send_len = ");
+                q.text("%#x" % self.miss_send_len)
+            q.breakable()
+        q.text('}')
+
+class table_mod(Message):
+    version = const.OFP_VERSION
+    type = 22
+
+    def __init__(self, xid=None, table_id=None, pad=None, config=None):
+        self.xid = xid
+        if table_id != None:
+            self.table_id = table_id
+        else:
+            self.table_id = 0
+        if pad != None:
+            self.pad = pad
+        else:
+            self.pad = [0,0,0]
+        if config != None:
+            self.config = config
+        else:
+            self.config = 0
+
+    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("!B", self.table_id))
+        packed.append(struct.pack("!3B", *self.pad))
+        packed.append(struct.pack("!L", self.config))
+        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")
+        obj = table_mod()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == 22)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 16: raise loxi.ProtocolError("table_mod length is %d, should be 16" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        obj.table_id = struct.unpack_from('!B', buf, 8)[0]
+        obj.pad = list(struct.unpack_from('!3B', buf, 9))
+        obj.config = struct.unpack_from('!L', buf, 12)[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
+        if self.table_id != other.table_id: return False
+        if self.pad != other.pad: 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():
+            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("table_id = ");
+                q.text("%#x" % self.table_id)
+                q.text(","); q.breakable()
+                q.text("pad = ");
+                q.pp(self.pad)
+                q.text(","); q.breakable()
+                q.text("config = ");
+                q.text("%#x" % self.config)
+            q.breakable()
+        q.text('}')
+
+class table_stats_reply(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REPLY
+    stats_type = const.OFPST_TABLE
+
+    def __init__(self, xid=None, flags=None, entries=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+        if entries != None:
+            self.entries = entries
+        else:
+            self.entries = []
+
+    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("".join([x.pack() for x in 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")
+        obj = table_stats_reply()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REPLY)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length < 12: raise loxi.ProtocolError("table_stats_reply length is %d, should be at least 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_TABLE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[0]
+        obj.entries = util.unpack_array(common.table_stats_entry.unpack, 64, buffer(buf, 12))
+        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_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('}')
+
+class table_stats_request(Message):
+    version = const.OFP_VERSION
+    type = const.OFPT_STATS_REQUEST
+    stats_type = const.OFPST_TABLE
+
+    def __init__(self, xid=None, flags=None):
+        self.xid = xid
+        if flags != None:
+            self.flags = flags
+        else:
+            self.flags = 0
+
+    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))
+        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")
+        obj = table_stats_request()
+        version = struct.unpack_from('!B', buf, 0)[0]
+        assert(version == const.OFP_VERSION)
+        type = struct.unpack_from('!B', buf, 1)[0]
+        assert(type == const.OFPT_STATS_REQUEST)
+        _length = struct.unpack_from('!H', buf, 2)[0]
+        assert(_length == len(buf))
+        if _length != 12: raise loxi.ProtocolError("table_stats_request length is %d, should be 12" % _length)
+        obj.xid = struct.unpack_from('!L', buf, 4)[0]
+        stats_type = struct.unpack_from('!H', buf, 8)[0]
+        assert(stats_type == const.OFPST_TABLE)
+        obj.flags = struct.unpack_from('!H', buf, 10)[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
+        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():
+            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('}')
+
+
+def parse_header(buf):
+    if len(buf) < 8:
+        raise loxi.ProtocolError("too short to be an OpenFlow message")
+    return struct.unpack_from("!BBHL", buf)
+
+def parse_message(buf):
+    msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
+    if msg_ver != const.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
+        raise loxi.ProtocolError("wrong OpenFlow version")
+    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_flow_mod(buf):
+    if len(buf) < 56 + 2:
+        raise loxi.ProtocolError("message too short")
+    cmd, = struct.unpack_from("!H", buf, 56)
+    if cmd in flow_mod_parsers:
+        return flow_mod_parsers[cmd](buf)
+    else:
+        raise loxi.ProtocolError("unexpected flow 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_vendor(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 = {
+    22 : table_mod.unpack,
+    const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
+    const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
+    const.OFPT_ECHO_REPLY : echo_reply.unpack,
+    const.OFPT_ECHO_REQUEST : echo_request.unpack,
+    const.OFPT_ERROR : error_msg.unpack,
+    const.OFPT_FEATURES_REPLY : features_reply.unpack,
+    const.OFPT_FEATURES_REQUEST : features_request.unpack,
+    const.OFPT_FLOW_MOD : parse_flow_mod,
+    const.OFPT_FLOW_REMOVED : flow_removed.unpack,
+    const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
+    const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
+    const.OFPT_HELLO : hello.unpack,
+    const.OFPT_PACKET_IN : packet_in.unpack,
+    const.OFPT_PACKET_OUT : packet_out.unpack,
+    const.OFPT_PORT_MOD : port_mod.unpack,
+    const.OFPT_PORT_STATUS : port_status.unpack,
+    const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
+    const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
+    const.OFPT_SET_CONFIG : set_config.unpack,
+    const.OFPT_STATS_REPLY : parse_stats_reply,
+    const.OFPT_STATS_REQUEST : parse_stats_request,
+    const.OFPT_VENDOR : parse_vendor,
+}
+
+flow_mod_parsers = {
+    const.OFPFC_ADD : flow_add.unpack,
+    const.OFPFC_MODIFY : flow_modify.unpack,
+    const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
+    const.OFPFC_DELETE : flow_delete.unpack,
+    const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
+}
+
+stats_reply_parsers = {
+    const.OFPST_DESC : desc_stats_reply.unpack,
+    const.OFPST_FLOW : flow_stats_reply.unpack,
+    const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
+    const.OFPST_TABLE : table_stats_reply.unpack,
+    const.OFPST_PORT : port_stats_reply.unpack,
+    const.OFPST_QUEUE : queue_stats_reply.unpack,
+    const.OFPST_VENDOR : experimenter_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_VENDOR : experimenter_stats_request.unpack,
+}
+
+experimenter_parsers = {
+    0x2320 : {
+        11: nicira_controller_role_reply.unpack,
+        10: nicira_controller_role_request.unpack,
+    },
+    0x5c16c7 : {
+        10: bsn_get_interfaces_reply.unpack,
+        9: bsn_get_interfaces_request.unpack,
+        2: bsn_get_ip_mask_reply.unpack,
+        1: bsn_get_ip_mask_request.unpack,
+        5: bsn_get_mirroring_reply.unpack,
+        4: bsn_get_mirroring_request.unpack,
+        0: bsn_set_ip_mask.unpack,
+        3: bsn_set_mirroring.unpack,
+        6: bsn_shell_command.unpack,
+        7: bsn_shell_output.unpack,
+        8: bsn_shell_status.unpack,
+    },
+}
diff --git a/src/python/loxi/of10/util.py b/src/python/loxi/of10/util.py
new file mode 100644
index 0000000..713d5cb
--- /dev/null
+++ b/src/python/loxi/of10/util.py
@@ -0,0 +1,64 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template util.py
+# Do not modify
+
+import loxi
+import const
+
+def unpack_array(deserializer, element_size, buf):
+    """
+    Deserialize an array of fixed length elements.
+    The deserializer function should take a buffer and return the new object.
+    """
+    if len(buf) % element_size != 0: raise loxi.ProtocolError("invalid array length")
+    n = len(buf) / element_size
+    return [deserializer(buffer(buf, i*element_size, element_size)) for i in range(n)]
+
+def pretty_mac(mac):
+    return ':'.join(["%02x" % x for x in mac])
+
+def pretty_ipv4(v):
+    return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
+
+def pretty_flags(v, flag_names):
+    set_flags = []
+    for flag_name in flag_names:
+        flag_value = getattr(const, flag_name)
+        if v & flag_value == flag_value:
+            set_flags.append(flag_name)
+        elif v & flag_value:
+            set_flags.append('%s&%#x' % (flag_name, v & flag_value))
+        v &= ~flag_value
+    if v:
+        set_flags.append("%#x" % v)
+    return '|'.join(set_flags) or '0'
+
+def pretty_wildcards(v):
+    if v == const.OFPFW_ALL:
+        return 'OFPFW_ALL'
+    flag_names = ['OFPFW_IN_PORT', 'OFPFW_DL_VLAN', 'OFPFW_DL_SRC', 'OFPFW_DL_DST',
+                  'OFPFW_DL_TYPE', 'OFPFW_NW_PROTO', 'OFPFW_TP_SRC', 'OFPFW_TP_DST',
+                  'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP',
+                  'OFPFW_NW_TOS']
+    return pretty_flags(v, flag_names)
+
+def pretty_port(v):
+    named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
+    for (k, v2) in named_ports:
+        if v == v2:
+            return k
+    return v
diff --git a/src/python/loxi/pp.py b/src/python/loxi/pp.py
new file mode 100644
index 0000000..852215d
--- /dev/null
+++ b/src/python/loxi/pp.py
@@ -0,0 +1,248 @@
+"""
+pp - port of Ruby's PP library
+Also based on Lindig, C., & GbR, G. D. (2000). Strictly Pretty.
+
+Example usage:
+>>> import pp.pp as pp
+>>> print pp([[1, 2], [3, 4]], maxwidth=15)
+[
+  [ 1, 2 ],
+  [ 3, 4 ]
+]
+"""
+import unittest
+from contextlib import contextmanager
+
+def pp(obj, maxwidth=79):
+    """
+    Pretty-print the given object.
+    """
+    ctx = PrettyPrinter(maxwidth=maxwidth)
+    ctx.pp(obj)
+    return str(ctx)
+
+
+## Pretty-printers for builtin classes
+
+def pretty_print_list(pp, obj):
+    with pp.group():
+        pp.text('[')
+        with pp.indent(2):
+            for v in obj:
+                if not pp.first(): pp.text(',')
+                pp.breakable()
+                pp.pp(v)
+        pp.breakable()
+        pp.text(']')
+
+def pretty_print_dict(pp, obj):
+    with pp.group():
+        pp.text('{')
+        with pp.indent(2):
+            for (k, v) in sorted(obj.items()):
+                if not pp.first(): pp.text(',')
+                pp.breakable()
+                pp.pp(k)
+                pp.text(': ')
+                pp.pp(v)
+        pp.breakable()
+        pp.text('}')
+
+pretty_printers = {
+    list: pretty_print_list,
+    dict: pretty_print_dict,
+}
+
+
+## Implementation
+
+class PrettyPrinter(object):
+    def __init__(self, maxwidth):
+        self.maxwidth = maxwidth
+        self.cur_indent = 0
+        self.root_group = Group()
+        self.group_stack = [self.root_group]
+
+    def current_group(self):
+        return self.group_stack[-1]
+
+    def text(self, s):
+        self.current_group().append(str(s))
+
+    def breakable(self, sep=' '):
+        self.current_group().append(Breakable(sep, self.cur_indent))
+
+    def first(self):
+        return self.current_group().first()
+
+    @contextmanager
+    def indent(self, n):
+        self.cur_indent += n
+        yield
+        self.cur_indent -= n
+
+    @contextmanager
+    def group(self):
+        self.group_stack.append(Group())
+        yield
+        new_group = self.group_stack.pop()
+        self.current_group().append(new_group)
+
+    def pp(self, obj):
+        if hasattr(obj, "pretty_print"):
+            obj.pretty_print(self)
+        elif type(obj) in pretty_printers:
+            pretty_printers[type(obj)](self, obj)
+        else:
+            self.text(repr(obj))
+
+    def __str__(self):
+        return self.root_group.render(0, self.maxwidth)
+
+class Group(object):
+    __slots__ = ["fragments", "length", "_first"]
+
+    def __init__(self):
+        self.fragments = []
+        self.length = 0
+        self._first = True
+
+    def append(self, x):
+        self.fragments.append(x)
+        self.length += len(x)
+
+    def first(self):
+        if self._first:
+            self._first = False
+            return True
+        return False
+
+    def __len__(self):
+        return self.length
+
+    def render(self, curwidth, maxwidth):
+        dobreak = len(self) > (maxwidth - curwidth)
+
+        a = []
+        for x in self.fragments:
+            if isinstance(x, Breakable):
+                if dobreak:
+                    a.append('\n')
+                    a.append(' ' * x.indent)
+                    curwidth = 0
+                else:
+                    a.append(x.sep)
+            elif isinstance(x, Group):
+                a.append(x.render(curwidth, maxwidth))
+            else:
+                a.append(x)
+            curwidth += len(a[-1])
+        return ''.join(a)
+
+class Breakable(object):
+    __slots__ = ["sep", "indent"]
+
+    def __init__(self, sep, indent):
+        self.sep = sep
+        self.indent = indent
+
+    def __len__(self):
+        return len(self.sep)
+
+
+## Tests
+
+class TestPP(unittest.TestCase):
+    def test_scalars(self):
+        self.assertEquals(pp(1), "1")
+        self.assertEquals(pp("foo"), "'foo'")
+
+    def test_hash(self):
+        expected = """{ 1: 'a', 'b': 2 }"""
+        self.assertEquals(pp(eval(expected)), expected)
+        expected = """\
+{
+  1: 'a',
+  'b': 2
+}"""
+        self.assertEquals(pp(eval(expected), maxwidth=0), expected)
+
+    def test_array(self):
+        expected = """[ 1, 'a', 2 ]"""
+        self.assertEquals(pp(eval(expected)), expected)
+        expected = """\
+[
+  1,
+  'a',
+  2
+]"""
+        self.assertEquals(pp(eval(expected), maxwidth=0), expected)
+
+    def test_nested(self):
+        expected = """[ [ 1, 2 ], [ 3, 4 ] ]"""
+        self.assertEquals(pp(eval(expected)), expected)
+        expected = """\
+[
+  [
+    1,
+    2
+  ],
+  [
+    3,
+    4
+  ]
+]"""
+        self.assertEquals(pp(eval(expected), maxwidth=0), expected)
+
+    def test_breaking(self):
+        expected = """\
+[
+  [ 1, 2 ],
+  'abcdefghijklmnopqrstuvwxyz'
+]"""
+        self.assertEquals(pp(eval(expected), maxwidth=24), expected)
+        expected = """\
+[
+  [ 'abcd', 2 ],
+  [ '0123456789' ],
+  [
+    '0123456789',
+    'abcdefghij'
+  ],
+  [ 'abcdefghijklmnop' ],
+  [
+    'abcdefghijklmnopq'
+  ],
+  { 'k': 'v' },
+  {
+    1: [ 2, [ 3, 4 ] ],
+    'foo': 'abcdefghijklmnop'
+  }
+]"""
+        self.assertEquals(pp(eval(expected), maxwidth=24), expected)
+        expected = """\
+[
+  [ 1, 2 ],
+  [ 3, 4 ]
+]"""
+        self.assertEquals(pp(eval(expected), maxwidth=15), expected)
+
+    # This is an edge case where our simpler algorithm breaks down.
+    @unittest.expectedFailure
+    def test_greedy_breaking(self):
+        expected = """\
+abc def
+ghijklmnopqrstuvwxyz\
+"""
+        pp = PrettyPrinter(maxwidth=8)
+        pp.text("abc")
+        with pp.group():
+            pp.breakable()
+        pp.text("def")
+        with pp.group():
+            pp.breakable()
+        pp.text("ghijklmnopqrstuvwxyz")
+        self.assertEquals(str(pp), expected)
+
+if __name__ == '__main__':
+    unittest.main()
