From patchwork Wed Oct 19 16:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejasree Kondoj X-Patchwork-Id: 118645 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A1D44A09E7; Wed, 19 Oct 2022 18:55:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 06FDC42C4A; Wed, 19 Oct 2022 18:54:41 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 111B742C46 for ; Wed, 19 Oct 2022 18:54:39 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29J8AYPD009500; Wed, 19 Oct 2022 09:54:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=Bi4smQ8zaxo+pacCeFbvmmFvDJb0pniNjrD0o9F757o=; b=kNj55IFCHonCAUfV6ra/sfOWDxvSg+2E3b8APTd2tf2HUvabfAguJFGR/3LuuGLW26Aw d/Fa/U2NujeuzOXmtFjF2Xkn9nwqcO5Oym2k+TiYc2uquS9f7dCavHStqALnEqV9GmXZ D8fKPuIPC/7AoA92pLRuVvVkEEDm+eS8yUP8ORrAkGdqGhq21DZuyNF/NArOSMQrojua 9y/OBbZU4l3YM43n8vvEn+qnaFNNPL0RPqmw8AobbZDJEF1ayHvXS5+xYbOZLJVAWlml Te/wf+8KoWf3iKuKYP5Fove+j+DbOxPxtIXR/Mzd1XbrpmCMYV/NTYl+yMAAITLYthZR 0Q== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3kadg5a7c9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 09:54:39 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 19 Oct 2022 09:54:37 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 19 Oct 2022 09:54:37 -0700 Received: from hyd1554.marvell.com (unknown [10.29.57.11]) by maili.marvell.com (Postfix) with ESMTP id 823003F7097; Wed, 19 Oct 2022 09:54:35 -0700 (PDT) From: Tejasree Kondoj To: Akhil Goyal , Fan Zhang , Ciara Power CC: Vidya Sagar Velumuri , Anoob Joseph , Subject: [PATCH 6/6] test/crypto: add unit test for custom UDP ports Date: Wed, 19 Oct 2022 22:24:18 +0530 Message-ID: <20221019165418.1970445-7-ktejasree@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019165418.1970445-1-ktejasree@marvell.com> References: <20221019165418.1970445-1-ktejasree@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: Gytl-6vWcXVyE-7M0aR88K4TiB5-ozyi X-Proofpoint-ORIG-GUID: Gytl-6vWcXVyE-7M0aR88K4TiB5-ozyi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-19_09,2022-10-19_04,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Vidya Sagar Velumuri 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 Signed-off-by: Vidya Sagar Velumuri --- 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;