X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest-crypto-perf%2Fcperf_options_parsing.c;h=0348972c85e7c7a3b4a5b24b6cd633f59912f4b1;hb=ded0d2c0aaca537e282f3ab9b0691148b87c1c26;hp=f3508a474d55e1e030b5b07dba658dbd63a7d672;hpb=96dfeb609be100d74cdbf7fb2cc3c30b85879163;p=dpdk.git diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index f3508a474d..0348972c85 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -1,33 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2016-2017 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2016-2017 Intel Corporation */ #include @@ -35,6 +7,7 @@ #include #include +#include #include "cperf_options.h" @@ -46,6 +19,54 @@ struct name_id_map { uint32_t id; }; +static void +usage(char *progname) +{ + printf("%s [EAL options] --\n" + " --silent: disable options dump\n" + " --ptest throughput / latency / verify / pmd-cyclecount :" + " set test type\n" + " --pool_sz N: set the number of crypto ops/mbufs allocated\n" + " --total-ops N: set the number of total operations performed\n" + " --burst-sz N: set the number of packets per burst\n" + " --buffer-sz N: set the size of a single packet\n" + " --imix N: set the distribution of packet sizes\n" + " --segment-sz N: set the size of the segment to use\n" + " --desc-nb N: set number of descriptors for each crypto device\n" + " --devtype TYPE: set crypto device type to use\n" + " --optype cipher-only / auth-only / cipher-then-auth /\n" + " auth-then-cipher / aead : set operation type\n" + " --sessionless: enable session-less crypto operations\n" + " --out-of-place: enable out-of-place crypto operations\n" + " --test-file NAME: set the test vector file path\n" + " --test-name NAME: set specific test name section in test file\n" + " --cipher-algo ALGO: set cipher algorithm\n" + " --cipher-op encrypt / decrypt: set the cipher operation\n" + " --cipher-key-sz N: set the cipher key size\n" + " --cipher-iv-sz N: set the cipher IV size\n" + " --auth-algo ALGO: set auth algorithm\n" + " --auth-op generate / verify: set the auth operation\n" + " --auth-key-sz N: set the auth key size\n" + " --auth-iv-sz N: set the auth IV size\n" + " --aead-algo ALGO: set AEAD algorithm\n" + " --aead-op encrypt / decrypt: set the AEAD operation\n" + " --aead-key-sz N: set the AEAD key size\n" + " --aead-iv-sz N: set the AEAD IV size\n" + " --aead-aad-sz N: set the AEAD AAD size\n" + " --digest-sz N: set the digest size\n" + " --pmd-cyclecount-delay-ms N: set delay between enqueue\n" + " and dequeue in pmd-cyclecount benchmarking mode\n" + " --csv-friendly: enable test result output CSV friendly\n" +#ifdef RTE_LIB_SECURITY + " --pdcp-sn-sz N: set PDCP SN size N <5/7/12/15/18>\n" + " --pdcp-domain DOMAIN: set PDCP domain \n" + " --pdcp-ses-hfn-en: enable session based fixed HFN\n" + " --docsis-hdr-sz: set DOCSIS header size\n" +#endif + " -h: prints this help\n", + progname); +} + static int get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len, const char *str_key) @@ -202,6 +223,8 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) char *token; uint32_t number; uint8_t count = 0; + uint32_t temp_min; + uint32_t temp_max; char *copy_arg = strdup(arg); @@ -220,8 +243,8 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) goto err_list; list[count++] = number; - *min = number; - *max = number; + temp_min = number; + temp_max = number; } else goto err_list; @@ -242,14 +265,19 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) list[count++] = number; - if (number < *min) - *min = number; - if (number > *max) - *max = number; + if (number < temp_min) + temp_min = number; + if (number > temp_max) + temp_max = number; token = strtok(NULL, ","); } + if (min) + *min = temp_min; + if (max) + *max = temp_max; + free(copy_arg); return count; @@ -328,17 +356,40 @@ parse_buffer_sz(struct cperf_options *opts, const char *arg) } static int -parse_segments_nb(struct cperf_options *opts, const char *arg) +parse_segment_sz(struct cperf_options *opts, const char *arg) { - int ret = parse_uint32_t(&opts->segments_nb, arg); + int ret = parse_uint32_t(&opts->segment_sz, arg); if (ret) { - RTE_LOG(ERR, USER1, "failed to parse segments number\n"); + RTE_LOG(ERR, USER1, "failed to parse segment size\n"); + return -1; + } + + if (opts->segment_sz == 0) { + RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n"); + return -1; + } + + return 0; +} + +static int +parse_imix(struct cperf_options *opts, const char *arg) +{ + int ret; + + ret = parse_list(arg, opts->imix_distribution_list, + NULL, NULL); + if (ret < 0) { + RTE_LOG(ERR, USER1, "failed to parse imix distribution\n"); return -1; } - if ((opts->segments_nb == 0) || (opts->segments_nb > 255)) { - RTE_LOG(ERR, USER1, "invalid segments number specified\n"); + opts->imix_distribution_count = ret; + + if (opts->imix_distribution_count <= 1) { + RTE_LOG(ERR, USER1, "imix distribution should have " + "at least two entries\n"); return -1; } @@ -398,6 +449,14 @@ parse_op_type(struct cperf_options *opts, const char *arg) { cperf_op_type_strs[CPERF_AEAD], CPERF_AEAD + }, + { + cperf_op_type_strs[CPERF_PDCP], + CPERF_PDCP + }, + { + cperf_op_type_strs[CPERF_DOCSIS], + CPERF_DOCSIS } }; @@ -447,6 +506,12 @@ parse_test_name(struct cperf_options *opts, { char *test_name = (char *) rte_zmalloc(NULL, sizeof(char) * (strlen(arg) + 3), 0); + if (test_name == NULL) { + RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n", + strlen(arg) + 3); + return -1; + } + snprintf(test_name, strlen(arg) + 3, "[%s]", arg); opts->test_name = test_name; @@ -572,6 +637,82 @@ parse_digest_sz(struct cperf_options *opts, const char *arg) return parse_uint16_t(&opts->digest_sz, arg); } +#ifdef RTE_LIB_SECURITY +static int +parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg) +{ + uint32_t val = 0; + int ret = parse_uint32_t(&val, arg); + + if (ret < 0) + return ret; + + if (val != RTE_SECURITY_PDCP_SN_SIZE_5 && + val != RTE_SECURITY_PDCP_SN_SIZE_7 && + val != RTE_SECURITY_PDCP_SN_SIZE_12 && + val != RTE_SECURITY_PDCP_SN_SIZE_15 && + val != RTE_SECURITY_PDCP_SN_SIZE_18) { + printf("\nInvalid pdcp SN size: %u\n", val); + return -ERANGE; + } + opts->pdcp_sn_sz = val; + + return 0; +} + +const char *cperf_pdcp_domain_strs[] = { + [RTE_SECURITY_PDCP_MODE_CONTROL] = "control", + [RTE_SECURITY_PDCP_MODE_DATA] = "data", + [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac" +}; + +static int +parse_pdcp_domain(struct cperf_options *opts, const char *arg) +{ + struct name_id_map pdcp_domain_namemap[] = { + { + cperf_pdcp_domain_strs + [RTE_SECURITY_PDCP_MODE_CONTROL], + RTE_SECURITY_PDCP_MODE_CONTROL }, + { + cperf_pdcp_domain_strs + [RTE_SECURITY_PDCP_MODE_DATA], + RTE_SECURITY_PDCP_MODE_DATA + }, + { + cperf_pdcp_domain_strs + [RTE_SECURITY_PDCP_MODE_SHORT_MAC], + RTE_SECURITY_PDCP_MODE_SHORT_MAC + } + }; + + int id = get_str_key_id_mapping(pdcp_domain_namemap, + RTE_DIM(pdcp_domain_namemap), arg); + if (id < 0) { + RTE_LOG(ERR, USER1, "invalid pdcp domain specified" + "\n"); + return -1; + } + + opts->pdcp_domain = (enum rte_security_pdcp_domain)id; + + return 0; +} + +static int +parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused) +{ + opts->pdcp_ses_hfn_en = 1; + return 0; +} + +static int +parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg) +{ + return parse_uint16_t(&opts->docsis_hdr_sz, arg); +} +#endif + static int parse_auth_iv_sz(struct cperf_options *opts, const char *arg) { @@ -678,9 +819,10 @@ static struct option lgopts[] = { { CPERF_TOTAL_OPS, required_argument, 0, 0 }, { CPERF_BURST_SIZE, required_argument, 0, 0 }, { CPERF_BUFFER_SIZE, required_argument, 0, 0 }, - { CPERF_SEGMENTS_NB, required_argument, 0, 0 }, + { CPERF_SEGMENT_SIZE, required_argument, 0, 0 }, { CPERF_DESC_NB, required_argument, 0, 0 }, + { CPERF_IMIX, required_argument, 0, 0 }, { CPERF_DEVTYPE, required_argument, 0, 0 }, { CPERF_OPTYPE, required_argument, 0, 0 }, @@ -711,6 +853,12 @@ static struct option lgopts[] = { { CPERF_DIGEST_SZ, required_argument, 0, 0 }, +#ifdef RTE_LIB_SECURITY + { CPERF_PDCP_SN_SZ, required_argument, 0, 0 }, + { CPERF_PDCP_DOMAIN, required_argument, 0, 0 }, + { CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 }, + { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 }, +#endif { CPERF_CSV, no_argument, 0, 0}, { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 }, @@ -739,10 +887,16 @@ cperf_options_default(struct cperf_options *opts) opts->min_burst_size = 32; opts->inc_burst_size = 0; - opts->segments_nb = 1; + /* + * Will be parsed from command line or set to + * maximum buffer size + digest, later + */ + opts->segment_sz = 0; + opts->imix_distribution_count = 0; strncpy(opts->device_type, "crypto_aesni_mb", sizeof(opts->device_type)); + opts->nb_qps = 1; opts->op_type = CPERF_CIPHER_THEN_AUTH; @@ -771,6 +925,12 @@ cperf_options_default(struct cperf_options *opts) opts->digest_sz = 12; opts->pmdcc_delay = 0; +#ifdef RTE_LIB_SECURITY + opts->pdcp_sn_sz = 12; + opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL; + opts->pdcp_ses_hfn_en = 0; + opts->docsis_hdr_sz = 17; +#endif } static int @@ -783,12 +943,13 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts) { CPERF_TOTAL_OPS, parse_total_ops }, { CPERF_BURST_SIZE, parse_burst_sz }, { CPERF_BUFFER_SIZE, parse_buffer_sz }, - { CPERF_SEGMENTS_NB, parse_segments_nb }, + { CPERF_SEGMENT_SIZE, parse_segment_sz }, { CPERF_DESC_NB, parse_desc_nb }, { CPERF_DEVTYPE, parse_device_type }, { CPERF_OPTYPE, parse_op_type }, { CPERF_SESSIONLESS, parse_sessionless }, { CPERF_OUT_OF_PLACE, parse_out_of_place }, + { CPERF_IMIX, parse_imix }, { CPERF_TEST_FILE, parse_test_file }, { CPERF_TEST_NAME, parse_test_name }, { CPERF_CIPHER_ALGO, parse_cipher_algo }, @@ -805,6 +966,12 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts) { CPERF_AEAD_IV_SZ, parse_aead_iv_sz }, { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz }, { CPERF_DIGEST_SZ, parse_digest_sz }, +#ifdef RTE_LIB_SECURITY + { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz }, + { CPERF_PDCP_DOMAIN, parse_pdcp_domain }, + { CPERF_PDCP_SES_HFN_EN, parse_pdcp_ses_hfn_en }, + { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz }, +#endif { CPERF_CSV, parse_csv_friendly}, { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms}, }; @@ -824,11 +991,14 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv) { int opt, retval, opt_idx; - while ((opt = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) { + while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) { switch (opt) { + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + break; /* long options */ case 0: - retval = cperf_opts_parse_long(opt_idx, options); if (retval != 0) return retval; @@ -836,6 +1006,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv) break; default: + usage(argv[0]); return -EINVAL; } } @@ -876,26 +1047,99 @@ check_cipher_buffer_length(struct cperf_options *options) if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC || options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC || options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) { - for (buffer_size = options->min_buffer_size; - buffer_size < options->max_buffer_size; - buffer_size += options->inc_buffer_size) { + if (options->inc_buffer_size != 0) + buffer_size = options->min_buffer_size; + else + buffer_size = options->buffer_size_list[0]; + + while (buffer_size <= options->max_buffer_size) { if ((buffer_size % DES_BLOCK_SIZE) != 0) { RTE_LOG(ERR, USER1, "Some of the buffer sizes are " "not suitable for the algorithm selected\n"); return -EINVAL; } + + if (options->inc_buffer_size != 0) + buffer_size += options->inc_buffer_size; + else { + if (++buffer_size_idx == options->buffer_size_count) + break; + buffer_size = options->buffer_size_list[buffer_size_idx]; + } + } } return 0; } +#ifdef RTE_LIB_SECURITY +static int +check_docsis_buffer_length(struct cperf_options *options) +{ + uint32_t buffer_size, buffer_size_idx = 0; + + if (options->inc_buffer_size != 0) + buffer_size = options->min_buffer_size; + else + buffer_size = options->buffer_size_list[0]; + + while (buffer_size <= options->max_buffer_size) { + if (buffer_size < (uint32_t)(options->docsis_hdr_sz + + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) { + RTE_LOG(ERR, USER1, "Some of the buffer sizes are not " + "valid for DOCSIS\n"); + return -EINVAL; + } + + if (options->inc_buffer_size != 0) + buffer_size += options->inc_buffer_size; + else { + if (++buffer_size_idx == options->buffer_size_count) + break; + buffer_size = + options->buffer_size_list[buffer_size_idx]; + } + } + + return 0; +} +#endif + int cperf_options_check(struct cperf_options *options) { - if (options->segments_nb > options->min_buffer_size) { + if (options->op_type == CPERF_CIPHER_ONLY || + options->op_type == CPERF_DOCSIS) + options->digest_sz = 0; + + if (options->out_of_place && + options->segment_sz <= options->max_buffer_size) { + RTE_LOG(ERR, USER1, "Out of place mode can only work " + "with non segmented buffers\n"); + return -EINVAL; + } + + /* + * If segment size is not set, assume only one segment, + * big enough to contain the largest buffer and the digest + */ + if (options->segment_sz == 0) + options->segment_sz = options->max_buffer_size + + options->digest_sz; + + if (options->segment_sz < options->digest_sz) { RTE_LOG(ERR, USER1, - "Segments number greater than buffer size.\n"); + "Segment size should be at least " + "the size of the digest\n"); + return -EINVAL; + } + + if ((options->imix_distribution_count != 0) && + (options->imix_distribution_count != + options->buffer_size_count)) { + RTE_LOG(ERR, USER1, "IMIX distribution must have the same " + "number of buffer sizes\n"); return -EINVAL; } @@ -927,13 +1171,6 @@ cperf_options_check(struct cperf_options *options) return -EINVAL; } - if (options->test == CPERF_TEST_TYPE_VERIFY && - options->total_ops > options->pool_sz) { - RTE_LOG(ERR, USER1, "Total number of ops must be less than or" - " equal to the pool size.\n"); - return -EINVAL; - } - if (options->test == CPERF_TEST_TYPE_VERIFY && (options->inc_buffer_size != 0 || options->buffer_size_count > 1)) { @@ -958,6 +1195,13 @@ cperf_options_check(struct cperf_options *options) return -EINVAL; } + if (options->test == CPERF_TEST_TYPE_VERIFY && + options->imix_distribution_count > 0) { + RTE_LOG(ERR, USER1, "IMIX is not allowed when " + "using the verify test.\n"); + return -EINVAL; + } + if (options->op_type == CPERF_CIPHER_THEN_AUTH) { if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT && options->auth_op != @@ -983,6 +1227,13 @@ cperf_options_check(struct cperf_options *options) return -EINVAL; } +#ifdef RTE_LIB_SECURITY + if (options->op_type == CPERF_DOCSIS) { + if (check_docsis_buffer_length(options) < 0) + return -EINVAL; + } +#endif + return 0; } @@ -1019,10 +1270,11 @@ cperf_options_dump(struct cperf_options *opts) printf("%u ", opts->burst_size_list[size_idx]); printf("\n"); } - printf("\n# segments per buffer: %u\n", opts->segments_nb); + printf("\n# segment size: %u\n", opts->segment_sz); printf("#\n"); printf("# cryptodev type: %s\n", opts->device_type); printf("#\n"); + printf("# number of queue pairs per device: %u\n", opts->nb_qps); printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]); printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no"); printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no"); @@ -1067,4 +1319,11 @@ cperf_options_dump(struct cperf_options *opts) printf("# aead aad size: %u\n", opts->aead_aad_sz); printf("#\n"); } + +#ifdef RTE_LIB_SECURITY + if (opts->op_type == CPERF_DOCSIS) { + printf("# docsis header size: %u\n", opts->docsis_hdr_sz); + printf("#\n"); + } +#endif }