test/crypto-perf: add vector file for AES-GCM
[dpdk.git] / app / test-crypto-perf / cperf_options_parsing.c
index 20577a1..09c9812 100644 (file)
@@ -10,6 +10,7 @@
 #include <rte_ether.h>
 
 #include "cperf_options.h"
+#include "cperf_test_vectors.h"
 
 #define AES_BLOCK_SIZE 16
 #define DES_BLOCK_SIZE 8
@@ -24,7 +25,7 @@ usage(char *progname)
 {
        printf("%s [EAL options] --\n"
                " --silent: disable options dump\n"
-               " --ptest throughput / latency / verify / pmd-cycleount :"
+               " --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"
@@ -57,7 +58,12 @@ usage(char *progname)
                " --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_LIBRTE_SECURITY
+               " --modex-len N: modex length, supported lengths are "
+               "60, 128, 255, 448. Default: 128\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 <control/user>\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",
@@ -310,6 +316,16 @@ parse_pool_sz(struct cperf_options *opts, const char *arg)
        return ret;
 }
 
+static int
+parse_modex_len(struct cperf_options *opts, const char *arg)
+{
+       int ret =  parse_uint16_t(&opts->modex_len, arg);
+
+       if (ret)
+               RTE_LOG(ERR, USER1, "failed to parse modex len");
+       return ret;
+}
+
 static int
 parse_burst_sz(struct cperf_options *opts, const char *arg)
 {
@@ -454,6 +470,14 @@ parse_op_type(struct cperf_options *opts, const char *arg)
                {
                        cperf_op_type_strs[CPERF_DOCSIS],
                        CPERF_DOCSIS
+               },
+               {
+                       cperf_op_type_strs[CPERF_IPSEC],
+                       CPERF_IPSEC
+               },
+               {
+                       cperf_op_type_strs[CPERF_ASYM_MODEX],
+                       CPERF_ASYM_MODEX
                }
        };
 
@@ -503,6 +527,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;
 
@@ -628,7 +658,7 @@ parse_digest_sz(struct cperf_options *opts, const char *arg)
        return parse_uint16_t(&opts->digest_sz, arg);
 }
 
-#ifdef RTE_LIBRTE_SECURITY
+#ifdef RTE_LIB_SECURITY
 static int
 parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
 {
@@ -653,7 +683,8 @@ parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
 
 const char *cperf_pdcp_domain_strs[] = {
        [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
-       [RTE_SECURITY_PDCP_MODE_DATA] = "data"
+       [RTE_SECURITY_PDCP_MODE_DATA] = "data",
+       [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
 };
 
 static int
@@ -668,6 +699,11 @@ parse_pdcp_domain(struct cperf_options *opts, const char *arg)
                        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
                }
        };
 
@@ -684,6 +720,13 @@ parse_pdcp_domain(struct cperf_options *opts, const char *arg)
        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)
 {
@@ -792,6 +835,7 @@ struct long_opt_parser {
 static struct option lgopts[] = {
 
        { CPERF_PTEST_TYPE, required_argument, 0, 0 },
+       { CPERF_MODEX_LEN, required_argument, 0, 0 },
 
        { CPERF_POOL_SIZE, required_argument, 0, 0 },
        { CPERF_TOTAL_OPS, required_argument, 0, 0 },
@@ -831,9 +875,10 @@ static struct option lgopts[] = {
 
        { CPERF_DIGEST_SZ, required_argument, 0, 0 },
 
-#ifdef RTE_LIBRTE_SECURITY
+#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},
@@ -902,11 +947,13 @@ cperf_options_default(struct cperf_options *opts)
        opts->digest_sz = 12;
 
        opts->pmdcc_delay = 0;
-#ifdef RTE_LIBRTE_SECURITY
+#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
+       opts->modex_data = (struct cperf_modex_test_data *)&modex_perf_data[0];
 }
 
 static int
@@ -914,6 +961,7 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
 {
        struct long_opt_parser parsermap[] = {
                { CPERF_PTEST_TYPE,     parse_cperf_test_type },
+               { CPERF_MODEX_LEN,      parse_modex_len },
                { CPERF_SILENT,         parse_silent },
                { CPERF_POOL_SIZE,      parse_pool_sz },
                { CPERF_TOTAL_OPS,      parse_total_ops },
@@ -942,9 +990,10 @@ 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_LIBRTE_SECURITY
+#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},
@@ -970,7 +1019,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv)
                switch (opt) {
                case 'h':
                        usage(argv[0]);
-                       rte_exit(EXIT_SUCCESS, "Displayed help\n");
+                       exit(EXIT_SUCCESS);
                        break;
                /* long options */
                case 0:
@@ -1048,7 +1097,7 @@ check_cipher_buffer_length(struct cperf_options *options)
        return 0;
 }
 
-#ifdef RTE_LIBRTE_SECURITY
+#ifdef RTE_LIB_SECURITY
 static int
 check_docsis_buffer_length(struct cperf_options *options)
 {
@@ -1084,6 +1133,8 @@ check_docsis_buffer_length(struct cperf_options *options)
 int
 cperf_options_check(struct cperf_options *options)
 {
+       int i;
+
        if (options->op_type == CPERF_CIPHER_ONLY ||
                        options->op_type == CPERF_DOCSIS)
                options->digest_sz = 0;
@@ -1099,9 +1150,17 @@ cperf_options_check(struct cperf_options *options)
         * 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)
+       if (options->segment_sz == 0) {
                options->segment_sz = options->max_buffer_size +
                                options->digest_sz;
+               /* In IPsec operation, packet length will be increased
+                * by some bytes depend upon the algorithm, so increasing
+                * the segment size by headroom to cover most of
+                * the scenarios.
+                */
+               if (options->op_type == CPERF_IPSEC)
+                       options->segment_sz += RTE_PKTMBUF_HEADROOM;
+       }
 
        if (options->segment_sz < options->digest_sz) {
                RTE_LOG(ERR, USER1,
@@ -1202,7 +1261,31 @@ cperf_options_check(struct cperf_options *options)
                        return -EINVAL;
        }
 
-#ifdef RTE_LIBRTE_SECURITY
+       if (options->modex_len) {
+               if (options->op_type != CPERF_ASYM_MODEX) {
+                       RTE_LOG(ERR, USER1, "Option modex len should be used only with "
+                                       " optype: modex.\n");
+                       return -EINVAL;
+               }
+
+               for (i = 0; i < (int)RTE_DIM(modex_perf_data); i++) {
+                       if (modex_perf_data[i].modulus.len ==
+                           options->modex_len) {
+                               options->modex_data =
+                                       (struct cperf_modex_test_data
+                                                *)&modex_perf_data[i];
+                               break;
+                       }
+               }
+               if (i == (int)RTE_DIM(modex_perf_data)) {
+                       RTE_LOG(ERR, USER1,
+                               "Option modex len: %d is not supported\n",
+                               options->modex_len);
+                       return -EINVAL;
+               }
+       }
+
+#ifdef RTE_LIB_SECURITY
        if (options->op_type == CPERF_DOCSIS) {
                if (check_docsis_buffer_length(options) < 0)
                        return -EINVAL;
@@ -1295,7 +1378,7 @@ cperf_options_dump(struct cperf_options *opts)
                printf("#\n");
        }
 
-#ifdef RTE_LIBRTE_SECURITY
+#ifdef RTE_LIB_SECURITY
        if (opts->op_type == CPERF_DOCSIS) {
                printf("# docsis header size: %u\n", opts->docsis_hdr_sz);
                printf("#\n");