Commit 23956f1d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use roughly throughout.

This very slightly reduces the amount of jitter in some cases.
parent 067cd537
......@@ -512,17 +512,17 @@ main(int argc, char **argv)
kernel_routes_changed = 0;
kernel_link_changed = 0;
kernel_addr_changed = 0;
kernel_dump_time = now.tv_sec + 20 + random() % 20;
kernel_dump_time = now.tv_sec + roughly(30);
schedule_neighbours_check(5000, 1);
expiry_time = now.tv_sec + 20 + random() % 20;
source_expiry_time = now.tv_sec + 200 + random() % 200;
expiry_time = now.tv_sec + roughly(30);
source_expiry_time = now.tv_sec + roughly(300);
/* Make some noise so that others notice us */
FOR_ALL_NETS(net) {
if(!net->up)
continue;
/* Apply jitter before we send the first message. */
usleep(5000 + random() % 10000);
usleep(roughly(10000));
gettime(&now);
send_hello(net);
send_self_update(net, 0);
......@@ -631,9 +631,9 @@ main(int argc, char **argv)
fprintf(stderr, "Warning: couldn't check exported routes.\n");
kernel_routes_changed = kernel_addr_changed = 0;
if(kernel_socket >= 0)
kernel_dump_time = now.tv_sec + 200 + random() % 200;
kernel_dump_time = now.tv_sec + roughly(300);
else
kernel_dump_time = now.tv_sec + 20 + random() % 20;
kernel_dump_time = now.tv_sec + roughly(30);
}
if(timeval_compare(&check_neighbours_timeout, &now) < 0) {
......@@ -647,12 +647,12 @@ main(int argc, char **argv)
check_networks();
expire_routes();
expire_resend();
expiry_time = now.tv_sec + 20 + random() % 20;
expiry_time = now.tv_sec + roughly(30);
}
if(now.tv_sec >= source_expiry_time) {
expire_sources();
source_expiry_time = now.tv_sec + 200 + random() % 200;
source_expiry_time = now.tv_sec + roughly(300);
}
FOR_ALL_NETS(net) {
......@@ -699,7 +699,7 @@ main(int argc, char **argv)
}
debugf("Exiting...\n");
usleep(5000 + random() % 10000);
usleep(roughly(10000));
gettime(&now);
/* Uninstall and retract all routes. */
......@@ -726,7 +726,7 @@ main(int argc, char **argv)
association caches. */
send_hello_noupdate(net, 10);
flushbuf(net);
usleep(500 + random() % 1000);
usleep(roughly(1000));
gettime(&now);
}
FOR_ALL_NETS(net) {
......@@ -735,7 +735,7 @@ main(int argc, char **argv)
/* Make sure they got it. */
send_hello_noupdate(net, 1);
flushbuf(net);
usleep(5000 + random() % 10000);
usleep(roughly(10000));
gettime(&now);
network_up(net, 0);
}
......@@ -808,7 +808,7 @@ schedule_neighbours_check(int msecs, int override)
{
struct timeval timeout;
timeval_plus_msec(&timeout, &now, msecs + random() % msecs);
timeval_plus_msec(&timeout, &now, roughly(msecs * 3 / 2));
if(override)
check_neighbours_timeout = timeout;
else
......
......@@ -413,7 +413,7 @@ void
schedule_flush_now(struct network *net)
{
/* Almost now */
int msecs = 5 + random() % 10;
int msecs = roughly(10);
if(net->flush_timeout.tv_sec != 0 &&
timeval_minus_msec(&net->flush_timeout, &now) < msecs)
return;
......
......@@ -127,8 +127,8 @@ jitter(struct network *net, int urgent)
if(urgent)
interval = MIN(interval, 100);
else
interval = MIN(interval, 2000);
return (interval / 2 + random() % interval) / 4;
interval = MIN(interval, 4000);
return roughly(interval) / 4;
}
unsigned int
......@@ -139,17 +139,14 @@ update_jitter(struct network *net, int urgent)
interval = MIN(interval, 100);
else
interval = MIN(interval, 4000);
return (interval / 2 + random() % interval);
return roughly(interval);
}
void
delay_jitter(struct timeval *time, struct timeval *timeout, int msecs)
{
int delay;
delay = msecs * 2 / 3 + random() % (msecs * 2 / 3);
*time = now;
timeval_plus_msec(timeout, &now, delay);
timeval_plus_msec(timeout, &now, roughly(msecs));
}
static int
......
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