blob: 2f7f1bf73eba26d1a4d96daa112980e0975b674f [file] [log] [blame]
Rich Laneca3da272013-05-05 09:07:33 -07001# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2# Copyright (c) 2011, 2012 Open Networking Foundation
3# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
Dan Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneca3da272013-05-05 09:07:33 -07005
6# Automatically generated by LOXI from template instruction.py
7# Do not modify
8
9import struct
10import action
11import const
12import util
13import loxi.generic_util
14import loxi
15
16def unpack_list(reader):
17 def deserializer(reader, typ):
18 parser = parsers.get(typ)
19 if not parser: raise loxi.ProtocolError("unknown instruction type %d" % typ)
20 return parser(reader)
21 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
22
23class Instruction(object):
24 type = None # override in subclass
25 pass
26
27class apply_actions(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070028 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070029
30 def __init__(self, actions=None):
31 if actions != None:
32 self.actions = actions
33 else:
34 self.actions = []
35 return
36
37 def pack(self):
38 packed = []
39 packed.append(struct.pack("!H", self.type))
40 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
41 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -070042 packed.append(util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070043 length = sum([len(x) for x in packed])
44 packed[1] = struct.pack("!H", length)
45 return ''.join(packed)
46
47 @staticmethod
48 def unpack(buf):
49 obj = apply_actions()
50 if type(buf) == loxi.generic_util.OFReader:
51 reader = buf
52 else:
53 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -070054 _type = reader.read("!H")[0]
55 assert(_type == 4)
56 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -070057 reader.skip(4)
58 obj.actions = action.unpack_list(reader)
59 return obj
60
61 def __eq__(self, other):
62 if type(self) != type(other): return False
63 if self.actions != other.actions: return False
64 return True
65
66 def __ne__(self, other):
67 return not self.__eq__(other)
68
69 def show(self):
70 import loxi.pp
71 return loxi.pp.pp(self)
72
73 def pretty_print(self, q):
74 q.text("apply_actions {")
75 with q.group():
76 with q.indent(2):
77 q.breakable()
78 q.text("actions = ");
79 q.pp(self.actions)
80 q.breakable()
81 q.text('}')
82
83class clear_actions(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070084 type = 5
Rich Laneca3da272013-05-05 09:07:33 -070085
86 def __init__(self):
87 return
88
89 def pack(self):
90 packed = []
91 packed.append(struct.pack("!H", self.type))
92 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
93 packed.append('\x00' * 4)
94 length = sum([len(x) for x in packed])
95 packed[1] = struct.pack("!H", length)
96 return ''.join(packed)
97
98 @staticmethod
99 def unpack(buf):
100 obj = clear_actions()
101 if type(buf) == loxi.generic_util.OFReader:
102 reader = buf
103 else:
104 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700105 _type = reader.read("!H")[0]
106 assert(_type == 5)
107 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700108 reader.skip(4)
109 return obj
110
111 def __eq__(self, other):
112 if type(self) != type(other): return False
113 return True
114
115 def __ne__(self, other):
116 return not self.__eq__(other)
117
118 def show(self):
119 import loxi.pp
120 return loxi.pp.pp(self)
121
122 def pretty_print(self, q):
123 q.text("clear_actions {")
124 with q.group():
125 with q.indent(2):
126 q.breakable()
127 q.breakable()
128 q.text('}')
129
Rich Laneca3da272013-05-05 09:07:33 -0700130class goto_table(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700131 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700132
133 def __init__(self, table_id=None):
134 if table_id != None:
135 self.table_id = table_id
136 else:
137 self.table_id = 0
138 return
139
140 def pack(self):
141 packed = []
142 packed.append(struct.pack("!H", self.type))
143 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
144 packed.append(struct.pack("!B", self.table_id))
145 packed.append('\x00' * 3)
146 length = sum([len(x) for x in packed])
147 packed[1] = struct.pack("!H", length)
148 return ''.join(packed)
149
150 @staticmethod
151 def unpack(buf):
152 obj = goto_table()
153 if type(buf) == loxi.generic_util.OFReader:
154 reader = buf
155 else:
156 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700157 _type = reader.read("!H")[0]
158 assert(_type == 1)
159 _len = reader.read("!H")[0]
160 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700161 reader.skip(3)
162 return obj
163
164 def __eq__(self, other):
165 if type(self) != type(other): return False
166 if self.table_id != other.table_id: return False
167 return True
168
169 def __ne__(self, other):
170 return not self.__eq__(other)
171
172 def show(self):
173 import loxi.pp
174 return loxi.pp.pp(self)
175
176 def pretty_print(self, q):
177 q.text("goto_table {")
178 with q.group():
179 with q.indent(2):
180 q.breakable()
181 q.text("table_id = ");
182 q.text("%#x" % self.table_id)
183 q.breakable()
184 q.text('}')
185
186class write_actions(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700187 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700188
189 def __init__(self, actions=None):
190 if actions != None:
191 self.actions = actions
192 else:
193 self.actions = []
194 return
195
196 def pack(self):
197 packed = []
198 packed.append(struct.pack("!H", self.type))
199 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
200 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700201 packed.append(util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700202 length = sum([len(x) for x in packed])
203 packed[1] = struct.pack("!H", length)
204 return ''.join(packed)
205
206 @staticmethod
207 def unpack(buf):
208 obj = write_actions()
209 if type(buf) == loxi.generic_util.OFReader:
210 reader = buf
211 else:
212 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700213 _type = reader.read("!H")[0]
214 assert(_type == 3)
215 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700216 reader.skip(4)
217 obj.actions = action.unpack_list(reader)
218 return obj
219
220 def __eq__(self, other):
221 if type(self) != type(other): return False
222 if self.actions != other.actions: return False
223 return True
224
225 def __ne__(self, other):
226 return not self.__eq__(other)
227
228 def show(self):
229 import loxi.pp
230 return loxi.pp.pp(self)
231
232 def pretty_print(self, q):
233 q.text("write_actions {")
234 with q.group():
235 with q.indent(2):
236 q.breakable()
237 q.text("actions = ");
238 q.pp(self.actions)
239 q.breakable()
240 q.text('}')
241
242class write_metadata(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700243 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700244
245 def __init__(self, metadata=None, metadata_mask=None):
246 if metadata != None:
247 self.metadata = metadata
248 else:
249 self.metadata = 0
250 if metadata_mask != None:
251 self.metadata_mask = metadata_mask
252 else:
253 self.metadata_mask = 0
254 return
255
256 def pack(self):
257 packed = []
258 packed.append(struct.pack("!H", self.type))
259 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
260 packed.append('\x00' * 4)
261 packed.append(struct.pack("!Q", self.metadata))
262 packed.append(struct.pack("!Q", self.metadata_mask))
263 length = sum([len(x) for x in packed])
264 packed[1] = struct.pack("!H", length)
265 return ''.join(packed)
266
267 @staticmethod
268 def unpack(buf):
269 obj = write_metadata()
270 if type(buf) == loxi.generic_util.OFReader:
271 reader = buf
272 else:
273 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700274 _type = reader.read("!H")[0]
275 assert(_type == 2)
276 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700277 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700278 obj.metadata = reader.read("!Q")[0]
279 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700280 return obj
281
282 def __eq__(self, other):
283 if type(self) != type(other): return False
284 if self.metadata != other.metadata: return False
285 if self.metadata_mask != other.metadata_mask: return False
286 return True
287
288 def __ne__(self, other):
289 return not self.__eq__(other)
290
291 def show(self):
292 import loxi.pp
293 return loxi.pp.pp(self)
294
295 def pretty_print(self, q):
296 q.text("write_metadata {")
297 with q.group():
298 with q.indent(2):
299 q.breakable()
300 q.text("metadata = ");
301 q.text("%#x" % self.metadata)
302 q.text(","); q.breakable()
303 q.text("metadata_mask = ");
304 q.text("%#x" % self.metadata_mask)
305 q.breakable()
306 q.text('}')
307
308
309parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -0700310 const.OFPIT_GOTO_TABLE : goto_table.unpack,
311 const.OFPIT_WRITE_METADATA : write_metadata.unpack,
312 const.OFPIT_WRITE_ACTIONS : write_actions.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700313 const.OFPIT_APPLY_ACTIONS : apply_actions.unpack,
314 const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700315}