blob: 06786ed750d61c962491d5d484efb7ad42d8a58c [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 action
Rich Lane7dcdf022013-12-11 14:45:27 -080013import oxm
Harshmeet Singh1db46332014-10-14 16:29:13 -070014import message
15import instruction
16import common
Rich Laneca3da272013-05-05 09:07:33 -070017import util
18import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070019
Rich Lane7dcdf022013-12-11 14:45:27 -080020class instruction(loxi.OFObject):
21 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070022
Rich Lane95f7fc92014-01-27 17:08:16 -080023
24 def __init__(self, type=None):
25 if type != None:
26 self.type = type
27 else:
28 self.type = 0
29 return
30
31 def pack(self):
32 packed = []
33 packed.append(struct.pack("!H", self.type))
34 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
35 packed.append('\x00' * 4)
36 length = sum([len(x) for x in packed])
37 packed[1] = struct.pack("!H", length)
38 return ''.join(packed)
39
Rich Lane7dcdf022013-12-11 14:45:27 -080040 @staticmethod
41 def unpack(reader):
42 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080043 subclass = instruction.subtypes.get(subtype)
44 if subclass:
45 return subclass.unpack(reader)
46
47 obj = instruction()
48 obj.type = reader.read("!H")[0]
49 _len = reader.read("!H")[0]
50 orig_reader = reader
51 reader = orig_reader.slice(_len - (2 + 2))
52 reader.skip(4)
53 return obj
54
55 def __eq__(self, other):
56 if type(self) != type(other): return False
57 if self.type != other.type: return False
58 return True
59
60 def pretty_print(self, q):
61 q.text("instruction {")
62 with q.group():
63 with q.indent(2):
64 q.breakable()
65 q.breakable()
66 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070067
Rich Lane7dcdf022013-12-11 14:45:27 -080068
69class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070070 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070071
72 def __init__(self, actions=None):
73 if actions != None:
74 self.actions = actions
75 else:
76 self.actions = []
77 return
78
79 def pack(self):
80 packed = []
81 packed.append(struct.pack("!H", self.type))
82 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
83 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080084 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070085 length = sum([len(x) for x in packed])
86 packed[1] = struct.pack("!H", length)
87 return ''.join(packed)
88
89 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080090 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070091 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070092 _type = reader.read("!H")[0]
93 assert(_type == 4)
94 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080095 orig_reader = reader
96 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070097 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080098 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070099 return obj
100
101 def __eq__(self, other):
102 if type(self) != type(other): return False
103 if self.actions != other.actions: return False
104 return True
105
Rich Laneca3da272013-05-05 09:07:33 -0700106 def pretty_print(self, q):
107 q.text("apply_actions {")
108 with q.group():
109 with q.indent(2):
110 q.breakable()
111 q.text("actions = ");
112 q.pp(self.actions)
113 q.breakable()
114 q.text('}')
115
Rich Lane7dcdf022013-12-11 14:45:27 -0800116instruction.subtypes[4] = apply_actions
117
118class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700119 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700120
121 def __init__(self):
122 return
123
124 def pack(self):
125 packed = []
126 packed.append(struct.pack("!H", self.type))
127 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
128 packed.append('\x00' * 4)
129 length = sum([len(x) for x in packed])
130 packed[1] = struct.pack("!H", length)
131 return ''.join(packed)
132
133 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800134 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700135 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700136 _type = reader.read("!H")[0]
137 assert(_type == 5)
138 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800139 orig_reader = reader
140 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700141 reader.skip(4)
142 return obj
143
144 def __eq__(self, other):
145 if type(self) != type(other): return False
146 return True
147
Rich Laneca3da272013-05-05 09:07:33 -0700148 def pretty_print(self, q):
149 q.text("clear_actions {")
150 with q.group():
151 with q.indent(2):
152 q.breakable()
153 q.breakable()
154 q.text('}')
155
Rich Lane7dcdf022013-12-11 14:45:27 -0800156instruction.subtypes[5] = clear_actions
157
158class experimenter(instruction):
159 subtypes = {}
160
Rich Lane95f7fc92014-01-27 17:08:16 -0800161 type = 65535
162
163 def __init__(self, experimenter=None, data=None):
164 if experimenter != None:
165 self.experimenter = experimenter
166 else:
167 self.experimenter = 0
168 if data != None:
169 self.data = data
170 else:
171 self.data = ''
172 return
173
174 def pack(self):
175 packed = []
176 packed.append(struct.pack("!H", self.type))
177 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
178 packed.append(struct.pack("!L", self.experimenter))
179 packed.append(self.data)
180 length = sum([len(x) for x in packed])
181 packed[1] = struct.pack("!H", length)
182 return ''.join(packed)
183
Rich Lane7dcdf022013-12-11 14:45:27 -0800184 @staticmethod
185 def unpack(reader):
186 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800187 subclass = experimenter.subtypes.get(subtype)
188 if subclass:
189 return subclass.unpack(reader)
190
191 obj = experimenter()
192 _type = reader.read("!H")[0]
193 assert(_type == 65535)
194 _len = reader.read("!H")[0]
195 orig_reader = reader
196 reader = orig_reader.slice(_len - (2 + 2))
197 obj.experimenter = reader.read("!L")[0]
198 obj.data = str(reader.read_all())
199 return obj
200
201 def __eq__(self, other):
202 if type(self) != type(other): return False
203 if self.experimenter != other.experimenter: return False
204 if self.data != other.data: return False
205 return True
206
207 def pretty_print(self, q):
208 q.text("experimenter {")
209 with q.group():
210 with q.indent(2):
211 q.breakable()
212 q.text("data = ");
213 q.pp(self.data)
214 q.breakable()
215 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800216
217instruction.subtypes[65535] = experimenter
218
219class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700220 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700221
222 def __init__(self, table_id=None):
223 if table_id != None:
224 self.table_id = table_id
225 else:
226 self.table_id = 0
227 return
228
229 def pack(self):
230 packed = []
231 packed.append(struct.pack("!H", self.type))
232 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
233 packed.append(struct.pack("!B", self.table_id))
234 packed.append('\x00' * 3)
235 length = sum([len(x) for x in packed])
236 packed[1] = struct.pack("!H", length)
237 return ''.join(packed)
238
239 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800240 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700241 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700242 _type = reader.read("!H")[0]
243 assert(_type == 1)
244 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800245 orig_reader = reader
246 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700247 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700248 reader.skip(3)
249 return obj
250
251 def __eq__(self, other):
252 if type(self) != type(other): return False
253 if self.table_id != other.table_id: return False
254 return True
255
Rich Laneca3da272013-05-05 09:07:33 -0700256 def pretty_print(self, q):
257 q.text("goto_table {")
258 with q.group():
259 with q.indent(2):
260 q.breakable()
261 q.text("table_id = ");
262 q.text("%#x" % self.table_id)
263 q.breakable()
264 q.text('}')
265
Rich Lane7dcdf022013-12-11 14:45:27 -0800266instruction.subtypes[1] = goto_table
267
268class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700269 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700270
271 def __init__(self, actions=None):
272 if actions != None:
273 self.actions = actions
274 else:
275 self.actions = []
276 return
277
278 def pack(self):
279 packed = []
280 packed.append(struct.pack("!H", self.type))
281 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
282 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800283 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700284 length = sum([len(x) for x in packed])
285 packed[1] = struct.pack("!H", length)
286 return ''.join(packed)
287
288 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800289 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700290 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700291 _type = reader.read("!H")[0]
292 assert(_type == 3)
293 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800294 orig_reader = reader
295 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700296 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800297 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700298 return obj
299
300 def __eq__(self, other):
301 if type(self) != type(other): return False
302 if self.actions != other.actions: return False
303 return True
304
Rich Laneca3da272013-05-05 09:07:33 -0700305 def pretty_print(self, q):
306 q.text("write_actions {")
307 with q.group():
308 with q.indent(2):
309 q.breakable()
310 q.text("actions = ");
311 q.pp(self.actions)
312 q.breakable()
313 q.text('}')
314
Rich Lane7dcdf022013-12-11 14:45:27 -0800315instruction.subtypes[3] = write_actions
316
317class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700318 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700319
320 def __init__(self, metadata=None, metadata_mask=None):
321 if metadata != None:
322 self.metadata = metadata
323 else:
324 self.metadata = 0
325 if metadata_mask != None:
326 self.metadata_mask = metadata_mask
327 else:
328 self.metadata_mask = 0
329 return
330
331 def pack(self):
332 packed = []
333 packed.append(struct.pack("!H", self.type))
334 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
335 packed.append('\x00' * 4)
336 packed.append(struct.pack("!Q", self.metadata))
337 packed.append(struct.pack("!Q", self.metadata_mask))
338 length = sum([len(x) for x in packed])
339 packed[1] = struct.pack("!H", length)
340 return ''.join(packed)
341
342 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800343 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700344 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700345 _type = reader.read("!H")[0]
346 assert(_type == 2)
347 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800348 orig_reader = reader
349 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700350 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700351 obj.metadata = reader.read("!Q")[0]
352 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700353 return obj
354
355 def __eq__(self, other):
356 if type(self) != type(other): return False
357 if self.metadata != other.metadata: return False
358 if self.metadata_mask != other.metadata_mask: return False
359 return True
360
Rich Laneca3da272013-05-05 09:07:33 -0700361 def pretty_print(self, q):
362 q.text("write_metadata {")
363 with q.group():
364 with q.indent(2):
365 q.breakable()
366 q.text("metadata = ");
367 q.text("%#x" % self.metadata)
368 q.text(","); q.breakable()
369 q.text("metadata_mask = ");
370 q.text("%#x" % self.metadata_mask)
371 q.breakable()
372 q.text('}')
373
Rich Lane7dcdf022013-12-11 14:45:27 -0800374instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700375
Rich Lane7b0f2012013-11-22 14:15:26 -0800376