net: add rte prefix to ether structures
[dpdk.git] / lib / librte_pipeline / rte_table_action.h
index 98babc5..ef45a30 100644 (file)
@@ -59,7 +59,9 @@ extern "C" {
 #include <stdint.h>
 
 #include <rte_compat.h>
+#include <rte_ether.h>
 #include <rte_meter.h>
+#include <rte_table_hash.h>
 
 #include "rte_pipeline.h"
 
@@ -68,11 +70,38 @@ enum rte_table_action_type {
        /** Forward to next pipeline table, output port or drop. */
        RTE_TABLE_ACTION_FWD = 0,
 
+       /**  Load balance. */
+       RTE_TABLE_ACTION_LB,
+
        /**  Traffic Metering and Policing. */
        RTE_TABLE_ACTION_MTR,
 
        /**  Traffic Management. */
        RTE_TABLE_ACTION_TM,
+
+       /** Packet encapsulations. */
+       RTE_TABLE_ACTION_ENCAP,
+
+       /** Network Address Translation (NAT). */
+       RTE_TABLE_ACTION_NAT,
+
+       /** Time to Live (TTL) update. */
+       RTE_TABLE_ACTION_TTL,
+
+       /** Statistics. */
+       RTE_TABLE_ACTION_STATS,
+
+       /** Timestamp. */
+       RTE_TABLE_ACTION_TIME,
+
+       /** Crypto. */
+       RTE_TABLE_ACTION_SYM_CRYPTO,
+
+       /** Tag. */
+       RTE_TABLE_ACTION_TAG,
+
+       /** Packet decapsulations. */
+       RTE_TABLE_ACTION_DECAP,
 };
 
 /** Common action configuration (per table action profile). */
@@ -100,6 +129,54 @@ struct rte_table_action_fwd_params {
        uint32_t id;
 };
 
+/**
+ * RTE_TABLE_ACTION_LB
+ */
+/** Load balance key size min (number of bytes). */
+#define RTE_TABLE_ACTION_LB_KEY_SIZE_MIN                    8
+
+/** Load balance key size max (number of bytes). */
+#define RTE_TABLE_ACTION_LB_KEY_SIZE_MAX                    64
+
+/** Load balance table size. */
+#define RTE_TABLE_ACTION_LB_TABLE_SIZE                      8
+
+/** Load balance action configuration (per table action profile). */
+struct rte_table_action_lb_config {
+       /** Key size (number of bytes). */
+       uint32_t key_size;
+
+       /** Key offset within the input packet buffer. Offset 0 points to the
+        * first byte of the MBUF structure.
+        */
+       uint32_t key_offset;
+
+       /** Key mask (*key_size* bytes are valid). */
+       uint8_t key_mask[RTE_TABLE_ACTION_LB_KEY_SIZE_MAX];
+
+       /** Hash function. */
+       rte_table_hash_op_hash f_hash;
+
+       /** Seed value for *f_hash*. */
+       uint64_t seed;
+
+       /** Output value offset within the input packet buffer. Offset 0 points
+        * to the first byte of the MBUF structure.
+        */
+       uint32_t out_offset;
+};
+
+/** Load balance action parameters (per table rule). */
+struct rte_table_action_lb_params {
+       /** Table defining the output values and their weights. The weights are
+        * set in 1/RTE_TABLE_ACTION_LB_TABLE_SIZE increments. To assign a
+        * weight of N/RTE_TABLE_ACTION_LB_TABLE_SIZE to a given output value
+        * (0 <= N <= RTE_TABLE_ACTION_LB_TABLE_SIZE), the same output value
+        * needs to show up exactly N times in this table.
+        */
+       uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE];
+};
+
 /**
  * RTE_TABLE_ACTION_MTR
  */
@@ -125,7 +202,7 @@ struct rte_table_action_dscp_table_entry {
        /** Packet color. Used by the meter action as the packet input color
         * for the color aware mode of the traffic metering algorithm.
         */
-       enum rte_meter_color color;
+       enum rte_color color;
 };
 
 /** DSCP translation table. */
