-
Notifications
You must be signed in to change notification settings - Fork 4
/
drop_interval_gen.c
68 lines (52 loc) · 1.31 KB
/
drop_interval_gen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define USUAL_PAYLOAD_SIZE 1404
double rand_packet_drop(double mean)
{
double e;
e = (-1 / mean) * log(1 - drand48());
return e;
}
int get_drop_count(char *ftp_filename)
{
int ftp_file_size;
FILE *ptr_ftp_file;
if((ptr_ftp_file = fopen(ftp_filename, "r")) == NULL)
{
printf("drop_interval_gen: Unable to read ftp file!\n");
exit(EXIT_FAILURE);
}
else
{
printf("drop_interval_gen: Opened ftp file successfully for calculating size.\n");
}
fseek(ptr_ftp_file, 0L, SEEK_END);
ftp_file_size = ftell(ptr_ftp_file);
fclose(ptr_ftp_file);
return (ftp_file_size / USUAL_PAYLOAD_SIZE);
}
int main(int argc, char *argv[])
{
FILE *ptr_fp_drop;
int i = get_drop_count(argv[1]);
srand48(time(0));
if((ptr_fp_drop = fopen("drop_intervals.txt", "wb")) == NULL)
{
printf("drop_interval_gen: Unable to create/open file!\n");
exit(EXIT_FAILURE);
}
else
{
printf("drop_interval_gen: Opened drop_intervals.txt successfully for writing.\n");
}
while (i > 0)
{
fprintf(ptr_fp_drop, "%f\n", rand_packet_drop(atoi(argv[2])));
i--;
}
fclose(ptr_fp_drop);
printf("Drop intervals generated successfully!\n");
return 0;
}