/
make_suffle_data.c
116 lines (98 loc) · 2.56 KB
/
make_suffle_data.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
int gMaxData = 100000;
void appendEvent(void *aArg)
{
FILE* sFp = (FILE*)aArg;
int i=0;
char sMachine[128];
int sError;
int sIndex;
char* sMsg[] = {"success", "info", "error"};
for(i = 0; i < gMaxData ; i++)
{
sprintf(sMachine, "%d.%d.%d.%d",rand()%255, rand()%255, rand()%255, rand()%255);
sError = rand()%8000 - 4000;
if(sError > 0 )
{
sIndex = 1;
}
else if( sError == 0 )
{
sIndex = 0;
}
else
{
sIndex = 2;
}
fprintf(sFp, "3 %s %d %s\n", sMachine, sError, sMsg[sIndex]);
}
}
void appendFw2(void *aArg)
{
char sSrc[128];
char sDst[128];
int i=0;
FILE* sFp = (FILE*)aArg;
for(i = 0; i < gMaxData; i++)
{
sprintf(sSrc, "%d.%d.%d.%d",rand()%255, rand()%255, rand()%255, rand()%255);
sprintf(sDst, "%d.%d.%d.%d",rand()%255, rand()%255, rand()%255, rand()%255);
fprintf(sFp, "2 %s ::%s %d %s ::%s %d %d %d\n",
sSrc, sSrc, rand()%10000,
sDst, sDst, rand()%10000,
rand(), rand());
}
}
void appendFw1(void *aArg)
{
char sSrc[128];
char sDst[128];
int i=0;
FILE* sFp = (FILE*)aArg;
for(i = 0; i < gMaxData; i++)
{
sprintf(sSrc, "%d.%d.%d.%d",rand()%255, rand()%255, rand()%255, rand()%255);
sprintf(sDst, "%d.%d.%d.%d",rand()%255, rand()%255, rand()%255, rand()%255);
fprintf(sFp, "1 %s ::%s %d %s ::%s %d %d %d\n",
sSrc, sSrc, rand()%10000,
sDst, sDst, rand()%10000,
rand(), rand());
}
}
int main(int argc, char **argv)
{
int i;
FILE *sFp;
pthread_t sThread[3];
int sRC;
srand(time(NULL));
if( argc >= 2 )
{
gMaxData = atoi(argv[1]);
}
printf("Max Data : %d\n", gMaxData);
sFp = fopen("suffle_data.txt", "wt");
if( !sFp )
{
printf("file open error\n");
exit(-1);
}
pthread_create(&sThread[0], NULL, (void*)&appendFw1, (void*)sFp);
pthread_create(&sThread[1], NULL, (void*)&appendFw2, (void*)sFp);
pthread_create(&sThread[2], NULL, (void*)&appendEvent, (void*)sFp);
for(i = 0;i < 3; i++)
{
printf("join %d\n", i);
sRC = pthread_join(sThread[i], NULL);
if( sRC < 0 )
{
printf("Failed to join hhread [%d]: %d\n", i, sRC);
exit(-1);
}
}
fclose(sFp);
return 0;
}