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 E4D08A0032; Thu, 1 Sep 2022 16:22:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2753842BAB; Thu, 1 Sep 2022 16:21:19 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 19C5C42B6D for ; Thu, 1 Sep 2022 16:21:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662042069; x=1693578069; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mkaiR00zkyndC54OmPVJvToKKnZPm+8Qmem3M1gU/SA=; b=HCUVZTorXWqgKo+2uocYZLEwzzWcaqotT/gnLqX8idPcuQ2oS6iVrb+1 zvwnAu2TfJ4U5we2qs4tWnHyswXTqw0076KEVER6y50woc8aHbjq6i2tu avCWqbn4u0KXA2UgIkbVhj/nVrVKYBacINeDGWiGv7IH+tW+/LmkfR8IT Nvb7iHLJzftIBFqzW6w7bcVs+DyyxGQRbZykHmSQN8M12IjZTpfM5RWfc xOQotHzyUSzZkFYiX154rra33D8zchOmeu67+h+y/7aYTYMr2gsAII+Po A9cQkf6nw1bPtL1FdjfV800l9J6cSOsbaWuYYvhT2WKUx4iPmjXRJD7ld A==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="357444073" X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="357444073" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:20:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="680870221" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga004.fm.intel.com with ESMTP; 01 Sep 2022 07:20:56 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Yogesh Jangra Subject: [PATCH V3 15/21] net/softnic: add pipeline learner table CLI commands Date: Thu, 1 Sep 2022 14:20:35 +0000 Message-Id: <20220901142041.2628537-16-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220901142041.2628537-1-cristian.dumitrescu@intel.com> References: <20220804165839.1074817-1-cristian.dumitrescu@intel.com> <20220901142041.2628537-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 command for managing the learner table default entry. Signed-off-by: Cristian Dumitrescu Signed-off-by: Yogesh Jangra --- drivers/net/softnic/rte_eth_softnic_cli.c | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c index 1e92e251aa..4b7d001033 100644 --- a/drivers/net/softnic/rte_eth_softnic_cli.c +++ b/drivers/net/softnic/rte_eth_softnic_cli.c @@ -1245,6 +1245,104 @@ cmd_softnic_pipeline_selector_show(struct pmd_internals *softnic, fclose(file); } +static int +pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p, + const char *learner_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_learner_default_entry_read(p, + learner_name, + line, + &is_blank_or_comment); + if (!entry) { + if (is_blank_or_comment) + continue; + + status = -EINVAL; + goto error; + } + + status = rte_swx_ctl_pipeline_learner_default_entry_add(p, + learner_name, + entry); + table_entry_free(entry); + if (status) + goto error; + } + +error: + *file_line_number = line_id; + free(line); + return status; +} + +/** + * pipeline learner default + */ +static void +cmd_softnic_pipeline_learner_default(struct pmd_internals *softnic, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct pipeline *p; + char *pipeline_name, *learner_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; + } + + learner_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_learner_default_entry_add(p->ctl, + learner_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); +} + /** * thread pipeline enable [ period ] */ @@ -1457,6 +1555,14 @@ softnic_cli_process(char *in, char *out, size_t out_size, void *arg) out, out_size); return; } + + if (n_tokens >= 5 && + !strcmp(tokens[2], "learner") && + !strcmp(tokens[4], "default")) { + cmd_softnic_pipeline_learner_default(softnic, tokens, n_tokens, + out, out_size); + return; + } } if (strcmp(tokens[0], "thread") == 0) { -- 2.34.1