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