Replace old neighbors according to an LRU policy when a new neighbor needs to be added

This commit is contained in:
adamdunkels 2010-10-25 11:58:07 +00:00
parent 5d8636d1f8
commit 3bbd6a00a9
2 changed files with 30 additions and 0 deletions

View file

@ -313,8 +313,37 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
PRINTLLADDR((&(locnbr->lladdr)));
PRINTF("state %u\n", state);
NEIGHBOR_STATE_CHANGED(locnbr);
locnbr->last_lookup = clock_time();
return locnbr;
} else {
/* We did not find any empty slot on the neighbor list, so we need
to remove one old entry to make room. */
{
uip_ds6_nbr_t *n, *oldest;
clock_time_t oldest_time;
oldest = NULL;
oldest_time = 0 - 1UL;
least_number = 0 - 1UL;
for(n = uip_ds6_nbr_cache;
n < &uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
n++) {
if(n->isused) {
if(n->last_lookup < oldest_time) {
oldest = n;
oldest_time = n->last_lookup;
}
}
}
if(oldest != NULL) {
uip_ds6_nbr_rm(oldest);
return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
}
}
}
PRINTF("uip_ds6_nbr_add drop\n");
return NULL;
}

View file

@ -162,6 +162,7 @@ typedef struct uip_ds6_nbr {
struct stimer reachable;
struct stimer sendns;
uint8_t nscount;
clock_time_t last_lookup;
#if UIP_CONF_IPV6_QUEUE_PKT
uint8_t queue_buf[UIP_BUFSIZE - UIP_LLH_LEN];
uint8_t queue_buf_len;