blob: fa404cf70080340c6cea7ab9bd1c3fc4f3d6d4ac [file] [log] [blame]
Dan Talayco6cc1fda2012-09-18 06:39:24 -07001"""
2Support an illegal message
3"""
4
Rich Laned7b0ffa2013-03-08 15:53:42 -08005import of10
Dan Talayco6cc1fda2012-09-18 06:39:24 -07006
7ILLEGAL_MESSAGE_TYPE=217
8
Rich Laneb73808c2013-03-11 15:22:23 -07009class illegal_message_type(of10.ofp_header):
Dan Talayco6cc1fda2012-09-18 06:39:24 -070010 """
Rich Laneb73808c2013-03-11 15:22:23 -070011 Wrapper class for illegal_message_type
Dan Talayco6cc1fda2012-09-18 06:39:24 -070012
13 OpenFlow message header: length, version, xid, type
14 @arg length: The total length of the message
15 @arg version: The OpenFlow version (1)
16 @arg xid: The transaction ID
Rich Laneb73808c2013-03-11 15:22:23 -070017 @arg type: The message type (ILLEGAL_MESSAGE_TYPE=217)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070018
Rich Laneb73808c2013-03-11 15:22:23 -070019 Data members inherited from ofp_header:
20 @arg version
21 @arg type
22 @arg length
23 @arg xid
Dan Talayco6cc1fda2012-09-18 06:39:24 -070024 @arg data: Binary string following message members
25
Dan Talayco6cc1fda2012-09-18 06:39:24 -070026 """
27
Rich Laneb73808c2013-03-11 15:22:23 -070028 def __init__(self, **kwargs):
29 of10.ofp_header.__init__(self)
30 self.version = of10.OFP_VERSION
31 self.type = ILLEGAL_MESSAGE_TYPE
Rich Lane8fbfd662013-03-11 15:30:44 -070032 self.xid = None
Dan Talayco6cc1fda2012-09-18 06:39:24 -070033 self.data = ""
Rich Laneb73808c2013-03-11 15:22:23 -070034 for (k, v) in kwargs.items():
35 if hasattr(self, k):
36 setattr(self, k, v)
37 else:
38 raise NameError("field %s does not exist in %s" % (k, self.__class__))
39
Dan Talayco6cc1fda2012-09-18 06:39:24 -070040
41 def pack(self):
42 """
43 Pack object into string
44
45 @return The packed string which can go on the wire
46
47 """
Rich Laneb73808c2013-03-11 15:22:23 -070048 self.length = len(self)
49 packed = ""
Dan Talayco6cc1fda2012-09-18 06:39:24 -070050
Rich Laneb73808c2013-03-11 15:22:23 -070051 packed += of10.ofp_header.pack(self, assertstruct=False)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070052 packed += self.data
53 return packed
54
55 def unpack(self, binary_string):
56 """
57 Unpack object from a binary string
58
59 @param binary_string The wire protocol byte string holding the object
60 represented as an array of bytes.
61 @return The remainder of binary_string that was not parsed.
62
63 """
Dan Talayco6cc1fda2012-09-18 06:39:24 -070064
Rich Laneb73808c2013-03-11 15:22:23 -070065 binary_string = of10.ofp_header.unpack(self, binary_string)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070066 self.data = binary_string
67 binary_string = ''
68 return binary_string
69
70 def __len__(self):
71 """
72 Return the length of this object once packed into a string
73
74 @return An integer representing the number bytes in the packed
75 string.
76
77 """
Rich Laneb73808c2013-03-11 15:22:23 -070078 length = 0
Dan Talayco6cc1fda2012-09-18 06:39:24 -070079
Rich Laneb73808c2013-03-11 15:22:23 -070080 length += of10.ofp_header.__len__(self)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070081 length += len(self.data)
82 return length
83
84 def show(self, prefix=''):
85 """
86 Generate a string (with multiple lines) describing the contents
87 of the object in a readable manner
88
89 @param prefix Pre-pended at the beginning of each line.
90
91 """
92
Rich Laneb73808c2013-03-11 15:22:23 -070093 outstr = prefix + 'illegal_message (217)\n'
Dan Talayco6cc1fda2012-09-18 06:39:24 -070094 prefix += ' '
95 outstr += prefix + 'ofp header\n'
Rich Laneb73808c2013-03-11 15:22:23 -070096 outstr += of10.ofp_header.show(self, prefix)
Dan Talayco6cc1fda2012-09-18 06:39:24 -070097 outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
Rich Laneb73808c2013-03-11 15:22:23 -070098 ##@todo Fix this circular reference
99 # if len(self.data) > 0:
100 # obj = of_message_parse(self.data)
101 # if obj != None:
102 # outstr += obj.show(prefix)
103 # else:
104 # outstr += prefix + "Unable to parse data\n"
Dan Talayco6cc1fda2012-09-18 06:39:24 -0700105 return outstr
106
107 def __eq__(self, other):
108 """
109 Return True if self and other hold the same data
110
111 @param other Other object in comparison
112
113 """
114 if type(self) != type(other): return False
Dan Talayco6cc1fda2012-09-18 06:39:24 -0700115
Rich Laneb73808c2013-03-11 15:22:23 -0700116 if not of10.ofp_header.__eq__(self, other): return False
Dan Talayco6cc1fda2012-09-18 06:39:24 -0700117 if self.data != other.data: return False
118 return True
119
120 def __ne__(self, other):
121 """
122 Return True if self and other do not hold the same data
123
124 @param other Other object in comparison
125
126 """
127 return not self.__eq__(other)