Sreeju Sreedhar | e3fefd9 | 2019-04-02 15:57:15 -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 | |
| 17 | """ |
| 18 | Support an illegal message |
| 19 | """ |
| 20 | |
| 21 | import struct |
| 22 | import ofp |
| 23 | |
| 24 | class illegal_message_type(object): |
| 25 | version = ofp.OFP_VERSION |
| 26 | type = 217 |
| 27 | |
| 28 | def __init__(self, xid=None): |
| 29 | self.xid = xid |
| 30 | |
| 31 | def pack(self): |
| 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) |
| 40 | |
| 41 | @staticmethod |
| 42 | def unpack(buf): |
| 43 | raise NotImplementedError() |
| 44 | |
| 45 | def __eq__(self, other): |
| 46 | if type(self) != type(other): return False |
| 47 | if self.version != other.version: return False |
| 48 | if self.type != other.type: return False |
| 49 | if self.xid != other.xid: return False |
| 50 | return True |
| 51 | |
| 52 | def __ne__(self, other): |
| 53 | return not self.__eq__(other) |
| 54 | |
| 55 | def __str__(self): |
| 56 | return self.show() |
| 57 | |
| 58 | def show(self): |
| 59 | return "illegal_message_type" |