From patchwork Thu Oct 29 12:53:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82775 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DC7D1A04B5; Thu, 29 Oct 2020 13:58:22 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7FC6FCD37; Thu, 29 Oct 2020 13:54:39 +0100 (CET) Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by dpdk.org (Postfix) with ESMTP id 64D45CB56 for ; Thu, 29 Oct 2020 13:54:37 +0100 (CET) Received: by mail-ej1-f68.google.com with SMTP id dk16so3065129ejb.12 for ; Thu, 29 Oct 2020 05:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3MPXsxCfRRB9N8ptwNC854FEpAKtojfIxEXkLm5Sfqg=; b=JLRM/KPTtHXLbVEFG14ypq4893RcktydwRkRyG6s+Wi3cGZhnE/wCGTVDq4Ak4bQSx 1AlQTObqARTp7gC5CRj9o8u2f46XLve9OyrgvUzrN8QARQbyGtzvyPKikPgqZzrqntde jUSDtqn/HqwWE2XjSVtmmDu1mO1j1XHjzX89lSU6Htc2qDiT9d9p+lDVcwBDCQIiALLe nW1aowR3H3ZWuRJSnolEzk1tgmC53O66E5GQzFwEgjAfg+LrXwbkKYNih9KLsf9HeQ70 u5qHNwdR0hnVVPczwBc53lH8/MXh60hUtGZ9S5lcXMUNfqSpyi1oLdHIAVpFsyyIvsMi BMBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3MPXsxCfRRB9N8ptwNC854FEpAKtojfIxEXkLm5Sfqg=; b=LUXmTdNPCJG4qXWH0JhfE3wFvGSaO1j7kiyAHi7INVN9vgkCuv087xTgF6LS8CMopA 4bHvd5bepM59Rk3Qub04ej3Oz1NlZmlrU+i7lRToDvJ25FpzcD9EJkNjLqGdT8vTXMRl kpnXGfbOkhLmiO2xTu1noE/0NjH6jJgXhTOr8H4+rYjFAtrDKQqObJnIQbpA2iw1pc+n Z0GPVW1BtUEAu44bdGlfn9PvSgI0mclgX5yqJWzjzqR1RAJP30mn7vs3xF/2MSJZB9ip JAK90fs3lKYdFdKq8aVVO8wprY4lu6rI5EyCESWEeeRYHVHiHyR1Lrn/rwUdy4CEybRo QV4w== X-Gm-Message-State: AOAM532KbQwIIkvOnDyBhKRnhn54JRmt2hBp6QQjoSoCqKCZZyYwmKG/ TG4foFqjA83qz5Z8gHWgogZERw== X-Google-Smtp-Source: ABdhPJxyjz1ID3abnAGdSgdKxAqNbzICN6Wq0Ndit+POQKOmaQL8AXfLjrzO2wdlJ5hc+eNwG1Z5qw== X-Received: by 2002:a17:906:728f:: with SMTP id b15mr1299052ejl.210.1603976066550; Thu, 29 Oct 2020 05:54:26 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:25 -0700 (PDT) From: Ibtisam Tariq To: marko.kovacevic@intel.com, konstantin.ananyev@intel.com, reshma.pattan@intel.com, john.mcnamara@intel.com, cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, chenbo.xia@intel.com, maxime.coquelin@redhat.com, xiaoyun.li@intel.com Cc: dev@dpdk.org, Ibtisam Tariq , jijiang.liu@intel.com Date: Thu, 29 Oct 2020 12:53:39 +0000 Message-Id: <20201029125339.30916-8-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com> References: <20201029125339.30916-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 8/8] examples/tep_termination: enhance getopt_long usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Instead of using getopt_long return value, strcmp was used to compare the input parameters with the struct option array. This patch get rid of all those strcmp by directly binding each longopt with an int enum. Bugzilla ID: 238 Fixes: a50245ede7 ("examples/tep_term: initialize VXLAN sample") Fixes: 2bb43bd435 ("examples/tep_term: add TSO offload configuration") Fixes: 39c6daca9b ("examples/tep_term: add UDP tunneling port configuration") Fixes: 9b96dd2609 ("examples/tep_term: add inner checksum Tx offload configuration") Fixes: e627e8843d ("examples/tep_term: add tunnel filter type configuration") Fixes: c6a0fb5f54 ("examples/tep_term: add encap/decap configuration") Cc: jijiang.liu@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/tep_termination/main.c | 341 ++++++++++++++++---------------- 1 file changed, 173 insertions(+), 168 deletions(-) diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c index 15bf8bbf7..089d8cc7a 100644 --- a/examples/tep_termination/main.c +++ b/examples/tep_termination/main.c @@ -75,18 +75,32 @@ /* Used to compare MAC addresses. */ #define MAC_ADDR_CMP 0xFFFFFFFFFFFFULL +enum { #define CMD_LINE_OPT_NB_DEVICES "nb-devices" + CMD_LINE_OPT_NB_DEVICES_NUM = 256, #define CMD_LINE_OPT_UDP_PORT "udp-port" + CMD_LINE_OPT_UDP_PORT_NUM, #define CMD_LINE_OPT_TX_CHECKSUM "tx-checksum" + CMD_LINE_OPT_TX_CHECKSUM_NUM, #define CMD_LINE_OPT_TSO_SEGSZ "tso-segsz" + CMD_LINE_OPT_TSO_SEGSZ_NUM, #define CMD_LINE_OPT_FILTER_TYPE "filter-type" + CMD_LINE_OPT_FILTER_TYPE_NUM, #define CMD_LINE_OPT_ENCAP "encap" + CMD_LINE_OPT_ENCAP_NUM, #define CMD_LINE_OPT_DECAP "decap" + CMD_LINE_OPT_DECAP_NUM, #define CMD_LINE_OPT_RX_RETRY "rx-retry" + CMD_LINE_OPT_RX_RETRY_NUM, #define CMD_LINE_OPT_RX_RETRY_DELAY "rx-retry-delay" -#define CMD_LINE_OPT_RX_RETRY_NUM "rx-retry-num" + CMD_LINE_OPT_RX_RETRY_DELAY_NUM, +#define CMD_LINE_OPT_RX_RETRY_NUMB "rx-retry-num" + CMD_LINE_OPT_RX_RETRY_NUMB_NUM, #define CMD_LINE_OPT_STATS "stats" + CMD_LINE_OPT_STATS_NUM, #define CMD_LINE_OPT_DEV_BASENAME "dev-basename" + CMD_LINE_OPT_DEV_BASENAME_NUM, +}; /* mask of enabled ports */ static uint32_t enabled_port_mask; @@ -268,18 +282,30 @@ tep_termination_parse_args(int argc, char **argv) unsigned i; const char *prgname = argv[0]; static struct option long_option[] = { - {CMD_LINE_OPT_NB_DEVICES, required_argument, NULL, 0}, - {CMD_LINE_OPT_UDP_PORT, required_argument, NULL, 0}, - {CMD_LINE_OPT_TX_CHECKSUM, required_argument, NULL, 0}, - {CMD_LINE_OPT_TSO_SEGSZ, required_argument, NULL, 0}, - {CMD_LINE_OPT_DECAP, required_argument, NULL, 0}, - {CMD_LINE_OPT_ENCAP, required_argument, NULL, 0}, - {CMD_LINE_OPT_FILTER_TYPE, required_argument, NULL, 0}, - {CMD_LINE_OPT_RX_RETRY, required_argument, NULL, 0}, - {CMD_LINE_OPT_RX_RETRY_DELAY, required_argument, NULL, 0}, - {CMD_LINE_OPT_RX_RETRY_NUM, required_argument, NULL, 0}, - {CMD_LINE_OPT_STATS, required_argument, NULL, 0}, - {CMD_LINE_OPT_DEV_BASENAME, required_argument, NULL, 0}, + {CMD_LINE_OPT_NB_DEVICES, required_argument, + NULL, CMD_LINE_OPT_NB_DEVICES_NUM}, + {CMD_LINE_OPT_UDP_PORT, required_argument, + NULL, CMD_LINE_OPT_UDP_PORT_NUM}, + {CMD_LINE_OPT_TX_CHECKSUM, required_argument, + NULL, CMD_LINE_OPT_TX_CHECKSUM_NUM}, + {CMD_LINE_OPT_TSO_SEGSZ, required_argument, + NULL, CMD_LINE_OPT_TSO_SEGSZ_NUM}, + {CMD_LINE_OPT_DECAP, required_argument, + NULL, CMD_LINE_OPT_DECAP_NUM}, + {CMD_LINE_OPT_ENCAP, required_argument, + NULL, CMD_LINE_OPT_ENCAP_NUM}, + {CMD_LINE_OPT_FILTER_TYPE, required_argument, + NULL, CMD_LINE_OPT_FILTER_TYPE_NUM}, + {CMD_LINE_OPT_RX_RETRY, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_NUM}, + {CMD_LINE_OPT_RX_RETRY_DELAY, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_DELAY_NUM}, + {CMD_LINE_OPT_RX_RETRY_NUMB, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_NUMB_NUM}, + {CMD_LINE_OPT_STATS, required_argument, + NULL, CMD_LINE_OPT_STATS_NUM}, + {CMD_LINE_OPT_DEV_BASENAME, required_argument, + NULL, CMD_LINE_OPT_DEV_BASENAME_NUM}, {NULL, 0, 0, 0}, }; @@ -297,174 +323,153 @@ tep_termination_parse_args(int argc, char **argv) return -1; } break; - case 0: - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_NB_DEVICES, - sizeof(CMD_LINE_OPT_NB_DEVICES))) { - ret = parse_num_opt(optarg, MAX_DEVICES); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for nb-devices [0-%d]\n", - MAX_DEVICES); - tep_termination_usage(prgname); - return -1; - } else - nb_devices = ret; - } - /* Enable/disable retries on RX. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_RX_RETRY, - sizeof(CMD_LINE_OPT_RX_RETRY))) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for rx-retry [0|1]\n"); - tep_termination_usage(prgname); - return -1; - } else - enable_retry = ret; + case CMD_LINE_OPT_NB_DEVICES_NUM: + { + ret = parse_num_opt(optarg, MAX_DEVICES); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for nb-devices [0-%d]\n", + MAX_DEVICES); + tep_termination_usage(prgname); + return -1; } - - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_TSO_SEGSZ, - sizeof(CMD_LINE_OPT_TSO_SEGSZ))) { - ret = parse_num_opt(optarg, INT16_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for TCP segment size [0-N]\n"); - tep_termination_usage(prgname); - return -1; - } else - tso_segsz = ret; + nb_devices = ret; + break; + } + case CMD_LINE_OPT_RX_RETRY_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for rx-retry [0|1]\n"); + tep_termination_usage(prgname); + return -1; } - - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_UDP_PORT, - sizeof(CMD_LINE_OPT_UDP_PORT))) { - ret = parse_num_opt(optarg, INT16_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for UDP port [0-N]\n"); - tep_termination_usage(prgname); - return -1; - } else - udp_port = ret; + enable_retry = ret; + break; + } + case CMD_LINE_OPT_TSO_SEGSZ_NUM: + { + ret = parse_num_opt(optarg, INT16_MAX); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for TCP segment size [0-N]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Specify the retries delay time (in useconds) on RX.*/ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_RX_RETRY_DELAY, - sizeof(CMD_LINE_OPT_RX_RETRY_DELAY))) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for rx-retry-delay [0-N]\n"); - tep_termination_usage(prgname); - return -1; - } else - burst_rx_delay_time = ret; + tso_segsz = ret; + break; + } + case CMD_LINE_OPT_UDP_PORT_NUM: + { + ret = parse_num_opt(optarg, INT16_MAX); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for UDP port [0-N]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Specify the retries number on RX. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_RX_RETRY_NUM, - sizeof(CMD_LINE_OPT_RX_RETRY_NUM))) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for rx-retry-num [0-N]\n"); - tep_termination_usage(prgname); - return -1; - } else - burst_rx_retry_num = ret; + udp_port = ret; + break; + } + case CMD_LINE_OPT_RX_RETRY_DELAY_NUM: + { + ret = parse_num_opt(optarg, INT32_MAX); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for rx-retry-delay [0-N]\n"); + tep_termination_usage(prgname); + return -1; } - - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_TX_CHECKSUM, - sizeof(CMD_LINE_OPT_TX_CHECKSUM))) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for tx-checksum [0|1]\n"); - tep_termination_usage(prgname); - return -1; - } else - tx_checksum = ret; + burst_rx_delay_time = ret; + break; + } + case CMD_LINE_OPT_RX_RETRY_NUMB_NUM: + { + ret = parse_num_opt(optarg, INT32_MAX); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for rx-retry-num [0-N]\n"); + tep_termination_usage(prgname); + return -1; } - - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_FILTER_TYPE, - sizeof(CMD_LINE_OPT_FILTER_TYPE))) { - ret = parse_num_opt(optarg, 3); - if ((ret == -1) || (ret == 0)) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for filter type [1-3]\n"); - tep_termination_usage(prgname); - return -1; - } else - filter_idx = ret - 1; + burst_rx_retry_num = ret; + break; + } + case CMD_LINE_OPT_TX_CHECKSUM_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for tx-checksum [0|1]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Enable/disable encapsulation on RX. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_DECAP, - sizeof(CMD_LINE_OPT_DECAP))) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for decap [0|1]\n"); - tep_termination_usage(prgname); - return -1; - } else - rx_decap = ret; + tx_checksum = ret; + break; + } + case CMD_LINE_OPT_FILTER_TYPE_NUM: + { + ret = parse_num_opt(optarg, 3); + if ((ret == -1) || (ret == 0)) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for filter type [1-3]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Enable/disable encapsulation on TX. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_ENCAP, - sizeof(CMD_LINE_OPT_ENCAP))) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for encap [0|1]\n"); - tep_termination_usage(prgname); - return -1; - } else - tx_encap = ret; + filter_idx = ret - 1; + break; + } + case CMD_LINE_OPT_DECAP_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for decap [0|1]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Enable/disable stats. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_STATS, - sizeof(CMD_LINE_OPT_STATS))) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for stats [0..N]\n"); - tep_termination_usage(prgname); - return -1; - } else - enable_stats = ret; + rx_decap = ret; + break; + } + case CMD_LINE_OPT_ENCAP_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for encap [0|1]\n"); + tep_termination_usage(prgname); + return -1; } - - /* Set character device basename. */ - if (!strncmp(long_option[option_index].name, - CMD_LINE_OPT_DEV_BASENAME, - sizeof(CMD_LINE_OPT_DEV_BASENAME))) { - if (us_vhost_parse_basename(optarg) == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for character " - "device basename (Max %d characters)\n", - MAX_BASENAME_SZ); - tep_termination_usage(prgname); - return -1; - } + tx_encap = ret; + break; + } + case CMD_LINE_OPT_STATS_NUM: + { + ret = parse_num_opt(optarg, INT32_MAX); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for stats [0..N]\n"); + tep_termination_usage(prgname); + return -1; } - + enable_stats = ret; break; - - /* Invalid option - print options. */ + } + case CMD_LINE_OPT_DEV_BASENAME_NUM: + { + if (us_vhost_parse_basename(optarg) == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for character " + "device basename (Max %d characters)\n", + MAX_BASENAME_SZ); + tep_termination_usage(prgname); + return -1; + } + break; + } + /* Invalid option - print options. */ default: tep_termination_usage(prgname); return -1;