From 3bbd6a00a9c3c6d6b059502d5dfb44f1e3c48983 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Mon, 25 Oct 2010 11:58:07 +0000 Subject: [PATCH] Replace old neighbors according to an LRU policy when a new neighbor needs to be added --- core/net/uip-ds6.c | 29 +++++++++++++++++++++++++++++ core/net/uip-ds6.h | 1 + 2 files changed, 30 insertions(+) diff --git a/core/net/uip-ds6.c b/core/net/uip-ds6.c index 7c069d489..a258c8fb1 100755 --- a/core/net/uip-ds6.c +++ b/core/net/uip-ds6.c @@ -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; } diff --git a/core/net/uip-ds6.h b/core/net/uip-ds6.h index 43d2cb209..7bfff119e 100755 --- a/core/net/uip-ds6.h +++ b/core/net/uip-ds6.h @@ -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;