1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 #ifndef __INCLUDE_RTE_TABLE_ACTION_H__ 6 #define __INCLUDE_RTE_TABLE_ACTION_H__ 7 8 /** 9 * @file 10 * RTE Pipeline Table Actions 11 * 12 * This API provides a common set of actions for pipeline tables to speed up 13 * application development. 14 * 15 * Each match-action rule added to a pipeline table has associated data that 16 * stores the action context. This data is input to the table action handler 17 * called for every input packet that hits the rule as part of the table lookup 18 * during the pipeline execution. The pipeline library allows the user to define 19 * his own table actions by providing customized table action handlers (table 20 * lookup) and complete freedom of setting the rules and their data (table rule 21 * add/delete). While the user can still follow this process, this API is 22 * intended to provide a quicker development alternative for a set of predefined 23 * actions. 24 * 25 * The typical steps to use this API are: 26 * - Define a table action profile. This is a configuration template that can 27 * potentially be shared by multiple tables from the same or different 28 * pipelines, with different tables from the same pipeline likely to use 29 * different action profiles. For every table using a given action profile, 30 * the profile defines the set of actions and the action configuration to be 31 * implemented for all the table rules. API functions: 32 * rte_table_action_profile_create(), 33 * rte_table_action_profile_action_register(), 34 * rte_table_action_profile_freeze(). 35 * 36 * - Instantiate the table action profile to create table action objects. Each 37 * pipeline table has its own table action object. API functions: 38 * rte_table_action_create(). 39 * 40 * - Use the table action object to generate the pipeline table action handlers 41 * (invoked by the pipeline table lookup operation). API functions: 42 * rte_table_action_table_params_get(). 43 * 44 * - Use the table action object to generate the rule data (for the pipeline 45 * table rule add operation) based on given action parameters. API functions: 46 * rte_table_action_apply(). 47 * 48 * - Use the table action object to read action data (e.g. stats counters) for 49 * any given rule. API functions: rte_table_action_XYZ_read(). 50 * 51 * @warning 52 * @b EXPERIMENTAL: this API may change without prior notice 53 */ 54 55 #include <stdint.h> 56 57 #include <rte_compat.h> 58 #include <rte_ether.h> 59 #include <rte_ip6.h> 60 #include <rte_meter.h> 61 #include <rte_table_hash.h> 62 63 #include "rte_pipeline.h" 64 65 #ifdef __cplusplus 66 extern "C" { 67 #endif 68 69 /** Table actions. */ 70 enum rte_table_action_type { 71 /** Forward to next pipeline table, output port or drop. */ 72 RTE_TABLE_ACTION_FWD = 0, 73 74 /** Load balance. */ 75 RTE_TABLE_ACTION_LB, 76 77 /** Traffic Metering and Policing. */ 78 RTE_TABLE_ACTION_MTR, 79 80 /** Traffic Management. */ 81 RTE_TABLE_ACTION_TM, 82 83 /** Packet encapsulations. */ 84 RTE_TABLE_ACTION_ENCAP, 85 86 /** Network Address Translation (NAT). */ 87 RTE_TABLE_ACTION_NAT, 88 89 /** Time to Live (TTL) update. */ 90 RTE_TABLE_ACTION_TTL, 91 92 /** Statistics. */ 93 RTE_TABLE_ACTION_STATS, 94 95 /** Timestamp. */ 96 RTE_TABLE_ACTION_TIME, 97 98 /** Crypto. */ 99 RTE_TABLE_ACTION_SYM_CRYPTO, 100 101 /** Tag. */ 102 RTE_TABLE_ACTION_TAG, 103 104 /** Packet decapsulations. */ 105 RTE_TABLE_ACTION_DECAP, 106 }; 107 108 /** Common action configuration (per table action profile). */ 109 struct rte_table_action_common_config { 110 /** Input packet Internet Protocol (IP) version. Non-zero for IPv4, zero 111 * for IPv6. 112 */ 113 int ip_version; 114 115 /** IP header offset within the input packet buffer. Offset 0 points to 116 * the first byte of the MBUF structure. 117 */ 118 uint32_t ip_offset; 119 }; 120 121 /** 122 * RTE_TABLE_ACTION_FWD 123 */ 124 /** Forward action parameters (per table rule). */ 125 struct rte_table_action_fwd_params { 126 /** Forward action. */ 127 enum rte_pipeline_action action; 128 129 /** Pipeline table ID or output port ID. */ 130 uint32_t id; 131 }; 132 133 /** 134 * RTE_TABLE_ACTION_LB 135 */ 136 /** Load balance key size min (number of bytes). */ 137 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MIN 8 138 139 /** Load balance key size max (number of bytes). */ 140 #define RTE_TABLE_ACTION_LB_KEY_SIZE_MAX 64 141 142 /** Load balance table size. */ 143 #define RTE_TABLE_ACTION_LB_TABLE_SIZE 8 144 145 /** Load balance action configuration (per table action profile). */ 146 struct rte_table_action_lb_config { 147 /** Key size (number of bytes). */ 148 uint32_t key_size; 149 150 /** Key offset within the input packet buffer. Offset 0 points to the 151 * first byte of the MBUF structure. 152 */ 153 uint32_t key_offset; 154 155 /** Key mask (*key_size* bytes are valid). */ 156 uint8_t key_mask[RTE_TABLE_ACTION_LB_KEY_SIZE_MAX]; 157 158 /** Hash function. */ 159 rte_table_hash_op_hash f_hash; 160 161 /** Seed value for *f_hash*. */ 162 uint64_t seed; 163 164 /** Output value offset within the input packet buffer. Offset 0 points 165 * to the first byte of the MBUF structure. 166 */ 167 uint32_t out_offset; 168 }; 169 170 /** Load balance action parameters (per table rule). */ 171 struct rte_table_action_lb_params { 172 /** Table defining the output values and their weights. The weights are 173 * set in 1/RTE_TABLE_ACTION_LB_TABLE_SIZE increments. To assign a 174 * weight of N/RTE_TABLE_ACTION_LB_TABLE_SIZE to a given output value 175 * (0 <= N <= RTE_TABLE_ACTION_LB_TABLE_SIZE), the same output value 176 * needs to show up exactly N times in this table. 177 */ 178 uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE]; 179 }; 180 181 /** 182 * RTE_TABLE_ACTION_MTR 183 */ 184 /** Max number of traffic classes (TCs). */ 185 #define RTE_TABLE_ACTION_TC_MAX 16 186 187 /** Max number of queues per traffic class. */ 188 #define RTE_TABLE_ACTION_TC_QUEUE_MAX 16 189 190 /** Differentiated Services Code Point (DSCP) translation table entry. */ 191 struct rte_table_action_dscp_table_entry { 192 /** Traffic class. Used by the meter or the traffic management actions. 193 * Has to be strictly smaller than *RTE_TABLE_ACTION_TC_MAX*. Traffic 194 * class 0 is the highest priority. 195 */ 196 uint32_t tc_id; 197 198 /** Traffic class queue. Used by the traffic management action. Has to 199 * be strictly smaller than *RTE_TABLE_ACTION_TC_QUEUE_MAX*. 200 */ 201 uint32_t tc_queue_id; 202 203 /** Packet color. Used by the meter action as the packet input color 204 * for the color aware mode of the traffic metering algorithm. 205 */ 206 enum rte_color color; 207 }; 208 209 /** DSCP translation table. */ 210 struct rte_table_action_dscp_table { 211 /** Array of DSCP table entries */ 212 struct rte_table_action_dscp_table_entry entry[64]; 213 }; 214 215 /** Supported traffic metering algorithms. */ 216 enum rte_table_action_meter_algorithm { 217 /** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */ 218 RTE_TABLE_ACTION_METER_SRTCM, 219 220 /** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */ 221 RTE_TABLE_ACTION_METER_TRTCM, 222 }; 223 224 /** Traffic metering profile (configuration template). */ 225 struct rte_table_action_meter_profile { 226 /** Traffic metering algorithm. */ 227 enum rte_table_action_meter_algorithm alg; 228 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 struct rte_ipv6_addr sa; /**< Source address. */ 424 struct rte_ipv6_addr da; /**< 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 union { 491 struct rte_table_action_ipv4_header ipv4; /**< IPv4 header. */ 492 struct rte_table_action_ipv6_header ipv6; /**< IPv6 header. */ 493 }; 494 495 struct rte_table_action_udp_header udp; /**< UDP header. */ 496 struct rte_table_action_vxlan_hdr vxlan; /**< VXLAN header. */ 497 }; 498 499 /** Encap action configuration (per table action profile). */ 500 struct rte_table_action_encap_config { 501 /** Bit mask defining the set of packet encapsulations enabled for the 502 * current table action profile. If bit (1 << N) is set in *encap_mask*, 503 * then packet encapsulation N is enabled, otherwise it is disabled. 504 * 505 * @see enum rte_table_action_encap_type 506 */ 507 uint64_t encap_mask; 508 509 /** Encapsulation type specific configuration. */ 510 union { 511 struct { 512 /** Input packet to be encapsulated: offset within the 513 * input packet buffer to the start of the Ethernet 514 * frame to be encapsulated. Offset 0 points to the 515 * first byte of the MBUF structure. 516 */ 517 uint32_t data_offset; 518 519 /** Encapsulation header: non-zero when encapsulation 520 * header includes a VLAN tag, zero otherwise. 521 */ 522 int vlan; 523 524 /** Encapsulation header: IP version of the IP header 525 * within the encapsulation header. Non-zero for IPv4, 526 * zero for IPv6. 527 */ 528 int ip_version; 529 } vxlan; /**< VXLAN specific configuration. */ 530 }; 531 }; 532 533 /** QinQ_PPPoE encap parameters. */ 534 struct rte_table_encap_ether_qinq_pppoe { 535 536 /** Only valid when *type* is set to QinQ. */ 537 struct rte_table_action_ether_hdr ether; 538 struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */ 539 struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */ 540 struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */ 541 }; 542 543 /** Encap action parameters (per table rule). */ 544 struct rte_table_action_encap_params { 545 /** Encapsulation type. */ 546 enum rte_table_action_encap_type type; 547 548 union { 549 /** Only valid when *type* is set to Ether. */ 550 struct rte_table_action_encap_ether_params ether; 551 552 /** Only valid when *type* is set to VLAN. */ 553 struct rte_table_action_encap_vlan_params vlan; 554 555 /** Only valid when *type* is set to QinQ. */ 556 struct rte_table_action_encap_qinq_params qinq; 557 558 /** Only valid when *type* is set to MPLS. */ 559 struct rte_table_action_encap_mpls_params mpls; 560 561 /** Only valid when *type* is set to PPPoE. */ 562 struct rte_table_action_encap_pppoe_params pppoe; 563 564 /** Only valid when *type* is set to VXLAN. */ 565 struct rte_table_action_encap_vxlan_params vxlan; 566 567 /** Only valid when *type* is set to QinQ_PPPoE. */ 568 struct rte_table_encap_ether_qinq_pppoe qinq_pppoe; 569 }; 570 }; 571 572 /** 573 * RTE_TABLE_ACTION_NAT 574 */ 575 /** NAT action configuration (per table action profile). */ 576 struct rte_table_action_nat_config { 577 /** When non-zero, the IP source address and L4 protocol source port are 578 * translated. When zero, the IP destination address and L4 protocol 579 * destination port are translated. 580 */ 581 int source_nat; 582 583 /** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum 584 * field is computed differently and placed at different header offset 585 * by each layer 4 protocol. 586 */ 587 uint8_t proto; 588 }; 589 590 /** NAT action parameters (per table rule). */ 591 struct rte_table_action_nat_params { 592 /** IP version for *addr*: non-zero for IPv4, zero for IPv6. */ 593 int ip_version; 594 595 /** IP address. */ 596 union { 597 /** IPv4 address; only valid when *ip_version* is non-zero. */ 598 uint32_t ipv4; 599 600 /** IPv6 address; only valid when *ip_version* is set to 0. */ 601 struct rte_ipv6_addr ipv6; 602 } addr; 603 604 /** Port. */ 605 uint16_t port; 606 }; 607 608 /** 609 * RTE_TABLE_ACTION_TTL 610 */ 611 /** TTL action configuration (per table action profile). */ 612 struct rte_table_action_ttl_config { 613 /** When non-zero, the input packets whose updated IPv4 Time to Live 614 * (TTL) field or IPv6 Hop Limit (HL) field is zero are dropped. 615 * When zero, the input packets whose updated IPv4 TTL field or IPv6 HL 616 * field is zero are forwarded as usual (typically for debugging 617 * purpose). 618 */ 619 int drop; 620 621 /** When non-zero, the *n_packets* stats counter for TTL action is 622 * enabled, otherwise disabled. 623 * 624 * @see struct rte_table_action_ttl_counters 625 */ 626 int n_packets_enabled; 627 }; 628 629 /** TTL action parameters (per table rule). */ 630 struct rte_table_action_ttl_params { 631 /** When non-zero, decrement the IPv4 TTL field and update the checksum 632 * field, or decrement the IPv6 HL field. When zero, the IPv4 TTL field 633 * or the IPv6 HL field is not changed. 634 */ 635 int decrement; 636 }; 637 638 /** TTL action statistics packets (per table rule). */ 639 struct rte_table_action_ttl_counters { 640 /** Number of IPv4 packets whose updated TTL field is zero or IPv6 641 * packets whose updated HL field is zero. 642 */ 643 uint64_t n_packets; 644 }; 645 646 /** 647 * RTE_TABLE_ACTION_STATS 648 */ 649 /** Stats action configuration (per table action profile). */ 650 struct rte_table_action_stats_config { 651 /** When non-zero, the *n_packets* stats counter is enabled, otherwise 652 * disabled. 653 * 654 * @see struct rte_table_action_stats_counters 655 */ 656 int n_packets_enabled; 657 658 /** When non-zero, the *n_bytes* stats counter is enabled, otherwise 659 * disabled. 660 * 661 * @see struct rte_table_action_stats_counters 662 */ 663 int n_bytes_enabled; 664 }; 665 666 /** Stats action parameters (per table rule). */ 667 struct rte_table_action_stats_params { 668 /** Initial value for the *n_packets* stats counter. Typically set to 0. 669 * 670 * @see struct rte_table_action_stats_counters 671 */ 672 uint64_t n_packets; 673 674 /** Initial value for the *n_bytes* stats counter. Typically set to 0. 675 * 676 * @see struct rte_table_action_stats_counters 677 */ 678 uint64_t n_bytes; 679 }; 680 681 /** Stats action counters (per table rule). */ 682 struct rte_table_action_stats_counters { 683 /** Number of packets. Valid only when *n_packets_valid* is non-zero. */ 684 uint64_t n_packets; 685 686 /** Number of bytes. Valid only when *n_bytes_valid* is non-zero. */ 687 uint64_t n_bytes; 688 689 /** When non-zero, the *n_packets* field is valid, otherwise invalid. */ 690 int n_packets_valid; 691 692 /** When non-zero, the *n_bytes* field is valid, otherwise invalid. */ 693 int n_bytes_valid; 694 }; 695 696 /** 697 * RTE_TABLE_ACTION_TIME 698 */ 699 /** Timestamp action parameters (per table rule). */ 700 struct rte_table_action_time_params { 701 /** Initial timestamp value. Typically set to current time. */ 702 uint64_t time; 703 }; 704 705 /** 706 * RTE_TABLE_ACTION_CRYPTO 707 */ 708 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX 709 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX (16) 710 #endif 711 712 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX 713 #define RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX (16) 714 #endif 715 716 #ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET 717 #define RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET \ 718 (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op)) 719 #endif 720 721 /** Common action structure to store the data's value, length, and offset */ 722 struct rte_table_action_vlo { 723 uint8_t *val; 724 uint32_t length; 725 uint32_t offset; 726 }; 727 728 /** Symmetric crypto action configuration (per table action profile). */ 729 struct rte_table_action_sym_crypto_config { 730 /** Target Cryptodev ID. */ 731 uint8_t cryptodev_id; 732 733 /** 734 * Offset to rte_crypto_op structure within the input packet buffer. 735 * Offset 0 points to the first byte of the MBUF structure. 736 */ 737 uint32_t op_offset; 738 739 /** The mempool for creating cryptodev sessions. */ 740 struct rte_mempool *mp_create; 741 742 /** The mempool for initializing cryptodev sessions. */ 743 struct rte_mempool *mp_init; 744 }; 745 746 /** Symmetric Crypto action parameters (per table rule). */ 747 struct rte_table_action_sym_crypto_params { 748 749 /** Xform pointer contains all relevant information */ 750 struct rte_crypto_sym_xform *xform; 751 752 /** 753 * Offset within the input packet buffer to the first byte of data 754 * to be processed by the crypto unit. Offset 0 points to the first 755 * byte of the MBUF structure. 756 */ 757 uint32_t data_offset; 758 759 union { 760 struct { 761 /** Cipher iv data. */ 762 struct rte_table_action_vlo cipher_iv; 763 764 /** Cipher iv data. */ 765 struct rte_table_action_vlo cipher_iv_update; 766 767 /** Auth iv data. */ 768 struct rte_table_action_vlo auth_iv; 769 770 /** Auth iv data. */ 771 struct rte_table_action_vlo auth_iv_update; 772 773 } cipher_auth; 774 775 struct { 776 /** AEAD AAD data. */ 777 struct rte_table_action_vlo aad; 778 779 /** AEAD iv data. */ 780 struct rte_table_action_vlo iv; 781 782 /** AEAD AAD data. */ 783 struct rte_table_action_vlo aad_update; 784 785 /** AEAD iv data. */ 786 struct rte_table_action_vlo iv_update; 787 788 } aead; 789 }; 790 }; 791 792 /** 793 * RTE_TABLE_ACTION_TAG 794 */ 795 /** Tag action parameters (per table rule). */ 796 struct rte_table_action_tag_params { 797 /** Tag to be attached to the input packet. */ 798 uint32_t tag; 799 }; 800 801 /** 802 * RTE_TABLE_ACTION_DECAP 803 */ 804 /** Decap action parameters (per table rule). */ 805 struct rte_table_action_decap_params { 806 /** Number of bytes to be removed from the start of the packet. */ 807 uint16_t n; 808 }; 809 810 /** 811 * Table action profile. 812 */ 813 struct rte_table_action_profile; 814 815 /** 816 * Table action profile create. 817 * 818 * @param[in] common 819 * Common action configuration. 820 * @return 821 * Table action profile handle on success, NULL otherwise. 822 */ 823 __rte_experimental 824 struct rte_table_action_profile * 825 rte_table_action_profile_create(struct rte_table_action_common_config *common); 826 827 /** 828 * Table action profile free. 829 * 830 * @param[in] profile 831 * Table profile action handle (needs to be valid). 832 * @return 833 * Zero on success, non-zero error code otherwise. 834 */ 835 __rte_experimental 836 int 837 rte_table_action_profile_free(struct rte_table_action_profile *profile); 838 839 /** 840 * Table action profile action register. 841 * 842 * @param[in] profile 843 * Table profile action handle (needs to be valid and not in frozen state). 844 * @param[in] type 845 * Specific table action to be registered for *profile*. 846 * @param[in] action_config 847 * Configuration for the *type* action. 848 * If struct rte_table_action_*type*_config is defined by the Table Action 849 * API, it needs to point to a valid instance of this structure, otherwise it 850 * needs to be set to NULL. 851 * @return 852 * Zero on success, non-zero error code otherwise. 853 */ 854 __rte_experimental 855 int 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 __rte_experimental 876 int 877 rte_table_action_profile_freeze(struct rte_table_action_profile *profile); 878 879 /** 880 * Table action. 881 */ 882 struct rte_table_action; 883 884 /** 885 * Table action create. 886 * 887 * Instantiates the given table action profile to create a table action object. 888 * 889 * @param[in] profile 890 * Table profile action handle (needs to be valid and in frozen state). 891 * @param[in] socket_id 892 * CPU socket ID where the internal data structures required by the new table 893 * action object should be allocated. 894 * @return 895 * Handle to table action object on success, NULL on error. 896 * 897 * @see rte_table_action_create() 898 */ 899 __rte_experimental 900 struct rte_table_action * 901 rte_table_action_create(struct rte_table_action_profile *profile, 902 uint32_t socket_id); 903 904 /** 905 * Table action free. 906 * 907 * @param[in] action 908 * Handle to table action object (needs to be valid). 909 * @return 910 * Zero on success, non-zero error code otherwise. 911 */ 912 __rte_experimental 913 int 914 rte_table_action_free(struct rte_table_action *action); 915 916 /** 917 * Table action table params get. 918 * 919 * @param[in] action 920 * Handle to table action object (needs to be valid). 921 * @param[inout] params 922 * Pipeline table parameters (needs to be pre-allocated). 923 * @return 924 * Zero on success, non-zero error code otherwise. 925 */ 926 __rte_experimental 927 int 928 rte_table_action_table_params_get(struct rte_table_action *action, 929 struct rte_pipeline_table_params *params); 930 931 /** 932 * Table action apply. 933 * 934 * @param[in] action 935 * Handle to table action object (needs to be valid). 936 * @param[in] data 937 * Data byte array (typically table rule data) to apply action *type* on. 938 * @param[in] type 939 * Specific table action previously registered for the table action profile of 940 * the *action* object. 941 * @param[in] action_params 942 * Parameters for the *type* action. 943 * If struct rte_table_action_*type*_params is defined by the Table Action 944 * API, it needs to point to a valid instance of this structure, otherwise it 945 * needs to be set to NULL. 946 * @return 947 * Zero on success, non-zero error code otherwise. 948 */ 949 __rte_experimental 950 int 951 rte_table_action_apply(struct rte_table_action *action, 952 void *data, 953 enum rte_table_action_type type, 954 void *action_params); 955 956 /** 957 * Table action DSCP table update. 958 * 959 * @param[in] action 960 * Handle to table action object (needs to be valid). 961 * @param[in] dscp_mask 962 * 64-bit mask defining the DSCP table entries to be updated. If bit N is set 963 * in this bit mask, then DSCP table entry N is to be updated, otherwise not. 964 * @param[in] table 965 * DSCP table. 966 * @return 967 * Zero on success, non-zero error code otherwise. 968 */ 969 __rte_experimental 970 int 971 rte_table_action_dscp_table_update(struct rte_table_action *action, 972 uint64_t dscp_mask, 973 struct rte_table_action_dscp_table *table); 974 975 /** 976 * Table action meter profile add. 977 * 978 * @param[in] action 979 * Handle to table action object (needs to be valid). 980 * @param[in] meter_profile_id 981 * Meter profile ID to be used for the *profile* once it is successfully added 982 * to the *action* object (needs to be unused by the set of meter profiles 983 * currently registered for the *action* object). 984 * @param[in] profile 985 * Meter profile to be added. 986 * @return 987 * Zero on success, non-zero error code otherwise. 988 */ 989 __rte_experimental 990 int 991 rte_table_action_meter_profile_add(struct rte_table_action *action, 992 uint32_t meter_profile_id, 993 struct rte_table_action_meter_profile *profile); 994 995 /** 996 * Table action meter profile delete. 997 * 998 * @param[in] action 999 * Handle to table action object (needs to be valid). 1000 * @param[in] meter_profile_id 1001 * Meter profile ID of the meter profile to be deleted from the *action* 1002 * object (needs to be valid for the *action* object). 1003 * @return 1004 * Zero on success, non-zero error code otherwise. 1005 */ 1006 __rte_experimental 1007 int 1008 rte_table_action_meter_profile_delete(struct rte_table_action *action, 1009 uint32_t meter_profile_id); 1010 1011 /** 1012 * Table action meter read. 1013 * 1014 * @param[in] action 1015 * Handle to table action object (needs to be valid). 1016 * @param[in] data 1017 * Data byte array (typically table rule data) with meter action previously 1018 * applied on it. 1019 * @param[in] tc_mask 1020 * Bit mask defining which traffic classes should have the meter stats 1021 * counters read from *data* and stored into *stats*. If bit N is set in this 1022 * bit mask, then traffic class N is part of this operation, otherwise it is 1023 * not. If bit N is set in this bit mask, then traffic class N must be one of 1024 * the traffic classes that are enabled for the meter action in the table 1025 * action profile used by the *action* object. 1026 * @param[inout] stats 1027 * When non-NULL, it points to the area where the meter stats counters read 1028 * from *data* are saved. Only the meter stats counters for the *tc_mask* 1029 * traffic classes are read and stored to *stats*. 1030 * @param[in] clear 1031 * When non-zero, the meter stats counters are cleared (i.e. set to zero), 1032 * otherwise the counters are not modified. When the read operation is enabled 1033 * (*stats* is non-NULL), the clear operation is performed after the read 1034 * operation is completed. 1035 * @return 1036 * Zero on success, non-zero error code otherwise. 1037 */ 1038 __rte_experimental 1039 int 1040 rte_table_action_meter_read(struct rte_table_action *action, 1041 void *data, 1042 uint32_t tc_mask, 1043 struct rte_table_action_mtr_counters *stats, 1044 int clear); 1045 1046 /** 1047 * Table action TTL read. 1048 * 1049 * @param[in] action 1050 * Handle to table action object (needs to be valid). 1051 * @param[in] data 1052 * Data byte array (typically table rule data) with TTL action previously 1053 * applied on it. 1054 * @param[inout] stats 1055 * When non-NULL, it points to the area where the TTL stats counters read from 1056 * *data* are saved. 1057 * @param[in] clear 1058 * When non-zero, the TTL stats counters are cleared (i.e. set to zero), 1059 * otherwise the counters are not modified. When the read operation is enabled 1060 * (*stats* is non-NULL), the clear operation is performed after the read 1061 * operation is completed. 1062 * @return 1063 * Zero on success, non-zero error code otherwise. 1064 */ 1065 __rte_experimental 1066 int 1067 rte_table_action_ttl_read(struct rte_table_action *action, 1068 void *data, 1069 struct rte_table_action_ttl_counters *stats, 1070 int clear); 1071 1072 /** 1073 * Table action stats read. 1074 * 1075 * @param[in] action 1076 * Handle to table action object (needs to be valid). 1077 * @param[in] data 1078 * Data byte array (typically table rule data) with stats action previously 1079 * applied on it. 1080 * @param[inout] stats 1081 * When non-NULL, it points to the area where the stats counters read from 1082 * *data* are saved. 1083 * @param[in] clear 1084 * When non-zero, the stats counters are cleared (i.e. set to zero), otherwise 1085 * the counters are not modified. When the read operation is enabled (*stats* 1086 * is non-NULL), the clear operation is performed after the read operation is 1087 * completed. 1088 * @return 1089 * Zero on success, non-zero error code otherwise. 1090 */ 1091 __rte_experimental 1092 int 1093 rte_table_action_stats_read(struct rte_table_action *action, 1094 void *data, 1095 struct rte_table_action_stats_counters *stats, 1096 int clear); 1097 1098 /** 1099 * Table action timestamp read. 1100 * 1101 * @param[in] action 1102 * Handle to table action object (needs to be valid). 1103 * @param[in] data 1104 * Data byte array (typically table rule data) with timestamp action 1105 * previously applied on it. 1106 * @param[inout] timestamp 1107 * Pre-allocated memory where the timestamp read from *data* is saved (has to 1108 * be non-NULL). 1109 * @return 1110 * Zero on success, non-zero error code otherwise. 1111 */ 1112 __rte_experimental 1113 int 1114 rte_table_action_time_read(struct rte_table_action *action, 1115 void *data, 1116 uint64_t *timestamp); 1117 1118 /** 1119 * Table action cryptodev symmetric session get. 1120 * 1121 * @param[in] action 1122 * Handle to table action object (needs to be valid). 1123 * @param[in] data 1124 * Data byte array (typically table rule data) with sym crypto action. 1125 * @return 1126 * The pointer to the session on success, NULL otherwise. 1127 */ 1128 __rte_experimental 1129 struct rte_cryptodev_sym_session * 1130 rte_table_action_crypto_sym_session_get(struct rte_table_action *action, 1131 void *data); 1132 1133 #ifdef __cplusplus 1134 } 1135 #endif 1136 1137 #endif /* __INCLUDE_RTE_TABLE_ACTION_H__ */ 1138