blob: 8e52e33f24868c77cc178547f952d76a952d4174 [file] [log] [blame]
Dan Talayco6cc1fda2012-09-18 06:39:24 -07001"""
2Support an illegal message
3"""
4
Rich Lane768ef952013-03-11 22:31:28 -07005import struct
Rich Lanee717c6e2013-03-12 10:25:50 -07006import ofp
Dan Talayco6cc1fda2012-09-18 06:39:24 -07007
Rich Lane768ef952013-03-11 22:31:28 -07008class illegal_message_type(object):
Rich Lanee717c6e2013-03-12 10:25:50 -07009 version = ofp.OFP_VERSION
Rich Lane768ef952013-03-11 22:31:28 -070010 type = 217
Dan Talayco6cc1fda2012-09-18 06:39:24 -070011
Rich Lane768ef952013-03-11 22:31:28 -070012 def __init__(self, xid=None):
13 self.xid = xid
Dan Talayco6cc1fda2012-09-18 06:39:24 -070014
15 def pack(self):
Rich Lane768ef952013-03-11 22:31:28 -070016 packed = []
17 packed.append(struct.pack("!B", self.version))
18 packed.append(struct.pack("!B", self.type))
19 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
20 packed.append(struct.pack("!L", self.xid))
21 length = sum([len(x) for x in packed])
22 packed[2] = struct.pack("!H", length)
23 return ''.join(packed)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070024
Rich Lane768ef952013-03-11 22:31:28 -070025 @staticmethod
26 def unpack(buf):
27 raise NotImplementedError()
Dan Talayco6cc1fda2012-09-18 06:39:24 -070028
29 def __eq__(self, other):
Dan Talayco6cc1fda2012-09-18 06:39:24 -070030 if type(self) != type(other): return False
Rich Lane768ef952013-03-11 22:31:28 -070031 if self.version != other.version: return False
32 if self.type != other.type: return False
33 if self.xid != other.xid: return False
Dan Talayco6cc1fda2012-09-18 06:39:24 -070034 return True
35
36 def __ne__(self, other):
Dan Talayco6cc1fda2012-09-18 06:39:24 -070037 return not self.__eq__(other)
Rich Lane768ef952013-03-11 22:31:28 -070038
39 def __str__(self):
40 return self.show()
41
42 def show(self):
43 return "illegal_message_type"