Merge pull request #504 from simonduq/fix/rpl-urgent-probing

RPL urgent probing fix
This commit is contained in:
Simon Duquennoy 2018-05-12 13:14:23 +02:00 committed by GitHub
commit e3e081ae31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 19 deletions

View File

@ -908,6 +908,8 @@ rpl_select_parent(rpl_dag_t *dag)
#if RPL_WITH_PROBING
if(rpl_parent_is_fresh(best)) {
rpl_set_preferred_parent(dag, best);
/* Unschedule any already scheduled urgent probing */
dag->instance->urgent_probing_target = NULL;
} else {
/* The best is not fresh. Look for the best fresh now. */
rpl_parent_t *best_fresh = best_parent(dag, 1);
@ -920,7 +922,7 @@ rpl_select_parent(rpl_dag_t *dag)
}
/* Probe the best parent shortly in order to get a fresh estimate */
dag->instance->urgent_probing_target = best;
rpl_schedule_probing(dag->instance);
rpl_schedule_probing_now(dag->instance);
}
#else /* RPL_WITH_PROBING */
rpl_set_preferred_parent(dag, best);

View File

@ -341,6 +341,7 @@ void rpl_schedule_dao_immediately(rpl_instance_t *);
void rpl_schedule_unicast_dio_immediately(rpl_instance_t *instance);
void rpl_cancel_dao(rpl_instance_t *instance);
void rpl_schedule_probing(rpl_instance_t *instance);
void rpl_schedule_probing_now(rpl_instance_t *instance);
void rpl_reset_dio_timer(rpl_instance_t *);
void rpl_reset_periodic_timer(void);

View File

@ -380,14 +380,7 @@ rpl_schedule_unicast_dio_immediately(rpl_instance_t *instance)
clock_time_t
get_probing_delay(rpl_dag_t *dag)
{
if(dag != NULL && dag->instance != NULL
&& dag->instance->urgent_probing_target != NULL) {
/* Urgent probing needed (to find out if a neighbor may become preferred parent) */
return random_rand() % (CLOCK_SECOND * 10);
} 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_parent_t *
@ -494,7 +487,6 @@ handle_probing_timer(void *ptr)
);
/* Send probe, e.g. unicast DIO or DIS */
RPL_PROBING_SEND_FUNC(instance, target_ipaddr);
instance->urgent_probing_target = NULL;
}
/* Schedule next probing */
@ -511,5 +503,12 @@ rpl_schedule_probing(rpl_instance_t *instance)
ctimer_set(&instance->probing_timer, RPL_PROBING_DELAY_FUNC(instance->current_dag),
handle_probing_timer, instance);
}
/*---------------------------------------------------------------------------*/
void
rpl_schedule_probing_now(rpl_instance_t *instance)
{
ctimer_set(&instance->probing_timer, random_rand() % (CLOCK_SECOND * 4),
handle_probing_timer, instance);
}
#endif /* RPL_WITH_PROBING */
/** @}*/

View File

@ -266,6 +266,11 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx)
if(instance->used == 1 ) {
parent = rpl_find_parent_any_dag(instance, &ipaddr);
if(parent != NULL) {
/* If this is the neighbor we were probing urgently, mark urgent
probing as done */
if(instance->urgent_probing_target == parent) {
instance->urgent_probing_target = NULL;
}
/* Trigger DAG rank recalculation. */
PRINTF("RPL: rpl_link_callback triggering update\n");
parent->flags |= RPL_PARENT_FLAG_UPDATED;

View File

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

View File

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

View File

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

View File

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