Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 17 | """ |
| 18 | Support an illegal message |
| 19 | """ |
| 20 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 21 | import struct |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 22 | import ofp |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 23 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 24 | class illegal_message_type(object): |
Rich Lane | e717c6e | 2013-03-12 10:25:50 -0700 | [diff] [blame] | 25 | version = ofp.OFP_VERSION |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 26 | type = 217 |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 27 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 28 | def __init__(self, xid=None): |
| 29 | self.xid = xid |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 30 | |
| 31 | def pack(self): |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 32 | packed = [] |
| 33 | packed.append(struct.pack("!B", self.version)) |
| 34 | packed.append(struct.pack("!B", self.type)) |
| 35 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 2 |
| 36 | packed.append(struct.pack("!L", self.xid)) |
| 37 | length = sum([len(x) for x in packed]) |
| 38 | packed[2] = struct.pack("!H", length) |
| 39 | return ''.join(packed) |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 40 | |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 41 | @staticmethod |
| 42 | def unpack(buf): |
| 43 | raise NotImplementedError() |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 44 | |
| 45 | def __eq__(self, other): |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 46 | if type(self) != type(other): return False |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 47 | if self.version != other.version: return False |
| 48 | if self.type != other.type: return False |
| 49 | if self.xid != other.xid: return False |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 50 | return True |
| 51 | |
| 52 | def __ne__(self, other): |
Dan Talayco | 6cc1fda | 2012-09-18 06:39:24 -0700 | [diff] [blame] | 53 | return not self.__eq__(other) |
Rich Lane | 768ef95 | 2013-03-11 22:31:28 -0700 | [diff] [blame] | 54 | |
| 55 | def __str__(self): |
| 56 | return self.show() |
| 57 | |
| 58 | def show(self): |
| 59 | return "illegal_message_type" |