Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 1 | """ |
| 2 | Support an illegal message |
| 3 | """ |
| 4 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 5 | import struct |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 6 | import ofp |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 7 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 8 | class illegal_message_type(object): |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 9 | version = ofp.OFP_VERSION |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 10 | type = 217 |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 11 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 12 | def __init__(self, xid=None): |
| 13 | self.xid = xid |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 14 | |
| 15 | def pack(self): |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 16 | 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 Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 24 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 25 | @staticmethod |
| 26 | def unpack(buf): |
| 27 | raise NotImplementedError() |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 28 | |
| 29 | def __eq__(self, other): |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 30 | if type(self) != type(other): return False |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 31 | if self.version != other.version: return False |
| 32 | if self.type != other.type: return False |
| 33 | if self.xid != other.xid: return False |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 34 | return True |
| 35 | |
| 36 | def __ne__(self, other): |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 37 | return not self.__eq__(other) |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 38 | |
| 39 | def __str__(self): |
| 40 | return self.show() |
| 41 | |
| 42 | def show(self): |
| 43 | return "illegal_message_type" |