More Shell commands

This commit is contained in:
Simon Duquennoy 2017-07-07 18:05:27 +02:00
parent 03f76a9058
commit 5999323a05
12 changed files with 151 additions and 110 deletions

View File

@ -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 },
};

View File

@ -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));

View File

@ -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 */

View File

@ -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;
}
/*---------------------------------------------------------------------------*/

View File

@ -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__)

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -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__ */

View File

@ -26,7 +26,7 @@
<description>Cooja Mote Type #mtype1</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
<commands EXPORT="discard">make TARGET=cooja clean
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</commands>
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0 MAKE_WITH_PERIODIC_ROUTES_PRINT=1</commands>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
@ -278,7 +278,7 @@ log.log("Waiting for routing links to fill\n");&#xD;
while(true) {;&#xD;
WAIT_UNTIL(id == 1 &amp;&amp; msg.contains("Routing links"));&#xD;
log.log(msg + "\n");&#xD;
if(msg.contains("Routing links (9 in total):")) {&#xD;
if(msg.contains("Routing links: 9")) {&#xD;
log.testOK(); /* Report test success and quit */&#xD;
}&#xD;
YIELD();&#xD;

View File

@ -26,7 +26,7 @@
<description>Cooja Mote Type #mtype11</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
<commands EXPORT="discard">make TARGET=cooja clean
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</commands>
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0 MAKE_WITH_PERIODIC_ROUTES_PRINT=1</commands>
<firmware
EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.mtype1</firmware>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
@ -280,7 +280,7 @@ log.log("Waiting for routing links to fill\n");&#xD;
while(true) {;&#xD;
WAIT_UNTIL(id == 1 &amp;&amp; msg.contains("Routing links"));&#xD;
log.log(msg + "\n");&#xD;
if(msg.contains("Routing links (9 in total):")) {&#xD;
if(msg.contains("Routing links: 9")) {&#xD;
log.testOK(); /* Report test success and quit */&#xD;
}&#xD;
YIELD();&#xD;

View File

@ -26,7 +26,7 @@
<description>Cooja Mote Type #mtype11</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
<commands EXPORT="discard">make TARGET=cooja clean
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</commands>
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1 MAKE_WITH_PERIODIC_ROUTES_PRINT=1</commands>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
@ -278,7 +278,7 @@ log.log("Waiting for routing links to fill\n");&#xD;
while(true) {;&#xD;
WAIT_UNTIL(id == 1 &amp;&amp; msg.contains("Routing links"));&#xD;
log.log(msg + "\n");&#xD;
if(msg.contains("Routing links (9 in total):")) {&#xD;
if(msg.contains("Routing links: 9")) {&#xD;
log.testOK(); /* Report test success and quit */&#xD;
}&#xD;
YIELD();&#xD;