blob: 94c957258e74af0b6da44f9b4d4cd96203f9b89c [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Talayco6cc1fda2012-09-18 06:39:24 -070017"""
18Support an illegal message
19"""
20
Rich Lane768ef952013-03-11 22:31:28 -070021import struct
Rich Lanee717c6e2013-03-12 10:25:50 -070022import ofp
Dan Talayco6cc1fda2012-09-18 06:39:24 -070023
Rich Lane768ef952013-03-11 22:31:28 -070024class illegal_message_type(object):
Rich Lanee717c6e2013-03-12 10:25:50 -070025 version = ofp.OFP_VERSION
Rich Lane768ef952013-03-11 22:31:28 -070026 type = 217
Dan Talayco6cc1fda2012-09-18 06:39:24 -070027
Rich Lane768ef952013-03-11 22:31:28 -070028 def __init__(self, xid=None):
29 self.xid = xid
Dan Talayco6cc1fda2012-09-18 06:39:24 -070030
31 def pack(self):
Rich Lane768ef952013-03-11 22:31:28 -070032 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 Talayco6cc1fda2012-09-18 06:39:24 -070040
Rich Lane768ef952013-03-11 22:31:28 -070041 @staticmethod
42 def unpack(buf):
43 raise NotImplementedError()
Dan Talayco6cc1fda2012-09-18 06:39:24 -070044
45 def __eq__(self, other):
Dan Talayco6cc1fda2012-09-18 06:39:24 -070046 if type(self) != type(other): return False
Rich Lane768ef952013-03-11 22:31:28 -070047 if self.version != other.version: return False
48 if self.type != other.type: return False
49 if self.xid != other.xid: return False
Dan Talayco6cc1fda2012-09-18 06:39:24 -070050 return True
51
52 def __ne__(self, other):
Dan Talayco6cc1fda2012-09-18 06:39:24 -070053 return not self.__eq__(other)
Rich Lane768ef952013-03-11 22:31:28 -070054
55 def __str__(self):
56 return self.show()
57
58 def show(self):
59 return "illegal_message_type"