blob: 961f3c6a7d15bef112c195d699d2516d413475fd [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
130class experimenter(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700131 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700132
133 def __init__(self, experimenter=None, data=None):
134 if experimenter != None:
135 self.experimenter = experimenter
136 else:
137 self.experimenter = 0
138 if data != None:
139 self.data = data
140 else:
Dan Talaycof6202252013-07-02 01:00:29 -0700141 self.data = ''
Rich Laneca3da272013-05-05 09:07:33 -0700142 return
143
144 def pack(self):
145 packed = []
146 packed.append(struct.pack("!H", self.type))
147 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
148 packed.append(struct.pack("!L", self.experimenter))
149 packed.append(self.data)
150 length = sum([len(x) for x in packed])
151 packed[1] = struct.pack("!H", length)
152 return ''.join(packed)
153
154 @staticmethod
155 def unpack(buf):
156 obj = experimenter()
157 if type(buf) == loxi.generic_util.OFReader:
158 reader = buf
159 else:
160 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700161 _type = reader.read("!H")[0]
162 assert(_type == 65535)
163 _len = reader.read("!H")[0]
164 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700165 obj.data = str(reader.read_all())
166 return obj
167
168 def __eq__(self, other):
169 if type(self) != type(other): return False
170 if self.experimenter != other.experimenter: return False
171 if self.data != other.data: return False
172 return True
173
174 def __ne__(self, other):
175 return not self.__eq__(other)
176
177 def show(self):
178 import loxi.pp
179 return loxi.pp.pp(self)
180
181 def pretty_print(self, q):
182 q.text("experimenter {")
183 with q.group():
184 with q.indent(2):
185 q.breakable()
186 q.text("experimenter = ");
187 q.text("%#x" % self.experimenter)
188 q.text(","); q.breakable()
189 q.text("data = ");
190 q.pp(self.data)
191 q.breakable()
192 q.text('}')
193
194class goto_table(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700195 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700196
197 def __init__(self, table_id=None):
198 if table_id != None:
199 self.table_id = table_id
200 else:
201 self.table_id = 0
202 return
203
204 def pack(self):
205 packed = []
206 packed.append(struct.pack("!H", self.type))
207 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
208 packed.append(struct.pack("!B", self.table_id))
209 packed.append('\x00' * 3)
210 length = sum([len(x) for x in packed])
211 packed[1] = struct.pack("!H", length)
212 return ''.join(packed)
213
214 @staticmethod
215 def unpack(buf):
216 obj = goto_table()
217 if type(buf) == loxi.generic_util.OFReader:
218 reader = buf
219 else:
220 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700221 _type = reader.read("!H")[0]
222 assert(_type == 1)
223 _len = reader.read("!H")[0]
224 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700225 reader.skip(3)
226 return obj
227
228 def __eq__(self, other):
229 if type(self) != type(other): return False
230 if self.table_id != other.table_id: return False
231 return True
232
233 def __ne__(self, other):
234 return not self.__eq__(other)
235
236 def show(self):
237 import loxi.pp
238 return loxi.pp.pp(self)
239
240 def pretty_print(self, q):
241 q.text("goto_table {")
242 with q.group():
243 with q.indent(2):
244 q.breakable()
245 q.text("table_id = ");
246 q.text("%#x" % self.table_id)
247 q.breakable()
248 q.text('}')
249
250class write_actions(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700251 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700252
253 def __init__(self, actions=None):
254 if actions != None:
255 self.actions = actions
256 else:
257 self.actions = []
258 return
259
260 def pack(self):
261 packed = []
262 packed.append(struct.pack("!H", self.type))
263 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
264 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700265 packed.append(util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700266 length = sum([len(x) for x in packed])
267 packed[1] = struct.pack("!H", length)
268 return ''.join(packed)
269
270 @staticmethod
271 def unpack(buf):
272 obj = write_actions()
273 if type(buf) == loxi.generic_util.OFReader:
274 reader = buf
275 else:
276 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700277 _type = reader.read("!H")[0]
278 assert(_type == 3)
279 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700280 reader.skip(4)
281 obj.actions = action.unpack_list(reader)
282 return obj
283
284 def __eq__(self, other):
285 if type(self) != type(other): return False
286 if self.actions != other.actions: return False
287 return True
288
289 def __ne__(self, other):
290 return not self.__eq__(other)
291
292 def show(self):
293 import loxi.pp
294 return loxi.pp.pp(self)
295
296 def pretty_print(self, q):
297 q.text("write_actions {")
298 with q.group():
299 with q.indent(2):
300 q.breakable()
301 q.text("actions = ");
302 q.pp(self.actions)
303 q.breakable()
304 q.text('}')
305
306class write_metadata(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700307 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700308
309 def __init__(self, metadata=None, metadata_mask=None):
310 if metadata != None:
311 self.metadata = metadata
312 else:
313 self.metadata = 0
314 if metadata_mask != None:
315 self.metadata_mask = metadata_mask
316 else:
317 self.metadata_mask = 0
318 return
319
320 def pack(self):
321 packed = []
322 packed.append(struct.pack("!H", self.type))
323 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
324 packed.append('\x00' * 4)
325 packed.append(struct.pack("!Q", self.metadata))
326 packed.append(struct.pack("!Q", self.metadata_mask))
327 length = sum([len(x) for x in packed])
328 packed[1] = struct.pack("!H", length)
329 return ''.join(packed)
330
331 @staticmethod
332 def unpack(buf):
333 obj = write_metadata()
334 if type(buf) == loxi.generic_util.OFReader:
335 reader = buf
336 else:
337 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700338 _type = reader.read("!H")[0]
339 assert(_type == 2)
340 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700341 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700342 obj.metadata = reader.read("!Q")[0]
343 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700344 return obj
345
346 def __eq__(self, other):
347 if type(self) != type(other): return False
348 if self.metadata != other.metadata: return False
349 if self.metadata_mask != other.metadata_mask: return False
350 return True
351
352 def __ne__(self, other):
353 return not self.__eq__(other)
354
355 def show(self):
356 import loxi.pp
357 return loxi.pp.pp(self)
358
359 def pretty_print(self, q):
360 q.text("write_metadata {")
361 with q.group():
362 with q.indent(2):
363 q.breakable()
364 q.text("metadata = ");
365 q.text("%#x" % self.metadata)
366 q.text(","); q.breakable()
367 q.text("metadata_mask = ");
368 q.text("%#x" % self.metadata_mask)
369 q.breakable()
370 q.text('}')
371
372
373parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -0700374 const.OFPIT_GOTO_TABLE : goto_table.unpack,
375 const.OFPIT_WRITE_METADATA : write_metadata.unpack,
376 const.OFPIT_WRITE_ACTIONS : write_actions.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700377 const.OFPIT_APPLY_ACTIONS : apply_actions.unpack,
378 const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack,
379 const.OFPIT_EXPERIMENTER : experimenter.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700380}