Commit 9a99f954 authored by Baptiste Jonglez's avatar Baptiste Jonglez

Compute the moving exponential average of the RTT

parent 675dc627
...@@ -58,6 +58,10 @@ struct timeval now; ...@@ -58,6 +58,10 @@ struct timeval now;
unsigned char myid[8]; unsigned char myid[8];
int debug = 0; int debug = 0;
/* A higher value means we forget old RTT samples faster. Must be
between 1 and 256, inclusive. */
unsigned int rtt_exponential_decay = 42;
int link_detect = 0; int link_detect = 0;
int all_wireless = 0; int all_wireless = 0;
int default_wireless_hello_interval = -1; int default_wireless_hello_interval = -1;
......
...@@ -90,6 +90,7 @@ extern int do_daemonise; ...@@ -90,6 +90,7 @@ extern int do_daemonise;
extern const char *logfile, *pidfile, *state_file; extern const char *logfile, *pidfile, *state_file;
extern int link_detect; extern int link_detect;
extern int all_wireless; extern int all_wireless;
extern unsigned int rtt_exponential_decay;
extern unsigned char myid[8]; extern unsigned char myid[8];
......
...@@ -610,6 +610,16 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -610,6 +610,16 @@ parse_packet(const unsigned char *from, struct interface *ifp,
rtt = local_waiting_us - remote_waiting_us; rtt = local_waiting_us - remote_waiting_us;
debugf("RTT to %s on %s sample result: %d us.\n", debugf("RTT to %s on %s sample result: %d us.\n",
format_address(from), ifp->name, rtt); format_address(from), ifp->name, rtt);
if (valid_rtt(neigh))
/* Running exponential average. */
neigh->rtt = (rtt_exponential_decay * MAX(rtt, 0)
+ (256 - rtt_exponential_decay) * neigh->rtt) / 256;
else
/* We prefer to be conservative with new neighbours
(higher RTT) */
neigh->rtt = MAX(2*rtt, 0);
neigh->rtt_time = now;
} }
return; return;
} }
......
...@@ -99,6 +99,8 @@ find_neighbour(const unsigned char *address, struct interface *ifp) ...@@ -99,6 +99,8 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
neigh->ihu_interval = 0; neigh->ihu_interval = 0;
neigh->hello_send_us = 0; neigh->hello_send_us = 0;
neigh->hello_rtt_receive_time = zero; neigh->hello_rtt_receive_time = zero;
neigh->rtt = 0;
neigh->rtt_time = zero;
neigh->ifp = ifp; neigh->ifp = ifp;
neigh->next = neighs; neigh->next = neighs;
neighs = neigh; neighs = neigh;
...@@ -325,3 +327,9 @@ neighbour_cost(struct neighbour *neigh) ...@@ -325,3 +327,9 @@ neighbour_cost(struct neighbour *neigh)
return MIN((a * b + 128) >> 8, INFINITY); return MIN((a * b + 128) >> 8, INFINITY);
} }
} }
int
valid_rtt(struct neighbour *neigh)
{
return (timeval_minus_msec(&now, &neigh->rtt_time) < 180000) ? 1 : 0;
}
...@@ -36,6 +36,8 @@ struct neighbour { ...@@ -36,6 +36,8 @@ struct neighbour {
according to remote clock. */ according to remote clock. */
unsigned int hello_send_us; unsigned int hello_send_us;
struct timeval hello_rtt_receive_time; struct timeval hello_rtt_receive_time;
unsigned int rtt;
struct timeval rtt_time;
struct interface *ifp; struct interface *ifp;
}; };
...@@ -53,3 +55,4 @@ unsigned check_neighbours(void); ...@@ -53,3 +55,4 @@ unsigned check_neighbours(void);
unsigned neighbour_txcost(struct neighbour *neigh); unsigned neighbour_txcost(struct neighbour *neigh);
unsigned neighbour_rxcost(struct neighbour *neigh); unsigned neighbour_rxcost(struct neighbour *neigh);
unsigned neighbour_cost(struct neighbour *neigh); unsigned neighbour_cost(struct neighbour *neigh);
int valid_rtt(struct neighbour *neigh);
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