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-cycleount :"
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_LIBRTE_SECURITY
61 " --docsis-hdr-sz: set DOCSIS header size\n"
63 " -h: prints this help\n",
68 get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
73 for (i = 0; i < map_len; i++) {
75 if (strcmp(str_key, map[i].name) == 0)
83 parse_cperf_test_type(struct cperf_options *opts, const char *arg)
85 struct name_id_map cperftest_namemap[] = {
87 cperf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
88 CPERF_TEST_TYPE_THROUGHPUT
91 cperf_test_type_strs[CPERF_TEST_TYPE_VERIFY],
92 CPERF_TEST_TYPE_VERIFY
95 cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY],
96 CPERF_TEST_TYPE_LATENCY
99 cperf_test_type_strs[CPERF_TEST_TYPE_PMDCC],
100 CPERF_TEST_TYPE_PMDCC
104 int id = get_str_key_id_mapping(
105 (struct name_id_map *)cperftest_namemap,
106 RTE_DIM(cperftest_namemap), arg);
108 RTE_LOG(ERR, USER1, "failed to parse test type");
112 opts->test = (enum cperf_perf_test_type)id;
118 parse_uint32_t(uint32_t *value, const char *arg)
121 unsigned long n = strtoul(arg, &end, 10);
123 if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
129 *value = (uint32_t) n;
135 parse_uint16_t(uint16_t *value, const char *arg)
138 int ret = parse_uint32_t(&val, arg);
143 if (val > UINT16_MAX)
146 *value = (uint16_t) val;
152 parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
157 char *copy_arg = strdup(arg);
159 if (copy_arg == NULL)
163 token = strtok(copy_arg, ":");
165 /* Parse minimum value */
167 number = strtoul(token, NULL, 10);
169 if (errno == EINVAL || errno == ERANGE ||
177 token = strtok(NULL, ":");
179 /* Parse increment value */
181 number = strtoul(token, NULL, 10);
183 if (errno == EINVAL || errno == ERANGE ||
191 token = strtok(NULL, ":");
193 /* Parse maximum value */
195 number = strtoul(token, NULL, 10);
197 if (errno == EINVAL || errno == ERANGE ||
206 if (strtok(NULL, ":") != NULL)
218 parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
226 char *copy_arg = strdup(arg);
228 if (copy_arg == NULL)
232 token = strtok(copy_arg, ",");
234 /* Parse first value */
236 number = strtoul(token, NULL, 10);
238 if (errno == EINVAL || errno == ERANGE ||
242 list[count++] = number;
248 token = strtok(NULL, ",");
250 while (token != NULL) {
251 if (count == MAX_LIST) {
252 RTE_LOG(WARNING, USER1, "Using only the first %u sizes\n",
257 number = strtoul(token, NULL, 10);
259 if (errno == EINVAL || errno == ERANGE ||
263 list[count++] = number;
265 if (number < temp_min)
267 if (number > temp_max)
270 token = strtok(NULL, ",");
287 parse_total_ops(struct cperf_options *opts, const char *arg)
289 int ret = parse_uint32_t(&opts->total_ops, arg);
292 RTE_LOG(ERR, USER1, "failed to parse total operations count\n");
294 if (opts->total_ops == 0) {
296 "invalid total operations count number specified\n");
304 parse_pool_sz(struct cperf_options *opts, const char *arg)
306 int ret = parse_uint32_t(&opts->pool_sz, arg);
309 RTE_LOG(ERR, USER1, "failed to parse pool size");
314 parse_burst_sz(struct cperf_options *opts, const char *arg)
318 /* Try parsing the argument as a range, if it fails, parse it as a list */
319 if (parse_range(arg, &opts->min_burst_size, &opts->max_burst_size,
320 &opts->inc_burst_size) < 0) {
321 ret = parse_list(arg, opts->burst_size_list,
322 &opts->min_burst_size,
323 &opts->max_burst_size);
325 RTE_LOG(ERR, USER1, "failed to parse burst size/s\n");
328 opts->burst_size_count = ret;
335 parse_buffer_sz(struct cperf_options *opts, const char *arg)
339 /* Try parsing the argument as a range, if it fails, parse it as a list */
340 if (parse_range(arg, &opts->min_buffer_size, &opts->max_buffer_size,
341 &opts->inc_buffer_size) < 0) {
342 ret = parse_list(arg, opts->buffer_size_list,
343 &opts->min_buffer_size,
344 &opts->max_buffer_size);
346 RTE_LOG(ERR, USER1, "failed to parse buffer size/s\n");
349 opts->buffer_size_count = ret;
356 parse_segment_sz(struct cperf_options *opts, const char *arg)
358 int ret = parse_uint32_t(&opts->segment_sz, arg);
361 RTE_LOG(ERR, USER1, "failed to parse segment size\n");
365 if (opts->segment_sz == 0) {
366 RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n");
374 parse_imix(struct cperf_options *opts, const char *arg)
378 ret = parse_list(arg, opts->imix_distribution_list,
381 RTE_LOG(ERR, USER1, "failed to parse imix distribution\n");
385 opts->imix_distribution_count = ret;
387 if (opts->imix_distribution_count <= 1) {
388 RTE_LOG(ERR, USER1, "imix distribution should have "
389 "at least two entries\n");
397 parse_desc_nb(struct cperf_options *opts, const char *arg)
399 int ret = parse_uint32_t(&opts->nb_descriptors, arg);
402 RTE_LOG(ERR, USER1, "failed to parse descriptors number\n");
406 if (opts->nb_descriptors == 0) {
407 RTE_LOG(ERR, USER1, "invalid descriptors number specified\n");
415 parse_device_type(struct cperf_options *opts, const char *arg)
417 if (strlen(arg) > (sizeof(opts->device_type) - 1))
420 strncpy(opts->device_type, arg, sizeof(opts->device_type) - 1);
421 *(opts->device_type + sizeof(opts->device_type) - 1) = '\0';
427 parse_op_type(struct cperf_options *opts, const char *arg)
429 struct name_id_map optype_namemap[] = {
431 cperf_op_type_strs[CPERF_CIPHER_ONLY],
435 cperf_op_type_strs[CPERF_AUTH_ONLY],
439 cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
440 CPERF_CIPHER_THEN_AUTH
443 cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
444 CPERF_AUTH_THEN_CIPHER
447 cperf_op_type_strs[CPERF_AEAD],
451 cperf_op_type_strs[CPERF_PDCP],
455 cperf_op_type_strs[CPERF_DOCSIS],
460 int id = get_str_key_id_mapping(optype_namemap,
461 RTE_DIM(optype_namemap), arg);
463 RTE_LOG(ERR, USER1, "invalid opt type specified\n");
467 opts->op_type = (enum cperf_op_type)id;
473 parse_sessionless(struct cperf_options *opts,
474 const char *arg __rte_unused)
476 opts->sessionless = 1;
481 parse_out_of_place(struct cperf_options *opts,
482 const char *arg __rte_unused)
484 opts->out_of_place = 1;
489 parse_test_file(struct cperf_options *opts,
492 opts->test_file = strdup(arg);
493 if (access(opts->test_file, F_OK) != -1)
495 RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
501 parse_test_name(struct cperf_options *opts,
504 char *test_name = (char *) rte_zmalloc(NULL,
505 sizeof(char) * (strlen(arg) + 3), 0);
506 snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
507 opts->test_name = test_name;
513 parse_silent(struct cperf_options *opts,
514 const char *arg __rte_unused)
522 parse_cipher_algo(struct cperf_options *opts, const char *arg)
525 enum rte_crypto_cipher_algorithm cipher_algo;
527 if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
528 RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
532 opts->cipher_algo = cipher_algo;
538 parse_cipher_op(struct cperf_options *opts, const char *arg)
540 struct name_id_map cipher_op_namemap[] = {
542 rte_crypto_cipher_operation_strings
543 [RTE_CRYPTO_CIPHER_OP_ENCRYPT],
544 RTE_CRYPTO_CIPHER_OP_ENCRYPT },
546 rte_crypto_cipher_operation_strings
547 [RTE_CRYPTO_CIPHER_OP_DECRYPT],
548 RTE_CRYPTO_CIPHER_OP_DECRYPT
552 int id = get_str_key_id_mapping(cipher_op_namemap,
553 RTE_DIM(cipher_op_namemap), arg);
555 RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
559 opts->cipher_op = (enum rte_crypto_cipher_operation)id;
565 parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
567 return parse_uint16_t(&opts->cipher_key_sz, arg);
571 parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
573 return parse_uint16_t(&opts->cipher_iv_sz, arg);
577 parse_auth_algo(struct cperf_options *opts, const char *arg)
579 enum rte_crypto_auth_algorithm auth_algo;
581 if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
582 RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
586 opts->auth_algo = auth_algo;
592 parse_auth_op(struct cperf_options *opts, const char *arg)
594 struct name_id_map auth_op_namemap[] = {
596 rte_crypto_auth_operation_strings
597 [RTE_CRYPTO_AUTH_OP_GENERATE],
598 RTE_CRYPTO_AUTH_OP_GENERATE },
600 rte_crypto_auth_operation_strings
601 [RTE_CRYPTO_AUTH_OP_VERIFY],
602 RTE_CRYPTO_AUTH_OP_VERIFY
606 int id = get_str_key_id_mapping(auth_op_namemap,
607 RTE_DIM(auth_op_namemap), arg);
609 RTE_LOG(ERR, USER1, "invalid authentication operation specified"
614 opts->auth_op = (enum rte_crypto_auth_operation)id;
620 parse_auth_key_sz(struct cperf_options *opts, const char *arg)
622 return parse_uint16_t(&opts->auth_key_sz, arg);
626 parse_digest_sz(struct cperf_options *opts, const char *arg)
628 return parse_uint16_t(&opts->digest_sz, arg);
631 #ifdef RTE_LIBRTE_SECURITY
633 parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
636 int ret = parse_uint32_t(&val, arg);
641 if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
642 val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
643 val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
644 val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
645 val != RTE_SECURITY_PDCP_SN_SIZE_18) {
646 printf("\nInvalid pdcp SN size: %u\n", val);
649 opts->pdcp_sn_sz = val;
654 const char *cperf_pdcp_domain_strs[] = {
655 [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
656 [RTE_SECURITY_PDCP_MODE_DATA] = "data"
660 parse_pdcp_domain(struct cperf_options *opts, const char *arg)
662 struct name_id_map pdcp_domain_namemap[] = {
664 cperf_pdcp_domain_strs
665 [RTE_SECURITY_PDCP_MODE_CONTROL],
666 RTE_SECURITY_PDCP_MODE_CONTROL },
668 cperf_pdcp_domain_strs
669 [RTE_SECURITY_PDCP_MODE_DATA],
670 RTE_SECURITY_PDCP_MODE_DATA
674 int id = get_str_key_id_mapping(pdcp_domain_namemap,
675 RTE_DIM(pdcp_domain_namemap), arg);
677 RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
682 opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
688 parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
690 return parse_uint16_t(&opts->docsis_hdr_sz, arg);
695 parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
697 return parse_uint16_t(&opts->auth_iv_sz, arg);
701 parse_aead_algo(struct cperf_options *opts, const char *arg)
703 enum rte_crypto_aead_algorithm aead_algo;
705 if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
706 RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
710 opts->aead_algo = aead_algo;
716 parse_aead_op(struct cperf_options *opts, const char *arg)
718 struct name_id_map aead_op_namemap[] = {
720 rte_crypto_aead_operation_strings
721 [RTE_CRYPTO_AEAD_OP_ENCRYPT],
722 RTE_CRYPTO_AEAD_OP_ENCRYPT },
724 rte_crypto_aead_operation_strings
725 [RTE_CRYPTO_AEAD_OP_DECRYPT],
726 RTE_CRYPTO_AEAD_OP_DECRYPT
730 int id = get_str_key_id_mapping(aead_op_namemap,
731 RTE_DIM(aead_op_namemap), arg);
733 RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
738 opts->aead_op = (enum rte_crypto_aead_operation)id;
744 parse_aead_key_sz(struct cperf_options *opts, const char *arg)
746 return parse_uint16_t(&opts->aead_key_sz, arg);
750 parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
752 return parse_uint16_t(&opts->aead_iv_sz, arg);
756 parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
758 return parse_uint16_t(&opts->aead_aad_sz, arg);
762 parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
770 parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
773 int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
776 RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
783 typedef int (*option_parser_t)(struct cperf_options *opts,
786 struct long_opt_parser {
787 const char *lgopt_name;
788 option_parser_t parser_fn;
792 static struct option lgopts[] = {
794 { CPERF_PTEST_TYPE, required_argument, 0, 0 },
796 { CPERF_POOL_SIZE, required_argument, 0, 0 },
797 { CPERF_TOTAL_OPS, required_argument, 0, 0 },
798 { CPERF_BURST_SIZE, required_argument, 0, 0 },
799 { CPERF_BUFFER_SIZE, required_argument, 0, 0 },
800 { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
801 { CPERF_DESC_NB, required_argument, 0, 0 },
803 { CPERF_IMIX, required_argument, 0, 0 },
804 { CPERF_DEVTYPE, required_argument, 0, 0 },
805 { CPERF_OPTYPE, required_argument, 0, 0 },
807 { CPERF_SILENT, no_argument, 0, 0 },
808 { CPERF_SESSIONLESS, no_argument, 0, 0 },
809 { CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
810 { CPERF_TEST_FILE, required_argument, 0, 0 },
811 { CPERF_TEST_NAME, required_argument, 0, 0 },
813 { CPERF_CIPHER_ALGO, required_argument, 0, 0 },
814 { CPERF_CIPHER_OP, required_argument, 0, 0 },
816 { CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
817 { CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
819 { CPERF_AUTH_ALGO, required_argument, 0, 0 },
820 { CPERF_AUTH_OP, required_argument, 0, 0 },
822 { CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
823 { CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
825 { CPERF_AEAD_ALGO, required_argument, 0, 0 },
826 { CPERF_AEAD_OP, required_argument, 0, 0 },
828 { CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
829 { CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
830 { CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
832 { CPERF_DIGEST_SZ, required_argument, 0, 0 },
834 #ifdef RTE_LIBRTE_SECURITY
835 { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
836 { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
837 { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
839 { CPERF_CSV, no_argument, 0, 0},
841 { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
847 cperf_options_default(struct cperf_options *opts)
849 opts->test = CPERF_TEST_TYPE_THROUGHPUT;
851 opts->pool_sz = 8192;
852 opts->total_ops = 10000000;
853 opts->nb_descriptors = 2048;
855 opts->buffer_size_list[0] = 64;
856 opts->buffer_size_count = 1;
857 opts->max_buffer_size = 64;
858 opts->min_buffer_size = 64;
859 opts->inc_buffer_size = 0;
861 opts->burst_size_list[0] = 32;
862 opts->burst_size_count = 1;
863 opts->max_burst_size = 32;
864 opts->min_burst_size = 32;
865 opts->inc_burst_size = 0;
868 * Will be parsed from command line or set to
869 * maximum buffer size + digest, later
871 opts->segment_sz = 0;
873 opts->imix_distribution_count = 0;
874 strncpy(opts->device_type, "crypto_aesni_mb",
875 sizeof(opts->device_type));
878 opts->op_type = CPERF_CIPHER_THEN_AUTH;
881 opts->test_file = NULL;
882 opts->test_name = NULL;
883 opts->sessionless = 0;
884 opts->out_of_place = 0;
887 opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
888 opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
889 opts->cipher_key_sz = 16;
890 opts->cipher_iv_sz = 16;
892 opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
893 opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
895 opts->auth_key_sz = 64;
896 opts->auth_iv_sz = 0;
898 opts->aead_key_sz = 0;
899 opts->aead_iv_sz = 0;
900 opts->aead_aad_sz = 0;
902 opts->digest_sz = 12;
904 opts->pmdcc_delay = 0;
905 #ifdef RTE_LIBRTE_SECURITY
906 opts->pdcp_sn_sz = 12;
907 opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
908 opts->docsis_hdr_sz = 17;
913 cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
915 struct long_opt_parser parsermap[] = {
916 { CPERF_PTEST_TYPE, parse_cperf_test_type },
917 { CPERF_SILENT, parse_silent },
918 { CPERF_POOL_SIZE, parse_pool_sz },
919 { CPERF_TOTAL_OPS, parse_total_ops },
920 { CPERF_BURST_SIZE, parse_burst_sz },
921 { CPERF_BUFFER_SIZE, parse_buffer_sz },
922 { CPERF_SEGMENT_SIZE, parse_segment_sz },
923 { CPERF_DESC_NB, parse_desc_nb },
924 { CPERF_DEVTYPE, parse_device_type },
925 { CPERF_OPTYPE, parse_op_type },
926 { CPERF_SESSIONLESS, parse_sessionless },
927 { CPERF_OUT_OF_PLACE, parse_out_of_place },
928 { CPERF_IMIX, parse_imix },
929 { CPERF_TEST_FILE, parse_test_file },
930 { CPERF_TEST_NAME, parse_test_name },
931 { CPERF_CIPHER_ALGO, parse_cipher_algo },
932 { CPERF_CIPHER_OP, parse_cipher_op },
933 { CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
934 { CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
935 { CPERF_AUTH_ALGO, parse_auth_algo },
936 { CPERF_AUTH_OP, parse_auth_op },
937 { CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
938 { CPERF_AUTH_IV_SZ, parse_auth_iv_sz },
939 { CPERF_AEAD_ALGO, parse_aead_algo },
940 { CPERF_AEAD_OP, parse_aead_op },
941 { CPERF_AEAD_KEY_SZ, parse_aead_key_sz },
942 { CPERF_AEAD_IV_SZ, parse_aead_iv_sz },
943 { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz },
944 { CPERF_DIGEST_SZ, parse_digest_sz },
945 #ifdef RTE_LIBRTE_SECURITY
946 { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz },
947 { CPERF_PDCP_DOMAIN, parse_pdcp_domain },
948 { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz },
950 { CPERF_CSV, parse_csv_friendly},
951 { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
955 for (i = 0; i < RTE_DIM(parsermap); i++) {
956 if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
957 strlen(lgopts[opt_idx].name)) == 0)
958 return parsermap[i].parser_fn(opts, optarg);
965 cperf_options_parse(struct cperf_options *options, int argc, char **argv)
967 int opt, retval, opt_idx;
969 while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
973 rte_exit(EXIT_SUCCESS, "Displayed help\n");
977 retval = cperf_opts_parse_long(opt_idx, options);
993 check_cipher_buffer_length(struct cperf_options *options)
995 uint32_t buffer_size, buffer_size_idx = 0;
997 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
998 options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
999 if (options->inc_buffer_size != 0)
1000 buffer_size = options->min_buffer_size;
1002 buffer_size = options->buffer_size_list[0];
1004 while (buffer_size <= options->max_buffer_size) {
1005 if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1006 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1007 "not suitable for the algorithm selected\n");
1011 if (options->inc_buffer_size != 0)
1012 buffer_size += options->inc_buffer_size;
1014 if (++buffer_size_idx == options->buffer_size_count)
1016 buffer_size = options->buffer_size_list[buffer_size_idx];
1022 if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1023 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1024 options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1025 if (options->inc_buffer_size != 0)
1026 buffer_size = options->min_buffer_size;
1028 buffer_size = options->buffer_size_list[0];
1030 while (buffer_size <= options->max_buffer_size) {
1031 if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1032 RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1033 "not suitable for the algorithm selected\n");
1037 if (options->inc_buffer_size != 0)
1038 buffer_size += options->inc_buffer_size;
1040 if (++buffer_size_idx == options->buffer_size_count)
1042 buffer_size = options->buffer_size_list[buffer_size_idx];
1051 #ifdef RTE_LIBRTE_SECURITY
1053 check_docsis_buffer_length(struct cperf_options *options)
1055 uint32_t buffer_size, buffer_size_idx = 0;
1057 if (options->inc_buffer_size != 0)
1058 buffer_size = options->min_buffer_size;
1060 buffer_size = options->buffer_size_list[0];
1062 while (buffer_size <= options->max_buffer_size) {
1063 if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1064 RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1065 RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1066 "valid for DOCSIS\n");
1070 if (options->inc_buffer_size != 0)
1071 buffer_size += options->inc_buffer_size;
1073 if (++buffer_size_idx == options->buffer_size_count)
1076 options->buffer_size_list[buffer_size_idx];
1085 cperf_options_check(struct cperf_options *options)
1087 if (options->op_type == CPERF_CIPHER_ONLY ||
1088 options->op_type == CPERF_DOCSIS)
1089 options->digest_sz = 0;
1091 if (options->out_of_place &&
1092 options->segment_sz <= options->max_buffer_size) {
1093 RTE_LOG(ERR, USER1, "Out of place mode can only work "
1094 "with non segmented buffers\n");
1099 * If segment size is not set, assume only one segment,
1100 * big enough to contain the largest buffer and the digest
1102 if (options->segment_sz == 0)
1103 options->segment_sz = options->max_buffer_size +
1106 if (options->segment_sz < options->digest_sz) {
1108 "Segment size should be at least "
1109 "the size of the digest\n");
1113 if ((options->imix_distribution_count != 0) &&
1114 (options->imix_distribution_count !=
1115 options->buffer_size_count)) {
1116 RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1117 "number of buffer sizes\n");
1121 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1122 options->test_file == NULL) {
1123 RTE_LOG(ERR, USER1, "Define path to the file with test"
1128 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1129 options->op_type != CPERF_CIPHER_ONLY &&
1130 options->test_name == NULL) {
1131 RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1132 " from the test vectors.\n");
1136 if (options->test_name != NULL && options->test_file == NULL) {
1137 RTE_LOG(ERR, USER1, "Define path to the file with test"
1142 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1143 options->test_file == NULL) {
1144 RTE_LOG(ERR, USER1, "Define path to the file with test"
1149 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1150 (options->inc_buffer_size != 0 ||
1151 options->buffer_size_count > 1)) {
1152 RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1153 "using the verify test.\n");
1157 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1158 (options->inc_burst_size != 0 ||
1159 options->burst_size_count > 1)) {
1160 RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1161 "using the verify test.\n");
1165 if (options->test == CPERF_TEST_TYPE_PMDCC &&
1166 options->pool_sz < options->nb_descriptors) {
1167 RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1168 "must be equal or greater than the number of "
1169 "cryptodev descriptors.\n");
1173 if (options->test == CPERF_TEST_TYPE_VERIFY &&
1174 options->imix_distribution_count > 0) {
1175 RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1176 "using the verify test.\n");
1180 if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1181 if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1183 RTE_CRYPTO_AUTH_OP_GENERATE) {
1184 RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1185 " options: encrypt and generate.\n");
1188 } else if (options->op_type == CPERF_AUTH_THEN_CIPHER) {
1189 if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1191 RTE_CRYPTO_AUTH_OP_VERIFY) {
1192 RTE_LOG(ERR, USER1, "Option auth then cipher must use"
1193 " options: decrypt and verify.\n");
1198 if (options->op_type == CPERF_CIPHER_ONLY ||
1199 options->op_type == CPERF_CIPHER_THEN_AUTH ||
1200 options->op_type == CPERF_AUTH_THEN_CIPHER) {
1201 if (check_cipher_buffer_length(options) < 0)
1205 #ifdef RTE_LIBRTE_SECURITY
1206 if (options->op_type == CPERF_DOCSIS) {
1207 if (check_docsis_buffer_length(options) < 0)
1216 cperf_options_dump(struct cperf_options *opts)
1220 printf("# Crypto Performance Application Options:\n");
1222 printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1224 printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1225 printf("# total number of ops: %u\n", opts->total_ops);
1226 if (opts->inc_buffer_size != 0) {
1227 printf("# buffer size:\n");
1228 printf("#\t min: %u\n", opts->min_buffer_size);
1229 printf("#\t max: %u\n", opts->max_buffer_size);
1230 printf("#\t inc: %u\n", opts->inc_buffer_size);
1232 printf("# buffer sizes: ");
1233 for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1234 printf("%u ", opts->buffer_size_list[size_idx]);
1237 if (opts->inc_burst_size != 0) {
1238 printf("# burst size:\n");
1239 printf("#\t min: %u\n", opts->min_burst_size);
1240 printf("#\t max: %u\n", opts->max_burst_size);
1241 printf("#\t inc: %u\n", opts->inc_burst_size);
1243 printf("# burst sizes: ");
1244 for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1245 printf("%u ", opts->burst_size_list[size_idx]);
1248 printf("\n# segment size: %u\n", opts->segment_sz);
1250 printf("# cryptodev type: %s\n", opts->device_type);
1252 printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1253 printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1254 printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1255 printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1256 if (opts->test == CPERF_TEST_TYPE_PMDCC)
1257 printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1261 if (opts->op_type == CPERF_AUTH_ONLY ||
1262 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1263 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1264 printf("# auth algorithm: %s\n",
1265 rte_crypto_auth_algorithm_strings[opts->auth_algo]);
1266 printf("# auth operation: %s\n",
1267 rte_crypto_auth_operation_strings[opts->auth_op]);
1268 printf("# auth key size: %u\n", opts->auth_key_sz);
1269 printf("# auth iv size: %u\n", opts->auth_iv_sz);
1270 printf("# auth digest size: %u\n", opts->digest_sz);
1274 if (opts->op_type == CPERF_CIPHER_ONLY ||
1275 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1276 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1277 printf("# cipher algorithm: %s\n",
1278 rte_crypto_cipher_algorithm_strings[opts->cipher_algo]);
1279 printf("# cipher operation: %s\n",
1280 rte_crypto_cipher_operation_strings[opts->cipher_op]);
1281 printf("# cipher key size: %u\n", opts->cipher_key_sz);
1282 printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1286 if (opts->op_type == CPERF_AEAD) {
1287 printf("# aead algorithm: %s\n",
1288 rte_crypto_aead_algorithm_strings[opts->aead_algo]);
1289 printf("# aead operation: %s\n",
1290 rte_crypto_aead_operation_strings[opts->aead_op]);
1291 printf("# aead key size: %u\n", opts->aead_key_sz);
1292 printf("# aead iv size: %u\n", opts->aead_iv_sz);
1293 printf("# aead digest size: %u\n", opts->digest_sz);
1294 printf("# aead aad size: %u\n", opts->aead_aad_sz);
1298 #ifdef RTE_LIBRTE_SECURITY
1299 if (opts->op_type == CPERF_DOCSIS) {
1300 printf("# docsis header size: %u\n", opts->docsis_hdr_sz);