From 5999323a050c0adb7e349f80b02ab9aac5a86ec4 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 7 Jul 2017 18:05:27 +0200 Subject: [PATCH] More Shell commands --- apps/shell/shell-commands.c | 112 +++++++++++++++++- core/net/mac/tsch/tsch-log.c | 6 +- core/net/mac/tsch/tsch.h | 2 +- core/net/rpl-lite/rpl-dag.c | 5 +- core/sys/log-conf.h | 7 -- core/sys/log.c | 2 +- examples/ipv6/rpl-tsch/Makefile | 5 + examples/ipv6/rpl-tsch/node.c | 106 ++++------------- examples/ipv6/rpl-tsch/project-conf.h | 4 +- .../08-ipv6/19-cooja-rpl-tsch.csc | 4 +- .../08-ipv6/20-cooja-rpl-tsch-orchestra.csc | 4 +- .../08-ipv6/21-cooja-rpl-tsch-security.csc | 4 +- 12 files changed, 151 insertions(+), 110 deletions(-) diff --git a/apps/shell/shell-commands.c b/apps/shell/shell-commands.c index bf88c63e2..bfbd94e32 100644 --- a/apps/shell/shell-commands.c +++ b/apps/shell/shell-commands.c @@ -115,8 +115,8 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args)) } else { SHELL_OUTPUT(output, "Received ping reply from "); shell_output_6addr(output, &remote_addr); - SHELL_OUTPUT(output, ", len %u, ttl %u, delay %u ms\n", - curr_ping_datalen, curr_ping_ttl, (1000*(unsigned)(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND); + SHELL_OUTPUT(output, ", len %u, ttl %u, delay %lu ms\n", + curr_ping_datalen, curr_ping_ttl, (1000*(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND); } PT_END(pt); @@ -233,6 +233,112 @@ PT_THREAD(cmd_help(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } /*---------------------------------------------------------------------------*/ +static +PT_THREAD(ipaddr(struct pt *pt, shell_output_func output, char *args)) +{ + int i; + uint8_t state; + + PT_BEGIN(pt); + + SHELL_OUTPUT(output, "Node IPv6 addresses:\n"); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + SHELL_OUTPUT(output, "-- "); + shell_output_6addr(output, &uip_ds6_if.addr_list[i].ipaddr); + SHELL_OUTPUT(output, "\n"); + } + } + + PT_END(pt); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(routes(struct pt *pt, shell_output_func output, char *args)) +{ + uip_ds6_defrt_t *default_route; +#if RPL_WITH_NON_STORING + rpl_ns_node_t *link; +#endif /* RPL_WITH_NON_STORING */ +#if RPL_WITH_STORING + uip_ds6_route_t *route; +#endif /* RPL_WITH_STORING */ + + PT_BEGIN(pt); + + /* Our default route */ + SHELL_OUTPUT(output, "Default route:\n"); + default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose()); + if(default_route != NULL) { + SHELL_OUTPUT(output, "-- "); + shell_output_6addr(output, &default_route->ipaddr); + if(default_route->lifetime.interval != 0) { + SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval); + } else { + SHELL_OUTPUT(output, " (lifetime: infinite)\n"); + } + } else { + SHELL_OUTPUT(output, "-- None\n"); + } + +#if RPL_WITH_NON_STORING + if(rpl_ns_num_nodes() > 0) { + /* Our routing links */ + SHELL_OUTPUT(output, "Routing links (%u in total):\n", rpl_ns_num_nodes()); + link = rpl_ns_node_head(); + while(link != NULL) { + uip_ipaddr_t child_ipaddr; + uip_ipaddr_t parent_ipaddr; + rpl_ns_get_node_global_addr(&child_ipaddr, link); + rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent); + SHELL_OUTPUT(output, "-- "); + shell_output_6addr(output, &child_ipaddr); + if(link->parent == NULL) { + memset(&parent_ipaddr, 0, sizeof(parent_ipaddr)); + SHELL_OUTPUT(output, " (DODAG root)"); + } else { + SHELL_OUTPUT(output, " to "); + shell_output_6addr(output, &parent_ipaddr); + } + if(link->lifetime != RPL_ROUTE_INFINITE_LIFETIME) { + SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)link->lifetime); + } else { + SHELL_OUTPUT(output, " (lifetime: infinite)\n"); + } + link = rpl_ns_node_next(link); + } + } else { + SHELL_OUTPUT(output, "No routing links\n"); + } +#endif /* RPL_WITH_NON_STORING */ + +#if RPL_WITH_STORING + if(uip_ds6_route_num_routes() > 0) { + /* Our routing entries */ + SHELL_OUTPUT(output, "Routing entries (%u in total):\n", uip_ds6_route_num_routes()); + route = uip_ds6_route_head(); + while(route != NULL) { + SHELL_OUTPUT(output, "-- "); + shell_output_6addr(output, &route->ipaddr); + SHELL_OUTPUT(output, " via "); + shell_output_6addr(output, uip_ds6_route_nexthop(route)); + if((unsigned long)route->state.lifetime != RPL_ROUTE_INFINITE_LIFETIME) { + SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime); + } else { + SHELL_OUTPUT(output, " (lifetime: infinite)\n"); + } + route = uip_ds6_route_next(route); + } + } else { + SHELL_OUTPUT(output, "No routing entries\n"); + } +#endif /* RPL_WITH_STORING */ + + PT_END(pt); +} +/*---------------------------------------------------------------------------*/ void shell_commands_init(void) { @@ -243,8 +349,10 @@ shell_commands_init(void) /*---------------------------------------------------------------------------*/ struct shell_command_t shell_commands[] = { { "help", cmd_help, "'> help': Shows this help" }, + { "ipaddr", ipaddr, "'> ipaddr': Shows all IPv6 addresses" }, { "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." }, + { "routes", routes, "'> routes': Shows the route entries" }, { "log", cmd_log, "'> log level': Sets log level (0--4). Level 4 also enables TSCH per-slot logging." }, { NULL, NULL, NULL }, }; diff --git a/core/net/mac/tsch/tsch-log.c b/core/net/mac/tsch/tsch-log.c index 6e2e1aa49..e92311217 100644 --- a/core/net/mac/tsch/tsch-log.c +++ b/core/net/mac/tsch/tsch-log.c @@ -74,16 +74,16 @@ tsch_log_process_pending(void) int16_t log_index; /* Loop on accessing (without removing) a pending input packet */ if(log_dropped != last_log_dropped) { - printf("TSCH:! logs dropped %u\n", log_dropped); + printf("[WARN: TSCH-LOG ] logs dropped %u\n", log_dropped); last_log_dropped = log_dropped; } while((log_index = ringbufindex_peek_get(&log_ringbuf)) != -1) { struct tsch_log_t *log = &log_array[log_index]; if(log->link == NULL) { - printf("TSCH: {asn-%x.%lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); + printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); } else { struct tsch_slotframe *sf = tsch_schedule_get_slotframe_by_handle(log->link->slotframe_handle); - printf("TSCH: {asn-%x.%lx link-%u-%u-%u-%u ch-%u} ", + printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-%u-%u-%u-%u ch-%u} ", log->asn.ms1b, log->asn.ls4b, log->link->slotframe_handle, sf ? sf->size.val : 0, log->link->timeslot, log->link->channel_offset, tsch_calculate_channel(&log->asn, log->link->channel_offset)); diff --git a/core/net/mac/tsch/tsch.h b/core/net/mac/tsch/tsch.h index b56ffaf3a..d436b69af 100644 --- a/core/net/mac/tsch/tsch.h +++ b/core/net/mac/tsch/tsch.h @@ -107,7 +107,7 @@ #ifdef TSCH_CONF_JOIN_MY_PANID_ONLY #define TSCH_JOIN_MY_PANID_ONLY TSCH_CONF_JOIN_MY_PANID_ONLY #else -#define TSCH_JOIN_MY_PANID_ONLY 0 +#define TSCH_JOIN_MY_PANID_ONLY 1 #endif /* The radio polling frequency (in Hz) during association process */ diff --git a/core/net/rpl-lite/rpl-dag.c b/core/net/rpl-lite/rpl-dag.c index 9fcc9f3bc..9d9ee06ea 100644 --- a/core/net/rpl-lite/rpl-dag.c +++ b/core/net/rpl-lite/rpl-dag.c @@ -517,8 +517,6 @@ process_dio_init_dag(uip_ipaddr_t *from, rpl_dio_t *dio) #endif /* RPL_WITH_PROBING */ /* Leave the network after RPL_DELAY_BEFORE_LEAVING in case we do not find a parent */ - rpl_timers_schedule_leaving(); - LOG_INFO("initialized DAG with instance ID %u, DAG ID ", curr_instance.instance_id); LOG_INFO_6ADDR(&curr_instance.dag.dag_id); @@ -526,6 +524,9 @@ process_dio_init_dag(uip_ipaddr_t *from, rpl_dio_t *dio) LOG_ANNOTATE("#A init=%u\n", curr_instance.dag.dag_id.u8[sizeof(curr_instance.dag.dag_id) - 1]); + LOG_WARN_("just joined, no parent yet, setting timer for leaving\n"); + rpl_timers_schedule_leaving(); + return 1; } /*---------------------------------------------------------------------------*/ diff --git a/core/sys/log-conf.h b/core/sys/log-conf.h index 6c81fd8d6..6eb526d6f 100644 --- a/core/sys/log-conf.h +++ b/core/sys/log-conf.h @@ -67,13 +67,6 @@ #define LOG_WITH_ANNOTATE 0 #endif /* LOG_CONF_WITH_ANNOTATE */ -/* Log level at startup. Can be modified at runtime via log_set_level() */ -#ifdef LOG_CONF_START_LEVEL -#define LOG_START_LEVEL LOG_CONF_START_LEVEL -#else /* LOG_CONF_START_LEVEL */ -#define LOG_START_LEVEL LOG_LEVEL_DBG /* All (already compiled) logs are enabled */ -#endif /* LOG_CONF_START_LEVEL */ - /* Custom output function -- default is printf */ #ifdef LOG_CONF_OUTPUT #define LOG_OUTPUT(...) LOG_CONF_OUTPUT(__VA_ARGS__) diff --git a/core/sys/log.c b/core/sys/log.c index adfa6027f..a112943c0 100644 --- a/core/sys/log.c +++ b/core/sys/log.c @@ -53,7 +53,7 @@ #include "sys/log.h" #include "net/ip/ip64-addr.h" -int curr_log_level = LOG_START_LEVEL; +int curr_log_level = LOG_LEVEL_DBG; /*---------------------------------------------------------------------------*/ void diff --git a/examples/ipv6/rpl-tsch/Makefile b/examples/ipv6/rpl-tsch/Makefile index 3abe2ab7d..03173e2a1 100644 --- a/examples/ipv6/rpl-tsch/Makefile +++ b/examples/ipv6/rpl-tsch/Makefile @@ -7,6 +7,7 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" CONTIKI_WITH_IPV6 = 1 MAKE_WITH_ORCHESTRA ?= 0 # force Orchestra from command line MAKE_WITH_SECURITY ?= 0 # force Security from command line +MAKE_WITH_PERIODIC_ROUTES_PRINT ?= 0 # print #routes periodically, used for regression tests APPS += orchestra shell MODULES += core/net/mac/tsch @@ -19,4 +20,8 @@ ifeq ($(MAKE_WITH_SECURITY),1) CFLAGS += -DWITH_SECURITY=1 endif +ifeq ($(MAKE_WITH_PERIODIC_ROUTES_PRINT),1) +CFLAGS += -DWITH_PERIODIC_ROUTES_PRINT=1 +endif + include $(CONTIKI)/Makefile.include diff --git a/examples/ipv6/rpl-tsch/node.c b/examples/ipv6/rpl-tsch/node.c index 105555ff4..dfc386b41 100644 --- a/examples/ipv6/rpl-tsch/node.c +++ b/examples/ipv6/rpl-tsch/node.c @@ -40,8 +40,10 @@ #include "node-id.h" #include "rpl.h" #include "rpl-dag-root.h" +#include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" +#include "net/mac/tsch/tsch-log.h" #if UIP_CONF_IPV6_RPL_LITE == 0 #include "rpl-private.h" #endif /* UIP_CONF_IPV6_RPL_LITE == 0 */ @@ -59,88 +61,9 @@ PROCESS(node_process, "RPL Node"); AUTOSTART_PROCESSES(&node_process); -/*---------------------------------------------------------------------------*/ -static void -print_network_status(void) -{ - int i; - uint8_t state; - uip_ds6_defrt_t *default_route; -#if RPL_WITH_STORING - uip_ds6_route_t *route; -#endif /* RPL_WITH_STORING */ -#if RPL_WITH_NON_STORING - rpl_ns_node_t *link; -#endif /* RPL_WITH_NON_STORING */ - - PRINTF("--- Network status ---\n"); - - /* Our IPv6 addresses */ - PRINTF("- Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - PRINTF("-- "); - PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); - PRINTF("\n"); - } - } - - /* Our default route */ - PRINTF("- Default route:\n"); - default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose()); - if(default_route != NULL) { - PRINTF("-- "); - PRINT6ADDR(&default_route->ipaddr); - PRINTF(" (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval); - } else { - PRINTF("-- None\n"); - } - -#if RPL_WITH_STORING - /* Our routing entries */ - PRINTF("- Routing entries (%u in total):\n", uip_ds6_route_num_routes()); - route = uip_ds6_route_head(); - while(route != NULL) { - PRINTF("-- "); - PRINT6ADDR(&route->ipaddr); - PRINTF(" via "); - PRINT6ADDR(uip_ds6_route_nexthop(route)); - PRINTF(" (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime); - route = uip_ds6_route_next(route); - } -#endif - -#if RPL_WITH_NON_STORING - /* Our routing links */ - PRINTF("- Routing links (%u in total):\n", rpl_ns_num_nodes()); - link = rpl_ns_node_head(); - while(link != NULL) { - uip_ipaddr_t child_ipaddr; - uip_ipaddr_t parent_ipaddr; - rpl_ns_get_node_global_addr(&child_ipaddr, link); - rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent); - PRINTF("-- "); - PRINT6ADDR(&child_ipaddr); - if(link->parent == NULL) { - memset(&parent_ipaddr, 0, sizeof(parent_ipaddr)); - PRINTF(" to DODAG root "); - } else { - PRINTF(" to "); - PRINT6ADDR(&parent_ipaddr); - } - PRINTF(" (lifetime: %lu seconds)\n", (unsigned long)link->lifetime); - link = rpl_ns_node_next(link); - } -#endif - - PRINTF("----------------------\n"); -} /*---------------------------------------------------------------------------*/ PROCESS_THREAD(node_process, ev, data) { - static struct etimer et; int is_coordinator; PROCESS_BEGIN(); @@ -149,6 +72,8 @@ PROCESS_THREAD(node_process, ev, data) #if WITH_SHELL serial_shell_init(); + log_set_level(LOG_LEVEL_WARN); + tsch_log_stop(); #endif /* WITH_SHELL */ #if CONTIKI_TARGET_COOJA @@ -164,13 +89,24 @@ PROCESS_THREAD(node_process, ev, data) orchestra_init(); #endif /* WITH_ORCHESTRA */ - /* Print out routing tables every minute */ - etimer_set(&et, CLOCK_SECOND * 60); - while(1) { - print_network_status(); - PROCESS_YIELD_UNTIL(etimer_expired(&et)); - etimer_reset(&et); +#if WITH_PERIODIC_ROUTES_PRINT + { + static struct etimer et; + /* Print out routing tables every minute */ + etimer_set(&et, CLOCK_SECOND * 60); + while(1) { + /* Used for non-regression testing */ + #if RPL_WITH_STORING + PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes()); + #endif + #if RPL_WITH_NON_STORING + PRINTF("Routing links: %u\n", rpl_ns_num_nodes()); + #endif + PROCESS_YIELD_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + } } +#endif /* WITH_PERIODIC_ROUTES_PRINT */ PROCESS_END(); } diff --git a/examples/ipv6/rpl-tsch/project-conf.h b/examples/ipv6/rpl-tsch/project-conf.h index 14e604212..fa5cf2425 100644 --- a/examples/ipv6/rpl-tsch/project-conf.h +++ b/examples/ipv6/rpl-tsch/project-conf.h @@ -104,7 +104,7 @@ /* IEEE802.15.4 PANID */ #undef IEEE802154_CONF_PANID -#define IEEE802154_CONF_PANID 0xabcd +#define IEEE802154_CONF_PANID 0x81a5 /* Do not start TSCH at init, wait for NETSTACK_MAC.on() */ #undef TSCH_CONF_AUTOSTART @@ -165,6 +165,4 @@ #define FRAMER_LOG_LEVEL LOG_LEVEL_WARN #define TSCH_LOG_CONF_PER_SLOT 1 -#define LOG_CONF_START_LEVEL LOG_LEVEL_WARN - #endif /* __PROJECT_CONF_H__ */ diff --git a/regression-tests/08-ipv6/19-cooja-rpl-tsch.csc b/regression-tests/08-ipv6/19-cooja-rpl-tsch.csc index 112172828..97f4dd798 100644 --- a/regression-tests/08-ipv6/19-cooja-rpl-tsch.csc +++ b/regression-tests/08-ipv6/19-cooja-rpl-tsch.csc @@ -26,7 +26,7 @@ Cooja Mote Type #mtype1 [CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c make TARGET=cooja clean -make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0 +make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0 MAKE_WITH_PERIODIC_ROUTES_PRINT=1 org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.Battery org.contikios.cooja.contikimote.interfaces.ContikiVib @@ -278,7 +278,7 @@ log.log("Waiting for routing links to fill\n"); while(true) {; WAIT_UNTIL(id == 1 && msg.contains("Routing links")); log.log(msg + "\n"); - if(msg.contains("Routing links (9 in total):")) { + if(msg.contains("Routing links: 9")) { log.testOK(); /* Report test success and quit */ } YIELD(); diff --git a/regression-tests/08-ipv6/20-cooja-rpl-tsch-orchestra.csc b/regression-tests/08-ipv6/20-cooja-rpl-tsch-orchestra.csc index 192617b23..676d86366 100644 --- a/regression-tests/08-ipv6/20-cooja-rpl-tsch-orchestra.csc +++ b/regression-tests/08-ipv6/20-cooja-rpl-tsch-orchestra.csc @@ -26,7 +26,7 @@ Cooja Mote Type #mtype11 [CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c make TARGET=cooja clean -make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0 +make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0 MAKE_WITH_PERIODIC_ROUTES_PRINT=1 [CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.mtype1 org.contikios.cooja.interfaces.Position @@ -280,7 +280,7 @@ log.log("Waiting for routing links to fill\n"); while(true) {; WAIT_UNTIL(id == 1 && msg.contains("Routing links")); log.log(msg + "\n"); - if(msg.contains("Routing links (9 in total):")) { + if(msg.contains("Routing links: 9")) { log.testOK(); /* Report test success and quit */ } YIELD(); diff --git a/regression-tests/08-ipv6/21-cooja-rpl-tsch-security.csc b/regression-tests/08-ipv6/21-cooja-rpl-tsch-security.csc index e3e192297..ffa370b01 100644 --- a/regression-tests/08-ipv6/21-cooja-rpl-tsch-security.csc +++ b/regression-tests/08-ipv6/21-cooja-rpl-tsch-security.csc @@ -26,7 +26,7 @@ Cooja Mote Type #mtype11 [CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c make TARGET=cooja clean -make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1 +make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1 MAKE_WITH_PERIODIC_ROUTES_PRINT=1 org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.Battery org.contikios.cooja.contikimote.interfaces.ContikiVib @@ -278,7 +278,7 @@ log.log("Waiting for routing links to fill\n"); while(true) {; WAIT_UNTIL(id == 1 && msg.contains("Routing links")); log.log(msg + "\n"); - if(msg.contains("Routing links (9 in total):")) { + if(msg.contains("Routing links: 9")) { log.testOK(); /* Report test success and quit */ } YIELD();