DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tejasree Kondoj <ktejasree@marvell.com>
To: Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <royzhang1980@gmail.com>,
	Ciara Power <ciara.power@intel.com>
Cc: Vidya Sagar Velumuri <vvelumuri@marvell.com>,
	Anoob Joseph <anoobj@marvell.com>, <dev@dpdk.org>
Subject: [PATCH v2 6/6] test/crypto: add unit test for custom UDP ports
Date: Fri, 21 Oct 2022 12:56:51 +0530	[thread overview]
Message-ID: <20221021072651.1985340-7-ktejasree@marvell.com> (raw)
In-Reply-To: <20221021072651.1985340-1-ktejasree@marvell.com>

From: Vidya Sagar Velumuri <vvelumuri@marvell.com>

Add unit test for custom UDP ports with UDP encapsulation.
Verify UDP header in egress path for all unit tests.

Signed-off-by: Tejasree Kondoj <ktejasree@marvell.com>
Signed-off-by: Vidya Sagar Velumuri <vvelumuri@marvell.com>
---
 app/test/test_cryptodev.c                | 21 +++++++
 app/test/test_cryptodev_security_ipsec.c | 71 ++++++++++++++++++------
 app/test/test_cryptodev_security_ipsec.h |  1 +
 3 files changed, 76 insertions(+), 17 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 96941dd55c..43fcef7e73 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -9892,6 +9892,23 @@ test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
 	return test_ipsec_proto_all(&flags);
 }
 
+static int
+test_ipsec_proto_udp_encap_custom_ports(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	if (gbl_driver_id == rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_CN10K_PMD)))
+		return TEST_SKIPPED;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+	flags.udp_encap_custom_ports = true;
+
+	return test_ipsec_proto_all(&flags);
+}
+
 static int
 test_ipsec_proto_udp_encap(const void *data __rte_unused)
 {
@@ -15358,6 +15375,10 @@ static struct unit_test_suite ipsec_proto_testsuite  = {
 			"UDP encapsulation",
 			ut_setup_security, ut_teardown,
 			test_ipsec_proto_udp_encap),
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation with custom ports",
+			ut_setup_security, ut_teardown,
+			test_ipsec_proto_udp_encap_custom_ports),
 		TEST_CASE_NAMED_ST(
 			"UDP encapsulation ports verification test",
 			ut_setup_security, ut_teardown,
diff --git a/app/test/test_cryptodev_security_ipsec.c b/app/test/test_cryptodev_security_ipsec.c
index 3219b41e39..d64e07f226 100644
--- a/app/test/test_cryptodev_security_ipsec.c
+++ b/app/test/test_cryptodev_security_ipsec.c
@@ -14,6 +14,8 @@
 #include "test_cryptodev_security_ipsec.h"
 
 #define IV_LEN_MAX 16
+#define UDP_CUSTOM_SPORT 4650
+#define UDP_CUSTOM_DPORT 4660
 
 #ifndef IPVERSION
 #define IPVERSION 4
@@ -508,6 +510,11 @@ test_ipsec_td_prepare(const struct crypto_param *param1,
 
 		if (flags->dec_ttl_or_hop_limit)
 			td->ipsec_xform.options.dec_ttl = 1;
+
+		if (flags->udp_encap && flags->udp_encap_custom_ports) {
+			td->ipsec_xform.udp.sport = UDP_CUSTOM_SPORT;
+			td->ipsec_xform.udp.dport = UDP_CUSTOM_DPORT;
+		}
 	}
 }
 
