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