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). */
84 /** Time to Live (TTL) update. */
88 /** Common action configuration (per table action profile). */
89 struct rte_table_action_common_config {
90 /** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero
95 /** IP header offset within the input packet buffer. Offset 0 points to
96 * the first byte of the MBUF structure.
102 * RTE_TABLE_ACTION_FWD
104 /** Forward action parameters (per table rule). */
105 struct rte_table_action_fwd_params {
106 /** Forward action. */
107 enum rte_pipeline_action action;
109 /** Pipeline table ID or output port ID. */
114 * RTE_TABLE_ACTION_MTR
116 /** Max number of traffic classes (TCs). */
117 #define RTE_TABLE_ACTION_TC_MAX 4
119 /** Max number of queues per traffic class. */
120 #define RTE_TABLE_ACTION_TC_QUEUE_MAX 4
122 /** Differentiated Services Code Point (DSCP) translation table entry. */
123 struct rte_table_action_dscp_table_entry {
124 /** Traffic class. Used by the meter or the traffic management actions.
125 * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic
126 * class 0 is the highest priority.
130 /** Traffic class queue. Used by the traffic management action. Has to
131 * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*.
133 uint32_t tc_queue_id;
135 /** Packet color. Used by the meter action as the packet input color
136 * for the color aware mode of the traffic metering algorithm.
138 enum rte_meter_color color;
141 /** DSCP translation table. */
142 struct rte_table_action_dscp_table {
143 /** Array of DSCP table entries */
144 struct rte_table_action_dscp_table_entry entry[64];
147 /** Supported traffic metering algorithms. */
148 enum rte_table_action_meter_algorithm {
149 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
150 RTE_TABLE_ACTION_METER_SRTCM,
152 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
153 RTE_TABLE_ACTION_METER_TRTCM,
156 /** Traffic metering profile (configuration template). */
157 struct rte_table_action_meter_profile {
158 /** Traffic metering algorithm. */
159 enum rte_table_action_meter_algorithm alg;
163 /** Only valid when *alg* is set to srTCM - IETF RFC 2697. */
164 struct rte_meter_srtcm_params srtcm;
166 /** Only valid when *alg* is set to trTCM - IETF RFC 2698. */
167 struct rte_meter_trtcm_params trtcm;
171 /** Policer actions. */
172 enum rte_table_action_policer {
173 /** Recolor the packet as green. */
174 RTE_TABLE_ACTION_POLICER_COLOR_GREEN = 0,
176 /** Recolor the packet as yellow. */
177 RTE_TABLE_ACTION_POLICER_COLOR_YELLOW,
179 /** Recolor the packet as red. */
180 RTE_TABLE_ACTION_POLICER_COLOR_RED,
182 /** Drop the packet. */
183 RTE_TABLE_ACTION_POLICER_DROP,
185 /** Number of policer actions. */
186 RTE_TABLE_ACTION_POLICER_MAX
189 /** Meter action configuration per traffic class. */
190 struct rte_table_action_mtr_tc_params {
191 /** Meter profile ID. */
192 uint32_t meter_profile_id;
194 /** Policer actions. */
195 enum rte_table_action_policer policer[e_RTE_METER_COLORS];
198 /** Meter action statistics counters per traffic class. */
199 struct rte_table_action_mtr_counters_tc {
200 /** Number of packets per color at the output of the traffic metering
201 * and before the policer actions are executed. Only valid when
202 * *n_packets_valid* is non-zero.
204 uint64_t n_packets[e_RTE_METER_COLORS];
206 /** Number of packet bytes per color at the output of the traffic
207 * metering and before the policer actions are executed. Only valid when
208 * *n_bytes_valid* is non-zero.
210 uint64_t n_bytes[e_RTE_METER_COLORS];
212 /** When non-zero, the *n_packets* field is valid. */
215 /** When non-zero, the *n_bytes* field is valid. */
219 /** Meter action configuration (per table action profile). */
220 struct rte_table_action_mtr_config {
221 /** Meter algorithm. */
222 enum rte_table_action_meter_algorithm alg;
224 /** Number of traffic classes. Each traffic class has its own traffic
225 * meter and policer instances. Needs to be equal to either 1 or to
226 * *RTE_TABLE_ACTION_TC_MAX*.
230 /** When non-zero, the *n_packets* meter stats counter is enabled,
231 * otherwise it is disabled.
233 * @see struct rte_table_action_mtr_counters_tc
235 int n_packets_enabled;
237 /** When non-zero, the *n_bytes* meter stats counter is enabled,
238 * otherwise it is disabled.
240 * @see struct rte_table_action_mtr_counters_tc
245 /** Meter action parameters (per table rule). */
246 struct rte_table_action_mtr_params {
247 /** Traffic meter and policer parameters for each of the *tc_mask*
250 struct rte_table_action_mtr_tc_params mtr[RTE_TABLE_ACTION_TC_MAX];
252 /** Bit mask defining which traffic class parameters are valid in *mtr*.
253 * If bit N is set in *tc_mask*, then parameters for traffic class N are
259 /** Meter action statistics counters (per table rule). */
260 struct rte_table_action_mtr_counters {
261 /** Stats counters for each of the *tc_mask* traffic classes. */
262 struct rte_table_action_mtr_counters_tc stats[RTE_TABLE_ACTION_TC_MAX];
264 /** Bit mask defining which traffic class parameters are valid in *mtr*.
265 * If bit N is set in *tc_mask*, then parameters for traffic class N are
272 * RTE_TABLE_ACTION_TM
274 /** Traffic management action configuration (per table action profile). */
275 struct rte_table_action_tm_config {
276 /** Number of subports per port. */
277 uint32_t n_subports_per_port;
279 /** Number of pipes per subport. */
280 uint32_t n_pipes_per_subport;
283 /** Traffic management action parameters (per table rule). */
284 struct rte_table_action_tm_params {
293 * RTE_TABLE_ACTION_ENCAP
295 /** Supported packet encapsulation types. */
296 enum rte_table_action_encap_type {
297 /** IP -> { Ether | IP } */
298 RTE_TABLE_ACTION_ENCAP_ETHER = 0,
300 /** IP -> { Ether | VLAN | IP } */
301 RTE_TABLE_ACTION_ENCAP_VLAN,
303 /** IP -> { Ether | S-VLAN | C-VLAN | IP } */
304 RTE_TABLE_ACTION_ENCAP_QINQ,
306 /** IP -> { Ether | MPLS | IP } */
307 RTE_TABLE_ACTION_ENCAP_MPLS,
309 /** IP -> { Ether | PPPoE | PPP | IP } */
310 RTE_TABLE_ACTION_ENCAP_PPPOE,
313 /** Pre-computed Ethernet header fields for encapsulation action. */
314 struct rte_table_action_ether_hdr {
315 struct ether_addr da; /**< Destination address. */
316 struct ether_addr sa; /**< Source address. */
319 /** Pre-computed VLAN header fields for encapsulation action. */
320 struct rte_table_action_vlan_hdr {
321 uint8_t pcp; /**< Priority Code Point (PCP). */
322 uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
323 uint16_t vid; /**< VLAN Identifier (VID). */
326 /** Pre-computed MPLS header fields for encapsulation action. */
327 struct rte_table_action_mpls_hdr {
328 uint32_t label; /**< Label. */
329 uint8_t tc; /**< Traffic Class (TC). */
330 uint8_t ttl; /**< Time to Live (TTL). */
333 /** Pre-computed PPPoE header fields for encapsulation action. */
334 struct rte_table_action_pppoe_hdr {
335 uint16_t session_id; /**< Session ID. */
338 /** Ether encap parameters. */
339 struct rte_table_action_encap_ether_params {
340 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
343 /** VLAN encap parameters. */
344 struct rte_table_action_encap_vlan_params {
345 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
346 struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
349 /** QinQ encap parameters. */
350 struct rte_table_action_encap_qinq_params {
351 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
352 struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
353 struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
356 /** Max number of MPLS labels per output packet for MPLS encapsulation. */
357 #ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
358 #define RTE_TABLE_ACTION_MPLS_LABELS_MAX 4
361 /** MPLS encap parameters. */
362 struct rte_table_action_encap_mpls_params {
363 /** Ethernet header. */
364 struct rte_table_action_ether_hdr ether;
367 struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
369 /** Number of MPLS labels in MPLS header. */
372 /** Non-zero for MPLS unicast, zero for MPLS multicast. */
376 /** PPPoE encap parameters. */
377 struct rte_table_action_encap_pppoe_params {
378 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
379 struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
382 /** Encap action configuration (per table action profile). */
383 struct rte_table_action_encap_config {
384 /** Bit mask defining the set of packet encapsulations enabled for the
385 * current table action profile. If bit (1 << N) is set in *encap_mask*,
386 * then packet encapsulation N is enabled, otherwise it is disabled.
388 * @see enum rte_table_action_encap_type
393 /** Encap action parameters (per table rule). */
394 struct rte_table_action_encap_params {
395 /** Encapsulation type. */
396 enum rte_table_action_encap_type type;
400 /** Only valid when *type* is set to Ether. */
401 struct rte_table_action_encap_ether_params ether;
403 /** Only valid when *type* is set to VLAN. */
404 struct rte_table_action_encap_vlan_params vlan;
406 /** Only valid when *type* is set to QinQ. */
407 struct rte_table_action_encap_qinq_params qinq;
409 /** Only valid when *type* is set to MPLS. */
410 struct rte_table_action_encap_mpls_params mpls;
412 /** Only valid when *type* is set to PPPoE. */
413 struct rte_table_action_encap_pppoe_params pppoe;
418 * RTE_TABLE_ACTION_NAT
420 /** NAT action configuration (per table action profile). */
421 struct rte_table_action_nat_config {
422 /** When non-zero, the IP source address and L4 protocol source port are
423 * translated. When zero, the IP destination address and L4 protocol
424 * destination port are translated.
428 /** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum
429 * field is computed differently and placed at different header offset
430 * by each layer 4 protocol.
435 /** NAT action parameters (per table rule). */
436 struct rte_table_action_nat_params {
437 /** IP version for *addr*: non-zero for IPv4, zero for IPv6. */
442 /** IPv4 address; only valid when *ip_version* is non-zero. */
445 /** IPv6 address; only valid when *ip_version* is set to 0. */
454 * RTE_TABLE_ACTION_TTL
456 /** TTL action configuration (per table action profile). */
457 struct rte_table_action_ttl_config {
458 /** When non-zero, the input packets whose updated IPv4 Time to Live
459 * (TTL) field or IPv6 Hop Limit (HL) field is zero are dropped.
460 * When zero, the input packets whose updated IPv4 TTL field or IPv6 HL
461 * field is zero are forwarded as usual (typically for debugging
466 /** When non-zero, the *n_packets* stats counter for TTL action is
467 * enabled, otherwise disabled.
469 * @see struct rte_table_action_ttl_counters
471 int n_packets_enabled;
474 /** TTL action parameters (per table rule). */
475 struct rte_table_action_ttl_params {
476 /** When non-zero, decrement the IPv4 TTL field and update the checksum
477 * field, or decrement the IPv6 HL field. When zero, the IPv4 TTL field
478 * or the IPv6 HL field is not changed.
483 /** TTL action statistics packets (per table rule). */
484 struct rte_table_action_ttl_counters {
485 /** Number of IPv4 packets whose updated TTL field is zero or IPv6
486 * packets whose updated HL field is zero.
492 * Table action profile.
494 struct rte_table_action_profile;
497 * Table action profile create.
500 * Common action configuration.
502 * Table action profile handle on success, NULL otherwise.
504 struct rte_table_action_profile * __rte_experimental
505 rte_table_action_profile_create(struct rte_table_action_common_config *common);
508 * Table action profile free.
511 * Table profile action handle (needs to be valid).
513 * Zero on success, non-zero error code otherwise.
515 int __rte_experimental
516 rte_table_action_profile_free(struct rte_table_action_profile *profile);
519 * Table action profile action register.
522 * Table profile action handle (needs to be valid and not in frozen state).
524 * Specific table action to be registered for *profile*.
525 * @param[in] action_config
526 * Configuration for the *type* action.
527 * If struct rte_table_action_*type*_config is defined by the Table Action
528 * API, it needs to point to a valid instance of this structure, otherwise it
529 * needs to be set to NULL.
531 * Zero on success, non-zero error code otherwise.
533 int __rte_experimental
534 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
535 enum rte_table_action_type type,
536 void *action_config);
539 * Table action profile freeze.
541 * Once this function is called successfully, the given profile enters the
542 * frozen state with the following immediate effects: no more actions can be
543 * registered for this profile, so the profile can be instantiated to create
544 * table action objects.
547 * Table profile action handle (needs to be valid and not in frozen state).
549 * Zero on success, non-zero error code otherwise.
551 * @see rte_table_action_create()
553 int __rte_experimental
554 rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
559 struct rte_table_action;
562 * Table action create.
564 * Instantiates the given table action profile to create a table action object.
567 * Table profile action handle (needs to be valid and in frozen state).
568 * @param[in] socket_id
569 * CPU socket ID where the internal data structures required by the new table
570 * action object should be allocated.
572 * Handle to table action object on success, NULL on error.
574 * @see rte_table_action_create()
576 struct rte_table_action * __rte_experimental
577 rte_table_action_create(struct rte_table_action_profile *profile,
584 * Handle to table action object (needs to be valid).
586 * Zero on success, non-zero error code otherwise.
588 int __rte_experimental
589 rte_table_action_free(struct rte_table_action *action);
592 * Table action table params get.
595 * Handle to table action object (needs to be valid).
596 * @param[inout] params
597 * Pipeline table parameters (needs to be pre-allocated).
599 * Zero on success, non-zero error code otherwise.
601 int __rte_experimental
602 rte_table_action_table_params_get(struct rte_table_action *action,
603 struct rte_pipeline_table_params *params);
606 * Table action apply.
609 * Handle to table action object (needs to be valid).
611 * Data byte array (typically table rule data) to apply action *type* on.
613 * Specific table action previously registered for the table action profile of
614 * the *action* object.
615 * @param[in] action_params
616 * Parameters for the *type* action.
617 * If struct rte_table_action_*type*_params is defined by the Table Action
618 * API, it needs to point to a valid instance of this structure, otherwise it
619 * needs to be set to NULL.
621 * Zero on success, non-zero error code otherwise.
623 int __rte_experimental
624 rte_table_action_apply(struct rte_table_action *action,
626 enum rte_table_action_type type,
627 void *action_params);
630 * Table action DSCP table update.
633 * Handle to table action object (needs to be valid).
634 * @param[in] dscp_mask
635 * 64-bit mask defining the DSCP table entries to be updated. If bit N is set
636 * in this bit mask, then DSCP table entry N is to be updated, otherwise not.
640 * Zero on success, non-zero error code otherwise.
642 int __rte_experimental
643 rte_table_action_dscp_table_update(struct rte_table_action *action,
645 struct rte_table_action_dscp_table *table);
648 * Table action meter profile add.
651 * Handle to table action object (needs to be valid).
652 * @param[in] meter_profile_id
653 * Meter profile ID to be used for the *profile* once it is successfully added
654 * to the *action* object (needs to be unused by the set of meter profiles
655 * currently registered for the *action* object).
657 * Meter profile to be added.
659 * Zero on success, non-zero error code otherwise.
661 int __rte_experimental
662 rte_table_action_meter_profile_add(struct rte_table_action *action,
663 uint32_t meter_profile_id,
664 struct rte_table_action_meter_profile *profile);
667 * Table action meter profile delete.
670 * Handle to table action object (needs to be valid).
671 * @param[in] meter_profile_id
672 * Meter profile ID of the meter profile to be deleted from the *action*
673 * object (needs to be valid for the *action* object).
675 * Zero on success, non-zero error code otherwise.
677 int __rte_experimental
678 rte_table_action_meter_profile_delete(struct rte_table_action *action,
679 uint32_t meter_profile_id);
682 * Table action meter read.
685 * Handle to table action object (needs to be valid).
687 * Data byte array (typically table rule data) with meter action previously
690 * Bit mask defining which traffic classes should have the meter stats
691 * counters read from *data* and stored into *stats*. If bit N is set in this
692 * bit mask, then traffic class N is part of this operation, otherwise it is
693 * not. If bit N is set in this bit mask, then traffic class N must be one of
694 * the traffic classes that are enabled for the meter action in the table
695 * action profile used by the *action* object.
696 * @param[inout] stats
697 * When non-NULL, it points to the area where the meter stats counters read
698 * from *data* are saved. Only the meter stats counters for the *tc_mask*
699 * traffic classes are read and stored to *stats*.
701 * When non-zero, the meter stats counters are cleared (i.e. set to zero),
702 * otherwise the counters are not modified. When the read operation is enabled
703 * (*stats* is non-NULL), the clear operation is performed after the read
704 * operation is completed.
706 * Zero on success, non-zero error code otherwise.
708 int __rte_experimental
709 rte_table_action_meter_read(struct rte_table_action *action,
712 struct rte_table_action_mtr_counters *stats,
716 * Table action TTL read.
719 * Handle to table action object (needs to be valid).
721 * Data byte array (typically table rule data) with TTL action previously
723 * @param[inout] stats
724 * When non-NULL, it points to the area where the TTL stats counters read from
727 * When non-zero, the TTL stats counters are cleared (i.e. set to zero),
728 * otherwise the counters are not modified. When the read operation is enabled
729 * (*stats* is non-NULL), the clear operation is performed after the read
730 * operation is completed.
732 * Zero on success, non-zero error code otherwise.
734 int __rte_experimental
735 rte_table_action_ttl_read(struct rte_table_action *action,
737 struct rte_table_action_ttl_counters *stats,
744 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */