From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23F4C431DE; Mon, 23 Oct 2023 09:03:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F326C4027E; Mon, 23 Oct 2023 09:03:31 +0200 (CEST) Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by mails.dpdk.org (Postfix) with ESMTP id 9680040270 for ; Mon, 23 Oct 2023 09:03:30 +0200 (CEST) Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-7b6f67c708eso1165886241.1 for ; Mon, 23 Oct 2023 00:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698044610; x=1698649410; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oALjavbdyeqBOjDUsHE9uWJP8nEBrULUBHSPnSSKI/A=; b=b2olm7c3KqooiBM8lldsNVvUzEVJJDi7LpsAzsWvtKJ3gNjAIwIL3eYRU5z6n/r5vc ubipYz0hjkOHWPox9fDgD1zgF3PcOmQQyVQIGIbRXOQiwgLiAWVV16N5udPeCWFDTSce cpjwo+/3VoeebRHIy1bVV8PG7wjRqYErcou7RwCB9bBRElqt7ETVb/C2pb4MNkYozMUa 9PPWRj63XvWcR0rw5IGYB9LyXzs/DL4Ew+V4hLr8GlPWHnhHzl0/XdGpsk/46AuXwWAo Q6nyoRvtMtoagiB+TQLBl1knXoy2ouc1uB0IzrU910EIP3sAcsYGUC94L3LXlZrfvlm3 HxQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698044610; x=1698649410; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oALjavbdyeqBOjDUsHE9uWJP8nEBrULUBHSPnSSKI/A=; b=uullmJBlW3xjUP+LQQbunhVj38p6jZJ0j+o5Dnfv2wZg1rY1MdihzWiYI9RW7JHIFa m8Ez+EzufivnzeNCKS9igyvWQCkYcLgTH3G4L21PgUP4HwgcwOnJbeeIFoHZFYSQxKVC h+brJ2aT10YbnV2H7caTvr1PZdi47MI+zFmsnlIQIkgQ1iRXC/jh19qdhx0T8XPx0OG6 MH6nk3qwXtitd5n6QpamnnKH9Mz9yLxxO+i8elgp/2UueehlITvKVx5EXxYh/QkiymN9 vfqUOhZN2qFUOKJjirabjOk2rPOf4OKGMHAwnUyAvL6TUdvUa9wp4WKLH3shAgFrrt0Z ZB8g== X-Gm-Message-State: AOJu0YzcanFHCwkbhiHDtfK+fX9CuQgqxkDnbErFOkKPU7z8GB0pYOIx 6gyIzq/IeFZu7aew23xY/GdPgcWyJso9MS7VpsI= X-Google-Smtp-Source: AGHT+IEwCEmE7+oEtKkJO5l1e/riZXdRySJcLzezue8++EPNff8uyfteUYrbFv+EcUVZvLYULUozpRvzWfUsgSUSGRI= X-Received: by 2002:a05:6102:4703:b0:458:8eb4:7d5b with SMTP id ei3-20020a056102470300b004588eb47d5bmr7083272vsb.15.1698044609676; Mon, 23 Oct 2023 00:03:29 -0700 (PDT) MIME-Version: 1.0 References: <20231019105000.520914-13-skori@marvell.com> <20231019173011.1186656-1-skori@marvell.com> <20231019173011.1186656-2-skori@marvell.com> In-Reply-To: <20231019173011.1186656-2-skori@marvell.com> From: Nithin Dabilpuram Date: Mon, 23 Oct 2023 12:33:17 +0530 Message-ID: Subject: Re: [PATCH v11 01/12] app/graph: support application CLI framework To: skori@marvell.com Cc: Thomas Monjalon , Rakesh Kudurumalla , dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Acked-By: Nithin Dabilpuram On Fri, Oct 20, 2023 at 9:37=E2=80=AFAM wrote: > > From: Sunil Kumar Kori > > Adds base framework to read a given .cli file as a command line > parameter "-s". > > Example: > # ./dpdk-graph -c 0xff -- -s ./app/graph/examples/dummy.cli > > Each .cli file will contain commands to configure different module like > mempool, ethdev, lookup tables, graph etc. Command parsing is backed by > commandline library. > > Each module needs to expose its supported commands & corresponding > callback functions to commandline library to get them parsed. > > Signed-off-by: Sunil Kumar Kori > Signed-off-by: Rakesh Kudurumalla > --- > v10..v11 > - Add information to kill telnet session in user guide. > - Merge l3fwd related information in a single section in user guide. > - Fix spellings. > > v9..v10 > - Add l3fwd_pcap.cli for pcap devices. > - Update table generation mechanism user guide document > > v8..v9: > - Replace strcpy() to rte_strscpy() > - Update release note. > - Update user guide > > v7..v8: > - Fix klocwork issues. > > v6..v7: > - Fix FreeBSD build error. > - Make route and neigh runtime configuration too. > > v5..v6: > - Fix build errors. > - Fix checkpatch errors. > - Fix individual patch build errors. > > v4..v5: > - Fix application exit issue. > - Enable graph packet capture feature. > - Fix graph coremask synchronization with eal coremask. > - Update user guide. > > https://patches.dpdk.org/project/dpdk/patch/20230919160455.1678716-1-skor= i@marvell.com/ > > v3..v4: > - Use commandline library to parse command tokens. > - Split to multiple smaller patches. > - Make neigh and route as dynamic database. > - add ethdev and graph stats command via telnet. > - Update user guide. > > https://patches.dpdk.org/project/dpdk/patch/20230908104907.4060511-1-skor= i@marvell.com/ > > MAINTAINERS | 7 ++ > app/graph/cli.c | 115 ++++++++++++++++++++++ > app/graph/cli.h | 32 +++++++ > app/graph/main.c | 128 +++++++++++++++++++++++++ > app/graph/meson.build | 15 +++ > app/graph/module_api.h | 16 ++++ > app/meson.build | 1 + > doc/guides/rel_notes/release_23_11.rst | 7 ++ > doc/guides/tools/graph.rst | 75 +++++++++++++++ > doc/guides/tools/index.rst | 1 + > 10 files changed, 397 insertions(+) > create mode 100644 app/graph/cli.c > create mode 100644 app/graph/cli.h > create mode 100644 app/graph/main.c > create mode 100644 app/graph/meson.build > create mode 100644 app/graph/module_api.h > create mode 100644 doc/guides/tools/graph.rst > > diff --git a/MAINTAINERS b/MAINTAINERS > index 4083658697..88a71d5455 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -1818,6 +1818,13 @@ F: dts/ > F: devtools/dts-check-format.sh > F: doc/guides/tools/dts.rst > > +Graph application > +M: Sunil Kumar Kori > +M: Rakesh Kudurumalla > +F: app/graph/ > +F: doc/guides/tools/graph.rst > +F: doc/guides/tools/img/graph-usecase-l3fwd.svg > + > > Other Example Applications > -------------------------- > diff --git a/app/graph/cli.c b/app/graph/cli.c > new file mode 100644 > index 0000000000..df4f8fcbb8 > --- /dev/null > +++ b/app/graph/cli.c > @@ -0,0 +1,115 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#include "module_api.h" > + > +#define CMD_MAX_TOKENS 256 > +#define MAX_LINE_SIZE 2048 > + > +cmdline_parse_ctx_t modules_ctx[] =3D { > + NULL, > +}; > + > +static struct cmdline *cl; > + > +static int > +is_comment(char *in) > +{ > + if ((strlen(in) && index("!#%;", in[0])) || > + (strncmp(in, "//", 2) =3D=3D 0) || > + (strncmp(in, "--", 2) =3D=3D 0)) > + return 1; > + > + return 0; > +} > + > +void > +cli_init(void) > +{ > + cl =3D cmdline_stdin_new(modules_ctx, ""); > +} > + > +void > +cli_exit(void) > +{ > + cmdline_stdin_exit(cl); > +} > + > +void > +cli_process(char *in, char *out, size_t out_size, __rte_unused void *obj= ) > +{ > + int rc; > + > + if (is_comment(in)) > + return; > + > + rc =3D cmdline_parse(cl, in); > + if (rc =3D=3D CMDLINE_PARSE_AMBIGUOUS) > + snprintf(out, out_size, MSG_CMD_FAIL, "Ambiguous command"= ); > + else if (rc =3D=3D CMDLINE_PARSE_NOMATCH) > + snprintf(out, out_size, MSG_CMD_FAIL, "Command mismatch")= ; > + else if (rc =3D=3D CMDLINE_PARSE_BAD_ARGS) > + snprintf(out, out_size, MSG_CMD_FAIL, "Bad arguments"); > + > + return; > + > +} > + > +int > +cli_script_process(const char *file_name, size_t msg_in_len_max, size_t = msg_out_len_max, void *obj) > +{ > + char *msg_in =3D NULL, *msg_out =3D NULL; > + int rc =3D -EINVAL; > + FILE *f =3D NULL; > + > + /* Check input arguments */ > + if ((file_name =3D=3D NULL) || (strlen(file_name) =3D=3D 0) || (m= sg_in_len_max =3D=3D 0) || > + (msg_out_len_max =3D=3D 0)) > + return rc; > + > + msg_in =3D malloc(msg_in_len_max + 1); > + msg_out =3D malloc(msg_out_len_max + 1); > + if ((msg_in =3D=3D NULL) || (msg_out =3D=3D NULL)) { > + rc =3D -ENOMEM; > + goto exit; > + } > + > + /* Open input file */ > + f =3D fopen(file_name, "r"); > + if (f =3D=3D NULL) { > + rc =3D -EIO; > + goto exit; > + } > + > + /* Read file */ > + while (fgets(msg_in, msg_in_len_max, f) !=3D NULL) { > + msg_out[0] =3D 0; > + > + cli_process(msg_in, msg_out, msg_out_len_max, obj); > + > + if (strlen(msg_out)) > + printf("%s", msg_out); > + } > + > + /* Close file */ > + fclose(f); > + rc =3D 0; > + > +exit: > + free(msg_out); > + free(msg_in); > + return rc; > +} > diff --git a/app/graph/cli.h b/app/graph/cli.h > new file mode 100644 > index 0000000000..652f948352 > --- /dev/null > +++ b/app/graph/cli.h > @@ -0,0 +1,32 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#ifndef APP_GRAPH_CLI_H > +#define APP_GRAPH_CLI_H > + > +/* Macros */ > +#define MSG_OUT_OF_MEMORY "Not enough memory.\n" > +#define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n" > +#define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n" > +#define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n" > +#define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n" > +#define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\= ".\n" > +#define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n" > +#define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n" > +#define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n" > +#define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n" > +#define MSG_CMD_FAIL "Command \"%s\" failed.\n" > + > +#define APP_CLI_CMD_NAME_SIZE 64 > + > +void cli_init(void); > + > +void cli_exit(void); > + > +void cli_process(char *in, char *out, size_t out_size, void *arg); > + > +int cli_script_process(const char *file_name, size_t msg_in_len_max, siz= e_t msg_out_len_max, > + void *arg); > + > +#endif > diff --git a/app/graph/main.c b/app/graph/main.c > new file mode 100644 > index 0000000000..734a94444e > --- /dev/null > +++ b/app/graph/main.c > @@ -0,0 +1,128 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include "module_api.h" > + > +volatile bool force_quit; > + > +static const char usage[] =3D "%s EAL_ARGS -- -s SCRIPT " > + "[--help]\n"; > + > +static struct app_params { > + char *script_name; > +} app =3D { > + .script_name =3D NULL, > +}; > + > +static void > +signal_handler(int signum) > +{ > + if (signum =3D=3D SIGINT || signum =3D=3D SIGTERM) { > + printf("\n\nSignal %d received, preparing to exit...\n", = signum); > + force_quit =3D true; > + } > +} > + > +static int > +app_args_parse(int argc, char **argv) > +{ > + struct option lgopts[] =3D { > + {"help", 0, 0, 'H'}, > + }; > + int s_present, n_args, i; > + char *app_name =3D argv[0]; > + int opt, option_index; > + > + /* Skip EAL input args */ > + n_args =3D argc; > + for (i =3D 0; i < n_args; i++) > + if (strcmp(argv[i], "--") =3D=3D 0) { > + argc -=3D i; > + argv +=3D i; > + break; > + } > + > + if (i =3D=3D n_args) > + return 0; > + > + /* Parse args */ > + s_present =3D 0; > + > + while ((opt =3D getopt_long(argc, argv, "s:", lgopts, &option_ind= ex)) !=3D EOF) { > + switch (opt) { > + case 's': > + if (s_present) { > + printf("Error: Multiple -s arguments\n"); > + return -1; > + } > + s_present =3D 1; > + > + if (!strlen(optarg)) { > + printf("Error: Argument for -s not provid= ed\n"); > + return -1; > + } > + > + app.script_name =3D strdup(optarg); > + if (app.script_name =3D=3D NULL) { > + printf("Error: Not enough memory\n"); > + return -1; > + } > + break; > + > + case 'H': > + default: > + printf(usage, app_name); > + return -1; > + } > + } > + optind =3D 1; /* reset getopt lib */ > + > + return 0; > +} > + > +int > +main(int argc, char **argv) > +{ > + int rc; > + > + /* Parse application arguments */ > + rc =3D app_args_parse(argc, argv); > + if (rc < 0) > + return rc; > + > + /* EAL */ > + rc =3D rte_eal_init(argc, argv); > + if (rc < 0) { > + printf("Error: EAL initialization failed (%d)\n", rc); > + return rc; > + }; > + > + force_quit =3D false; > + signal(SIGINT, signal_handler); > + signal(SIGTERM, signal_handler); > + > + cli_init(); > + > + /* Script */ > + if (app.script_name) { > + cli_script_process(app.script_name, 0, > + 0, NULL); > + } > + > + cli_exit(); > + rte_eal_cleanup(); > + return 0; > +} > diff --git a/app/graph/meson.build b/app/graph/meson.build > new file mode 100644 > index 0000000000..ed33a04476 > --- /dev/null > +++ b/app/graph/meson.build > @@ -0,0 +1,15 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(c) 2023 Marvell. > + > +# override default name to drop the hyphen > +name =3D 'graph' > +build =3D cc.has_header('sys/epoll.h') > +if not build > + subdir_done() > +endif > + > +deps +=3D ['graph', 'eal', 'lpm', 'ethdev', 'node', 'cmdline'] > +sources =3D files( > + 'cli.c', > + 'main.c', > +) > diff --git a/app/graph/module_api.h b/app/graph/module_api.h > new file mode 100644 > index 0000000000..372aeae7e3 > --- /dev/null > +++ b/app/graph/module_api.h > @@ -0,0 +1,16 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#ifndef APP_GRAPH_MODULE_API_H > +#define APP_GRAPH_MODULE_API_H > + > +#include > +#include > +#include "cli.h" > +/* > + * Externs > + */ > +extern volatile bool force_quit; > + > +#endif > diff --git a/app/meson.build b/app/meson.build > index e4bf5c531c..728c936383 100644 > --- a/app/meson.build > +++ b/app/meson.build > @@ -17,6 +17,7 @@ endif > apps =3D [ > 'dumpcap', > 'pdump', > + 'graph', > 'proc-info', > 'test-acl', > 'test-bbdev', > diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_note= s/release_23_11.rst > index 0a6fc76a9d..f43b416565 100644 > --- a/doc/guides/rel_notes/release_23_11.rst > +++ b/doc/guides/rel_notes/release_23_11.rst > @@ -243,6 +243,13 @@ New Features > Added dispatcher library which purpose is to help decouple different > parts (modules) of an eventdev-based application. > > +* **Added CLI based graph application.** > + > + Added CLI based graph application which exercises on different usecase= s. > + Application provides a framework so that each usecase can be added via= CLI > + file. Each CLI will further be translated into a graph representing us= er's > + required usecase. > + > > Removed Items > ------------- > diff --git a/doc/guides/tools/graph.rst b/doc/guides/tools/graph.rst > new file mode 100644 > index 0000000000..cb005e7856 > --- /dev/null > +++ b/doc/guides/tools/graph.rst > @@ -0,0 +1,75 @@ > +.. SPDX-License-Identifier: BSD-3-Clause > + Copyright(c) 2023 Marvell. > + > +dpdk-graph Application > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +The ``dpdk-graph`` tool is a Data Plane Development Kit (DPDK) > +application that allows exercising various graph use cases. > +This application has a generic framework to add new graph based use case= s to > +verify functionality. Each use case is defined as a ``.cli`` fi= le. > +Based on the input file, application creates a graph to cater the use ca= se. > + > +Also this application framework can be used by other graph based applica= tions. > + > +Running the Application > +----------------------- > + > +The application has a number of command line options which can be provid= ed in > +following syntax > + > +.. code-block:: console > + > + dpdk-graph [EAL Options] -- [application options] > + > +EAL Options > +~~~~~~~~~~~ > + > +Following are the EAL command-line options that can be used in conjuncti= on > +with the ``dpdk-graph`` application. > +See the DPDK Getting Started Guides for more information on these option= s. > + > +* ``-c `` or ``-l `` > + > + Set the hexadecimal bit mask of the cores to run on. The CORELIS= T is a > + list of cores to be used. > + > +Application Options > +~~~~~~~~~~~~~~~~~~~ > + > +Following are the application command-line options: > + > +* ``-s`` > + > + Script name with absolute path which specifies the use case. It = is > + a mandatory parameter which will be used to create desired graph > + for a given use case. > + > +* ``--help`` > + > + Dumps application usage > + > +Supported CLI commands > +---------------------- > + > +This section provides details on commands which can be used in ``.cli`` > +file to express the requested use case configuration. > + > +.. table:: Exposed CLIs > + :widths: auto > + > + +--------------------------------------+-----------------------------= ------+---------+----------+ > + | Command | Description = | Dynamic | Optional | > + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ > + | | = | | | > + +--------------------------------------+-----------------------------= ------+---------+----------+ > + > +Runtime configuration > +--------------------- > + > + > +Created graph for use case > +-------------------------- > + > +On the successful execution of ``.cli`` file, corresponding gra= ph will be created. > +This section mentions the created graph for each use case. > diff --git a/doc/guides/tools/index.rst b/doc/guides/tools/index.rst > index f2afb1fcc5..4f4dc8b518 100644 > --- a/doc/guides/tools/index.rst > +++ b/doc/guides/tools/index.rst > @@ -23,4 +23,5 @@ DPDK Tools User Guides > testeventdev > testregex > testmldev > + graph > dts > -- > 2.25.1 >