From patchwork Thu Oct 29 12:53:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82768 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 60879A04B5; Thu, 29 Oct 2020 13:55:31 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E41A9CCA8; Thu, 29 Oct 2020 13:53:51 +0100 (CET) Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by dpdk.org (Postfix) with ESMTP id B8364CBA8 for ; Thu, 29 Oct 2020 13:53:49 +0100 (CET) Received: by mail-ej1-f67.google.com with SMTP id 7so3713330ejm.0 for ; Thu, 29 Oct 2020 05:53:49 -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; bh=j8sxZ8oZOjKK5/6ZOtA5tuPnqzUPJXPrdW18vOuQ8kI=; b=1U48cW5uy7jDvldc5tiUNLCh5RdliKjnWXAAAcfE5Bqewa/2npzC3OssY35A93x+Qh 9lDQwmLjrxEyl4808ToqpvvsQBYp5Hh08Qf66Ds4q8tJ6Ry1QcOvIKeyyroCMEc/4VJe LoQCRkQyl9aoScYJD1zANIoVgURWcAQMg/Yd28yVKBuYfM6Hx+l1RiB9CQGDmiWYJL7f BXyQwMVUOJitb4oay4IpZuimzPmyLi7NVspZxeaQ82OksqjwUiVSYQ7tV5kaC0Lsxrqs Ov258kGBJChpziYKZBLcmi+QrPxqyddxs5smoRGRhaqJTooMqtrcEgKkVOSO8HwAz/oC yQDg== 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; bh=j8sxZ8oZOjKK5/6ZOtA5tuPnqzUPJXPrdW18vOuQ8kI=; b=sqeBZGUr7uXHusSERA2hbiVkTY2rt1mmrzuNJI6Kt0F4J/h9udhVtwB57D36WXYxLl 4ibPeGmGevVv1NMdrM4JLc+D6QtOJkAdSM4/y1Zhmm2U7gyC1M7RYrqTHdG6VBD5Bbc6 ucByFzQBvZEsF4Xv/nocF8B2n6JwY5NOz5mztEnDUVQBhLnUvOzy69EBZXIAQllNtpME lZT+bTEy+ohHlLXwLgtZKm5Qo2eNq04CstXh52OS+AN2xm+4GZs0U2xUB4xBBu+UUTf4 yTmRJZFvPfB7J+qXkA/3xb9SEDtB+oNgRf2ey8RfDUfH3PF4U7Is6aiAHKBy/IvAlOMZ rd1A== X-Gm-Message-State: AOAM531e8iuCVXscfq9O5AumV/HD58RfTev8fe5h39Ze6VsnXhKRYOvG n4rWJbalYUYTz/OYX1aTPmc4gA== X-Google-Smtp-Source: ABdhPJwUKMluvSZmNydmSC0VH2Z+/9P80sPfLK//UsdLbIhzmbfpAIb6KWZxzD7ry8wT58o93f6V+w== X-Received: by 2002:a17:906:da03:: with SMTP id fi3mr3885181ejb.321.1603976029472; Thu, 29 Oct 2020 05:53:49 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:53:48 -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 Date: Thu, 29 Oct 2020 12:53:32 +0000 Message-Id: <20201029125339.30916-1-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH 1/8] examples/fips_validation: 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: 3d0fad56b74 ("examples/fips_validation: add crypto FIPS application"} Cc: marko.kovacevic@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/fips_validation/main.c | 241 +++++++++++++++++++------------- 1 file changed, 143 insertions(+), 98 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 07532c956..5fb76b421 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -15,17 +15,31 @@ #include "fips_validation.h" #include "fips_dev_self_test.h" +enum{ #define REQ_FILE_PATH_KEYWORD "req-file" + /* first long only option value must be >= 256, so that we won't + * conflict with short options + */ + REQ_FILE_PATH_KEYWORD_NUM = 256, #define RSP_FILE_PATH_KEYWORD "rsp-file" + RSP_FILE_PATH_KEYWORD_NUM, #define MBUF_DATAROOM_KEYWORD "mbuf-dataroom" + MBUF_DATAROOM_KEYWORD_NUM, #define FOLDER_KEYWORD "path-is-folder" + FOLDER_KEYWORD_NUM, #define CRYPTODEV_KEYWORD "cryptodev" + CRYPTODEV_KEYWORD_NUM, #define CRYPTODEV_ID_KEYWORD "cryptodev-id" + CRYPTODEV_ID_KEYWORD_NUM, #define CRYPTODEV_ST_KEYWORD "self-test" + CRYPTODEV_ST_KEYWORD_NUM, #define CRYPTODEV_BK_ID_KEYWORD "broken-test-id" + CRYPTODEV_BK_ID_KEYWORD_NUM, #define CRYPTODEV_BK_DIR_KEY "broken-test-dir" + CRYPTODEV_BK_DIR_KEY_NUM, #define CRYPTODEV_ENC_KEYWORD "enc" #define CRYPTODEV_DEC_KEYWORD "dec" +}; struct fips_test_vector vec; struct fips_test_interim_info info; @@ -226,15 +240,24 @@ cryptodev_fips_validate_parse_args(int argc, char **argv) char **argvopt; int option_index; struct option lgopts[] = { - {REQ_FILE_PATH_KEYWORD, required_argument, 0, 0}, - {RSP_FILE_PATH_KEYWORD, required_argument, 0, 0}, - {FOLDER_KEYWORD, no_argument, 0, 0}, - {MBUF_DATAROOM_KEYWORD, required_argument, 0, 0}, - {CRYPTODEV_KEYWORD, required_argument, 0, 0}, - {CRYPTODEV_ID_KEYWORD, required_argument, 0, 0}, - {CRYPTODEV_ST_KEYWORD, no_argument, 0, 0}, - {CRYPTODEV_BK_ID_KEYWORD, required_argument, 0, 0}, - {CRYPTODEV_BK_DIR_KEY, required_argument, 0, 0}, + {REQ_FILE_PATH_KEYWORD, required_argument, + NULL, REQ_FILE_PATH_KEYWORD_NUM}, + {RSP_FILE_PATH_KEYWORD, required_argument, + NULL, RSP_FILE_PATH_KEYWORD_NUM}, + {FOLDER_KEYWORD, no_argument, + NULL, FOLDER_KEYWORD_NUM}, + {MBUF_DATAROOM_KEYWORD, required_argument, + NULL, MBUF_DATAROOM_KEYWORD_NUM}, + {CRYPTODEV_KEYWORD, required_argument, + NULL, CRYPTODEV_KEYWORD_NUM}, + {CRYPTODEV_ID_KEYWORD, required_argument, + NULL, CRYPTODEV_ID_KEYWORD_NUM}, + {CRYPTODEV_ST_KEYWORD, no_argument, + NULL, CRYPTODEV_ST_KEYWORD_NUM}, + {CRYPTODEV_BK_ID_KEYWORD, required_argument, + NULL, CRYPTODEV_BK_ID_KEYWORD_NUM}, + {CRYPTODEV_BK_DIR_KEY, required_argument, + NULL, CRYPTODEV_BK_DIR_KEY_NUM}, {NULL, 0, 0, 0} }; @@ -251,105 +274,127 @@ cryptodev_fips_validate_parse_args(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, "s:", lgopts, &option_index)) != EOF) { + if (opt == '?') { + cryptodev_fips_validate_usage(prgname); + return -1; + } + switch (opt) { - case 0: - if (strcmp(lgopts[option_index].name, - REQ_FILE_PATH_KEYWORD) == 0) - env.req_path = optarg; - else if (strcmp(lgopts[option_index].name, - RSP_FILE_PATH_KEYWORD) == 0) - env.rsp_path = optarg; - else if (strcmp(lgopts[option_index].name, - FOLDER_KEYWORD) == 0) - env.is_path_folder = 1; - else if (strcmp(lgopts[option_index].name, - CRYPTODEV_KEYWORD) == 0) { - ret = parse_cryptodev_arg(optarg); - if (ret < 0) { - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } - } else if (strcmp(lgopts[option_index].name, - CRYPTODEV_ID_KEYWORD) == 0) { - ret = parse_cryptodev_id_arg(optarg); - if (ret < 0) { - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } - } else if (strcmp(lgopts[option_index].name, - CRYPTODEV_ST_KEYWORD) == 0) { - env.self_test = 1; - } else if (strcmp(lgopts[option_index].name, - CRYPTODEV_BK_ID_KEYWORD) == 0) { - if (!env.broken_test_config) { - env.broken_test_config = rte_malloc( - NULL, - sizeof(*env.broken_test_config), - 0); - if (!env.broken_test_config) - return -ENOMEM; - - env.broken_test_config->expect_fail_dir = - self_test_dir_enc_auth_gen; - } + case REQ_FILE_PATH_KEYWORD_NUM: + { + env.req_path = optarg; + break; + } + case RSP_FILE_PATH_KEYWORD_NUM: + { + env.rsp_path = optarg; + break; + } + case FOLDER_KEYWORD_NUM: + { + env.is_path_folder = 1; + break; + } + case CRYPTODEV_KEYWORD_NUM: + { + ret = parse_cryptodev_arg(optarg); + if (ret < 0) { + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } - if (parser_read_uint32( - &env.broken_test_config->expect_fail_test_idx, - optarg) < 0) { - rte_free(env.broken_test_config); - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } - } else if (strcmp(lgopts[option_index].name, - CRYPTODEV_BK_DIR_KEY) == 0) { - if (!env.broken_test_config) { - env.broken_test_config = rte_malloc( - NULL, - sizeof(*env.broken_test_config), - 0); - if (!env.broken_test_config) - return -ENOMEM; - - env.broken_test_config-> - expect_fail_test_idx = 0; - } + break; + } + case CRYPTODEV_ID_KEYWORD_NUM: + { + ret = parse_cryptodev_id_arg(optarg); + if (ret < 0) { + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + break; + } + case CRYPTODEV_ST_KEYWORD_NUM: + { + env.self_test = 1; + break; + } + case CRYPTODEV_BK_ID_KEYWORD_NUM: + { + if (!env.broken_test_config) { + env.broken_test_config = rte_malloc( + NULL, + sizeof(*env.broken_test_config), + 0); + if (!env.broken_test_config) + return -ENOMEM; + + env.broken_test_config->expect_fail_dir = + self_test_dir_enc_auth_gen; + } - if (strcmp(optarg, CRYPTODEV_ENC_KEYWORD) == 0) - env.broken_test_config->expect_fail_dir = - self_test_dir_enc_auth_gen; - else if (strcmp(optarg, CRYPTODEV_DEC_KEYWORD) - == 0) - env.broken_test_config->expect_fail_dir = - self_test_dir_dec_auth_verify; - else { - rte_free(env.broken_test_config); - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } - } else if (strcmp(lgopts[option_index].name, - MBUF_DATAROOM_KEYWORD) == 0) { - uint32_t data_room_size; - - if (parser_read_uint32(&data_room_size, - optarg) < 0) { - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } + if (parser_read_uint32( + &env.broken_test_config->expect_fail_test_idx, + optarg) < 0) { + rte_free(env.broken_test_config); + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + break; + } + case CRYPTODEV_BK_DIR_KEY_NUM: + { + if (!env.broken_test_config) { + env.broken_test_config = rte_malloc( + NULL, + sizeof(*env.broken_test_config), + 0); + if (!env.broken_test_config) + return -ENOMEM; + + env.broken_test_config-> + expect_fail_test_idx = 0; + } - if (data_room_size == 0 || - data_room_size > UINT16_MAX) { - cryptodev_fips_validate_usage(prgname); - return -EINVAL; - } + if (strcmp(optarg, CRYPTODEV_ENC_KEYWORD) == 0) + env.broken_test_config->expect_fail_dir = + self_test_dir_enc_auth_gen; + else if (strcmp(optarg, CRYPTODEV_DEC_KEYWORD) + == 0) + env.broken_test_config->expect_fail_dir = + self_test_dir_dec_auth_verify; + else { + rte_free(env.broken_test_config); + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + break; + } + case MBUF_DATAROOM_KEYWORD_NUM: + { + uint32_t data_room_size; - env.mbuf_data_room = data_room_size; - } else { + if (parser_read_uint32(&data_room_size, + optarg) < 0) { cryptodev_fips_validate_usage(prgname); return -EINVAL; } + + if (data_room_size == 0 || + data_room_size > UINT16_MAX) { + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } + + env.mbuf_data_room = data_room_size; + break; + } default: - return -1; + { + cryptodev_fips_validate_usage(prgname); + return -EINVAL; + } } } From patchwork Thu Oct 29 12:53:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82769 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 B5C42A04B5; Thu, 29 Oct 2020 13:55:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7C4B4CB96; Thu, 29 Oct 2020 13:53:59 +0100 (CET) Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by dpdk.org (Postfix) with ESMTP id 33E46CB56 for ; Thu, 29 Oct 2020 13:53:58 +0100 (CET) Received: by mail-ed1-f68.google.com with SMTP id dg9so2864904edb.12 for ; Thu, 29 Oct 2020 05:53:58 -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=1uDQqEDj12FGjfFLhWqY7mUHJCOn+q/keM9wT3A+eqU=; b=vbQ1I8fTJ4WOIK7fyccyb//UF4aIJDZGcy0i/1bmlEK33ysI+SsBtyjFxA4r7epATk BviwpCAU8A4cctT31+C5+D3vzTgsEan2Ozk+uUY2GEbUuow/Vo0rUquYf+PgYLV7gqmB SE3xaNlBiZiAfsxnxvkfGsUFJmWPt5D36d+wWG74sqY5q7SK9pBvzau7f6eE8ow9GiMW 5Y5uQbnTTptRXyjqnBrfDYcA+syfvSK1Tw7hx0ZVHxFohKKtuFOe3arLncEQL1TlA2X+ /0dj8ZWERcGX1HRrsRD+ab+I8hJ1T3XIq8ibPL6EJ0SO2KZOm/DNXHTH9WrKeu6y08Ty C/yw== 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=1uDQqEDj12FGjfFLhWqY7mUHJCOn+q/keM9wT3A+eqU=; b=cpQ1fnjV5U9nEGGzKeRlytPsInH/06OFAX9kkGv6QilITfCa20XYwvc+Ph9xUlCfDL hl+TjeK1M4Ktw3xckK3TGGgOu4WwzmpjDPZzzcil8wlktl3TWceVarHaVpZU8n5k2BvI nZwiC0DxGbpzgvdARA7nXHAnBUOqybsN8H3g9X6dq1pCNdbFTHpGiJuDIFJoNGCwCnxv tCtoJDCaYiwTva+GqSa4F5Z2GDomwdQbIxx2Rlnbo2mHHiT7o9bWtsfY61L8h2Q9nW7k RURXh2vxbXZcd4y4j+24iJXM9gnuunP/JdJPqe6beVrYRVTz9ygjjlbYQs24rHKUko/U 1UCQ== X-Gm-Message-State: AOAM533yTqDqdDb10ut2IDdrIFW3UuMNCVzTevBFhoRMPhjUSTUK944d jbKGwlqAOkUUcp5pdltvVozOOTQUdLq22uJN X-Google-Smtp-Source: ABdhPJxXRIJwAUwlA84RrfsnRC39r5nq+D3SPvop0oYvBsaJi88ihWyF/mdD/asFlIn+3WohVeOBpA== X-Received: by 2002:a50:a683:: with SMTP id e3mr3802727edc.33.1603976035841; Thu, 29 Oct 2020 05:53:55 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:53:55 -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 Date: Thu, 29 Oct 2020 12:53:33 +0000 Message-Id: <20201029125339.30916-2-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 2/8] examples/l3fwd-acl: 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: 361b2e9559 ("acl: new sample l3fwd-acl") Cc: konstantin.ananyev@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/l3fwd-acl/main.c | 189 +++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 92 deletions(-) diff --git a/examples/l3fwd-acl/main.c b/examples/l3fwd-acl/main.c index 961594f5f..5c8de1fc0 100644 --- a/examples/l3fwd-acl/main.c +++ b/examples/l3fwd-acl/main.c @@ -195,13 +195,24 @@ send_single_packet(struct rte_mbuf *m, uint16_t port); #define ACL_LEAD_CHAR ('@') #define ROUTE_LEAD_CHAR ('R') #define COMMENT_LEAD_CHAR ('#') + +enum{ #define OPTION_CONFIG "config" + OPTION_CONFIG_NUM = 256, #define OPTION_NONUMA "no-numa" + OPTION_NONUMA_NUM, #define OPTION_ENBJMO "enable-jumbo" + OPTION_ENBJMO_NUM, #define OPTION_RULE_IPV4 "rule_ipv4" + OPTION_RULE_IPV4_NUM, #define OPTION_RULE_IPV6 "rule_ipv6" + OPTION_RULE_IPV6_NUM, #define OPTION_ALG "alg" + OPTION_ALG_NUM, #define OPTION_ETH_DEST "eth-dest" + OPTION_ETH_DEST_NUM, +}; + #define ACL_DENY_SIGNATURE 0xf0000000 #define RTE_LOGTYPE_L3FWDACL RTE_LOGTYPE_USER3 #define acl_log(format, ...) RTE_LOG(ERR, L3FWDACL, format, ##__VA_ARGS__) @@ -1747,13 +1758,13 @@ parse_args(int argc, char **argv) int option_index; char *prgname = argv[0]; static struct option lgopts[] = { - {OPTION_CONFIG, 1, 0, 0}, - {OPTION_NONUMA, 0, 0, 0}, - {OPTION_ENBJMO, 0, 0, 0}, - {OPTION_RULE_IPV4, 1, 0, 0}, - {OPTION_RULE_IPV6, 1, 0, 0}, - {OPTION_ALG, 1, 0, 0}, - {OPTION_ETH_DEST, 1, 0, 0}, + {OPTION_CONFIG, 1, NULL, OPTION_CONFIG_NUM}, + {OPTION_NONUMA, 0, NULL, OPTION_NONUMA_NUM}, + {OPTION_ENBJMO, 0, NULL, OPTION_ENBJMO_NUM}, + {OPTION_RULE_IPV4, 1, NULL, OPTION_RULE_IPV4_NUM}, + {OPTION_RULE_IPV6, 1, NULL, OPTION_RULE_IPV6_NUM}, + {OPTION_ALG, 1, NULL, OPTION_ALG_NUM}, + {OPTION_ETH_DEST, 1, NULL, OPTION_ETH_DEST_NUM}, {NULL, 0, 0, 0} }; @@ -1778,98 +1789,92 @@ parse_args(int argc, char **argv) break; /* long options */ - case 0: - if (!strncmp(lgopts[option_index].name, - OPTION_CONFIG, - sizeof(OPTION_CONFIG))) { - ret = parse_config(optarg); - if (ret) { - printf("invalid config\n"); - print_usage(prgname); - return -1; - } - } - - if (!strncmp(lgopts[option_index].name, - OPTION_NONUMA, - sizeof(OPTION_NONUMA))) { - printf("numa is disabled\n"); - numa_on = 0; - } - - if (!strncmp(lgopts[option_index].name, - OPTION_ENBJMO, sizeof(OPTION_ENBJMO))) { - struct option lenopts = { - "max-pkt-len", - required_argument, - 0, - 0 - }; - - printf("jumbo frame is enabled\n"); - port_conf.rxmode.offloads |= - DEV_RX_OFFLOAD_JUMBO_FRAME; - port_conf.txmode.offloads |= - DEV_TX_OFFLOAD_MULTI_SEGS; - - /* - * if no max-pkt-len set, then use the - * default value RTE_ETHER_MAX_LEN - */ - if (0 == getopt_long(argc, argvopt, "", - &lenopts, &option_index)) { - ret = parse_max_pkt_len(optarg); - if ((ret < 64) || - (ret > MAX_JUMBO_PKT_LEN)) { - printf("invalid packet " - "length\n"); - print_usage(prgname); - return -1; - } - port_conf.rxmode.max_rx_pkt_len = ret; - } - printf("set jumbo frame max packet length " - "to %u\n", - (unsigned int) - port_conf.rxmode.max_rx_pkt_len); - } - - if (!strncmp(lgopts[option_index].name, - OPTION_RULE_IPV4, - sizeof(OPTION_RULE_IPV4))) - parm_config.rule_ipv4_name = optarg; - - if (!strncmp(lgopts[option_index].name, - OPTION_RULE_IPV6, - sizeof(OPTION_RULE_IPV6))) { - parm_config.rule_ipv6_name = optarg; + case OPTION_CONFIG_NUM: + { + ret = parse_config(optarg); + if (ret) { + printf("invalid config\n"); + print_usage(prgname); + return -1; } - - if (!strncmp(lgopts[option_index].name, - OPTION_ALG, sizeof(OPTION_ALG))) { - parm_config.alg = parse_acl_alg(optarg); - if (parm_config.alg == - RTE_ACL_CLASSIFY_DEFAULT) { - printf("unknown %s value:\"%s\"\n", - OPTION_ALG, optarg); + break; + } + case OPTION_NONUMA_NUM: + { + printf("numa is disabled\n"); + numa_on = 0; + break; + } + case OPTION_ENBJMO_NUM: + { + struct option lenopts = { + "max-pkt-len", + required_argument, + 0, + 0 + }; + + printf("jumbo frame is enabled\n"); + port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_JUMBO_FRAME; + port_conf.txmode.offloads |= + DEV_TX_OFFLOAD_MULTI_SEGS; + + /* + * if no max-pkt-len set, then use the + * default value RTE_ETHER_MAX_LEN + */ + if (0 == getopt_long(argc, argvopt, "", + &lenopts, &option_index)) { + ret = parse_max_pkt_len(optarg); + if ((ret < 64) || + (ret > MAX_JUMBO_PKT_LEN)) { + printf("invalid packet " + "length\n"); print_usage(prgname); return -1; } + port_conf.rxmode.max_rx_pkt_len = ret; } - - if (!strncmp(lgopts[option_index].name, OPTION_ETH_DEST, - sizeof(OPTION_ETH_DEST))) { - const char *serr = parse_eth_dest(optarg); - if (serr != NULL) { - printf("invalid %s value:\"%s\": %s\n", - OPTION_ETH_DEST, optarg, serr); - print_usage(prgname); - return -1; - } + printf("set jumbo frame max packet length " + "to %u\n", + (unsigned int) + port_conf.rxmode.max_rx_pkt_len); + break; + } + case OPTION_RULE_IPV4_NUM: + { + parm_config.rule_ipv4_name = optarg; + break; + } + case OPTION_RULE_IPV6_NUM: + { + parm_config.rule_ipv6_name = optarg; + break; + } + case OPTION_ALG_NUM: + { + parm_config.alg = parse_acl_alg(optarg); + if (parm_config.alg == + RTE_ACL_CLASSIFY_DEFAULT) { + printf("unknown %s value:\"%s\"\n", + OPTION_ALG, optarg); + print_usage(prgname); + return -1; } - break; - + } + case OPTION_ETH_DEST_NUM: + { + const char *serr = parse_eth_dest(optarg); + if (serr != NULL) { + printf("invalid %s value:\"%s\": %s\n", + OPTION_ETH_DEST, optarg, serr); + print_usage(prgname); + return -1; + } + break; + } default: print_usage(prgname); return -1; From patchwork Thu Oct 29 12:53:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82770 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 F2C6AA04B5; Thu, 29 Oct 2020 13:56:15 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 04042CD03; Thu, 29 Oct 2020 13:54:05 +0100 (CET) Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by dpdk.org (Postfix) with ESMTP id D2A68CA5C for ; Thu, 29 Oct 2020 13:54:03 +0100 (CET) Received: by mail-ej1-f67.google.com with SMTP id j24so3616103ejc.11 for ; Thu, 29 Oct 2020 05:54:03 -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=xXKTbnGtKWaEgsa4QoaqvKSiRh+sY9mJw0C0OoTiF30=; b=h4YUX/e1w0qs1tTtR055OIaeaXWPhCl+EV1uhtNrGee10sZ/xrVg9NxdjAjdopkclP uHRTMgycGd+5PN1cDvAQ/te79wd2gg1GawPzOYV7hKZ1L68pyGB9RRzfCgCltFeFDti5 ixZE09riOrEJxhOqCrlxLUruJZOdiLK/yHXsbIJ81yys607mi0XOLuqIdG8CP3Rr2bhH ZuoDp+Z/LKjQRePrsk0Dn6ByTFy8RLyzSEDxMmdH+32hLm7kIPewrN37wXbVFmOLl2rI P4e0oySwaFbGnEeuBC5gApZJzE9aG0XdiFDwFKUKZvUGyTJbW3819hX3MGk/L9AnbxiF d32Q== 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=xXKTbnGtKWaEgsa4QoaqvKSiRh+sY9mJw0C0OoTiF30=; b=t/MDq94vguJ4ESnnOAs5TzCyhASjBYsCAX4GMTBsvwpfYFhX9XOnDCtVhm9CyyiMtV H3GaboToV3QfxelAw8Zj6l2TUpPpood+4efk+kZ8QjBIh5K+e6/nR99pE8zMhKHXvrxw kNxz0JyYJYv2y4WG0kIMVgCgpJmZ55kxV+wLVnJqIKXUWGr1q602NeV3Di5+Y6v3EAUd g+uRDHaOm1Y+UJt01n3YBHkMqapzEK0uz/MeAtXdZzgCGM88trND3wF44G0yMyg40AT3 yyJXtPZK2i/SkxhLi1M6xKGN0mvdjxKfmvoYyuBPL/kcl/tm3bXd19BrbaoFBlpfjwpb qw+w== X-Gm-Message-State: AOAM530Ri8MbO+YuijxmYKPI7JFB9CPcp6AFYvhtC+q23qYQALUPmS2o wqRPbXFIXkSlAZ+FwDYOK5i8vw== X-Google-Smtp-Source: ABdhPJxXNHVWblGG5GteXlnDAH8Jsiw+1wlilSf+QgQWfmH87cImUMrDm9CCXio7JA00SWqEYJr89A== X-Received: by 2002:a17:906:7016:: with SMTP id n22mr4139428ejj.402.1603976042641; Thu, 29 Oct 2020 05:54:02 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:02 -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 , sergio.gonzalez.monroy@intel.com, phil.yang@arm.com Date: Thu, 29 Oct 2020 12:53:34 +0000 Message-Id: <20201029125339.30916-3-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 3/8] examples/packet_ordering: 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: 850f3733f8 ("examples/packet_ordering: new sample app") Fixes: 016493307a ("examples/packet_ordering: add stats per worker thread") Cc: sergio.gonzalez.monroy@intel.com Cc: phil.yang@arm.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/packet_ordering/main.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c index a79d77a32..ac41d1a88 100644 --- a/examples/packet_ordering/main.c +++ b/examples/packet_ordering/main.c @@ -29,6 +29,13 @@ /* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_REORDERAPP RTE_LOGTYPE_USER1 +enum{ +#define OPTION_DISABLE_REORDER "disable-reorder" + OPTION_DISABLE_REORDER_NUM = 256, +#define OPTION_INSIGHT_WORKER "insight-worker" + OPTION_INSIGHT_WORKER_NUM, +}; + unsigned int portmask; unsigned int disable_reorder; unsigned int insight_worker; @@ -157,8 +164,8 @@ parse_args(int argc, char **argv) char **argvopt; char *prgname = argv[0]; static struct option lgopts[] = { - {"disable-reorder", 0, 0, 0}, - {"insight-worker", 0, 0, 0}, + {OPTION_DISABLE_REORDER, 0, NULL, OPTION_DISABLE_REORDER_NUM}, + {OPTION_INSIGHT_WORKER, 0, NULL, OPTION_INSIGHT_WORKER_NUM}, {NULL, 0, 0, 0} }; @@ -177,17 +184,18 @@ parse_args(int argc, char **argv) } break; /* long options */ - case 0: - if (!strcmp(lgopts[option_index].name, "disable-reorder")) { - printf("reorder disabled\n"); - disable_reorder = 1; - } - if (!strcmp(lgopts[option_index].name, - "insight-worker")) { - printf("print all worker statistics\n"); - insight_worker = 1; - } + case OPTION_DISABLE_REORDER_NUM: + { + printf("reorder disabled\n"); + disable_reorder = 1; break; + } + case OPTION_INSIGHT_WORKER_NUM: + { + printf("print all worker statistics\n"); + insight_worker = 1; + break; + } default: print_usage(prgname); return -1; From patchwork Thu Oct 29 12:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82771 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 F1FD5A04B5; Thu, 29 Oct 2020 13:56:39 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06116CD0C; Thu, 29 Oct 2020 13:54:10 +0100 (CET) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by dpdk.org (Postfix) with ESMTP id 3B9D9CB77 for ; Thu, 29 Oct 2020 13:54:09 +0100 (CET) Received: by mail-ed1-f65.google.com with SMTP id x1so2944984eds.1 for ; Thu, 29 Oct 2020 05:54:09 -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=hh3g5WzqD5S+zUs5HGu2JK9e4iFTPeM4q2faRMtwklA=; b=BQz0M5JFK2EEOKs76fAcNRgIsg9sLom6Aj3kOLjqmJiwVuPSukHkHFRNxDtbFkRyvr njRLq7Z4bXat4KLXUUYH/DBCgaN8H0kMwEsWx+9qMSKApNK/IjSNWI1KRMWq5x8maSd4 RXr0070equr56Wkbs72MfMm3WJqPANb6zEvGzkt5nDQm7QeK6VQKyWNJm+V/GQM4LosP YD1+Jrk5VDIdIm2nzyF7XIm1QFYXjvFnqFAJLIIQ6GCdvB1+3tgxLopNkGGRv8yedIim KmdjfkJ/CTuMAECBuWGpsEIrQFTuocbVi01MB8UaQpSL8XClq4fJfqJuBd/STa0YsYZ3 6zFA== 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=hh3g5WzqD5S+zUs5HGu2JK9e4iFTPeM4q2faRMtwklA=; b=TDKoVN/loHcGYRdfy4wvq7b31pt4KXQOW7ZQzuua8zvRWoas8/l0JjnU8WZlUZFlmN 2YpGNw2o4DOmHekYlQZV7OdRfdnSeSBwxsimo6l7L84rGqZliA0TTDoEFmCCqQ+JmjKm UQnyE/pp8cr7RPFBmPMikcZW3yuJOG/rmYOMk7VCzYetkvRLAUwomt0PFpRi+qamChcQ TzfzB15BeovVetxShSj2hvRAjT4oSy/169WM6tkataslB/n9HBCmBGeF5X7BJw16RBKn Wf1vumXE+nMUlfJlzrDx3Tb32s8KYxzdjCj3tQCZkWKytTfbpkAFwKjsLFA93efplXbo 2NuQ== X-Gm-Message-State: AOAM530+Wp2ACYvUKjKa1AP+O4rrmptahPoAMa+ceBwW5GL4wRkRZT+u 4kO7iEqFAAr9/EuDvSxYIzmEXA== X-Google-Smtp-Source: ABdhPJwW6kjYNd7Y5RveKANt2gpt9xsRAG0GjzgVvhgZHKPVYdSUPb6em3FzIS8bWlWYdOc8GqP6qw== X-Received: by 2002:a05:6402:1d13:: with SMTP id dg19mr3887268edb.217.1603976047923; Thu, 29 Oct 2020 05:54:07 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:07 -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 , ian.betts@intel.com Date: Thu, 29 Oct 2020 12:53:35 +0000 Message-Id: <20201029125339.30916-4-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 4/8] examples/performance-thread/l3fwd-thread: 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: d48415e1fe ("examples/performance-thread: add l3fwd-thread app") Cc: ian.betts@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- .../performance-thread/l3fwd-thread/main.c | 221 ++++++++++-------- 1 file changed, 121 insertions(+), 100 deletions(-) diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c index e96076f29..3de33438f 100644 --- a/examples/performance-thread/l3fwd-thread/main.c +++ b/examples/performance-thread/l3fwd-thread/main.c @@ -2858,18 +2858,28 @@ parse_eth_dest(const char *optarg) dest[c] = peer_addr[c]; *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid]; } - +enum { #define CMD_LINE_OPT_RX_CONFIG "rx" + CMD_LINE_OPT_RX_CONFIG_NUM = 256, #define CMD_LINE_OPT_TX_CONFIG "tx" + CMD_LINE_OPT_TX_CONFIG_NUM, #define CMD_LINE_OPT_STAT_LCORE "stat-lcore" + CMD_LINE_OPT_STAT_LCORE_NUM, #define CMD_LINE_OPT_ETH_DEST "eth-dest" + CMD_LINE_OPT_ETH_DEST_NUM, #define CMD_LINE_OPT_NO_NUMA "no-numa" + CMD_LINE_OPT_NO_NUMA_NUM, #define CMD_LINE_OPT_IPV6 "ipv6" + CMD_LINE_OPT_IPV6_NUM, #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" + CMD_LINE_OPT_ENABLE_JUMBO_NUM, #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num" + CMD_LINE_OPT_HASH_ENTRY_NUM_NUM, #define CMD_LINE_OPT_NO_LTHREADS "no-lthreads" + CMD_LINE_OPT_NO_LTHREADS_NUM, #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" - + CMD_LINE_OPT_PARSE_PTYPE_NUM, +}; /* Parse the argument given in the command line of the application */ static int parse_args(int argc, char **argv) @@ -2879,16 +2889,26 @@ parse_args(int argc, char **argv) int option_index; char *prgname = argv[0]; static struct option lgopts[] = { - {CMD_LINE_OPT_RX_CONFIG, 1, 0, 0}, - {CMD_LINE_OPT_TX_CONFIG, 1, 0, 0}, - {CMD_LINE_OPT_STAT_LCORE, 1, 0, 0}, - {CMD_LINE_OPT_ETH_DEST, 1, 0, 0}, - {CMD_LINE_OPT_NO_NUMA, 0, 0, 0}, - {CMD_LINE_OPT_IPV6, 0, 0, 0}, - {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0}, - {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0}, - {CMD_LINE_OPT_NO_LTHREADS, 0, 0, 0}, - {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0}, + {CMD_LINE_OPT_RX_CONFIG, 1, + NULL, CMD_LINE_OPT_RX_CONFIG_NUM}, + {CMD_LINE_OPT_TX_CONFIG, 1, + NULL, CMD_LINE_OPT_TX_CONFIG_NUM}, + {CMD_LINE_OPT_STAT_LCORE, 1, + NULL, CMD_LINE_OPT_STAT_LCORE_NUM}, + {CMD_LINE_OPT_ETH_DEST, 1, + NULL, CMD_LINE_OPT_ETH_DEST_NUM}, + {CMD_LINE_OPT_NO_NUMA, 0, + NULL, CMD_LINE_OPT_NO_NUMA_NUM}, + {CMD_LINE_OPT_IPV6, 0, + NULL, CMD_LINE_OPT_IPV6_NUM}, + {CMD_LINE_OPT_ENABLE_JUMBO, 0, + NULL, CMD_LINE_OPT_ENABLE_JUMBO_NUM}, + {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, + NULL, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM}, + {CMD_LINE_OPT_NO_LTHREADS, 0, + NULL, CMD_LINE_OPT_NO_LTHREADS_NUM}, + {CMD_LINE_OPT_PARSE_PTYPE, 0, + NULL, CMD_LINE_OPT_PARSE_PTYPE_NUM}, {NULL, 0, 0, 0} }; @@ -2913,107 +2933,108 @@ parse_args(int argc, char **argv) break; /* long options */ - case 0: - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_RX_CONFIG, - sizeof(CMD_LINE_OPT_RX_CONFIG))) { - ret = parse_rx_config(optarg); - if (ret) { - printf("invalid rx-config\n"); - print_usage(prgname); - return -1; - } + case CMD_LINE_OPT_RX_CONFIG_NUM: + { + ret = parse_rx_config(optarg); + if (ret) { + printf("invalid rx-config\n"); + print_usage(prgname); + return -1; } - - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_TX_CONFIG, - sizeof(CMD_LINE_OPT_TX_CONFIG))) { - ret = parse_tx_config(optarg); - if (ret) { - printf("invalid tx-config\n"); - print_usage(prgname); - return -1; - } + break; + } + case CMD_LINE_OPT_TX_CONFIG_NUM: + { + ret = parse_tx_config(optarg); + if (ret) { + printf("invalid tx-config\n"); + print_usage(prgname); + return -1; } + break; + } #if (APP_CPU_LOAD > 0) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_STAT_LCORE, - sizeof(CMD_LINE_OPT_STAT_LCORE))) { - cpu_load_lcore_id = parse_stat_lcore(optarg); - } + case CMD_LINE_OPT_STAT_LCORE_NUM: + { + cpu_load_lcore_id = parse_stat_lcore(optarg); + break; + } #endif - - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ETH_DEST, - sizeof(CMD_LINE_OPT_ETH_DEST))) - parse_eth_dest(optarg); - - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA, - sizeof(CMD_LINE_OPT_NO_NUMA))) { - printf("numa is disabled\n"); - numa_on = 0; - } - + case CMD_LINE_OPT_ETH_DEST_NUM: + { + parse_eth_dest(optarg); + break; + } + case CMD_LINE_OPT_NO_NUMA_NUM: + { + printf("numa is disabled\n"); + numa_on = 0; + break; + } #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_IPV6, - sizeof(CMD_LINE_OPT_IPV6))) { - printf("ipv6 is specified\n"); - ipv6 = 1; - } + case CMD_LINE_OPT_IPV6_NUM: + { + printf("ipv6 is specified\n"); + ipv6 = 1; + break; + } #endif + case CMD_LINE_OPT_NO_LTHREADS_NUM: + { + printf("l-threads model is disabled\n"); + lthreads_on = 0; + break; + } + case CMD_LINE_OPT_PARSE_PTYPE_NUM: + { + printf("software packet type parsing enabled\n"); + parse_ptype_on = 1; + break; + } + case CMD_LINE_OPT_ENABLE_JUMBO_NUM: + { + struct option lenopts = {"max-pkt-len", + required_argument, 0, 0}; + + printf("jumbo frame is enabled - disabling simple TX path\n"); + port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_JUMBO_FRAME; + port_conf.txmode.offloads |= + DEV_TX_OFFLOAD_MULTI_SEGS; + + /* if no max-pkt-len set, use the default value + * RTE_ETHER_MAX_LEN + */ + if (0 == getopt_long(argc, argvopt, "", &lenopts, + &option_index)) { - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_LTHREADS, - sizeof(CMD_LINE_OPT_NO_LTHREADS))) { - printf("l-threads model is disabled\n"); - lthreads_on = 0; - } - - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_PARSE_PTYPE, - sizeof(CMD_LINE_OPT_PARSE_PTYPE))) { - printf("software packet type parsing enabled\n"); - parse_ptype_on = 1; - } - - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_JUMBO, - sizeof(CMD_LINE_OPT_ENABLE_JUMBO))) { - struct option lenopts = {"max-pkt-len", required_argument, 0, - 0}; - - printf("jumbo frame is enabled - disabling simple TX path\n"); - port_conf.rxmode.offloads |= - DEV_RX_OFFLOAD_JUMBO_FRAME; - port_conf.txmode.offloads |= - DEV_TX_OFFLOAD_MULTI_SEGS; - - /* if no max-pkt-len set, use the default value - * RTE_ETHER_MAX_LEN - */ - if (0 == getopt_long(argc, argvopt, "", &lenopts, - &option_index)) { - - ret = parse_max_pkt_len(optarg); - if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) { - printf("invalid packet length\n"); - print_usage(prgname); - return -1; - } - port_conf.rxmode.max_rx_pkt_len = ret; - } - printf("set jumbo frame max packet length to %u\n", - (unsigned int)port_conf.rxmode.max_rx_pkt_len); - } -#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_HASH_ENTRY_NUM, - sizeof(CMD_LINE_OPT_HASH_ENTRY_NUM))) { - ret = parse_hash_entry_number(optarg); - if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) { - hash_entry_number = ret; - } else { - printf("invalid hash entry number\n"); + ret = parse_max_pkt_len(optarg); + if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) { + printf("invalid packet length\n"); print_usage(prgname); return -1; } + port_conf.rxmode.max_rx_pkt_len = ret; } -#endif + printf("set jumbo frame max packet length to %u\n", + (unsigned int)port_conf.rxmode.max_rx_pkt_len); break; - + } +#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) + case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM: + { + ret = parse_hash_entry_number(optarg); + if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) { + hash_entry_number = ret; + } else { + printf("invalid hash entry number\n"); + print_usage(prgname); + return -1; + } + break; + } +#endif default: print_usage(prgname); return -1; From patchwork Thu Oct 29 12:53:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82772 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 1413CA04B5; Thu, 29 Oct 2020 13:56:59 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7F06ECDB2; Thu, 29 Oct 2020 13:54:16 +0100 (CET) Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by dpdk.org (Postfix) with ESMTP id 54F54CD45 for ; Thu, 29 Oct 2020 13:54:14 +0100 (CET) Received: by mail-ed1-f67.google.com with SMTP id w25so2949753edx.2 for ; Thu, 29 Oct 2020 05:54:14 -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=7TLpnV0i2RdCBqHiVAFELll23TafIhKVlHVsgadQudE=; b=mmoaflowPEyQ9sqxXNwNcX4K4udBM7e5mSlm31F4eRulFCFsyx9UQwdFzH0VyoLQU1 lGnD4jZCHx0Nhjsd9q3e4W0kJ+4IDhF3dMNPvhMZW1ryN9eTYFW+HwfoWDxEwv4wX2TS ago4INWu0Uq9Nw1r2JRx04sGnUbN6uXyKZyToEdB+QDJkqdS/bOQOOvBW/O5fnoTOSjW TkjC4yig6lNJxD5tTF1CUV0JQmdubsbeNpSNXsygaYPPHRbDb16BxH/pdebdWn0FaFmw 29PwtiSFf+CK3KvndrzK7bjb5ul1ZpRLZGhiN/9CwtP62ucj05kLu5AtgrL7afj+p0od hvmQ== 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=7TLpnV0i2RdCBqHiVAFELll23TafIhKVlHVsgadQudE=; b=CEccIQO3A9e5lsvBsglBMplo2xPiIUMIpCMmtNj5T7/tQcJcwn46Fze8r2U6aH85Wb /A6oISQoExDcJwGSgOStr57D3ALKeqBrEy3xW3/L9C44tmDLbbXFm6shI1pFhocg47kJ CC+VYIQlQCqyPOnDCWW0PgVShRnWVqtyskYxGmIY4HcxN90BClzZprIAxNRh4l1hqdaJ zc9xLeyC0zLWmNl6t4+Jowfym8hpq2dMWtGVi9xd2fxmVTiTXS8DGYa446h0CHfboRBu PANdQReqmscIiiqas4snG7J2R3f6i36xC6T2JbIF4j4PvnH2kphiHl+u/p3blK9oyttb DX8Q== X-Gm-Message-State: AOAM532gdBawJsvOPbiIMEzkdCgzWWWPRz654x2JY3RrbXwTRbrcjjvH L9ywZu+nYawRqx4GyNHFCWmwUw== X-Google-Smtp-Source: ABdhPJyYJSD4y6TP9CQwovLRpA065vL0R4XuywdOdqNW9bRNR0+nSlmoSUbgTSxt/RD0e7eCpRQHww== X-Received: by 2002:a05:6402:289:: with SMTP id l9mr3882983edv.294.1603976053050; Thu, 29 Oct 2020 05:54:13 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:12 -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 , stephen@networkplumber.org Date: Thu, 29 Oct 2020 12:53:36 +0000 Message-Id: <20201029125339.30916-5-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 5/8] examples/qos_sched: 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: de3cfa2c98 ("sched: initial import") Fixes: cb056611a8 ("eal: rename lcore master and slave") Cc: stephen@networkplumber.org Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/qos_sched/args.c | 161 +++++++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 62 deletions(-) diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c index c62719623..8411a87b5 100644 --- a/examples/qos_sched/args.c +++ b/examples/qos_sched/args.c @@ -297,6 +297,25 @@ app_parse_burst_conf(const char *conf_str) return 0; } +enum { +#define CMD_LINE_OPT_PFC "pfc" + CMD_LINE_OPT_PFC_NUM = 256, +#define CMD_LINE_OPT_MNC "mnc" + CMD_LINE_OPT_MNC_NUM, +#define CMD_LINE_OPT_RSZ "rsz" + CMD_LINE_OPT_RSZ_NUM, +#define CMD_LINE_OPT_BSZ "bsz" + CMD_LINE_OPT_BSZ_NUM, +#define CMD_LINE_OPT_MSZ "msz" + CMD_LINE_OPT_MSZ_NUM, +#define CMD_LINE_OPT_RTH "rth" + CMD_LINE_OPT_RTH_NUM, +#define CMD_LINE_OPT_TTH "tth" + CMD_LINE_OPT_TTH_NUM, +#define CMD_LINE_OPT_CFG "cfg" + CMD_LINE_OPT_CFG_NUM, +}; + /* * Parses the argument given in the command line of the application, * calculates mask for used cores and initializes EAL with calculated core mask @@ -306,19 +325,26 @@ app_parse_args(int argc, char **argv) { int opt, ret; int option_index; - const char *optname; char *prgname = argv[0]; uint32_t i, nb_lcores; static struct option lgopts[] = { - { "pfc", 1, 0, 0 }, - { "mnc", 1, 0, 0 }, - { "rsz", 1, 0, 0 }, - { "bsz", 1, 0, 0 }, - { "msz", 1, 0, 0 }, - { "rth", 1, 0, 0 }, - { "tth", 1, 0, 0 }, - { "cfg", 1, 0, 0 }, + { CMD_LINE_OPT_PFC, 1, + NULL, CMD_LINE_OPT_PFC_NUM }, + { CMD_LINE_OPT_MNC, 1, + NULL, CMD_LINE_OPT_MNC_NUM}, + { CMD_LINE_OPT_RSZ, 1, + NULL, CMD_LINE_OPT_RSZ_NUM}, + { CMD_LINE_OPT_BSZ, 1, + NULL, CMD_LINE_OPT_BSZ_NUM}, + { CMD_LINE_OPT_MSZ, 1, + NULL, CMD_LINE_OPT_MSZ_NUM}, + { CMD_LINE_OPT_RTH, 1, + NULL, CMD_LINE_OPT_RTH_NUM}, + { CMD_LINE_OPT_TTH, 1, + NULL, CMD_LINE_OPT_TTH_NUM}, + { CMD_LINE_OPT_CFG, 1, + NULL, CMD_LINE_OPT_CFG_NUM}, { NULL, 0, 0, 0 } }; @@ -342,66 +368,77 @@ app_parse_args(int argc, char **argv) interactive = 1; break; /* long options */ - case 0: - optname = lgopts[option_index].name; - if (str_is(optname, "pfc")) { - ret = app_parse_flow_conf(optarg); - if (ret) { - RTE_LOG(ERR, APP, "Invalid pipe configuration %s\n", optarg); - return -1; - } - break; - } - if (str_is(optname, "mnc")) { - app_main_core = (uint32_t)atoi(optarg); - break; - } - if (str_is(optname, "rsz")) { - ret = app_parse_ring_conf(optarg); - if (ret) { - RTE_LOG(ERR, APP, "Invalid ring configuration %s\n", optarg); - return -1; - } - break; + + case CMD_LINE_OPT_PFC_NUM: + { + ret = app_parse_flow_conf(optarg); + if (ret) { + RTE_LOG(ERR, APP, "Invalid pipe configuration %s\n", + optarg); + return -1; } - if (str_is(optname, "bsz")) { - ret = app_parse_burst_conf(optarg); - if (ret) { - RTE_LOG(ERR, APP, "Invalid burst configuration %s\n", optarg); - return -1; - } - break; + break; + } + case CMD_LINE_OPT_MNC_NUM: + { + app_main_core = (uint32_t)atoi(optarg); + break; + } + case CMD_LINE_OPT_RSZ_NUM: + { + ret = app_parse_ring_conf(optarg); + if (ret) { + RTE_LOG(ERR, APP, "Invalid ring configuration %s\n", + optarg); + return -1; } - if (str_is(optname, "msz")) { - mp_size = atoi(optarg); - if (mp_size <= 0) { - RTE_LOG(ERR, APP, "Invalid mempool size %s\n", optarg); - return -1; - } - break; + break; + } + case CMD_LINE_OPT_BSZ_NUM: + { + ret = app_parse_burst_conf(optarg); + if (ret) { + RTE_LOG(ERR, APP, "Invalid burst configuration %s\n", + optarg); + return -1; } - if (str_is(optname, "rth")) { - ret = app_parse_rth_conf(optarg); - if (ret) { - RTE_LOG(ERR, APP, "Invalid RX threshold configuration %s\n", optarg); - return -1; - } - break; + break; + } + case CMD_LINE_OPT_MSZ_NUM: + { + mp_size = atoi(optarg); + if (mp_size <= 0) { + RTE_LOG(ERR, APP, "Invalid mempool size %s\n", + optarg); + return -1; } - if (str_is(optname, "tth")) { - ret = app_parse_tth_conf(optarg); - if (ret) { - RTE_LOG(ERR, APP, "Invalid TX threshold configuration %s\n", optarg); - return -1; - } - break; + break; + } + case CMD_LINE_OPT_RTH_NUM: + { + ret = app_parse_rth_conf(optarg); + if (ret) { + RTE_LOG(ERR, APP, "Invalid RX threshold configuration %s\n", + optarg); + return -1; } - if (str_is(optname, "cfg")) { - cfg_profile = optarg; - break; + break; + } + case CMD_LINE_OPT_TTH_NUM: + { + ret = app_parse_tth_conf(optarg); + if (ret) { + RTE_LOG(ERR, APP, "Invalid TX threshold configuration %s\n", + optarg); + return -1; } break; - + } + case CMD_LINE_OPT_CFG_NUM: + { + cfg_profile = optarg; + break; + } default: app_usage(prgname); return -1; From patchwork Thu Oct 29 12:53:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82773 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 D2295A04B5; Thu, 29 Oct 2020 13:57:17 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 87774CCA9; Thu, 29 Oct 2020 13:54:21 +0100 (CET) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by dpdk.org (Postfix) with ESMTP id DAC72CD2D for ; Thu, 29 Oct 2020 13:54:18 +0100 (CET) Received: by mail-ed1-f65.google.com with SMTP id dn5so2877400edb.10 for ; Thu, 29 Oct 2020 05:54:18 -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=v54L7UD6yejsgEALST3TN0JngpIJRZj5J+lHDtSeOQg=; b=K2lz75wocoF1k2rYRw8IMVZWIjYSIPvCg2ASsXbfpdijFmVMxuu9wedVuWv4vg3Xyo 57HfBpuBHb8UjXx7pIbLRtP4REAX84Z1mourfu1amzv2U1W6xbfBZBBbTK2MAnWhTygQ TnpIcWmgSc7h9Ajvr6I8LE9jDdI9WMOf+KZzoOyNyrsGSUbuuCDbsfr3PVq6D7Wap1eE TcdureytTzBWGW1reN49iqOkz3CUbl2cepVQeS1To/sK9ClFxzYEy4hOVa4Vbdch7rbN 9UB7MMj6Ck6Ke5POwZYpW+gqWLz7bJfpmb6DdWt/NQNfGmh9oVkQN6GCr8bVkNOvaiU7 +NXQ== 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=v54L7UD6yejsgEALST3TN0JngpIJRZj5J+lHDtSeOQg=; b=Dg1hoKCvzIYVNkbKgEnLtdqdZgEtwUUX+CoXRkoeKJAivtXd/p4vscOp09vXhMXmHs VEaomfGb4uuxh1WHqDxsR2AnjpJgtkJRNGAJnEOdkp+qK2/dKsrjgvQLktsbaU5jKpzK LagvHjrMfkAIN6fSm079lhZu2PG2sBLahzostxHB5IoTssCUx+FYr8IRF72RBFBd62uv 4p5SE+Fv0wHBXrCBUb/EJ9qyUroVqMGWRYIHUNqMpjcUGFocaNjwEv65D6Fofq7olfqD +sGxCHbdM42jmyBYQ4opFe3/+MU5w35aI7pvR8dA9uZ7UFri03Y/9Xp7OHLhAFWGTVue Kgrg== X-Gm-Message-State: AOAM530kuUUpdeFhxEupXSCalnoXC5MYXNKlIhJsd9ggBkYWNRJ7qojV 7kJL1P/x4aKOOMWGkS73FfIHRw== X-Google-Smtp-Source: ABdhPJxsY6tYb9LX3F78HhHLT1e+QGs1Yh7Rh+elu7cx9QHkQXWngxX47pv/4IkzJgjIDN/HC6yang== X-Received: by 2002:a05:6402:945:: with SMTP id h5mr3918399edz.6.1603976057554; Thu, 29 Oct 2020 05:54:17 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:17 -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 , jiayu.hu@intel.com, huawei.xie@intel.com Date: Thu, 29 Oct 2020 12:53:37 +0000 Message-Id: <20201029125339.30916-6-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 6/8] examples/vhost: 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: d19533e86f ("examples/vhost: copy old vhost example") Fixes: bde19a4d4b ("examples/vhost: rename --dev-basename to --socket-file") Cc: jiayu.hu@intel.com Cc: huawei.xie@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/vhost/main.c | 264 +++++++++++++++++++++++------------------- 1 file changed, 143 insertions(+), 121 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index faa482245..8056cac7a 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -450,6 +450,29 @@ us_vhost_usage(const char *prgname) prgname); } +enum { +#define CMD_LINE_OPT_VM2VM "vm2vm" + CMD_LINE_OPT_VM2VM_NUM = 256, +#define CMD_LINE_OPT_RX_RETRY "rx-retry" + CMD_LINE_OPT_RX_RETRY_NUM, +#define CMD_LINE_OPT_RX_RETRY_DELAY "rx-retry-delay" + 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_MERGEABLE "mergeable" + CMD_LINE_OPT_MERGEABLE_NUM, +#define CMD_LINE_OPT_STATS "stats" + CMD_LINE_OPT_STATS_NUM, +#define CMD_LINE_OPT_SOCKET_FILE "socket-file" + CMD_LINE_OPT_SOCKET_FILE_NUM, +#define CMD_LINE_OPT_TX_CSUM "tx-csum" + CMD_LINE_OPT_TX_CSUM_NUM, +#define CMD_LINE_OPT_TSO "tso" + CMD_LINE_OPT_TSO_NUM, +#define CMD_LINE_OPT_CLIENT "client" +#define CMD_LINE_OPT_BUILTIN_NET_DRIVER "builtin-net-driver" +}; + /* * Parse the arguments given in the command line of the application. */ @@ -461,17 +484,27 @@ us_vhost_parse_args(int argc, char **argv) unsigned i; const char *prgname = argv[0]; static struct option long_option[] = { - {"vm2vm", required_argument, NULL, 0}, - {"rx-retry", required_argument, NULL, 0}, - {"rx-retry-delay", required_argument, NULL, 0}, - {"rx-retry-num", required_argument, NULL, 0}, - {"mergeable", required_argument, NULL, 0}, - {"stats", required_argument, NULL, 0}, - {"socket-file", required_argument, NULL, 0}, - {"tx-csum", required_argument, NULL, 0}, - {"tso", required_argument, NULL, 0}, - {"client", no_argument, &client_mode, 1}, - {"builtin-net-driver", no_argument, &builtin_net_driver, 1}, + {CMD_LINE_OPT_VM2VM, required_argument, + NULL, CMD_LINE_OPT_VM2VM_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_MERGEABLE, required_argument, + NULL, CMD_LINE_OPT_MERGEABLE_NUM}, + {CMD_LINE_OPT_STATS, required_argument, + NULL, CMD_LINE_OPT_STATS_NUM}, + {CMD_LINE_OPT_SOCKET_FILE, required_argument, + NULL, CMD_LINE_OPT_SOCKET_FILE_NUM}, + {CMD_LINE_OPT_TX_CSUM, required_argument, + NULL, CMD_LINE_OPT_TX_CSUM_NUM}, + {CMD_LINE_OPT_TSO, required_argument, + NULL, CMD_LINE_OPT_TSO_NUM}, + {CMD_LINE_OPT_CLIENT, no_argument, &client_mode, 1}, + {CMD_LINE_OPT_BUILTIN_NET_DRIVER, no_argument, + &builtin_net_driver, 1}, {NULL, 0, 0, 0}, }; @@ -497,126 +530,115 @@ us_vhost_parse_args(int argc, char **argv) break; - case 0: - /* Enable/disable vm2vm comms. */ - if (!strncmp(long_option[option_index].name, "vm2vm", - MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, (VM2VM_LAST - 1)); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for " - "vm2vm [0|1|2]\n"); - us_vhost_usage(prgname); - return -1; - } else { - vm2vm_mode = (vm2vm_type)ret; - } + case CMD_LINE_OPT_VM2VM_NUM: + { + ret = parse_num_opt(optarg, (VM2VM_LAST - 1)); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for " + "vm2vm [0|1|2]\n"); + us_vhost_usage(prgname); + return -1; } - - /* Enable/disable retries on RX. */ - if (!strncmp(long_option[option_index].name, "rx-retry", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry [0|1]\n"); - us_vhost_usage(prgname); - return -1; - } else { - enable_retry = ret; - } + vm2vm_mode = (vm2vm_type)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"); + us_vhost_usage(prgname); + return -1; } - - /* Enable/disable TX checksum offload. */ - if (!strncmp(long_option[option_index].name, "tx-csum", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tx-csum [0|1]\n"); - us_vhost_usage(prgname); - return -1; - } else - enable_tx_csum = ret; + enable_retry = ret; + break; + } + case CMD_LINE_OPT_TX_CSUM_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tx-csum [0|1]\n"); + us_vhost_usage(prgname); + return -1; } - - /* Enable/disable TSO offload. */ - if (!strncmp(long_option[option_index].name, "tso", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tso [0|1]\n"); - us_vhost_usage(prgname); - return -1; - } else - enable_tso = ret; + enable_tx_csum = ret; + break; + } + case CMD_LINE_OPT_TSO_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tso [0|1]\n"); + us_vhost_usage(prgname); + return -1; } - - /* Specify the retries delay time (in useconds) on RX. */ - if (!strncmp(long_option[option_index].name, "rx-retry-delay", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-delay [0-N]\n"); - us_vhost_usage(prgname); - return -1; - } else { - burst_rx_delay_time = ret; - } + enable_tso = 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"); + us_vhost_usage(prgname); + return -1; } - - /* Specify the retries number on RX. */ - if (!strncmp(long_option[option_index].name, "rx-retry-num", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-num [0-N]\n"); - us_vhost_usage(prgname); - return -1; - } else { - burst_rx_retry_num = 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"); + us_vhost_usage(prgname); + return -1; } - - /* Enable/disable RX mergeable buffers. */ - if (!strncmp(long_option[option_index].name, "mergeable", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, 1); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for mergeable [0|1]\n"); - us_vhost_usage(prgname); - return -1; - } else { - mergeable = !!ret; - if (ret) { - vmdq_conf_default.rxmode.offloads |= - DEV_RX_OFFLOAD_JUMBO_FRAME; - vmdq_conf_default.rxmode.max_rx_pkt_len - = JUMBO_FRAME_MAX_SIZE; - } - } + burst_rx_retry_num = ret; + break; + } + case CMD_LINE_OPT_MERGEABLE_NUM: + { + ret = parse_num_opt(optarg, 1); + if (ret == -1) { + RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for mergeable [0|1]\n"); + us_vhost_usage(prgname); + return -1; } - - /* Enable/disable stats. */ - if (!strncmp(long_option[option_index].name, "stats", MAX_LONG_OPT_SZ)) { - ret = parse_num_opt(optarg, INT32_MAX); - if (ret == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for stats [0..N]\n"); - us_vhost_usage(prgname); - return -1; - } else { - enable_stats = ret; - } + mergeable = !!ret; + if (ret) { + vmdq_conf_default.rxmode.offloads |= + DEV_RX_OFFLOAD_JUMBO_FRAME; + vmdq_conf_default.rxmode.max_rx_pkt_len + = JUMBO_FRAME_MAX_SIZE; } - - /* Set socket file path. */ - if (!strncmp(long_option[option_index].name, - "socket-file", MAX_LONG_OPT_SZ)) { - if (us_vhost_parse_socket_path(optarg) == -1) { - RTE_LOG(INFO, VHOST_CONFIG, - "Invalid argument for socket name (Max %d characters)\n", - PATH_MAX); - us_vhost_usage(prgname); - return -1; - } + 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"); + us_vhost_usage(prgname); + return -1; } - + enable_stats = ret; break; - - /* Invalid option - print options. */ + } + case CMD_LINE_OPT_SOCKET_FILE_NUM: + { + if (us_vhost_parse_socket_path(optarg) == -1) { + RTE_LOG(INFO, VHOST_CONFIG, + "Invalid argument for socket name (Max %d characters)\n", + PATH_MAX); + us_vhost_usage(prgname); + return -1; + } + break; + } + /* Invalid option - print options. */ default: us_vhost_usage(prgname); return -1; From patchwork Thu Oct 29 12:53:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82774 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 F309BA04B5; Thu, 29 Oct 2020 13:57:43 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7C382CDF2; Thu, 29 Oct 2020 13:54:26 +0100 (CET) Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by dpdk.org (Postfix) with ESMTP id 6B3F5CDCA for ; Thu, 29 Oct 2020 13:54:23 +0100 (CET) Received: by mail-ej1-f66.google.com with SMTP id t25so3596987ejd.13 for ; Thu, 29 Oct 2020 05:54:23 -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=xiMR9VpKeYjtjDyP5wuQiRXfxn2eKnHb8aC3kMCbhz4=; b=G7ih8+IR5VhHeHaNlAMjIXYwuZVbX2qiqkGk4XOWWkmOZBND9IcWjza8Hv0sHdHrIf nCO4Pcdxg/mi1fkVJAihiLRkyMh88mRxwlijCILUquWsYEOWtwZog+ug331prmXsQT46 FuP1otDZy+eXKwRUbT79IRk1EMvY12HLpM1SlUVYcCpfR24QIkjrirPlFHqHblwzaA08 zlrL2jrbWEgjjnRk7ksG5Zk+yUzM66ua7rX4r6g/bcsZJnZHEqMywlYK4YwNlX0GQZ3O 8e7/Ea9VK5QK9HBAKYrmem2dbTMcds79DRGtPWkZ3UHhMpFZ5DJYmNQnTSU2Ez64C+5g cyIg== 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=xiMR9VpKeYjtjDyP5wuQiRXfxn2eKnHb8aC3kMCbhz4=; b=Msc3Vw4wXX0Mo7Q6PSwHOgH0FhG03tmdIi0/Fnr3g6SdvABljACD6Zpdq/Pq90MrCK yA/rAaCVyKZ6BBMSBG6CyxpaA3Oa29KkKjrxjaUjhkI7x43EZFbtjb6eE4FiUCplCGzf ASTqSPHh7ta5BA0b0Pn/oZ67+K+tgFa0l5qmcEqGvnC+H6SbBqmxmVX54WlqCBiuBf6a Q7Y38ydRyvADgWlHx26cMTgBjtGGqeus3wevjYXvi8xdqIR2VjSyEhICHVYb0WWcu9NV zGA2A2Ta44IOvwpsY4H1ch9ewUHilbcWmO3wtumHtARY6+hpAadTTklchIRsOpIgKVXe SI9g== X-Gm-Message-State: AOAM532oq+D+b0XPYefD+CuJd3n0BTzu28ak5GHzHh69RE1whhfuO4lt PLlQT+ABZ0qQ9YDOIKdFwyvdNw== X-Google-Smtp-Source: ABdhPJwAmU2nhZ8/3Ug4h61SS8uUx6GoNNpwpl9arydhESp+UBRo8rqQ6Y/qIdoxnnjLppgWGqaHYQ== X-Received: by 2002:a17:906:3a1a:: with SMTP id z26mr3758164eje.519.1603976062135; Thu, 29 Oct 2020 05:54:22 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:21 -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 , roy.fan.zhang@intel.com Date: Thu, 29 Oct 2020 12:53:38 +0000 Message-Id: <20201029125339.30916-7-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 7/8] examples/vhost_crypto: 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: f5188211c7 ("examples/vhost_crypto: add sample application") Cc: roy.fan.zhang@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/vhost_crypto/main.c | 78 ++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index 11ad49159..c68b409b3 100644 --- a/examples/vhost_crypto/main.c +++ b/examples/vhost_crypto/main.c @@ -62,10 +62,16 @@ struct vhost_crypto_options { uint32_t guest_polling; } options; +enum { #define CONFIG_KEYWORD "config" + CONFIG_KEYWORD_NUM = 256, #define SOCKET_FILE_KEYWORD "socket-file" + SOCKET_FILE_KEYWORD_NUM, #define ZERO_COPY_KEYWORD "zero-copy" + ZERO_COPY_KEYWORD_NUM, #define POLLING_KEYWORD "guest-polling" + POLLING_KEYWORD_NUM, +}; #define NB_SOCKET_FIELDS (2) @@ -210,10 +216,14 @@ vhost_crypto_parse_args(int argc, char **argv) char **argvopt; int option_index; struct option lgopts[] = { - {SOCKET_FILE_KEYWORD, required_argument, 0, 0}, - {CONFIG_KEYWORD, required_argument, 0, 0}, - {ZERO_COPY_KEYWORD, no_argument, 0, 0}, - {POLLING_KEYWORD, no_argument, 0, 0}, + {SOCKET_FILE_KEYWORD, required_argument, + NULL, SOCKET_FILE_KEYWORD_NUM}, + {CONFIG_KEYWORD, required_argument, + NULL, CONFIG_KEYWORD_NUM}, + {ZERO_COPY_KEYWORD, no_argument, + NULL, ZERO_COPY_KEYWORD_NUM}, + {POLLING_KEYWORD, no_argument, + NULL, POLLING_KEYWORD_NUM}, {NULL, 0, 0, 0} }; @@ -222,36 +232,46 @@ vhost_crypto_parse_args(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, "s:", lgopts, &option_index)) != EOF) { + if (opt == '?') { + vhost_crypto_usage(prgname); + return -1; + } + switch (opt) { - case 0: - if (strcmp(lgopts[option_index].name, - SOCKET_FILE_KEYWORD) == 0) { - ret = parse_socket_arg(optarg); - if (ret < 0) { - vhost_crypto_usage(prgname); - return ret; - } - } else if (strcmp(lgopts[option_index].name, - CONFIG_KEYWORD) == 0) { - ret = parse_config(optarg); - if (ret < 0) { - vhost_crypto_usage(prgname); - return ret; - } - } else if (strcmp(lgopts[option_index].name, - ZERO_COPY_KEYWORD) == 0) { - options.zero_copy = - RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE; - } else if (strcmp(lgopts[option_index].name, - POLLING_KEYWORD) == 0) { - options.guest_polling = 1; - } else { + case SOCKET_FILE_KEYWORD_NUM: + { + ret = parse_socket_arg(optarg); + if (ret < 0) { vhost_crypto_usage(prgname); - return -EINVAL; + return ret; } break; + } + case CONFIG_KEYWORD_NUM: + { + ret = parse_config(optarg); + if (ret < 0) { + vhost_crypto_usage(prgname); + return ret; + } + break; + } + case ZERO_COPY_KEYWORD_NUM: + { + options.zero_copy = + RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE; + break; + } + case POLLING_KEYWORD_NUM: + { + options.guest_polling = 1; + break; + } default: - return -1; + { + vhost_crypto_usage(prgname); + return -EINVAL; + } } } 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;