]>
Commit | Line | Data |
---|---|---|
f25d0cf3 | 1 | /* |
b02475c5 | 2 | * Copyright (c) 2012, 2013 Nicira, Inc. |
f25d0cf3 BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef OFP_ACTIONS_H | |
18 | #define OFP_ACTIONS_H 1 | |
19 | ||
20 | #include <stdint.h> | |
21 | #include "meta-flow.h" | |
22 | #include "ofp-errors.h" | |
23 | #include "ofp-util.h" | |
24 | #include "openflow/openflow.h" | |
25 | #include "openflow/nicira-ext.h" | |
26 | #include "openvswitch/types.h" | |
27 | ||
28 | /* List of OVS abstracted actions. | |
29 | * | |
30 | * This macro is used directly only internally by this header, but the list is | |
31 | * still of interest to developers. | |
32 | * | |
33 | * Each DEFINE_OFPACT invocation has the following parameters: | |
34 | * | |
35 | * 1. <ENUM>, used below in the enum definition of OFPACT_<ENUM>, and | |
36 | * elsewhere. | |
37 | * | |
38 | * 2. <STRUCT> corresponding to a structure "struct <STRUCT>", that must be | |
39 | * defined below. This structure must be an abstract definition of the | |
40 | * action. Its first member must have type "struct ofpact" and name | |
41 | * "ofpact". It may be fixed length or end with a flexible array member | |
42 | * (e.g. "int member[];"). | |
43 | * | |
44 | * 3. <MEMBER>, which has one of two possible values: | |
45 | * | |
46 | * - If "struct <STRUCT>" is fixed-length, it must be "ofpact". | |
47 | * | |
48 | * - If "struct <STRUCT>" is variable-length, it must be the name of the | |
49 | * flexible array member. | |
50 | */ | |
51 | #define OFPACTS \ | |
52 | /* Output. */ \ | |
53 | DEFINE_OFPACT(OUTPUT, ofpact_output, ofpact) \ | |
54 | DEFINE_OFPACT(CONTROLLER, ofpact_controller, ofpact) \ | |
55 | DEFINE_OFPACT(ENQUEUE, ofpact_enqueue, ofpact) \ | |
56 | DEFINE_OFPACT(OUTPUT_REG, ofpact_output_reg, ofpact) \ | |
57 | DEFINE_OFPACT(BUNDLE, ofpact_bundle, slaves) \ | |
58 | \ | |
59 | /* Header changes. */ \ | |
60 | DEFINE_OFPACT(SET_VLAN_VID, ofpact_vlan_vid, ofpact) \ | |
61 | DEFINE_OFPACT(SET_VLAN_PCP, ofpact_vlan_pcp, ofpact) \ | |
62 | DEFINE_OFPACT(STRIP_VLAN, ofpact_null, ofpact) \ | |
3e34fbdd | 63 | DEFINE_OFPACT(PUSH_VLAN, ofpact_null, ofpact) \ |
f25d0cf3 BP |
64 | DEFINE_OFPACT(SET_ETH_SRC, ofpact_mac, ofpact) \ |
65 | DEFINE_OFPACT(SET_ETH_DST, ofpact_mac, ofpact) \ | |
66 | DEFINE_OFPACT(SET_IPV4_SRC, ofpact_ipv4, ofpact) \ | |
67 | DEFINE_OFPACT(SET_IPV4_DST, ofpact_ipv4, ofpact) \ | |
68 | DEFINE_OFPACT(SET_IPV4_DSCP, ofpact_dscp, ofpact) \ | |
69 | DEFINE_OFPACT(SET_L4_SRC_PORT, ofpact_l4_port, ofpact) \ | |
70 | DEFINE_OFPACT(SET_L4_DST_PORT, ofpact_l4_port, ofpact) \ | |
71 | DEFINE_OFPACT(REG_MOVE, ofpact_reg_move, ofpact) \ | |
72 | DEFINE_OFPACT(REG_LOAD, ofpact_reg_load, ofpact) \ | |
bd85dac1 AZ |
73 | DEFINE_OFPACT(STACK_PUSH, ofpact_stack, ofpact) \ |
74 | DEFINE_OFPACT(STACK_POP, ofpact_stack, ofpact) \ | |
c2d967a5 | 75 | DEFINE_OFPACT(DEC_TTL, ofpact_cnt_ids, cnt_ids) \ |
0f3f3c3d | 76 | DEFINE_OFPACT(SET_MPLS_TTL, ofpact_mpls_ttl, ofpact) \ |
b676167a | 77 | DEFINE_OFPACT(DEC_MPLS_TTL, ofpact_null, ofpact) \ |
b02475c5 SH |
78 | DEFINE_OFPACT(PUSH_MPLS, ofpact_push_mpls, ofpact) \ |
79 | DEFINE_OFPACT(POP_MPLS, ofpact_pop_mpls, ofpact) \ | |
f25d0cf3 BP |
80 | \ |
81 | /* Metadata. */ \ | |
82 | DEFINE_OFPACT(SET_TUNNEL, ofpact_tunnel, ofpact) \ | |
83 | DEFINE_OFPACT(SET_QUEUE, ofpact_queue, ofpact) \ | |
84 | DEFINE_OFPACT(POP_QUEUE, ofpact_null, ofpact) \ | |
85 | DEFINE_OFPACT(FIN_TIMEOUT, ofpact_fin_timeout, ofpact) \ | |
86 | \ | |
87 | /* Flow table interaction. */ \ | |
88 | DEFINE_OFPACT(RESUBMIT, ofpact_resubmit, ofpact) \ | |
89 | DEFINE_OFPACT(LEARN, ofpact_learn, specs) \ | |
90 | \ | |
91 | /* Arithmetic. */ \ | |
92 | DEFINE_OFPACT(MULTIPATH, ofpact_multipath, ofpact) \ | |
f25d0cf3 BP |
93 | \ |
94 | /* Other. */ \ | |
95 | DEFINE_OFPACT(NOTE, ofpact_note, data) \ | |
8dd54666 | 96 | DEFINE_OFPACT(EXIT, ofpact_null, ofpact) \ |
29089a54 | 97 | DEFINE_OFPACT(SAMPLE, ofpact_sample, ofpact) \ |
8dd54666 IY |
98 | \ |
99 | /* Instructions */ \ | |
638a19b0 | 100 | DEFINE_OFPACT(METER, ofpact_meter, ofpact) \ |
5dca28b5 | 101 | /* XXX Write-Actions */ \ |
b19e8793 | 102 | DEFINE_OFPACT(CLEAR_ACTIONS, ofpact_null, ofpact) \ |
638a19b0 | 103 | DEFINE_OFPACT(WRITE_METADATA, ofpact_metadata, ofpact) \ |
8dd54666 | 104 | DEFINE_OFPACT(GOTO_TABLE, ofpact_goto_table, ofpact) |
f25d0cf3 BP |
105 | |
106 | /* enum ofpact_type, with a member OFPACT_<ENUM> for each action. */ | |
107 | enum OVS_PACKED_ENUM ofpact_type { | |
108 | #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) OFPACT_##ENUM, | |
109 | OFPACTS | |
110 | #undef DEFINE_OFPACT | |
111 | }; | |
112 | ||
113 | /* N_OFPACTS, the number of values of "enum ofpact_type". */ | |
114 | enum { | |
115 | N_OFPACTS = | |
116 | #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) + 1 | |
117 | OFPACTS | |
118 | #undef DEFINE_OFPACT | |
119 | }; | |
120 | ||
121 | /* Header for an action. | |
122 | * | |
123 | * Each action is a structure "struct ofpact_*" that begins with "struct | |
124 | * ofpact", usually followed by other data that describes the action. Actions | |
2ac3c572 BP |
125 | * are padded out to a multiple of OFPACT_ALIGNTO bytes in length. |
126 | * | |
127 | * The 'compat' member is special: | |
128 | * | |
129 | * - Most "struct ofpact"s correspond to one particular kind of OpenFlow | |
130 | * action, at least in a given OpenFlow version. For example, | |
131 | * OFPACT_SET_VLAN_VID corresponds to OFPAT10_SET_VLAN_VID in OpenFlow | |
132 | * 1.0. | |
133 | * | |
134 | * For such actions, the 'compat' member is not meaningful and generally | |
135 | * should be zero. | |
136 | * | |
137 | * - A few "struct ofpact"s correspond to multiple OpenFlow actions. For | |
138 | * example, OFPACT_SET_TUNNEL can be NXAST_SET_TUNNEL or | |
139 | * NXAST_SET_TUNNEL64. In these cases, if the "struct ofpact" originated | |
140 | * from OpenFlow, then we want to make sure that, if it gets translated | |
141 | * back to OpenFlow later, it is translated back to the same action type. | |
142 | * (Otherwise, we'd violate the promise made in DESIGN, in the "Action | |
143 | * Reproduction" section.) | |
144 | * | |
145 | * For such actions, the 'compat' member should be the original action | |
146 | * type. (If the action didn't originate from OpenFlow, then setting | |
147 | * 'compat' to zero should be fine: code to translate the ofpact to | |
148 | * OpenFlow must tolerate this case.) | |
149 | */ | |
f25d0cf3 BP |
150 | struct ofpact { |
151 | enum ofpact_type type; /* OFPACT_*. */ | |
152 | enum ofputil_action_code compat; /* Original type when added, if any. */ | |
153 | uint16_t len; /* Length of the action, in bytes, including | |
154 | * struct ofpact, excluding padding. */ | |
155 | }; | |
156 | ||
157 | #ifdef __GNUC__ | |
158 | /* Make sure that OVS_PACKED_ENUM really worked. */ | |
159 | BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4); | |
160 | #endif | |
161 | ||
162 | /* Alignment. */ | |
163 | #define OFPACT_ALIGNTO 8 | |
164 | #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO) | |
165 | ||
166 | static inline struct ofpact * | |
167 | ofpact_next(const struct ofpact *ofpact) | |
168 | { | |
169 | return (void *) ((uint8_t *) ofpact + OFPACT_ALIGN(ofpact->len)); | |
170 | } | |
171 | ||
172 | static inline struct ofpact * | |
173 | ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len) | |
174 | { | |
175 | return (void *) ((uint8_t *) ofpacts + ofpacts_len); | |
176 | } | |
177 | ||
178 | /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts | |
179 | * starting at OFPACTS. */ | |
180 | #define OFPACT_FOR_EACH(POS, OFPACTS, OFPACTS_LEN) \ | |
181 | for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN); \ | |
182 | (POS) = ofpact_next(POS)) | |
183 | \f | |
184 | /* Action structure for each OFPACT_*. */ | |
185 | ||
b19e8793 | 186 | /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS. |
f25d0cf3 | 187 | * |
7bcb1506 | 188 | * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT, |
8e61c110 | 189 | * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS. |
f25d0cf3 BP |
190 | * |
191 | * Action structure for actions that do not have any extra data beyond the | |
192 | * action type. */ | |
193 | struct ofpact_null { | |
194 | struct ofpact ofpact; | |
195 | }; | |
196 | ||
197 | /* OFPACT_OUTPUT. | |
198 | * | |
199 | * Used for OFPAT10_OUTPUT. */ | |
200 | struct ofpact_output { | |
201 | struct ofpact ofpact; | |
4e022ec0 | 202 | ofp_port_t port; /* Output port. */ |
f25d0cf3 BP |
203 | uint16_t max_len; /* Max send len, for port OFPP_CONTROLLER. */ |
204 | }; | |
205 | ||
206 | /* OFPACT_CONTROLLER. | |
207 | * | |
208 | * Used for NXAST_CONTROLLER. */ | |
209 | struct ofpact_controller { | |
210 | struct ofpact ofpact; | |
211 | uint16_t max_len; /* Maximum length to send to controller. */ | |
212 | uint16_t controller_id; /* Controller ID to send packet-in. */ | |
213 | enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */ | |
214 | }; | |
215 | ||
216 | /* OFPACT_ENQUEUE. | |
217 | * | |
218 | * Used for OFPAT10_ENQUEUE. */ | |
219 | struct ofpact_enqueue { | |
220 | struct ofpact ofpact; | |
4e022ec0 | 221 | ofp_port_t port; |
f25d0cf3 BP |
222 | uint32_t queue; |
223 | }; | |
224 | ||
225 | /* OFPACT_OUTPUT_REG. | |
226 | * | |
227 | * Used for NXAST_OUTPUT_REG. */ | |
228 | struct ofpact_output_reg { | |
229 | struct ofpact ofpact; | |
230 | struct mf_subfield src; | |
231 | uint16_t max_len; | |
232 | }; | |
233 | ||
234 | /* OFPACT_BUNDLE. | |
235 | * | |
236 | * Used for NXAST_BUNDLE. */ | |
237 | struct ofpact_bundle { | |
238 | struct ofpact ofpact; | |
239 | ||
240 | /* Slave choice algorithm to apply to hash value. */ | |
241 | enum nx_bd_algorithm algorithm; | |
242 | ||
243 | /* What fields to hash and how. */ | |
244 | enum nx_hash_fields fields; | |
245 | uint16_t basis; /* Universal hash parameter. */ | |
246 | ||
247 | struct mf_subfield dst; | |
248 | ||
249 | /* Slaves for output. */ | |
250 | unsigned int n_slaves; | |
4e022ec0 | 251 | ofp_port_t slaves[]; |
f25d0cf3 BP |
252 | }; |
253 | ||
254 | /* OFPACT_SET_VLAN_VID. | |
255 | * | |
256 | * Used for OFPAT10_SET_VLAN_VID. */ | |
257 | struct ofpact_vlan_vid { | |
258 | struct ofpact ofpact; | |
259 | uint16_t vlan_vid; /* VLAN VID in low 12 bits, 0 in other bits. */ | |
260 | }; | |
261 | ||
262 | /* OFPACT_SET_VLAN_PCP. | |
263 | * | |
264 | * Used for OFPAT10_SET_VLAN_PCP. */ | |
265 | struct ofpact_vlan_pcp { | |
266 | struct ofpact ofpact; | |
267 | uint8_t vlan_pcp; /* VLAN PCP in low 3 bits, 0 in other bits. */ | |
268 | }; | |
269 | ||
270 | /* OFPACT_SET_ETH_SRC, OFPACT_SET_ETH_DST. | |
271 | * | |
272 | * Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */ | |
273 | struct ofpact_mac { | |
274 | struct ofpact ofpact; | |
275 | uint8_t mac[ETH_ADDR_LEN]; | |
276 | }; | |
277 | ||
278 | /* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST. | |
279 | * | |
280 | * Used for OFPAT10_SET_NW_SRC, OFPAT10_SET_NW_DST. */ | |
281 | struct ofpact_ipv4 { | |
282 | struct ofpact ofpact; | |
283 | ovs_be32 ipv4; | |
284 | }; | |
285 | ||
286 | /* OFPACT_SET_IPV4_DSCP. | |
287 | * | |
288 | * Used for OFPAT10_SET_NW_TOS. */ | |
289 | struct ofpact_dscp { | |
290 | struct ofpact ofpact; | |
291 | uint8_t dscp; /* DSCP in high 6 bits, rest ignored. */ | |
292 | }; | |
293 | ||
294 | /* OFPACT_SET_L4_SRC_PORT, OFPACT_SET_L4_DST_PORT. | |
295 | * | |
296 | * Used for OFPAT10_SET_TP_SRC, OFPAT10_SET_TP_DST. */ | |
297 | struct ofpact_l4_port { | |
298 | struct ofpact ofpact; | |
299 | uint16_t port; /* TCP or UDP port number. */ | |
300 | }; | |
301 | ||
302 | /* OFPACT_REG_MOVE. | |
303 | * | |
304 | * Used for NXAST_REG_MOVE. */ | |
305 | struct ofpact_reg_move { | |
306 | struct ofpact ofpact; | |
307 | struct mf_subfield src; | |
308 | struct mf_subfield dst; | |
309 | }; | |
310 | ||
bd85dac1 AZ |
311 | /* OFPACT_STACK_PUSH. |
312 | * | |
313 | * Used for NXAST_STACK_PUSH and NXAST_STACK_POP. */ | |
314 | struct ofpact_stack { | |
315 | struct ofpact ofpact; | |
316 | struct mf_subfield subfield; | |
317 | }; | |
318 | ||
f25d0cf3 BP |
319 | /* OFPACT_REG_LOAD. |
320 | * | |
9bab681f | 321 | * Used for NXAST_REG_LOAD, OFPAT12_SET_FIELD. */ |
f25d0cf3 BP |
322 | struct ofpact_reg_load { |
323 | struct ofpact ofpact; | |
324 | struct mf_subfield dst; | |
158edc8d | 325 | union mf_subvalue subvalue; /* Least-significant bits are used. */ |
f25d0cf3 BP |
326 | }; |
327 | ||
b02475c5 SH |
328 | /* OFPACT_PUSH_VLAN/MPLS/PBB |
329 | * | |
330 | * Used for NXAST_PUSH_MPLS, OFPAT11_PUSH_MPLS. */ | |
331 | struct ofpact_push_mpls { | |
332 | struct ofpact ofpact; | |
333 | ovs_be16 ethertype; | |
334 | }; | |
335 | ||
336 | /* OFPACT_POP_MPLS | |
337 | * | |
338 | * Used for NXAST_POP_MPLS, OFPAT11_POP_MPLS.. */ | |
339 | struct ofpact_pop_mpls { | |
340 | struct ofpact ofpact; | |
341 | ovs_be16 ethertype; | |
342 | }; | |
343 | ||
f25d0cf3 BP |
344 | /* OFPACT_SET_TUNNEL. |
345 | * | |
346 | * Used for NXAST_SET_TUNNEL, NXAST_SET_TUNNEL64. */ | |
347 | struct ofpact_tunnel { | |
348 | struct ofpact ofpact; | |
349 | uint64_t tun_id; | |
350 | }; | |
351 | ||
352 | /* OFPACT_SET_QUEUE. | |
353 | * | |
354 | * Used for NXAST_SET_QUEUE. */ | |
355 | struct ofpact_queue { | |
356 | struct ofpact ofpact; | |
357 | uint32_t queue_id; | |
358 | }; | |
359 | ||
360 | /* OFPACT_FIN_TIMEOUT. | |
361 | * | |
362 | * Used for NXAST_FIN_TIMEOUT. */ | |
363 | struct ofpact_fin_timeout { | |
364 | struct ofpact ofpact; | |
365 | uint16_t fin_idle_timeout; | |
366 | uint16_t fin_hard_timeout; | |
367 | }; | |
368 | ||
4cceacb9 JS |
369 | /* OFPACT_WRITE_METADATA. |
370 | * | |
371 | * Used for NXAST_WRITE_METADATA. */ | |
372 | struct ofpact_metadata { | |
373 | struct ofpact ofpact; | |
374 | ovs_be64 metadata; | |
375 | ovs_be64 mask; | |
376 | }; | |
377 | ||
638a19b0 JR |
378 | /* OFPACT_METER. |
379 | * | |
380 | * Used for OFPIT13_METER. */ | |
381 | struct ofpact_meter { | |
382 | struct ofpact ofpact; | |
383 | uint32_t meter_id; | |
384 | }; | |
385 | ||
f25d0cf3 BP |
386 | /* OFPACT_RESUBMIT. |
387 | * | |
388 | * Used for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE. */ | |
389 | struct ofpact_resubmit { | |
390 | struct ofpact ofpact; | |
4e022ec0 | 391 | ofp_port_t in_port; |
f25d0cf3 BP |
392 | uint8_t table_id; |
393 | }; | |
394 | ||
395 | /* Part of struct ofpact_learn, below. */ | |
396 | struct ofpact_learn_spec { | |
e956d63b | 397 | int n_bits; /* Number of bits in source and dest. */ |
f25d0cf3 | 398 | |
e956d63b BP |
399 | int src_type; /* One of NX_LEARN_SRC_*. */ |
400 | struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */ | |
401 | union mf_subvalue src_imm; /* NX_LEARN_SRC_IMMEDIATE only. */ | |
f25d0cf3 | 402 | |
e956d63b BP |
403 | int dst_type; /* One of NX_LEARN_DST_*. */ |
404 | struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */ | |
f25d0cf3 BP |
405 | }; |
406 | ||
407 | /* OFPACT_LEARN. | |
408 | * | |
409 | * Used for NXAST_LEARN. */ | |
410 | struct ofpact_learn { | |
411 | struct ofpact ofpact; | |
412 | ||
413 | uint16_t idle_timeout; /* Idle time before discarding (seconds). */ | |
414 | uint16_t hard_timeout; /* Max time before discarding (seconds). */ | |
415 | uint16_t priority; /* Priority level of flow entry. */ | |
416 | uint64_t cookie; /* Cookie for new flow. */ | |
417 | uint16_t flags; /* Either 0 or OFPFF_SEND_FLOW_REM. */ | |
418 | uint8_t table_id; /* Table to insert flow entry. */ | |
419 | uint16_t fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */ | |
420 | uint16_t fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */ | |
421 | ||
422 | unsigned int n_specs; | |
423 | struct ofpact_learn_spec specs[]; | |
424 | }; | |
425 | ||
426 | /* OFPACT_MULTIPATH. | |
427 | * | |
428 | * Used for NXAST_MULTIPATH. */ | |
429 | struct ofpact_multipath { | |
430 | struct ofpact ofpact; | |
431 | ||
432 | /* What fields to hash and how. */ | |
433 | enum nx_hash_fields fields; | |
434 | uint16_t basis; /* Universal hash parameter. */ | |
435 | ||
436 | /* Multipath link choice algorithm to apply to hash value. */ | |
437 | enum nx_mp_algorithm algorithm; | |
438 | uint16_t max_link; /* Number of output links, minus 1. */ | |
439 | uint32_t arg; /* Algorithm-specific argument. */ | |
440 | ||
441 | /* Where to store the result. */ | |
442 | struct mf_subfield dst; | |
443 | }; | |
444 | ||
f25d0cf3 BP |
445 | /* OFPACT_NOTE. |
446 | * | |
447 | * Used for NXAST_NOTE. */ | |
448 | struct ofpact_note { | |
449 | struct ofpact ofpact; | |
450 | size_t length; | |
451 | uint8_t data[]; | |
452 | }; | |
453 | ||
29089a54 RL |
454 | /* OFPACT_SAMPLE. |
455 | * | |
456 | * Used for NXAST_SAMPLE. */ | |
457 | struct ofpact_sample { | |
458 | struct ofpact ofpact; | |
459 | uint16_t probability; // Always >0. | |
460 | uint32_t collector_set_id; | |
461 | uint32_t obs_domain_id; | |
462 | uint32_t obs_point_id; | |
463 | }; | |
464 | ||
c2d967a5 MM |
465 | /* OFPACT_DEC_TTL. |
466 | * | |
7bcb1506 | 467 | * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */ |
c2d967a5 MM |
468 | struct ofpact_cnt_ids { |
469 | struct ofpact ofpact; | |
470 | ||
471 | /* Controller ids. */ | |
472 | unsigned int n_controllers; | |
473 | uint16_t cnt_ids[]; | |
8dd54666 | 474 | }; |
c2d967a5 | 475 | |
0f3f3c3d SH |
476 | /* OFPACT_SET_MPLS_TTL. |
477 | * | |
478 | * Used for NXAST_SET_MPLS_TTL */ | |
479 | struct ofpact_mpls_ttl { | |
480 | struct ofpact ofpact; | |
481 | ||
482 | uint8_t ttl; | |
483 | }; | |
484 | ||
8dd54666 IY |
485 | /* OFPACT_GOTO_TABLE |
486 | * | |
487 | * Used for OFPIT11_GOTO_TABLE */ | |
488 | struct ofpact_goto_table { | |
489 | struct ofpact ofpact; | |
490 | uint8_t table_id; | |
c2d967a5 MM |
491 | }; |
492 | ||
f25d0cf3 | 493 | /* Converting OpenFlow to ofpacts. */ |
d01c980f BP |
494 | enum ofperr ofpacts_pull_openflow10(struct ofpbuf *openflow, |
495 | unsigned int actions_len, | |
496 | struct ofpbuf *ofpacts); | |
497 | enum ofperr ofpacts_pull_openflow11_actions(struct ofpbuf *openflow, | |
498 | unsigned int actions_len, | |
499 | struct ofpbuf *ofpacts); | |
500 | enum ofperr ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow, | |
501 | unsigned int instructions_len, | |
bff7eeb6 | 502 | uint8_t table_id, |
d01c980f | 503 | struct ofpbuf *ofpacts); |
f25d0cf3 | 504 | enum ofperr ofpacts_check(const struct ofpact[], size_t ofpacts_len, |
eca39bce | 505 | struct flow *, ofp_port_t max_ports); |
4cceacb9 | 506 | enum ofperr ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len); |
f25d0cf3 BP |
507 | |
508 | /* Converting ofpacts to OpenFlow. */ | |
d01c980f BP |
509 | void ofpacts_put_openflow10(const struct ofpact[], size_t ofpacts_len, |
510 | struct ofpbuf *openflow); | |
a07c15bc SH |
511 | size_t ofpacts_put_openflow11_actions(const struct ofpact[], size_t ofpacts_len, |
512 | struct ofpbuf *openflow); | |
d01c980f BP |
513 | void ofpacts_put_openflow11_instructions(const struct ofpact[], |
514 | size_t ofpacts_len, | |
515 | struct ofpbuf *openflow); | |
f25d0cf3 BP |
516 | |
517 | /* Working with ofpacts. */ | |
518 | bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len, | |
4e022ec0 | 519 | ofp_port_t port); |
f25d0cf3 BP |
520 | bool ofpacts_equal(const struct ofpact a[], size_t a_len, |
521 | const struct ofpact b[], size_t b_len); | |
522 | ||
523 | /* Formatting ofpacts. | |
524 | * | |
525 | * (For parsing ofpacts, see ofp-parse.h.) */ | |
526 | void ofpacts_format(const struct ofpact[], size_t ofpacts_len, struct ds *); | |
527 | ||
528 | /* Internal use by the helpers below. */ | |
529 | void ofpact_init(struct ofpact *, enum ofpact_type, size_t len); | |
530 | void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len); | |
531 | ||
532 | /* For each OFPACT_<ENUM> with a corresponding struct <STRUCT>, this defines | |
533 | * the following commonly useful functions: | |
534 | * | |
535 | * struct <STRUCT> *ofpact_put_<ENUM>(struct ofpbuf *ofpacts); | |
536 | * | |
537 | * Appends a new 'ofpact', of length OFPACT_<ENUM>_RAW_SIZE, to 'ofpacts', | |
538 | * initializes it with ofpact_init_<ENUM>(), and returns it. Also sets | |
539 | * 'ofpacts->l2' to the returned action. | |
540 | * | |
541 | * After using this function to add a variable-length action, add the | |
542 | * elements of the flexible array (e.g. with ofpbuf_put()), then use | |
543 | * ofpact_update_len() to update the length embedded into the action. | |
544 | * (Keep in mind the need to refresh the structure from 'ofpacts->l2' after | |
545 | * adding data to 'ofpacts'.) | |
546 | * | |
547 | * struct <STRUCT> *ofpact_get_<ENUM>(const struct ofpact *ofpact); | |
548 | * | |
549 | * Returns 'ofpact' cast to "struct <STRUCT> *". 'ofpact->type' must be | |
550 | * OFPACT_<ENUM>. | |
551 | * | |
552 | * as well as the following more rarely useful definitions: | |
553 | * | |
554 | * void ofpact_init_<ENUM>(struct <STRUCT> *ofpact); | |
555 | * | |
556 | * Initializes the parts of 'ofpact' that identify it as having type | |
557 | * OFPACT_<ENUM> and length OFPACT_<ENUM>_RAW_SIZE and zeros the rest. | |
558 | * | |
559 | * <ENUM>_RAW_SIZE | |
560 | * | |
561 | * The size of the action structure. For a fixed-length action, this is | |
562 | * sizeof(struct <STRUCT>). For a variable-length action, this is the | |
563 | * offset to the variable-length part. | |
564 | * | |
565 | * <ENUM>_SIZE | |
566 | * | |
567 | * An integer constant, the value of OFPACT_<ENUM>_RAW_SIZE rounded up to a | |
568 | * multiple of OFPACT_ALIGNTO. | |
569 | */ | |
570 | #define DEFINE_OFPACT(ENUM, STRUCT, MEMBER) \ | |
571 | BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0); \ | |
572 | \ | |
573 | enum { OFPACT_##ENUM##_RAW_SIZE \ | |
574 | = (offsetof(struct STRUCT, MEMBER) \ | |
575 | ? offsetof(struct STRUCT, MEMBER) \ | |
576 | : sizeof(struct STRUCT)) }; \ | |
577 | \ | |
578 | enum { OFPACT_##ENUM##_SIZE \ | |
579 | = ROUND_UP(OFPACT_##ENUM##_RAW_SIZE, OFPACT_ALIGNTO) }; \ | |
580 | \ | |
581 | static inline struct STRUCT * \ | |
582 | ofpact_get_##ENUM(const struct ofpact *ofpact) \ | |
583 | { \ | |
cb22974d | 584 | ovs_assert(ofpact->type == OFPACT_##ENUM); \ |
f25d0cf3 BP |
585 | return (struct STRUCT *) ofpact; \ |
586 | } \ | |
587 | \ | |
588 | static inline struct STRUCT * \ | |
589 | ofpact_put_##ENUM(struct ofpbuf *ofpacts) \ | |
590 | { \ | |
591 | return ofpact_put(ofpacts, OFPACT_##ENUM, \ | |
592 | OFPACT_##ENUM##_RAW_SIZE); \ | |
593 | } \ | |
594 | \ | |
595 | static inline void \ | |
596 | ofpact_init_##ENUM(struct STRUCT *ofpact) \ | |
597 | { \ | |
598 | ofpact_init(&ofpact->ofpact, OFPACT_##ENUM, \ | |
599 | OFPACT_##ENUM##_RAW_SIZE); \ | |
600 | } | |
601 | OFPACTS | |
602 | #undef DEFINE_OFPACT | |
603 | ||
604 | /* Functions to use after adding ofpacts to a buffer. */ | |
605 | void ofpact_update_len(struct ofpbuf *, struct ofpact *); | |
606 | void ofpact_pad(struct ofpbuf *); | |
607 | ||
99c476dc IY |
608 | /* OpenFlow 1.1 instructions. |
609 | * The order is sorted in execution order. Not in the value of OFPIT11_xxx. | |
610 | * It is enforced on parser from text string. | |
611 | */ | |
a64f0b0f | 612 | #define OVS_INSTRUCTIONS \ |
638a19b0 JR |
613 | DEFINE_INST(OFPIT13_METER, \ |
614 | ofp13_instruction_meter, false, \ | |
615 | "meter") \ | |
616 | \ | |
99c476dc IY |
617 | DEFINE_INST(OFPIT11_APPLY_ACTIONS, \ |
618 | ofp11_instruction_actions, true, \ | |
619 | "apply_actions") \ | |
a64f0b0f | 620 | \ |
99c476dc IY |
621 | DEFINE_INST(OFPIT11_CLEAR_ACTIONS, \ |
622 | ofp11_instruction, false, \ | |
623 | "clear_actions") \ | |
a64f0b0f IY |
624 | \ |
625 | DEFINE_INST(OFPIT11_WRITE_ACTIONS, \ | |
626 | ofp11_instruction_actions, true, \ | |
627 | "write_actions") \ | |
628 | \ | |
99c476dc IY |
629 | DEFINE_INST(OFPIT11_WRITE_METADATA, \ |
630 | ofp11_instruction_write_metadata, false, \ | |
631 | "write_metadata") \ | |
a64f0b0f | 632 | \ |
99c476dc IY |
633 | DEFINE_INST(OFPIT11_GOTO_TABLE, \ |
634 | ofp11_instruction_goto_table, false, \ | |
635 | "goto_table") | |
a64f0b0f IY |
636 | |
637 | enum ovs_instruction_type { | |
638 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) OVSINST_##ENUM, | |
639 | OVS_INSTRUCTIONS | |
640 | #undef DEFINE_INST | |
641 | }; | |
642 | ||
643 | enum { | |
644 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 | |
645 | N_OVS_INSTRUCTIONS = OVS_INSTRUCTIONS | |
646 | #undef DEFINE_INST | |
647 | }; | |
648 | ||
8dd54666 IY |
649 | |
650 | static inline bool | |
651 | ofpact_is_instruction(const struct ofpact *a) | |
652 | { | |
5dca28b5 | 653 | /* XXX Write-Actions */ |
b19e8793 | 654 | return a->type == OFPACT_CLEAR_ACTIONS |
638a19b0 | 655 | || a->type == OFPACT_METER |
4cceacb9 | 656 | || a->type == OFPACT_WRITE_METADATA |
b19e8793 | 657 | || a->type == OFPACT_GOTO_TABLE; |
8dd54666 IY |
658 | } |
659 | ||
ba0bc9b0 BP |
660 | const char *ovs_instruction_name_from_type(enum ovs_instruction_type type); |
661 | int ovs_instruction_type_from_name(const char *name); | |
a359d5ad | 662 | |
f5c45121 SH |
663 | void ofpact_set_field_init(struct ofpact_reg_load *load, |
664 | const struct mf_field *mf, const void *src); | |
665 | ||
f25d0cf3 | 666 | #endif /* ofp-actions.h */ |