From patchwork Thu Aug 4 16:58:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 114636 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 482C4A00C4; Thu, 4 Aug 2022 19:00:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D475D42C65; Thu, 4 Aug 2022 18:59:09 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 3F50242C17 for ; Thu, 4 Aug 2022 18:59:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659632346; x=1691168346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mL9MPEvgVOAdtHiwVXXLAlWvlp+bs+Uor9HVkM9vDpY=; b=IpwPh2vQMlApqRPiDTYERAyDxy+0TTwcgLmo6MNix2d3lpFgGS6+NlnE VKoNvQUcl7iSiUPWDbCUgkgWRzVx/H42I084WdxaSKrQezaPan/Kiuuwj 36d8ezhVh5nhZ98qJb1D+b1V1BRUvFY5Sj7cSbIAYJRRsUEvkHgBYb1jA nkGgyeqdT4IWIsmsDwzsB3Rih87hy7NR8a6SXVYr77vEfelFZg6GmZn0D NWhz67SpK+vplFgyg60LoYZS5z3Z+IQjS5k6kZdIXau5p0LTVGkS2ZbfU EvNGI4irvzjSr/h045bOuAAYLViTxJ3VX+s46I+P5KN9LcMvs+buSApzW Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10429"; a="290000166" X-IronPort-AV: E=Sophos;i="5.93,216,1654585200"; d="scan'208";a="290000166" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2022 09:59:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,216,1654585200"; d="scan'208";a="636163208" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.157]) by orsmga001.jf.intel.com with ESMTP; 04 Aug 2022 09:59:04 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: jasvinder.singh@intel.com, yogesh.jangra@intel.com Subject: [PATCH 13/21] net/softnic: add pipeline table CLI commands Date: Thu, 4 Aug 2022 16:58:31 +0000 Message-Id: <20220804165839.1074817-14-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804165839.1074817-1-cristian.dumitrescu@intel.com> References: <20220804165839.1074817-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add CLI commands for pipeline table entry management. Signed-off-by: Cristian Dumitrescu Signed-off-by: Yogesh Jangra --- drivers/net/softnic/rte_eth_softnic_cli.c | 376 ++++++++++++++++++++++ 1 file changed, 376 insertions(+) diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c index a814257229..dd219e229d 100644 --- a/drivers/net/softnic/rte_eth_softnic_cli.c +++ b/drivers/net/softnic/rte_eth_softnic_cli.c @@ -428,6 +428,354 @@ cmd_softnic_pipeline_build(struct pmd_internals *softnic, snprintf(out, out_size, "Pipeline creation failed.\n"); } +static void +table_entry_free(struct rte_swx_table_entry *entry) +{ + if (!entry) + return; + + free(entry->key); + free(entry->key_mask); + free(entry->action_data); + free(entry); +} + +static int +pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, + const char *table_name, + FILE *file, + uint32_t *file_line_number) +{ + char *line = NULL; + uint32_t line_id = 0; + int status = 0; + + /* Buffer allocation. */ + line = malloc(MAX_LINE_SIZE); + if (!line) + return -ENOMEM; + + /* File read. */ + for (line_id = 1; ; line_id++) { + struct rte_swx_table_entry *entry; + int is_blank_or_comment; + + if (fgets(line, MAX_LINE_SIZE, file) == NULL) + break; + + entry = rte_swx_ctl_pipeline_table_entry_read(p, + table_name, + line, + &is_blank_or_comment); + if (!entry) { + if (is_blank_or_comment) + continue; + + status = -EINVAL; + goto error; + } + + status = rte_swx_ctl_pipeline_table_entry_add(p, + table_name, + entry); + table_entry_free(entry); + if (status) + goto error; + } + +error: + free(line); + *file_line_number = line_id; + return status; +} + +/** + * pipeline table add + */ +static void +cmd_softnic_pipeline_table_add(struct pmd_internals *softnic, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct pipeline *p; + char *pipeline_name, *table_name, *file_name; + FILE *file = NULL; + uint32_t file_line_number = 0; + int status; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + pipeline_name = tokens[1]; + p = softnic_pipeline_find(softnic, pipeline_name); + if (!p) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); + return; + } + + table_name = tokens[3]; + + file_name = tokens[5]; + file = fopen(file_name, "r"); + if (!file) { + snprintf(out, out_size, "Cannot open file %s.\n", file_name); + return; + } + + status = pipeline_table_entries_add(p->ctl, + table_name, + file, + &file_line_number); + if (status) + snprintf(out, out_size, "Invalid entry in file %s at line %u\n", + file_name, + file_line_number); + + fclose(file); +} + +static int +pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p, + const char *table_name, + FILE *file, + uint32_t *file_line_number) +{ + char *line = NULL; + uint32_t line_id = 0; + int status = 0; + + /* Buffer allocation. */ + line = malloc(MAX_LINE_SIZE); + if (!line) + return -ENOMEM; + + /* File read. */ + for (line_id = 1; ; line_id++) { + struct rte_swx_table_entry *entry; + int is_blank_or_comment; + + if (fgets(line, MAX_LINE_SIZE, file) == NULL) + break; + + entry = rte_swx_ctl_pipeline_table_entry_read(p, + table_name, + line, + &is_blank_or_comment); + if (!entry) { + if (is_blank_or_comment) + continue; + + status = -EINVAL; + goto error; + } + + status = rte_swx_ctl_pipeline_table_entry_delete(p, + table_name, + entry); + table_entry_free(entry); + if (status) + goto error; + } + +error: + *file_line_number = line_id; + free(line); + return status; +} + +/** + * pipeline table delete + */ +static void +cmd_softnic_pipeline_table_delete(struct pmd_internals *softnic, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct pipeline *p; + char *pipeline_name, *table_name, *file_name; + FILE *file = NULL; + uint32_t file_line_number = 0; + int status; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + pipeline_name = tokens[1]; + p = softnic_pipeline_find(softnic, pipeline_name); + if (!p) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); + return; + } + + table_name = tokens[3]; + + file_name = tokens[5]; + file = fopen(file_name, "r"); + if (!file) { + snprintf(out, out_size, "Cannot open file %s.\n", file_name); + return; + } + + status = pipeline_table_entries_delete(p->ctl, + table_name, + file, + &file_line_number); + if (status) + snprintf(out, out_size, "Invalid entry in file %s at line %u\n", + file_name, + file_line_number); + + fclose(file); +} + +static int +pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p, + const char *table_name, + FILE *file, + uint32_t *file_line_number) +{ + char *line = NULL; + uint32_t line_id = 0; + int status = 0; + + /* Buffer allocation. */ + line = malloc(MAX_LINE_SIZE); + if (!line) + return -ENOMEM; + + /* File read. */ + for (line_id = 1; ; line_id++) { + struct rte_swx_table_entry *entry; + int is_blank_or_comment; + + if (fgets(line, MAX_LINE_SIZE, file) == NULL) + break; + + entry = rte_swx_ctl_pipeline_table_entry_read(p, + table_name, + line, + &is_blank_or_comment); + if (!entry) { + if (is_blank_or_comment) + continue; + + status = -EINVAL; + goto error; + } + + status = rte_swx_ctl_pipeline_table_default_entry_add(p, + table_name, + entry); + table_entry_free(entry); + if (status) + goto error; + } + +error: + *file_line_number = line_id; + free(line); + return status; +} + +/** + * pipeline table default + */ +static void +cmd_softnic_pipeline_table_default(struct pmd_internals *softnic, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct pipeline *p; + char *pipeline_name, *table_name, *file_name; + FILE *file = NULL; + uint32_t file_line_number = 0; + int status; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + pipeline_name = tokens[1]; + p = softnic_pipeline_find(softnic, pipeline_name); + if (!p) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); + return; + } + + table_name = tokens[3]; + + file_name = tokens[5]; + file = fopen(file_name, "r"); + if (!file) { + snprintf(out, out_size, "Cannot open file %s.\n", file_name); + return; + } + + status = pipeline_table_default_entry_add(p->ctl, + table_name, + file, + &file_line_number); + if (status) + snprintf(out, out_size, "Invalid entry in file %s at line %u\n", + file_name, + file_line_number); + + fclose(file); +} + +/** + * pipeline table show [filename] + */ +static void +cmd_softnic_pipeline_table_show(struct pmd_internals *softnic __rte_unused, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct pipeline *p; + char *pipeline_name, *table_name; + FILE *file = NULL; + int status; + + if (n_tokens != 5 && n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + pipeline_name = tokens[1]; + p = softnic_pipeline_find(softnic, pipeline_name); + if (!p) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); + return; + } + + table_name = tokens[3]; + file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout; + if (!file) { + snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]); + return; + } + + status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name); + if (status) + snprintf(out, out_size, MSG_ARG_INVALID, "table_name"); + + if (file) + fclose(file); +} + /** * thread pipeline enable [ period ] */ @@ -572,6 +920,34 @@ softnic_cli_process(char *in, char *out, size_t out_size, void *arg) cmd_softnic_pipeline_build(softnic, tokens, n_tokens, out, out_size); return; } + + if ((n_tokens >= 5) && + !strcmp(tokens[2], "table") && + !strcmp(tokens[4], "add")) { + cmd_softnic_pipeline_table_add(softnic, tokens, n_tokens, out, out_size); + return; + } + + if ((n_tokens >= 5) && + !strcmp(tokens[2], "table") && + !strcmp(tokens[4], "delete")) { + cmd_softnic_pipeline_table_delete(softnic, tokens, n_tokens, + out, out_size); + return; + } + + if ((n_tokens >= 5) && + !strcmp(tokens[2], "table") && + !strcmp(tokens[4], "default")) { + cmd_softnic_pipeline_table_default(softnic, tokens, n_tokens, + out, out_size); + return; + } + + if ((n_tokens >= 5) && !strcmp(tokens[2], "table") && !strcmp(tokens[4], "show")) { + cmd_softnic_pipeline_table_show(softnic, tokens, n_tokens, out, out_size); + return; + } } if (strcmp(tokens[0], "thread") == 0) {