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