From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id EF4CE4CBB for ; Fri, 8 Jun 2018 18:31:06 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 09:31:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,490,1520924400"; d="scan'208";a="57654267" Received: from silpixa00397517.ir.intel.com (HELO silpixa00397517.ger.corp.intel.com) ([10.237.222.54]) by orsmga003.jf.intel.com with ESMTP; 08 Jun 2018 09:31:03 -0700 From: Kevin Laatz To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, Kevin Laatz Date: Fri, 8 Jun 2018 17:30:53 +0100 Message-Id: <20180608163053.37891-1-kevin.laatz@intel.com> X-Mailer: git-send-email 2.9.5 Subject: [dpdk-dev] [PATCH] examples/ip_pipeline: add link show to the cli 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, 08 Jun 2018 16:31:07 -0000 Add the functionality to track links in the application. This enables the user to print the name, mac address and per-port statistics for each link in the application. Signed-off-by: Kevin Laatz --- examples/ip_pipeline/cli.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ examples/ip_pipeline/link.c | 6 +++ examples/ip_pipeline/link.h | 3 ++ 3 files changed, 112 insertions(+) diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c index c9587f5..b7fba3b 100644 --- a/examples/ip_pipeline/cli.c +++ b/examples/ip_pipeline/cli.c @@ -9,6 +9,7 @@ #include #include +#include #include "cli.h" #include "kni.h" @@ -4355,6 +4356,103 @@ cmd_thread_pipeline_disable(char **tokens, } } +/* Print the link stats and info */ +static void +print_link_info(struct link *link, char *out, size_t out_size) +{ + struct rte_eth_stats stats; + struct ether_addr mac_addr; + struct rte_eth_link eth_link; + + memset(&stats, 0, sizeof(stats)); + rte_eth_stats_get(link->port_id, &stats); + + rte_eth_macaddr_get(link->port_id, &mac_addr); + rte_eth_link_get(link->port_id, ð_link); + + snprintf(out, out_size, + "\n" + "Link name: %s\n" + "\tPort %u MAC: %02"PRIx8":%02"PRIx8":%02"PRIx8 + ":%02"PRIx8":%02"PRIx8":%02"PRIx8"\n" + "\tLink Status: %s\n" + "\tLink Speed: %u\n" + "\n" + "\tRX info:\n" + "\t\tQueues: %u\n" + "\t\tPackets: %" PRIu64 + "\t\tBytes: %" PRIu64"\n" + "\t\tErrors: %" PRIu64 + "\t\tMissed: %" PRIu64 + "\t\tNo-mbuf: %" PRIu64"\n" + "\tTX info:\n" + "\t\tQueues: %u\n" + "\t\tPackets: %" PRIu64 + "\t\tBytes: %" PRIu64"\n" + "\t\tErrors: %" PRIu64"\n", + link->name, + link->port_id, + mac_addr.addr_bytes[0], mac_addr.addr_bytes[1], + mac_addr.addr_bytes[2], mac_addr.addr_bytes[3], + mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], + eth_link.link_status == 1 ? "UP" : "DOWN", + eth_link.link_speed, + link->n_rxq, + stats.ipackets, + stats.ibytes, + stats.ierrors, + stats.imissed, + stats.rx_nombuf, + link->n_txq, + stats.opackets, + stats.obytes, + stats.oerrors); +} + +/* + * link show [] + */ +static void +cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size) +{ + struct link *link; + struct link_list *link_list; + char *link_name; + uint32_t i = 0; + + if (n_tokens != 2 && n_tokens != 3) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + link_list = links_get(); + + if (TAILQ_EMPTY(link_list)) { + snprintf(out, out_size, "No links - nothing to show\n"); + return; + } + + if (n_tokens == 2) { + TAILQ_FOREACH(link, link_list, node) { + size_t os = out_size - (i * strlen(out)); + char *o = &out[i * strlen(out)]; + + if (os == 0) { + snprintf(out, out_size, MSG_CMD_FAIL, + "Output buffer too small"); + return; + } + + print_link_info(link, o, os); + i++; + } + } else { + link_name = tokens[2]; + link = link_find(link_name); + print_link_info(link, out, out_size); + } +} + void cli_process(char *in, char *out, size_t out_size) { @@ -4380,6 +4478,11 @@ cli_process(char *in, char *out, size_t out_size) } if (strcmp(tokens[0], "link") == 0) { + if (strcmp(tokens[1], "show") == 0) { + cmd_link_show(tokens, n_tokens, out, out_size); + return; + } + cmd_link(tokens, n_tokens, out, out_size); return; } diff --git a/examples/ip_pipeline/link.c b/examples/ip_pipeline/link.c index b8a431f..b11f0c1 100644 --- a/examples/ip_pipeline/link.c +++ b/examples/ip_pipeline/link.c @@ -36,6 +36,12 @@ link_find(const char *name) return NULL; } +struct link_list * +links_get(void) +{ + return &link_list; +} + static struct rte_eth_conf port_conf_default = { .link_speeds = 0, .rxmode = { diff --git a/examples/ip_pipeline/link.h b/examples/ip_pipeline/link.h index 37d3dc4..10f9d51 100644 --- a/examples/ip_pipeline/link.h +++ b/examples/ip_pipeline/link.h @@ -30,6 +30,9 @@ link_init(void); struct link * link_find(const char *name); +struct link_list * +links_get(void); + struct link_params_rss { uint32_t queue_id[LINK_RXQ_RSS_MAX]; uint32_t n_queues; -- 2.9.5