update pyloxi to 026ff024585f1588a7f11fa4c1a9a48d44dc098d
diff --git a/src/python/loxi/of13/instruction.py b/src/python/loxi/of13/instruction.py
index b5d3fc8..e36cc73 100644
--- a/src/python/loxi/of13/instruction.py
+++ b/src/python/loxi/of13/instruction.py
@@ -3,28 +3,36 @@
 # Copyright (c) 2012, 2013 Big Switch Networks, Inc.
 # See the file LICENSE.pyloxi which should have been included in the source distribution
 
-# Automatically generated by LOXI from template instruction.py
+# Automatically generated by LOXI from template module.py
 # Do not modify
 
 import struct
-import action
+import loxi
 import const
+import common
+import action
+import instruction
+import oxm
+import action_id
+import instruction_id
+import meter_band
 import util
 import loxi.generic_util
-import loxi
 
-def unpack_list(reader):
-    def deserializer(reader, typ):
-        parser = parsers.get(typ)
-        if not parser: raise loxi.ProtocolError("unknown instruction type %d" % typ)
-        return parser(reader)
-    return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+class instruction(loxi.OFObject):
+    subtypes = {}
 
-class Instruction(object):
-    type = None # override in subclass
-    pass
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!H', 0)
+        try:
+            subclass = instruction.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype)
+        return subclass.unpack(reader)
 
-class apply_actions(Instruction):
+
+class apply_actions(instruction):
     type = 4
 
     def __init__(self, actions=None):
@@ -39,23 +47,21 @@
         packed.append(struct.pack("!H", self.type))
         packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
         packed.append('\x00' * 4)
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[1] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = apply_actions()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 4)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
@@ -63,13 +69,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("apply_actions {")
         with q.group():
@@ -80,7 +79,37 @@
             q.breakable()
         q.text('}')
 
-class bsn_disable_src_mac_check(Instruction):
+instruction.subtypes[4] = apply_actions
+
+class experimenter(instruction):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 4)
+        try:
+            subclass = experimenter.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+instruction.subtypes[65535] = experimenter
+
+class bsn(experimenter):
+    subtypes = {}
+
+    @staticmethod
+    def unpack(reader):
+        subtype, = reader.peek('!L', 8)
+        try:
+            subclass = bsn.subtypes[subtype]
+        except KeyError:
+            raise loxi.ProtocolError("unknown bsn experimenter instruction subtype %#x" % subtype)
+        return subclass.unpack(reader)
+
+experimenter.subtypes[6035143] = bsn
+
+class bsn_disable_src_mac_check(bsn):
     type = 65535
     experimenter = 6035143
     subtype = 0
@@ -100,15 +129,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = bsn_disable_src_mac_check()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 65535)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         _experimenter = reader.read("!L")[0]
         assert(_experimenter == 6035143)
         _subtype = reader.read("!L")[0]
@@ -120,13 +147,6 @@
         if type(self) != type(other): return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("bsn_disable_src_mac_check {")
         with q.group():
@@ -135,7 +155,9 @@
             q.breakable()
         q.text('}')
 
-class clear_actions(Instruction):
+bsn.subtypes[0] = bsn_disable_src_mac_check
+
+class clear_actions(instruction):
     type = 5
 
     def __init__(self):
@@ -151,15 +173,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = clear_actions()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 5)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
         return obj
 
@@ -167,13 +187,6 @@
         if type(self) != type(other): return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("clear_actions {")
         with q.group():
@@ -182,7 +195,9 @@
             q.breakable()
         q.text('}')
 
-class goto_table(Instruction):
+instruction.subtypes[5] = clear_actions
+
+class goto_table(instruction):
     type = 1
 
     def __init__(self, table_id=None):
@@ -203,15 +218,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = goto_table()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 1)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.table_id = reader.read("!B")[0]
         reader.skip(3)
         return obj
@@ -221,13 +234,6 @@
         if self.table_id != other.table_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("goto_table {")
         with q.group():
@@ -238,7 +244,9 @@
             q.breakable()
         q.text('}')
 
-class meter(Instruction):
+instruction.subtypes[1] = goto_table
+
+class meter(instruction):
     type = 6
 
     def __init__(self, meter_id=None):
@@ -258,15 +266,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = meter()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 6)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         obj.meter_id = reader.read("!L")[0]
         return obj
 
@@ -275,13 +281,6 @@
         if self.meter_id != other.meter_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("meter {")
         with q.group():
@@ -292,7 +291,9 @@
             q.breakable()
         q.text('}')
 
-class write_actions(Instruction):
+instruction.subtypes[6] = meter
+
+class write_actions(instruction):
     type = 3
 
     def __init__(self, actions=None):
@@ -307,23 +308,21 @@
         packed.append(struct.pack("!H", self.type))
         packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
         packed.append('\x00' * 4)
-        packed.append(util.pack_list(self.actions))
+        packed.append(loxi.generic_util.pack_list(self.actions))
         length = sum([len(x) for x in packed])
         packed[1] = struct.pack("!H", length)
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = write_actions()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 3)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
-        obj.actions = action.unpack_list(reader)
+        obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
         return obj
 
     def __eq__(self, other):
@@ -331,13 +330,6 @@
         if self.actions != other.actions: return False
         return True
 
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
-
     def pretty_print(self, q):
         q.text("write_actions {")
         with q.group():
@@ -348,7 +340,9 @@
             q.breakable()
         q.text('}')
 
-class write_metadata(Instruction):
+instruction.subtypes[3] = write_actions
+
+class write_metadata(instruction):
     type = 2
 
     def __init__(self, metadata=None, metadata_mask=None):
@@ -374,15 +368,13 @@
         return ''.join(packed)
 
     @staticmethod
-    def unpack(buf):
+    def unpack(reader):
         obj = write_metadata()
-        if type(buf) == loxi.generic_util.OFReader:
-            reader = buf
-        else:
-            reader = loxi.generic_util.OFReader(buf)
         _type = reader.read("!H")[0]
         assert(_type == 2)
         _len = reader.read("!H")[0]
+        orig_reader = reader
+        reader = orig_reader.slice(_len - (2 + 2))
         reader.skip(4)
         obj.metadata = reader.read("!Q")[0]
         obj.metadata_mask = reader.read("!Q")[0]
@@ -394,13 +386,6 @@
         if self.metadata_mask != other.metadata_mask: 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("write_metadata {")
         with q.group():
@@ -414,31 +399,6 @@
             q.breakable()
         q.text('}')
 
+instruction.subtypes[2] = write_metadata
 
-def parse_experimenter(reader):
-    experimenter, = reader.peek("!4xL")
-    if experimenter == 0x005c16c7: # Big Switch Networks
-        subtype, = reader.peek("!8xL")
-    else:
-        raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
 
-    if subtype in experimenter_parsers[experimenter]:
-        return experimenter_parsers[experimenter][subtype](reader)
-    else:
-        raise loxi.ProtocolError("unexpected experimenter id %#x subtype %#x" % (experimenter, subtype))
-
-parsers = {
-    const.OFPIT_GOTO_TABLE : goto_table.unpack,
-    const.OFPIT_WRITE_METADATA : write_metadata.unpack,
-    const.OFPIT_WRITE_ACTIONS : write_actions.unpack,
-    const.OFPIT_APPLY_ACTIONS : apply_actions.unpack,
-    const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack,
-    const.OFPIT_METER : meter.unpack,
-    const.OFPIT_EXPERIMENTER : parse_experimenter,
-}
-
-experimenter_parsers = {
-    6035143 : {
-        0: bsn_disable_src_mac_check.unpack,
-    },
-}