DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ibtisam Tariq <ibtisam.tariq@emumba.com>
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 <ibtisam.tariq@emumba.com>,
	jijiang.liu@intel.com
Subject: [dpdk-dev] [PATCH 8/8] examples/tep_termination: enhance getopt_long usage
Date: Thu, 29 Oct 2020 12:53:39 +0000	[thread overview]
Message-ID: <20201029125339.30916-8-ibtisam.tariq@emumba.com> (raw)
In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com>

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 <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
 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;
-- 
2.17.1


  parent reply	other threads:[~2020-10-29 12:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 12:53 [dpdk-dev] [PATCH 1/8] examples/fips_validation: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 2/8] examples/l3fwd-acl: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 3/8] examples/packet_ordering: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 4/8] examples/performance-thread/l3fwd-thread: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 5/8] examples/qos_sched: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 6/8] examples/vhost: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 7/8] examples/vhost_crypto: " Ibtisam Tariq
2020-10-29 12:53 ` Ibtisam Tariq [this message]
2020-10-29 13:16   ` [dpdk-dev] [PATCH 8/8] examples/tep_termination: " David Marchand
2020-11-02  8:18     ` Ibtisam Tariq
2020-10-29 22:07 ` [dpdk-dev] [PATCH 1/8] examples/fips_validation: " David Marchand
2020-11-02  8:32   ` Ibtisam Tariq
2020-11-04 10:00     ` Ibtisam Tariq
2020-11-05  8:59       ` David Marchand
2020-11-10  6:10         ` Ibtisam Tariq
2020-11-10  8:23           ` David Marchand
2020-11-10  9:03             ` Ibtisam Tariq

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201029125339.30916-8-ibtisam.tariq@emumba.com \
    --to=ibtisam.tariq@emumba.com \
    --cc=chenbo.xia@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=jasvinder.singh@intel.com \
    --cc=jijiang.liu@intel.com \
    --cc=john.mcnamara@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=reshma.pattan@intel.com \
    --cc=xiaoyun.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).