1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef __INCLUDE_RTE_TABLE_ACTION_H__
6 #define __INCLUDE_RTE_TABLE_ACTION_H__
10 * RTE Pipeline Table Actions
12 * This API provides a common set of actions for pipeline tables to speed up
13 * application development.
15 * Each match-action rule added to a pipeline table has associated data that
16 * stores the action context. This data is input to the table action handler
17 * called for every input packet that hits the rule as part of the table lookup
18 * during the pipeline execution. The pipeline library allows the user to define
19 * his own table actions by providing customized table action handlers (table
20 * lookup) and complete freedom of setting the rules and their data (table rule
21 * add/delete). While the user can still follow this process, this API is
22 * intended to provide a quicker development alternative for a set of predefined
25 * The typical steps to use this API are:
26 * - Define a table action profile. This is a configuration template that can
27 * potentially be shared by multiple tables from the same or different
28 * pipelines, with different tables from the same pipeline likely to use
29 * different action profiles. For every table using a given action profile,
30 * the profile defines the set of actions and the action configuration to be
31 * implemented for all the table rules. API functions:
32 * rte_table_action_profile_create(),
33 * rte_table_action_profile_action_register(),
34 * rte_table_action_profile_freeze().
36 * - Instantiate the table action profile to create table action objects. Each
37 * pipeline table has its own table action object. API functions:
38 * rte_table_action_create().
40 * - Use the table action object to generate the pipeline table action handlers
41 * (invoked by the pipeline table lookup operation). API functions:
42 * rte_table_action_table_params_get().
44 * - Use the table action object to generate the rule data (for the pipeline
45 * table rule add operation) based on given action parameters. API functions:
46 * rte_table_action_apply().
48 * - Use the table action object to read action data (e.g. stats counters) for
49 * any given rule. API functions: rte_table_action_XYZ_read().
52 * @b EXPERIMENTAL: this API may change without prior notice
61 #include <rte_compat.h>
62 #include <rte_ether.h>
63 #include <rte_meter.h>
65 #include "rte_pipeline.h"
68 enum rte_table_action_type {
69 /** Forward to next pipeline table, output port or drop. */
70 RTE_TABLE_ACTION_FWD = 0,
72 /** Traffic Metering and Policing. */
75 /** Traffic Management. */
78 /** Packet encapsulations. */
79 RTE_TABLE_ACTION_ENCAP,
81 /** Network Address Translation (NAT). */
85 /** Common action configuration (per table action profile). */
86 struct rte_table_action_common_config {
87 /** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero
92 /** IP header offset within the input packet buffer. Offset 0 points to
93 * the first byte of the MBUF structure.
99 * RTE_TABLE_ACTION_FWD
101 /** Forward action parameters (per table rule). */
102 struct rte_table_action_fwd_params {
103 /** Forward action. */
104 enum rte_pipeline_action action;
106 /** Pipeline table ID or output port ID. */
111 * RTE_TABLE_ACTION_MTR
113 /** Max number of traffic classes (TCs). */
114 #define RTE_TABLE_ACTION_TC_MAX 4
116 /** Max number of queues per traffic class. */
117 #define RTE_TABLE_ACTION_TC_QUEUE_MAX 4
119 /** Differentiated Services Code Point (DSCP) translation table entry. */
120 struct rte_table_action_dscp_table_entry {
121 /** Traffic class. Used by the meter or the traffic management actions.
122 * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic
123 * class 0 is the highest priority.
127 /** Traffic class queue. Used by the traffic management action. Has to
128 * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*.
130 uint32_t tc_queue_id;
132 /** Packet color. Used by the meter action as the packet input color
133 * for the color aware mode of the traffic metering algorithm.
135 enum rte_meter_color color;
138 /** DSCP translation table. */
139 struct rte_table_action_dscp_table {
140 /** Array of DSCP table entries */
141 struct rte_table_action_dscp_table_entry entry[64];
144 /** Supported traffic metering algorithms. */
145 enum rte_table_action_meter_algorithm {
146 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
147 RTE_TABLE_ACTION_METER_SRTCM,
149 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
150 RTE_TABLE_ACTION_METER_TRTCM,
153 /** Traffic metering profile (configuration template). */
154 struct rte_table_action_meter_profile {
155 /** Traffic metering algorithm. */
156 enum rte_table_action_meter_algorithm alg;
160 /** Only valid when *alg* is set to srTCM - IETF RFC 2697. */
161 struct rte_meter_srtcm_params srtcm;
163 /** Only valid when *alg* is set to trTCM - IETF RFC 2698. */
164 struct rte_meter_trtcm_params trtcm;
168 /** Policer actions. */
169 enum rte_table_action_policer {
170 /** Recolor the packet as green. */
171 RTE_TABLE_ACTION_POLICER_COLOR_GREEN = 0,
173 /** Recolor the packet as yellow. */
174 RTE_TABLE_ACTION_POLICER_COLOR_YELLOW,
176 /** Recolor the packet as red. */
177 RTE_TABLE_ACTION_POLICER_COLOR_RED,
179 /** Drop the packet. */
180 RTE_TABLE_ACTION_POLICER_DROP,
182 /** Number of policer actions. */
183 RTE_TABLE_ACTION_POLICER_MAX
186 /** Meter action configuration per traffic class. */
187 struct rte_table_action_mtr_tc_params {
188 /** Meter profile ID. */
189 uint32_t meter_profile_id;
191 /** Policer actions. */
192 enum rte_table_action_policer policer[e_RTE_METER_COLORS];
195 /** Meter action statistics counters per traffic class. */
196 struct rte_table_action_mtr_counters_tc {
197 /** Number of packets per color at the output of the traffic metering
198 * and before the policer actions are executed. Only valid when
199 * *n_packets_valid* is non-zero.
201 uint64_t n_packets[e_RTE_METER_COLORS];
203 /** Number of packet bytes per color at the output of the traffic
204 * metering and before the policer actions are executed. Only valid when
205 * *n_bytes_valid* is non-zero.
207 uint64_t n_bytes[e_RTE_METER_COLORS];
209 /** When non-zero, the *n_packets* field is valid. */
212 /** When non-zero, the *n_bytes* field is valid. */
216 /** Meter action configuration (per table action profile). */
217 struct rte_table_action_mtr_config {
218 /** Meter algorithm. */
219 enum rte_table_action_meter_algorithm alg;
221 /** Number of traffic classes. Each traffic class has its own traffic
222 * meter and policer instances. Needs to be equal to either 1 or to
223 * *RTE_TABLE_ACTION_TC_MAX*.
227 /** When non-zero, the *n_packets* meter stats counter is enabled,
228 * otherwise it is disabled.
230 * @see struct rte_table_action_mtr_counters_tc
232 int n_packets_enabled;
234 /** When non-zero, the *n_bytes* meter stats counter is enabled,
235 * otherwise it is disabled.
237 * @see struct rte_table_action_mtr_counters_tc
242 /** Meter action parameters (per table rule). */
243 struct rte_table_action_mtr_params {
244 /** Traffic meter and policer parameters for each of the *tc_mask*
247 struct rte_table_action_mtr_tc_params mtr[RTE_TABLE_ACTION_TC_MAX];
249 /** Bit mask defining which traffic class parameters are valid in *mtr*.
250 * If bit N is set in *tc_mask*, then parameters for traffic class N are
256 /** Meter action statistics counters (per table rule). */
257 struct rte_table_action_mtr_counters {
258 /** Stats counters for each of the *tc_mask* traffic classes. */
259 struct rte_table_action_mtr_counters_tc stats[RTE_TABLE_ACTION_TC_MAX];
261 /** Bit mask defining which traffic class parameters are valid in *mtr*.
262 * If bit N is set in *tc_mask*, then parameters for traffic class N are
269 * RTE_TABLE_ACTION_TM
271 /** Traffic management action configuration (per table action profile). */
272 struct rte_table_action_tm_config {
273 /** Number of subports per port. */
274 uint32_t n_subports_per_port;
276 /** Number of pipes per subport. */
277 uint32_t n_pipes_per_subport;
280 /** Traffic management action parameters (per table rule). */
281 struct rte_table_action_tm_params {
290 * RTE_TABLE_ACTION_ENCAP
292 /** Supported packet encapsulation types. */
293 enum rte_table_action_encap_type {
294 /** IP -> { Ether | IP } */
295 RTE_TABLE_ACTION_ENCAP_ETHER = 0,
297 /** IP -> { Ether | VLAN | IP } */
298 RTE_TABLE_ACTION_ENCAP_VLAN,
300 /** IP -> { Ether | S-VLAN | C-VLAN | IP } */
301 RTE_TABLE_ACTION_ENCAP_QINQ,
303 /** IP -> { Ether | MPLS | IP } */
304 RTE_TABLE_ACTION_ENCAP_MPLS,
306 /** IP -> { Ether | PPPoE | PPP | IP } */
307 RTE_TABLE_ACTION_ENCAP_PPPOE,
310 /** Pre-computed Ethernet header fields for encapsulation action. */
311 struct rte_table_action_ether_hdr {
312 struct ether_addr da; /**< Destination address. */
313 struct ether_addr sa; /**< Source address. */
316 /** Pre-computed VLAN header fields for encapsulation action. */
317 struct rte_table_action_vlan_hdr {
318 uint8_t pcp; /**< Priority Code Point (PCP). */
319 uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
320 uint16_t vid; /**< VLAN Identifier (VID). */
323 /** Pre-computed MPLS header fields for encapsulation action. */
324 struct rte_table_action_mpls_hdr {
325 uint32_t label; /**< Label. */
326 uint8_t tc; /**< Traffic Class (TC). */
327 uint8_t ttl; /**< Time to Live (TTL). */
330 /** Pre-computed PPPoE header fields for encapsulation action. */
331 struct rte_table_action_pppoe_hdr {
332 uint16_t session_id; /**< Session ID. */
335 /** Ether encap parameters. */
336 struct rte_table_action_encap_ether_params {
337 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
340 /** VLAN encap parameters. */
341 struct rte_table_action_encap_vlan_params {
342 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
343 struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
346 /** QinQ encap parameters. */
347 struct rte_table_action_encap_qinq_params {
348 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
349 struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
350 struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
353 /** Max number of MPLS labels per output packet for MPLS encapsulation. */
354 #ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
355 #define RTE_TABLE_ACTION_MPLS_LABELS_MAX 4
358 /** MPLS encap parameters. */
359 struct rte_table_action_encap_mpls_params {
360 /** Ethernet header. */
361 struct rte_table_action_ether_hdr ether;
364 struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
366 /** Number of MPLS labels in MPLS header. */
369 /** Non-zero for MPLS unicast, zero for MPLS multicast. */
373 /** PPPoE encap parameters. */
374 struct rte_table_action_encap_pppoe_params {
375 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
376 struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
379 /** Encap action configuration (per table action profile). */
380 struct rte_table_action_encap_config {
381 /** Bit mask defining the set of packet encapsulations enabled for the
382 * current table action profile. If bit (1 << N) is set in *encap_mask*,
383 * then packet encapsulation N is enabled, otherwise it is disabled.
385 * @see enum rte_table_action_encap_type
390 /** Encap action parameters (per table rule). */
391 struct rte_table_action_encap_params {
392 /** Encapsulation type. */
393 enum rte_table_action_encap_type type;
397 /** Only valid when *type* is set to Ether. */
398 struct rte_table_action_encap_ether_params ether;
400 /** Only valid when *type* is set to VLAN. */
401 struct rte_table_action_encap_vlan_params vlan;
403 /** Only valid when *type* is set to QinQ. */
404 struct rte_table_action_encap_qinq_params qinq;
406 /** Only valid when *type* is set to MPLS. */
407 struct rte_table_action_encap_mpls_params mpls;
409 /** Only valid when *type* is set to PPPoE. */
410 struct rte_table_action_encap_pppoe_params pppoe;
415 * RTE_TABLE_ACTION_NAT
417 /** NAT action configuration (per table action profile). */
418 struct rte_table_action_nat_config {
419 /** When non-zero, the IP source address and L4 protocol source port are
420 * translated. When zero, the IP destination address and L4 protocol
421 * destination port are translated.
425 /** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum
426 * field is computed differently and placed at different header offset
427 * by each layer 4 protocol.
432 /** NAT action parameters (per table rule). */
433 struct rte_table_action_nat_params {
434 /** IP version for *addr*: non-zero for IPv4, zero for IPv6. */
439 /** IPv4 address; only valid when *ip_version* is non-zero. */
442 /** IPv6 address; only valid when *ip_version* is set to 0. */
451 * Table action profile.
453 struct rte_table_action_profile;
456 * Table action profile create.
459 * Common action configuration.
461 * Table action profile handle on success, NULL otherwise.
463 struct rte_table_action_profile * __rte_experimental
464 rte_table_action_profile_create(struct rte_table_action_common_config *common);
467 * Table action profile free.
470 * Table profile action handle (needs to be valid).
472 * Zero on success, non-zero error code otherwise.
474 int __rte_experimental
475 rte_table_action_profile_free(struct rte_table_action_profile *profile);
478 * Table action profile action register.
481 * Table profile action handle (needs to be valid and not in frozen state).
483 * Specific table action to be registered for *profile*.
484 * @param[in] action_config
485 * Configuration for the *type* action.
486 * If struct rte_table_action_*type*_config is defined by the Table Action
487 * API, it needs to point to a valid instance of this structure, otherwise it
488 * needs to be set to NULL.
490 * Zero on success, non-zero error code otherwise.
492 int __rte_experimental
493 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
494 enum rte_table_action_type type,
495 void *action_config);
498 * Table action profile freeze.
500 * Once this function is called successfully, the given profile enters the
501 * frozen state with the following immediate effects: no more actions can be
502 * registered for this profile, so the profile can be instantiated to create
503 * table action objects.
506 * Table profile action handle (needs to be valid and not in frozen state).
508 * Zero on success, non-zero error code otherwise.
510 * @see rte_table_action_create()
512 int __rte_experimental
513 rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
518 struct rte_table_action;
521 * Table action create.
523 * Instantiates the given table action profile to create a table action object.
526 * Table profile action handle (needs to be valid and in frozen state).
527 * @param[in] socket_id
528 * CPU socket ID where the internal data structures required by the new table
529 * action object should be allocated.
531 * Handle to table action object on success, NULL on error.
533 * @see rte_table_action_create()
535 struct rte_table_action * __rte_experimental
536 rte_table_action_create(struct rte_table_action_profile *profile,
543 * Handle to table action object (needs to be valid).
545 * Zero on success, non-zero error code otherwise.
547 int __rte_experimental
548 rte_table_action_free(struct rte_table_action *action);
551 * Table action table params get.
554 * Handle to table action object (needs to be valid).
555 * @param[inout] params
556 * Pipeline table parameters (needs to be pre-allocated).
558 * Zero on success, non-zero error code otherwise.
560 int __rte_experimental
561 rte_table_action_table_params_get(struct rte_table_action *action,
562 struct rte_pipeline_table_params *params);
565 * Table action apply.
568 * Handle to table action object (needs to be valid).
570 * Data byte array (typically table rule data) to apply action *type* on.
572 * Specific table action previously registered for the table action profile of
573 * the *action* object.
574 * @param[in] action_params
575 * Parameters for the *type* action.
576 * If struct rte_table_action_*type*_params is defined by the Table Action
577 * API, it needs to point to a valid instance of this structure, otherwise it
578 * needs to be set to NULL.
580 * Zero on success, non-zero error code otherwise.
582 int __rte_experimental
583 rte_table_action_apply(struct rte_table_action *action,
585 enum rte_table_action_type type,
586 void *action_params);
589 * Table action DSCP table update.
592 * Handle to table action object (needs to be valid).
593 * @param[in] dscp_mask
594 * 64-bit mask defining the DSCP table entries to be updated. If bit N is set
595 * in this bit mask, then DSCP table entry N is to be updated, otherwise not.
599 * Zero on success, non-zero error code otherwise.
601 int __rte_experimental
602 rte_table_action_dscp_table_update(struct rte_table_action *action,
604 struct rte_table_action_dscp_table *table);
607 * Table action meter profile add.
610 * Handle to table action object (needs to be valid).
611 * @param[in] meter_profile_id
612 * Meter profile ID to be used for the *profile* once it is successfully added
613 * to the *action* object (needs to be unused by the set of meter profiles
614 * currently registered for the *action* object).
616 * Meter profile to be added.
618 * Zero on success, non-zero error code otherwise.
620 int __rte_experimental
621 rte_table_action_meter_profile_add(struct rte_table_action *action,
622 uint32_t meter_profile_id,
623 struct rte_table_action_meter_profile *profile);
626 * Table action meter profile delete.
629 * Handle to table action object (needs to be valid).
630 * @param[in] meter_profile_id
631 * Meter profile ID of the meter profile to be deleted from the *action*
632 * object (needs to be valid for the *action* object).
634 * Zero on success, non-zero error code otherwise.
636 int __rte_experimental
637 rte_table_action_meter_profile_delete(struct rte_table_action *action,
638 uint32_t meter_profile_id);
641 * Table action meter read.
644 * Handle to table action object (needs to be valid).
646 * Data byte array (typically table rule data) with meter action previously
649 * Bit mask defining which traffic classes should have the meter stats
650 * counters read from *data* and stored into *stats*. If bit N is set in this
651 * bit mask, then traffic class N is part of this operation, otherwise it is
652 * not. If bit N is set in this bit mask, then traffic class N must be one of
653 * the traffic classes that are enabled for the meter action in the table
654 * action profile used by the *action* object.
655 * @param[inout] stats
656 * When non-NULL, it points to the area where the meter stats counters read
657 * from *data* are saved. Only the meter stats counters for the *tc_mask*
658 * traffic classes are read and stored to *stats*.
660 * When non-zero, the meter stats counters are cleared (i.e. set to zero),
661 * otherwise the counters are not modified. When the read operation is enabled
662 * (*stats* is non-NULL), the clear operation is performed after the read
663 * operation is completed.
665 * Zero on success, non-zero error code otherwise.
667 int __rte_experimental
668 rte_table_action_meter_read(struct rte_table_action *action,
671 struct rte_table_action_mtr_counters *stats,
678 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */