xref: /dpdk/app/test/test_security_inline_proto.c (revision 4677de0a4c2ba803d0e1adc26774f2c6c8b5b6df)
186e2487cSAkhil Goyal /* SPDX-License-Identifier: BSD-3-Clause
286e2487cSAkhil Goyal  * Copyright(C) 2022 Marvell.
386e2487cSAkhil Goyal  */
486e2487cSAkhil Goyal 
586e2487cSAkhil Goyal 
686e2487cSAkhil Goyal #include <stdio.h>
786e2487cSAkhil Goyal #include <inttypes.h>
886e2487cSAkhil Goyal 
986e2487cSAkhil Goyal #include <rte_ethdev.h>
1086e2487cSAkhil Goyal #include <rte_malloc.h>
1186e2487cSAkhil Goyal #include <rte_security.h>
1286e2487cSAkhil Goyal 
1386e2487cSAkhil Goyal #include "test.h"
1486e2487cSAkhil Goyal #include "test_security_inline_proto_vectors.h"
151d3a3e18SAnoob Joseph #include "test_security_proto.h"
1686e2487cSAkhil Goyal 
1786e2487cSAkhil Goyal #ifdef RTE_EXEC_ENV_WINDOWS
1886e2487cSAkhil Goyal static int
1986e2487cSAkhil Goyal test_inline_ipsec(void)
2086e2487cSAkhil Goyal {
2186e2487cSAkhil Goyal 	printf("Inline ipsec not supported on Windows, skipping test\n");
2286e2487cSAkhil Goyal 	return TEST_SKIPPED;
2386e2487cSAkhil Goyal }
2486e2487cSAkhil Goyal 
2510864656SVolodymyr Fialko static int
2610864656SVolodymyr Fialko test_event_inline_ipsec(void)
2710864656SVolodymyr Fialko {
2810864656SVolodymyr Fialko 	printf("Event inline ipsec not supported on Windows, skipping test\n");
2910864656SVolodymyr Fialko 	return TEST_SKIPPED;
3010864656SVolodymyr Fialko }
3110864656SVolodymyr Fialko 
323edd1197SNithin Dabilpuram static int
333edd1197SNithin Dabilpuram test_inline_ipsec_sg(void)
343edd1197SNithin Dabilpuram {
353edd1197SNithin Dabilpuram 	printf("Inline ipsec SG not supported on Windows, skipping test\n");
363edd1197SNithin Dabilpuram 	return TEST_SKIPPED;
373edd1197SNithin Dabilpuram }
383edd1197SNithin Dabilpuram 
3986e2487cSAkhil Goyal #else
4086e2487cSAkhil Goyal 
4110864656SVolodymyr Fialko #include <rte_eventdev.h>
4210864656SVolodymyr Fialko #include <rte_event_eth_rx_adapter.h>
4310864656SVolodymyr Fialko #include <rte_event_eth_tx_adapter.h>
4410864656SVolodymyr Fialko 
4586e2487cSAkhil Goyal #define NB_ETHPORTS_USED		1
4686e2487cSAkhil Goyal #define MEMPOOL_CACHE_SIZE		32
4786e2487cSAkhil Goyal #define MAX_PKT_BURST			32
484ed89049SDavid Marchand #define RX_DESC_DEFAULT	1024
494ed89049SDavid Marchand #define TX_DESC_DEFAULT	1024
5086e2487cSAkhil Goyal #define RTE_PORT_ALL		(~(uint16_t)0x0)
5186e2487cSAkhil Goyal 
5286e2487cSAkhil Goyal #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
5386e2487cSAkhil Goyal #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
5486e2487cSAkhil Goyal #define RX_WTHRESH 0 /**< Default values of RX write-back threshold reg. */
5586e2487cSAkhil Goyal 
5686e2487cSAkhil Goyal #define TX_PTHRESH 32 /**< Default values of TX prefetch threshold reg. */
5786e2487cSAkhil Goyal #define TX_HTHRESH 0  /**< Default values of TX host threshold reg. */
5886e2487cSAkhil Goyal #define TX_WTHRESH 0  /**< Default values of TX write-back threshold reg. */
5986e2487cSAkhil Goyal 
6086e2487cSAkhil Goyal #define MAX_TRAFFIC_BURST		2048
6186e2487cSAkhil Goyal #define NB_MBUF				10240
6286e2487cSAkhil Goyal 
63a3105777SAkhil Goyal #define ENCAP_DECAP_BURST_SZ		33
64a3105777SAkhil Goyal #define APP_REASS_TIMEOUT		10
65a3105777SAkhil Goyal 
6686e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_128_gcm;
6786e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_192_gcm;
6886e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_256_gcm;
6986e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_128_gcm_frag;
7086e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_128_cbc_null;
7186e2487cSAkhil Goyal extern struct ipsec_test_data pkt_null_aes_xcbc;
7286e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha384;
7386e2487cSAkhil Goyal extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha512;
74d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_3des_cbc_hmac_sha256;
75d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_3des_cbc_hmac_sha384;
76d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_3des_cbc_hmac_sha512;
77d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_3des_cbc_hmac_sha256_v6;
78d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_des_cbc_hmac_sha256;
79d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_des_cbc_hmac_sha384;
80d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_des_cbc_hmac_sha512;
81d7001863SVidya Sagar Velumuri extern struct ipsec_test_data pkt_des_cbc_hmac_sha256_v6;
825a23f6eaSVidya Sagar Velumuri extern struct ipsec_test_data pkt_aes_128_cbc_md5;
8386e2487cSAkhil Goyal 
8486e2487cSAkhil Goyal static struct rte_mempool *mbufpool;
8586e2487cSAkhil Goyal static struct rte_mempool *sess_pool;
8686e2487cSAkhil Goyal /* ethernet addresses of ports */
8786e2487cSAkhil Goyal static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
8886e2487cSAkhil Goyal 
8986e2487cSAkhil Goyal static struct rte_eth_conf port_conf = {
9086e2487cSAkhil Goyal 	.rxmode = {
9186e2487cSAkhil Goyal 		.mq_mode = RTE_ETH_MQ_RX_NONE,
9286e2487cSAkhil Goyal 		.offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM |
9386e2487cSAkhil Goyal 			    RTE_ETH_RX_OFFLOAD_SECURITY,
9486e2487cSAkhil Goyal 	},
9586e2487cSAkhil Goyal 	.txmode = {
9686e2487cSAkhil Goyal 		.mq_mode = RTE_ETH_MQ_TX_NONE,
9786e2487cSAkhil Goyal 		.offloads = RTE_ETH_TX_OFFLOAD_SECURITY |
9886e2487cSAkhil Goyal 			    RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE,
9986e2487cSAkhil Goyal 	},
10086e2487cSAkhil Goyal 	.lpbk_mode = 1,  /* enable loopback */
10186e2487cSAkhil Goyal };
10286e2487cSAkhil Goyal 
10386e2487cSAkhil Goyal static struct rte_eth_rxconf rx_conf = {
10486e2487cSAkhil Goyal 	.rx_thresh = {
10586e2487cSAkhil Goyal 		.pthresh = RX_PTHRESH,
10686e2487cSAkhil Goyal 		.hthresh = RX_HTHRESH,
10786e2487cSAkhil Goyal 		.wthresh = RX_WTHRESH,
10886e2487cSAkhil Goyal 	},
10986e2487cSAkhil Goyal 	.rx_free_thresh = 32,
11086e2487cSAkhil Goyal };
11186e2487cSAkhil Goyal 
11286e2487cSAkhil Goyal static struct rte_eth_txconf tx_conf = {
11386e2487cSAkhil Goyal 	.tx_thresh = {
11486e2487cSAkhil Goyal 		.pthresh = TX_PTHRESH,
11586e2487cSAkhil Goyal 		.hthresh = TX_HTHRESH,
11686e2487cSAkhil Goyal 		.wthresh = TX_WTHRESH,
11786e2487cSAkhil Goyal 	},
11886e2487cSAkhil Goyal 	.tx_free_thresh = 32, /* Use PMD default values */
11986e2487cSAkhil Goyal 	.tx_rs_thresh = 32, /* Use PMD default values */
12086e2487cSAkhil Goyal };
12186e2487cSAkhil Goyal 
12210864656SVolodymyr Fialko static uint16_t port_id;
12310864656SVolodymyr Fialko static uint8_t eventdev_id;
12410864656SVolodymyr Fialko static uint8_t rx_adapter_id;
12510864656SVolodymyr Fialko static uint8_t tx_adapter_id;
1263edd1197SNithin Dabilpuram static uint16_t plaintext_len;
1273edd1197SNithin Dabilpuram static bool sg_mode;
12810864656SVolodymyr Fialko 
12910864656SVolodymyr Fialko static bool event_mode_enabled;
13086e2487cSAkhil Goyal 
13186e2487cSAkhil Goyal static uint64_t link_mbps;
13286e2487cSAkhil Goyal 
133a3105777SAkhil Goyal static int ip_reassembly_dynfield_offset = -1;
134a3105777SAkhil Goyal 
13586e2487cSAkhil Goyal static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
13686e2487cSAkhil Goyal 
13786e2487cSAkhil Goyal /* Create Inline IPsec session */
13886e2487cSAkhil Goyal static int
13986e2487cSAkhil Goyal create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid,
14079bdb787SAkhil Goyal 		void **sess, void **ctx,
14186e2487cSAkhil Goyal 		uint32_t *ol_flags, const struct ipsec_test_flags *flags,
14286e2487cSAkhil Goyal 		struct rte_security_session_conf *sess_conf)
14386e2487cSAkhil Goyal {
14486e2487cSAkhil Goyal 	uint16_t src_v6[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
14586e2487cSAkhil Goyal 				0x0000, 0x001a};
14686e2487cSAkhil Goyal 	uint16_t dst_v6[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
14786e2487cSAkhil Goyal 				0xe82c, 0x4887};
14886e2487cSAkhil Goyal 	uint32_t src_v4 = rte_cpu_to_be_32(RTE_IPV4(192, 168, 1, 2));
14986e2487cSAkhil Goyal 	uint32_t dst_v4 = rte_cpu_to_be_32(RTE_IPV4(192, 168, 1, 1));
15086e2487cSAkhil Goyal 	struct rte_security_capability_idx sec_cap_idx;
15186e2487cSAkhil Goyal 	const struct rte_security_capability *sec_cap;
15286e2487cSAkhil Goyal 	enum rte_security_ipsec_sa_direction dir;
15379bdb787SAkhil Goyal 	void *sec_ctx;
15486e2487cSAkhil Goyal 	uint32_t verify;
15586e2487cSAkhil Goyal 
15686e2487cSAkhil Goyal 	sess_conf->action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
15786e2487cSAkhil Goyal 	sess_conf->protocol = RTE_SECURITY_PROTOCOL_IPSEC;
15886e2487cSAkhil Goyal 	sess_conf->ipsec = sa->ipsec_xform;
15986e2487cSAkhil Goyal 
16086e2487cSAkhil Goyal 	dir = sa->ipsec_xform.direction;
16186e2487cSAkhil Goyal 	verify = flags->tunnel_hdr_verify;
16286e2487cSAkhil Goyal 
16386e2487cSAkhil Goyal 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
16486e2487cSAkhil Goyal 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
16586e2487cSAkhil Goyal 			src_v4 += 1;
16686e2487cSAkhil Goyal 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
16786e2487cSAkhil Goyal 			dst_v4 += 1;
16886e2487cSAkhil Goyal 	}
16986e2487cSAkhil Goyal 
17086e2487cSAkhil Goyal 	if (sa->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
17186e2487cSAkhil Goyal 		if (sa->ipsec_xform.tunnel.type ==
17286e2487cSAkhil Goyal 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
17386e2487cSAkhil Goyal 			memcpy(&sess_conf->ipsec.tunnel.ipv4.src_ip, &src_v4,
17486e2487cSAkhil Goyal 					sizeof(src_v4));
17586e2487cSAkhil Goyal 			memcpy(&sess_conf->ipsec.tunnel.ipv4.dst_ip, &dst_v4,
17686e2487cSAkhil Goyal 					sizeof(dst_v4));
17786e2487cSAkhil Goyal 
17886e2487cSAkhil Goyal 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
17986e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv4.df = 0;
18086e2487cSAkhil Goyal 
18186e2487cSAkhil Goyal 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
18286e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv4.df = 1;
18386e2487cSAkhil Goyal 
18486e2487cSAkhil Goyal 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
18586e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv4.dscp = 0;
18686e2487cSAkhil Goyal 
18786e2487cSAkhil Goyal 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
18886e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv4.dscp =
18986e2487cSAkhil Goyal 						TEST_IPSEC_DSCP_VAL;
19086e2487cSAkhil Goyal 		} else {
19186e2487cSAkhil Goyal 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
19286e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv6.dscp = 0;
19386e2487cSAkhil Goyal 
19486e2487cSAkhil Goyal 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
19586e2487cSAkhil Goyal 				sess_conf->ipsec.tunnel.ipv6.dscp =
19686e2487cSAkhil Goyal 						TEST_IPSEC_DSCP_VAL;
19786e2487cSAkhil Goyal 
19891d1d052SVamsi Attunuru 			if (flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1)
19991d1d052SVamsi Attunuru 				sess_conf->ipsec.tunnel.ipv6.flabel = 0;
20091d1d052SVamsi Attunuru 
20191d1d052SVamsi Attunuru 			if (flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0)
20291d1d052SVamsi Attunuru 				sess_conf->ipsec.tunnel.ipv6.flabel =
20391d1d052SVamsi Attunuru 						TEST_IPSEC_FLABEL_VAL;
20491d1d052SVamsi Attunuru 
20586e2487cSAkhil Goyal 			memcpy(&sess_conf->ipsec.tunnel.ipv6.src_addr, &src_v6,
20686e2487cSAkhil Goyal 					sizeof(src_v6));
20786e2487cSAkhil Goyal 			memcpy(&sess_conf->ipsec.tunnel.ipv6.dst_addr, &dst_v6,
20886e2487cSAkhil Goyal 					sizeof(dst_v6));
20986e2487cSAkhil Goyal 		}
21086e2487cSAkhil Goyal 	}
21186e2487cSAkhil Goyal 
21286e2487cSAkhil Goyal 	/* Save SA as userdata for the security session. When
21386e2487cSAkhil Goyal 	 * the packet is received, this userdata will be
21486e2487cSAkhil Goyal 	 * retrieved using the metadata from the packet.
21586e2487cSAkhil Goyal 	 *
21686e2487cSAkhil Goyal 	 * The PMD is expected to set similar metadata for other
21786e2487cSAkhil Goyal 	 * operations, like rte_eth_event, which are tied to
21886e2487cSAkhil Goyal 	 * security session. In such cases, the userdata could
21986e2487cSAkhil Goyal 	 * be obtained to uniquely identify the security
22086e2487cSAkhil Goyal 	 * parameters denoted.
22186e2487cSAkhil Goyal 	 */
22286e2487cSAkhil Goyal 
22386e2487cSAkhil Goyal 	sess_conf->userdata = (void *) sa;
22486e2487cSAkhil Goyal 
22579bdb787SAkhil Goyal 	sec_ctx = rte_eth_dev_get_sec_ctx(portid);
22686e2487cSAkhil Goyal 	if (sec_ctx == NULL) {
22786e2487cSAkhil Goyal 		printf("Ethernet device doesn't support security features.\n");
22886e2487cSAkhil Goyal 		return TEST_SKIPPED;
22986e2487cSAkhil Goyal 	}
23086e2487cSAkhil Goyal 
23186e2487cSAkhil Goyal 	sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
23286e2487cSAkhil Goyal 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
23386e2487cSAkhil Goyal 	sec_cap_idx.ipsec.proto = sess_conf->ipsec.proto;
23486e2487cSAkhil Goyal 	sec_cap_idx.ipsec.mode = sess_conf->ipsec.mode;
23586e2487cSAkhil Goyal 	sec_cap_idx.ipsec.direction = sess_conf->ipsec.direction;
23686e2487cSAkhil Goyal 	sec_cap = rte_security_capability_get(sec_ctx, &sec_cap_idx);
23786e2487cSAkhil Goyal 	if (sec_cap == NULL) {
23886e2487cSAkhil Goyal 		printf("No capabilities registered\n");
23986e2487cSAkhil Goyal 		return TEST_SKIPPED;
24086e2487cSAkhil Goyal 	}
24186e2487cSAkhil Goyal 
24286e2487cSAkhil Goyal 	if (sa->aead || sa->aes_gmac)
24386e2487cSAkhil Goyal 		memcpy(&sess_conf->ipsec.salt, sa->salt.data,
24486e2487cSAkhil Goyal 			RTE_MIN(sizeof(sess_conf->ipsec.salt), sa->salt.len));
24586e2487cSAkhil Goyal 
24686e2487cSAkhil Goyal 	/* Copy cipher session parameters */
24786e2487cSAkhil Goyal 	if (sa->aead) {
24886e2487cSAkhil Goyal 		rte_memcpy(sess_conf->crypto_xform, &sa->xform.aead,
24986e2487cSAkhil Goyal 				sizeof(struct rte_crypto_sym_xform));
25086e2487cSAkhil Goyal 		sess_conf->crypto_xform->aead.key.data = sa->key.data;
25186e2487cSAkhil Goyal 		/* Verify crypto capabilities */
2521d3a3e18SAnoob Joseph 		if (test_sec_crypto_caps_aead_verify(sec_cap, sess_conf->crypto_xform) != 0) {
25386e2487cSAkhil Goyal 			RTE_LOG(INFO, USER1,
25486e2487cSAkhil Goyal 				"Crypto capabilities not supported\n");
25586e2487cSAkhil Goyal 			return TEST_SKIPPED;
25686e2487cSAkhil Goyal 		}
25786e2487cSAkhil Goyal 	} else {
25886e2487cSAkhil Goyal 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
25986e2487cSAkhil Goyal 			rte_memcpy(&sess_conf->crypto_xform->cipher,
26086e2487cSAkhil Goyal 					&sa->xform.chain.cipher.cipher,
26186e2487cSAkhil Goyal 					sizeof(struct rte_crypto_cipher_xform));
26286e2487cSAkhil Goyal 
26386e2487cSAkhil Goyal 			rte_memcpy(&sess_conf->crypto_xform->next->auth,
26486e2487cSAkhil Goyal 					&sa->xform.chain.auth.auth,
26586e2487cSAkhil Goyal 					sizeof(struct rte_crypto_auth_xform));
26686e2487cSAkhil Goyal 			sess_conf->crypto_xform->cipher.key.data =
26786e2487cSAkhil Goyal 							sa->key.data;
26886e2487cSAkhil Goyal 			sess_conf->crypto_xform->next->auth.key.data =
26986e2487cSAkhil Goyal 							sa->auth_key.data;
27086e2487cSAkhil Goyal 			/* Verify crypto capabilities */
2711d3a3e18SAnoob Joseph 			if (test_sec_crypto_caps_cipher_verify(sec_cap,
27286e2487cSAkhil Goyal 					sess_conf->crypto_xform) != 0) {
27386e2487cSAkhil Goyal 				RTE_LOG(INFO, USER1,
27486e2487cSAkhil Goyal 					"Cipher crypto capabilities not supported\n");
27586e2487cSAkhil Goyal 				return TEST_SKIPPED;
27686e2487cSAkhil Goyal 			}
27786e2487cSAkhil Goyal 
2781d3a3e18SAnoob Joseph 			if (test_sec_crypto_caps_auth_verify(sec_cap,
27986e2487cSAkhil Goyal 					sess_conf->crypto_xform->next) != 0) {
28086e2487cSAkhil Goyal 				RTE_LOG(INFO, USER1,
28186e2487cSAkhil Goyal 					"Auth crypto capabilities not supported\n");
28286e2487cSAkhil Goyal 				return TEST_SKIPPED;
28386e2487cSAkhil Goyal 			}
28486e2487cSAkhil Goyal 		} else {
28586e2487cSAkhil Goyal 			rte_memcpy(&sess_conf->crypto_xform->next->cipher,
28686e2487cSAkhil Goyal 					&sa->xform.chain.cipher.cipher,
28786e2487cSAkhil Goyal 					sizeof(struct rte_crypto_cipher_xform));
28886e2487cSAkhil Goyal 			rte_memcpy(&sess_conf->crypto_xform->auth,
28986e2487cSAkhil Goyal 					&sa->xform.chain.auth.auth,
29086e2487cSAkhil Goyal 					sizeof(struct rte_crypto_auth_xform));
29186e2487cSAkhil Goyal 			sess_conf->crypto_xform->auth.key.data =
29286e2487cSAkhil Goyal 							sa->auth_key.data;
29386e2487cSAkhil Goyal 			sess_conf->crypto_xform->next->cipher.key.data =
29486e2487cSAkhil Goyal 							sa->key.data;
29586e2487cSAkhil Goyal 
29686e2487cSAkhil Goyal 			/* Verify crypto capabilities */
2971d3a3e18SAnoob Joseph 			if (test_sec_crypto_caps_cipher_verify(sec_cap,
29886e2487cSAkhil Goyal 					sess_conf->crypto_xform->next) != 0) {
29986e2487cSAkhil Goyal 				RTE_LOG(INFO, USER1,
30086e2487cSAkhil Goyal 					"Cipher crypto capabilities not supported\n");
30186e2487cSAkhil Goyal 				return TEST_SKIPPED;
30286e2487cSAkhil Goyal 			}
30386e2487cSAkhil Goyal 
3041d3a3e18SAnoob Joseph 			if (test_sec_crypto_caps_auth_verify(sec_cap,
30586e2487cSAkhil Goyal 					sess_conf->crypto_xform) != 0) {
30686e2487cSAkhil Goyal 				RTE_LOG(INFO, USER1,
30786e2487cSAkhil Goyal 					"Auth crypto capabilities not supported\n");
30886e2487cSAkhil Goyal 				return TEST_SKIPPED;
30986e2487cSAkhil Goyal 			}
31086e2487cSAkhil Goyal 		}
31186e2487cSAkhil Goyal 	}
31286e2487cSAkhil Goyal 
31386e2487cSAkhil Goyal 	if (test_ipsec_sec_caps_verify(&sess_conf->ipsec, sec_cap, false) != 0)
31486e2487cSAkhil Goyal 		return TEST_SKIPPED;
31586e2487cSAkhil Goyal 
31686e2487cSAkhil Goyal 	if ((sa->ipsec_xform.direction ==
31786e2487cSAkhil Goyal 			RTE_SECURITY_IPSEC_SA_DIR_EGRESS) &&
31886e2487cSAkhil Goyal 			(sa->ipsec_xform.options.iv_gen_disable == 1)) {
31986e2487cSAkhil Goyal 		/* Set env variable when IV generation is disabled */
32086e2487cSAkhil Goyal 		char arr[128];
32186e2487cSAkhil Goyal 		int len = 0, j = 0;
32286e2487cSAkhil Goyal 		int iv_len = (sa->aead || sa->aes_gmac) ? 8 : 16;
32386e2487cSAkhil Goyal 
32486e2487cSAkhil Goyal 		for (; j < iv_len; j++)
32586e2487cSAkhil Goyal 			len += snprintf(arr+len, sizeof(arr) - len,
32686e2487cSAkhil Goyal 					"0x%x, ", sa->iv.data[j]);
32786e2487cSAkhil Goyal 		setenv("ETH_SEC_IV_OVR", arr, 1);
32886e2487cSAkhil Goyal 	}
32986e2487cSAkhil Goyal 
3303f3fc330SAkhil Goyal 	*sess = rte_security_session_create(sec_ctx, sess_conf, sess_pool);
33186e2487cSAkhil Goyal 	if (*sess == NULL) {
33286e2487cSAkhil Goyal 		printf("SEC Session init failed.\n");
33386e2487cSAkhil Goyal 		return TEST_FAILED;
33486e2487cSAkhil Goyal 	}
33586e2487cSAkhil Goyal 
33686e2487cSAkhil Goyal 	*ol_flags = sec_cap->ol_flags;
33786e2487cSAkhil Goyal 	*ctx = sec_ctx;
33886e2487cSAkhil Goyal 
33986e2487cSAkhil Goyal 	return 0;
34086e2487cSAkhil Goyal }
34186e2487cSAkhil Goyal 
34286e2487cSAkhil Goyal /* Check the link status of all ports in up to 3s, and print them finally */
34386e2487cSAkhil Goyal static void
34486e2487cSAkhil Goyal check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
34586e2487cSAkhil Goyal {
34686e2487cSAkhil Goyal #define CHECK_INTERVAL 100 /* 100ms */
34786e2487cSAkhil Goyal #define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */
34886e2487cSAkhil Goyal 	uint16_t portid;
34986e2487cSAkhil Goyal 	uint8_t count, all_ports_up, print_flag = 0;
35086e2487cSAkhil Goyal 	struct rte_eth_link link;
35186e2487cSAkhil Goyal 	int ret;
35286e2487cSAkhil Goyal 	char link_status[RTE_ETH_LINK_MAX_STR_LEN];
35386e2487cSAkhil Goyal 
35486e2487cSAkhil Goyal 	printf("Checking link statuses...\n");
35586e2487cSAkhil Goyal 	fflush(stdout);
35686e2487cSAkhil Goyal 	for (count = 0; count <= MAX_CHECK_TIME; count++) {
35786e2487cSAkhil Goyal 		all_ports_up = 1;
35886e2487cSAkhil Goyal 		for (portid = 0; portid < port_num; portid++) {
35986e2487cSAkhil Goyal 			if ((port_mask & (1 << portid)) == 0)
36086e2487cSAkhil Goyal 				continue;
36186e2487cSAkhil Goyal 			memset(&link, 0, sizeof(link));
36286e2487cSAkhil Goyal 			ret = rte_eth_link_get_nowait(portid, &link);
36386e2487cSAkhil Goyal 			if (ret < 0) {
36486e2487cSAkhil Goyal 				all_ports_up = 0;
36586e2487cSAkhil Goyal 				if (print_flag == 1)
36686e2487cSAkhil Goyal 					printf("Port %u link get failed: %s\n",
36786e2487cSAkhil Goyal 						portid, rte_strerror(-ret));
36886e2487cSAkhil Goyal 				continue;
36986e2487cSAkhil Goyal 			}
37086e2487cSAkhil Goyal 
37186e2487cSAkhil Goyal 			/* print link status if flag set */
37286e2487cSAkhil Goyal 			if (print_flag == 1) {
37386e2487cSAkhil Goyal 				if (link.link_status && link_mbps == 0)
37486e2487cSAkhil Goyal 					link_mbps = link.link_speed;
37586e2487cSAkhil Goyal 
37686e2487cSAkhil Goyal 				rte_eth_link_to_str(link_status,
37786e2487cSAkhil Goyal 					sizeof(link_status), &link);
37886e2487cSAkhil Goyal 				printf("Port %d %s\n", portid, link_status);
37986e2487cSAkhil Goyal 				continue;
38086e2487cSAkhil Goyal 			}
38186e2487cSAkhil Goyal 			/* clear all_ports_up flag if any link down */
38286e2487cSAkhil Goyal 			if (link.link_status == RTE_ETH_LINK_DOWN) {
38386e2487cSAkhil Goyal 				all_ports_up = 0;
38486e2487cSAkhil Goyal 				break;
38586e2487cSAkhil Goyal 			}
38686e2487cSAkhil Goyal 		}
38786e2487cSAkhil Goyal 		/* after finally printing all link status, get out */
38886e2487cSAkhil Goyal 		if (print_flag == 1)
38986e2487cSAkhil Goyal 			break;
39086e2487cSAkhil Goyal 
39186e2487cSAkhil Goyal 		if (all_ports_up == 0) {
39286e2487cSAkhil Goyal 			fflush(stdout);
39386e2487cSAkhil Goyal 			rte_delay_ms(CHECK_INTERVAL);
39486e2487cSAkhil Goyal 		}
39586e2487cSAkhil Goyal 
39686e2487cSAkhil Goyal 		/* set the print_flag if all ports up or timeout */
39786e2487cSAkhil Goyal 		if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1))
39886e2487cSAkhil Goyal 			print_flag = 1;
39986e2487cSAkhil Goyal 	}
40086e2487cSAkhil Goyal }
40186e2487cSAkhil Goyal 
40286e2487cSAkhil Goyal static void
40386e2487cSAkhil Goyal print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
40486e2487cSAkhil Goyal {
40586e2487cSAkhil Goyal 	char buf[RTE_ETHER_ADDR_FMT_SIZE];
40686e2487cSAkhil Goyal 	rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
40786e2487cSAkhil Goyal 	printf("%s%s", name, buf);
40886e2487cSAkhil Goyal }
40986e2487cSAkhil Goyal 
41086e2487cSAkhil Goyal static void
41186e2487cSAkhil Goyal copy_buf_to_pkt_segs(const uint8_t *buf, unsigned int len,
41286e2487cSAkhil Goyal 		     struct rte_mbuf *pkt, unsigned int offset)
41386e2487cSAkhil Goyal {
41486e2487cSAkhil Goyal 	unsigned int copied = 0;
41586e2487cSAkhil Goyal 	unsigned int copy_len;
41686e2487cSAkhil Goyal 	struct rte_mbuf *seg;
41786e2487cSAkhil Goyal 	void *seg_buf;
41886e2487cSAkhil Goyal 
41986e2487cSAkhil Goyal 	seg = pkt;
4203edd1197SNithin Dabilpuram 	while (offset >= rte_pktmbuf_tailroom(seg)) {
4213edd1197SNithin Dabilpuram 		offset -= rte_pktmbuf_tailroom(seg);
42286e2487cSAkhil Goyal 		seg = seg->next;
42386e2487cSAkhil Goyal 	}
4243edd1197SNithin Dabilpuram 	copy_len = seg->buf_len - seg->data_off - offset;
42586e2487cSAkhil Goyal 	seg_buf = rte_pktmbuf_mtod_offset(seg, char *, offset);
42686e2487cSAkhil Goyal 	while (len > copy_len) {
42786e2487cSAkhil Goyal 		rte_memcpy(seg_buf, buf + copied, (size_t) copy_len);
42886e2487cSAkhil Goyal 		len -= copy_len;
42986e2487cSAkhil Goyal 		copied += copy_len;
4303edd1197SNithin Dabilpuram 		seg->data_len += copy_len;
4313edd1197SNithin Dabilpuram 
43286e2487cSAkhil Goyal 		seg = seg->next;
4333edd1197SNithin Dabilpuram 		copy_len = seg->buf_len - seg->data_off;
43486e2487cSAkhil Goyal 		seg_buf = rte_pktmbuf_mtod(seg, void *);
43586e2487cSAkhil Goyal 	}
43686e2487cSAkhil Goyal 	rte_memcpy(seg_buf, buf + copied, (size_t) len);
4373edd1197SNithin Dabilpuram 	seg->data_len = len;
4383edd1197SNithin Dabilpuram 
4393edd1197SNithin Dabilpuram 	pkt->pkt_len += copied + len;
44086e2487cSAkhil Goyal }
44186e2487cSAkhil Goyal 
442c215f6cdSNithin Dabilpuram static bool
443c215f6cdSNithin Dabilpuram is_outer_ipv4(struct ipsec_test_data *td)
444c215f6cdSNithin Dabilpuram {
445c215f6cdSNithin Dabilpuram 	bool outer_ipv4;
446c215f6cdSNithin Dabilpuram 
447c215f6cdSNithin Dabilpuram 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS ||
448c215f6cdSNithin Dabilpuram 	    td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT)
449c215f6cdSNithin Dabilpuram 		outer_ipv4 = (((td->input_text.data[0] & 0xF0) >> 4) == IPVERSION);
450c215f6cdSNithin Dabilpuram 	else
451c215f6cdSNithin Dabilpuram 		outer_ipv4 = (td->ipsec_xform.tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4);
452c215f6cdSNithin Dabilpuram 	return outer_ipv4;
453c215f6cdSNithin Dabilpuram }
454c215f6cdSNithin Dabilpuram 
45586e2487cSAkhil Goyal static inline struct rte_mbuf *
456c215f6cdSNithin Dabilpuram init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, bool outer_ipv4)
45786e2487cSAkhil Goyal {
4583edd1197SNithin Dabilpuram 	struct rte_mbuf *pkt, *tail;
4593edd1197SNithin Dabilpuram 	uint16_t space;
46086e2487cSAkhil Goyal 
46186e2487cSAkhil Goyal 	pkt = rte_pktmbuf_alloc(mp);
46286e2487cSAkhil Goyal 	if (pkt == NULL)
46386e2487cSAkhil Goyal 		return NULL;
464c215f6cdSNithin Dabilpuram 
465c215f6cdSNithin Dabilpuram 	if (outer_ipv4) {
46686e2487cSAkhil Goyal 		rte_memcpy(rte_pktmbuf_append(pkt, RTE_ETHER_HDR_LEN),
46786e2487cSAkhil Goyal 				&dummy_ipv4_eth_hdr, RTE_ETHER_HDR_LEN);
46886e2487cSAkhil Goyal 		pkt->l3_len = sizeof(struct rte_ipv4_hdr);
46986e2487cSAkhil Goyal 	} else {
47086e2487cSAkhil Goyal 		rte_memcpy(rte_pktmbuf_append(pkt, RTE_ETHER_HDR_LEN),
47186e2487cSAkhil Goyal 				&dummy_ipv6_eth_hdr, RTE_ETHER_HDR_LEN);
47286e2487cSAkhil Goyal 		pkt->l3_len = sizeof(struct rte_ipv6_hdr);
47386e2487cSAkhil Goyal 	}
47486e2487cSAkhil Goyal 	pkt->l2_len = RTE_ETHER_HDR_LEN;
47586e2487cSAkhil Goyal 
4763edd1197SNithin Dabilpuram 	space = rte_pktmbuf_tailroom(pkt);
4773edd1197SNithin Dabilpuram 	tail = pkt;
4783edd1197SNithin Dabilpuram 	/* Error if SG mode is not enabled */
4793edd1197SNithin Dabilpuram 	if (!sg_mode && space < len) {
4803edd1197SNithin Dabilpuram 		rte_pktmbuf_free(pkt);
4813edd1197SNithin Dabilpuram 		return NULL;
4823edd1197SNithin Dabilpuram 	}
4833edd1197SNithin Dabilpuram 	/* Extra room for expansion */
4843edd1197SNithin Dabilpuram 	while (space < len) {
4853edd1197SNithin Dabilpuram 		tail->next = rte_pktmbuf_alloc(mp);
4863edd1197SNithin Dabilpuram 		if (!tail->next)
4873edd1197SNithin Dabilpuram 			goto error;
4883edd1197SNithin Dabilpuram 		tail = tail->next;
4893edd1197SNithin Dabilpuram 		space += rte_pktmbuf_tailroom(tail);
4903edd1197SNithin Dabilpuram 		pkt->nb_segs++;
4913edd1197SNithin Dabilpuram 	}
4923edd1197SNithin Dabilpuram 
4933edd1197SNithin Dabilpuram 	if (pkt->buf_len > len + RTE_ETHER_HDR_LEN)
49486e2487cSAkhil Goyal 		rte_memcpy(rte_pktmbuf_append(pkt, len), data, len);
49586e2487cSAkhil Goyal 	else
49686e2487cSAkhil Goyal 		copy_buf_to_pkt_segs(data, len, pkt, RTE_ETHER_HDR_LEN);
49786e2487cSAkhil Goyal 	return pkt;
4983edd1197SNithin Dabilpuram error:
4993edd1197SNithin Dabilpuram 	rte_pktmbuf_free(pkt);
5003edd1197SNithin Dabilpuram 	return NULL;
50186e2487cSAkhil Goyal }
50286e2487cSAkhil Goyal 
50386e2487cSAkhil Goyal static int
50486e2487cSAkhil Goyal init_mempools(unsigned int nb_mbuf)
50586e2487cSAkhil Goyal {
50679bdb787SAkhil Goyal 	void *sec_ctx;
50786e2487cSAkhil Goyal 	uint16_t nb_sess = 512;
50886e2487cSAkhil Goyal 	uint32_t sess_sz;
50986e2487cSAkhil Goyal 	char s[64];
51086e2487cSAkhil Goyal 
51186e2487cSAkhil Goyal 	if (mbufpool == NULL) {
51286e2487cSAkhil Goyal 		snprintf(s, sizeof(s), "mbuf_pool");
51386e2487cSAkhil Goyal 		mbufpool = rte_pktmbuf_pool_create(s, nb_mbuf,
5143edd1197SNithin Dabilpuram 				MEMPOOL_CACHE_SIZE, RTE_CACHE_LINE_SIZE,
51586e2487cSAkhil Goyal 				RTE_MBUF_DEFAULT_BUF_SIZE, SOCKET_ID_ANY);
51686e2487cSAkhil Goyal 		if (mbufpool == NULL) {
51786e2487cSAkhil Goyal 			printf("Cannot init mbuf pool\n");
51886e2487cSAkhil Goyal 			return TEST_FAILED;
51986e2487cSAkhil Goyal 		}
52086e2487cSAkhil Goyal 		printf("Allocated mbuf pool\n");
52186e2487cSAkhil Goyal 	}
52286e2487cSAkhil Goyal 
52386e2487cSAkhil Goyal 	sec_ctx = rte_eth_dev_get_sec_ctx(port_id);
52486e2487cSAkhil Goyal 	if (sec_ctx == NULL) {
52586e2487cSAkhil Goyal 		printf("Device does not support Security ctx\n");
52686e2487cSAkhil Goyal 		return TEST_SKIPPED;
52786e2487cSAkhil Goyal 	}
52886e2487cSAkhil Goyal 	sess_sz = rte_security_session_get_size(sec_ctx);
52986e2487cSAkhil Goyal 	if (sess_pool == NULL) {
53086e2487cSAkhil Goyal 		snprintf(s, sizeof(s), "sess_pool");
53186e2487cSAkhil Goyal 		sess_pool = rte_mempool_create(s, nb_sess, sess_sz,
53286e2487cSAkhil Goyal 				MEMPOOL_CACHE_SIZE, 0,
53386e2487cSAkhil Goyal 				NULL, NULL, NULL, NULL,
53486e2487cSAkhil Goyal 				SOCKET_ID_ANY, 0);
53586e2487cSAkhil Goyal 		if (sess_pool == NULL) {
53686e2487cSAkhil Goyal 			printf("Cannot init sess pool\n");
53786e2487cSAkhil Goyal 			return TEST_FAILED;
53886e2487cSAkhil Goyal 		}
53986e2487cSAkhil Goyal 		printf("Allocated sess pool\n");
54086e2487cSAkhil Goyal 	}
54186e2487cSAkhil Goyal 
54286e2487cSAkhil Goyal 	return 0;
54386e2487cSAkhil Goyal }
54486e2487cSAkhil Goyal 
54586e2487cSAkhil Goyal static int
54686e2487cSAkhil Goyal create_default_flow(uint16_t portid)
54786e2487cSAkhil Goyal {
54886e2487cSAkhil Goyal 	struct rte_flow_action action[2];
54986e2487cSAkhil Goyal 	struct rte_flow_item pattern[2];
55086e2487cSAkhil Goyal 	struct rte_flow_attr attr = {0};
55186e2487cSAkhil Goyal 	struct rte_flow_error err;
55286e2487cSAkhil Goyal 	struct rte_flow *flow;
55386e2487cSAkhil Goyal 	int ret;
55486e2487cSAkhil Goyal 
55586e2487cSAkhil Goyal 	/* Add the default rte_flow to enable SECURITY for all ESP packets */
55686e2487cSAkhil Goyal 
55786e2487cSAkhil Goyal 	pattern[0].type = RTE_FLOW_ITEM_TYPE_ESP;
55886e2487cSAkhil Goyal 	pattern[0].spec = NULL;
55986e2487cSAkhil Goyal 	pattern[0].mask = NULL;
56086e2487cSAkhil Goyal 	pattern[0].last = NULL;
56186e2487cSAkhil Goyal 	pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
56286e2487cSAkhil Goyal 
56386e2487cSAkhil Goyal 	action[0].type = RTE_FLOW_ACTION_TYPE_SECURITY;
56486e2487cSAkhil Goyal 	action[0].conf = NULL;
56586e2487cSAkhil Goyal 	action[1].type = RTE_FLOW_ACTION_TYPE_END;
56686e2487cSAkhil Goyal 	action[1].conf = NULL;
56786e2487cSAkhil Goyal 
56886e2487cSAkhil Goyal 	attr.ingress = 1;
56986e2487cSAkhil Goyal 
57086e2487cSAkhil Goyal 	ret = rte_flow_validate(portid, &attr, pattern, action, &err);
57186e2487cSAkhil Goyal 	if (ret) {
57286e2487cSAkhil Goyal 		printf("\nValidate flow failed, ret = %d\n", ret);
57386e2487cSAkhil Goyal 		return -1;
57486e2487cSAkhil Goyal 	}
57586e2487cSAkhil Goyal 	flow = rte_flow_create(portid, &attr, pattern, action, &err);
57686e2487cSAkhil Goyal 	if (flow == NULL) {
57786e2487cSAkhil Goyal 		printf("\nDefault flow rule create failed\n");
57886e2487cSAkhil Goyal 		return -1;
57986e2487cSAkhil Goyal 	}
58086e2487cSAkhil Goyal 
58186e2487cSAkhil Goyal 	default_flow[portid] = flow;
58286e2487cSAkhil Goyal 
58386e2487cSAkhil Goyal 	return 0;
58486e2487cSAkhil Goyal }
58586e2487cSAkhil Goyal 
58686e2487cSAkhil Goyal static void
58786e2487cSAkhil Goyal destroy_default_flow(uint16_t portid)
58886e2487cSAkhil Goyal {
58986e2487cSAkhil Goyal 	struct rte_flow_error err;
59086e2487cSAkhil Goyal 	int ret;
59186e2487cSAkhil Goyal 
59286e2487cSAkhil Goyal 	if (!default_flow[portid])
59386e2487cSAkhil Goyal 		return;
59486e2487cSAkhil Goyal 	ret = rte_flow_destroy(portid, default_flow[portid], &err);
59586e2487cSAkhil Goyal 	if (ret) {
59686e2487cSAkhil Goyal 		printf("\nDefault flow rule destroy failed\n");
59786e2487cSAkhil Goyal 		return;
59886e2487cSAkhil Goyal 	}
59986e2487cSAkhil Goyal 	default_flow[portid] = NULL;
60086e2487cSAkhil Goyal }
60186e2487cSAkhil Goyal 
60286e2487cSAkhil Goyal struct rte_mbuf **tx_pkts_burst;
60386e2487cSAkhil Goyal struct rte_mbuf **rx_pkts_burst;
60486e2487cSAkhil Goyal 
60586e2487cSAkhil Goyal static int
606a3105777SAkhil Goyal compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
607a3105777SAkhil Goyal {
608a3105777SAkhil Goyal 	unsigned int len;
609a3105777SAkhil Goyal 	unsigned int nb_segs = m->nb_segs;
610a3105777SAkhil Goyal 	unsigned int matched = 0;
611a3105777SAkhil Goyal 	struct rte_mbuf *save = m;
612a3105777SAkhil Goyal 
613a3105777SAkhil Goyal 	while (m) {
614a3105777SAkhil Goyal 		len = tot_len;
615a3105777SAkhil Goyal 		if (len > m->data_len)
616a3105777SAkhil Goyal 			len = m->data_len;
617a3105777SAkhil Goyal 		if (len != 0) {
618a3105777SAkhil Goyal 			if (memcmp(rte_pktmbuf_mtod(m, char *),
619a3105777SAkhil Goyal 					ref + matched, len)) {
620a3105777SAkhil Goyal 				printf("\n====Reassembly case failed: Data Mismatch");
621a3105777SAkhil Goyal 				rte_hexdump(stdout, "Reassembled",
622a3105777SAkhil Goyal 					rte_pktmbuf_mtod(m, char *),
623a3105777SAkhil Goyal 					len);
624a3105777SAkhil Goyal 				rte_hexdump(stdout, "reference",
625a3105777SAkhil Goyal 					ref + matched,
626a3105777SAkhil Goyal 					len);
627a3105777SAkhil Goyal 				return TEST_FAILED;
628a3105777SAkhil Goyal 			}
629a3105777SAkhil Goyal 		}
630a3105777SAkhil Goyal 		tot_len -= len;
631a3105777SAkhil Goyal 		matched += len;
632a3105777SAkhil Goyal 		m = m->next;
633a3105777SAkhil Goyal 	}
634a3105777SAkhil Goyal 
635a3105777SAkhil Goyal 	if (tot_len) {
636a3105777SAkhil Goyal 		printf("\n====Reassembly case failed: Data Missing %u",
637a3105777SAkhil Goyal 		       tot_len);
638a3105777SAkhil Goyal 		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
639a3105777SAkhil Goyal 		rte_pktmbuf_dump(stderr, save, -1);
640a3105777SAkhil Goyal 		return TEST_FAILED;
641a3105777SAkhil Goyal 	}
642a3105777SAkhil Goyal 	return TEST_SUCCESS;
643a3105777SAkhil Goyal }
644a3105777SAkhil Goyal 
645a3105777SAkhil Goyal static inline bool
646a3105777SAkhil Goyal is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
647a3105777SAkhil Goyal {
648a3105777SAkhil Goyal 	static uint64_t ip_reassembly_dynflag;
649a3105777SAkhil Goyal 	int ip_reassembly_dynflag_offset;
650a3105777SAkhil Goyal 
651a3105777SAkhil Goyal 	if (ip_reassembly_dynflag == 0) {
652a3105777SAkhil Goyal 		ip_reassembly_dynflag_offset = rte_mbuf_dynflag_lookup(
653a3105777SAkhil Goyal 			RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME, NULL);
654a3105777SAkhil Goyal 		if (ip_reassembly_dynflag_offset < 0)
655a3105777SAkhil Goyal 			return false;
656a3105777SAkhil Goyal 		ip_reassembly_dynflag = RTE_BIT64(ip_reassembly_dynflag_offset);
657a3105777SAkhil Goyal 	}
658a3105777SAkhil Goyal 
659a3105777SAkhil Goyal 	return (mbuf->ol_flags & ip_reassembly_dynflag) != 0;
660a3105777SAkhil Goyal }
661a3105777SAkhil Goyal 
662a3105777SAkhil Goyal static void
663a3105777SAkhil Goyal free_mbuf(struct rte_mbuf *mbuf)
664a3105777SAkhil Goyal {
665a3105777SAkhil Goyal 	rte_eth_ip_reassembly_dynfield_t dynfield;
666a3105777SAkhil Goyal 
667a3105777SAkhil Goyal 	if (!mbuf)
668a3105777SAkhil Goyal 		return;
669a3105777SAkhil Goyal 
670a3105777SAkhil Goyal 	if (!is_ip_reassembly_incomplete(mbuf)) {
671a3105777SAkhil Goyal 		rte_pktmbuf_free(mbuf);
672a3105777SAkhil Goyal 	} else {
673a3105777SAkhil Goyal 		if (ip_reassembly_dynfield_offset < 0)
674a3105777SAkhil Goyal 			return;
675a3105777SAkhil Goyal 
676a3105777SAkhil Goyal 		while (mbuf) {
677a3105777SAkhil Goyal 			dynfield = *RTE_MBUF_DYNFIELD(mbuf,
678a3105777SAkhil Goyal 					ip_reassembly_dynfield_offset,
679a3105777SAkhil Goyal 					rte_eth_ip_reassembly_dynfield_t *);
680a3105777SAkhil Goyal 			rte_pktmbuf_free(mbuf);
6812f97b943SRahul Bhansali 			if (dynfield.nb_frags == 0)
6822f97b943SRahul Bhansali 				break;
683a3105777SAkhil Goyal 			mbuf = dynfield.next_frag;
684a3105777SAkhil Goyal 		}
685a3105777SAkhil Goyal 	}
686a3105777SAkhil Goyal }
687a3105777SAkhil Goyal 
688a3105777SAkhil Goyal 
689a3105777SAkhil Goyal static int
690a3105777SAkhil Goyal get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
691a3105777SAkhil Goyal 				struct reassembly_vector *vector)
692a3105777SAkhil Goyal {
693a3105777SAkhil Goyal 	rte_eth_ip_reassembly_dynfield_t *dynfield[MAX_PKT_BURST];
694a3105777SAkhil Goyal 	int j = 0, ret;
695a3105777SAkhil Goyal 	/**
696a3105777SAkhil Goyal 	 * IP reassembly offload is incomplete, and fragments are listed in
697a3105777SAkhil Goyal 	 * dynfield which can be reassembled in SW.
698a3105777SAkhil Goyal 	 */
699a3105777SAkhil Goyal 	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
700a3105777SAkhil Goyal 		"\nMatching with original frags.");
701a3105777SAkhil Goyal 
702a3105777SAkhil Goyal 	if (ip_reassembly_dynfield_offset < 0)
703a3105777SAkhil Goyal 		return -1;
704a3105777SAkhil Goyal 
705a3105777SAkhil Goyal 	printf("\ncomparing frag: %d", j);
706a3105777SAkhil Goyal 	/* Skip Ethernet header comparison */
707a3105777SAkhil Goyal 	rte_pktmbuf_adj(mbuf, RTE_ETHER_HDR_LEN);
708a3105777SAkhil Goyal 	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
709a3105777SAkhil Goyal 				vector->frags[j]->len);
710a3105777SAkhil Goyal 	if (ret)
711a3105777SAkhil Goyal 		return ret;
712a3105777SAkhil Goyal 	j++;
713a3105777SAkhil Goyal 	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reassembly_dynfield_offset,
714a3105777SAkhil Goyal 					rte_eth_ip_reassembly_dynfield_t *);
715a3105777SAkhil Goyal 	printf("\ncomparing frag: %d", j);
716a3105777SAkhil Goyal 	/* Skip Ethernet header comparison */
717a3105777SAkhil Goyal 	rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
718a3105777SAkhil Goyal 	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
719a3105777SAkhil Goyal 			vector->frags[j]->len);
720a3105777SAkhil Goyal 	if (ret)
721a3105777SAkhil Goyal 		return ret;
722a3105777SAkhil Goyal 
723a3105777SAkhil Goyal 	while ((dynfield[j]->nb_frags > 1) &&
724a3105777SAkhil Goyal 			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
725a3105777SAkhil Goyal 		j++;
726a3105777SAkhil Goyal 		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
727a3105777SAkhil Goyal 					ip_reassembly_dynfield_offset,
728a3105777SAkhil Goyal 					rte_eth_ip_reassembly_dynfield_t *);
729a3105777SAkhil Goyal 		printf("\ncomparing frag: %d", j);
730a3105777SAkhil Goyal 		/* Skip Ethernet header comparison */
731a3105777SAkhil Goyal 		rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
732a3105777SAkhil Goyal 		ret = compare_pkt_data(dynfield[j]->next_frag,
733a3105777SAkhil Goyal 				vector->frags[j]->data, vector->frags[j]->len);
734a3105777SAkhil Goyal 		if (ret)
735a3105777SAkhil Goyal 			return ret;
736a3105777SAkhil Goyal 	}
737a3105777SAkhil Goyal 	return ret;
738a3105777SAkhil Goyal }
739a3105777SAkhil Goyal 
740a3105777SAkhil Goyal static int
7412f97b943SRahul Bhansali event_tx_burst(struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
7422f97b943SRahul Bhansali {
7432f97b943SRahul Bhansali 	struct rte_event ev;
7442f97b943SRahul Bhansali 	int i, nb_sent = 0;
7452f97b943SRahul Bhansali 
7462f97b943SRahul Bhansali 	/* Convert packets to events */
7472f97b943SRahul Bhansali 	memset(&ev, 0, sizeof(ev));
7482f97b943SRahul Bhansali 	ev.sched_type = RTE_SCHED_TYPE_PARALLEL;
7492f97b943SRahul Bhansali 	for (i = 0; i < nb_pkts; i++) {
7502f97b943SRahul Bhansali 		ev.mbuf = tx_pkts[i];
7512f97b943SRahul Bhansali 		ev.mbuf->port = port_id;
7522f97b943SRahul Bhansali 		nb_sent += rte_event_eth_tx_adapter_enqueue(
7532f97b943SRahul Bhansali 				eventdev_id, port_id, &ev, 1, 0);
7542f97b943SRahul Bhansali 	}
7552f97b943SRahul Bhansali 
7562f97b943SRahul Bhansali 	return nb_sent;
7572f97b943SRahul Bhansali }
7582f97b943SRahul Bhansali 
7592f97b943SRahul Bhansali static int
7602f97b943SRahul Bhansali event_rx_burst(struct rte_mbuf **rx_pkts, uint16_t nb_pkts_to_rx)
7612f97b943SRahul Bhansali {
7622f97b943SRahul Bhansali 	int nb_ev, nb_rx = 0, j = 0;
7632f97b943SRahul Bhansali 	const int ms_per_pkt = 5;
7642f97b943SRahul Bhansali 	struct rte_event ev;
7652f97b943SRahul Bhansali 
7662f97b943SRahul Bhansali 	do {
7672f97b943SRahul Bhansali 		nb_ev = rte_event_dequeue_burst(eventdev_id, port_id,
7682f97b943SRahul Bhansali 				&ev, 1, 0);
7692f97b943SRahul Bhansali 
7702f97b943SRahul Bhansali 		if (nb_ev == 0) {
7712f97b943SRahul Bhansali 			rte_delay_ms(1);
7722f97b943SRahul Bhansali 			continue;
7732f97b943SRahul Bhansali 		}
7742f97b943SRahul Bhansali 
7752f97b943SRahul Bhansali 		/* Get packet from event */
7762f97b943SRahul Bhansali 		if (ev.event_type != RTE_EVENT_TYPE_ETHDEV) {
7772f97b943SRahul Bhansali 			printf("Unsupported event type: %i\n",
7782f97b943SRahul Bhansali 				ev.event_type);
7792f97b943SRahul Bhansali 			continue;
7802f97b943SRahul Bhansali 		}
7812f97b943SRahul Bhansali 		rx_pkts[nb_rx++] = ev.mbuf;
7822f97b943SRahul Bhansali 	} while (j++ < (nb_pkts_to_rx * ms_per_pkt) && nb_rx < nb_pkts_to_rx);
7832f97b943SRahul Bhansali 
7842f97b943SRahul Bhansali 	return nb_rx;
7852f97b943SRahul Bhansali }
7862f97b943SRahul Bhansali 
7872f97b943SRahul Bhansali static int
7881d63855bSNithin Dabilpuram verify_inbound_oop(struct ipsec_test_data *td,
7891d63855bSNithin Dabilpuram 		   bool silent, struct rte_mbuf *mbuf)
7901d63855bSNithin Dabilpuram {
7911d63855bSNithin Dabilpuram 	int ret = TEST_SUCCESS, rc;
7921d63855bSNithin Dabilpuram 	struct rte_mbuf *orig;
7931d63855bSNithin Dabilpuram 	uint32_t len;
7941d63855bSNithin Dabilpuram 	void *data;
7951d63855bSNithin Dabilpuram 
7961d63855bSNithin Dabilpuram 	orig = *rte_security_oop_dynfield(mbuf);
7971d63855bSNithin Dabilpuram 	if (!orig) {
7981d63855bSNithin Dabilpuram 		if (!silent)
7991d63855bSNithin Dabilpuram 			printf("\nUnable to get orig buffer OOP session");
8001d63855bSNithin Dabilpuram 		return TEST_FAILED;
8011d63855bSNithin Dabilpuram 	}
8021d63855bSNithin Dabilpuram 
8031d63855bSNithin Dabilpuram 	/* Skip Ethernet header comparison */
8041d63855bSNithin Dabilpuram 	rte_pktmbuf_adj(orig, RTE_ETHER_HDR_LEN);
8051d63855bSNithin Dabilpuram 
8061d63855bSNithin Dabilpuram 	len = td->input_text.len;
8071d63855bSNithin Dabilpuram 	if (orig->pkt_len != len) {
8081d63855bSNithin Dabilpuram 		if (!silent)
8091d63855bSNithin Dabilpuram 			printf("\nOriginal packet length mismatch, expected %u, got %u ",
8101d63855bSNithin Dabilpuram 			       len, orig->pkt_len);
8111d63855bSNithin Dabilpuram 		ret = TEST_FAILED;
8121d63855bSNithin Dabilpuram 	}
8131d63855bSNithin Dabilpuram 
8141d63855bSNithin Dabilpuram 	data = rte_pktmbuf_mtod(orig, void *);
8151d63855bSNithin Dabilpuram 	rc = memcmp(data, td->input_text.data, len);
8161d63855bSNithin Dabilpuram 	if (rc) {
8171d63855bSNithin Dabilpuram 		ret = TEST_FAILED;
8181d63855bSNithin Dabilpuram 		if (silent)
8191d63855bSNithin Dabilpuram 			goto exit;
8201d63855bSNithin Dabilpuram 
8211d63855bSNithin Dabilpuram 		printf("TestCase %s line %d: %s\n", __func__, __LINE__,
8221d63855bSNithin Dabilpuram 		       "output text not as expected\n");
8231d63855bSNithin Dabilpuram 
8241d63855bSNithin Dabilpuram 		rte_hexdump(stdout, "expected", td->input_text.data, len);
8251d63855bSNithin Dabilpuram 		rte_hexdump(stdout, "actual", data, len);
8261d63855bSNithin Dabilpuram 	}
8271d63855bSNithin Dabilpuram exit:
8281d63855bSNithin Dabilpuram 	rte_pktmbuf_free(orig);
8291d63855bSNithin Dabilpuram 	return ret;
8301d63855bSNithin Dabilpuram }
8311d63855bSNithin Dabilpuram 
8321d63855bSNithin Dabilpuram static int
83319d7fcc5SRahul Bhansali test_ipsec_with_rx_inject(struct ip_pkt_vector *vector, const struct ipsec_test_flags *flags)
83419d7fcc5SRahul Bhansali {
83519d7fcc5SRahul Bhansali 	struct rte_security_session_conf sess_conf_out = {0};
83619d7fcc5SRahul Bhansali 	struct rte_security_session_conf sess_conf_in = {0};
83719d7fcc5SRahul Bhansali 	uint32_t nb_tx, burst_sz, nb_sent = 0, nb_inj = 0;
83819d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform cipher_out = {0};
83919d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform cipher_in = {0};
84019d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform auth_out = {0};
84119d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform aead_out = {0};
84219d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform auth_in = {0};
84319d7fcc5SRahul Bhansali 	struct rte_crypto_sym_xform aead_in = {0};
84419d7fcc5SRahul Bhansali 	void *out_ses[ENCAP_DECAP_BURST_SZ] = {0};
84519d7fcc5SRahul Bhansali 	void *in_ses[ENCAP_DECAP_BURST_SZ] = {0};
84619d7fcc5SRahul Bhansali 	uint32_t i, j, nb_rx = 0, nb_inj_rx = 0;
84719d7fcc5SRahul Bhansali 	struct rte_mbuf **inj_pkts_burst;
84819d7fcc5SRahul Bhansali 	struct ipsec_test_data sa_data;
84919d7fcc5SRahul Bhansali 	uint32_t ol_flags;
85019d7fcc5SRahul Bhansali 	bool outer_ipv4;
85119d7fcc5SRahul Bhansali 	int ret = 0;
85219d7fcc5SRahul Bhansali 	void *ctx;
85319d7fcc5SRahul Bhansali 
85419d7fcc5SRahul Bhansali 	inj_pkts_burst = calloc(MAX_TRAFFIC_BURST, sizeof(void *));
85519d7fcc5SRahul Bhansali 	if (!inj_pkts_burst)
85619d7fcc5SRahul Bhansali 		return TEST_FAILED;
85719d7fcc5SRahul Bhansali 
85819d7fcc5SRahul Bhansali 	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
85919d7fcc5SRahul Bhansali 	nb_tx = burst_sz;
86019d7fcc5SRahul Bhansali 
86119d7fcc5SRahul Bhansali 	memcpy(&sa_data, vector->sa_data, sizeof(struct ipsec_test_data));
86219d7fcc5SRahul Bhansali 	sa_data.ipsec_xform.direction =	RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
86319d7fcc5SRahul Bhansali 	outer_ipv4 = is_outer_ipv4(&sa_data);
86419d7fcc5SRahul Bhansali 
86519d7fcc5SRahul Bhansali 	for (i = 0; i < nb_tx; i++) {
86619d7fcc5SRahul Bhansali 		tx_pkts_burst[i] = init_packet(mbufpool, vector->full_pkt->data,
86719d7fcc5SRahul Bhansali 					       vector->full_pkt->len, outer_ipv4);
86819d7fcc5SRahul Bhansali 		if (tx_pkts_burst[i] == NULL) {
86919d7fcc5SRahul Bhansali 			ret = -1;
87019d7fcc5SRahul Bhansali 			printf("\n packed init failed\n");
87119d7fcc5SRahul Bhansali 			goto out;
87219d7fcc5SRahul Bhansali 		}
87319d7fcc5SRahul Bhansali 	}
87419d7fcc5SRahul Bhansali 
87519d7fcc5SRahul Bhansali 	for (i = 0; i < burst_sz; i++) {
87619d7fcc5SRahul Bhansali 		memcpy(&sa_data, vector->sa_data, sizeof(struct ipsec_test_data));
87719d7fcc5SRahul Bhansali 		/* Update SPI for every new SA */
87819d7fcc5SRahul Bhansali 		sa_data.ipsec_xform.spi += i;
87919d7fcc5SRahul Bhansali 		sa_data.ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
88019d7fcc5SRahul Bhansali 		if (sa_data.aead) {
88119d7fcc5SRahul Bhansali 			sess_conf_out.crypto_xform = &aead_out;
88219d7fcc5SRahul Bhansali 		} else {
88319d7fcc5SRahul Bhansali 			sess_conf_out.crypto_xform = &cipher_out;
88419d7fcc5SRahul Bhansali 			sess_conf_out.crypto_xform->next = &auth_out;
88519d7fcc5SRahul Bhansali 		}
88619d7fcc5SRahul Bhansali 
88719d7fcc5SRahul Bhansali 		/* Create Inline IPsec outbound session. */
88819d7fcc5SRahul Bhansali 		ret = create_inline_ipsec_session(&sa_data, port_id, &out_ses[i], &ctx, &ol_flags,
88919d7fcc5SRahul Bhansali 						  flags, &sess_conf_out);
89019d7fcc5SRahul Bhansali 		if (ret) {
89119d7fcc5SRahul Bhansali 			printf("\nInline outbound session create failed\n");
89219d7fcc5SRahul Bhansali 			goto out;
89319d7fcc5SRahul Bhansali 		}
89419d7fcc5SRahul Bhansali 	}
89519d7fcc5SRahul Bhansali 
89619d7fcc5SRahul Bhansali 	for (i = 0; i < nb_tx; i++) {
89719d7fcc5SRahul Bhansali 		if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
89819d7fcc5SRahul Bhansali 			rte_security_set_pkt_metadata(ctx,
89919d7fcc5SRahul Bhansali 				out_ses[i], tx_pkts_burst[i], NULL);
90019d7fcc5SRahul Bhansali 		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
90119d7fcc5SRahul Bhansali 	}
90219d7fcc5SRahul Bhansali 
90319d7fcc5SRahul Bhansali 	for (i = 0; i < burst_sz; i++) {
90419d7fcc5SRahul Bhansali 		memcpy(&sa_data, vector->sa_data, sizeof(struct ipsec_test_data));
90519d7fcc5SRahul Bhansali 		/* Update SPI for every new SA */
90619d7fcc5SRahul Bhansali 		sa_data.ipsec_xform.spi += i;
90719d7fcc5SRahul Bhansali 		sa_data.ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
90819d7fcc5SRahul Bhansali 
90919d7fcc5SRahul Bhansali 		if (sa_data.aead) {
91019d7fcc5SRahul Bhansali 			sess_conf_in.crypto_xform = &aead_in;
91119d7fcc5SRahul Bhansali 		} else {
91219d7fcc5SRahul Bhansali 			sess_conf_in.crypto_xform = &auth_in;
91319d7fcc5SRahul Bhansali 			sess_conf_in.crypto_xform->next = &cipher_in;
91419d7fcc5SRahul Bhansali 		}
91519d7fcc5SRahul Bhansali 		/* Create Inline IPsec inbound session. */
91619d7fcc5SRahul Bhansali 		ret = create_inline_ipsec_session(&sa_data, port_id, &in_ses[i], &ctx, &ol_flags,
91719d7fcc5SRahul Bhansali 						  flags, &sess_conf_in);
91819d7fcc5SRahul Bhansali 		if (ret) {
91919d7fcc5SRahul Bhansali 			printf("\nInline inbound session create failed\n");
92019d7fcc5SRahul Bhansali 			goto out;
92119d7fcc5SRahul Bhansali 		}
92219d7fcc5SRahul Bhansali 	}
92319d7fcc5SRahul Bhansali 
92419d7fcc5SRahul Bhansali 	rte_delay_ms(1);
92519d7fcc5SRahul Bhansali 	/* Create and receive encrypted packets */
92619d7fcc5SRahul Bhansali 	if (event_mode_enabled)
92719d7fcc5SRahul Bhansali 		nb_sent = event_tx_burst(tx_pkts_burst, nb_tx);
92819d7fcc5SRahul Bhansali 	else
92919d7fcc5SRahul Bhansali 		nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_tx);
93019d7fcc5SRahul Bhansali 	if (nb_sent != nb_tx) {
93119d7fcc5SRahul Bhansali 		ret = -1;
93219d7fcc5SRahul Bhansali 		printf("\nFailed to tx %u pkts", nb_tx);
93319d7fcc5SRahul Bhansali 		goto out;
93419d7fcc5SRahul Bhansali 	}
93519d7fcc5SRahul Bhansali 
93619d7fcc5SRahul Bhansali 	rte_delay_ms(1);
93719d7fcc5SRahul Bhansali 
93819d7fcc5SRahul Bhansali 	/* Retry few times before giving up */
93919d7fcc5SRahul Bhansali 	nb_rx = 0;
94019d7fcc5SRahul Bhansali 	j = 0;
94119d7fcc5SRahul Bhansali 	if (event_mode_enabled)
94219d7fcc5SRahul Bhansali 		nb_rx = event_rx_burst(rx_pkts_burst, nb_tx);
94319d7fcc5SRahul Bhansali 	else
94419d7fcc5SRahul Bhansali 		do {
94519d7fcc5SRahul Bhansali 			nb_rx += rte_eth_rx_burst(port_id, 0, &rx_pkts_burst[nb_rx],
94619d7fcc5SRahul Bhansali 						  nb_tx - nb_rx);
94719d7fcc5SRahul Bhansali 			j++;
94819d7fcc5SRahul Bhansali 			if (nb_rx >= nb_tx)
94919d7fcc5SRahul Bhansali 				break;
95019d7fcc5SRahul Bhansali 			rte_delay_ms(1);
95119d7fcc5SRahul Bhansali 		} while (j < 5 || !nb_rx);
95219d7fcc5SRahul Bhansali 
95319d7fcc5SRahul Bhansali 	/* Check for minimum number of Rx packets expected */
95419d7fcc5SRahul Bhansali 	if (nb_rx != nb_tx) {
95519d7fcc5SRahul Bhansali 		printf("\nReceived less Rx pkts(%u)\n", nb_rx);
95619d7fcc5SRahul Bhansali 		ret = TEST_FAILED;
95719d7fcc5SRahul Bhansali 		goto out;
95819d7fcc5SRahul Bhansali 	}
95919d7fcc5SRahul Bhansali 
96019d7fcc5SRahul Bhansali 	for (i = 0; i < nb_rx; i++) {
96119d7fcc5SRahul Bhansali 		if (!(rx_pkts_burst[i]->packet_type & RTE_PTYPE_TUNNEL_ESP)) {
96219d7fcc5SRahul Bhansali 			printf("\nNot received ESP packet, pytpe=%x\n",
96319d7fcc5SRahul Bhansali 					rx_pkts_burst[i]->packet_type);
96419d7fcc5SRahul Bhansali 			goto out;
96519d7fcc5SRahul Bhansali 		}
96619d7fcc5SRahul Bhansali 		rx_pkts_burst[i]->l2_len = RTE_ETHER_HDR_LEN;
96719d7fcc5SRahul Bhansali 	}
96819d7fcc5SRahul Bhansali 
96919d7fcc5SRahul Bhansali 	/* Inject Packets */
97019d7fcc5SRahul Bhansali 	if (flags->rx_inject)
97119d7fcc5SRahul Bhansali 		nb_inj = rte_security_inb_pkt_rx_inject(ctx, rx_pkts_burst, in_ses, nb_rx);
97219d7fcc5SRahul Bhansali 	else {
97319d7fcc5SRahul Bhansali 		printf("\nInject flag disabled, Failed to Inject %u pkts", nb_rx);
97419d7fcc5SRahul Bhansali 		goto out;
97519d7fcc5SRahul Bhansali 	}
97619d7fcc5SRahul Bhansali 	if (nb_inj != nb_rx) {
97719d7fcc5SRahul Bhansali 		ret = -1;
97819d7fcc5SRahul Bhansali 		printf("\nFailed to Inject %u pkts", nb_rx);
97919d7fcc5SRahul Bhansali 		goto out;
98019d7fcc5SRahul Bhansali 	}
98119d7fcc5SRahul Bhansali 
98219d7fcc5SRahul Bhansali 	rte_delay_ms(1);
98319d7fcc5SRahul Bhansali 
98419d7fcc5SRahul Bhansali 	/* Retry few times before giving up */
98519d7fcc5SRahul Bhansali 	nb_inj_rx = 0;
98619d7fcc5SRahul Bhansali 	j = 0;
98719d7fcc5SRahul Bhansali 	if (event_mode_enabled)
98819d7fcc5SRahul Bhansali 		nb_inj_rx = event_rx_burst(inj_pkts_burst, nb_inj);
98919d7fcc5SRahul Bhansali 	else
99019d7fcc5SRahul Bhansali 		do {
99119d7fcc5SRahul Bhansali 			nb_inj_rx += rte_eth_rx_burst(port_id, 0, &inj_pkts_burst[nb_inj_rx],
99219d7fcc5SRahul Bhansali 						      nb_inj - nb_inj_rx);
99319d7fcc5SRahul Bhansali 			j++;
99419d7fcc5SRahul Bhansali 			if (nb_inj_rx >= nb_inj)
99519d7fcc5SRahul Bhansali 				break;
99619d7fcc5SRahul Bhansali 			rte_delay_ms(1);
99719d7fcc5SRahul Bhansali 		} while (j < 5 || !nb_inj_rx);
99819d7fcc5SRahul Bhansali 
99919d7fcc5SRahul Bhansali 	/* Check for minimum number of Rx packets expected */
100019d7fcc5SRahul Bhansali 	if (nb_inj_rx != nb_inj) {
100119d7fcc5SRahul Bhansali 		printf("\nReceived less Rx pkts(%u)\n", nb_inj_rx);
100219d7fcc5SRahul Bhansali 		ret = TEST_FAILED;
100319d7fcc5SRahul Bhansali 		goto out;
100419d7fcc5SRahul Bhansali 	}
100519d7fcc5SRahul Bhansali 
100619d7fcc5SRahul Bhansali 	for (i = 0; i < nb_inj_rx; i++) {
100719d7fcc5SRahul Bhansali 		if (inj_pkts_burst[i]->ol_flags &
100819d7fcc5SRahul Bhansali 		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
100919d7fcc5SRahul Bhansali 		    !(inj_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
101019d7fcc5SRahul Bhansali 			printf("\nsecurity offload failed\n");
101119d7fcc5SRahul Bhansali 			ret = TEST_FAILED;
101219d7fcc5SRahul Bhansali 			break;
101319d7fcc5SRahul Bhansali 		}
101419d7fcc5SRahul Bhansali 
101519d7fcc5SRahul Bhansali 		if (vector->full_pkt->len + RTE_ETHER_HDR_LEN !=
101619d7fcc5SRahul Bhansali 		    inj_pkts_burst[i]->pkt_len) {
101719d7fcc5SRahul Bhansali 			printf("\nreassembled/decrypted packet length mismatch\n");
101819d7fcc5SRahul Bhansali 			ret = TEST_FAILED;
101919d7fcc5SRahul Bhansali 			break;
102019d7fcc5SRahul Bhansali 		}
102119d7fcc5SRahul Bhansali 		rte_pktmbuf_adj(inj_pkts_burst[i], RTE_ETHER_HDR_LEN);
102219d7fcc5SRahul Bhansali 		ret = compare_pkt_data(inj_pkts_burst[i], vector->full_pkt->data,
102319d7fcc5SRahul Bhansali 				       vector->full_pkt->len);
102419d7fcc5SRahul Bhansali 		if (ret != TEST_SUCCESS)
102519d7fcc5SRahul Bhansali 			break;
102619d7fcc5SRahul Bhansali 	}
102719d7fcc5SRahul Bhansali 
102819d7fcc5SRahul Bhansali out:
102919d7fcc5SRahul Bhansali 	/* Clear session data. */
103019d7fcc5SRahul Bhansali 	for (i = 0; i < burst_sz; i++) {
103119d7fcc5SRahul Bhansali 		if (out_ses[i])
103219d7fcc5SRahul Bhansali 			rte_security_session_destroy(ctx, out_ses[i]);
103319d7fcc5SRahul Bhansali 		if (in_ses[i])
103419d7fcc5SRahul Bhansali 			rte_security_session_destroy(ctx, in_ses[i]);
103519d7fcc5SRahul Bhansali 	}
103619d7fcc5SRahul Bhansali 
103719d7fcc5SRahul Bhansali 	for (i = nb_sent; i < nb_tx; i++)
103819d7fcc5SRahul Bhansali 		free_mbuf(tx_pkts_burst[i]);
103919d7fcc5SRahul Bhansali 	for (i = 0; i < nb_rx; i++)
104019d7fcc5SRahul Bhansali 		free_mbuf(rx_pkts_burst[i]);
104119d7fcc5SRahul Bhansali 	for (i = 0; i < nb_inj_rx; i++)
104219d7fcc5SRahul Bhansali 		free_mbuf(inj_pkts_burst[i]);
104319d7fcc5SRahul Bhansali 	free(inj_pkts_burst);
104419d7fcc5SRahul Bhansali 
104519d7fcc5SRahul Bhansali 	return ret;
104619d7fcc5SRahul Bhansali }
104719d7fcc5SRahul Bhansali 
104819d7fcc5SRahul Bhansali static int
1049a3105777SAkhil Goyal test_ipsec_with_reassembly(struct reassembly_vector *vector,
1050a3105777SAkhil Goyal 		const struct ipsec_test_flags *flags)
1051a3105777SAkhil Goyal {
10522973dbf9SAkhil Goyal 	void *out_ses[ENCAP_DECAP_BURST_SZ] = {0};
10532973dbf9SAkhil Goyal 	void *in_ses[ENCAP_DECAP_BURST_SZ] = {0};
1054a3105777SAkhil Goyal 	struct rte_eth_ip_reassembly_params reass_capa = {0};
1055a3105777SAkhil Goyal 	struct rte_security_session_conf sess_conf_out = {0};
1056a3105777SAkhil Goyal 	struct rte_security_session_conf sess_conf_in = {0};
1057a3105777SAkhil Goyal 	unsigned int nb_tx, burst_sz, nb_sent = 0;
1058a3105777SAkhil Goyal 	struct rte_crypto_sym_xform cipher_out = {0};
1059a3105777SAkhil Goyal 	struct rte_crypto_sym_xform auth_out = {0};
1060a3105777SAkhil Goyal 	struct rte_crypto_sym_xform aead_out = {0};
1061a3105777SAkhil Goyal 	struct rte_crypto_sym_xform cipher_in = {0};
1062a3105777SAkhil Goyal 	struct rte_crypto_sym_xform auth_in = {0};
1063a3105777SAkhil Goyal 	struct rte_crypto_sym_xform aead_in = {0};
1064a3105777SAkhil Goyal 	struct ipsec_test_data sa_data;
106579bdb787SAkhil Goyal 	void *ctx;
1066a3105777SAkhil Goyal 	unsigned int i, nb_rx = 0, j;
1067a3105777SAkhil Goyal 	uint32_t ol_flags;
1068c215f6cdSNithin Dabilpuram 	bool outer_ipv4;
1069a3105777SAkhil Goyal 	int ret = 0;
1070a3105777SAkhil Goyal 
1071a3105777SAkhil Goyal 	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
1072a3105777SAkhil Goyal 	nb_tx = vector->nb_frags * burst_sz;
1073a3105777SAkhil Goyal 
1074a3105777SAkhil Goyal 	rte_eth_ip_reassembly_capability_get(port_id, &reass_capa);
1075a3105777SAkhil Goyal 	if (reass_capa.max_frags < vector->nb_frags)
1076a3105777SAkhil Goyal 		return TEST_SKIPPED;
1077a3105777SAkhil Goyal 
1078a3105777SAkhil Goyal 	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
1079a3105777SAkhil Goyal 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
1080a3105777SAkhil Goyal 
1081c215f6cdSNithin Dabilpuram 	memcpy(&sa_data, vector->sa_data, sizeof(struct ipsec_test_data));
1082c215f6cdSNithin Dabilpuram 	sa_data.ipsec_xform.direction =	RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1083c215f6cdSNithin Dabilpuram 	outer_ipv4 = is_outer_ipv4(&sa_data);
1084c215f6cdSNithin Dabilpuram 
1085a3105777SAkhil Goyal 	for (i = 0; i < nb_tx; i += vector->nb_frags) {
1086a3105777SAkhil Goyal 		for (j = 0; j < vector->nb_frags; j++) {
1087a3105777SAkhil Goyal 			tx_pkts_burst[i+j] = init_packet(mbufpool,
1088a3105777SAkhil Goyal 						vector->frags[j]->data,
1089c215f6cdSNithin Dabilpuram 						vector->frags[j]->len, outer_ipv4);
1090a3105777SAkhil Goyal 			if (tx_pkts_burst[i+j] == NULL) {
1091a3105777SAkhil Goyal 				ret = -1;
1092a3105777SAkhil Goyal 				printf("\n packed init failed\n");
1093a3105777SAkhil Goyal 				goto out;
1094a3105777SAkhil Goyal 			}
1095a3105777SAkhil Goyal 		}
1096a3105777SAkhil Goyal 	}
1097a3105777SAkhil Goyal 
1098a3105777SAkhil Goyal 	for (i = 0; i < burst_sz; i++) {
1099a3105777SAkhil Goyal 		memcpy(&sa_data, vector->sa_data,
1100a3105777SAkhil Goyal 				sizeof(struct ipsec_test_data));
1101a3105777SAkhil Goyal 		/* Update SPI for every new SA */
1102a3105777SAkhil Goyal 		sa_data.ipsec_xform.spi += i;
1103a3105777SAkhil Goyal 		sa_data.ipsec_xform.direction =
1104a3105777SAkhil Goyal 					RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1105a3105777SAkhil Goyal 		if (sa_data.aead) {
1106a3105777SAkhil Goyal 			sess_conf_out.crypto_xform = &aead_out;
1107a3105777SAkhil Goyal 		} else {
1108a3105777SAkhil Goyal 			sess_conf_out.crypto_xform = &cipher_out;
1109a3105777SAkhil Goyal 			sess_conf_out.crypto_xform->next = &auth_out;
1110a3105777SAkhil Goyal 		}
1111a3105777SAkhil Goyal 
1112a3105777SAkhil Goyal 		/* Create Inline IPsec outbound session. */
1113a3105777SAkhil Goyal 		ret = create_inline_ipsec_session(&sa_data, port_id,
1114a3105777SAkhil Goyal 				&out_ses[i], &ctx, &ol_flags, flags,
1115a3105777SAkhil Goyal 				&sess_conf_out);
1116a3105777SAkhil Goyal 		if (ret) {
1117a3105777SAkhil Goyal 			printf("\nInline outbound session create failed\n");
1118a3105777SAkhil Goyal 			goto out;
1119a3105777SAkhil Goyal 		}
1120a3105777SAkhil Goyal 	}
1121a3105777SAkhil Goyal 
1122a3105777SAkhil Goyal 	j = 0;
1123a3105777SAkhil Goyal 	for (i = 0; i < nb_tx; i++) {
1124a3105777SAkhil Goyal 		if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
1125a3105777SAkhil Goyal 			rte_security_set_pkt_metadata(ctx,
1126a3105777SAkhil Goyal 				out_ses[j], tx_pkts_burst[i], NULL);
1127a3105777SAkhil Goyal 		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
1128a3105777SAkhil Goyal 
1129a3105777SAkhil Goyal 		/* Move to next SA after nb_frags */
1130a3105777SAkhil Goyal 		if ((i + 1) % vector->nb_frags == 0)
1131a3105777SAkhil Goyal 			j++;
1132a3105777SAkhil Goyal 	}
1133a3105777SAkhil Goyal 
1134a3105777SAkhil Goyal 	for (i = 0; i < burst_sz; i++) {
1135a3105777SAkhil Goyal 		memcpy(&sa_data, vector->sa_data,
1136a3105777SAkhil Goyal 				sizeof(struct ipsec_test_data));
1137a3105777SAkhil Goyal 		/* Update SPI for every new SA */
1138a3105777SAkhil Goyal 		sa_data.ipsec_xform.spi += i;
1139a3105777SAkhil Goyal 		sa_data.ipsec_xform.direction =
1140a3105777SAkhil Goyal 					RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1141a3105777SAkhil Goyal 
1142a3105777SAkhil Goyal 		if (sa_data.aead) {
1143a3105777SAkhil Goyal 			sess_conf_in.crypto_xform = &aead_in;
1144a3105777SAkhil Goyal 		} else {
1145a3105777SAkhil Goyal 			sess_conf_in.crypto_xform = &auth_in;
1146a3105777SAkhil Goyal 			sess_conf_in.crypto_xform->next = &cipher_in;
1147a3105777SAkhil Goyal 		}
1148a3105777SAkhil Goyal 		/* Create Inline IPsec inbound session. */
1149a3105777SAkhil Goyal 		ret = create_inline_ipsec_session(&sa_data, port_id, &in_ses[i],
1150a3105777SAkhil Goyal 				&ctx, &ol_flags, flags, &sess_conf_in);
1151a3105777SAkhil Goyal 		if (ret) {
1152a3105777SAkhil Goyal 			printf("\nInline inbound session create failed\n");
1153a3105777SAkhil Goyal 			goto out;
1154a3105777SAkhil Goyal 		}
1155a3105777SAkhil Goyal 	}
1156a3105777SAkhil Goyal 
1157a3105777SAkhil Goyal 	/* Retrieve reassembly dynfield offset if available */
1158a3105777SAkhil Goyal 	if (ip_reassembly_dynfield_offset < 0 && vector->nb_frags > 1)
1159a3105777SAkhil Goyal 		ip_reassembly_dynfield_offset = rte_mbuf_dynfield_lookup(
1160a3105777SAkhil Goyal 				RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME, NULL);
1161a3105777SAkhil Goyal 
1162a3105777SAkhil Goyal 
1163a3105777SAkhil Goyal 	ret = create_default_flow(port_id);
1164a3105777SAkhil Goyal 	if (ret)
1165a3105777SAkhil Goyal 		goto out;
1166a3105777SAkhil Goyal 
11672f97b943SRahul Bhansali 	if (event_mode_enabled)
11682f97b943SRahul Bhansali 		nb_sent = event_tx_burst(tx_pkts_burst, nb_tx);
11692f97b943SRahul Bhansali 	else
1170a3105777SAkhil Goyal 		nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_tx);
1171a3105777SAkhil Goyal 	if (nb_sent != nb_tx) {
1172a3105777SAkhil Goyal 		ret = -1;
1173a3105777SAkhil Goyal 		printf("\nFailed to tx %u pkts", nb_tx);
1174a3105777SAkhil Goyal 		goto out;
1175a3105777SAkhil Goyal 	}
1176a3105777SAkhil Goyal 
1177a3105777SAkhil Goyal 	rte_delay_ms(1);
1178a3105777SAkhil Goyal 
1179a3105777SAkhil Goyal 	/* Retry few times before giving up */
1180a3105777SAkhil Goyal 	nb_rx = 0;
1181a3105777SAkhil Goyal 	j = 0;
11822f97b943SRahul Bhansali 	if (event_mode_enabled)
11832f97b943SRahul Bhansali 		nb_rx = event_rx_burst(rx_pkts_burst, nb_tx);
11842f97b943SRahul Bhansali 	else
1185a3105777SAkhil Goyal 		do {
1186a3105777SAkhil Goyal 			nb_rx += rte_eth_rx_burst(port_id, 0, &rx_pkts_burst[nb_rx],
1187a3105777SAkhil Goyal 						  nb_tx - nb_rx);
1188a3105777SAkhil Goyal 			j++;
1189a3105777SAkhil Goyal 			if (nb_rx >= nb_tx)
1190a3105777SAkhil Goyal 				break;
1191a3105777SAkhil Goyal 			rte_delay_ms(1);
1192a3105777SAkhil Goyal 		} while (j < 5 || !nb_rx);
1193a3105777SAkhil Goyal 
1194a3105777SAkhil Goyal 	/* Check for minimum number of Rx packets expected */
1195a3105777SAkhil Goyal 	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
1196a3105777SAkhil Goyal 	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
1197a3105777SAkhil Goyal 		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
1198a3105777SAkhil Goyal 		ret = TEST_FAILED;
1199a3105777SAkhil Goyal 		goto out;
1200a3105777SAkhil Goyal 	}
1201a3105777SAkhil Goyal 
1202a3105777SAkhil Goyal 	for (i = 0; i < nb_rx; i++) {
1203a3105777SAkhil Goyal 		if (vector->nb_frags > 1 &&
1204a3105777SAkhil Goyal 		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
1205a3105777SAkhil Goyal 			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
1206a3105777SAkhil Goyal 							      vector);
1207a3105777SAkhil Goyal 			if (ret != TEST_SUCCESS)
1208a3105777SAkhil Goyal 				break;
1209a3105777SAkhil Goyal 			continue;
1210a3105777SAkhil Goyal 		}
1211a3105777SAkhil Goyal 
1212a3105777SAkhil Goyal 		if (rx_pkts_burst[i]->ol_flags &
1213a3105777SAkhil Goyal 		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
1214a3105777SAkhil Goyal 		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
1215a3105777SAkhil Goyal 			printf("\nsecurity offload failed\n");
1216a3105777SAkhil Goyal 			ret = TEST_FAILED;
1217a3105777SAkhil Goyal 			break;
1218a3105777SAkhil Goyal 		}
1219a3105777SAkhil Goyal 
1220a3105777SAkhil Goyal 		if (vector->full_pkt->len + RTE_ETHER_HDR_LEN !=
1221a3105777SAkhil Goyal 				rx_pkts_burst[i]->pkt_len) {
1222a3105777SAkhil Goyal 			printf("\nreassembled/decrypted packet length mismatch\n");
1223a3105777SAkhil Goyal 			ret = TEST_FAILED;
1224a3105777SAkhil Goyal 			break;
1225a3105777SAkhil Goyal 		}
1226a3105777SAkhil Goyal 		rte_pktmbuf_adj(rx_pkts_burst[i], RTE_ETHER_HDR_LEN);
1227a3105777SAkhil Goyal 		ret = compare_pkt_data(rx_pkts_burst[i],
1228a3105777SAkhil Goyal 				       vector->full_pkt->data,
1229a3105777SAkhil Goyal 				       vector->full_pkt->len);
1230a3105777SAkhil Goyal 		if (ret != TEST_SUCCESS)
1231a3105777SAkhil Goyal 			break;
1232a3105777SAkhil Goyal 	}
1233a3105777SAkhil Goyal 
1234a3105777SAkhil Goyal out:
1235a3105777SAkhil Goyal 	destroy_default_flow(port_id);
1236a3105777SAkhil Goyal 
1237a3105777SAkhil Goyal 	/* Clear session data. */
1238a3105777SAkhil Goyal 	for (i = 0; i < burst_sz; i++) {
1239a3105777SAkhil Goyal 		if (out_ses[i])
1240a3105777SAkhil Goyal 			rte_security_session_destroy(ctx, out_ses[i]);
1241a3105777SAkhil Goyal 		if (in_ses[i])
1242a3105777SAkhil Goyal 			rte_security_session_destroy(ctx, in_ses[i]);
1243a3105777SAkhil Goyal 	}
1244a3105777SAkhil Goyal 
1245a3105777SAkhil Goyal 	for (i = nb_sent; i < nb_tx; i++)
1246a3105777SAkhil Goyal 		free_mbuf(tx_pkts_burst[i]);
1247a3105777SAkhil Goyal 	for (i = 0; i < nb_rx; i++)
1248a3105777SAkhil Goyal 		free_mbuf(rx_pkts_burst[i]);
1249a3105777SAkhil Goyal 	return ret;
1250a3105777SAkhil Goyal }
1251a3105777SAkhil Goyal 
1252a3105777SAkhil Goyal static int
125334e8a9d9SVamsi Attunuru test_ipsec_inline_sa_exp_event_callback(uint16_t port_id,
125434e8a9d9SVamsi Attunuru 		enum rte_eth_event_type type, void *param, void *ret_param)
125534e8a9d9SVamsi Attunuru {
125634e8a9d9SVamsi Attunuru 	struct sa_expiry_vector *vector = (struct sa_expiry_vector *)param;
125734e8a9d9SVamsi Attunuru 	struct rte_eth_event_ipsec_desc *event_desc = NULL;
125834e8a9d9SVamsi Attunuru 
125934e8a9d9SVamsi Attunuru 	RTE_SET_USED(port_id);
126034e8a9d9SVamsi Attunuru 
126134e8a9d9SVamsi Attunuru 	if (type != RTE_ETH_EVENT_IPSEC)
126234e8a9d9SVamsi Attunuru 		return -1;
126334e8a9d9SVamsi Attunuru 
126434e8a9d9SVamsi Attunuru 	event_desc = ret_param;
126534e8a9d9SVamsi Attunuru 	if (event_desc == NULL) {
126634e8a9d9SVamsi Attunuru 		printf("Event descriptor not set\n");
126734e8a9d9SVamsi Attunuru 		return -1;
126834e8a9d9SVamsi Attunuru 	}
126934e8a9d9SVamsi Attunuru 	vector->notify_event = true;
127034e8a9d9SVamsi Attunuru 	if (event_desc->metadata != (uint64_t)vector->sa_data) {
127134e8a9d9SVamsi Attunuru 		printf("Mismatch in event specific metadata\n");
127234e8a9d9SVamsi Attunuru 		return -1;
127334e8a9d9SVamsi Attunuru 	}
1274ff8ef86cSVamsi Attunuru 	switch (event_desc->subtype) {
1275ff8ef86cSVamsi Attunuru 	case RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY:
127634e8a9d9SVamsi Attunuru 		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
1277ff8ef86cSVamsi Attunuru 		break;
1278ff8ef86cSVamsi Attunuru 	case RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY:
127934e8a9d9SVamsi Attunuru 		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
1280ff8ef86cSVamsi Attunuru 		break;
1281ff8ef86cSVamsi Attunuru 	case RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY:
1282ff8ef86cSVamsi Attunuru 		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
1283ff8ef86cSVamsi Attunuru 		break;
1284ff8ef86cSVamsi Attunuru 	case RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY:
1285ff8ef86cSVamsi Attunuru 		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
1286ff8ef86cSVamsi Attunuru 		break;
1287ff8ef86cSVamsi Attunuru 	default:
128834e8a9d9SVamsi Attunuru 		printf("Invalid IPsec event reported\n");
128934e8a9d9SVamsi Attunuru 		return -1;
129034e8a9d9SVamsi Attunuru 	}
129134e8a9d9SVamsi Attunuru 
1292ff8ef86cSVamsi Attunuru 	return 0;
129334e8a9d9SVamsi Attunuru }
129434e8a9d9SVamsi Attunuru 
129534e8a9d9SVamsi Attunuru static enum rte_eth_event_ipsec_subtype
129634e8a9d9SVamsi Attunuru test_ipsec_inline_setup_expiry_vector(struct sa_expiry_vector *vector,
129734e8a9d9SVamsi Attunuru 		const struct ipsec_test_flags *flags,
129834e8a9d9SVamsi Attunuru 		struct ipsec_test_data *tdata)
129934e8a9d9SVamsi Attunuru {
130034e8a9d9SVamsi Attunuru 	enum rte_eth_event_ipsec_subtype event = RTE_ETH_EVENT_IPSEC_UNKNOWN;
130134e8a9d9SVamsi Attunuru 
130234e8a9d9SVamsi Attunuru 	vector->event = RTE_ETH_EVENT_IPSEC_UNKNOWN;
130334e8a9d9SVamsi Attunuru 	vector->notify_event = false;
130434e8a9d9SVamsi Attunuru 	vector->sa_data = (void *)tdata;
130534e8a9d9SVamsi Attunuru 	if (flags->sa_expiry_pkts_soft)
130634e8a9d9SVamsi Attunuru 		event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
1307ff8ef86cSVamsi Attunuru 	else if (flags->sa_expiry_bytes_soft)
130834e8a9d9SVamsi Attunuru 		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
1309ff8ef86cSVamsi Attunuru 	else if (flags->sa_expiry_pkts_hard)
1310ff8ef86cSVamsi Attunuru 		event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
1311ff8ef86cSVamsi Attunuru 	else
1312ff8ef86cSVamsi Attunuru 		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
131334e8a9d9SVamsi Attunuru 	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_IPSEC,
131434e8a9d9SVamsi Attunuru 		       test_ipsec_inline_sa_exp_event_callback, vector);
131534e8a9d9SVamsi Attunuru 
131634e8a9d9SVamsi Attunuru 	return event;
131734e8a9d9SVamsi Attunuru }
131834e8a9d9SVamsi Attunuru 
131934e8a9d9SVamsi Attunuru static int
132086e2487cSAkhil Goyal test_ipsec_inline_proto_process(struct ipsec_test_data *td,
132186e2487cSAkhil Goyal 		struct ipsec_test_data *res_d,
132286e2487cSAkhil Goyal 		int nb_pkts,
132386e2487cSAkhil Goyal 		bool silent,
132486e2487cSAkhil Goyal 		const struct ipsec_test_flags *flags)
132586e2487cSAkhil Goyal {
132634e8a9d9SVamsi Attunuru 	enum rte_eth_event_ipsec_subtype event = RTE_ETH_EVENT_IPSEC_UNKNOWN;
132786e2487cSAkhil Goyal 	struct rte_security_session_conf sess_conf = {0};
132886e2487cSAkhil Goyal 	struct rte_crypto_sym_xform cipher = {0};
132986e2487cSAkhil Goyal 	struct rte_crypto_sym_xform auth = {0};
133086e2487cSAkhil Goyal 	struct rte_crypto_sym_xform aead = {0};
133134e8a9d9SVamsi Attunuru 	struct sa_expiry_vector vector = {0};
133279bdb787SAkhil Goyal 	void *ctx;
133386e2487cSAkhil Goyal 	int nb_rx = 0, nb_sent;
133486e2487cSAkhil Goyal 	uint32_t ol_flags;
133586e2487cSAkhil Goyal 	int i, j = 0, ret;
1336c215f6cdSNithin Dabilpuram 	bool outer_ipv4;
13372973dbf9SAkhil Goyal 	void *ses;
133886e2487cSAkhil Goyal 
133986e2487cSAkhil Goyal 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_pkts);
134086e2487cSAkhil Goyal 
1341ff8ef86cSVamsi Attunuru 	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
1342ff8ef86cSVamsi Attunuru 		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
134334e8a9d9SVamsi Attunuru 		if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
134434e8a9d9SVamsi Attunuru 			return TEST_SUCCESS;
134534e8a9d9SVamsi Attunuru 		event = test_ipsec_inline_setup_expiry_vector(&vector, flags, td);
134634e8a9d9SVamsi Attunuru 	}
134734e8a9d9SVamsi Attunuru 
134886e2487cSAkhil Goyal 	if (td->aead) {
134986e2487cSAkhil Goyal 		sess_conf.crypto_xform = &aead;
135086e2487cSAkhil Goyal 	} else {
135186e2487cSAkhil Goyal 		if (td->ipsec_xform.direction ==
135286e2487cSAkhil Goyal 				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
135386e2487cSAkhil Goyal 			sess_conf.crypto_xform = &cipher;
135486e2487cSAkhil Goyal 			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
135586e2487cSAkhil Goyal 			sess_conf.crypto_xform->next = &auth;
135686e2487cSAkhil Goyal 			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
135786e2487cSAkhil Goyal 		} else {
135886e2487cSAkhil Goyal 			sess_conf.crypto_xform = &auth;
135986e2487cSAkhil Goyal 			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
136086e2487cSAkhil Goyal 			sess_conf.crypto_xform->next = &cipher;
136186e2487cSAkhil Goyal 			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
136286e2487cSAkhil Goyal 		}
136386e2487cSAkhil Goyal 	}
136486e2487cSAkhil Goyal 
136586e2487cSAkhil Goyal 	/* Create Inline IPsec session. */
136686e2487cSAkhil Goyal 	ret = create_inline_ipsec_session(td, port_id, &ses, &ctx,
136786e2487cSAkhil Goyal 					  &ol_flags, flags, &sess_conf);
136886e2487cSAkhil Goyal 	if (ret)
136986e2487cSAkhil Goyal 		return ret;
137086e2487cSAkhil Goyal 
13711d63855bSNithin Dabilpuram 	if (flags->inb_oop && rte_security_oop_dynfield_offset < 0) {
13721d63855bSNithin Dabilpuram 		printf("\nDynamic field not available for inline inbound OOP");
13731d63855bSNithin Dabilpuram 		ret = TEST_FAILED;
13741d63855bSNithin Dabilpuram 		goto out;
13751d63855bSNithin Dabilpuram 	}
13761d63855bSNithin Dabilpuram 
137786e2487cSAkhil Goyal 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
137886e2487cSAkhil Goyal 		ret = create_default_flow(port_id);
137986e2487cSAkhil Goyal 		if (ret)
138086e2487cSAkhil Goyal 			goto out;
138186e2487cSAkhil Goyal 	}
1382c215f6cdSNithin Dabilpuram 	outer_ipv4 = is_outer_ipv4(td);
1383c215f6cdSNithin Dabilpuram 
138486e2487cSAkhil Goyal 	for (i = 0; i < nb_pkts; i++) {
138586e2487cSAkhil Goyal 		tx_pkts_burst[i] = init_packet(mbufpool, td->input_text.data,
1386c215f6cdSNithin Dabilpuram 						td->input_text.len, outer_ipv4);
138786e2487cSAkhil Goyal 		if (tx_pkts_burst[i] == NULL) {
138886e2487cSAkhil Goyal 			while (i--)
138986e2487cSAkhil Goyal 				rte_pktmbuf_free(tx_pkts_burst[i]);
139086e2487cSAkhil Goyal 			ret = TEST_FAILED;
139186e2487cSAkhil Goyal 			goto out;
139286e2487cSAkhil Goyal 		}
139386e2487cSAkhil Goyal 
139486e2487cSAkhil Goyal 		if (test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkts_burst[i],
139586e2487cSAkhil Goyal 					uint8_t *, RTE_ETHER_HDR_LEN), flags)) {
139686e2487cSAkhil Goyal 			while (i--)
139786e2487cSAkhil Goyal 				rte_pktmbuf_free(tx_pkts_burst[i]);
139886e2487cSAkhil Goyal 			ret = TEST_FAILED;
139986e2487cSAkhil Goyal 			goto out;
140086e2487cSAkhil Goyal 		}
140186e2487cSAkhil Goyal 
140286e2487cSAkhil Goyal 		if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
140386e2487cSAkhil Goyal 			if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
140486e2487cSAkhil Goyal 				rte_security_set_pkt_metadata(ctx, ses,
140586e2487cSAkhil Goyal 						tx_pkts_burst[i], NULL);
140686e2487cSAkhil Goyal 			tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
140786e2487cSAkhil Goyal 		}
140886e2487cSAkhil Goyal 	}
140986e2487cSAkhil Goyal 	/* Send packet to ethdev for inline IPsec processing. */
141010864656SVolodymyr Fialko 	if (event_mode_enabled)
141110864656SVolodymyr Fialko 		nb_sent = event_tx_burst(tx_pkts_burst, nb_pkts);
141210864656SVolodymyr Fialko 	else
141386e2487cSAkhil Goyal 		nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_pkts);
141410864656SVolodymyr Fialko 
141586e2487cSAkhil Goyal 	if (nb_sent != nb_pkts) {
141610864656SVolodymyr Fialko 		printf("\nUnable to TX %d packets, sent: %i", nb_pkts, nb_sent);
141786e2487cSAkhil Goyal 		for ( ; nb_sent < nb_pkts; nb_sent++)
141886e2487cSAkhil Goyal 			rte_pktmbuf_free(tx_pkts_burst[nb_sent]);
141986e2487cSAkhil Goyal 		ret = TEST_FAILED;
142086e2487cSAkhil Goyal 		goto out;
142186e2487cSAkhil Goyal 	}
142286e2487cSAkhil Goyal 
142386e2487cSAkhil Goyal 	rte_pause();
142486e2487cSAkhil Goyal 
142586e2487cSAkhil Goyal 	/* Receive back packet on loopback interface. */
142610864656SVolodymyr Fialko 	if (event_mode_enabled)
142710864656SVolodymyr Fialko 		nb_rx = event_rx_burst(rx_pkts_burst, nb_sent);
142810864656SVolodymyr Fialko 	else
142986e2487cSAkhil Goyal 		do {
143086e2487cSAkhil Goyal 			rte_delay_ms(1);
143110864656SVolodymyr Fialko 			nb_rx += rte_eth_rx_burst(port_id, 0,
143210864656SVolodymyr Fialko 					&rx_pkts_burst[nb_rx],
143386e2487cSAkhil Goyal 					nb_sent - nb_rx);
143486e2487cSAkhil Goyal 			if (nb_rx >= nb_sent)
143586e2487cSAkhil Goyal 				break;
143686e2487cSAkhil Goyal 		} while (j++ < 5 || nb_rx == 0);
143786e2487cSAkhil Goyal 
1438ff8ef86cSVamsi Attunuru 	if (!flags->sa_expiry_pkts_hard &&
1439ff8ef86cSVamsi Attunuru 			!flags->sa_expiry_bytes_hard &&
1440ff8ef86cSVamsi Attunuru 			(nb_rx != nb_sent)) {
144110864656SVolodymyr Fialko 		printf("\nUnable to RX all %d packets, received(%i)",
144210864656SVolodymyr Fialko 				nb_sent, nb_rx);
144310864656SVolodymyr Fialko 		while (--nb_rx >= 0)
144486e2487cSAkhil Goyal 			rte_pktmbuf_free(rx_pkts_burst[nb_rx]);
144586e2487cSAkhil Goyal 		ret = TEST_FAILED;
144686e2487cSAkhil Goyal 		goto out;
144786e2487cSAkhil Goyal 	}
144886e2487cSAkhil Goyal 
144986e2487cSAkhil Goyal 	for (i = 0; i < nb_rx; i++) {
145086e2487cSAkhil Goyal 		rte_pktmbuf_adj(rx_pkts_burst[i], RTE_ETHER_HDR_LEN);
145186e2487cSAkhil Goyal 
1452*4677de0aSSrujana Challa 		/* For tests with status as error for test success,
1453*4677de0aSSrujana Challa 		 * skip verification
1454*4677de0aSSrujana Challa 		 */
1455*4677de0aSSrujana Challa 		if (td->ipsec_xform.direction ==
1456*4677de0aSSrujana Challa 		    RTE_SECURITY_IPSEC_SA_DIR_INGRESS && (flags->icv_corrupt ||
1457*4677de0aSSrujana Challa 		    flags->sa_expiry_pkts_hard || flags->tunnel_hdr_verify ||
1458*4677de0aSSrujana Challa 		    td->ar_packet)) {
1459*4677de0aSSrujana Challa 			if (!(rx_pkts_burst[i]->ol_flags &
1460*4677de0aSSrujana Challa 			    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
1461*4677de0aSSrujana Challa 				rte_pktmbuf_free(rx_pkts_burst[i]);
1462*4677de0aSSrujana Challa 				rx_pkts_burst[i] = NULL;
1463*4677de0aSSrujana Challa 				return TEST_FAILED;
1464*4677de0aSSrujana Challa 			}
1465*4677de0aSSrujana Challa 		} else {
146686e2487cSAkhil Goyal 			ret = test_ipsec_post_process(rx_pkts_burst[i], td,
146786e2487cSAkhil Goyal 						      res_d, silent, flags);
146886e2487cSAkhil Goyal 			if (ret != TEST_SUCCESS) {
146986e2487cSAkhil Goyal 				for ( ; i < nb_rx; i++)
147086e2487cSAkhil Goyal 					rte_pktmbuf_free(rx_pkts_burst[i]);
147186e2487cSAkhil Goyal 				goto out;
147286e2487cSAkhil Goyal 			}
1473*4677de0aSSrujana Challa 		}
147486e2487cSAkhil Goyal 
147586e2487cSAkhil Goyal 		ret = test_ipsec_stats_verify(ctx, ses, flags,
147686e2487cSAkhil Goyal 					td->ipsec_xform.direction);
147786e2487cSAkhil Goyal 		if (ret != TEST_SUCCESS) {
147886e2487cSAkhil Goyal 			for ( ; i < nb_rx; i++)
147986e2487cSAkhil Goyal 				rte_pktmbuf_free(rx_pkts_burst[i]);
148086e2487cSAkhil Goyal 			goto out;
148186e2487cSAkhil Goyal 		}
148286e2487cSAkhil Goyal 
14831d63855bSNithin Dabilpuram 		if (flags->inb_oop) {
14841d63855bSNithin Dabilpuram 			ret = verify_inbound_oop(td, silent, rx_pkts_burst[i]);
14851d63855bSNithin Dabilpuram 			if (ret != TEST_SUCCESS) {
14861d63855bSNithin Dabilpuram 				for ( ; i < nb_rx; i++)
14871d63855bSNithin Dabilpuram 					rte_pktmbuf_free(rx_pkts_burst[i]);
14881d63855bSNithin Dabilpuram 				goto out;
14891d63855bSNithin Dabilpuram 			}
14901d63855bSNithin Dabilpuram 		}
14911d63855bSNithin Dabilpuram 
149286e2487cSAkhil Goyal 		rte_pktmbuf_free(rx_pkts_burst[i]);
149386e2487cSAkhil Goyal 		rx_pkts_burst[i] = NULL;
149486e2487cSAkhil Goyal 	}
149586e2487cSAkhil Goyal 
149686e2487cSAkhil Goyal out:
149786e2487cSAkhil Goyal 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
149886e2487cSAkhil Goyal 		destroy_default_flow(port_id);
1499ff8ef86cSVamsi Attunuru 	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
1500ff8ef86cSVamsi Attunuru 		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
150134e8a9d9SVamsi Attunuru 		if (vector.notify_event && (vector.event == event))
150234e8a9d9SVamsi Attunuru 			ret = TEST_SUCCESS;
150334e8a9d9SVamsi Attunuru 		else
150434e8a9d9SVamsi Attunuru 			ret = TEST_FAILED;
150534e8a9d9SVamsi Attunuru 
150634e8a9d9SVamsi Attunuru 		rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_IPSEC,
150734e8a9d9SVamsi Attunuru 			test_ipsec_inline_sa_exp_event_callback, &vector);
150834e8a9d9SVamsi Attunuru 	}
150986e2487cSAkhil Goyal 
151086e2487cSAkhil Goyal 	/* Destroy session so that other cases can create the session again */
151186e2487cSAkhil Goyal 	rte_security_session_destroy(ctx, ses);
151286e2487cSAkhil Goyal 	ses = NULL;
151386e2487cSAkhil Goyal 
151486e2487cSAkhil Goyal 	return ret;
151586e2487cSAkhil Goyal }
151686e2487cSAkhil Goyal 
151786e2487cSAkhil Goyal static int
151878dc764eSAkhil Goyal test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
151978dc764eSAkhil Goyal {
152078dc764eSAkhil Goyal 	struct ipsec_test_data td_outb;
152178dc764eSAkhil Goyal 	struct ipsec_test_data td_inb;
152278dc764eSAkhil Goyal 	unsigned int i, nb_pkts = 1, pass_cnt = 0, fail_cnt = 0;
152378dc764eSAkhil Goyal 	int ret;
152478dc764eSAkhil Goyal 
152578dc764eSAkhil Goyal 	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
152634e8a9d9SVamsi Attunuru 			flags->sa_expiry_bytes_soft ||
1527ff8ef86cSVamsi Attunuru 			flags->sa_expiry_bytes_hard ||
152878dc764eSAkhil Goyal 			flags->sa_expiry_pkts_hard)
1529838e8decSVidya Sagar Velumuri 		nb_pkts = TEST_SEC_PKTS_MAX;
153078dc764eSAkhil Goyal 
1531838e8decSVidya Sagar Velumuri 	for (i = 0; i < RTE_DIM(sec_alg_list); i++) {
1532838e8decSVidya Sagar Velumuri 		test_ipsec_td_prepare(sec_alg_list[i].param1,
1533838e8decSVidya Sagar Velumuri 				      sec_alg_list[i].param2,
153478dc764eSAkhil Goyal 				      flags, &td_outb, 1);
153578dc764eSAkhil Goyal 
153678dc764eSAkhil Goyal 		if (!td_outb.aead) {
153778dc764eSAkhil Goyal 			enum rte_crypto_cipher_algorithm cipher_alg;
153878dc764eSAkhil Goyal 			enum rte_crypto_auth_algorithm auth_alg;
153978dc764eSAkhil Goyal 
154078dc764eSAkhil Goyal 			cipher_alg = td_outb.xform.chain.cipher.cipher.algo;
154178dc764eSAkhil Goyal 			auth_alg = td_outb.xform.chain.auth.auth.algo;
154278dc764eSAkhil Goyal 
154378dc764eSAkhil Goyal 			if (td_outb.aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
154478dc764eSAkhil Goyal 				continue;
154578dc764eSAkhil Goyal 
154678dc764eSAkhil Goyal 			/* ICV is not applicable for NULL auth */
154778dc764eSAkhil Goyal 			if (flags->icv_corrupt &&
154878dc764eSAkhil Goyal 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
154978dc764eSAkhil Goyal 				continue;
155078dc764eSAkhil Goyal 
155178dc764eSAkhil Goyal 			/* IV is not applicable for NULL cipher */
155278dc764eSAkhil Goyal 			if (flags->iv_gen &&
155378dc764eSAkhil Goyal 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
155478dc764eSAkhil Goyal 				continue;
155578dc764eSAkhil Goyal 		}
155678dc764eSAkhil Goyal 
155778dc764eSAkhil Goyal 		if (flags->udp_encap)
155878dc764eSAkhil Goyal 			td_outb.ipsec_xform.options.udp_encap = 1;
155978dc764eSAkhil Goyal 
156034e8a9d9SVamsi Attunuru 		if (flags->sa_expiry_bytes_soft)
156134e8a9d9SVamsi Attunuru 			td_outb.ipsec_xform.life.bytes_soft_limit =
156234e8a9d9SVamsi Attunuru 				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
156334e8a9d9SVamsi Attunuru 				  * nb_pkts) >> 3) - 1;
1564ff8ef86cSVamsi Attunuru 		if (flags->sa_expiry_pkts_hard)
1565838e8decSVidya Sagar Velumuri 			td_outb.ipsec_xform.life.packets_hard_limit = TEST_SEC_PKTS_MAX - 1;
1566ff8ef86cSVamsi Attunuru 		if (flags->sa_expiry_bytes_hard)
1567ff8ef86cSVamsi Attunuru 			td_outb.ipsec_xform.life.bytes_hard_limit =
1568ff8ef86cSVamsi Attunuru 				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
1569ff8ef86cSVamsi Attunuru 				  * nb_pkts) >> 3) - 1;
157034e8a9d9SVamsi Attunuru 
157178dc764eSAkhil Goyal 		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
157278dc764eSAkhil Goyal 						false, flags);
157378dc764eSAkhil Goyal 		if (ret == TEST_SKIPPED)
157478dc764eSAkhil Goyal 			continue;
157578dc764eSAkhil Goyal 
157678dc764eSAkhil Goyal 		if (ret == TEST_FAILED) {
157778dc764eSAkhil Goyal 			printf("\n TEST FAILED");
1578838e8decSVidya Sagar Velumuri 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
157978dc764eSAkhil Goyal 			fail_cnt++;
158078dc764eSAkhil Goyal 			continue;
158178dc764eSAkhil Goyal 		}
158278dc764eSAkhil Goyal 
158378dc764eSAkhil Goyal 		test_ipsec_td_update(&td_inb, &td_outb, 1, flags);
158478dc764eSAkhil Goyal 
158578dc764eSAkhil Goyal 		ret = test_ipsec_inline_proto_process(&td_inb, NULL, nb_pkts,
158678dc764eSAkhil Goyal 						false, flags);
158778dc764eSAkhil Goyal 		if (ret == TEST_SKIPPED)
158878dc764eSAkhil Goyal 			continue;
158978dc764eSAkhil Goyal 
159078dc764eSAkhil Goyal 		if (ret == TEST_FAILED) {
159178dc764eSAkhil Goyal 			printf("\n TEST FAILED");
1592838e8decSVidya Sagar Velumuri 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
159378dc764eSAkhil Goyal 			fail_cnt++;
159478dc764eSAkhil Goyal 			continue;
159578dc764eSAkhil Goyal 		}
159678dc764eSAkhil Goyal 
159778dc764eSAkhil Goyal 		if (flags->display_alg)
1598838e8decSVidya Sagar Velumuri 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
159978dc764eSAkhil Goyal 
160078dc764eSAkhil Goyal 		pass_cnt++;
160178dc764eSAkhil Goyal 	}
160278dc764eSAkhil Goyal 
160378dc764eSAkhil Goyal 	printf("Tests passed: %d, failed: %d", pass_cnt, fail_cnt);
160478dc764eSAkhil Goyal 	if (fail_cnt > 0)
160578dc764eSAkhil Goyal 		return TEST_FAILED;
160678dc764eSAkhil Goyal 	if (pass_cnt > 0)
160778dc764eSAkhil Goyal 		return TEST_SUCCESS;
160878dc764eSAkhil Goyal 	else
160978dc764eSAkhil Goyal 		return TEST_SKIPPED;
161078dc764eSAkhil Goyal }
161178dc764eSAkhil Goyal 
1612fd33d9eeSAkhil Goyal static int
1613fd33d9eeSAkhil Goyal test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],
1614fd33d9eeSAkhil Goyal 		struct ipsec_test_data res_d[],
1615fd33d9eeSAkhil Goyal 		int nb_pkts,
1616fd33d9eeSAkhil Goyal 		bool silent,
1617fd33d9eeSAkhil Goyal 		const struct ipsec_test_flags *flags)
1618fd33d9eeSAkhil Goyal {
1619fd33d9eeSAkhil Goyal 	struct rte_security_session_conf sess_conf = {0};
1620fd33d9eeSAkhil Goyal 	struct ipsec_test_data *res_d_tmp = NULL;
1621fd33d9eeSAkhil Goyal 	struct rte_crypto_sym_xform cipher = {0};
1622fd33d9eeSAkhil Goyal 	struct rte_crypto_sym_xform auth = {0};
1623fd33d9eeSAkhil Goyal 	struct rte_crypto_sym_xform aead = {0};
1624fd33d9eeSAkhil Goyal 	struct rte_mbuf *rx_pkt = NULL;
1625fd33d9eeSAkhil Goyal 	struct rte_mbuf *tx_pkt = NULL;
1626fd33d9eeSAkhil Goyal 	int nb_rx, nb_sent;
16272973dbf9SAkhil Goyal 	void *ses;
162879bdb787SAkhil Goyal 	void *ctx;
1629fd33d9eeSAkhil Goyal 	uint32_t ol_flags;
1630c215f6cdSNithin Dabilpuram 	bool outer_ipv4;
1631fd33d9eeSAkhil Goyal 	int i, ret;
1632fd33d9eeSAkhil Goyal 
1633fd33d9eeSAkhil Goyal 	if (td[0].aead) {
1634fd33d9eeSAkhil Goyal 		sess_conf.crypto_xform = &aead;
1635fd33d9eeSAkhil Goyal 	} else {
1636fd33d9eeSAkhil Goyal 		if (td[0].ipsec_xform.direction ==
1637fd33d9eeSAkhil Goyal 				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1638fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform = &cipher;
1639fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1640fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->next = &auth;
1641fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
1642fd33d9eeSAkhil Goyal 		} else {
1643fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform = &auth;
1644fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
1645fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->next = &cipher;
1646fd33d9eeSAkhil Goyal 			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1647fd33d9eeSAkhil Goyal 		}
1648fd33d9eeSAkhil Goyal 	}
1649fd33d9eeSAkhil Goyal 
1650fd33d9eeSAkhil Goyal 	/* Create Inline IPsec session. */
1651fd33d9eeSAkhil Goyal 	ret = create_inline_ipsec_session(&td[0], port_id, &ses, &ctx,
1652fd33d9eeSAkhil Goyal 					  &ol_flags, flags, &sess_conf);
1653fd33d9eeSAkhil Goyal 	if (ret)
1654fd33d9eeSAkhil Goyal 		return ret;
1655fd33d9eeSAkhil Goyal 
1656fd33d9eeSAkhil Goyal 	if (td[0].ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
1657fd33d9eeSAkhil Goyal 		ret = create_default_flow(port_id);
1658fd33d9eeSAkhil Goyal 		if (ret)
1659fd33d9eeSAkhil Goyal 			goto out;
1660fd33d9eeSAkhil Goyal 	}
1661c215f6cdSNithin Dabilpuram 	outer_ipv4 = is_outer_ipv4(td);
1662fd33d9eeSAkhil Goyal 
1663fd33d9eeSAkhil Goyal 	for (i = 0; i < nb_pkts; i++) {
1664fd33d9eeSAkhil Goyal 		tx_pkt = init_packet(mbufpool, td[i].input_text.data,
1665c215f6cdSNithin Dabilpuram 					td[i].input_text.len, outer_ipv4);
1666fd33d9eeSAkhil Goyal 		if (tx_pkt == NULL) {
1667fd33d9eeSAkhil Goyal 			ret = TEST_FAILED;
1668fd33d9eeSAkhil Goyal 			goto out;
1669fd33d9eeSAkhil Goyal 		}
1670fd33d9eeSAkhil Goyal 
1671fd33d9eeSAkhil Goyal 		if (test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkt,
1672fd33d9eeSAkhil Goyal 					uint8_t *, RTE_ETHER_HDR_LEN), flags)) {
1673fd33d9eeSAkhil Goyal 			ret = TEST_FAILED;
1674fd33d9eeSAkhil Goyal 			goto out;
1675fd33d9eeSAkhil Goyal 		}
1676fd33d9eeSAkhil Goyal 
1677fd33d9eeSAkhil Goyal 		if (td[i].ipsec_xform.direction ==
1678fd33d9eeSAkhil Goyal 				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1679fd33d9eeSAkhil Goyal 			if (flags->antireplay) {
1680fd33d9eeSAkhil Goyal 				sess_conf.ipsec.esn.value =
1681fd33d9eeSAkhil Goyal 						td[i].ipsec_xform.esn.value;
1682fd33d9eeSAkhil Goyal 				ret = rte_security_session_update(ctx, ses,
1683fd33d9eeSAkhil Goyal 						&sess_conf);
1684fd33d9eeSAkhil Goyal 				if (ret) {
1685fd33d9eeSAkhil Goyal 					printf("Could not update ESN in session\n");
1686fd33d9eeSAkhil Goyal 					rte_pktmbuf_free(tx_pkt);
1687fd33d9eeSAkhil Goyal 					ret = TEST_SKIPPED;
1688fd33d9eeSAkhil Goyal 					goto out;
1689fd33d9eeSAkhil Goyal 				}
1690fd33d9eeSAkhil Goyal 			}
1691fd33d9eeSAkhil Goyal 			if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
1692fd33d9eeSAkhil Goyal 				rte_security_set_pkt_metadata(ctx, ses,
1693fd33d9eeSAkhil Goyal 						tx_pkt, NULL);
1694fd33d9eeSAkhil Goyal 			tx_pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
1695fd33d9eeSAkhil Goyal 		}
16960f2748a0SVidya Sagar Velumuri 
1697fd33d9eeSAkhil Goyal 		/* Send packet to ethdev for inline IPsec processing. */
16980f2748a0SVidya Sagar Velumuri 		if (event_mode_enabled)
16990f2748a0SVidya Sagar Velumuri 			nb_sent = event_tx_burst(&tx_pkt, 1);
17000f2748a0SVidya Sagar Velumuri 		else
1701fd33d9eeSAkhil Goyal 			nb_sent = rte_eth_tx_burst(port_id, 0, &tx_pkt, 1);
17020f2748a0SVidya Sagar Velumuri 
1703fd33d9eeSAkhil Goyal 		if (nb_sent != 1) {
1704fd33d9eeSAkhil Goyal 			printf("\nUnable to TX packets");
1705fd33d9eeSAkhil Goyal 			rte_pktmbuf_free(tx_pkt);
1706fd33d9eeSAkhil Goyal 			ret = TEST_FAILED;
1707fd33d9eeSAkhil Goyal 			goto out;
1708fd33d9eeSAkhil Goyal 		}
1709fd33d9eeSAkhil Goyal 
1710fd33d9eeSAkhil Goyal 		rte_pause();
1711fd33d9eeSAkhil Goyal 
1712fd33d9eeSAkhil Goyal 		/* Receive back packet on loopback interface. */
17130f2748a0SVidya Sagar Velumuri 		if (event_mode_enabled)
17140f2748a0SVidya Sagar Velumuri 			nb_rx = event_rx_burst(&rx_pkt, nb_sent);
17150f2748a0SVidya Sagar Velumuri 		else {
1716fd33d9eeSAkhil Goyal 			do {
1717fd33d9eeSAkhil Goyal 				rte_delay_ms(1);
1718fd33d9eeSAkhil Goyal 				nb_rx = rte_eth_rx_burst(port_id, 0, &rx_pkt, 1);
1719fd33d9eeSAkhil Goyal 			} while (nb_rx == 0);
17200f2748a0SVidya Sagar Velumuri 		}
1721fd33d9eeSAkhil Goyal 		rte_pktmbuf_adj(rx_pkt, RTE_ETHER_HDR_LEN);
1722fd33d9eeSAkhil Goyal 
1723fd33d9eeSAkhil Goyal 		if (res_d != NULL)
1724fd33d9eeSAkhil Goyal 			res_d_tmp = &res_d[i];
1725fd33d9eeSAkhil Goyal 
1726fd33d9eeSAkhil Goyal 		ret = test_ipsec_post_process(rx_pkt, &td[i],
1727fd33d9eeSAkhil Goyal 					      res_d_tmp, silent, flags);
1728fd33d9eeSAkhil Goyal 		if (ret != TEST_SUCCESS) {
1729fd33d9eeSAkhil Goyal 			rte_pktmbuf_free(rx_pkt);
1730fd33d9eeSAkhil Goyal 			goto out;
1731fd33d9eeSAkhil Goyal 		}
1732fd33d9eeSAkhil Goyal 
1733fd33d9eeSAkhil Goyal 		ret = test_ipsec_stats_verify(ctx, ses, flags,
1734fd33d9eeSAkhil Goyal 					td->ipsec_xform.direction);
1735fd33d9eeSAkhil Goyal 		if (ret != TEST_SUCCESS) {
1736fd33d9eeSAkhil Goyal 			rte_pktmbuf_free(rx_pkt);
1737fd33d9eeSAkhil Goyal 			goto out;
1738fd33d9eeSAkhil Goyal 		}
1739fd33d9eeSAkhil Goyal 
1740fd33d9eeSAkhil Goyal 		rte_pktmbuf_free(rx_pkt);
1741fd33d9eeSAkhil Goyal 		rx_pkt = NULL;
1742fd33d9eeSAkhil Goyal 		tx_pkt = NULL;
1743fd33d9eeSAkhil Goyal 	}
1744fd33d9eeSAkhil Goyal 
1745fd33d9eeSAkhil Goyal out:
1746fd33d9eeSAkhil Goyal 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
1747fd33d9eeSAkhil Goyal 		destroy_default_flow(port_id);
1748fd33d9eeSAkhil Goyal 
1749fd33d9eeSAkhil Goyal 	/* Destroy session so that other cases can create the session again */
1750fd33d9eeSAkhil Goyal 	rte_security_session_destroy(ctx, ses);
1751fd33d9eeSAkhil Goyal 	ses = NULL;
1752fd33d9eeSAkhil Goyal 
1753fd33d9eeSAkhil Goyal 	return ret;
1754fd33d9eeSAkhil Goyal }
175578dc764eSAkhil Goyal 
175678dc764eSAkhil Goyal static int
17572f97b943SRahul Bhansali ut_setup_inline_ipsec_reassembly(void)
17582f97b943SRahul Bhansali {
17592f97b943SRahul Bhansali 	struct rte_eth_ip_reassembly_params reass_capa = {0};
17602f97b943SRahul Bhansali 	int ret;
17612f97b943SRahul Bhansali 
17622f97b943SRahul Bhansali 	rte_eth_ip_reassembly_capability_get(port_id, &reass_capa);
17632f97b943SRahul Bhansali 	if (reass_capa.timeout_ms > APP_REASS_TIMEOUT) {
17642f97b943SRahul Bhansali 		reass_capa.timeout_ms = APP_REASS_TIMEOUT;
17652f97b943SRahul Bhansali 		rte_eth_ip_reassembly_conf_set(port_id, &reass_capa);
17662f97b943SRahul Bhansali 	}
17672f97b943SRahul Bhansali 
17682f97b943SRahul Bhansali 	/* Start event devices */
17692f97b943SRahul Bhansali 	if (event_mode_enabled) {
17702f97b943SRahul Bhansali 		ret = rte_event_eth_rx_adapter_start(rx_adapter_id);
17712f97b943SRahul Bhansali 		if (ret < 0) {
17722f97b943SRahul Bhansali 			printf("Failed to start rx adapter %d\n", ret);
17732f97b943SRahul Bhansali 			return ret;
17742f97b943SRahul Bhansali 		}
17752f97b943SRahul Bhansali 
17762f97b943SRahul Bhansali 		ret = rte_event_dev_start(eventdev_id);
17772f97b943SRahul Bhansali 		if (ret < 0) {
17782f97b943SRahul Bhansali 			printf("Failed to start event device %d\n", ret);
17792f97b943SRahul Bhansali 			return ret;
17802f97b943SRahul Bhansali 		}
17812f97b943SRahul Bhansali 	}
17822f97b943SRahul Bhansali 
17832f97b943SRahul Bhansali 	/* Start device */
17842f97b943SRahul Bhansali 	ret = rte_eth_dev_start(port_id);
17852f97b943SRahul Bhansali 	if (ret < 0) {
17862f97b943SRahul Bhansali 		printf("rte_eth_dev_start: err=%d, port=%d\n",
17872f97b943SRahul Bhansali 			ret, port_id);
17882f97b943SRahul Bhansali 		return ret;
17892f97b943SRahul Bhansali 	}
17902f97b943SRahul Bhansali 	/* always enable promiscuous */
17912f97b943SRahul Bhansali 	ret = rte_eth_promiscuous_enable(port_id);
17922f97b943SRahul Bhansali 	if (ret != 0) {
17932f97b943SRahul Bhansali 		printf("rte_eth_promiscuous_enable: err=%s, port=%d\n",
17942f97b943SRahul Bhansali 			rte_strerror(-ret), port_id);
17952f97b943SRahul Bhansali 		return ret;
17962f97b943SRahul Bhansali 	}
17972f97b943SRahul Bhansali 
17982f97b943SRahul Bhansali 	check_all_ports_link_status(1, RTE_PORT_ALL);
17992f97b943SRahul Bhansali 
18002f97b943SRahul Bhansali 	return 0;
18012f97b943SRahul Bhansali }
18022f97b943SRahul Bhansali 
18032f97b943SRahul Bhansali static void
18042f97b943SRahul Bhansali ut_teardown_inline_ipsec_reassembly(void)
18052f97b943SRahul Bhansali {
18062f97b943SRahul Bhansali 	struct rte_eth_ip_reassembly_params reass_conf = {0};
18072f97b943SRahul Bhansali 	uint16_t portid;
18082f97b943SRahul Bhansali 	int ret;
18092f97b943SRahul Bhansali 
18102f97b943SRahul Bhansali 	/* Stop event devices */
18112f97b943SRahul Bhansali 	if (event_mode_enabled)
18122f97b943SRahul Bhansali 		rte_event_dev_stop(eventdev_id);
18132f97b943SRahul Bhansali 
18142f97b943SRahul Bhansali 	/* port tear down */
18152f97b943SRahul Bhansali 	RTE_ETH_FOREACH_DEV(portid) {
18162f97b943SRahul Bhansali 		ret = rte_eth_dev_stop(portid);
18172f97b943SRahul Bhansali 		if (ret != 0)
18182f97b943SRahul Bhansali 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
18192f97b943SRahul Bhansali 			       rte_strerror(-ret), portid);
18202f97b943SRahul Bhansali 
18212f97b943SRahul Bhansali 		/* Clear reassembly configuration */
18222f97b943SRahul Bhansali 		rte_eth_ip_reassembly_conf_set(portid, &reass_conf);
18232f97b943SRahul Bhansali 	}
18242f97b943SRahul Bhansali }
18252f97b943SRahul Bhansali static int
182619d7fcc5SRahul Bhansali ut_setup_inline_ipsec_rx_inj(void)
182719d7fcc5SRahul Bhansali {
182819d7fcc5SRahul Bhansali 	void *sec_ctx;
182919d7fcc5SRahul Bhansali 	int ret;
183019d7fcc5SRahul Bhansali 
183119d7fcc5SRahul Bhansali 	sec_ctx = rte_eth_dev_get_sec_ctx(port_id);
183219d7fcc5SRahul Bhansali 	ret = rte_security_rx_inject_configure(sec_ctx, port_id, true);
183319d7fcc5SRahul Bhansali 	if (ret) {
183419d7fcc5SRahul Bhansali 		printf("Could not enable Rx inject\n");
183519d7fcc5SRahul Bhansali 		return TEST_SKIPPED;
183619d7fcc5SRahul Bhansali 	}
183719d7fcc5SRahul Bhansali 
183819d7fcc5SRahul Bhansali 	/* Start event devices */
183919d7fcc5SRahul Bhansali 	if (event_mode_enabled) {
184019d7fcc5SRahul Bhansali 		ret = rte_event_dev_start(eventdev_id);
184119d7fcc5SRahul Bhansali 		if (ret < 0) {
184219d7fcc5SRahul Bhansali 			printf("Failed to start event device %d\n", ret);
184319d7fcc5SRahul Bhansali 			return ret;
184419d7fcc5SRahul Bhansali 		}
184519d7fcc5SRahul Bhansali 	}
184619d7fcc5SRahul Bhansali 
184719d7fcc5SRahul Bhansali 	/* Start device */
184819d7fcc5SRahul Bhansali 	ret = rte_eth_dev_start(port_id);
184919d7fcc5SRahul Bhansali 	if (ret < 0) {
185019d7fcc5SRahul Bhansali 		printf("rte_eth_dev_start: err=%d, port=%d\n",
185119d7fcc5SRahul Bhansali 			ret, port_id);
185219d7fcc5SRahul Bhansali 		return ret;
185319d7fcc5SRahul Bhansali 	}
185419d7fcc5SRahul Bhansali 	/* always enable promiscuous */
185519d7fcc5SRahul Bhansali 	ret = rte_eth_promiscuous_enable(port_id);
185619d7fcc5SRahul Bhansali 	if (ret != 0) {
185719d7fcc5SRahul Bhansali 		printf("rte_eth_promiscuous_enable: err=%s, port=%d\n",
185819d7fcc5SRahul Bhansali 			rte_strerror(-ret), port_id);
185919d7fcc5SRahul Bhansali 		return ret;
186019d7fcc5SRahul Bhansali 	}
186119d7fcc5SRahul Bhansali 
186219d7fcc5SRahul Bhansali 	check_all_ports_link_status(1, RTE_PORT_ALL);
186319d7fcc5SRahul Bhansali 
186419d7fcc5SRahul Bhansali 	return 0;
186519d7fcc5SRahul Bhansali }
186619d7fcc5SRahul Bhansali 
186719d7fcc5SRahul Bhansali static int
186886e2487cSAkhil Goyal ut_setup_inline_ipsec(void)
186986e2487cSAkhil Goyal {
187086e2487cSAkhil Goyal 	int ret;
187186e2487cSAkhil Goyal 
18722f97b943SRahul Bhansali 	/* Start event devices */
18732f97b943SRahul Bhansali 	if (event_mode_enabled) {
18742f97b943SRahul Bhansali 		ret = rte_event_dev_start(eventdev_id);
18752f97b943SRahul Bhansali 		if (ret < 0) {
18762f97b943SRahul Bhansali 			printf("Failed to start event device %d\n", ret);
18772f97b943SRahul Bhansali 			return ret;
18782f97b943SRahul Bhansali 		}
18792f97b943SRahul Bhansali 	}
18802f97b943SRahul Bhansali 
188186e2487cSAkhil Goyal 	/* Start device */
188286e2487cSAkhil Goyal 	ret = rte_eth_dev_start(port_id);
188386e2487cSAkhil Goyal 	if (ret < 0) {
188486e2487cSAkhil Goyal 		printf("rte_eth_dev_start: err=%d, port=%d\n",
188586e2487cSAkhil Goyal 			ret, port_id);
188686e2487cSAkhil Goyal 		return ret;
188786e2487cSAkhil Goyal 	}
188886e2487cSAkhil Goyal 	/* always enable promiscuous */
188986e2487cSAkhil Goyal 	ret = rte_eth_promiscuous_enable(port_id);
189086e2487cSAkhil Goyal 	if (ret != 0) {
189186e2487cSAkhil Goyal 		printf("rte_eth_promiscuous_enable: err=%s, port=%d\n",
189286e2487cSAkhil Goyal 			rte_strerror(-ret), port_id);
189386e2487cSAkhil Goyal 		return ret;
189486e2487cSAkhil Goyal 	}
189586e2487cSAkhil Goyal 
189686e2487cSAkhil Goyal 	check_all_ports_link_status(1, RTE_PORT_ALL);
189786e2487cSAkhil Goyal 
189886e2487cSAkhil Goyal 	return 0;
189986e2487cSAkhil Goyal }
190086e2487cSAkhil Goyal 
190186e2487cSAkhil Goyal static void
190219d7fcc5SRahul Bhansali ut_teardown_inline_ipsec_rx_inj(void)
190319d7fcc5SRahul Bhansali {
190419d7fcc5SRahul Bhansali 	uint16_t portid;
190519d7fcc5SRahul Bhansali 	void *sec_ctx;
190619d7fcc5SRahul Bhansali 	int ret;
190719d7fcc5SRahul Bhansali 
190819d7fcc5SRahul Bhansali 	/* Stop event devices */
190919d7fcc5SRahul Bhansali 	if (event_mode_enabled)
191019d7fcc5SRahul Bhansali 		rte_event_dev_stop(eventdev_id);
191119d7fcc5SRahul Bhansali 
191219d7fcc5SRahul Bhansali 	/* port tear down */
191319d7fcc5SRahul Bhansali 	RTE_ETH_FOREACH_DEV(portid) {
191419d7fcc5SRahul Bhansali 		ret = rte_eth_dev_stop(portid);
191519d7fcc5SRahul Bhansali 		if (ret != 0)
191619d7fcc5SRahul Bhansali 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
191719d7fcc5SRahul Bhansali 			       rte_strerror(-ret), portid);
191819d7fcc5SRahul Bhansali 
191919d7fcc5SRahul Bhansali 		sec_ctx = rte_eth_dev_get_sec_ctx(portid);
192019d7fcc5SRahul Bhansali 		ret = rte_security_rx_inject_configure(sec_ctx, portid, false);
192119d7fcc5SRahul Bhansali 		if (ret)
192219d7fcc5SRahul Bhansali 			printf("Could not disable Rx inject\n");
192319d7fcc5SRahul Bhansali 
192419d7fcc5SRahul Bhansali 	}
192519d7fcc5SRahul Bhansali }
192619d7fcc5SRahul Bhansali 
192719d7fcc5SRahul Bhansali static void
192886e2487cSAkhil Goyal ut_teardown_inline_ipsec(void)
192986e2487cSAkhil Goyal {
193086e2487cSAkhil Goyal 	uint16_t portid;
193186e2487cSAkhil Goyal 	int ret;
193286e2487cSAkhil Goyal 
19332f97b943SRahul Bhansali 	/* Stop event devices */
19342f97b943SRahul Bhansali 	if (event_mode_enabled)
19352f97b943SRahul Bhansali 		rte_event_dev_stop(eventdev_id);
19362f97b943SRahul Bhansali 
193786e2487cSAkhil Goyal 	/* port tear down */
193886e2487cSAkhil Goyal 	RTE_ETH_FOREACH_DEV(portid) {
193986e2487cSAkhil Goyal 		ret = rte_eth_dev_stop(portid);
194086e2487cSAkhil Goyal 		if (ret != 0)
194186e2487cSAkhil Goyal 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
194286e2487cSAkhil Goyal 			       rte_strerror(-ret), portid);
194386e2487cSAkhil Goyal 	}
194486e2487cSAkhil Goyal }
194586e2487cSAkhil Goyal 
194686e2487cSAkhil Goyal static int
194786e2487cSAkhil Goyal inline_ipsec_testsuite_setup(void)
194886e2487cSAkhil Goyal {
19493edd1197SNithin Dabilpuram 	struct rte_eth_conf local_port_conf;
19503edd1197SNithin Dabilpuram 	struct rte_eth_dev_info dev_info;
195186e2487cSAkhil Goyal 	uint16_t nb_rxd;
195286e2487cSAkhil Goyal 	uint16_t nb_txd;
195386e2487cSAkhil Goyal 	uint16_t nb_ports;
195486e2487cSAkhil Goyal 	int ret;
195586e2487cSAkhil Goyal 	uint16_t nb_rx_queue = 1, nb_tx_queue = 1;
195686e2487cSAkhil Goyal 
195786e2487cSAkhil Goyal 	printf("Start inline IPsec test.\n");
195886e2487cSAkhil Goyal 
195986e2487cSAkhil Goyal 	nb_ports = rte_eth_dev_count_avail();
196086e2487cSAkhil Goyal 	if (nb_ports < NB_ETHPORTS_USED) {
196186e2487cSAkhil Goyal 		printf("At least %u port(s) used for test\n",
196286e2487cSAkhil Goyal 		       NB_ETHPORTS_USED);
196386e2487cSAkhil Goyal 		return TEST_SKIPPED;
196486e2487cSAkhil Goyal 	}
196586e2487cSAkhil Goyal 
196686e2487cSAkhil Goyal 	ret = init_mempools(NB_MBUF);
196786e2487cSAkhil Goyal 	if (ret)
196886e2487cSAkhil Goyal 		return ret;
196986e2487cSAkhil Goyal 
197086e2487cSAkhil Goyal 	if (tx_pkts_burst == NULL) {
197186e2487cSAkhil Goyal 		tx_pkts_burst = (struct rte_mbuf **)rte_calloc("tx_buff",
197286e2487cSAkhil Goyal 					  MAX_TRAFFIC_BURST,
197386e2487cSAkhil Goyal 					  sizeof(void *),
197486e2487cSAkhil Goyal 					  RTE_CACHE_LINE_SIZE);
197586e2487cSAkhil Goyal 		if (!tx_pkts_burst)
197686e2487cSAkhil Goyal 			return TEST_FAILED;
197786e2487cSAkhil Goyal 
197886e2487cSAkhil Goyal 		rx_pkts_burst = (struct rte_mbuf **)rte_calloc("rx_buff",
197986e2487cSAkhil Goyal 					  MAX_TRAFFIC_BURST,
198086e2487cSAkhil Goyal 					  sizeof(void *),
198186e2487cSAkhil Goyal 					  RTE_CACHE_LINE_SIZE);
198286e2487cSAkhil Goyal 		if (!rx_pkts_burst)
198386e2487cSAkhil Goyal 			return TEST_FAILED;
198486e2487cSAkhil Goyal 	}
198586e2487cSAkhil Goyal 
198686e2487cSAkhil Goyal 	printf("Generate %d packets\n", MAX_TRAFFIC_BURST);
198786e2487cSAkhil Goyal 
19884ed89049SDavid Marchand 	nb_rxd = RX_DESC_DEFAULT;
19894ed89049SDavid Marchand 	nb_txd = TX_DESC_DEFAULT;
199086e2487cSAkhil Goyal 
199186e2487cSAkhil Goyal 	/* configuring port 0 for the test is enough */
199286e2487cSAkhil Goyal 	port_id = 0;
19933edd1197SNithin Dabilpuram 	if (rte_eth_dev_info_get(0, &dev_info)) {
19943edd1197SNithin Dabilpuram 		printf("Failed to get devinfo");
19953edd1197SNithin Dabilpuram 		return -1;
19963edd1197SNithin Dabilpuram 	}
19973edd1197SNithin Dabilpuram 
19983edd1197SNithin Dabilpuram 	memcpy(&local_port_conf, &port_conf, sizeof(port_conf));
19993edd1197SNithin Dabilpuram 	/* Add Multi seg flags */
20003edd1197SNithin Dabilpuram 	if (sg_mode) {
20013edd1197SNithin Dabilpuram 		uint16_t max_data_room = RTE_MBUF_DEFAULT_DATAROOM *
20023edd1197SNithin Dabilpuram 			dev_info.rx_desc_lim.nb_seg_max;
20033edd1197SNithin Dabilpuram 
20043edd1197SNithin Dabilpuram 		local_port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
20053edd1197SNithin Dabilpuram 		local_port_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
20063edd1197SNithin Dabilpuram 		local_port_conf.rxmode.mtu = RTE_MIN(dev_info.max_mtu, max_data_room - 256);
20073edd1197SNithin Dabilpuram 	}
20083edd1197SNithin Dabilpuram 
200986e2487cSAkhil Goyal 	/* port configure */
201086e2487cSAkhil Goyal 	ret = rte_eth_dev_configure(port_id, nb_rx_queue,
20113edd1197SNithin Dabilpuram 				    nb_tx_queue, &local_port_conf);
201286e2487cSAkhil Goyal 	if (ret < 0) {
201386e2487cSAkhil Goyal 		printf("Cannot configure device: err=%d, port=%d\n",
201486e2487cSAkhil Goyal 			 ret, port_id);
201586e2487cSAkhil Goyal 		return ret;
201686e2487cSAkhil Goyal 	}
201786e2487cSAkhil Goyal 	ret = rte_eth_macaddr_get(port_id, &ports_eth_addr[port_id]);
201886e2487cSAkhil Goyal 	if (ret < 0) {
201986e2487cSAkhil Goyal 		printf("Cannot get mac address: err=%d, port=%d\n",
202086e2487cSAkhil Goyal 			 ret, port_id);
202186e2487cSAkhil Goyal 		return ret;
202286e2487cSAkhil Goyal 	}
202386e2487cSAkhil Goyal 	printf("Port %u ", port_id);
202486e2487cSAkhil Goyal 	print_ethaddr("Address:", &ports_eth_addr[port_id]);
202586e2487cSAkhil Goyal 	printf("\n");
202686e2487cSAkhil Goyal 
202786e2487cSAkhil Goyal 	/* tx queue setup */
202886e2487cSAkhil Goyal 	ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
202986e2487cSAkhil Goyal 				     SOCKET_ID_ANY, &tx_conf);
203086e2487cSAkhil Goyal 	if (ret < 0) {
203186e2487cSAkhil Goyal 		printf("rte_eth_tx_queue_setup: err=%d, port=%d\n",
203286e2487cSAkhil Goyal 				ret, port_id);
203386e2487cSAkhil Goyal 		return ret;
203486e2487cSAkhil Goyal 	}
203586e2487cSAkhil Goyal 	/* rx queue steup */
203686e2487cSAkhil Goyal 	ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd, SOCKET_ID_ANY,
203786e2487cSAkhil Goyal 				     &rx_conf, mbufpool);
203886e2487cSAkhil Goyal 	if (ret < 0) {
203986e2487cSAkhil Goyal 		printf("rte_eth_rx_queue_setup: err=%d, port=%d\n",
204086e2487cSAkhil Goyal 				ret, port_id);
204186e2487cSAkhil Goyal 		return ret;
204286e2487cSAkhil Goyal 	}
2043838e8decSVidya Sagar Velumuri 
2044838e8decSVidya Sagar Velumuri 	test_sec_alg_list_populate();
204586e2487cSAkhil Goyal 
20463edd1197SNithin Dabilpuram 	/* Change the plaintext size for tests without Known vectors */
20473edd1197SNithin Dabilpuram 	if (sg_mode) {
20483edd1197SNithin Dabilpuram 		/* Leave space of 256B as ESP packet would be bigger and we
20493edd1197SNithin Dabilpuram 		 * expect packets to be received back on same interface.
20503edd1197SNithin Dabilpuram 		 * Without SG mode, default value is picked.
20513edd1197SNithin Dabilpuram 		 */
20523edd1197SNithin Dabilpuram 		plaintext_len = local_port_conf.rxmode.mtu - 256;
205315ccc647SNithin Dabilpuram 	} else {
205415ccc647SNithin Dabilpuram 		plaintext_len = 0;
20553edd1197SNithin Dabilpuram 	}
20563edd1197SNithin Dabilpuram 
205786e2487cSAkhil Goyal 	return 0;
205886e2487cSAkhil Goyal }
205986e2487cSAkhil Goyal 
206086e2487cSAkhil Goyal static void
206186e2487cSAkhil Goyal inline_ipsec_testsuite_teardown(void)
206286e2487cSAkhil Goyal {
206386e2487cSAkhil Goyal 	uint16_t portid;
206486e2487cSAkhil Goyal 	int ret;
206586e2487cSAkhil Goyal 
206686e2487cSAkhil Goyal 	/* port tear down */
206786e2487cSAkhil Goyal 	RTE_ETH_FOREACH_DEV(portid) {
206886e2487cSAkhil Goyal 		ret = rte_eth_dev_reset(portid);
206986e2487cSAkhil Goyal 		if (ret != 0)
207086e2487cSAkhil Goyal 			printf("rte_eth_dev_reset: err=%s, port=%u\n",
207186e2487cSAkhil Goyal 			       rte_strerror(-ret), port_id);
207286e2487cSAkhil Goyal 	}
207310864656SVolodymyr Fialko 	rte_free(tx_pkts_burst);
207410864656SVolodymyr Fialko 	rte_free(rx_pkts_burst);
207510864656SVolodymyr Fialko }
207610864656SVolodymyr Fialko 
207710864656SVolodymyr Fialko static int
207810864656SVolodymyr Fialko event_inline_ipsec_testsuite_setup(void)
207910864656SVolodymyr Fialko {
208010864656SVolodymyr Fialko 	struct rte_event_eth_rx_adapter_queue_conf queue_conf = {0};
208110864656SVolodymyr Fialko 	struct rte_event_dev_info evdev_default_conf = {0};
208210864656SVolodymyr Fialko 	struct rte_event_dev_config eventdev_conf = {0};
208310864656SVolodymyr Fialko 	struct rte_event_queue_conf eventq_conf = {0};
208410864656SVolodymyr Fialko 	struct rte_event_port_conf ev_port_conf = {0};
208510864656SVolodymyr Fialko 	const uint16_t nb_txd = 1024, nb_rxd = 1024;
208610864656SVolodymyr Fialko 	uint16_t nb_rx_queue = 1, nb_tx_queue = 1;
208710864656SVolodymyr Fialko 	uint8_t ev_queue_id = 0, tx_queue_id = 0;
208810864656SVolodymyr Fialko 	int nb_eventqueue = 1, nb_eventport = 1;
208910864656SVolodymyr Fialko 	const int all_queues = -1;
209010864656SVolodymyr Fialko 	uint32_t caps = 0;
209110864656SVolodymyr Fialko 	uint16_t nb_ports;
209210864656SVolodymyr Fialko 	int ret;
209310864656SVolodymyr Fialko 
209410864656SVolodymyr Fialko 	printf("Start event inline IPsec test.\n");
209510864656SVolodymyr Fialko 
209610864656SVolodymyr Fialko 	nb_ports = rte_eth_dev_count_avail();
209710864656SVolodymyr Fialko 	if (nb_ports == 0) {
209810864656SVolodymyr Fialko 		printf("Test require: 1 port, available: 0\n");
209910864656SVolodymyr Fialko 		return TEST_SKIPPED;
210010864656SVolodymyr Fialko 	}
210110864656SVolodymyr Fialko 
210210864656SVolodymyr Fialko 	init_mempools(NB_MBUF);
210310864656SVolodymyr Fialko 
210410864656SVolodymyr Fialko 	if (tx_pkts_burst == NULL) {
210510864656SVolodymyr Fialko 		tx_pkts_burst = (struct rte_mbuf **)rte_calloc("tx_buff",
210610864656SVolodymyr Fialko 					  MAX_TRAFFIC_BURST,
210710864656SVolodymyr Fialko 					  sizeof(void *),
210810864656SVolodymyr Fialko 					  RTE_CACHE_LINE_SIZE);
210910864656SVolodymyr Fialko 		if (!tx_pkts_burst)
211010864656SVolodymyr Fialko 			return -1;
211110864656SVolodymyr Fialko 
211210864656SVolodymyr Fialko 		rx_pkts_burst = (struct rte_mbuf **)rte_calloc("rx_buff",
211310864656SVolodymyr Fialko 					  MAX_TRAFFIC_BURST,
211410864656SVolodymyr Fialko 					  sizeof(void *),
211510864656SVolodymyr Fialko 					  RTE_CACHE_LINE_SIZE);
211610864656SVolodymyr Fialko 		if (!rx_pkts_burst)
211710864656SVolodymyr Fialko 			return -1;
211810864656SVolodymyr Fialko 
211910864656SVolodymyr Fialko 	}
212010864656SVolodymyr Fialko 
212110864656SVolodymyr Fialko 	printf("Generate %d packets\n", MAX_TRAFFIC_BURST);
212210864656SVolodymyr Fialko 
212310864656SVolodymyr Fialko 	/* configuring port 0 for the test is enough */
212410864656SVolodymyr Fialko 	port_id = 0;
212510864656SVolodymyr Fialko 	/* port configure */
212610864656SVolodymyr Fialko 	ret = rte_eth_dev_configure(port_id, nb_rx_queue,
212710864656SVolodymyr Fialko 				    nb_tx_queue, &port_conf);
212810864656SVolodymyr Fialko 	if (ret < 0) {
212910864656SVolodymyr Fialko 		printf("Cannot configure device: err=%d, port=%d\n",
213010864656SVolodymyr Fialko 			 ret, port_id);
213110864656SVolodymyr Fialko 		return ret;
213210864656SVolodymyr Fialko 	}
213310864656SVolodymyr Fialko 
213410864656SVolodymyr Fialko 	/* Tx queue setup */
213510864656SVolodymyr Fialko 	ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
213610864656SVolodymyr Fialko 				     SOCKET_ID_ANY, &tx_conf);
213710864656SVolodymyr Fialko 	if (ret < 0) {
213810864656SVolodymyr Fialko 		printf("rte_eth_tx_queue_setup: err=%d, port=%d\n",
213910864656SVolodymyr Fialko 				ret, port_id);
214010864656SVolodymyr Fialko 		return ret;
214110864656SVolodymyr Fialko 	}
214210864656SVolodymyr Fialko 
214310864656SVolodymyr Fialko 	/* rx queue steup */
214410864656SVolodymyr Fialko 	ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd, SOCKET_ID_ANY,
214510864656SVolodymyr Fialko 				     &rx_conf, mbufpool);
214610864656SVolodymyr Fialko 	if (ret < 0) {
214710864656SVolodymyr Fialko 		printf("rte_eth_rx_queue_setup: err=%d, port=%d\n",
214810864656SVolodymyr Fialko 				ret, port_id);
214910864656SVolodymyr Fialko 		return ret;
215010864656SVolodymyr Fialko 	}
215110864656SVolodymyr Fialko 
215210864656SVolodymyr Fialko 	/* Setup eventdev */
215310864656SVolodymyr Fialko 	eventdev_id = 0;
215410864656SVolodymyr Fialko 	rx_adapter_id = 0;
215510864656SVolodymyr Fialko 	tx_adapter_id = 0;
215610864656SVolodymyr Fialko 
215710864656SVolodymyr Fialko 	/* Get default conf of eventdev */
215810864656SVolodymyr Fialko 	ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
215910864656SVolodymyr Fialko 	if (ret < 0) {
216010864656SVolodymyr Fialko 		printf("Error in getting event device info[devID:%d]\n",
216110864656SVolodymyr Fialko 				eventdev_id);
216210864656SVolodymyr Fialko 		return ret;
216310864656SVolodymyr Fialko 	}
216410864656SVolodymyr Fialko 
216510864656SVolodymyr Fialko 	/* Get Tx adapter capabilities */
216610864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_caps_get(eventdev_id, tx_adapter_id, &caps);
216710864656SVolodymyr Fialko 	if (ret < 0) {
216810864656SVolodymyr Fialko 		printf("Failed to get event device %d eth tx adapter"
216910864656SVolodymyr Fialko 				" capabilities for port %d\n",
217010864656SVolodymyr Fialko 				eventdev_id, port_id);
217110864656SVolodymyr Fialko 		return ret;
217210864656SVolodymyr Fialko 	}
217310864656SVolodymyr Fialko 	if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
217410864656SVolodymyr Fialko 		tx_queue_id = nb_eventqueue++;
217510864656SVolodymyr Fialko 
217610864656SVolodymyr Fialko 	eventdev_conf.nb_events_limit =
217710864656SVolodymyr Fialko 			evdev_default_conf.max_num_events;
217810864656SVolodymyr Fialko 	eventdev_conf.nb_event_queue_flows =
217910864656SVolodymyr Fialko 			evdev_default_conf.max_event_queue_flows;
218010864656SVolodymyr Fialko 	eventdev_conf.nb_event_port_dequeue_depth =
218110864656SVolodymyr Fialko 			evdev_default_conf.max_event_port_dequeue_depth;
218210864656SVolodymyr Fialko 	eventdev_conf.nb_event_port_enqueue_depth =
218310864656SVolodymyr Fialko 			evdev_default_conf.max_event_port_enqueue_depth;
218410864656SVolodymyr Fialko 
218510864656SVolodymyr Fialko 	eventdev_conf.nb_event_queues = nb_eventqueue;
218610864656SVolodymyr Fialko 	eventdev_conf.nb_event_ports = nb_eventport;
218710864656SVolodymyr Fialko 
218810864656SVolodymyr Fialko 	/* Configure event device */
218910864656SVolodymyr Fialko 
219010864656SVolodymyr Fialko 	ret = rte_event_dev_configure(eventdev_id, &eventdev_conf);
219110864656SVolodymyr Fialko 	if (ret < 0) {
219210864656SVolodymyr Fialko 		printf("Error in configuring event device\n");
219310864656SVolodymyr Fialko 		return ret;
219410864656SVolodymyr Fialko 	}
219510864656SVolodymyr Fialko 
219610864656SVolodymyr Fialko 	/* Configure event queue */
219710864656SVolodymyr Fialko 	eventq_conf.schedule_type = RTE_SCHED_TYPE_PARALLEL;
219810864656SVolodymyr Fialko 	eventq_conf.nb_atomic_flows = 1024;
219910864656SVolodymyr Fialko 	eventq_conf.nb_atomic_order_sequences = 1024;
220010864656SVolodymyr Fialko 
220110864656SVolodymyr Fialko 	/* Setup the queue */
220210864656SVolodymyr Fialko 	ret = rte_event_queue_setup(eventdev_id, ev_queue_id, &eventq_conf);
220310864656SVolodymyr Fialko 	if (ret < 0) {
220410864656SVolodymyr Fialko 		printf("Failed to setup event queue %d\n", ret);
220510864656SVolodymyr Fialko 		return ret;
220610864656SVolodymyr Fialko 	}
220710864656SVolodymyr Fialko 
220810864656SVolodymyr Fialko 	/* Configure event port */
220910864656SVolodymyr Fialko 	ret = rte_event_port_setup(eventdev_id, port_id, NULL);
221010864656SVolodymyr Fialko 	if (ret < 0) {
221110864656SVolodymyr Fialko 		printf("Failed to setup event port %d\n", ret);
221210864656SVolodymyr Fialko 		return ret;
221310864656SVolodymyr Fialko 	}
221410864656SVolodymyr Fialko 
221510864656SVolodymyr Fialko 	/* Make event queue - event port link */
221610864656SVolodymyr Fialko 	ret = rte_event_port_link(eventdev_id, port_id, NULL, NULL, 1);
221710864656SVolodymyr Fialko 	if (ret < 0) {
221810864656SVolodymyr Fialko 		printf("Failed to link event port %d\n", ret);
221910864656SVolodymyr Fialko 		return ret;
222010864656SVolodymyr Fialko 	}
222110864656SVolodymyr Fialko 
222210864656SVolodymyr Fialko 	/* Setup port conf */
222310864656SVolodymyr Fialko 	ev_port_conf.new_event_threshold = 1200;
222410864656SVolodymyr Fialko 	ev_port_conf.dequeue_depth =
222510864656SVolodymyr Fialko 			evdev_default_conf.max_event_port_dequeue_depth;
222610864656SVolodymyr Fialko 	ev_port_conf.enqueue_depth =
222710864656SVolodymyr Fialko 			evdev_default_conf.max_event_port_enqueue_depth;
222810864656SVolodymyr Fialko 
222910864656SVolodymyr Fialko 	/* Create Rx adapter */
223010864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_create(rx_adapter_id, eventdev_id,
223110864656SVolodymyr Fialko 			&ev_port_conf);
223210864656SVolodymyr Fialko 	if (ret < 0) {
223310864656SVolodymyr Fialko 		printf("Failed to create rx adapter %d\n", ret);
223410864656SVolodymyr Fialko 		return ret;
223510864656SVolodymyr Fialko 	}
223610864656SVolodymyr Fialko 
223710864656SVolodymyr Fialko 	/* Setup queue conf */
223810864656SVolodymyr Fialko 	queue_conf.ev.queue_id = ev_queue_id;
223910864656SVolodymyr Fialko 	queue_conf.ev.sched_type = RTE_SCHED_TYPE_PARALLEL;
224010864656SVolodymyr Fialko 	queue_conf.ev.event_type = RTE_EVENT_TYPE_ETHDEV;
224110864656SVolodymyr Fialko 
224210864656SVolodymyr Fialko 	/* Add queue to the adapter */
224310864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_queue_add(rx_adapter_id, port_id,
224410864656SVolodymyr Fialko 			all_queues, &queue_conf);
224510864656SVolodymyr Fialko 	if (ret < 0) {
224610864656SVolodymyr Fialko 		printf("Failed to add eth queue to rx adapter %d\n", ret);
224710864656SVolodymyr Fialko 		return ret;
224810864656SVolodymyr Fialko 	}
224910864656SVolodymyr Fialko 
225010864656SVolodymyr Fialko 	/* Start rx adapter */
225110864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_start(rx_adapter_id);
225210864656SVolodymyr Fialko 	if (ret < 0) {
225310864656SVolodymyr Fialko 		printf("Failed to start rx adapter %d\n", ret);
225410864656SVolodymyr Fialko 		return ret;
225510864656SVolodymyr Fialko 	}
225610864656SVolodymyr Fialko 
225710864656SVolodymyr Fialko 	/* Create tx adapter */
225810864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_create(tx_adapter_id, eventdev_id,
225910864656SVolodymyr Fialko 			&ev_port_conf);
226010864656SVolodymyr Fialko 	if (ret < 0) {
226110864656SVolodymyr Fialko 		printf("Failed to create tx adapter %d\n", ret);
226210864656SVolodymyr Fialko 		return ret;
226310864656SVolodymyr Fialko 	}
226410864656SVolodymyr Fialko 
226510864656SVolodymyr Fialko 	/* Add queue to the adapter */
226610864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_queue_add(tx_adapter_id, port_id,
226710864656SVolodymyr Fialko 			all_queues);
226810864656SVolodymyr Fialko 	if (ret < 0) {
226910864656SVolodymyr Fialko 		printf("Failed to add eth queue to tx adapter %d\n", ret);
227010864656SVolodymyr Fialko 		return ret;
227110864656SVolodymyr Fialko 	}
227210864656SVolodymyr Fialko 	/* Setup Tx queue & port */
227310864656SVolodymyr Fialko 	if (tx_queue_id) {
227410864656SVolodymyr Fialko 		/* Setup the queue */
227510864656SVolodymyr Fialko 		ret = rte_event_queue_setup(eventdev_id, tx_queue_id,
227610864656SVolodymyr Fialko 				&eventq_conf);
227710864656SVolodymyr Fialko 		if (ret < 0) {
227810864656SVolodymyr Fialko 			printf("Failed to setup tx event queue %d\n", ret);
227910864656SVolodymyr Fialko 			return ret;
228010864656SVolodymyr Fialko 		}
228110864656SVolodymyr Fialko 		/* Link Tx event queue to Tx port */
228210864656SVolodymyr Fialko 		ret = rte_event_port_link(eventdev_id, port_id,
228310864656SVolodymyr Fialko 				&tx_queue_id, NULL, 1);
228410864656SVolodymyr Fialko 		if (ret != 1) {
228510864656SVolodymyr Fialko 			printf("Failed to link event queue to port\n");
228610864656SVolodymyr Fialko 			return ret;
228710864656SVolodymyr Fialko 		}
228810864656SVolodymyr Fialko 	}
228910864656SVolodymyr Fialko 
229010864656SVolodymyr Fialko 	/* Start tx adapter */
229110864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_start(tx_adapter_id);
229210864656SVolodymyr Fialko 	if (ret < 0) {
229310864656SVolodymyr Fialko 		printf("Failed to start tx adapter %d\n", ret);
229410864656SVolodymyr Fialko 		return ret;
229510864656SVolodymyr Fialko 	}
229610864656SVolodymyr Fialko 
229710864656SVolodymyr Fialko 	/* Start eventdev */
229810864656SVolodymyr Fialko 	ret = rte_event_dev_start(eventdev_id);
229910864656SVolodymyr Fialko 	if (ret < 0) {
230010864656SVolodymyr Fialko 		printf("Failed to start event device %d\n", ret);
230110864656SVolodymyr Fialko 		return ret;
230210864656SVolodymyr Fialko 	}
230310864656SVolodymyr Fialko 
230410864656SVolodymyr Fialko 	event_mode_enabled = true;
2305838e8decSVidya Sagar Velumuri 
2306838e8decSVidya Sagar Velumuri 	test_sec_alg_list_populate();
230710864656SVolodymyr Fialko 
230810864656SVolodymyr Fialko 	return 0;
230910864656SVolodymyr Fialko }
231010864656SVolodymyr Fialko 
231110864656SVolodymyr Fialko static void
231210864656SVolodymyr Fialko event_inline_ipsec_testsuite_teardown(void)
231310864656SVolodymyr Fialko {
231410864656SVolodymyr Fialko 	uint16_t portid;
231510864656SVolodymyr Fialko 	int ret;
231610864656SVolodymyr Fialko 
231710864656SVolodymyr Fialko 	event_mode_enabled = false;
231810864656SVolodymyr Fialko 
231910864656SVolodymyr Fialko 	/* Stop and release rx adapter */
232010864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_stop(rx_adapter_id);
232110864656SVolodymyr Fialko 	if (ret < 0)
232210864656SVolodymyr Fialko 		printf("Failed to stop rx adapter %d\n", ret);
232310864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_queue_del(rx_adapter_id, port_id, -1);
232410864656SVolodymyr Fialko 	if (ret < 0)
232510864656SVolodymyr Fialko 		printf("Failed to remove rx adapter queues %d\n", ret);
232610864656SVolodymyr Fialko 	ret = rte_event_eth_rx_adapter_free(rx_adapter_id);
232710864656SVolodymyr Fialko 	if (ret < 0)
232810864656SVolodymyr Fialko 		printf("Failed to free rx adapter %d\n", ret);
232910864656SVolodymyr Fialko 
233010864656SVolodymyr Fialko 	/* Stop and release tx adapter */
233110864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_stop(tx_adapter_id);
233210864656SVolodymyr Fialko 	if (ret < 0)
233310864656SVolodymyr Fialko 		printf("Failed to stop tx adapter %d\n", ret);
233410864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_queue_del(tx_adapter_id, port_id, -1);
233510864656SVolodymyr Fialko 	if (ret < 0)
233610864656SVolodymyr Fialko 		printf("Failed to remove tx adapter queues %d\n", ret);
233710864656SVolodymyr Fialko 	ret = rte_event_eth_tx_adapter_free(tx_adapter_id);
233810864656SVolodymyr Fialko 	if (ret < 0)
233910864656SVolodymyr Fialko 		printf("Failed to free tx adapter %d\n", ret);
234010864656SVolodymyr Fialko 
234110864656SVolodymyr Fialko 	/* Stop and release event devices */
234210864656SVolodymyr Fialko 	rte_event_dev_stop(eventdev_id);
234310864656SVolodymyr Fialko 	ret = rte_event_dev_close(eventdev_id);
234410864656SVolodymyr Fialko 	if (ret < 0)
234510864656SVolodymyr Fialko 		printf("Failed to close event dev %d, %d\n", eventdev_id, ret);
234610864656SVolodymyr Fialko 
234710864656SVolodymyr Fialko 	/* port tear down */
234810864656SVolodymyr Fialko 	RTE_ETH_FOREACH_DEV(portid) {
234910864656SVolodymyr Fialko 		ret = rte_eth_dev_reset(portid);
235010864656SVolodymyr Fialko 		if (ret != 0)
235110864656SVolodymyr Fialko 			printf("rte_eth_dev_reset: err=%s, port=%u\n",
235210864656SVolodymyr Fialko 			       rte_strerror(-ret), port_id);
235310864656SVolodymyr Fialko 	}
235410864656SVolodymyr Fialko 
235510864656SVolodymyr Fialko 	rte_free(tx_pkts_burst);
235610864656SVolodymyr Fialko 	rte_free(rx_pkts_burst);
235786e2487cSAkhil Goyal }
235886e2487cSAkhil Goyal 
235986e2487cSAkhil Goyal static int
2360a3105777SAkhil Goyal test_inline_ip_reassembly(const void *testdata)
2361a3105777SAkhil Goyal {
2362a3105777SAkhil Goyal 	struct reassembly_vector reassembly_td = {0};
2363a3105777SAkhil Goyal 	const struct reassembly_vector *td = testdata;
2364a3105777SAkhil Goyal 	struct ip_reassembly_test_packet full_pkt;
2365a3105777SAkhil Goyal 	struct ip_reassembly_test_packet frags[MAX_FRAGS];
236615ccc647SNithin Dabilpuram 	uint16_t extra_data, extra_data_sum = 0;
2367a3105777SAkhil Goyal 	struct ipsec_test_flags flags = {0};
2368a3105777SAkhil Goyal 	int i = 0;
2369a3105777SAkhil Goyal 
2370a3105777SAkhil Goyal 	reassembly_td.sa_data = td->sa_data;
2371a3105777SAkhil Goyal 	reassembly_td.nb_frags = td->nb_frags;
2372a3105777SAkhil Goyal 	reassembly_td.burst = td->burst;
2373a3105777SAkhil Goyal 
2374a3105777SAkhil Goyal 	memcpy(&full_pkt, td->full_pkt,
2375a3105777SAkhil Goyal 			sizeof(struct ip_reassembly_test_packet));
2376a3105777SAkhil Goyal 	reassembly_td.full_pkt = &full_pkt;
2377a3105777SAkhil Goyal 
2378a3105777SAkhil Goyal 	for (; i < reassembly_td.nb_frags; i++) {
2379a3105777SAkhil Goyal 		memcpy(&frags[i], td->frags[i],
2380a3105777SAkhil Goyal 			sizeof(struct ip_reassembly_test_packet));
2381a3105777SAkhil Goyal 		reassembly_td.frags[i] = &frags[i];
238215ccc647SNithin Dabilpuram 
238315ccc647SNithin Dabilpuram 		/* Add extra data for multi-seg test on all fragments except last one */
238415ccc647SNithin Dabilpuram 		extra_data = 0;
238515ccc647SNithin Dabilpuram 		if (plaintext_len && reassembly_td.frags[i]->len < plaintext_len &&
238615ccc647SNithin Dabilpuram 		    (i != reassembly_td.nb_frags - 1))
238715ccc647SNithin Dabilpuram 			extra_data = ((plaintext_len - reassembly_td.frags[i]->len) & ~0x7ULL);
238815ccc647SNithin Dabilpuram 
2389a3105777SAkhil Goyal 		test_vector_payload_populate(reassembly_td.frags[i],
239015ccc647SNithin Dabilpuram 				(i == 0) ? true : false, extra_data, extra_data_sum);
239115ccc647SNithin Dabilpuram 		extra_data_sum += extra_data;
2392a3105777SAkhil Goyal 	}
239315ccc647SNithin Dabilpuram 	test_vector_payload_populate(reassembly_td.full_pkt, true, extra_data_sum, 0);
2394a3105777SAkhil Goyal 
2395a3105777SAkhil Goyal 	return test_ipsec_with_reassembly(&reassembly_td, &flags);
2396a3105777SAkhil Goyal }
2397a3105777SAkhil Goyal 
2398a3105777SAkhil Goyal static int
239986e2487cSAkhil Goyal test_ipsec_inline_proto_known_vec(const void *test_data)
240086e2487cSAkhil Goyal {
240186e2487cSAkhil Goyal 	struct ipsec_test_data td_outb;
240286e2487cSAkhil Goyal 	struct ipsec_test_flags flags;
240386e2487cSAkhil Goyal 
240486e2487cSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
240586e2487cSAkhil Goyal 
240686e2487cSAkhil Goyal 	memcpy(&td_outb, test_data, sizeof(td_outb));
240786e2487cSAkhil Goyal 
240886e2487cSAkhil Goyal 	if (td_outb.aead ||
240986e2487cSAkhil Goyal 	    td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL) {
241086e2487cSAkhil Goyal 		/* Disable IV gen to be able to test with known vectors */
241186e2487cSAkhil Goyal 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
241286e2487cSAkhil Goyal 	}
241386e2487cSAkhil Goyal 
241486e2487cSAkhil Goyal 	return test_ipsec_inline_proto_process(&td_outb, NULL, 1,
241586e2487cSAkhil Goyal 				false, &flags);
241686e2487cSAkhil Goyal }
241786e2487cSAkhil Goyal 
24181c015ddeSAkhil Goyal static int
24191c015ddeSAkhil Goyal test_ipsec_inline_proto_known_vec_inb(const void *test_data)
24201c015ddeSAkhil Goyal {
24211c015ddeSAkhil Goyal 	const struct ipsec_test_data *td = test_data;
24221c015ddeSAkhil Goyal 	struct ipsec_test_flags flags;
24231c015ddeSAkhil Goyal 	struct ipsec_test_data td_inb;
24241c015ddeSAkhil Goyal 
24251c015ddeSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
24261c015ddeSAkhil Goyal 
24271c015ddeSAkhil Goyal 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
24281c015ddeSAkhil Goyal 		test_ipsec_td_in_from_out(td, &td_inb);
24291c015ddeSAkhil Goyal 	else
24301c015ddeSAkhil Goyal 		memcpy(&td_inb, td, sizeof(td_inb));
24311c015ddeSAkhil Goyal 
24321c015ddeSAkhil Goyal 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
24331c015ddeSAkhil Goyal }
24341c015ddeSAkhil Goyal 
243578dc764eSAkhil Goyal static int
24361d63855bSNithin Dabilpuram test_ipsec_inline_proto_oop_inb(const void *test_data)
24371d63855bSNithin Dabilpuram {
24381d63855bSNithin Dabilpuram 	const struct ipsec_test_data *td = test_data;
24391d63855bSNithin Dabilpuram 	struct ipsec_test_flags flags;
24401d63855bSNithin Dabilpuram 	struct ipsec_test_data td_inb;
24411d63855bSNithin Dabilpuram 
24421d63855bSNithin Dabilpuram 	memset(&flags, 0, sizeof(flags));
24431d63855bSNithin Dabilpuram 	flags.inb_oop = true;
24441d63855bSNithin Dabilpuram 
24451d63855bSNithin Dabilpuram 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
24461d63855bSNithin Dabilpuram 		test_ipsec_td_in_from_out(td, &td_inb);
24471d63855bSNithin Dabilpuram 	else
24481d63855bSNithin Dabilpuram 		memcpy(&td_inb, td, sizeof(td_inb));
24491d63855bSNithin Dabilpuram 
24501d63855bSNithin Dabilpuram 	td_inb.ipsec_xform.options.ingress_oop = true;
24511d63855bSNithin Dabilpuram 
24521d63855bSNithin Dabilpuram 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
24531d63855bSNithin Dabilpuram }
24541d63855bSNithin Dabilpuram 
24551d63855bSNithin Dabilpuram static int
245619d7fcc5SRahul Bhansali test_ipsec_inline_proto_rx_inj_inb(const void *test_data)
245719d7fcc5SRahul Bhansali {
245819d7fcc5SRahul Bhansali 	const struct ip_pkt_vector *td = test_data;
245919d7fcc5SRahul Bhansali 	struct ip_reassembly_test_packet full_pkt;
246019d7fcc5SRahul Bhansali 	struct ipsec_test_flags flags = {0};
246119d7fcc5SRahul Bhansali 	struct ip_pkt_vector out_td = {0};
246219d7fcc5SRahul Bhansali 	uint16_t extra_data = 0;
246319d7fcc5SRahul Bhansali 
246419d7fcc5SRahul Bhansali 	flags.rx_inject = true;
246519d7fcc5SRahul Bhansali 
246619d7fcc5SRahul Bhansali 	out_td.sa_data = td->sa_data;
246719d7fcc5SRahul Bhansali 	out_td.burst = td->burst;
246819d7fcc5SRahul Bhansali 
246919d7fcc5SRahul Bhansali 	memcpy(&full_pkt, td->full_pkt,
247019d7fcc5SRahul Bhansali 			sizeof(struct ip_reassembly_test_packet));
247119d7fcc5SRahul Bhansali 	out_td.full_pkt = &full_pkt;
247219d7fcc5SRahul Bhansali 
247319d7fcc5SRahul Bhansali 	/* Add extra data for multi-seg test */
247419d7fcc5SRahul Bhansali 	if (plaintext_len && out_td.full_pkt->len < plaintext_len)
247519d7fcc5SRahul Bhansali 		extra_data = ((plaintext_len - out_td.full_pkt->len) & ~0x7ULL);
247619d7fcc5SRahul Bhansali 
247719d7fcc5SRahul Bhansali 	test_vector_payload_populate(out_td.full_pkt, true, extra_data, 0);
247819d7fcc5SRahul Bhansali 
247919d7fcc5SRahul Bhansali 	return test_ipsec_with_rx_inject(&out_td, &flags);
248019d7fcc5SRahul Bhansali }
248119d7fcc5SRahul Bhansali 
248219d7fcc5SRahul Bhansali static int
248363bf81a6SAnatoly Burakov test_ipsec_inline_proto_display_list(void)
248478dc764eSAkhil Goyal {
248578dc764eSAkhil Goyal 	struct ipsec_test_flags flags;
248678dc764eSAkhil Goyal 
248778dc764eSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
248878dc764eSAkhil Goyal 
248978dc764eSAkhil Goyal 	flags.display_alg = true;
24903edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
249178dc764eSAkhil Goyal 
249278dc764eSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
249378dc764eSAkhil Goyal }
24941c015ddeSAkhil Goyal 
2495eb3e17ecSAkhil Goyal static int
249663bf81a6SAnatoly Burakov test_ipsec_inline_proto_udp_encap(void)
2497eb3e17ecSAkhil Goyal {
2498eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2499eb3e17ecSAkhil Goyal 
2500eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2501eb3e17ecSAkhil Goyal 
2502eb3e17ecSAkhil Goyal 	flags.udp_encap = true;
25033edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2504eb3e17ecSAkhil Goyal 
2505eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2506eb3e17ecSAkhil Goyal }
2507eb3e17ecSAkhil Goyal 
2508eb3e17ecSAkhil Goyal static int
250963bf81a6SAnatoly Burakov test_ipsec_inline_proto_udp_ports_verify(void)
2510eb3e17ecSAkhil Goyal {
2511eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2512eb3e17ecSAkhil Goyal 
2513eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2514eb3e17ecSAkhil Goyal 
2515eb3e17ecSAkhil Goyal 	flags.udp_encap = true;
2516eb3e17ecSAkhil Goyal 	flags.udp_ports_verify = true;
25173edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2518eb3e17ecSAkhil Goyal 
2519eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2520eb3e17ecSAkhil Goyal }
2521eb3e17ecSAkhil Goyal 
2522eb3e17ecSAkhil Goyal static int
252363bf81a6SAnatoly Burakov test_ipsec_inline_proto_err_icv_corrupt(void)
2524eb3e17ecSAkhil Goyal {
2525eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2526eb3e17ecSAkhil Goyal 
2527eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2528eb3e17ecSAkhil Goyal 
2529eb3e17ecSAkhil Goyal 	flags.icv_corrupt = true;
25303edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2531eb3e17ecSAkhil Goyal 
2532eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2533eb3e17ecSAkhil Goyal }
2534eb3e17ecSAkhil Goyal 
2535eb3e17ecSAkhil Goyal static int
253663bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_dst_addr_verify(void)
2537eb3e17ecSAkhil Goyal {
2538eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2539eb3e17ecSAkhil Goyal 
2540eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2541eb3e17ecSAkhil Goyal 
2542eb3e17ecSAkhil Goyal 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
25433edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2544eb3e17ecSAkhil Goyal 
2545eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2546eb3e17ecSAkhil Goyal }
2547eb3e17ecSAkhil Goyal 
2548eb3e17ecSAkhil Goyal static int
254963bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_src_dst_addr_verify(void)
2550eb3e17ecSAkhil Goyal {
2551eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2552eb3e17ecSAkhil Goyal 
2553eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2554eb3e17ecSAkhil Goyal 
2555eb3e17ecSAkhil Goyal 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
25563edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2557eb3e17ecSAkhil Goyal 
2558eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2559eb3e17ecSAkhil Goyal }
2560eb3e17ecSAkhil Goyal 
2561eb3e17ecSAkhil Goyal static int
256263bf81a6SAnatoly Burakov test_ipsec_inline_proto_inner_ip_csum(void)
2563eb3e17ecSAkhil Goyal {
2564eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2565eb3e17ecSAkhil Goyal 
2566eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2567eb3e17ecSAkhil Goyal 
2568eb3e17ecSAkhil Goyal 	flags.ip_csum = true;
25693edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2570eb3e17ecSAkhil Goyal 
2571eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2572eb3e17ecSAkhil Goyal }
2573eb3e17ecSAkhil Goyal 
2574eb3e17ecSAkhil Goyal static int
257563bf81a6SAnatoly Burakov test_ipsec_inline_proto_inner_l4_csum(void)
2576eb3e17ecSAkhil Goyal {
2577eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2578eb3e17ecSAkhil Goyal 
2579eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2580eb3e17ecSAkhil Goyal 
2581eb3e17ecSAkhil Goyal 	flags.l4_csum = true;
25823edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2583eb3e17ecSAkhil Goyal 
2584eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2585eb3e17ecSAkhil Goyal }
2586eb3e17ecSAkhil Goyal 
2587eb3e17ecSAkhil Goyal static int
258863bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_v4_in_v4(void)
2589eb3e17ecSAkhil Goyal {
2590eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2591eb3e17ecSAkhil Goyal 
2592eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2593eb3e17ecSAkhil Goyal 
2594eb3e17ecSAkhil Goyal 	flags.ipv6 = false;
2595eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = false;
25963edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2597eb3e17ecSAkhil Goyal 
2598eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2599eb3e17ecSAkhil Goyal }
2600eb3e17ecSAkhil Goyal 
2601eb3e17ecSAkhil Goyal static int
260263bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_v6_in_v6(void)
2603eb3e17ecSAkhil Goyal {
2604eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2605eb3e17ecSAkhil Goyal 
2606eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2607eb3e17ecSAkhil Goyal 
2608eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2609eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
26103edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2611eb3e17ecSAkhil Goyal 
2612eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2613eb3e17ecSAkhil Goyal }
2614eb3e17ecSAkhil Goyal 
2615eb3e17ecSAkhil Goyal static int
261663bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_v4_in_v6(void)
2617eb3e17ecSAkhil Goyal {
2618eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2619eb3e17ecSAkhil Goyal 
2620eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2621eb3e17ecSAkhil Goyal 
2622eb3e17ecSAkhil Goyal 	flags.ipv6 = false;
2623eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
26243edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2625eb3e17ecSAkhil Goyal 
2626eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2627eb3e17ecSAkhil Goyal }
2628eb3e17ecSAkhil Goyal 
2629eb3e17ecSAkhil Goyal static int
263063bf81a6SAnatoly Burakov test_ipsec_inline_proto_tunnel_v6_in_v4(void)
2631eb3e17ecSAkhil Goyal {
2632eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2633eb3e17ecSAkhil Goyal 
2634eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2635eb3e17ecSAkhil Goyal 
2636eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2637eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = false;
26383edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2639eb3e17ecSAkhil Goyal 
2640eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2641eb3e17ecSAkhil Goyal }
2642eb3e17ecSAkhil Goyal 
2643eb3e17ecSAkhil Goyal static int
264463bf81a6SAnatoly Burakov test_ipsec_inline_proto_transport_v4(void)
2645eb3e17ecSAkhil Goyal {
2646eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2647eb3e17ecSAkhil Goyal 
2648eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2649eb3e17ecSAkhil Goyal 
2650eb3e17ecSAkhil Goyal 	flags.ipv6 = false;
2651eb3e17ecSAkhil Goyal 	flags.transport = true;
26523edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2653eb3e17ecSAkhil Goyal 
2654eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2655eb3e17ecSAkhil Goyal }
2656eb3e17ecSAkhil Goyal 
2657eb3e17ecSAkhil Goyal static int
265863bf81a6SAnatoly Burakov test_ipsec_inline_proto_transport_l4_csum(void)
2659eb3e17ecSAkhil Goyal {
2660eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags = {
2661eb3e17ecSAkhil Goyal 		.l4_csum = true,
2662eb3e17ecSAkhil Goyal 		.transport = true,
26633edd1197SNithin Dabilpuram 		.plaintext_len = plaintext_len,
2664eb3e17ecSAkhil Goyal 	};
2665eb3e17ecSAkhil Goyal 
2666eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2667eb3e17ecSAkhil Goyal }
2668eb3e17ecSAkhil Goyal 
2669eb3e17ecSAkhil Goyal static int
267063bf81a6SAnatoly Burakov test_ipsec_inline_proto_stats(void)
2671eb3e17ecSAkhil Goyal {
2672eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2673eb3e17ecSAkhil Goyal 
2674eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2675eb3e17ecSAkhil Goyal 
2676eb3e17ecSAkhil Goyal 	flags.stats_success = true;
26773edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2678eb3e17ecSAkhil Goyal 
2679eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2680eb3e17ecSAkhil Goyal }
2681eb3e17ecSAkhil Goyal 
2682eb3e17ecSAkhil Goyal static int
268363bf81a6SAnatoly Burakov test_ipsec_inline_proto_pkt_fragment(void)
2684eb3e17ecSAkhil Goyal {
2685eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2686eb3e17ecSAkhil Goyal 
2687eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2688eb3e17ecSAkhil Goyal 
2689eb3e17ecSAkhil Goyal 	flags.fragment = true;
26903edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2691eb3e17ecSAkhil Goyal 
2692eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2693eb3e17ecSAkhil Goyal 
2694eb3e17ecSAkhil Goyal }
2695eb3e17ecSAkhil Goyal 
2696eb3e17ecSAkhil Goyal static int
269763bf81a6SAnatoly Burakov test_ipsec_inline_proto_copy_df_inner_0(void)
2698eb3e17ecSAkhil Goyal {
2699eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2700eb3e17ecSAkhil Goyal 
2701eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2702eb3e17ecSAkhil Goyal 
2703eb3e17ecSAkhil Goyal 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
27043edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2705eb3e17ecSAkhil Goyal 
2706eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2707eb3e17ecSAkhil Goyal }
2708eb3e17ecSAkhil Goyal 
2709eb3e17ecSAkhil Goyal static int
271063bf81a6SAnatoly Burakov test_ipsec_inline_proto_copy_df_inner_1(void)
2711eb3e17ecSAkhil Goyal {
2712eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2713eb3e17ecSAkhil Goyal 
2714eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2715eb3e17ecSAkhil Goyal 
2716eb3e17ecSAkhil Goyal 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
27173edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2718eb3e17ecSAkhil Goyal 
2719eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2720eb3e17ecSAkhil Goyal }
2721eb3e17ecSAkhil Goyal 
2722eb3e17ecSAkhil Goyal static int
272363bf81a6SAnatoly Burakov test_ipsec_inline_proto_set_df_0_inner_1(void)
2724eb3e17ecSAkhil Goyal {
2725eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2726eb3e17ecSAkhil Goyal 
2727eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2728eb3e17ecSAkhil Goyal 
2729eb3e17ecSAkhil Goyal 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
27303edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2731eb3e17ecSAkhil Goyal 
2732eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2733eb3e17ecSAkhil Goyal }
2734eb3e17ecSAkhil Goyal 
2735eb3e17ecSAkhil Goyal static int
273663bf81a6SAnatoly Burakov test_ipsec_inline_proto_set_df_1_inner_0(void)
2737eb3e17ecSAkhil Goyal {
2738eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2739eb3e17ecSAkhil Goyal 
2740eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2741eb3e17ecSAkhil Goyal 
2742eb3e17ecSAkhil Goyal 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
27433edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2744eb3e17ecSAkhil Goyal 
2745eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2746eb3e17ecSAkhil Goyal }
2747eb3e17ecSAkhil Goyal 
2748eb3e17ecSAkhil Goyal static int
274963bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv4_copy_dscp_inner_0(void)
2750eb3e17ecSAkhil Goyal {
2751eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2752eb3e17ecSAkhil Goyal 
2753eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2754eb3e17ecSAkhil Goyal 
2755eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
27563edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2757eb3e17ecSAkhil Goyal 
2758eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2759eb3e17ecSAkhil Goyal }
2760eb3e17ecSAkhil Goyal 
2761eb3e17ecSAkhil Goyal static int
276263bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv4_copy_dscp_inner_1(void)
2763eb3e17ecSAkhil Goyal {
2764eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2765eb3e17ecSAkhil Goyal 
2766eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2767eb3e17ecSAkhil Goyal 
2768eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
27693edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2770eb3e17ecSAkhil Goyal 
2771eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2772eb3e17ecSAkhil Goyal }
2773eb3e17ecSAkhil Goyal 
2774eb3e17ecSAkhil Goyal static int
277563bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1(void)
2776eb3e17ecSAkhil Goyal {
2777eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2778eb3e17ecSAkhil Goyal 
2779eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2780eb3e17ecSAkhil Goyal 
2781eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
27823edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2783eb3e17ecSAkhil Goyal 
2784eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2785eb3e17ecSAkhil Goyal }
2786eb3e17ecSAkhil Goyal 
2787eb3e17ecSAkhil Goyal static int
278863bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0(void)
2789eb3e17ecSAkhil Goyal {
2790eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2791eb3e17ecSAkhil Goyal 
2792eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2793eb3e17ecSAkhil Goyal 
2794eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
27953edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2796eb3e17ecSAkhil Goyal 
2797eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2798eb3e17ecSAkhil Goyal }
2799eb3e17ecSAkhil Goyal 
2800eb3e17ecSAkhil Goyal static int
280163bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_copy_dscp_inner_0(void)
2802eb3e17ecSAkhil Goyal {
2803eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2804eb3e17ecSAkhil Goyal 
2805eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2806eb3e17ecSAkhil Goyal 
2807eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2808eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
2809eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
28103edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2811eb3e17ecSAkhil Goyal 
2812eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2813eb3e17ecSAkhil Goyal }
2814eb3e17ecSAkhil Goyal 
2815eb3e17ecSAkhil Goyal static int
281663bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_copy_dscp_inner_1(void)
2817eb3e17ecSAkhil Goyal {
2818eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2819eb3e17ecSAkhil Goyal 
2820eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2821eb3e17ecSAkhil Goyal 
2822eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2823eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
2824eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
28253edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2826eb3e17ecSAkhil Goyal 
2827eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2828eb3e17ecSAkhil Goyal }
2829eb3e17ecSAkhil Goyal 
2830eb3e17ecSAkhil Goyal static int
283163bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1(void)
2832eb3e17ecSAkhil Goyal {
2833eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2834eb3e17ecSAkhil Goyal 
2835eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2836eb3e17ecSAkhil Goyal 
2837eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2838eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
2839eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
28403edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2841eb3e17ecSAkhil Goyal 
2842eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2843eb3e17ecSAkhil Goyal }
2844eb3e17ecSAkhil Goyal 
2845eb3e17ecSAkhil Goyal static int
284663bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0(void)
2847eb3e17ecSAkhil Goyal {
2848eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2849eb3e17ecSAkhil Goyal 
2850eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2851eb3e17ecSAkhil Goyal 
2852eb3e17ecSAkhil Goyal 	flags.ipv6 = true;
2853eb3e17ecSAkhil Goyal 	flags.tunnel_ipv6 = true;
2854eb3e17ecSAkhil Goyal 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
28553edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2856eb3e17ecSAkhil Goyal 
2857eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2858eb3e17ecSAkhil Goyal }
2859eb3e17ecSAkhil Goyal 
2860eb3e17ecSAkhil Goyal static int
286163bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_copy_flabel_inner_0(void)
286291d1d052SVamsi Attunuru {
286391d1d052SVamsi Attunuru 	struct ipsec_test_flags flags;
286491d1d052SVamsi Attunuru 
286591d1d052SVamsi Attunuru 	memset(&flags, 0, sizeof(flags));
286691d1d052SVamsi Attunuru 
286791d1d052SVamsi Attunuru 	flags.ipv6 = true;
286891d1d052SVamsi Attunuru 	flags.tunnel_ipv6 = true;
286991d1d052SVamsi Attunuru 	flags.flabel = TEST_IPSEC_COPY_FLABEL_INNER_0;
287091d1d052SVamsi Attunuru 
287191d1d052SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
287291d1d052SVamsi Attunuru }
287391d1d052SVamsi Attunuru 
287491d1d052SVamsi Attunuru static int
287563bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_copy_flabel_inner_1(void)
287691d1d052SVamsi Attunuru {
287791d1d052SVamsi Attunuru 	struct ipsec_test_flags flags;
287891d1d052SVamsi Attunuru 
287991d1d052SVamsi Attunuru 	memset(&flags, 0, sizeof(flags));
288091d1d052SVamsi Attunuru 
288191d1d052SVamsi Attunuru 	flags.ipv6 = true;
288291d1d052SVamsi Attunuru 	flags.tunnel_ipv6 = true;
288391d1d052SVamsi Attunuru 	flags.flabel = TEST_IPSEC_COPY_FLABEL_INNER_1;
288491d1d052SVamsi Attunuru 
288591d1d052SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
288691d1d052SVamsi Attunuru }
288791d1d052SVamsi Attunuru 
288891d1d052SVamsi Attunuru static int
288963bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_set_flabel_0_inner_1(void)
289091d1d052SVamsi Attunuru {
289191d1d052SVamsi Attunuru 	struct ipsec_test_flags flags;
289291d1d052SVamsi Attunuru 
289391d1d052SVamsi Attunuru 	memset(&flags, 0, sizeof(flags));
289491d1d052SVamsi Attunuru 
289591d1d052SVamsi Attunuru 	flags.ipv6 = true;
289691d1d052SVamsi Attunuru 	flags.tunnel_ipv6 = true;
289791d1d052SVamsi Attunuru 	flags.flabel = TEST_IPSEC_SET_FLABEL_0_INNER_1;
289891d1d052SVamsi Attunuru 
289991d1d052SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
290091d1d052SVamsi Attunuru }
290191d1d052SVamsi Attunuru 
290291d1d052SVamsi Attunuru static int
290363bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_set_flabel_1_inner_0(void)
290491d1d052SVamsi Attunuru {
290591d1d052SVamsi Attunuru 	struct ipsec_test_flags flags;
290691d1d052SVamsi Attunuru 
290791d1d052SVamsi Attunuru 	memset(&flags, 0, sizeof(flags));
290891d1d052SVamsi Attunuru 
290991d1d052SVamsi Attunuru 	flags.ipv6 = true;
291091d1d052SVamsi Attunuru 	flags.tunnel_ipv6 = true;
291191d1d052SVamsi Attunuru 	flags.flabel = TEST_IPSEC_SET_FLABEL_1_INNER_0;
291291d1d052SVamsi Attunuru 
291391d1d052SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
291491d1d052SVamsi Attunuru }
291591d1d052SVamsi Attunuru 
291691d1d052SVamsi Attunuru static int
291763bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv4_ttl_decrement(void)
2918eb3e17ecSAkhil Goyal {
2919eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags = {
29203edd1197SNithin Dabilpuram 		.dec_ttl_or_hop_limit = true,
29213edd1197SNithin Dabilpuram 		.plaintext_len = plaintext_len,
2922eb3e17ecSAkhil Goyal 	};
2923eb3e17ecSAkhil Goyal 
2924eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2925eb3e17ecSAkhil Goyal }
2926eb3e17ecSAkhil Goyal 
2927eb3e17ecSAkhil Goyal static int
292863bf81a6SAnatoly Burakov test_ipsec_inline_proto_ipv6_hop_limit_decrement(void)
2929eb3e17ecSAkhil Goyal {
2930eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags = {
2931eb3e17ecSAkhil Goyal 		.ipv6 = true,
29323edd1197SNithin Dabilpuram 		.dec_ttl_or_hop_limit = true,
29333edd1197SNithin Dabilpuram 		.plaintext_len = plaintext_len,
2934eb3e17ecSAkhil Goyal 	};
2935eb3e17ecSAkhil Goyal 
2936eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2937eb3e17ecSAkhil Goyal }
2938eb3e17ecSAkhil Goyal 
2939eb3e17ecSAkhil Goyal static int
294063bf81a6SAnatoly Burakov test_ipsec_inline_proto_iv_gen(void)
2941eb3e17ecSAkhil Goyal {
2942eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2943eb3e17ecSAkhil Goyal 
2944eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2945eb3e17ecSAkhil Goyal 
2946eb3e17ecSAkhil Goyal 	flags.iv_gen = true;
29473edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
2948eb3e17ecSAkhil Goyal 
2949eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_all(&flags);
2950eb3e17ecSAkhil Goyal }
2951eb3e17ecSAkhil Goyal 
2952eb3e17ecSAkhil Goyal static int
295363bf81a6SAnatoly Burakov test_ipsec_inline_proto_sa_pkt_soft_expiry(void)
295434e8a9d9SVamsi Attunuru {
295534e8a9d9SVamsi Attunuru 	struct ipsec_test_flags flags = {
29563edd1197SNithin Dabilpuram 		.sa_expiry_pkts_soft = true,
29573edd1197SNithin Dabilpuram 		.plaintext_len = plaintext_len,
295834e8a9d9SVamsi Attunuru 	};
295934e8a9d9SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
296034e8a9d9SVamsi Attunuru }
296134e8a9d9SVamsi Attunuru static int
296263bf81a6SAnatoly Burakov test_ipsec_inline_proto_sa_byte_soft_expiry(void)
296334e8a9d9SVamsi Attunuru {
296434e8a9d9SVamsi Attunuru 	struct ipsec_test_flags flags = {
29653edd1197SNithin Dabilpuram 		.sa_expiry_bytes_soft = true,
29663edd1197SNithin Dabilpuram 		.plaintext_len = plaintext_len,
296734e8a9d9SVamsi Attunuru 	};
296834e8a9d9SVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
296934e8a9d9SVamsi Attunuru }
297034e8a9d9SVamsi Attunuru 
297134e8a9d9SVamsi Attunuru static int
297263bf81a6SAnatoly Burakov test_ipsec_inline_proto_sa_pkt_hard_expiry(void)
2973ff8ef86cSVamsi Attunuru {
2974ff8ef86cSVamsi Attunuru 	struct ipsec_test_flags flags = {
2975ff8ef86cSVamsi Attunuru 		.sa_expiry_pkts_hard = true
2976ff8ef86cSVamsi Attunuru 	};
2977ff8ef86cSVamsi Attunuru 
2978ff8ef86cSVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
2979ff8ef86cSVamsi Attunuru }
2980ff8ef86cSVamsi Attunuru 
2981ff8ef86cSVamsi Attunuru static int
298263bf81a6SAnatoly Burakov test_ipsec_inline_proto_sa_byte_hard_expiry(void)
2983ff8ef86cSVamsi Attunuru {
2984ff8ef86cSVamsi Attunuru 	struct ipsec_test_flags flags = {
2985ff8ef86cSVamsi Attunuru 		.sa_expiry_bytes_hard = true
2986ff8ef86cSVamsi Attunuru 	};
2987ff8ef86cSVamsi Attunuru 
2988ff8ef86cSVamsi Attunuru 	return test_ipsec_inline_proto_all(&flags);
2989ff8ef86cSVamsi Attunuru }
2990ff8ef86cSVamsi Attunuru 
2991ff8ef86cSVamsi Attunuru static int
2992eb3e17ecSAkhil Goyal test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
2993eb3e17ecSAkhil Goyal {
2994eb3e17ecSAkhil Goyal 	struct ipsec_test_data td_outb;
2995eb3e17ecSAkhil Goyal 	struct ipsec_test_flags flags;
2996eb3e17ecSAkhil Goyal 
2997eb3e17ecSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
2998eb3e17ecSAkhil Goyal 	flags.fragment = true;
29993edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
3000eb3e17ecSAkhil Goyal 
3001eb3e17ecSAkhil Goyal 	memcpy(&td_outb, test_data, sizeof(td_outb));
3002eb3e17ecSAkhil Goyal 
3003eb3e17ecSAkhil Goyal 	/* Disable IV gen to be able to test with known vectors */
3004eb3e17ecSAkhil Goyal 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
3005eb3e17ecSAkhil Goyal 
3006eb3e17ecSAkhil Goyal 	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
3007eb3e17ecSAkhil Goyal 						&flags);
3008eb3e17ecSAkhil Goyal }
3009fd33d9eeSAkhil Goyal 
3010fd33d9eeSAkhil Goyal static int
3011fd33d9eeSAkhil Goyal test_ipsec_inline_pkt_replay(const void *test_data, const uint64_t esn[],
3012fd33d9eeSAkhil Goyal 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
3013fd33d9eeSAkhil Goyal 		      uint64_t winsz)
3014fd33d9eeSAkhil Goyal {
3015838e8decSVidya Sagar Velumuri 	struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX];
3016838e8decSVidya Sagar Velumuri 	struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX];
3017fd33d9eeSAkhil Goyal 	struct ipsec_test_flags flags;
3018fd33d9eeSAkhil Goyal 	uint32_t i, ret = 0;
3019fd33d9eeSAkhil Goyal 
3020fd33d9eeSAkhil Goyal 	memset(&flags, 0, sizeof(flags));
3021fd33d9eeSAkhil Goyal 	flags.antireplay = true;
30223edd1197SNithin Dabilpuram 	flags.plaintext_len = plaintext_len;
3023fd33d9eeSAkhil Goyal 
3024fd33d9eeSAkhil Goyal 	for (i = 0; i < nb_pkts; i++) {
302510864656SVolodymyr Fialko 		memcpy(&td_outb[i], test_data, sizeof(td_outb[0]));
3026fd33d9eeSAkhil Goyal 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
3027fd33d9eeSAkhil Goyal 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
3028fd33d9eeSAkhil Goyal 		td_outb[i].ipsec_xform.options.esn = esn_en;
3029fd33d9eeSAkhil Goyal 	}
3030fd33d9eeSAkhil Goyal 
3031fd33d9eeSAkhil Goyal 	for (i = 0; i < nb_pkts; i++)
3032fd33d9eeSAkhil Goyal 		td_outb[i].ipsec_xform.esn.value = esn[i];
3033fd33d9eeSAkhil Goyal 
3034fd33d9eeSAkhil Goyal 	ret = test_ipsec_inline_proto_process_with_esn(td_outb, td_inb,
3035fd33d9eeSAkhil Goyal 				nb_pkts, true, &flags);
3036fd33d9eeSAkhil Goyal 	if (ret != TEST_SUCCESS)
3037fd33d9eeSAkhil Goyal 		return ret;
3038fd33d9eeSAkhil Goyal 
3039fd33d9eeSAkhil Goyal 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
3040fd33d9eeSAkhil Goyal 
3041fd33d9eeSAkhil Goyal 	for (i = 0; i < nb_pkts; i++) {
3042fd33d9eeSAkhil Goyal 		td_inb[i].ipsec_xform.options.esn = esn_en;
3043fd33d9eeSAkhil Goyal 		/* Set antireplay flag for packets to be dropped */
3044fd33d9eeSAkhil Goyal 		td_inb[i].ar_packet = replayed_pkt[i];
3045fd33d9eeSAkhil Goyal 	}
3046fd33d9eeSAkhil Goyal 
3047fd33d9eeSAkhil Goyal 	ret = test_ipsec_inline_proto_process_with_esn(td_inb, NULL, nb_pkts,
3048fd33d9eeSAkhil Goyal 				true, &flags);
3049fd33d9eeSAkhil Goyal 
3050fd33d9eeSAkhil Goyal 	return ret;
3051fd33d9eeSAkhil Goyal }
3052fd33d9eeSAkhil Goyal 
3053fd33d9eeSAkhil Goyal static int
3054fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
3055fd33d9eeSAkhil Goyal {
3056fd33d9eeSAkhil Goyal 
3057fd33d9eeSAkhil Goyal 	uint32_t nb_pkts = 5;
3058fd33d9eeSAkhil Goyal 	bool replayed_pkt[5];
3059fd33d9eeSAkhil Goyal 	uint64_t esn[5];
3060fd33d9eeSAkhil Goyal 
3061fd33d9eeSAkhil Goyal 	/* 1. Advance the TOP of the window to WS * 2 */
3062fd33d9eeSAkhil Goyal 	esn[0] = winsz * 2;
3063fd33d9eeSAkhil Goyal 	/* 2. Test sequence number within the new window(WS + 1) */
3064fd33d9eeSAkhil Goyal 	esn[1] = winsz + 1;
3065fd33d9eeSAkhil Goyal 	/* 3. Test sequence number less than the window BOTTOM */
3066fd33d9eeSAkhil Goyal 	esn[2] = winsz;
3067fd33d9eeSAkhil Goyal 	/* 4. Test sequence number in the middle of the window */
3068fd33d9eeSAkhil Goyal 	esn[3] = winsz + (winsz / 2);
3069fd33d9eeSAkhil Goyal 	/* 5. Test replay of the packet in the middle of the window */
3070fd33d9eeSAkhil Goyal 	esn[4] = winsz + (winsz / 2);
3071fd33d9eeSAkhil Goyal 
3072fd33d9eeSAkhil Goyal 	replayed_pkt[0] = false;
3073fd33d9eeSAkhil Goyal 	replayed_pkt[1] = false;
3074fd33d9eeSAkhil Goyal 	replayed_pkt[2] = true;
3075fd33d9eeSAkhil Goyal 	replayed_pkt[3] = false;
3076fd33d9eeSAkhil Goyal 	replayed_pkt[4] = true;
3077fd33d9eeSAkhil Goyal 
3078fd33d9eeSAkhil Goyal 	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt,
3079fd33d9eeSAkhil Goyal 			nb_pkts, false, winsz);
3080fd33d9eeSAkhil Goyal }
3081fd33d9eeSAkhil Goyal 
3082fd33d9eeSAkhil Goyal static int
3083fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_antireplay1024(const void *test_data)
3084fd33d9eeSAkhil Goyal {
3085fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_antireplay(test_data, 1024);
3086fd33d9eeSAkhil Goyal }
3087fd33d9eeSAkhil Goyal 
3088fd33d9eeSAkhil Goyal static int
3089fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_antireplay2048(const void *test_data)
3090fd33d9eeSAkhil Goyal {
3091fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_antireplay(test_data, 2048);
3092fd33d9eeSAkhil Goyal }
3093fd33d9eeSAkhil Goyal 
3094fd33d9eeSAkhil Goyal static int
3095fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_antireplay4096(const void *test_data)
3096fd33d9eeSAkhil Goyal {
3097fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_antireplay(test_data, 4096);
3098fd33d9eeSAkhil Goyal }
3099fd33d9eeSAkhil Goyal 
3100fd33d9eeSAkhil Goyal static int
3101fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
3102fd33d9eeSAkhil Goyal {
3103fd33d9eeSAkhil Goyal 
3104fd33d9eeSAkhil Goyal 	uint32_t nb_pkts = 7;
3105fd33d9eeSAkhil Goyal 	bool replayed_pkt[7];
3106fd33d9eeSAkhil Goyal 	uint64_t esn[7];
3107fd33d9eeSAkhil Goyal 
3108fd33d9eeSAkhil Goyal 	/* Set the initial sequence number */
3109fd33d9eeSAkhil Goyal 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
3110fd33d9eeSAkhil Goyal 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
3111fd33d9eeSAkhil Goyal 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
3112fd33d9eeSAkhil Goyal 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
3113fd33d9eeSAkhil Goyal 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
3114fd33d9eeSAkhil Goyal 	/* 3. Test with sequence number within window (1<<32 - 1) */
3115fd33d9eeSAkhil Goyal 	esn[3] = (uint64_t)((1ULL << 32) - 1);
3116fd33d9eeSAkhil Goyal 	/* 4. Test with sequence number within window (1<<32 - 1) */
3117fd33d9eeSAkhil Goyal 	esn[4] = (uint64_t)(1ULL << 32);
3118fd33d9eeSAkhil Goyal 	/* 5. Test with duplicate sequence number within
3119fd33d9eeSAkhil Goyal 	 * new window (1<<32 - 1)
3120fd33d9eeSAkhil Goyal 	 */
3121fd33d9eeSAkhil Goyal 	esn[5] = (uint64_t)((1ULL << 32) - 1);
3122fd33d9eeSAkhil Goyal 	/* 6. Test with duplicate sequence number within new window (1<<32) */
3123fd33d9eeSAkhil Goyal 	esn[6] = (uint64_t)(1ULL << 32);
3124fd33d9eeSAkhil Goyal 
3125fd33d9eeSAkhil Goyal 	replayed_pkt[0] = false;
3126fd33d9eeSAkhil Goyal 	replayed_pkt[1] = false;
3127fd33d9eeSAkhil Goyal 	replayed_pkt[2] = false;
3128fd33d9eeSAkhil Goyal 	replayed_pkt[3] = false;
3129fd33d9eeSAkhil Goyal 	replayed_pkt[4] = false;
3130fd33d9eeSAkhil Goyal 	replayed_pkt[5] = true;
3131fd33d9eeSAkhil Goyal 	replayed_pkt[6] = true;
3132fd33d9eeSAkhil Goyal 
3133fd33d9eeSAkhil Goyal 	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
3134fd33d9eeSAkhil Goyal 				     true, winsz);
3135fd33d9eeSAkhil Goyal }
3136fd33d9eeSAkhil Goyal 
3137fd33d9eeSAkhil Goyal static int
3138fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_esn_antireplay1024(const void *test_data)
3139fd33d9eeSAkhil Goyal {
3140fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 1024);
3141fd33d9eeSAkhil Goyal }
3142fd33d9eeSAkhil Goyal 
3143fd33d9eeSAkhil Goyal static int
3144fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_esn_antireplay2048(const void *test_data)
3145fd33d9eeSAkhil Goyal {
3146fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 2048);
3147fd33d9eeSAkhil Goyal }
3148fd33d9eeSAkhil Goyal 
3149fd33d9eeSAkhil Goyal static int
3150fd33d9eeSAkhil Goyal test_ipsec_inline_proto_pkt_esn_antireplay4096(const void *test_data)
3151fd33d9eeSAkhil Goyal {
3152fd33d9eeSAkhil Goyal 	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 4096);
3153fd33d9eeSAkhil Goyal }
3154fd33d9eeSAkhil Goyal 
315586e2487cSAkhil Goyal static struct unit_test_suite inline_ipsec_testsuite  = {
315686e2487cSAkhil Goyal 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
315786e2487cSAkhil Goyal 	.unit_test_cases = {
315886e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
315986e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
316086e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
316186e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec, &pkt_aes_128_gcm),
316286e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
316386e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
316486e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
316586e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec, &pkt_aes_192_gcm),
316686e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
316786e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
316886e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
316986e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec, &pkt_aes_256_gcm),
317086e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
31715a23f6eaSVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
31725a23f6eaSVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
31735a23f6eaSVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
31745a23f6eaSVidya Sagar Velumuri 			&pkt_aes_128_cbc_md5),
31755a23f6eaSVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
317686e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
317786e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
317886e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec,
317986e2487cSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha256),
318086e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
318186e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
318286e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
318386e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec,
318486e2487cSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha384),
318586e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
318686e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
318786e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
318886e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec,
318986e2487cSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha512),
319086e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3191d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
3192d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3193d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3194d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha256),
3195d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3196d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
3197d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3198d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3199d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha384),
3200d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3201d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
3202d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3203d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3204d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha512),
3205d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
320686e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
320786e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
320886e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec, &pkt_aes_256_gcm_v6),
320986e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
321086e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
321186e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
321286e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec,
321386e2487cSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha256_v6),
321486e2487cSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3215d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
3216d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3217d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3218d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha256_v6),
3219d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
322086e2487cSAkhil Goyal 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
322186e2487cSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
322286e2487cSAkhil Goyal 			test_ipsec_inline_proto_known_vec,
322386e2487cSAkhil Goyal 			&pkt_null_aes_xcbc),
3224d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3225d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
3226d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3227d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3228d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha256),
3229d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3230d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
3231d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3232d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3233d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha384),
3234d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3235d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
3236d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3237d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3238d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha512),
3239d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3240d7001863SVidya Sagar Velumuri 			"Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
3241d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3242d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec,
3243d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha256_v6),
3244eb3e17ecSAkhil Goyal 
3245eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3246eb3e17ecSAkhil Goyal 			"Outbound fragmented packet",
3247eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3248eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_known_vec_fragmented,
3249eb3e17ecSAkhil Goyal 			&pkt_aes_128_gcm_frag),
3250eb3e17ecSAkhil Goyal 
32511c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32521c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
32531c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32541c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_gcm),
32551c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32561c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
32571c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32581c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_192_gcm),
32591c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32601c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
32611c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32621c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm),
32631c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32641c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
32651c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32661c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_cbc_null),
32671c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32685a23f6eaSVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
32695a23f6eaSVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32705a23f6eaSVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
32715a23f6eaSVidya Sagar Velumuri 			&pkt_aes_128_cbc_md5),
32725a23f6eaSVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
32731c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
32741c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32751c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb,
32761c015ddeSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha256),
32771c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32781c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
32791c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32801c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb,
32811c015ddeSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha384),
32821c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
32831c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
32841c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
32851c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb,
32861c015ddeSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha512),
32871c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3288d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
3289d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3290d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3291d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha256),
3292d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3293d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
3294d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3295d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3296d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha384),
3297d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3298d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
3299d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3300d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3301d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha512),
3302d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
33031c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
33041c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
33051c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
33061c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
33071c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
33081c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
33091c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb,
33101c015ddeSAkhil Goyal 			&pkt_aes_128_cbc_hmac_sha256_v6),
33111c015ddeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3312d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
3313d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3314d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3315d7001863SVidya Sagar Velumuri 			&pkt_3des_cbc_hmac_sha256_v6),
3316d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
33171c015ddeSAkhil Goyal 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
33181c015ddeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
33191c015ddeSAkhil Goyal 			test_ipsec_inline_proto_known_vec_inb,
33201c015ddeSAkhil Goyal 			&pkt_null_aes_xcbc),
3321d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3322d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
3323d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3324d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3325d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha256),
3326d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3327d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
3328d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3329d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3330d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha384),
3331d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3332d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
3333d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3334d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3335d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha512),
3336d7001863SVidya Sagar Velumuri 		TEST_CASE_NAMED_WITH_DATA(
3337d7001863SVidya Sagar Velumuri 			"Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
3338d7001863SVidya Sagar Velumuri 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3339d7001863SVidya Sagar Velumuri 			test_ipsec_inline_proto_known_vec_inb,
3340d7001863SVidya Sagar Velumuri 			&pkt_des_cbc_hmac_sha256_v6),
3341d7001863SVidya Sagar Velumuri 
33421c015ddeSAkhil Goyal 
334378dc764eSAkhil Goyal 		TEST_CASE_NAMED_ST(
334478dc764eSAkhil Goyal 			"Combined test alg list",
334578dc764eSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
334678dc764eSAkhil Goyal 			test_ipsec_inline_proto_display_list),
334778dc764eSAkhil Goyal 
3348eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3349eb3e17ecSAkhil Goyal 			"UDP encapsulation",
3350eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3351eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_udp_encap),
3352eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3353eb3e17ecSAkhil Goyal 			"UDP encapsulation ports verification test",
3354eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3355eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_udp_ports_verify),
3356eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3357eb3e17ecSAkhil Goyal 			"Negative test: ICV corruption",
3358eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3359eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_err_icv_corrupt),
3360eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3361eb3e17ecSAkhil Goyal 			"Tunnel dst addr verification",
3362eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3363eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_dst_addr_verify),
3364eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3365eb3e17ecSAkhil Goyal 			"Tunnel src and dst addr verification",
3366eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3367eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_src_dst_addr_verify),
3368eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3369eb3e17ecSAkhil Goyal 			"Inner IP checksum",
3370eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3371eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_inner_ip_csum),
3372eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3373eb3e17ecSAkhil Goyal 			"Inner L4 checksum",
3374eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3375eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_inner_l4_csum),
3376eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3377eb3e17ecSAkhil Goyal 			"Tunnel IPv4 in IPv4",
3378eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3379eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_v4_in_v4),
3380eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3381eb3e17ecSAkhil Goyal 			"Tunnel IPv6 in IPv6",
3382eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3383eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_v6_in_v6),
3384eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3385eb3e17ecSAkhil Goyal 			"Tunnel IPv4 in IPv6",
3386eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3387eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_v4_in_v6),
3388eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3389eb3e17ecSAkhil Goyal 			"Tunnel IPv6 in IPv4",
3390eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3391eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_tunnel_v6_in_v4),
3392eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3393eb3e17ecSAkhil Goyal 			"Transport IPv4",
3394eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3395eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_transport_v4),
3396eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3397eb3e17ecSAkhil Goyal 			"Transport l4 checksum",
3398eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3399eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_transport_l4_csum),
3400eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3401eb3e17ecSAkhil Goyal 			"Statistics: success",
3402eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3403eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_stats),
3404eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3405eb3e17ecSAkhil Goyal 			"Fragmented packet",
3406eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3407eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_pkt_fragment),
3408eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3409eb3e17ecSAkhil Goyal 			"Tunnel header copy DF (inner 0)",
3410eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3411eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_copy_df_inner_0),
3412eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3413eb3e17ecSAkhil Goyal 			"Tunnel header copy DF (inner 1)",
3414eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3415eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_copy_df_inner_1),
3416eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3417eb3e17ecSAkhil Goyal 			"Tunnel header set DF 0 (inner 1)",
3418eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3419eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_set_df_0_inner_1),
3420eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3421eb3e17ecSAkhil Goyal 			"Tunnel header set DF 1 (inner 0)",
3422eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3423eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_set_df_1_inner_0),
3424eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3425eb3e17ecSAkhil Goyal 			"Tunnel header IPv4 copy DSCP (inner 0)",
3426eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3427eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv4_copy_dscp_inner_0),
3428eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3429eb3e17ecSAkhil Goyal 			"Tunnel header IPv4 copy DSCP (inner 1)",
3430eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3431eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv4_copy_dscp_inner_1),
3432eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3433eb3e17ecSAkhil Goyal 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
3434eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3435eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1),
3436eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3437eb3e17ecSAkhil Goyal 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
3438eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3439eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0),
3440eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3441eb3e17ecSAkhil Goyal 			"Tunnel header IPv6 copy DSCP (inner 0)",
3442eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3443eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv6_copy_dscp_inner_0),
3444eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3445eb3e17ecSAkhil Goyal 			"Tunnel header IPv6 copy DSCP (inner 1)",
3446eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3447eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv6_copy_dscp_inner_1),
3448eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3449eb3e17ecSAkhil Goyal 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
3450eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3451eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1),
3452eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3453eb3e17ecSAkhil Goyal 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
3454eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3455eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0),
3456eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
345791d1d052SVamsi Attunuru 			"Tunnel header IPv6 copy FLABEL (inner 0)",
345891d1d052SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
345991d1d052SVamsi Attunuru 			test_ipsec_inline_proto_ipv6_copy_flabel_inner_0),
346091d1d052SVamsi Attunuru 		TEST_CASE_NAMED_ST(
346191d1d052SVamsi Attunuru 			"Tunnel header IPv6 copy FLABEL (inner 1)",
346291d1d052SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
346391d1d052SVamsi Attunuru 			test_ipsec_inline_proto_ipv6_copy_flabel_inner_1),
346491d1d052SVamsi Attunuru 		TEST_CASE_NAMED_ST(
346591d1d052SVamsi Attunuru 			"Tunnel header IPv6 set FLABEL 0 (inner 1)",
346691d1d052SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
346791d1d052SVamsi Attunuru 			test_ipsec_inline_proto_ipv6_set_flabel_0_inner_1),
346891d1d052SVamsi Attunuru 		TEST_CASE_NAMED_ST(
346991d1d052SVamsi Attunuru 			"Tunnel header IPv6 set FLABEL 1 (inner 0)",
347091d1d052SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
347191d1d052SVamsi Attunuru 			test_ipsec_inline_proto_ipv6_set_flabel_1_inner_0),
347291d1d052SVamsi Attunuru 		TEST_CASE_NAMED_ST(
3473eb3e17ecSAkhil Goyal 			"Tunnel header IPv4 decrement inner TTL",
3474eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3475eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv4_ttl_decrement),
3476eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3477eb3e17ecSAkhil Goyal 			"Tunnel header IPv6 decrement inner hop limit",
3478eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3479eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_ipv6_hop_limit_decrement),
3480eb3e17ecSAkhil Goyal 		TEST_CASE_NAMED_ST(
3481eb3e17ecSAkhil Goyal 			"IV generation",
3482eb3e17ecSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3483eb3e17ecSAkhil Goyal 			test_ipsec_inline_proto_iv_gen),
348434e8a9d9SVamsi Attunuru 		TEST_CASE_NAMED_ST(
348534e8a9d9SVamsi Attunuru 			"SA soft expiry with packet limit",
348634e8a9d9SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
348734e8a9d9SVamsi Attunuru 			test_ipsec_inline_proto_sa_pkt_soft_expiry),
348834e8a9d9SVamsi Attunuru 		TEST_CASE_NAMED_ST(
348934e8a9d9SVamsi Attunuru 			"SA soft expiry with byte limit",
349034e8a9d9SVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
349134e8a9d9SVamsi Attunuru 			test_ipsec_inline_proto_sa_byte_soft_expiry),
3492ff8ef86cSVamsi Attunuru 		TEST_CASE_NAMED_ST(
3493ff8ef86cSVamsi Attunuru 			"SA hard expiry with packet limit",
3494ff8ef86cSVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3495ff8ef86cSVamsi Attunuru 			test_ipsec_inline_proto_sa_pkt_hard_expiry),
3496ff8ef86cSVamsi Attunuru 		TEST_CASE_NAMED_ST(
3497ff8ef86cSVamsi Attunuru 			"SA hard expiry with byte limit",
3498ff8ef86cSVamsi Attunuru 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3499ff8ef86cSVamsi Attunuru 			test_ipsec_inline_proto_sa_byte_hard_expiry),
3500eb3e17ecSAkhil Goyal 
3501a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3502fd33d9eeSAkhil Goyal 			"Antireplay with window size 1024",
3503fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3504fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_antireplay1024,
3505fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3506fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3507fd33d9eeSAkhil Goyal 			"Antireplay with window size 2048",
3508fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3509fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_antireplay2048,
3510fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3511fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3512fd33d9eeSAkhil Goyal 			"Antireplay with window size 4096",
3513fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3514fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_antireplay4096,
3515fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3516fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3517fd33d9eeSAkhil Goyal 			"ESN and Antireplay with window size 1024",
3518fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3519fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_esn_antireplay1024,
3520fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3521fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3522fd33d9eeSAkhil Goyal 			"ESN and Antireplay with window size 2048",
3523fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3524fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_esn_antireplay2048,
3525fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3526fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3527fd33d9eeSAkhil Goyal 			"ESN and Antireplay with window size 4096",
3528fd33d9eeSAkhil Goyal 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
3529fd33d9eeSAkhil Goyal 			test_ipsec_inline_proto_pkt_esn_antireplay4096,
3530fd33d9eeSAkhil Goyal 			&pkt_aes_128_gcm),
3531fd33d9eeSAkhil Goyal 
3532fd33d9eeSAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3533a3105777SAkhil Goyal 			"IPv4 Reassembly with 2 fragments",
35342f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3535a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_2frag_vector),
3536a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3537a3105777SAkhil Goyal 			"IPv6 Reassembly with 2 fragments",
35382f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3539a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv6_2frag_vector),
3540a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3541a3105777SAkhil Goyal 			"IPv4 Reassembly with 4 fragments",
35422f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3543a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_4frag_vector),
3544a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3545a3105777SAkhil Goyal 			"IPv6 Reassembly with 4 fragments",
35462f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3547a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv6_4frag_vector),
3548a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3549a3105777SAkhil Goyal 			"IPv4 Reassembly with 5 fragments",
35502f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3551a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_5frag_vector),
3552a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3553a3105777SAkhil Goyal 			"IPv6 Reassembly with 5 fragments",
35542f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3555a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv6_5frag_vector),
3556a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3557a3105777SAkhil Goyal 			"IPv4 Reassembly with incomplete fragments",
35582f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3559a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_incomplete_vector),
3560a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3561a3105777SAkhil Goyal 			"IPv4 Reassembly with overlapping fragments",
35622f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3563a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_overlap_vector),
3564a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3565a3105777SAkhil Goyal 			"IPv4 Reassembly with out of order fragments",
35662f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3567a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_out_of_order_vector),
3568a3105777SAkhil Goyal 		TEST_CASE_NAMED_WITH_DATA(
3569a3105777SAkhil Goyal 			"IPv4 Reassembly with burst of 4 fragments",
35702f97b943SRahul Bhansali 			ut_setup_inline_ipsec_reassembly, ut_teardown_inline_ipsec_reassembly,
3571a3105777SAkhil Goyal 			test_inline_ip_reassembly, &ipv4_4frag_burst_vector),
35721d63855bSNithin Dabilpuram 		TEST_CASE_NAMED_WITH_DATA(
35731d63855bSNithin Dabilpuram 			"Inbound Out-Of-Place processing",
35741d63855bSNithin Dabilpuram 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
35751d63855bSNithin Dabilpuram 			test_ipsec_inline_proto_oop_inb,
35761d63855bSNithin Dabilpuram 			&pkt_aes_128_gcm),
357719d7fcc5SRahul Bhansali 		TEST_CASE_NAMED_WITH_DATA(
357819d7fcc5SRahul Bhansali 			"Inbound Rx Inject processing",
357919d7fcc5SRahul Bhansali 			ut_setup_inline_ipsec_rx_inj, ut_teardown_inline_ipsec_rx_inj,
358019d7fcc5SRahul Bhansali 			test_ipsec_inline_proto_rx_inj_inb, &ipv4_vector),
358186e2487cSAkhil Goyal 
358286e2487cSAkhil Goyal 		TEST_CASES_END() /**< NULL terminate unit test array */
358386e2487cSAkhil Goyal 	},
358486e2487cSAkhil Goyal };
358586e2487cSAkhil Goyal 
358686e2487cSAkhil Goyal 
358786e2487cSAkhil Goyal static int
358886e2487cSAkhil Goyal test_inline_ipsec(void)
358986e2487cSAkhil Goyal {
359010864656SVolodymyr Fialko 	inline_ipsec_testsuite.setup = inline_ipsec_testsuite_setup;
359110864656SVolodymyr Fialko 	inline_ipsec_testsuite.teardown = inline_ipsec_testsuite_teardown;
359210864656SVolodymyr Fialko 	return unit_test_suite_runner(&inline_ipsec_testsuite);
359310864656SVolodymyr Fialko }
359410864656SVolodymyr Fialko 
35953edd1197SNithin Dabilpuram 
35963edd1197SNithin Dabilpuram static int
35973edd1197SNithin Dabilpuram test_inline_ipsec_sg(void)
35983edd1197SNithin Dabilpuram {
35993edd1197SNithin Dabilpuram 	int rc;
36003edd1197SNithin Dabilpuram 
36013edd1197SNithin Dabilpuram 	inline_ipsec_testsuite.setup = inline_ipsec_testsuite_setup;
36023edd1197SNithin Dabilpuram 	inline_ipsec_testsuite.teardown = inline_ipsec_testsuite_teardown;
36033edd1197SNithin Dabilpuram 
36043edd1197SNithin Dabilpuram 	sg_mode = true;
36053edd1197SNithin Dabilpuram 	/* Run the tests */
36063edd1197SNithin Dabilpuram 	rc = unit_test_suite_runner(&inline_ipsec_testsuite);
36073edd1197SNithin Dabilpuram 	sg_mode = false;
36083edd1197SNithin Dabilpuram 
36093edd1197SNithin Dabilpuram 	port_conf.rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_SCATTER;
36103edd1197SNithin Dabilpuram 	port_conf.txmode.offloads &= ~RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
36113edd1197SNithin Dabilpuram 	return rc;
36123edd1197SNithin Dabilpuram }
36133edd1197SNithin Dabilpuram 
361410864656SVolodymyr Fialko static int
361510864656SVolodymyr Fialko test_event_inline_ipsec(void)
361610864656SVolodymyr Fialko {
361710864656SVolodymyr Fialko 	inline_ipsec_testsuite.setup = event_inline_ipsec_testsuite_setup;
361810864656SVolodymyr Fialko 	inline_ipsec_testsuite.teardown = event_inline_ipsec_testsuite_teardown;
361986e2487cSAkhil Goyal 	return unit_test_suite_runner(&inline_ipsec_testsuite);
362086e2487cSAkhil Goyal }
362186e2487cSAkhil Goyal 
362286e2487cSAkhil Goyal #endif /* !RTE_EXEC_ENV_WINDOWS */
362386e2487cSAkhil Goyal 
362486e2487cSAkhil Goyal REGISTER_TEST_COMMAND(inline_ipsec_autotest, test_inline_ipsec);
36253edd1197SNithin Dabilpuram REGISTER_TEST_COMMAND(inline_ipsec_sg_autotest, test_inline_ipsec_sg);
362610864656SVolodymyr Fialko REGISTER_TEST_COMMAND(event_inline_ipsec_autotest, test_event_inline_ipsec);
3627