diff --git a/os/net/routing/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c index 8afa2440f..bd0632778 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -368,6 +368,8 @@ rpl_neighbor_select_best(void) #if RPL_WITH_PROBING if(best != NULL) { if(rpl_neighbor_is_fresh(best)) { + /* Unschedule any already scheduled urgent probing */ + curr_instance.dag.urgent_probing_target = NULL; /* Return best if it is fresh */ return best; } else { @@ -380,7 +382,7 @@ rpl_neighbor_select_best(void) LOG_WARN_6ADDR(rpl_neighbor_get_ipaddr(best)); LOG_WARN_("\n"); curr_instance.dag.urgent_probing_target = best; - rpl_schedule_probing(); + rpl_schedule_probing_now(); } /* The best is our preferred parent. It is not fresh but used to be, diff --git a/os/net/routing/rpl-lite/rpl-timers.c b/os/net/routing/rpl-lite/rpl-timers.c index 5b4ab8faa..6fb00ca17 100644 --- a/os/net/routing/rpl-lite/rpl-timers.c +++ b/os/net/routing/rpl-lite/rpl-timers.c @@ -342,13 +342,7 @@ handle_dao_ack_timer(void *ptr) clock_time_t get_probing_delay(void) { - if(curr_instance.used && curr_instance.dag.urgent_probing_target != NULL) { - /* Urgent probing needed (to find out if a neighbor may become preferred parent) */ - return random_rand() % (CLOCK_SECOND * 4); - } else { - /* Else, use normal probing interval */ - return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); - } + return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); } /*---------------------------------------------------------------------------*/ rpl_nbr_t * @@ -440,7 +434,7 @@ handle_probing_timer(void *ptr) ); /* Send probe, e.g. unicast DIO or DIS */ RPL_PROBING_SEND_FUNC(target_ipaddr); - curr_instance.dag.urgent_probing_target = NULL; + /* urgent_probing_target will be NULLed in the packet_sent callback */ } else { LOG_INFO("no neighbor needs probing\n"); } @@ -457,6 +451,15 @@ rpl_schedule_probing(void) handle_probing_timer, NULL); } } +/*---------------------------------------------------------------------------*/ +void +rpl_schedule_probing_now(void) +{ + if(curr_instance.used) { + ctimer_set(&curr_instance.dag.probing_timer, + random_rand() % (CLOCK_SECOND * 4), handle_probing_timer, NULL); + } +} #endif /* RPL_WITH_PROBING */ /*---------------------------------------------------------------------------*/ /*------------------------------- Leaving-- -------------------------------- */ diff --git a/os/net/routing/rpl-lite/rpl-timers.h b/os/net/routing/rpl-lite/rpl-timers.h index 884a55696..e153858fc 100644 --- a/os/net/routing/rpl-lite/rpl-timers.h +++ b/os/net/routing/rpl-lite/rpl-timers.h @@ -104,6 +104,11 @@ void rpl_timers_schedule_dao_ack(uip_ipaddr_t *target, uint16_t sequence); */ void rpl_schedule_probing(void); +/** + * Schedule probing within a few seconds +*/ +void rpl_schedule_probing_now(void); + /** * Schedule a state update ASAP. Useful to force an update from a context * where updating directly would be unsafe. diff --git a/os/net/routing/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c index fd93b40e8..47ffc5387 100644 --- a/os/net/routing/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -99,6 +99,11 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx) if(curr_instance.used == 1 ) { rpl_nbr_t *nbr = rpl_neighbor_get_from_lladdr((uip_lladdr_t *)addr); if(nbr != NULL) { + /* If this is the neighbor we were probing urgently, mark urgent + probing as done */ + if(curr_instance.dag.urgent_probing_target == nbr) { + curr_instance.dag.urgent_probing_target = NULL; + } /* Link stats were updated, and we need to update our internal state. Updating from here is unsafe; postpone */ LOG_INFO("packet sent to ");