blob: e4d2fb05c3cf9a471f5f53100322e8166dfdde7e [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
Harshmeet Singh1db46332014-10-14 16:29:13 -070013import message
Rich Lane7dcdf022013-12-11 14:45:27 -080014import instruction
Harshmeet Singh1db46332014-10-14 16:29:13 -070015import common
Rich Laneca3da272013-05-05 09:07:33 -070016import util
17import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070018
Rich Lane7dcdf022013-12-11 14:45:27 -080019class instruction(loxi.OFObject):
20 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070021
Rich Lane95f7fc92014-01-27 17:08:16 -080022
23 def __init__(self, type=None):
24 if type != None:
25 self.type = type
26 else:
27 self.type = 0
28 return
29
30 def pack(self):
31 packed = []
32 packed.append(struct.pack("!H", self.type))
33 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
34 packed.append('\x00' * 4)
35 length = sum([len(x) for x in packed])
36 packed[1] = struct.pack("!H", length)
37 return ''.join(packed)
38
Rich Lane7dcdf022013-12-11 14:45:27 -080039 @staticmethod
40 def unpack(reader):
41 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080042 subclass = instruction.subtypes.get(subtype)
43 if subclass:
44 return subclass.unpack(reader)
45
46 obj = instruction()
47 obj.type = reader.read("!H")[0]
48 _len = reader.read("!H")[0]
49 orig_reader = reader
50 reader = orig_reader.slice(_len - (2 + 2))
51 reader.skip(4)
52 return obj
53
54 def __eq__(self, other):
55 if type(self) != type(other): return False
56 if self.type != other.type: return False
57 return True
58
59 def pretty_print(self, q):
60 q.text("instruction {")
61 with q.group():
62 with q.indent(2):
63 q.breakable()
64 q.breakable()
65 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070066
Rich Lane7dcdf022013-12-11 14:45:27 -080067
68class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070069 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070070
71 def __init__(self, actions=None):
72 if actions != None:
73 self.actions = actions
74 else:
75 self.actions = []
76 return
77
78 def pack(self):
79 packed = []
80 packed.append(struct.pack("!H", self.type))
81 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
82 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080083 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070084 length = sum([len(x) for x in packed])
85 packed[1] = struct.pack("!H", length)
86 return ''.join(packed)
87
88 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080089 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070090 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070091 _type = reader.read("!H")[0]
92 assert(_type == 4)
93 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080094 orig_reader = reader
95 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070096 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080097 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070098 return obj
99
100 def __eq__(self, other):
101 if type(self) != type(other): return False
102 if self.actions != other.actions: return False
103 return True
104
Rich Laneca3da272013-05-05 09:07:33 -0700105 def pretty_print(self, q):
106 q.text("apply_actions {")
107 with q.group():
108 with q.indent(2):
109 q.breakable()
110 q.text("actions = ");
111 q.pp(self.actions)
112 q.breakable()
113 q.text('}')
114
Rich Lane7dcdf022013-12-11 14:45:27 -0800115instruction.subtypes[4] = apply_actions
116
117class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700118 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700119
120 def __init__(self):
121 return
122
123 def pack(self):
124 packed = []
125 packed.append(struct.pack("!H", self.type))
126 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
127 packed.append('\x00' * 4)
128 length = sum([len(x) for x in packed])
129 packed[1] = struct.pack("!H", length)
130 return ''.join(packed)
131
132 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800133 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700134 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700135 _type = reader.read("!H")[0]
136 assert(_type == 5)
137 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800138 orig_reader = reader
139 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700140 reader.skip(4)
141 return obj
142
143 def __eq__(self, other):
144 if type(self) != type(other): return False
145 return True
146
Rich Laneca3da272013-05-05 09:07:33 -0700147 def pretty_print(self, q):
148 q.text("clear_actions {")
149 with q.group():
150 with q.indent(2):
151 q.breakable()
152 q.breakable()
153 q.text('}')
154
Rich Lane7dcdf022013-12-11 14:45:27 -0800155instruction.subtypes[5] = clear_actions
156
157class experimenter(instruction):
158 subtypes = {}
159
Rich Lane95f7fc92014-01-27 17:08:16 -0800160 type = 65535
161
162 def __init__(self, experimenter=None, data=None):
163 if experimenter != None:
164 self.experimenter = experimenter
165 else:
166 self.experimenter = 0
167 if data != None:
168 self.data = data
169 else:
170 self.data = ''
171 return
172
173 def pack(self):
174 packed = []
175 packed.append(struct.pack("!H", self.type))
176 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
177 packed.append(struct.pack("!L", self.experimenter))
178 packed.append(self.data)
179 length = sum([len(x) for x in packed])
180 packed[1] = struct.pack("!H", length)
181 return ''.join(packed)
182
Rich Lane7dcdf022013-12-11 14:45:27 -0800183 @staticmethod
184 def unpack(reader):
185 subtype, = reader.peek('!L', 4)
Rich Lane95f7fc92014-01-27 17:08:16 -0800186 subclass = experimenter.subtypes.get(subtype)
187 if subclass:
188 return subclass.unpack(reader)
189
190 obj = experimenter()
191 _type = reader.read("!H")[0]
192 assert(_type == 65535)
193 _len = reader.read("!H")[0]
194 orig_reader = reader
195 reader = orig_reader.slice(_len - (2 + 2))
196 obj.experimenter = reader.read("!L")[0]
197 obj.data = str(reader.read_all())
198 return obj
199
200 def __eq__(self, other):
201 if type(self) != type(other): return False
202 if self.experimenter != other.experimenter: return False
203 if self.data != other.data: return False
204 return True
205
206 def pretty_print(self, q):
207 q.text("experimenter {")
208 with q.group():
209 with q.indent(2):
210 q.breakable()
211 q.text("data = ");
212 q.pp(self.data)
213 q.breakable()
214 q.text('}')
Rich Lane7dcdf022013-12-11 14:45:27 -0800215
216instruction.subtypes[65535] = experimenter
217
218class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700219 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700220
221 def __init__(self, table_id=None):
222 if table_id != None:
223 self.table_id = table_id
224 else:
225 self.table_id = 0
226 return
227
228 def pack(self):
229 packed = []
230 packed.append(struct.pack("!H", self.type))
231 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
232 packed.append(struct.pack("!B", self.table_id))
233 packed.append('\x00' * 3)
234 length = sum([len(x) for x in packed])
235 packed[1] = struct.pack("!H", length)
236 return ''.join(packed)
237
238 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800239 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700240 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700241 _type = reader.read("!H")[0]
242 assert(_type == 1)
243 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800244 orig_reader = reader
245 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700246 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700247 reader.skip(3)
248 return obj
249
250 def __eq__(self, other):
251 if type(self) != type(other): return False
252 if self.table_id != other.table_id: return False
253 return True
254
Rich Laneca3da272013-05-05 09:07:33 -0700255 def pretty_print(self, q):
256 q.text("goto_table {")
257 with q.group():
258 with q.indent(2):
259 q.breakable()
260 q.text("table_id = ");
261 q.text("%#x" % self.table_id)
262 q.breakable()
263 q.text('}')
264
Rich Lane7dcdf022013-12-11 14:45:27 -0800265instruction.subtypes[1] = goto_table
266
267class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700268 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700269
270 def __init__(self, actions=None):
271 if actions != None:
272 self.actions = actions
273 else:
274 self.actions = []
275 return
276
277 def pack(self):
278 packed = []
279 packed.append(struct.pack("!H", self.type))
280 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
281 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800282 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700283 length = sum([len(x) for x in packed])
284 packed[1] = struct.pack("!H", length)
285 return ''.join(packed)
286
287 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800288 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700289 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700290 _type = reader.read("!H")[0]
291 assert(_type == 3)
292 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800293 orig_reader = reader
294 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700295 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800296 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700297 return obj
298
299 def __eq__(self, other):
300 if type(self) != type(other): return False
301 if self.actions != other.actions: return False
302 return True
303
Rich Laneca3da272013-05-05 09:07:33 -0700304 def pretty_print(self, q):
305 q.text("write_actions {")
306 with q.group():
307 with q.indent(2):
308 q.breakable()
309 q.text("actions = ");
310 q.pp(self.actions)
311 q.breakable()
312 q.text('}')
313
Rich Lane7dcdf022013-12-11 14:45:27 -0800314instruction.subtypes[3] = write_actions
315
316class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700317 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700318
319 def __init__(self, metadata=None, metadata_mask=None):
320 if metadata != None:
321 self.metadata = metadata
322 else:
323 self.metadata = 0
324 if metadata_mask != None:
325 self.metadata_mask = metadata_mask
326 else:
327 self.metadata_mask = 0
328 return
329
330 def pack(self):
331 packed = []
332 packed.append(struct.pack("!H", self.type))
333 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
334 packed.append('\x00' * 4)
335 packed.append(struct.pack("!Q", self.metadata))
336 packed.append(struct.pack("!Q", self.metadata_mask))
337 length = sum([len(x) for x in packed])
338 packed[1] = struct.pack("!H", length)
339 return ''.join(packed)
340
341 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800342 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700343 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700344 _type = reader.read("!H")[0]
345 assert(_type == 2)
346 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800347 orig_reader = reader
348 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700349 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700350 obj.metadata = reader.read("!Q")[0]
351 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700352 return obj
353
354 def __eq__(self, other):
355 if type(self) != type(other): return False
356 if self.metadata != other.metadata: return False
357 if self.metadata_mask != other.metadata_mask: return False
358 return True
359
Rich Laneca3da272013-05-05 09:07:33 -0700360 def pretty_print(self, q):
361 q.text("write_metadata {")
362 with q.group():
363 with q.indent(2):
364 q.breakable()
365 q.text("metadata = ");
366 q.text("%#x" % self.metadata)
367 q.text(","); q.breakable()
368 q.text("metadata_mask = ");
369 q.text("%#x" % self.metadata_mask)
370 q.breakable()
371 q.text('}')
372
Rich Lane7dcdf022013-12-11 14:45:27 -0800373instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700374
Rich Lane7b0f2012013-11-22 14:15:26 -0800375