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 DF6D5431DE; Mon, 23 Oct 2023 09:05:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5AA6A406B4; Mon, 23 Oct 2023 09:05:01 +0200 (CEST) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by mails.dpdk.org (Postfix) with ESMTP id 7562040608 for ; Mon, 23 Oct 2023 09:04:59 +0200 (CEST) Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-41cc7379b23so19283351cf.3 for ; Mon, 23 Oct 2023 00:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698044699; x=1698649499; 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=oAesdOUgZ1VxHDCPKw4clBjrmPh3BgpQpQ7llFu6Qvc=; b=W1ryqDv/yCVIeR1Q1FOqagRRk28fRJJMn/31oz/utf1iTgt75PQMgA3z91DC9M2M0I OEDSNdwdymTI/gNmRfKg4QgAwilDGwWIeHOxbvvNEXwTqhVnleCgmCZK47AymPWcx+Cw A9Qj2LIC25xdnAVIyvOL7PQ8LZbzBRIS1gVInZrbRUk6S6qec8yYjZLZ2WMH25Tw+lOy bfcMcwBJwgUt4/SYpR3qyYdRST1XWe4dXeG0iwkMSCHb/NkpIX7UxyR3g2W46KlvvHho 0UyNqc2wn+d661igwdyGfNtKuXOEl83AqCU134rAfqN/Q9Nb6ukiRJKtJ/DmU7Ijnm/E oxVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698044699; x=1698649499; 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=oAesdOUgZ1VxHDCPKw4clBjrmPh3BgpQpQ7llFu6Qvc=; b=EyusIM9kIHPc2udS6RBZmHOgeZMpI9DS4JmYNYUtuNsp0B7+mTpPjR7nZ9YaPqHXqU 0zHcbch139WZ40afOueCOK2/avNvMZFvZv+qvc+mcCGlonrq0WhXlFdONkg0YH0q1i/N Tmnu/wG57e0fkCt43oiIoMzxY6hsnw26T1NMDTh/Z3OPoUqzde8lbU8DsGV2XmSoZ1V/ QdlIQ1+FZGst1ZnTaVURvw3qGo/65GtDBmrNH527dFD6mjtJVPyDn5PnevZhiyDd2hoB olF0My5FZlDSGebwM4Y0Zoh30yQzLoVEuVzgnxMJVxlAN08Yoh3EFTjOfMfe4zBDvfie USsQ== X-Gm-Message-State: AOJu0YxalezsvgrHgWOJpHuioaH+2173BgbjJxFHWG1satX5R3aZX0pP EBZqg1r5CvvMphAsMpeACDOob1OiPbqld/3GIhXnzTh+ASs= X-Google-Smtp-Source: AGHT+IGPznErQhEv9yaIEyL3T8i6L0A6M0Pn2j0IUvRwQtOsf22oK6gWwUla4wkMR68EB72OivLTaiBKPmKzWRBuSB4= X-Received: by 2002:ac8:5c91:0:b0:418:1a99:3918 with SMTP id r17-20020ac85c91000000b004181a993918mr11101221qta.6.1698044698634; Mon, 23 Oct 2023 00:04:58 -0700 (PDT) MIME-Version: 1.0 References: <20231019105000.520914-13-skori@marvell.com> <20231019173011.1186656-1-skori@marvell.com> <20231019173011.1186656-7-skori@marvell.com> In-Reply-To: <20231019173011.1186656-7-skori@marvell.com> From: Nithin Dabilpuram Date: Mon, 23 Oct 2023 12:34:46 +0530 Message-ID: Subject: Re: [PATCH v11 06/12] app/graph: support IPv4 lookup command line interfaces To: skori@marvell.com Cc: 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 8:07=E2=80=AFPM wrote: > > From: Sunil Kumar Kori > > Adds ipv4_lookup module to configure LPM table. This LPM table > will be used for IPv4 lookup and forwarding. > > Following commands are exposed: > - ipv4_lookup route add ipv4 netmask via > - help ipv4_lookup > > Signed-off-by: Sunil Kumar Kori > Signed-off-by: Rakesh Kudurumalla > --- > app/graph/cli.c | 2 + > app/graph/ethdev.c | 2 +- > app/graph/ip4_route.c | 221 +++++++++++++++++++++++++++++++++++++ > app/graph/meson.build | 1 + > app/graph/module_api.h | 1 + > app/graph/route.h | 26 +++++ > app/graph/route_priv.h | 44 ++++++++ > doc/guides/tools/graph.rst | 9 ++ > 8 files changed, 305 insertions(+), 1 deletion(-) > create mode 100644 app/graph/ip4_route.c > create mode 100644 app/graph/route.h > create mode 100644 app/graph/route_priv.h > > diff --git a/app/graph/cli.c b/app/graph/cli.c > index fa394fade6..25785ea4dc 100644 > --- a/app/graph/cli.c > +++ b/app/graph/cli.c > @@ -30,6 +30,8 @@ cmdline_parse_ctx_t modules_ctx[] =3D { > (cmdline_parse_inst_t *)ðdev_ip6_cmd_ctx, > (cmdline_parse_inst_t *)ðdev_cmd_ctx, > (cmdline_parse_inst_t *)ðdev_help_cmd_ctx, > + (cmdline_parse_inst_t *)&ipv4_lookup_cmd_ctx, > + (cmdline_parse_inst_t *)&ipv4_lookup_help_cmd_ctx, > NULL, > }; > > diff --git a/app/graph/ethdev.c b/app/graph/ethdev.c > index 8df55b4b12..4e4d23b692 100644 > --- a/app/graph/ethdev.c > +++ b/app/graph/ethdev.c > @@ -164,7 +164,7 @@ ethdev_stop(void) > } > > ethdev_list_clean(); > - rte_eal_cleanup(); > + route_ip4_list_clean(); > printf("Bye...\n"); > } > > diff --git a/app/graph/ip4_route.c b/app/graph/ip4_route.c > new file mode 100644 > index 0000000000..db3354c270 > --- /dev/null > +++ b/app/graph/ip4_route.c > @@ -0,0 +1,221 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#include "module_api.h" > +#include "route_priv.h" > + > +static const char > +cmd_ipv4_lookup_help[] =3D "ipv4_lookup route add ipv4 netmask via "; > + > +struct ip4_route route4 =3D TAILQ_HEAD_INITIALIZER(route4); > + > + > +void > +route_ip4_list_clean(void) > +{ > + struct route_ipv4_config *route; > + > + while (!TAILQ_EMPTY(&route4)) { > + route =3D TAILQ_FIRST(&route4); > + TAILQ_REMOVE(&route4, route, next); > + } > +} > + > +static struct route_ipv4_config * > +find_route4_entry(struct route_ipv4_config *route) > +{ > + struct route_ipv4_config *ipv4route; > + > + TAILQ_FOREACH(ipv4route, &route4, next) { > + if (!memcmp(ipv4route, route, sizeof(*route))) > + return ipv4route; > + } > + return NULL; > + > +} > + > +static uint8_t > +convert_netmask_to_depth(uint32_t netmask) > +{ > + uint8_t zerobits =3D 0; > + > + while ((netmask & 0x1) =3D=3D 0) { > + netmask =3D netmask >> 1; > + zerobits++; > + } > + > + return (32 - zerobits); > +} > + > +static int > +route4_rewirte_table_update(struct route_ipv4_config *ipv4route) > +{ > + uint8_t depth; > + int portid; > + > + portid =3D ethdev_portid_by_ip4(ipv4route->via, ipv4route->netmas= k); > + if (portid < 0) { > + printf("Invalid portid found to install the route\n"); > + return portid; > + } > + > + depth =3D convert_netmask_to_depth(ipv4route->netmask); > + > + return rte_node_ip4_route_add(ipv4route->ip, depth, portid, > + RTE_NODE_IP4_LOOKUP_NEXT_REWRITE); > +} > + > +static int > +route_ip4_add(struct route_ipv4_config *route) > +{ > + struct route_ipv4_config *ipv4route; > + int rc =3D -EINVAL; > + > + ipv4route =3D find_route4_entry(route); > + > + if (!ipv4route) { > + ipv4route =3D malloc(sizeof(struct route_ipv4_config)); > + if (!ipv4route) > + return -ENOMEM; > + } else { > + return 0; > + } > + > + ipv4route->ip =3D route->ip; > + ipv4route->netmask =3D route->netmask; > + ipv4route->via =3D route->via; > + ipv4route->is_used =3D true; > + > + /* FIXME: Get graph status here and then update table */ > + rc =3D route4_rewirte_table_update(ipv4route); > + if (rc) > + goto free; > + > + TAILQ_INSERT_TAIL(&route4, ipv4route, next); > + return 0; > +free: > + free(ipv4route); > + return rc; > +} > + > +int > +route_ip4_add_to_lookup(void) > +{ > + struct route_ipv4_config *route =3D NULL; > + int rc =3D -EINVAL; > + > + TAILQ_FOREACH(route, &route4, next) { > + rc =3D route4_rewirte_table_update(route); > + if (rc < 0) > + return rc; > + } > + > + return 0; > +} > + > +static void > +cli_ipv4_lookup_help(__rte_unused void *parsed_result, __rte_unused stru= ct cmdline *cl, > + __rte_unused void *data) > +{ > + size_t len; > + > + len =3D strlen(conn->msg_out); > + conn->msg_out +=3D len; > + snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n", > + "--------------------------- ipv4_lookup command help --= -------------------------", > + cmd_ipv4_lookup_help); > + > + len =3D strlen(conn->msg_out); > + conn->msg_out_len_max -=3D len; > +} > + > +static void > +cli_ipv4_lookup(void *parsed_result, __rte_unused struct cmdline *cl, vo= id *data __rte_unused) > +{ > + struct ip4_lookup_cmd_tokens *res =3D parsed_result; > + struct route_ipv4_config config; > + int rc =3D -EINVAL; > + > + if (parser_ip4_read(&config.ip, res->ip)) { > + printf(MSG_ARG_INVALID, "ipv4"); > + return; > + } > + > + if (parser_ip4_read(&config.netmask, res->mask)) { > + printf(MSG_ARG_INVALID, "netmask"); > + return; > + } > + > + if (parser_ip4_read(&config.via, res->via_ip)) { > + printf(MSG_ARG_INVALID, "via ip"); > + return; > + } > + > + rc =3D route_ip4_add(&config); > + if (rc < 0) > + printf(MSG_CMD_FAIL, res->cmd); > +} > + > +cmdline_parse_token_string_t ip4_lookup_cmd =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, cmd, "ipv4= _lookup"); > +cmdline_parse_token_string_t ip4_lookup_route =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, route, "ro= ute"); > +cmdline_parse_token_string_t ip4_lookup_add =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, add, "add"= ); > +cmdline_parse_token_string_t ip4_lookup_ip4 =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, ip4, "ipv4= "); > +cmdline_parse_token_string_t ip4_lookup_ip =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, ip, NULL); > +cmdline_parse_token_string_t ip4_lookup_netmask =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, netmask, "= netmask"); > +cmdline_parse_token_string_t ip4_lookup_mask =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, mask, NULL= ); > +cmdline_parse_token_string_t ip4_lookup_via =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, via, "via"= ); > +cmdline_parse_token_string_t ip4_lookup_via_ip =3D > + TOKEN_STRING_INITIALIZER(struct ip4_lookup_cmd_tokens, via_ip, NU= LL); > + > +cmdline_parse_inst_t ipv4_lookup_cmd_ctx =3D { > + .f =3D cli_ipv4_lookup, > + .data =3D NULL, > + .help_str =3D cmd_ipv4_lookup_help, > + .tokens =3D { > + (void *)&ip4_lookup_cmd, > + (void *)&ip4_lookup_route, > + (void *)&ip4_lookup_add, > + (void *)&ip4_lookup_ip4, > + (void *)&ip4_lookup_ip, > + (void *)&ip4_lookup_netmask, > + (void *)&ip4_lookup_mask, > + (void *)&ip4_lookup_via, > + (void *)&ip4_lookup_via_ip, > + NULL, > + }, > +}; > + > +cmdline_parse_token_string_t ipv4_lookup_help_cmd =3D > + TOKEN_STRING_INITIALIZER(struct ipv4_lookup_help_cmd_tokens, cmd,= "help"); > +cmdline_parse_token_string_t ipv4_lookup_help_module =3D > + TOKEN_STRING_INITIALIZER(struct ipv4_lookup_help_cmd_tokens, modu= le, "ipv4_lookup"); > + > +cmdline_parse_inst_t ipv4_lookup_help_cmd_ctx =3D { > + .f =3D cli_ipv4_lookup_help, > + .data =3D NULL, > + .help_str =3D "", > + .tokens =3D { > + (void *)&ipv4_lookup_help_cmd, > + (void *)&ipv4_lookup_help_module, > + NULL, > + }, > +}; > diff --git a/app/graph/meson.build b/app/graph/meson.build > index c17e0cc63e..1f35f82583 100644 > --- a/app/graph/meson.build > +++ b/app/graph/meson.build > @@ -13,6 +13,7 @@ sources =3D files( > 'cli.c', > 'conn.c', > 'ethdev.c', > + 'ip4_route.c', > 'main.c', > 'mempool.c', > 'utils.c', > diff --git a/app/graph/module_api.h b/app/graph/module_api.h > index e8a6ccb562..bd4d245c75 100644 > --- a/app/graph/module_api.h > +++ b/app/graph/module_api.h > @@ -12,6 +12,7 @@ > #include "conn.h" > #include "ethdev.h" > #include "mempool.h" > +#include "route.h" > #include "utils.h" > /* > * Externs > diff --git a/app/graph/route.h b/app/graph/route.h > new file mode 100644 > index 0000000000..a44d401d55 > --- /dev/null > +++ b/app/graph/route.h > @@ -0,0 +1,26 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#ifndef APP_GRAPH_ROUTE_H > +#define APP_GRAPH_ROUTE_H > + > +#define MAX_ROUTE_ENTRIES 32 > + > +extern cmdline_parse_inst_t ipv4_lookup_cmd_ctx; > +extern cmdline_parse_inst_t ipv4_lookup_help_cmd_ctx; > + > +struct route_ipv4_config { > + TAILQ_ENTRY(route_ipv4_config) next; > + uint32_t ip; > + uint32_t netmask; > + uint32_t via; > + bool is_used; > +}; > + > +TAILQ_HEAD(ip4_route, route_ipv4_config); > + > +int route_ip4_add_to_lookup(void); > +void route_ip4_list_clean(void); > + > +#endif > diff --git a/app/graph/route_priv.h b/app/graph/route_priv.h > new file mode 100644 > index 0000000000..f363a551a9 > --- /dev/null > +++ b/app/graph/route_priv.h > @@ -0,0 +1,44 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Marvell. > + */ > + > +#ifndef APP_GRAPH_ROUTE_PRIV_H > +#define APP_GRAPH_ROUTE_PRIV_H > + > +#define MAX_ROUTE_ENTRIES 32 > + > +struct ip4_lookup_cmd_tokens { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t route; > + cmdline_fixed_string_t add; > + cmdline_fixed_string_t ip4; > + cmdline_fixed_string_t ip; > + cmdline_fixed_string_t netmask; > + cmdline_fixed_string_t mask; > + cmdline_fixed_string_t via; > + cmdline_fixed_string_t via_ip; > +}; > + > +struct ip6_lookup_cmd_tokens { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t route; > + cmdline_fixed_string_t add; > + cmdline_fixed_string_t ip6; > + cmdline_fixed_string_t ip; > + cmdline_fixed_string_t netmask; > + cmdline_fixed_string_t mask; > + cmdline_fixed_string_t via; > + cmdline_fixed_string_t via_ip; > +}; > + > +struct ipv4_lookup_help_cmd_tokens { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t module; > +}; > + > +struct ipv6_lookup_help_cmd_tokens { > + cmdline_fixed_string_t cmd; > + cmdline_fixed_string_t module; > +}; > + > +#endif > diff --git a/doc/guides/tools/graph.rst b/doc/guides/tools/graph.rst > index 5dedea97de..7530ef6f65 100644 > --- a/doc/guides/tools/graph.rst > +++ b/doc/guides/tools/graph.rst > @@ -112,6 +112,15 @@ file to express the requested use case configuration= . > | help ethdev | | Command to dump ethdev hel= p | Yes | Yes | > | | | message. = | | | > +--------------------------------------+-----------------------------= ------+---------+----------+ > + | | ipv4_lookup route add ipv4 | | Command to add a route int= o | Yes | Yes | > + | | netmask via | | ``ipv4_lookup`` LPM table.= It is| | | > + | | | needed if user wishes to r= oute | | | > + | | | the packets based on LPM l= ookup | | | > + | | | table. = | | | > + +--------------------------------------+-----------------------------= ------+---------+----------+ > + | help ipv4_lookup | | Command to dump ``ipv4_loo= kup`` | Yes | Yes | > + | | | help message. = | | | > + +--------------------------------------+-----------------------------= ------+---------+----------+ > > Runtime configuration > --------------------- > -- > 2.25.1 >