update pyloxi to 026ff024585f1588a7f11fa4c1a9a48d44dc098d
diff --git a/src/python/loxi/of11/instruction.py b/src/python/loxi/of11/instruction.py
index 38bcdb6..e93e070 100644
--- a/src/python/loxi/of11/instruction.py
+++ b/src/python/loxi/of11/instruction.py
@@ -3,28 +3,32 @@
# 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 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 +43,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 +65,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 +75,9 @@
q.breakable()
q.text('}')
-class clear_actions(Instruction):
+instruction.subtypes[4] = apply_actions
+
+class clear_actions(instruction):
type = 5
def __init__(self):
@@ -96,15 +93,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
@@ -112,13 +107,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():
@@ -127,7 +115,23 @@
q.breakable()
q.text('}')
-class goto_table(Instruction):
+instruction.subtypes[5] = clear_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 goto_table(instruction):
type = 1
def __init__(self, table_id=None):
@@ -148,15 +152,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
@@ -166,13 +168,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():
@@ -183,7 +178,9 @@
q.breakable()
q.text('}')
-class write_actions(Instruction):
+instruction.subtypes[1] = goto_table
+
+class write_actions(instruction):
type = 3
def __init__(self, actions=None):
@@ -198,23 +195,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):
@@ -222,13 +217,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():
@@ -239,7 +227,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):
@@ -265,15 +255,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]
@@ -285,13 +273,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():
@@ -305,26 +286,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,
-}
-
-experimenter_parsers = {
-}