jn516x examples: print out network state periodically

This commit is contained in:
Simon Duquennoy 2015-12-02 10:26:06 +01:00
parent 3ff44f77b9
commit bef32c20fb
4 changed files with 69 additions and 3 deletions

View File

@ -93,6 +93,14 @@ PROCESS_THREAD(border_router_process, ev, data)
rpl_tools_init(&prefix);
/* 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);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -58,6 +58,7 @@ AUTOSTART_PROCESSES(&node_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(node_process, ev, data)
{
static struct etimer et;
PROCESS_BEGIN();
/* 3 possible roles:
@ -71,8 +72,6 @@ PROCESS_THREAD(node_process, ev, data)
#if CONFIG_VIA_BUTTON
{
#define CONFIG_WAIT_TIME 10
static struct etimer et;
SENSORS_ACTIVATE(button_sensor);
etimer_set(&et, CLOCK_SECOND * CONFIG_WAIT_TIME);
@ -103,6 +102,16 @@ PROCESS_THREAD(node_process, ev, data)
rpl_tools_init(&prefix);
} else {
rpl_tools_init(NULL);
} PROCESS_END();
}
/* 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);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -43,6 +43,54 @@
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
/*---------------------------------------------------------------------------*/
void
print_network_status(void)
{
int i;
uint8_t state;
uip_ds6_defrt_t *default_route;
uip_ds6_route_t *route;
PRINTA("--- Network status ---\n");
/* Our IPv6 addresses */
PRINTA("- 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)) {
PRINTA("-- ");
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
PRINTA("\n");
}
}
/* Our default route */
PRINTA("- Default route:\n");
default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose());
if(default_route != NULL) {
PRINTA("-- ");
uip_debug_ipaddr_print(&default_route->ipaddr);;
PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval);
} else {
PRINTA("-- None\n");
}
/* Our routing entries */
PRINTA("- Routing entries (%u in total):\n", uip_ds6_route_num_routes());
route = uip_ds6_route_head();
while(route != NULL) {
PRINTA("-- ");
uip_debug_ipaddr_print(&route->ipaddr);
PRINTA(" via ");
uip_debug_ipaddr_print(uip_ds6_route_nexthop(route));
PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime);
route = uip_ds6_route_next(route);
}
PRINTA("----------------------\n");
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)

View File

@ -33,3 +33,4 @@
*/
void rpl_tools_init(uip_ipaddr_t *br_prefix);
void print_network_status(void);