1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
8 #include <rte_cryptodev.h>
9 #include <rte_malloc.h>
10 #include <rte_ether.h>
12 #include "cperf_options.h"
13 #include "cperf_test_vectors.h"
15 #define AES_BLOCK_SIZE 16
16 #define DES_BLOCK_SIZE 8
26 printf("%s [EAL options] --\n"
27 " --silent: disable options dump\n"
28 " --ptest throughput / latency / verify / pmd-cyclecount :"
30 " --pool_sz N: set the number of crypto ops/mbufs allocated\n"
31 " --total-ops N: set the number of total operations performed\n"
32 " --burst-sz N: set the number of packets per burst\n"
33 " --buffer-sz N: set the size of a single packet\n"
34 " --imix N: set the distribution of packet sizes\n"
35 " --segment-sz N: set the size of the segment to use\n"
36 " --desc-nb N: set number of descriptors for each crypto device\n"
37 " --devtype TYPE: set crypto device type to use\n"
38 " --optype cipher-only / auth-only / cipher-then-auth /\n"
39 " auth-then-cipher / aead : set operation type\n"
40 " --sessionless: enable session-less crypto operations\n"
41 " --out-of-place: enable out-of-place crypto operations\n"
42 " --test-file NAME: set the test vector file path\n"
43 " --test-name NAME: set specific test name section in test file\n"
44 " --cipher-algo ALGO: set cipher algorithm\n"
45 " --cipher-op encrypt / decrypt: set the cipher operation\n"
46 " --cipher-key-sz N: set the cipher key size\n"
47 " --cipher-iv-sz N: set the cipher IV size\n"
48 " --auth-algo ALGO: set auth algorithm\n"
49 " --auth-op generate / verify: set the auth operation\n"
50 " --auth-key-sz N: set the auth key size\n"
51 " --auth-iv-sz N: set the auth IV size\n"
52 " --aead-algo ALGO: set AEAD algorithm\n"
53 " --aead-op encrypt / decrypt: set the AEAD operation\n"
54 " --aead-key-sz N: set the AEAD key size\n"
55 " --aead-iv-sz N: set the AEAD IV size\n"
56 " --aead-aad-sz N: set the AEAD AAD size\n"
57 " --digest-sz N: set the digest size\n"
58 " --pmd-cyclecount-delay-ms N: set delay between enqueue\n"
59 " and dequeue in pmd-cyclecount benchmarking mode\n"
60 " --csv-friendly: enable test result output CSV friendly\n"
61 " --modex-len N: modex length, supported lengths are "
62 "60, 128, 255, 448. Default: 128\n"
63 #ifdef RTE_LIB_SECURITY
64 " --pdcp-sn-sz N: set PDCP SN size N <5/7/12/15/18>\n"
65 " --pdcp-domain DOMAIN: set PDCP domain <control/user>\n"
66 " --pdcp-ses-hfn-en: enable session based fixed HFN\n"
67 " --enable-sdap: enable sdap\n"
68 " --docsis-hdr-sz: set DOCSIS header size\n"
70 " -h: prints this help\n",
75 get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
80 for (i = 0; i < map_len; i++) {
82 if (strcmp(str_key, map[i].name) == 0)
90 parse_cperf_test_type(struct cperf_options *opts, const char *arg)
92 struct name_id_map cperftest_namemap[] = {
94 cperf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
95 CPERF_TEST_TYPE_THROUGHPUT
98 cperf_test_type_strs[CPERF_TEST_TYPE_VERIFY],
99 CPERF_TEST_TYPE_VERIFY
102 cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY],
103 CPERF_TEST_TYPE_LATENCY
106 cperf_test_type_strs[CPERF_TEST_TYPE_PMDCC],
107 CPERF_TEST_TYPE_PMDCC
111 int id = get_str_key_id_mapping(
112 (struct name_id_map *)cperftest_namemap,
113 RTE_DIM(cperftest_namemap), arg);
115 RTE_LOG(ERR, USER1, "failed to parse test type");
119 opts->test = (enum cperf_perf_test_type)id;
125 parse_uint32_t(uint32_t *value, const char *arg)
128 unsigned long n = strtoul(arg, &end, 10);
130 if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
136 *value = (uint32_t) n;
142 parse_uint16_t(uint16_t *value, const char *arg)
145 int ret = parse_uint32_t(&val, arg);
150 if (val > UINT16_MAX)
153 *value = (uint16_t) val;
159 parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
164 char *copy_arg = strdup(arg);
166 if (copy_arg == NULL)
170 token = strtok(copy_arg, ":");
172 /* Parse minimum value */
174 number = strtoul(token, NULL, 10);
176 if (errno == EINVAL || errno == ERANGE ||
184 token = strtok(NULL, ":");
186 /* Parse increment value */
188 number = strtoul(token, NULL, 10);
190 if (errno == EINVAL || errno == ERANGE ||
198 token = strtok(NULL, ":");
200 /* Parse maximum value */
202 number = strtoul(token, NULL, 10);
204 if (errno == EINVAL || errno == ERANGE ||
213 if (strtok(NULL, ":") != NULL)
225 parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
233 char *copy_arg = strdup(arg);
235 if (copy_arg == NULL)
239 token = strtok(copy_arg, ",");
241 /* Parse first value */
243 number = strtoul(token, NULL, 10);
245 if (errno == EINVAL || errno == ERANGE ||
249 list[count++] = number;
255 token = strtok(NULL, ",");
257 while (token != NULL) {
258 if (count == MAX_LIST) {
259 RTE_LOG(WARNING, USER1, "Using only the first %u sizes\n",
264 number = strtoul(token, NULL, 10);
266 if (errno == EINVAL || errno == ERANGE ||
270 list[count++] = number;
272 if (number < temp_min)
274 if (number > temp_max)
277 token = strtok(NULL, ",");
294 parse_total_ops(struct cperf_options *opts, const char *arg)
296 int ret = parse_uint32_t(&opts->total_ops, arg);
299 RTE_LOG(ERR, USER1, "failed to parse total operations count\n");
301 if (opts->total_ops == 0) {
303 "invalid total operations count number specified\n");
311 parse_pool_sz(struct cperf_options *opts, const char *arg)
313 int ret = parse_uint32_t(&opts->pool_sz, arg);
316 RTE_LOG(ERR, USER1, "failed to parse pool size");
321 parse_modex_len(struct cperf_options *opts, const char *arg)
323 int ret = parse_uint16_t(&opts->modex_len, arg);
326 RTE_LOG(ERR, USER1, "failed to parse modex len");
331 parse_burst_sz(struct cperf_options *opts, const char *arg)
335 /* Try parsing the argument as a range, if it fails, parse it as a list */
336 if (parse_range(arg, &opts->min_burst_size, &opts->max_burst_size,
337 &opts->inc_burst_size) < 0) {
338 ret = parse_list(arg, opts->burst_size_list,
339 &opts->min_burst_size,
340 &opts->max_burst_size);
342 RTE_LOG(ERR, USER1, "failed to parse burst size/s\n");
345 opts->burst_size_count = ret;
352 parse_buffer_sz(struct cperf_options *opts, const char *arg)
356 /* Try parsing the argument as a range, if it fails, parse it as a list */
357 if (parse_range(arg, &opts->min_buffer_size, &opts->max_buffer_size,
358 &opts->inc_buffer_size) < 0) {
359 ret = parse_list(arg, opts->buffer_size_list,
360 &opts->min_buffer_size,
361 &opts->max_buffer_size);
363 RTE_LOG(ERR, USER1, "failed to parse buffer size/s\n");
366 opts->buffer_size_count = ret;
373 parse_segment_sz(struct cperf_options *opts, const char *arg)
375 int ret = parse_uint32_t(&opts->segment_sz, arg);
378 RTE_LOG(ERR, USER1, "failed to parse segment size\n");
382 if (opts->segment_sz == 0) {
383 RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n");
391 parse_imix(struct cperf_options *opts, const char *arg)
395 ret = parse_list(arg, opts->imix_distribution_list,
398 RTE_LOG(ERR, USER1, "failed to parse imix distribution\n");
402 opts->imix_distribution_count = ret;
404 if (opts->imix_distribution_count <= 1) {
405 RTE_LOG(ERR, USER1, "imix distribution should have "
406 "at least two entries\n");
414 parse_desc_nb(struct cperf_options *opts, const char *arg)
416 int ret = parse_uint32_t(&opts->nb_descriptors, arg);
419 RTE_LOG(ERR, USER1, "failed to parse descriptors number\n");
423 if (opts->nb_descriptors == 0) {
424 RTE_LOG(ERR, USER1, "invalid descriptors number specified\n");
432 parse_device_type(struct cperf_options *opts, const char *arg)
434 if (strlen(arg) > (sizeof(opts->device_type) - 1))
437 strncpy(opts->device_type, arg, sizeof(opts->device_type) - 1);
438 *(opts->device_type + sizeof(opts->device_type) - 1) = '\0';
444 parse_op_type(struct cperf_options *opts, const char *arg)
446 struct name_id_map optype_namemap[] = {
448 cperf_op_type_strs[CPERF_CIPHER_ONLY],
452 cperf_op_type_strs[CPERF_AUTH_ONLY],
456 cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
457 CPERF_CIPHER_THEN_AUTH
460 cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
461 CPERF_AUTH_THEN_CIPHER
464 cperf_op_type_strs[CPERF_AEAD],
468 cperf_op_type_strs[CPERF_PDCP],
472 cperf_op_type_strs[CPERF_DOCSIS],
476 cperf_op_type_strs[CPERF_IPSEC],
480 cperf_op_type_strs[CPERF_ASYM_MODEX],
485 int id = get_str_key_id_mapping(optype_namemap,
486 RTE_DIM(optype_namemap), arg);
488 RTE_LOG(ERR, USER1, "invalid opt type specified\n");
492 opts->op_type = (enum cperf_op_type)id;
498 parse_sessionless(struct cperf_options *opts,
499 const char *arg __rte_unused)
501 opts->sessionless = 1;
506 parse_out_of_place(struct cperf_options *opts,
507 const char *arg __rte_unused)
509 opts->out_of_place = 1;
514 parse_test_file(struct cperf_options *opts,
517 opts->test_file = strdup(arg);
518 if (access(opts->test_file, F_OK) != -1)
520 RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
526 parse_test_name(struct cperf_options *opts,
529 char *test_name = (char *) rte_zmalloc(NULL,
530 sizeof(char) * (strlen(arg) + 3), 0);
531 if (test_name == NULL) {
532 RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
537 snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
538 opts->test_name = test_name;
544 parse_silent(struct cperf_options *opts,
545 const char *arg __rte_unused)
553 parse_enable_sdap(struct cperf_options *opts,
554 const char *arg __rte_unused)
562 parse_cipher_algo(struct cperf_options *opts, const char *arg)
565 enum rte_crypto_cipher_algorithm cipher_algo;
567 if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
568 RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
572 opts->cipher_algo = cipher_algo;
578 parse_cipher_op(struct cperf_options *opts, const char *arg)
580 struct name_id_map cipher_op_namemap[] = {
582 rte_crypto_cipher_operation_strings
583 [RTE_CRYPTO_CIPHER_OP_ENCRYPT],
584 RTE_CRYPTO_CIPHER_OP_ENCRYPT },
586 rte_crypto_cipher_operation_strings
587 [RTE_CRYPTO_CIPHER_OP_DECRYPT],
588 RTE_CRYPTO_CIPHER_OP_DECRYPT
592 int id = get_str_key_id_mapping(cipher_op_namemap,
593 RTE_DIM(cipher_op_namemap), arg);
595 RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
599 opts->cipher_op = (enum rte_crypto_cipher_operation)id;
605 parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
607 return parse_uint16_t(&opts->cipher_key_sz, arg);
611 parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
613 return parse_uint16_t(&opts->cipher_iv_sz, arg);
617 parse_auth_algo(struct cperf_options *opts, const char *arg)
619 enum rte_crypto_auth_algorithm auth_algo;
621 if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
622 RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
626 opts->auth_algo = auth_algo;
632 parse_auth_op(struct cperf_options *opts, const char *arg)
634 struct name_id_map auth_op_namemap[] = {
636 rte_crypto_auth_operation_strings
637 [RTE_CRYPTO_AUTH_OP_GENERATE],
638 RTE_CRYPTO_AUTH_OP_GENERATE },
640 rte_crypto_auth_operation_strings
641 [RTE_CRYPTO_AUTH_OP_VERIFY],
642 RTE_CRYPTO_AUTH_OP_VERIFY
646 int id = get_str_key_id_mapping(auth_op_namemap,
647 RTE_DIM(auth_op_namemap), arg);
649 RTE_LOG(ERR, USER1, "invalid authentication operation specified"
654 opts->auth_op = (enum rte_crypto_auth_operation)id;
660 parse_auth_key_sz(struct cperf_options *opts, const char *arg)
662 return parse_uint16_t(&opts->auth_key_sz, arg);
666 parse_digest_sz(struct cperf_options *opts, const char *arg)
668 return parse_uint16_t(&opts->digest_sz, arg);
671 #ifdef RTE_LIB_SECURITY
673 parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
676 int ret = parse_uint32_t(&val, arg);
681 if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
682 val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
683 val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
684 val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
685 val != RTE_SECURITY_PDCP_SN_SIZE_18) {
686 printf("\nInvalid pdcp SN size: %u\n", val);
689 opts->pdcp_sn_sz = val;
694 const char *cperf_pdcp_domain_strs[] = {
695 [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
696 [RTE_SECURITY_PDCP_MODE_DATA] = "data",
697 [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
701 parse_pdcp_domain(struct cperf_options *opts, const char *arg)
703 struct name_id_map pdcp_domain_namemap[] = {
705 cperf_pdcp_domain_strs
706 [RTE_SECURITY_PDCP_MODE_CONTROL],
707 RTE_SECURITY_PDCP_MODE_CONTROL },
709 cperf_pdcp_domain_strs
710 [RTE_SECURITY_PDCP_MODE_DATA],
711 RTE_SECURITY_PDCP_MODE_DATA
714 cperf_pdcp_domain_strs
715 [RTE_SECURITY_PDCP_MODE_SHORT_MAC],
716 RTE_SECURITY_PDCP_MODE_SHORT_MAC
720 int id = get_str_key_id_mapping(pdcp_domain_namemap,
721 RTE_DIM(pdcp_domain_namemap), arg);
723 RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
728 opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
734 parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused)
736 opts->pdcp_ses_hfn_en = 1;
741 parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
743 return parse_uint16_t(&opts->docsis_hdr_sz, arg);
748 parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
750 return parse_uint16_t(&opts->auth_iv_sz, arg);
754 parse_aead_algo(struct cperf_options *opts, const char *arg)
756 enum rte_crypto_aead_algorithm aead_algo;
758 if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
759 RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
763 opts->aead_algo = aead_algo;
769 parse_aead_op(struct cperf_options *opts, const char *arg)
771 struct name_id_map aead_op_namemap[] = {
773 rte_crypto_aead_operation_strings
774 [RTE_CRYPTO_AEAD_OP_ENCRYPT],
775 RTE_CRYPTO_AEAD_OP_ENCRYPT },
777 rte_crypto_aead_operation_strings
778 [RTE_CRYPTO_AEAD_OP_DECRYPT],
779 RTE_CRYPTO_AEAD_OP_DECRYPT
783 int id = get_str_key_id_mapping(aead_op_namemap,
784 RTE_DIM(aead_op_namemap), arg);
786 RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
791 opts->aead_op = (enum rte_crypto_aead_operation)id;
797 parse_aead_key_sz(struct cperf_options *opts, const char *arg)
799 return parse_uint16_t(&opts->aead_key_sz, arg);
803 parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
805 return parse_uint16_t(&opts->aead_iv_sz, arg);
809 parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
811 return parse_uint16_t(&opts->aead_aad_sz, arg);
815 parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
823 parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
826 int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
829 RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
836 typedef int (*option_parser_t)(struct cperf_options *opts,
839 struct long_opt_parser {
840 const char *lgopt_name;
841 option_parser_t parser_fn;
845 static struct option lgopts[] = {
847 { CPERF_PTEST_TYPE, required_argument, 0, 0 },
848 { CPERF_MODEX_LEN, required_argument, 0, 0 },
850 { CPERF_POOL_SIZE, required_argument, 0, 0 },
851 { CPERF_TOTAL_OPS, required_argument, 0, 0 },
852 { CPERF_BURST_SIZE, required_argument, 0, 0 },
853 { CPERF_BUFFER_SIZE, required_argument, 0, 0 },
854 { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
855 { CPERF_DESC_NB, required_argument, 0, 0 },
857 { CPERF_IMIX, required_argument, 0, 0 },
858 { CPERF_DEVTYPE, required_argument, 0, 0 },
859 { CPERF_OPTYPE, required_argument, 0, 0 },
861 { CPERF_SILENT, no_argument, 0, 0 },
862 { CPERF_SESSIONLESS, no_argument, 0, 0 },
863 { CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
864 { CPERF_TEST_FILE, required_argument, 0, 0 },
865 { CPERF_TEST_NAME, required_argument, 0, 0 },
867 { CPERF_CIPHER_ALGO, required_argument, 0, 0 },
868 { CPERF_CIPHER_OP, required_argument, 0, 0 },
870 { CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
871 { CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
873 { CPERF_AUTH_ALGO, required_argument, 0, 0 },
874 { CPERF_AUTH_OP, required_argument, 0, 0 },
876 { CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
877 { CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
879 { CPERF_AEAD_ALGO, required_argument, 0, 0 },
880 { CPERF_AEAD_OP, required_argument, 0, 0 },
882 { CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
883 { CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
884 { CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
886 { CPERF_DIGEST_SZ, required_argument, 0, 0 },
888 #ifdef RTE_LIB_SECURITY
889 { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
890 { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
891 { CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 },
892 { CPERF_ENABLE_SDAP, no_argument, 0, 0 },
893 { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
895 { CPERF_CSV, no_argument, 0, 0},
897 { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
903 cperf_options_default(struct cperf_options *opts)
905 opts->test = CPERF_TEST_TYPE_THROUGHPUT;
907 opts->pool_sz = 8192;
908 opts->total_ops = 10000000;
909 opts->nb_descriptors = 2048;
911 opts->buffer_size_list[0] = 64;
912 opts->buffer_size_count = 1;
913 opts->max_buffer_size = 64;
914 opts->min_buffer_size = 64;
915 opts->inc_buffer_size = 0;
917 opts->burst_size_list[0] = 32;
918 opts->burst_size_count = 1;
919 opts->max_burst_size = 32;
920 opts->min_burst_size = 32;
921 opts->inc_burst_size = 0;
924 * Will be parsed from command line or set to
925 * maximum buffer size + digest, later
927 opts->segment_sz = 0;
929 opts->imix_distribution_count = 0;
930 strncpy(opts->device_type, "crypto_aesni_mb",
931 sizeof(opts->device_type));
934 opts->op_type = CPERF_CIPHER_THEN_AUTH;
937 opts->test_file = NULL;
938 opts->test_name = NULL;
939 opts->sessionless = 0;
940 opts->out_of_place = 0;
943 opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
944 opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
945 opts->cipher_key_sz = 16;
946 opts->cipher_iv_sz = 16;
948 opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
949 opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
951 opts->auth_key_sz = 64;
952 opts->auth_iv_sz = 0;
954 opts->aead_key_sz = 0;
955 opts->aead_iv_sz = 0;
956 opts->aead_aad_sz = 0;
958 opts->digest_sz = 12;
960 opts->pmdcc_delay = 0;
961 #ifdef RTE_LIB_SECURITY
962 opts->pdcp_sn_sz = 12;
963 opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
964 opts->pdcp_ses_hfn_en = 0;
966 opts->docsis_hdr_sz = 17;
968 opts->modex_data = (struct cperf_modex_test_data *)&modex_perf_data[0];
972 cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
974 struct long_opt_parser parsermap[] = {
975 { CPERF_PTEST_TYPE, parse_cperf_test_type },
976 { CPERF_MODEX_LEN, parse_modex_len },
977 { CPERF_SILENT, parse_silent },
978 { CPERF_POOL_SIZE, parse_pool_sz },
979 { CPERF_TOTAL_OPS, parse_total_ops },
980 { CPERF_BURST_SIZE, parse_burst_sz },
981 { CPERF_BUFFER_SIZE, parse_buffer_sz },
982 { CPERF_SEGMENT_SIZE, parse_segment_sz },
983 { CPERF_DESC_NB, parse_desc_nb },
984 { CPERF_DEVTYPE, parse_device_type },
985 { CPERF_OPTYPE, parse_op_type },
986 { CPERF_SESSIONLESS, parse_sessionless },
987 { CPERF_OUT_OF_PLACE, parse_out_of_place },
988 { CPERF_IMIX, parse_imix },
989 { CPERF_TEST_FILE, parse_test_file },
990 { CPERF_TEST_NAME, parse_test_name },
991 { CPERF_CIPHER_ALGO, parse_cipher_algo },
992 { CPERF_CIPHER_OP, parse_cipher_op },
993 { CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
994 { CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
995 { CPERF_AUTH_ALGO, parse_auth_algo },
996 { CPERF_AUTH_OP, parse_auth_op },
997 { CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
998 { CPERF_AUTH_IV_SZ, parse_auth_iv_sz },
999 { CPERF_AEAD_ALGO, parse_aead_algo },
1000 { CPERF_AEAD_OP, parse_aead_op },
1001 { CPERF_AEAD_KEY_SZ, parse_aead_key_sz },
1002 { CPERF_AEAD_IV_SZ, parse_aead_iv_sz },
1003 { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz },
1004 { CPERF_DIGEST_SZ, parse_digest_sz },
1005 #ifdef RTE_LIB_SECURITY
1006 { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz },
1007 { CPERF_PDCP_DOMAIN, parse_pdcp_domain },
1008 { CPERF_PDCP_SES_HFN_EN, parse_pdcp_ses_hfn_en },
1009 { CPERF_ENABLE_SDAP, parse_enable_sdap },
1010 { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz },
1012 { CPERF_CSV, parse_csv_friendly},
1013 { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
1017 for (i = 0; i < RTE_DIM(parsermap); i++) {
1018 if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
1019 strlen(lgopts[opt_idx].name)) == 0)
1020 return parsermap[i].parser_fn(opts, optarg);
1027 cperf_options_parse(struct cperf_options *options, int argc, char **argv)
1029 int opt, retval, opt_idx;
1031 while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
1039 retval = cperf_opts_parse_long(opt_idx, options);
1055 check_cipher_buffer_length(struct cperf_options *options)
1057 uint32_t buffer_size, buffer_size_idx = 0;
1059 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
1060 options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
1061 if (options->inc_buffer_size != 0)
1062 buffer_size = options->min_buffer_size;
1064 buffer_size = options->buffer_size_list[0];
1066 while (buffer_size <= options->max_buffer_size) {
1067 if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1068 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1069 "not suitable for the algorithm selected\n");
1073 if (options->inc_buffer_size != 0)
1074 buffer_size += options->inc_buffer_size;
1076 if (++buffer_size_idx == options->buffer_size_count)
1078 buffer_size = options->buffer_size_list[buffer_size_idx];
1084 if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1085 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1086 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1087 if (options->inc_buffer_size != 0)
1088 buffer_size = options->min_buffer_size;
1090 buffer_size = options->buffer_size_list[0];
1092 while (buffer_size <= options->max_buffer_size) {
1093 if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1094 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1095 "not suitable for the algorithm selected\n");
1099 if (options->inc_buffer_size != 0)
1100 buffer_size += options->inc_buffer_size;
1102 if (++buffer_size_idx == options->buffer_size_count)
1104 buffer_size = options->buffer_size_list[buffer_size_idx];
1113 #ifdef RTE_LIB_SECURITY
1115 check_docsis_buffer_length(struct cperf_options *options)
1117 uint32_t buffer_size, buffer_size_idx = 0;
1119 if (options->inc_buffer_size != 0)
1120 buffer_size = options->min_buffer_size;
1122 buffer_size = options->buffer_size_list[0];
1124 while (buffer_size <= options->max_buffer_size) {
1125 if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1126 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1127 RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1128 "valid for DOCSIS\n");
1132 if (options->inc_buffer_size != 0)
1133 buffer_size += options->inc_buffer_size;
1135 if (++buffer_size_idx == options->buffer_size_count)
1138 options->buffer_size_list[buffer_size_idx];
1147 is_valid_chained_op(struct cperf_options *options)
1149 if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1150 options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1153 if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1154 options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY)
1161 cperf_options_check(struct cperf_options *options)
1165 if (options->op_type == CPERF_CIPHER_ONLY ||
1166 options->op_type == CPERF_DOCSIS)
1167 options->digest_sz = 0;
1169 if (options->out_of_place &&
1170 options->segment_sz <= options->max_buffer_size) {
1171 RTE_LOG(ERR, USER1, "Out of place mode can only work "
1172 "with non segmented buffers\n");
1177 * If segment size is not set, assume only one segment,
1178 * big enough to contain the largest buffer and the digest
1180 if (options->segment_sz == 0) {
1181 options->segment_sz = options->max_buffer_size +
1183 /* In IPsec operation, packet length will be increased
1184 * by some bytes depend upon the algorithm, so increasing
1185 * the segment size by headroom to cover most of
1188 if (options->op_type == CPERF_IPSEC)
1189 options->segment_sz += RTE_PKTMBUF_HEADROOM;
1192 if (options->segment_sz < options->digest_sz) {
1194 "Segment size should be at least "
1195 "the size of the digest\n");
1199 if ((options->imix_distribution_count != 0) &&
1200 (options->imix_distribution_count !=
1201 options->buffer_size_count)) {
1202 RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1203 "number of buffer sizes\n");
1207 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1208 options->test_file == NULL) {
1209 RTE_LOG(ERR, USER1, "Define path to the file with test"
1214 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1215 options->op_type != CPERF_CIPHER_ONLY &&
1216 options->test_name == NULL) {
1217 RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1218 " from the test vectors.\n");
1222 if (options->test_name != NULL && options->test_file == NULL) {
1223 RTE_LOG(ERR, USER1, "Define path to the file with test"
1228 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1229 options->test_file == NULL) {
1230 RTE_LOG(ERR, USER1, "Define path to the file with test"
1235 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1236 (options->inc_buffer_size != 0 ||
1237 options->buffer_size_count > 1)) {
1238 RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1239 "using the verify test.\n");
1243 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1244 (options->inc_burst_size != 0 ||
1245 options->burst_size_count > 1)) {
1246 RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1247 "using the verify test.\n");
1251 if (options->test == CPERF_TEST_TYPE_PMDCC &&
1252 options->pool_sz < options->nb_descriptors) {
1253 RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1254 "must be equal or greater than the number of "
1255 "cryptodev descriptors.\n");
1259 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1260 options->imix_distribution_count > 0) {
1261 RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1262 "using the verify test.\n");
1266 if (options->op_type == CPERF_CIPHER_THEN_AUTH ||
1267 options->op_type == CPERF_AUTH_THEN_CIPHER) {
1268 if (!is_valid_chained_op(options)) {
1269 RTE_LOG(ERR, USER1, "Invalid chained operation.\n");
1274 if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1275 if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1277 RTE_CRYPTO_AUTH_OP_GENERATE) {
1278 RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1279 " options: encrypt and generate.\n");
1284 if (options->op_type == CPERF_CIPHER_ONLY ||
1285 options->op_type == CPERF_CIPHER_THEN_AUTH ||
1286 options->op_type == CPERF_AUTH_THEN_CIPHER) {
1287 if (check_cipher_buffer_length(options) < 0)
1291 if (options->modex_len) {
1292 if (options->op_type != CPERF_ASYM_MODEX) {
1293 RTE_LOG(ERR, USER1, "Option modex len should be used only with "
1294 " optype: modex.\n");
1298 for (i = 0; i < (int)RTE_DIM(modex_perf_data); i++) {
1299 if (modex_perf_data[i].modulus.len ==
1300 options->modex_len) {
1301 options->modex_data =
1302 (struct cperf_modex_test_data
1303 *)&modex_perf_data[i];
1307 if (i == (int)RTE_DIM(modex_perf_data)) {
1309 "Option modex len: %d is not supported\n",
1310 options->modex_len);
1315 #ifdef RTE_LIB_SECURITY
1316 if (options->op_type == CPERF_DOCSIS) {
1317 if (check_docsis_buffer_length(options) < 0)
1326 cperf_options_dump(struct cperf_options *opts)
1330 printf("# Crypto Performance Application Options:\n");
1332 printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1334 printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1335 printf("# total number of ops: %u\n", opts->total_ops);
1336 if (opts->inc_buffer_size != 0) {
1337 printf("# buffer size:\n");
1338 printf("#\t min: %u\n", opts->min_buffer_size);
1339 printf("#\t max: %u\n", opts->max_buffer_size);
1340 printf("#\t inc: %u\n", opts->inc_buffer_size);
1342 printf("# buffer sizes: ");
1343 for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1344 printf("%u ", opts->buffer_size_list[size_idx]);
1347 if (opts->inc_burst_size != 0) {
1348 printf("# burst size:\n");
1349 printf("#\t min: %u\n", opts->min_burst_size);
1350 printf("#\t max: %u\n", opts->max_burst_size);
1351 printf("#\t inc: %u\n", opts->inc_burst_size);
1353 printf("# burst sizes: ");
1354 for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1355 printf("%u ", opts->burst_size_list[size_idx]);
1358 printf("\n# segment size: %u\n", opts->segment_sz);
1360 printf("# cryptodev type: %s\n", opts->device_type);
1362 printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1363 printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1364 printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1365 printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1366 if (opts->test == CPERF_TEST_TYPE_PMDCC)
1367 printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1371 if (opts->op_type == CPERF_AUTH_ONLY ||
1372 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1373 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1374 printf("# auth algorithm: %s\n",
1375 rte_crypto_auth_algorithm_strings[opts->auth_algo]);
1376 printf("# auth operation: %s\n",
1377 rte_crypto_auth_operation_strings[opts->auth_op]);
1378 printf("# auth key size: %u\n", opts->auth_key_sz);
1379 printf("# auth iv size: %u\n", opts->auth_iv_sz);
1380 printf("# auth digest size: %u\n", opts->digest_sz);
1384 if (opts->op_type == CPERF_CIPHER_ONLY ||
1385 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1386 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1387 printf("# cipher algorithm: %s\n",
1388 rte_crypto_cipher_algorithm_strings[opts->cipher_algo]);
1389 printf("# cipher operation: %s\n",
1390 rte_crypto_cipher_operation_strings[opts->cipher_op]);
1391 printf("# cipher key size: %u\n", opts->cipher_key_sz);
1392 printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1396 if (opts->op_type == CPERF_AEAD) {
1397 printf("# aead algorithm: %s\n",
1398 rte_crypto_aead_algorithm_strings[opts->aead_algo]);
1399 printf("# aead operation: %s\n",
1400 rte_crypto_aead_operation_strings[opts->aead_op]);
1401 printf("# aead key size: %u\n", opts->aead_key_sz);
1402 printf("# aead iv size: %u\n", opts->aead_iv_sz);
1403 printf("# aead digest size: %u\n", opts->digest_sz);
1404 printf("# aead aad size: %u\n", opts->aead_aad_sz);
1408 #ifdef RTE_LIB_SECURITY
1409 if (opts->op_type == CPERF_DOCSIS) {
1410 printf("# docsis header size: %u\n", opts->docsis_hdr_sz);