From patchwork Thu May 19 13:03:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forrest Shi X-Patchwork-Id: 68108 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3048664qge; Thu, 19 May 2016 00:36:47 -0700 (PDT) X-Received: by 10.140.109.10 with SMTP id k10mr12089943qgf.89.1463643407177; Thu, 19 May 2016 00:36:47 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k98si3118026qgk.120.2016.05.19.00.36.46; Thu, 19 May 2016 00:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C7E1B61775; Thu, 19 May 2016 07:36:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DATE_IN_FUTURE_03_06, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 32305617D7; Thu, 19 May 2016 07:35:14 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2DBAE616D6; Thu, 19 May 2016 07:35:06 +0000 (UTC) Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0097.outbound.protection.outlook.com [157.56.110.97]) by lists.linaro.org (Postfix) with ESMTPS id 0401061777 for ; Thu, 19 May 2016 07:33:27 +0000 (UTC) Received: from BLUPR0301CA0041.namprd03.prod.outlook.com (10.162.113.179) by BY2PR03MB473.namprd03.prod.outlook.com (10.141.141.143) with Microsoft SMTP Server (TLS) id 15.1.492.11; Thu, 19 May 2016 07:33:26 +0000 Received: from BL2FFO11FD052.protection.gbl (2a01:111:f400:7c09::157) by BLUPR0301CA0041.outlook.office365.com (2a01:111:e400:5259::51) with Microsoft SMTP Server (TLS) id 15.1.497.12 via Frontend Transport; Thu, 19 May 2016 07:33:25 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 192.88.168.50 as permitted sender) Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD052.mail.protection.outlook.com (10.173.161.214) with Microsoft SMTP Server (TLS) id 15.1.492.8 via Frontend Transport; Thu, 19 May 2016 07:33:25 +0000 Received: from netperf2.ap.freescale.net ([10.232.133.164]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u4J7XMKA015507; Thu, 19 May 2016 00:33:23 -0700 From: To: Date: Thu, 19 May 2016 18:33:09 +0530 Message-ID: <1463662989-1339-1-git-send-email-forrest.shi@linaro.org> X-Mailer: git-send-email 2.8.2 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131081168058600594; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(189002)(199003)(9170700003)(19580395003)(105596002)(86152002)(19580405001)(1220700001)(106466001)(87936001)(81166006)(33646002)(48376002)(8676002)(2906002)(189998001)(50226002)(110136002)(2351001)(8936002)(104016004)(586003)(6806005)(11100500001)(5003940100001)(4326007)(50986999)(229853001)(5008740100001)(36756003)(50466002)(77096005)(2876002)(86362001)(92566002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR03MB473; H:tx30smr01.am.freescale.net; FPR:; SPF:SoftFail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD052; 1:Hwd7uoPFuOu+yQ9vyoAM5tk8i0KEqF7RwjhZP7y02Ssa5/zaZK/YsAIk0QqIiThYuH9CuxnJMsUzbYndVFjoU+RFH3RAH1RbmAZ8rWWdy1+cnDbIOFHkZi85M54F9E7Nult4WHkrd9rf2EI8m1B1LM0b/PG2GI95dyGJRezGyqjLKtw93mct8ZWo8T3vF3MIIWcOsEzv2YMmuaw5o9We7VN3AGpDiIGjdUSSnc0KqXboi6jhv8aChC1w4zQJ4VuV55CG59rWAeNgjJQUmJGPcwlqwWrDWNe10ol3FcA8EZk8aKaIl6oHtYDQwjhyGNUKiC+T0nLFPpj3nPRvAVV3A4CYioEtUhDiS/VLmzaM7h6F+iLin8Ckg4c1ZCzqNTrbEJdhFZtXuluItvmLYb5DZhX2iNqEZ6/6f+5kXTsTKgEdWEN/EPVl/St/tos7Ibth+6X5z3pvdfINt6jpy2gOlMK+N/YFYymhSwwtG4wg9Zx7Ybv/Z7Dz3Hsuz1xP+YFr8eyOEfm8W8hVY9AYjL36UMTOMrQLLdGV3cPM25H+E/8bY215YcWYBkkqydbCovc0/S3IsWxb2gr4cUF28rka9X/oDzXvwiEaEu0fWQ9/WHNJlF2m9cPZN/Mkqej0/egR MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 6e7baa8b-e64a-47e1-e029-08d37fb7dd41 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB473; 2:ghwI6VEJQApH3Uhjw4RbpoX+v1eWiJHeP6WfrGUlWXgY2xYehlDYLRUpN7UZ5SD+/Zt+OVUpmn+XcAKmvC2v7cwwfZ9OY3pPMewjGe4CmKu8UrEmo0venFI09h5FcG0MJosxc4QshsVEkFmTA0HHLiKRGya+kOcrnNO3+oZUPgCS08u7x2uJGfXOdhLMHdfg; 3:eEXmXN/r+2K5gbn0CcRUMrmZFeT5gtYeuFb/q2fgjrwn45cYfAMpH1KZclgwxckqdHr2kc9X1nFQ6L8iuk2jUt6epsZS1KuDwyg84LadhdEDnNUpAeDztmjtc7sGf+pz9tc0sPDo15qlbrNKnCHqdg+soTJG9IZvh+h2dGyDdB8qOo8YUcIX+tHyOMnqrt3Utscu9aK6OC6zgNNxyucPJdoWz8A1Sbhg5aRbt0k/vS0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB473; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB473; 25:Kbh91BfOucdn1D36tksnnvucGEr5NeLKCNjly2gRPZynjg4BC7FyIjegqwwCf1sLZ45SdmP6RKWN0rdf2YILDnY30yfNkSejQWplgLMrkiyReYq9df7Bzbgg2nWrgo0jDSeVavcPl1jYoqnOgEZXoYdbShoiyq7Bp6cr1fOsWnQkPkZX+T4V83d2L2kvpj/kcdXd452xienkjSoBhDVCDWa8LFP9le3S5An1Jfi+17qd519kB/KzmoSswunF/QVTZ7p0+YnYo59li05K+9Ws+mosVVHhB9nJDUfiyfh++r86dcpk3XMcJRtJCMIIX7BLgAxtLL/sc1kW7AubH/7+5F65Y3qU/OmX7BIu7NtmcivY10qHb8a9eewHjgJiWYumsrTEIQYnsA+0xnk2VVMwpNcOjHxG9DIYxj0oEYcNtGyJAaTPo3gehaeaHqPVnQADFOFzJg/yp38kT/bEad0T93xYtZmA9FYybE92hxK7nGgUq6vs5Pw3JsPvE7KQRpho1vEDcYg3oorw9erWkDHYBfyTXTsIpPM/Vx8sg0Jkl1vo5tdWRZZV+96kyvUxne/i0feqz+WijbJRPUcoKEeEM8oxBx2Ek7u/X/gzmZKHEUfPopME5ci1OaT2n2YZSkN9HfkfKWsm+UPseeJGtG4/mQKbKv5vwTpK8kFW1Pnq1TTDXBqQyd27zDmkBwVviGdLk2yXWeZYRxiE3UDEroo2cw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13024025)(13023025)(13018025)(13017025)(13015025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BY2PR03MB473; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR03MB473; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB473; 4:2zmFCnIh1XecifOE0SSZeSwtGZ9Ra3yZNJX+LPNgJHyv/gMwQGuMQ8Tt3C11zkdWkJ6btVFHFe1SIVP0qEm6JwovwfZTYCnM1pjiTePpYpoMNnHJcAByWfq1iYY9U8IJ/inKzKk5djU2I0Ii5bYtgUDzqSEKyAlfHn6QtpZIU61dlr3n1C83pH11RiIQ2I20HiZ+TPOB0cHfDJy6G5X8duvWAfLkY4RNs2aMJefKt3i9Qwk+vjUmFn6yamYTvUYWva3ZXQUn4uduJHgsxqefLRy6gU9qTa446q7XHQXgk23hm/EspM0VDPgabgJsKbzxhmqvAKXbfTjQhNLhPHUY+qiLnGWsbTB3qFjKJ6iWqHZd/ta1RYClP/v0dS3+ZgVgapG/f0/M+UnsVlwtz9O9GtO1GNoftJlag/9lZbT4eUp3WH3mTggGYuIPiIzwqKoxmDLFgoU5+3PzPvXAUw9w2xQAqE8XmOMzdV2jsBCDkuI= X-Forefront-PRVS: 094700CA91 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB473; 23:QX6UDsHHy03bmUEnlUEA5AW8rnaLETsG15Vitdsqbb?= =?us-ascii?Q?JuRTFWQjSFxEfOjdz8nfN7kjPoRDOUB8JJTKFP9iEM/C4gw70qw5Lr0XdRJQ?= =?us-ascii?Q?rptAqcpd9tJ/x8xfPV+K1URvxTd34DXiNBgEu8fqQNFJ+BIP22vqbJDz52xX?= =?us-ascii?Q?nlGO4pZypzJreMICafAoL4ObfeHPm22UJ4HrWm6c6YkPUKTivVgTIkqAUHpB?= =?us-ascii?Q?VhJGAVt2zHdMNE3nK+vcOE54mO+qbhZGxu3gibCwjMS1uZAMQ/Xxphk6CPeS?= =?us-ascii?Q?Lbjbak2tJuc3RzMQXt8a4ICXS6jHdF/P1Voanl8iHm6X0IXv22DhqBWOLwvs?= =?us-ascii?Q?lbKiKl3r/8JzdIRrUT+2J9ltXv3tEqZiMJ8JSN74pq432rd+2dlbBedu4Szt?= =?us-ascii?Q?KSbD+metRBHh9a5VqPd/wDXgopSSq2UNBOZ6gdztekopMxB71Ts5TuEmo0qa?= =?us-ascii?Q?y5pybDG3umt3YNA2/7/9K6Ekq36fW1qj2rBDagx69QfslFmTJHaUyUcSwvCM?= =?us-ascii?Q?fxJxZwROYQlMa46TGmzlOmVAOKP+GIcMsjTOwChI115F/NBLwf6Wx7Yd38Yi?= =?us-ascii?Q?ynXYqTxgdo9epXKOYxVaanNwVDAqygaAP6P8w6rt7KoKkFCSaiHZyMB+9MYW?= =?us-ascii?Q?SpXg0/Nxcrtdp3+ovXo0q5US6Iw8a3uXQzxidoXJK/rUP8pIAyswE1heB0QY?= =?us-ascii?Q?TWLGb7VJmwBqbJE94c4oqqBW3sPh4qUPbG+55MAx02yt7ezxzTa3oWinS5sP?= =?us-ascii?Q?t1IweYCqBGXaFZzKiZF6H+2YW/iKAvEmwdubRo09WgdChzZcMBktpdBN3vtn?= =?us-ascii?Q?zOWY4YTyi1hkG9H/zYOID63Ui00GecC82dLZ3OYj1FA/uZkTUjrvlCkRUXbS?= =?us-ascii?Q?tv4mnW/VS8cqDaSlkCT52aqKpE9P08OQoQp/4IwxWc4vQGDauce+NymUtJ+x?= =?us-ascii?Q?EKxgecXpmRCyTsiZCKnK4beIgRdLMLdMDreft6YG3a6WY4rVrOPMQYNIdVbn?= =?us-ascii?Q?8=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB473; 5:fhk/gvC2r9EMoiYCb9c69Qh+Y/H9AxuuOiHgnJS+2eZO3hfZXRWxKmVXROyMXhxl5cqqwI+utMmfwzNeYjX6CJDH+x9g1jGz4ir+OYX8ELzuPfdgPTj04GDWvNNnGiBerMTZbqYeghlWBgX7+vcPJhlcxfEw8W56nMEXB0iF2UU=; 24:Qre86lMroVpfaAsr6I8MkePoRzH9qLNRBXd/8qKRAjvQaruAZR/d00lfHeUT5OUvMlqRMhN1XftigRtf/vZbUcwAnYlVDtl5BzDlej34Tc8=; 7:qE8WU5yZLfR0FX2VefE7GieRuYfGH1TrSpu4y3YXZl/bMhgS0TP/+62KJ9c1IhVE5qfbHnJT6BMITOn30mc9g1kbCWVOAvVCAgvqsl+9Ot5IewNfqtSoy11vEbG+d4jWnc0PILLUNnQHBmGx0/ry6BZIW1FuIWuNiVGQwAFPTal/cLH4FxLNwXXiPvFfbdeW SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2016 07:33:25.5480 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB473 X-Topics: patch Subject: [lng-odp] [PATCH 4/5] example:l3fwd: add command line arguments parsing X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Xuelin Shi get config from cmdline arguments instead of hard-coded string. Signed-off-by: Xuelin Shi --- example/l3fwd/odp_l3fwd.c | 216 +++++++++++++++++++++++++++++++++++++------ example/l3fwd/odp_l3fwd_db.c | 9 -- 2 files changed, 190 insertions(+), 35 deletions(-) diff --git a/example/l3fwd/odp_l3fwd.c b/example/l3fwd/odp_l3fwd.c index 29da045..5598a5a 100644 --- a/example/l3fwd/odp_l3fwd.c +++ b/example/l3fwd/odp_l3fwd.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -14,19 +15,27 @@ #include #include +#include + #include "odp_l3fwd_db.h" #define POOL_NUM_PKT 8192 #define POOL_SEG_LEN 1856 #define MAX_PKT_BURST 32 -static const char * const route_str[] = { - "1.1.1.0/24:fm1-mac1:00.e0.0c.00.85.00", - "2.1.1.0/24:fm1-mac2:00.e0.0c.00.85.01", -}; - #define MAX_NB_WORKER 8 #define MAX_NB_PKTIO 4 +#define MAX_NB_ROUTE 32 + +/** Get rid of path in filename - only for unix-type paths using '/' */ +#define NO_PATH(file_name) (strrchr((file_name), '/') ? \ + strrchr((file_name), '/') + 1 : (file_name)) + +typedef struct { + char *if_names[MAX_NB_PKTIO]; + uint32_t if_count; + char *route_str[MAX_NB_ROUTE]; +} app_args_t; struct l3fwd_pktio_s { odp_pktio_t pktio; @@ -39,6 +48,7 @@ struct thread_arg_s { }; struct { + app_args_t cmd_args; struct l3fwd_pktio_s l3fwd_pktios[MAX_NB_PKTIO]; odph_linux_pthread_t l3fwd_workers[MAX_NB_WORKER]; struct thread_arg_s worker_args[MAX_NB_WORKER]; @@ -46,6 +56,10 @@ struct { uint32_t nb_worker; /* effective workers */ } global; +static void print_usage(char *progname); +static void print_info(char *progname, app_args_t *args); +static void parse_cmdline_args(int argc, char *argv[], app_args_t *args); + static odp_pktio_t create_pktio(const char *name, odp_pool_t pool, odp_pktin_queue_t *pktin, odp_pktout_queue_t *pktout) @@ -97,16 +111,17 @@ static void *run_worker(void *arg) odp_packet_t pkt_tbl_drop[MAX_PKT_BURST]; uint32_t pkts, i; struct l3fwd_pktio_s *port; + char *if_name; i = ((struct thread_arg_s *)arg)->if_idx; port = &global.l3fwd_pktios[i]; - + if_name = global.cmd_args.if_names[i]; if (odp_pktio_start(port->pktio)) { - printf("unable to start interface: %d\n", i); + printf("unable to start pktio: %s\n", if_name); exit(1); } - printf("start interface: %d\n", i); + printf("start pktio: %s\n", if_name); for (;;) { int need_to_drop = 0; @@ -180,13 +195,7 @@ int main(int argc, char **argv) odph_linux_thr_params_t thr_params; uint32_t cpu, i; uint8_t mac[ODPH_ETHADDR_LEN]; - - if (argc != 3) { - printf("Usage: odp_l3fwd eth0 eth1\n"); - printf("Where eth0 and eth1 are the used interfaces" - " (must have 2 of them)\n"); - exit(1); - } + app_args_t *args; if (odp_init_global(&instance, NULL, NULL)) { printf("Error: ODP global init failed.\n"); @@ -201,17 +210,21 @@ int main(int argc, char **argv) /* Clear global argument */ memset(&global, 0, sizeof(global)); + /* Parse cmdline arguments */ + args = &global.cmd_args; + parse_cmdline_args(argc, argv, args); + /* Init l3fwd tale */ init_fwd_db(); /* Add route into table */ - for (i = 0; i < sizeof(route_str) / sizeof(char *); i++) { - char buf[128]; - - snprintf(buf, 128, "%s", route_str[i]); - create_fwd_db_entry(buf); + for (i = 0; i < MAX_NB_ROUTE; i++) { + if (args->route_str[i]) + create_fwd_db_entry(args->route_str[i]); } + print_info(NO_PATH(argv[0]), args); + /* Create packet pool */ odp_pool_param_init(¶ms); params.pkt.seg_len = POOL_SEG_LEN; @@ -226,20 +239,25 @@ int main(int argc, char **argv) exit(1); } - /* TODO: parse cmdline to get pktio number, name */ - global.nb_pktio = 2; + global.nb_pktio = args->if_count; for (i = 0; i < global.nb_pktio; i++) { struct l3fwd_pktio_s *port; - char *ifname = argv[i + 1]; + char buf[16]; port = &global.l3fwd_pktios[i]; - port->pktio = create_pktio(ifname, pool, &port->ifin, + port->pktio = create_pktio(args->if_names[i], pool, &port->ifin, &port->ifout); odp_pktio_mac_addr(port->pktio, mac, ODPH_ETHADDR_LEN); - resolve_fwd_db(ifname, port->pktio, mac); + resolve_fwd_db(args->if_names[i], port->pktio, mac); + + /* print mac string, could be used to config pktgen */ + sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + printf("create pktio %s, mac %s\n", args->if_names[i], buf); } - global.nb_worker = 2; + /* one thread for each port */ + global.nb_worker = args->if_count; memset(&thr_params, 0, sizeof(thr_params)); thr_params.start = run_worker; thr_params.thr_type = ODP_THREAD_WORKER; @@ -264,3 +282,149 @@ int main(int argc, char **argv) return 0; } + +static void print_usage(char *progname) +{ + printf("\n" + "ODP L3 forwarding application.\n" + "\n" + "Usage: %s OPTIONS\n" + " E.g. %s -i eth0,eth1\n" + " In the above example,\n" + " eth0 will send pkts to eth1 and vice versa\n" + "\n" + "Mandatory OPTIONS:\n" + " -i, --interface eth interfaces (comma-separated, no spaces)\n" + " -r, --route SubNet:Intf[:NextHopMAC]\n" + " NextHopMAC can be optional, in this case, zeroed mac\n" + "\n" + "Optional OPTIONS\n" + " -h, --help Display help and exit.\n\n" + "\n", NO_PATH(progname), NO_PATH(progname) + ); +} + +static void parse_cmdline_args(int argc, char *argv[], app_args_t *args) +{ + int opt; + int long_index; + char *token, *local; + size_t len, route_index = 0; + int i, mem_failure = 0; + + static struct option longopts[] = { + {"interface", required_argument, NULL, 'i'}, /* return 'i' */ + {"route", required_argument, NULL, 'r'}, /* return 'r' */ + {"help", no_argument, NULL, 'h'}, /* return 'h' */ + {NULL, 0, NULL, 0} + }; + + while (1) { + opt = getopt_long(argc, argv, "+i:r:h", + longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + /* parse packet-io interface names */ + case 'i': + len = strlen(optarg); + if (len == 0) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + len += 1; /* add room for '\0' */ + + local = malloc(len); + if (!local) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + + /* count the number of tokens separated by ',' */ + strcpy(local, optarg); + for (token = strtok(local, ","), i = 0; + token != NULL; + token = strtok(NULL, ","), i++) + ; + + if (i == 0) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + + args->if_count = i; + + /* store the if names (reset names string) */ + strcpy(local, optarg); + for (token = strtok(local, ","), i = 0; + token != NULL; token = strtok(NULL, ","), i++) { + args->if_names[i] = token; + } + break; + + /*Configure Route in forwarding database*/ + case 'r': + if (route_index >= MAX_NB_ROUTE) { + printf("No more routes can be added\n"); + break; + } + local = calloc(1, strlen(optarg) + 1); + if (!local) { + mem_failure = 1; + break; + } + memcpy(local, optarg, strlen(optarg)); + local[strlen(optarg)] = '\0'; + args->route_str[route_index++] = local; + break; + + case 'h': + print_usage(argv[0]); + exit(EXIT_SUCCESS); + break; + + default: + break; + } + } + + if (args->if_count == 0 || mem_failure == 1) { + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + + optind = 1; /* reset 'extern optind' from the getopt lib */ +} + +static void print_info(char *progname, app_args_t *args) +{ + uint32_t i; + + printf("\n" + "ODP system info\n" + "---------------\n" + "ODP API version: %s\n" + "ODP impl name: %s\n" + "CPU model: %s\n" + "CPU freq (hz): %" PRIu64 "\n" + "Cache line size: %i\n" + "CPU count: %i\n" + "\n", + odp_version_api_str(), odp_version_impl_name(), + odp_cpu_model_str(), odp_cpu_hz_max(), + odp_sys_cache_line_size(), odp_cpu_count()); + + printf("Running ODP appl: \"%s\"\n" + "-----------------\n" + "IF-count: %i\n" + "Using IFs: ", + progname, args->if_count); + + for (i = 0; i < args->if_count; ++i) + printf(" %s", args->if_names[i]); + + printf("\n\n"); + fflush(NULL); +} diff --git a/example/l3fwd/odp_l3fwd_db.c b/example/l3fwd/odp_l3fwd_db.c index 7fde4ae..c1e1b5b 100644 --- a/example/l3fwd/odp_l3fwd_db.c +++ b/example/l3fwd/odp_l3fwd_db.c @@ -342,15 +342,6 @@ int create_fwd_db_entry(char *input) pos++; } - /* Verify we parsed exactly the number of tokens we expected */ - if (3 != pos) { - printf("ERROR: \"%s\" contains %d tokens, expected 3\n", - input, - pos); - free(local); - return -1; - } - /* Reset pktio to invalid */ entry->pktio = ODP_PKTIO_INVALID;