cryptodev: add feature flags to disable
[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 100
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
97         {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, 1, 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 int
885 crypto_ipsec_2sa(void)
886 {
887         struct ipsec_testsuite_params *ts_params = &testsuite_params;
888         struct ipsec_unitest_params *ut_params = &unittest_params;
889         struct rte_ipsec_group grp[BURST_SIZE];
890         uint32_t k, ng, i, r;
891
892         for (i = 0; i < BURST_SIZE; i++) {
893                 r = i % 2;
894                 /* call crypto prepare */
895                 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
896                                 ut_params->ibuf + i, ut_params->cop + i, 1);
897                 if (k != 1) {
898                         RTE_LOG(ERR, USER1,
899                                 "rte_ipsec_pkt_crypto_prepare fail\n");
900                         return TEST_FAILED;
901                 }
902                 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
903                                 ut_params->cop + i, 1);
904                 if (k != 1) {
905                         RTE_LOG(ERR, USER1,
906                                 "rte_cryptodev_enqueue_burst fail\n");
907                         return TEST_FAILED;
908                 }
909         }
910
911         if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
912                 return TEST_FAILED;
913
914         ng = rte_ipsec_pkt_crypto_group(
915                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
916                 ut_params->obuf, grp, BURST_SIZE);
917         if (ng != BURST_SIZE) {
918                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
919                                 ng);
920                 return TEST_FAILED;
921         }
922
923         /* call crypto process */
924         for (i = 0; i < ng; i++) {
925                 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
926                 if (k != grp[i].cnt) {
927                         RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
928                         return TEST_FAILED;
929                 }
930         }
931         return TEST_SUCCESS;
932 }
933
934 #define PKT_4   4
935 #define PKT_12  12
936 #define PKT_21  21
937
938 static uint32_t
939 crypto_ipsec_4grp(uint32_t pkt_num)
940 {
941         uint32_t sa_ind;
942
943         /* group packets in 4 different size groups groups, 2 per SA */
944         if (pkt_num < PKT_4)
945                 sa_ind = 0;
946         else if (pkt_num < PKT_12)
947                 sa_ind = 1;
948         else if (pkt_num < PKT_21)
949                 sa_ind = 0;
950         else
951                 sa_ind = 1;
952
953         return sa_ind;
954 }
955
956 static uint32_t
957 crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
958 {
959         struct ipsec_unitest_params *ut_params = &unittest_params;
960         uint32_t i, j;
961         uint32_t rc = 0;
962
963         if (grp_ind == 0) {
964                 for (i = 0, j = 0; i < PKT_4; i++, j++)
965                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
966                                 rc = TEST_FAILED;
967                                 break;
968                         }
969         } else if (grp_ind == 1) {
970                 for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
971                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
972                                 rc = TEST_FAILED;
973                                 break;
974                         }
975                 }
976         } else if (grp_ind == 2) {
977                 for (i = 0, j =  PKT_12; i < (PKT_21 - PKT_12); i++, j++)
978                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
979                                 rc = TEST_FAILED;
980                                 break;
981                         }
982         } else if (grp_ind == 3) {
983                 for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
984                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
985                                 rc = TEST_FAILED;
986                                 break;
987                         }
988         } else
989                 rc = TEST_FAILED;
990
991         return rc;
992 }
993
994 static uint32_t
995 crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
996 {
997         uint32_t rc = 0;
998
999         if (grp_ind == 0) {
1000                 if (grp[grp_ind].cnt != PKT_4)
1001                         rc = TEST_FAILED;
1002         } else if (grp_ind == 1) {
1003                 if (grp[grp_ind].cnt != PKT_12 - PKT_4)
1004                         rc = TEST_FAILED;
1005         } else if (grp_ind == 2) {
1006                 if (grp[grp_ind].cnt != PKT_21 - PKT_12)
1007                         rc = TEST_FAILED;
1008         } else if (grp_ind == 3) {
1009                 if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
1010                         rc = TEST_FAILED;
1011         } else
1012                 rc = TEST_FAILED;
1013
1014         return rc;
1015 }
1016
1017 static int
1018 crypto_ipsec_2sa_4grp(void)
1019 {
1020         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1021         struct ipsec_unitest_params *ut_params = &unittest_params;
1022         struct rte_ipsec_group grp[BURST_SIZE];
1023         uint32_t k, ng, i, j;
1024         uint32_t rc = 0;
1025
1026         for (i = 0; i < BURST_SIZE; i++) {
1027                 j = crypto_ipsec_4grp(i);
1028
1029                 /* call crypto prepare */
1030                 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
1031                                 ut_params->ibuf + i, ut_params->cop + i, 1);
1032                 if (k != 1) {
1033                         RTE_LOG(ERR, USER1,
1034                                 "rte_ipsec_pkt_crypto_prepare fail\n");
1035                         return TEST_FAILED;
1036                 }
1037                 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
1038                                 ut_params->cop + i, 1);
1039                 if (k != 1) {
1040                         RTE_LOG(ERR, USER1,
1041                                 "rte_cryptodev_enqueue_burst fail\n");
1042                         return TEST_FAILED;
1043                 }
1044         }
1045
1046         if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
1047                 return TEST_FAILED;
1048
1049         ng = rte_ipsec_pkt_crypto_group(
1050                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
1051                 ut_params->obuf, grp, BURST_SIZE);
1052         if (ng != 4) {
1053                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
1054                         ng);
1055                 return TEST_FAILED;
1056         }
1057
1058         /* call crypto process */
1059         for (i = 0; i < ng; i++) {
1060                 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
1061                 if (k != grp[i].cnt) {
1062                         RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
1063                         return TEST_FAILED;
1064                 }
1065                 rc = crypto_ipsec_4grp_check_cnt(i, grp);
1066                 if (rc != 0) {
1067                         RTE_LOG(ERR, USER1,
1068                                 "crypto_ipsec_4grp_check_cnt fail\n");
1069                         return TEST_FAILED;
1070                 }
1071                 rc = crypto_ipsec_4grp_check_mbufs(i, grp);
1072                 if (rc != 0) {
1073                         RTE_LOG(ERR, USER1,
1074                                 "crypto_ipsec_4grp_check_mbufs fail\n");
1075                         return TEST_FAILED;
1076                 }
1077         }
1078         return TEST_SUCCESS;
1079 }
1080
1081 static void
1082 test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
1083 {
1084         struct ipsec_unitest_params *ut_params = &unittest_params;
1085         struct rte_mbuf *ibuf_tmp[BURST_SIZE];
1086         uint16_t j;
1087
1088         /* reorder packets and create gaps in sequence numbers */
1089         static const uint32_t reorder[BURST_SIZE] = {
1090                         24, 25, 26, 27, 28, 29, 30, 31,
1091                         16, 17, 18, 19, 20, 21, 22, 23,
1092                         8, 9, 10, 11, 12, 13, 14, 15,
1093                         0, 1, 2, 3, 4, 5, 6, 7,
1094         };
1095
1096         if (num_pkts != BURST_SIZE)
1097                 return;
1098
1099         for (j = 0; j != BURST_SIZE; j++)
1100                 ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
1101
1102         memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
1103 }
1104
1105 static int
1106 test_ipsec_crypto_op_alloc(uint16_t num_pkts)
1107 {
1108         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1109         struct ipsec_unitest_params *ut_params = &unittest_params;
1110         int rc = 0;
1111         uint16_t j;
1112
1113         for (j = 0; j < num_pkts && rc == 0; j++) {
1114                 ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
1115                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1116                 if (ut_params->cop[j] == NULL) {
1117                         RTE_LOG(ERR, USER1,
1118                                 "Failed to allocate symmetric crypto op\n");
1119                         rc = TEST_FAILED;
1120                 }
1121         }
1122
1123         return rc;
1124 }
1125
1126 static void
1127 test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
1128 {
1129         uint16_t j = ut_params->pkt_index;
1130
1131         printf("\ntest config: num %d\n", i);
1132         printf("        replay_win_sz %u\n", test_cfg[i].replay_win_sz);
1133         printf("        esn %u\n", test_cfg[i].esn);
1134         printf("        flags 0x%" PRIx64 "\n", test_cfg[i].flags);
1135         printf("        pkt_sz %zu\n", test_cfg[i].pkt_sz);
1136         printf("        num_pkts %u\n\n", test_cfg[i].num_pkts);
1137
1138         if (ut_params->ibuf[j]) {
1139                 printf("ibuf[%u] data:\n", j);
1140                 rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
1141                         ut_params->ibuf[j]->data_len);
1142         }
1143         if (ut_params->obuf[j]) {
1144                 printf("obuf[%u] data:\n", j);
1145                 rte_pktmbuf_dump(stdout, ut_params->obuf[j],
1146                         ut_params->obuf[j]->data_len);
1147         }
1148         if (ut_params->testbuf[j]) {
1149                 printf("testbuf[%u] data:\n", j);
1150                 rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
1151                         ut_params->testbuf[j]->data_len);
1152         }
1153 }
1154
1155 static void
1156 destroy_sa(uint32_t j)
1157 {
1158         struct ipsec_unitest_params *ut = &unittest_params;
1159
1160         rte_ipsec_sa_fini(ut->ss[j].sa);
1161         rte_free(ut->ss[j].sa);
1162         rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses);
1163         memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
1164 }
1165
1166 static int
1167 crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1168                 uint16_t num_pkts)
1169 {
1170         uint16_t j;
1171
1172         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1173                 ut_params->pkt_index = j;
1174
1175                 /* compare the data buffers */
1176                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1177                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1178                         test_cfg[i].pkt_sz,
1179                         "input and output data does not match\n");
1180                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1181                         ut_params->obuf[j]->pkt_len,
1182                         "data_len is not equal to pkt_len");
1183                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1184                         test_cfg[i].pkt_sz,
1185                         "data_len is not equal to input data");
1186         }
1187
1188         return 0;
1189 }
1190
1191 static int
1192 test_ipsec_crypto_inb_burst_null_null(int i)
1193 {
1194         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1195         struct ipsec_unitest_params *ut_params = &unittest_params;
1196         uint16_t num_pkts = test_cfg[i].num_pkts;
1197         uint16_t j;
1198         int rc;
1199
1200         /* create rte_ipsec_sa */
1201         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1202                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1203         if (rc != 0) {
1204                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1205                         i);
1206                 return TEST_FAILED;
1207         }
1208
1209         /* Generate test mbuf data */
1210         for (j = 0; j < num_pkts && rc == 0; j++) {
1211                 /* packet with sequence number 0 is invalid */
1212                 ut_params->ibuf[j] = setup_test_string_tunneled(
1213                         ts_params->mbuf_pool, null_encrypted_data,
1214                         test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1215                 if (ut_params->ibuf[j] == NULL)
1216                         rc = TEST_FAILED;
1217         }
1218
1219         if (rc == 0) {
1220                 if (test_cfg[i].reorder_pkts)
1221                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
1222                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1223         }
1224
1225         if (rc == 0) {
1226                 /* call ipsec library api */
1227                 rc = crypto_ipsec(num_pkts);
1228                 if (rc == 0)
1229                         rc = crypto_inb_burst_null_null_check(
1230                                         ut_params, i, num_pkts);
1231                 else {
1232                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1233                                 i);
1234                         rc = TEST_FAILED;
1235                 }
1236         }
1237
1238         if (rc == TEST_FAILED)
1239                 test_ipsec_dump_buffers(ut_params, i);
1240
1241         destroy_sa(0);
1242         return rc;
1243 }
1244
1245 static int
1246 test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1247 {
1248         int i;
1249         int rc = 0;
1250         struct ipsec_unitest_params *ut_params = &unittest_params;
1251
1252         ut_params->ipsec_xform.spi = INBOUND_SPI;
1253         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1254         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1255         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1256         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1257
1258         for (i = 0; i < num_cfg && rc == 0; i++) {
1259                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1260                 rc = test_ipsec_crypto_inb_burst_null_null(i);
1261         }
1262
1263         return rc;
1264 }
1265
1266 static int
1267 crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1268         uint16_t num_pkts)
1269 {
1270         void *obuf_data;
1271         void *testbuf_data;
1272         uint16_t j;
1273
1274         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1275                 ut_params->pkt_index = j;
1276
1277                 testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1278                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1279                 /* compare the buffer data */
1280                 TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1281                         ut_params->obuf[j]->pkt_len,
1282                         "test and output data does not match\n");
1283                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1284                         ut_params->testbuf[j]->data_len,
1285                         "obuf data_len is not equal to testbuf data_len");
1286                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1287                         ut_params->testbuf[j]->pkt_len,
1288                         "obuf pkt_len is not equal to testbuf pkt_len");
1289         }
1290
1291         return 0;
1292 }
1293
1294 static int
1295 test_ipsec_crypto_outb_burst_null_null(int i)
1296 {
1297         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1298         struct ipsec_unitest_params *ut_params = &unittest_params;
1299         uint16_t num_pkts = test_cfg[i].num_pkts;
1300         uint16_t j;
1301         int32_t rc;
1302
1303         /* create rte_ipsec_sa*/
1304         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1305                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1306         if (rc != 0) {
1307                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1308                         i);
1309                 return TEST_FAILED;
1310         }
1311
1312         /* Generate input mbuf data */
1313         for (j = 0; j < num_pkts && rc == 0; j++) {
1314                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1315                         null_plain_data, test_cfg[i].pkt_sz, 0);
1316                 if (ut_params->ibuf[j] == NULL)
1317                         rc = TEST_FAILED;
1318                 else {
1319                         /* Generate test mbuf data */
1320                         /* packet with sequence number 0 is invalid */
1321                         ut_params->testbuf[j] = setup_test_string_tunneled(
1322                                         ts_params->mbuf_pool,
1323                                         null_plain_data, test_cfg[i].pkt_sz,
1324                                         OUTBOUND_SPI, j + 1);
1325                         if (ut_params->testbuf[j] == NULL)
1326                                 rc = TEST_FAILED;
1327                 }
1328         }
1329
1330         if (rc == 0)
1331                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1332
1333         if (rc == 0) {
1334                 /* call ipsec library api */
1335                 rc = crypto_ipsec(num_pkts);
1336                 if (rc == 0)
1337                         rc = crypto_outb_burst_null_null_check(ut_params,
1338                                         num_pkts);
1339                 else
1340                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1341                                 i);
1342         }
1343
1344         if (rc == TEST_FAILED)
1345                 test_ipsec_dump_buffers(ut_params, i);
1346
1347         destroy_sa(0);
1348         return rc;
1349 }
1350
1351 static int
1352 test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1353 {
1354         int i;
1355         int rc = 0;
1356         struct ipsec_unitest_params *ut_params = &unittest_params;
1357
1358         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1359         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1360         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1361         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1362         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1363
1364         for (i = 0; i < num_cfg && rc == 0; i++) {
1365                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1366                 rc = test_ipsec_crypto_outb_burst_null_null(i);
1367         }
1368
1369         return rc;
1370 }
1371
1372 static int
1373 inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1374         uint16_t num_pkts)
1375 {
1376         void *ibuf_data;
1377         void *obuf_data;
1378         uint16_t j;
1379
1380         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1381                 ut_params->pkt_index = j;
1382
1383                 /* compare the buffer data */
1384                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1385                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1386
1387                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1388                         ut_params->ibuf[j]->data_len,
1389                         "input and output data does not match\n");
1390                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1391                         ut_params->obuf[j]->data_len,
1392                         "ibuf data_len is not equal to obuf data_len");
1393                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1394                         ut_params->obuf[j]->pkt_len,
1395                         "ibuf pkt_len is not equal to obuf pkt_len");
1396                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1397                         test_cfg[i].pkt_sz,
1398                         "data_len is not equal input data");
1399         }
1400         return 0;
1401 }
1402
1403 static int
1404 test_ipsec_inline_crypto_inb_burst_null_null(int i)
1405 {
1406         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1407         struct ipsec_unitest_params *ut_params = &unittest_params;
1408         uint16_t num_pkts = test_cfg[i].num_pkts;
1409         uint16_t j;
1410         int32_t rc;
1411         uint32_t n;
1412
1413         /* create rte_ipsec_sa*/
1414         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1415                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1416         if (rc != 0) {
1417                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1418                         i);
1419                 return TEST_FAILED;
1420         }
1421
1422         /* Generate inbound mbuf data */
1423         for (j = 0; j < num_pkts && rc == 0; j++) {
1424                 ut_params->ibuf[j] = setup_test_string_tunneled(
1425                         ts_params->mbuf_pool,
1426                         null_plain_data, test_cfg[i].pkt_sz,
1427                         INBOUND_SPI, j + 1);
1428                 if (ut_params->ibuf[j] == NULL)
1429                         rc = TEST_FAILED;
1430                 else {
1431                         /* Generate test mbuf data */
1432                         ut_params->obuf[j] = setup_test_string(
1433                                 ts_params->mbuf_pool,
1434                                 null_plain_data, test_cfg[i].pkt_sz, 0);
1435                         if (ut_params->obuf[j] == NULL)
1436                                 rc = TEST_FAILED;
1437                 }
1438         }
1439
1440         if (rc == 0) {
1441                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1442                                 num_pkts);
1443                 if (n == num_pkts)
1444                         rc = inline_inb_burst_null_null_check(ut_params, i,
1445                                         num_pkts);
1446                 else {
1447                         RTE_LOG(ERR, USER1,
1448                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1449                                 i);
1450                         rc = TEST_FAILED;
1451                 }
1452         }
1453
1454         if (rc == TEST_FAILED)
1455                 test_ipsec_dump_buffers(ut_params, i);
1456
1457         destroy_sa(0);
1458         return rc;
1459 }
1460
1461 static int
1462 test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1463 {
1464         int i;
1465         int rc = 0;
1466         struct ipsec_unitest_params *ut_params = &unittest_params;
1467
1468         ut_params->ipsec_xform.spi = INBOUND_SPI;
1469         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1470         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1471         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1472         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1473
1474         for (i = 0; i < num_cfg && rc == 0; i++) {
1475                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1476                 rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1477         }
1478
1479         return rc;
1480 }
1481
1482 static int
1483 test_ipsec_inline_proto_inb_burst_null_null(int i)
1484 {
1485         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1486         struct ipsec_unitest_params *ut_params = &unittest_params;
1487         uint16_t num_pkts = test_cfg[i].num_pkts;
1488         uint16_t j;
1489         int32_t rc;
1490         uint32_t n;
1491
1492         /* create rte_ipsec_sa*/
1493         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1494                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1495         if (rc != 0) {
1496                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1497                         i);
1498                 return TEST_FAILED;
1499         }
1500
1501         /* Generate inbound mbuf data */
1502         for (j = 0; j < num_pkts && rc == 0; j++) {
1503                 ut_params->ibuf[j] = setup_test_string(
1504                         ts_params->mbuf_pool,
1505                         null_plain_data, test_cfg[i].pkt_sz, 0);
1506                 if (ut_params->ibuf[j] == NULL)
1507                         rc = TEST_FAILED;
1508                 else {
1509                         /* Generate test mbuf data */
1510                         ut_params->obuf[j] = setup_test_string(
1511                                 ts_params->mbuf_pool,
1512                                 null_plain_data, test_cfg[i].pkt_sz, 0);
1513                         if (ut_params->obuf[j] == NULL)
1514                                 rc = TEST_FAILED;
1515                 }
1516         }
1517
1518         if (rc == 0) {
1519                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1520                                 num_pkts);
1521                 if (n == num_pkts)
1522                         rc = inline_inb_burst_null_null_check(ut_params, i,
1523                                         num_pkts);
1524                 else {
1525                         RTE_LOG(ERR, USER1,
1526                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1527                                 i);
1528                         rc = TEST_FAILED;
1529                 }
1530         }
1531
1532         if (rc == TEST_FAILED)
1533                 test_ipsec_dump_buffers(ut_params, i);
1534
1535         destroy_sa(0);
1536         return rc;
1537 }
1538
1539 static int
1540 test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1541 {
1542         int i;
1543         int rc = 0;
1544         struct ipsec_unitest_params *ut_params = &unittest_params;
1545
1546         ut_params->ipsec_xform.spi = INBOUND_SPI;
1547         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1548         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1549         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1550         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1551
1552         for (i = 0; i < num_cfg && rc == 0; i++) {
1553                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1554                 rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1555         }
1556
1557         return rc;
1558 }
1559
1560 static int
1561 inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1562         uint16_t num_pkts)
1563 {
1564         void *obuf_data;
1565         void *ibuf_data;
1566         uint16_t j;
1567
1568         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1569                 ut_params->pkt_index = j;
1570
1571                 /* compare the buffer data */
1572                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1573                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1574                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1575                         ut_params->ibuf[j]->data_len,
1576                         "input and output data does not match\n");
1577                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1578                         ut_params->obuf[j]->data_len,
1579                         "ibuf data_len is not equal to obuf data_len");
1580                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1581                         ut_params->obuf[j]->pkt_len,
1582                         "ibuf pkt_len is not equal to obuf pkt_len");
1583
1584                 /* check mbuf ol_flags */
1585                 TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
1586                         "ibuf PKT_TX_SEC_OFFLOAD is not set");
1587         }
1588         return 0;
1589 }
1590
1591 static int
1592 test_ipsec_inline_crypto_outb_burst_null_null(int i)
1593 {
1594         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1595         struct ipsec_unitest_params *ut_params = &unittest_params;
1596         uint16_t num_pkts = test_cfg[i].num_pkts;
1597         uint16_t j;
1598         int32_t rc;
1599         uint32_t n;
1600
1601         /* create rte_ipsec_sa */
1602         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1603                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1604         if (rc != 0) {
1605                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1606                         i);
1607                 return TEST_FAILED;
1608         }
1609
1610         /* Generate test mbuf data */
1611         for (j = 0; j < num_pkts && rc == 0; j++) {
1612                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1613                         null_plain_data, test_cfg[i].pkt_sz, 0);
1614                 if (ut_params->ibuf[0] == NULL)
1615                         rc = TEST_FAILED;
1616
1617                 if (rc == 0) {
1618                         /* Generate test tunneled mbuf data for comparison */
1619                         ut_params->obuf[j] = setup_test_string_tunneled(
1620                                         ts_params->mbuf_pool,
1621                                         null_plain_data, test_cfg[i].pkt_sz,
1622                                         OUTBOUND_SPI, j + 1);
1623                         if (ut_params->obuf[j] == NULL)
1624                                 rc = TEST_FAILED;
1625                 }
1626         }
1627
1628         if (rc == 0) {
1629                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1630                                 num_pkts);
1631                 if (n == num_pkts)
1632                         rc = inline_outb_burst_null_null_check(ut_params,
1633                                         num_pkts);
1634                 else {
1635                         RTE_LOG(ERR, USER1,
1636                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1637                                 i);
1638                         rc = TEST_FAILED;
1639                 }
1640         }
1641
1642         if (rc == TEST_FAILED)
1643                 test_ipsec_dump_buffers(ut_params, i);
1644
1645         destroy_sa(0);
1646         return rc;
1647 }
1648
1649 static int
1650 test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1651 {
1652         int i;
1653         int rc = 0;
1654         struct ipsec_unitest_params *ut_params = &unittest_params;
1655
1656         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1657         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1658         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1659         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1660         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1661
1662         for (i = 0; i < num_cfg && rc == 0; i++) {
1663                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1664                 rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1665         }
1666
1667         return rc;
1668 }
1669
1670 static int
1671 test_ipsec_inline_proto_outb_burst_null_null(int i)
1672 {
1673         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1674         struct ipsec_unitest_params *ut_params = &unittest_params;
1675         uint16_t num_pkts = test_cfg[i].num_pkts;
1676         uint16_t j;
1677         int32_t rc;
1678         uint32_t n;
1679
1680         /* create rte_ipsec_sa */
1681         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1682                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1683         if (rc != 0) {
1684                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1685                         i);
1686                 return TEST_FAILED;
1687         }
1688
1689         /* Generate test mbuf data */
1690         for (j = 0; j < num_pkts && rc == 0; j++) {
1691                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1692                         null_plain_data, test_cfg[i].pkt_sz, 0);
1693                 if (ut_params->ibuf[0] == NULL)
1694                         rc = TEST_FAILED;
1695
1696                 if (rc == 0) {
1697                         /* Generate test tunneled mbuf data for comparison */
1698                         ut_params->obuf[j] = setup_test_string(
1699                                         ts_params->mbuf_pool,
1700                                         null_plain_data, test_cfg[i].pkt_sz, 0);
1701                         if (ut_params->obuf[j] == NULL)
1702                                 rc = TEST_FAILED;
1703                 }
1704         }
1705
1706         if (rc == 0) {
1707                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1708                                 num_pkts);
1709                 if (n == num_pkts)
1710                         rc = inline_outb_burst_null_null_check(ut_params,
1711                                         num_pkts);
1712                 else {
1713                         RTE_LOG(ERR, USER1,
1714                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1715                                 i);
1716                         rc = TEST_FAILED;
1717                 }
1718         }
1719
1720         if (rc == TEST_FAILED)
1721                 test_ipsec_dump_buffers(ut_params, i);
1722
1723         destroy_sa(0);
1724         return rc;
1725 }
1726
1727 static int
1728 test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1729 {
1730         int i;
1731         int rc = 0;
1732         struct ipsec_unitest_params *ut_params = &unittest_params;
1733
1734         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1735         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1736         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1737         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1738         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1739
1740         for (i = 0; i < num_cfg && rc == 0; i++) {
1741                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1742                 rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1743         }
1744
1745         return rc;
1746 }
1747
1748 static int
1749 test_ipsec_lksd_proto_inb_burst_null_null(int i)
1750 {
1751         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1752         struct ipsec_unitest_params *ut_params = &unittest_params;
1753         uint16_t num_pkts = test_cfg[i].num_pkts;
1754         uint16_t j;
1755         int rc;
1756
1757         /* create rte_ipsec_sa */
1758         rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1759                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1760         if (rc != 0) {
1761                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1762                         i);
1763                 return TEST_FAILED;
1764         }
1765
1766         /* Generate test mbuf data */
1767         for (j = 0; j < num_pkts && rc == 0; j++) {
1768                 /* packet with sequence number 0 is invalid */
1769                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1770                         null_encrypted_data, test_cfg[i].pkt_sz, 0);
1771                 if (ut_params->ibuf[j] == NULL)
1772                         rc = TEST_FAILED;
1773         }
1774
1775         if (rc == 0) {
1776                 if (test_cfg[i].reorder_pkts)
1777                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
1778                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1779         }
1780
1781         if (rc == 0) {
1782                 /* call ipsec library api */
1783                 rc = lksd_proto_ipsec(num_pkts);
1784                 if (rc == 0)
1785                         rc = crypto_inb_burst_null_null_check(ut_params, i,
1786                                         num_pkts);
1787                 else {
1788                         RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1789                                 __func__, i);
1790                         rc = TEST_FAILED;
1791                 }
1792         }
1793
1794         if (rc == TEST_FAILED)
1795                 test_ipsec_dump_buffers(ut_params, i);
1796
1797         destroy_sa(0);
1798         return rc;
1799 }
1800
1801 static int
1802 test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1803 {
1804         int i;
1805         int rc = 0;
1806         struct ipsec_unitest_params *ut_params = &unittest_params;
1807
1808         ut_params->ipsec_xform.spi = INBOUND_SPI;
1809         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1810         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1811         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1812         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1813
1814         for (i = 0; i < num_cfg && rc == 0; i++) {
1815                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1816                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1817         }
1818
1819         return rc;
1820 }
1821
1822 static int
1823 test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1824 {
1825         int i;
1826         int rc = 0;
1827         struct ipsec_unitest_params *ut_params = &unittest_params;
1828
1829         ut_params->ipsec_xform.spi = INBOUND_SPI;
1830         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1831         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1832         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1833         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1834
1835         for (i = 0; i < num_cfg && rc == 0; i++) {
1836                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1837                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1838         }
1839
1840         return rc;
1841 }
1842
1843 static int
1844 replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1845         int num_pkts)
1846 {
1847         uint16_t j;
1848
1849         for (j = 0; j < num_pkts; j++) {
1850                 /* compare the buffer data */
1851                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1852                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1853                         test_cfg[i].pkt_sz,
1854                         "input and output data does not match\n");
1855
1856                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1857                         ut_params->obuf[j]->pkt_len,
1858                         "data_len is not equal to pkt_len");
1859         }
1860
1861         return 0;
1862 }
1863
1864 static int
1865 test_ipsec_replay_inb_inside_null_null(int i)
1866 {
1867         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1868         struct ipsec_unitest_params *ut_params = &unittest_params;
1869         int rc;
1870
1871         /* create rte_ipsec_sa*/
1872         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1873                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1874         if (rc != 0) {
1875                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1876                         i);
1877                 return TEST_FAILED;
1878         }
1879
1880         /* Generate inbound mbuf data */
1881         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1882                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1883         if (ut_params->ibuf[0] == NULL)
1884                 rc = TEST_FAILED;
1885         else
1886                 rc = test_ipsec_crypto_op_alloc(1);
1887
1888         if (rc == 0) {
1889                 /* call ipsec library api */
1890                 rc = crypto_ipsec(1);
1891                 if (rc == 0)
1892                         rc = replay_inb_null_null_check(ut_params, i, 1);
1893                 else {
1894                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1895                                         i);
1896                         rc = TEST_FAILED;
1897                 }
1898         }
1899
1900         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1901                 /* generate packet with seq number inside the replay window */
1902                 if (ut_params->ibuf[0]) {
1903                         rte_pktmbuf_free(ut_params->ibuf[0]);
1904                         ut_params->ibuf[0] = 0;
1905                 }
1906
1907                 ut_params->ibuf[0] = setup_test_string_tunneled(
1908                         ts_params->mbuf_pool, null_encrypted_data,
1909                         test_cfg[i].pkt_sz, INBOUND_SPI,
1910                         test_cfg[i].replay_win_sz);
1911                 if (ut_params->ibuf[0] == NULL)
1912                         rc = TEST_FAILED;
1913                 else
1914                         rc = test_ipsec_crypto_op_alloc(1);
1915
1916                 if (rc == 0) {
1917                         /* call ipsec library api */
1918                         rc = crypto_ipsec(1);
1919                         if (rc == 0)
1920                                 rc = replay_inb_null_null_check(
1921                                                 ut_params, i, 1);
1922                         else {
1923                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1924                                 rc = TEST_FAILED;
1925                         }
1926                 }
1927         }
1928
1929         if (rc == TEST_FAILED)
1930                 test_ipsec_dump_buffers(ut_params, i);
1931
1932         destroy_sa(0);
1933
1934         return rc;
1935 }
1936
1937 static int
1938 test_ipsec_replay_inb_inside_null_null_wrapper(void)
1939 {
1940         int i;
1941         int rc = 0;
1942         struct ipsec_unitest_params *ut_params = &unittest_params;
1943
1944         ut_params->ipsec_xform.spi = INBOUND_SPI;
1945         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1946         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1947         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1948         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1949
1950         for (i = 0; i < num_cfg && rc == 0; i++) {
1951                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1952                 rc = test_ipsec_replay_inb_inside_null_null(i);
1953         }
1954
1955         return rc;
1956 }
1957
1958 static int
1959 test_ipsec_replay_inb_outside_null_null(int i)
1960 {
1961         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1962         struct ipsec_unitest_params *ut_params = &unittest_params;
1963         int rc;
1964
1965         /* create rte_ipsec_sa */
1966         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1967                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1968         if (rc != 0) {
1969                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
1970                         i);
1971                 return TEST_FAILED;
1972         }
1973
1974         /* Generate test mbuf data */
1975         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1976                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
1977                 test_cfg[i].replay_win_sz + 2);
1978         if (ut_params->ibuf[0] == NULL)
1979                 rc = TEST_FAILED;
1980         else
1981                 rc = test_ipsec_crypto_op_alloc(1);
1982
1983         if (rc == 0) {
1984                 /* call ipsec library api */
1985                 rc = crypto_ipsec(1);
1986                 if (rc == 0)
1987                         rc = replay_inb_null_null_check(ut_params, i, 1);
1988                 else {
1989                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1990                                         i);
1991                         rc = TEST_FAILED;
1992                 }
1993         }
1994
1995         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1996                 /* generate packet with seq number outside the replay window */
1997                 if (ut_params->ibuf[0]) {
1998                         rte_pktmbuf_free(ut_params->ibuf[0]);
1999                         ut_params->ibuf[0] = 0;
2000                 }
2001                 ut_params->ibuf[0] = setup_test_string_tunneled(
2002                         ts_params->mbuf_pool, null_encrypted_data,
2003                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2004                 if (ut_params->ibuf[0] == NULL)
2005                         rc = TEST_FAILED;
2006                 else
2007                         rc = test_ipsec_crypto_op_alloc(1);
2008
2009                 if (rc == 0) {
2010                         /* call ipsec library api */
2011                         rc = crypto_ipsec(1);
2012                         if (rc == 0) {
2013                                 if (test_cfg[i].esn == 0) {
2014                                         RTE_LOG(ERR, USER1,
2015                                                 "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2016                                                 i,
2017                                                 test_cfg[i].replay_win_sz + 2,
2018                                                 1);
2019                                         rc = TEST_FAILED;
2020                                 }
2021                         } else {
2022                                 RTE_LOG(ERR, USER1,
2023                                         "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2024                                         i, test_cfg[i].replay_win_sz + 2, 1);
2025                                 rc = 0;
2026                         }
2027                 }
2028         }
2029
2030         if (rc == TEST_FAILED)
2031                 test_ipsec_dump_buffers(ut_params, i);
2032
2033         destroy_sa(0);
2034
2035         return rc;
2036 }
2037
2038 static int
2039 test_ipsec_replay_inb_outside_null_null_wrapper(void)
2040 {
2041         int i;
2042         int rc = 0;
2043         struct ipsec_unitest_params *ut_params = &unittest_params;
2044
2045         ut_params->ipsec_xform.spi = INBOUND_SPI;
2046         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2047         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2048         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2049         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2050
2051         for (i = 0; i < num_cfg && rc == 0; i++) {
2052                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2053                 rc = test_ipsec_replay_inb_outside_null_null(i);
2054         }
2055
2056         return rc;
2057 }
2058
2059 static int
2060 test_ipsec_replay_inb_repeat_null_null(int i)
2061 {
2062         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2063         struct ipsec_unitest_params *ut_params = &unittest_params;
2064         int rc;
2065
2066         /* create rte_ipsec_sa */
2067         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2068                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2069         if (rc != 0) {
2070                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n", i);
2071                 return TEST_FAILED;
2072         }
2073
2074         /* Generate test mbuf data */
2075         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2076                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2077         if (ut_params->ibuf[0] == NULL)
2078                 rc = TEST_FAILED;
2079         else
2080                 rc = test_ipsec_crypto_op_alloc(1);
2081
2082         if (rc == 0) {
2083                 /* call ipsec library api */
2084                 rc = crypto_ipsec(1);
2085                 if (rc == 0)
2086                         rc = replay_inb_null_null_check(ut_params, i, 1);
2087                 else {
2088                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2089                                         i);
2090                         rc = TEST_FAILED;
2091                 }
2092         }
2093
2094         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2095                 /*
2096                  * generate packet with repeat seq number in the replay
2097                  * window
2098                  */
2099                 if (ut_params->ibuf[0]) {
2100                         rte_pktmbuf_free(ut_params->ibuf[0]);
2101                         ut_params->ibuf[0] = 0;
2102                 }
2103
2104                 ut_params->ibuf[0] = setup_test_string_tunneled(
2105                         ts_params->mbuf_pool, null_encrypted_data,
2106                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2107                 if (ut_params->ibuf[0] == NULL)
2108                         rc = TEST_FAILED;
2109                 else
2110                         rc = test_ipsec_crypto_op_alloc(1);
2111
2112                 if (rc == 0) {
2113                         /* call ipsec library api */
2114                         rc = crypto_ipsec(1);
2115                         if (rc == 0) {
2116                                 RTE_LOG(ERR, USER1,
2117                                         "packet is not repeated in the replay window, cfg %d seq %u\n",
2118                                         i, 1);
2119                                 rc = TEST_FAILED;
2120                         } else {
2121                                 RTE_LOG(ERR, USER1,
2122                                         "packet is repeated in the replay window, cfg %d seq %u\n",
2123                                         i, 1);
2124                                 rc = 0;
2125                         }
2126                 }
2127         }
2128
2129         if (rc == TEST_FAILED)
2130                 test_ipsec_dump_buffers(ut_params, i);
2131
2132         destroy_sa(0);
2133
2134         return rc;
2135 }
2136
2137 static int
2138 test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2139 {
2140         int i;
2141         int rc = 0;
2142         struct ipsec_unitest_params *ut_params = &unittest_params;
2143
2144         ut_params->ipsec_xform.spi = INBOUND_SPI;
2145         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2146         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2147         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2148         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2149
2150         for (i = 0; i < num_cfg && rc == 0; i++) {
2151                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2152                 rc = test_ipsec_replay_inb_repeat_null_null(i);
2153         }
2154
2155         return rc;
2156 }
2157
2158 static int
2159 test_ipsec_replay_inb_inside_burst_null_null(int i)
2160 {
2161         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2162         struct ipsec_unitest_params *ut_params = &unittest_params;
2163         uint16_t num_pkts = test_cfg[i].num_pkts;
2164         int rc;
2165         int j;
2166
2167         /* create rte_ipsec_sa*/
2168         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2169                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2170         if (rc != 0) {
2171                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2172                         i);
2173                 return TEST_FAILED;
2174         }
2175
2176         /* Generate inbound mbuf data */
2177         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2178                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2179         if (ut_params->ibuf[0] == NULL)
2180                 rc = TEST_FAILED;
2181         else
2182                 rc = test_ipsec_crypto_op_alloc(1);
2183
2184         if (rc == 0) {
2185                 /* call ipsec library api */
2186                 rc = crypto_ipsec(1);
2187                 if (rc == 0)
2188                         rc = replay_inb_null_null_check(ut_params, i, 1);
2189                 else {
2190                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2191                                         i);
2192                         rc = TEST_FAILED;
2193                 }
2194         }
2195
2196         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2197                 /*
2198                  *  generate packet(s) with seq number(s) inside the
2199                  *  replay window
2200                  */
2201                 if (ut_params->ibuf[0]) {
2202                         rte_pktmbuf_free(ut_params->ibuf[0]);
2203                         ut_params->ibuf[0] = 0;
2204                 }
2205
2206                 for (j = 0; j < num_pkts && rc == 0; j++) {
2207                         /* packet with sequence number 1 already processed */
2208                         ut_params->ibuf[j] = setup_test_string_tunneled(
2209                                 ts_params->mbuf_pool, null_encrypted_data,
2210                                 test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2211                         if (ut_params->ibuf[j] == NULL)
2212                                 rc = TEST_FAILED;
2213                 }
2214
2215                 if (rc == 0) {
2216                         if (test_cfg[i].reorder_pkts)
2217                                 test_ipsec_reorder_inb_pkt_burst(num_pkts);
2218                         rc = test_ipsec_crypto_op_alloc(num_pkts);
2219                 }
2220
2221                 if (rc == 0) {
2222                         /* call ipsec library api */
2223                         rc = crypto_ipsec(num_pkts);
2224                         if (rc == 0)
2225                                 rc = replay_inb_null_null_check(
2226                                                 ut_params, i, num_pkts);
2227                         else {
2228                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2229                                 rc = TEST_FAILED;
2230                         }
2231                 }
2232         }
2233
2234         if (rc == TEST_FAILED)
2235                 test_ipsec_dump_buffers(ut_params, i);
2236
2237         destroy_sa(0);
2238
2239         return rc;
2240 }
2241
2242 static int
2243 test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2244 {
2245         int i;
2246         int rc = 0;
2247         struct ipsec_unitest_params *ut_params = &unittest_params;
2248
2249         ut_params->ipsec_xform.spi = INBOUND_SPI;
2250         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2251         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2252         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2253         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2254
2255         for (i = 0; i < num_cfg && rc == 0; i++) {
2256                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2257                 rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2258         }
2259
2260         return rc;
2261 }
2262
2263
2264 static int
2265 crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2266                 int i)
2267 {
2268         uint16_t j;
2269
2270         for (j = 0; j < BURST_SIZE; j++) {
2271                 ut_params->pkt_index = j;
2272
2273                 /* compare the data buffers */
2274                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2275                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2276                         test_cfg[i].pkt_sz,
2277                         "input and output data does not match\n");
2278                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2279                         ut_params->obuf[j]->pkt_len,
2280                         "data_len is not equal to pkt_len");
2281                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2282                         test_cfg[i].pkt_sz,
2283                         "data_len is not equal to input data");
2284         }
2285
2286         return 0;
2287 }
2288
2289 static int
2290 test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2291 {
2292         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2293         struct ipsec_unitest_params *ut_params = &unittest_params;
2294         uint16_t num_pkts = test_cfg[i].num_pkts;
2295         uint16_t j, r;
2296         int rc = 0;
2297
2298         if (num_pkts != BURST_SIZE)
2299                 return rc;
2300
2301         /* create rte_ipsec_sa */
2302         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2303                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2304         if (rc != 0) {
2305                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2306                         i);
2307                 return TEST_FAILED;
2308         }
2309
2310         /* create second rte_ipsec_sa */
2311         ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2312         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2313                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2314         if (rc != 0) {
2315                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2316                         i);
2317                 destroy_sa(0);
2318                 return TEST_FAILED;
2319         }
2320
2321         /* Generate test mbuf data */
2322         for (j = 0; j < num_pkts && rc == 0; j++) {
2323                 r = j % 2;
2324                 /* packet with sequence number 0 is invalid */
2325                 ut_params->ibuf[j] = setup_test_string_tunneled(
2326                         ts_params->mbuf_pool, null_encrypted_data,
2327                         test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2328                 if (ut_params->ibuf[j] == NULL)
2329                         rc = TEST_FAILED;
2330         }
2331
2332         if (rc == 0)
2333                 rc = test_ipsec_crypto_op_alloc(num_pkts);
2334
2335         if (rc == 0) {
2336                 /* call ipsec library api */
2337                 rc = crypto_ipsec_2sa();
2338                 if (rc == 0)
2339                         rc = crypto_inb_burst_2sa_null_null_check(
2340                                         ut_params, i);
2341                 else {
2342                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2343                                 i);
2344                         rc = TEST_FAILED;
2345                 }
2346         }
2347
2348         if (rc == TEST_FAILED)
2349                 test_ipsec_dump_buffers(ut_params, i);
2350
2351         destroy_sa(0);
2352         destroy_sa(1);
2353         return rc;
2354 }
2355
2356 static int
2357 test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2358 {
2359         int i;
2360         int rc = 0;
2361         struct ipsec_unitest_params *ut_params = &unittest_params;
2362
2363         ut_params->ipsec_xform.spi = INBOUND_SPI;
2364         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2365         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2366         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2367         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2368
2369         for (i = 0; i < num_cfg && rc == 0; i++) {
2370                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2371                 rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2372         }
2373
2374         return rc;
2375 }
2376
2377 static int
2378 test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2379 {
2380         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2381         struct ipsec_unitest_params *ut_params = &unittest_params;
2382         uint16_t num_pkts = test_cfg[i].num_pkts;
2383         uint16_t j, k;
2384         int rc = 0;
2385
2386         if (num_pkts != BURST_SIZE)
2387                 return rc;
2388
2389         /* create rte_ipsec_sa */
2390         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2391                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2392         if (rc != 0) {
2393                 RTE_LOG(ERR, USER1, "rte_ipsec_sa_init failed, cfg %d\n",
2394                         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, "rte_ipsec_sa_init failed, cfg %d\n",
2404                         i);
2405                 destroy_sa(0);
2406                 return TEST_FAILED;
2407         }
2408
2409         /* Generate test mbuf data */
2410         for (j = 0; j < num_pkts && rc == 0; j++) {
2411                 k = crypto_ipsec_4grp(j);
2412
2413                 /* packet with sequence number 0 is invalid */
2414                 ut_params->ibuf[j] = setup_test_string_tunneled(
2415                         ts_params->mbuf_pool, null_encrypted_data,
2416                         test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
2417                 if (ut_params->ibuf[j] == NULL)
2418                         rc = TEST_FAILED;
2419         }
2420
2421         if (rc == 0)
2422                 rc = test_ipsec_crypto_op_alloc(num_pkts);
2423
2424         if (rc == 0) {
2425                 /* call ipsec library api */
2426                 rc = crypto_ipsec_2sa_4grp();
2427                 if (rc == 0)
2428                         rc = crypto_inb_burst_2sa_null_null_check(
2429                                         ut_params, i);
2430                 else {
2431                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2432                                 i);
2433                         rc = TEST_FAILED;
2434                 }
2435         }
2436
2437         if (rc == TEST_FAILED)
2438                 test_ipsec_dump_buffers(ut_params, i);
2439
2440         destroy_sa(0);
2441         destroy_sa(1);
2442         return rc;
2443 }
2444
2445 static int
2446 test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
2447 {
2448         int i;
2449         int rc = 0;
2450         struct ipsec_unitest_params *ut_params = &unittest_params;
2451
2452         ut_params->ipsec_xform.spi = INBOUND_SPI;
2453         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2454         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2455         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2456         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2457
2458         for (i = 0; i < num_cfg && rc == 0; i++) {
2459                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2460                 rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
2461         }
2462
2463         return rc;
2464 }
2465
2466 static struct unit_test_suite ipsec_testsuite  = {
2467         .suite_name = "IPsec NULL Unit Test Suite",
2468         .setup = testsuite_setup,
2469         .teardown = testsuite_teardown,
2470         .unit_test_cases = {
2471                 TEST_CASE_ST(ut_setup, ut_teardown,
2472                         test_ipsec_crypto_inb_burst_null_null_wrapper),
2473                 TEST_CASE_ST(ut_setup, ut_teardown,
2474                         test_ipsec_crypto_outb_burst_null_null_wrapper),
2475                 TEST_CASE_ST(ut_setup, ut_teardown,
2476                         test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
2477                 TEST_CASE_ST(ut_setup, ut_teardown,
2478                         test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
2479                 TEST_CASE_ST(ut_setup, ut_teardown,
2480                         test_ipsec_inline_proto_inb_burst_null_null_wrapper),
2481                 TEST_CASE_ST(ut_setup, ut_teardown,
2482                         test_ipsec_inline_proto_outb_burst_null_null_wrapper),
2483                 TEST_CASE_ST(ut_setup, ut_teardown,
2484                         test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
2485                 TEST_CASE_ST(ut_setup, ut_teardown,
2486                         test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
2487                 TEST_CASE_ST(ut_setup, ut_teardown,
2488                         test_ipsec_replay_inb_inside_null_null_wrapper),
2489                 TEST_CASE_ST(ut_setup, ut_teardown,
2490                         test_ipsec_replay_inb_outside_null_null_wrapper),
2491                 TEST_CASE_ST(ut_setup, ut_teardown,
2492                         test_ipsec_replay_inb_repeat_null_null_wrapper),
2493                 TEST_CASE_ST(ut_setup, ut_teardown,
2494                         test_ipsec_replay_inb_inside_burst_null_null_wrapper),
2495                 TEST_CASE_ST(ut_setup, ut_teardown,
2496                         test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
2497                 TEST_CASE_ST(ut_setup, ut_teardown,
2498                         test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
2499                 TEST_CASES_END() /**< NULL terminate unit test array */
2500         }
2501 };
2502
2503 static int
2504 test_ipsec(void)
2505 {
2506         return unit_test_suite_runner(&ipsec_testsuite);
2507 }
2508
2509 REGISTER_TEST_COMMAND(ipsec_autotest, test_ipsec);