root/trunk/src/renetcolAgg.c @ 24

Revision 24, 8.0 KB (checked in by andreu, 16 years ago)

aggregation feature first E2E step : collect to rrdfiles

  • Property svn:eol-style set to native
Line 
1/*
2 * File: renetcolAgg.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2007 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include "renetcolAgg.h"
27
28struct SHMForAgg *shmForAgg;
29
30int
31main(int argc, char *argv[])
32{
33  int shmid;
34  int i, index;
35  key_t key;
36  static char buf[2048];
37  static char name[2048];
38  static char ipStr[20];
39  static char createstr[2048];
40  int res_rrd = 0;
41  FILE *fp;
42  static time_t now;
43
44  key = 8765;
45  if ((shmid = shmget(key, SHMSIZE, 0666)) < 0) {
46    perror("shmget");
47    exit(1);
48  }
49  if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) {
50    perror("shmat");
51    exit(1);
52  }
53
54  fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. By.\n");
55  if (fork () != 0)
56    exit (0);
57  if (setsid() == -1){
58    exit(4);
59  }
60 
61  do {
62    if (shmForAgg->readed == 1) {
63      shmForAgg->readed = 0;
64      if (shmForAgg->currentTable == 0) {
65        index = 1;
66      }else{
67        index = 0;
68      }
69      now = time((time_t *)NULL);
70      for (i=0; i<shmForAgg->v4PrefixNb; i++){
71       
72        /* HERE Put in RRD FILE */
73       
74        name[0] = '\0';
75        createstr[0] = '\0';
76        ipStr[0] = '\0';
77        buf[0] = '\0';
78/*      strcat(name, RRD_LOCATION); */
79        sprintf(ipStr, "%lu", shmForAgg->prefixV4Tab[index][i].beginning);
80        strcat(name, ipStr);
81/*      strcat(name, SAMPLING_HERE); */
82        strcat(name, RRD_EXTENSION);
83        fprintf(stderr, "%s\n", name);
84        if ( (fp=fopen(name,"r")) == NULL ){
85          strcat(createstr, name);
86          strcat(createstr, END_RRD_CREATE);
87          fprintf(stderr, "%s\n", createstr);
88          res_rrd = wrap_rrd_create(createstr);
89/*        printf("%d\n", res_rrd); */
90        }else{
91          fclose(fp);
92        }
93   
94        snprintf(buf, 1024, "%s%s %lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
95/*               RRD_LOCATION, */
96                 ipStr,
97                 RRD_EXTENSION,
98                 now,  /* or ctime(&now) with %s */
99                 shmForAgg->prefixV4Tab[index][i].flowNbIN,  /* 1  */
100                 shmForAgg->prefixV4Tab[index][i].flowNbOUT,
101                 shmForAgg->prefixV4Tab[index][i].bytesNbIN,
102                 shmForAgg->prefixV4Tab[index][i].bytesNbOUT,
103                 shmForAgg->prefixV4Tab[index][i].pktsNbIN,  /* 5 */
104                 shmForAgg->prefixV4Tab[index][i].pktsNbOUT,
105                 shmForAgg->prefixV4Tab[index][i].udpPktsNbIN,
106                 shmForAgg->prefixV4Tab[index][i].udpPktsNbOUT,
107                 shmForAgg->prefixV4Tab[index][i].tcpPktsNbIN,
108                 shmForAgg->prefixV4Tab[index][i].tcpPktsNbOUT, /* 10 */
109                 shmForAgg->prefixV4Tab[index][i].icmpPktsNbIN,
110                 shmForAgg->prefixV4Tab[index][i].icmpPktsNbOUT,
111                 shmForAgg->prefixV4Tab[index][i].othersPktsNbIN,
112                 shmForAgg->prefixV4Tab[index][i].othersPktsNbOUT,
113                 shmForAgg->prefixV4Tab[index][i].udpBytesNbIN,  /* 15 */
114                 shmForAgg->prefixV4Tab[index][i].udpBytesNbOUT,
115                 shmForAgg->prefixV4Tab[index][i].tcpBytesNbIN,
116                 shmForAgg->prefixV4Tab[index][i].tcpBytesNbOUT,
117                 shmForAgg->prefixV4Tab[index][i].icmpBytesNbIN,
118                 shmForAgg->prefixV4Tab[index][i].icmpBytesNbOUT,  /*  20 */
119                 shmForAgg->prefixV4Tab[index][i].othersBytesNbIN,
120                 shmForAgg->prefixV4Tab[index][i].othersBytesNbOUT,
121                 shmForAgg->prefixV4Tab[index][i].udpFlowNbIN,
122                 shmForAgg->prefixV4Tab[index][i].udpFlowNbOUT,
123                 shmForAgg->prefixV4Tab[index][i].tcpFlowNbIN, /* 25 */
124                 shmForAgg->prefixV4Tab[index][i].tcpFlowNbOUT,
125                 shmForAgg->prefixV4Tab[index][i].icmpFlowNbIN,
126                 shmForAgg->prefixV4Tab[index][i].icmpFlowNbOUT,
127                 shmForAgg->prefixV4Tab[index][i].othersFlowNbIN,
128                 shmForAgg->prefixV4Tab[index][i].othersFlowNbOUT  /* 30 */
129                 );
130        printf("\n%s\n", buf);
131        res_rrd = wrap_rrd_update(buf);
132        printf("resultat wrap_rrd_update : %d\n", res_rrd);
133       
134/*      fprintf(stderr, "%lu \n %llu flows,\t %llu bytes,\t %llu pkts\n Pkts (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Bytes (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Flows (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n \n %llu flows,\t %llu bytes,\t %llu pkts\n Pkts (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Bytes (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Flows (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n \n", */
135/*              shmForAgg->prefixV4Tab[index][i].beginning, */
136/*              shmForAgg->prefixV4Tab[index][i].flowNbIN, */
137/*              shmForAgg->prefixV4Tab[index][i].bytesNbIN, */
138/*              shmForAgg->prefixV4Tab[index][i].pktsNbIN, */
139/*              shmForAgg->prefixV4Tab[index][i].udpPktsNbIN, */
140/*              shmForAgg->prefixV4Tab[index][i].tcpPktsNbIN, */
141/*              shmForAgg->prefixV4Tab[index][i].icmpPktsNbIN, */
142/*              shmForAgg->prefixV4Tab[index][i].othersPktsNbIN, */
143/*              shmForAgg->prefixV4Tab[index][i].udpBytesNbIN, */
144/*              shmForAgg->prefixV4Tab[index][i].tcpBytesNbIN, */
145/*              shmForAgg->prefixV4Tab[index][i].icmpBytesNbIN, */
146/*              shmForAgg->prefixV4Tab[index][i].othersBytesNbIN, */
147/*              shmForAgg->prefixV4Tab[index][i].udpFlowNbIN, */
148/*              shmForAgg->prefixV4Tab[index][i].tcpFlowNbIN, */
149/*              shmForAgg->prefixV4Tab[index][i].icmpFlowNbIN, */
150/*              shmForAgg->prefixV4Tab[index][i].othersFlowNbIN, */
151/*              shmForAgg->prefixV4Tab[index][i].flowNbOUT, */
152/*              shmForAgg->prefixV4Tab[index][i].bytesNbOUT, */
153/*              shmForAgg->prefixV4Tab[index][i].pktsNbOUT, */
154/*              shmForAgg->prefixV4Tab[index][i].udpPktsNbOUT, */
155/*              shmForAgg->prefixV4Tab[index][i].tcpPktsNbOUT, */
156/*              shmForAgg->prefixV4Tab[index][i].icmpPktsNbOUT, */
157/*              shmForAgg->prefixV4Tab[index][i].othersPktsNbOUT, */
158/*              shmForAgg->prefixV4Tab[index][i].udpBytesNbOUT, */
159/*              shmForAgg->prefixV4Tab[index][i].tcpBytesNbOUT, */
160/*              shmForAgg->prefixV4Tab[index][i].icmpBytesNbOUT, */
161/*              shmForAgg->prefixV4Tab[index][i].othersBytesNbOUT, */
162/*              shmForAgg->prefixV4Tab[index][i].udpFlowNbOUT, */
163/*              shmForAgg->prefixV4Tab[index][i].tcpFlowNbOUT, */
164/*              shmForAgg->prefixV4Tab[index][i].icmpFlowNbOUT, */
165/*              shmForAgg->prefixV4Tab[index][i].othersFlowNbOUT */
166/*              ); */
167        shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
168        shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
169        shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
170        shmForAgg->prefixV4Tab[index][i].udpPktsNbIN = 0;
171        shmForAgg->prefixV4Tab[index][i].tcpPktsNbIN = 0;
172        shmForAgg->prefixV4Tab[index][i].icmpPktsNbIN = 0;
173        shmForAgg->prefixV4Tab[index][i].othersPktsNbIN = 0;
174        shmForAgg->prefixV4Tab[index][i].udpBytesNbIN = 0;
175        shmForAgg->prefixV4Tab[index][i].tcpBytesNbIN = 0;
176        shmForAgg->prefixV4Tab[index][i].icmpBytesNbIN = 0;
177        shmForAgg->prefixV4Tab[index][i].othersBytesNbIN = 0;
178        shmForAgg->prefixV4Tab[index][i].udpFlowNbIN = 0;
179        shmForAgg->prefixV4Tab[index][i].tcpFlowNbIN = 0;
180        shmForAgg->prefixV4Tab[index][i].icmpFlowNbIN = 0;
181        shmForAgg->prefixV4Tab[index][i].othersFlowNbIN = 0;
182        shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
183        shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
184        shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
185        shmForAgg->prefixV4Tab[index][i].udpPktsNbOUT = 0;
186        shmForAgg->prefixV4Tab[index][i].tcpPktsNbOUT = 0;
187        shmForAgg->prefixV4Tab[index][i].icmpPktsNbOUT = 0;
188        shmForAgg->prefixV4Tab[index][i].othersPktsNbOUT = 0;
189        shmForAgg->prefixV4Tab[index][i].udpBytesNbOUT = 0;
190        shmForAgg->prefixV4Tab[index][i].tcpBytesNbOUT = 0;
191        shmForAgg->prefixV4Tab[index][i].icmpBytesNbOUT = 0;
192        shmForAgg->prefixV4Tab[index][i].othersBytesNbOUT = 0;
193        shmForAgg->prefixV4Tab[index][i].udpFlowNbOUT = 0;
194        shmForAgg->prefixV4Tab[index][i].tcpFlowNbOUT = 0;
195        shmForAgg->prefixV4Tab[index][i].icmpFlowNbOUT = 0;
196        shmForAgg->prefixV4Tab[index][i].othersFlowNbOUT = 0;   
197      }
198    }
199    sleep(5);
200  } while (1);
201
202  exit(0);
203}
Note: See TracBrowser for help on using the browser.