test/ipsec: fix log messages
[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, "create_sa failed, cfg %d\n", i);
1205                 return TEST_FAILED;
1206         }
1207
1208         /* Generate test mbuf data */
1209         for (j = 0; j < num_pkts && rc == 0; j++) {
1210                 /* packet with sequence number 0 is invalid */
1211                 ut_params->ibuf[j] = setup_test_string_tunneled(
1212                         ts_params->mbuf_pool, null_encrypted_data,
1213                         test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1214                 if (ut_params->ibuf[j] == NULL)
1215                         rc = TEST_FAILED;
1216         }
1217
1218         if (rc == 0) {
1219                 if (test_cfg[i].reorder_pkts)
1220                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
1221                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1222         }
1223
1224         if (rc == 0) {
1225                 /* call ipsec library api */
1226                 rc = crypto_ipsec(num_pkts);
1227                 if (rc == 0)
1228                         rc = crypto_inb_burst_null_null_check(
1229                                         ut_params, i, num_pkts);
1230                 else {
1231                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1232                                 i);
1233                         rc = TEST_FAILED;
1234                 }
1235         }
1236
1237         if (rc == TEST_FAILED)
1238                 test_ipsec_dump_buffers(ut_params, i);
1239
1240         destroy_sa(0);
1241         return rc;
1242 }
1243
1244 static int
1245 test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1246 {
1247         int i;
1248         int rc = 0;
1249         struct ipsec_unitest_params *ut_params = &unittest_params;
1250
1251         ut_params->ipsec_xform.spi = INBOUND_SPI;
1252         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1253         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1254         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1255         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1256
1257         for (i = 0; i < num_cfg && rc == 0; i++) {
1258                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1259                 rc = test_ipsec_crypto_inb_burst_null_null(i);
1260         }
1261
1262         return rc;
1263 }
1264
1265 static int
1266 crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1267         uint16_t num_pkts)
1268 {
1269         void *obuf_data;
1270         void *testbuf_data;
1271         uint16_t j;
1272
1273         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1274                 ut_params->pkt_index = j;
1275
1276                 testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1277                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1278                 /* compare the buffer data */
1279                 TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1280                         ut_params->obuf[j]->pkt_len,
1281                         "test and output data does not match\n");
1282                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1283                         ut_params->testbuf[j]->data_len,
1284                         "obuf data_len is not equal to testbuf data_len");
1285                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1286                         ut_params->testbuf[j]->pkt_len,
1287                         "obuf pkt_len is not equal to testbuf pkt_len");
1288         }
1289
1290         return 0;
1291 }
1292
1293 static int
1294 test_ipsec_crypto_outb_burst_null_null(int i)
1295 {
1296         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1297         struct ipsec_unitest_params *ut_params = &unittest_params;
1298         uint16_t num_pkts = test_cfg[i].num_pkts;
1299         uint16_t j;
1300         int32_t rc;
1301
1302         /* create rte_ipsec_sa*/
1303         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1304                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1305         if (rc != 0) {
1306                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1307                 return TEST_FAILED;
1308         }
1309
1310         /* Generate input mbuf data */
1311         for (j = 0; j < num_pkts && rc == 0; j++) {
1312                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1313                         null_plain_data, test_cfg[i].pkt_sz, 0);
1314                 if (ut_params->ibuf[j] == NULL)
1315                         rc = TEST_FAILED;
1316                 else {
1317                         /* Generate test mbuf data */
1318                         /* packet with sequence number 0 is invalid */
1319                         ut_params->testbuf[j] = setup_test_string_tunneled(
1320                                         ts_params->mbuf_pool,
1321                                         null_plain_data, test_cfg[i].pkt_sz,
1322                                         OUTBOUND_SPI, j + 1);
1323                         if (ut_params->testbuf[j] == NULL)
1324                                 rc = TEST_FAILED;
1325                 }
1326         }
1327
1328         if (rc == 0)
1329                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1330
1331         if (rc == 0) {
1332                 /* call ipsec library api */
1333                 rc = crypto_ipsec(num_pkts);
1334                 if (rc == 0)
1335                         rc = crypto_outb_burst_null_null_check(ut_params,
1336                                         num_pkts);
1337                 else
1338                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1339                                 i);
1340         }
1341
1342         if (rc == TEST_FAILED)
1343                 test_ipsec_dump_buffers(ut_params, i);
1344
1345         destroy_sa(0);
1346         return rc;
1347 }
1348
1349 static int
1350 test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1351 {
1352         int i;
1353         int rc = 0;
1354         struct ipsec_unitest_params *ut_params = &unittest_params;
1355
1356         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1357         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1358         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1359         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1360         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1361
1362         for (i = 0; i < num_cfg && rc == 0; i++) {
1363                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1364                 rc = test_ipsec_crypto_outb_burst_null_null(i);
1365         }
1366
1367         return rc;
1368 }
1369
1370 static int
1371 inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1372         uint16_t num_pkts)
1373 {
1374         void *ibuf_data;
1375         void *obuf_data;
1376         uint16_t j;
1377
1378         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1379                 ut_params->pkt_index = j;
1380
1381                 /* compare the buffer data */
1382                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1383                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1384
1385                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1386                         ut_params->ibuf[j]->data_len,
1387                         "input and output data does not match\n");
1388                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1389                         ut_params->obuf[j]->data_len,
1390                         "ibuf data_len is not equal to obuf data_len");
1391                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1392                         ut_params->obuf[j]->pkt_len,
1393                         "ibuf pkt_len is not equal to obuf pkt_len");
1394                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1395                         test_cfg[i].pkt_sz,
1396                         "data_len is not equal input data");
1397         }
1398         return 0;
1399 }
1400
1401 static int
1402 test_ipsec_inline_crypto_inb_burst_null_null(int i)
1403 {
1404         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1405         struct ipsec_unitest_params *ut_params = &unittest_params;
1406         uint16_t num_pkts = test_cfg[i].num_pkts;
1407         uint16_t j;
1408         int32_t rc;
1409         uint32_t n;
1410
1411         /* create rte_ipsec_sa*/
1412         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1413                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1414         if (rc != 0) {
1415                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1416                 return TEST_FAILED;
1417         }
1418
1419         /* Generate inbound mbuf data */
1420         for (j = 0; j < num_pkts && rc == 0; j++) {
1421                 ut_params->ibuf[j] = setup_test_string_tunneled(
1422                         ts_params->mbuf_pool,
1423                         null_plain_data, test_cfg[i].pkt_sz,
1424                         INBOUND_SPI, j + 1);
1425                 if (ut_params->ibuf[j] == NULL)
1426                         rc = TEST_FAILED;
1427                 else {
1428                         /* Generate test mbuf data */
1429                         ut_params->obuf[j] = setup_test_string(
1430                                 ts_params->mbuf_pool,
1431                                 null_plain_data, test_cfg[i].pkt_sz, 0);
1432                         if (ut_params->obuf[j] == NULL)
1433                                 rc = TEST_FAILED;
1434                 }
1435         }
1436
1437         if (rc == 0) {
1438                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1439                                 num_pkts);
1440                 if (n == num_pkts)
1441                         rc = inline_inb_burst_null_null_check(ut_params, i,
1442                                         num_pkts);
1443                 else {
1444                         RTE_LOG(ERR, USER1,
1445                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1446                                 i);
1447                         rc = TEST_FAILED;
1448                 }
1449         }
1450
1451         if (rc == TEST_FAILED)
1452                 test_ipsec_dump_buffers(ut_params, i);
1453
1454         destroy_sa(0);
1455         return rc;
1456 }
1457
1458 static int
1459 test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1460 {
1461         int i;
1462         int rc = 0;
1463         struct ipsec_unitest_params *ut_params = &unittest_params;
1464
1465         ut_params->ipsec_xform.spi = INBOUND_SPI;
1466         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1467         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1468         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1469         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1470
1471         for (i = 0; i < num_cfg && rc == 0; i++) {
1472                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1473                 rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1474         }
1475
1476         return rc;
1477 }
1478
1479 static int
1480 test_ipsec_inline_proto_inb_burst_null_null(int i)
1481 {
1482         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1483         struct ipsec_unitest_params *ut_params = &unittest_params;
1484         uint16_t num_pkts = test_cfg[i].num_pkts;
1485         uint16_t j;
1486         int32_t rc;
1487         uint32_t n;
1488
1489         /* create rte_ipsec_sa*/
1490         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1491                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1492         if (rc != 0) {
1493                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1494                 return TEST_FAILED;
1495         }
1496
1497         /* Generate inbound mbuf data */
1498         for (j = 0; j < num_pkts && rc == 0; j++) {
1499                 ut_params->ibuf[j] = setup_test_string(
1500                         ts_params->mbuf_pool,
1501                         null_plain_data, test_cfg[i].pkt_sz, 0);
1502                 if (ut_params->ibuf[j] == NULL)
1503                         rc = TEST_FAILED;
1504                 else {
1505                         /* Generate test mbuf data */
1506                         ut_params->obuf[j] = setup_test_string(
1507                                 ts_params->mbuf_pool,
1508                                 null_plain_data, test_cfg[i].pkt_sz, 0);
1509                         if (ut_params->obuf[j] == NULL)
1510                                 rc = TEST_FAILED;
1511                 }
1512         }
1513
1514         if (rc == 0) {
1515                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1516                                 num_pkts);
1517                 if (n == num_pkts)
1518                         rc = inline_inb_burst_null_null_check(ut_params, i,
1519                                         num_pkts);
1520                 else {
1521                         RTE_LOG(ERR, USER1,
1522                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1523                                 i);
1524                         rc = TEST_FAILED;
1525                 }
1526         }
1527
1528         if (rc == TEST_FAILED)
1529                 test_ipsec_dump_buffers(ut_params, i);
1530
1531         destroy_sa(0);
1532         return rc;
1533 }
1534
1535 static int
1536 test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1537 {
1538         int i;
1539         int rc = 0;
1540         struct ipsec_unitest_params *ut_params = &unittest_params;
1541
1542         ut_params->ipsec_xform.spi = INBOUND_SPI;
1543         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1544         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1545         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1546         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1547
1548         for (i = 0; i < num_cfg && rc == 0; i++) {
1549                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1550                 rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1551         }
1552
1553         return rc;
1554 }
1555
1556 static int
1557 inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1558         uint16_t num_pkts)
1559 {
1560         void *obuf_data;
1561         void *ibuf_data;
1562         uint16_t j;
1563
1564         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1565                 ut_params->pkt_index = j;
1566
1567                 /* compare the buffer data */
1568                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1569                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1570                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1571                         ut_params->ibuf[j]->data_len,
1572                         "input and output data does not match\n");
1573                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1574                         ut_params->obuf[j]->data_len,
1575                         "ibuf data_len is not equal to obuf data_len");
1576                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1577                         ut_params->obuf[j]->pkt_len,
1578                         "ibuf pkt_len is not equal to obuf pkt_len");
1579
1580                 /* check mbuf ol_flags */
1581                 TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
1582                         "ibuf PKT_TX_SEC_OFFLOAD is not set");
1583         }
1584         return 0;
1585 }
1586
1587 static int
1588 test_ipsec_inline_crypto_outb_burst_null_null(int i)
1589 {
1590         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1591         struct ipsec_unitest_params *ut_params = &unittest_params;
1592         uint16_t num_pkts = test_cfg[i].num_pkts;
1593         uint16_t j;
1594         int32_t rc;
1595         uint32_t n;
1596
1597         /* create rte_ipsec_sa */
1598         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1599                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1600         if (rc != 0) {
1601                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1602                 return TEST_FAILED;
1603         }
1604
1605         /* Generate test mbuf data */
1606         for (j = 0; j < num_pkts && rc == 0; j++) {
1607                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1608                         null_plain_data, test_cfg[i].pkt_sz, 0);
1609                 if (ut_params->ibuf[0] == NULL)
1610                         rc = TEST_FAILED;
1611
1612                 if (rc == 0) {
1613                         /* Generate test tunneled mbuf data for comparison */
1614                         ut_params->obuf[j] = setup_test_string_tunneled(
1615                                         ts_params->mbuf_pool,
1616                                         null_plain_data, test_cfg[i].pkt_sz,
1617                                         OUTBOUND_SPI, j + 1);
1618                         if (ut_params->obuf[j] == NULL)
1619                                 rc = TEST_FAILED;
1620                 }
1621         }
1622
1623         if (rc == 0) {
1624                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1625                                 num_pkts);
1626                 if (n == num_pkts)
1627                         rc = inline_outb_burst_null_null_check(ut_params,
1628                                         num_pkts);
1629                 else {
1630                         RTE_LOG(ERR, USER1,
1631                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1632                                 i);
1633                         rc = TEST_FAILED;
1634                 }
1635         }
1636
1637         if (rc == TEST_FAILED)
1638                 test_ipsec_dump_buffers(ut_params, i);
1639
1640         destroy_sa(0);
1641         return rc;
1642 }
1643
1644 static int
1645 test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1646 {
1647         int i;
1648         int rc = 0;
1649         struct ipsec_unitest_params *ut_params = &unittest_params;
1650
1651         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1652         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1653         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1654         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1655         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1656
1657         for (i = 0; i < num_cfg && rc == 0; i++) {
1658                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1659                 rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1660         }
1661
1662         return rc;
1663 }
1664
1665 static int
1666 test_ipsec_inline_proto_outb_burst_null_null(int i)
1667 {
1668         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1669         struct ipsec_unitest_params *ut_params = &unittest_params;
1670         uint16_t num_pkts = test_cfg[i].num_pkts;
1671         uint16_t j;
1672         int32_t rc;
1673         uint32_t n;
1674
1675         /* create rte_ipsec_sa */
1676         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1677                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1678         if (rc != 0) {
1679                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1680                 return TEST_FAILED;
1681         }
1682
1683         /* Generate test mbuf data */
1684         for (j = 0; j < num_pkts && rc == 0; j++) {
1685                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1686                         null_plain_data, test_cfg[i].pkt_sz, 0);
1687                 if (ut_params->ibuf[0] == NULL)
1688                         rc = TEST_FAILED;
1689
1690                 if (rc == 0) {
1691                         /* Generate test tunneled mbuf data for comparison */
1692                         ut_params->obuf[j] = setup_test_string(
1693                                         ts_params->mbuf_pool,
1694                                         null_plain_data, test_cfg[i].pkt_sz, 0);
1695                         if (ut_params->obuf[j] == NULL)
1696                                 rc = TEST_FAILED;
1697                 }
1698         }
1699
1700         if (rc == 0) {
1701                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1702                                 num_pkts);
1703                 if (n == num_pkts)
1704                         rc = inline_outb_burst_null_null_check(ut_params,
1705                                         num_pkts);
1706                 else {
1707                         RTE_LOG(ERR, USER1,
1708                                 "rte_ipsec_pkt_process failed, cfg %d\n",
1709                                 i);
1710                         rc = TEST_FAILED;
1711                 }
1712         }
1713
1714         if (rc == TEST_FAILED)
1715                 test_ipsec_dump_buffers(ut_params, i);
1716
1717         destroy_sa(0);
1718         return rc;
1719 }
1720
1721 static int
1722 test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1723 {
1724         int i;
1725         int rc = 0;
1726         struct ipsec_unitest_params *ut_params = &unittest_params;
1727
1728         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1729         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1730         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1731         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1732         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1733
1734         for (i = 0; i < num_cfg && rc == 0; i++) {
1735                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1736                 rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1737         }
1738
1739         return rc;
1740 }
1741
1742 static int
1743 test_ipsec_lksd_proto_inb_burst_null_null(int i)
1744 {
1745         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1746         struct ipsec_unitest_params *ut_params = &unittest_params;
1747         uint16_t num_pkts = test_cfg[i].num_pkts;
1748         uint16_t j;
1749         int rc;
1750
1751         /* create rte_ipsec_sa */
1752         rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1753                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1754         if (rc != 0) {
1755                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1756                 return TEST_FAILED;
1757         }
1758
1759         /* Generate test mbuf data */
1760         for (j = 0; j < num_pkts && rc == 0; j++) {
1761                 /* packet with sequence number 0 is invalid */
1762                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1763                         null_encrypted_data, test_cfg[i].pkt_sz, 0);
1764                 if (ut_params->ibuf[j] == NULL)
1765                         rc = TEST_FAILED;
1766         }
1767
1768         if (rc == 0) {
1769                 if (test_cfg[i].reorder_pkts)
1770                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
1771                 rc = test_ipsec_crypto_op_alloc(num_pkts);
1772         }
1773
1774         if (rc == 0) {
1775                 /* call ipsec library api */
1776                 rc = lksd_proto_ipsec(num_pkts);
1777                 if (rc == 0)
1778                         rc = crypto_inb_burst_null_null_check(ut_params, i,
1779                                         num_pkts);
1780                 else {
1781                         RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1782                                 __func__, i);
1783                         rc = TEST_FAILED;
1784                 }
1785         }
1786
1787         if (rc == TEST_FAILED)
1788                 test_ipsec_dump_buffers(ut_params, i);
1789
1790         destroy_sa(0);
1791         return rc;
1792 }
1793
1794 static int
1795 test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1796 {
1797         int i;
1798         int rc = 0;
1799         struct ipsec_unitest_params *ut_params = &unittest_params;
1800
1801         ut_params->ipsec_xform.spi = INBOUND_SPI;
1802         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1803         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1804         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1805         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1806
1807         for (i = 0; i < num_cfg && rc == 0; i++) {
1808                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1809                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1810         }
1811
1812         return rc;
1813 }
1814
1815 static int
1816 test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1817 {
1818         int i;
1819         int rc = 0;
1820         struct ipsec_unitest_params *ut_params = &unittest_params;
1821
1822         ut_params->ipsec_xform.spi = INBOUND_SPI;
1823         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1824         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1825         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1826         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1827
1828         for (i = 0; i < num_cfg && rc == 0; i++) {
1829                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1830                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1831         }
1832
1833         return rc;
1834 }
1835
1836 static int
1837 replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1838         int num_pkts)
1839 {
1840         uint16_t j;
1841
1842         for (j = 0; j < num_pkts; j++) {
1843                 /* compare the buffer data */
1844                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1845                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1846                         test_cfg[i].pkt_sz,
1847                         "input and output data does not match\n");
1848
1849                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1850                         ut_params->obuf[j]->pkt_len,
1851                         "data_len is not equal to pkt_len");
1852         }
1853
1854         return 0;
1855 }
1856
1857 static int
1858 test_ipsec_replay_inb_inside_null_null(int i)
1859 {
1860         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1861         struct ipsec_unitest_params *ut_params = &unittest_params;
1862         int rc;
1863
1864         /* create rte_ipsec_sa*/
1865         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1866                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1867         if (rc != 0) {
1868                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1869                 return TEST_FAILED;
1870         }
1871
1872         /* Generate inbound mbuf data */
1873         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1874                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1875         if (ut_params->ibuf[0] == NULL)
1876                 rc = TEST_FAILED;
1877         else
1878                 rc = test_ipsec_crypto_op_alloc(1);
1879
1880         if (rc == 0) {
1881                 /* call ipsec library api */
1882                 rc = crypto_ipsec(1);
1883                 if (rc == 0)
1884                         rc = replay_inb_null_null_check(ut_params, i, 1);
1885                 else {
1886                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1887                                         i);
1888                         rc = TEST_FAILED;
1889                 }
1890         }
1891
1892         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1893                 /* generate packet with seq number inside the replay window */
1894                 if (ut_params->ibuf[0]) {
1895                         rte_pktmbuf_free(ut_params->ibuf[0]);
1896                         ut_params->ibuf[0] = 0;
1897                 }
1898
1899                 ut_params->ibuf[0] = setup_test_string_tunneled(
1900                         ts_params->mbuf_pool, null_encrypted_data,
1901                         test_cfg[i].pkt_sz, INBOUND_SPI,
1902                         test_cfg[i].replay_win_sz);
1903                 if (ut_params->ibuf[0] == NULL)
1904                         rc = TEST_FAILED;
1905                 else
1906                         rc = test_ipsec_crypto_op_alloc(1);
1907
1908                 if (rc == 0) {
1909                         /* call ipsec library api */
1910                         rc = crypto_ipsec(1);
1911                         if (rc == 0)
1912                                 rc = replay_inb_null_null_check(
1913                                                 ut_params, i, 1);
1914                         else {
1915                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1916                                 rc = TEST_FAILED;
1917                         }
1918                 }
1919         }
1920
1921         if (rc == TEST_FAILED)
1922                 test_ipsec_dump_buffers(ut_params, i);
1923
1924         destroy_sa(0);
1925
1926         return rc;
1927 }
1928
1929 static int
1930 test_ipsec_replay_inb_inside_null_null_wrapper(void)
1931 {
1932         int i;
1933         int rc = 0;
1934         struct ipsec_unitest_params *ut_params = &unittest_params;
1935
1936         ut_params->ipsec_xform.spi = INBOUND_SPI;
1937         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1938         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1939         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1940         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1941
1942         for (i = 0; i < num_cfg && rc == 0; i++) {
1943                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1944                 rc = test_ipsec_replay_inb_inside_null_null(i);
1945         }
1946
1947         return rc;
1948 }
1949
1950 static int
1951 test_ipsec_replay_inb_outside_null_null(int i)
1952 {
1953         struct ipsec_testsuite_params *ts_params = &testsuite_params;
1954         struct ipsec_unitest_params *ut_params = &unittest_params;
1955         int rc;
1956
1957         /* create rte_ipsec_sa */
1958         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1959                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1960         if (rc != 0) {
1961                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1962                 return TEST_FAILED;
1963         }
1964
1965         /* Generate test mbuf data */
1966         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1967                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
1968                 test_cfg[i].replay_win_sz + 2);
1969         if (ut_params->ibuf[0] == NULL)
1970                 rc = TEST_FAILED;
1971         else
1972                 rc = test_ipsec_crypto_op_alloc(1);
1973
1974         if (rc == 0) {
1975                 /* call ipsec library api */
1976                 rc = crypto_ipsec(1);
1977                 if (rc == 0)
1978                         rc = replay_inb_null_null_check(ut_params, i, 1);
1979                 else {
1980                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1981                                         i);
1982                         rc = TEST_FAILED;
1983                 }
1984         }
1985
1986         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1987                 /* generate packet with seq number outside the replay window */
1988                 if (ut_params->ibuf[0]) {
1989                         rte_pktmbuf_free(ut_params->ibuf[0]);
1990                         ut_params->ibuf[0] = 0;
1991                 }
1992                 ut_params->ibuf[0] = setup_test_string_tunneled(
1993                         ts_params->mbuf_pool, null_encrypted_data,
1994                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1995                 if (ut_params->ibuf[0] == NULL)
1996                         rc = TEST_FAILED;
1997                 else
1998                         rc = test_ipsec_crypto_op_alloc(1);
1999
2000                 if (rc == 0) {
2001                         /* call ipsec library api */
2002                         rc = crypto_ipsec(1);
2003                         if (rc == 0) {
2004                                 if (test_cfg[i].esn == 0) {
2005                                         RTE_LOG(ERR, USER1,
2006                                                 "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2007                                                 i,
2008                                                 test_cfg[i].replay_win_sz + 2,
2009                                                 1);
2010                                         rc = TEST_FAILED;
2011                                 }
2012                         } else {
2013                                 RTE_LOG(ERR, USER1,
2014                                         "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2015                                         i, test_cfg[i].replay_win_sz + 2, 1);
2016                                 rc = 0;
2017                         }
2018                 }
2019         }
2020
2021         if (rc == TEST_FAILED)
2022                 test_ipsec_dump_buffers(ut_params, i);
2023
2024         destroy_sa(0);
2025
2026         return rc;
2027 }
2028
2029 static int
2030 test_ipsec_replay_inb_outside_null_null_wrapper(void)
2031 {
2032         int i;
2033         int rc = 0;
2034         struct ipsec_unitest_params *ut_params = &unittest_params;
2035
2036         ut_params->ipsec_xform.spi = INBOUND_SPI;
2037         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2038         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2039         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2040         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2041
2042         for (i = 0; i < num_cfg && rc == 0; i++) {
2043                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2044                 rc = test_ipsec_replay_inb_outside_null_null(i);
2045         }
2046
2047         return rc;
2048 }
2049
2050 static int
2051 test_ipsec_replay_inb_repeat_null_null(int i)
2052 {
2053         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2054         struct ipsec_unitest_params *ut_params = &unittest_params;
2055         int rc;
2056
2057         /* create rte_ipsec_sa */
2058         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2059                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2060         if (rc != 0) {
2061                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2062                 return TEST_FAILED;
2063         }
2064
2065         /* Generate test mbuf data */
2066         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2067                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2068         if (ut_params->ibuf[0] == NULL)
2069                 rc = TEST_FAILED;
2070         else
2071                 rc = test_ipsec_crypto_op_alloc(1);
2072
2073         if (rc == 0) {
2074                 /* call ipsec library api */
2075                 rc = crypto_ipsec(1);
2076                 if (rc == 0)
2077                         rc = replay_inb_null_null_check(ut_params, i, 1);
2078                 else {
2079                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2080                                         i);
2081                         rc = TEST_FAILED;
2082                 }
2083         }
2084
2085         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2086                 /*
2087                  * generate packet with repeat seq number in the replay
2088                  * window
2089                  */
2090                 if (ut_params->ibuf[0]) {
2091                         rte_pktmbuf_free(ut_params->ibuf[0]);
2092                         ut_params->ibuf[0] = 0;
2093                 }
2094
2095                 ut_params->ibuf[0] = setup_test_string_tunneled(
2096                         ts_params->mbuf_pool, null_encrypted_data,
2097                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2098                 if (ut_params->ibuf[0] == NULL)
2099                         rc = TEST_FAILED;
2100                 else
2101                         rc = test_ipsec_crypto_op_alloc(1);
2102
2103                 if (rc == 0) {
2104                         /* call ipsec library api */
2105                         rc = crypto_ipsec(1);
2106                         if (rc == 0) {
2107                                 RTE_LOG(ERR, USER1,
2108                                         "packet is not repeated in the replay window, cfg %d seq %u\n",
2109                                         i, 1);
2110                                 rc = TEST_FAILED;
2111                         } else {
2112                                 RTE_LOG(ERR, USER1,
2113                                         "packet is repeated in the replay window, cfg %d seq %u\n",
2114                                         i, 1);
2115                                 rc = 0;
2116                         }
2117                 }
2118         }
2119
2120         if (rc == TEST_FAILED)
2121                 test_ipsec_dump_buffers(ut_params, i);
2122
2123         destroy_sa(0);
2124
2125         return rc;
2126 }
2127
2128 static int
2129 test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2130 {
2131         int i;
2132         int rc = 0;
2133         struct ipsec_unitest_params *ut_params = &unittest_params;
2134
2135         ut_params->ipsec_xform.spi = INBOUND_SPI;
2136         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2137         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2138         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2139         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2140
2141         for (i = 0; i < num_cfg && rc == 0; i++) {
2142                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2143                 rc = test_ipsec_replay_inb_repeat_null_null(i);
2144         }
2145
2146         return rc;
2147 }
2148
2149 static int
2150 test_ipsec_replay_inb_inside_burst_null_null(int i)
2151 {
2152         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2153         struct ipsec_unitest_params *ut_params = &unittest_params;
2154         uint16_t num_pkts = test_cfg[i].num_pkts;
2155         int rc;
2156         int j;
2157
2158         /* create rte_ipsec_sa*/
2159         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2160                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2161         if (rc != 0) {
2162                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2163                 return TEST_FAILED;
2164         }
2165
2166         /* Generate inbound mbuf data */
2167         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2168                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2169         if (ut_params->ibuf[0] == NULL)
2170                 rc = TEST_FAILED;
2171         else
2172                 rc = test_ipsec_crypto_op_alloc(1);
2173
2174         if (rc == 0) {
2175                 /* call ipsec library api */
2176                 rc = crypto_ipsec(1);
2177                 if (rc == 0)
2178                         rc = replay_inb_null_null_check(ut_params, i, 1);
2179                 else {
2180                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2181                                         i);
2182                         rc = TEST_FAILED;
2183                 }
2184         }
2185
2186         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2187                 /*
2188                  *  generate packet(s) with seq number(s) inside the
2189                  *  replay window
2190                  */
2191                 if (ut_params->ibuf[0]) {
2192                         rte_pktmbuf_free(ut_params->ibuf[0]);
2193                         ut_params->ibuf[0] = 0;
2194                 }
2195
2196                 for (j = 0; j < num_pkts && rc == 0; j++) {
2197                         /* packet with sequence number 1 already processed */
2198                         ut_params->ibuf[j] = setup_test_string_tunneled(
2199                                 ts_params->mbuf_pool, null_encrypted_data,
2200                                 test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2201                         if (ut_params->ibuf[j] == NULL)
2202                                 rc = TEST_FAILED;
2203                 }
2204
2205                 if (rc == 0) {
2206                         if (test_cfg[i].reorder_pkts)
2207                                 test_ipsec_reorder_inb_pkt_burst(num_pkts);
2208                         rc = test_ipsec_crypto_op_alloc(num_pkts);
2209                 }
2210
2211                 if (rc == 0) {
2212                         /* call ipsec library api */
2213                         rc = crypto_ipsec(num_pkts);
2214                         if (rc == 0)
2215                                 rc = replay_inb_null_null_check(
2216                                                 ut_params, i, num_pkts);
2217                         else {
2218                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2219                                 rc = TEST_FAILED;
2220                         }
2221                 }
2222         }
2223
2224         if (rc == TEST_FAILED)
2225                 test_ipsec_dump_buffers(ut_params, i);
2226
2227         destroy_sa(0);
2228
2229         return rc;
2230 }
2231
2232 static int
2233 test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2234 {
2235         int i;
2236         int rc = 0;
2237         struct ipsec_unitest_params *ut_params = &unittest_params;
2238
2239         ut_params->ipsec_xform.spi = INBOUND_SPI;
2240         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2241         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2242         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2243         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2244
2245         for (i = 0; i < num_cfg && rc == 0; i++) {
2246                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2247                 rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2248         }
2249
2250         return rc;
2251 }
2252
2253
2254 static int
2255 crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2256                 int i)
2257 {
2258         uint16_t j;
2259
2260         for (j = 0; j < BURST_SIZE; j++) {
2261                 ut_params->pkt_index = j;
2262
2263                 /* compare the data buffers */
2264                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2265                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2266                         test_cfg[i].pkt_sz,
2267                         "input and output data does not match\n");
2268                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2269                         ut_params->obuf[j]->pkt_len,
2270                         "data_len is not equal to pkt_len");
2271                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2272                         test_cfg[i].pkt_sz,
2273                         "data_len is not equal to input data");
2274         }
2275
2276         return 0;
2277 }
2278
2279 static int
2280 test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2281 {
2282         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2283         struct ipsec_unitest_params *ut_params = &unittest_params;
2284         uint16_t num_pkts = test_cfg[i].num_pkts;
2285         uint16_t j, r;
2286         int rc = 0;
2287
2288         if (num_pkts != BURST_SIZE)
2289                 return rc;
2290
2291         /* create rte_ipsec_sa */
2292         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2293                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2294         if (rc != 0) {
2295                 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2296                 return TEST_FAILED;
2297         }
2298
2299         /* create second rte_ipsec_sa */
2300         ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2301         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2302                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2303         if (rc != 0) {
2304                 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2305                 destroy_sa(0);
2306                 return TEST_FAILED;
2307         }
2308
2309         /* Generate test mbuf data */
2310         for (j = 0; j < num_pkts && rc == 0; j++) {
2311                 r = j % 2;
2312                 /* packet with sequence number 0 is invalid */
2313                 ut_params->ibuf[j] = setup_test_string_tunneled(
2314                         ts_params->mbuf_pool, null_encrypted_data,
2315                         test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2316                 if (ut_params->ibuf[j] == NULL)
2317                         rc = TEST_FAILED;
2318         }
2319
2320         if (rc == 0)
2321                 rc = test_ipsec_crypto_op_alloc(num_pkts);
2322
2323         if (rc == 0) {
2324                 /* call ipsec library api */
2325                 rc = crypto_ipsec_2sa();
2326                 if (rc == 0)
2327                         rc = crypto_inb_burst_2sa_null_null_check(
2328                                         ut_params, i);
2329                 else {
2330                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2331                                 i);
2332                         rc = TEST_FAILED;
2333                 }
2334         }
2335
2336         if (rc == TEST_FAILED)
2337                 test_ipsec_dump_buffers(ut_params, i);
2338
2339         destroy_sa(0);
2340         destroy_sa(1);
2341         return rc;
2342 }
2343
2344 static int
2345 test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2346 {
2347         int i;
2348         int rc = 0;
2349         struct ipsec_unitest_params *ut_params = &unittest_params;
2350
2351         ut_params->ipsec_xform.spi = INBOUND_SPI;
2352         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2353         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2354         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2355         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2356
2357         for (i = 0; i < num_cfg && rc == 0; i++) {
2358                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2359                 rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2360         }
2361
2362         return rc;
2363 }
2364
2365 static int
2366 test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2367 {
2368         struct ipsec_testsuite_params *ts_params = &testsuite_params;
2369         struct ipsec_unitest_params *ut_params = &unittest_params;
2370         uint16_t num_pkts = test_cfg[i].num_pkts;
2371         uint16_t j, k;
2372         int rc = 0;
2373
2374         if (num_pkts != BURST_SIZE)
2375                 return rc;
2376
2377         /* create rte_ipsec_sa */
2378         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2379                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2380         if (rc != 0) {
2381                 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2382                 return TEST_FAILED;
2383         }
2384
2385         /* create second rte_ipsec_sa */
2386         ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2387         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2388                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2389         if (rc != 0) {
2390                 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2391                 destroy_sa(0);
2392                 return TEST_FAILED;
2393         }
2394
2395         /* Generate test mbuf data */
2396         for (j = 0; j < num_pkts && rc == 0; j++) {
2397                 k = crypto_ipsec_4grp(j);
2398
2399                 /* packet with sequence number 0 is invalid */
2400                 ut_params->ibuf[j] = setup_test_string_tunneled(
2401                         ts_params->mbuf_pool, null_encrypted_data,
2402                         test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
2403                 if (ut_params->ibuf[j] == NULL)
2404                         rc = TEST_FAILED;
2405         }
2406
2407         if (rc == 0)
2408                 rc = test_ipsec_crypto_op_alloc(num_pkts);
2409
2410         if (rc == 0) {
2411                 /* call ipsec library api */
2412                 rc = crypto_ipsec_2sa_4grp();
2413                 if (rc == 0)
2414                         rc = crypto_inb_burst_2sa_null_null_check(
2415                                         ut_params, i);
2416                 else {
2417                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2418                                 i);
2419                         rc = TEST_FAILED;
2420                 }
2421         }
2422
2423         if (rc == TEST_FAILED)
2424                 test_ipsec_dump_buffers(ut_params, i);
2425
2426         destroy_sa(0);
2427         destroy_sa(1);
2428         return rc;
2429 }
2430
2431 static int
2432 test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
2433 {
2434         int i;
2435         int rc = 0;
2436         struct ipsec_unitest_params *ut_params = &unittest_params;
2437
2438         ut_params->ipsec_xform.spi = INBOUND_SPI;
2439         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2440         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2441         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2442         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2443
2444         for (i = 0; i < num_cfg && rc == 0; i++) {
2445                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2446                 rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
2447         }
2448
2449         return rc;
2450 }
2451
2452 static struct unit_test_suite ipsec_testsuite  = {
2453         .suite_name = "IPsec NULL Unit Test Suite",
2454         .setup = testsuite_setup,
2455         .teardown = testsuite_teardown,
2456         .unit_test_cases = {
2457                 TEST_CASE_ST(ut_setup, ut_teardown,
2458                         test_ipsec_crypto_inb_burst_null_null_wrapper),
2459                 TEST_CASE_ST(ut_setup, ut_teardown,
2460                         test_ipsec_crypto_outb_burst_null_null_wrapper),
2461                 TEST_CASE_ST(ut_setup, ut_teardown,
2462                         test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
2463                 TEST_CASE_ST(ut_setup, ut_teardown,
2464                         test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
2465                 TEST_CASE_ST(ut_setup, ut_teardown,
2466                         test_ipsec_inline_proto_inb_burst_null_null_wrapper),
2467                 TEST_CASE_ST(ut_setup, ut_teardown,
2468                         test_ipsec_inline_proto_outb_burst_null_null_wrapper),
2469                 TEST_CASE_ST(ut_setup, ut_teardown,
2470                         test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
2471                 TEST_CASE_ST(ut_setup, ut_teardown,
2472                         test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
2473                 TEST_CASE_ST(ut_setup, ut_teardown,
2474                         test_ipsec_replay_inb_inside_null_null_wrapper),
2475                 TEST_CASE_ST(ut_setup, ut_teardown,
2476                         test_ipsec_replay_inb_outside_null_null_wrapper),
2477                 TEST_CASE_ST(ut_setup, ut_teardown,
2478                         test_ipsec_replay_inb_repeat_null_null_wrapper),
2479                 TEST_CASE_ST(ut_setup, ut_teardown,
2480                         test_ipsec_replay_inb_inside_burst_null_null_wrapper),
2481                 TEST_CASE_ST(ut_setup, ut_teardown,
2482                         test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
2483                 TEST_CASE_ST(ut_setup, ut_teardown,
2484                         test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
2485                 TEST_CASES_END() /**< NULL terminate unit test array */
2486         }
2487 };
2488
2489 static int
2490 test_ipsec(void)
2491 {
2492         return unit_test_suite_runner(&ipsec_testsuite);
2493 }
2494
2495 REGISTER_TEST_COMMAND(ipsec_autotest, test_ipsec);