Commit 3f392904 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix and simplify route timeout and gc.

parent 849a1f89
...@@ -724,20 +724,15 @@ expire_routes(void) ...@@ -724,20 +724,15 @@ expire_routes(void)
while(i < numroutes) { while(i < numroutes) {
struct route *route = &routes[i]; struct route *route = &routes[i];
if(route->blackhole_time > 0 && if(route->time < now.tv_sec - route_gc_delay) {
route->blackhole_time < now.tv_sec - 65) {
flush_route(route); flush_route(route);
continue; continue;
} }
if(route->time < now.tv_sec - 120) update_route_metric(route);
update_route(route->dest->address, ((route->seqno + 1) & 0xFF),
INFINITY, route->nexthop, NULL, 0);
else
update_route_metric(route);
if(route->installed && route->refmetric < INFINITY) { if(route->installed && route->refmetric < INFINITY) {
if(route->time <= now.tv_sec - 70) if(route->time < now.tv_sec - MAX(5, route_timeout_delay - 25))
send_unicast_request(route->nexthop, route->dest); send_unicast_request(route->nexthop, route->dest);
} }
i++; i++;
......
...@@ -38,6 +38,8 @@ THE SOFTWARE. ...@@ -38,6 +38,8 @@ THE SOFTWARE.
struct route routes[MAXROUTES]; struct route routes[MAXROUTES];
int numroutes = 0; int numroutes = 0;
int kernel_metric = 0; int kernel_metric = 0;
int route_timeout_delay = 50;
int route_gc_delay = 95;
struct route * struct route *
find_route(const unsigned char *dest, struct neighbour *nexthop) find_route(const unsigned char *dest, struct neighbour *nexthop)
...@@ -254,18 +256,33 @@ void ...@@ -254,18 +256,33 @@ void
update_route_metric(struct route *route) update_route_metric(struct route *route)
{ {
int oldmetric; int oldmetric;
int newmetric;
oldmetric = route->metric; oldmetric = route->metric;
change_route_metric(route, if(route->time < now.tv_sec - route_timeout_delay) {
MIN(route->refmetric + neighbour_cost(route->nexthop), if(oldmetric < INFINITY) {
INFINITY)); route->refmetric = INFINITY;
route->seqno = (route->dest->seqno + 1) & 0xFF;
}
newmetric = INFINITY;
} else {
newmetric = MIN(route->refmetric + neighbour_cost(route->nexthop),
INFINITY);
}
change_route_metric(route, newmetric);
if(route->installed) { if(route->installed) {
struct route *better_route; if(newmetric > oldmetric) {
better_route = find_best_route(route->dest); struct route *better_route;
if(better_route && better_route->metric <= route->metric - 96) better_route = find_best_route(route->dest);
consider_route(better_route); if(better_route && better_route->metric <= route->metric - 96)
else consider_route(better_route);
send_triggered_update(route, oldmetric); else
send_triggered_update(route, oldmetric);
} else {
send_triggered_update(route, oldmetric);
}
} else { } else {
consider_route(route); consider_route(route);
} }
...@@ -306,13 +323,8 @@ update_route(const unsigned char *d, int seqno, int refmetric, ...@@ -306,13 +323,8 @@ update_route(const unsigned char *d, int seqno, int refmetric,
oldseqno = route->seqno; oldseqno = route->seqno;
oldmetric = route->metric; oldmetric = route->metric;
route->time = now.tv_sec; route->time = now.tv_sec;
if(refmetric < INFINITY) { if(route->refmetric >= INFINITY)
route->blackhole_time = 0; route->origtime = now.tv_sec;
if(route->refmetric >= INFINITY)
route->origtime = now.tv_sec;
} else if(route->blackhole_time <= 0) {
route->blackhole_time = now.tv_sec;
}
route->seqno = seqno; route->seqno = seqno;
route->refmetric = refmetric; route->refmetric = refmetric;
change_route_metric(route, metric); change_route_metric(route, metric);
...@@ -347,7 +359,6 @@ update_route(const unsigned char *d, int seqno, int refmetric, ...@@ -347,7 +359,6 @@ update_route(const unsigned char *d, int seqno, int refmetric,
route->nexthop = nexthop; route->nexthop = nexthop;
route->time = now.tv_sec; route->time = now.tv_sec;
route->origtime = now.tv_sec; route->origtime = now.tv_sec;
route->blackhole_time = 0;
route->installed = 0; route->installed = 0;
numroutes++; numroutes++;
for(i = 0; i < numpxroutes; i++) for(i = 0; i < numpxroutes; i++)
......
...@@ -30,13 +30,14 @@ struct route { ...@@ -30,13 +30,14 @@ struct route {
struct neighbour *nexthop; struct neighbour *nexthop;
int time; int time;
int origtime; int origtime;
int blackhole_time;
int installed; int installed;
}; };
extern struct route routes[MAXROUTES]; extern struct route routes[MAXROUTES];
extern int numroutes; extern int numroutes;
extern int kernel_metric; extern int kernel_metric;
extern int route_timeout_delay;
extern int route_gc_delay;
struct route *find_route(const unsigned char *dest, struct neighbour *nexthop); struct route *find_route(const unsigned char *dest, struct neighbour *nexthop);
struct route *find_installed_route(struct destination *dest); struct route *find_installed_route(struct destination *dest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment