blob: 38f867091f6504982e08f4764518b17ae144f1da [file] [log] [blame]
Nathan Knuth418fdc82016-09-16 22:51:15 -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# See the file LICENSE.pyloxi which should have been included in the source distribution
5
6# Automatically generated by LOXI from template module.py
7# Do not modify
8
9import struct
10import loxi
11import util
12import loxi.generic_util
13
14import sys
15ofp = sys.modules['loxi.of12']
16
17class instruction(loxi.OFObject):
18 subtypes = {}
19
20
21 def __init__(self, type=None):
22 if type != None:
23 self.type = type
24 else:
25 self.type = 0
26 return
27
28 def pack(self):
29 packed = []
30 packed.append(struct.pack("!H", self.type))
31 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
32 packed.append('\x00' * 4)
33 length = sum([len(x) for x in packed])
34 packed[1] = struct.pack("!H", length)
35 return ''.join(packed)
36
37 @staticmethod
38 def unpack(reader):
39 subtype, = reader.peek('!H', 0)
40 subclass = instruction.subtypes.get(subtype)
41 if subclass:
42 return subclass.unpack(reader)
43
44 obj = instruction()
45 obj.type = reader.read("!H")[0]
46 _len = reader.read("!H")[0]
47 orig_reader = reader
48 reader = orig_reader.slice(_len, 4)
49 reader.skip(4)
50 return obj
51
52 def __eq__(self, other):
53 if type(self) != type(other): return False
54 if self.type != other.type: return False
55 return True
56
57 def pretty_print(self, q):
58 q.text("instruction {")
59 with q.group():
60 with q.indent(2):
61 q.breakable()
62 q.breakable()
63 q.text('}')
64
65
66class apply_actions(instruction):
67 type = 4
68
69 def __init__(self, actions=None):
70 if actions != None:
71 self.actions = actions
72 else:
73 self.actions = []
74 return
75
76 def pack(self):
77 packed = []
78 packed.append(struct.pack("!H", self.type))
79 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
80 packed.append('\x00' * 4)
81 packed.append(loxi.generic_util.pack_list(self.actions))
82 length = sum([len(x) for x in packed])
83 packed[1] = struct.pack("!H", length)
84 return ''.join(packed)
85
86 @staticmethod
87 def unpack(reader):
88 obj = apply_actions()
89 _type = reader.read("!H")[0]
90 assert(_type == 4)
91 _len = reader.read("!H")[0]
92 orig_reader = reader
93 reader = orig_reader.slice(_len, 4)
94 reader.skip(4)
95 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
96 return obj
97
98 def __eq__(self, other):
99 if type(self) != type(other): return False
100 if self.actions != other.actions: return False
101 return True
102
103 def pretty_print(self, q):
104 q.text("apply_actions {")
105 with q.group():
106 with q.indent(2):
107 q.breakable()
108 q.text("actions = ");
109 q.pp(self.actions)
110 q.breakable()
111 q.text('}')
112
113instruction.subtypes[4] = apply_actions
114
115class clear_actions(instruction):
116 type = 5
117
118 def __init__(self):
119 return
120
121 def pack(self):
122 packed = []
123 packed.append(struct.pack("!H", self.type))
124 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
125 packed.append('\x00' * 4)
126 length = sum([len(x) for x in packed])
127 packed[1] = struct.pack("!H", length)
128 return ''.join(packed)
129
130 @staticmethod
131 def unpack(reader):
132 obj = clear_actions()
133 _type = reader.read("!H")[0]
134 assert(_type == 5)
135 _len = reader.read("!H")[0]
136 orig_reader = reader
137 reader = orig_reader.slice(_len, 4)
138 reader.skip(4)
139 return obj
140
141 def __eq__(self, other):
142 if type(self) != type(other): return False
143 return True
144
145 def pretty_print(self, q):
146 q.text("clear_actions {")
147 with q.group():
148 with q.indent(2):
149 q.breakable()
150 q.breakable()
151 q.text('}')
152
153instruction.subtypes[5] = clear_actions
154
155class experimenter(instruction):
156 subtypes = {}
157
158 type = 65535
159
160 def __init__(self, experimenter=None, data=None):
161 if experimenter != None:
162 self.experimenter = experimenter
163 else:
164 self.experimenter = 0
165 if data != None:
166 self.data = data
167 else:
168 self.data = ''
169 return
170
171 def pack(self):
172 packed = []
173 packed.append(struct.pack("!H", self.type))
174 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
175 packed.append(struct.pack("!L", self.experimenter))
176 packed.append(self.data)
177 length = sum([len(x) for x in packed])
178 packed[1] = struct.pack("!H", length)
179 return ''.join(packed)
180
181 @staticmethod
182 def unpack(reader):
183 subtype, = reader.peek('!L', 4)
184 subclass = experimenter.subtypes.get(subtype)
185 if subclass:
186 return subclass.unpack(reader)
187
188 obj = experimenter()
189 _type = reader.read("!H")[0]
190 assert(_type == 65535)
191 _len = reader.read("!H")[0]
192 orig_reader = reader
193 reader = orig_reader.slice(_len, 4)
194 obj.experimenter = reader.read("!L")[0]
195 obj.data = str(reader.read_all())
196 return obj
197
198 def __eq__(self, other):
199 if type(self) != type(other): return False
200 if self.experimenter != other.experimenter: return False
201 if self.data != other.data: return False
202 return True
203
204 def pretty_print(self, q):
205 q.text("experimenter {")
206 with q.group():
207 with q.indent(2):
208 q.breakable()
209 q.text("data = ");
210 q.pp(self.data)
211 q.breakable()
212 q.text('}')
213
214instruction.subtypes[65535] = experimenter
215
216class goto_table(instruction):
217 type = 1
218
219 def __init__(self, table_id=None):
220 if table_id != None:
221 self.table_id = table_id
222 else:
223 self.table_id = 0
224 return
225
226 def pack(self):
227 packed = []
228 packed.append(struct.pack("!H", self.type))
229 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
230 packed.append(struct.pack("!B", self.table_id))
231 packed.append('\x00' * 3)
232 length = sum([len(x) for x in packed])
233 packed[1] = struct.pack("!H", length)
234 return ''.join(packed)
235
236 @staticmethod
237 def unpack(reader):
238 obj = goto_table()
239 _type = reader.read("!H")[0]
240 assert(_type == 1)
241 _len = reader.read("!H")[0]
242 orig_reader = reader
243 reader = orig_reader.slice(_len, 4)
244 obj.table_id = reader.read("!B")[0]
245 reader.skip(3)
246 return obj
247
248 def __eq__(self, other):
249 if type(self) != type(other): return False
250 if self.table_id != other.table_id: return False
251 return True
252
253 def pretty_print(self, q):
254 q.text("goto_table {")
255 with q.group():
256 with q.indent(2):
257 q.breakable()
258 q.text("table_id = ");
259 q.text("%#x" % self.table_id)
260 q.breakable()
261 q.text('}')
262
263instruction.subtypes[1] = goto_table
264
265class write_actions(instruction):
266 type = 3
267
268 def __init__(self, actions=None):
269 if actions != None:
270 self.actions = actions
271 else:
272 self.actions = []
273 return
274
275 def pack(self):
276 packed = []
277 packed.append(struct.pack("!H", self.type))
278 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
279 packed.append('\x00' * 4)
280 packed.append(loxi.generic_util.pack_list(self.actions))
281 length = sum([len(x) for x in packed])
282 packed[1] = struct.pack("!H", length)
283 return ''.join(packed)
284
285 @staticmethod
286 def unpack(reader):
287 obj = write_actions()
288 _type = reader.read("!H")[0]
289 assert(_type == 3)
290 _len = reader.read("!H")[0]
291 orig_reader = reader
292 reader = orig_reader.slice(_len, 4)
293 reader.skip(4)
294 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
295 return obj
296
297 def __eq__(self, other):
298 if type(self) != type(other): return False
299 if self.actions != other.actions: return False
300 return True
301
302 def pretty_print(self, q):
303 q.text("write_actions {")
304 with q.group():
305 with q.indent(2):
306 q.breakable()
307 q.text("actions = ");
308 q.pp(self.actions)
309 q.breakable()
310 q.text('}')
311
312instruction.subtypes[3] = write_actions
313
314class write_metadata(instruction):
315 type = 2
316
317 def __init__(self, metadata=None, metadata_mask=None):
318 if metadata != None:
319 self.metadata = metadata
320 else:
321 self.metadata = 0
322 if metadata_mask != None:
323 self.metadata_mask = metadata_mask
324 else:
325 self.metadata_mask = 0
326 return
327
328 def pack(self):
329 packed = []
330 packed.append(struct.pack("!H", self.type))
331 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
332 packed.append('\x00' * 4)
333 packed.append(struct.pack("!Q", self.metadata))
334 packed.append(struct.pack("!Q", self.metadata_mask))
335 length = sum([len(x) for x in packed])
336 packed[1] = struct.pack("!H", length)
337 return ''.join(packed)
338
339 @staticmethod
340 def unpack(reader):
341 obj = write_metadata()
342 _type = reader.read("!H")[0]
343 assert(_type == 2)
344 _len = reader.read("!H")[0]
345 orig_reader = reader
346 reader = orig_reader.slice(_len, 4)
347 reader.skip(4)
348 obj.metadata = reader.read("!Q")[0]
349 obj.metadata_mask = reader.read("!Q")[0]
350 return obj
351
352 def __eq__(self, other):
353 if type(self) != type(other): return False
354 if self.metadata != other.metadata: return False
355 if self.metadata_mask != other.metadata_mask: return False
356 return True
357
358 def pretty_print(self, q):
359 q.text("write_metadata {")
360 with q.group():
361 with q.indent(2):
362 q.breakable()
363 q.text("metadata = ");
364 q.text("%#x" % self.metadata)
365 q.text(","); q.breakable()
366 q.text("metadata_mask = ");
367 q.text("%#x" % self.metadata_mask)
368 q.breakable()
369 q.text('}')
370
371instruction.subtypes[2] = write_metadata
372
373