blob: eb0f517d318484dd9ebea7aff7e6c9e1eb45a806 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Rich Laneca3da272013-05-05 09:07:33 -070017# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
18# Copyright (c) 2011, 2012 Open Networking Foundation
19# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
Dan Talaycof6202252013-07-02 01:00:29 -070020# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneca3da272013-05-05 09:07:33 -070021
Rich Lane7dcdf022013-12-11 14:45:27 -080022# Automatically generated by LOXI from template module.py
Rich Laneca3da272013-05-05 09:07:33 -070023# Do not modify
24
25import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080026import loxi
Rich Laneca3da272013-05-05 09:07:33 -070027import util
28import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070029
Rich Lanee2567702015-01-26 15:04:35 -080030import sys
31ofp = sys.modules['loxi.of11']
32
Rich Lane7dcdf022013-12-11 14:45:27 -080033class instruction(loxi.OFObject):
34 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070035
Rich Lane95f7fc92014-01-27 17:08:16 -080036
37 def __init__(self, type=None):
38 if type != None:
39 self.type = type
40 else:
41 self.type = 0
42 return
43
44 def pack(self):
45 packed = []
46 packed.append(struct.pack("!H", self.type))
47 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
48 packed.append('\x00' * 4)
49 length = sum([len(x) for x in packed])
50 packed[1] = struct.pack("!H", length)
51 return ''.join(packed)
52
Rich Lane7dcdf022013-12-11 14:45:27 -080053 @staticmethod
54 def unpack(reader):
55 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080056 subclass = instruction.subtypes.get(subtype)
57 if subclass:
58 return subclass.unpack(reader)
59
60 obj = instruction()
61 obj.type = reader.read("!H")[0]
62 _len = reader.read("!H")[0]
63 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -080064 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -080065 reader.skip(4)
66 return obj
67
68 def __eq__(self, other):
69 if type(self) != type(other): return False
70 if self.type != other.type: return False
71 return True
72
73 def pretty_print(self, q):
74 q.text("instruction {")
75 with q.group():
76 with q.indent(2):
77 q.breakable()
78 q.breakable()
79 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070080
Rich Lane7dcdf022013-12-11 14:45:27 -080081
82class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070083 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070084
85 def __init__(self, actions=None):
86 if actions != None:
87 self.actions = actions
88 else:
89 self.actions = []
90 return
91
92 def pack(self):
93 packed = []
94 packed.append(struct.pack("!H", self.type))
95 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
96 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080097 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070098 length = sum([len(x) for x in packed])
99 packed[1] = struct.pack("!H", length)
100 return ''.join(packed)
101
102 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800103 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700104 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700105 _type = reader.read("!H")[0]
106 assert(_type == 4)
107 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800108 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800109 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700110 reader.skip(4)
Rich Lanee2567702015-01-26 15:04:35 -0800111 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700112 return obj
113
114 def __eq__(self, other):
115 if type(self) != type(other): return False
116 if self.actions != other.actions: return False
117 return True
118
Rich Laneca3da272013-05-05 09:07:33 -0700119 def pretty_print(self, q):
120 q.text("apply_actions {")
121 with q.group():
122 with q.indent(2):
123 q.breakable()
124 q.text("actions = ");
125 q.pp(self.actions)
126 q.breakable()
127 q.text('}')
128
Rich Lane7dcdf022013-12-11 14:45:27 -0800129instruction.subtypes[4] = apply_actions
130
131class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700132 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700133
134 def __init__(self):
135 return
136
137 def pack(self):
138 packed = []
139 packed.append(struct.pack("!H", self.type))
140 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
141 packed.append('\x00' * 4)
142 length = sum([len(x) for x in packed])
143 packed[1] = struct.pack("!H", length)
144 return ''.join(packed)
145
146 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800147 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700148 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700149 _type = reader.read("!H")[0]
150 assert(_type == 5)
151 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800152 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800153 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700154 reader.skip(4)
155 return obj
156
157 def __eq__(self, other):
158 if type(self) != type(other): return False
159 return True
160
Rich Laneca3da272013-05-05 09:07:33 -0700161 def pretty_print(self, q):
162 q.text("clear_actions {")
163 with q.group():
164 with q.indent(2):
165 q.breakable()
166 q.breakable()
167 q.text('}')
168
Rich Lane7dcdf022013-12-11 14:45:27 -0800169instruction.subtypes[5] = clear_actions
170
171class experimenter(instruction):
172 subtypes = {}
173
Rich Lane95f7fc92014-01-27 17:08:16 -0800174 type = 65535
175
176 def __init__(self, experimenter=None, data=None):
177 if experimenter != None:
178 self.experimenter = experimenter
179 else:
180 self.experimenter = 0
181 if data != None:
182 self.data = data
183 else:
184 self.data = ''
185 return
186
187 def pack(self):
188 packed = []
189 packed.append(struct.pack("!H", self.type))
190 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
191 packed.append(struct.pack("!L", self.experimenter))
192 packed.append(self.data)
193 length = sum([len(x) for x in packed])
194 packed[1] = struct.pack("!H", length)
195 return ''.join(packed)
196
Rich Lane7dcdf022013-12-11 14:45:27 -0800197 @staticmethod
198 def unpack(reader):
199 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800200 subclass = experimenter.subtypes.get(subtype)
201 if subclass:
202 return subclass.unpack(reader)
203
204 obj = experimenter()
205 _type = reader.read("!H")[0]
206 assert(_type == 65535)
207 _len = reader.read("!H")[0]
208 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800209 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800210 obj.experimenter = reader.read("!L")[0]
211 obj.data = str(reader.read_all())
212 return obj
213
214 def __eq__(self, other):
215 if type(self) != type(other): return False
216 if self.experimenter != other.experimenter: return False
217 if self.data != other.data: return False
218 return True
219
220 def pretty_print(self, q):
221 q.text("experimenter {")
222 with q.group():
223 with q.indent(2):
224 q.breakable()
225 q.text("data = ");
226 q.pp(self.data)
227 q.breakable()
228 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800229
230instruction.subtypes[65535] = experimenter
231
232class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700233 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700234
235 def __init__(self, table_id=None):
236 if table_id != None:
237 self.table_id = table_id
238 else:
239 self.table_id = 0
240 return
241
242 def pack(self):
243 packed = []
244 packed.append(struct.pack("!H", self.type))
245 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
246 packed.append(struct.pack("!B", self.table_id))
247 packed.append('\x00' * 3)
248 length = sum([len(x) for x in packed])
249 packed[1] = struct.pack("!H", length)
250 return ''.join(packed)
251
252 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800253 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700254 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700255 _type = reader.read("!H")[0]
256 assert(_type == 1)
257 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800258 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800259 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700260 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700261 reader.skip(3)
262 return obj
263
264 def __eq__(self, other):
265 if type(self) != type(other): return False
266 if self.table_id != other.table_id: return False
267 return True
268
Rich Laneca3da272013-05-05 09:07:33 -0700269 def pretty_print(self, q):
270 q.text("goto_table {")
271 with q.group():
272 with q.indent(2):
273 q.breakable()
274 q.text("table_id = ");
275 q.text("%#x" % self.table_id)
276 q.breakable()
277 q.text('}')
278
Rich Lane7dcdf022013-12-11 14:45:27 -0800279instruction.subtypes[1] = goto_table
280
281class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700282 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700283
284 def __init__(self, actions=None):
285 if actions != None:
286 self.actions = actions
287 else:
288 self.actions = []
289 return
290
291 def pack(self):
292 packed = []
293 packed.append(struct.pack("!H", self.type))
294 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
295 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800296 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700297 length = sum([len(x) for x in packed])
298 packed[1] = struct.pack("!H", length)
299 return ''.join(packed)
300
301 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800302 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700303 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700304 _type = reader.read("!H")[0]
305 assert(_type == 3)
306 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800307 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800308 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700309 reader.skip(4)
Rich Lanee2567702015-01-26 15:04:35 -0800310 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700311 return obj
312
313 def __eq__(self, other):
314 if type(self) != type(other): return False
315 if self.actions != other.actions: return False
316 return True
317
Rich Laneca3da272013-05-05 09:07:33 -0700318 def pretty_print(self, q):
319 q.text("write_actions {")
320 with q.group():
321 with q.indent(2):
322 q.breakable()
323 q.text("actions = ");
324 q.pp(self.actions)
325 q.breakable()
326 q.text('}')
327
Rich Lane7dcdf022013-12-11 14:45:27 -0800328instruction.subtypes[3] = write_actions
329
330class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700331 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700332
333 def __init__(self, metadata=None, metadata_mask=None):
334 if metadata != None:
335 self.metadata = metadata
336 else:
337 self.metadata = 0
338 if metadata_mask != None:
339 self.metadata_mask = metadata_mask
340 else:
341 self.metadata_mask = 0
342 return
343
344 def pack(self):
345 packed = []
346 packed.append(struct.pack("!H", self.type))
347 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
348 packed.append('\x00' * 4)
349 packed.append(struct.pack("!Q", self.metadata))
350 packed.append(struct.pack("!Q", self.metadata_mask))
351 length = sum([len(x) for x in packed])
352 packed[1] = struct.pack("!H", length)
353 return ''.join(packed)
354
355 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800356 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700357 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700358 _type = reader.read("!H")[0]
359 assert(_type == 2)
360 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800361 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800362 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700363 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700364 obj.metadata = reader.read("!Q")[0]
365 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700366 return obj
367
368 def __eq__(self, other):
369 if type(self) != type(other): return False
370 if self.metadata != other.metadata: return False
371 if self.metadata_mask != other.metadata_mask: return False
372 return True
373
Rich Laneca3da272013-05-05 09:07:33 -0700374 def pretty_print(self, q):
375 q.text("write_metadata {")
376 with q.group():
377 with q.indent(2):
378 q.breakable()
379 q.text("metadata = ");
380 q.text("%#x" % self.metadata)
381 q.text(","); q.breakable()
382 q.text("metadata_mask = ");
383 q.text("%#x" % self.metadata_mask)
384 q.breakable()
385 q.text('}')
386
Rich Lane7dcdf022013-12-11 14:45:27 -0800387instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700388
Rich Lane7b0f2012013-11-22 14:15:26 -0800389