diff --git a/apps/shell/shell-commands.c b/apps/shell/shell-commands.c index 48edf55e0..3d53f7d94 100644 --- a/apps/shell/shell-commands.c +++ b/apps/shell/shell-commands.c @@ -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." }, diff --git a/core/net/ipv6/uip-ds6-nbr.c b/core/net/ipv6/uip-ds6-nbr.c index 90ff7e27e..7091e497c 100644 --- a/core/net/ipv6/uip-ds6-nbr.c +++ b/core/net/ipv6/uip-ds6-nbr.c @@ -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); diff --git a/core/net/ipv6/uip-ds6-nbr.h b/core/net/ipv6/uip-ds6-nbr.h index e4a2fee42..6e199a11f 100644 --- a/core/net/ipv6/uip-ds6-nbr.h +++ b/core/net/ipv6/uip-ds6-nbr.h @@ -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 /**