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,
82 /** Common action configuration (per table action profile). */
83 struct rte_table_action_common_config {
84 /** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero
89 /** IP header offset within the input packet buffer. Offset 0 points to
90 * the first byte of the MBUF structure.
96 * RTE_TABLE_ACTION_FWD
98 /** Forward action parameters (per table rule). */
99 struct rte_table_action_fwd_params {
100 /** Forward action. */
101 enum rte_pipeline_action action;
103 /** Pipeline table ID or output port ID. */
108 * RTE_TABLE_ACTION_MTR
110 /** Max number of traffic classes (TCs). */
111 #define RTE_TABLE_ACTION_TC_MAX 4
113 /** Max number of queues per traffic class. */
114 #define RTE_TABLE_ACTION_TC_QUEUE_MAX 4
116 /** Differentiated Services Code Point (DSCP) translation table entry. */
117 struct rte_table_action_dscp_table_entry {
118 /** Traffic class. Used by the meter or the traffic management actions.
119 * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic
120 * class 0 is the highest priority.
124 /** Traffic class queue. Used by the traffic management action. Has to
125 * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*.
127 uint32_t tc_queue_id;
129 /** Packet color. Used by the meter action as the packet input color
130 * for the color aware mode of the traffic metering algorithm.
132 enum rte_meter_color color;
135 /** DSCP translation table. */
136 struct rte_table_action_dscp_table {
137 /** Array of DSCP table entries */
138 struct rte_table_action_dscp_table_entry entry[64];
141 /** Supported traffic metering algorithms. */
142 enum rte_table_action_meter_algorithm {
143 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
144 RTE_TABLE_ACTION_METER_SRTCM,
146 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
147 RTE_TABLE_ACTION_METER_TRTCM,
150 /** Traffic metering profile (configuration template). */
151 struct rte_table_action_meter_profile {
152 /** Traffic metering algorithm. */
153 enum rte_table_action_meter_algorithm alg;
157 /** Only valid when *alg* is set to srTCM - IETF RFC 2697. */
158 struct rte_meter_srtcm_params srtcm;
160 /** Only valid when *alg* is set to trTCM - IETF RFC 2698. */
161 struct rte_meter_trtcm_params trtcm;
165 /** Policer actions. */
166 enum rte_table_action_policer {
167 /** Recolor the packet as green. */
168 RTE_TABLE_ACTION_POLICER_COLOR_GREEN = 0,
170 /** Recolor the packet as yellow. */
171 RTE_TABLE_ACTION_POLICER_COLOR_YELLOW,
173 /** Recolor the packet as red. */
174 RTE_TABLE_ACTION_POLICER_COLOR_RED,
176 /** Drop the packet. */
177 RTE_TABLE_ACTION_POLICER_DROP,
179 /** Number of policer actions. */
180 RTE_TABLE_ACTION_POLICER_MAX
183 /** Meter action configuration per traffic class. */
184 struct rte_table_action_mtr_tc_params {
185 /** Meter profile ID. */
186 uint32_t meter_profile_id;
188 /** Policer actions. */
189 enum rte_table_action_policer policer[e_RTE_METER_COLORS];
192 /** Meter action statistics counters per traffic class. */
193 struct rte_table_action_mtr_counters_tc {
194 /** Number of packets per color at the output of the traffic metering
195 * and before the policer actions are executed. Only valid when
196 * *n_packets_valid* is non-zero.
198 uint64_t n_packets[e_RTE_METER_COLORS];
200 /** Number of packet bytes per color at the output of the traffic
201 * metering and before the policer actions are executed. Only valid when
202 * *n_bytes_valid* is non-zero.
204 uint64_t n_bytes[e_RTE_METER_COLORS];
206 /** When non-zero, the *n_packets* field is valid. */
209 /** When non-zero, the *n_bytes* field is valid. */
213 /** Meter action configuration (per table action profile). */
214 struct rte_table_action_mtr_config {
215 /** Meter algorithm. */
216 enum rte_table_action_meter_algorithm alg;
218 /** Number of traffic classes. Each traffic class has its own traffic
219 * meter and policer instances. Needs to be equal to either 1 or to
220 * *RTE_TABLE_ACTION_TC_MAX*.
224 /** When non-zero, the *n_packets* meter stats counter is enabled,
225 * otherwise it is disabled.
227 * @see struct rte_table_action_mtr_counters_tc
229 int n_packets_enabled;
231 /** When non-zero, the *n_bytes* meter stats counter is enabled,
232 * otherwise it is disabled.
234 * @see struct rte_table_action_mtr_counters_tc
239 /** Meter action parameters (per table rule). */
240 struct rte_table_action_mtr_params {
241 /** Traffic meter and policer parameters for each of the *tc_mask*
244 struct rte_table_action_mtr_tc_params mtr[RTE_TABLE_ACTION_TC_MAX];
246 /** Bit mask defining which traffic class parameters are valid in *mtr*.
247 * If bit N is set in *tc_mask*, then parameters for traffic class N are
253 /** Meter action statistics counters (per table rule). */
254 struct rte_table_action_mtr_counters {
255 /** Stats counters for each of the *tc_mask* traffic classes. */
256 struct rte_table_action_mtr_counters_tc stats[RTE_TABLE_ACTION_TC_MAX];
258 /** Bit mask defining which traffic class parameters are valid in *mtr*.
259 * If bit N is set in *tc_mask*, then parameters for traffic class N are
266 * RTE_TABLE_ACTION_TM
268 /** Traffic management action configuration (per table action profile). */
269 struct rte_table_action_tm_config {
270 /** Number of subports per port. */
271 uint32_t n_subports_per_port;
273 /** Number of pipes per subport. */
274 uint32_t n_pipes_per_subport;
277 /** Traffic management action parameters (per table rule). */
278 struct rte_table_action_tm_params {
287 * RTE_TABLE_ACTION_ENCAP
289 /** Supported packet encapsulation types. */
290 enum rte_table_action_encap_type {
291 /** IP -> { Ether | IP } */
292 RTE_TABLE_ACTION_ENCAP_ETHER = 0,
294 /** IP -> { Ether | VLAN | IP } */
295 RTE_TABLE_ACTION_ENCAP_VLAN,
297 /** IP -> { Ether | S-VLAN | C-VLAN | IP } */
298 RTE_TABLE_ACTION_ENCAP_QINQ,
300 /** IP -> { Ether | MPLS | IP } */
301 RTE_TABLE_ACTION_ENCAP_MPLS,
303 /** IP -> { Ether | PPPoE | PPP | IP } */
304 RTE_TABLE_ACTION_ENCAP_PPPOE,
307 /** Pre-computed Ethernet header fields for encapsulation action. */
308 struct rte_table_action_ether_hdr {
309 struct ether_addr da; /**< Destination address. */
310 struct ether_addr sa; /**< Source address. */
313 /** Pre-computed VLAN header fields for encapsulation action. */
314 struct rte_table_action_vlan_hdr {
315 uint8_t pcp; /**< Priority Code Point (PCP). */
316 uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
317 uint16_t vid; /**< VLAN Identifier (VID). */
320 /** Pre-computed MPLS header fields for encapsulation action. */
321 struct rte_table_action_mpls_hdr {
322 uint32_t label; /**< Label. */
323 uint8_t tc; /**< Traffic Class (TC). */
324 uint8_t ttl; /**< Time to Live (TTL). */
327 /** Pre-computed PPPoE header fields for encapsulation action. */
328 struct rte_table_action_pppoe_hdr {
329 uint16_t session_id; /**< Session ID. */
332 /** Ether encap parameters. */
333 struct rte_table_action_encap_ether_params {
334 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
337 /** VLAN encap parameters. */
338 struct rte_table_action_encap_vlan_params {
339 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
340 struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
343 /** QinQ encap parameters. */
344 struct rte_table_action_encap_qinq_params {
345 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
346 struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
347 struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
350 /** Max number of MPLS labels per output packet for MPLS encapsulation. */
351 #ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
352 #define RTE_TABLE_ACTION_MPLS_LABELS_MAX 4
355 /** MPLS encap parameters. */
356 struct rte_table_action_encap_mpls_params {
357 /** Ethernet header. */
358 struct rte_table_action_ether_hdr ether;
361 struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
363 /** Number of MPLS labels in MPLS header. */
366 /** Non-zero for MPLS unicast, zero for MPLS multicast. */
370 /** PPPoE encap parameters. */
371 struct rte_table_action_encap_pppoe_params {
372 struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
373 struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
376 /** Encap action configuration (per table action profile). */
377 struct rte_table_action_encap_config {
378 /** Bit mask defining the set of packet encapsulations enabled for the
379 * current table action profile. If bit (1 << N) is set in *encap_mask*,
380 * then packet encapsulation N is enabled, otherwise it is disabled.
382 * @see enum rte_table_action_encap_type
387 /** Encap action parameters (per table rule). */
388 struct rte_table_action_encap_params {
389 /** Encapsulation type. */
390 enum rte_table_action_encap_type type;
394 /** Only valid when *type* is set to Ether. */
395 struct rte_table_action_encap_ether_params ether;
397 /** Only valid when *type* is set to VLAN. */
398 struct rte_table_action_encap_vlan_params vlan;
400 /** Only valid when *type* is set to QinQ. */
401 struct rte_table_action_encap_qinq_params qinq;
403 /** Only valid when *type* is set to MPLS. */
404 struct rte_table_action_encap_mpls_params mpls;
406 /** Only valid when *type* is set to PPPoE. */
407 struct rte_table_action_encap_pppoe_params pppoe;
412 * Table action profile.
414 struct rte_table_action_profile;
417 * Table action profile create.
420 * Common action configuration.
422 * Table action profile handle on success, NULL otherwise.
424 struct rte_table_action_profile * __rte_experimental
425 rte_table_action_profile_create(struct rte_table_action_common_config *common);
428 * Table action profile free.
431 * Table profile action handle (needs to be valid).
433 * Zero on success, non-zero error code otherwise.
435 int __rte_experimental
436 rte_table_action_profile_free(struct rte_table_action_profile *profile);
439 * Table action profile action register.
442 * Table profile action handle (needs to be valid and not in frozen state).
444 * Specific table action to be registered for *profile*.
445 * @param[in] action_config
446 * Configuration for the *type* action.
447 * If struct rte_table_action_*type*_config is defined by the Table Action
448 * API, it needs to point to a valid instance of this structure, otherwise it
449 * needs to be set to NULL.
451 * Zero on success, non-zero error code otherwise.
453 int __rte_experimental
454 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
455 enum rte_table_action_type type,
456 void *action_config);
459 * Table action profile freeze.
461 * Once this function is called successfully, the given profile enters the
462 * frozen state with the following immediate effects: no more actions can be
463 * registered for this profile, so the profile can be instantiated to create
464 * table action objects.
467 * Table profile action handle (needs to be valid and not in frozen state).
469 * Zero on success, non-zero error code otherwise.
471 * @see rte_table_action_create()
473 int __rte_experimental
474 rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
479 struct rte_table_action;
482 * Table action create.
484 * Instantiates the given table action profile to create a table action object.
487 * Table profile action handle (needs to be valid and in frozen state).
488 * @param[in] socket_id
489 * CPU socket ID where the internal data structures required by the new table
490 * action object should be allocated.
492 * Handle to table action object on success, NULL on error.
494 * @see rte_table_action_create()
496 struct rte_table_action * __rte_experimental
497 rte_table_action_create(struct rte_table_action_profile *profile,
504 * Handle to table action object (needs to be valid).
506 * Zero on success, non-zero error code otherwise.
508 int __rte_experimental
509 rte_table_action_free(struct rte_table_action *action);
512 * Table action table params get.
515 * Handle to table action object (needs to be valid).
516 * @param[inout] params
517 * Pipeline table parameters (needs to be pre-allocated).
519 * Zero on success, non-zero error code otherwise.
521 int __rte_experimental
522 rte_table_action_table_params_get(struct rte_table_action *action,
523 struct rte_pipeline_table_params *params);
526 * Table action apply.
529 * Handle to table action object (needs to be valid).
531 * Data byte array (typically table rule data) to apply action *type* on.
533 * Specific table action previously registered for the table action profile of
534 * the *action* object.
535 * @param[in] action_params
536 * Parameters for the *type* action.
537 * If struct rte_table_action_*type*_params is defined by the Table Action
538 * API, it needs to point to a valid instance of this structure, otherwise it
539 * needs to be set to NULL.
541 * Zero on success, non-zero error code otherwise.
543 int __rte_experimental
544 rte_table_action_apply(struct rte_table_action *action,
546 enum rte_table_action_type type,
547 void *action_params);
550 * Table action DSCP table update.
553 * Handle to table action object (needs to be valid).
554 * @param[in] dscp_mask
555 * 64-bit mask defining the DSCP table entries to be updated. If bit N is set
556 * in this bit mask, then DSCP table entry N is to be updated, otherwise not.
560 * Zero on success, non-zero error code otherwise.
562 int __rte_experimental
563 rte_table_action_dscp_table_update(struct rte_table_action *action,
565 struct rte_table_action_dscp_table *table);
568 * Table action meter profile add.
571 * Handle to table action object (needs to be valid).
572 * @param[in] meter_profile_id
573 * Meter profile ID to be used for the *profile* once it is successfully added
574 * to the *action* object (needs to be unused by the set of meter profiles
575 * currently registered for the *action* object).
577 * Meter profile to be added.
579 * Zero on success, non-zero error code otherwise.
581 int __rte_experimental
582 rte_table_action_meter_profile_add(struct rte_table_action *action,
583 uint32_t meter_profile_id,
584 struct rte_table_action_meter_profile *profile);
587 * Table action meter profile delete.
590 * Handle to table action object (needs to be valid).
591 * @param[in] meter_profile_id
592 * Meter profile ID of the meter profile to be deleted from the *action*
593 * object (needs to be valid for the *action* object).
595 * Zero on success, non-zero error code otherwise.
597 int __rte_experimental
598 rte_table_action_meter_profile_delete(struct rte_table_action *action,
599 uint32_t meter_profile_id);
602 * Table action meter read.
605 * Handle to table action object (needs to be valid).
607 * Data byte array (typically table rule data) with meter action previously
610 * Bit mask defining which traffic classes should have the meter stats
611 * counters read from *data* and stored into *stats*. If bit N is set in this
612 * bit mask, then traffic class N is part of this operation, otherwise it is
613 * not. If bit N is set in this bit mask, then traffic class N must be one of
614 * the traffic classes that are enabled for the meter action in the table
615 * action profile used by the *action* object.
616 * @param[inout] stats
617 * When non-NULL, it points to the area where the meter stats counters read
618 * from *data* are saved. Only the meter stats counters for the *tc_mask*
619 * traffic classes are read and stored to *stats*.
621 * When non-zero, the meter stats counters are cleared (i.e. set to zero),
622 * otherwise the counters are not modified. When the read operation is enabled
623 * (*stats* is non-NULL), the clear operation is performed after the read
624 * operation is completed.
626 * Zero on success, non-zero error code otherwise.
628 int __rte_experimental
629 rte_table_action_meter_read(struct rte_table_action *action,
632 struct rte_table_action_mtr_counters *stats,
639 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */