test/crypto-perf: support DOCSIS protocol
[dpdk.git] / app / test-crypto-perf / cperf_options_parsing.c
index f43c5be..20577a1 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <rte_cryptodev.h>
 #include <rte_malloc.h>
+#include <rte_ether.h>
 
 #include "cperf_options.h"
 
@@ -56,6 +57,9 @@ 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
+               " --docsis-hdr-sz: set DOCSIS header size\n"
+#endif
                " -h: prints this help\n",
                progname);
 }
@@ -446,6 +450,10 @@ parse_op_type(struct cperf_options *opts, const char *arg)
                {
                        cperf_op_type_strs[CPERF_PDCP],
                        CPERF_PDCP
+               },
+               {
+                       cperf_op_type_strs[CPERF_DOCSIS],
+                       CPERF_DOCSIS
                }
        };
 
@@ -675,6 +683,12 @@ parse_pdcp_domain(struct cperf_options *opts, const char *arg)
 
        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
@@ -820,6 +834,7 @@ static struct option lgopts[] = {
 #ifdef RTE_LIBRTE_SECURITY
        { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
        { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
+       { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
 #endif
        { CPERF_CSV, no_argument, 0, 0},
 
@@ -890,6 +905,7 @@ cperf_options_default(struct cperf_options *opts)
 #ifdef RTE_LIBRTE_SECURITY
        opts->pdcp_sn_sz = 12;
        opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
+       opts->docsis_hdr_sz = 17;
 #endif
 }
 
@@ -929,6 +945,7 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
 #ifdef RTE_LIBRTE_SECURITY
                { CPERF_PDCP_SN_SZ,     parse_pdcp_sn_sz },
                { CPERF_PDCP_DOMAIN,    parse_pdcp_domain },
+               { CPERF_DOCSIS_HDR_SZ,  parse_docsis_hdr_sz },
 #endif
                { CPERF_CSV,            parse_csv_friendly},
                { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
@@ -1031,10 +1048,44 @@ check_cipher_buffer_length(struct cperf_options *options)
        return 0;
 }
 
+#ifdef RTE_LIBRTE_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->op_type == CPERF_CIPHER_ONLY)
+       if (options->op_type == CPERF_CIPHER_ONLY ||
+                       options->op_type == CPERF_DOCSIS)
                options->digest_sz = 0;
 
        if (options->out_of_place &&
@@ -1151,6 +1202,13 @@ cperf_options_check(struct cperf_options *options)
                        return -EINVAL;
        }
 
+#ifdef RTE_LIBRTE_SECURITY
+       if (options->op_type == CPERF_DOCSIS) {
+               if (check_docsis_buffer_length(options) < 0)
+                       return -EINVAL;
+       }
+#endif
+
        return 0;
 }
 
@@ -1236,4 +1294,11 @@ cperf_options_dump(struct cperf_options *opts)
                printf("# aead aad size: %u\n", opts->aead_aad_sz);
                printf("#\n");
        }
+
+#ifdef RTE_LIBRTE_SECURITY
+       if (opts->op_type == CPERF_DOCSIS) {
+               printf("# docsis header size: %u\n", opts->docsis_hdr_sz);
+               printf("#\n");
+       }
+#endif
 }