[v1,1/2] ethdev: add random item support

Message ID 20230822090505.3242455-2-michaelba@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: add random item support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Aug. 22, 2023, 9:05 a.m. UTC
  Add support for a new item type "RTE_FLOW_ITEM_TYPE_RANDOM".
This item enables to match on some random value as a part of flow rule.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 doc/guides/nics/features/default.ini   |  1 +
 doc/guides/prog_guide/rte_flow.rst     | 11 +++++++++
 doc/guides/rel_notes/release_23_11.rst |  4 ++++
 lib/ethdev/rte_flow.c                  |  1 +
 lib/ethdev/rte_flow.h                  | 33 ++++++++++++++++++++++++++
 5 files changed, 50 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/default.ini b/doc/guides/nics/features/default.ini
index 2011e97127..0a790dafe8 100644
--- a/doc/guides/nics/features/default.ini
+++ b/doc/guides/nics/features/default.ini
@@ -139,6 +139,7 @@  pppoes               =
 pppoe_proto_id       =
 quota                =
 raw                  =
+random               =
 represented_port     =
 sctp                 =
 tag                  =
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 5bc998a433..5ad699dff7 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1566,6 +1566,17 @@  Matches an InfiniBand base transport header in RoCE packet.
 
 - ``hdr``: InfiniBand base transport header definition (``rte_ib.h``).
 
+Item: ``RANDOM``
+^^^^^^^^^^^^^^^^
+
+Matches a random value.
+
+This value is not based on the packet data/headers.
+Application shouldn't assume that this value is kept during the life time of
+the packet.
+
+- ``value``: Random value.
+
 Actions
 ~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst
index 4411bb32c1..1e90bf83e7 100644
--- a/doc/guides/rel_notes/release_23_11.rst
+++ b/doc/guides/rel_notes/release_23_11.rst
@@ -72,6 +72,10 @@  New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added flow matching of Infiniband BTH.**
+
+  Added ``RTE_FLOW_ITEM_RANDOM`` to match random value.
+
 
 Removed Items
 -------------
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 271d854f78..51db3e5aec 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -136,6 +136,7 @@  static const struct rte_flow_desc_data rte_flow_desc_item[] = {
 		     sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
 	MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
 	MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)),
+	MK_FLOW_ITEM(RANDOM, sizeof(struct rte_flow_item_random)),
 	MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
 	MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)),
 	MK_FLOW_ITEM(GRE_OPTION, sizeof(struct rte_flow_item_gre_opt)),
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 2ebb76dbc0..b5228b293c 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -688,6 +688,19 @@  enum rte_flow_item_type {
 	 * @see struct rte_flow_item_ib_bth.
 	 */
 	RTE_FLOW_ITEM_TYPE_IB_BTH,
+
+	/**
+	 * [META]
+	 *
+	 * Matches a random value.
+	 *
+	 * This value is not based on the packet data/headers.
+	 * Application shouldn't assume that this value is kept during the life
+	 * time of the packet.
+	 *
+	 * @see struct rte_flow_item_random.
+	 */
+	RTE_FLOW_ITEM_TYPE_RANDOM,
 };
 
 /**
@@ -2031,6 +2044,25 @@  static const struct rte_flow_item_ib_bth rte_flow_item_ib_bth_mask = {
 };
 #endif
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ITEM_TYPE_RANDOM
+ *
+ * Matches a random value.
+ */
+struct rte_flow_item_random {
+	uint32_t value;
+};
+
+/** Default mask for RTE_FLOW_ITEM_TYPE_RANDOM. */
+#ifndef __cplusplus
+static const struct rte_flow_item_random rte_flow_item_random_mask = {
+	.value = UINT32_MAX,
+};
+#endif
+
 /**
  * Matching pattern item definition.
  *
@@ -3875,6 +3907,7 @@  enum rte_flow_field_id {
 	RTE_FLOW_FIELD_GENEVE_OPT_CLASS,/**< GENEVE option class. */
 	RTE_FLOW_FIELD_GENEVE_OPT_DATA,	/**< GENEVE option data. */
 	RTE_FLOW_FIELD_MPLS,		/**< MPLS header. */
+	RTE_FLOW_FIELD_RANDOM		/**< Random value. */
 };
 
 /**