Merge pull request #1132 from tpetry/master

LRU deletion strategy for rime routes
This commit is contained in:
Nicolas Tsiftes 2015-09-24 14:27:14 +02:00
commit 3fcff231ec

View file

@ -121,7 +121,7 @@ int
route_add(const linkaddr_t *dest, const linkaddr_t *nexthop,
uint8_t cost, uint8_t seqno)
{
struct route_entry *e;
struct route_entry *e, *oldest = NULL;
/* Avoid inserting duplicate entries. */
e = route_lookup(dest);
@ -131,8 +131,14 @@ route_add(const linkaddr_t *dest, const linkaddr_t *nexthop,
/* Allocate a new entry or reuse the oldest entry with highest cost. */
e = memb_alloc(&route_mem);
if(e == NULL) {
/* Remove oldest entry. XXX */
e = list_chop(route_table);
/* Remove oldest entry. */
for(e = list_head(route_table); e != NULL; e = list_item_next(e)) {
if(oldest == NULL || e->time >= oldest->time) {
oldest = e;
}
}
e = oldest;
list_remove(route_table, e);
PRINTF("route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
e->dest.u8[0], e->dest.u8[1],
e->nexthop.u8[0], e->nexthop.u8[1],