@@ -182,7 +259,7 @@ struct rte_table_action_mtr_tc_params {
        uint32_t meter_profile_id;
 
        /** Policer actions. */
-       enum rte_table_action_policer policer[e_RTE_METER_COLORS];
+       enum rte_table_action_policer policer[RTE_COLORS];
 };
 
 /** Meter action statistics counters per traffic class. */
@@ -191,13 +268,13 @@ struct rte_table_action_mtr_counters_tc {
         * and before the policer actions are executed. Only valid when
         * *n_packets_valid* is non-zero.
         */
-       uint64_t n_packets[e_RTE_METER_COLORS];
+       uint64_t n_packets[RTE_COLORS];
 
        /** Number of packet bytes per color at the output of the traffic
         * metering and before the policer actions are executed. Only valid when
         * *n_bytes_valid* is non-zero.
         */
-       uint64_t n_bytes[e_RTE_METER_COLORS];
+       uint64_t n_bytes[RTE_COLORS];
 
        /** When non-zero, the *n_packets* field is valid. */
        int n_packets_valid;
@@ -279,6 +356,460 @@ struct rte_table_action_tm_params {
        uint32_t pipe_id;
 };
 
+/**
+ * RTE_TABLE_ACTION_ENCAP
+ */
+/** Supported packet encapsulation types. */
+enum rte_table_action_encap_type {
+       /** IP -> { Ether | IP } */
+       RTE_TABLE_ACTION_ENCAP_ETHER = 0,
+
+       /** IP -> { Ether | VLAN | IP } */
+       RTE_TABLE_ACTION_ENCAP_VLAN,
+
+       /** IP -> { Ether | S-VLAN | C-VLAN | IP } */
+       RTE_TABLE_ACTION_ENCAP_QINQ,
+
+       /** IP -> { Ether | MPLS | IP } */
+       RTE_TABLE_ACTION_ENCAP_MPLS,
+
+       /** IP -> { Ether | PPPoE | PPP | IP } */
+       RTE_TABLE_ACTION_ENCAP_PPPOE,
+
+       /** Ether -> { Ether | IP | UDP | VXLAN | Ether }
+        * Ether -> { Ether | VLAN | IP | UDP | VXLAN | Ether }
+        */
+       RTE_TABLE_ACTION_ENCAP_VXLAN,
+
+       /** IP -> { Ether | S-VLAN | C-VLAN | PPPoE | PPP | IP } */
+       RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE,
+};
+
+/** Pre-computed Ethernet header fields for encapsulation action. */
+struct rte_table_action_ether_hdr {
+       struct rte_ether_addr da; /**< Destination address. */
+       struct rte_ether_addr sa; /**< Source address. */
+};
+
+/** Pre-computed VLAN header fields for encapsulation action. */
+struct rte_table_action_vlan_hdr {
+       uint8_t pcp; /**< Priority Code Point (PCP). */
+       uint8_t dei; /**< Drop Eligibility Indicator (DEI). */
+       uint16_t vid; /**< VLAN Identifier (VID). */
+};
+
+/** Pre-computed MPLS header fields for encapsulation action. */
+struct rte_table_action_mpls_hdr {
+       uint32_t label; /**< Label. */
+       uint8_t tc; /**< Traffic Class (TC). */
+       uint8_t ttl; /**< Time to Live (TTL). */
+};
+
+/** Pre-computed PPPoE header fields for encapsulation action. */
+struct rte_table_action_pppoe_hdr {
+       uint16_t session_id; /**< Session ID. */
+};
+
+/** Pre-computed IPv4 header fields for encapsulation action. */
+struct rte_table_action_ipv4_header {
+       uint32_t sa; /**< Source address. */
+       uint32_t da; /**< Destination address. */
+       uint8_t dscp; /**< DiffServ Code Point (DSCP). */
+       uint8_t ttl; /**< Time To Live (TTL). */
+};
+
+/** Pre-computed IPv6 header fields for encapsulation action. */
+struct rte_table_action_ipv6_header {
+       uint8_t sa[16]; /**< Source address. */
+       uint8_t da[16]; /**< Destination address. */
+       uint32_t flow_label; /**< Flow label. */
+       uint8_t dscp; /**< DiffServ Code Point (DSCP). */
+       uint8_t hop_limit; /**< Hop Limit (HL). */
+};
+
+/** Pre-computed UDP header fields for encapsulation action. */
+struct rte_table_action_udp_header {
+       uint16_t sp; /**< Source port. */
+       uint16_t dp; /**< Destination port. */
+};
+
+/** Pre-computed VXLAN header fields for encapsulation action. */
+struct rte_table_action_vxlan_hdr {
+       uint32_t vni; /**< VXLAN Network Identifier (VNI). */
+};
+
+/** Ether encap parameters. */
+struct rte_table_action_encap_ether_params {
+       struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
+};
+
+/** VLAN encap parameters. */
+struct rte_table_action_encap_vlan_params {
+       struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
+       struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
+};
+
+/** QinQ encap parameters. */
+struct rte_table_action_encap_qinq_params {
+       struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
+       struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
+       struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
+};
+
+/** Max number of MPLS labels per output packet for MPLS encapsulation. */
+#ifndef RTE_TABLE_ACTION_MPLS_LABELS_MAX
+#define RTE_TABLE_ACTION_MPLS_LABELS_MAX                   4
+#endif
+
+/** MPLS encap parameters. */
+struct rte_table_action_encap_mpls_params {
+       /** Ethernet header. */
+       struct rte_table_action_ether_hdr ether;
+
+       /** MPLS header. */
+       struct rte_table_action_mpls_hdr mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
+
+       /** Number of MPLS labels in MPLS header. */
+       uint32_t mpls_count;
+
+       /** Non-zero for MPLS unicast, zero for MPLS multicast. */
+       int unicast;
+};
+
+/** PPPoE encap parameters. */
+struct rte_table_action_encap_pppoe_params {
+       struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
+       struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
+};
+
+/** VXLAN encap parameters. */
+struct rte_table_action_encap_vxlan_params {
+       struct rte_table_action_ether_hdr ether; /**< Ethernet header. */
+       struct rte_table_action_vlan_hdr vlan; /**< VLAN header. */
+
+       RTE_STD_C11
+       union {
+               struct rte_table_action_ipv4_header ipv4; /**< IPv4 header. */
+               struct rte_table_action_ipv6_header ipv6; /**< IPv6 header. */
+       };
+
+       struct rte_table_action_udp_header udp; /**< UDP header. */
+       struct rte_table_action_vxlan_hdr vxlan; /**< VXLAN header. */
+};
+
+/** Encap action configuration (per table action profile). */
+struct rte_table_action_encap_config {
+       /** Bit mask defining the set of packet encapsulations enabled for the
+        * current table action profile. If bit (1 << N) is set in *encap_mask*,
+        * then packet encapsulation N is enabled, otherwise it is disabled.
+        *
+        * @see enum rte_table_action_encap_type
+        */
+       uint64_t encap_mask;
+
+       /** Encapsulation type specific configuration. */
+       RTE_STD_C11
+       union {
+               struct {
+                       /** Input packet to be encapsulated: offset within the
+                        * input packet buffer to the start of the Ethernet
+                        * frame to be encapsulated. Offset 0 points to the
+                        * first byte of the MBUF structure.
+                        */
+                       uint32_t data_offset;
+
+                       /** Encapsulation header: non-zero when encapsulation
+                        * header includes a VLAN tag, zero otherwise.
+                        */
+                       int vlan;
+
+                       /** Encapsulation header: IP version of the IP header
+                        * within the encapsulation header. Non-zero for IPv4,
+                        * zero for IPv6.
+                        */
+                       int ip_version;
+               } vxlan; /**< VXLAN specific configuration. */
+       };
+};
+
+/** QinQ_PPPoE encap parameters. */
+struct rte_table_encap_ether_qinq_pppoe {
+
+       /** Only valid when *type* is set to QinQ. */
+       struct rte_table_action_ether_hdr ether;
+       struct rte_table_action_vlan_hdr svlan; /**< Service VLAN header. */
+       struct rte_table_action_vlan_hdr cvlan; /**< Customer VLAN header. */
+       struct rte_table_action_pppoe_hdr pppoe; /**< PPPoE/PPP headers. */
+};
+
+/** Encap action parameters (per table rule). */
+struct rte_table_action_encap_params {
+       /** Encapsulation type. */
+       enum rte_table_action_encap_type type;
+
+       RTE_STD_C11
+       union {
+               /** Only valid when *type* is set to Ether. */
+               struct rte_table_action_encap_ether_params ether;
+
+               /** Only valid when *type* is set to VLAN. */
+               struct rte_table_action_encap_vlan_params vlan;
+
+               /** Only valid when *type* is set to QinQ. */
+               struct rte_table_action_encap_qinq_params qinq;
+
+               /** Only valid when *type* is set to MPLS. */
+               struct rte_table_action_encap_mpls_params mpls;
+
+               /** Only valid when *type* is set to PPPoE. */
+               struct rte_table_action_encap_pppoe_params pppoe;
+
+               /** Only valid when *type* is set to VXLAN. */
+               struct rte_table_action_encap_vxlan_params vxlan;
+
+               /** Only valid when *type* is set to QinQ_PPPoE. */
+               struct rte_table_encap_ether_qinq_pppoe qinq_pppoe;
+       };
+};
+
+/**
+ * RTE_TABLE_ACTION_NAT
+ */
+/** NAT action configuration (per table action profile). */
+struct rte_table_action_nat_config {
+       /** When non-zero, the IP source address and L4 protocol source port are
+        * translated. When zero, the IP destination address and L4 protocol
+        * destination port are translated.
+        */
+       int source_nat;
+
+       /** Layer 4 protocol, for example TCP (0x06) or UDP (0x11). The checksum
+        * field is computed differently and placed at different header offset
+        * by each layer 4 protocol.
+        */
+       uint8_t proto;
+};
+
+/** NAT action parameters (per table rule). */
+struct rte_table_action_nat_params {
+       /** IP version for *addr*: non-zero for IPv4, zero for IPv6. */
+       int ip_version;
+
+       /** IP address. */
+       union {
+               /** IPv4 address; only valid when *ip_version* is non-zero. */
+               uint32_t ipv4;
+
+               /** IPv6 address; only valid when *ip_version* is set to 0. */
+               uint8_t ipv6[16];
+       } addr;
+
+       /** Port. */
+       uint16_t port;
+};
+
+/**
+ * RTE_TABLE_ACTION_TTL
+ */
+/** TTL action configuration (per table action profile). */
+struct rte_table_action_ttl_config {
+       /** When non-zero, the input packets whose updated IPv4 Time to Live
+        * (TTL) field or IPv6 Hop Limit (HL) field is zero are dropped.
+        * When zero, the input packets whose updated IPv4 TTL field or IPv6 HL
+        * field is zero are forwarded as usual (typically for debugging
+        * purpose).
+        */
+       int drop;
+
+       /** When non-zero, the *n_packets* stats counter for TTL action is
+        * enabled, otherwise disabled.
+        *
+        * @see struct rte_table_action_ttl_counters
+        */
+       int n_packets_enabled;
+};
+
+/** TTL action parameters (per table rule). */
+struct rte_table_action_ttl_params {
+       /** When non-zero, decrement the IPv4 TTL field and update the checksum
+        * field, or decrement the IPv6 HL field. When zero, the IPv4 TTL field
+        * or the IPv6 HL field is not changed.
+        */
+       int decrement;
+};
+
+/** TTL action statistics packets (per table rule). */
+struct rte_table_action_ttl_counters {
+       /** Number of IPv4 packets whose updated TTL field is zero or IPv6
+        * packets whose updated HL field is zero.
+        */
+       uint64_t n_packets;
+};
+
+/**
+ * RTE_TABLE_ACTION_STATS
+ */
+/** Stats action configuration (per table action profile). */
+struct rte_table_action_stats_config {
+       /** When non-zero, the *n_packets* stats counter is enabled, otherwise
+        * disabled.
+        *
+        * @see struct rte_table_action_stats_counters
+        */
+       int n_packets_enabled;
+
+       /** When non-zero, the *n_bytes* stats counter is enabled, otherwise
+        * disabled.
+        *
+        * @see struct rte_table_action_stats_counters
+        */
+       int n_bytes_enabled;
+};
+
+/** Stats action parameters (per table rule). */
+struct rte_table_action_stats_params {
+       /** Initial value for the *n_packets* stats counter. Typically set to 0.
+        *
+        * @see struct rte_table_action_stats_counters
+        */
+       uint64_t n_packets;
+
+       /** Initial value for the *n_bytes* stats counter. Typically set to 0.
+        *
+        * @see struct rte_table_action_stats_counters
+        */
+       uint64_t n_bytes;
+};
+
+/** Stats action counters (per table rule). */
+struct rte_table_action_stats_counters {
+       /** Number of packets. Valid only when *n_packets_valid* is non-zero. */
+       uint64_t n_packets;
+
+       /** Number of bytes. Valid only when *n_bytes_valid* is non-zero. */
+       uint64_t n_bytes;
+
+       /** When non-zero, the *n_packets* field is valid, otherwise invalid. */
+       int n_packets_valid;
+
+       /** When non-zero, the *n_bytes* field is valid, otherwise invalid. */
+       int n_bytes_valid;
+};
+
+/**
+ * RTE_TABLE_ACTION_TIME
+ */
+/** Timestamp action parameters (per table rule). */
+struct rte_table_action_time_params {
+       /** Initial timestamp value. Typically set to current time. */
+       uint64_t time;
+};
+
+/**
+ * RTE_TABLE_ACTION_CRYPTO
+ */
+#ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX
+#define RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX                (16)
+#endif
+
+#ifndef RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX
+#define RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX       (16)
+#endif
+
+#ifndef RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET
+#define RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET                          \
+       (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
+#endif
+
+/** Common action structure to store the data's value, length, and offset */
+struct rte_table_action_vlo {
+       uint8_t *val;
+       uint32_t length;
+       uint32_t offset;
+};
+
+/** Symmetric crypto action configuration (per table action profile). */
+struct rte_table_action_sym_crypto_config {
+       /** Target Cryptodev ID. */
+       uint8_t cryptodev_id;
+
+       /**
+        * Offset to rte_crypto_op structure within the input packet buffer.
+        * Offset 0 points to the first byte of the MBUF structure.
+        */
+       uint32_t op_offset;
+
+       /** The mempool for creating cryptodev sessions. */
+       struct rte_mempool *mp_create;
+
+       /** The mempool for initializing cryptodev sessions. */
+       struct rte_mempool *mp_init;
+};
+
+/** Symmetric Crypto action parameters (per table rule). */
+struct rte_table_action_sym_crypto_params {
+
+       /** Xform pointer contains all relevant information */
+       struct rte_crypto_sym_xform *xform;
+
+       /**
+        * Offset within the input packet buffer to the first byte of data
+        * to be processed by the crypto unit. Offset 0 points to the first
+        * byte of the MBUF structure.
+        */
+       uint32_t data_offset;
+
+       union {
+               struct {
+                       /** Cipher iv data. */
+                       struct rte_table_action_vlo cipher_iv;
+
+                       /** Cipher iv data. */
+                       struct rte_table_action_vlo cipher_iv_update;
+
+                       /** Auth iv data. */
+                       struct rte_table_action_vlo auth_iv;
+
+                       /** Auth iv data. */
+                       struct rte_table_action_vlo auth_iv_update;
+
+               } cipher_auth;
+
+               struct {
+                       /** AEAD AAD data. */
+                       struct rte_table_action_vlo aad;
+
+                       /** AEAD iv data. */
+                       struct rte_table_action_vlo iv;
+
+                       /** AEAD AAD data. */
+                       struct rte_table_action_vlo aad_update;
+
+                       /** AEAD iv data. */
+                       struct rte_table_action_vlo iv_update;
+
+               } aead;
+       };
+};
+
+/**
+ * RTE_TABLE_ACTION_TAG
+ */
+/** Tag action parameters (per table rule). */
+struct rte_table_action_tag_params {
+       /** Tag to be attached to the input packet. */
+       uint32_t tag;
+};
+
+/**
+ * RTE_TABLE_ACTION_DECAP
+ */
+/** Decap action parameters (per table rule). */
+struct rte_table_action_decap_params {
+       /** Number of bytes to be removed from the start of the packet. */
+       uint16_t n;
+};
+
 /**
  * Table action profile.
  */
@@ -503,6 +1034,89 @@ rte_table_action_meter_read(struct rte_table_action *action,
        struct rte_table_action_mtr_counters *stats,
        int clear);
 
+/**
+ * Table action TTL read.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @param[in] data
+ *   Data byte array (typically table rule data) with TTL action previously
+ *   applied on it.
+ * @param[inout] stats
+ *   When non-NULL, it points to the area where the TTL stats counters read from
+ *   *data* are saved.
+ * @param[in] clear
+ *   When non-zero, the TTL stats counters are cleared (i.e. set to zero),
+ *   otherwise the counters are not modified. When the read operation is enabled
+ *   (*stats* is non-NULL), the clear operation is performed after the read
+ *   operation is completed.
+ * @return
+ *   Zero on success, non-zero error code otherwise.
+ */
+int __rte_experimental
+rte_table_action_ttl_read(struct rte_table_action *action,
+       void *data,
+       struct rte_table_action_ttl_counters *stats,
+       int clear);
+
+/**
+ * Table action stats read.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @param[in] data
+ *   Data byte array (typically table rule data) with stats action previously
+ *   applied on it.
+ * @param[inout] stats
+ *   When non-NULL, it points to the area where the stats counters read from
+ *   *data* are saved.
+ * @param[in] clear
+ *   When non-zero, the stats counters are cleared (i.e. set to zero), otherwise
+ *   the counters are not modified. When the read operation is enabled (*stats*
+ *   is non-NULL), the clear operation is performed after the read operation is
+ *   completed.
+ * @return
+ *   Zero on success, non-zero error code otherwise.
+ */
+int __rte_experimental
+rte_table_action_stats_read(struct rte_table_action *action,
+       void *data,
+       struct rte_table_action_stats_counters *stats,
+       int clear);
+
+/**
+ * Table action timestamp read.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @param[in] data
+ *   Data byte array (typically table rule data) with timestamp action
+ *   previously applied on it.
+ * @param[inout] timestamp
+ *   Pre-allocated memory where the timestamp read from *data* is saved (has to
+ *   be non-NULL).
+ * @return
+ *   Zero on success, non-zero error code otherwise.
+ */
+int __rte_experimental
+rte_table_action_time_read(struct rte_table_action *action,
+       void *data,
+       uint64_t *timestamp);
+
+/**
+ * Table action cryptodev symmetric session get.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @param[in] data
+ *   Data byte array (typically table rule data) with sym crypto action.
+ * @return
+ *   The pointer to the session on success, NULL otherwise.
+ */
+struct rte_cryptodev_sym_session *__rte_experimental
+rte_table_action_crypto_sym_session_get(struct rte_table_action *action,
+       void *data);
+
 #ifdef __cplusplus
 }
 #endif