Remove only the worst parent if the table is full when processing a DIO.

This commit is contained in:
nvt 2011-02-13 21:33:47 +01:00
parent 432928d000
commit 5ec2f19dc9

View file

@ -52,7 +52,7 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#define DEBUG DEBUG_NONE #define DEBUG DEBUG_PRINT
#include "net/uip-debug.h" #include "net/uip-debug.h"
#include "net/neighbor-info.h" #include "net/neighbor-info.h"
@ -119,6 +119,22 @@ remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
} }
} }
/************************************************************************/ /************************************************************************/
static void
remove_worst_parent(rpl_dag_t *dag)
{
rpl_parent_t *p, *worst;
PRINTF("RPL: Removing the worst parent\n");
worst = NULL;
for(p = list_head(dag->parents); p != NULL; p = p->next) {
if(worst == NULL || p->rank > worst->rank) {
worst = p;
}
}
rpl_remove_parent(dag, worst);
}
/************************************************************************/
static int static int
should_send_dao(rpl_dag_t *dag, rpl_dio_t *dio, rpl_parent_t *p) should_send_dao(rpl_dag_t *dag, rpl_dio_t *dio, rpl_parent_t *p)
{ {
@ -679,11 +695,10 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
*/ */
p = rpl_find_parent(dag, from); p = rpl_find_parent(dag, from);
if(p == NULL && if(p == NULL) {
DAG_RANK(dio->rank, dag) <= DAG_RANK(dag->preferred_parent->rank, dag)) {
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) { if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) {
/* Try to make room for a new parent. */ /* Make room for a new parent. */
remove_parents(dag, dag->preferred_parent->rank + dag->min_hoprankinc); remove_worst_parent(dag);
} }
/* Add the DIO sender as a candidate parent. */ /* Add the DIO sender as a candidate parent. */