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