Modified the default RPL probing selection process. Will now probe the least recently updated parent from time to time

This commit is contained in:
Simon Duquennoy 2015-05-08 10:19:14 +02:00
parent 47ba4c0c4b
commit 2dd182f4a8

View File

@ -331,18 +331,17 @@ rpl_cancel_dao(rpl_instance_t *instance)
static rpl_parent_t * static rpl_parent_t *
get_probing_target(rpl_dag_t *dag) get_probing_target(rpl_dag_t *dag)
{ {
/* Returns the next probing target. The current implementation looks for the /* Returns the next probing target. The current implementation probes the current
* best parent to which we have not transmitted since 2 * RPL_PROBING_INTERVAL. * preferred parent if we have not updated its link for 2 * RPL_PROBING_INTERVAL.
* This will mostly select the preferred and second best parents. Probing the * Otherwise, it picks at random between:
* second best parent is important: if the link is good, RPL might choose to * (1) selecting the best parent not updated for 2 * RPL_PROBING_INTERVAL
* switch to it. If the link is bad, the second best parent will decrease in * (2) selecting the least recently updated parent
* ranking, and another parent will be probed next time. */ */
rpl_parent_t *p; rpl_parent_t *p;
rpl_parent_t *probing_target; rpl_parent_t *probing_target = NULL;
rpl_rank_t probing_target_rank; rpl_rank_t probing_target_rank = INFINITE_RANK;
/* Look for a parent we have not sent to since 2 * RPL_PROBING_INTERVAL, /* min_last_tx is the clock time (2 * RPL_PROBING_INTERVAL) in the past */
* e.g. with last_tx_time earlier than min_last_tx */
clock_time_t min_last_tx = clock_time(); clock_time_t min_last_tx = clock_time();
min_last_tx = min_last_tx > 2 * RPL_PROBING_INTERVAL ? min_last_tx - 2 * RPL_PROBING_INTERVAL : 1; min_last_tx = min_last_tx > 2 * RPL_PROBING_INTERVAL ? min_last_tx - 2 * RPL_PROBING_INTERVAL : 1;
@ -357,27 +356,35 @@ get_probing_target(rpl_dag_t *dag)
return dag->preferred_parent; return dag->preferred_parent;
} }
/* Look for the best parent that needs probing. */ if((random_rand() % 2) == 0) {
probing_target = NULL; /* With 1/2 probability: probe best parent not updated for 2 * RPL_PROBING_INTERVAL */
probing_target_rank = INFINITE_RANK;
p = nbr_table_head(rpl_parents); p = nbr_table_head(rpl_parents);
while(p != NULL) { while(p != NULL) {
if(p->dag == dag && p->last_tx_time < min_last_tx) { if(p->dag == dag && p->last_tx_time < min_last_tx) {
rpl_rank_t p_rank = dag->instance->of->calculate_rank(p, 0);
/* p is in our dag and needs probing */ /* p is in our dag and needs probing */
if(probing_target == NULL) { rpl_rank_t p_rank = dag->instance->of->calculate_rank(p, 0);
if(probing_target == NULL
|| p_rank < probing_target_rank) {
probing_target = p; probing_target = p;
probing_target_rank = p_rank; probing_target_rank = p_rank;
} else {
if(p_rank < probing_target_rank) {
/* Found better candidate */
probing_target = p;
probing_target_rank = p_rank;
}
} }
} }
p = nbr_table_next(rpl_parents, p); p = nbr_table_next(rpl_parents, p);
} }
} else {
/* With 1/2 probability: probe the least recently updated parent */
p = nbr_table_head(rpl_parents);
while(p != NULL) {
if(p->dag == dag) {
if(probing_target == NULL
|| p->last_tx_time < probing_target->last_tx_time) {
probing_target = p;
}
}
p = nbr_table_next(rpl_parents, p);
}
}
return probing_target; return probing_target;
} }