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