[v4,2/2] app/testpmd: add random item support

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

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Michael Baum Dec. 14, 2023, 10:58 a.m. UTC
  Add support for random item, usage example:

	pattern random spec value 0x1 mask value 0x3 / eth / end

Flow rule with above pattern matching 25% of the traffic, it hits only
when random value suffix is "01" and miss the others ("00", "10", "11").

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Reviewed-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 28 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 +++
 2 files changed, 32 insertions(+)
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index ce71818705..359c187b3c 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -433,6 +433,8 @@  enum index {
 	ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
 	ITEM_META,
 	ITEM_META_DATA,
+	ITEM_RANDOM,
+	ITEM_RANDOM_VALUE,
 	ITEM_GRE_KEY,
 	ITEM_GRE_KEY_VALUE,
 	ITEM_GRE_OPTION,
@@ -956,6 +958,7 @@  static const char *const modify_field_ids[] = {
 	"hash_result",
 	"geneve_opt_type", "geneve_opt_class", "geneve_opt_data", "mpls",
 	"tcp_data_off", "ipv4_ihl", "ipv4_total_len", "ipv6_payload_len",
+	"random",
 	NULL
 };
 
@@ -1562,6 +1565,7 @@  static const enum index next_item[] = {
 	ITEM_ICMP6_ND_OPT_SLA_ETH,
 	ITEM_ICMP6_ND_OPT_TLA_ETH,
 	ITEM_META,
+	ITEM_RANDOM,
 	ITEM_GRE_KEY,
 	ITEM_GRE_OPTION,
 	ITEM_GTP_PSC,
@@ -1873,6 +1877,12 @@  static const enum index item_meta[] = {
 	ZERO,
 };
 
+static const enum index item_random[] = {
+	ITEM_RANDOM_VALUE,
+	ITEM_NEXT,
+	ZERO,
+};
+
 static const enum index item_gtp_psc[] = {
 	ITEM_GTP_PSC_QFI,
 	ITEM_GTP_PSC_PDU_T,
@@ -5195,6 +5205,21 @@  static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
 					     data, "\xff\xff\xff\xff")),
 	},
+	[ITEM_RANDOM] = {
+		.name = "random",
+		.help = "match random value",
+		.priv = PRIV_ITEM(RANDOM, sizeof(struct rte_flow_item_random)),
+		.next = NEXT(item_random),
+		.call = parse_vc,
+	},
+	[ITEM_RANDOM_VALUE] = {
+		.name = "value",
+		.help = "random value",
+		.next = NEXT(item_random, NEXT_ENTRY(COMMON_UNSIGNED),
+			     item_param),
+		.args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_random,
+					     value, "\xff\xff")),
+	},
 	[ITEM_GRE_KEY] = {
 		.name = "gre_key",
 		.help = "match GRE key",
@@ -12883,6 +12908,9 @@  flow_item_default_mask(const struct rte_flow_item *item)
 	case RTE_FLOW_ITEM_TYPE_META:
 		mask = &rte_flow_item_meta_mask;
 		break;
+	case RTE_FLOW_ITEM_TYPE_RANDOM:
+		mask = &rte_flow_item_random_mask;
+		break;
 	case RTE_FLOW_ITEM_TYPE_FUZZY:
 		mask = &rte_flow_item_fuzzy_mask;
 		break;
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 447e28e694..0cd1615d9e 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3756,6 +3756,10 @@  This section lists supported pattern items and their attributes, if any.
 
   - ``data {unsigned}``: metadata value.
 
+- ``random``: match application specific random value.
+
+  - ``value {unsigned}``: random value.
+
 - ``gtp_psc``: match GTP PDU extension header with type 0x85.
 
   - ``pdu_type {unsigned}``: PDU type.