Commit 6d16c3b1 authored by Alessandro Rubini's avatar Alessandro Rubini

fix: 9.5.11.2: requests are randomized 0%-200% of value

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c985998f
......@@ -6,19 +6,25 @@
*/
#include <ppsi/ppsi.h>
enum rand_type {
RAND_NONE, /* Not randomized */
RAND_70_130, /* Should be 70% to 130% of 1 << value */
RAND_0_200, /* Should be 0% to 200% of 1 << value */
};
struct timeout_config {
char *name;
int isrand;
int which_rand;
int value;
};
/* most timeouts have a static configuration. Save it here */
static struct timeout_config to_configs[__PP_TO_ARRAY_SIZE] = {
[PP_TO_REQUEST] = {"REQUEST", 1,},
[PP_TO_SYNC_SEND] = {"SYNC_SEND", 1,},
[PP_TO_ANN_RECEIPT] = {"ANN_RECEIPT", 0,},
[PP_TO_ANN_SEND] = {"ANN_SEND", 1,},
[PP_TO_FAULTY] = {"FAULTY", 0, 4000},
[PP_TO_REQUEST] = {"REQUEST", RAND_0_200,},
[PP_TO_SYNC_SEND] = {"SYNC_SEND", RAND_70_130,},
[PP_TO_ANN_RECEIPT] = {"ANN_RECEIPT", RAND_NONE,},
[PP_TO_ANN_SEND] = {"ANN_SEND", RAND_70_130,},
[PP_TO_FAULTY] = {"FAULTY", RAND_NONE, 4000},
/* extension timeouts are explicitly set to a value */
};
......@@ -43,12 +49,6 @@ void __pp_timeout_set(struct pp_instance *ppi, int index, int millisec)
to_configs[index].name, millisec);
}
/*
* Randomize a timeout. We are required to fit between 70% and 130%
* of the value for 90% of the time, at least. But making it "almost
* exact" is bad in a big network. So randomize between 80% and 120%:
* constant part is 80% and variable is 40%.
*/
void pp_timeout_set(struct pp_instance *ppi, int index)
{
......@@ -57,11 +57,6 @@ void pp_timeout_set(struct pp_instance *ppi, int index)
int millisec;
int logval = to_configs[index].value;
if (!to_configs[index].isrand){
__pp_timeout_set(ppi, index, logval); /* not a logval */
return;
}
if (!seed) {
uint32_t *p;
/* use the least 32 bits of the mac address as seed */
......@@ -84,9 +79,23 @@ void pp_timeout_set(struct pp_instance *ppi, int index)
* Here below, 0 gets to 16 * 25 = 400ms, 40% of the nominal value
*/
millisec = (1 << (logval + 4)) * 25;
/* twice 40% + a random value between 0 and 40% */
millisec = (millisec * 2) + rval % millisec;
switch(to_configs[index].which_rand) {
case RAND_70_130:
/*
* We are required to fit between 70% and 130%
* of the value for 90% of the time, at least.
* So randomize between 80% and 120%: constant
* part is 80% and variable is 40%.
*/
millisec = (millisec * 2) + rval % millisec;
break;
case RAND_0_200:
millisec = rval % (millisec * 5);
break;
case RAND_NONE:
millisec = logval; /* not a log, just a constant */
}
__pp_timeout_set(ppi, index, millisec);
}
......
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