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