xref: /dpdk/app/test/test_ipsec.c (revision 3feaf4127ccc9abe7fa04d66de7afb59e5b78ddc)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2018 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5a9de470cSBruce Richardson #include <time.h>
6a9de470cSBruce Richardson 
7a9de470cSBruce Richardson #include <rte_common.h>
8a9de470cSBruce Richardson #include <rte_hexdump.h>
9a9de470cSBruce Richardson #include <rte_mbuf.h>
10a9de470cSBruce Richardson #include <rte_malloc.h>
11a9de470cSBruce Richardson #include <rte_memcpy.h>
122cb4a0d4SBernard Iremonger #include <rte_cycles.h>
13a9de470cSBruce Richardson #include <rte_bus_vdev.h>
14a9de470cSBruce Richardson #include <rte_ip.h>
15a9de470cSBruce Richardson 
16a9de470cSBruce Richardson #include <rte_crypto.h>
17a9de470cSBruce Richardson #include <rte_cryptodev.h>
18a9de470cSBruce Richardson #include <rte_cryptodev_pmd.h>
19a9de470cSBruce Richardson #include <rte_lcore.h>
20a9de470cSBruce Richardson #include <rte_ipsec.h>
21a9de470cSBruce Richardson #include <rte_random.h>
22a9de470cSBruce Richardson #include <rte_esp.h>
23a9de470cSBruce Richardson #include <rte_security_driver.h>
24a9de470cSBruce Richardson 
25a9de470cSBruce Richardson #include "test.h"
26a9de470cSBruce Richardson #include "test_cryptodev.h"
27a9de470cSBruce Richardson 
28a9de470cSBruce Richardson #define VDEV_ARGS_SIZE	100
29fd42108eSBernard Iremonger #define MAX_NB_SESSIONS	200
30a9de470cSBruce Richardson #define MAX_NB_SAS		2
31a9de470cSBruce Richardson #define REPLAY_WIN_0	0
32a9de470cSBruce Richardson #define REPLAY_WIN_32	32
33a9de470cSBruce Richardson #define REPLAY_WIN_64	64
34a9de470cSBruce Richardson #define REPLAY_WIN_128	128
35a9de470cSBruce Richardson #define REPLAY_WIN_256	256
36a9de470cSBruce Richardson #define DATA_64_BYTES	64
37a9de470cSBruce Richardson #define DATA_80_BYTES	80
38a9de470cSBruce Richardson #define DATA_100_BYTES	100
39a9de470cSBruce Richardson #define ESN_ENABLED		1
40a9de470cSBruce Richardson #define ESN_DISABLED	0
41a9de470cSBruce Richardson #define INBOUND_SPI		7
42a9de470cSBruce Richardson #define OUTBOUND_SPI	17
43a9de470cSBruce Richardson #define BURST_SIZE		32
44a9de470cSBruce Richardson #define REORDER_PKTS	1
452cb4a0d4SBernard Iremonger #define DEQUEUE_COUNT	1000
46a9de470cSBruce Richardson 
47a9de470cSBruce Richardson struct user_params {
48a9de470cSBruce Richardson 	enum rte_crypto_sym_xform_type auth;
49a9de470cSBruce Richardson 	enum rte_crypto_sym_xform_type cipher;
50a9de470cSBruce Richardson 	enum rte_crypto_sym_xform_type aead;
51a9de470cSBruce Richardson 
52a9de470cSBruce Richardson 	char auth_algo[128];
53a9de470cSBruce Richardson 	char cipher_algo[128];
54a9de470cSBruce Richardson 	char aead_algo[128];
55a9de470cSBruce Richardson };
56a9de470cSBruce Richardson 
57a9de470cSBruce Richardson struct ipsec_testsuite_params {
58a9de470cSBruce Richardson 	struct rte_mempool *mbuf_pool;
59a9de470cSBruce Richardson 	struct rte_mempool *cop_mpool;
60a9de470cSBruce Richardson 	struct rte_cryptodev_config conf;
61a9de470cSBruce Richardson 	struct rte_cryptodev_qp_conf qp_conf;
62a9de470cSBruce Richardson 
63a9de470cSBruce Richardson 	uint8_t valid_dev;
64a9de470cSBruce Richardson 	uint8_t valid_dev_found;
65a9de470cSBruce Richardson };
66a9de470cSBruce Richardson 
67a9de470cSBruce Richardson struct ipsec_unitest_params {
68a9de470cSBruce Richardson 	struct rte_crypto_sym_xform cipher_xform;
69a9de470cSBruce Richardson 	struct rte_crypto_sym_xform auth_xform;
70a9de470cSBruce Richardson 	struct rte_crypto_sym_xform aead_xform;
71a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *crypto_xforms;
72a9de470cSBruce Richardson 
73a9de470cSBruce Richardson 	struct rte_security_ipsec_xform ipsec_xform;
74a9de470cSBruce Richardson 
75a9de470cSBruce Richardson 	struct rte_ipsec_sa_prm sa_prm;
76a9de470cSBruce Richardson 	struct rte_ipsec_session ss[MAX_NB_SAS];
77a9de470cSBruce Richardson 
78a9de470cSBruce Richardson 	struct rte_crypto_op *cop[BURST_SIZE];
79a9de470cSBruce Richardson 
80a9de470cSBruce Richardson 	struct rte_mbuf *obuf[BURST_SIZE], *ibuf[BURST_SIZE],
81a9de470cSBruce Richardson 		*testbuf[BURST_SIZE];
82a9de470cSBruce Richardson 
83a9de470cSBruce Richardson 	uint16_t pkt_index;
84a9de470cSBruce Richardson };
85a9de470cSBruce Richardson 
86a9de470cSBruce Richardson struct ipsec_test_cfg {
87a9de470cSBruce Richardson 	uint32_t replay_win_sz;
88a9de470cSBruce Richardson 	uint32_t esn;
89a9de470cSBruce Richardson 	uint64_t flags;
90a9de470cSBruce Richardson 	size_t pkt_sz;
91a9de470cSBruce Richardson 	uint16_t num_pkts;
92a9de470cSBruce Richardson 	uint32_t reorder_pkts;
93a9de470cSBruce Richardson };
94a9de470cSBruce Richardson 
95a9de470cSBruce Richardson static const struct ipsec_test_cfg test_cfg[] = {
96a9de470cSBruce Richardson 	{REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, 1, 0},
97fd42108eSBernard Iremonger 	{REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, BURST_SIZE, 0},
98a9de470cSBruce Richardson 	{REPLAY_WIN_0, ESN_DISABLED, 0, DATA_80_BYTES, BURST_SIZE,
99a9de470cSBruce Richardson 		REORDER_PKTS},
100a9de470cSBruce Richardson 	{REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, 1, 0},
101a9de470cSBruce Richardson 	{REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, BURST_SIZE,
102a9de470cSBruce Richardson 		REORDER_PKTS},
103a9de470cSBruce Richardson 	{REPLAY_WIN_64, ESN_ENABLED, 0, DATA_64_BYTES, 1, 0},
104a9de470cSBruce Richardson 	{REPLAY_WIN_128, ESN_ENABLED, RTE_IPSEC_SAFLAG_SQN_ATOM,
105a9de470cSBruce Richardson 		DATA_80_BYTES, 1, 0},
106a9de470cSBruce Richardson 	{REPLAY_WIN_256, ESN_DISABLED, 0, DATA_100_BYTES, 1, 0},
107a9de470cSBruce Richardson };
108a9de470cSBruce Richardson 
109a9de470cSBruce Richardson static const int num_cfg = RTE_DIM(test_cfg);
110a9de470cSBruce Richardson static struct ipsec_testsuite_params testsuite_params = { NULL };
111a9de470cSBruce Richardson static struct ipsec_unitest_params unittest_params;
112a9de470cSBruce Richardson static struct user_params uparams;
113a9de470cSBruce Richardson 
114a9de470cSBruce Richardson struct supported_cipher_algo {
115a9de470cSBruce Richardson 	const char *keyword;
116a9de470cSBruce Richardson 	enum rte_crypto_cipher_algorithm algo;
117a9de470cSBruce Richardson 	uint16_t iv_len;
118a9de470cSBruce Richardson 	uint16_t block_size;
119a9de470cSBruce Richardson 	uint16_t key_len;
120a9de470cSBruce Richardson };
121a9de470cSBruce Richardson 
122a9de470cSBruce Richardson struct supported_auth_algo {
123a9de470cSBruce Richardson 	const char *keyword;
124a9de470cSBruce Richardson 	enum rte_crypto_auth_algorithm algo;
125a9de470cSBruce Richardson 	uint16_t digest_len;
126a9de470cSBruce Richardson 	uint16_t key_len;
127a9de470cSBruce Richardson 	uint8_t key_not_req;
128a9de470cSBruce Richardson };
129a9de470cSBruce Richardson 
130a9de470cSBruce Richardson const struct supported_cipher_algo cipher_algos[] = {
131a9de470cSBruce Richardson 	{
132a9de470cSBruce Richardson 		.keyword = "null",
133a9de470cSBruce Richardson 		.algo = RTE_CRYPTO_CIPHER_NULL,
134a9de470cSBruce Richardson 		.iv_len = 0,
135a9de470cSBruce Richardson 		.block_size = 4,
136a9de470cSBruce Richardson 		.key_len = 0
137a9de470cSBruce Richardson 	},
138a9de470cSBruce Richardson };
139a9de470cSBruce Richardson 
140a9de470cSBruce Richardson const struct supported_auth_algo auth_algos[] = {
141a9de470cSBruce Richardson 	{
142a9de470cSBruce Richardson 		.keyword = "null",
143a9de470cSBruce Richardson 		.algo = RTE_CRYPTO_AUTH_NULL,
144a9de470cSBruce Richardson 		.digest_len = 0,
145a9de470cSBruce Richardson 		.key_len = 0,
146a9de470cSBruce Richardson 		.key_not_req = 1
147a9de470cSBruce Richardson 	},
148a9de470cSBruce Richardson };
149a9de470cSBruce Richardson 
150a9de470cSBruce Richardson static int
151a9de470cSBruce Richardson dummy_sec_create(void *device, struct rte_security_session_conf *conf,
152a9de470cSBruce Richardson 	struct rte_security_session *sess, struct rte_mempool *mp)
153a9de470cSBruce Richardson {
154a9de470cSBruce Richardson 	RTE_SET_USED(device);
155a9de470cSBruce Richardson 	RTE_SET_USED(conf);
156a9de470cSBruce Richardson 	RTE_SET_USED(mp);
157a9de470cSBruce Richardson 
158a9de470cSBruce Richardson 	sess->sess_private_data = NULL;
159a9de470cSBruce Richardson 	return 0;
160a9de470cSBruce Richardson }
161a9de470cSBruce Richardson 
162a9de470cSBruce Richardson static int
163a9de470cSBruce Richardson dummy_sec_destroy(void *device, struct rte_security_session *sess)
164a9de470cSBruce Richardson {
165a9de470cSBruce Richardson 	RTE_SET_USED(device);
166a9de470cSBruce Richardson 	RTE_SET_USED(sess);
167a9de470cSBruce Richardson 	return 0;
168a9de470cSBruce Richardson }
169a9de470cSBruce Richardson 
170a9de470cSBruce Richardson static const struct rte_security_ops dummy_sec_ops = {
171a9de470cSBruce Richardson 	.session_create = dummy_sec_create,
172a9de470cSBruce Richardson 	.session_destroy = dummy_sec_destroy,
173a9de470cSBruce Richardson };
174a9de470cSBruce Richardson 
175a9de470cSBruce Richardson static struct rte_security_ctx dummy_sec_ctx = {
176a9de470cSBruce Richardson 	.ops = &dummy_sec_ops,
177a9de470cSBruce Richardson };
178a9de470cSBruce Richardson 
179a9de470cSBruce Richardson static const struct supported_cipher_algo *
180a9de470cSBruce Richardson find_match_cipher_algo(const char *cipher_keyword)
181a9de470cSBruce Richardson {
182a9de470cSBruce Richardson 	size_t i;
183a9de470cSBruce Richardson 
184a9de470cSBruce Richardson 	for (i = 0; i < RTE_DIM(cipher_algos); i++) {
185a9de470cSBruce Richardson 		const struct supported_cipher_algo *algo =
186a9de470cSBruce Richardson 			&cipher_algos[i];
187a9de470cSBruce Richardson 
188a9de470cSBruce Richardson 		if (strcmp(cipher_keyword, algo->keyword) == 0)
189a9de470cSBruce Richardson 			return algo;
190a9de470cSBruce Richardson 	}
191a9de470cSBruce Richardson 
192a9de470cSBruce Richardson 	return NULL;
193a9de470cSBruce Richardson }
194a9de470cSBruce Richardson 
195a9de470cSBruce Richardson static const struct supported_auth_algo *
196a9de470cSBruce Richardson find_match_auth_algo(const char *auth_keyword)
197a9de470cSBruce Richardson {
198a9de470cSBruce Richardson 	size_t i;
199a9de470cSBruce Richardson 
200a9de470cSBruce Richardson 	for (i = 0; i < RTE_DIM(auth_algos); i++) {
201a9de470cSBruce Richardson 		const struct supported_auth_algo *algo =
202a9de470cSBruce Richardson 			&auth_algos[i];
203a9de470cSBruce Richardson 
204a9de470cSBruce Richardson 		if (strcmp(auth_keyword, algo->keyword) == 0)
205a9de470cSBruce Richardson 			return algo;
206a9de470cSBruce Richardson 	}
207a9de470cSBruce Richardson 
208a9de470cSBruce Richardson 	return NULL;
209a9de470cSBruce Richardson }
210a9de470cSBruce Richardson 
211a9de470cSBruce Richardson static void
212a9de470cSBruce Richardson fill_crypto_xform(struct ipsec_unitest_params *ut_params,
213a9de470cSBruce Richardson 	const struct supported_auth_algo *auth_algo,
214a9de470cSBruce Richardson 	const struct supported_cipher_algo *cipher_algo)
215a9de470cSBruce Richardson {
216a9de470cSBruce Richardson 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
217a9de470cSBruce Richardson 	ut_params->cipher_xform.cipher.algo = cipher_algo->algo;
21863774c02SBernard Iremonger 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
21963774c02SBernard Iremonger 	ut_params->auth_xform.auth.algo = auth_algo->algo;
220a9de470cSBruce Richardson 
221a9de470cSBruce Richardson 	if (ut_params->ipsec_xform.direction ==
222a9de470cSBruce Richardson 			RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
22363774c02SBernard Iremonger 		ut_params->cipher_xform.cipher.op =
22463774c02SBernard Iremonger 			RTE_CRYPTO_CIPHER_OP_DECRYPT;
22563774c02SBernard Iremonger 		ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
226a9de470cSBruce Richardson 		ut_params->cipher_xform.next = NULL;
22763774c02SBernard Iremonger 		ut_params->auth_xform.next = &ut_params->cipher_xform;
22863774c02SBernard Iremonger 		ut_params->crypto_xforms = &ut_params->auth_xform;
229a9de470cSBruce Richardson 	} else {
23063774c02SBernard Iremonger 		ut_params->cipher_xform.cipher.op =
23163774c02SBernard Iremonger 			RTE_CRYPTO_CIPHER_OP_ENCRYPT;
23263774c02SBernard Iremonger 		ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
233a9de470cSBruce Richardson 		ut_params->auth_xform.next = NULL;
23463774c02SBernard Iremonger 		ut_params->cipher_xform.next = &ut_params->auth_xform;
23563774c02SBernard Iremonger 		ut_params->crypto_xforms = &ut_params->cipher_xform;
236a9de470cSBruce Richardson 	}
237a9de470cSBruce Richardson }
238a9de470cSBruce Richardson 
239a9de470cSBruce Richardson static int
240a9de470cSBruce Richardson check_cryptodev_capablity(const struct ipsec_unitest_params *ut,
241a9de470cSBruce Richardson 		uint8_t dev_id)
242a9de470cSBruce Richardson {
243a9de470cSBruce Richardson 	struct rte_cryptodev_sym_capability_idx cap_idx;
244a9de470cSBruce Richardson 	const struct rte_cryptodev_symmetric_capability *cap;
245a9de470cSBruce Richardson 	int rc = -1;
246a9de470cSBruce Richardson 
247a9de470cSBruce Richardson 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
248a9de470cSBruce Richardson 	cap_idx.algo.auth = ut->auth_xform.auth.algo;
249a9de470cSBruce Richardson 	cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
250a9de470cSBruce Richardson 
251a9de470cSBruce Richardson 	if (cap != NULL) {
252a9de470cSBruce Richardson 		rc = rte_cryptodev_sym_capability_check_auth(cap,
253a9de470cSBruce Richardson 				ut->auth_xform.auth.key.length,
254a9de470cSBruce Richardson 				ut->auth_xform.auth.digest_length, 0);
255a9de470cSBruce Richardson 		if (rc == 0) {
256a9de470cSBruce Richardson 			cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
257a9de470cSBruce Richardson 			cap_idx.algo.cipher = ut->cipher_xform.cipher.algo;
258a9de470cSBruce Richardson 			cap = rte_cryptodev_sym_capability_get(
259a9de470cSBruce Richardson 					dev_id, &cap_idx);
260a9de470cSBruce Richardson 			if (cap != NULL)
261a9de470cSBruce Richardson 				rc = rte_cryptodev_sym_capability_check_cipher(
262a9de470cSBruce Richardson 					cap,
263a9de470cSBruce Richardson 					ut->cipher_xform.cipher.key.length,
264a9de470cSBruce Richardson 					ut->cipher_xform.cipher.iv.length);
265a9de470cSBruce Richardson 		}
266a9de470cSBruce Richardson 	}
267a9de470cSBruce Richardson 
268a9de470cSBruce Richardson 	return rc;
269a9de470cSBruce Richardson }
270a9de470cSBruce Richardson 
271a9de470cSBruce Richardson static int
272a9de470cSBruce Richardson testsuite_setup(void)
273a9de470cSBruce Richardson {
274a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
275a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
276a9de470cSBruce Richardson 	const struct supported_auth_algo *auth_algo;
277a9de470cSBruce Richardson 	const struct supported_cipher_algo *cipher_algo;
278a9de470cSBruce Richardson 	struct rte_cryptodev_info info;
279a9de470cSBruce Richardson 	uint32_t i, nb_devs, dev_id;
280a9de470cSBruce Richardson 	size_t sess_sz;
281a9de470cSBruce Richardson 	int rc;
282a9de470cSBruce Richardson 
283a9de470cSBruce Richardson 	memset(ts_params, 0, sizeof(*ts_params));
28463774c02SBernard Iremonger 	memset(ut_params, 0, sizeof(*ut_params));
28563774c02SBernard Iremonger 	memset(&uparams, 0, sizeof(struct user_params));
286a9de470cSBruce Richardson 
287a9de470cSBruce Richardson 	uparams.auth = RTE_CRYPTO_SYM_XFORM_AUTH;
288a9de470cSBruce Richardson 	uparams.cipher = RTE_CRYPTO_SYM_XFORM_CIPHER;
28963774c02SBernard Iremonger 	uparams.aead = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
290a9de470cSBruce Richardson 	strcpy(uparams.auth_algo, "null");
291a9de470cSBruce Richardson 	strcpy(uparams.cipher_algo, "null");
292a9de470cSBruce Richardson 
293a9de470cSBruce Richardson 	auth_algo = find_match_auth_algo(uparams.auth_algo);
294a9de470cSBruce Richardson 	cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
295a9de470cSBruce Richardson 	fill_crypto_xform(ut_params, auth_algo, cipher_algo);
296a9de470cSBruce Richardson 
297a9de470cSBruce Richardson 	nb_devs = rte_cryptodev_count();
298a9de470cSBruce Richardson 	if (nb_devs < 1) {
299e0f4a0edSDavid Marchand 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
300e0f4a0edSDavid Marchand 		return TEST_SKIPPED;
301a9de470cSBruce Richardson 	}
302a9de470cSBruce Richardson 
303a9de470cSBruce Richardson 	/* Find first valid crypto device */
304a9de470cSBruce Richardson 	for (i = 0; i < nb_devs; i++) {
305a9de470cSBruce Richardson 		rc = check_cryptodev_capablity(ut_params, i);
306a9de470cSBruce Richardson 		if (rc == 0) {
307a9de470cSBruce Richardson 			ts_params->valid_dev = i;
308a9de470cSBruce Richardson 			ts_params->valid_dev_found = 1;
309a9de470cSBruce Richardson 			break;
310a9de470cSBruce Richardson 		}
311a9de470cSBruce Richardson 	}
312a9de470cSBruce Richardson 
313a9de470cSBruce Richardson 	if (ts_params->valid_dev_found == 0)
314a9de470cSBruce Richardson 		return TEST_FAILED;
315a9de470cSBruce Richardson 
316a9de470cSBruce Richardson 	ts_params->mbuf_pool = rte_pktmbuf_pool_create(
317a9de470cSBruce Richardson 			"CRYPTO_MBUFPOOL",
318a9de470cSBruce Richardson 			NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
319a9de470cSBruce Richardson 			rte_socket_id());
320a9de470cSBruce Richardson 	if (ts_params->mbuf_pool == NULL) {
321a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
322a9de470cSBruce Richardson 		return TEST_FAILED;
323a9de470cSBruce Richardson 	}
324a9de470cSBruce Richardson 
325a9de470cSBruce Richardson 	ts_params->cop_mpool = rte_crypto_op_pool_create(
326a9de470cSBruce Richardson 			"MBUF_CRYPTO_SYM_OP_POOL",
327a9de470cSBruce Richardson 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
328a9de470cSBruce Richardson 			NUM_MBUFS, MBUF_CACHE_SIZE,
329a9de470cSBruce Richardson 			DEFAULT_NUM_XFORMS *
330a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform) +
331a9de470cSBruce Richardson 			MAXIMUM_IV_LENGTH,
332a9de470cSBruce Richardson 			rte_socket_id());
333a9de470cSBruce Richardson 	if (ts_params->cop_mpool == NULL) {
334a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
335a9de470cSBruce Richardson 		return TEST_FAILED;
336a9de470cSBruce Richardson 	}
337a9de470cSBruce Richardson 
338a9de470cSBruce Richardson 	/* Set up all the qps on the first of the valid devices found */
339a9de470cSBruce Richardson 	dev_id = ts_params->valid_dev;
340a9de470cSBruce Richardson 
341a9de470cSBruce Richardson 	rte_cryptodev_info_get(dev_id, &info);
342a9de470cSBruce Richardson 
343a9de470cSBruce Richardson 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
344a9de470cSBruce Richardson 	ts_params->conf.socket_id = SOCKET_ID_ANY;
345c9030ae3SAnoob Joseph 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
346a9de470cSBruce Richardson 
347a9de470cSBruce Richardson 	sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id);
348a9de470cSBruce Richardson 	sess_sz = RTE_MAX(sess_sz, sizeof(struct rte_security_session));
349a9de470cSBruce Richardson 
350a9de470cSBruce Richardson 	/*
351a9de470cSBruce Richardson 	 * Create mempools for sessions
352a9de470cSBruce Richardson 	 */
353a9de470cSBruce Richardson 	if (info.sym.max_nb_sessions != 0 &&
354a9de470cSBruce Richardson 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
355a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "Device does not support "
356a9de470cSBruce Richardson 				"at least %u sessions\n",
357a9de470cSBruce Richardson 				MAX_NB_SESSIONS);
358a9de470cSBruce Richardson 		return TEST_FAILED;
359a9de470cSBruce Richardson 	}
360a9de470cSBruce Richardson 
361a9de470cSBruce Richardson 	ts_params->qp_conf.mp_session_private = rte_mempool_create(
362a9de470cSBruce Richardson 				"test_priv_sess_mp",
363a9de470cSBruce Richardson 				MAX_NB_SESSIONS,
364a9de470cSBruce Richardson 				sess_sz,
365a9de470cSBruce Richardson 				0, 0, NULL, NULL, NULL,
366a9de470cSBruce Richardson 				NULL, SOCKET_ID_ANY,
367a9de470cSBruce Richardson 				0);
368a9de470cSBruce Richardson 
369a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session_private,
370a9de470cSBruce Richardson 			"private session mempool allocation failed");
371a9de470cSBruce Richardson 
372a9de470cSBruce Richardson 	ts_params->qp_conf.mp_session =
373a9de470cSBruce Richardson 		rte_cryptodev_sym_session_pool_create("test_sess_mp",
374a9de470cSBruce Richardson 			MAX_NB_SESSIONS, 0, 0, 0, SOCKET_ID_ANY);
375a9de470cSBruce Richardson 
376a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session,
377a9de470cSBruce Richardson 			"session mempool allocation failed");
378a9de470cSBruce Richardson 
379a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
380a9de470cSBruce Richardson 			&ts_params->conf),
381a9de470cSBruce Richardson 			"Failed to configure cryptodev %u with %u qps",
382a9de470cSBruce Richardson 			dev_id, ts_params->conf.nb_queue_pairs);
383a9de470cSBruce Richardson 
384a9de470cSBruce Richardson 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
385a9de470cSBruce Richardson 
386a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
387a9de470cSBruce Richardson 		dev_id, 0, &ts_params->qp_conf,
388a9de470cSBruce Richardson 		rte_cryptodev_socket_id(dev_id)),
389a9de470cSBruce Richardson 		"Failed to setup queue pair %u on cryptodev %u",
390a9de470cSBruce Richardson 		0, dev_id);
391a9de470cSBruce Richardson 
392a9de470cSBruce Richardson 	return TEST_SUCCESS;
393a9de470cSBruce Richardson }
394a9de470cSBruce Richardson 
395a9de470cSBruce Richardson static void
396a9de470cSBruce Richardson testsuite_teardown(void)
397a9de470cSBruce Richardson {
398a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
399a9de470cSBruce Richardson 
400a9de470cSBruce Richardson 	if (ts_params->mbuf_pool != NULL) {
401a9de470cSBruce Richardson 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
402a9de470cSBruce Richardson 		rte_mempool_avail_count(ts_params->mbuf_pool));
403a9de470cSBruce Richardson 		rte_mempool_free(ts_params->mbuf_pool);
404a9de470cSBruce Richardson 		ts_params->mbuf_pool = NULL;
405a9de470cSBruce Richardson 	}
406a9de470cSBruce Richardson 
407a9de470cSBruce Richardson 	if (ts_params->cop_mpool != NULL) {
408a9de470cSBruce Richardson 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
409a9de470cSBruce Richardson 		rte_mempool_avail_count(ts_params->cop_mpool));
410a9de470cSBruce Richardson 		rte_mempool_free(ts_params->cop_mpool);
411a9de470cSBruce Richardson 		ts_params->cop_mpool = NULL;
412a9de470cSBruce Richardson 	}
413a9de470cSBruce Richardson 
414a9de470cSBruce Richardson 	/* Free session mempools */
415a9de470cSBruce Richardson 	if (ts_params->qp_conf.mp_session != NULL) {
416a9de470cSBruce Richardson 		rte_mempool_free(ts_params->qp_conf.mp_session);
417a9de470cSBruce Richardson 		ts_params->qp_conf.mp_session = NULL;
418a9de470cSBruce Richardson 	}
419a9de470cSBruce Richardson 
420a9de470cSBruce Richardson 	if (ts_params->qp_conf.mp_session_private != NULL) {
421a9de470cSBruce Richardson 		rte_mempool_free(ts_params->qp_conf.mp_session_private);
422a9de470cSBruce Richardson 		ts_params->qp_conf.mp_session_private = NULL;
423a9de470cSBruce Richardson 	}
424a9de470cSBruce Richardson }
425a9de470cSBruce Richardson 
426a9de470cSBruce Richardson static int
427a9de470cSBruce Richardson ut_setup(void)
428a9de470cSBruce Richardson {
429a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
430a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
431a9de470cSBruce Richardson 
432a9de470cSBruce Richardson 	/* Clear unit test parameters before running test */
433a9de470cSBruce Richardson 	memset(ut_params, 0, sizeof(*ut_params));
434a9de470cSBruce Richardson 
435a9de470cSBruce Richardson 	/* Reconfigure device to default parameters */
436a9de470cSBruce Richardson 	ts_params->conf.socket_id = SOCKET_ID_ANY;
437a9de470cSBruce Richardson 
438a9de470cSBruce Richardson 	/* Start the device */
439a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_dev),
440a9de470cSBruce Richardson 			"Failed to start cryptodev %u",
441a9de470cSBruce Richardson 			ts_params->valid_dev);
442a9de470cSBruce Richardson 
443a9de470cSBruce Richardson 	return TEST_SUCCESS;
444a9de470cSBruce Richardson }
445a9de470cSBruce Richardson 
446a9de470cSBruce Richardson static void
447a9de470cSBruce Richardson ut_teardown(void)
448a9de470cSBruce Richardson {
449a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
450a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
451a9de470cSBruce Richardson 	int i;
452a9de470cSBruce Richardson 
453a9de470cSBruce Richardson 	for (i = 0; i < BURST_SIZE; i++) {
454a9de470cSBruce Richardson 		/* free crypto operation structure */
455a9de470cSBruce Richardson 		if (ut_params->cop[i])
456a9de470cSBruce Richardson 			rte_crypto_op_free(ut_params->cop[i]);
457a9de470cSBruce Richardson 
458a9de470cSBruce Richardson 		/*
459a9de470cSBruce Richardson 		 * free mbuf - both obuf and ibuf are usually the same,
460a9de470cSBruce Richardson 		 * so check if they point at the same address is necessary,
461a9de470cSBruce Richardson 		 * to avoid freeing the mbuf twice.
462a9de470cSBruce Richardson 		 */
463a9de470cSBruce Richardson 		if (ut_params->obuf[i]) {
464a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->obuf[i]);
465a9de470cSBruce Richardson 			if (ut_params->ibuf[i] == ut_params->obuf[i])
466a9de470cSBruce Richardson 				ut_params->ibuf[i] = 0;
467a9de470cSBruce Richardson 			ut_params->obuf[i] = 0;
468a9de470cSBruce Richardson 		}
469a9de470cSBruce Richardson 		if (ut_params->ibuf[i]) {
470a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->ibuf[i]);
471a9de470cSBruce Richardson 			ut_params->ibuf[i] = 0;
472a9de470cSBruce Richardson 		}
473a9de470cSBruce Richardson 
474a9de470cSBruce Richardson 		if (ut_params->testbuf[i]) {
475a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->testbuf[i]);
476a9de470cSBruce Richardson 			ut_params->testbuf[i] = 0;
477a9de470cSBruce Richardson 		}
478a9de470cSBruce Richardson 	}
479a9de470cSBruce Richardson 
480a9de470cSBruce Richardson 	if (ts_params->mbuf_pool != NULL)
481a9de470cSBruce Richardson 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
482a9de470cSBruce Richardson 			rte_mempool_avail_count(ts_params->mbuf_pool));
483a9de470cSBruce Richardson 
484a9de470cSBruce Richardson 	/* Stop the device */
485a9de470cSBruce Richardson 	rte_cryptodev_stop(ts_params->valid_dev);
486a9de470cSBruce Richardson }
487a9de470cSBruce Richardson 
488a9de470cSBruce Richardson #define IPSEC_MAX_PAD_SIZE	UINT8_MAX
489a9de470cSBruce Richardson 
490a9de470cSBruce Richardson static const uint8_t esp_pad_bytes[IPSEC_MAX_PAD_SIZE] = {
491a9de470cSBruce Richardson 	1, 2, 3, 4, 5, 6, 7, 8,
492a9de470cSBruce Richardson 	9, 10, 11, 12, 13, 14, 15, 16,
493a9de470cSBruce Richardson 	17, 18, 19, 20, 21, 22, 23, 24,
494a9de470cSBruce Richardson 	25, 26, 27, 28, 29, 30, 31, 32,
495a9de470cSBruce Richardson 	33, 34, 35, 36, 37, 38, 39, 40,
496a9de470cSBruce Richardson 	41, 42, 43, 44, 45, 46, 47, 48,
497a9de470cSBruce Richardson 	49, 50, 51, 52, 53, 54, 55, 56,
498a9de470cSBruce Richardson 	57, 58, 59, 60, 61, 62, 63, 64,
499a9de470cSBruce Richardson 	65, 66, 67, 68, 69, 70, 71, 72,
500a9de470cSBruce Richardson 	73, 74, 75, 76, 77, 78, 79, 80,
501a9de470cSBruce Richardson 	81, 82, 83, 84, 85, 86, 87, 88,
502a9de470cSBruce Richardson 	89, 90, 91, 92, 93, 94, 95, 96,
503a9de470cSBruce Richardson 	97, 98, 99, 100, 101, 102, 103, 104,
504a9de470cSBruce Richardson 	105, 106, 107, 108, 109, 110, 111, 112,
505a9de470cSBruce Richardson 	113, 114, 115, 116, 117, 118, 119, 120,
506a9de470cSBruce Richardson 	121, 122, 123, 124, 125, 126, 127, 128,
507a9de470cSBruce Richardson 	129, 130, 131, 132, 133, 134, 135, 136,
508a9de470cSBruce Richardson 	137, 138, 139, 140, 141, 142, 143, 144,
509a9de470cSBruce Richardson 	145, 146, 147, 148, 149, 150, 151, 152,
510a9de470cSBruce Richardson 	153, 154, 155, 156, 157, 158, 159, 160,
511a9de470cSBruce Richardson 	161, 162, 163, 164, 165, 166, 167, 168,
512a9de470cSBruce Richardson 	169, 170, 171, 172, 173, 174, 175, 176,
513a9de470cSBruce Richardson 	177, 178, 179, 180, 181, 182, 183, 184,
514a9de470cSBruce Richardson 	185, 186, 187, 188, 189, 190, 191, 192,
515a9de470cSBruce Richardson 	193, 194, 195, 196, 197, 198, 199, 200,
516a9de470cSBruce Richardson 	201, 202, 203, 204, 205, 206, 207, 208,
517a9de470cSBruce Richardson 	209, 210, 211, 212, 213, 214, 215, 216,
518a9de470cSBruce Richardson 	217, 218, 219, 220, 221, 222, 223, 224,
519a9de470cSBruce Richardson 	225, 226, 227, 228, 229, 230, 231, 232,
520a9de470cSBruce Richardson 	233, 234, 235, 236, 237, 238, 239, 240,
521a9de470cSBruce Richardson 	241, 242, 243, 244, 245, 246, 247, 248,
522a9de470cSBruce Richardson 	249, 250, 251, 252, 253, 254, 255,
523a9de470cSBruce Richardson };
524a9de470cSBruce Richardson 
525a9de470cSBruce Richardson /* ***** data for tests ***** */
526a9de470cSBruce Richardson 
527a9de470cSBruce Richardson const char null_plain_data[] =
528a9de470cSBruce Richardson 	"Network Security People Have A Strange Sense Of Humor unlike Other "
529a9de470cSBruce Richardson 	"People who have a normal sense of humour";
530a9de470cSBruce Richardson 
531a9de470cSBruce Richardson const char null_encrypted_data[] =
532a9de470cSBruce Richardson 	"Network Security People Have A Strange Sense Of Humor unlike Other "
533a9de470cSBruce Richardson 	"People who have a normal sense of humour";
534a9de470cSBruce Richardson 
535a7c528e5SOlivier Matz struct rte_ipv4_hdr ipv4_outer  = {
536a9de470cSBruce Richardson 	.version_ihl = IPVERSION << 4 |
53724ac604eSOlivier Matz 		sizeof(ipv4_outer) / RTE_IPV4_IHL_MULTIPLIER,
538a9de470cSBruce Richardson 	.time_to_live = IPDEFTTL,
539a9de470cSBruce Richardson 	.next_proto_id = IPPROTO_ESP,
5400c9da755SDavid Marchand 	.src_addr = RTE_IPV4(192, 168, 1, 100),
5410c9da755SDavid Marchand 	.dst_addr = RTE_IPV4(192, 168, 2, 100),
542a9de470cSBruce Richardson };
543a9de470cSBruce Richardson 
544a9de470cSBruce Richardson static struct rte_mbuf *
545a9de470cSBruce Richardson setup_test_string(struct rte_mempool *mpool,
546a9de470cSBruce Richardson 		const char *string, size_t len, uint8_t blocksize)
547a9de470cSBruce Richardson {
548a9de470cSBruce Richardson 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
549a9de470cSBruce Richardson 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
550a9de470cSBruce Richardson 
551a9de470cSBruce Richardson 	if (m) {
552a9de470cSBruce Richardson 		memset(m->buf_addr, 0, m->buf_len);
553a9de470cSBruce Richardson 		char *dst = rte_pktmbuf_append(m, t_len);
554a9de470cSBruce Richardson 
555a9de470cSBruce Richardson 		if (!dst) {
556a9de470cSBruce Richardson 			rte_pktmbuf_free(m);
557a9de470cSBruce Richardson 			return NULL;
558a9de470cSBruce Richardson 		}
559a9de470cSBruce Richardson 		if (string != NULL)
560a9de470cSBruce Richardson 			rte_memcpy(dst, string, t_len);
561a9de470cSBruce Richardson 		else
562a9de470cSBruce Richardson 			memset(dst, 0, t_len);
563a9de470cSBruce Richardson 	}
564a9de470cSBruce Richardson 
565a9de470cSBruce Richardson 	return m;
566a9de470cSBruce Richardson }
567a9de470cSBruce Richardson 
568a9de470cSBruce Richardson static struct rte_mbuf *
569a9de470cSBruce Richardson setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
570a9de470cSBruce Richardson 	size_t len, uint32_t spi, uint32_t seq)
571a9de470cSBruce Richardson {
572a9de470cSBruce Richardson 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
573a7c528e5SOlivier Matz 	uint32_t hdrlen = sizeof(struct rte_ipv4_hdr) +
574a7c528e5SOlivier Matz 		sizeof(struct rte_esp_hdr);
575a9de470cSBruce Richardson 	uint32_t taillen = sizeof(struct esp_tail);
576a9de470cSBruce Richardson 	uint32_t t_len = len + hdrlen + taillen;
577a9de470cSBruce Richardson 	uint32_t padlen;
578a9de470cSBruce Richardson 
5795ef25467SOlivier Matz 	struct rte_esp_hdr esph  = {
580a9de470cSBruce Richardson 		.spi = rte_cpu_to_be_32(spi),
581a9de470cSBruce Richardson 		.seq = rte_cpu_to_be_32(seq)
582a9de470cSBruce Richardson 	};
583a9de470cSBruce Richardson 
584a9de470cSBruce Richardson 	padlen = RTE_ALIGN(t_len, 4) - t_len;
585a9de470cSBruce Richardson 	t_len += padlen;
586a9de470cSBruce Richardson 
587a9de470cSBruce Richardson 	struct esp_tail espt  = {
588a9de470cSBruce Richardson 		.pad_len = padlen,
589a9de470cSBruce Richardson 		.next_proto = IPPROTO_IPIP,
590a9de470cSBruce Richardson 	};
591a9de470cSBruce Richardson 
592a9de470cSBruce Richardson 	if (m == NULL)
593a9de470cSBruce Richardson 		return NULL;
594a9de470cSBruce Richardson 
595a9de470cSBruce Richardson 	memset(m->buf_addr, 0, m->buf_len);
596a9de470cSBruce Richardson 	char *dst = rte_pktmbuf_append(m, t_len);
597a9de470cSBruce Richardson 
598a9de470cSBruce Richardson 	if (!dst) {
599a9de470cSBruce Richardson 		rte_pktmbuf_free(m);
600a9de470cSBruce Richardson 		return NULL;
601a9de470cSBruce Richardson 	}
602a9de470cSBruce Richardson 	/* copy outer IP and ESP header */
603a9de470cSBruce Richardson 	ipv4_outer.total_length = rte_cpu_to_be_16(t_len);
604a9de470cSBruce Richardson 	ipv4_outer.packet_id = rte_cpu_to_be_16(seq);
605a9de470cSBruce Richardson 	rte_memcpy(dst, &ipv4_outer, sizeof(ipv4_outer));
606a9de470cSBruce Richardson 	dst += sizeof(ipv4_outer);
607a9de470cSBruce Richardson 	m->l3_len = sizeof(ipv4_outer);
608a9de470cSBruce Richardson 	rte_memcpy(dst, &esph, sizeof(esph));
609a9de470cSBruce Richardson 	dst += sizeof(esph);
610a9de470cSBruce Richardson 
611a9de470cSBruce Richardson 	if (string != NULL) {
612a9de470cSBruce Richardson 		/* copy payload */
613a9de470cSBruce Richardson 		rte_memcpy(dst, string, len);
614a9de470cSBruce Richardson 		dst += len;
615a9de470cSBruce Richardson 		/* copy pad bytes */
616a9de470cSBruce Richardson 		rte_memcpy(dst, esp_pad_bytes, padlen);
617a9de470cSBruce Richardson 		dst += padlen;
618a9de470cSBruce Richardson 		/* copy ESP tail header */
619a9de470cSBruce Richardson 		rte_memcpy(dst, &espt, sizeof(espt));
620a9de470cSBruce Richardson 	} else
621a9de470cSBruce Richardson 		memset(dst, 0, t_len);
622a9de470cSBruce Richardson 
623a9de470cSBruce Richardson 	return m;
624a9de470cSBruce Richardson }
625a9de470cSBruce Richardson 
626a9de470cSBruce Richardson static int
627a9de470cSBruce Richardson create_dummy_sec_session(struct ipsec_unitest_params *ut,
628a9de470cSBruce Richardson 	struct rte_cryptodev_qp_conf *qp, uint32_t j)
629a9de470cSBruce Richardson {
630a9de470cSBruce Richardson 	static struct rte_security_session_conf conf;
631a9de470cSBruce Richardson 
632a9de470cSBruce Richardson 	ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
633a9de470cSBruce Richardson 					&conf, qp->mp_session_private);
634a9de470cSBruce Richardson 
635a9de470cSBruce Richardson 	if (ut->ss[j].security.ses == NULL)
636a9de470cSBruce Richardson 		return -ENOMEM;
637a9de470cSBruce Richardson 
638a9de470cSBruce Richardson 	ut->ss[j].security.ctx = &dummy_sec_ctx;
639a9de470cSBruce Richardson 	ut->ss[j].security.ol_flags = 0;
640a9de470cSBruce Richardson 	return 0;
641a9de470cSBruce Richardson }
642a9de470cSBruce Richardson 
643a9de470cSBruce Richardson static int
644a9de470cSBruce Richardson create_crypto_session(struct ipsec_unitest_params *ut,
645a9de470cSBruce Richardson 	struct rte_cryptodev_qp_conf *qp, uint8_t dev_id, uint32_t j)
646a9de470cSBruce Richardson {
647a9de470cSBruce Richardson 	int32_t rc;
648a9de470cSBruce Richardson 	struct rte_cryptodev_sym_session *s;
649a9de470cSBruce Richardson 
650a9de470cSBruce Richardson 	s = rte_cryptodev_sym_session_create(qp->mp_session);
651a9de470cSBruce Richardson 	if (s == NULL)
652a9de470cSBruce Richardson 		return -ENOMEM;
653a9de470cSBruce Richardson 
654a9de470cSBruce Richardson 	/* initiliaze SA crypto session for device */
655a9de470cSBruce Richardson 	rc = rte_cryptodev_sym_session_init(dev_id, s,
656a9de470cSBruce Richardson 			ut->crypto_xforms, qp->mp_session_private);
657a9de470cSBruce Richardson 	if (rc == 0) {
658a9de470cSBruce Richardson 		ut->ss[j].crypto.ses = s;
659a9de470cSBruce Richardson 		return 0;
660a9de470cSBruce Richardson 	} else {
661a9de470cSBruce Richardson 		/* failure, do cleanup */
662a9de470cSBruce Richardson 		rte_cryptodev_sym_session_clear(dev_id, s);
663a9de470cSBruce Richardson 		rte_cryptodev_sym_session_free(s);
664a9de470cSBruce Richardson 		return rc;
665a9de470cSBruce Richardson 	}
666a9de470cSBruce Richardson }
667a9de470cSBruce Richardson 
668a9de470cSBruce Richardson static int
669a9de470cSBruce Richardson create_session(struct ipsec_unitest_params *ut,
670a9de470cSBruce Richardson 	struct rte_cryptodev_qp_conf *qp, uint8_t crypto_dev, uint32_t j)
671a9de470cSBruce Richardson {
672a9de470cSBruce Richardson 	if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
673a9de470cSBruce Richardson 		return create_crypto_session(ut, qp, crypto_dev, j);
674a9de470cSBruce Richardson 	else
675a9de470cSBruce Richardson 		return create_dummy_sec_session(ut, qp, j);
676a9de470cSBruce Richardson }
677a9de470cSBruce Richardson 
678a9de470cSBruce Richardson static int
679a9de470cSBruce Richardson fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags)
680a9de470cSBruce Richardson {
681a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
682a9de470cSBruce Richardson 	struct rte_ipsec_sa_prm *prm = &ut_params->sa_prm;
683a9de470cSBruce Richardson 	const struct supported_auth_algo *auth_algo;
684a9de470cSBruce Richardson 	const struct supported_cipher_algo *cipher_algo;
685a9de470cSBruce Richardson 
686a9de470cSBruce Richardson 	memset(prm, 0, sizeof(*prm));
687a9de470cSBruce Richardson 
688a9de470cSBruce Richardson 	prm->userdata = 1;
689a9de470cSBruce Richardson 	prm->flags = flags;
690a9de470cSBruce Richardson 	prm->replay_win_sz = replay_win_sz;
691a9de470cSBruce Richardson 
692a9de470cSBruce Richardson 	/* setup ipsec xform */
693a9de470cSBruce Richardson 	prm->ipsec_xform = ut_params->ipsec_xform;
694a9de470cSBruce Richardson 	prm->ipsec_xform.salt = (uint32_t)rte_rand();
695a9de470cSBruce Richardson 
696a9de470cSBruce Richardson 	/* setup tunnel related fields */
697a9de470cSBruce Richardson 	prm->tun.hdr_len = sizeof(ipv4_outer);
698a9de470cSBruce Richardson 	prm->tun.next_proto = IPPROTO_IPIP;
699a9de470cSBruce Richardson 	prm->tun.hdr = &ipv4_outer;
700a9de470cSBruce Richardson 
701a9de470cSBruce Richardson 	/* setup crypto section */
702a9de470cSBruce Richardson 	if (uparams.aead != 0) {
703a9de470cSBruce Richardson 		/* TODO: will need to fill out with other test cases */
704a9de470cSBruce Richardson 	} else {
705a9de470cSBruce Richardson 		if (uparams.auth == 0 && uparams.cipher == 0)
706a9de470cSBruce Richardson 			return TEST_FAILED;
707a9de470cSBruce Richardson 
708a9de470cSBruce Richardson 		auth_algo = find_match_auth_algo(uparams.auth_algo);
709a9de470cSBruce Richardson 		cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
710a9de470cSBruce Richardson 
711a9de470cSBruce Richardson 		fill_crypto_xform(ut_params, auth_algo, cipher_algo);
712a9de470cSBruce Richardson 	}
713a9de470cSBruce Richardson 
714a9de470cSBruce Richardson 	prm->crypto_xform = ut_params->crypto_xforms;
715a9de470cSBruce Richardson 	return TEST_SUCCESS;
716a9de470cSBruce Richardson }
717a9de470cSBruce Richardson 
718a9de470cSBruce Richardson static int
719a9de470cSBruce Richardson create_sa(enum rte_security_session_action_type action_type,
720a9de470cSBruce Richardson 		uint32_t replay_win_sz, uint64_t flags, uint32_t j)
721a9de470cSBruce Richardson {
722a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts = &testsuite_params;
723a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut = &unittest_params;
724a9de470cSBruce Richardson 	size_t sz;
725a9de470cSBruce Richardson 	int rc;
726a9de470cSBruce Richardson 
727a9de470cSBruce Richardson 	memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
728a9de470cSBruce Richardson 
729a9de470cSBruce Richardson 	rc = fill_ipsec_param(replay_win_sz, flags);
730a9de470cSBruce Richardson 	if (rc != 0)
731a9de470cSBruce Richardson 		return TEST_FAILED;
732a9de470cSBruce Richardson 
733a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
734a9de470cSBruce Richardson 	sz = rte_ipsec_sa_size(&ut->sa_prm);
735a9de470cSBruce Richardson 	TEST_ASSERT(sz > 0, "rte_ipsec_sa_size() failed\n");
736a9de470cSBruce Richardson 
737a9de470cSBruce Richardson 	ut->ss[j].sa = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
738a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(ut->ss[j].sa,
739a9de470cSBruce Richardson 		"failed to allocate memory for rte_ipsec_sa\n");
740a9de470cSBruce Richardson 
741a9de470cSBruce Richardson 	ut->ss[j].type = action_type;
742a9de470cSBruce Richardson 	rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j);
743a9de470cSBruce Richardson 	if (rc != 0)
744a9de470cSBruce Richardson 		return TEST_FAILED;
745a9de470cSBruce Richardson 
746a9de470cSBruce Richardson 	rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz);
747a9de470cSBruce Richardson 	rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL;
748a9de470cSBruce Richardson 	if (rc == 0)
749a9de470cSBruce Richardson 		rc = rte_ipsec_session_prepare(&ut->ss[j]);
750a9de470cSBruce Richardson 
751a9de470cSBruce Richardson 	return rc;
752a9de470cSBruce Richardson }
753a9de470cSBruce Richardson 
754a9de470cSBruce Richardson static int
7552cb4a0d4SBernard Iremonger crypto_dequeue_burst(uint16_t num_pkts)
7562cb4a0d4SBernard Iremonger {
7572cb4a0d4SBernard Iremonger 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
7582cb4a0d4SBernard Iremonger 	struct ipsec_unitest_params *ut_params = &unittest_params;
7592cb4a0d4SBernard Iremonger 	uint32_t pkt_cnt, k;
7602cb4a0d4SBernard Iremonger 	int i;
7612cb4a0d4SBernard Iremonger 
7622cb4a0d4SBernard Iremonger 	for (i = 0, pkt_cnt = 0;
7632cb4a0d4SBernard Iremonger 		i < DEQUEUE_COUNT && pkt_cnt != num_pkts; i++) {
7642cb4a0d4SBernard Iremonger 		k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
7652cb4a0d4SBernard Iremonger 			&ut_params->cop[pkt_cnt], num_pkts - pkt_cnt);
7662cb4a0d4SBernard Iremonger 		pkt_cnt += k;
7672cb4a0d4SBernard Iremonger 		rte_delay_us(1);
7682cb4a0d4SBernard Iremonger 	}
7692cb4a0d4SBernard Iremonger 
7702cb4a0d4SBernard Iremonger 	if (pkt_cnt != num_pkts) {
7712cb4a0d4SBernard Iremonger 		RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
7722cb4a0d4SBernard Iremonger 		return TEST_FAILED;
7732cb4a0d4SBernard Iremonger 	}
7742cb4a0d4SBernard Iremonger 	return TEST_SUCCESS;
7752cb4a0d4SBernard Iremonger }
7762cb4a0d4SBernard Iremonger 
7772cb4a0d4SBernard Iremonger static int
778a9de470cSBruce Richardson crypto_ipsec(uint16_t num_pkts)
779a9de470cSBruce Richardson {
780a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
781a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
782a9de470cSBruce Richardson 	uint32_t k, ng;
783a9de470cSBruce Richardson 	struct rte_ipsec_group grp[1];
784a9de470cSBruce Richardson 
785a9de470cSBruce Richardson 	/* call crypto prepare */
786a9de470cSBruce Richardson 	k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
787a9de470cSBruce Richardson 		ut_params->cop, num_pkts);
788a9de470cSBruce Richardson 	if (k != num_pkts) {
789a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
790a9de470cSBruce Richardson 		return TEST_FAILED;
791a9de470cSBruce Richardson 	}
7922cb4a0d4SBernard Iremonger 
793a9de470cSBruce Richardson 	k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
794a9de470cSBruce Richardson 		ut_params->cop, num_pkts);
795a9de470cSBruce Richardson 	if (k != num_pkts) {
796a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_cryptodev_enqueue_burst fail\n");
797a9de470cSBruce Richardson 		return TEST_FAILED;
798a9de470cSBruce Richardson 	}
799a9de470cSBruce Richardson 
8002cb4a0d4SBernard Iremonger 	if (crypto_dequeue_burst(num_pkts) == TEST_FAILED)
801a9de470cSBruce Richardson 		return TEST_FAILED;
802a9de470cSBruce Richardson 
803a9de470cSBruce Richardson 	ng = rte_ipsec_pkt_crypto_group(
804a9de470cSBruce Richardson 		(const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
805a9de470cSBruce Richardson 		ut_params->obuf, grp, num_pkts);
806a9de470cSBruce Richardson 	if (ng != 1 ||
807a9de470cSBruce Richardson 		grp[0].m[0] != ut_params->obuf[0] ||
808a9de470cSBruce Richardson 		grp[0].cnt != num_pkts ||
809a9de470cSBruce Richardson 		grp[0].id.ptr != &ut_params->ss[0]) {
810a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
811a9de470cSBruce Richardson 		return TEST_FAILED;
812a9de470cSBruce Richardson 	}
813a9de470cSBruce Richardson 
814a9de470cSBruce Richardson 	/* call crypto process */
815a9de470cSBruce Richardson 	k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
816a9de470cSBruce Richardson 	if (k != num_pkts) {
817a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
818a9de470cSBruce Richardson 		return TEST_FAILED;
819a9de470cSBruce Richardson 	}
820a9de470cSBruce Richardson 
821a9de470cSBruce Richardson 	return TEST_SUCCESS;
822a9de470cSBruce Richardson }
823a9de470cSBruce Richardson 
824a9de470cSBruce Richardson static int
825a9de470cSBruce Richardson lksd_proto_ipsec(uint16_t num_pkts)
826a9de470cSBruce Richardson {
827a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
828a9de470cSBruce Richardson 	uint32_t i, k, ng;
829a9de470cSBruce Richardson 	struct rte_ipsec_group grp[1];
830a9de470cSBruce Richardson 
831a9de470cSBruce Richardson 	/* call crypto prepare */
832a9de470cSBruce Richardson 	k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
833a9de470cSBruce Richardson 		ut_params->cop, num_pkts);
834a9de470cSBruce Richardson 	if (k != num_pkts) {
835a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
836a9de470cSBruce Richardson 		return TEST_FAILED;
837a9de470cSBruce Richardson 	}
838a9de470cSBruce Richardson 
839a9de470cSBruce Richardson 	/* check crypto ops */
840a9de470cSBruce Richardson 	for (i = 0; i != num_pkts; i++) {
841a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->cop[i]->type,
842a9de470cSBruce Richardson 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
843a9de470cSBruce Richardson 			"%s: invalid crypto op type for %u-th packet\n",
844a9de470cSBruce Richardson 			__func__, i);
845a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->cop[i]->status,
846a9de470cSBruce Richardson 			RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
847a9de470cSBruce Richardson 			"%s: invalid crypto op status for %u-th packet\n",
848a9de470cSBruce Richardson 			__func__, i);
849a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->cop[i]->sess_type,
850a9de470cSBruce Richardson 			RTE_CRYPTO_OP_SECURITY_SESSION,
851a9de470cSBruce Richardson 			"%s: invalid crypto op sess_type for %u-th packet\n",
852a9de470cSBruce Richardson 			__func__, i);
853a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->cop[i]->sym->m_src,
854a9de470cSBruce Richardson 			ut_params->ibuf[i],
855a9de470cSBruce Richardson 			"%s: invalid crypto op m_src for %u-th packet\n",
856a9de470cSBruce Richardson 			__func__, i);
857a9de470cSBruce Richardson 	}
858a9de470cSBruce Richardson 
859a9de470cSBruce Richardson 	/* update crypto ops, pretend all finished ok */
860a9de470cSBruce Richardson 	for (i = 0; i != num_pkts; i++)
861a9de470cSBruce Richardson 		ut_params->cop[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
862a9de470cSBruce Richardson 
863a9de470cSBruce Richardson 	ng = rte_ipsec_pkt_crypto_group(
864a9de470cSBruce Richardson 		(const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
865a9de470cSBruce Richardson 		ut_params->obuf, grp, num_pkts);
866a9de470cSBruce Richardson 	if (ng != 1 ||
867a9de470cSBruce Richardson 		grp[0].m[0] != ut_params->obuf[0] ||
868a9de470cSBruce Richardson 		grp[0].cnt != num_pkts ||
869a9de470cSBruce Richardson 		grp[0].id.ptr != &ut_params->ss[0]) {
870a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
871a9de470cSBruce Richardson 		return TEST_FAILED;
872a9de470cSBruce Richardson 	}
873a9de470cSBruce Richardson 
874a9de470cSBruce Richardson 	/* call crypto process */
875a9de470cSBruce Richardson 	k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
876a9de470cSBruce Richardson 	if (k != num_pkts) {
877a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
878a9de470cSBruce Richardson 		return TEST_FAILED;
879a9de470cSBruce Richardson 	}
880a9de470cSBruce Richardson 
881a9de470cSBruce Richardson 	return TEST_SUCCESS;
882a9de470cSBruce Richardson }
883a9de470cSBruce Richardson 
884*3feaf412SBernard Iremonger static void
885*3feaf412SBernard Iremonger dump_grp_pkt(uint32_t i, struct rte_ipsec_group *grp, uint32_t k)
886*3feaf412SBernard Iremonger {
887*3feaf412SBernard Iremonger 	RTE_LOG(ERR, USER1,
888*3feaf412SBernard Iremonger 		"After rte_ipsec_pkt_process grp[%d].cnt=%d k=%d fail\n",
889*3feaf412SBernard Iremonger 		i, grp[i].cnt, k);
890*3feaf412SBernard Iremonger 	RTE_LOG(ERR, USER1,
891*3feaf412SBernard Iremonger 		"After rte_ipsec_pkt_process grp[%d].m=%p grp[%d].m[%d]=%p\n",
892*3feaf412SBernard Iremonger 		i, grp[i].m, i, k, grp[i].m[k]);
893*3feaf412SBernard Iremonger 
894*3feaf412SBernard Iremonger 	rte_pktmbuf_dump(stdout, grp[i].m[k], grp[i].m[k]->data_len);
895*3feaf412SBernard Iremonger }
896*3feaf412SBernard Iremonger 
897a9de470cSBruce Richardson static int
898a9de470cSBruce Richardson crypto_ipsec_2sa(void)
899a9de470cSBruce Richardson {
900a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
901a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
902a9de470cSBruce Richardson 	struct rte_ipsec_group grp[BURST_SIZE];
903a9de470cSBruce Richardson 	uint32_t k, ng, i, r;
904a9de470cSBruce Richardson 
905a9de470cSBruce Richardson 	for (i = 0; i < BURST_SIZE; i++) {
906a9de470cSBruce Richardson 		r = i % 2;
907a9de470cSBruce Richardson 		/* call crypto prepare */
908a9de470cSBruce Richardson 		k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
909a9de470cSBruce Richardson 				ut_params->ibuf + i, ut_params->cop + i, 1);
910a9de470cSBruce Richardson 		if (k != 1) {
911a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
912a9de470cSBruce Richardson 				"rte_ipsec_pkt_crypto_prepare fail\n");
913a9de470cSBruce Richardson 			return TEST_FAILED;
914a9de470cSBruce Richardson 		}
915a9de470cSBruce Richardson 		k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
916a9de470cSBruce Richardson 				ut_params->cop + i, 1);
917a9de470cSBruce Richardson 		if (k != 1) {
918a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
919a9de470cSBruce Richardson 				"rte_cryptodev_enqueue_burst fail\n");
920a9de470cSBruce Richardson 			return TEST_FAILED;
921a9de470cSBruce Richardson 		}
922a9de470cSBruce Richardson 	}
923a9de470cSBruce Richardson 
9242cb4a0d4SBernard Iremonger 	if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
925a9de470cSBruce Richardson 		return TEST_FAILED;
926a9de470cSBruce Richardson 
927a9de470cSBruce Richardson 	ng = rte_ipsec_pkt_crypto_group(
928a9de470cSBruce Richardson 		(const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
929a9de470cSBruce Richardson 		ut_params->obuf, grp, BURST_SIZE);
930a9de470cSBruce Richardson 	if (ng != BURST_SIZE) {
931a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
932a9de470cSBruce Richardson 			ng);
933a9de470cSBruce Richardson 		return TEST_FAILED;
934a9de470cSBruce Richardson 	}
935a9de470cSBruce Richardson 
936a9de470cSBruce Richardson 	/* call crypto process */
937a9de470cSBruce Richardson 	for (i = 0; i < ng; i++) {
938a9de470cSBruce Richardson 		k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
939a9de470cSBruce Richardson 		if (k != grp[i].cnt) {
940*3feaf412SBernard Iremonger 			dump_grp_pkt(i, grp, k);
941a9de470cSBruce Richardson 			return TEST_FAILED;
942a9de470cSBruce Richardson 		}
943a9de470cSBruce Richardson 	}
944a9de470cSBruce Richardson 	return TEST_SUCCESS;
945a9de470cSBruce Richardson }
946a9de470cSBruce Richardson 
947a9de470cSBruce Richardson #define PKT_4	4
948a9de470cSBruce Richardson #define PKT_12	12
949a9de470cSBruce Richardson #define PKT_21	21
950a9de470cSBruce Richardson 
951a9de470cSBruce Richardson static uint32_t
952a9de470cSBruce Richardson crypto_ipsec_4grp(uint32_t pkt_num)
953a9de470cSBruce Richardson {
954a9de470cSBruce Richardson 	uint32_t sa_ind;
955a9de470cSBruce Richardson 
956a9de470cSBruce Richardson 	/* group packets in 4 different size groups groups, 2 per SA */
957a9de470cSBruce Richardson 	if (pkt_num < PKT_4)
958a9de470cSBruce Richardson 		sa_ind = 0;
959a9de470cSBruce Richardson 	else if (pkt_num < PKT_12)
960a9de470cSBruce Richardson 		sa_ind = 1;
961a9de470cSBruce Richardson 	else if (pkt_num < PKT_21)
962a9de470cSBruce Richardson 		sa_ind = 0;
963a9de470cSBruce Richardson 	else
964a9de470cSBruce Richardson 		sa_ind = 1;
965a9de470cSBruce Richardson 
966a9de470cSBruce Richardson 	return sa_ind;
967a9de470cSBruce Richardson }
968a9de470cSBruce Richardson 
969a9de470cSBruce Richardson static uint32_t
970a9de470cSBruce Richardson crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
971a9de470cSBruce Richardson {
972a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
973a9de470cSBruce Richardson 	uint32_t i, j;
974a9de470cSBruce Richardson 	uint32_t rc = 0;
975a9de470cSBruce Richardson 
976a9de470cSBruce Richardson 	if (grp_ind == 0) {
977a9de470cSBruce Richardson 		for (i = 0, j = 0; i < PKT_4; i++, j++)
978a9de470cSBruce Richardson 			if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
979a9de470cSBruce Richardson 				rc = TEST_FAILED;
980a9de470cSBruce Richardson 				break;
981a9de470cSBruce Richardson 			}
982a9de470cSBruce Richardson 	} else if (grp_ind == 1) {
983a9de470cSBruce Richardson 		for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
984a9de470cSBruce Richardson 			if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
985a9de470cSBruce Richardson 				rc = TEST_FAILED;
986a9de470cSBruce Richardson 				break;
987a9de470cSBruce Richardson 			}
988a9de470cSBruce Richardson 		}
989a9de470cSBruce Richardson 	} else if (grp_ind == 2) {
990a9de470cSBruce Richardson 		for (i = 0, j =  PKT_12; i < (PKT_21 - PKT_12); i++, j++)
991a9de470cSBruce Richardson 			if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
992a9de470cSBruce Richardson 				rc = TEST_FAILED;
993a9de470cSBruce Richardson 				break;
994a9de470cSBruce Richardson 			}
995a9de470cSBruce Richardson 	} else if (grp_ind == 3) {
996a9de470cSBruce Richardson 		for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
997a9de470cSBruce Richardson 			if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
998a9de470cSBruce Richardson 				rc = TEST_FAILED;
999a9de470cSBruce Richardson 				break;
1000a9de470cSBruce Richardson 			}
1001a9de470cSBruce Richardson 	} else
1002a9de470cSBruce Richardson 		rc = TEST_FAILED;
1003a9de470cSBruce Richardson 
1004a9de470cSBruce Richardson 	return rc;
1005a9de470cSBruce Richardson }
1006a9de470cSBruce Richardson 
1007a9de470cSBruce Richardson static uint32_t
1008a9de470cSBruce Richardson crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
1009a9de470cSBruce Richardson {
1010a9de470cSBruce Richardson 	uint32_t rc = 0;
1011a9de470cSBruce Richardson 
1012a9de470cSBruce Richardson 	if (grp_ind == 0) {
1013a9de470cSBruce Richardson 		if (grp[grp_ind].cnt != PKT_4)
1014a9de470cSBruce Richardson 			rc = TEST_FAILED;
1015a9de470cSBruce Richardson 	} else if (grp_ind == 1) {
1016a9de470cSBruce Richardson 		if (grp[grp_ind].cnt != PKT_12 - PKT_4)
1017a9de470cSBruce Richardson 			rc = TEST_FAILED;
1018a9de470cSBruce Richardson 	} else if (grp_ind == 2) {
1019a9de470cSBruce Richardson 		if (grp[grp_ind].cnt != PKT_21 - PKT_12)
1020a9de470cSBruce Richardson 			rc = TEST_FAILED;
1021a9de470cSBruce Richardson 	} else if (grp_ind == 3) {
1022a9de470cSBruce Richardson 		if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
1023a9de470cSBruce Richardson 			rc = TEST_FAILED;
1024a9de470cSBruce Richardson 	} else
1025a9de470cSBruce Richardson 		rc = TEST_FAILED;
1026a9de470cSBruce Richardson 
1027a9de470cSBruce Richardson 	return rc;
1028a9de470cSBruce Richardson }
1029a9de470cSBruce Richardson 
1030a9de470cSBruce Richardson static int
1031a9de470cSBruce Richardson crypto_ipsec_2sa_4grp(void)
1032a9de470cSBruce Richardson {
1033a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1034a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1035a9de470cSBruce Richardson 	struct rte_ipsec_group grp[BURST_SIZE];
1036a9de470cSBruce Richardson 	uint32_t k, ng, i, j;
1037a9de470cSBruce Richardson 	uint32_t rc = 0;
1038a9de470cSBruce Richardson 
1039a9de470cSBruce Richardson 	for (i = 0; i < BURST_SIZE; i++) {
1040a9de470cSBruce Richardson 		j = crypto_ipsec_4grp(i);
1041a9de470cSBruce Richardson 
1042a9de470cSBruce Richardson 		/* call crypto prepare */
1043a9de470cSBruce Richardson 		k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
1044a9de470cSBruce Richardson 				ut_params->ibuf + i, ut_params->cop + i, 1);
1045a9de470cSBruce Richardson 		if (k != 1) {
1046a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1047a9de470cSBruce Richardson 				"rte_ipsec_pkt_crypto_prepare fail\n");
1048a9de470cSBruce Richardson 			return TEST_FAILED;
1049a9de470cSBruce Richardson 		}
1050a9de470cSBruce Richardson 		k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
1051a9de470cSBruce Richardson 				ut_params->cop + i, 1);
1052a9de470cSBruce Richardson 		if (k != 1) {
1053a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1054a9de470cSBruce Richardson 				"rte_cryptodev_enqueue_burst fail\n");
1055a9de470cSBruce Richardson 			return TEST_FAILED;
1056a9de470cSBruce Richardson 		}
1057a9de470cSBruce Richardson 	}
1058a9de470cSBruce Richardson 
10592cb4a0d4SBernard Iremonger 	if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
1060a9de470cSBruce Richardson 		return TEST_FAILED;
1061a9de470cSBruce Richardson 
1062a9de470cSBruce Richardson 	ng = rte_ipsec_pkt_crypto_group(
1063a9de470cSBruce Richardson 		(const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
1064a9de470cSBruce Richardson 		ut_params->obuf, grp, BURST_SIZE);
1065a9de470cSBruce Richardson 	if (ng != 4) {
1066a9de470cSBruce Richardson 		RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
1067a9de470cSBruce Richardson 			ng);
1068a9de470cSBruce Richardson 		return TEST_FAILED;
1069a9de470cSBruce Richardson 	}
1070a9de470cSBruce Richardson 
1071a9de470cSBruce Richardson 	/* call crypto process */
1072a9de470cSBruce Richardson 	for (i = 0; i < ng; i++) {
1073a9de470cSBruce Richardson 		k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
1074a9de470cSBruce Richardson 		if (k != grp[i].cnt) {
1075*3feaf412SBernard Iremonger 			dump_grp_pkt(i, grp, k);
1076a9de470cSBruce Richardson 			return TEST_FAILED;
1077a9de470cSBruce Richardson 		}
1078a9de470cSBruce Richardson 		rc = crypto_ipsec_4grp_check_cnt(i, grp);
1079a9de470cSBruce Richardson 		if (rc != 0) {
1080a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1081a9de470cSBruce Richardson 				"crypto_ipsec_4grp_check_cnt fail\n");
1082a9de470cSBruce Richardson 			return TEST_FAILED;
1083a9de470cSBruce Richardson 		}
1084a9de470cSBruce Richardson 		rc = crypto_ipsec_4grp_check_mbufs(i, grp);
1085a9de470cSBruce Richardson 		if (rc != 0) {
1086a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1087a9de470cSBruce Richardson 				"crypto_ipsec_4grp_check_mbufs fail\n");
1088a9de470cSBruce Richardson 			return TEST_FAILED;
1089a9de470cSBruce Richardson 		}
1090a9de470cSBruce Richardson 	}
1091a9de470cSBruce Richardson 	return TEST_SUCCESS;
1092a9de470cSBruce Richardson }
1093a9de470cSBruce Richardson 
1094a9de470cSBruce Richardson static void
1095a9de470cSBruce Richardson test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
1096a9de470cSBruce Richardson {
1097a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1098a9de470cSBruce Richardson 	struct rte_mbuf *ibuf_tmp[BURST_SIZE];
1099a9de470cSBruce Richardson 	uint16_t j;
1100a9de470cSBruce Richardson 
1101a9de470cSBruce Richardson 	/* reorder packets and create gaps in sequence numbers */
1102a9de470cSBruce Richardson 	static const uint32_t reorder[BURST_SIZE] = {
1103a9de470cSBruce Richardson 			24, 25, 26, 27, 28, 29, 30, 31,
1104a9de470cSBruce Richardson 			16, 17, 18, 19, 20, 21, 22, 23,
1105a9de470cSBruce Richardson 			8, 9, 10, 11, 12, 13, 14, 15,
1106a9de470cSBruce Richardson 			0, 1, 2, 3, 4, 5, 6, 7,
1107a9de470cSBruce Richardson 	};
1108a9de470cSBruce Richardson 
1109a9de470cSBruce Richardson 	if (num_pkts != BURST_SIZE)
1110a9de470cSBruce Richardson 		return;
1111a9de470cSBruce Richardson 
1112a9de470cSBruce Richardson 	for (j = 0; j != BURST_SIZE; j++)
1113a9de470cSBruce Richardson 		ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
1114a9de470cSBruce Richardson 
1115a9de470cSBruce Richardson 	memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
1116a9de470cSBruce Richardson }
1117a9de470cSBruce Richardson 
1118a9de470cSBruce Richardson static int
1119a9de470cSBruce Richardson test_ipsec_crypto_op_alloc(uint16_t num_pkts)
1120a9de470cSBruce Richardson {
1121a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1122a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1123a9de470cSBruce Richardson 	int rc = 0;
1124a9de470cSBruce Richardson 	uint16_t j;
1125a9de470cSBruce Richardson 
1126a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1127a9de470cSBruce Richardson 		ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
1128a9de470cSBruce Richardson 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1129a9de470cSBruce Richardson 		if (ut_params->cop[j] == NULL) {
1130a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1131a9de470cSBruce Richardson 				"Failed to allocate symmetric crypto op\n");
1132a9de470cSBruce Richardson 			rc = TEST_FAILED;
1133a9de470cSBruce Richardson 		}
1134a9de470cSBruce Richardson 	}
1135a9de470cSBruce Richardson 
1136a9de470cSBruce Richardson 	return rc;
1137a9de470cSBruce Richardson }
1138a9de470cSBruce Richardson 
1139a9de470cSBruce Richardson static void
1140a9de470cSBruce Richardson test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
1141a9de470cSBruce Richardson {
1142a9de470cSBruce Richardson 	uint16_t j = ut_params->pkt_index;
1143a9de470cSBruce Richardson 
1144a9de470cSBruce Richardson 	printf("\ntest config: num %d\n", i);
1145a9de470cSBruce Richardson 	printf("	replay_win_sz %u\n", test_cfg[i].replay_win_sz);
1146a9de470cSBruce Richardson 	printf("	esn %u\n", test_cfg[i].esn);
1147a9de470cSBruce Richardson 	printf("	flags 0x%" PRIx64 "\n", test_cfg[i].flags);
1148a9de470cSBruce Richardson 	printf("	pkt_sz %zu\n", test_cfg[i].pkt_sz);
1149a9de470cSBruce Richardson 	printf("	num_pkts %u\n\n", test_cfg[i].num_pkts);
1150a9de470cSBruce Richardson 
1151a9de470cSBruce Richardson 	if (ut_params->ibuf[j]) {
1152a9de470cSBruce Richardson 		printf("ibuf[%u] data:\n", j);
1153a9de470cSBruce Richardson 		rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
1154a9de470cSBruce Richardson 			ut_params->ibuf[j]->data_len);
1155a9de470cSBruce Richardson 	}
1156a9de470cSBruce Richardson 	if (ut_params->obuf[j]) {
1157a9de470cSBruce Richardson 		printf("obuf[%u] data:\n", j);
1158a9de470cSBruce Richardson 		rte_pktmbuf_dump(stdout, ut_params->obuf[j],
1159a9de470cSBruce Richardson 			ut_params->obuf[j]->data_len);
1160a9de470cSBruce Richardson 	}
1161a9de470cSBruce Richardson 	if (ut_params->testbuf[j]) {
1162a9de470cSBruce Richardson 		printf("testbuf[%u] data:\n", j);
1163a9de470cSBruce Richardson 		rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
1164a9de470cSBruce Richardson 			ut_params->testbuf[j]->data_len);
1165a9de470cSBruce Richardson 	}
1166a9de470cSBruce Richardson }
1167a9de470cSBruce Richardson 
1168a9de470cSBruce Richardson static void
1169a9de470cSBruce Richardson destroy_sa(uint32_t j)
1170a9de470cSBruce Richardson {
1171a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut = &unittest_params;
1172a9de470cSBruce Richardson 
1173a9de470cSBruce Richardson 	rte_ipsec_sa_fini(ut->ss[j].sa);
1174a9de470cSBruce Richardson 	rte_free(ut->ss[j].sa);
1175a9de470cSBruce Richardson 	rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses);
1176a9de470cSBruce Richardson 	memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
1177a9de470cSBruce Richardson }
1178a9de470cSBruce Richardson 
1179a9de470cSBruce Richardson static int
1180a9de470cSBruce Richardson crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1181a9de470cSBruce Richardson 		uint16_t num_pkts)
1182a9de470cSBruce Richardson {
1183a9de470cSBruce Richardson 	uint16_t j;
1184a9de470cSBruce Richardson 
1185a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1186a9de470cSBruce Richardson 		ut_params->pkt_index = j;
1187a9de470cSBruce Richardson 
1188a9de470cSBruce Richardson 		/* compare the data buffers */
1189a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1190a9de470cSBruce Richardson 			rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1191a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
1192a9de470cSBruce Richardson 			"input and output data does not match\n");
1193a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1194a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
1195a9de470cSBruce Richardson 			"data_len is not equal to pkt_len");
1196a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1197a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
1198a9de470cSBruce Richardson 			"data_len is not equal to input data");
1199a9de470cSBruce Richardson 	}
1200a9de470cSBruce Richardson 
1201a9de470cSBruce Richardson 	return 0;
1202a9de470cSBruce Richardson }
1203a9de470cSBruce Richardson 
1204a9de470cSBruce Richardson static int
1205a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_null_null(int i)
1206a9de470cSBruce Richardson {
1207a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1208a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1209a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1210a9de470cSBruce Richardson 	uint16_t j;
1211a9de470cSBruce Richardson 	int rc;
1212a9de470cSBruce Richardson 
1213a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
1214a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1215a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1216a9de470cSBruce Richardson 	if (rc != 0) {
12179ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1218a9de470cSBruce Richardson 		return TEST_FAILED;
1219a9de470cSBruce Richardson 	}
1220a9de470cSBruce Richardson 
1221a9de470cSBruce Richardson 	/* Generate test mbuf data */
1222a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1223a9de470cSBruce Richardson 		/* packet with sequence number 0 is invalid */
1224a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string_tunneled(
1225a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
1226a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1227a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
1228a9de470cSBruce Richardson 			rc = TEST_FAILED;
1229a9de470cSBruce Richardson 	}
1230a9de470cSBruce Richardson 
1231a9de470cSBruce Richardson 	if (rc == 0) {
1232a9de470cSBruce Richardson 		if (test_cfg[i].reorder_pkts)
1233a9de470cSBruce Richardson 			test_ipsec_reorder_inb_pkt_burst(num_pkts);
1234a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(num_pkts);
1235a9de470cSBruce Richardson 	}
1236a9de470cSBruce Richardson 
1237a9de470cSBruce Richardson 	if (rc == 0) {
1238a9de470cSBruce Richardson 		/* call ipsec library api */
1239a9de470cSBruce Richardson 		rc = crypto_ipsec(num_pkts);
1240a9de470cSBruce Richardson 		if (rc == 0)
1241a9de470cSBruce Richardson 			rc = crypto_inb_burst_null_null_check(
1242a9de470cSBruce Richardson 					ut_params, i, num_pkts);
1243a9de470cSBruce Richardson 		else {
1244a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1245a9de470cSBruce Richardson 				i);
1246a9de470cSBruce Richardson 			rc = TEST_FAILED;
1247a9de470cSBruce Richardson 		}
1248a9de470cSBruce Richardson 	}
1249a9de470cSBruce Richardson 
1250a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1251a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1252a9de470cSBruce Richardson 
1253a9de470cSBruce Richardson 	destroy_sa(0);
1254a9de470cSBruce Richardson 	return rc;
1255a9de470cSBruce Richardson }
1256a9de470cSBruce Richardson 
1257a9de470cSBruce Richardson static int
1258a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1259a9de470cSBruce Richardson {
1260a9de470cSBruce Richardson 	int i;
1261a9de470cSBruce Richardson 	int rc = 0;
1262a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1263a9de470cSBruce Richardson 
1264a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1265a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1266a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1267a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1268a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1269a9de470cSBruce Richardson 
1270a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1271a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1272a9de470cSBruce Richardson 		rc = test_ipsec_crypto_inb_burst_null_null(i);
1273a9de470cSBruce Richardson 	}
1274a9de470cSBruce Richardson 
1275a9de470cSBruce Richardson 	return rc;
1276a9de470cSBruce Richardson }
1277a9de470cSBruce Richardson 
1278a9de470cSBruce Richardson static int
1279a9de470cSBruce Richardson crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1280a9de470cSBruce Richardson 	uint16_t num_pkts)
1281a9de470cSBruce Richardson {
1282a9de470cSBruce Richardson 	void *obuf_data;
1283a9de470cSBruce Richardson 	void *testbuf_data;
1284a9de470cSBruce Richardson 	uint16_t j;
1285a9de470cSBruce Richardson 
1286a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1287a9de470cSBruce Richardson 		ut_params->pkt_index = j;
1288a9de470cSBruce Richardson 
1289a9de470cSBruce Richardson 		testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1290a9de470cSBruce Richardson 		obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1291a9de470cSBruce Richardson 		/* compare the buffer data */
1292a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1293a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
1294a9de470cSBruce Richardson 			"test and output data does not match\n");
1295a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1296a9de470cSBruce Richardson 			ut_params->testbuf[j]->data_len,
1297a9de470cSBruce Richardson 			"obuf data_len is not equal to testbuf data_len");
1298a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1299a9de470cSBruce Richardson 			ut_params->testbuf[j]->pkt_len,
1300a9de470cSBruce Richardson 			"obuf pkt_len is not equal to testbuf pkt_len");
1301a9de470cSBruce Richardson 	}
1302a9de470cSBruce Richardson 
1303a9de470cSBruce Richardson 	return 0;
1304a9de470cSBruce Richardson }
1305a9de470cSBruce Richardson 
1306a9de470cSBruce Richardson static int
1307a9de470cSBruce Richardson test_ipsec_crypto_outb_burst_null_null(int i)
1308a9de470cSBruce Richardson {
1309a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1310a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1311a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1312a9de470cSBruce Richardson 	uint16_t j;
1313a9de470cSBruce Richardson 	int32_t rc;
1314a9de470cSBruce Richardson 
1315a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
1316a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1317a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1318a9de470cSBruce Richardson 	if (rc != 0) {
13199ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1320a9de470cSBruce Richardson 		return TEST_FAILED;
1321a9de470cSBruce Richardson 	}
1322a9de470cSBruce Richardson 
1323a9de470cSBruce Richardson 	/* Generate input mbuf data */
1324a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1325a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1326a9de470cSBruce Richardson 			null_plain_data, test_cfg[i].pkt_sz, 0);
1327a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
1328a9de470cSBruce Richardson 			rc = TEST_FAILED;
1329a9de470cSBruce Richardson 		else {
1330a9de470cSBruce Richardson 			/* Generate test mbuf data */
1331a9de470cSBruce Richardson 			/* packet with sequence number 0 is invalid */
1332a9de470cSBruce Richardson 			ut_params->testbuf[j] = setup_test_string_tunneled(
1333a9de470cSBruce Richardson 					ts_params->mbuf_pool,
1334a9de470cSBruce Richardson 					null_plain_data, test_cfg[i].pkt_sz,
1335a9de470cSBruce Richardson 					OUTBOUND_SPI, j + 1);
1336a9de470cSBruce Richardson 			if (ut_params->testbuf[j] == NULL)
1337a9de470cSBruce Richardson 				rc = TEST_FAILED;
1338a9de470cSBruce Richardson 		}
1339a9de470cSBruce Richardson 	}
1340a9de470cSBruce Richardson 
1341a9de470cSBruce Richardson 	if (rc == 0)
1342a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(num_pkts);
1343a9de470cSBruce Richardson 
1344a9de470cSBruce Richardson 	if (rc == 0) {
1345a9de470cSBruce Richardson 		/* call ipsec library api */
1346a9de470cSBruce Richardson 		rc = crypto_ipsec(num_pkts);
1347a9de470cSBruce Richardson 		if (rc == 0)
1348a9de470cSBruce Richardson 			rc = crypto_outb_burst_null_null_check(ut_params,
1349a9de470cSBruce Richardson 					num_pkts);
1350a9de470cSBruce Richardson 		else
1351a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1352a9de470cSBruce Richardson 				i);
1353a9de470cSBruce Richardson 	}
1354a9de470cSBruce Richardson 
1355a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1356a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1357a9de470cSBruce Richardson 
1358a9de470cSBruce Richardson 	destroy_sa(0);
1359a9de470cSBruce Richardson 	return rc;
1360a9de470cSBruce Richardson }
1361a9de470cSBruce Richardson 
1362a9de470cSBruce Richardson static int
1363a9de470cSBruce Richardson test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1364a9de470cSBruce Richardson {
1365a9de470cSBruce Richardson 	int i;
1366a9de470cSBruce Richardson 	int rc = 0;
1367a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1368a9de470cSBruce Richardson 
1369a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1370a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1371a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1372a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1373a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1374a9de470cSBruce Richardson 
1375a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1376a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1377a9de470cSBruce Richardson 		rc = test_ipsec_crypto_outb_burst_null_null(i);
1378a9de470cSBruce Richardson 	}
1379a9de470cSBruce Richardson 
1380a9de470cSBruce Richardson 	return rc;
1381a9de470cSBruce Richardson }
1382a9de470cSBruce Richardson 
1383a9de470cSBruce Richardson static int
1384a9de470cSBruce Richardson inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1385a9de470cSBruce Richardson 	uint16_t num_pkts)
1386a9de470cSBruce Richardson {
1387a9de470cSBruce Richardson 	void *ibuf_data;
1388a9de470cSBruce Richardson 	void *obuf_data;
1389a9de470cSBruce Richardson 	uint16_t j;
1390a9de470cSBruce Richardson 
1391a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1392a9de470cSBruce Richardson 		ut_params->pkt_index = j;
1393a9de470cSBruce Richardson 
1394a9de470cSBruce Richardson 		/* compare the buffer data */
1395a9de470cSBruce Richardson 		ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1396a9de470cSBruce Richardson 		obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1397a9de470cSBruce Richardson 
1398a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1399a9de470cSBruce Richardson 			ut_params->ibuf[j]->data_len,
1400a9de470cSBruce Richardson 			"input and output data does not match\n");
1401a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1402a9de470cSBruce Richardson 			ut_params->obuf[j]->data_len,
1403a9de470cSBruce Richardson 			"ibuf data_len is not equal to obuf data_len");
1404a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1405a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
1406a9de470cSBruce Richardson 			"ibuf pkt_len is not equal to obuf pkt_len");
1407a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1408a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
1409a9de470cSBruce Richardson 			"data_len is not equal input data");
1410a9de470cSBruce Richardson 	}
1411a9de470cSBruce Richardson 	return 0;
1412a9de470cSBruce Richardson }
1413a9de470cSBruce Richardson 
1414a9de470cSBruce Richardson static int
1415a9de470cSBruce Richardson test_ipsec_inline_crypto_inb_burst_null_null(int i)
1416a9de470cSBruce Richardson {
1417a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1418a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1419a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1420a9de470cSBruce Richardson 	uint16_t j;
1421a9de470cSBruce Richardson 	int32_t rc;
1422a9de470cSBruce Richardson 	uint32_t n;
1423a9de470cSBruce Richardson 
1424a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
1425a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1426a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1427a9de470cSBruce Richardson 	if (rc != 0) {
14289ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1429a9de470cSBruce Richardson 		return TEST_FAILED;
1430a9de470cSBruce Richardson 	}
1431a9de470cSBruce Richardson 
1432a9de470cSBruce Richardson 	/* Generate inbound mbuf data */
1433a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1434a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string_tunneled(
1435a9de470cSBruce Richardson 			ts_params->mbuf_pool,
1436a9de470cSBruce Richardson 			null_plain_data, test_cfg[i].pkt_sz,
1437a9de470cSBruce Richardson 			INBOUND_SPI, j + 1);
1438a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
1439a9de470cSBruce Richardson 			rc = TEST_FAILED;
1440a9de470cSBruce Richardson 		else {
1441a9de470cSBruce Richardson 			/* Generate test mbuf data */
1442a9de470cSBruce Richardson 			ut_params->obuf[j] = setup_test_string(
1443a9de470cSBruce Richardson 				ts_params->mbuf_pool,
1444a9de470cSBruce Richardson 				null_plain_data, test_cfg[i].pkt_sz, 0);
1445a9de470cSBruce Richardson 			if (ut_params->obuf[j] == NULL)
1446a9de470cSBruce Richardson 				rc = TEST_FAILED;
1447a9de470cSBruce Richardson 		}
1448a9de470cSBruce Richardson 	}
1449a9de470cSBruce Richardson 
1450a9de470cSBruce Richardson 	if (rc == 0) {
1451a9de470cSBruce Richardson 		n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1452a9de470cSBruce Richardson 				num_pkts);
1453a9de470cSBruce Richardson 		if (n == num_pkts)
1454a9de470cSBruce Richardson 			rc = inline_inb_burst_null_null_check(ut_params, i,
1455a9de470cSBruce Richardson 					num_pkts);
1456a9de470cSBruce Richardson 		else {
1457a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1458a9de470cSBruce Richardson 				"rte_ipsec_pkt_process failed, cfg %d\n",
1459a9de470cSBruce Richardson 				i);
1460a9de470cSBruce Richardson 			rc = TEST_FAILED;
1461a9de470cSBruce Richardson 		}
1462a9de470cSBruce Richardson 	}
1463a9de470cSBruce Richardson 
1464a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1465a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1466a9de470cSBruce Richardson 
1467a9de470cSBruce Richardson 	destroy_sa(0);
1468a9de470cSBruce Richardson 	return rc;
1469a9de470cSBruce Richardson }
1470a9de470cSBruce Richardson 
1471a9de470cSBruce Richardson static int
1472a9de470cSBruce Richardson test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1473a9de470cSBruce Richardson {
1474a9de470cSBruce Richardson 	int i;
1475a9de470cSBruce Richardson 	int rc = 0;
1476a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1477a9de470cSBruce Richardson 
1478a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1479a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1480a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1481a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1482a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1483a9de470cSBruce Richardson 
1484a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1485a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1486a9de470cSBruce Richardson 		rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1487a9de470cSBruce Richardson 	}
1488a9de470cSBruce Richardson 
1489a9de470cSBruce Richardson 	return rc;
1490a9de470cSBruce Richardson }
1491a9de470cSBruce Richardson 
1492a9de470cSBruce Richardson static int
1493a9de470cSBruce Richardson test_ipsec_inline_proto_inb_burst_null_null(int i)
1494a9de470cSBruce Richardson {
1495a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1496a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1497a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1498a9de470cSBruce Richardson 	uint16_t j;
1499a9de470cSBruce Richardson 	int32_t rc;
1500a9de470cSBruce Richardson 	uint32_t n;
1501a9de470cSBruce Richardson 
1502a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
1503a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1504a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1505a9de470cSBruce Richardson 	if (rc != 0) {
15069ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1507a9de470cSBruce Richardson 		return TEST_FAILED;
1508a9de470cSBruce Richardson 	}
1509a9de470cSBruce Richardson 
1510a9de470cSBruce Richardson 	/* Generate inbound mbuf data */
1511a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1512a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string(
1513a9de470cSBruce Richardson 			ts_params->mbuf_pool,
1514a9de470cSBruce Richardson 			null_plain_data, test_cfg[i].pkt_sz, 0);
1515a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
1516a9de470cSBruce Richardson 			rc = TEST_FAILED;
1517a9de470cSBruce Richardson 		else {
1518a9de470cSBruce Richardson 			/* Generate test mbuf data */
1519a9de470cSBruce Richardson 			ut_params->obuf[j] = setup_test_string(
1520a9de470cSBruce Richardson 				ts_params->mbuf_pool,
1521a9de470cSBruce Richardson 				null_plain_data, test_cfg[i].pkt_sz, 0);
1522a9de470cSBruce Richardson 			if (ut_params->obuf[j] == NULL)
1523a9de470cSBruce Richardson 				rc = TEST_FAILED;
1524a9de470cSBruce Richardson 		}
1525a9de470cSBruce Richardson 	}
1526a9de470cSBruce Richardson 
1527a9de470cSBruce Richardson 	if (rc == 0) {
1528a9de470cSBruce Richardson 		n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1529a9de470cSBruce Richardson 				num_pkts);
1530a9de470cSBruce Richardson 		if (n == num_pkts)
1531a9de470cSBruce Richardson 			rc = inline_inb_burst_null_null_check(ut_params, i,
1532a9de470cSBruce Richardson 					num_pkts);
1533a9de470cSBruce Richardson 		else {
1534a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1535a9de470cSBruce Richardson 				"rte_ipsec_pkt_process failed, cfg %d\n",
1536a9de470cSBruce Richardson 				i);
1537a9de470cSBruce Richardson 			rc = TEST_FAILED;
1538a9de470cSBruce Richardson 		}
1539a9de470cSBruce Richardson 	}
1540a9de470cSBruce Richardson 
1541a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1542a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1543a9de470cSBruce Richardson 
1544a9de470cSBruce Richardson 	destroy_sa(0);
1545a9de470cSBruce Richardson 	return rc;
1546a9de470cSBruce Richardson }
1547a9de470cSBruce Richardson 
1548a9de470cSBruce Richardson static int
1549a9de470cSBruce Richardson test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1550a9de470cSBruce Richardson {
1551a9de470cSBruce Richardson 	int i;
1552a9de470cSBruce Richardson 	int rc = 0;
1553a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1554a9de470cSBruce Richardson 
1555a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1556a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1557a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1558a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1559a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1560a9de470cSBruce Richardson 
1561a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1562a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1563a9de470cSBruce Richardson 		rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1564a9de470cSBruce Richardson 	}
1565a9de470cSBruce Richardson 
1566a9de470cSBruce Richardson 	return rc;
1567a9de470cSBruce Richardson }
1568a9de470cSBruce Richardson 
1569a9de470cSBruce Richardson static int
1570a9de470cSBruce Richardson inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1571a9de470cSBruce Richardson 	uint16_t num_pkts)
1572a9de470cSBruce Richardson {
1573a9de470cSBruce Richardson 	void *obuf_data;
1574a9de470cSBruce Richardson 	void *ibuf_data;
1575a9de470cSBruce Richardson 	uint16_t j;
1576a9de470cSBruce Richardson 
1577a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1578a9de470cSBruce Richardson 		ut_params->pkt_index = j;
1579a9de470cSBruce Richardson 
1580a9de470cSBruce Richardson 		/* compare the buffer data */
1581a9de470cSBruce Richardson 		ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1582a9de470cSBruce Richardson 		obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1583a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1584a9de470cSBruce Richardson 			ut_params->ibuf[j]->data_len,
1585a9de470cSBruce Richardson 			"input and output data does not match\n");
1586a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1587a9de470cSBruce Richardson 			ut_params->obuf[j]->data_len,
1588a9de470cSBruce Richardson 			"ibuf data_len is not equal to obuf data_len");
1589a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1590a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
1591a9de470cSBruce Richardson 			"ibuf pkt_len is not equal to obuf pkt_len");
1592a9de470cSBruce Richardson 
1593a9de470cSBruce Richardson 		/* check mbuf ol_flags */
1594a9de470cSBruce Richardson 		TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
1595a9de470cSBruce Richardson 			"ibuf PKT_TX_SEC_OFFLOAD is not set");
1596a9de470cSBruce Richardson 	}
1597a9de470cSBruce Richardson 	return 0;
1598a9de470cSBruce Richardson }
1599a9de470cSBruce Richardson 
1600a9de470cSBruce Richardson static int
1601a9de470cSBruce Richardson test_ipsec_inline_crypto_outb_burst_null_null(int i)
1602a9de470cSBruce Richardson {
1603a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1604a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1605a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1606a9de470cSBruce Richardson 	uint16_t j;
1607a9de470cSBruce Richardson 	int32_t rc;
1608a9de470cSBruce Richardson 	uint32_t n;
1609a9de470cSBruce Richardson 
1610a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
1611a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1612a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1613a9de470cSBruce Richardson 	if (rc != 0) {
16149ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1615a9de470cSBruce Richardson 		return TEST_FAILED;
1616a9de470cSBruce Richardson 	}
1617a9de470cSBruce Richardson 
1618a9de470cSBruce Richardson 	/* Generate test mbuf data */
1619a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1620a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1621a9de470cSBruce Richardson 			null_plain_data, test_cfg[i].pkt_sz, 0);
1622a9de470cSBruce Richardson 		if (ut_params->ibuf[0] == NULL)
1623a9de470cSBruce Richardson 			rc = TEST_FAILED;
1624a9de470cSBruce Richardson 
1625a9de470cSBruce Richardson 		if (rc == 0) {
1626a9de470cSBruce Richardson 			/* Generate test tunneled mbuf data for comparison */
1627a9de470cSBruce Richardson 			ut_params->obuf[j] = setup_test_string_tunneled(
1628a9de470cSBruce Richardson 					ts_params->mbuf_pool,
1629a9de470cSBruce Richardson 					null_plain_data, test_cfg[i].pkt_sz,
1630a9de470cSBruce Richardson 					OUTBOUND_SPI, j + 1);
1631a9de470cSBruce Richardson 			if (ut_params->obuf[j] == NULL)
1632a9de470cSBruce Richardson 				rc = TEST_FAILED;
1633a9de470cSBruce Richardson 		}
1634a9de470cSBruce Richardson 	}
1635a9de470cSBruce Richardson 
1636a9de470cSBruce Richardson 	if (rc == 0) {
1637a9de470cSBruce Richardson 		n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1638a9de470cSBruce Richardson 				num_pkts);
1639a9de470cSBruce Richardson 		if (n == num_pkts)
1640a9de470cSBruce Richardson 			rc = inline_outb_burst_null_null_check(ut_params,
1641a9de470cSBruce Richardson 					num_pkts);
1642a9de470cSBruce Richardson 		else {
1643a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1644a9de470cSBruce Richardson 				"rte_ipsec_pkt_process failed, cfg %d\n",
1645a9de470cSBruce Richardson 				i);
1646a9de470cSBruce Richardson 			rc = TEST_FAILED;
1647a9de470cSBruce Richardson 		}
1648a9de470cSBruce Richardson 	}
1649a9de470cSBruce Richardson 
1650a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1651a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1652a9de470cSBruce Richardson 
1653a9de470cSBruce Richardson 	destroy_sa(0);
1654a9de470cSBruce Richardson 	return rc;
1655a9de470cSBruce Richardson }
1656a9de470cSBruce Richardson 
1657a9de470cSBruce Richardson static int
1658a9de470cSBruce Richardson test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1659a9de470cSBruce Richardson {
1660a9de470cSBruce Richardson 	int i;
1661a9de470cSBruce Richardson 	int rc = 0;
1662a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1663a9de470cSBruce Richardson 
1664a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1665a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1666a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1667a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1668a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1669a9de470cSBruce Richardson 
1670a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1671a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1672a9de470cSBruce Richardson 		rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1673a9de470cSBruce Richardson 	}
1674a9de470cSBruce Richardson 
1675a9de470cSBruce Richardson 	return rc;
1676a9de470cSBruce Richardson }
1677a9de470cSBruce Richardson 
1678a9de470cSBruce Richardson static int
1679a9de470cSBruce Richardson test_ipsec_inline_proto_outb_burst_null_null(int i)
1680a9de470cSBruce Richardson {
1681a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1682a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1683a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1684a9de470cSBruce Richardson 	uint16_t j;
1685a9de470cSBruce Richardson 	int32_t rc;
1686a9de470cSBruce Richardson 	uint32_t n;
1687a9de470cSBruce Richardson 
1688a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
1689a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1690a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1691a9de470cSBruce Richardson 	if (rc != 0) {
16929ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1693a9de470cSBruce Richardson 		return TEST_FAILED;
1694a9de470cSBruce Richardson 	}
1695a9de470cSBruce Richardson 
1696a9de470cSBruce Richardson 	/* Generate test mbuf data */
1697a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1698a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1699a9de470cSBruce Richardson 			null_plain_data, test_cfg[i].pkt_sz, 0);
1700a9de470cSBruce Richardson 		if (ut_params->ibuf[0] == NULL)
1701a9de470cSBruce Richardson 			rc = TEST_FAILED;
1702a9de470cSBruce Richardson 
1703a9de470cSBruce Richardson 		if (rc == 0) {
1704a9de470cSBruce Richardson 			/* Generate test tunneled mbuf data for comparison */
1705a9de470cSBruce Richardson 			ut_params->obuf[j] = setup_test_string(
1706a9de470cSBruce Richardson 					ts_params->mbuf_pool,
1707a9de470cSBruce Richardson 					null_plain_data, test_cfg[i].pkt_sz, 0);
1708a9de470cSBruce Richardson 			if (ut_params->obuf[j] == NULL)
1709a9de470cSBruce Richardson 				rc = TEST_FAILED;
1710a9de470cSBruce Richardson 		}
1711a9de470cSBruce Richardson 	}
1712a9de470cSBruce Richardson 
1713a9de470cSBruce Richardson 	if (rc == 0) {
1714a9de470cSBruce Richardson 		n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1715a9de470cSBruce Richardson 				num_pkts);
1716a9de470cSBruce Richardson 		if (n == num_pkts)
1717a9de470cSBruce Richardson 			rc = inline_outb_burst_null_null_check(ut_params,
1718a9de470cSBruce Richardson 					num_pkts);
1719a9de470cSBruce Richardson 		else {
1720a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1,
1721a9de470cSBruce Richardson 				"rte_ipsec_pkt_process failed, cfg %d\n",
1722a9de470cSBruce Richardson 				i);
1723a9de470cSBruce Richardson 			rc = TEST_FAILED;
1724a9de470cSBruce Richardson 		}
1725a9de470cSBruce Richardson 	}
1726a9de470cSBruce Richardson 
1727a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1728a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1729a9de470cSBruce Richardson 
1730a9de470cSBruce Richardson 	destroy_sa(0);
1731a9de470cSBruce Richardson 	return rc;
1732a9de470cSBruce Richardson }
1733a9de470cSBruce Richardson 
1734a9de470cSBruce Richardson static int
1735a9de470cSBruce Richardson test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1736a9de470cSBruce Richardson {
1737a9de470cSBruce Richardson 	int i;
1738a9de470cSBruce Richardson 	int rc = 0;
1739a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1740a9de470cSBruce Richardson 
1741a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1742a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1743a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1744a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1745a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1746a9de470cSBruce Richardson 
1747a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1748a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1749a9de470cSBruce Richardson 		rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1750a9de470cSBruce Richardson 	}
1751a9de470cSBruce Richardson 
1752a9de470cSBruce Richardson 	return rc;
1753a9de470cSBruce Richardson }
1754a9de470cSBruce Richardson 
1755a9de470cSBruce Richardson static int
1756a9de470cSBruce Richardson test_ipsec_lksd_proto_inb_burst_null_null(int i)
1757a9de470cSBruce Richardson {
1758a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1759a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1760a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
1761a9de470cSBruce Richardson 	uint16_t j;
1762a9de470cSBruce Richardson 	int rc;
1763a9de470cSBruce Richardson 
1764a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
1765a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1766a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1767a9de470cSBruce Richardson 	if (rc != 0) {
17689ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1769a9de470cSBruce Richardson 		return TEST_FAILED;
1770a9de470cSBruce Richardson 	}
1771a9de470cSBruce Richardson 
1772a9de470cSBruce Richardson 	/* Generate test mbuf data */
1773a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
1774a9de470cSBruce Richardson 		/* packet with sequence number 0 is invalid */
1775a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1776a9de470cSBruce Richardson 			null_encrypted_data, test_cfg[i].pkt_sz, 0);
1777a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
1778a9de470cSBruce Richardson 			rc = TEST_FAILED;
1779a9de470cSBruce Richardson 	}
1780a9de470cSBruce Richardson 
1781a9de470cSBruce Richardson 	if (rc == 0) {
1782a9de470cSBruce Richardson 		if (test_cfg[i].reorder_pkts)
1783a9de470cSBruce Richardson 			test_ipsec_reorder_inb_pkt_burst(num_pkts);
1784a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(num_pkts);
1785a9de470cSBruce Richardson 	}
1786a9de470cSBruce Richardson 
1787a9de470cSBruce Richardson 	if (rc == 0) {
1788a9de470cSBruce Richardson 		/* call ipsec library api */
1789a9de470cSBruce Richardson 		rc = lksd_proto_ipsec(num_pkts);
1790a9de470cSBruce Richardson 		if (rc == 0)
1791a9de470cSBruce Richardson 			rc = crypto_inb_burst_null_null_check(ut_params, i,
1792a9de470cSBruce Richardson 					num_pkts);
1793a9de470cSBruce Richardson 		else {
1794a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1795a9de470cSBruce Richardson 				__func__, i);
1796a9de470cSBruce Richardson 			rc = TEST_FAILED;
1797a9de470cSBruce Richardson 		}
1798a9de470cSBruce Richardson 	}
1799a9de470cSBruce Richardson 
1800a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1801a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1802a9de470cSBruce Richardson 
1803a9de470cSBruce Richardson 	destroy_sa(0);
1804a9de470cSBruce Richardson 	return rc;
1805a9de470cSBruce Richardson }
1806a9de470cSBruce Richardson 
1807a9de470cSBruce Richardson static int
1808a9de470cSBruce Richardson test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1809a9de470cSBruce Richardson {
1810a9de470cSBruce Richardson 	int i;
1811a9de470cSBruce Richardson 	int rc = 0;
1812a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1813a9de470cSBruce Richardson 
1814a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1815a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1816a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1817a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1818a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1819a9de470cSBruce Richardson 
1820a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1821a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1822a9de470cSBruce Richardson 		rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1823a9de470cSBruce Richardson 	}
1824a9de470cSBruce Richardson 
1825a9de470cSBruce Richardson 	return rc;
1826a9de470cSBruce Richardson }
1827a9de470cSBruce Richardson 
1828a9de470cSBruce Richardson static int
1829a9de470cSBruce Richardson test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1830a9de470cSBruce Richardson {
1831a9de470cSBruce Richardson 	int i;
1832a9de470cSBruce Richardson 	int rc = 0;
1833a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1834a9de470cSBruce Richardson 
1835a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1836a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1837a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1838a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1839a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1840a9de470cSBruce Richardson 
1841a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1842a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1843a9de470cSBruce Richardson 		rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1844a9de470cSBruce Richardson 	}
1845a9de470cSBruce Richardson 
1846a9de470cSBruce Richardson 	return rc;
1847a9de470cSBruce Richardson }
1848a9de470cSBruce Richardson 
1849a9de470cSBruce Richardson static int
1850a9de470cSBruce Richardson replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1851a9de470cSBruce Richardson 	int num_pkts)
1852a9de470cSBruce Richardson {
1853a9de470cSBruce Richardson 	uint16_t j;
1854a9de470cSBruce Richardson 
1855a9de470cSBruce Richardson 	for (j = 0; j < num_pkts; j++) {
1856a9de470cSBruce Richardson 		/* compare the buffer data */
1857a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1858a9de470cSBruce Richardson 			rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1859a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
1860a9de470cSBruce Richardson 			"input and output data does not match\n");
1861a9de470cSBruce Richardson 
1862a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1863a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
1864a9de470cSBruce Richardson 			"data_len is not equal to pkt_len");
1865a9de470cSBruce Richardson 	}
1866a9de470cSBruce Richardson 
1867a9de470cSBruce Richardson 	return 0;
1868a9de470cSBruce Richardson }
1869a9de470cSBruce Richardson 
1870a9de470cSBruce Richardson static int
1871a9de470cSBruce Richardson test_ipsec_replay_inb_inside_null_null(int i)
1872a9de470cSBruce Richardson {
1873a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1874a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1875a9de470cSBruce Richardson 	int rc;
1876a9de470cSBruce Richardson 
1877a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
1878a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1879a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1880a9de470cSBruce Richardson 	if (rc != 0) {
18819ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1882a9de470cSBruce Richardson 		return TEST_FAILED;
1883a9de470cSBruce Richardson 	}
1884a9de470cSBruce Richardson 
1885a9de470cSBruce Richardson 	/* Generate inbound mbuf data */
1886a9de470cSBruce Richardson 	ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1887a9de470cSBruce Richardson 		null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1888a9de470cSBruce Richardson 	if (ut_params->ibuf[0] == NULL)
1889a9de470cSBruce Richardson 		rc = TEST_FAILED;
1890a9de470cSBruce Richardson 	else
1891a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(1);
1892a9de470cSBruce Richardson 
1893a9de470cSBruce Richardson 	if (rc == 0) {
1894a9de470cSBruce Richardson 		/* call ipsec library api */
1895a9de470cSBruce Richardson 		rc = crypto_ipsec(1);
1896a9de470cSBruce Richardson 		if (rc == 0)
1897a9de470cSBruce Richardson 			rc = replay_inb_null_null_check(ut_params, i, 1);
1898a9de470cSBruce Richardson 		else {
1899a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1900a9de470cSBruce Richardson 					i);
1901a9de470cSBruce Richardson 			rc = TEST_FAILED;
1902a9de470cSBruce Richardson 		}
1903a9de470cSBruce Richardson 	}
1904a9de470cSBruce Richardson 
1905a9de470cSBruce Richardson 	if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1906a9de470cSBruce Richardson 		/* generate packet with seq number inside the replay window */
1907a9de470cSBruce Richardson 		if (ut_params->ibuf[0]) {
1908a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->ibuf[0]);
1909a9de470cSBruce Richardson 			ut_params->ibuf[0] = 0;
1910a9de470cSBruce Richardson 		}
1911a9de470cSBruce Richardson 
1912a9de470cSBruce Richardson 		ut_params->ibuf[0] = setup_test_string_tunneled(
1913a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
1914a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI,
1915a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz);
1916a9de470cSBruce Richardson 		if (ut_params->ibuf[0] == NULL)
1917a9de470cSBruce Richardson 			rc = TEST_FAILED;
1918a9de470cSBruce Richardson 		else
1919a9de470cSBruce Richardson 			rc = test_ipsec_crypto_op_alloc(1);
1920a9de470cSBruce Richardson 
1921a9de470cSBruce Richardson 		if (rc == 0) {
1922a9de470cSBruce Richardson 			/* call ipsec library api */
1923a9de470cSBruce Richardson 			rc = crypto_ipsec(1);
1924a9de470cSBruce Richardson 			if (rc == 0)
1925a9de470cSBruce Richardson 				rc = replay_inb_null_null_check(
1926a9de470cSBruce Richardson 						ut_params, i, 1);
1927a9de470cSBruce Richardson 			else {
1928a9de470cSBruce Richardson 				RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1929a9de470cSBruce Richardson 				rc = TEST_FAILED;
1930a9de470cSBruce Richardson 			}
1931a9de470cSBruce Richardson 		}
1932a9de470cSBruce Richardson 	}
1933a9de470cSBruce Richardson 
1934a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
1935a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
1936a9de470cSBruce Richardson 
1937a9de470cSBruce Richardson 	destroy_sa(0);
1938a9de470cSBruce Richardson 
1939a9de470cSBruce Richardson 	return rc;
1940a9de470cSBruce Richardson }
1941a9de470cSBruce Richardson 
1942a9de470cSBruce Richardson static int
1943a9de470cSBruce Richardson test_ipsec_replay_inb_inside_null_null_wrapper(void)
1944a9de470cSBruce Richardson {
1945a9de470cSBruce Richardson 	int i;
1946a9de470cSBruce Richardson 	int rc = 0;
1947a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1948a9de470cSBruce Richardson 
1949a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
1950a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1951a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1952a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1953a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1954a9de470cSBruce Richardson 
1955a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
1956a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1957a9de470cSBruce Richardson 		rc = test_ipsec_replay_inb_inside_null_null(i);
1958a9de470cSBruce Richardson 	}
1959a9de470cSBruce Richardson 
1960a9de470cSBruce Richardson 	return rc;
1961a9de470cSBruce Richardson }
1962a9de470cSBruce Richardson 
1963a9de470cSBruce Richardson static int
1964a9de470cSBruce Richardson test_ipsec_replay_inb_outside_null_null(int i)
1965a9de470cSBruce Richardson {
1966a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
1967a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
1968a9de470cSBruce Richardson 	int rc;
1969a9de470cSBruce Richardson 
1970a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
1971a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1972a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1973a9de470cSBruce Richardson 	if (rc != 0) {
19749ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1975a9de470cSBruce Richardson 		return TEST_FAILED;
1976a9de470cSBruce Richardson 	}
1977a9de470cSBruce Richardson 
1978a9de470cSBruce Richardson 	/* Generate test mbuf data */
1979a9de470cSBruce Richardson 	ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1980a9de470cSBruce Richardson 		null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
1981a9de470cSBruce Richardson 		test_cfg[i].replay_win_sz + 2);
1982a9de470cSBruce Richardson 	if (ut_params->ibuf[0] == NULL)
1983a9de470cSBruce Richardson 		rc = TEST_FAILED;
1984a9de470cSBruce Richardson 	else
1985a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(1);
1986a9de470cSBruce Richardson 
1987a9de470cSBruce Richardson 	if (rc == 0) {
1988a9de470cSBruce Richardson 		/* call ipsec library api */
1989a9de470cSBruce Richardson 		rc = crypto_ipsec(1);
1990a9de470cSBruce Richardson 		if (rc == 0)
1991a9de470cSBruce Richardson 			rc = replay_inb_null_null_check(ut_params, i, 1);
1992a9de470cSBruce Richardson 		else {
1993a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1994a9de470cSBruce Richardson 					i);
1995a9de470cSBruce Richardson 			rc = TEST_FAILED;
1996a9de470cSBruce Richardson 		}
1997a9de470cSBruce Richardson 	}
1998a9de470cSBruce Richardson 
1999a9de470cSBruce Richardson 	if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2000a9de470cSBruce Richardson 		/* generate packet with seq number outside the replay window */
2001a9de470cSBruce Richardson 		if (ut_params->ibuf[0]) {
2002a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->ibuf[0]);
2003a9de470cSBruce Richardson 			ut_params->ibuf[0] = 0;
2004a9de470cSBruce Richardson 		}
2005a9de470cSBruce Richardson 		ut_params->ibuf[0] = setup_test_string_tunneled(
2006a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
2007a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2008a9de470cSBruce Richardson 		if (ut_params->ibuf[0] == NULL)
2009a9de470cSBruce Richardson 			rc = TEST_FAILED;
2010a9de470cSBruce Richardson 		else
2011a9de470cSBruce Richardson 			rc = test_ipsec_crypto_op_alloc(1);
2012a9de470cSBruce Richardson 
2013a9de470cSBruce Richardson 		if (rc == 0) {
2014a9de470cSBruce Richardson 			/* call ipsec library api */
2015a9de470cSBruce Richardson 			rc = crypto_ipsec(1);
2016a9de470cSBruce Richardson 			if (rc == 0) {
2017a9de470cSBruce Richardson 				if (test_cfg[i].esn == 0) {
2018a9de470cSBruce Richardson 					RTE_LOG(ERR, USER1,
2019a9de470cSBruce Richardson 						"packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2020a9de470cSBruce Richardson 						i,
2021a9de470cSBruce Richardson 						test_cfg[i].replay_win_sz + 2,
2022a9de470cSBruce Richardson 						1);
2023a9de470cSBruce Richardson 					rc = TEST_FAILED;
2024a9de470cSBruce Richardson 				}
2025a9de470cSBruce Richardson 			} else {
2026a9de470cSBruce Richardson 				RTE_LOG(ERR, USER1,
2027a9de470cSBruce Richardson 					"packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2028a9de470cSBruce Richardson 					i, test_cfg[i].replay_win_sz + 2, 1);
2029a9de470cSBruce Richardson 				rc = 0;
2030a9de470cSBruce Richardson 			}
2031a9de470cSBruce Richardson 		}
2032a9de470cSBruce Richardson 	}
2033a9de470cSBruce Richardson 
2034a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
2035a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
2036a9de470cSBruce Richardson 
2037a9de470cSBruce Richardson 	destroy_sa(0);
2038a9de470cSBruce Richardson 
2039a9de470cSBruce Richardson 	return rc;
2040a9de470cSBruce Richardson }
2041a9de470cSBruce Richardson 
2042a9de470cSBruce Richardson static int
2043a9de470cSBruce Richardson test_ipsec_replay_inb_outside_null_null_wrapper(void)
2044a9de470cSBruce Richardson {
2045a9de470cSBruce Richardson 	int i;
2046a9de470cSBruce Richardson 	int rc = 0;
2047a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2048a9de470cSBruce Richardson 
2049a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
2050a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2051a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2052a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2053a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2054a9de470cSBruce Richardson 
2055a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
2056a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2057a9de470cSBruce Richardson 		rc = test_ipsec_replay_inb_outside_null_null(i);
2058a9de470cSBruce Richardson 	}
2059a9de470cSBruce Richardson 
2060a9de470cSBruce Richardson 	return rc;
2061a9de470cSBruce Richardson }
2062a9de470cSBruce Richardson 
2063a9de470cSBruce Richardson static int
2064a9de470cSBruce Richardson test_ipsec_replay_inb_repeat_null_null(int i)
2065a9de470cSBruce Richardson {
2066a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
2067a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2068a9de470cSBruce Richardson 	int rc;
2069a9de470cSBruce Richardson 
2070a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
2071a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2072a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2073a9de470cSBruce Richardson 	if (rc != 0) {
20749ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2075a9de470cSBruce Richardson 		return TEST_FAILED;
2076a9de470cSBruce Richardson 	}
2077a9de470cSBruce Richardson 
2078a9de470cSBruce Richardson 	/* Generate test mbuf data */
2079a9de470cSBruce Richardson 	ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2080a9de470cSBruce Richardson 		null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2081a9de470cSBruce Richardson 	if (ut_params->ibuf[0] == NULL)
2082a9de470cSBruce Richardson 		rc = TEST_FAILED;
2083a9de470cSBruce Richardson 	else
2084a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(1);
2085a9de470cSBruce Richardson 
2086a9de470cSBruce Richardson 	if (rc == 0) {
2087a9de470cSBruce Richardson 		/* call ipsec library api */
2088a9de470cSBruce Richardson 		rc = crypto_ipsec(1);
2089a9de470cSBruce Richardson 		if (rc == 0)
2090a9de470cSBruce Richardson 			rc = replay_inb_null_null_check(ut_params, i, 1);
2091a9de470cSBruce Richardson 		else {
2092a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2093a9de470cSBruce Richardson 					i);
2094a9de470cSBruce Richardson 			rc = TEST_FAILED;
2095a9de470cSBruce Richardson 		}
2096a9de470cSBruce Richardson 	}
2097a9de470cSBruce Richardson 
2098a9de470cSBruce Richardson 	if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2099a9de470cSBruce Richardson 		/*
2100a9de470cSBruce Richardson 		 * generate packet with repeat seq number in the replay
2101a9de470cSBruce Richardson 		 * window
2102a9de470cSBruce Richardson 		 */
2103a9de470cSBruce Richardson 		if (ut_params->ibuf[0]) {
2104a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->ibuf[0]);
2105a9de470cSBruce Richardson 			ut_params->ibuf[0] = 0;
2106a9de470cSBruce Richardson 		}
2107a9de470cSBruce Richardson 
2108a9de470cSBruce Richardson 		ut_params->ibuf[0] = setup_test_string_tunneled(
2109a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
2110a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2111a9de470cSBruce Richardson 		if (ut_params->ibuf[0] == NULL)
2112a9de470cSBruce Richardson 			rc = TEST_FAILED;
2113a9de470cSBruce Richardson 		else
2114a9de470cSBruce Richardson 			rc = test_ipsec_crypto_op_alloc(1);
2115a9de470cSBruce Richardson 
2116a9de470cSBruce Richardson 		if (rc == 0) {
2117a9de470cSBruce Richardson 			/* call ipsec library api */
2118a9de470cSBruce Richardson 			rc = crypto_ipsec(1);
2119a9de470cSBruce Richardson 			if (rc == 0) {
2120a9de470cSBruce Richardson 				RTE_LOG(ERR, USER1,
2121a9de470cSBruce Richardson 					"packet is not repeated in the replay window, cfg %d seq %u\n",
2122a9de470cSBruce Richardson 					i, 1);
2123a9de470cSBruce Richardson 				rc = TEST_FAILED;
2124a9de470cSBruce Richardson 			} else {
2125a9de470cSBruce Richardson 				RTE_LOG(ERR, USER1,
2126a9de470cSBruce Richardson 					"packet is repeated in the replay window, cfg %d seq %u\n",
2127a9de470cSBruce Richardson 					i, 1);
2128a9de470cSBruce Richardson 				rc = 0;
2129a9de470cSBruce Richardson 			}
2130a9de470cSBruce Richardson 		}
2131a9de470cSBruce Richardson 	}
2132a9de470cSBruce Richardson 
2133a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
2134a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
2135a9de470cSBruce Richardson 
2136a9de470cSBruce Richardson 	destroy_sa(0);
2137a9de470cSBruce Richardson 
2138a9de470cSBruce Richardson 	return rc;
2139a9de470cSBruce Richardson }
2140a9de470cSBruce Richardson 
2141a9de470cSBruce Richardson static int
2142a9de470cSBruce Richardson test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2143a9de470cSBruce Richardson {
2144a9de470cSBruce Richardson 	int i;
2145a9de470cSBruce Richardson 	int rc = 0;
2146a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2147a9de470cSBruce Richardson 
2148a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
2149a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2150a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2151a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2152a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2153a9de470cSBruce Richardson 
2154a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
2155a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2156a9de470cSBruce Richardson 		rc = test_ipsec_replay_inb_repeat_null_null(i);
2157a9de470cSBruce Richardson 	}
2158a9de470cSBruce Richardson 
2159a9de470cSBruce Richardson 	return rc;
2160a9de470cSBruce Richardson }
2161a9de470cSBruce Richardson 
2162a9de470cSBruce Richardson static int
2163a9de470cSBruce Richardson test_ipsec_replay_inb_inside_burst_null_null(int i)
2164a9de470cSBruce Richardson {
2165a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
2166a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2167a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
2168a9de470cSBruce Richardson 	int rc;
2169a9de470cSBruce Richardson 	int j;
2170a9de470cSBruce Richardson 
2171a9de470cSBruce Richardson 	/* create rte_ipsec_sa*/
2172a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2173a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2174a9de470cSBruce Richardson 	if (rc != 0) {
21759ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2176a9de470cSBruce Richardson 		return TEST_FAILED;
2177a9de470cSBruce Richardson 	}
2178a9de470cSBruce Richardson 
2179a9de470cSBruce Richardson 	/* Generate inbound mbuf data */
2180a9de470cSBruce Richardson 	ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2181a9de470cSBruce Richardson 		null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2182a9de470cSBruce Richardson 	if (ut_params->ibuf[0] == NULL)
2183a9de470cSBruce Richardson 		rc = TEST_FAILED;
2184a9de470cSBruce Richardson 	else
2185a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(1);
2186a9de470cSBruce Richardson 
2187a9de470cSBruce Richardson 	if (rc == 0) {
2188a9de470cSBruce Richardson 		/* call ipsec library api */
2189a9de470cSBruce Richardson 		rc = crypto_ipsec(1);
2190a9de470cSBruce Richardson 		if (rc == 0)
2191a9de470cSBruce Richardson 			rc = replay_inb_null_null_check(ut_params, i, 1);
2192a9de470cSBruce Richardson 		else {
2193a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2194a9de470cSBruce Richardson 					i);
2195a9de470cSBruce Richardson 			rc = TEST_FAILED;
2196a9de470cSBruce Richardson 		}
2197a9de470cSBruce Richardson 	}
2198a9de470cSBruce Richardson 
2199a9de470cSBruce Richardson 	if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2200a9de470cSBruce Richardson 		/*
2201a9de470cSBruce Richardson 		 *  generate packet(s) with seq number(s) inside the
2202a9de470cSBruce Richardson 		 *  replay window
2203a9de470cSBruce Richardson 		 */
2204a9de470cSBruce Richardson 		if (ut_params->ibuf[0]) {
2205a9de470cSBruce Richardson 			rte_pktmbuf_free(ut_params->ibuf[0]);
2206a9de470cSBruce Richardson 			ut_params->ibuf[0] = 0;
2207a9de470cSBruce Richardson 		}
2208a9de470cSBruce Richardson 
2209a9de470cSBruce Richardson 		for (j = 0; j < num_pkts && rc == 0; j++) {
2210a9de470cSBruce Richardson 			/* packet with sequence number 1 already processed */
2211a9de470cSBruce Richardson 			ut_params->ibuf[j] = setup_test_string_tunneled(
2212a9de470cSBruce Richardson 				ts_params->mbuf_pool, null_encrypted_data,
2213a9de470cSBruce Richardson 				test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2214a9de470cSBruce Richardson 			if (ut_params->ibuf[j] == NULL)
2215a9de470cSBruce Richardson 				rc = TEST_FAILED;
2216a9de470cSBruce Richardson 		}
2217a9de470cSBruce Richardson 
2218a9de470cSBruce Richardson 		if (rc == 0) {
2219a9de470cSBruce Richardson 			if (test_cfg[i].reorder_pkts)
2220a9de470cSBruce Richardson 				test_ipsec_reorder_inb_pkt_burst(num_pkts);
2221a9de470cSBruce Richardson 			rc = test_ipsec_crypto_op_alloc(num_pkts);
2222a9de470cSBruce Richardson 		}
2223a9de470cSBruce Richardson 
2224a9de470cSBruce Richardson 		if (rc == 0) {
2225a9de470cSBruce Richardson 			/* call ipsec library api */
2226a9de470cSBruce Richardson 			rc = crypto_ipsec(num_pkts);
2227a9de470cSBruce Richardson 			if (rc == 0)
2228a9de470cSBruce Richardson 				rc = replay_inb_null_null_check(
2229a9de470cSBruce Richardson 						ut_params, i, num_pkts);
2230a9de470cSBruce Richardson 			else {
2231a9de470cSBruce Richardson 				RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2232a9de470cSBruce Richardson 				rc = TEST_FAILED;
2233a9de470cSBruce Richardson 			}
2234a9de470cSBruce Richardson 		}
2235a9de470cSBruce Richardson 	}
2236a9de470cSBruce Richardson 
2237a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
2238a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
2239a9de470cSBruce Richardson 
2240a9de470cSBruce Richardson 	destroy_sa(0);
2241a9de470cSBruce Richardson 
2242a9de470cSBruce Richardson 	return rc;
2243a9de470cSBruce Richardson }
2244a9de470cSBruce Richardson 
2245a9de470cSBruce Richardson static int
2246a9de470cSBruce Richardson test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2247a9de470cSBruce Richardson {
2248a9de470cSBruce Richardson 	int i;
2249a9de470cSBruce Richardson 	int rc = 0;
2250a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2251a9de470cSBruce Richardson 
2252a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
2253a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2254a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2255a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2256a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2257a9de470cSBruce Richardson 
2258a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
2259a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2260a9de470cSBruce Richardson 		rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2261a9de470cSBruce Richardson 	}
2262a9de470cSBruce Richardson 
2263a9de470cSBruce Richardson 	return rc;
2264a9de470cSBruce Richardson }
2265a9de470cSBruce Richardson 
2266a9de470cSBruce Richardson 
2267a9de470cSBruce Richardson static int
2268a9de470cSBruce Richardson crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2269a9de470cSBruce Richardson 		int i)
2270a9de470cSBruce Richardson {
2271a9de470cSBruce Richardson 	uint16_t j;
2272a9de470cSBruce Richardson 
2273a9de470cSBruce Richardson 	for (j = 0; j < BURST_SIZE; j++) {
2274a9de470cSBruce Richardson 		ut_params->pkt_index = j;
2275a9de470cSBruce Richardson 
2276a9de470cSBruce Richardson 		/* compare the data buffers */
2277a9de470cSBruce Richardson 		TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2278a9de470cSBruce Richardson 			rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2279a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
2280a9de470cSBruce Richardson 			"input and output data does not match\n");
2281a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2282a9de470cSBruce Richardson 			ut_params->obuf[j]->pkt_len,
2283a9de470cSBruce Richardson 			"data_len is not equal to pkt_len");
2284a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2285a9de470cSBruce Richardson 			test_cfg[i].pkt_sz,
2286a9de470cSBruce Richardson 			"data_len is not equal to input data");
2287a9de470cSBruce Richardson 	}
2288a9de470cSBruce Richardson 
2289a9de470cSBruce Richardson 	return 0;
2290a9de470cSBruce Richardson }
2291a9de470cSBruce Richardson 
2292a9de470cSBruce Richardson static int
2293a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2294a9de470cSBruce Richardson {
2295a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
2296a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2297a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
2298a9de470cSBruce Richardson 	uint16_t j, r;
2299a9de470cSBruce Richardson 	int rc = 0;
2300a9de470cSBruce Richardson 
2301a9de470cSBruce Richardson 	if (num_pkts != BURST_SIZE)
2302a9de470cSBruce Richardson 		return rc;
2303a9de470cSBruce Richardson 
2304a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
2305a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2306a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2307a9de470cSBruce Richardson 	if (rc != 0) {
23089ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2309a9de470cSBruce Richardson 		return TEST_FAILED;
2310a9de470cSBruce Richardson 	}
2311a9de470cSBruce Richardson 
2312a9de470cSBruce Richardson 	/* create second rte_ipsec_sa */
2313a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2314a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2315a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2316a9de470cSBruce Richardson 	if (rc != 0) {
23179ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2318a9de470cSBruce Richardson 		destroy_sa(0);
2319a9de470cSBruce Richardson 		return TEST_FAILED;
2320a9de470cSBruce Richardson 	}
2321a9de470cSBruce Richardson 
2322a9de470cSBruce Richardson 	/* Generate test mbuf data */
2323a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
2324a9de470cSBruce Richardson 		r = j % 2;
2325a9de470cSBruce Richardson 		/* packet with sequence number 0 is invalid */
2326a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string_tunneled(
2327a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
2328a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2329a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
2330a9de470cSBruce Richardson 			rc = TEST_FAILED;
2331a9de470cSBruce Richardson 	}
2332a9de470cSBruce Richardson 
2333a9de470cSBruce Richardson 	if (rc == 0)
2334a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(num_pkts);
2335a9de470cSBruce Richardson 
2336a9de470cSBruce Richardson 	if (rc == 0) {
2337a9de470cSBruce Richardson 		/* call ipsec library api */
2338a9de470cSBruce Richardson 		rc = crypto_ipsec_2sa();
2339a9de470cSBruce Richardson 		if (rc == 0)
2340a9de470cSBruce Richardson 			rc = crypto_inb_burst_2sa_null_null_check(
2341a9de470cSBruce Richardson 					ut_params, i);
2342a9de470cSBruce Richardson 		else {
2343a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2344a9de470cSBruce Richardson 				i);
2345a9de470cSBruce Richardson 			rc = TEST_FAILED;
2346a9de470cSBruce Richardson 		}
2347a9de470cSBruce Richardson 	}
2348a9de470cSBruce Richardson 
2349a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
2350a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
2351a9de470cSBruce Richardson 
2352a9de470cSBruce Richardson 	destroy_sa(0);
2353a9de470cSBruce Richardson 	destroy_sa(1);
2354a9de470cSBruce Richardson 	return rc;
2355a9de470cSBruce Richardson }
2356a9de470cSBruce Richardson 
2357a9de470cSBruce Richardson static int
2358a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2359a9de470cSBruce Richardson {
2360a9de470cSBruce Richardson 	int i;
2361a9de470cSBruce Richardson 	int rc = 0;
2362a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2363a9de470cSBruce Richardson 
2364a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
2365a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2366a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2367a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2368a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2369a9de470cSBruce Richardson 
2370a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
2371a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2372a9de470cSBruce Richardson 		rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2373a9de470cSBruce Richardson 	}
2374a9de470cSBruce Richardson 
2375a9de470cSBruce Richardson 	return rc;
2376a9de470cSBruce Richardson }
2377a9de470cSBruce Richardson 
2378a9de470cSBruce Richardson static int
2379a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2380a9de470cSBruce Richardson {
2381a9de470cSBruce Richardson 	struct ipsec_testsuite_params *ts_params = &testsuite_params;
2382a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2383a9de470cSBruce Richardson 	uint16_t num_pkts = test_cfg[i].num_pkts;
2384a9de470cSBruce Richardson 	uint16_t j, k;
2385a9de470cSBruce Richardson 	int rc = 0;
2386a9de470cSBruce Richardson 
2387a9de470cSBruce Richardson 	if (num_pkts != BURST_SIZE)
2388a9de470cSBruce Richardson 		return rc;
2389a9de470cSBruce Richardson 
2390a9de470cSBruce Richardson 	/* create rte_ipsec_sa */
2391a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2392a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2393a9de470cSBruce Richardson 	if (rc != 0) {
23949ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2395a9de470cSBruce Richardson 		return TEST_FAILED;
2396a9de470cSBruce Richardson 	}
2397a9de470cSBruce Richardson 
2398a9de470cSBruce Richardson 	/* create second rte_ipsec_sa */
2399a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2400a9de470cSBruce Richardson 	rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2401a9de470cSBruce Richardson 			test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2402a9de470cSBruce Richardson 	if (rc != 0) {
24039ab6ff97SBernard Iremonger 		RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2404a9de470cSBruce Richardson 		destroy_sa(0);
2405a9de470cSBruce Richardson 		return TEST_FAILED;
2406a9de470cSBruce Richardson 	}
2407a9de470cSBruce Richardson 
2408a9de470cSBruce Richardson 	/* Generate test mbuf data */
2409a9de470cSBruce Richardson 	for (j = 0; j < num_pkts && rc == 0; j++) {
2410a9de470cSBruce Richardson 		k = crypto_ipsec_4grp(j);
2411a9de470cSBruce Richardson 
2412a9de470cSBruce Richardson 		/* packet with sequence number 0 is invalid */
2413a9de470cSBruce Richardson 		ut_params->ibuf[j] = setup_test_string_tunneled(
2414a9de470cSBruce Richardson 			ts_params->mbuf_pool, null_encrypted_data,
2415a9de470cSBruce Richardson 			test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
2416a9de470cSBruce Richardson 		if (ut_params->ibuf[j] == NULL)
2417a9de470cSBruce Richardson 			rc = TEST_FAILED;
2418a9de470cSBruce Richardson 	}
2419a9de470cSBruce Richardson 
2420a9de470cSBruce Richardson 	if (rc == 0)
2421a9de470cSBruce Richardson 		rc = test_ipsec_crypto_op_alloc(num_pkts);
2422a9de470cSBruce Richardson 
2423a9de470cSBruce Richardson 	if (rc == 0) {
2424a9de470cSBruce Richardson 		/* call ipsec library api */
2425a9de470cSBruce Richardson 		rc = crypto_ipsec_2sa_4grp();
2426a9de470cSBruce Richardson 		if (rc == 0)
2427a9de470cSBruce Richardson 			rc = crypto_inb_burst_2sa_null_null_check(
2428a9de470cSBruce Richardson 					ut_params, i);
2429a9de470cSBruce Richardson 		else {
2430a9de470cSBruce Richardson 			RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2431a9de470cSBruce Richardson 				i);
2432a9de470cSBruce Richardson 			rc = TEST_FAILED;
2433a9de470cSBruce Richardson 		}
2434a9de470cSBruce Richardson 	}
2435a9de470cSBruce Richardson 
2436a9de470cSBruce Richardson 	if (rc == TEST_FAILED)
2437a9de470cSBruce Richardson 		test_ipsec_dump_buffers(ut_params, i);
2438a9de470cSBruce Richardson 
2439a9de470cSBruce Richardson 	destroy_sa(0);
2440a9de470cSBruce Richardson 	destroy_sa(1);
2441a9de470cSBruce Richardson 	return rc;
2442a9de470cSBruce Richardson }
2443a9de470cSBruce Richardson 
2444a9de470cSBruce Richardson static int
2445a9de470cSBruce Richardson test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
2446a9de470cSBruce Richardson {
2447a9de470cSBruce Richardson 	int i;
2448a9de470cSBruce Richardson 	int rc = 0;
2449a9de470cSBruce Richardson 	struct ipsec_unitest_params *ut_params = &unittest_params;
2450a9de470cSBruce Richardson 
2451a9de470cSBruce Richardson 	ut_params->ipsec_xform.spi = INBOUND_SPI;
2452a9de470cSBruce Richardson 	ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2453a9de470cSBruce Richardson 	ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2454a9de470cSBruce Richardson 	ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2455a9de470cSBruce Richardson 	ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2456a9de470cSBruce Richardson 
2457a9de470cSBruce Richardson 	for (i = 0; i < num_cfg && rc == 0; i++) {
2458a9de470cSBruce Richardson 		ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2459a9de470cSBruce Richardson 		rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
2460a9de470cSBruce Richardson 	}
2461a9de470cSBruce Richardson 
2462a9de470cSBruce Richardson 	return rc;
2463a9de470cSBruce Richardson }
2464a9de470cSBruce Richardson 
2465a9de470cSBruce Richardson static struct unit_test_suite ipsec_testsuite  = {
2466a9de470cSBruce Richardson 	.suite_name = "IPsec NULL Unit Test Suite",
2467a9de470cSBruce Richardson 	.setup = testsuite_setup,
2468a9de470cSBruce Richardson 	.teardown = testsuite_teardown,
2469a9de470cSBruce Richardson 	.unit_test_cases = {
2470a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2471a9de470cSBruce Richardson 			test_ipsec_crypto_inb_burst_null_null_wrapper),
2472a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2473a9de470cSBruce Richardson 			test_ipsec_crypto_outb_burst_null_null_wrapper),
2474a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2475a9de470cSBruce Richardson 			test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
2476a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2477a9de470cSBruce Richardson 			test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
2478a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2479a9de470cSBruce Richardson 			test_ipsec_inline_proto_inb_burst_null_null_wrapper),
2480a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2481a9de470cSBruce Richardson 			test_ipsec_inline_proto_outb_burst_null_null_wrapper),
2482a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2483a9de470cSBruce Richardson 			test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
2484a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2485a9de470cSBruce Richardson 			test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
2486a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2487a9de470cSBruce Richardson 			test_ipsec_replay_inb_inside_null_null_wrapper),
2488a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2489a9de470cSBruce Richardson 			test_ipsec_replay_inb_outside_null_null_wrapper),
2490a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2491a9de470cSBruce Richardson 			test_ipsec_replay_inb_repeat_null_null_wrapper),
2492a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2493a9de470cSBruce Richardson 			test_ipsec_replay_inb_inside_burst_null_null_wrapper),
2494a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2495a9de470cSBruce Richardson 			test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
2496a9de470cSBruce Richardson 		TEST_CASE_ST(ut_setup, ut_teardown,
2497a9de470cSBruce Richardson 			test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
2498a9de470cSBruce Richardson 		TEST_CASES_END() /**< NULL terminate unit test array */
2499a9de470cSBruce Richardson 	}
2500a9de470cSBruce Richardson };
2501a9de470cSBruce Richardson 
2502a9de470cSBruce Richardson static int
2503a9de470cSBruce Richardson test_ipsec(void)
2504a9de470cSBruce Richardson {
2505a9de470cSBruce Richardson 	return unit_test_suite_runner(&ipsec_testsuite);
2506a9de470cSBruce Richardson }
2507a9de470cSBruce Richardson 
2508a9de470cSBruce Richardson REGISTER_TEST_COMMAND(ipsec_autotest, test_ipsec);
2509