blob: e4472cddbf08c1e329b269c906e291dd8b1e59be [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
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 Lane7dcdf022013-12-11 14:45:27 -080022 @staticmethod
23 def unpack(reader):
24 subtype, = reader.peek('!H', 0)
25 try:
26 subclass = instruction.subtypes[subtype]
27 except KeyError:
28 raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype)
29 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070030
Rich Lane7dcdf022013-12-11 14:45:27 -080031
32class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070033 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070034
35 def __init__(self, actions=None):
36 if actions != None:
37 self.actions = actions
38 else:
39 self.actions = []
40 return
41
42 def pack(self):
43 packed = []
44 packed.append(struct.pack("!H", self.type))
45 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
46 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080047 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070048 length = sum([len(x) for x in packed])
49 packed[1] = struct.pack("!H", length)
50 return ''.join(packed)
51
52 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080053 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070054 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070055 _type = reader.read("!H")[0]
56 assert(_type == 4)
57 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080058 orig_reader = reader
59 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070060 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080061 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070062 return obj
63
64 def __eq__(self, other):
65 if type(self) != type(other): return False
66 if self.actions != other.actions: return False
67 return True
68
Rich Laneca3da272013-05-05 09:07:33 -070069 def pretty_print(self, q):
70 q.text("apply_actions {")
71 with q.group():
72 with q.indent(2):
73 q.breakable()
74 q.text("actions = ");
75 q.pp(self.actions)
76 q.breakable()
77 q.text('}')
78
Rich Lane7dcdf022013-12-11 14:45:27 -080079instruction.subtypes[4] = apply_actions
80
81class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070082 type = 5
Rich Laneca3da272013-05-05 09:07:33 -070083
84 def __init__(self):
85 return
86
87 def pack(self):
88 packed = []
89 packed.append(struct.pack("!H", self.type))
90 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
91 packed.append('\x00' * 4)
92 length = sum([len(x) for x in packed])
93 packed[1] = struct.pack("!H", length)
94 return ''.join(packed)
95
96 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080097 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070098 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070099 _type = reader.read("!H")[0]
100 assert(_type == 5)
101 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800102 orig_reader = reader
103 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700104 reader.skip(4)
105 return obj
106
107 def __eq__(self, other):
108 if type(self) != type(other): return False
109 return True
110
Rich Laneca3da272013-05-05 09:07:33 -0700111 def pretty_print(self, q):
112 q.text("clear_actions {")
113 with q.group():
114 with q.indent(2):
115 q.breakable()
116 q.breakable()
117 q.text('}')
118
Rich Lane7dcdf022013-12-11 14:45:27 -0800119instruction.subtypes[5] = clear_actions
120
121class experimenter(instruction):
122 subtypes = {}
123
124 @staticmethod
125 def unpack(reader):
126 subtype, = reader.peek('!L', 4)
127 try:
128 subclass = experimenter.subtypes[subtype]
129 except KeyError:
130 raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype)
131 return subclass.unpack(reader)
132
133instruction.subtypes[65535] = experimenter
134
135class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700136 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700137
138 def __init__(self, table_id=None):
139 if table_id != None:
140 self.table_id = table_id
141 else:
142 self.table_id = 0
143 return
144
145 def pack(self):
146 packed = []
147 packed.append(struct.pack("!H", self.type))
148 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
149 packed.append(struct.pack("!B", self.table_id))
150 packed.append('\x00' * 3)
151 length = sum([len(x) for x in packed])
152 packed[1] = struct.pack("!H", length)
153 return ''.join(packed)
154
155 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800156 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700157 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700158 _type = reader.read("!H")[0]
159 assert(_type == 1)
160 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800161 orig_reader = reader
162 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700163 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700164 reader.skip(3)
165 return obj
166
167 def __eq__(self, other):
168 if type(self) != type(other): return False
169 if self.table_id != other.table_id: return False
170 return True
171
Rich Laneca3da272013-05-05 09:07:33 -0700172 def pretty_print(self, q):
173 q.text("goto_table {")
174 with q.group():
175 with q.indent(2):
176 q.breakable()
177 q.text("table_id = ");
178 q.text("%#x" % self.table_id)
179 q.breakable()
180 q.text('}')
181
Rich Lane7dcdf022013-12-11 14:45:27 -0800182instruction.subtypes[1] = goto_table
183
184class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700185 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700186
187 def __init__(self, actions=None):
188 if actions != None:
189 self.actions = actions
190 else:
191 self.actions = []
192 return
193
194 def pack(self):
195 packed = []
196 packed.append(struct.pack("!H", self.type))
197 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
198 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800199 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700200 length = sum([len(x) for x in packed])
201 packed[1] = struct.pack("!H", length)
202 return ''.join(packed)
203
204 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800205 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700206 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700207 _type = reader.read("!H")[0]
208 assert(_type == 3)
209 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800210 orig_reader = reader
211 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700212 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800213 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700214 return obj
215
216 def __eq__(self, other):
217 if type(self) != type(other): return False
218 if self.actions != other.actions: return False
219 return True
220
Rich Laneca3da272013-05-05 09:07:33 -0700221 def pretty_print(self, q):
222 q.text("write_actions {")
223 with q.group():
224 with q.indent(2):
225 q.breakable()
226 q.text("actions = ");
227 q.pp(self.actions)
228 q.breakable()
229 q.text('}')
230
Rich Lane7dcdf022013-12-11 14:45:27 -0800231instruction.subtypes[3] = write_actions
232
233class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700234 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700235
236 def __init__(self, metadata=None, metadata_mask=None):
237 if metadata != None:
238 self.metadata = metadata
239 else:
240 self.metadata = 0
241 if metadata_mask != None:
242 self.metadata_mask = metadata_mask
243 else:
244 self.metadata_mask = 0
245 return
246
247 def pack(self):
248 packed = []
249 packed.append(struct.pack("!H", self.type))
250 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
251 packed.append('\x00' * 4)
252 packed.append(struct.pack("!Q", self.metadata))
253 packed.append(struct.pack("!Q", self.metadata_mask))
254 length = sum([len(x) for x in packed])
255 packed[1] = struct.pack("!H", length)
256 return ''.join(packed)
257
258 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800259 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700260 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700261 _type = reader.read("!H")[0]
262 assert(_type == 2)
263 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800264 orig_reader = reader
265 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700266 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700267 obj.metadata = reader.read("!Q")[0]
268 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700269 return obj
270
271 def __eq__(self, other):
272 if type(self) != type(other): return False
273 if self.metadata != other.metadata: return False
274 if self.metadata_mask != other.metadata_mask: return False
275 return True
276
Rich Laneca3da272013-05-05 09:07:33 -0700277 def pretty_print(self, q):
278 q.text("write_metadata {")
279 with q.group():
280 with q.indent(2):
281 q.breakable()
282 q.text("metadata = ");
283 q.text("%#x" % self.metadata)
284 q.text(","); q.breakable()
285 q.text("metadata_mask = ");
286 q.text("%#x" % self.metadata_mask)
287 q.breakable()
288 q.text('}')
289
Rich Lane7dcdf022013-12-11 14:45:27 -0800290instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700291
Rich Lane7b0f2012013-11-22 14:15:26 -0800292