Shell: new command to show list of IPv6 nbrs

This commit is contained in:
Simon Duquennoy 2017-07-15 12:35:59 +02:00
parent 48c809a320
commit 2847a05e0a
3 changed files with 64 additions and 1 deletions

View File

@ -72,6 +72,25 @@ static struct process *curr_ping_process;
static uint8_t curr_ping_ttl;
static uint16_t curr_ping_datalen;
/*---------------------------------------------------------------------------*/
static const char *
ds6_nbr_state_to_str(uint8_t state)
{
switch(state) {
case NBR_INCOMPLETE:
return "Incomplete";
case NBR_REACHABLE:
return "Reachable";
case NBR_STALE:
return "Stale";
case NBR_DELAY:
return "Delay";
case NBR_PROBE:
return "Probe";
default:
return "Unknown";
}
}
/*---------------------------------------------------------------------------*/
static const char *
rpl_state_to_str(enum rpl_dag_state state)
@ -331,6 +350,35 @@ PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_ip_neighbors(struct pt *pt, shell_output_func output, char *args))
{
uip_ds6_nbr_t *nbr;
PT_BEGIN(pt);
nbr = uip_ds6_nbr_head();
if(nbr == NULL) {
SHELL_OUTPUT(output, "Node IPv6 neighbors: none\n");
PT_EXIT(pt);
}
SHELL_OUTPUT(output, "Node IPv6 neighbors:\n");
while(nbr != NULL) {
SHELL_OUTPUT(output, "-- ");
shell_output_6addr(output, uip_ds6_nbr_get_ipaddr(nbr));
SHELL_OUTPUT(output, " <-> ");
shell_output_lladdr(output, (linkaddr_t *)uip_ds6_nbr_get_ll(nbr));
SHELL_OUTPUT(output, ", router %u, state %s ",
nbr->isrouter, ds6_nbr_state_to_str(nbr->state));
SHELL_OUTPUT(output, "\n");
nbr = uip_ds6_nbr_next(nbr);
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
@ -535,7 +583,8 @@ shell_commands_init(void)
/*---------------------------------------------------------------------------*/
struct shell_command_t shell_commands[] = {
{ "help", cmd_help, "'> help': Shows this help" },
{ "ipaddr", cmd_ipaddr, "'> ipaddr': Shows all IPv6 addresses" },
{ "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" },
{ "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" },
{ "log", cmd_log, "'> log level': Sets log level (0--4). Level 4 also enables TSCH per-slot logging." },
{ "ping", cmd_ping, "'> ping addr': Pings the IPv6 address 'addr'" },
{ "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (on) or not (off). A /64 prefix can be optionally specified." },

View File

@ -161,6 +161,18 @@ uip_ds6_nbr_num(void)
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_head(void)
{
return nbr_table_head(ds6_neighbors);
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_next(uip_ds6_nbr_t *nbr)
{
return nbr_table_next(ds6_neighbors, nbr);
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr)
{
uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);

View File

@ -97,6 +97,8 @@ const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
void uip_ds6_link_callback(int status, int numtx);
void uip_ds6_neighbor_periodic(void);
int uip_ds6_nbr_num(void);
uip_ds6_nbr_t *uip_ds6_nbr_head(void);
uip_ds6_nbr_t *uip_ds6_nbr_next(uip_ds6_nbr_t *nbr);
#if UIP_ND6_SEND_NS
/**