numam-dpdk/app/test-crypto-perf/cperf_options_parsing.c
Slawomir Mrozowicz f8be1786b1 app/crypto-perf: introduce performance test application
This patchset introduce new application which allows measuring
performance parameters of PMDs available in crypto tree. The goal of
this application is to replace existing performance tests in app/test.
Parameters available are: throughput (--ptest throughput) and latency
(--ptest latency). User can use multiply cores to run tests on but only
one type of crypto PMD can be measured during single application
execution. Cipher parameters, type of device, type of operation and
chain mode have to be specified in the command line as application
parameters. These parameters are checked using device capabilities
structure.
Couple of new library functions in librte_cryptodev are introduced for
application use.
To build the application a CONFIG_RTE_APP_CRYPTO_PERF flag has to be set
(it is set by default).
Example of usage: -c 0xc0 --vdev crypto_aesni_mb_pmd -w 0000:00:00.0 --
--ptest throughput --devtype crypto_aesni_mb --optype cipher-then-auth
--cipher-algo aes-cbc --cipher-op encrypt --cipher-key-sz 16 --auth-algo
sha1-hmac --auth-op generate --auth-key-sz 64 --auth-digest-sz 12
--total-ops 10000000 --burst-sz 32 --buffer-sz 64

Signed-off-by: Declan Doherty <declan.doherty@intel.com>
Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
Signed-off-by: Piotr Azarewicz <piotrx.t.azarewicz@intel.com>
Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
Signed-off-by: Michal Kobylinski <michalx.kobylinski@intel.com>
2017-01-30 17:46:36 +01:00

877 lines
20 KiB
C

