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