xref: /dpdk/lib/pipeline/rte_table_action.h (revision 25a2a0dc3de31ca0a6fbc9371cf3dd85dfd74b07)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 
5 #ifndef __INCLUDE_RTE_TABLE_ACTION_H__
6 #define __INCLUDE_RTE_TABLE_ACTION_H__
7 
8 /**
9  * @file
10  * RTE Pipeline Table Actions
11  *
12  * This API provides a common set of actions for pipeline tables to speed up
13  * application development.
14  *
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
23  * actions.
24  *
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().
35  *
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().
39  *
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().
43  *
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().
47  *
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().
50  *
51  * @warning
52  * @b EXPERIMENTAL: this API may change without prior notice
53  */
54 
55 #include <stdint.h>
56 
57 #include <rte_compat.h>
58 #include <rte_ether.h>
59 #include <rte_meter.h>
60 #include <rte_table_hash.h>
61 
62 #include "rte_pipeline.h"
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /** Table actions. */
69 enum rte_table_action_type {
70 	/** Forward to next pipeline table, output port or drop. */
71 	RTE_TABLE_ACTION_FWD = 0,
72 
73 	/**  Load balance. */
74 	RTE_TABLE_ACTION_LB,
75 
76 	/**  Traffic Metering and Policing. */
77 	RTE_TABLE_ACTION_MTR,
78 
79 	/**  Traffic Management. */
80 	RTE_TABLE_ACTION_TM,
81 
82 	/** Packet encapsulations. */
83 	RTE_TABLE_ACTION_ENCAP,
84 
85 	/** Network Address Translation (NAT). */
86 	RTE_TABLE_ACTION_NAT,
87 
88 	/** Time to Live (TTL) update. */
89 	RTE_TABLE_ACTION_TTL,
90 
91 	/** Statistics. */
92 	RTE_TABLE_ACTION_STATS,
93 
94 	/** Timestamp. */
95 	RTE_TABLE_ACTION_TIME,
96 
97 	/** Crypto. */
98 	RTE_TABLE_ACTION_SYM_CRYPTO,
99 
100 	/** Tag. */
101 	RTE_TABLE_ACTION_TAG,
102 
103 	/** Packet decapsulations. */
104 	RTE_TABLE_ACTION_DECAP,
105 };
106 
107 /** Common action configuration (per table action profile). */
108 struct rte_table_action_common_config {
109 	/** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero
110 	 * for IPv6.
111 	 */
112 	int ip_version;
113 
114 	/** IP header offset within the input packet buffer. Offset 0 points to
115 	 * the first byte of the MBUF structure.
116 	 */
117 	uint32_t ip_offset;
118 };
119 
120 /**
121  * RTE_TABLE_ACTION_FWD
122  */
123 /** Forward action parameters (per table rule). */
124 struct rte_table_action_fwd_params {
125 	/** Forward action. */
126 	enum rte_pipeline_action action;
127 
128 	/** Pipeline table ID or output port ID. */
129 	uint32_t id;
130 };
131 
132 /**
133  * RTE_TABLE_ACTION_LB
134  */
135 /** Load balance key size min (number of bytes). */
136 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MIN                    8
137 
138 /** Load balance key size max (number of bytes). */
139 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MAX                    64
140 
141 /** Load balance table size. */
142 #define RTE_TABLE_ACTION_LB_TABLE_SIZE                      8
143 
144 /** Load balance action configuration (per table action profile). */
145 struct rte_table_action_lb_config {
146 	/** Key size (number of bytes). */
147 	uint32_t key_size;
148 
149 	/** Key offset within the input packet buffer. Offset 0 points to the
150 	 * first byte of the MBUF structure.
151 	 */
152 	uint32_t key_offset;
153 
154 	/** Key mask (*key_size* bytes are valid). */
155 	uint8_t key_mask[RTE_TABLE_ACTION_LB_KEY_SIZE_MAX];
156 
157 	/** Hash function. */
158 	rte_table_hash_op_hash f_hash;
159 
160 	/** Seed value for *f_hash*. */
161 	uint64_t seed;
162 
163 	/** Output value offset within the input packet buffer. Offset 0 points
164 	 * to the first byte of the MBUF structure.
165 	 */
166 	uint32_t out_offset;
167 };
168 
169 /** Load balance action parameters (per table rule). */
170 struct rte_table_action_lb_params {
171 	/** Table defining the output values and their weights. The weights are
172 	 * set in 1/RTE_TABLE_ACTION_LB_TABLE_SIZE increments. To assign a
173 	 * weight of N/RTE_TABLE_ACTION_LB_TABLE_SIZE to a given output value
174 	 * (0 <= N <= RTE_TABLE_ACTION_LB_TABLE_SIZE), the same output value
175 	 * needs to show up exactly N times in this table.
176 	 */
177 	uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE];
178 };
179 
180 /**
181  * RTE_TABLE_ACTION_MTR
182  */
183 /** Max number of traffic classes (TCs). */
184 #define RTE_TABLE_ACTION_TC_MAX                                  16
185 
186 /** Max number of queues per traffic class. */
187 #define RTE_TABLE_ACTION_TC_QUEUE_MAX                            16
188 
189 /** Differentiated Services Code Point (DSCP) translation table entry. */
190 struct rte_table_action_dscp_table_entry {
191 	/** Traffic class. Used by the meter or the traffic management actions.
192 	 * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic
193 	 * class 0 is the highest priority.
194 	 */
195 	uint32_t tc_id;
196 
197 	/** Traffic class queue. Used by the traffic management action. Has to
198 	 * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*.
199 	 */
200 	uint32_t tc_queue_id;
201 
202 	/** Packet color. Used by the meter action as the packet input color
203 	 * for the color aware mode of the traffic metering algorithm.
204 	 */
205 	enum rte_color color;
206 };
207 
208 /** DSCP translation table. */
209 struct rte_table_action_dscp_table {
210 	/** Array of DSCP table entries */
211 	struct rte_table_action_dscp_table_entry entry[64];
212 };
213 
214 /** Supported traffic metering algorithms. */
215 enum rte_table_action_meter_algorithm {
216 	/** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
217 	RTE_TABLE_ACTION_METER_SRTCM,
218 
219 	/** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
220 	RTE_TABLE_ACTION_METER_TRTCM,
221 };
222 
223 /** Traffic metering profile (configuration template). */
224 struct rte_table_action_meter_profile {
225 	/** Traffic metering algorithm. */
226 	enum rte_table_action_meter_algorithm alg;
227 
228 	union {
229 		/** Only valid when *alg* is set to srTCM - IETF RFC 2697. */
230 		struct rte_meter_srtcm_params srtcm;
231 
232 		/** Only valid when *alg* is set to trTCM - IETF RFC 2698. */
233 		struct rte_meter_trtcm_params trtcm;
234 	};
235 };
236 
237 /** Policer actions. */
238 enum rte_table_action_policer {
239 	/** Recolor the packet as green. */
240 	RTE_TABLE_ACTION_POLICER_COLOR_GREEN = 0,
241 
242 	/** Recolor the packet as yellow. */
243 	RTE_TABLE_ACTION_POLICER_COLOR_YELLOW,
244 
245 	/** Recolor the packet as red. */
246 	RTE_TABLE_ACTION_POLICER_COLOR_RED,
247 
248 	/** Drop the packet. */
249 	RTE_TABLE_ACTION_POLICER_DROP,
250 
251 	/** Number of policer actions. */
252 	RTE_TABLE_ACTION_POLICER_MAX
253 };
254 
255 /** Meter action configuration per traffic class. */
256 struct rte_table_action_mtr_tc_params {
257 	/** Meter profile ID. */
258 	uint32_t meter_profile_id;
259 
260 	/** Policer actions. */
261 	enum rte_table_action_policer policer[RTE_COLORS];
262 };
263 
264 /** Meter action statistics counters per traffic class. */
265 struct rte_table_action_mtr_counters_tc {
266 	/** Number of packets per color at the output of the traffic metering
267 	 * and before the policer actions are executed. Only valid when
268 	 * *n_packets_valid* is non-zero.
269 	 */
270 	uint64_t n_packets[RTE_COLORS];
271 
272 	/** Number of packet bytes per color at the output of the traffic
273 	 * metering and before the policer actions are executed. Only valid when
274 	 * *n_bytes_valid* is non-zero.
275 	 */
276 	uint64_t n_bytes[RTE_COLORS];
277 
278 	/** When non-zero, the *n_packets* field is valid. */
279 	int n_packets_valid;
280 
281 	/** When non-zero, the *n_bytes* field is valid. */
282 	int n_bytes_valid;
283 };
284 
285 /** Meter action configuration (per table action profile). */
286 struct rte_table_action_mtr_config {
287 	/** Meter algorithm. */
288 	enum rte_table_action_meter_algorithm alg;
289 
290 	/** Number of traffic classes. Each traffic class has its own traffic
291 	 * meter and policer instances. Needs to be equal to either 1 or to
292 	 * *RTE_TABLE_ACTION_TC_MAX*.
293 	 */
294 	uint32_t n_tc;
295 
296 	/** When non-zero, the *n_packets* meter stats counter is enabled,
297 	 * otherwise it is disabled.
298 	 *
299 	 * @see struct rte_table_action_mtr_counters_tc
300 	 */
301 	int n_packets_enabled;
302 
303 	/** When non-zero, the *n_bytes* meter stats counter is enabled,
304 	 * otherwise it is disabled.
305 	 *
306 	 * @see struct rte_table_action_mtr_counters_tc
307 	 */
308 	int n_bytes_enabled;
309 };
310 
311 /** Meter action parameters (per table rule). */
312 struct rte_table_action_mtr_params {
313 	/** Traffic meter and policer parameters for each of the *tc_mask*
314 	 * traffic classes.
315 	 */
316 	struct rte_table_action_mtr_tc_params mtr[RTE_TABLE_ACTION_TC_MAX];
317 
318 	/** Bit mask defining which traffic class parameters are valid in *mtr*.
319 	 * If bit N is set in *tc_mask*, then parameters for traffic class N are
320 	 * valid in *mtr*.
321 	 */
322 	uint32_t tc_mask;
323 };
324 
325 /** Meter action statistics counters (per table rule). */
326 struct rte_table_action_mtr_counters {
327 	/** Stats counters for each of the *tc_mask* traffic classes. */
328 	struct rte_table_action_mtr_counters_tc stats[RTE_TABLE_ACTION_TC_MAX];
329 
330 	/** Bit mask defining which traffic class parameters are valid in *mtr*.
331 	 * If bit N is set in *tc_mask*, then parameters for traffic class N are
332 	 * valid in *mtr*.
333 	 */
334 	uint32_t tc_mask;
335 };
336 
337 /**
338  * RTE_TABLE_ACTION_TM
339  */
340 /** Traffic management action configuration (per table action profile). */
341 struct rte_table_action_tm_config {
342 	/** Number of subports per port. */
343 	uint32_t n_subports_per_port;
344 
345 	/** Number of pipes per subport. */
346 	uint32_t n_pipes_per_subport;
347 };
348 
349 /** Traffic management action parameters (per table rule). */
350 struct rte_table_action_tm_params {
351 	/** Subport ID. */
352 	uint32_t subport_id;
353 
354 	/** Pipe ID. */
355 	uint32_t pipe_id;
356 };
357 
358 /**
359  * RTE_TABLE_ACTION_ENCAP
360  */
361 /** Supported packet encapsulation types. */
362 enum rte_table_action_encap_type {
363 	/** IP -> { Ether | IP } */
364 	RTE_TABLE_ACTION_ENCAP_ETHER = 0,
365 
366 	/** IP -> { Ether | VLAN | IP } */
367 	RTE_TABLE_ACTION_ENCAP_VLAN,
368 
369 	/** IP -> { Ether | S-VLAN | C-VLAN | IP } */
370 	RTE_TABLE_ACTION_ENCAP_QINQ,
371 
372 	/** IP -> { Ether | MPLS | IP } */
373 	RTE_TABLE_ACTION_ENCAP_MPLS,
374 
375 	/** IP -> { Ether | PPPoE | PPP | IP } */
376 	RTE_TABLE_ACTION_ENCAP_PPPOE,
377 
378 	/** Ether -> { Ether | IP | UDP | VXLAN | Ether }
379 	 * Ether -> { Ether | VLAN | IP | UDP | VXLAN | Ether }
380 	 */
381 	RTE_TABLE_ACTION_ENCAP_VXLAN,
382 
383 	/** IP -> { Ether | S-VLAN | C-VLAN | PPPoE | PPP | IP } */
384 	RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE,
385 };
386 
387 /** Pre-computed Ethernet header fields for encapsulation action. */
388 struct rte_table_action_ether_hdr {
389 	struct rte_ether_addr da; /**< Destination address. */
390 	struct rte_ether_addr sa; /**< Source address. */
391 };
392 
393 /** Pre-computed VLAN header fields for encapsulation action. */
394 struct rte_table_action_vlan_hdr {
395 	uint8_t pcp; /**< Priority Code Point (PCP). */
396 	uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
397 	uint16_t vid; /**< VLAN Identifier (VID). */
398 };
399 
400 /** Pre-computed MPLS header fields for encapsulation action. */
401 struct rte_table_action_mpls_hdr {
402 	uint32_t label; /**< Label. */
403 	uint8_t tc; /**< Traffic Class (TC). */
404 	uint8_t ttl; /**< Time to Live (TTL). */
405 };
406 
407 /** Pre-computed PPPoE header fields for encapsulation action. */
408 struct rte_table_action_pppoe_hdr {
409 	uint16_t session_id; /**< Session ID. */
410 };
411 
412 /** Pre-computed IPv4 header fields for encapsulation action. */
413 struct rte_table_action_ipv4_header {
414 	uint32_t sa; /**< Source address. */
415 	uint32_t da; /**< Destination address. */
416 	uint8_t dscp; /**< DiffServ Code Point (DSCP). */
417 	uint8_t ttl; /**< Time To Live (TTL). */
418 };
419 
420 /** Pre-computed IPv6 header fields for encapsulation action. */
421 struct rte_table_action_ipv6_header {
422 	uint8_t sa[16]; /**< Source address. */
423 	uint8_t da[16]; /**< Destination address. */
424 	uint32_t flow_label; /**< Flow label. */
425 	uint8_t dscp; /**< DiffServ Code Point (DSCP). */
426 	uint8_t hop_limit; /**< Hop Limit (HL). */
427 };
428 
429 /** Pre-computed UDP header fields for encapsulation action. */
430 struct rte_table_action_udp_header {
431 	uint16_t sp; /**< Source port. */
432 	uint16_t dp; /**< Destination port. */
433 };
434 
435 /** Pre-computed VXLAN header fields for encapsulation action. */
436 struct rte_table_action_vxlan_hdr {
437 	uint32_t vni; /**< VXLAN Network Identifier (VNI). */
438 };
439 
440 /** Ether encap parameters. */
441 struct rte_table_action_encap_ether_params {
442 	struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
443 };
444 
445 /** VLAN encap parameters. */
446 struct rte_table_action_encap_vlan_params {
447 	struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
448 	struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
449 };
450 
451 /** QinQ encap parameters. */
452 struct rte_table_action_encap_qinq_params {
453 	struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
454 	struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
455 	struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
456 };
457 
458 /** Max number of MPLS labels per output packet for MPLS encapsulation. */
459 #ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
460 #define RTE_TABLE_ACTION_MPLS_LABELS_MAX                   4
461 #endif
462 
463 /** MPLS encap parameters. */
464 struct rte_table_action_encap_mpls_params {
465 	/** Ethernet header. */
466 	struct rte_table_action_ether_hdr ether;
467 
468 	/** MPLS header. */
469 	struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
470 
471 	/** Number of MPLS labels in MPLS header. */
472 	uint32_t mpls_count;
473 
474 	/** Non-zero for MPLS unicast, zero for MPLS multicast. */
475 	int unicast;
476 };
477 
478 /** PPPoE encap parameters. */
479 struct rte_table_action_encap_pppoe_params {
480 	struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
481 	struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
482 };
483 
484 /** VXLAN encap parameters. */
485 struct rte_table_action_encap_vxlan_params {
486 	struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
487 	struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
488 
489 	union {
490 		struct rte_table_action_ipv4_header ipv4; /**< IPv4 header. */
491 		struct rte_table_action_ipv6_header ipv6; /**< IPv6 header. */
492 	};
493 
494 	struct rte_table_action_udp_header udp; /**< UDP header. */
495 	struct rte_table_action_vxlan_hdr vxlan; /**< VXLAN header. */
496 };
497 
498 /** Encap action configuration (per table action profile). */
499 struct rte_table_action_encap_config {
500 	/** Bit mask defining the set of packet encapsulations enabled for the
501 	 * current table action profile. If bit (1 << N) is set in *encap_mask*,
502 	 * then packet encapsulation N is enabled, otherwise it is disabled.
503 	 *
504 	 * @see enum rte_table_action_encap_type
505 	 */
506 	uint64_t encap_mask;
507 
508 	/** Encapsulation type specific configuration. */
509 	union {
510 		struct {
511 			/** Input packet to be encapsulated: offset within the
512 			 * input packet buffer to the start of the Ethernet
513 			 * frame to be encapsulated. Offset 0 points to the
514 			 * first byte of the MBUF structure.
515 			 */
516 			uint32_t data_offset;
517 
518 			/** Encapsulation header: non-zero when encapsulation
519 			 * header includes a VLAN tag, zero otherwise.
520 			 */
521 			int vlan;
522 
523 			/** Encapsulation header: IP version of the IP header
524 			 * within the encapsulation header. Non-zero for IPv4,
525 			 * zero for IPv6.
526 			 */
527 			int ip_version;
528 		} vxlan; /**< VXLAN specific configuration. */
529 	};
530 };
531 
532 /** QinQ_PPPoE encap parameters. */
533 struct rte_table_encap_ether_qinq_pppoe {
534 
535 	/** Only valid when *type* is set to QinQ. */
536 	struct rte_table_action_ether_hdr ether;
537 	struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
538 	struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
539 	struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
540 };
541 
542 /** Encap action parameters (per table rule). */
543 struct rte_table_action_encap_params {
544 	/** Encapsulation type. */
545 	enum rte_table_action_encap_type type;
546 
547 	union {
548 		/** Only valid when *type* is set to Ether. */
549 		struct rte_table_action_encap_ether_params ether;
550 
551 		/** Only valid when *type* is set to VLAN. */
552 		struct rte_table_action_encap_vlan_params vlan;
553 
554 		/** Only valid when *type* is set to QinQ. */
555 		struct rte_table_action_encap_qinq_params qinq;
556 
557 		/** Only valid when *type* is set to MPLS. */
558 		struct rte_table_action_encap_mpls_params mpls;
559 
560 		/** Only valid when *type* is set to PPPoE. */
561 		struct rte_table_action_encap_pppoe_params pppoe;
562 
563 		/** Only valid when *type* is set to VXLAN. */
564 		struct rte_table_action_encap_vxlan_params vxlan;
565 
566 		/** Only valid when *type* is set to QinQ_PPPoE. */
567 		struct rte_table_encap_ether_qinq_pppoe qinq_pppoe;
568 	};
569 };
570 
571 /**
572  * RTE_TABLE_ACTION_NAT
573  */
574 /** NAT action configuration (per table action profile). */
575 struct rte_table_action_nat_config {
576 	/** When non-zero, the IP source address and L4 protocol source port are
577 	 * translated. When zero, the IP destination address and L4 protocol
578 	 * destination port are translated.
579 	 */
580 	int source_nat;
581 
582 	/** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum
583 	 * field is computed differently and placed at different header offset
584 	 * by each layer 4 protocol.
585 	 */
586 	uint8_t proto;
587 };
588 
589 /** NAT action parameters (per table rule). */
590 struct rte_table_action_nat_params {
591 	/** IP version for *addr*: non-zero for IPv4, zero for IPv6. */
592 	int ip_version;
593 
594 	/** IP address. */
595 	union {
596 		/** IPv4 address; only valid when *ip_version* is non-zero. */
597 		uint32_t ipv4;
598 
599 		/** IPv6 address; only valid when *ip_version* is set to 0. */
600 		uint8_t ipv6[16];
601 	} addr;
602 
603 	/** Port. */
604 	uint16_t port;
605 };
606 
607 /**
608  * RTE_TABLE_ACTION_TTL
609  */
610 /** TTL action configuration (per table action profile). */
611 struct rte_table_action_ttl_config {
612 	/** When non-zero, the input packets whose updated IPv4 Time to Live
613 	 * (TTL) field or IPv6 Hop Limit (HL) field is zero are dropped.
614 	 * When zero, the input packets whose updated IPv4 TTL field or IPv6 HL
615 	 * field is zero are forwarded as usual (typically for debugging
616 	 * purpose).
617 	 */
618 	int drop;
619 
620 	/** When non-zero, the *n_packets* stats counter for TTL action is
621 	 * enabled, otherwise disabled.
622 	 *
623 	 * @see struct rte_table_action_ttl_counters
624 	 */
625 	int n_packets_enabled;
626 };
627 
628 /** TTL action parameters (per table rule). */
629 struct rte_table_action_ttl_params {
630 	/** When non-zero, decrement the IPv4 TTL field and update the checksum
631 	 * field, or decrement the IPv6 HL field. When zero, the IPv4 TTL field
632 	 * or the IPv6 HL field is not changed.
633 	 */
634 	int decrement;
635 };
636 
637 /** TTL action statistics packets (per table rule). */
638 struct rte_table_action_ttl_counters {
639 	/** Number of IPv4 packets whose updated TTL field is zero or IPv6
640 	 * packets whose updated HL field is zero.
641 	 */
642 	uint64_t n_packets;
643 };
644 
645 /**
646  * RTE_TABLE_ACTION_STATS
647  */
648 /** Stats action configuration (per table action profile). */
649 struct rte_table_action_stats_config {
650 	/** When non-zero, the *n_packets* stats counter is enabled, otherwise
651 	 * disabled.
652 	 *
653 	 * @see struct rte_table_action_stats_counters
654 	 */
655 	int n_packets_enabled;
656 
657 	/** When non-zero, the *n_bytes* stats counter is enabled, otherwise
658 	 * disabled.
659 	 *
660 	 * @see struct rte_table_action_stats_counters
661 	 */
662 	int n_bytes_enabled;
663 };
664 
665 /** Stats action parameters (per table rule). */
666 struct rte_table_action_stats_params {
667 	/** Initial value for the *n_packets* stats counter. Typically set to 0.
668 	 *
669 	 * @see struct rte_table_action_stats_counters
670 	 */
671 	uint64_t n_packets;
672 
673 	/** Initial value for the *n_bytes* stats counter. Typically set to 0.
674 	 *
675 	 * @see struct rte_table_action_stats_counters
676 	 */
677 	uint64_t n_bytes;
678 };
679 
680 /** Stats action counters (per table rule). */
681 struct rte_table_action_stats_counters {
682 	/** Number of packets. Valid only when *n_packets_valid* is non-zero. */
683 	uint64_t n_packets;
684 
685 	/** Number of bytes. Valid only when *n_bytes_valid* is non-zero. */
686 	uint64_t n_bytes;
687 
688 	/** When non-zero, the *n_packets* field is valid, otherwise invalid. */
689 	int n_packets_valid;
690 
691 	/** When non-zero, the *n_bytes* field is valid, otherwise invalid. */
692 	int n_bytes_valid;
693 };
694 
695 /**
696  * RTE_TABLE_ACTION_TIME
697  */
698 /** Timestamp action parameters (per table rule). */
699 struct rte_table_action_time_params {
700 	/** Initial timestamp value. Typically set to current time. */
701 	uint64_t time;
702 };
703 
704 /**
705  * RTE_TABLE_ACTION_CRYPTO
706  */
707 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX
708 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX		(16)
709 #endif
710 
711 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX
712 #define RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX	(16)
713 #endif
714 
715 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET
716 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET				\
717 	(sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
718 #endif
719 
720 /** Common action structure to store the data's value, length, and offset */
721 struct rte_table_action_vlo {
722 	uint8_t *val;
723 	uint32_t length;
724 	uint32_t offset;
725 };
726 
727 /** Symmetric crypto action configuration (per table action profile). */
728 struct rte_table_action_sym_crypto_config {
729 	/** Target Cryptodev ID. */
730 	uint8_t cryptodev_id;
731 
732 	/**
733 	 * Offset to rte_crypto_op structure within the input packet buffer.
734 	 * Offset 0 points to the first byte of the MBUF structure.
735 	 */
736 	uint32_t op_offset;
737 
738 	/** The mempool for creating cryptodev sessions. */
739 	struct rte_mempool *mp_create;
740 
741 	/** The mempool for initializing cryptodev sessions. */
742 	struct rte_mempool *mp_init;
743 };
744 
745 /** Symmetric Crypto action parameters (per table rule). */
746 struct rte_table_action_sym_crypto_params {
747 
748 	/** Xform pointer contains all relevant information */
749 	struct rte_crypto_sym_xform *xform;
750 
751 	/**
752 	 * Offset within the input packet buffer to the first byte of data
753 	 * to be processed by the crypto unit. Offset 0 points to the first
754 	 * byte of the MBUF structure.
755 	 */
756 	uint32_t data_offset;
757 
758 	union {
759 		struct {
760 			/** Cipher iv data. */
761 			struct rte_table_action_vlo cipher_iv;
762 
763 			/** Cipher iv data. */
764 			struct rte_table_action_vlo cipher_iv_update;
765 
766 			/** Auth iv data. */
767 			struct rte_table_action_vlo auth_iv;
768 
769 			/** Auth iv data. */
770 			struct rte_table_action_vlo auth_iv_update;
771 
772 		} cipher_auth;
773 
774 		struct {
775 			/** AEAD AAD data. */
776 			struct rte_table_action_vlo aad;
777 
778 			/** AEAD iv data. */
779 			struct rte_table_action_vlo iv;
780 
781 			/** AEAD AAD data. */
782 			struct rte_table_action_vlo aad_update;
783 
784 			/** AEAD iv data. */
785 			struct rte_table_action_vlo iv_update;
786 
787 		} aead;
788 	};
789 };
790 
791 /**
792  * RTE_TABLE_ACTION_TAG
793  */
794 /** Tag action parameters (per table rule). */
795 struct rte_table_action_tag_params {
796 	/** Tag to be attached to the input packet. */
797 	uint32_t tag;
798 };
799 
800 /**
801  * RTE_TABLE_ACTION_DECAP
802  */
803 /** Decap action parameters (per table rule). */
804 struct rte_table_action_decap_params {
805 	/** Number of bytes to be removed from the start of the packet. */
806 	uint16_t n;
807 };
808 
809 /**
810  * Table action profile.
811  */
812 struct rte_table_action_profile;
813 
814 /**
815  * Table action profile create.
816  *
817  * @param[in] common
818  *   Common action configuration.
819  * @return
820  *   Table action profile handle on success, NULL otherwise.
821  */
822 __rte_experimental
823 struct rte_table_action_profile *
824 rte_table_action_profile_create(struct rte_table_action_common_config *common);
825 
826 /**
827  * Table action profile free.
828  *
829  * @param[in] profile
830  *   Table profile action handle (needs to be valid).
831  * @return
832  *   Zero on success, non-zero error code otherwise.
833  */
834 __rte_experimental
835 int
836 rte_table_action_profile_free(struct rte_table_action_profile *profile);
837 
838 /**
839  * Table action profile action register.
840  *
841  * @param[in] profile
842  *   Table profile action handle (needs to be valid and not in frozen state).
843  * @param[in] type
844  *   Specific table action to be registered for *profile*.
845  * @param[in] action_config
846  *   Configuration for the *type* action.
847  *   If struct rte_table_action_*type*_config is defined by the Table Action
848  *   API, it needs to point to a valid instance of this structure, otherwise it
849  *   needs to be set to NULL.
850  * @return
851  *   Zero on success, non-zero error code otherwise.
852  */
853 __rte_experimental
854 int
855 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
856 	enum rte_table_action_type type,
857 	void *action_config);
858 
859 /**
860  * Table action profile freeze.
861  *
862  * Once this function is called successfully, the given profile enters the
863  * frozen state with the following immediate effects: no more actions can be
864  * registered for this profile, so the profile can be instantiated to create
865  * table action objects.
866  *
867  * @param[in] profile
868  *   Table profile action handle (needs to be valid and not in frozen state).
869  * @return
870  *   Zero on success, non-zero error code otherwise.
871  *
872  * @see rte_table_action_create()
873  */
874 __rte_experimental
875 int
876 rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
877 
878 /**
879  * Table action.
880  */
881 struct rte_table_action;
882 
883 /**
884  * Table action create.
885  *
886  * Instantiates the given table action profile to create a table action object.
887  *
888  * @param[in] profile
889  *   Table profile action handle (needs to be valid and in frozen state).
890  * @param[in] socket_id
891  *   CPU socket ID where the internal data structures required by the new table
892  *   action object should be allocated.
893  * @return
894  *   Handle to table action object on success, NULL on error.
895  *
896  * @see rte_table_action_create()
897  */
898 __rte_experimental
899 struct rte_table_action *
900 rte_table_action_create(struct rte_table_action_profile *profile,
901 	uint32_t socket_id);
902 
903 /**
904  * Table action free.
905  *
906  * @param[in] action
907  *   Handle to table action object (needs to be valid).
908  * @return
909  *   Zero on success, non-zero error code otherwise.
910  */
911 __rte_experimental
912 int
913 rte_table_action_free(struct rte_table_action *action);
914 
915 /**
916  * Table action table params get.
917  *
918  * @param[in] action
919  *   Handle to table action object (needs to be valid).
920  * @param[inout] params
921  *   Pipeline table parameters (needs to be pre-allocated).
922  * @return
923  *   Zero on success, non-zero error code otherwise.
924  */
925 __rte_experimental
926 int
927 rte_table_action_table_params_get(struct rte_table_action *action,
928 	struct rte_pipeline_table_params *params);
929 
930 /**
931  * Table action apply.
932  *
933  * @param[in] action
934  *   Handle to table action object (needs to be valid).
935  * @param[in] data
936  *   Data byte array (typically table rule data) to apply action *type* on.
937  * @param[in] type
938  *   Specific table action previously registered for the table action profile of
939  *   the *action* object.
940  * @param[in] action_params
941  *   Parameters for the *type* action.
942  *   If struct rte_table_action_*type*_params is defined by the Table Action
943  *   API, it needs to point to a valid instance of this structure, otherwise it
944  *   needs to be set to NULL.
945  * @return
946  *   Zero on success, non-zero error code otherwise.
947  */
948 __rte_experimental
949 int
950 rte_table_action_apply(struct rte_table_action *action,
951 	void *data,
952 	enum rte_table_action_type type,
953 	void *action_params);
954 
955 /**
956  * Table action DSCP table update.
957  *
958  * @param[in] action
959  *   Handle to table action object (needs to be valid).
960  * @param[in] dscp_mask
961  *   64-bit mask defining the DSCP table entries to be updated. If bit N is set
962  *   in this bit mask, then DSCP table entry N is to be updated, otherwise not.
963  * @param[in] table
964  *   DSCP table.
965  * @return
966  *   Zero on success, non-zero error code otherwise.
967  */
968 __rte_experimental
969 int
970 rte_table_action_dscp_table_update(struct rte_table_action *action,
971 	uint64_t dscp_mask,
972 	struct rte_table_action_dscp_table *table);
973 
974 /**
975  * Table action meter profile add.
976  *
977  * @param[in] action
978  *   Handle to table action object (needs to be valid).
979  * @param[in] meter_profile_id
980  *   Meter profile ID to be used for the *profile* once it is successfully added
981  *   to the *action* object (needs to be unused by the set of meter profiles
982  *   currently registered for the *action* object).
983  * @param[in] profile
984  *   Meter profile to be added.
985  * @return
986  *   Zero on success, non-zero error code otherwise.
987  */
988 __rte_experimental
989 int
990 rte_table_action_meter_profile_add(struct rte_table_action *action,
991 	uint32_t meter_profile_id,
992 	struct rte_table_action_meter_profile *profile);
993 
994 /**
995  * Table action meter profile delete.
996  *
997  * @param[in] action
998  *   Handle to table action object (needs to be valid).
999  * @param[in] meter_profile_id
1000  *   Meter profile ID of the meter profile to be deleted from the *action*
1001  *   object (needs to be valid for the *action* object).
1002  * @return
1003  *   Zero on success, non-zero error code otherwise.
1004  */
1005 __rte_experimental
1006 int
1007 rte_table_action_meter_profile_delete(struct rte_table_action *action,
1008 	uint32_t meter_profile_id);
1009 
1010 /**
1011  * Table action meter read.
1012  *
1013  * @param[in] action
1014  *   Handle to table action object (needs to be valid).
1015  * @param[in] data
1016  *   Data byte array (typically table rule data) with meter action previously
1017  *   applied on it.
1018  * @param[in] tc_mask
1019  *   Bit mask defining which traffic classes should have the meter stats
1020  *   counters read from *data* and stored into *stats*. If bit N is set in this
1021  *   bit mask, then traffic class N is part of this operation, otherwise it is
1022  *   not. If bit N is set in this bit mask, then traffic class N must be one of
1023  *   the traffic classes that are enabled for the meter action in the table
1024  *   action profile used by the *action* object.
1025  * @param[inout] stats
1026  *   When non-NULL, it points to the area where the meter stats counters read
1027  *   from *data* are saved. Only the meter stats counters for the *tc_mask*
1028  *   traffic classes are read and stored to *stats*.
1029  * @param[in] clear
1030  *   When non-zero, the meter stats counters are cleared (i.e. set to zero),
1031  *   otherwise the counters are not modified. When the read operation is enabled
1032  *   (*stats* is non-NULL), the clear operation is performed after the read
1033  *   operation is completed.
1034  * @return
1035  *   Zero on success, non-zero error code otherwise.
1036  */
1037 __rte_experimental
1038 int
1039 rte_table_action_meter_read(struct rte_table_action *action,
1040 	void *data,
1041 	uint32_t tc_mask,
1042 	struct rte_table_action_mtr_counters *stats,
1043 	int clear);
1044 
1045 /**
1046  * Table action TTL read.
1047  *
1048  * @param[in] action
1049  *   Handle to table action object (needs to be valid).
1050  * @param[in] data
1051  *   Data byte array (typically table rule data) with TTL action previously
1052  *   applied on it.
1053  * @param[inout] stats
1054  *   When non-NULL, it points to the area where the TTL stats counters read from
1055  *   *data* are saved.
1056  * @param[in] clear
1057  *   When non-zero, the TTL stats counters are cleared (i.e. set to zero),
1058  *   otherwise the counters are not modified. When the read operation is enabled
1059  *   (*stats* is non-NULL), the clear operation is performed after the read
1060  *   operation is completed.
1061  * @return
1062  *   Zero on success, non-zero error code otherwise.
1063  */
1064 __rte_experimental
1065 int
1066 rte_table_action_ttl_read(struct rte_table_action *action,
1067 	void *data,
1068 	struct rte_table_action_ttl_counters *stats,
1069 	int clear);
1070 
1071 /**
1072  * Table action stats read.
1073  *
1074  * @param[in] action
1075  *   Handle to table action object (needs to be valid).
1076  * @param[in] data
1077  *   Data byte array (typically table rule data) with stats action previously
1078  *   applied on it.
1079  * @param[inout] stats
1080  *   When non-NULL, it points to the area where the stats counters read from
1081  *   *data* are saved.
1082  * @param[in] clear
1083  *   When non-zero, the stats counters are cleared (i.e. set to zero), otherwise
1084  *   the counters are not modified. When the read operation is enabled (*stats*
1085  *   is non-NULL), the clear operation is performed after the read operation is
1086  *   completed.
1087  * @return
1088  *   Zero on success, non-zero error code otherwise.
1089  */
1090 __rte_experimental
1091 int
1092 rte_table_action_stats_read(struct rte_table_action *action,
1093 	void *data,
1094 	struct rte_table_action_stats_counters *stats,
1095 	int clear);
1096 
1097 /**
1098  * Table action timestamp read.
1099  *
1100  * @param[in] action
1101  *   Handle to table action object (needs to be valid).
1102  * @param[in] data
1103  *   Data byte array (typically table rule data) with timestamp action
1104  *   previously applied on it.
1105  * @param[inout] timestamp
1106  *   Pre-allocated memory where the timestamp read from *data* is saved (has to
1107  *   be non-NULL).
1108  * @return
1109  *   Zero on success, non-zero error code otherwise.
1110  */
1111 __rte_experimental
1112 int
1113 rte_table_action_time_read(struct rte_table_action *action,
1114 	void *data,
1115 	uint64_t *timestamp);
1116 
1117 /**
1118  * Table action cryptodev symmetric session get.
1119  *
1120  * @param[in] action
1121  *   Handle to table action object (needs to be valid).
1122  * @param[in] data
1123  *   Data byte array (typically table rule data) with sym crypto action.
1124  * @return
1125  *   The pointer to the session on success, NULL otherwise.
1126  */
1127 __rte_experimental
1128 struct rte_cryptodev_sym_session *
1129 rte_table_action_crypto_sym_session_get(struct rte_table_action *action,
1130 	void *data);
1131 
1132 #ifdef __cplusplus
1133 }
1134 #endif
1135 
1136 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */
1137