blob: 07359f836c5ff56187d3128936ea8b1a9125b3b7 [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 const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
14import instruction
Rich Laneca3da272013-05-05 09:07:33 -070015import util
16import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070017
Rich Lane7dcdf022013-12-11 14:45:27 -080018class instruction(loxi.OFObject):
19 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070020
Rich Lane95f7fc92014-01-27 17:08:16 -080021
22 def __init__(self, type=None):
23 if type != None:
24 self.type = type
25 else:
26 self.type = 0
27 return
28
29 def pack(self):
30 packed = []
31 packed.append(struct.pack("!H", self.type))
32 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
33 packed.append('\x00' * 4)
34 length = sum([len(x) for x in packed])
35 packed[1] = struct.pack("!H", length)
36 return ''.join(packed)
37
Rich Lane7dcdf022013-12-11 14:45:27 -080038 @staticmethod
39 def unpack(reader):
40 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080041 subclass = instruction.subtypes.get(subtype)
42 if subclass:
43 return subclass.unpack(reader)
44
45 obj = instruction()
46 obj.type = reader.read("!H")[0]
47 _len = reader.read("!H")[0]
48 orig_reader = reader
49 reader = orig_reader.slice(_len - (2 + 2))
50 reader.skip(4)
51 return obj
52
53 def __eq__(self, other):
54 if type(self) != type(other): return False
55 if self.type != other.type: return False
56 return True
57
58 def pretty_print(self, q):
59 q.text("instruction {")
60 with q.group():
61 with q.indent(2):
62 q.breakable()
63 q.breakable()
64 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070065
Rich Lane7dcdf022013-12-11 14:45:27 -080066
67class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070068 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070069
70 def __init__(self, actions=None):
71 if actions != None:
72 self.actions = actions
73 else:
74 self.actions = []
75 return
76
77 def pack(self):
78 packed = []
79 packed.append(struct.pack("!H", self.type))
80 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
81 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080082 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070083 length = sum([len(x) for x in packed])
84 packed[1] = struct.pack("!H", length)
85 return ''.join(packed)
86
87 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080088 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070089 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070090 _type = reader.read("!H")[0]
91 assert(_type == 4)
92 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080093 orig_reader = reader
94 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070095 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080096 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070097 return obj
98
99 def __eq__(self, other):
100 if type(self) != type(other): return False
101 if self.actions != other.actions: return False
102 return True
103
Rich Laneca3da272013-05-05 09:07:33 -0700104 def pretty_print(self, q):
105 q.text("apply_actions {")
106 with q.group():
107 with q.indent(2):
108 q.breakable()
109 q.text("actions = ");
110 q.pp(self.actions)
111 q.breakable()
112 q.text('}')
113
Rich Lane7dcdf022013-12-11 14:45:27 -0800114instruction.subtypes[4] = apply_actions
115
116class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700117 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700118
119 def __init__(self):
120 return
121
122 def pack(self):
123 packed = []
124 packed.append(struct.pack("!H", self.type))
125 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
126 packed.append('\x00' * 4)
127 length = sum([len(x) for x in packed])
128 packed[1] = struct.pack("!H", length)
129 return ''.join(packed)
130
131 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800132 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700133 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700134 _type = reader.read("!H")[0]
135 assert(_type == 5)
136 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800137 orig_reader = reader
138 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700139 reader.skip(4)
140 return obj
141
142 def __eq__(self, other):
143 if type(self) != type(other): return False
144 return True
145
Rich Laneca3da272013-05-05 09:07:33 -0700146 def pretty_print(self, q):
147 q.text("clear_actions {")
148 with q.group():
149 with q.indent(2):
150 q.breakable()
151 q.breakable()
152 q.text('}')
153
Rich Lane7dcdf022013-12-11 14:45:27 -0800154instruction.subtypes[5] = clear_actions
155
156class experimenter(instruction):
157 subtypes = {}
158
Rich Lane95f7fc92014-01-27 17:08:16 -0800159 type = 65535
160
161 def __init__(self, experimenter=None, data=None):
162 if experimenter != None:
163 self.experimenter = experimenter
164 else:
165 self.experimenter = 0
166 if data != None:
167 self.data = data
168 else:
169 self.data = ''
170 return
171
172 def pack(self):
173 packed = []
174 packed.append(struct.pack("!H", self.type))
175 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
176 packed.append(struct.pack("!L", self.experimenter))
177 packed.append(self.data)
178 length = sum([len(x) for x in packed])
179 packed[1] = struct.pack("!H", length)
180 return ''.join(packed)
181
Rich Lane7dcdf022013-12-11 14:45:27 -0800182 @staticmethod
183 def unpack(reader):
184 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800185 subclass = experimenter.subtypes.get(subtype)
186 if subclass:
187 return subclass.unpack(reader)
188
189 obj = experimenter()
190 _type = reader.read("!H")[0]
191 assert(_type == 65535)
192 _len = reader.read("!H")[0]
193 orig_reader = reader
194 reader = orig_reader.slice(_len - (2 + 2))
195 obj.experimenter = reader.read("!L")[0]
196 obj.data = str(reader.read_all())
197 return obj
198
199 def __eq__(self, other):
200 if type(self) != type(other): return False
201 if self.experimenter != other.experimenter: return False
202 if self.data != other.data: return False
203 return True
204
205 def pretty_print(self, q):
206 q.text("experimenter {")
207 with q.group():
208 with q.indent(2):
209 q.breakable()
210 q.text("data = ");
211 q.pp(self.data)
212 q.breakable()
213 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800214
215instruction.subtypes[65535] = experimenter
216
217class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700218 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700219
220 def __init__(self, table_id=None):
221 if table_id != None:
222 self.table_id = table_id
223 else:
224 self.table_id = 0
225 return
226
227 def pack(self):
228 packed = []
229 packed.append(struct.pack("!H", self.type))
230 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
231 packed.append(struct.pack("!B", self.table_id))
232 packed.append('\x00' * 3)
233 length = sum([len(x) for x in packed])
234 packed[1] = struct.pack("!H", length)
235 return ''.join(packed)
236
237 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800238 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700239 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700240 _type = reader.read("!H")[0]
241 assert(_type == 1)
242 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800243 orig_reader = reader
244 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700245 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700246 reader.skip(3)
247 return obj
248
249 def __eq__(self, other):
250 if type(self) != type(other): return False
251 if self.table_id != other.table_id: return False
252 return True
253
Rich Laneca3da272013-05-05 09:07:33 -0700254 def pretty_print(self, q):
255 q.text("goto_table {")
256 with q.group():
257 with q.indent(2):
258 q.breakable()
259 q.text("table_id = ");
260 q.text("%#x" % self.table_id)
261 q.breakable()
262 q.text('}')
263
Rich Lane7dcdf022013-12-11 14:45:27 -0800264instruction.subtypes[1] = goto_table
265
266class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700267 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700268
269 def __init__(self, actions=None):
270 if actions != None:
271 self.actions = actions
272 else:
273 self.actions = []
274 return
275
276 def pack(self):
277 packed = []
278 packed.append(struct.pack("!H", self.type))
279 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
280 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800281 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700282 length = sum([len(x) for x in packed])
283 packed[1] = struct.pack("!H", length)
284 return ''.join(packed)
285
286 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800287 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700288 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700289 _type = reader.read("!H")[0]
290 assert(_type == 3)
291 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800292 orig_reader = reader
293 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700294 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800295 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700296 return obj
297
298 def __eq__(self, other):
299 if type(self) != type(other): return False
300 if self.actions != other.actions: return False
301 return True
302
Rich Laneca3da272013-05-05 09:07:33 -0700303 def pretty_print(self, q):
304 q.text("write_actions {")
305 with q.group():
306 with q.indent(2):
307 q.breakable()
308 q.text("actions = ");
309 q.pp(self.actions)
310 q.breakable()
311 q.text('}')
312
Rich Lane7dcdf022013-12-11 14:45:27 -0800313instruction.subtypes[3] = write_actions
314
315class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700316 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700317
318 def __init__(self, metadata=None, metadata_mask=None):
319 if metadata != None:
320 self.metadata = metadata
321 else:
322 self.metadata = 0
323 if metadata_mask != None:
324 self.metadata_mask = metadata_mask
325 else:
326 self.metadata_mask = 0
327 return
328
329 def pack(self):
330 packed = []
331 packed.append(struct.pack("!H", self.type))
332 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
333 packed.append('\x00' * 4)
334 packed.append(struct.pack("!Q", self.metadata))
335 packed.append(struct.pack("!Q", self.metadata_mask))
336 length = sum([len(x) for x in packed])
337 packed[1] = struct.pack("!H", length)
338 return ''.join(packed)
339
340 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800341 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700342 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700343 _type = reader.read("!H")[0]
344 assert(_type == 2)
345 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800346 orig_reader = reader
347 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700348 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700349 obj.metadata = reader.read("!Q")[0]
350 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700351 return obj
352
353 def __eq__(self, other):
354 if type(self) != type(other): return False
355 if self.metadata != other.metadata: return False
356 if self.metadata_mask != other.metadata_mask: return False
357 return True
358
Rich Laneca3da272013-05-05 09:07:33 -0700359 def pretty_print(self, q):
360 q.text("write_metadata {")
361 with q.group():
362 with q.indent(2):
363 q.breakable()
364 q.text("metadata = ");
365 q.text("%#x" % self.metadata)
366 q.text(","); q.breakable()
367 q.text("metadata_mask = ");
368 q.text("%#x" % self.metadata_mask)
369 q.breakable()
370 q.text('}')
371
Rich Lane7dcdf022013-12-11 14:45:27 -0800372instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700373
Rich Lane7b0f2012013-11-22 14:15:26 -0800374