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 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 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 __rte_experimental 827 struct rte_table_action_profile * 828 rte_table_action_profile_create(struct rte_table_action_common_config *common); 829 830 /** 831 * Table action profile free. 832 * 833 * @param[in] profile 834 * Table profile action handle (needs to be valid). 835 * @return 836 * Zero on success, non-zero error code otherwise. 837 */ 838 __rte_experimental 839 int 840 rte_table_action_profile_free(struct rte_table_action_profile *profile); 841 842 /** 843 * Table action profile action register. 844 * 845 * @param[in] profile 846 * Table profile action handle (needs to be valid and not in frozen state). 847 * @param[in] type 848 * Specific table action to be registered for *profile*. 849 * @param[in] action_config 850 * Configuration for the *type* action. 851 * If struct rte_table_action_*type*_config is defined by the Table Action 852 * API, it needs to point to a valid instance of this structure, otherwise it 853 * needs to be set to NULL. 854 * @return 855 * Zero on success, non-zero error code otherwise. 856 */ 857 __rte_experimental 858 int 859 rte_table_action_profile_action_register(struct rte_table_action_profile *profile, 860 enum rte_table_action_type type, 861 void *action_config); 862 863 /** 864 * Table action profile freeze. 865 * 866 * Once this function is called successfully, the given profile enters the 867 * frozen state with the following immediate effects: no more actions can be 868 * registered for this profile, so the profile can be instantiated to create 869 * table action objects. 870 * 871 * @param[in] profile 872 * Table profile action handle (needs to be valid and not in frozen state). 873 * @return 874 * Zero on success, non-zero error code otherwise. 875 * 876 * @see rte_table_action_create() 877 */ 878 __rte_experimental 879 int 880 rte_table_action_profile_freeze(struct rte_table_action_profile *profile); 881 882 /** 883 * Table action. 884 */ 885 struct rte_table_action; 886 887 /** 888 * Table action create. 889 * 890 * Instantiates the given table action profile to create a table action object. 891 * 892 * @param[in] profile 893 * Table profile action handle (needs to be valid and in frozen state). 894 * @param[in] socket_id 895 * CPU socket ID where the internal data structures required by the new table 896 * action object should be allocated. 897 * @return 898 * Handle to table action object on success, NULL on error. 899 * 900 * @see rte_table_action_create() 901 */ 902 __rte_experimental 903 struct rte_table_action * 904 rte_table_action_create(struct rte_table_action_profile *profile, 905 uint32_t socket_id); 906 907 /** 908 * Table action free. 909 * 910 * @param[in] action 911 * Handle to table action object (needs to be valid). 912 * @return 913 * Zero on success, non-zero error code otherwise. 914 */ 915 __rte_experimental 916 int 917 rte_table_action_free(struct rte_table_action *action); 918 919 /** 920 * Table action table params get. 921 * 922 * @param[in] action 923 * Handle to table action object (needs to be valid). 924 * @param[inout] params 925 * Pipeline table parameters (needs to be pre-allocated). 926 * @return 927 * Zero on success, non-zero error code otherwise. 928 */ 929 __rte_experimental 930 int 931 rte_table_action_table_params_get(struct rte_table_action *action, 932 struct rte_pipeline_table_params *params); 933 934 /** 935 * Table action apply. 936 * 937 * @param[in] action 938 * Handle to table action object (needs to be valid). 939 * @param[in] data 940 * Data byte array (typically table rule data) to apply action *type* on. 941 * @param[in] type 942 * Specific table action previously registered for the table action profile of 943 * the *action* object. 944 * @param[in] action_params 945 * Parameters for the *type* action. 946 * If struct rte_table_action_*type*_params is defined by the Table Action 947 * API, it needs to point to a valid instance of this structure, otherwise it 948 * needs to be set to NULL. 949 * @return 950 * Zero on success, non-zero error code otherwise. 951 */ 952 __rte_experimental 953 int 954 rte_table_action_apply(struct rte_table_action *action, 955 void *data, 956 enum rte_table_action_type type, 957 void *action_params); 958 959 /** 960 * Table action DSCP table update. 961 * 962 * @param[in] action 963 * Handle to table action object (needs to be valid). 964 * @param[in] dscp_mask 965 * 64-bit mask defining the DSCP table entries to be updated. If bit N is set 966 * in this bit mask, then DSCP table entry N is to be updated, otherwise not. 967 * @param[in] table 968 * DSCP table. 969 * @return 970 * Zero on success, non-zero error code otherwise. 971 */ 972 __rte_experimental 973 int 974 rte_table_action_dscp_table_update(struct rte_table_action *action, 975 uint64_t dscp_mask, 976 struct rte_table_action_dscp_table *table); 977 978 /** 979 * Table action meter profile add. 980 * 981 * @param[in] action 982 * Handle to table action object (needs to be valid). 983 * @param[in] meter_profile_id 984 * Meter profile ID to be used for the *profile* once it is successfully added 985 * to the *action* object (needs to be unused by the set of meter profiles 986 * currently registered for the *action* object). 987 * @param[in] profile 988 * Meter profile to be added. 989 * @return 990 * Zero on success, non-zero error code otherwise. 991 */ 992 __rte_experimental 993 int 994 rte_table_action_meter_profile_add(struct rte_table_action *action, 995 uint32_t meter_profile_id, 996 struct rte_table_action_meter_profile *profile); 997 998 /** 999 * Table action meter profile delete. 1000 * 1001 * @param[in] action 1002 * Handle to table action object (needs to be valid). 1003 * @param[in] meter_profile_id 1004 * Meter profile ID of the meter profile to be deleted from the *action* 1005 * object (needs to be valid for the *action* object). 1006 * @return 1007 * Zero on success, non-zero error code otherwise. 1008 */ 1009 __rte_experimental 1010 int 1011 rte_table_action_meter_profile_delete(struct rte_table_action *action, 1012 uint32_t meter_profile_id); 1013 1014 /** 1015 * Table action meter read. 1016 * 1017 * @param[in] action 1018 * Handle to table action object (needs to be valid). 1019 * @param[in] data 1020 * Data byte array (typically table rule data) with meter action previously 1021 * applied on it. 1022 * @param[in] tc_mask 1023 * Bit mask defining which traffic classes should have the meter stats 1024 * counters read from *data* and stored into *stats*. If bit N is set in this 1025 * bit mask, then traffic class N is part of this operation, otherwise it is 1026 * not. If bit N is set in this bit mask, then traffic class N must be one of 1027 * the traffic classes that are enabled for the meter action in the table 1028 * action profile used by the *action* object. 1029 * @param[inout] stats 1030 * When non-NULL, it points to the area where the meter stats counters read 1031 * from *data* are saved. Only the meter stats counters for the *tc_mask* 1032 * traffic classes are read and stored to *stats*. 1033 * @param[in] clear 1034 * When non-zero, the meter stats counters are cleared (i.e. set to zero), 1035 * otherwise the counters are not modified. When the read operation is enabled 1036 * (*stats* is non-NULL), the clear operation is performed after the read 1037 * operation is completed. 1038 * @return 1039 * Zero on success, non-zero error code otherwise. 1040 */ 1041 __rte_experimental 1042 int 1043 rte_table_action_meter_read(struct rte_table_action *action, 1044 void *data, 1045 uint32_t tc_mask, 1046 struct rte_table_action_mtr_counters *stats, 1047 int clear); 1048 1049 /** 1050 * Table action TTL read. 1051 * 1052 * @param[in] action 1053 * Handle to table action object (needs to be valid). 1054 * @param[in] data 1055 * Data byte array (typically table rule data) with TTL action previously 1056 * applied on it. 1057 * @param[inout] stats 1058 * When non-NULL, it points to the area where the TTL stats counters read from 1059 * *data* are saved. 1060 * @param[in] clear 1061 * When non-zero, the TTL stats counters are cleared (i.e. set to zero), 1062 * otherwise the counters are not modified. When the read operation is enabled 1063 * (*stats* is non-NULL), the clear operation is performed after the read 1064 * operation is completed. 1065 * @return 1066 * Zero on success, non-zero error code otherwise. 1067 */ 1068 __rte_experimental 1069 int 1070 rte_table_action_ttl_read(struct rte_table_action *action, 1071 void *data, 1072 struct rte_table_action_ttl_counters *stats, 1073 int clear); 1074 1075 /** 1076 * Table action stats read. 1077 * 1078 * @param[in] action 1079 * Handle to table action object (needs to be valid). 1080 * @param[in] data 1081 * Data byte array (typically table rule data) with stats action previously 1082 * applied on it. 1083 * @param[inout] stats 1084 * When non-NULL, it points to the area where the stats counters read from 1085 * *data* are saved. 1086 * @param[in] clear 1087 * When non-zero, the stats counters are cleared (i.e. set to zero), otherwise 1088 * the counters are not modified. When the read operation is enabled (*stats* 1089 * is non-NULL), the clear operation is performed after the read operation is 1090 * completed. 1091 * @return 1092 * Zero on success, non-zero error code otherwise. 1093 */ 1094 __rte_experimental 1095 int 1096 rte_table_action_stats_read(struct rte_table_action *action, 1097 void *data, 1098 struct rte_table_action_stats_counters *stats, 1099 int clear); 1100 1101 /** 1102 * Table action timestamp read. 1103 * 1104 * @param[in] action 1105 * Handle to table action object (needs to be valid). 1106 * @param[in] data 1107 * Data byte array (typically table rule data) with timestamp action 1108 * previously applied on it. 1109 * @param[inout] timestamp 1110 * Pre-allocated memory where the timestamp read from *data* is saved (has to 1111 * be non-NULL). 1112 * @return 1113 * Zero on success, non-zero error code otherwise. 1114 */ 1115 __rte_experimental 1116 int 1117 rte_table_action_time_read(struct rte_table_action *action, 1118 void *data, 1119 uint64_t *timestamp); 1120 1121 /** 1122 * Table action cryptodev symmetric session get. 1123 * 1124 * @param[in] action 1125 * Handle to table action object (needs to be valid). 1126 * @param[in] data 1127 * Data byte array (typically table rule data) with sym crypto action. 1128 * @return 1129 * The pointer to the session on success, NULL otherwise. 1130 */ 1131 __rte_experimental 1132 struct rte_cryptodev_sym_session * 1133 rte_table_action_crypto_sym_session_get(struct rte_table_action *action, 1134 void *data); 1135 1136 #ifdef __cplusplus 1137 } 1138 #endif 1139 1140 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */ 1141