57static const int drop_freq[] = { 500, 100, 50 };
62static const int corrupt_freq[] = { 500, 100, 50 };
68static const int up_low[] = { 60, 10, 5 };
69static const int up_high[] = { 600, 60, 10 };
75static const int down_low[] = { 5, 10, 10 };
76static const int down_high[] = { 10, 60, 120 };
82static const struct packet_flood_parms packet_flood_data[] =
83{{10, 100}, {10, 1500}, {100, 1500}};
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]);
161 "GREMLIN: CONNECTION GOING %s FOR %d SECONDS",
162 (up ?
"UP" :
"DOWN"),
170 if (up && flip(drop_freq[drop_level-1]))
184corrupt_gremlin(
struct buffer *buf,
int flags)
186 const int corrupt_level = GREMLIN_CORRUPT_LEVEL(flags);
189 if (flip(corrupt_freq[corrupt_level-1]))
195 uint8_t r = roll(0, 255);
196 int method = roll(0, 5);
205 *(
BPTR(buf) + buf->
len - 1) = r;
209 *(
BPTR(buf) + roll(0, buf->
len - 1)) = r;
221 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.