[2/6] test/crypto: enable larger packet sizes with TLS

Message ID 20240822071651.2403105-3-anoobj@marvell.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers
Series Fixes and improvements in crypto unit tests |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Anoob Joseph Aug. 22, 2024, 7:16 a.m. UTC
Enable larger packet sizes with TLS. Add wrapper for existing
create_segmented_mbuf() function to get allocations from both pools.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
 app/test/test_cryptodev.c                     | 13 +++++--
 app/test/test_cryptodev.h                     | 38 +++++++++++++++++++
 app/test/test_cryptodev_security_tls_record.h | 12 +++---
 app/test/test_security_proto.h                |  7 +++-
 4 files changed, 58 insertions(+), 12 deletions(-)
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 9d8ca8f616..5444d82c50 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -12139,12 +12139,13 @@  test_tls_record_proto_process(const struct tls_record_test_data td[],
 		}
 
 		/* Setup source mbuf payload */
-		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len,
-				nb_segs, 0);
+		ut_params->ibuf = create_segmented_mbuf_multi_pool(ts_params->mbuf_pool,
+				ts_params->large_mbuf_pool, td[i].input_text.len, nb_segs, 0);
 		pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, td[i].input_text.data);
 		if (flags->out_of_place)
-			ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
-					td[i].output_text.len, nb_segs, 0);
+			ut_params->obuf = create_segmented_mbuf_multi_pool(ts_params->mbuf_pool,
+					ts_params->large_mbuf_pool, td[i].output_text.len, nb_segs,
+					0);
 		else
 			ut_params->obuf = NULL;
 
@@ -12375,6 +12376,10 @@  test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		pass_cnt++;
 	}
 
+	if (flags->data_walkthrough)
+		printf("\t Min payload size: %d, Max payload size: %d\n",
+				TLS_RECORD_PLAINTEXT_MIN_LEN, max_payload_len);
+
 	if (pass_cnt > 0)
 		return TEST_SUCCESS;
 	else
diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h
index af56145cdd..c322f10b94 100644
--- a/app/test/test_cryptodev.h
+++ b/app/test/test_cryptodev.h
@@ -233,6 +233,44 @@  create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
 	return NULL;
 }
 
+static inline struct rte_mbuf *
+create_segmented_mbuf_multi_pool(struct rte_mempool *mbuf_pool_small,
+		struct rte_mempool *mbuf_pool_large, int pkt_len, int nb_segs, uint8_t pattern)
+{
+	struct rte_mempool *mbuf_pool;
+	int max_seg_len, seg_len;
+
+	if (nb_segs < 1) {
+		printf("Number of segments must be 1 or more (is %d)\n", nb_segs);
+		return NULL;
+	}
+
+	if (pkt_len >= nb_segs)
+		seg_len = pkt_len / nb_segs;
+	else
+		seg_len = 1;
+
+	/* Determine max segment length */
+	max_seg_len = seg_len + pkt_len % nb_segs;
+
+	if (max_seg_len > LARGE_MBUF_DATAPAYLOAD_SIZE) {
+		printf("Segment size %d is too big\n", max_seg_len);
+		return NULL;
+	}
+
+	if (max_seg_len > MBUF_DATAPAYLOAD_SIZE)
+		mbuf_pool = mbuf_pool_large;
+	else
+		mbuf_pool = mbuf_pool_small;
+
+	if (mbuf_pool == NULL) {
+		printf("Invalid mbuf pool\n");
+		return NULL;
+	}
+
+	return create_segmented_mbuf(mbuf_pool, pkt_len, nb_segs, pattern);
+}
+
 int
 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
diff --git a/app/test/test_cryptodev_security_tls_record.h b/app/test/test_cryptodev_security_tls_record.h
index e4a291c153..a98cea24f6 100644
--- a/app/test/test_cryptodev_security_tls_record.h
+++ b/app/test/test_cryptodev_security_tls_record.h
@@ -11,32 +11,32 @@ 
 #include "test_security_proto.h"
 
 /* TLS 1.2 Ciphertext length can be up to (2^14 + 2048 + 5 (TLS Header)) Bytes */
-#define TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN  (4096u)
+#define TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN  (18437u)
 static_assert(TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
 /* TLS 1.2 Plaintext length can be up to (2^14 + 1024) Bytes */
-#define TLS_1_2_RECORD_PLAINTEXT_MAX_LEN   (3072u)
+#define TLS_1_2_RECORD_PLAINTEXT_MAX_LEN   (17408u)
 static_assert(TLS_1_2_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
 /* DTLS 1.2 Ciphertext length is similar to TLS 1.2 */
-#define DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (4096u)
+#define DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (18437u)
 static_assert(DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
 /* DTLS 1.2 Plaintext length is similar to TLS 1.2 */
-#define DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN  (3072u)
+#define DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN  (17408u)
 static_assert(DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
 /* TLS 1.3 Ciphertext length can be up to (2^14 + 256 + 5 (TLS Header)) Bytes */
-#define TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN  (4096u)
+#define TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN  (16645u)
 static_assert(TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN <= TEST_SEC_CIPHERTEXT_MAX_LEN,
 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
 /* TLS 1.3 Plaintext length can be up to 2^14 Bytes */
-#define TLS_1_3_RECORD_PLAINTEXT_MAX_LEN   (3072u)
+#define TLS_1_3_RECORD_PLAINTEXT_MAX_LEN   (16384u)
 static_assert(TLS_1_3_RECORD_PLAINTEXT_MAX_LEN <= TEST_SEC_CLEARTEXT_MAX_LEN,
 	      "TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!");
 
diff --git a/app/test/test_security_proto.h b/app/test/test_security_proto.h
index 7eb815604a..8acb0fecca 100644
--- a/app/test/test_security_proto.h
+++ b/app/test/test_security_proto.h
@@ -10,10 +10,13 @@ 
 
 #include "test_cryptodev.h"
 
-#define TEST_SEC_CLEARTEXT_MAX_LEN  (MBUF_DATAPAYLOAD_SIZE - 1024)
-#define TEST_SEC_CIPHERTEXT_MAX_LEN (MBUF_DATAPAYLOAD_SIZE)
+#define TEST_SEC_CLEARTEXT_MAX_LEN  17408u
+#define TEST_SEC_CIPHERTEXT_MAX_LEN 18437u
 #define TEST_SEC_PKTS_MAX 32
 
+static_assert(TEST_SEC_CIPHERTEXT_MAX_LEN <= LARGE_MBUF_DATAPAYLOAD_SIZE,
+	      "TEST_SEC_CIPHERTEXT_MAX_LEN should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
+
 struct crypto_param {
 	enum rte_crypto_sym_xform_type type;
 	union {