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"
14 #define AES_BLOCK_SIZE 16
15 #define DES_BLOCK_SIZE 8
25 printf("%s [EAL options] --\n"
26 " --silent: disable options dump\n"
27 " --ptest throughput / latency / verify / pmd-cyclecount :"
29 " --pool_sz N: set the number of crypto ops/mbufs allocated\n"
30 " --total-ops N: set the number of total operations performed\n"
31 " --burst-sz N: set the number of packets per burst\n"
32 " --buffer-sz N: set the size of a single packet\n"
33 " --imix N: set the distribution of packet sizes\n"
34 " --segment-sz N: set the size of the segment to use\n"
35 " --desc-nb N: set number of descriptors for each crypto device\n"
36 " --devtype TYPE: set crypto device type to use\n"
37 " --optype cipher-only / auth-only / cipher-then-auth /\n"
38 " auth-then-cipher / aead : set operation type\n"
39 " --sessionless: enable session-less crypto operations\n"
40 " --out-of-place: enable out-of-place crypto operations\n"
41 " --test-file NAME: set the test vector file path\n"
42 " --test-name NAME: set specific test name section in test file\n"
43 " --cipher-algo ALGO: set cipher algorithm\n"
44 " --cipher-op encrypt / decrypt: set the cipher operation\n"
45 " --cipher-key-sz N: set the cipher key size\n"
46 " --cipher-iv-sz N: set the cipher IV size\n"
47 " --auth-algo ALGO: set auth algorithm\n"
48 " --auth-op generate / verify: set the auth operation\n"
49 " --auth-key-sz N: set the auth key size\n"
50 " --auth-iv-sz N: set the auth IV size\n"
51 " --aead-algo ALGO: set AEAD algorithm\n"
52 " --aead-op encrypt / decrypt: set the AEAD operation\n"
53 " --aead-key-sz N: set the AEAD key size\n"
54 " --aead-iv-sz N: set the AEAD IV size\n"
55 " --aead-aad-sz N: set the AEAD AAD size\n"
56 " --digest-sz N: set the digest size\n"
57 " --pmd-cyclecount-delay-ms N: set delay between enqueue\n"
58 " and dequeue in pmd-cyclecount benchmarking mode\n"
59 " --csv-friendly: enable test result output CSV friendly\n"
60 #ifdef RTE_LIB_SECURITY
61 " --pdcp-sn-sz N: set PDCP SN size N <5/7/12/15/18>\n"
62 " --pdcp-domain DOMAIN: set PDCP domain <control/user>\n"
63 " --pdcp-ses-hfn-en: enable session based fixed HFN\n"
64 " --docsis-hdr-sz: set DOCSIS header size\n"
66 " -h: prints this help\n",
71 get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
76 for (i = 0; i < map_len; i++) {
78 if (strcmp(str_key, map[i].name) == 0)
86 parse_cperf_test_type(struct cperf_options *opts, const char *arg)
88 struct name_id_map cperftest_namemap[] = {
90 cperf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
91 CPERF_TEST_TYPE_THROUGHPUT
94 cperf_test_type_strs[CPERF_TEST_TYPE_VERIFY],
95 CPERF_TEST_TYPE_VERIFY
98 cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY],
99 CPERF_TEST_TYPE_LATENCY
102 cperf_test_type_strs[CPERF_TEST_TYPE_PMDCC],
103 CPERF_TEST_TYPE_PMDCC
107 int id = get_str_key_id_mapping(
108 (struct name_id_map *)cperftest_namemap,
109 RTE_DIM(cperftest_namemap), arg);
111 RTE_LOG(ERR, USER1, "failed to parse test type");
115 opts->test = (enum cperf_perf_test_type)id;
121 parse_uint32_t(uint32_t *value, const char *arg)
124 unsigned long n = strtoul(arg, &end, 10);
126 if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
132 *value = (uint32_t) n;
138 parse_uint16_t(uint16_t *value, const char *arg)
141 int ret = parse_uint32_t(&val, arg);
146 if (val > UINT16_MAX)
149 *value = (uint16_t) val;
155 parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
160 char *copy_arg = strdup(arg);
162 if (copy_arg == NULL)
166 token = strtok(copy_arg, ":");
168 /* Parse minimum value */
170 number = strtoul(token, NULL, 10);
172 if (errno == EINVAL || errno == ERANGE ||
180 token = strtok(NULL, ":");
182 /* Parse increment value */
184 number = strtoul(token, NULL, 10);
186 if (errno == EINVAL || errno == ERANGE ||
194 token = strtok(NULL, ":");
196 /* Parse maximum value */
198 number = strtoul(token, NULL, 10);
200 if (errno == EINVAL || errno == ERANGE ||
209 if (strtok(NULL, ":") != NULL)
221 parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
229 char *copy_arg = strdup(arg);
231 if (copy_arg == NULL)
235 token = strtok(copy_arg, ",");
237 /* Parse first value */
239 number = strtoul(token, NULL, 10);
241 if (errno == EINVAL || errno == ERANGE ||
245 list[count++] = number;
251 token = strtok(NULL, ",");
253 while (token != NULL) {
254 if (count == MAX_LIST) {
255 RTE_LOG(WARNING, USER1, "Using only the first %u sizes\n",
260 number = strtoul(token, NULL, 10);
262 if (errno == EINVAL || errno == ERANGE ||
266 list[count++] = number;
268 if (number < temp_min)
270 if (number > temp_max)
273 token = strtok(NULL, ",");
290 parse_total_ops(struct cperf_options *opts, const char *arg)
292 int ret = parse_uint32_t(&opts->total_ops, arg);
295 RTE_LOG(ERR, USER1, "failed to parse total operations count\n");
297 if (opts->total_ops == 0) {
299 "invalid total operations count number specified\n");
307 parse_pool_sz(struct cperf_options *opts, const char *arg)
309 int ret = parse_uint32_t(&opts->pool_sz, arg);
312 RTE_LOG(ERR, USER1, "failed to parse pool size");
317 parse_burst_sz(struct cperf_options *opts, const char *arg)
321 /* Try parsing the argument as a range, if it fails, parse it as a list */
322 if (parse_range(arg, &opts->min_burst_size, &opts->max_burst_size,
323 &opts->inc_burst_size) < 0) {
324 ret = parse_list(arg, opts->burst_size_list,
325 &opts->min_burst_size,
326 &opts->max_burst_size);
328 RTE_LOG(ERR, USER1, "failed to parse burst size/s\n");
331 opts->burst_size_count = ret;
338 parse_buffer_sz(struct cperf_options *opts, const char *arg)
342 /* Try parsing the argument as a range, if it fails, parse it as a list */
343 if (parse_range(arg, &opts->min_buffer_size, &opts->max_buffer_size,
344 &opts->inc_buffer_size) < 0) {
345 ret = parse_list(arg, opts->buffer_size_list,
346 &opts->min_buffer_size,
347 &opts->max_buffer_size);
349 RTE_LOG(ERR, USER1, "failed to parse buffer size/s\n");
352 opts->buffer_size_count = ret;
359 parse_segment_sz(struct cperf_options *opts, const char *arg)
361 int ret = parse_uint32_t(&opts->segment_sz, arg);
364 RTE_LOG(ERR, USER1, "failed to parse segment size\n");
368 if (opts->segment_sz == 0) {
369 RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n");
377 parse_imix(struct cperf_options *opts, const char *arg)
381 ret = parse_list(arg, opts->imix_distribution_list,
384 RTE_LOG(ERR, USER1, "failed to parse imix distribution\n");
388 opts->imix_distribution_count = ret;
390 if (opts->imix_distribution_count <= 1) {
391 RTE_LOG(ERR, USER1, "imix distribution should have "
392 "at least two entries\n");
400 parse_desc_nb(struct cperf_options *opts, const char *arg)
402 int ret = parse_uint32_t(&opts->nb_descriptors, arg);
405 RTE_LOG(ERR, USER1, "failed to parse descriptors number\n");
409 if (opts->nb_descriptors == 0) {
410 RTE_LOG(ERR, USER1, "invalid descriptors number specified\n");
418 parse_device_type(struct cperf_options *opts, const char *arg)
420 if (strlen(arg) > (sizeof(opts->device_type) - 1))
423 strncpy(opts->device_type, arg, sizeof(opts->device_type) - 1);
424 *(opts->device_type + sizeof(opts->device_type) - 1) = '\0';
430 parse_op_type(struct cperf_options *opts, const char *arg)
432 struct name_id_map optype_namemap[] = {
434 cperf_op_type_strs[CPERF_CIPHER_ONLY],
438 cperf_op_type_strs[CPERF_AUTH_ONLY],
442 cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
443 CPERF_CIPHER_THEN_AUTH
446 cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
447 CPERF_AUTH_THEN_CIPHER
450 cperf_op_type_strs[CPERF_AEAD],
454 cperf_op_type_strs[CPERF_PDCP],
458 cperf_op_type_strs[CPERF_DOCSIS],
462 cperf_op_type_strs[CPERF_IPSEC],
466 cperf_op_type_strs[CPERF_ASYM_MODEX],
471 int id = get_str_key_id_mapping(optype_namemap,
472 RTE_DIM(optype_namemap), arg);
474 RTE_LOG(ERR, USER1, "invalid opt type specified\n");
478 opts->op_type = (enum cperf_op_type)id;
484 parse_sessionless(struct cperf_options *opts,
485 const char *arg __rte_unused)
487 opts->sessionless = 1;
492 parse_out_of_place(struct cperf_options *opts,
493 const char *arg __rte_unused)
495 opts->out_of_place = 1;
500 parse_test_file(struct cperf_options *opts,
503 opts->test_file = strdup(arg);
504 if (access(opts->test_file, F_OK) != -1)
506 RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
512 parse_test_name(struct cperf_options *opts,
515 char *test_name = (char *) rte_zmalloc(NULL,
516 sizeof(char) * (strlen(arg) + 3), 0);
517 if (test_name == NULL) {
518 RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
523 snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
524 opts->test_name = test_name;
530 parse_silent(struct cperf_options *opts,
531 const char *arg __rte_unused)
539 parse_cipher_algo(struct cperf_options *opts, const char *arg)
542 enum rte_crypto_cipher_algorithm cipher_algo;
544 if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
545 RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
549 opts->cipher_algo = cipher_algo;
555 parse_cipher_op(struct cperf_options *opts, const char *arg)
557 struct name_id_map cipher_op_namemap[] = {
559 rte_crypto_cipher_operation_strings
560 [RTE_CRYPTO_CIPHER_OP_ENCRYPT],
561 RTE_CRYPTO_CIPHER_OP_ENCRYPT },
563 rte_crypto_cipher_operation_strings
564 [RTE_CRYPTO_CIPHER_OP_DECRYPT],
565 RTE_CRYPTO_CIPHER_OP_DECRYPT
569 int id = get_str_key_id_mapping(cipher_op_namemap,
570 RTE_DIM(cipher_op_namemap), arg);
572 RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
576 opts->cipher_op = (enum rte_crypto_cipher_operation)id;
582 parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
584 return parse_uint16_t(&opts->cipher_key_sz, arg);
588 parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
590 return parse_uint16_t(&opts->cipher_iv_sz, arg);
594 parse_auth_algo(struct cperf_options *opts, const char *arg)
596 enum rte_crypto_auth_algorithm auth_algo;
598 if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
599 RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
603 opts->auth_algo = auth_algo;
609 parse_auth_op(struct cperf_options *opts, const char *arg)
611 struct name_id_map auth_op_namemap[] = {
613 rte_crypto_auth_operation_strings
614 [RTE_CRYPTO_AUTH_OP_GENERATE],
615 RTE_CRYPTO_AUTH_OP_GENERATE },
617 rte_crypto_auth_operation_strings
618 [RTE_CRYPTO_AUTH_OP_VERIFY],
619 RTE_CRYPTO_AUTH_OP_VERIFY
623 int id = get_str_key_id_mapping(auth_op_namemap,
624 RTE_DIM(auth_op_namemap), arg);
626 RTE_LOG(ERR, USER1, "invalid authentication operation specified"
631 opts->auth_op = (enum rte_crypto_auth_operation)id;
637 parse_auth_key_sz(struct cperf_options *opts, const char *arg)
639 return parse_uint16_t(&opts->auth_key_sz, arg);
643 parse_digest_sz(struct cperf_options *opts, const char *arg)
645 return parse_uint16_t(&opts->digest_sz, arg);
648 #ifdef RTE_LIB_SECURITY
650 parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
653 int ret = parse_uint32_t(&val, arg);
658 if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
659 val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
660 val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
661 val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
662 val != RTE_SECURITY_PDCP_SN_SIZE_18) {
663 printf("\nInvalid pdcp SN size: %u\n", val);
666 opts->pdcp_sn_sz = val;
671 const char *cperf_pdcp_domain_strs[] = {
672 [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
673 [RTE_SECURITY_PDCP_MODE_DATA] = "data",
674 [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
678 parse_pdcp_domain(struct cperf_options *opts, const char *arg)
680 struct name_id_map pdcp_domain_namemap[] = {
682 cperf_pdcp_domain_strs
683 [RTE_SECURITY_PDCP_MODE_CONTROL],
684 RTE_SECURITY_PDCP_MODE_CONTROL },
686 cperf_pdcp_domain_strs
687 [RTE_SECURITY_PDCP_MODE_DATA],
688 RTE_SECURITY_PDCP_MODE_DATA
691 cperf_pdcp_domain_strs
692 [RTE_SECURITY_PDCP_MODE_SHORT_MAC],
693 RTE_SECURITY_PDCP_MODE_SHORT_MAC
697 int id = get_str_key_id_mapping(pdcp_domain_namemap,
698 RTE_DIM(pdcp_domain_namemap), arg);
700 RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
705 opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
711 parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused)
713 opts->pdcp_ses_hfn_en = 1;
718 parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
720 return parse_uint16_t(&opts->docsis_hdr_sz, arg);
725 parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
727 return parse_uint16_t(&opts->auth_iv_sz, arg);
731 parse_aead_algo(struct cperf_options *opts, const char *arg)
733 enum rte_crypto_aead_algorithm aead_algo;
735 if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
736 RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
740 opts->aead_algo = aead_algo;
746 parse_aead_op(struct cperf_options *opts, const char *arg)
748 struct name_id_map aead_op_namemap[] = {
750 rte_crypto_aead_operation_strings
751 [RTE_CRYPTO_AEAD_OP_ENCRYPT],
752 RTE_CRYPTO_AEAD_OP_ENCRYPT },
754 rte_crypto_aead_operation_strings
755 [RTE_CRYPTO_AEAD_OP_DECRYPT],
756 RTE_CRYPTO_AEAD_OP_DECRYPT
760 int id = get_str_key_id_mapping(aead_op_namemap,
761 RTE_DIM(aead_op_namemap), arg);
763 RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
768 opts->aead_op = (enum rte_crypto_aead_operation)id;
774 parse_aead_key_sz(struct cperf_options *opts, const char *arg)
776 return parse_uint16_t(&opts->aead_key_sz, arg);
780 parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
782 return parse_uint16_t(&opts->aead_iv_sz, arg);
786 parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
788 return parse_uint16_t(&opts->aead_aad_sz, arg);
792 parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
800 parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
803 int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
806 RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
813 typedef int (*option_parser_t)(struct cperf_options *opts,
816 struct long_opt_parser {
817 const char *lgopt_name;
818 option_parser_t parser_fn;
822 static struct option lgopts[] = {
824 { CPERF_PTEST_TYPE, required_argument, 0, 0 },
826 { CPERF_POOL_SIZE, required_argument, 0, 0 },
827 { CPERF_TOTAL_OPS, required_argument, 0, 0 },
828 { CPERF_BURST_SIZE, required_argument, 0, 0 },
829 { CPERF_BUFFER_SIZE, required_argument, 0, 0 },
830 { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
831 { CPERF_DESC_NB, required_argument, 0, 0 },
833 { CPERF_IMIX, required_argument, 0, 0 },
834 { CPERF_DEVTYPE, required_argument, 0, 0 },
835 { CPERF_OPTYPE, required_argument, 0, 0 },
837 { CPERF_SILENT, no_argument, 0, 0 },
838 { CPERF_SESSIONLESS, no_argument, 0, 0 },
839 { CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
840 { CPERF_TEST_FILE, required_argument, 0, 0 },
841 { CPERF_TEST_NAME, required_argument, 0, 0 },
843 { CPERF_CIPHER_ALGO, required_argument, 0, 0 },
844 { CPERF_CIPHER_OP, required_argument, 0, 0 },
846 { CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
847 { CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
849 { CPERF_AUTH_ALGO, required_argument, 0, 0 },
850 { CPERF_AUTH_OP, required_argument, 0, 0 },
852 { CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
853 { CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
855 { CPERF_AEAD_ALGO, required_argument, 0, 0 },
856 { CPERF_AEAD_OP, required_argument, 0, 0 },
858 { CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
859 { CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
860 { CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
862 { CPERF_DIGEST_SZ, required_argument, 0, 0 },
864 #ifdef RTE_LIB_SECURITY
865 { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
866 { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
867 { CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 },
868 { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
870 { CPERF_CSV, no_argument, 0, 0},
872 { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
878 cperf_options_default(struct cperf_options *opts)
880 opts->test = CPERF_TEST_TYPE_THROUGHPUT;
882 opts->pool_sz = 8192;
883 opts->total_ops = 10000000;
884 opts->nb_descriptors = 2048;
886 opts->buffer_size_list[0] = 64;
887 opts->buffer_size_count = 1;
888 opts->max_buffer_size = 64;
889 opts->min_buffer_size = 64;
890 opts->inc_buffer_size = 0;
892 opts->burst_size_list[0] = 32;
893 opts->burst_size_count = 1;
894 opts->max_burst_size = 32;
895 opts->min_burst_size = 32;
896 opts->inc_burst_size = 0;
899 * Will be parsed from command line or set to
900 * maximum buffer size + digest, later
902 opts->segment_sz = 0;
904 opts->imix_distribution_count = 0;
905 strncpy(opts->device_type, "crypto_aesni_mb",
906 sizeof(opts->device_type));
909 opts->op_type = CPERF_CIPHER_THEN_AUTH;
912 opts->test_file = NULL;
913 opts->test_name = NULL;
914 opts->sessionless = 0;
915 opts->out_of_place = 0;
918 opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
919 opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
920 opts->cipher_key_sz = 16;
921 opts->cipher_iv_sz = 16;
923 opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
924 opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
926 opts->auth_key_sz = 64;
927 opts->auth_iv_sz = 0;
929 opts->aead_key_sz = 0;
930 opts->aead_iv_sz = 0;
931 opts->aead_aad_sz = 0;
933 opts->digest_sz = 12;
935 opts->pmdcc_delay = 0;
936 #ifdef RTE_LIB_SECURITY
937 opts->pdcp_sn_sz = 12;
938 opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
939 opts->pdcp_ses_hfn_en = 0;
940 opts->docsis_hdr_sz = 17;
945 cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
947 struct long_opt_parser parsermap[] = {
948 { CPERF_PTEST_TYPE, parse_cperf_test_type },
949 { CPERF_SILENT, parse_silent },
950 { CPERF_POOL_SIZE, parse_pool_sz },
951 { CPERF_TOTAL_OPS, parse_total_ops },
952 { CPERF_BURST_SIZE, parse_burst_sz },
953 { CPERF_BUFFER_SIZE, parse_buffer_sz },
954 { CPERF_SEGMENT_SIZE, parse_segment_sz },
955 { CPERF_DESC_NB, parse_desc_nb },
956 { CPERF_DEVTYPE, parse_device_type },
957 { CPERF_OPTYPE, parse_op_type },
958 { CPERF_SESSIONLESS, parse_sessionless },
959 { CPERF_OUT_OF_PLACE, parse_out_of_place },
960 { CPERF_IMIX, parse_imix },
961 { CPERF_TEST_FILE, parse_test_file },
962 { CPERF_TEST_NAME, parse_test_name },
963 { CPERF_CIPHER_ALGO, parse_cipher_algo },
964 { CPERF_CIPHER_OP, parse_cipher_op },
965 { CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
966 { CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
967 { CPERF_AUTH_ALGO, parse_auth_algo },
968 { CPERF_AUTH_OP, parse_auth_op },
969 { CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
970 { CPERF_AUTH_IV_SZ, parse_auth_iv_sz },
971 { CPERF_AEAD_ALGO, parse_aead_algo },
972 { CPERF_AEAD_OP, parse_aead_op },
973 { CPERF_AEAD_KEY_SZ, parse_aead_key_sz },
974 { CPERF_AEAD_IV_SZ, parse_aead_iv_sz },
975 { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz },
976 { CPERF_DIGEST_SZ, parse_digest_sz },
977 #ifdef RTE_LIB_SECURITY
978 { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz },
979 { CPERF_PDCP_DOMAIN, parse_pdcp_domain },
980 { CPERF_PDCP_SES_HFN_EN, parse_pdcp_ses_hfn_en },
981 { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz },
983 { CPERF_CSV, parse_csv_friendly},
984 { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
988 for (i = 0; i < RTE_DIM(parsermap); i++) {
989 if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
990 strlen(lgopts[opt_idx].name)) == 0)
991 return parsermap[i].parser_fn(opts, optarg);
998 cperf_options_parse(struct cperf_options *options, int argc, char **argv)
1000 int opt, retval, opt_idx;
1002 while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
1010 retval = cperf_opts_parse_long(opt_idx, options);
1026 check_cipher_buffer_length(struct cperf_options *options)
1028 uint32_t buffer_size, buffer_size_idx = 0;
1030 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
1031 options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
1032 if (options->inc_buffer_size != 0)
1033 buffer_size = options->min_buffer_size;
1035 buffer_size = options->buffer_size_list[0];
1037 while (buffer_size <= options->max_buffer_size) {
1038 if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1039 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1040 "not suitable for the algorithm selected\n");
1044 if (options->inc_buffer_size != 0)
1045 buffer_size += options->inc_buffer_size;
1047 if (++buffer_size_idx == options->buffer_size_count)
1049 buffer_size = options->buffer_size_list[buffer_size_idx];
1055 if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1056 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1057 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1058 if (options->inc_buffer_size != 0)
1059 buffer_size = options->min_buffer_size;
1061 buffer_size = options->buffer_size_list[0];
1063 while (buffer_size <= options->max_buffer_size) {
1064 if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1065 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1066 "not suitable for the algorithm selected\n");
1070 if (options->inc_buffer_size != 0)
1071 buffer_size += options->inc_buffer_size;
1073 if (++buffer_size_idx == options->buffer_size_count)
1075 buffer_size = options->buffer_size_list[buffer_size_idx];
1084 #ifdef RTE_LIB_SECURITY
1086 check_docsis_buffer_length(struct cperf_options *options)
1088 uint32_t buffer_size, buffer_size_idx = 0;
1090 if (options->inc_buffer_size != 0)
1091 buffer_size = options->min_buffer_size;
1093 buffer_size = options->buffer_size_list[0];
1095 while (buffer_size <= options->max_buffer_size) {
1096 if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1097 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1098 RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1099 "valid for DOCSIS\n");
1103 if (options->inc_buffer_size != 0)
1104 buffer_size += options->inc_buffer_size;
1106 if (++buffer_size_idx == options->buffer_size_count)
1109 options->buffer_size_list[buffer_size_idx];
1118 cperf_options_check(struct cperf_options *options)
1120 if (options->op_type == CPERF_CIPHER_ONLY ||
1121 options->op_type == CPERF_DOCSIS)
1122 options->digest_sz = 0;
1124 if (options->out_of_place &&
1125 options->segment_sz <= options->max_buffer_size) {
1126 RTE_LOG(ERR, USER1, "Out of place mode can only work "
1127 "with non segmented buffers\n");
1132 * If segment size is not set, assume only one segment,
1133 * big enough to contain the largest buffer and the digest
1135 if (options->segment_sz == 0)
1136 options->segment_sz = options->max_buffer_size +
1139 if (options->segment_sz < options->digest_sz) {
1141 "Segment size should be at least "
1142 "the size of the digest\n");
1146 if ((options->imix_distribution_count != 0) &&
1147 (options->imix_distribution_count !=
1148 options->buffer_size_count)) {
1149 RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1150 "number of buffer sizes\n");
1154 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1155 options->test_file == NULL) {
1156 RTE_LOG(ERR, USER1, "Define path to the file with test"
1161 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1162 options->op_type != CPERF_CIPHER_ONLY &&
1163 options->test_name == NULL) {
1164 RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1165 " from the test vectors.\n");
1169 if (options->test_name != NULL && options->test_file == NULL) {
1170 RTE_LOG(ERR, USER1, "Define path to the file with test"
1175 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1176 options->test_file == NULL) {
1177 RTE_LOG(ERR, USER1, "Define path to the file with test"
1182 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1183 (options->inc_buffer_size != 0 ||
1184 options->buffer_size_count > 1)) {
1185 RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1186 "using the verify test.\n");
1190 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1191 (options->inc_burst_size != 0 ||
1192 options->burst_size_count > 1)) {
1193 RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1194 "using the verify test.\n");
1198 if (options->test == CPERF_TEST_TYPE_PMDCC &&
1199 options->pool_sz < options->nb_descriptors) {
1200 RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1201 "must be equal or greater than the number of "
1202 "cryptodev descriptors.\n");
1206 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1207 options->imix_distribution_count > 0) {
1208 RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1209 "using the verify test.\n");
1213 if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1214 if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1216 RTE_CRYPTO_AUTH_OP_GENERATE) {
1217 RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1218 " options: encrypt and generate.\n");
1221 } else if (options->op_type == CPERF_AUTH_THEN_CIPHER) {
1222 if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1224 RTE_CRYPTO_AUTH_OP_VERIFY) {
1225 RTE_LOG(ERR, USER1, "Option auth then cipher must use"
1226 " options: decrypt and verify.\n");
1231 if (options->op_type == CPERF_CIPHER_ONLY ||
1232 options->op_type == CPERF_CIPHER_THEN_AUTH ||
1233 options->op_type == CPERF_AUTH_THEN_CIPHER) {
1234 if (check_cipher_buffer_length(options) < 0)
1238 #ifdef RTE_LIB_SECURITY
1239 if (options->op_type == CPERF_DOCSIS) {
1240 if (check_docsis_buffer_length(options) < 0)
1249 cperf_options_dump(struct cperf_options *opts)
1253 printf("# Crypto Performance Application Options:\n");
1255 printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1257 printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1258 printf("# total number of ops: %u\n", opts->total_ops);
1259 if (opts->inc_buffer_size != 0) {
1260 printf("# buffer size:\n");
1261 printf("#\t min: %u\n", opts->min_buffer_size);
1262 printf("#\t max: %u\n", opts->max_buffer_size);
1263 printf("#\t inc: %u\n", opts->inc_buffer_size);
1265 printf("# buffer sizes: ");
1266 for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1267 printf("%u ", opts->buffer_size_list[size_idx]);
1270 if (opts->inc_burst_size != 0) {
1271 printf("# burst size:\n");
1272 printf("#\t min: %u\n", opts->min_burst_size);
1273 printf("#\t max: %u\n", opts->max_burst_size);
1274 printf("#\t inc: %u\n", opts->inc_burst_size);
1276 printf("# burst sizes: ");
1277 for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1278 printf("%u ", opts->burst_size_list[size_idx]);
1281 printf("\n# segment size: %u\n", opts->segment_sz);
1283 printf("# cryptodev type: %s\n", opts->device_type);
1285 printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1286 printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1287 printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1288 printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1289 if (opts->test == CPERF_TEST_TYPE_PMDCC)
1290 printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1294 if (opts->op_type == CPERF_AUTH_ONLY ||
1295 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1296 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1297 printf("# auth algorithm: %s\n",
1298 rte_crypto_auth_algorithm_strings[opts->auth_algo]);
1299 printf("# auth operation: %s\n",
1300 rte_crypto_auth_operation_strings[opts->auth_op]);
1301 printf("# auth key size: %u\n", opts->auth_key_sz);
1302 printf("# auth iv size: %u\n", opts->auth_iv_sz);
1303 printf("# auth digest size: %u\n", opts->digest_sz);
1307 if (opts->op_type == CPERF_CIPHER_ONLY ||
1308 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1309 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1310 printf("# cipher algorithm: %s\n",
1311 rte_crypto_cipher_algorithm_strings[opts->cipher_algo]);
1312 printf("# cipher operation: %s\n",
1313 rte_crypto_cipher_operation_strings[opts->cipher_op]);
1314 printf("# cipher key size: %u\n", opts->cipher_key_sz);
1315 printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1319 if (opts->op_type == CPERF_AEAD) {
1320 printf("# aead algorithm: %s\n",
1321 rte_crypto_aead_algorithm_strings[opts->aead_algo]);
1322 printf("# aead operation: %s\n",
1323 rte_crypto_aead_operation_strings[opts->aead_op]);
1324 printf("# aead key size: %u\n", opts->aead_key_sz);
1325 printf("# aead iv size: %u\n", opts->aead_iv_sz);
1326 printf("# aead digest size: %u\n", opts->digest_sz);
1327 printf("# aead aad size: %u\n", opts->aead_aad_sz);
1331 #ifdef RTE_LIB_SECURITY
1332 if (opts->op_type == CPERF_DOCSIS) {
1333 printf("# docsis header size: %u\n", opts->docsis_hdr_sz);