blob: 3e5553a4d912cb775a1ee251c9ab15d0275203ee [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 Lane5454b682014-01-14 17:07:36 -080019import bsn_tlv
Rich Laneca3da272013-05-05 09:07:33 -070020import util
21import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070022
Rich Lane7dcdf022013-12-11 14:45:27 -080023class instruction(loxi.OFObject):
24 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070025
Rich Lane7dcdf022013-12-11 14:45:27 -080026 @staticmethod
27 def unpack(reader):
28 subtype, = reader.peek('!H', 0)
29 try:
30 subclass = instruction.subtypes[subtype]
31 except KeyError:
32 raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype)
33 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070034
Rich Lane7dcdf022013-12-11 14:45:27 -080035
36class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070037 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070038
39 def __init__(self, actions=None):
40 if actions != None:
41 self.actions = actions
42 else:
43 self.actions = []
44 return
45
46 def pack(self):
47 packed = []
48 packed.append(struct.pack("!H", self.type))
49 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
50 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080051 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070052 length = sum([len(x) for x in packed])
53 packed[1] = struct.pack("!H", length)
54 return ''.join(packed)
55
56 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080057 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070058 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070059 _type = reader.read("!H")[0]
60 assert(_type == 4)
61 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080062 orig_reader = reader
63 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070064 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080065 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070066 return obj
67
68 def __eq__(self, other):
69 if type(self) != type(other): return False
70 if self.actions != other.actions: return False
71 return True
72
Rich Laneca3da272013-05-05 09:07:33 -070073 def pretty_print(self, q):
74 q.text("apply_actions {")
75 with q.group():
76 with q.indent(2):
77 q.breakable()
78 q.text("actions = ");
79 q.pp(self.actions)
80 q.breakable()
81 q.text('}')
82
Rich Lane7dcdf022013-12-11 14:45:27 -080083instruction.subtypes[4] = apply_actions
84
85class experimenter(instruction):
86 subtypes = {}
87
88 @staticmethod
89 def unpack(reader):
90 subtype, = reader.peek('!L', 4)
91 try:
92 subclass = experimenter.subtypes[subtype]
93 except KeyError:
94 raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype)
95 return subclass.unpack(reader)
96
97instruction.subtypes[65535] = experimenter
98
99class bsn(experimenter):
100 subtypes = {}
101
102 @staticmethod
103 def unpack(reader):
104 subtype, = reader.peek('!L', 8)
105 try:
106 subclass = bsn.subtypes[subtype]
107 except KeyError:
108 raise loxi.ProtocolError("unknown bsn experimenter instruction subtype %#x" % subtype)
109 return subclass.unpack(reader)
110
111experimenter.subtypes[6035143] = bsn
112
Rich Lane5454b682014-01-14 17:07:36 -0800113class bsn_arp_offload(bsn):
114 type = 65535
115 experimenter = 6035143
116 subtype = 1
117
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(struct.pack("!L", self.experimenter))
126 packed.append(struct.pack("!L", self.subtype))
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
133 def unpack(reader):
134 obj = bsn_arp_offload()
135 _type = reader.read("!H")[0]
136 assert(_type == 65535)
137 _len = reader.read("!H")[0]
138 orig_reader = reader
139 reader = orig_reader.slice(_len - (2 + 2))
140 _experimenter = reader.read("!L")[0]
141 assert(_experimenter == 6035143)
142 _subtype = reader.read("!L")[0]
143 assert(_subtype == 1)
144 reader.skip(4)
145 return obj
146
147 def __eq__(self, other):
148 if type(self) != type(other): return False
149 return True
150
151 def pretty_print(self, q):
152 q.text("bsn_arp_offload {")
153 with q.group():
154 with q.indent(2):
155 q.breakable()
156 q.breakable()
157 q.text('}')
158
159bsn.subtypes[1] = bsn_arp_offload
160
Rich Lane7dcdf022013-12-11 14:45:27 -0800161class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800162 type = 65535
163 experimenter = 6035143
164 subtype = 0
165
166 def __init__(self):
167 return
168
169 def pack(self):
170 packed = []
171 packed.append(struct.pack("!H", self.type))
172 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
173 packed.append(struct.pack("!L", self.experimenter))
174 packed.append(struct.pack("!L", self.subtype))
175 packed.append('\x00' * 4)
176 length = sum([len(x) for x in packed])
177 packed[1] = struct.pack("!H", length)
178 return ''.join(packed)
179
180 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800181 def unpack(reader):
Rich Lane7b0f2012013-11-22 14:15:26 -0800182 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800183 _type = reader.read("!H")[0]
184 assert(_type == 65535)
185 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800186 orig_reader = reader
187 reader = orig_reader.slice(_len - (2 + 2))
Rich Lane7b0f2012013-11-22 14:15:26 -0800188 _experimenter = reader.read("!L")[0]
189 assert(_experimenter == 6035143)
190 _subtype = reader.read("!L")[0]
191 assert(_subtype == 0)
192 reader.skip(4)
193 return obj
194
195 def __eq__(self, other):
196 if type(self) != type(other): return False
197 return True
198
Rich Lane7b0f2012013-11-22 14:15:26 -0800199 def pretty_print(self, q):
200 q.text("bsn_disable_src_mac_check {")
201 with q.group():
202 with q.indent(2):
203 q.breakable()
204 q.breakable()
205 q.text('}')
206
Rich Lane7dcdf022013-12-11 14:45:27 -0800207bsn.subtypes[0] = bsn_disable_src_mac_check
208
209class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700210 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700211
212 def __init__(self):
213 return
214
215 def pack(self):
216 packed = []
217 packed.append(struct.pack("!H", self.type))
218 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
219 packed.append('\x00' * 4)
220 length = sum([len(x) for x in packed])
221 packed[1] = struct.pack("!H", length)
222 return ''.join(packed)
223
224 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800225 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700226 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700227 _type = reader.read("!H")[0]
228 assert(_type == 5)
229 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800230 orig_reader = reader
231 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700232 reader.skip(4)
233 return obj
234
235 def __eq__(self, other):
236 if type(self) != type(other): return False
237 return True
238
Rich Laneca3da272013-05-05 09:07:33 -0700239 def pretty_print(self, q):
240 q.text("clear_actions {")
241 with q.group():
242 with q.indent(2):
243 q.breakable()
244 q.breakable()
245 q.text('}')
246
Rich Lane7dcdf022013-12-11 14:45:27 -0800247instruction.subtypes[5] = clear_actions
248
249class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700250 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700251
252 def __init__(self, table_id=None):
253 if table_id != None:
254 self.table_id = table_id
255 else:
256 self.table_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("!B", self.table_id))
264 packed.append('\x00' * 3)
265 length = sum([len(x) for x in packed])
266 packed[1] = struct.pack("!H", length)
267 return ''.join(packed)
268
269 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800270 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700271 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700272 _type = reader.read("!H")[0]
273 assert(_type == 1)
274 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800275 orig_reader = reader
276 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700277 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700278 reader.skip(3)
279 return obj
280
281 def __eq__(self, other):
282 if type(self) != type(other): return False
283 if self.table_id != other.table_id: return False
284 return True
285
Rich Laneca3da272013-05-05 09:07:33 -0700286 def pretty_print(self, q):
287 q.text("goto_table {")
288 with q.group():
289 with q.indent(2):
290 q.breakable()
291 q.text("table_id = ");
292 q.text("%#x" % self.table_id)
293 q.breakable()
294 q.text('}')
295
Rich Lane7dcdf022013-12-11 14:45:27 -0800296instruction.subtypes[1] = goto_table
297
298class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700299 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700300
301 def __init__(self, meter_id=None):
302 if meter_id != None:
303 self.meter_id = meter_id
304 else:
305 self.meter_id = 0
306 return
307
308 def pack(self):
309 packed = []
310 packed.append(struct.pack("!H", self.type))
311 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
312 packed.append(struct.pack("!L", self.meter_id))
313 length = sum([len(x) for x in packed])
314 packed[1] = struct.pack("!H", length)
315 return ''.join(packed)
316
317 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800318 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700319 obj = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700320 _type = reader.read("!H")[0]
321 assert(_type == 6)
322 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800323 orig_reader = reader
324 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700325 obj.meter_id = reader.read("!L")[0]
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.meter_id != other.meter_id: return False
331 return True
332
Rich Laneca3da272013-05-05 09:07:33 -0700333 def pretty_print(self, q):
334 q.text("meter {")
335 with q.group():
336 with q.indent(2):
337 q.breakable()
338 q.text("meter_id = ");
339 q.text("%#x" % self.meter_id)
340 q.breakable()
341 q.text('}')
342
Rich Lane7dcdf022013-12-11 14:45:27 -0800343instruction.subtypes[6] = meter
344
345class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700346 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700347
348 def __init__(self, actions=None):
349 if actions != None:
350 self.actions = actions
351 else:
352 self.actions = []
353 return
354
355 def pack(self):
356 packed = []
357 packed.append(struct.pack("!H", self.type))
358 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
359 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800360 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700361 length = sum([len(x) for x in packed])
362 packed[1] = struct.pack("!H", length)
363 return ''.join(packed)
364
365 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800366 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700367 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700368 _type = reader.read("!H")[0]
369 assert(_type == 3)
370 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800371 orig_reader = reader
372 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700373 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800374 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700375 return obj
376
377 def __eq__(self, other):
378 if type(self) != type(other): return False
379 if self.actions != other.actions: return False
380 return True
381
Rich Laneca3da272013-05-05 09:07:33 -0700382 def pretty_print(self, q):
383 q.text("write_actions {")
384 with q.group():
385 with q.indent(2):
386 q.breakable()
387 q.text("actions = ");
388 q.pp(self.actions)
389 q.breakable()
390 q.text('}')
391
Rich Lane7dcdf022013-12-11 14:45:27 -0800392instruction.subtypes[3] = write_actions
393
394class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700395 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700396
397 def __init__(self, metadata=None, metadata_mask=None):
398 if metadata != None:
399 self.metadata = metadata
400 else:
401 self.metadata = 0
402 if metadata_mask != None:
403 self.metadata_mask = metadata_mask
404 else:
405 self.metadata_mask = 0
406 return
407
408 def pack(self):
409 packed = []
410 packed.append(struct.pack("!H", self.type))
411 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
412 packed.append('\x00' * 4)
413 packed.append(struct.pack("!Q", self.metadata))
414 packed.append(struct.pack("!Q", self.metadata_mask))
415 length = sum([len(x) for x in packed])
416 packed[1] = struct.pack("!H", length)
417 return ''.join(packed)
418
419 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800420 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700421 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700422 _type = reader.read("!H")[0]
423 assert(_type == 2)
424 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800425 orig_reader = reader
426 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700427 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700428 obj.metadata = reader.read("!Q")[0]
429 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700430 return obj
431
432 def __eq__(self, other):
433 if type(self) != type(other): return False
434 if self.metadata != other.metadata: return False
435 if self.metadata_mask != other.metadata_mask: return False
436 return True
437
Rich Laneca3da272013-05-05 09:07:33 -0700438 def pretty_print(self, q):
439 q.text("write_metadata {")
440 with q.group():
441 with q.indent(2):
442 q.breakable()
443 q.text("metadata = ");
444 q.text("%#x" % self.metadata)
445 q.text(","); q.breakable()
446 q.text("metadata_mask = ");
447 q.text("%#x" % self.metadata_mask)
448 q.breakable()
449 q.text('}')
450
Rich Lane7dcdf022013-12-11 14:45:27 -0800451instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700452
Rich Lane7b0f2012013-11-22 14:15:26 -0800453