From: Vidya Sagar Velumuri <vvelum...@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 <ktejas...@marvell.com>
Signed-off-by: Vidya Sagar Velumuri <vvelum...@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

Reply via email to