From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id F27791B449 for ; Fri, 2 Nov 2018 12:37:12 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Nov 2018 04:37:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,455,1534834800"; d="scan'208";a="105381797" Received: from silpixa00382658.ir.intel.com ([10.237.223.29]) by orsmga002.jf.intel.com with ESMTP; 02 Nov 2018 04:37:11 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Jasvinder Singh Date: Fri, 2 Nov 2018 11:36:58 +0000 Message-Id: <1541158623-29742-7-git-send-email-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541158623-29742-1-git-send-email-cristian.dumitrescu@intel.com> References: <1541158623-29742-1-git-send-email-cristian.dumitrescu@intel.com> Subject: [dpdk-dev] [PATCH 07/12] examples/ip_pipeline: support rule stats read X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2018 11:37:13 -0000 Add support for rule stats read operation. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- examples/ip_pipeline/cli.c | 105 ++++++++++++++++++++++++++++++++++++++-- examples/ip_pipeline/pipeline.h | 2 +- examples/ip_pipeline/thread.c | 24 +++++---- 3 files changed, 117 insertions(+), 14 deletions(-) diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c index 54d347c..e7ad93e 100644 --- a/examples/ip_pipeline/cli.c +++ b/examples/ip_pipeline/cli.c @@ -4741,17 +4741,114 @@ cmd_pipeline_table_rule_delete_default(char **tokens, static const char cmd_pipeline_table_rule_stats_read_help[] = -"pipeline table rule read stats [clear]\n"; +"pipeline table rule read stats [clear]\n" +" match \n"; static void cmd_pipeline_table_rule_stats_read(char **tokens, - uint32_t n_tokens __rte_unused, + uint32_t n_tokens, char *out, size_t out_size) { - snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]); -} + struct table_rule_match m; + struct rte_table_action_stats_counters stats; + char *pipeline_name; + uint32_t table_id, n_tokens_parsed; + int clear = 0, status; + + if (n_tokens < 7) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + pipeline_name = tokens[1]; + + if (strcmp(tokens[2], "table") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table"); + return; + } + + if (parser_read_uint32(&table_id, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "table_id"); + return; + } + + if (strcmp(tokens[4], "rule") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule"); + return; + } + + if (strcmp(tokens[5], "read") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read"); + return; + } + + if (strcmp(tokens[6], "stats") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); + return; + } + + n_tokens -= 7; + tokens += 7; + + /* clear */ + if (n_tokens && (strcmp(tokens[0], "clear") == 0)) { + clear = 1; + + n_tokens--; + tokens++; + } + + /* match */ + if ((n_tokens == 0) || strcmp(tokens[0], "match")) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match"); + return; + } + + n_tokens_parsed = parse_match(tokens, + n_tokens, + out, + out_size, + &m); + if (n_tokens_parsed == 0) + return; + n_tokens -= n_tokens_parsed; + tokens += n_tokens_parsed; + + /* end */ + if (n_tokens) { + snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); + return; + } + + /* Read table rule stats. */ + status = pipeline_table_rule_stats_read(pipeline_name, + table_id, + &m, + &stats, + clear); + if (status) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } + /* Print stats. */ + if (stats.n_packets_valid && stats.n_bytes_valid) + snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n", + stats.n_packets, + stats.n_bytes); + + if (stats.n_packets_valid && !stats.n_bytes_valid) + snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n", + stats.n_packets); + + if (!stats.n_packets_valid && stats.n_bytes_valid) + snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n", + stats.n_bytes); + + if (!stats.n_packets_valid && !stats.n_bytes_valid) + snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n"); +} static const char cmd_pipeline_table_meter_profile_add_help[] = "pipeline table meter profile \n" diff --git a/examples/ip_pipeline/pipeline.h b/examples/ip_pipeline/pipeline.h index 15a38fd..2c42e0d 100644 --- a/examples/ip_pipeline/pipeline.h +++ b/examples/ip_pipeline/pipeline.h @@ -355,7 +355,7 @@ pipeline_table_rule_delete_default(const char *pipeline_name, int pipeline_table_rule_stats_read(const char *pipeline_name, uint32_t table_id, - void *data, + struct table_rule_match *match, struct rte_table_action_stats_counters *stats, int clear); diff --git a/examples/ip_pipeline/thread.c b/examples/ip_pipeline/thread.c index 1baad67..b172f91 100644 --- a/examples/ip_pipeline/thread.c +++ b/examples/ip_pipeline/thread.c @@ -1796,31 +1796,37 @@ pipeline_table_rule_delete_default(const char *pipeline_name, int pipeline_table_rule_stats_read(const char *pipeline_name, uint32_t table_id, - void *data, + struct table_rule_match *match, struct rte_table_action_stats_counters *stats, int clear) { struct pipeline *p; + struct table *table; struct pipeline_msg_req *req; struct pipeline_msg_rsp *rsp; + struct table_rule *rule; int status; /* Check input params */ if ((pipeline_name == NULL) || - (data == NULL) || + (match == NULL) || (stats == NULL)) return -1; p = pipeline_find(pipeline_name); if ((p == NULL) || - (table_id >= p->n_tables)) + (table_id >= p->n_tables) || + match_check(match, p, table_id)) return -1; - if (!pipeline_is_running(p)) { - struct rte_table_action *a = p->table[table_id].a; + table = &p->table[table_id]; + rule = table_rule_find(table, match); + if (rule == NULL) + return -1; - status = rte_table_action_stats_read(a, - data, + if (!pipeline_is_running(p)) { + status = rte_table_action_stats_read(table->a, + rule->data, stats, clear); @@ -1835,7 +1841,7 @@ pipeline_table_rule_stats_read(const char *pipeline_name, /* Write request */ req->type = PIPELINE_REQ_TABLE_RULE_STATS_READ; req->id = table_id; - req->table_rule_stats_read.data = data; + req->table_rule_stats_read.data = rule->data; req->table_rule_stats_read.clear = clear; /* Send request and wait for response */ @@ -1845,7 +1851,7 @@ pipeline_table_rule_stats_read(const char *pipeline_name, /* Read response */ status = rsp->status; - if (status) + if (status == 0) memcpy(stats, &rsp->table_rule_stats_read.stats, sizeof(*stats)); /* Free response */ -- 2.7.4