blob: 8fec8ae45e18b147efa0c02e49cf8b23fd30a90b [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
Rich Lane7dcdf022013-12-11 14:45:27 -08006# Automatically generated by LOXI from template module.py
Rich Laneca3da272013-05-05 09:07:33 -07007# Do not modify
8
9import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Laneca3da272013-05-05 09:07:33 -070011import util
12import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070013
Rich Lanee2567702015-01-26 15:04:35 -080014import sys
15ofp = sys.modules['loxi.of11']
16
Rich Lane7dcdf022013-12-11 14:45:27 -080017class instruction(loxi.OFObject):
18 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070019
Rich Lane95f7fc92014-01-27 17:08:16 -080020
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
Rich Lane7dcdf022013-12-11 14:45:27 -080037 @staticmethod
38 def unpack(reader):
39 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080040 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
Rich Lanecb18dbd2014-12-18 10:02:29 -080048 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -080049 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('}')
Rich Laneca3da272013-05-05 09:07:33 -070064
Rich Lane7dcdf022013-12-11 14:45:27 -080065
66class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070067 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070068
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)
Rich Lane7dcdf022013-12-11 14:45:27 -080081 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070082 length = sum([len(x) for x in packed])
83 packed[1] = struct.pack("!H", length)
84 return ''.join(packed)
85
86 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080087 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070088 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070089 _type = reader.read("!H")[0]
90 assert(_type == 4)
91 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080092 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -080093 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -070094 reader.skip(4)
Rich Lanee2567702015-01-26 15:04:35 -080095 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070096 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
Rich Laneca3da272013-05-05 09:07:33 -0700103 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800113instruction.subtypes[4] = apply_actions
114
115class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700116 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700117
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
Rich Lane7dcdf022013-12-11 14:45:27 -0800131 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700132 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700133 _type = reader.read("!H")[0]
134 assert(_type == 5)
135 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800136 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800137 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700138 reader.skip(4)
139 return obj
140
141 def __eq__(self, other):
142 if type(self) != type(other): return False
143 return True
144
Rich Laneca3da272013-05-05 09:07:33 -0700145 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800153instruction.subtypes[5] = clear_actions
154
155class experimenter(instruction):
156 subtypes = {}
157
Rich Lane95f7fc92014-01-27 17:08:16 -0800158 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800181 @staticmethod
182 def unpack(reader):
183 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800184 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
Rich Lanecb18dbd2014-12-18 10:02:29 -0800193 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800194 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('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800213
214instruction.subtypes[65535] = experimenter
215
216class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700217 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700218
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
Rich Lane7dcdf022013-12-11 14:45:27 -0800237 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700238 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700239 _type = reader.read("!H")[0]
240 assert(_type == 1)
241 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800242 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800243 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700244 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700245 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
Rich Laneca3da272013-05-05 09:07:33 -0700253 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800263instruction.subtypes[1] = goto_table
264
265class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700266 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700267
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)
Rich Lane7dcdf022013-12-11 14:45:27 -0800280 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700281 length = sum([len(x) for x in packed])
282 packed[1] = struct.pack("!H", length)
283 return ''.join(packed)
284
285 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800286 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700287 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700288 _type = reader.read("!H")[0]
289 assert(_type == 3)
290 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800291 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800292 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700293 reader.skip(4)
Rich Lanee2567702015-01-26 15:04:35 -0800294 obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700295 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
Rich Laneca3da272013-05-05 09:07:33 -0700302 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800312instruction.subtypes[3] = write_actions
313
314class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700315 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700316
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
Rich Lane7dcdf022013-12-11 14:45:27 -0800340 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700341 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700342 _type = reader.read("!H")[0]
343 assert(_type == 2)
344 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800345 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800346 reader = orig_reader.slice(_len, 4)
Rich Laneca3da272013-05-05 09:07:33 -0700347 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700348 obj.metadata = reader.read("!Q")[0]
349 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700350 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
Rich Laneca3da272013-05-05 09:07:33 -0700358 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
Rich Lane7dcdf022013-12-11 14:45:27 -0800371instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700372
Rich Lane7b0f2012013-11-22 14:15:26 -0800373