blob: e93e070079657520882778b5909bae4176bbf85d [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
Rich Laneca3da272013-05-05 09:07:33 -070015import util
16import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070017
Rich Lane7dcdf022013-12-11 14:45:27 -080018class instruction(loxi.OFObject):
19 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070020
Rich Lane7dcdf022013-12-11 14:45:27 -080021 @staticmethod
22 def unpack(reader):
23 subtype, = reader.peek('!H', 0)
24 try:
25 subclass = instruction.subtypes[subtype]
26 except KeyError:
27 raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype)
28 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070029
Rich Lane7dcdf022013-12-11 14:45:27 -080030
31class apply_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070032 type = 4
Rich Laneca3da272013-05-05 09:07:33 -070033
34 def __init__(self, actions=None):
35 if actions != None:
36 self.actions = actions
37 else:
38 self.actions = []
39 return
40
41 def pack(self):
42 packed = []
43 packed.append(struct.pack("!H", self.type))
44 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
45 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -080046 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -070047 length = sum([len(x) for x in packed])
48 packed[1] = struct.pack("!H", length)
49 return ''.join(packed)
50
51 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080052 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070053 obj = apply_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070054 _type = reader.read("!H")[0]
55 assert(_type == 4)
56 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080057 orig_reader = reader
58 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -070059 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -080060 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -070061 return obj
62
63 def __eq__(self, other):
64 if type(self) != type(other): return False
65 if self.actions != other.actions: return False
66 return True
67
Rich Laneca3da272013-05-05 09:07:33 -070068 def pretty_print(self, q):
69 q.text("apply_actions {")
70 with q.group():
71 with q.indent(2):
72 q.breakable()
73 q.text("actions = ");
74 q.pp(self.actions)
75 q.breakable()
76 q.text('}')
77
Rich Lane7dcdf022013-12-11 14:45:27 -080078instruction.subtypes[4] = apply_actions
79
80class clear_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -070081 type = 5
Rich Laneca3da272013-05-05 09:07:33 -070082
83 def __init__(self):
84 return
85
86 def pack(self):
87 packed = []
88 packed.append(struct.pack("!H", self.type))
89 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
90 packed.append('\x00' * 4)
91 length = sum([len(x) for x in packed])
92 packed[1] = struct.pack("!H", length)
93 return ''.join(packed)
94
95 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080096 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070097 obj = clear_actions()
Dan Talaycof6202252013-07-02 01:00:29 -070098 _type = reader.read("!H")[0]
99 assert(_type == 5)
100 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800101 orig_reader = reader
102 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700103 reader.skip(4)
104 return obj
105
106 def __eq__(self, other):
107 if type(self) != type(other): return False
108 return True
109
Rich Laneca3da272013-05-05 09:07:33 -0700110 def pretty_print(self, q):
111 q.text("clear_actions {")
112 with q.group():
113 with q.indent(2):
114 q.breakable()
115 q.breakable()
116 q.text('}')
117
Rich Lane7dcdf022013-12-11 14:45:27 -0800118instruction.subtypes[5] = clear_actions
119
120class experimenter(instruction):
121 subtypes = {}
122
123 @staticmethod
124 def unpack(reader):
125 subtype, = reader.peek('!L', 4)
126 try:
127 subclass = experimenter.subtypes[subtype]
128 except KeyError:
129 raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype)
130 return subclass.unpack(reader)
131
132instruction.subtypes[65535] = experimenter
133
134class goto_table(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700135 type = 1
Rich Laneca3da272013-05-05 09:07:33 -0700136
137 def __init__(self, table_id=None):
138 if table_id != None:
139 self.table_id = table_id
140 else:
141 self.table_id = 0
142 return
143
144 def pack(self):
145 packed = []
146 packed.append(struct.pack("!H", self.type))
147 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
148 packed.append(struct.pack("!B", self.table_id))
149 packed.append('\x00' * 3)
150 length = sum([len(x) for x in packed])
151 packed[1] = struct.pack("!H", length)
152 return ''.join(packed)
153
154 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800155 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700156 obj = goto_table()
Dan Talaycof6202252013-07-02 01:00:29 -0700157 _type = reader.read("!H")[0]
158 assert(_type == 1)
159 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800160 orig_reader = reader
161 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700162 obj.table_id = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700163 reader.skip(3)
164 return obj
165
166 def __eq__(self, other):
167 if type(self) != type(other): return False
168 if self.table_id != other.table_id: return False
169 return True
170
Rich Laneca3da272013-05-05 09:07:33 -0700171 def pretty_print(self, q):
172 q.text("goto_table {")
173 with q.group():
174 with q.indent(2):
175 q.breakable()
176 q.text("table_id = ");
177 q.text("%#x" % self.table_id)
178 q.breakable()
179 q.text('}')
180
Rich Lane7dcdf022013-12-11 14:45:27 -0800181instruction.subtypes[1] = goto_table
182
183class write_actions(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700184 type = 3
Rich Laneca3da272013-05-05 09:07:33 -0700185
186 def __init__(self, actions=None):
187 if actions != None:
188 self.actions = actions
189 else:
190 self.actions = []
191 return
192
193 def pack(self):
194 packed = []
195 packed.append(struct.pack("!H", self.type))
196 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
197 packed.append('\x00' * 4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800198 packed.append(loxi.generic_util.pack_list(self.actions))
Rich Laneca3da272013-05-05 09:07:33 -0700199 length = sum([len(x) for x in packed])
200 packed[1] = struct.pack("!H", length)
201 return ''.join(packed)
202
203 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800204 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700205 obj = write_actions()
Dan Talaycof6202252013-07-02 01:00:29 -0700206 _type = reader.read("!H")[0]
207 assert(_type == 3)
208 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800209 orig_reader = reader
210 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700211 reader.skip(4)
Rich Lane7dcdf022013-12-11 14:45:27 -0800212 obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack)
Rich Laneca3da272013-05-05 09:07:33 -0700213 return obj
214
215 def __eq__(self, other):
216 if type(self) != type(other): return False
217 if self.actions != other.actions: return False
218 return True
219
Rich Laneca3da272013-05-05 09:07:33 -0700220 def pretty_print(self, q):
221 q.text("write_actions {")
222 with q.group():
223 with q.indent(2):
224 q.breakable()
225 q.text("actions = ");
226 q.pp(self.actions)
227 q.breakable()
228 q.text('}')
229
Rich Lane7dcdf022013-12-11 14:45:27 -0800230instruction.subtypes[3] = write_actions
231
232class write_metadata(instruction):
Dan Talaycof6202252013-07-02 01:00:29 -0700233 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700234
235 def __init__(self, metadata=None, metadata_mask=None):
236 if metadata != None:
237 self.metadata = metadata
238 else:
239 self.metadata = 0
240 if metadata_mask != None:
241 self.metadata_mask = metadata_mask
242 else:
243 self.metadata_mask = 0
244 return
245
246 def pack(self):
247 packed = []
248 packed.append(struct.pack("!H", self.type))
249 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
250 packed.append('\x00' * 4)
251 packed.append(struct.pack("!Q", self.metadata))
252 packed.append(struct.pack("!Q", self.metadata_mask))
253 length = sum([len(x) for x in packed])
254 packed[1] = struct.pack("!H", length)
255 return ''.join(packed)
256
257 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800258 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700259 obj = write_metadata()
Dan Talaycof6202252013-07-02 01:00:29 -0700260 _type = reader.read("!H")[0]
261 assert(_type == 2)
262 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800263 orig_reader = reader
264 reader = orig_reader.slice(_len - (2 + 2))
Rich Laneca3da272013-05-05 09:07:33 -0700265 reader.skip(4)
Dan Talaycof6202252013-07-02 01:00:29 -0700266 obj.metadata = reader.read("!Q")[0]
267 obj.metadata_mask = reader.read("!Q")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700268 return obj
269
270 def __eq__(self, other):
271 if type(self) != type(other): return False
272 if self.metadata != other.metadata: return False
273 if self.metadata_mask != other.metadata_mask: return False
274 return True
275
Rich Laneca3da272013-05-05 09:07:33 -0700276 def pretty_print(self, q):
277 q.text("write_metadata {")
278 with q.group():
279 with q.indent(2):
280 q.breakable()
281 q.text("metadata = ");
282 q.text("%#x" % self.metadata)
283 q.text(","); q.breakable()
284 q.text("metadata_mask = ");
285 q.text("%#x" % self.metadata_mask)
286 q.breakable()
287 q.text('}')
288
Rich Lane7dcdf022013-12-11 14:45:27 -0800289instruction.subtypes[2] = write_metadata
Rich Laneca3da272013-05-05 09:07:33 -0700290
Rich Lane7b0f2012013-11-22 14:15:26 -0800291