From db37e381566e0252c5cf06d344ba4d0ab157b284 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Mon, 14 Feb 2011 23:01:11 +0100 Subject: [PATCH] Make sure we don't remove the preferred parent --- core/net/rpl/rpl-dag.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/net/rpl/rpl-dag.c b/core/net/rpl/rpl-dag.c index c5c6e0fa8..ec2bc0f9c 100644 --- a/core/net/rpl/rpl-dag.c +++ b/core/net/rpl/rpl-dag.c @@ -120,19 +120,25 @@ remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank) } /************************************************************************/ 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; PRINTF("RPL: Removing the worst parent\n"); + /* Find the parent with the highest rank. */ worst = NULL; - for(p = list_head(dag->parents); p != NULL; p = p->next) { - if(worst == NULL || p->rank > worst->rank) { + for(p = list_head(dag->parents); p != NULL; p = list_item_next(p)) { + if(p != dag->preferred_parent && + (worst == NULL || p->rank > worst->rank)) { 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 @@ -698,7 +704,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) if(p == NULL) { if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) { /* Make room for a new parent. */ - remove_worst_parent(dag); + remove_worst_parent(dag, dio->rank); } /* Add the DIO sender as a candidate parent. */