loxi_prep: remove illegal_message_type dependency on pylibopenflow internals
diff --git a/src/python/oftest/illegal_message.py b/src/python/oftest/illegal_message.py
index fa404cf..f225b90 100644
--- a/src/python/oftest/illegal_message.py
+++ b/src/python/oftest/illegal_message.py
@@ -2,126 +2,42 @@
Support an illegal message
"""
+import struct
import of10
-ILLEGAL_MESSAGE_TYPE=217
+class illegal_message_type(object):
+ version = of10.OFP_VERSION
+ type = 217
-class illegal_message_type(of10.ofp_header):
- """
- Wrapper class for illegal_message_type
-
- OpenFlow message header: length, version, xid, type
- @arg length: The total length of the message
- @arg version: The OpenFlow version (1)
- @arg xid: The transaction ID
- @arg type: The message type (ILLEGAL_MESSAGE_TYPE=217)
-
- Data members inherited from ofp_header:
- @arg version
- @arg type
- @arg length
- @arg xid
- @arg data: Binary string following message members
-
- """
-
- def __init__(self, **kwargs):
- of10.ofp_header.__init__(self)
- self.version = of10.OFP_VERSION
- self.type = ILLEGAL_MESSAGE_TYPE
- self.xid = None
- self.data = ""
- for (k, v) in kwargs.items():
- if hasattr(self, k):
- setattr(self, k, v)
- else:
- raise NameError("field %s does not exist in %s" % (k, self.__class__))
-
+ def __init__(self, xid=None):
+ self.xid = xid
def pack(self):
- """
- Pack object into string
+ 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)
- @return The packed string which can go on the wire
-
- """
- self.length = len(self)
- packed = ""
-
- packed += of10.ofp_header.pack(self, assertstruct=False)
- packed += self.data
- return packed
-
- def unpack(self, binary_string):
- """
- Unpack object from a binary string
-
- @param binary_string The wire protocol byte string holding the object
- represented as an array of bytes.
- @return The remainder of binary_string that was not parsed.
-
- """
-
- binary_string = of10.ofp_header.unpack(self, binary_string)
- self.data = binary_string
- binary_string = ''
- return binary_string
-
- def __len__(self):
- """
- Return the length of this object once packed into a string
-
- @return An integer representing the number bytes in the packed
- string.
-
- """
- length = 0
-
- length += of10.ofp_header.__len__(self)
- length += len(self.data)
- return length
-
- def show(self, prefix=''):
- """
- Generate a string (with multiple lines) describing the contents
- of the object in a readable manner
-
- @param prefix Pre-pended at the beginning of each line.
-
- """
-
- outstr = prefix + 'illegal_message (217)\n'
- prefix += ' '
- outstr += prefix + 'ofp header\n'
- outstr += of10.ofp_header.show(self, prefix)
- outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
- ##@todo Fix this circular reference
- # if len(self.data) > 0:
- # obj = of_message_parse(self.data)
- # if obj != None:
- # outstr += obj.show(prefix)
- # else:
- # outstr += prefix + "Unable to parse data\n"
- return outstr
+ @staticmethod
+ def unpack(buf):
+ raise NotImplementedError()
def __eq__(self, other):
- """
- Return True if self and other hold the same data
-
- @param other Other object in comparison
-
- """
if type(self) != type(other): return False
-
- if not of10.ofp_header.__eq__(self, other): return False
- if self.data != other.data: 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 True if self and other do not hold the same data
-
- @param other Other object in comparison
-
- """
return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ return "illegal_message_type"