From 72f558fb6e8a46da1d0c59537516bc1110c6f62f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 9 May 2018 14:39:14 -0700 Subject: [PATCH] RPL Classic: make sure no more than one probe gets in queue at any given time --- os/net/routing/rpl-classic/rpl-dag.c | 4 +++- os/net/routing/rpl-classic/rpl-private.h | 1 + os/net/routing/rpl-classic/rpl-timers.c | 17 ++++++++--------- os/net/routing/rpl-classic/rpl.c | 5 +++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index 742ef16c4..670a54f3f 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -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); diff --git a/os/net/routing/rpl-classic/rpl-private.h b/os/net/routing/rpl-classic/rpl-private.h index 1259fffeb..5a01c538a 100644 --- a/os/net/routing/rpl-classic/rpl-private.h +++ b/os/net/routing/rpl-classic/rpl-private.h @@ -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); diff --git a/os/net/routing/rpl-classic/rpl-timers.c b/os/net/routing/rpl-classic/rpl-timers.c index c812a8897..97233f574 100644 --- a/os/net/routing/rpl-classic/rpl-timers.c +++ b/os/net/routing/rpl-classic/rpl-timers.c @@ -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 */ /** @}*/ diff --git a/os/net/routing/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c index b1905d611..ecbcdc158 100644 --- a/os/net/routing/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -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;