/*-
* 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.
*/
#include <getopt.h>
#include <unistd.h>
#include <rte_malloc.h>
#include "cperf_options.h"
struct name_id_map {
const char *name;
uint32_t id;
};
static int
get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
const char *str_key)
{
unsigned int i;
for (i = 0; i < map_len; i++) {
if (strcmp(str_key, map[i].name) == 0)
return map[i].id;
}
return -1;
}
static int
parse_cperf_test_type(struct cperf_options *opts, const char *arg)
{
struct name_id_map cperftest_namemap[] = {
{
cperf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
CPERF_TEST_TYPE_THROUGHPUT
},
{
cperf_test_type_strs[CPERF_TEST_TYPE_CYCLECOUNT],
CPERF_TEST_TYPE_CYCLECOUNT
},
{
cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY],
CPERF_TEST_TYPE_LATENCY
}
};
int id = get_str_key_id_mapping(
(struct name_id_map *)cperftest_namemap,
RTE_DIM(cperftest_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "failed to parse test type");
return -1;
}
opts->test = (enum cperf_perf_test_type)id;
return 0;
}
static int
parse_uint32_t(uint32_t *value, const char *arg)
{
char *end = NULL;
unsigned long n = strtoul(arg, &end, 10);
if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
return -1;
if (n > UINT32_MAX)
return -ERANGE;
*value = (uint32_t) n;
return 0;
}
static int
parse_uint16_t(uint16_t *value, const char *arg)
{
uint32_t val = 0;
int ret = parse_uint32_t(&val, arg);
if (ret < 0)
return ret;
if (val > UINT16_MAX)
return -ERANGE;
*value = (uint16_t) val;
return 0;
}
static int
parse_total_ops(struct cperf_options *opts, const char *arg)
{
int ret = parse_uint32_t(&opts->total_ops, arg);
if (ret)
RTE_LOG(ERR, USER1, "failed to parse total operations count");
return ret;
}
static int
parse_pool_sz(struct cperf_options *opts, const char *arg)
{
int ret = parse_uint32_t(&opts->pool_sz, arg);
if (ret)
RTE_LOG(ERR, USER1, "failed to parse pool size");
return ret;
}
static int
parse_burst_sz(struct cperf_options *opts, const char *arg)
{
int ret = parse_uint32_t(&opts->burst_sz, arg);
if (ret)
RTE_LOG(ERR, USER1, "failed to parse burst size");
return ret;
}
static int
parse_buffer_sz(struct cperf_options *opts, const char *arg)
{
uint32_t i, valid_buf_sz[] = {
32, 64, 128, 256, 384, 512, 768, 1024, 1280, 1536, 1792,
2048
};
if (parse_uint32_t(&opts->buffer_sz, arg)) {
RTE_LOG(ERR, USER1, "failed to parse buffer size");
return -1;
}
for (i = 0; i < RTE_DIM(valid_buf_sz); i++)
if (valid_buf_sz[i] == opts->buffer_sz)
return 0;
RTE_LOG(ERR, USER1, "invalid buffer size specified");
return -1;
}
static int
parse_segments_nb(struct cperf_options *opts, const char *arg)
{
int ret = parse_uint32_t(&opts->segments_nb, arg);
if (ret) {
RTE_LOG(ERR, USER1, "failed to parse segments number\n");
return -1;
}
if ((opts->segments_nb == 0) || (opts->segments_nb > 255)) {
RTE_LOG(ERR, USER1, "invalid segments number specified\n");
return -1;
}
return 0;
}
static int
parse_device_type(struct cperf_options *opts, const char *arg)
{
if (strlen(arg) > (sizeof(opts->device_type) - 1))
return -1;
strncpy(opts->device_type, arg, sizeof(opts->device_type));
return 0;
}
static int
parse_op_type(struct cperf_options *opts, const char *arg)
{
struct name_id_map optype_namemap[] = {
{
cperf_op_type_strs[CPERF_CIPHER_ONLY],
CPERF_CIPHER_ONLY
},
{
cperf_op_type_strs[CPERF_AUTH_ONLY],
CPERF_AUTH_ONLY
},
{
cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
CPERF_CIPHER_THEN_AUTH
},
{
cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
CPERF_AUTH_THEN_CIPHER
},
{
cperf_op_type_strs[CPERF_AEAD],
CPERF_AEAD
}
};
int id = get_str_key_id_mapping(optype_namemap,
RTE_DIM(optype_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "invalid opt type specified\n");
return -1;
}
opts->op_type = (enum cperf_op_type)id;
return 0;
}
static int
parse_sessionless(struct cperf_options *opts,
const char *arg __rte_unused)
{
opts->sessionless = 1;
return 0;
}
static int
parse_out_of_place(struct cperf_options *opts,
const char *arg __rte_unused)
{
opts->out_of_place = 1;
return 0;
}
static int
parse_verify(struct cperf_options *opts,
const char *arg __rte_unused)
{
opts->verify = 1;
return 0;
}
static int
parse_test_file(struct cperf_options *opts,
const char *arg)
{
opts->test_file = strdup(arg);
if (access(opts->test_file, F_OK) != -1)
return 0;
RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
return -1;
}
static int
parse_test_name(struct cperf_options *opts,
const char *arg)
{
char *test_name = (char *) rte_zmalloc(NULL,
sizeof(char) * (strlen(arg) + 3), 0);
snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
opts->test_name = test_name;
return 0;
}
static int
parse_silent(struct cperf_options *opts,
const char *arg __rte_unused)
{
opts->silent = 1;
return 0;
}
static int
parse_cipher_algo(struct cperf_options *opts, const char *arg)
{
struct name_id_map cipher_algo_namemap[] = {
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_3DES_CBC],
RTE_CRYPTO_CIPHER_3DES_CBC
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_3DES_ECB],
RTE_CRYPTO_CIPHER_3DES_ECB
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_3DES_CTR],
RTE_CRYPTO_CIPHER_3DES_CTR
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_CBC],
RTE_CRYPTO_CIPHER_AES_CBC
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_CCM],
RTE_CRYPTO_CIPHER_AES_CCM
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_CTR],
RTE_CRYPTO_CIPHER_AES_CTR
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_ECB],
RTE_CRYPTO_CIPHER_AES_ECB
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_GCM],
RTE_CRYPTO_CIPHER_AES_GCM
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_F8],
RTE_CRYPTO_CIPHER_AES_F8
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_AES_XTS],
RTE_CRYPTO_CIPHER_AES_XTS
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_ARC4],
RTE_CRYPTO_CIPHER_ARC4
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_NULL],
RTE_CRYPTO_CIPHER_NULL
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_KASUMI_F8],
RTE_CRYPTO_CIPHER_KASUMI_F8
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_SNOW3G_UEA2],
RTE_CRYPTO_CIPHER_SNOW3G_UEA2
},
{
rte_crypto_cipher_algorithm_strings
[RTE_CRYPTO_CIPHER_ZUC_EEA3],
RTE_CRYPTO_CIPHER_ZUC_EEA3
},
};
int id = get_str_key_id_mapping(cipher_algo_namemap,
RTE_DIM(cipher_algo_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
return -1;
}
opts->cipher_algo = (enum rte_crypto_cipher_algorithm)id;
return 0;
}
static int
parse_cipher_op(struct cperf_options *opts, const char *arg)
{
struct name_id_map cipher_op_namemap[] = {
{
rte_crypto_cipher_operation_strings
[RTE_CRYPTO_CIPHER_OP_ENCRYPT],
RTE_CRYPTO_CIPHER_OP_ENCRYPT },
{
rte_crypto_cipher_operation_strings
[RTE_CRYPTO_CIPHER_OP_DECRYPT],
RTE_CRYPTO_CIPHER_OP_DECRYPT
}
};
int id = get_str_key_id_mapping(cipher_op_namemap,
RTE_DIM(cipher_op_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
return -1;
}
opts->cipher_op = (enum rte_crypto_cipher_operation)id;
return 0;
}
static int
parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
{
return parse_uint16_t(&opts->cipher_key_sz, arg);
}
static int
parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
{
return parse_uint16_t(&opts->cipher_iv_sz, arg);
}
static int
parse_auth_algo(struct cperf_options *opts, const char *arg) {
struct name_id_map cipher_auth_namemap[] = {
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_CBC_MAC],
RTE_CRYPTO_AUTH_AES_CBC_MAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_CCM],
RTE_CRYPTO_AUTH_AES_CCM
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_CMAC],
RTE_CRYPTO_AUTH_AES_CMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_GCM],
RTE_CRYPTO_AUTH_AES_GCM
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_GMAC],
RTE_CRYPTO_AUTH_AES_GMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_AES_XCBC_MAC],
RTE_CRYPTO_AUTH_AES_XCBC_MAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_MD5],
RTE_CRYPTO_AUTH_MD5
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_MD5_HMAC],
RTE_CRYPTO_AUTH_MD5_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA1],
RTE_CRYPTO_AUTH_SHA1
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA1_HMAC],
RTE_CRYPTO_AUTH_SHA1_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA224],
RTE_CRYPTO_AUTH_SHA224
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA224_HMAC],
RTE_CRYPTO_AUTH_SHA224_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA256],
RTE_CRYPTO_AUTH_SHA256
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA256_HMAC],
RTE_CRYPTO_AUTH_SHA256_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA384],
RTE_CRYPTO_AUTH_SHA384
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA384_HMAC],
RTE_CRYPTO_AUTH_SHA384_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA512],
RTE_CRYPTO_AUTH_SHA512
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SHA512_HMAC],
RTE_CRYPTO_AUTH_SHA512_HMAC
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_KASUMI_F9],
RTE_CRYPTO_AUTH_KASUMI_F9
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_SNOW3G_UIA2],
RTE_CRYPTO_AUTH_SNOW3G_UIA2
},
{
rte_crypto_auth_algorithm_strings
[RTE_CRYPTO_AUTH_ZUC_EIA3],
RTE_CRYPTO_AUTH_ZUC_EIA3
},
};
int id = get_str_key_id_mapping(cipher_auth_namemap,
RTE_DIM(cipher_auth_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "invalid authentication algorithm specified"
"\n");
return -1;
}
opts->auth_algo = (enum rte_crypto_auth_algorithm)id;
return 0;
}
static int
parse_auth_op(struct cperf_options *opts, const char *arg)
{
struct name_id_map auth_op_namemap[] = {
{
rte_crypto_auth_operation_strings
[RTE_CRYPTO_AUTH_OP_GENERATE],
RTE_CRYPTO_AUTH_OP_GENERATE },
{
rte_crypto_auth_operation_strings
[RTE_CRYPTO_AUTH_OP_VERIFY],
RTE_CRYPTO_AUTH_OP_VERIFY
}
};
int id = get_str_key_id_mapping(auth_op_namemap,
RTE_DIM(auth_op_namemap), arg);
if (id < 0) {
RTE_LOG(ERR, USER1, "invalid authentication operation specified"
"\n");
return -1;
}
opts->auth_op = (enum rte_crypto_auth_operation)id;
return 0;
}
static int
parse_auth_key_sz(struct cperf_options *opts, const char *arg)
{
return parse_uint16_t(&opts->auth_key_sz, arg);
}
static int
parse_auth_digest_sz(struct cperf_options *opts, const char *arg)
{
return parse_uint16_t(&opts->auth_digest_sz, arg);
}
static int
parse_auth_aad_sz(struct cperf_options *opts, const char *arg)
{
return parse_uint16_t(&opts->auth_aad_sz, arg);
}
static int
parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
{
opts->csv = 1;
opts->silent = 1;
return 0;
}
typedef int (*option_parser_t)(struct cperf_options *opts,
const char *arg);
struct long_opt_parser {
const char *lgopt_name;
option_parser_t parser_fn;
};
static struct option lgopts[] = {
{ CPERF_PTEST_TYPE, required_argument, 0, 0 },
{ CPERF_POOL_SIZE, required_argument, 0, 0 },
{ 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_DEVTYPE, required_argument, 0, 0 },
{ CPERF_OPTYPE, required_argument, 0, 0 },
{ CPERF_SILENT, no_argument, 0, 0 },
{ CPERF_SESSIONLESS, no_argument, 0, 0 },
{ CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
{ CPERF_VERIFY, no_argument, 0, 0 },
{ CPERF_TEST_FILE, required_argument, 0, 0 },
{ CPERF_TEST_NAME, required_argument, 0, 0 },
{ CPERF_CIPHER_ALGO, required_argument, 0, 0 },
{ CPERF_CIPHER_OP, required_argument, 0, 0 },
{ CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
{ CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
{ CPERF_AUTH_ALGO, required_argument, 0, 0 },
{ CPERF_AUTH_OP, required_argument, 0, 0 },
{ CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
{ CPERF_AUTH_DIGEST_SZ, required_argument, 0, 0 },
{ CPERF_AUTH_AAD_SZ, required_argument, 0, 0 },
{ CPERF_CSV, no_argument, 0, 0},
{ NULL, 0, 0, 0 }
};
void
cperf_options_default(struct cperf_options *opts)
{
opts->test = CPERF_TEST_TYPE_THROUGHPUT;
opts->pool_sz = 8192;
opts->total_ops = 10000000;
opts->burst_sz = 32;
opts->buffer_sz = 64;
opts->segments_nb = 1;
strncpy(opts->device_type, "crypto_aesni_mb",
sizeof(opts->device_type));
opts->op_type = CPERF_CIPHER_THEN_AUTH;
opts->silent = 0;
opts->verify = 0;
opts->test_file = NULL;
opts->test_name = NULL;
opts->sessionless = 0;
opts->out_of_place = 0;
opts->csv = 0;
opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
opts->cipher_key_sz = 16;
opts->cipher_iv_sz = 16;
opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
opts->auth_key_sz = 64;
opts->auth_digest_sz = 12;
opts->auth_aad_sz = 0;
}
static int
cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
{
struct long_opt_parser parsermap[] = {
{ CPERF_PTEST_TYPE, parse_cperf_test_type },
{ CPERF_SILENT, parse_silent },
{ CPERF_POOL_SIZE, parse_pool_sz },
{ 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_DEVTYPE, parse_device_type },
{ CPERF_OPTYPE, parse_op_type },
{ CPERF_SESSIONLESS, parse_sessionless },
{ CPERF_OUT_OF_PLACE, parse_out_of_place },
{ CPERF_VERIFY, parse_verify },
{ CPERF_TEST_FILE, parse_test_file },
{ CPERF_TEST_NAME, parse_test_name },
{ CPERF_CIPHER_ALGO, parse_cipher_algo },
{ CPERF_CIPHER_OP, parse_cipher_op },
{ CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
{ CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
{ CPERF_AUTH_ALGO, parse_auth_algo },
{ CPERF_AUTH_OP, parse_auth_op },
{ CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
{ CPERF_AUTH_DIGEST_SZ, parse_auth_digest_sz },
{ CPERF_AUTH_AAD_SZ, parse_auth_aad_sz },
{ CPERF_CSV, parse_csv_friendly},
};
unsigned int i;
for (i = 0; i < RTE_DIM(parsermap); i++) {
if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
strlen(lgopts[opt_idx].name)) == 0)
return parsermap[i].parser_fn(opts, optarg);
}
return -EINVAL;
}
int
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) {
switch (opt) {
/* long options */
case 0:
retval = cperf_opts_parse_long(opt_idx, options);
if (retval != 0)
return retval;
break;
default:
return -EINVAL;
}
}
return 0;
}
int
cperf_options_check(struct cperf_options *options)
{
if (options->segments_nb > options->buffer_sz) {
RTE_LOG(ERR, USER1,
"Segments number greater than buffer size.\n");
return -EINVAL;
}
if (options->verify && options->test_file == NULL) {
RTE_LOG(ERR, USER1, "Define path to the file with test"
" vectors.\n");
return -EINVAL;
}
if (options->test_name != NULL && options->test_file == NULL) {
RTE_LOG(ERR, USER1, "Define path to the file with test"
" vectors.\n");
return -EINVAL;
}
if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
options->test_file == NULL) {
RTE_LOG(ERR, USER1, "Define path to the file with test"
" vectors.\n");
return -EINVAL;
}
if (options->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->op_type == CPERF_CIPHER_THEN_AUTH) {
if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
options->auth_op !=
RTE_CRYPTO_AUTH_OP_GENERATE) {
RTE_LOG(ERR, USER1, "Option cipher then auth must use"
" options: encrypt and generate.\n");
return -EINVAL;
}
} else if (options->op_type == CPERF_AUTH_THEN_CIPHER) {
if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_DECRYPT &&
options->auth_op !=
RTE_CRYPTO_AUTH_OP_VERIFY) {
RTE_LOG(ERR, USER1, "Option auth then cipher must use"
" options: decrypt and verify.\n");
return -EINVAL;
}
} else if (options->op_type == CPERF_AEAD) {
if (!(options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
options->auth_op ==
RTE_CRYPTO_AUTH_OP_GENERATE) &&
!(options->cipher_op ==
RTE_CRYPTO_CIPHER_OP_DECRYPT &&
options->auth_op ==
RTE_CRYPTO_AUTH_OP_VERIFY)) {
RTE_LOG(ERR, USER1, "Use together options: encrypt and"
" generate or decrypt and verify.\n");
return -EINVAL;
}
}
return 0;
}
void
cperf_options_dump(struct cperf_options *opts)
{
printf("# Crypto Performance Application Options:\n");
printf("#\n");
printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
printf("#\n");
printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
printf("# total number of ops: %u\n", opts->total_ops);
printf("# burst size: %u\n", opts->burst_sz);
printf("# buffer size: %u\n", opts->buffer_sz);
printf("# segments per buffer: %u\n", opts->segments_nb);
printf("#\n");
printf("# cryptodev type: %s\n", opts->device_type);
printf("#\n");
printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
printf("# verify operation: %s\n", opts->verify ? "yes" : "no");
printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
printf("#\n");
if (opts->op_type == CPERF_AUTH_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
opts->op_type == CPERF_AUTH_THEN_CIPHER ||
opts->op_type == CPERF_AEAD) {
printf("# auth algorithm: %s\n",
rte_crypto_auth_algorithm_strings[opts->auth_algo]);
printf("# auth operation: %s\n",
rte_crypto_auth_operation_strings[opts->auth_op]);
printf("# auth key size: %u\n", opts->auth_key_sz);
printf("# auth digest size: %u\n", opts->auth_digest_sz);
printf("# auth aad size: %u\n", opts->auth_aad_sz);
printf("#\n");
}
if (opts->op_type == CPERF_CIPHER_ONLY ||
opts->op_type == CPERF_CIPHER_THEN_AUTH ||
opts->op_type == CPERF_AUTH_THEN_CIPHER ||
opts->op_type == CPERF_AEAD) {
printf("# cipher algorithm: %s\n",
rte_crypto_cipher_algorithm_strings[opts->cipher_algo]);
printf("# cipher operation: %s\n",
rte_crypto_cipher_operation_strings[opts->cipher_op]);
printf("# cipher key size: %u\n", opts->cipher_key_sz);
printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
printf("#\n");
}
}