From 0018e3a181ecf57b5a702a9b15105194be9aad65 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 9 Mar 2014 10:01:10 +0000 Subject: [PATCH] shell: added RPL route shell command --- sys/shell/commands/Makefile | 3 ++ sys/shell/commands/sc_rpl.c | 53 +++++++++++++++++++++++++++++ sys/shell/commands/shell_commands.c | 7 ++++ 3 files changed, 63 insertions(+) create mode 100644 sys/shell/commands/sc_rpl.c diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 64938e4899..0deeb0867a 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -25,6 +25,9 @@ endif ifneq (,$(filter ps,$(USEMODULE))) SRC += sc_ps.c endif +ifneq (,$(filter rpl,$(USEMODULE))) + SRC += sc_rpl.c +endif ifneq (,$(filter rtc,$(USEMODULE))) SRC += sc_rtc.c endif diff --git a/sys/shell/commands/sc_rpl.c b/sys/shell/commands/sc_rpl.c new file mode 100644 index 0000000000..2117a4d818 --- /dev/null +++ b/sys/shell/commands/sc_rpl.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 Oliver Hahm + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup shell_commands + * @{ + * @file sc_rpl.c + * @brief provides shell commands to manage and query RPL + * @author Oliver Hahm + * @} + */ + +#include +#include + +#include "rpl.h" + +static char addr_str[IPV6_MAX_ADDR_STR_LEN]; + +void _rpl_route_handler(int argc, char **argv) +{ + (void) argc; + (void) argv; + + rpl_routing_entry_t *rtable; + rtable = rpl_get_routing_table(); + unsigned c = 0; + puts("--------------------------------------------------------------------"); + puts("Routing table"); + printf(" %-3s %-18s %-18s %s\n", "#", "target", "next hop", "lifetime"); + puts("--------------------------------------------------------------------"); + + for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) { + if (rtable[i].used) { + c++; + printf(" %03d: %-18s ", i, ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, + (&rtable[i].address))); + printf("%-18s ", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, + (&rtable[i].next_hop))); + printf("%d\n", rtable[i].lifetime); + + } + } + puts("--------------------------------------------------------------------"); + printf(" %d routing table entries\n", c); + + puts("$"); +} diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index f1740511da..dfc48b8878 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -104,6 +104,10 @@ extern void _transceiver_set_ignore_handler(int argc, char **argv); extern void _net_if_ifconfig(int argc, char **argv); #endif +#ifdef MODULE_RPL +extern void _rpl_route_handler(int argc, char **argv); +#endif + #ifdef MODULE_MCI extern void _get_sectorsize(int argc, char **argv); extern void _get_blocksize(int argc, char **argv); @@ -172,6 +176,9 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_NET_IF {"ifconfig", "Configures a network interface", _net_if_ifconfig}, #endif +#ifdef MODULE_RPL + {"route", "Shows the routing table", _rpl_route_handler}, +#endif #ifdef MODULE_MCI {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}, {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes},