1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_cycles.h>
13 #include <rte_bus_vdev.h>
16 #include <rte_crypto.h>
17 #include <rte_cryptodev.h>
18 #include <rte_cryptodev_pmd.h>
19 #include <rte_lcore.h>
20 #include <rte_ipsec.h>
21 #include <rte_random.h>
23 #include <rte_security_driver.h>
26 #include "test_cryptodev.h"
28 #define VDEV_ARGS_SIZE 100
29 #define MAX_NB_SESSIONS 200
31 #define REPLAY_WIN_0 0
32 #define REPLAY_WIN_32 32
33 #define REPLAY_WIN_64 64
34 #define REPLAY_WIN_128 128
35 #define REPLAY_WIN_256 256
36 #define DATA_64_BYTES 64
37 #define DATA_80_BYTES 80
38 #define DATA_100_BYTES 100
40 #define ESN_DISABLED 0
42 #define OUTBOUND_SPI 17
44 #define REORDER_PKTS 1
45 #define DEQUEUE_COUNT 1000
48 enum rte_crypto_sym_xform_type auth;
49 enum rte_crypto_sym_xform_type cipher;
50 enum rte_crypto_sym_xform_type aead;
53 char cipher_algo[128];
57 struct ipsec_testsuite_params {
58 struct rte_mempool *mbuf_pool;
59 struct rte_mempool *cop_mpool;
60 struct rte_cryptodev_config conf;
61 struct rte_cryptodev_qp_conf qp_conf;
64 uint8_t valid_dev_found;
67 struct ipsec_unitest_params {
68 struct rte_crypto_sym_xform cipher_xform;
69 struct rte_crypto_sym_xform auth_xform;
70 struct rte_crypto_sym_xform aead_xform;
71 struct rte_crypto_sym_xform *crypto_xforms;
73 struct rte_security_ipsec_xform ipsec_xform;
75 struct rte_ipsec_sa_prm sa_prm;
76 struct rte_ipsec_session ss[MAX_NB_SAS];
78 struct rte_crypto_op *cop[BURST_SIZE];
80 struct rte_mbuf *obuf[BURST_SIZE], *ibuf[BURST_SIZE],
86 struct ipsec_test_cfg {
87 uint32_t replay_win_sz;
92 uint32_t reorder_pkts;
95 static const struct ipsec_test_cfg test_cfg[] = {
96 {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, 1, 0},
97 {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, BURST_SIZE, 0},
98 {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_80_BYTES, BURST_SIZE,
100 {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, 1, 0},
101 {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, BURST_SIZE,
103 {REPLAY_WIN_64, ESN_ENABLED, 0, DATA_64_BYTES, 1, 0},
104 {REPLAY_WIN_128, ESN_ENABLED, RTE_IPSEC_SAFLAG_SQN_ATOM,
105 DATA_80_BYTES, 1, 0},
106 {REPLAY_WIN_256, ESN_DISABLED, 0, DATA_100_BYTES, 1, 0},
109 static const int num_cfg = RTE_DIM(test_cfg);
110 static struct ipsec_testsuite_params testsuite_params = { NULL };
111 static struct ipsec_unitest_params unittest_params;
112 static struct user_params uparams;
114 struct supported_cipher_algo {
116 enum rte_crypto_cipher_algorithm algo;
122 struct supported_auth_algo {
124 enum rte_crypto_auth_algorithm algo;
130 const struct supported_cipher_algo cipher_algos[] = {
133 .algo = RTE_CRYPTO_CIPHER_NULL,
140 const struct supported_auth_algo auth_algos[] = {
143 .algo = RTE_CRYPTO_AUTH_NULL,
151 dummy_sec_create(void *device, struct rte_security_session_conf *conf,
152 struct rte_security_session *sess, struct rte_mempool *mp)
154 RTE_SET_USED(device);
158 sess->sess_private_data = NULL;
163 dummy_sec_destroy(void *device, struct rte_security_session *sess)
165 RTE_SET_USED(device);
170 static const struct rte_security_ops dummy_sec_ops = {
171 .session_create = dummy_sec_create,
172 .session_destroy = dummy_sec_destroy,
175 static struct rte_security_ctx dummy_sec_ctx = {
176 .ops = &dummy_sec_ops,
179 static const struct supported_cipher_algo *
180 find_match_cipher_algo(const char *cipher_keyword)
184 for (i = 0; i < RTE_DIM(cipher_algos); i++) {
185 const struct supported_cipher_algo *algo =
188 if (strcmp(cipher_keyword, algo->keyword) == 0)
195 static const struct supported_auth_algo *
196 find_match_auth_algo(const char *auth_keyword)
200 for (i = 0; i < RTE_DIM(auth_algos); i++) {
201 const struct supported_auth_algo *algo =
204 if (strcmp(auth_keyword, algo->keyword) == 0)
212 fill_crypto_xform(struct ipsec_unitest_params *ut_params,
213 const struct supported_auth_algo *auth_algo,
214 const struct supported_cipher_algo *cipher_algo)
216 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
217 ut_params->cipher_xform.cipher.algo = cipher_algo->algo;
218 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
219 ut_params->auth_xform.auth.algo = auth_algo->algo;
221 if (ut_params->ipsec_xform.direction ==
222 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
223 ut_params->cipher_xform.cipher.op =
224 RTE_CRYPTO_CIPHER_OP_DECRYPT;
225 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
226 ut_params->cipher_xform.next = NULL;
227 ut_params->auth_xform.next = &ut_params->cipher_xform;
228 ut_params->crypto_xforms = &ut_params->auth_xform;
230 ut_params->cipher_xform.cipher.op =
231 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
232 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
233 ut_params->auth_xform.next = NULL;
234 ut_params->cipher_xform.next = &ut_params->auth_xform;
235 ut_params->crypto_xforms = &ut_params->cipher_xform;
240 check_cryptodev_capablity(const struct ipsec_unitest_params *ut,
243 struct rte_cryptodev_sym_capability_idx cap_idx;
244 const struct rte_cryptodev_symmetric_capability *cap;
247 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
248 cap_idx.algo.auth = ut->auth_xform.auth.algo;
249 cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
252 rc = rte_cryptodev_sym_capability_check_auth(cap,
253 ut->auth_xform.auth.key.length,
254 ut->auth_xform.auth.digest_length, 0);
256 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
257 cap_idx.algo.cipher = ut->cipher_xform.cipher.algo;
258 cap = rte_cryptodev_sym_capability_get(
261 rc = rte_cryptodev_sym_capability_check_cipher(
263 ut->cipher_xform.cipher.key.length,
264 ut->cipher_xform.cipher.iv.length);
272 testsuite_setup(void)
274 struct ipsec_testsuite_params *ts_params = &testsuite_params;
275 struct ipsec_unitest_params *ut_params = &unittest_params;
276 const struct supported_auth_algo *auth_algo;
277 const struct supported_cipher_algo *cipher_algo;
278 struct rte_cryptodev_info info;
279 uint32_t i, nb_devs, dev_id;
283 memset(ts_params, 0, sizeof(*ts_params));
284 memset(ut_params, 0, sizeof(*ut_params));
285 memset(&uparams, 0, sizeof(struct user_params));
287 uparams.auth = RTE_CRYPTO_SYM_XFORM_AUTH;
288 uparams.cipher = RTE_CRYPTO_SYM_XFORM_CIPHER;
289 uparams.aead = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
290 strcpy(uparams.auth_algo, "null");
291 strcpy(uparams.cipher_algo, "null");
293 auth_algo = find_match_auth_algo(uparams.auth_algo);
294 cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
295 fill_crypto_xform(ut_params, auth_algo, cipher_algo);
297 nb_devs = rte_cryptodev_count();
299 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
303 /* Find first valid crypto device */
304 for (i = 0; i < nb_devs; i++) {
305 rc = check_cryptodev_capablity(ut_params, i);
307 ts_params->valid_dev = i;
308 ts_params->valid_dev_found = 1;
313 if (ts_params->valid_dev_found == 0)
316 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
318 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
320 if (ts_params->mbuf_pool == NULL) {
321 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
325 ts_params->cop_mpool = rte_crypto_op_pool_create(
326 "MBUF_CRYPTO_SYM_OP_POOL",
327 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
328 NUM_MBUFS, MBUF_CACHE_SIZE,
330 sizeof(struct rte_crypto_sym_xform) +
333 if (ts_params->cop_mpool == NULL) {
334 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
338 /* Set up all the qps on the first of the valid devices found */
339 dev_id = ts_params->valid_dev;
341 rte_cryptodev_info_get(dev_id, &info);
343 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
344 ts_params->conf.socket_id = SOCKET_ID_ANY;
345 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
347 sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id);
348 sess_sz = RTE_MAX(sess_sz, sizeof(struct rte_security_session));
351 * Create mempools for sessions
353 if (info.sym.max_nb_sessions != 0 &&
354 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
355 RTE_LOG(ERR, USER1, "Device does not support "
356 "at least %u sessions\n",
361 ts_params->qp_conf.mp_session_private = rte_mempool_create(
365 0, 0, NULL, NULL, NULL,
369 TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session_private,
370 "private session mempool allocation failed");
372 ts_params->qp_conf.mp_session =
373 rte_cryptodev_sym_session_pool_create("test_sess_mp",
374 MAX_NB_SESSIONS, 0, 0, 0, SOCKET_ID_ANY);
376 TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session,
377 "session mempool allocation failed");
379 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
381 "Failed to configure cryptodev %u with %u qps",
382 dev_id, ts_params->conf.nb_queue_pairs);
384 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
386 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
387 dev_id, 0, &ts_params->qp_conf,
388 rte_cryptodev_socket_id(dev_id)),
389 "Failed to setup queue pair %u on cryptodev %u",
396 testsuite_teardown(void)
398 struct ipsec_testsuite_params *ts_params = &testsuite_params;
400 if (ts_params->mbuf_pool != NULL) {
401 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
402 rte_mempool_avail_count(ts_params->mbuf_pool));
403 rte_mempool_free(ts_params->mbuf_pool);
404 ts_params->mbuf_pool = NULL;
407 if (ts_params->cop_mpool != NULL) {
408 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
409 rte_mempool_avail_count(ts_params->cop_mpool));
410 rte_mempool_free(ts_params->cop_mpool);
411 ts_params->cop_mpool = NULL;
414 /* Free session mempools */
415 if (ts_params->qp_conf.mp_session != NULL) {
416 rte_mempool_free(ts_params->qp_conf.mp_session);
417 ts_params->qp_conf.mp_session = NULL;
420 if (ts_params->qp_conf.mp_session_private != NULL) {
421 rte_mempool_free(ts_params->qp_conf.mp_session_private);
422 ts_params->qp_conf.mp_session_private = NULL;
429 struct ipsec_testsuite_params *ts_params = &testsuite_params;
430 struct ipsec_unitest_params *ut_params = &unittest_params;
432 /* Clear unit test parameters before running test */
433 memset(ut_params, 0, sizeof(*ut_params));
435 /* Reconfigure device to default parameters */
436 ts_params->conf.socket_id = SOCKET_ID_ANY;
438 /* Start the device */
439 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_dev),
440 "Failed to start cryptodev %u",
441 ts_params->valid_dev);
449 struct ipsec_testsuite_params *ts_params = &testsuite_params;
450 struct ipsec_unitest_params *ut_params = &unittest_params;
453 for (i = 0; i < BURST_SIZE; i++) {
454 /* free crypto operation structure */
455 if (ut_params->cop[i])
456 rte_crypto_op_free(ut_params->cop[i]);
459 * free mbuf - both obuf and ibuf are usually the same,
460 * so check if they point at the same address is necessary,
461 * to avoid freeing the mbuf twice.
463 if (ut_params->obuf[i]) {
464 rte_pktmbuf_free(ut_params->obuf[i]);
465 if (ut_params->ibuf[i] == ut_params->obuf[i])
466 ut_params->ibuf[i] = 0;
467 ut_params->obuf[i] = 0;
469 if (ut_params->ibuf[i]) {
470 rte_pktmbuf_free(ut_params->ibuf[i]);
471 ut_params->ibuf[i] = 0;
474 if (ut_params->testbuf[i]) {
475 rte_pktmbuf_free(ut_params->testbuf[i]);
476 ut_params->testbuf[i] = 0;
480 if (ts_params->mbuf_pool != NULL)
481 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
482 rte_mempool_avail_count(ts_params->mbuf_pool));
484 /* Stop the device */
485 rte_cryptodev_stop(ts_params->valid_dev);
488 #define IPSEC_MAX_PAD_SIZE UINT8_MAX
490 static const uint8_t esp_pad_bytes[IPSEC_MAX_PAD_SIZE] = {
491 1, 2, 3, 4, 5, 6, 7, 8,
492 9, 10, 11, 12, 13, 14, 15, 16,
493 17, 18, 19, 20, 21, 22, 23, 24,
494 25, 26, 27, 28, 29, 30, 31, 32,
495 33, 34, 35, 36, 37, 38, 39, 40,
496 41, 42, 43, 44, 45, 46, 47, 48,
497 49, 50, 51, 52, 53, 54, 55, 56,
498 57, 58, 59, 60, 61, 62, 63, 64,
499 65, 66, 67, 68, 69, 70, 71, 72,
500 73, 74, 75, 76, 77, 78, 79, 80,
501 81, 82, 83, 84, 85, 86, 87, 88,
502 89, 90, 91, 92, 93, 94, 95, 96,
503 97, 98, 99, 100, 101, 102, 103, 104,
504 105, 106, 107, 108, 109, 110, 111, 112,
505 113, 114, 115, 116, 117, 118, 119, 120,
506 121, 122, 123, 124, 125, 126, 127, 128,
507 129, 130, 131, 132, 133, 134, 135, 136,
508 137, 138, 139, 140, 141, 142, 143, 144,
509 145, 146, 147, 148, 149, 150, 151, 152,
510 153, 154, 155, 156, 157, 158, 159, 160,
511 161, 162, 163, 164, 165, 166, 167, 168,
512 169, 170, 171, 172, 173, 174, 175, 176,
513 177, 178, 179, 180, 181, 182, 183, 184,
514 185, 186, 187, 188, 189, 190, 191, 192,
515 193, 194, 195, 196, 197, 198, 199, 200,
516 201, 202, 203, 204, 205, 206, 207, 208,
517 209, 210, 211, 212, 213, 214, 215, 216,
518 217, 218, 219, 220, 221, 222, 223, 224,
519 225, 226, 227, 228, 229, 230, 231, 232,
520 233, 234, 235, 236, 237, 238, 239, 240,
521 241, 242, 243, 244, 245, 246, 247, 248,
522 249, 250, 251, 252, 253, 254, 255,
525 /* ***** data for tests ***** */
527 const char null_plain_data[] =
528 "Network Security People Have A Strange Sense Of Humor unlike Other "
529 "People who have a normal sense of humour";
531 const char null_encrypted_data[] =
532 "Network Security People Have A Strange Sense Of Humor unlike Other "
533 "People who have a normal sense of humour";
535 struct rte_ipv4_hdr ipv4_outer = {
536 .version_ihl = IPVERSION << 4 |
537 sizeof(ipv4_outer) / RTE_IPV4_IHL_MULTIPLIER,
538 .time_to_live = IPDEFTTL,
539 .next_proto_id = IPPROTO_ESP,
540 .src_addr = RTE_IPV4(192, 168, 1, 100),
541 .dst_addr = RTE_IPV4(192, 168, 2, 100),
544 static struct rte_mbuf *
545 setup_test_string(struct rte_mempool *mpool,
546 const char *string, size_t len, uint8_t blocksize)
548 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
549 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
552 memset(m->buf_addr, 0, m->buf_len);
553 char *dst = rte_pktmbuf_append(m, t_len);
560 rte_memcpy(dst, string, t_len);
562 memset(dst, 0, t_len);
568 static struct rte_mbuf *
569 setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
570 size_t len, uint32_t spi, uint32_t seq)
572 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
573 uint32_t hdrlen = sizeof(struct rte_ipv4_hdr) +
574 sizeof(struct rte_esp_hdr);
575 uint32_t taillen = sizeof(struct esp_tail);
576 uint32_t t_len = len + hdrlen + taillen;
579 struct rte_esp_hdr esph = {
580 .spi = rte_cpu_to_be_32(spi),
581 .seq = rte_cpu_to_be_32(seq)
584 padlen = RTE_ALIGN(t_len, 4) - t_len;
587 struct esp_tail espt = {
589 .next_proto = IPPROTO_IPIP,
595 memset(m->buf_addr, 0, m->buf_len);
596 char *dst = rte_pktmbuf_append(m, t_len);
602 /* copy outer IP and ESP header */
603 ipv4_outer.total_length = rte_cpu_to_be_16(t_len);
604 ipv4_outer.packet_id = rte_cpu_to_be_16(seq);
605 rte_memcpy(dst, &ipv4_outer, sizeof(ipv4_outer));
606 dst += sizeof(ipv4_outer);
607 m->l3_len = sizeof(ipv4_outer);
608 rte_memcpy(dst, &esph, sizeof(esph));
611 if (string != NULL) {
613 rte_memcpy(dst, string, len);
616 rte_memcpy(dst, esp_pad_bytes, padlen);
618 /* copy ESP tail header */
619 rte_memcpy(dst, &espt, sizeof(espt));
621 memset(dst, 0, t_len);
627 create_dummy_sec_session(struct ipsec_unitest_params *ut,
628 struct rte_cryptodev_qp_conf *qp, uint32_t j)
630 static struct rte_security_session_conf conf;
632 ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
633 &conf, qp->mp_session_private);
635 if (ut->ss[j].security.ses == NULL)
638 ut->ss[j].security.ctx = &dummy_sec_ctx;
639 ut->ss[j].security.ol_flags = 0;
644 create_crypto_session(struct ipsec_unitest_params *ut,
645 struct rte_cryptodev_qp_conf *qp, uint8_t dev_id, uint32_t j)
648 struct rte_cryptodev_sym_session *s;
650 s = rte_cryptodev_sym_session_create(qp->mp_session);
654 /* initiliaze SA crypto session for device */
655 rc = rte_cryptodev_sym_session_init(dev_id, s,
656 ut->crypto_xforms, qp->mp_session_private);
658 ut->ss[j].crypto.ses = s;
661 /* failure, do cleanup */
662 rte_cryptodev_sym_session_clear(dev_id, s);
663 rte_cryptodev_sym_session_free(s);
669 create_session(struct ipsec_unitest_params *ut,
670 struct rte_cryptodev_qp_conf *qp, uint8_t crypto_dev, uint32_t j)
672 if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
673 return create_crypto_session(ut, qp, crypto_dev, j);
675 return create_dummy_sec_session(ut, qp, j);
679 fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags)
681 struct ipsec_unitest_params *ut_params = &unittest_params;
682 struct rte_ipsec_sa_prm *prm = &ut_params->sa_prm;
683 const struct supported_auth_algo *auth_algo;
684 const struct supported_cipher_algo *cipher_algo;
686 memset(prm, 0, sizeof(*prm));
690 prm->replay_win_sz = replay_win_sz;
692 /* setup ipsec xform */
693 prm->ipsec_xform = ut_params->ipsec_xform;
694 prm->ipsec_xform.salt = (uint32_t)rte_rand();
696 /* setup tunnel related fields */
697 prm->tun.hdr_len = sizeof(ipv4_outer);
698 prm->tun.next_proto = IPPROTO_IPIP;
699 prm->tun.hdr = &ipv4_outer;
701 /* setup crypto section */
702 if (uparams.aead != 0) {
703 /* TODO: will need to fill out with other test cases */
705 if (uparams.auth == 0 && uparams.cipher == 0)
708 auth_algo = find_match_auth_algo(uparams.auth_algo);
709 cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
711 fill_crypto_xform(ut_params, auth_algo, cipher_algo);
714 prm->crypto_xform = ut_params->crypto_xforms;
719 create_sa(enum rte_security_session_action_type action_type,
720 uint32_t replay_win_sz, uint64_t flags, uint32_t j)
722 struct ipsec_testsuite_params *ts = &testsuite_params;
723 struct ipsec_unitest_params *ut = &unittest_params;
727 memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
729 rc = fill_ipsec_param(replay_win_sz, flags);
733 /* create rte_ipsec_sa*/
734 sz = rte_ipsec_sa_size(&ut->sa_prm);
735 TEST_ASSERT(sz > 0, "rte_ipsec_sa_size() failed\n");
737 ut->ss[j].sa = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
738 TEST_ASSERT_NOT_NULL(ut->ss[j].sa,
739 "failed to allocate memory for rte_ipsec_sa\n");
741 ut->ss[j].type = action_type;
742 rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j);
746 rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz);
747 rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL;
749 rc = rte_ipsec_session_prepare(&ut->ss[j]);
755 crypto_dequeue_burst(uint16_t num_pkts)
757 struct ipsec_testsuite_params *ts_params = &testsuite_params;
758 struct ipsec_unitest_params *ut_params = &unittest_params;
762 for (i = 0, pkt_cnt = 0;
763 i < DEQUEUE_COUNT && pkt_cnt != num_pkts; i++) {
764 k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
765 &ut_params->cop[pkt_cnt], num_pkts - pkt_cnt);
770 if (pkt_cnt != num_pkts) {
771 RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
778 crypto_ipsec(uint16_t num_pkts)
780 struct ipsec_testsuite_params *ts_params = &testsuite_params;
781 struct ipsec_unitest_params *ut_params = &unittest_params;
783 struct rte_ipsec_group grp[1];
785 /* call crypto prepare */
786 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
787 ut_params->cop, num_pkts);
789 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
793 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
794 ut_params->cop, num_pkts);
796 RTE_LOG(ERR, USER1, "rte_cryptodev_enqueue_burst fail\n");
800 if (crypto_dequeue_burst(num_pkts) == TEST_FAILED)
803 ng = rte_ipsec_pkt_crypto_group(
804 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
805 ut_params->obuf, grp, num_pkts);
807 grp[0].m[0] != ut_params->obuf[0] ||
808 grp[0].cnt != num_pkts ||
809 grp[0].id.ptr != &ut_params->ss[0]) {
810 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
814 /* call crypto process */
815 k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
817 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
825 lksd_proto_ipsec(uint16_t num_pkts)
827 struct ipsec_unitest_params *ut_params = &unittest_params;
829 struct rte_ipsec_group grp[1];
831 /* call crypto prepare */
832 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
833 ut_params->cop, num_pkts);
835 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
839 /* check crypto ops */
840 for (i = 0; i != num_pkts; i++) {
841 TEST_ASSERT_EQUAL(ut_params->cop[i]->type,
842 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
843 "%s: invalid crypto op type for %u-th packet\n",
845 TEST_ASSERT_EQUAL(ut_params->cop[i]->status,
846 RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
847 "%s: invalid crypto op status for %u-th packet\n",
849 TEST_ASSERT_EQUAL(ut_params->cop[i]->sess_type,
850 RTE_CRYPTO_OP_SECURITY_SESSION,
851 "%s: invalid crypto op sess_type for %u-th packet\n",
853 TEST_ASSERT_EQUAL(ut_params->cop[i]->sym->m_src,
855 "%s: invalid crypto op m_src for %u-th packet\n",
859 /* update crypto ops, pretend all finished ok */
860 for (i = 0; i != num_pkts; i++)
861 ut_params->cop[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
863 ng = rte_ipsec_pkt_crypto_group(
864 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
865 ut_params->obuf, grp, num_pkts);
867 grp[0].m[0] != ut_params->obuf[0] ||
868 grp[0].cnt != num_pkts ||
869 grp[0].id.ptr != &ut_params->ss[0]) {
870 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
874 /* call crypto process */
875 k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
877 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
885 crypto_ipsec_2sa(void)
887 struct ipsec_testsuite_params *ts_params = &testsuite_params;
888 struct ipsec_unitest_params *ut_params = &unittest_params;
889 struct rte_ipsec_group grp[BURST_SIZE];
890 uint32_t k, ng, i, r;
892 for (i = 0; i < BURST_SIZE; i++) {
894 /* call crypto prepare */
895 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
896 ut_params->ibuf + i, ut_params->cop + i, 1);
899 "rte_ipsec_pkt_crypto_prepare fail\n");
902 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
903 ut_params->cop + i, 1);
906 "rte_cryptodev_enqueue_burst fail\n");
911 if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
914 ng = rte_ipsec_pkt_crypto_group(
915 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
916 ut_params->obuf, grp, BURST_SIZE);
917 if (ng != BURST_SIZE) {
918 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
923 /* call crypto process */
924 for (i = 0; i < ng; i++) {
925 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
926 if (k != grp[i].cnt) {
927 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
939 crypto_ipsec_4grp(uint32_t pkt_num)
943 /* group packets in 4 different size groups groups, 2 per SA */
946 else if (pkt_num < PKT_12)
948 else if (pkt_num < PKT_21)
957 crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
959 struct ipsec_unitest_params *ut_params = &unittest_params;
964 for (i = 0, j = 0; i < PKT_4; i++, j++)
965 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
969 } else if (grp_ind == 1) {
970 for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
971 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
976 } else if (grp_ind == 2) {
977 for (i = 0, j = PKT_12; i < (PKT_21 - PKT_12); i++, j++)
978 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
982 } else if (grp_ind == 3) {
983 for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
984 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
995 crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
1000 if (grp[grp_ind].cnt != PKT_4)
1002 } else if (grp_ind == 1) {
1003 if (grp[grp_ind].cnt != PKT_12 - PKT_4)
1005 } else if (grp_ind == 2) {
1006 if (grp[grp_ind].cnt != PKT_21 - PKT_12)
1008 } else if (grp_ind == 3) {
1009 if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
1018 crypto_ipsec_2sa_4grp(void)
1020 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1021 struct ipsec_unitest_params *ut_params = &unittest_params;
1022 struct rte_ipsec_group grp[BURST_SIZE];
1023 uint32_t k, ng, i, j;
1026 for (i = 0; i < BURST_SIZE; i++) {
1027 j = crypto_ipsec_4grp(i);
1029 /* call crypto prepare */
1030 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
1031 ut_params->ibuf + i, ut_params->cop + i, 1);
1034 "rte_ipsec_pkt_crypto_prepare fail\n");
1037 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
1038 ut_params->cop + i, 1);
1041 "rte_cryptodev_enqueue_burst fail\n");
1046 if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
1049 ng = rte_ipsec_pkt_crypto_group(
1050 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
1051 ut_params->obuf, grp, BURST_SIZE);
1053 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
1058 /* call crypto process */
1059 for (i = 0; i < ng; i++) {
1060 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
1061 if (k != grp[i].cnt) {
1062 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
1065 rc = crypto_ipsec_4grp_check_cnt(i, grp);
1068 "crypto_ipsec_4grp_check_cnt fail\n");
1071 rc = crypto_ipsec_4grp_check_mbufs(i, grp);
1074 "crypto_ipsec_4grp_check_mbufs fail\n");
1078 return TEST_SUCCESS;
1082 test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
1084 struct ipsec_unitest_params *ut_params = &unittest_params;
1085 struct rte_mbuf *ibuf_tmp[BURST_SIZE];
1088 /* reorder packets and create gaps in sequence numbers */
1089 static const uint32_t reorder[BURST_SIZE] = {
1090 24, 25, 26, 27, 28, 29, 30, 31,
1091 16, 17, 18, 19, 20, 21, 22, 23,
1092 8, 9, 10, 11, 12, 13, 14, 15,
1093 0, 1, 2, 3, 4, 5, 6, 7,
1096 if (num_pkts != BURST_SIZE)
1099 for (j = 0; j != BURST_SIZE; j++)
1100 ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
1102 memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
1106 test_ipsec_crypto_op_alloc(uint16_t num_pkts)
1108 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1109 struct ipsec_unitest_params *ut_params = &unittest_params;
1113 for (j = 0; j < num_pkts && rc == 0; j++) {
1114 ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
1115 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1116 if (ut_params->cop[j] == NULL) {
1118 "Failed to allocate symmetric crypto op\n");
1127 test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
1129 uint16_t j = ut_params->pkt_index;
1131 printf("\ntest config: num %d\n", i);
1132 printf(" replay_win_sz %u\n", test_cfg[i].replay_win_sz);
1133 printf(" esn %u\n", test_cfg[i].esn);
1134 printf(" flags 0x%" PRIx64 "\n", test_cfg[i].flags);
1135 printf(" pkt_sz %zu\n", test_cfg[i].pkt_sz);
1136 printf(" num_pkts %u\n\n", test_cfg[i].num_pkts);
1138 if (ut_params->ibuf[j]) {
1139 printf("ibuf[%u] data:\n", j);
1140 rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
1141 ut_params->ibuf[j]->data_len);
1143 if (ut_params->obuf[j]) {
1144 printf("obuf[%u] data:\n", j);
1145 rte_pktmbuf_dump(stdout, ut_params->obuf[j],
1146 ut_params->obuf[j]->data_len);
1148 if (ut_params->testbuf[j]) {
1149 printf("testbuf[%u] data:\n", j);
1150 rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
1151 ut_params->testbuf[j]->data_len);
1156 destroy_sa(uint32_t j)
1158 struct ipsec_unitest_params *ut = &unittest_params;
1160 rte_ipsec_sa_fini(ut->ss[j].sa);
1161 rte_free(ut->ss[j].sa);
1162 rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses);
1163 memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
1167 crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1172 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1173 ut_params->pkt_index = j;
1175 /* compare the data buffers */
1176 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1177 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1179 "input and output data does not match\n");
1180 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1181 ut_params->obuf[j]->pkt_len,
1182 "data_len is not equal to pkt_len");
1183 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1185 "data_len is not equal to input data");
1192 test_ipsec_crypto_inb_burst_null_null(int i)
1194 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1195 struct ipsec_unitest_params *ut_params = &unittest_params;
1196 uint16_t num_pkts = test_cfg[i].num_pkts;
1200 /* create rte_ipsec_sa */
1201 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1202 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1204 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1208 /* Generate test mbuf data */
1209 for (j = 0; j < num_pkts && rc == 0; j++) {
1210 /* packet with sequence number 0 is invalid */
1211 ut_params->ibuf[j] = setup_test_string_tunneled(
1212 ts_params->mbuf_pool, null_encrypted_data,
1213 test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1214 if (ut_params->ibuf[j] == NULL)
1219 if (test_cfg[i].reorder_pkts)
1220 test_ipsec_reorder_inb_pkt_burst(num_pkts);
1221 rc = test_ipsec_crypto_op_alloc(num_pkts);
1225 /* call ipsec library api */
1226 rc = crypto_ipsec(num_pkts);
1228 rc = crypto_inb_burst_null_null_check(
1229 ut_params, i, num_pkts);
1231 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1237 if (rc == TEST_FAILED)
1238 test_ipsec_dump_buffers(ut_params, i);
1245 test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1249 struct ipsec_unitest_params *ut_params = &unittest_params;
1251 ut_params->ipsec_xform.spi = INBOUND_SPI;
1252 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1253 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1254 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1255 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1257 for (i = 0; i < num_cfg && rc == 0; i++) {
1258 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1259 rc = test_ipsec_crypto_inb_burst_null_null(i);
1266 crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1273 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1274 ut_params->pkt_index = j;
1276 testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1277 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1278 /* compare the buffer data */
1279 TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1280 ut_params->obuf[j]->pkt_len,
1281 "test and output data does not match\n");
1282 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1283 ut_params->testbuf[j]->data_len,
1284 "obuf data_len is not equal to testbuf data_len");
1285 TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1286 ut_params->testbuf[j]->pkt_len,
1287 "obuf pkt_len is not equal to testbuf pkt_len");
1294 test_ipsec_crypto_outb_burst_null_null(int i)
1296 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1297 struct ipsec_unitest_params *ut_params = &unittest_params;
1298 uint16_t num_pkts = test_cfg[i].num_pkts;
1302 /* create rte_ipsec_sa*/
1303 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1304 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1306 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1310 /* Generate input mbuf data */
1311 for (j = 0; j < num_pkts && rc == 0; j++) {
1312 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1313 null_plain_data, test_cfg[i].pkt_sz, 0);
1314 if (ut_params->ibuf[j] == NULL)
1317 /* Generate test mbuf data */
1318 /* packet with sequence number 0 is invalid */
1319 ut_params->testbuf[j] = setup_test_string_tunneled(
1320 ts_params->mbuf_pool,
1321 null_plain_data, test_cfg[i].pkt_sz,
1322 OUTBOUND_SPI, j + 1);
1323 if (ut_params->testbuf[j] == NULL)
1329 rc = test_ipsec_crypto_op_alloc(num_pkts);
1332 /* call ipsec library api */
1333 rc = crypto_ipsec(num_pkts);
1335 rc = crypto_outb_burst_null_null_check(ut_params,
1338 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1342 if (rc == TEST_FAILED)
1343 test_ipsec_dump_buffers(ut_params, i);
1350 test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1354 struct ipsec_unitest_params *ut_params = &unittest_params;
1356 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1357 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1358 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1359 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1360 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1362 for (i = 0; i < num_cfg && rc == 0; i++) {
1363 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1364 rc = test_ipsec_crypto_outb_burst_null_null(i);
1371 inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1378 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1379 ut_params->pkt_index = j;
1381 /* compare the buffer data */
1382 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1383 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1385 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1386 ut_params->ibuf[j]->data_len,
1387 "input and output data does not match\n");
1388 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1389 ut_params->obuf[j]->data_len,
1390 "ibuf data_len is not equal to obuf data_len");
1391 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1392 ut_params->obuf[j]->pkt_len,
1393 "ibuf pkt_len is not equal to obuf pkt_len");
1394 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1396 "data_len is not equal input data");
1402 test_ipsec_inline_crypto_inb_burst_null_null(int i)
1404 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1405 struct ipsec_unitest_params *ut_params = &unittest_params;
1406 uint16_t num_pkts = test_cfg[i].num_pkts;
1411 /* create rte_ipsec_sa*/
1412 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1413 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1415 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1419 /* Generate inbound mbuf data */
1420 for (j = 0; j < num_pkts && rc == 0; j++) {
1421 ut_params->ibuf[j] = setup_test_string_tunneled(
1422 ts_params->mbuf_pool,
1423 null_plain_data, test_cfg[i].pkt_sz,
1424 INBOUND_SPI, j + 1);
1425 if (ut_params->ibuf[j] == NULL)
1428 /* Generate test mbuf data */
1429 ut_params->obuf[j] = setup_test_string(
1430 ts_params->mbuf_pool,
1431 null_plain_data, test_cfg[i].pkt_sz, 0);
1432 if (ut_params->obuf[j] == NULL)
1438 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1441 rc = inline_inb_burst_null_null_check(ut_params, i,
1445 "rte_ipsec_pkt_process failed, cfg %d\n",
1451 if (rc == TEST_FAILED)
1452 test_ipsec_dump_buffers(ut_params, i);
1459 test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1463 struct ipsec_unitest_params *ut_params = &unittest_params;
1465 ut_params->ipsec_xform.spi = INBOUND_SPI;
1466 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1467 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1468 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1469 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1471 for (i = 0; i < num_cfg && rc == 0; i++) {
1472 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1473 rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1480 test_ipsec_inline_proto_inb_burst_null_null(int i)
1482 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1483 struct ipsec_unitest_params *ut_params = &unittest_params;
1484 uint16_t num_pkts = test_cfg[i].num_pkts;
1489 /* create rte_ipsec_sa*/
1490 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1491 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1493 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1497 /* Generate inbound mbuf data */
1498 for (j = 0; j < num_pkts && rc == 0; j++) {
1499 ut_params->ibuf[j] = setup_test_string(
1500 ts_params->mbuf_pool,
1501 null_plain_data, test_cfg[i].pkt_sz, 0);
1502 if (ut_params->ibuf[j] == NULL)
1505 /* Generate test mbuf data */
1506 ut_params->obuf[j] = setup_test_string(
1507 ts_params->mbuf_pool,
1508 null_plain_data, test_cfg[i].pkt_sz, 0);
1509 if (ut_params->obuf[j] == NULL)
1515 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1518 rc = inline_inb_burst_null_null_check(ut_params, i,
1522 "rte_ipsec_pkt_process failed, cfg %d\n",
1528 if (rc == TEST_FAILED)
1529 test_ipsec_dump_buffers(ut_params, i);
1536 test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1540 struct ipsec_unitest_params *ut_params = &unittest_params;
1542 ut_params->ipsec_xform.spi = INBOUND_SPI;
1543 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1544 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1545 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1546 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1548 for (i = 0; i < num_cfg && rc == 0; i++) {
1549 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1550 rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1557 inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1564 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1565 ut_params->pkt_index = j;
1567 /* compare the buffer data */
1568 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1569 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1570 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1571 ut_params->ibuf[j]->data_len,
1572 "input and output data does not match\n");
1573 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1574 ut_params->obuf[j]->data_len,
1575 "ibuf data_len is not equal to obuf data_len");
1576 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1577 ut_params->obuf[j]->pkt_len,
1578 "ibuf pkt_len is not equal to obuf pkt_len");
1580 /* check mbuf ol_flags */
1581 TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
1582 "ibuf PKT_TX_SEC_OFFLOAD is not set");
1588 test_ipsec_inline_crypto_outb_burst_null_null(int i)
1590 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1591 struct ipsec_unitest_params *ut_params = &unittest_params;
1592 uint16_t num_pkts = test_cfg[i].num_pkts;
1597 /* create rte_ipsec_sa */
1598 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1599 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1601 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1605 /* Generate test mbuf data */
1606 for (j = 0; j < num_pkts && rc == 0; j++) {
1607 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1608 null_plain_data, test_cfg[i].pkt_sz, 0);
1609 if (ut_params->ibuf[0] == NULL)
1613 /* Generate test tunneled mbuf data for comparison */
1614 ut_params->obuf[j] = setup_test_string_tunneled(
1615 ts_params->mbuf_pool,
1616 null_plain_data, test_cfg[i].pkt_sz,
1617 OUTBOUND_SPI, j + 1);
1618 if (ut_params->obuf[j] == NULL)
1624 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1627 rc = inline_outb_burst_null_null_check(ut_params,
1631 "rte_ipsec_pkt_process failed, cfg %d\n",
1637 if (rc == TEST_FAILED)
1638 test_ipsec_dump_buffers(ut_params, i);
1645 test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1649 struct ipsec_unitest_params *ut_params = &unittest_params;
1651 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1652 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1653 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1654 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1655 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1657 for (i = 0; i < num_cfg && rc == 0; i++) {
1658 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1659 rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1666 test_ipsec_inline_proto_outb_burst_null_null(int i)
1668 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1669 struct ipsec_unitest_params *ut_params = &unittest_params;
1670 uint16_t num_pkts = test_cfg[i].num_pkts;
1675 /* create rte_ipsec_sa */
1676 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1677 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1679 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1683 /* Generate test mbuf data */
1684 for (j = 0; j < num_pkts && rc == 0; j++) {
1685 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1686 null_plain_data, test_cfg[i].pkt_sz, 0);
1687 if (ut_params->ibuf[0] == NULL)
1691 /* Generate test tunneled mbuf data for comparison */
1692 ut_params->obuf[j] = setup_test_string(
1693 ts_params->mbuf_pool,
1694 null_plain_data, test_cfg[i].pkt_sz, 0);
1695 if (ut_params->obuf[j] == NULL)
1701 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1704 rc = inline_outb_burst_null_null_check(ut_params,
1708 "rte_ipsec_pkt_process failed, cfg %d\n",
1714 if (rc == TEST_FAILED)
1715 test_ipsec_dump_buffers(ut_params, i);
1722 test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1726 struct ipsec_unitest_params *ut_params = &unittest_params;
1728 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1729 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1730 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1731 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1732 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1734 for (i = 0; i < num_cfg && rc == 0; i++) {
1735 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1736 rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1743 test_ipsec_lksd_proto_inb_burst_null_null(int i)
1745 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1746 struct ipsec_unitest_params *ut_params = &unittest_params;
1747 uint16_t num_pkts = test_cfg[i].num_pkts;
1751 /* create rte_ipsec_sa */
1752 rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1753 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1755 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1759 /* Generate test mbuf data */
1760 for (j = 0; j < num_pkts && rc == 0; j++) {
1761 /* packet with sequence number 0 is invalid */
1762 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1763 null_encrypted_data, test_cfg[i].pkt_sz, 0);
1764 if (ut_params->ibuf[j] == NULL)
1769 if (test_cfg[i].reorder_pkts)
1770 test_ipsec_reorder_inb_pkt_burst(num_pkts);
1771 rc = test_ipsec_crypto_op_alloc(num_pkts);
1775 /* call ipsec library api */
1776 rc = lksd_proto_ipsec(num_pkts);
1778 rc = crypto_inb_burst_null_null_check(ut_params, i,
1781 RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1787 if (rc == TEST_FAILED)
1788 test_ipsec_dump_buffers(ut_params, i);
1795 test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1799 struct ipsec_unitest_params *ut_params = &unittest_params;
1801 ut_params->ipsec_xform.spi = INBOUND_SPI;
1802 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1803 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1804 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1805 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1807 for (i = 0; i < num_cfg && rc == 0; i++) {
1808 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1809 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1816 test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1820 struct ipsec_unitest_params *ut_params = &unittest_params;
1822 ut_params->ipsec_xform.spi = INBOUND_SPI;
1823 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1824 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1825 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1826 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1828 for (i = 0; i < num_cfg && rc == 0; i++) {
1829 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1830 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1837 replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1842 for (j = 0; j < num_pkts; j++) {
1843 /* compare the buffer data */
1844 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1845 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1847 "input and output data does not match\n");
1849 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1850 ut_params->obuf[j]->pkt_len,
1851 "data_len is not equal to pkt_len");
1858 test_ipsec_replay_inb_inside_null_null(int i)
1860 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1861 struct ipsec_unitest_params *ut_params = &unittest_params;
1864 /* create rte_ipsec_sa*/
1865 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1866 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1868 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1872 /* Generate inbound mbuf data */
1873 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1874 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1875 if (ut_params->ibuf[0] == NULL)
1878 rc = test_ipsec_crypto_op_alloc(1);
1881 /* call ipsec library api */
1882 rc = crypto_ipsec(1);
1884 rc = replay_inb_null_null_check(ut_params, i, 1);
1886 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1892 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1893 /* generate packet with seq number inside the replay window */
1894 if (ut_params->ibuf[0]) {
1895 rte_pktmbuf_free(ut_params->ibuf[0]);
1896 ut_params->ibuf[0] = 0;
1899 ut_params->ibuf[0] = setup_test_string_tunneled(
1900 ts_params->mbuf_pool, null_encrypted_data,
1901 test_cfg[i].pkt_sz, INBOUND_SPI,
1902 test_cfg[i].replay_win_sz);
1903 if (ut_params->ibuf[0] == NULL)
1906 rc = test_ipsec_crypto_op_alloc(1);
1909 /* call ipsec library api */
1910 rc = crypto_ipsec(1);
1912 rc = replay_inb_null_null_check(
1915 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1921 if (rc == TEST_FAILED)
1922 test_ipsec_dump_buffers(ut_params, i);
1930 test_ipsec_replay_inb_inside_null_null_wrapper(void)
1934 struct ipsec_unitest_params *ut_params = &unittest_params;
1936 ut_params->ipsec_xform.spi = INBOUND_SPI;
1937 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1938 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1939 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1940 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1942 for (i = 0; i < num_cfg && rc == 0; i++) {
1943 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1944 rc = test_ipsec_replay_inb_inside_null_null(i);
1951 test_ipsec_replay_inb_outside_null_null(int i)
1953 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1954 struct ipsec_unitest_params *ut_params = &unittest_params;
1957 /* create rte_ipsec_sa */
1958 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1959 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1961 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1965 /* Generate test mbuf data */
1966 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1967 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
1968 test_cfg[i].replay_win_sz + 2);
1969 if (ut_params->ibuf[0] == NULL)
1972 rc = test_ipsec_crypto_op_alloc(1);
1975 /* call ipsec library api */
1976 rc = crypto_ipsec(1);
1978 rc = replay_inb_null_null_check(ut_params, i, 1);
1980 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1986 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1987 /* generate packet with seq number outside the replay window */
1988 if (ut_params->ibuf[0]) {
1989 rte_pktmbuf_free(ut_params->ibuf[0]);
1990 ut_params->ibuf[0] = 0;
1992 ut_params->ibuf[0] = setup_test_string_tunneled(
1993 ts_params->mbuf_pool, null_encrypted_data,
1994 test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1995 if (ut_params->ibuf[0] == NULL)
1998 rc = test_ipsec_crypto_op_alloc(1);
2001 /* call ipsec library api */
2002 rc = crypto_ipsec(1);
2004 if (test_cfg[i].esn == 0) {
2006 "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2008 test_cfg[i].replay_win_sz + 2,
2014 "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2015 i, test_cfg[i].replay_win_sz + 2, 1);
2021 if (rc == TEST_FAILED)
2022 test_ipsec_dump_buffers(ut_params, i);
2030 test_ipsec_replay_inb_outside_null_null_wrapper(void)
2034 struct ipsec_unitest_params *ut_params = &unittest_params;
2036 ut_params->ipsec_xform.spi = INBOUND_SPI;
2037 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2038 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2039 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2040 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2042 for (i = 0; i < num_cfg && rc == 0; i++) {
2043 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2044 rc = test_ipsec_replay_inb_outside_null_null(i);
2051 test_ipsec_replay_inb_repeat_null_null(int i)
2053 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2054 struct ipsec_unitest_params *ut_params = &unittest_params;
2057 /* create rte_ipsec_sa */
2058 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2059 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2061 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2065 /* Generate test mbuf data */
2066 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2067 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2068 if (ut_params->ibuf[0] == NULL)
2071 rc = test_ipsec_crypto_op_alloc(1);
2074 /* call ipsec library api */
2075 rc = crypto_ipsec(1);
2077 rc = replay_inb_null_null_check(ut_params, i, 1);
2079 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2085 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2087 * generate packet with repeat seq number in the replay
2090 if (ut_params->ibuf[0]) {
2091 rte_pktmbuf_free(ut_params->ibuf[0]);
2092 ut_params->ibuf[0] = 0;
2095 ut_params->ibuf[0] = setup_test_string_tunneled(
2096 ts_params->mbuf_pool, null_encrypted_data,
2097 test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2098 if (ut_params->ibuf[0] == NULL)
2101 rc = test_ipsec_crypto_op_alloc(1);
2104 /* call ipsec library api */
2105 rc = crypto_ipsec(1);
2108 "packet is not repeated in the replay window, cfg %d seq %u\n",
2113 "packet is repeated in the replay window, cfg %d seq %u\n",
2120 if (rc == TEST_FAILED)
2121 test_ipsec_dump_buffers(ut_params, i);
2129 test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2133 struct ipsec_unitest_params *ut_params = &unittest_params;
2135 ut_params->ipsec_xform.spi = INBOUND_SPI;
2136 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2137 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2138 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2139 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2141 for (i = 0; i < num_cfg && rc == 0; i++) {
2142 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2143 rc = test_ipsec_replay_inb_repeat_null_null(i);
2150 test_ipsec_replay_inb_inside_burst_null_null(int i)
2152 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2153 struct ipsec_unitest_params *ut_params = &unittest_params;
2154 uint16_t num_pkts = test_cfg[i].num_pkts;
2158 /* create rte_ipsec_sa*/
2159 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2160 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2162 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2166 /* Generate inbound mbuf data */
2167 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2168 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2169 if (ut_params->ibuf[0] == NULL)
2172 rc = test_ipsec_crypto_op_alloc(1);
2175 /* call ipsec library api */
2176 rc = crypto_ipsec(1);
2178 rc = replay_inb_null_null_check(ut_params, i, 1);
2180 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2186 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2188 * generate packet(s) with seq number(s) inside the
2191 if (ut_params->ibuf[0]) {
2192 rte_pktmbuf_free(ut_params->ibuf[0]);
2193 ut_params->ibuf[0] = 0;
2196 for (j = 0; j < num_pkts && rc == 0; j++) {
2197 /* packet with sequence number 1 already processed */
2198 ut_params->ibuf[j] = setup_test_string_tunneled(
2199 ts_params->mbuf_pool, null_encrypted_data,
2200 test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2201 if (ut_params->ibuf[j] == NULL)
2206 if (test_cfg[i].reorder_pkts)
2207 test_ipsec_reorder_inb_pkt_burst(num_pkts);
2208 rc = test_ipsec_crypto_op_alloc(num_pkts);
2212 /* call ipsec library api */
2213 rc = crypto_ipsec(num_pkts);
2215 rc = replay_inb_null_null_check(
2216 ut_params, i, num_pkts);
2218 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2224 if (rc == TEST_FAILED)
2225 test_ipsec_dump_buffers(ut_params, i);
2233 test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2237 struct ipsec_unitest_params *ut_params = &unittest_params;
2239 ut_params->ipsec_xform.spi = INBOUND_SPI;
2240 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2241 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2242 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2243 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2245 for (i = 0; i < num_cfg && rc == 0; i++) {
2246 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2247 rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2255 crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2260 for (j = 0; j < BURST_SIZE; j++) {
2261 ut_params->pkt_index = j;
2263 /* compare the data buffers */
2264 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2265 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2267 "input and output data does not match\n");
2268 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2269 ut_params->obuf[j]->pkt_len,
2270 "data_len is not equal to pkt_len");
2271 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2273 "data_len is not equal to input data");
2280 test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2282 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2283 struct ipsec_unitest_params *ut_params = &unittest_params;
2284 uint16_t num_pkts = test_cfg[i].num_pkts;
2288 if (num_pkts != BURST_SIZE)
2291 /* create rte_ipsec_sa */
2292 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2293 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2295 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2299 /* create second rte_ipsec_sa */
2300 ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2301 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2302 test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2304 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2309 /* Generate test mbuf data */
2310 for (j = 0; j < num_pkts && rc == 0; j++) {
2312 /* packet with sequence number 0 is invalid */
2313 ut_params->ibuf[j] = setup_test_string_tunneled(
2314 ts_params->mbuf_pool, null_encrypted_data,
2315 test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2316 if (ut_params->ibuf[j] == NULL)
2321 rc = test_ipsec_crypto_op_alloc(num_pkts);
2324 /* call ipsec library api */
2325 rc = crypto_ipsec_2sa();
2327 rc = crypto_inb_burst_2sa_null_null_check(
2330 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2336 if (rc == TEST_FAILED)
2337 test_ipsec_dump_buffers(ut_params, i);
2345 test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2349 struct ipsec_unitest_params *ut_params = &unittest_params;
2351 ut_params->ipsec_xform.spi = INBOUND_SPI;
2352 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2353 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2354 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2355 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2357 for (i = 0; i < num_cfg && rc == 0; i++) {
2358 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2359 rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2366 test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2368 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2369 struct ipsec_unitest_params *ut_params = &unittest_params;
2370 uint16_t num_pkts = test_cfg[i].num_pkts;
2374 if (num_pkts != BURST_SIZE)
2377 /* create rte_ipsec_sa */
2378 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2379 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2381 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2385 /* create second rte_ipsec_sa */
2386 ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2387 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2388 test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2390 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2395 /* Generate test mbuf data */
2396 for (j = 0; j < num_pkts && rc == 0; j++) {
2397 k = crypto_ipsec_4grp(j);
2399 /* packet with sequence number 0 is invalid */
2400 ut_params->ibuf[j] = setup_test_string_tunneled(
2401 ts_params->mbuf_pool, null_encrypted_data,
2402 test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
2403 if (ut_params->ibuf[j] == NULL)
2408 rc = test_ipsec_crypto_op_alloc(num_pkts);
2411 /* call ipsec library api */
2412 rc = crypto_ipsec_2sa_4grp();
2414 rc = crypto_inb_burst_2sa_null_null_check(
2417 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2423 if (rc == TEST_FAILED)
2424 test_ipsec_dump_buffers(ut_params, i);
2432 test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
2436 struct ipsec_unitest_params *ut_params = &unittest_params;
2438 ut_params->ipsec_xform.spi = INBOUND_SPI;
2439 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2440 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2441 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2442 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2444 for (i = 0; i < num_cfg && rc == 0; i++) {
2445 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2446 rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
2452 static struct unit_test_suite ipsec_testsuite = {
2453 .suite_name = "IPsec NULL Unit Test Suite",
2454 .setup = testsuite_setup,
2455 .teardown = testsuite_teardown,
2456 .unit_test_cases = {
2457 TEST_CASE_ST(ut_setup, ut_teardown,
2458 test_ipsec_crypto_inb_burst_null_null_wrapper),
2459 TEST_CASE_ST(ut_setup, ut_teardown,
2460 test_ipsec_crypto_outb_burst_null_null_wrapper),
2461 TEST_CASE_ST(ut_setup, ut_teardown,
2462 test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
2463 TEST_CASE_ST(ut_setup, ut_teardown,
2464 test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
2465 TEST_CASE_ST(ut_setup, ut_teardown,
2466 test_ipsec_inline_proto_inb_burst_null_null_wrapper),
2467 TEST_CASE_ST(ut_setup, ut_teardown,
2468 test_ipsec_inline_proto_outb_burst_null_null_wrapper),
2469 TEST_CASE_ST(ut_setup, ut_teardown,
2470 test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
2471 TEST_CASE_ST(ut_setup, ut_teardown,
2472 test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
2473 TEST_CASE_ST(ut_setup, ut_teardown,
2474 test_ipsec_replay_inb_inside_null_null_wrapper),
2475 TEST_CASE_ST(ut_setup, ut_teardown,
2476 test_ipsec_replay_inb_outside_null_null_wrapper),
2477 TEST_CASE_ST(ut_setup, ut_teardown,
2478 test_ipsec_replay_inb_repeat_null_null_wrapper),
2479 TEST_CASE_ST(ut_setup, ut_teardown,
2480 test_ipsec_replay_inb_inside_burst_null_null_wrapper),
2481 TEST_CASE_ST(ut_setup, ut_teardown,
2482 test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
2483 TEST_CASE_ST(ut_setup, ut_teardown,
2484 test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
2485 TEST_CASES_END() /**< NULL terminate unit test array */
2492 return unit_test_suite_runner(&ipsec_testsuite);
2495 REGISTER_TEST_COMMAND(ipsec_autotest, test_ipsec);