Commit f8a954e1 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Compute jitter dynamically, on a per-interface basis.

parent 1b0c2bf8
...@@ -210,9 +210,6 @@ main(int argc, char **argv) ...@@ -210,9 +210,6 @@ main(int argc, char **argv)
if(seqno_interval <= 0) if(seqno_interval <= 0)
seqno_interval = MAX(wireless_hello_interval - 1, 2); seqno_interval = MAX(wireless_hello_interval - 1, 2);
jitter = MIN(wireless_hello_interval * 1000 / 4, 2000);
update_jitter = 2 * jitter;
rc = parse_address(*arg, myid); rc = parse_address(*arg, myid);
if(rc < 0) if(rc < 0)
goto syntax; goto syntax;
...@@ -775,3 +772,20 @@ update_hello_interval(struct network *net) ...@@ -775,3 +772,20 @@ update_hello_interval(struct network *net)
return rc; return rc;
} }
/* This should be no more than half the hello interval, so that hellos
aren't sent late. The result is in milliseconds. */
unsigned int
jitter(struct network *net)
{
unsigned interval = net->hello_interval * 1000;
return (interval / 2 + random() % interval) / 4;
}
unsigned int
update_jitter(struct network *net)
{
unsigned interval = net->hello_interval * 1000;
return (interval / 2 + random() % interval);
}
...@@ -101,3 +101,6 @@ extern int max_request_hopcount; ...@@ -101,3 +101,6 @@ extern int max_request_hopcount;
int network_idle(struct network *net); int network_idle(struct network *net);
int update_hello_interval(struct network *net); int update_hello_interval(struct network *net);
unsigned int jitter(struct network *net);
unsigned int update_jitter(struct network *net);
...@@ -40,8 +40,6 @@ struct timeval update_flush_time = {0, 0}; ...@@ -40,8 +40,6 @@ struct timeval update_flush_time = {0, 0};
const unsigned char packet_header[8] = {42, 1}; const unsigned char packet_header[8] = {42, 1};
unsigned int jitter;
unsigned int update_jitter;
int add_cost = 0; int add_cost = 0;
int parasitic = 0; int parasitic = 0;
int silent_time = 30; int silent_time = 30;
...@@ -268,7 +266,7 @@ flushbuf(struct network *net) ...@@ -268,7 +266,7 @@ flushbuf(struct network *net)
static void static void
schedule_flush(struct network *net) schedule_flush(struct network *net)
{ {
int msecs = jitter / 2 + random() % jitter; int msecs = jitter(net);
if(net->flush_time.tv_sec != 0 && if(net->flush_time.tv_sec != 0 &&
timeval_minus_msec(&net->flush_time, &now) < msecs) timeval_minus_msec(&net->flush_time, &now) < msecs)
return; return;
...@@ -522,9 +520,10 @@ flushupdates(void) ...@@ -522,9 +520,10 @@ flushupdates(void)
} }
static void static void
schedule_update_flush(void) schedule_update_flush(struct network *net)
{ {
int msecs = update_jitter / 2 + random() % update_jitter; int msecs;
msecs = update_jitter(net);
if(update_flush_time.tv_sec != 0 && if(update_flush_time.tv_sec != 0 &&
timeval_minus_msec(&update_flush_time, &now) < msecs) timeval_minus_msec(&update_flush_time, &now) < msecs)
return; return;
...@@ -599,7 +598,7 @@ send_update(struct network *net, ...@@ -599,7 +598,7 @@ send_update(struct network *net,
buffer_update(net, routes[i].src->prefix, routes[i].src->plen); buffer_update(net, routes[i].src->prefix, routes[i].src->plen);
net->update_time = now.tv_sec; net->update_time = now.tv_sec;
} }
schedule_update_flush(); schedule_update_flush(net);
} }
void void
...@@ -625,7 +624,7 @@ send_self_update(struct network *net, int force_seqno) ...@@ -625,7 +624,7 @@ send_self_update(struct network *net, int force_seqno)
if(xroutes[i].exported) if(xroutes[i].exported)
send_update(net, xroutes[i].prefix, xroutes[i].plen); send_update(net, xroutes[i].prefix, xroutes[i].plen);
} }
schedule_update_flush(); schedule_update_flush(net);
} }
void void
......
...@@ -26,8 +26,6 @@ extern unsigned short myseqno; ...@@ -26,8 +26,6 @@ extern unsigned short myseqno;
extern int seqno_time; extern int seqno_time;
extern int seqno_interval; extern int seqno_interval;
extern unsigned int jitter;
extern unsigned int update_jitter;
extern int add_cost; extern int add_cost;
extern int parasitic; extern int parasitic;
extern int silent_time; extern int silent_time;
......
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