@@ -765,23 +772,6 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td,
 
 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
 	   flags->udp_encap) {
-		const struct rte_ipv4_hdr *iph4;
-		const struct rte_ipv6_hdr *iph6;
-
-		if (td->ipsec_xform.tunnel.type ==
-				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
-			iph4 = (const struct rte_ipv4_hdr *)output_text;
-			if (iph4->next_proto_id != IPPROTO_UDP) {
-				printf("UDP header is not found\n");
-				return TEST_FAILED;
-			}
-		} else {
-			iph6 = (const struct rte_ipv6_hdr *)output_text;
-			if (iph6->proto != IPPROTO_UDP) {
-				printf("UDP header is not found\n");
-				return TEST_FAILED;
-			}
-		}
 
 		len -= sizeof(struct rte_udp_hdr);
 		output_text += sizeof(struct rte_udp_hdr);
@@ -1043,6 +1033,53 @@ test_ipsec_post_process(struct rte_mbuf *m, const struct ipsec_test_data *td,
 		}
 	}
 
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
+	   flags->udp_encap) {
+		const struct rte_ipv4_hdr *iph4;
+		const struct rte_ipv6_hdr *iph6;
+
+		if (td->ipsec_xform.tunnel.type ==
+				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
+			iph4 = (const struct rte_ipv4_hdr *)output_text;
+
+			if (iph4->next_proto_id != IPPROTO_UDP) {
+				printf("UDP header is not found\n");
+				return TEST_FAILED;
+			}
+
+			if (flags->udp_encap_custom_ports) {
+				const struct rte_udp_hdr *udph;
+
+				udph = (const struct rte_udp_hdr *)(output_text +
+					sizeof(struct rte_ipv4_hdr));
+				if ((rte_be_to_cpu_16(udph->src_port) != UDP_CUSTOM_SPORT) ||
+				    (rte_be_to_cpu_16(udph->dst_port) != UDP_CUSTOM_DPORT)) {
+					printf("UDP custom ports not matching.\n");
+					return TEST_FAILED;
+				}
+			}
+		} else {
+			iph6 = (const struct rte_ipv6_hdr *)output_text;
+
+			if (iph6->proto != IPPROTO_UDP) {
+				printf("UDP header is not found\n");
+				return TEST_FAILED;
+			}
+
+			if (flags->udp_encap_custom_ports) {
+				const struct rte_udp_hdr *udph;
+
+				udph = (const struct rte_udp_hdr *)(output_text +
+					sizeof(struct rte_ipv6_hdr));
+				if ((rte_be_to_cpu_16(udph->src_port) != UDP_CUSTOM_SPORT) ||
+				    (rte_be_to_cpu_16(udph->dst_port) != UDP_CUSTOM_DPORT)) {
+					printf("UDP custom ports not matching.\n");
+					return TEST_FAILED;
+				}
+			}
+		}
+	}
+
 	/*
 	 * In case of known vector tests & all inbound tests, res_d provided
 	 * would be NULL and output data need to be validated against expected.
diff --git a/app/test/test_cryptodev_security_ipsec.h b/app/test/test_cryptodev_security_ipsec.h
index b98f4741b2..008b17c290 100644
--- a/app/test/test_cryptodev_security_ipsec.h
+++ b/app/test/test_cryptodev_security_ipsec.h
@@ -93,6 +93,7 @@ struct ipsec_test_flags {
 	uint32_t tunnel_hdr_verify;
 	bool udp_encap;
 	bool udp_ports_verify;
+	bool udp_encap_custom_ports;
 	bool ip_csum;
 	bool l4_csum;
 	bool ipv6;
-- 
2.25.1


  parent reply	other threads:[~2022-10-21  7:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21  7:26 [PATCH v2 0/6] update autotest with new algorithms Tejasree Kondoj
2022-10-21  7:26 ` [PATCH v2 1/6] test/security: add unit tests for DES and 3DES Tejasree Kondoj
2022-10-21  7:26 ` [PATCH v2 2/6] test/security: add unit tests for auth algo MD5 Tejasree Kondoj
2022-10-21  7:26 ` [PATCH v2 3/6] test/security: update antireplay unit test for event mode Tejasree Kondoj
2022-10-21  7:26 ` [PATCH v2 4/6] test/crypto: check antireply capability only for ingress Tejasree Kondoj
2022-10-21  7:26 ` [PATCH v2 5/6] test/crypto: add unit tests for DES and MD5 Tejasree Kondoj
2022-10-21  7:26 ` Tejasree Kondoj [this message]
2022-10-21 15:00 ` [PATCH v2 0/6] update autotest with new algorithms Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221021072651.1985340-7-ktejasree@marvell.com \
    --to=ktejasree@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=royzhang1980@gmail.com \
    --cc=vvelumuri@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).