blob: e36cc730fb134448690474d7259ddc2da390ada2 [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
15import oxm
16import action_id
17import instruction_id
18import meter_band
Rich Laneca3da272013-05-05 09:07:33 -070019import util
20import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070021
Rich Lane7dcdf022013-12-11 14:45:27 -080022class instruction(loxi.OFObject):
23 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070024
Rich Lane7dcdf022013-12-11 14:45:27 -080025 @staticmethod
26 def unpack(reader):
27 subtype, = reader.peek('!H', 0)
28 try:
29 subclass = instruction.subtypes[subtype]
30 except KeyError:
31 raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype)
32 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070033
Rich Lane7dcdf022013-12-11 14:45:27 -080034
35class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070036 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070037
38 def __init__(self, actions=None):
39 if actions != None:
40 self.actions = actions
41 else:
42 self.actions = []
43 return
44
45 def pack(self):
46 packed = []
47 packed.append(struct.pack("!H", self.type))
48 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
49 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080050 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070051 length = sum([len(x) for x in packed])
52 packed[1] = struct.pack("!H", length)
53 return ''.join(packed)
54
55 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080056 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070057 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070058 _type = reader.read("!H")[0]
59 assert(_type == 4)
60 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080061 orig_reader = reader
62 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070063 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080064 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070065 return obj
66
67 def __eq__(self, other):
68 if type(self) != type(other): return False
69 if self.actions != other.actions: return False
70 return True
71
Rich Laneca3da272013-05-05 09:07:33 -070072 def pretty_print(self, q):
73 q.text("apply_actions {")
74 with q.group():
75 with q.indent(2):
76 q.breakable()
77 q.text("actions = ");
78 q.pp(self.actions)
79 q.breakable()
80 q.text('}')
81
Rich Lane7dcdf022013-12-11 14:45:27 -080082instruction.subtypes[4] = apply_actions
83
84class experimenter(instruction):
85 subtypes = {}
86
87 @staticmethod
88 def unpack(reader):
89 subtype, = reader.peek('!L', 4)
90 try:
91 subclass = experimenter.subtypes[subtype]
92 except KeyError:
93 raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype)
94 return subclass.unpack(reader)
95
96instruction.subtypes[65535] = experimenter
97
98class bsn(experimenter):
99 subtypes = {}
100
101 @staticmethod
102 def unpack(reader):
103 subtype, = reader.peek('!L', 8)
104 try:
105 subclass = bsn.subtypes[subtype]
106 except KeyError:
107 raise loxi.ProtocolError("unknown bsn experimenter instruction subtype %#x" % subtype)
108 return subclass.unpack(reader)
109
110experimenter.subtypes[6035143] = bsn
111
112class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800113 type = 65535
114 experimenter = 6035143
115 subtype = 0
116
117 def __init__(self):
118 return
119
120 def pack(self):
121 packed = []
122 packed.append(struct.pack("!H", self.type))
123 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
124 packed.append(struct.pack("!L", self.experimenter))
125 packed.append(struct.pack("!L", self.subtype))
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 Lane7b0f2012013-11-22 14:15:26 -0800133 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800134 _type = reader.read("!H")[0]
135 assert(_type == 65535)
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 Lane7b0f2012013-11-22 14:15:26 -0800139 _experimenter = reader.read("!L")[0]
140 assert(_experimenter == 6035143)
141 _subtype = reader.read("!L")[0]
142 assert(_subtype == 0)
143 reader.skip(4)
144 return obj
145
146 def __eq__(self, other):
147 if type(self) != type(other): return False
148 return True
149
Rich Lane7b0f2012013-11-22 14:15:26 -0800150 def pretty_print(self, q):
151 q.text("bsn_disable_src_mac_check {")
152 with q.group():
153 with q.indent(2):
154 q.breakable()
155 q.breakable()
156 q.text('}')
157
Rich Lane7dcdf022013-12-11 14:45:27 -0800158bsn.subtypes[0] = bsn_disable_src_mac_check
159
160class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700161 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700162
163 def __init__(self):
164 return
165
166 def pack(self):
167 packed = []
168 packed.append(struct.pack("!H", self.type))
169 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
170 packed.append('\x00' * 4)
171 length = sum([len(x) for x in packed])
172 packed[1] = struct.pack("!H", length)
173 return ''.join(packed)
174
175 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800176 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700177 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700178 _type = reader.read("!H")[0]
179 assert(_type == 5)
180 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800181 orig_reader = reader
182 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700183 reader.skip(4)
184 return obj
185
186 def __eq__(self, other):
187 if type(self) != type(other): return False
188 return True
189
Rich Laneca3da272013-05-05 09:07:33 -0700190 def pretty_print(self, q):
191 q.text("clear_actions {")
192 with q.group():
193 with q.indent(2):
194 q.breakable()
195 q.breakable()
196 q.text('}')
197
Rich Lane7dcdf022013-12-11 14:45:27 -0800198instruction.subtypes[5] = clear_actions
199
200class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700201 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700202
203 def __init__(self, table_id=None):
204 if table_id != None:
205 self.table_id = table_id
206 else:
207 self.table_id = 0
208 return
209
210 def pack(self):
211 packed = []
212 packed.append(struct.pack("!H", self.type))
213 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
214 packed.append(struct.pack("!B", self.table_id))
215 packed.append('\x00' * 3)
216 length = sum([len(x) for x in packed])
217 packed[1] = struct.pack("!H", length)
218 return ''.join(packed)
219
220 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800221 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700222 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700223 _type = reader.read("!H")[0]
224 assert(_type == 1)
225 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800226 orig_reader = reader
227 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700228 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700229 reader.skip(3)
230 return obj
231
232 def __eq__(self, other):
233 if type(self) != type(other): return False
234 if self.table_id != other.table_id: return False
235 return True
236
Rich Laneca3da272013-05-05 09:07:33 -0700237 def pretty_print(self, q):
238 q.text("goto_table {")
239 with q.group():
240 with q.indent(2):
241 q.breakable()
242 q.text("table_id = ");
243 q.text("%#x" % self.table_id)
244 q.breakable()
245 q.text('}')
246
Rich Lane7dcdf022013-12-11 14:45:27 -0800247instruction.subtypes[1] = goto_table
248
249class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700250 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700251
252 def __init__(self, meter_id=None):
253 if meter_id != None:
254 self.meter_id = meter_id
255 else:
256 self.meter_id = 0
257 return
258
259 def pack(self):
260 packed = []
261 packed.append(struct.pack("!H", self.type))
262 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
263 packed.append(struct.pack("!L", self.meter_id))
264 length = sum([len(x) for x in packed])
265 packed[1] = struct.pack("!H", length)
266 return ''.join(packed)
267
268 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800269 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700270 obj = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700271 _type = reader.read("!H")[0]
272 assert(_type == 6)
273 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800274 orig_reader = reader
275 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700276 obj.meter_id = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700277 return obj
278
279 def __eq__(self, other):
280 if type(self) != type(other): return False
281 if self.meter_id != other.meter_id: return False
282 return True
283
Rich Laneca3da272013-05-05 09:07:33 -0700284 def pretty_print(self, q):
285 q.text("meter {")
286 with q.group():
287 with q.indent(2):
288 q.breakable()
289 q.text("meter_id = ");
290 q.text("%#x" % self.meter_id)
291 q.breakable()
292 q.text('}')
293
Rich Lane7dcdf022013-12-11 14:45:27 -0800294instruction.subtypes[6] = meter
295
296class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700297 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700298
299 def __init__(self, actions=None):
300 if actions != None:
301 self.actions = actions
302 else:
303 self.actions = []
304 return
305
306 def pack(self):
307 packed = []
308 packed.append(struct.pack("!H", self.type))
309 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
310 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800311 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700312 length = sum([len(x) for x in packed])
313 packed[1] = struct.pack("!H", length)
314 return ''.join(packed)
315
316 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800317 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700318 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700319 _type = reader.read("!H")[0]
320 assert(_type == 3)
321 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800322 orig_reader = reader
323 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700324 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800325 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700326 return obj
327
328 def __eq__(self, other):
329 if type(self) != type(other): return False
330 if self.actions != other.actions: return False
331 return True
332
Rich Laneca3da272013-05-05 09:07:33 -0700333 def pretty_print(self, q):
334 q.text("write_actions {")
335 with q.group():
336 with q.indent(2):
337 q.breakable()
338 q.text("actions = ");
339 q.pp(self.actions)
340 q.breakable()
341 q.text('}')
342
Rich Lane7dcdf022013-12-11 14:45:27 -0800343instruction.subtypes[3] = write_actions
344
345class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700346 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700347
348 def __init__(self, metadata=None, metadata_mask=None):
349 if metadata != None:
350 self.metadata = metadata
351 else:
352 self.metadata = 0
353 if metadata_mask != None:
354 self.metadata_mask = metadata_mask
355 else:
356 self.metadata_mask = 0
357 return
358
359 def pack(self):
360 packed = []
361 packed.append(struct.pack("!H", self.type))
362 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
363 packed.append('\x00' * 4)
364 packed.append(struct.pack("!Q", self.metadata))
365 packed.append(struct.pack("!Q", self.metadata_mask))
366 length = sum([len(x) for x in packed])
367 packed[1] = struct.pack("!H", length)
368 return ''.join(packed)
369
370 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800371 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700372 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700373 _type = reader.read("!H")[0]
374 assert(_type == 2)
375 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800376 orig_reader = reader
377 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700378 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700379 obj.metadata = reader.read("!Q")[0]
380 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700381 return obj
382
383 def __eq__(self, other):
384 if type(self) != type(other): return False
385 if self.metadata != other.metadata: return False
386 if self.metadata_mask != other.metadata_mask: return False
387 return True
388
Rich Laneca3da272013-05-05 09:07:33 -0700389 def pretty_print(self, q):
390 q.text("write_metadata {")
391 with q.group():
392 with q.indent(2):
393 q.breakable()
394 q.text("metadata = ");
395 q.text("%#x" % self.metadata)
396 q.text(","); q.breakable()
397 q.text("metadata_mask = ");
398 q.text("%#x" % self.metadata_mask)
399 q.breakable()
400 q.text('}')
401
Rich Lane7dcdf022013-12-11 14:45:27 -0800402instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700403
Rich Lane7b0f2012013-11-22 14:15:26 -0800404