mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
c06335b71b
Previously `shell_commands` was a "catch-all" module that included shell commands for each and every used module that has a shell companion. Instead, the new `shell_cmds` module is now used to provide shell commands as individually selectable submodules, e.g. `cmd_gnrc_icmpv6_echo` now provides the ICMPv6 echo command (a.k.a. ping). To still have a "catch all" module to pull in shell commands of modules already used, `shell_cmds_default` was introduced. `shell_commands` depends now on `shell_cmds_default` for backward compatibility, but has been deprecated. New apps should use `shell_cmds_default` instead. For a handful of shell commands individual selection was already possible. Those modules now depend on the corresponding `cmd_%` module and they have been deprecated.
106 lines
2.7 KiB
C
106 lines
2.7 KiB
C
/*
|
|
* Copyright (C) Koen Zandberg <koen@bergzand.net>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup sys_shell_commands
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief Shell commands for displaying neighbor statistics
|
|
*
|
|
* @author Koen Zandberg <koen@bergzand.net>
|
|
* @author Benjamin Valentin <benpicco@beuth-hochschule.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "net/gnrc/netif.h"
|
|
#include "net/netstats.h"
|
|
#include "net/netstats/neighbor.h"
|
|
#include "shell.h"
|
|
|
|
static void _print_neighbors(netif_t *dev)
|
|
{
|
|
netstats_nb_t *stats = &dev->neighbors.pstats[0];
|
|
unsigned header_len = 0;
|
|
char l2addr_str[3 * L2UTIL_ADDR_MAX_LEN];
|
|
puts("Neighbor link layer stats:");
|
|
header_len += printf("L2 address fresh");
|
|
if (IS_USED(MODULE_NETSTATS_NEIGHBOR_ETX)) {
|
|
header_len += printf(" etx");
|
|
}
|
|
if (IS_USED(MODULE_NETSTATS_NEIGHBOR_COUNT)) {
|
|
header_len += printf(" sent received");
|
|
}
|
|
if (IS_USED(MODULE_NETSTATS_NEIGHBOR_RSSI)) {
|
|
header_len += printf(" rssi ");
|
|
}
|
|
if (IS_USED(MODULE_NETSTATS_NEIGHBOR_LQI)) {
|
|
header_len += printf(" lqi");
|
|
}
|
|
if (IS_USED(MODULE_NETSTATS_NEIGHBOR_TX_TIME)) {
|
|
header_len += printf(" avg tx time");
|
|
}
|
|
printf("\n");
|
|
|
|
while (header_len--) {
|
|
printf("-");
|
|
}
|
|
printf("\n");
|
|
|
|
for (unsigned i = 0; i < NETSTATS_NB_SIZE; ++i) {
|
|
netstats_nb_t *entry = &stats[i];
|
|
|
|
if (entry->l2_addr_len == 0) {
|
|
continue;
|
|
}
|
|
|
|
printf("%-24s ",
|
|
gnrc_netif_addr_to_str(entry->l2_addr, entry->l2_addr_len, l2addr_str));
|
|
if (netstats_nb_isfresh(dev, entry)) {
|
|
printf("%5u", (unsigned)entry->freshness);
|
|
} else {
|
|
printf("STALE");
|
|
}
|
|
|
|
#if IS_USED(MODULE_NETSTATS_NEIGHBOR_ETX)
|
|
printf(" %3u%%", (100 * entry->etx) / NETSTATS_NB_ETX_DIVISOR);
|
|
#endif
|
|
#if IS_USED(MODULE_NETSTATS_NEIGHBOR_COUNT)
|
|
printf(" %4"PRIu16" %8"PRIu16, entry->tx_count, entry->rx_count);
|
|
#endif
|
|
#if IS_USED(MODULE_NETSTATS_NEIGHBOR_RSSI)
|
|
printf(" %4i dBm", (int8_t) entry->rssi);
|
|
#endif
|
|
#if IS_USED(MODULE_NETSTATS_NEIGHBOR_LQI)
|
|
printf(" %u", entry->lqi);
|
|
#endif
|
|
#if IS_USED(MODULE_NETSTATS_NEIGHBOR_TX_TIME)
|
|
printf(" %7"PRIu32" µs", entry->time_tx_avg);
|
|
#endif
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
static int _netstats_nb(int argc, char **argv)
|
|
{
|
|
(void) argc;
|
|
(void) argv;
|
|
|
|
gnrc_netif_t *netif = NULL;
|
|
while ((netif = gnrc_netif_iter(netif))) {
|
|
_print_neighbors(&netif->netif);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
SHELL_COMMAND(neigh, "Show neighbor statistics", _netstats_nb);
|