56static const int drop_freq[] = { 500, 100, 50 };
61static const int corrupt_freq[] = { 500, 100, 50 };
67static const int up_low[] = { 60, 10, 5 };
68static const int up_high[] = { 600, 60, 10 };
74static const int down_low[] = { 5, 10, 10 };
75static const int down_high[] = { 10, 60, 120 };
81static const struct packet_flood_parms packet_flood_data[] = { { 10, 100 },
85struct packet_flood_parms
86get_packet_flood_parms(int level)
88 ASSERT(level > 0 && level < 4);
89 return packet_flood_data[level - 1];
106roll(
int low,
int high)
110 ret = low + (
get_random() % (high - low + 1));
111 ASSERT(ret >= low && ret <= high);
115static bool initialized;
123ask_gremlin(
int flags)
125 const int up_down_level = GREMLIN_UP_DOWN_LEVEL(flags);
126 const int drop_level = GREMLIN_DROP_LEVEL(flags);
151 delta = roll(down_low[up_down_level - 1], down_high[up_down_level - 1]);
156 delta = roll(up_low[up_down_level - 1], up_high[up_down_level - 1]);
160 msg(
D_GREMLIN,
"GREMLIN: CONNECTION GOING %s FOR %d SECONDS", (up ?
"UP" :
"DOWN"),
168 if (up && flip(drop_freq[drop_level - 1]))
182corrupt_gremlin(
struct buffer *buf,
int flags)
184 const int corrupt_level = GREMLIN_CORRUPT_LEVEL(flags);
187 if (flip(corrupt_freq[corrupt_level - 1]))
193 uint8_t r = roll(0, 255);
194 int method = roll(0, 5);
203 *(
BPTR(buf) + buf->
len - 1) = r;
207 *(
BPTR(buf) + roll(0, buf->
len - 1)) = r;
219 buf->
len -= roll(0, buf->
len - 1);
static bool buf_write(struct buffer *dest, const void *src, size_t size)
long int get_random(void)
Data Channel Cryptography Module.
#define D_GREMLIN_VERBOSE
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.