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_pause.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 100
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
47 enum rte_crypto_sym_xform_type auth;
48 enum rte_crypto_sym_xform_type cipher;
49 enum rte_crypto_sym_xform_type aead;
52 char cipher_algo[128];
56 struct ipsec_testsuite_params {
57 struct rte_mempool *mbuf_pool;
58 struct rte_mempool *cop_mpool;
59 struct rte_cryptodev_config conf;
60 struct rte_cryptodev_qp_conf qp_conf;
63 uint8_t valid_dev_found;
66 struct ipsec_unitest_params {
67 struct rte_crypto_sym_xform cipher_xform;
68 struct rte_crypto_sym_xform auth_xform;
69 struct rte_crypto_sym_xform aead_xform;
70 struct rte_crypto_sym_xform *crypto_xforms;
72 struct rte_security_ipsec_xform ipsec_xform;
74 struct rte_ipsec_sa_prm sa_prm;
75 struct rte_ipsec_session ss[MAX_NB_SAS];
77 struct rte_crypto_op *cop[BURST_SIZE];
79 struct rte_mbuf *obuf[BURST_SIZE], *ibuf[BURST_SIZE],
85 struct ipsec_test_cfg {
86 uint32_t replay_win_sz;
91 uint32_t reorder_pkts;
94 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_80_BYTES, BURST_SIZE,
99 {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, 1, 0},
100 {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, BURST_SIZE,
102 {REPLAY_WIN_64, ESN_ENABLED, 0, DATA_64_BYTES, 1, 0},
103 {REPLAY_WIN_128, ESN_ENABLED, RTE_IPSEC_SAFLAG_SQN_ATOM,
104 DATA_80_BYTES, 1, 0},
105 {REPLAY_WIN_256, ESN_DISABLED, 0, DATA_100_BYTES, 1, 0},
108 static const int num_cfg = RTE_DIM(test_cfg);
109 static struct ipsec_testsuite_params testsuite_params = { NULL };
110 static struct ipsec_unitest_params unittest_params;
111 static struct user_params uparams;
113 struct supported_cipher_algo {
115 enum rte_crypto_cipher_algorithm algo;
121 struct supported_auth_algo {
123 enum rte_crypto_auth_algorithm algo;
129 const struct supported_cipher_algo cipher_algos[] = {
132 .algo = RTE_CRYPTO_CIPHER_NULL,
139 const struct supported_auth_algo auth_algos[] = {
142 .algo = RTE_CRYPTO_AUTH_NULL,
150 dummy_sec_create(void *device, struct rte_security_session_conf *conf,
151 struct rte_security_session *sess, struct rte_mempool *mp)
153 RTE_SET_USED(device);
157 sess->sess_private_data = NULL;
162 dummy_sec_destroy(void *device, struct rte_security_session *sess)
164 RTE_SET_USED(device);
169 static const struct rte_security_ops dummy_sec_ops = {
170 .session_create = dummy_sec_create,
171 .session_destroy = dummy_sec_destroy,
174 static struct rte_security_ctx dummy_sec_ctx = {
175 .ops = &dummy_sec_ops,
178 static const struct supported_cipher_algo *
179 find_match_cipher_algo(const char *cipher_keyword)
183 for (i = 0; i < RTE_DIM(cipher_algos); i++) {
184 const struct supported_cipher_algo *algo =
187 if (strcmp(cipher_keyword, algo->keyword) == 0)
194 static const struct supported_auth_algo *
195 find_match_auth_algo(const char *auth_keyword)
199 for (i = 0; i < RTE_DIM(auth_algos); i++) {
200 const struct supported_auth_algo *algo =
203 if (strcmp(auth_keyword, algo->keyword) == 0)
211 fill_crypto_xform(struct ipsec_unitest_params *ut_params,
212 const struct supported_auth_algo *auth_algo,
213 const struct supported_cipher_algo *cipher_algo)
215 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
216 ut_params->cipher_xform.cipher.algo = cipher_algo->algo;
217 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
218 ut_params->auth_xform.auth.algo = auth_algo->algo;
220 if (ut_params->ipsec_xform.direction ==
221 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
222 ut_params->cipher_xform.cipher.op =
223 RTE_CRYPTO_CIPHER_OP_DECRYPT;
224 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
225 ut_params->cipher_xform.next = NULL;
226 ut_params->auth_xform.next = &ut_params->cipher_xform;
227 ut_params->crypto_xforms = &ut_params->auth_xform;
229 ut_params->cipher_xform.cipher.op =
230 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
231 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
232 ut_params->auth_xform.next = NULL;
233 ut_params->cipher_xform.next = &ut_params->auth_xform;
234 ut_params->crypto_xforms = &ut_params->cipher_xform;
239 check_cryptodev_capablity(const struct ipsec_unitest_params *ut,
242 struct rte_cryptodev_sym_capability_idx cap_idx;
243 const struct rte_cryptodev_symmetric_capability *cap;
246 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
247 cap_idx.algo.auth = ut->auth_xform.auth.algo;
248 cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
251 rc = rte_cryptodev_sym_capability_check_auth(cap,
252 ut->auth_xform.auth.key.length,
253 ut->auth_xform.auth.digest_length, 0);
255 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
256 cap_idx.algo.cipher = ut->cipher_xform.cipher.algo;
257 cap = rte_cryptodev_sym_capability_get(
260 rc = rte_cryptodev_sym_capability_check_cipher(
262 ut->cipher_xform.cipher.key.length,
263 ut->cipher_xform.cipher.iv.length);
271 testsuite_setup(void)
273 struct ipsec_testsuite_params *ts_params = &testsuite_params;
274 struct ipsec_unitest_params *ut_params = &unittest_params;
275 const struct supported_auth_algo *auth_algo;
276 const struct supported_cipher_algo *cipher_algo;
277 struct rte_cryptodev_info info;
278 uint32_t i, nb_devs, dev_id;
282 memset(ts_params, 0, sizeof(*ts_params));
283 memset(ut_params, 0, sizeof(*ut_params));
284 memset(&uparams, 0, sizeof(struct user_params));
286 uparams.auth = RTE_CRYPTO_SYM_XFORM_AUTH;
287 uparams.cipher = RTE_CRYPTO_SYM_XFORM_CIPHER;
288 uparams.aead = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
289 strcpy(uparams.auth_algo, "null");
290 strcpy(uparams.cipher_algo, "null");
292 auth_algo = find_match_auth_algo(uparams.auth_algo);
293 cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
294 fill_crypto_xform(ut_params, auth_algo, cipher_algo);
296 nb_devs = rte_cryptodev_count();
298 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
302 /* Find first valid crypto device */
303 for (i = 0; i < nb_devs; i++) {
304 rc = check_cryptodev_capablity(ut_params, i);
306 ts_params->valid_dev = i;
307 ts_params->valid_dev_found = 1;
312 if (ts_params->valid_dev_found == 0)
315 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
317 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
319 if (ts_params->mbuf_pool == NULL) {
320 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
324 ts_params->cop_mpool = rte_crypto_op_pool_create(
325 "MBUF_CRYPTO_SYM_OP_POOL",
326 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
327 NUM_MBUFS, MBUF_CACHE_SIZE,
329 sizeof(struct rte_crypto_sym_xform) +
332 if (ts_params->cop_mpool == NULL) {
333 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
337 /* Set up all the qps on the first of the valid devices found */
338 dev_id = ts_params->valid_dev;
340 rte_cryptodev_info_get(dev_id, &info);
342 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
343 ts_params->conf.socket_id = SOCKET_ID_ANY;
345 sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id);
346 sess_sz = RTE_MAX(sess_sz, sizeof(struct rte_security_session));
349 * Create mempools for sessions
351 if (info.sym.max_nb_sessions != 0 &&
352 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
353 RTE_LOG(ERR, USER1, "Device does not support "
354 "at least %u sessions\n",
359 ts_params->qp_conf.mp_session_private = rte_mempool_create(
363 0, 0, NULL, NULL, NULL,
367 TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session_private,
368 "private session mempool allocation failed");
370 ts_params->qp_conf.mp_session =
371 rte_cryptodev_sym_session_pool_create("test_sess_mp",
372 MAX_NB_SESSIONS, 0, 0, 0, SOCKET_ID_ANY);
374 TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session,
375 "session mempool allocation failed");
377 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
379 "Failed to configure cryptodev %u with %u qps",
380 dev_id, ts_params->conf.nb_queue_pairs);
382 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
384 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
385 dev_id, 0, &ts_params->qp_conf,
386 rte_cryptodev_socket_id(dev_id)),
387 "Failed to setup queue pair %u on cryptodev %u",
394 testsuite_teardown(void)
396 struct ipsec_testsuite_params *ts_params = &testsuite_params;
398 if (ts_params->mbuf_pool != NULL) {
399 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
400 rte_mempool_avail_count(ts_params->mbuf_pool));
401 rte_mempool_free(ts_params->mbuf_pool);
402 ts_params->mbuf_pool = NULL;
405 if (ts_params->cop_mpool != NULL) {
406 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
407 rte_mempool_avail_count(ts_params->cop_mpool));
408 rte_mempool_free(ts_params->cop_mpool);
409 ts_params->cop_mpool = NULL;
412 /* Free session mempools */
413 if (ts_params->qp_conf.mp_session != NULL) {
414 rte_mempool_free(ts_params->qp_conf.mp_session);
415 ts_params->qp_conf.mp_session = NULL;
418 if (ts_params->qp_conf.mp_session_private != NULL) {
419 rte_mempool_free(ts_params->qp_conf.mp_session_private);
420 ts_params->qp_conf.mp_session_private = NULL;
427 struct ipsec_testsuite_params *ts_params = &testsuite_params;
428 struct ipsec_unitest_params *ut_params = &unittest_params;
430 /* Clear unit test parameters before running test */
431 memset(ut_params, 0, sizeof(*ut_params));
433 /* Reconfigure device to default parameters */
434 ts_params->conf.socket_id = SOCKET_ID_ANY;
436 /* Start the device */
437 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_dev),
438 "Failed to start cryptodev %u",
439 ts_params->valid_dev);
447 struct ipsec_testsuite_params *ts_params = &testsuite_params;
448 struct ipsec_unitest_params *ut_params = &unittest_params;
451 for (i = 0; i < BURST_SIZE; i++) {
452 /* free crypto operation structure */
453 if (ut_params->cop[i])
454 rte_crypto_op_free(ut_params->cop[i]);
457 * free mbuf - both obuf and ibuf are usually the same,
458 * so check if they point at the same address is necessary,
459 * to avoid freeing the mbuf twice.
461 if (ut_params->obuf[i]) {
462 rte_pktmbuf_free(ut_params->obuf[i]);
463 if (ut_params->ibuf[i] == ut_params->obuf[i])
464 ut_params->ibuf[i] = 0;
465 ut_params->obuf[i] = 0;
467 if (ut_params->ibuf[i]) {
468 rte_pktmbuf_free(ut_params->ibuf[i]);
469 ut_params->ibuf[i] = 0;
472 if (ut_params->testbuf[i]) {
473 rte_pktmbuf_free(ut_params->testbuf[i]);
474 ut_params->testbuf[i] = 0;
478 if (ts_params->mbuf_pool != NULL)
479 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
480 rte_mempool_avail_count(ts_params->mbuf_pool));
482 /* Stop the device */
483 rte_cryptodev_stop(ts_params->valid_dev);
486 #define IPSEC_MAX_PAD_SIZE UINT8_MAX
488 static const uint8_t esp_pad_bytes[IPSEC_MAX_PAD_SIZE] = {
489 1, 2, 3, 4, 5, 6, 7, 8,
490 9, 10, 11, 12, 13, 14, 15, 16,
491 17, 18, 19, 20, 21, 22, 23, 24,
492 25, 26, 27, 28, 29, 30, 31, 32,
493 33, 34, 35, 36, 37, 38, 39, 40,
494 41, 42, 43, 44, 45, 46, 47, 48,
495 49, 50, 51, 52, 53, 54, 55, 56,
496 57, 58, 59, 60, 61, 62, 63, 64,
497 65, 66, 67, 68, 69, 70, 71, 72,
498 73, 74, 75, 76, 77, 78, 79, 80,
499 81, 82, 83, 84, 85, 86, 87, 88,
500 89, 90, 91, 92, 93, 94, 95, 96,
501 97, 98, 99, 100, 101, 102, 103, 104,
502 105, 106, 107, 108, 109, 110, 111, 112,
503 113, 114, 115, 116, 117, 118, 119, 120,
504 121, 122, 123, 124, 125, 126, 127, 128,
505 129, 130, 131, 132, 133, 134, 135, 136,
506 137, 138, 139, 140, 141, 142, 143, 144,
507 145, 146, 147, 148, 149, 150, 151, 152,
508 153, 154, 155, 156, 157, 158, 159, 160,
509 161, 162, 163, 164, 165, 166, 167, 168,
510 169, 170, 171, 172, 173, 174, 175, 176,
511 177, 178, 179, 180, 181, 182, 183, 184,
512 185, 186, 187, 188, 189, 190, 191, 192,
513 193, 194, 195, 196, 197, 198, 199, 200,
514 201, 202, 203, 204, 205, 206, 207, 208,
515 209, 210, 211, 212, 213, 214, 215, 216,
516 217, 218, 219, 220, 221, 222, 223, 224,
517 225, 226, 227, 228, 229, 230, 231, 232,
518 233, 234, 235, 236, 237, 238, 239, 240,
519 241, 242, 243, 244, 245, 246, 247, 248,
520 249, 250, 251, 252, 253, 254, 255,
523 /* ***** data for tests ***** */
525 const char null_plain_data[] =
526 "Network Security People Have A Strange Sense Of Humor unlike Other "
527 "People who have a normal sense of humour";
529 const char null_encrypted_data[] =
530 "Network Security People Have A Strange Sense Of Humor unlike Other "
531 "People who have a normal sense of humour";
533 struct ipv4_hdr ipv4_outer = {
534 .version_ihl = IPVERSION << 4 |
535 sizeof(ipv4_outer) / IPV4_IHL_MULTIPLIER,
536 .time_to_live = IPDEFTTL,
537 .next_proto_id = IPPROTO_ESP,
538 .src_addr = IPv4(192, 168, 1, 100),
539 .dst_addr = IPv4(192, 168, 2, 100),
542 static struct rte_mbuf *
543 setup_test_string(struct rte_mempool *mpool,
544 const char *string, size_t len, uint8_t blocksize)
546 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
547 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
550 memset(m->buf_addr, 0, m->buf_len);
551 char *dst = rte_pktmbuf_append(m, t_len);
558 rte_memcpy(dst, string, t_len);
560 memset(dst, 0, t_len);
566 static struct rte_mbuf *
567 setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
568 size_t len, uint32_t spi, uint32_t seq)
570 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
571 uint32_t hdrlen = sizeof(struct ipv4_hdr) + sizeof(struct esp_hdr);
572 uint32_t taillen = sizeof(struct esp_tail);
573 uint32_t t_len = len + hdrlen + taillen;
576 struct esp_hdr esph = {
577 .spi = rte_cpu_to_be_32(spi),
578 .seq = rte_cpu_to_be_32(seq)
581 padlen = RTE_ALIGN(t_len, 4) - t_len;
584 struct esp_tail espt = {
586 .next_proto = IPPROTO_IPIP,
592 memset(m->buf_addr, 0, m->buf_len);
593 char *dst = rte_pktmbuf_append(m, t_len);
599 /* copy outer IP and ESP header */
600 ipv4_outer.total_length = rte_cpu_to_be_16(t_len);
601 ipv4_outer.packet_id = rte_cpu_to_be_16(seq);
602 rte_memcpy(dst, &ipv4_outer, sizeof(ipv4_outer));
603 dst += sizeof(ipv4_outer);
604 m->l3_len = sizeof(ipv4_outer);
605 rte_memcpy(dst, &esph, sizeof(esph));
608 if (string != NULL) {
610 rte_memcpy(dst, string, len);
613 rte_memcpy(dst, esp_pad_bytes, padlen);
615 /* copy ESP tail header */
616 rte_memcpy(dst, &espt, sizeof(espt));
618 memset(dst, 0, t_len);
624 create_dummy_sec_session(struct ipsec_unitest_params *ut,
625 struct rte_cryptodev_qp_conf *qp, uint32_t j)
627 static struct rte_security_session_conf conf;
629 ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
630 &conf, qp->mp_session_private);
632 if (ut->ss[j].security.ses == NULL)
635 ut->ss[j].security.ctx = &dummy_sec_ctx;
636 ut->ss[j].security.ol_flags = 0;
641 create_crypto_session(struct ipsec_unitest_params *ut,
642 struct rte_cryptodev_qp_conf *qp, uint8_t dev_id, uint32_t j)
645 struct rte_cryptodev_sym_session *s;
647 s = rte_cryptodev_sym_session_create(qp->mp_session);
651 /* initiliaze SA crypto session for device */
652 rc = rte_cryptodev_sym_session_init(dev_id, s,
653 ut->crypto_xforms, qp->mp_session_private);
655 ut->ss[j].crypto.ses = s;
658 /* failure, do cleanup */
659 rte_cryptodev_sym_session_clear(dev_id, s);
660 rte_cryptodev_sym_session_free(s);
666 create_session(struct ipsec_unitest_params *ut,
667 struct rte_cryptodev_qp_conf *qp, uint8_t crypto_dev, uint32_t j)
669 if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
670 return create_crypto_session(ut, qp, crypto_dev, j);
672 return create_dummy_sec_session(ut, qp, j);
676 fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags)
678 struct ipsec_unitest_params *ut_params = &unittest_params;
679 struct rte_ipsec_sa_prm *prm = &ut_params->sa_prm;
680 const struct supported_auth_algo *auth_algo;
681 const struct supported_cipher_algo *cipher_algo;
683 memset(prm, 0, sizeof(*prm));
687 prm->replay_win_sz = replay_win_sz;
689 /* setup ipsec xform */
690 prm->ipsec_xform = ut_params->ipsec_xform;
691 prm->ipsec_xform.salt = (uint32_t)rte_rand();
693 /* setup tunnel related fields */
694 prm->tun.hdr_len = sizeof(ipv4_outer);
695 prm->tun.next_proto = IPPROTO_IPIP;
696 prm->tun.hdr = &ipv4_outer;
698 /* setup crypto section */
699 if (uparams.aead != 0) {
700 /* TODO: will need to fill out with other test cases */
702 if (uparams.auth == 0 && uparams.cipher == 0)
705 auth_algo = find_match_auth_algo(uparams.auth_algo);
706 cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
708 fill_crypto_xform(ut_params, auth_algo, cipher_algo);
711 prm->crypto_xform = ut_params->crypto_xforms;
716 create_sa(enum rte_security_session_action_type action_type,
717 uint32_t replay_win_sz, uint64_t flags, uint32_t j)
719 struct ipsec_testsuite_params *ts = &testsuite_params;
720 struct ipsec_unitest_params *ut = &unittest_params;
724 memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
726 rc = fill_ipsec_param(replay_win_sz, flags);
730 /* create rte_ipsec_sa*/
731 sz = rte_ipsec_sa_size(&ut->sa_prm);
732 TEST_ASSERT(sz > 0, "rte_ipsec_sa_size() failed\n");
734 ut->ss[j].sa = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
735 TEST_ASSERT_NOT_NULL(ut->ss[j].sa,
736 "failed to allocate memory for rte_ipsec_sa\n");
738 ut->ss[j].type = action_type;
739 rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j);
743 rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz);
744 rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL;
746 rc = rte_ipsec_session_prepare(&ut->ss[j]);
752 crypto_ipsec(uint16_t num_pkts)
754 struct ipsec_testsuite_params *ts_params = &testsuite_params;
755 struct ipsec_unitest_params *ut_params = &unittest_params;
757 struct rte_ipsec_group grp[1];
759 /* call crypto prepare */
760 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
761 ut_params->cop, num_pkts);
763 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
766 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
767 ut_params->cop, num_pkts);
769 RTE_LOG(ERR, USER1, "rte_cryptodev_enqueue_burst fail\n");
773 k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
774 ut_params->cop, num_pkts);
776 RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
780 ng = rte_ipsec_pkt_crypto_group(
781 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
782 ut_params->obuf, grp, num_pkts);
784 grp[0].m[0] != ut_params->obuf[0] ||
785 grp[0].cnt != num_pkts ||
786 grp[0].id.ptr != &ut_params->ss[0]) {
787 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
791 /* call crypto process */
792 k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
794 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
802 lksd_proto_ipsec(uint16_t num_pkts)
804 struct ipsec_unitest_params *ut_params = &unittest_params;
806 struct rte_ipsec_group grp[1];
808 /* call crypto prepare */
809 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
810 ut_params->cop, num_pkts);
812 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
816 /* check crypto ops */
817 for (i = 0; i != num_pkts; i++) {
818 TEST_ASSERT_EQUAL(ut_params->cop[i]->type,
819 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
820 "%s: invalid crypto op type for %u-th packet\n",
822 TEST_ASSERT_EQUAL(ut_params->cop[i]->status,
823 RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
824 "%s: invalid crypto op status for %u-th packet\n",
826 TEST_ASSERT_EQUAL(ut_params->cop[i]->sess_type,
827 RTE_CRYPTO_OP_SECURITY_SESSION,
828 "%s: invalid crypto op sess_type for %u-th packet\n",
830 TEST_ASSERT_EQUAL(ut_params->cop[i]->sym->m_src,
832 "%s: invalid crypto op m_src for %u-th packet\n",
836 /* update crypto ops, pretend all finished ok */
837 for (i = 0; i != num_pkts; i++)
838 ut_params->cop[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
840 ng = rte_ipsec_pkt_crypto_group(
841 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
842 ut_params->obuf, grp, num_pkts);
844 grp[0].m[0] != ut_params->obuf[0] ||
845 grp[0].cnt != num_pkts ||
846 grp[0].id.ptr != &ut_params->ss[0]) {
847 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
851 /* call crypto process */
852 k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
854 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
862 crypto_ipsec_2sa(void)
864 struct ipsec_testsuite_params *ts_params = &testsuite_params;
865 struct ipsec_unitest_params *ut_params = &unittest_params;
866 struct rte_ipsec_group grp[BURST_SIZE];
868 uint32_t k, ng, i, r;
870 for (i = 0; i < BURST_SIZE; i++) {
872 /* call crypto prepare */
873 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
874 ut_params->ibuf + i, ut_params->cop + i, 1);
877 "rte_ipsec_pkt_crypto_prepare fail\n");
880 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
881 ut_params->cop + i, 1);
884 "rte_cryptodev_enqueue_burst fail\n");
889 k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
890 ut_params->cop, BURST_SIZE);
891 if (k != BURST_SIZE) {
892 RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
896 ng = rte_ipsec_pkt_crypto_group(
897 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
898 ut_params->obuf, grp, BURST_SIZE);
899 if (ng != BURST_SIZE) {
900 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
905 /* call crypto process */
906 for (i = 0; i < ng; i++) {
907 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
908 if (k != grp[i].cnt) {
909 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
921 crypto_ipsec_4grp(uint32_t pkt_num)
925 /* group packets in 4 different size groups groups, 2 per SA */
928 else if (pkt_num < PKT_12)
930 else if (pkt_num < PKT_21)
939 crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
941 struct ipsec_unitest_params *ut_params = &unittest_params;
946 for (i = 0, j = 0; i < PKT_4; i++, j++)
947 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
951 } else if (grp_ind == 1) {
952 for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
953 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
958 } else if (grp_ind == 2) {
959 for (i = 0, j = PKT_12; i < (PKT_21 - PKT_12); i++, j++)
960 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
964 } else if (grp_ind == 3) {
965 for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
966 if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
977 crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
982 if (grp[grp_ind].cnt != PKT_4)
984 } else if (grp_ind == 1) {
985 if (grp[grp_ind].cnt != PKT_12 - PKT_4)
987 } else if (grp_ind == 2) {
988 if (grp[grp_ind].cnt != PKT_21 - PKT_12)
990 } else if (grp_ind == 3) {
991 if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
1000 crypto_ipsec_2sa_4grp(void)
1002 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1003 struct ipsec_unitest_params *ut_params = &unittest_params;
1004 struct rte_ipsec_group grp[BURST_SIZE];
1005 uint32_t k, ng, i, j;
1008 for (i = 0; i < BURST_SIZE; i++) {
1009 j = crypto_ipsec_4grp(i);
1011 /* call crypto prepare */
1012 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
1013 ut_params->ibuf + i, ut_params->cop + i, 1);
1016 "rte_ipsec_pkt_crypto_prepare fail\n");
1019 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
1020 ut_params->cop + i, 1);
1023 "rte_cryptodev_enqueue_burst fail\n");
1028 k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
1029 ut_params->cop, BURST_SIZE);
1030 if (k != BURST_SIZE) {
1031 RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
1035 ng = rte_ipsec_pkt_crypto_group(
1036 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
1037 ut_params->obuf, grp, BURST_SIZE);
1039 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
1044 /* call crypto process */
1045 for (i = 0; i < ng; i++) {
1046 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
1047 if (k != grp[i].cnt) {
1048 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
1051 rc = crypto_ipsec_4grp_check_cnt(i, grp);
1054 "crypto_ipsec_4grp_check_cnt fail\n");
1057 rc = crypto_ipsec_4grp_check_mbufs(i, grp);
1060 "crypto_ipsec_4grp_check_mbufs fail\n");
1064 return TEST_SUCCESS;
1068 test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
1070 struct ipsec_unitest_params *ut_params = &unittest_params;
1071 struct rte_mbuf *ibuf_tmp[BURST_SIZE];
1074 /* reorder packets and create gaps in sequence numbers */
1075 static const uint32_t reorder[BURST_SIZE] = {
1076 24, 25, 26, 27, 28, 29, 30, 31,
1077 16, 17, 18, 19, 20, 21, 22, 23,
1078 8, 9, 10, 11, 12, 13, 14, 15,
1079 0, 1, 2, 3, 4, 5, 6, 7,
1082 if (num_pkts != BURST_SIZE)
1085 for (j = 0; j != BURST_SIZE; j++)
1086 ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
1088 memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
1092 test_ipsec_crypto_op_alloc(uint16_t num_pkts)
1094 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1095 struct ipsec_unitest_params *ut_params = &unittest_params;
1099 for (j = 0; j < num_pkts && rc == 0; j++) {
1100 ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
1101 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1102 if (ut_params->cop[j] == NULL) {
1104 "Failed to allocate symmetric crypto op\n");
1113 test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
1115 uint16_t j = ut_params->pkt_index;
1117 printf("\ntest config: num %d\n", i);
1118 printf(" replay_win_sz %u\n", test_cfg[i].replay_win_sz);
1119 printf(" esn %u\n", test_cfg[i].esn);
1120 printf(" flags 0x%" PRIx64 "\n", test_cfg[i].flags);
1121 printf(" pkt_sz %zu\n", test_cfg[i].pkt_sz);
1122 printf(" num_pkts %u\n\n", test_cfg[i].num_pkts);
1124 if (ut_params->ibuf[j]) {
1125 printf("ibuf[%u] data:\n", j);
1126 rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
1127 ut_params->ibuf[j]->data_len);
1129 if (ut_params->obuf[j]) {
1130 printf("obuf[%u] data:\n", j);
1131 rte_pktmbuf_dump(stdout, ut_params->obuf[j],
1132 ut_params->obuf[j]->data_len);
1134 if (ut_params->testbuf[j]) {
1135 printf("testbuf[%u] data:\n", j);
1136 rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
1137 ut_params->testbuf[j]->data_len);
1142 destroy_sa(uint32_t j)
1144 struct ipsec_unitest_params *ut = &unittest_params;
1146 rte_ipsec_sa_fini(ut->ss[j].sa);
1147 rte_free(ut->ss[j].sa);
1148 rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses);
1149 memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
1153 crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1158 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1159 ut_params->pkt_index = j;
1161 /* compare the data buffers */
1162 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1163 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1165 "input and output data does not match\n");
1166 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1167 ut_params->obuf[j]->pkt_len,
1168 "data_len is not equal to pkt_len");
1169 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1171 "data_len is not equal to input data");
1178 test_ipsec_crypto_inb_burst_null_null(int i)
1180 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1181 struct ipsec_unitest_params *ut_params = &unittest_params;
1182 uint16_t num_pkts = test_cfg[i].num_pkts;
1186 /* create rte_ipsec_sa */
1187 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1188 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1190 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1195 /* Generate test mbuf data */
1196 for (j = 0; j < num_pkts && rc == 0; j++) {
1197 /* packet with sequence number 0 is invalid */
1198 ut_params->ibuf[j] = setup_test_string_tunneled(
1199 ts_params->mbuf_pool, null_encrypted_data,
1200 test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1201 if (ut_params->ibuf[j] == NULL)
1206 if (test_cfg[i].reorder_pkts)
1207 test_ipsec_reorder_inb_pkt_burst(num_pkts);
1208 rc = test_ipsec_crypto_op_alloc(num_pkts);
1212 /* call ipsec library api */
1213 rc = crypto_ipsec(num_pkts);
1215 rc = crypto_inb_burst_null_null_check(
1216 ut_params, i, num_pkts);
1218 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1224 if (rc == TEST_FAILED)
1225 test_ipsec_dump_buffers(ut_params, i);
1232 test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1236 struct ipsec_unitest_params *ut_params = &unittest_params;
1238 ut_params->ipsec_xform.spi = INBOUND_SPI;
1239 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1240 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1241 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1242 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1244 for (i = 0; i < num_cfg && rc == 0; i++) {
1245 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1246 rc = test_ipsec_crypto_inb_burst_null_null(i);
1253 crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1260 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1261 ut_params->pkt_index = j;
1263 testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1264 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1265 /* compare the buffer data */
1266 TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1267 ut_params->obuf[j]->pkt_len,
1268 "test and output data does not match\n");
1269 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1270 ut_params->testbuf[j]->data_len,
1271 "obuf data_len is not equal to testbuf data_len");
1272 TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1273 ut_params->testbuf[j]->pkt_len,
1274 "obuf pkt_len is not equal to testbuf pkt_len");
1281 test_ipsec_crypto_outb_burst_null_null(int i)
1283 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1284 struct ipsec_unitest_params *ut_params = &unittest_params;
1285 uint16_t num_pkts = test_cfg[i].num_pkts;
1289 /* create rte_ipsec_sa*/
1290 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1291 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1293 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1298 /* Generate input mbuf data */
1299 for (j = 0; j < num_pkts && rc == 0; j++) {
1300 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1301 null_plain_data, test_cfg[i].pkt_sz, 0);
1302 if (ut_params->ibuf[j] == NULL)
1305 /* Generate test mbuf data */
1306 /* packet with sequence number 0 is invalid */
1307 ut_params->testbuf[j] = setup_test_string_tunneled(
1308 ts_params->mbuf_pool,
1309 null_plain_data, test_cfg[i].pkt_sz,
1310 OUTBOUND_SPI, j + 1);
1311 if (ut_params->testbuf[j] == NULL)
1317 rc = test_ipsec_crypto_op_alloc(num_pkts);
1320 /* call ipsec library api */
1321 rc = crypto_ipsec(num_pkts);
1323 rc = crypto_outb_burst_null_null_check(ut_params,
1326 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1330 if (rc == TEST_FAILED)
1331 test_ipsec_dump_buffers(ut_params, i);
1338 test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1342 struct ipsec_unitest_params *ut_params = &unittest_params;
1344 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1345 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1346 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1347 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1348 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1350 for (i = 0; i < num_cfg && rc == 0; i++) {
1351 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1352 rc = test_ipsec_crypto_outb_burst_null_null(i);
1359 inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1366 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1367 ut_params->pkt_index = j;
1369 /* compare the buffer data */
1370 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1371 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1373 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1374 ut_params->ibuf[j]->data_len,
1375 "input and output data does not match\n");
1376 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1377 ut_params->obuf[j]->data_len,
1378 "ibuf data_len is not equal to obuf data_len");
1379 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1380 ut_params->obuf[j]->pkt_len,
1381 "ibuf pkt_len is not equal to obuf pkt_len");
1382 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1384 "data_len is not equal input data");
1390 test_ipsec_inline_crypto_inb_burst_null_null(int i)
1392 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1393 struct ipsec_unitest_params *ut_params = &unittest_params;
1394 uint16_t num_pkts = test_cfg[i].num_pkts;
1399 /* create rte_ipsec_sa*/
1400 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1401 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1403 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1408 /* Generate inbound mbuf data */
1409 for (j = 0; j < num_pkts && rc == 0; j++) {
1410 ut_params->ibuf[j] = setup_test_string_tunneled(
1411 ts_params->mbuf_pool,
1412 null_plain_data, test_cfg[i].pkt_sz,
1413 INBOUND_SPI, j + 1);
1414 if (ut_params->ibuf[j] == NULL)
1417 /* Generate test mbuf data */
1418 ut_params->obuf[j] = setup_test_string(
1419 ts_params->mbuf_pool,
1420 null_plain_data, test_cfg[i].pkt_sz, 0);
1421 if (ut_params->obuf[j] == NULL)
1427 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1430 rc = inline_inb_burst_null_null_check(ut_params, i,
1434 "rte_ipsec_pkt_process failed, cfg %d\n",
1440 if (rc == TEST_FAILED)
1441 test_ipsec_dump_buffers(ut_params, i);
1448 test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1452 struct ipsec_unitest_params *ut_params = &unittest_params;
1454 ut_params->ipsec_xform.spi = INBOUND_SPI;
1455 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1456 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1457 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1458 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1460 for (i = 0; i < num_cfg && rc == 0; i++) {
1461 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1462 rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1469 test_ipsec_inline_proto_inb_burst_null_null(int i)
1471 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1472 struct ipsec_unitest_params *ut_params = &unittest_params;
1473 uint16_t num_pkts = test_cfg[i].num_pkts;
1478 /* create rte_ipsec_sa*/
1479 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1480 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1482 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1487 /* Generate inbound mbuf data */
1488 for (j = 0; j < num_pkts && rc == 0; j++) {
1489 ut_params->ibuf[j] = setup_test_string(
1490 ts_params->mbuf_pool,
1491 null_plain_data, test_cfg[i].pkt_sz, 0);
1492 if (ut_params->ibuf[j] == NULL)
1495 /* Generate test mbuf data */
1496 ut_params->obuf[j] = setup_test_string(
1497 ts_params->mbuf_pool,
1498 null_plain_data, test_cfg[i].pkt_sz, 0);
1499 if (ut_params->obuf[j] == NULL)
1505 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1508 rc = inline_inb_burst_null_null_check(ut_params, i,
1512 "rte_ipsec_pkt_process failed, cfg %d\n",
1518 if (rc == TEST_FAILED)
1519 test_ipsec_dump_buffers(ut_params, i);
1526 test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1530 struct ipsec_unitest_params *ut_params = &unittest_params;
1532 ut_params->ipsec_xform.spi = INBOUND_SPI;
1533 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1534 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1535 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1536 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1538 for (i = 0; i < num_cfg && rc == 0; i++) {
1539 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1540 rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1547 inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1554 for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1555 ut_params->pkt_index = j;
1557 /* compare the buffer data */
1558 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1559 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1560 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1561 ut_params->ibuf[j]->data_len,
1562 "input and output data does not match\n");
1563 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1564 ut_params->obuf[j]->data_len,
1565 "ibuf data_len is not equal to obuf data_len");
1566 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1567 ut_params->obuf[j]->pkt_len,
1568 "ibuf pkt_len is not equal to obuf pkt_len");
1570 /* check mbuf ol_flags */
1571 TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
1572 "ibuf PKT_TX_SEC_OFFLOAD is not set");
1578 test_ipsec_inline_crypto_outb_burst_null_null(int i)
1580 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1581 struct ipsec_unitest_params *ut_params = &unittest_params;
1582 uint16_t num_pkts = test_cfg[i].num_pkts;
1587 /* create rte_ipsec_sa */
1588 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1589 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1591 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1596 /* Generate test mbuf data */
1597 for (j = 0; j < num_pkts && rc == 0; j++) {
1598 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1599 null_plain_data, test_cfg[i].pkt_sz, 0);
1600 if (ut_params->ibuf[0] == NULL)
1604 /* Generate test tunneled mbuf data for comparison */
1605 ut_params->obuf[j] = setup_test_string_tunneled(
1606 ts_params->mbuf_pool,
1607 null_plain_data, test_cfg[i].pkt_sz,
1608 OUTBOUND_SPI, j + 1);
1609 if (ut_params->obuf[j] == NULL)
1615 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1618 rc = inline_outb_burst_null_null_check(ut_params,
1622 "rte_ipsec_pkt_process failed, cfg %d\n",
1628 if (rc == TEST_FAILED)
1629 test_ipsec_dump_buffers(ut_params, i);
1636 test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1640 struct ipsec_unitest_params *ut_params = &unittest_params;
1642 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1643 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1644 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1645 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1646 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1648 for (i = 0; i < num_cfg && rc == 0; i++) {
1649 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1650 rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1657 test_ipsec_inline_proto_outb_burst_null_null(int i)
1659 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1660 struct ipsec_unitest_params *ut_params = &unittest_params;
1661 uint16_t num_pkts = test_cfg[i].num_pkts;
1666 /* create rte_ipsec_sa */
1667 rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1668 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1670 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1675 /* Generate test mbuf data */
1676 for (j = 0; j < num_pkts && rc == 0; j++) {
1677 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1678 null_plain_data, test_cfg[i].pkt_sz, 0);
1679 if (ut_params->ibuf[0] == NULL)
1683 /* Generate test tunneled mbuf data for comparison */
1684 ut_params->obuf[j] = setup_test_string(
1685 ts_params->mbuf_pool,
1686 null_plain_data, test_cfg[i].pkt_sz, 0);
1687 if (ut_params->obuf[j] == NULL)
1693 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1696 rc = inline_outb_burst_null_null_check(ut_params,
1700 "rte_ipsec_pkt_process failed, cfg %d\n",
1706 if (rc == TEST_FAILED)
1707 test_ipsec_dump_buffers(ut_params, i);
1714 test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1718 struct ipsec_unitest_params *ut_params = &unittest_params;
1720 ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1721 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1722 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1723 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1724 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1726 for (i = 0; i < num_cfg && rc == 0; i++) {
1727 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1728 rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1735 test_ipsec_lksd_proto_inb_burst_null_null(int i)
1737 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1738 struct ipsec_unitest_params *ut_params = &unittest_params;
1739 uint16_t num_pkts = test_cfg[i].num_pkts;
1743 /* create rte_ipsec_sa */
1744 rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1745 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1747 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1752 /* Generate test mbuf data */
1753 for (j = 0; j < num_pkts && rc == 0; j++) {
1754 /* packet with sequence number 0 is invalid */
1755 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1756 null_encrypted_data, test_cfg[i].pkt_sz, 0);
1757 if (ut_params->ibuf[j] == NULL)
1762 if (test_cfg[i].reorder_pkts)
1763 test_ipsec_reorder_inb_pkt_burst(num_pkts);
1764 rc = test_ipsec_crypto_op_alloc(num_pkts);
1768 /* call ipsec library api */
1769 rc = lksd_proto_ipsec(num_pkts);
1771 rc = crypto_inb_burst_null_null_check(ut_params, i,
1774 RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1780 if (rc == TEST_FAILED)
1781 test_ipsec_dump_buffers(ut_params, i);
1788 test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1792 struct ipsec_unitest_params *ut_params = &unittest_params;
1794 ut_params->ipsec_xform.spi = INBOUND_SPI;
1795 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1796 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1797 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1798 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1800 for (i = 0; i < num_cfg && rc == 0; i++) {
1801 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1802 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1809 test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1813 struct ipsec_unitest_params *ut_params = &unittest_params;
1815 ut_params->ipsec_xform.spi = INBOUND_SPI;
1816 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1817 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1818 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1819 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1821 for (i = 0; i < num_cfg && rc == 0; i++) {
1822 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1823 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1830 replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1835 for (j = 0; j < num_pkts; j++) {
1836 /* compare the buffer data */
1837 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1838 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1840 "input and output data does not match\n");
1842 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1843 ut_params->obuf[j]->pkt_len,
1844 "data_len is not equal to pkt_len");
1851 test_ipsec_replay_inb_inside_null_null(int i)
1853 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1854 struct ipsec_unitest_params *ut_params = &unittest_params;
1857 /* create rte_ipsec_sa*/
1858 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1859 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1861 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1866 /* Generate inbound mbuf data */
1867 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1868 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1869 if (ut_params->ibuf[0] == NULL)
1872 rc = test_ipsec_crypto_op_alloc(1);
1875 /* call ipsec library api */
1876 rc = crypto_ipsec(1);
1878 rc = replay_inb_null_null_check(ut_params, i, 1);
1880 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1886 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1887 /* generate packet with seq number inside the replay window */
1888 if (ut_params->ibuf[0]) {
1889 rte_pktmbuf_free(ut_params->ibuf[0]);
1890 ut_params->ibuf[0] = 0;
1893 ut_params->ibuf[0] = setup_test_string_tunneled(
1894 ts_params->mbuf_pool, null_encrypted_data,
1895 test_cfg[i].pkt_sz, INBOUND_SPI,
1896 test_cfg[i].replay_win_sz);
1897 if (ut_params->ibuf[0] == NULL)
1900 rc = test_ipsec_crypto_op_alloc(1);
1903 /* call ipsec library api */
1904 rc = crypto_ipsec(1);
1906 rc = replay_inb_null_null_check(
1909 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1915 if (rc == TEST_FAILED)
1916 test_ipsec_dump_buffers(ut_params, i);
1924 test_ipsec_replay_inb_inside_null_null_wrapper(void)
1928 struct ipsec_unitest_params *ut_params = &unittest_params;
1930 ut_params->ipsec_xform.spi = INBOUND_SPI;
1931 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1932 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1933 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1934 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1936 for (i = 0; i < num_cfg && rc == 0; i++) {
1937 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1938 rc = test_ipsec_replay_inb_inside_null_null(i);
1945 test_ipsec_replay_inb_outside_null_null(int i)
1947 struct ipsec_testsuite_params *ts_params = &testsuite_params;
1948 struct ipsec_unitest_params *ut_params = &unittest_params;
1951 /* create rte_ipsec_sa */
1952 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1953 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1955 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1960 /* Generate test mbuf data */
1961 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1962 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
1963 test_cfg[i].replay_win_sz + 2);
1964 if (ut_params->ibuf[0] == NULL)
1967 rc = test_ipsec_crypto_op_alloc(1);
1970 /* call ipsec library api */
1971 rc = crypto_ipsec(1);
1973 rc = replay_inb_null_null_check(ut_params, i, 1);
1975 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1981 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1982 /* generate packet with seq number outside the replay window */
1983 if (ut_params->ibuf[0]) {
1984 rte_pktmbuf_free(ut_params->ibuf[0]);
1985 ut_params->ibuf[0] = 0;
1987 ut_params->ibuf[0] = setup_test_string_tunneled(
1988 ts_params->mbuf_pool, null_encrypted_data,
1989 test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1990 if (ut_params->ibuf[0] == NULL)
1993 rc = test_ipsec_crypto_op_alloc(1);
1996 /* call ipsec library api */
1997 rc = crypto_ipsec(1);
1999 if (test_cfg[i].esn == 0) {
2001 "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2003 test_cfg[i].replay_win_sz + 2,
2009 "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2010 i, test_cfg[i].replay_win_sz + 2, 1);
2016 if (rc == TEST_FAILED)
2017 test_ipsec_dump_buffers(ut_params, i);
2025 test_ipsec_replay_inb_outside_null_null_wrapper(void)
2029 struct ipsec_unitest_params *ut_params = &unittest_params;
2031 ut_params->ipsec_xform.spi = INBOUND_SPI;
2032 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2033 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2034 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2035 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2037 for (i = 0; i < num_cfg && rc == 0; i++) {
2038 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2039 rc = test_ipsec_replay_inb_outside_null_null(i);
2046 test_ipsec_replay_inb_repeat_null_null(int i)
2048 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2049 struct ipsec_unitest_params *ut_params = &unittest_params;
2052 /* create rte_ipsec_sa */
2053 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2054 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2056 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n", i);
2060 /* Generate test mbuf data */
2061 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2062 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2063 if (ut_params->ibuf[0] == NULL)
2066 rc = test_ipsec_crypto_op_alloc(1);
2069 /* call ipsec library api */
2070 rc = crypto_ipsec(1);
2072 rc = replay_inb_null_null_check(ut_params, i, 1);
2074 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2080 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2082 * generate packet with repeat seq number in the replay
2085 if (ut_params->ibuf[0]) {
2086 rte_pktmbuf_free(ut_params->ibuf[0]);
2087 ut_params->ibuf[0] = 0;
2090 ut_params->ibuf[0] = setup_test_string_tunneled(
2091 ts_params->mbuf_pool, null_encrypted_data,
2092 test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2093 if (ut_params->ibuf[0] == NULL)
2096 rc = test_ipsec_crypto_op_alloc(1);
2099 /* call ipsec library api */
2100 rc = crypto_ipsec(1);
2103 "packet is not repeated in the replay window, cfg %d seq %u\n",
2108 "packet is repeated in the replay window, cfg %d seq %u\n",
2115 if (rc == TEST_FAILED)
2116 test_ipsec_dump_buffers(ut_params, i);
2124 test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2128 struct ipsec_unitest_params *ut_params = &unittest_params;
2130 ut_params->ipsec_xform.spi = INBOUND_SPI;
2131 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2132 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2133 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2134 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2136 for (i = 0; i < num_cfg && rc == 0; i++) {
2137 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2138 rc = test_ipsec_replay_inb_repeat_null_null(i);
2145 test_ipsec_replay_inb_inside_burst_null_null(int i)
2147 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2148 struct ipsec_unitest_params *ut_params = &unittest_params;
2149 uint16_t num_pkts = test_cfg[i].num_pkts;
2153 /* create rte_ipsec_sa*/
2154 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2155 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2157 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2162 /* Generate inbound mbuf data */
2163 ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2164 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2165 if (ut_params->ibuf[0] == NULL)
2168 rc = test_ipsec_crypto_op_alloc(1);
2171 /* call ipsec library api */
2172 rc = crypto_ipsec(1);
2174 rc = replay_inb_null_null_check(ut_params, i, 1);
2176 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2182 if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2184 * generate packet(s) with seq number(s) inside the
2187 if (ut_params->ibuf[0]) {
2188 rte_pktmbuf_free(ut_params->ibuf[0]);
2189 ut_params->ibuf[0] = 0;
2192 for (j = 0; j < num_pkts && rc == 0; j++) {
2193 /* packet with sequence number 1 already processed */
2194 ut_params->ibuf[j] = setup_test_string_tunneled(
2195 ts_params->mbuf_pool, null_encrypted_data,
2196 test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2197 if (ut_params->ibuf[j] == NULL)
2202 if (test_cfg[i].reorder_pkts)
2203 test_ipsec_reorder_inb_pkt_burst(num_pkts);
2204 rc = test_ipsec_crypto_op_alloc(num_pkts);
2208 /* call ipsec library api */
2209 rc = crypto_ipsec(num_pkts);
2211 rc = replay_inb_null_null_check(
2212 ut_params, i, num_pkts);
2214 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2220 if (rc == TEST_FAILED)
2221 test_ipsec_dump_buffers(ut_params, i);
2229 test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2233 struct ipsec_unitest_params *ut_params = &unittest_params;
2235 ut_params->ipsec_xform.spi = INBOUND_SPI;
2236 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2237 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2238 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2239 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2241 for (i = 0; i < num_cfg && rc == 0; i++) {
2242 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2243 rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2251 crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2256 for (j = 0; j < BURST_SIZE; j++) {
2257 ut_params->pkt_index = j;
2259 /* compare the data buffers */
2260 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2261 rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2263 "input and output data does not match\n");
2264 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2265 ut_params->obuf[j]->pkt_len,
2266 "data_len is not equal to pkt_len");
2267 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2269 "data_len is not equal to input data");
2276 test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2278 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2279 struct ipsec_unitest_params *ut_params = &unittest_params;
2280 uint16_t num_pkts = test_cfg[i].num_pkts;
2284 if (num_pkts != BURST_SIZE)
2287 /* create rte_ipsec_sa */
2288 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2289 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2291 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2296 /* create second rte_ipsec_sa */
2297 ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2298 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2299 test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2301 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2307 /* Generate test mbuf data */
2308 for (j = 0; j < num_pkts && rc == 0; j++) {
2310 /* packet with sequence number 0 is invalid */
2311 ut_params->ibuf[j] = setup_test_string_tunneled(
2312 ts_params->mbuf_pool, null_encrypted_data,
2313 test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2314 if (ut_params->ibuf[j] == NULL)
2319 rc = test_ipsec_crypto_op_alloc(num_pkts);
2322 /* call ipsec library api */
2323 rc = crypto_ipsec_2sa();
2325 rc = crypto_inb_burst_2sa_null_null_check(
2328 RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2334 if (rc == TEST_FAILED)
2335 test_ipsec_dump_buffers(ut_params, i);
2343 test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2347 struct ipsec_unitest_params *ut_params = &unittest_params;
2349 ut_params->ipsec_xform.spi = INBOUND_SPI;
2350 ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2351 ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2352 ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2353 ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2355 for (i = 0; i < num_cfg && rc == 0; i++) {
2356 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2357 rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2364 test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2366 struct ipsec_testsuite_params *ts_params = &testsuite_params;
2367 struct ipsec_unitest_params *ut_params = &unittest_params;
2368 uint16_t num_pkts = test_cfg[i].num_pkts;
2372 if (num_pkts != BURST_SIZE)
2375 /* create rte_ipsec_sa */
2376 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2377 test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2379 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2384 /* create second rte_ipsec_sa */
2385 ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2386 rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2387 test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2389 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
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);