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 | #include "renetcolAgg.h" |
---|
36 | |
---|
37 | struct SHMForAgg *shmForAgg; |
---|
38 | |
---|
39 | int |
---|
40 | main(int argc, char *argv[]) |
---|
41 | { |
---|
42 | int shmid; |
---|
43 | int i, j, k = 0; |
---|
44 | int index = 1; |
---|
45 | int rrd_update_er_ct = 0; |
---|
46 | int rrd_update_ok_ct = 0; |
---|
47 | int rrd_already_created_ct = 0; |
---|
48 | int rrd_create_er_ct = 0; |
---|
49 | int rrd_create_ok_ct = 0; |
---|
50 | int isFirstUpdate = 1; |
---|
51 | key_t key; |
---|
52 | static char buf[2048]; |
---|
53 | static char name[2048]; |
---|
54 | static char ipStr[24]; |
---|
55 | #if defined(MATRIX) && defined(IPV4AGGIDR) |
---|
56 | static char indexStr[24]; |
---|
57 | #endif |
---|
58 | static char asStr[7]; |
---|
59 | static char createstr[2048]; |
---|
60 | char *opt[27]; |
---|
61 | char *optUpdate[3]; |
---|
62 | FILE *fp; |
---|
63 | static time_t now, now2; |
---|
64 | |
---|
65 | key = 8765; |
---|
66 | if ((shmid = shmget(key, SHMSIZE, 0666)) < 0) { |
---|
67 | perror("shmget"); |
---|
68 | exit(1); |
---|
69 | } |
---|
70 | if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) { |
---|
71 | perror("shmat"); |
---|
72 | exit(1); |
---|
73 | } |
---|
74 | |
---|
75 | fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. By.\n"); |
---|
76 | if (fork () != 0) |
---|
77 | exit (0); |
---|
78 | if (setsid() == -1){ |
---|
79 | exit(4); |
---|
80 | } |
---|
81 | |
---|
82 | do { |
---|
83 | if (shmForAgg->readed == 1) { |
---|
84 | shmForAgg->readed = 0; |
---|
85 | if (shmForAgg->currentTable == 0) { |
---|
86 | index = 1; |
---|
87 | }else{ |
---|
88 | index = 0; |
---|
89 | } |
---|
90 | now = time((time_t *)NULL); |
---|
91 | if (isFirstUpdate == 0) { |
---|
92 | |
---|
93 | for (i=0; i<shmForAgg->v4PrefixNb; i++){ |
---|
94 | |
---|
95 | if (shmForAgg->prefixV4Tab[index][i].sampling != 0) { |
---|
96 | for (j=0; j<strlen(name); j++) {name[j] = '\0';} |
---|
97 | for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} |
---|
98 | for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} |
---|
99 | for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} |
---|
100 | strcat(name, PREFIX_RRD_LOCATION); |
---|
101 | sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", |
---|
102 | shmForAgg->prefixV4Tab[index][i].beginning>>24, |
---|
103 | shmForAgg->prefixV4Tab[index][i].beginning<<8>>24, |
---|
104 | shmForAgg->prefixV4Tab[index][i].beginning<<16>>24, |
---|
105 | shmForAgg->prefixV4Tab[index][i].beginning<<24>>24, |
---|
106 | shmForAgg->prefixV4Tab[index][i].mask, |
---|
107 | shmForAgg->prefixV4Tab[index][i].sampling |
---|
108 | ); |
---|
109 | strcat(name, ipStr); |
---|
110 | strcat(name, RRD_EXTENSION); |
---|
111 | if ( (fp=fopen(name,"r")) == NULL ){ |
---|
112 | opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); |
---|
113 | strcpy(opt[0], RRD_PARAM_PREFIX_0); |
---|
114 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
115 | strcpy(opt[1], name); |
---|
116 | opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); |
---|
117 | strcpy(opt[2], RRD_PARAM_PREFIX_1); |
---|
118 | opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); |
---|
119 | strcpy(opt[3], RRD_PARAM_PREFIX_2); |
---|
120 | opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); |
---|
121 | strcpy(opt[4], RRD_PARAM_PREFIX_3); |
---|
122 | opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); |
---|
123 | strcpy(opt[5], RRD_PARAM_PREFIX_4); |
---|
124 | opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); |
---|
125 | strcpy(opt[6], RRD_PARAM_PREFIX_5); |
---|
126 | opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); |
---|
127 | strcpy(opt[7], RRD_PARAM_PREFIX_6); |
---|
128 | opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); |
---|
129 | strcpy(opt[8], RRD_PARAM_PREFIX_7); |
---|
130 | opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); |
---|
131 | strcpy(opt[9], RRD_PARAM_PREFIX_8); |
---|
132 | opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); |
---|
133 | strcpy(opt[10], RRD_PARAM_PREFIX_9); |
---|
134 | opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); |
---|
135 | strcpy(opt[11], RRD_PARAM_PREFIX_10); |
---|
136 | opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); |
---|
137 | strcpy(opt[12], RRD_PARAM_PREFIX_11); |
---|
138 | opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); |
---|
139 | strcpy(opt[13], RRD_PARAM_PREFIX_12); |
---|
140 | opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); |
---|
141 | strcpy(opt[14], RRD_PARAM_PREFIX_13); |
---|
142 | opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); |
---|
143 | strcpy(opt[15], RRD_PARAM_PREFIX_14); |
---|
144 | opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); |
---|
145 | strcpy(opt[16], RRD_PARAM_PREFIX_15); |
---|
146 | opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); |
---|
147 | strcpy(opt[17], RRD_PARAM_PREFIX_16); |
---|
148 | opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); |
---|
149 | strcpy(opt[18], RRD_PARAM_PREFIX_17); |
---|
150 | opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); |
---|
151 | strcpy(opt[19], RRD_PARAM_PREFIX_18); |
---|
152 | opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); |
---|
153 | strcpy(opt[20], RRD_PARAM_PREFIX_19); |
---|
154 | opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); |
---|
155 | strcpy(opt[21], RRD_PARAM_PREFIX_20); |
---|
156 | opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); |
---|
157 | strcpy(opt[22], RRD_PARAM_PREFIX_21); |
---|
158 | opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); |
---|
159 | strcpy(opt[23], RRD_PARAM_PREFIX_22); |
---|
160 | opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); |
---|
161 | strcpy(opt[24], RRD_PARAM_PREFIX_23); |
---|
162 | opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); |
---|
163 | strcpy(opt[25], RRD_PARAM_PREFIX_24); |
---|
164 | opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); |
---|
165 | strcpy(opt[26], RRD_PARAM_PREFIX_25); |
---|
166 | optind = opterr = 0; |
---|
167 | rrd_clear_error(); |
---|
168 | if ( rrd_create(27,opt) < 0) { |
---|
169 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
---|
170 | rrd_create_er_ct++; |
---|
171 | } else { |
---|
172 | rrd_create_ok_ct++; |
---|
173 | } |
---|
174 | for ( j=0; j<27; j++) { |
---|
175 | free(opt[j]); |
---|
176 | opt[j] = NULL; |
---|
177 | } |
---|
178 | }else{ |
---|
179 | fclose(fp); |
---|
180 | rrd_already_created_ct++; |
---|
181 | snprintf(buf, |
---|
182 | 2048, |
---|
183 | "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", |
---|
184 | now-300, |
---|
185 | shmForAgg->prefixV4Tab[index][i].flowNbIN, |
---|
186 | shmForAgg->prefixV4Tab[index][i].flowNbOUT, |
---|
187 | shmForAgg->prefixV4Tab[index][i].bytesNbIN, |
---|
188 | shmForAgg->prefixV4Tab[index][i].bytesNbOUT, |
---|
189 | shmForAgg->prefixV4Tab[index][i].pktsNbIN, |
---|
190 | shmForAgg->prefixV4Tab[index][i].pktsNbOUT, |
---|
191 | shmForAgg->prefixV4Tab[index][i].firstCoSIN, |
---|
192 | shmForAgg->prefixV4Tab[index][i].firstCoSOUT, |
---|
193 | shmForAgg->prefixV4Tab[index][i].secondCoSIN, |
---|
194 | shmForAgg->prefixV4Tab[index][i].secondCoSOUT, |
---|
195 | shmForAgg->prefixV4Tab[index][i].thirdCoSIN, |
---|
196 | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT, |
---|
197 | shmForAgg->prefixV4Tab[index][i].fourthCoSIN, |
---|
198 | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT |
---|
199 | ); |
---|
200 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
---|
201 | strcpy(optUpdate[0], RRD_UPDATE_0); |
---|
202 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
203 | strcpy(optUpdate[1], name); |
---|
204 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
---|
205 | strcpy(optUpdate[2], buf); |
---|
206 | optind = opterr = 0; |
---|
207 | rrd_clear_error(); |
---|
208 | if ( rrd_update(3, optUpdate) < 0 ) { |
---|
209 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
---|
210 | rrd_update_er_ct++; |
---|
211 | } else { |
---|
212 | rrd_update_ok_ct++; |
---|
213 | } |
---|
214 | for ( j=0; j<3; j++) { |
---|
215 | free(optUpdate[j]); |
---|
216 | optUpdate[j] = NULL; |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; |
---|
221 | shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; |
---|
222 | shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; |
---|
223 | shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; |
---|
224 | shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; |
---|
225 | shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; |
---|
226 | shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; |
---|
227 | shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; |
---|
228 | shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; |
---|
229 | shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; |
---|
230 | shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; |
---|
231 | shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; |
---|
232 | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; |
---|
233 | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | for (i=0; i<shmForAgg->v4SubnetNb; i++){ |
---|
238 | |
---|
239 | if (shmForAgg->prefixV4SubnetTab[index][i].sampling != 0) { |
---|
240 | for (j=0; j<strlen(name); j++) {name[j] = '\0';} |
---|
241 | for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} |
---|
242 | for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} |
---|
243 | for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} |
---|
244 | strcat(name, PREFIX_RRD_LOCATION); |
---|
245 | sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", |
---|
246 | shmForAgg->prefixV4SubnetTab[index][i].beginning>>24, |
---|
247 | shmForAgg->prefixV4SubnetTab[index][i].beginning<<8>>24, |
---|
248 | shmForAgg->prefixV4SubnetTab[index][i].beginning<<16>>24, |
---|
249 | shmForAgg->prefixV4SubnetTab[index][i].beginning<<24>>24, |
---|
250 | shmForAgg->prefixV4SubnetTab[index][i].mask, |
---|
251 | shmForAgg->prefixV4SubnetTab[index][i].sampling |
---|
252 | ); |
---|
253 | strcat(name, ipStr); |
---|
254 | strcat(name, RRD_EXTENSION); |
---|
255 | if ( (fp=fopen(name,"r")) == NULL ){ |
---|
256 | opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); |
---|
257 | strcpy(opt[0], RRD_PARAM_PREFIX_0); |
---|
258 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
259 | strcpy(opt[1], name); |
---|
260 | opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); |
---|
261 | strcpy(opt[2], RRD_PARAM_PREFIX_1); |
---|
262 | opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); |
---|
263 | strcpy(opt[3], RRD_PARAM_PREFIX_2); |
---|
264 | opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); |
---|
265 | strcpy(opt[4], RRD_PARAM_PREFIX_3); |
---|
266 | opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); |
---|
267 | strcpy(opt[5], RRD_PARAM_PREFIX_4); |
---|
268 | opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); |
---|
269 | strcpy(opt[6], RRD_PARAM_PREFIX_5); |
---|
270 | opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); |
---|
271 | strcpy(opt[7], RRD_PARAM_PREFIX_6); |
---|
272 | opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); |
---|
273 | strcpy(opt[8], RRD_PARAM_PREFIX_7); |
---|
274 | opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); |
---|
275 | strcpy(opt[9], RRD_PARAM_PREFIX_8); |
---|
276 | opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); |
---|
277 | strcpy(opt[10], RRD_PARAM_PREFIX_9); |
---|
278 | opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); |
---|
279 | strcpy(opt[11], RRD_PARAM_PREFIX_10); |
---|
280 | opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); |
---|
281 | strcpy(opt[12], RRD_PARAM_PREFIX_11); |
---|
282 | opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); |
---|
283 | strcpy(opt[13], RRD_PARAM_PREFIX_12); |
---|
284 | opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); |
---|
285 | strcpy(opt[14], RRD_PARAM_PREFIX_13); |
---|
286 | opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); |
---|
287 | strcpy(opt[15], RRD_PARAM_PREFIX_14); |
---|
288 | opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); |
---|
289 | strcpy(opt[16], RRD_PARAM_PREFIX_15); |
---|
290 | opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); |
---|
291 | strcpy(opt[17], RRD_PARAM_PREFIX_16); |
---|
292 | opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); |
---|
293 | strcpy(opt[18], RRD_PARAM_PREFIX_17); |
---|
294 | opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); |
---|
295 | strcpy(opt[19], RRD_PARAM_PREFIX_18); |
---|
296 | opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); |
---|
297 | strcpy(opt[20], RRD_PARAM_PREFIX_19); |
---|
298 | opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); |
---|
299 | strcpy(opt[21], RRD_PARAM_PREFIX_20); |
---|
300 | opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); |
---|
301 | strcpy(opt[22], RRD_PARAM_PREFIX_21); |
---|
302 | opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); |
---|
303 | strcpy(opt[23], RRD_PARAM_PREFIX_22); |
---|
304 | opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); |
---|
305 | strcpy(opt[24], RRD_PARAM_PREFIX_23); |
---|
306 | opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); |
---|
307 | strcpy(opt[25], RRD_PARAM_PREFIX_24); |
---|
308 | opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); |
---|
309 | strcpy(opt[26], RRD_PARAM_PREFIX_25); |
---|
310 | optind = opterr = 0; |
---|
311 | rrd_clear_error(); |
---|
312 | if ( rrd_create(27,opt) < 0) { |
---|
313 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
---|
314 | rrd_create_er_ct++; |
---|
315 | } else { |
---|
316 | rrd_create_ok_ct++; |
---|
317 | } |
---|
318 | for ( j=0; j<27; j++) { |
---|
319 | free(opt[j]); |
---|
320 | opt[j] = NULL; |
---|
321 | } |
---|
322 | }else{ |
---|
323 | fclose(fp); |
---|
324 | rrd_already_created_ct++; |
---|
325 | snprintf(buf, |
---|
326 | 2048, |
---|
327 | "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", |
---|
328 | now-300, |
---|
329 | shmForAgg->prefixV4SubnetTab[index][i].flowNbIN, |
---|
330 | shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT, |
---|
331 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN, |
---|
332 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT, |
---|
333 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN, |
---|
334 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT, |
---|
335 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN, |
---|
336 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT, |
---|
337 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN, |
---|
338 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT, |
---|
339 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN, |
---|
340 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT, |
---|
341 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN, |
---|
342 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT |
---|
343 | ); |
---|
344 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
---|
345 | strcpy(optUpdate[0], RRD_UPDATE_0); |
---|
346 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
347 | strcpy(optUpdate[1], name); |
---|
348 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
---|
349 | strcpy(optUpdate[2], buf); |
---|
350 | optind = opterr = 0; |
---|
351 | rrd_clear_error(); |
---|
352 | if ( rrd_update(3, optUpdate) < 0 ) { |
---|
353 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
---|
354 | rrd_update_er_ct++; |
---|
355 | } else { |
---|
356 | rrd_update_ok_ct++; |
---|
357 | } |
---|
358 | for ( j=0; j<3; j++) { |
---|
359 | free(optUpdate[j]); |
---|
360 | optUpdate[j] = NULL; |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; |
---|
365 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; |
---|
366 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; |
---|
367 | shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; |
---|
368 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; |
---|
369 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; |
---|
370 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; |
---|
371 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; |
---|
372 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; |
---|
373 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; |
---|
374 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; |
---|
375 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; |
---|
376 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; |
---|
377 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0; |
---|
378 | } |
---|
379 | } |
---|
380 | #if defined(MATRIX) && defined(IPV4AGGIDR) |
---|
381 | |
---|
382 | |
---|
383 | for (i=0; i<ROUTER_INDEX_MAX; i++){ |
---|
384 | for (j=0; j<ROUTER_INDEX_MAX; j++){ |
---|
385 | |
---|
386 | for (k=0; k<strlen(name); k++) {name[k] = '\0';} |
---|
387 | for (k=0; k<strlen(createstr); k++) {createstr[k] = '\0';} |
---|
388 | for (k=0; k<strlen(indexStr); k++) {indexStr[k] = '\0';} |
---|
389 | for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} |
---|
390 | strcat(name, MATRIX_RRD_LOCATION); |
---|
391 | sprintf(indexStr, "%d_%d", |
---|
392 | i, |
---|
393 | j |
---|
394 | ); |
---|
395 | strcat(name, indexStr); |
---|
396 | strcat(name, RRD_EXTENSION); |
---|
397 | if ( (fp=fopen(name,"r")) == NULL ){ |
---|
398 | opt[0]= (char *) malloc((strlen(RRD_PARAM_MATRIX_0) + 1) * sizeof(char)); |
---|
399 | strcpy(opt[0], RRD_PARAM_MATRIX_0); |
---|
400 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
401 | strcpy(opt[1], name); |
---|
402 | opt[2]= (char *) malloc((strlen(RRD_PARAM_MATRIX_1) + 1) * sizeof(char)); |
---|
403 | strcpy(opt[2], RRD_PARAM_MATRIX_1); |
---|
404 | opt[3]= (char *) malloc((strlen(RRD_PARAM_MATRIX_2) + 1) * sizeof(char)); |
---|
405 | strcpy(opt[3], RRD_PARAM_MATRIX_2); |
---|
406 | opt[4]= (char *) malloc((strlen(RRD_PARAM_MATRIX_3) + 1) * sizeof(char)); |
---|
407 | strcpy(opt[4], RRD_PARAM_MATRIX_3); |
---|
408 | opt[5]= (char *) malloc((strlen(RRD_PARAM_MATRIX_4) + 1) * sizeof(char)); |
---|
409 | strcpy(opt[5], RRD_PARAM_MATRIX_4); |
---|
410 | opt[6]= (char *) malloc((strlen(RRD_PARAM_MATRIX_5) + 1) * sizeof(char)); |
---|
411 | strcpy(opt[6], RRD_PARAM_MATRIX_5); |
---|
412 | opt[7]= (char *) malloc((strlen(RRD_PARAM_MATRIX_6) + 1) * sizeof(char)); |
---|
413 | strcpy(opt[7], RRD_PARAM_MATRIX_6); |
---|
414 | opt[8]= (char *) malloc((strlen(RRD_PARAM_MATRIX_7) + 1) * sizeof(char)); |
---|
415 | strcpy(opt[8], RRD_PARAM_MATRIX_7); |
---|
416 | opt[9]= (char *) malloc((strlen(RRD_PARAM_MATRIX_8) + 1) * sizeof(char)); |
---|
417 | strcpy(opt[9], RRD_PARAM_MATRIX_8); |
---|
418 | opt[10]= (char *) malloc((strlen(RRD_PARAM_MATRIX_9) + 1) * sizeof(char)); |
---|
419 | strcpy(opt[10], RRD_PARAM_MATRIX_9); |
---|
420 | opt[11]= (char *) malloc((strlen(RRD_PARAM_MATRIX_10) + 1) * sizeof(char)); |
---|
421 | strcpy(opt[11], RRD_PARAM_MATRIX_10); |
---|
422 | opt[12]= (char *) malloc((strlen(RRD_PARAM_MATRIX_11) + 1) * sizeof(char)); |
---|
423 | strcpy(opt[12], RRD_PARAM_MATRIX_11); |
---|
424 | opt[13]= (char *) malloc((strlen(RRD_PARAM_MATRIX_12) + 1) * sizeof(char)); |
---|
425 | strcpy(opt[13], RRD_PARAM_MATRIX_12); |
---|
426 | opt[14]= (char *) malloc((strlen(RRD_PARAM_MATRIX_13) + 1) * sizeof(char)); |
---|
427 | strcpy(opt[14], RRD_PARAM_MATRIX_13); |
---|
428 | opt[15]= (char *) malloc((strlen(RRD_PARAM_MATRIX_14) + 1) * sizeof(char)); |
---|
429 | strcpy(opt[15], RRD_PARAM_MATRIX_14); |
---|
430 | optind = opterr = 0; |
---|
431 | rrd_clear_error(); |
---|
432 | if ( rrd_create(16,opt) < 0) { |
---|
433 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
---|
434 | rrd_create_er_ct++; |
---|
435 | } else { |
---|
436 | rrd_create_ok_ct++; |
---|
437 | } |
---|
438 | for ( k=0; k<16; k++) { |
---|
439 | free(opt[k]); |
---|
440 | opt[k] = NULL; |
---|
441 | } |
---|
442 | }else{ |
---|
443 | fclose(fp); |
---|
444 | rrd_already_created_ct++; |
---|
445 | snprintf(buf, |
---|
446 | 2048, |
---|
447 | "%lu:%llu:%llu:%llu", |
---|
448 | now-300, |
---|
449 | shmForAgg->matrixPOP[index][i][j].flowNb, |
---|
450 | shmForAgg->matrixPOP[index][i][j].bytesNb, |
---|
451 | shmForAgg->matrixPOP[index][i][j].pktsNb |
---|
452 | ); |
---|
453 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
---|
454 | strcpy(optUpdate[0], RRD_UPDATE_0); |
---|
455 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
456 | strcpy(optUpdate[1], name); |
---|
457 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
---|
458 | strcpy(optUpdate[2], buf); |
---|
459 | optind = opterr = 0; |
---|
460 | rrd_clear_error(); |
---|
461 | if ( rrd_update(3, optUpdate) < 0 ) { |
---|
462 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
---|
463 | rrd_update_er_ct++; |
---|
464 | } else { |
---|
465 | rrd_update_ok_ct++; |
---|
466 | } |
---|
467 | for ( k=0; k<3; k++) { |
---|
468 | free(optUpdate[k]); |
---|
469 | optUpdate[k] = NULL; |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | for (i=0; i<ROUTER_INDEX_MAX; i++){ |
---|
477 | for (j=0; j<ROUTER_INDEX_MAX; j++) { |
---|
478 | shmForAgg->matrixPOP[index][i][j].bytesNb = 0; |
---|
479 | shmForAgg->matrixPOP[index][i][j].pktsNb = 0; |
---|
480 | shmForAgg->matrixPOP[index][i][j].flowNb = 0; |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | #endif |
---|
485 | #ifdef ASACC |
---|
486 | |
---|
487 | |
---|
488 | |
---|
489 | |
---|
490 | |
---|
491 | for (i=0; i<shmForAgg->ASNb; i++){ |
---|
492 | |
---|
493 | if (shmForAgg->ASTab[index][i].sampling != 0) { |
---|
494 | for (j=0; j<strlen(name); j++) {name[j] = '\0';} |
---|
495 | for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} |
---|
496 | for (j=0; j<strlen(asStr); j++) {asStr[j] = '\0';} |
---|
497 | for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} |
---|
498 | strcat(name, AS_RRD_LOCATION); |
---|
499 | sprintf(asStr, "%hu_%lu", |
---|
500 | shmForAgg->ASTab[index][i].as, |
---|
501 | shmForAgg->ASTab[index][i].sampling |
---|
502 | ); |
---|
503 | strcat(name, asStr); |
---|
504 | strcat(name, RRD_EXTENSION); |
---|
505 | if ( (fp=fopen(name,"r")) == NULL ){ |
---|
506 | opt[0]= (char *) malloc((strlen(RRD_PARAM_AS_0) + 1) * sizeof(char)); |
---|
507 | strcpy(opt[0], RRD_PARAM_AS_0); |
---|
508 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
509 | strcpy(opt[1], name); |
---|
510 | opt[2]= (char *) malloc((strlen(RRD_PARAM_AS_1) + 1) * sizeof(char)); |
---|
511 | strcpy(opt[2], RRD_PARAM_AS_1); |
---|
512 | opt[3]= (char *) malloc((strlen(RRD_PARAM_AS_2) + 1) * sizeof(char)); |
---|
513 | strcpy(opt[3], RRD_PARAM_AS_2); |
---|
514 | opt[4]= (char *) malloc((strlen(RRD_PARAM_AS_3) + 1) * sizeof(char)); |
---|
515 | strcpy(opt[4], RRD_PARAM_AS_3); |
---|
516 | opt[5]= (char *) malloc((strlen(RRD_PARAM_AS_4) + 1) * sizeof(char)); |
---|
517 | strcpy(opt[5], RRD_PARAM_AS_4); |
---|
518 | opt[6]= (char *) malloc((strlen(RRD_PARAM_AS_5) + 1) * sizeof(char)); |
---|
519 | strcpy(opt[6], RRD_PARAM_AS_5); |
---|
520 | opt[7]= (char *) malloc((strlen(RRD_PARAM_AS_6) + 1) * sizeof(char)); |
---|
521 | strcpy(opt[7], RRD_PARAM_AS_6); |
---|
522 | opt[8]= (char *) malloc((strlen(RRD_PARAM_AS_7) + 1) * sizeof(char)); |
---|
523 | strcpy(opt[8], RRD_PARAM_AS_7); |
---|
524 | opt[9]= (char *) malloc((strlen(RRD_PARAM_AS_8) + 1) * sizeof(char)); |
---|
525 | strcpy(opt[9], RRD_PARAM_AS_8); |
---|
526 | opt[10]= (char *) malloc((strlen(RRD_PARAM_AS_9) + 1) * sizeof(char)); |
---|
527 | strcpy(opt[10], RRD_PARAM_AS_9); |
---|
528 | opt[11]= (char *) malloc((strlen(RRD_PARAM_AS_10) + 1) * sizeof(char)); |
---|
529 | strcpy(opt[11], RRD_PARAM_AS_10); |
---|
530 | opt[12]= (char *) malloc((strlen(RRD_PARAM_AS_11) + 1) * sizeof(char)); |
---|
531 | strcpy(opt[12], RRD_PARAM_AS_11); |
---|
532 | opt[13]= (char *) malloc((strlen(RRD_PARAM_AS_12) + 1) * sizeof(char)); |
---|
533 | strcpy(opt[13], RRD_PARAM_AS_12); |
---|
534 | opt[14]= (char *) malloc((strlen(RRD_PARAM_AS_13) + 1) * sizeof(char)); |
---|
535 | strcpy(opt[14], RRD_PARAM_AS_13); |
---|
536 | opt[15]= (char *) malloc((strlen(RRD_PARAM_AS_14) + 1) * sizeof(char)); |
---|
537 | strcpy(opt[15], RRD_PARAM_AS_14); |
---|
538 | opt[16]= (char *) malloc((strlen(RRD_PARAM_AS_15) + 1) * sizeof(char)); |
---|
539 | strcpy(opt[16], RRD_PARAM_AS_15); |
---|
540 | opt[17]= (char *) malloc((strlen(RRD_PARAM_AS_16) + 1) * sizeof(char)); |
---|
541 | strcpy(opt[17], RRD_PARAM_AS_16); |
---|
542 | opt[18]= (char *) malloc((strlen(RRD_PARAM_AS_17) + 1) * sizeof(char)); |
---|
543 | strcpy(opt[18], RRD_PARAM_AS_17); |
---|
544 | optind = opterr = 0; |
---|
545 | rrd_clear_error(); |
---|
546 | if ( rrd_create(19,opt) < 0) { |
---|
547 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
---|
548 | rrd_create_er_ct++; |
---|
549 | } else { |
---|
550 | rrd_create_ok_ct++; |
---|
551 | } |
---|
552 | for ( j=0; j<19; j++) { |
---|
553 | free(opt[j]); |
---|
554 | opt[j] = NULL; |
---|
555 | } |
---|
556 | }else{ |
---|
557 | fclose(fp); |
---|
558 | rrd_already_created_ct++; |
---|
559 | snprintf(buf, |
---|
560 | 2048, |
---|
561 | "%lu:%llu:%llu:%llu:%llu:%llu:%llu", |
---|
562 | now-300, |
---|
563 | shmForAgg->ASTab[index][i].flowNbIN, |
---|
564 | shmForAgg->ASTab[index][i].flowNbOUT, |
---|
565 | shmForAgg->ASTab[index][i].bytesNbIN, |
---|
566 | shmForAgg->ASTab[index][i].bytesNbOUT, |
---|
567 | shmForAgg->ASTab[index][i].pktsNbIN, |
---|
568 | shmForAgg->ASTab[index][i].pktsNbOUT |
---|
569 | ); |
---|
570 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
---|
571 | strcpy(optUpdate[0], RRD_UPDATE_0); |
---|
572 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
---|
573 | strcpy(optUpdate[1], name); |
---|
574 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
---|
575 | strcpy(optUpdate[2], buf); |
---|
576 | optind = opterr = 0; |
---|
577 | rrd_clear_error(); |
---|
578 | if ( rrd_update(3, optUpdate) < 0 ) { |
---|
579 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
---|
580 | rrd_update_er_ct++; |
---|
581 | } else { |
---|
582 | rrd_update_ok_ct++; |
---|
583 | } |
---|
584 | for ( j=0; j<3; j++) { |
---|
585 | free(optUpdate[j]); |
---|
586 | optUpdate[j] = NULL; |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | shmForAgg->ASTab[index][i].flowNbIN = 0; |
---|
591 | shmForAgg->ASTab[index][i].bytesNbIN = 0; |
---|
592 | shmForAgg->ASTab[index][i].pktsNbIN = 0; |
---|
593 | shmForAgg->ASTab[index][i].flowNbOUT = 0; |
---|
594 | shmForAgg->ASTab[index][i].bytesNbOUT = 0; |
---|
595 | shmForAgg->ASTab[index][i].pktsNbOUT = 0; |
---|
596 | } |
---|
597 | } |
---|
598 | #endif |
---|
599 | now2 = time((time_t *)NULL); |
---|
600 | #ifdef DEBUGAGG |
---|
601 | fprintf(stderr, "IPv4 subnet managment (rrd update) : \n %d sec, %d files updated, %d errors, total %d\n %d rrd file already created, %d errors in creation, %d new rrd file creations", |
---|
602 | (int)now2-now, |
---|
603 | rrd_update_ok_ct, |
---|
604 | rrd_update_er_ct, |
---|
605 | rrd_update_ok_ct+rrd_update_er_ct, |
---|
606 | rrd_already_created_ct, |
---|
607 | rrd_create_er_ct, |
---|
608 | rrd_create_ok_ct); |
---|
609 | #endif |
---|
610 | rrd_update_ok_ct = 0; |
---|
611 | rrd_update_er_ct = 0; |
---|
612 | rrd_already_created_ct = 0; |
---|
613 | rrd_create_er_ct = 0; |
---|
614 | rrd_create_ok_ct = 0; |
---|
615 | rrd_clear_error(); |
---|
616 | } else { |
---|
617 | isFirstUpdate = 0; |
---|
618 | |
---|
619 | for (i=0; i<shmForAgg->v4PrefixNb; i++){ |
---|
620 | shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; |
---|
621 | shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; |
---|
622 | shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; |
---|
623 | shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; |
---|
624 | shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; |
---|
625 | shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; |
---|
626 | shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; |
---|
627 | shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; |
---|
628 | shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; |
---|
629 | shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; |
---|
630 | shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; |
---|
631 | shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; |
---|
632 | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; |
---|
633 | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; |
---|
634 | } |
---|
635 | for (i=0; i<shmForAgg->v4SubnetNb; i++){ |
---|
636 | shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; |
---|
637 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; |
---|
638 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; |
---|
639 | shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; |
---|
640 | shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; |
---|
641 | shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; |
---|
642 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; |
---|
643 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; |
---|
644 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; |
---|
645 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; |
---|
646 | shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; |
---|
647 | shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; |
---|
648 | shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; |
---|
649 | shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0; |
---|
650 | } |
---|
651 | |
---|
652 | #ifdef MATRIX |
---|
653 | for (i=0; i<ROUTER_INDEX_MAX; i++){ |
---|
654 | for (j=0; j<ROUTER_INDEX_MAX; j++) { |
---|
655 | shmForAgg->matrixPOP[index][i][j].bytesNb = 0; |
---|
656 | shmForAgg->matrixPOP[index][i][j].pktsNb = 0; |
---|
657 | shmForAgg->matrixPOP[index][i][j].flowNb = 0; |
---|
658 | } |
---|
659 | } |
---|
660 | #endif |
---|
661 | #ifdef ASACC |
---|
662 | for (i=0; i<shmForAgg->ASNb; i++){ |
---|
663 | shmForAgg->ASTab[index][i].flowNbIN = 0; |
---|
664 | shmForAgg->ASTab[index][i].bytesNbIN = 0; |
---|
665 | shmForAgg->ASTab[index][i].pktsNbIN = 0; |
---|
666 | shmForAgg->ASTab[index][i].flowNbOUT = 0; |
---|
667 | shmForAgg->ASTab[index][i].bytesNbOUT = 0; |
---|
668 | shmForAgg->ASTab[index][i].pktsNbOUT = 0; |
---|
669 | } |
---|
670 | #endif |
---|
671 | } |
---|
672 | } |
---|
673 | sleep(10); |
---|
674 | } while (1); |
---|
675 | exit(0); |
---|
676 | } |
---|