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 D9F2EA00C5; Wed, 12 Jan 2022 20:00:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0CDA4270D; Wed, 12 Jan 2022 20:00:51 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id C312540150 for ; Wed, 12 Jan 2022 20:00:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642014050; x=1673550050; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vyrocSiiTKVP8h0esT+DjqGgerRR07hx0ikdJ0UwBmA=; b=iSXMJ8hHiMkpUA7064E9WfbgkKKO0XY33LbxeMc77ezd1aYO7PvseUJE KD+CJ/gylk7pFvrlRvrchtpTVSPOXPMQIcEtTgm62DtbFbZC9ATt7SgHz eunSKcBhyJ7nSasO1nVf5NaQ+plWJ9wMa7yMZtKdh+xkqFacvNH1dijNM JPIIRixOLVR8HpcXxK6JjhO7/J74eekPETOuMov8RR658sapziZSUaShE henJJEdxorV64ft7hctN7JvjcKKSmnnfbsUvtqKfoZmyz+sml7oHfAvP7 uHE8Y/tMH09b3EHlpJOqcNCPmzqpXdCfWb0MJHxFF+MymRziS0pM+FDHi A==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="307174988" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="307174988" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 10:59:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="529326352" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by orsmga008.jf.intel.com with ESMTP; 12 Jan 2022 10:59:11 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Harshad Narayane Subject: [PATCH V2] examples/pipeline: print table entries to file Date: Wed, 12 Jan 2022 18:59:10 +0000 Message-Id: <20220112185910.78377-1-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220112183518.77895-1-cristian.dumitrescu@intel.com> References: <20220112183518.77895-1-cristian.dumitrescu@intel.com> 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 support for the show CLI command to print table entries to a file instead of standard output. Signed-off-by: Cristian Dumitrescu Signed-off-by: Harshad Narayane --- examples/pipeline/cli.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index c32349e5f0..edae63dae6 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -1346,7 +1346,7 @@ cmd_pipeline_table_default(char **tokens, } static const char cmd_pipeline_table_show_help[] = -"pipeline table show\n"; +"pipeline table show [filename]\n"; static void cmd_pipeline_table_show(char **tokens, @@ -1357,9 +1357,10 @@ cmd_pipeline_table_show(char **tokens, { struct pipeline *p; char *pipeline_name, *table_name; + FILE *file = NULL; int status; - if (n_tokens != 5) { + if (n_tokens != 5 && n_tokens != 6) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } @@ -1372,9 +1373,18 @@ cmd_pipeline_table_show(char **tokens, } table_name = tokens[3]; - status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name); + 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); } static const char cmd_pipeline_selector_group_add_help[] = @@ -1806,7 +1816,7 @@ cmd_pipeline_selector_group_member_delete(char **tokens, } static const char cmd_pipeline_selector_show_help[] = -"pipeline selector show\n"; +"pipeline selector show [filename]\n"; static void cmd_pipeline_selector_show(char **tokens, @@ -1817,9 +1827,10 @@ cmd_pipeline_selector_show(char **tokens, { struct pipeline *p; char *pipeline_name, *selector_name; + FILE *file = NULL; int status; - if (n_tokens != 5) { + if (n_tokens != 5 && n_tokens != 6) { snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); return; } @@ -1832,10 +1843,19 @@ cmd_pipeline_selector_show(char **tokens, } selector_name = tokens[3]; - status = rte_swx_ctl_pipeline_selector_fprintf(stdout, - p->ctl, selector_name); + + 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_selector_fprintf(file, p->ctl, selector_name); if (status) snprintf(out, out_size, MSG_ARG_INVALID, "selector_name"); + + if (file) + fclose(file); } static int -- 2.17.1