blob: 5b825d0ac559501282e8aef77e859c4f58821ff1 [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 meter(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700251 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700252
253 def __init__(self, meter_id=None):
254 if meter_id != None:
255 self.meter_id = meter_id
256 else:
257 self.meter_id = 0
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(struct.pack("!L", self.meter_id))
265 length = sum([len(x) for x in packed])
266 packed[1] = struct.pack("!H", length)
267 return ''.join(packed)
268
269 @staticmethod
270 def unpack(buf):
271 obj = meter()
272 if type(buf) == loxi.generic_util.OFReader:
273 reader = buf
274 else:
275 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700276 _type = reader.read("!H")[0]
277 assert(_type == 6)
278 _len = reader.read("!H")[0]
279 obj.meter_id = reader.read("!L")[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.meter_id != other.meter_id: return False
285 return True
286
287 def __ne__(self, other):
288 return not self.__eq__(other)
289
290 def show(self):
291 import loxi.pp
292 return loxi.pp.pp(self)
293
294 def pretty_print(self, q):
295 q.text("meter {")
296 with q.group():
297 with q.indent(2):
298 q.breakable()
299 q.text("meter_id = ");
300 q.text("%#x" % self.meter_id)
301 q.breakable()
302 q.text('}')
303
304class write_actions(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700305 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700306
307 def __init__(self, actions=None):
308 if actions != None:
309 self.actions = actions
310 else:
311 self.actions = []
312 return
313
314 def pack(self):
315 packed = []
316 packed.append(struct.pack("!H", self.type))
317 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
318 packed.append('\x00' * 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700319 packed.append(util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700320 length = sum([len(x) for x in packed])
321 packed[1] = struct.pack("!H", length)
322 return ''.join(packed)
323
324 @staticmethod
325 def unpack(buf):
326 obj = write_actions()
327 if type(buf) == loxi.generic_util.OFReader:
328 reader = buf
329 else:
330 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700331 _type = reader.read("!H")[0]
332 assert(_type == 3)
333 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700334 reader.skip(4)
335 obj.actions = action.unpack_list(reader)
336 return obj
337
338 def __eq__(self, other):
339 if type(self) != type(other): return False
340 if self.actions != other.actions: return False
341 return True
342
343 def __ne__(self, other):
344 return not self.__eq__(other)
345
346 def show(self):
347 import loxi.pp
348 return loxi.pp.pp(self)
349
350 def pretty_print(self, q):
351 q.text("write_actions {")
352 with q.group():
353 with q.indent(2):
354 q.breakable()
355 q.text("actions = ");
356 q.pp(self.actions)
357 q.breakable()
358 q.text('}')
359
360class write_metadata(Instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700361 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700362
363 def __init__(self, metadata=None, metadata_mask=None):
364 if metadata != None:
365 self.metadata = metadata
366 else:
367 self.metadata = 0
368 if metadata_mask != None:
369 self.metadata_mask = metadata_mask
370 else:
371 self.metadata_mask = 0
372 return
373
374 def pack(self):
375 packed = []
376 packed.append(struct.pack("!H", self.type))
377 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
378 packed.append('\x00' * 4)
379 packed.append(struct.pack("!Q", self.metadata))
380 packed.append(struct.pack("!Q", self.metadata_mask))
381 length = sum([len(x) for x in packed])
382 packed[1] = struct.pack("!H", length)
383 return ''.join(packed)
384
385 @staticmethod
386 def unpack(buf):
387 obj = write_metadata()
388 if type(buf) == loxi.generic_util.OFReader:
389 reader = buf
390 else:
391 reader = loxi.generic_util.OFReader(buf)
Dan Talaycof6202252013-07-02 01:00:29 -0700392 _type = reader.read("!H")[0]
393 assert(_type == 2)
394 _len = reader.read("!H")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700395 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700396 obj.metadata = reader.read("!Q")[0]
397 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700398 return obj
399
400 def __eq__(self, other):
401 if type(self) != type(other): return False
402 if self.metadata != other.metadata: return False
403 if self.metadata_mask != other.metadata_mask: return False
404 return True
405
406 def __ne__(self, other):
407 return not self.__eq__(other)
408
409 def show(self):
410 import loxi.pp
411 return loxi.pp.pp(self)
412
413 def pretty_print(self, q):
414 q.text("write_metadata {")
415 with q.group():
416 with q.indent(2):
417 q.breakable()
418 q.text("metadata = ");
419 q.text("%#x" % self.metadata)
420 q.text(","); q.breakable()
421 q.text("metadata_mask = ");
422 q.text("%#x" % self.metadata_mask)
423 q.breakable()
424 q.text('}')
425
426
427parsers = {
Dan Talaycof6202252013-07-02 01:00:29 -0700428 const.OFPIT_GOTO_TABLE : goto_table.unpack,
429 const.OFPIT_WRITE_METADATA : write_metadata.unpack,
430 const.OFPIT_WRITE_ACTIONS : write_actions.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700431 const.OFPIT_APPLY_ACTIONS : apply_actions.unpack,
432 const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700433 const.OFPIT_METER : meter.unpack,
Dan Talaycof6202252013-07-02 01:00:29 -0700434 const.OFPIT_EXPERIMENTER : experimenter.unpack,
Rich Laneca3da272013-05-05 09:07:33 -0700435}