summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKevin Laatz <kevin.laatz@intel.com>2018-06-22 15:31:47 +0100
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>2018-07-12 13:48:29 +0200
commitecfc2b1c074a937a67fc8bb094e6f2ee6ca86f82 (patch)
tree2d3ee87b92ed266610025bdf29c26bc8f617a8eb /examples
parent8232129e57233239a580636a8b533b7725f90e9e (diff)
downloaddpdk-ecfc2b1c074a937a67fc8bb094e6f2ee6ca86f82.zip
dpdk-ecfc2b1c074a937a67fc8bb094e6f2ee6ca86f82.tar.gz
dpdk-ecfc2b1c074a937a67fc8bb094e6f2ee6ca86f82.tar.xz
examples/ip_pipeline: add link command
Add the functionality to track links in the application. This enables the user to print the name, mac address and statistics for each link in the application. Signed-off-by: Kevin Laatz <kevin.laatz@intel.com> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/ip_pipeline/cli.c91
-rw-r--r--examples/ip_pipeline/link.c6
-rw-r--r--examples/ip_pipeline/link.h3
3 files changed, 100 insertions, 0 deletions
diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
index c9587f5..27c9844 100644
--- a/examples/ip_pipeline/cli.c
+++ b/examples/ip_pipeline/cli.c
@@ -9,6 +9,7 @@
#include <rte_common.h>
#include <rte_cycles.h>
+#include <rte_ethdev.h>
#include "cli.h"
#include "kni.h"
@@ -237,6 +238,91 @@ cmd_link(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;
+ uint16_t mtu;
+
+ 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, &eth_link);
+ rte_eth_dev_get_mtu(link->port_id, &mtu);
+
+ snprintf(out, out_size,
+ "\n"
+ "%s: flags=<%s> mtu %u\n"
+ "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
+ "\tport# %u speed %u Mbps\n"
+ "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
+ "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
+ "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
+ "\tTX errors %" PRIu64"\n",
+ link->name,
+ eth_link.link_status == 0 ? "DOWN" : "UP",
+ mtu,
+ 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],
+ link->n_rxq,
+ link->n_txq,
+ link->port_id,
+ eth_link.link_speed,
+ stats.ipackets,
+ stats.ibytes,
+ stats.ierrors,
+ stats.imissed,
+ stats.rx_nombuf,
+ stats.opackets,
+ stats.obytes,
+ stats.oerrors);
+}
+
+/*
+ * link show [<link_name>]
+ */
+static void
+cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
+{
+ struct link *link;
+ char *link_name;
+
+ if (n_tokens != 2 && n_tokens != 3) {
+ snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+ return;
+ }
+
+ if (n_tokens == 2) {
+ link = link_next(NULL);
+
+ while (link != NULL) {
+ out_size = out_size - strlen(out);
+ out = &out[strlen(out)];
+
+ print_link_info(link, out, out_size);
+ link = link_next(link);
+ }
+ } else {
+ out_size = out_size - strlen(out);
+ out = &out[strlen(out)];
+
+ link_name = tokens[2];
+ link = link_find(link_name);
+
+ if (link == NULL) {
+ snprintf(out, out_size, MSG_ARG_INVALID,
+ "Link does not exist");
+ return;
+ }
+ print_link_info(link, out, out_size);
+ }
+}
+
/**
* swq <swq_name>
* size <size>
@@ -4380,6 +4466,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 805c2eb..2ccfea4 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 *
+link_next(struct link *link)
+{
+ return (link == NULL) ? TAILQ_FIRST(&link_list) : TAILQ_NEXT(link, node);
+}
+
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..34ff114 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 *
+link_next(struct link *link);
+
struct link_params_rss {
uint32_t queue_id[LINK_RXQ_RSS_MAX];
uint32_t n_queues;