From 5ff2bcc89e3434237924a80d3bbd85caab70c06b Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Thu, 12 Nov 2020 15:51:11 +0200 Subject: example: cls: add command line option to enable promisc mode Add new command line option -P (--promisc_mode) for enabling promiscuous mode for the pktio interface. Enabling promiscuous mode is required for example when using ODP_PMR_DMAC PMRs. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen --- example/classifier/odp_classifier.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'example/classifier') diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index f0cab8c05..f7d10a812 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -84,6 +84,7 @@ typedef struct { int shutdown; /**< Shutdown threads if !0 */ int shutdown_sig; int verbose; + int promisc_mode; /**< Promiscuous mode enabled */ } appl_args_t; enum packet_mode { @@ -199,6 +200,7 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) odp_pktio_t pktio; odp_pktio_param_t pktio_param; odp_pktin_queue_param_t pktin_param; + odp_pktio_capability_t capa; odp_pktio_param_init(&pktio_param); pktio_param.in_mode = ODP_PKTIN_MODE_SCHED; @@ -213,6 +215,11 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) exit(EXIT_FAILURE); } + if (odp_pktio_capability(pktio, &capa)) { + ODPH_ERR("pktio capability failed for %s\n", dev); + exit(EXIT_FAILURE); + } + odp_pktin_queue_param_init(&pktin_param); pktin_param.queue_param.sched.sync = ODP_SCHED_SYNC_ATOMIC; pktin_param.classifier_enable = 1; @@ -227,6 +234,18 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) exit(EXIT_FAILURE); } + if (appl_args_gbl->promisc_mode) { + if (!capa.set_op.op.promisc_mode) { + ODPH_ERR("enabling promisc mode not supported %s\n", dev); + exit(EXIT_FAILURE); + } + + if (odp_pktio_promisc_mode_set(pktio, true)) { + ODPH_ERR("failed to enable promisc mode for %s\n", dev); + exit(EXIT_FAILURE); + } + } + printf(" created pktio:%02" PRIu64 ", dev:%s, queue mode (ATOMIC queues)\n" " \tdefault pktio%02" PRIu64 "\n", @@ -973,15 +992,17 @@ static int parse_args(int argc, char *argv[], appl_args_t *appl_args) {"policy", required_argument, NULL, 'p'}, {"mode", required_argument, NULL, 'm'}, {"time", required_argument, NULL, 't'}, + {"promisc_mode", no_argument, NULL, 'P'}, {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; - static const char *shortopts = "+c:t:i:p:m:t:vh"; + static const char *shortopts = "+c:t:i:p:m:t:Pvh"; appl_args->cpu_count = 1; /* Use one worker by default */ appl_args->verbose = 0; + appl_args->promisc_mode = 0; while (ret == 0) { opt = getopt_long(argc, argv, shortopts, @@ -1028,6 +1049,9 @@ static int parse_args(int argc, char *argv[], appl_args_t *appl_args) else appl_args->appl_mode = APPL_MODE_REPLY; break; + case 'P': + appl_args->promisc_mode = 1; + break; case 'v': appl_args->verbose = 1; break; @@ -1067,8 +1091,9 @@ static void print_info(char *progname, appl_args_t *appl_args) printf("Running ODP appl: \"%s\"\n" "-----------------\n" - "Using IF:%s ", + "Using IF: %s\n", progname, appl_args->if_name); + printf("Promisc mode: %s\n", appl_args->promisc_mode ? "enabled" : "disabled"); printf("\n\n"); fflush(NULL); } @@ -1110,10 +1135,11 @@ static void usage(void) " !0: Packet ICMP mode. Received packets will be sent back\n" " default: Packet Drop mode\n" "\n" - " -t, --timeout !0: Time for which the classifier will be run in seconds\n" + " -t, --timeout !0: Time for which the classifier will be run in seconds\n" " 0: Runs in infinite loop\n" " default: Runs in infinite loop\n" "\n" + " -P, --promisc_mode Enable promiscuous mode.\n" " -h, --help Display help and exit.\n" "\n"); } -- cgit v1.2.3