blob: 08b512453aac1019a885374a09f5bb9eca340a1c [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.
4
5# Automatically generated by LOXI from template instruction.py
6# Do not modify
7
8import struct
9import action
10import const
11import util
12import loxi.generic_util
13import loxi
14
15def unpack_list(reader):
16 def deserializer(reader, typ):
17 parser = parsers.get(typ)
18 if not parser: raise loxi.ProtocolError("unknown instruction type %d" % typ)
19 return parser(reader)
20 return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
21
22class Instruction(object):
23 type = None # override in subclass
24 pass
25
26class apply_actions(Instruction):
27 type = const.OFPIT_APPLY_ACTIONS
28
29 def __init__(self, actions=None):
30 if actions != None:
31 self.actions = actions
32 else:
33 self.actions = []
34 return
35
36 def pack(self):
37 packed = []
38 packed.append(struct.pack("!H", self.type))
39 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
40 packed.append('\x00' * 4)
41 packed.append("".join([x.pack() for x in self.actions]))
42 length = sum([len(x) for x in packed])
43 packed[1] = struct.pack("!H", length)
44 return ''.join(packed)
45
46 @staticmethod
47 def unpack(buf):
48 obj = apply_actions()
49 if type(buf) == loxi.generic_util.OFReader:
50 reader = buf
51 else:
52 reader = loxi.generic_util.OFReader(buf)
53 _type = reader.read('!H')[0]
54 assert(_type == const.OFPIT_APPLY_ACTIONS)
55 _len = reader.read('!H')[0]
56 reader.skip(4)
57 obj.actions = action.unpack_list(reader)
58 return obj
59
60 def __eq__(self, other):
61 if type(self) != type(other): return False
62 if self.actions != other.actions: return False
63 return True
64
65 def __ne__(self, other):
66 return not self.__eq__(other)
67
68 def show(self):
69 import loxi.pp
70 return loxi.pp.pp(self)
71
72 def pretty_print(self, q):
73 q.text("apply_actions {")
74 with q.group():
75 with q.indent(2):
76 q.breakable()
77 q.text("actions = ");
78 q.pp(self.actions)
79 q.breakable()
80 q.text('}')
81
82class clear_actions(Instruction):
83 type = const.OFPIT_CLEAR_ACTIONS
84
85 def __init__(self):
86 return
87
88 def pack(self):
89 packed = []
90 packed.append(struct.pack("!H", self.type))
91 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
92 packed.append('\x00' * 4)
93 length = sum([len(x) for x in packed])
94 packed[1] = struct.pack("!H", length)
95 return ''.join(packed)
96
97 @staticmethod
98 def unpack(buf):
99 obj = clear_actions()
100 if type(buf) == loxi.generic_util.OFReader:
101 reader = buf
102 else:
103 reader = loxi.generic_util.OFReader(buf)
104 _type = reader.read('!H')[0]
105 assert(_type == const.OFPIT_CLEAR_ACTIONS)
106 _len = reader.read('!H')[0]
107 reader.skip(4)
108 return obj
109
110 def __eq__(self, other):
111 if type(self) != type(other): return False
112 return True
113
114 def __ne__(self, other):
115 return not self.__eq__(other)
116
117 def show(self):
118 import loxi.pp
119 return loxi.pp.pp(self)
120
121 def pretty_print(self, q):
122 q.text("clear_actions {")
123 with q.group():
124 with q.indent(2):
125 q.breakable()
126 q.breakable()
127 q.text('}')
128
129class experimenter(Instruction):
130 type = const.OFPIT_EXPERIMENTER
131
132 def __init__(self, experimenter=None, data=None):
133 if experimenter != None:
134 self.experimenter = experimenter
135 else:
136 self.experimenter = 0
137 if data != None:
138 self.data = data
139 else:
140 self.data = ""
141 return
142
143 def pack(self):
144 packed = []
145 packed.append(struct.pack("!H", self.type))
146 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
147 packed.append(struct.pack("!L", self.experimenter))
148 packed.append(self.data)
149 length = sum([len(x) for x in packed])
150 packed[1] = struct.pack("!H", length)
151 return ''.join(packed)
152
153 @staticmethod
154 def unpack(buf):
155 obj = experimenter()
156 if type(buf) == loxi.generic_util.OFReader:
157 reader = buf
158 else:
159 reader = loxi.generic_util.OFReader(buf)
160 _type = reader.read('!H')[0]
161 assert(_type == const.OFPIT_EXPERIMENTER)
162 _len = reader.read('!H')[0]
163 obj.experimenter = reader.read('!L')[0]
164 obj.data = str(reader.read_all())
165 return obj
166
167 def __eq__(self, other):
168 if type(self) != type(other): return False
169 if self.experimenter != other.experimenter: return False
170 if self.data != other.data: return False
171 return True
172
173 def __ne__(self, other):
174 return not self.__eq__(other)
175
176 def show(self):
177 import loxi.pp
178 return loxi.pp.pp(self)
179
180 def pretty_print(self, q):
181 q.text("experimenter {")
182 with q.group():
183 with q.indent(2):
184 q.breakable()
185 q.text("experimenter = ");
186 q.text("%#x" % self.experimenter)
187 q.text(","); q.breakable()
188 q.text("data = ");
189 q.pp(self.data)
190 q.breakable()
191 q.text('}')
192
193class goto_table(Instruction):
194 type = const.OFPIT_GOTO_TABLE
195
196 def __init__(self, table_id=None):
197 if table_id != None:
198 self.table_id = table_id
199 else:
200 self.table_id = 0
201 return
202
203 def pack(self):
204 packed = []
205 packed.append(struct.pack("!H", self.type))
206 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
207 packed.append(struct.pack("!B", self.table_id))
208 packed.append('\x00' * 3)
209 length = sum([len(x) for x in packed])
210 packed[1] = struct.pack("!H", length)
211 return ''.join(packed)
212
213 @staticmethod
214 def unpack(buf):
215 obj = goto_table()
216 if type(buf) == loxi.generic_util.OFReader:
217 reader = buf
218 else:
219 reader = loxi.generic_util.OFReader(buf)
220 _type = reader.read('!H')[0]
221 assert(_type == const.OFPIT_GOTO_TABLE)
222 _len = reader.read('!H')[0]
223 obj.table_id = reader.read('!B')[0]
224 reader.skip(3)
225 return obj
226
227 def __eq__(self, other):
228 if type(self) != type(other): return False
229 if self.table_id != other.table_id: return False
230 return True
231
232 def __ne__(self, other):
233 return not self.__eq__(other)
234
235 def show(self):
236 import loxi.pp
237 return loxi.pp.pp(self)
238
239 def pretty_print(self, q):
240 q.text("goto_table {")
241 with q.group():
242 with q.indent(2):
243 q.breakable()
244 q.text("table_id = ");
245 q.text("%#x" % self.table_id)
246 q.breakable()
247 q.text('}')
248
249class meter(Instruction):
250 type = const.OFPIT_METER
251
252 def __init__(self, meter_id=None):
253 if meter_id != None:
254 self.meter_id = meter_id
255 else:
256 self.meter_id = 0
257 return
258
259 def pack(self):
260 packed = []
261 packed.append(struct.pack("!H", self.type))
262 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
263 packed.append(struct.pack("!L", self.meter_id))
264 length = sum([len(x) for x in packed])
265 packed[1] = struct.pack("!H", length)
266 return ''.join(packed)
267
268 @staticmethod
269 def unpack(buf):
270 obj = meter()
271 if type(buf) == loxi.generic_util.OFReader:
272 reader = buf
273 else:
274 reader = loxi.generic_util.OFReader(buf)
275 _type = reader.read('!H')[0]
276 assert(_type == const.OFPIT_METER)
277 _len = reader.read('!H')[0]
278 obj.meter_id = reader.read('!L')[0]
279 return obj
280
281 def __eq__(self, other):
282 if type(self) != type(other): return False
283 if self.meter_id != other.meter_id: return False
284 return True
285
286 def __ne__(self, other):
287 return not self.__eq__(other)
288
289 def show(self):
290 import loxi.pp
291 return loxi.pp.pp(self)
292
293 def pretty_print(self, q):
294 q.text("meter {")
295 with q.group():
296 with q.indent(2):
297 q.breakable()
298 q.text("meter_id = ");
299 q.text("%#x" % self.meter_id)
300 q.breakable()
301 q.text('}')
302
303class write_actions(Instruction):
304 type = const.OFPIT_WRITE_ACTIONS
305
306 def __init__(self, actions=None):
307 if actions != None:
308 self.actions = actions
309 else:
310 self.actions = []
311 return
312
313 def pack(self):
314 packed = []
315 packed.append(struct.pack("!H", self.type))
316 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
317 packed.append('\x00' * 4)
318 packed.append("".join([x.pack() for x in self.actions]))
319 length = sum([len(x) for x in packed])
320 packed[1] = struct.pack("!H", length)
321 return ''.join(packed)
322
323 @staticmethod
324 def unpack(buf):
325 obj = write_actions()
326 if type(buf) == loxi.generic_util.OFReader:
327 reader = buf
328 else:
329 reader = loxi.generic_util.OFReader(buf)
330 _type = reader.read('!H')[0]
331 assert(_type == const.OFPIT_WRITE_ACTIONS)
332 _len = reader.read('!H')[0]
333 reader.skip(4)
334 obj.actions = action.unpack_list(reader)
335 return obj
336
337 def __eq__(self, other):
338 if type(self) != type(other): return False
339 if self.actions != other.actions: return False
340 return True
341
342 def __ne__(self, other):
343 return not self.__eq__(other)
344
345 def show(self):
346 import loxi.pp
347 return loxi.pp.pp(self)
348
349 def pretty_print(self, q):
350 q.text("write_actions {")
351 with q.group():
352 with q.indent(2):
353 q.breakable()
354 q.text("actions = ");
355 q.pp(self.actions)
356 q.breakable()
357 q.text('}')
358
359class write_metadata(Instruction):
360 type = const.OFPIT_WRITE_METADATA
361
362 def __init__(self, metadata=None, metadata_mask=None):
363 if metadata != None:
364 self.metadata = metadata
365 else:
366 self.metadata = 0
367 if metadata_mask != None:
368 self.metadata_mask = metadata_mask
369 else:
370 self.metadata_mask = 0
371 return
372
373 def pack(self):
374 packed = []
375 packed.append(struct.pack("!H", self.type))
376 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
377 packed.append('\x00' * 4)
378 packed.append(struct.pack("!Q", self.metadata))
379 packed.append(struct.pack("!Q", self.metadata_mask))
380 length = sum([len(x) for x in packed])
381 packed[1] = struct.pack("!H", length)
382 return ''.join(packed)
383
384 @staticmethod
385 def unpack(buf):
386 obj = write_metadata()
387 if type(buf) == loxi.generic_util.OFReader:
388 reader = buf
389 else:
390 reader = loxi.generic_util.OFReader(buf)
391 _type = reader.read('!H')[0]
392 assert(_type == const.OFPIT_WRITE_METADATA)
393 _len = reader.read('!H')[0]
394 reader.skip(4)
395 obj.metadata = reader.read('!Q')[0]
396 obj.metadata_mask = reader.read('!Q')[0]
397 return obj
398
399 def __eq__(self, other):
400 if type(self) != type(other): return False
401 if self.metadata != other.metadata: return False
402 if self.metadata_mask != other.metadata_mask: return False
403 return True
404
405 def __ne__(self, other):
406 return not self.__eq__(other)
407
408 def show(self):
409 import loxi.pp
410 return loxi.pp.pp(self)
411
412 def pretty_print(self, q):
413 q.text("write_metadata {")
414 with q.group():
415 with q.indent(2):
416 q.breakable()
417 q.text("metadata = ");
418 q.text("%#x" % self.metadata)
419 q.text(","); q.breakable()
420 q.text("metadata_mask = ");
421 q.text("%#x" % self.metadata_mask)
422 q.breakable()
423 q.text('}')
424
425
426parsers = {
427 const.OFPIT_APPLY_ACTIONS : apply_actions.unpack,
428 const.OFPIT_CLEAR_ACTIONS : clear_actions.unpack,
429 const.OFPIT_EXPERIMENTER : experimenter.unpack,
430 const.OFPIT_GOTO_TABLE : goto_table.unpack,
431 const.OFPIT_METER : meter.unpack,
432 const.OFPIT_WRITE_ACTIONS : write_actions.unpack,
433 const.OFPIT_WRITE_METADATA : write_metadata.unpack,
434}