Make sure we don't remove the preferred parent
This commit is contained in:
parent
20bf23cf06
commit
db37e38156
1 changed files with 11 additions and 5 deletions
|
@ -120,19 +120,25 @@ remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
|
||||||
}
|
}
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
static void
|
static void
|
||||||
remove_worst_parent(rpl_dag_t *dag)
|
remove_worst_parent(rpl_dag_t *dag, rpl_rank_t min_worst_rank)
|
||||||
{
|
{
|
||||||
rpl_parent_t *p, *worst;
|
rpl_parent_t *p, *worst;
|
||||||
|
|
||||||
PRINTF("RPL: Removing the worst parent\n");
|
PRINTF("RPL: Removing the worst parent\n");
|
||||||
|
|
||||||
|
/* Find the parent with the highest rank. */
|
||||||
worst = NULL;
|
worst = NULL;
|
||||||
for(p = list_head(dag->parents); p != NULL; p = p->next) {
|
for(p = list_head(dag->parents); p != NULL; p = list_item_next(p)) {
|
||||||
if(worst == NULL || p->rank > worst->rank) {
|
if(p != dag->preferred_parent &&
|
||||||
|
(worst == NULL || p->rank > worst->rank)) {
|
||||||
worst = p;
|
worst = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rpl_remove_parent(dag, worst);
|
/* Remove the neighbor if its rank is worse than the minimum worst
|
||||||
|
rank. */
|
||||||
|
if(worst != NULL && worst->rank > min_worst_rank) {
|
||||||
|
rpl_remove_parent(dag, worst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
static int
|
static int
|
||||||
|
@ -698,7 +704,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) {
|
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) {
|
||||||
/* Make room for a new parent. */
|
/* Make room for a new parent. */
|
||||||
remove_worst_parent(dag);
|
remove_worst_parent(dag, dio->rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the DIO sender as a candidate parent. */
|
/* Add the DIO sender as a candidate parent. */
|
||||||
|
|
Loading…
Reference in a new issue