blob: 7004dba47059addc503e30227666da8fe9212d57 [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 Lane1a820412014-01-06 14:15:07 -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
113class bsn_disable_src_mac_check(bsn):
Rich Lane7b0f2012013-11-22 14:15:26 -0800114 type = 65535
115 experimenter = 6035143
116 subtype = 0
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
Rich Lane7dcdf022013-12-11 14:45:27 -0800133 def unpack(reader):
Rich Lane7b0f2012013-11-22 14:15:26 -0800134 obj = bsn_disable_src_mac_check()
Rich Lane7b0f2012013-11-22 14:15:26 -0800135 _type = reader.read("!H")[0]
136 assert(_type == 65535)
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 Lane7b0f2012013-11-22 14:15:26 -0800140 _experimenter = reader.read("!L")[0]
141 assert(_experimenter == 6035143)
142 _subtype = reader.read("!L")[0]
143 assert(_subtype == 0)
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
Rich Lane7b0f2012013-11-22 14:15:26 -0800151 def pretty_print(self, q):
152 q.text("bsn_disable_src_mac_check {")
153 with q.group():
154 with q.indent(2):
155 q.breakable()
156 q.breakable()
157 q.text('}')
158
Rich Lane7dcdf022013-12-11 14:45:27 -0800159bsn.subtypes[0] = bsn_disable_src_mac_check
160
161class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700162 type = 5
Rich Laneca3da272013-05-05 09:07:33 -0700163
164 def __init__(self):
165 return
166
167 def pack(self):
168 packed = []
169 packed.append(struct.pack("!H", self.type))
170 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
171 packed.append('\x00' * 4)
172 length = sum([len(x) for x in packed])
173 packed[1] = struct.pack("!H", length)
174 return ''.join(packed)
175
176 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800177 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700178 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700179 _type = reader.read("!H")[0]
180 assert(_type == 5)
181 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800182 orig_reader = reader
183 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700184 reader.skip(4)
185 return obj
186
187 def __eq__(self, other):
188 if type(self) != type(other): return False
189 return True
190
Rich Laneca3da272013-05-05 09:07:33 -0700191 def pretty_print(self, q):
192 q.text("clear_actions {")
193 with q.group():
194 with q.indent(2):
195 q.breakable()
196 q.breakable()
197 q.text('}')
198
Rich Lane7dcdf022013-12-11 14:45:27 -0800199instruction.subtypes[5] = clear_actions
200
201class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700202 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700203
204 def __init__(self, table_id=None):
205 if table_id != None:
206 self.table_id = table_id
207 else:
208 self.table_id = 0
209 return
210
211 def pack(self):
212 packed = []
213 packed.append(struct.pack("!H", self.type))
214 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
215 packed.append(struct.pack("!B", self.table_id))
216 packed.append('\x00' * 3)
217 length = sum([len(x) for x in packed])
218 packed[1] = struct.pack("!H", length)
219 return ''.join(packed)
220
221 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800222 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700223 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700224 _type = reader.read("!H")[0]
225 assert(_type == 1)
226 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800227 orig_reader = reader
228 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700229 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700230 reader.skip(3)
231 return obj
232
233 def __eq__(self, other):
234 if type(self) != type(other): return False
235 if self.table_id != other.table_id: return False
236 return True
237
Rich Laneca3da272013-05-05 09:07:33 -0700238 def pretty_print(self, q):
239 q.text("goto_table {")
240 with q.group():
241 with q.indent(2):
242 q.breakable()
243 q.text("table_id = ");
244 q.text("%#x" % self.table_id)
245 q.breakable()
246 q.text('}')
247
Rich Lane7dcdf022013-12-11 14:45:27 -0800248instruction.subtypes[1] = goto_table
249
250class meter(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700251 type = 6
Rich Laneca3da272013-05-05 09:07:33 -0700252
253 def __init__(self, meter_id=None):
254 if meter_id != None:
255 self.meter_id = meter_id
256 else:
257 self.meter_id = 0
258 return
259
260 def pack(self):
261 packed = []
262 packed.append(struct.pack("!H", self.type))
263 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
264 packed.append(struct.pack("!L", self.meter_id))
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 = meter()
Dan Talaycof6202252013-07-02 01:00:29 -0700272 _type = reader.read("!H")[0]
273 assert(_type == 6)
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.meter_id = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700278 return obj
279
280 def __eq__(self, other):
281 if type(self) != type(other): return False
282 if self.meter_id != other.meter_id: return False
283 return True
284
Rich Laneca3da272013-05-05 09:07:33 -0700285 def pretty_print(self, q):
286 q.text("meter {")
287 with q.group():
288 with q.indent(2):
289 q.breakable()
290 q.text("meter_id = ");
291 q.text("%#x" % self.meter_id)
292 q.breakable()
293 q.text('}')
294
Rich Lane7dcdf022013-12-11 14:45:27 -0800295instruction.subtypes[6] = meter
296
297class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700298 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700299
300 def __init__(self, actions=None):
301 if actions != None:
302 self.actions = actions
303 else:
304 self.actions = []
305 return
306
307 def pack(self):
308 packed = []
309 packed.append(struct.pack("!H", self.type))
310 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
311 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800312 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700313 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 = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700320 _type = reader.read("!H")[0]
321 assert(_type == 3)
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))
Rich Laneca3da272013-05-05 09:07:33 -0700325 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800326 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700327 return obj
328
329 def __eq__(self, other):
330 if type(self) != type(other): return False
331 if self.actions != other.actions: return False
332 return True
333
Rich Laneca3da272013-05-05 09:07:33 -0700334 def pretty_print(self, q):
335 q.text("write_actions {")
336 with q.group():
337 with q.indent(2):
338 q.breakable()
339 q.text("actions = ");
340 q.pp(self.actions)
341 q.breakable()
342 q.text('}')
343
Rich Lane7dcdf022013-12-11 14:45:27 -0800344instruction.subtypes[3] = write_actions
345
346class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700347 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700348
349 def __init__(self, metadata=None, metadata_mask=None):
350 if metadata != None:
351 self.metadata = metadata
352 else:
353 self.metadata = 0
354 if metadata_mask != None:
355 self.metadata_mask = metadata_mask
356 else:
357 self.metadata_mask = 0
358 return
359
360 def pack(self):
361 packed = []
362 packed.append(struct.pack("!H", self.type))
363 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
364 packed.append('\x00' * 4)
365 packed.append(struct.pack("!Q", self.metadata))
366 packed.append(struct.pack("!Q", self.metadata_mask))
367 length = sum([len(x) for x in packed])
368 packed[1] = struct.pack("!H", length)
369 return ''.join(packed)
370
371 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800372 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700373 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700374 _type = reader.read("!H")[0]
375 assert(_type == 2)
376 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800377 orig_reader = reader
378 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700379 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700380 obj.metadata = reader.read("!Q")[0]
381 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700382 return obj
383
384 def __eq__(self, other):
385 if type(self) != type(other): return False
386 if self.metadata != other.metadata: return False
387 if self.metadata_mask != other.metadata_mask: return False
388 return True
389
Rich Laneca3da272013-05-05 09:07:33 -0700390 def pretty_print(self, q):
391 q.text("write_metadata {")
392 with q.group():
393 with q.indent(2):
394 q.breakable()
395 q.text("metadata = ");
396 q.text("%#x" % self.metadata)
397 q.text(","); q.breakable()
398 q.text("metadata_mask = ");
399 q.text("%#x" % self.metadata_mask)
400 q.breakable()
401 q.text('}')
402
Rich Lane7dcdf022013-12-11 14:45:27 -0800403instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700404
Rich Lane7b0f2012013-11-22 14:15:26 -0800405