root/trunk/src/renetcol.c @ 60

Revision 60, 19.1 KB (checked in by andreu, 15 years ago)

new aggregation mode based on SNMP index and AS aggregation

  • Property svn:eol-style set to native
Line 
1/*
2 * File: renetcol.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2005 2006 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 "renetcol.h"
27
28struct MyPtrs myPtrs; /* defined in routers_mgmt.h */
29
30struct SHMForAgg *shmForAgg;
31
32unsigned short currentIPOutputFile = 0;    /* index on the current IP file */
33unsigned short currentMPLSOutputFile = 0;  /* index on the current MPLS file */
34char outputName[256];
35char cof_str[20];                          /* current ouput file name */
36FILE *fIP;                                 /* pointer on the IP output file */
37FILE *fMPLS;                              /* pointer on the MPLS output file */
38
39struct sigaction myAction; /* handler for renetcolSender communication */
40sigjmp_buf contextSigalrm; /* '' */
41volatile sig_atomic_t sigusr1Up = 0;
42/* struct sigaction myAction;  for timer not used in this version */
43
44unsigned short currentIntervalle = 0;        /* based on 5 min intervalles */ 
45
46unsigned short offsetV9 = 0;                 /* index in a neflow v9 packet */
47
48unsigned char buffer1;
49unsigned char buffer2[2];
50unsigned char buffer4[4];
51unsigned char buffer6[6];
52
53short currentFlowsetNumber;
54short currentFlowsetId;
55TplFlowSetPtr curTplFlSetPtr; /* current template flowset pointer */
56TplOptionPtr curTplOptionPtr;
57RouterPtr routersListPtr;
58
59unsigned long sortedRouterList[ROUTER_INDEX_MAX];
60unsigned long indexedRouterList[ROUTER_INDEX_MAX];
61int routerNb = 0;                                  /* routers number */
62
63key_t myKey = 0;
64int myQueue = 0;
65
66/* Next structure used as cache in rules reading */
67RuleDefPtr rulesAddress[FIELD_TYPE_NUMBER+1][MAX_RULES_PER_FIELD];
68
69int reInitConf = 0;
70
71static struct tm *tmPtr;
72
73extern int errno;
74static int inputSock;
75static int sockNamelg;
76static int inputSock2;
77static int sockNameFromlg;
78static int rcv;
79static int sockBufSize = SOCKET_BUFFER_SIZE;           
80/* static unsigned short flowNumber; */
81static unsigned short receptPort = RECEPTION_PORT;
82/* static unsigned char *ptr_buffer; */
83static char *receptAddress = RECEPTION_ADDRESS;
84static struct sockaddr_in name;
85static struct sockaddr_in name2;
86static struct sockaddr_in fromName;
87
88/*
89 * Main
90 * ----
91 */
92int 
93main (int argc, char *argv[])
94{
95  RulesPtr tmp = NULL;
96  int shmid;
97  key_t key;
98  int i,j;
99  int k;
100
101#ifdef IPV4AGGIDR
102  fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on routers ID in %s file.\n", ROUTERS_LIST);
103#endif
104
105#ifdef IPV4AGGIDSNMP
106  fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST);
107#endif
108 
109  openlog(argv[0], LOG_PID, LOG_USER);
110
111  initCache();
112  /* GET the list of routers who are available to send NDE to the collector */
113  if ( (routerNb = getRegisteredRouters(ROUTERS_LIST,
114                                        &sortedRouterList[0],
115                                        &indexedRouterList[0])) == -1) {
116    fprintf(stderr,
117            "ERROR in getRegisteredRouters from file %s\n",
118            ROUTERS_LIST);
119    exit(-1);
120  }
121  /* Create the list of routers */
122  for (i=0; i<routerNb; i++){
123    fprintf(stderr, "add router : %lu\n", sortedRouterList[i]);
124    routersListPtr = addRouter(routersListPtr, sortedRouterList[i]);
125  }
126 
127  /* Shared memory */
128  key = 8765;
129  if ((shmid = shmget(key, SHMSIZE, IPC_CREAT | 0666)) < 0) {
130    perror("shmget");
131    exit(1);
132  }
133  if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) {
134    perror("shmat");
135    exit(1);
136  }
137
138  if ( (shmForAgg->v4PrefixNb = getPrefixV4(SUBNETS_LIST, &(shmForAgg->prefixV4Tab[0][0]))) < 1){
139    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_LIST);
140    exit(1);
141  } else {
142    fprintf(stderr, "%hu prefix are readed from %s\n",
143            shmForAgg->v4PrefixNb,
144            SUBNETS_LIST);
145  }
146  if ( (shmForAgg->v4PrefixNb = getPrefixV4(SUBNETS_LIST, &(shmForAgg->prefixV4Tab[1][0]))) < 1){
147    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_LIST);
148    exit(1);
149  }
150
151  shmForAgg->currentTable = 0;
152  shmForAgg->secondTable = 1;
153  shmForAgg->readed = 0;
154
155  /* get the rules */
156  myPtrs.rulesListPtr = NULL;
157  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
158  tmp = myPtrs.rulesListPtr;
159  for ( ; tmp->next; tmp=tmp->next) {
160    if (tmp->type != 2) {
161      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
162    }
163  }
164  tmp = NULL;
165#ifdef DEBUG
166  printRule(rulesListPtr);
167#endif
168
169#ifdef ASACC
170  /* get the AS list */
171  if ( (shmForAgg->ASNb = getAS(AS_LIST, &(shmForAgg->ASTab[0][0]))) < 1){
172    fprintf(stderr, "renetcol: Error in %s\n", AS_LIST);
173    exit(1);
174  } else {
175    fprintf(stderr, "%hu AS are readed from %s\n",
176            shmForAgg->ASNb,
177            AS_LIST);
178  }
179  if ( (shmForAgg->ASNb = getAS(AS_LIST, &(shmForAgg->ASTab[1][0]))) < 1){
180    fprintf(stderr, "renetcol: Error in %s\n", AS_LIST);
181    exit(1);
182  }
183#endif
184
185  /* the fork */
186  fprintf(stderr, "renetcol: I become a deamon, next messages via syslogd. By.\n");
187  if (fork () != 0)
188    exit (0);
189  if (setsid() == -1){
190    exit(4);
191  }
192
193  /* handler, SIGUSR1 from renetcolSender */
194  myAction.sa_handler = sigusr1Mgmt;
195  myAction.sa_flags = SA_RESTART;
196  sigemptyset (&(myAction.sa_mask));
197  sigaddset (&(myAction.sa_mask), SIGALRM);
198  sigaction (SIGUSR1, &myAction, NULL);
199
200  /* Cache for fast rules access */
201  setCache(myPtrs.rulesListPtr);
202  myPtrs.rulesAddressPtr = (RuleDefPtr *)rulesAddress;
203
204  /* IPC messages queue init */
205  myKey = createKey(argv[0]);
206  myQueue = createQueue(myKey);
207  sendMyPid(myQueue);
208
209  /* get SNMP index information */
210  k = getSNMPIndexList(INTERFACES_TYPE_LIST, routersListPtr);
211
212  /* INIT THE CURRENTS VARIABLES*/
213  myPtrs.currentRouterPtr = routersListPtr;
214  myPtrs.currentHeaderV9Ptr = (NetFlowV9HeaderPtr)
215    malloc(sizeof(struct NetFlowV9Header));
216  myPtrs.offsetV9Ptr = &offsetV9;
217  myPtrs.currentFlowsetIdPtr = &currentFlowsetId;
218  myPtrs.pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram));
219  myPtrs.currentFlowsetNumberPtr = &currentFlowsetNumber;
220#ifdef IPV4AGGIDR
221  myPtrs.routersID = &indexedRouterList;
222#endif
223  myPtrs.currentV4Tab = shmForAgg->prefixV4Tab[shmForAgg->currentTable];
224  myPtrs.secondV4Tab = shmForAgg->prefixV4Tab[shmForAgg->secondTable];
225#ifdef ASACC
226  myPtrs.asNb = shmForAgg->ASNb;
227  myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
228  myPtrs.secondASTab = shmForAgg->ASTab[shmForAgg->secondTable];
229#endif
230#ifdef MATRIX
231  myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
232#endif
233
234  /* INIT MATRIX TABLES */
235#ifdef MATRIX
236  for (i=0; i<ROUTER_INDEX_MAX; i++){
237    for (j=0; j<ROUTER_INDEX_MAX; j++) {
238      shmForAgg->matrixPOP[0][i][j].bytesNb = 0;
239      shmForAgg->matrixPOP[0][i][j].pktsNb = 0;
240      shmForAgg->matrixPOP[0][i][j].flowNb = 0;
241      shmForAgg->matrixPOP[1][i][j].bytesNb = 0;
242      shmForAgg->matrixPOP[1][i][j].pktsNb = 0;
243      shmForAgg->matrixPOP[1][i][j].flowNb = 0;
244    }
245  }
246#endif
247
248  /* Checkup */
249  if (myPtrs.pcktPtr==NULL) {
250    fprintf(stderr, "ERROR in struct Datagram allocation\n");
251    exit(1);
252  } else {
253    myPtrs.pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader));
254    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader));
255  }
256  if (! (myPtrs.ptr_buffer = malloc(sockBufSize))) 
257    {
258      printf("ERROR during socket buffer allocation\n");
259      exit(2);
260    }
261
262  /* INIT INPUT STREAM*/
263  initStream();
264
265  socketLoop(); /* all work on datagram is made here */
266
267  closelog();
268
269  fprintf(stderr, "END\n");
270
271  return (0);
272}
273
274/*
275 * send his PID to another program via IPC message queue
276 *
277 * @param queueID the IPC queue ident
278 *
279 */
280void 
281sendMyPid(int queueID)
282{
283  msgType myMsg;
284  char *msgTextIndex;
285  unsigned short tplMsgType = 12;
286  pid_t myPID;
287 
288  myPID = getpid();
289  msgTextIndex = mempcpy(mempcpy(myMsg.text,
290                                 &tplMsgType,
291                                 sizeof (unsigned short)
292                                 ),
293                         &myPID,
294                         sizeof(pid_t)
295                         );
296  myMsg.type = 1;
297  msgSend(queueID, myMsg);
298}
299
300/*
301 * Send the "read rules list" message to another program
302 *
303 * @param queueID the IPC queue ident
304 *
305 */
306void sendReadRulesSignal(int queueID)
307{
308  msgType myMsg;
309  char *msgTextIndex;
310  unsigned short tplMsgType = 13;
311 
312  msgTextIndex = mempcpy(myMsg.text,
313                         &tplMsgType,
314                         sizeof (unsigned short)
315                         );
316  myMsg.type = 1;
317  msgSend(queueID, myMsg);
318}
319
320/*
321 *
322 */
323void 
324sigusr1Mgmt(int num)
325{
326  sigusr1Up = 1;
327}
328
329/*
330 * init the rule structure
331 */
332void 
333initRule()
334{
335  RulesPtr tmp = NULL;
336  initCache();
337  tmp = myPtrs.rulesListPtr;
338  for ( ; tmp; tmp=tmp->next) {
339    myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
340  }
341  myPtrs.rulesListPtr = NULL;
342  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
343  tmp = myPtrs.rulesListPtr;
344  for ( ; tmp; tmp=tmp->next) {
345    if (tmp->type != 2) {
346      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
347    }
348  }
349  tmp = NULL;
350  initCache();
351  setCache(myPtrs.rulesListPtr);
352  sendReadRulesSignal(myQueue);
353#ifdef DEBUG
354  printRule(myPtrs.rulesListPtr);
355#endif
356}
357
358/*
359 * init cache table
360 */
361void
362initCache()
363{
364  int i,j;
365  for (i=0; i<FIELD_TYPE_NUMBER+1; i++){
366    for (j=0; j<MAX_RULES_PER_FIELD; j++){
367      rulesAddress[i][j] = NULL;
368    }
369  }
370}
371
372/*
373 * setCache()
374 */
375void
376setCache(RulesPtr rPtr)
377{
378  int i=0;
379  RulesPtr tmp = rPtr;
380  RuleDefPtr def = NULL;
381
382#ifdef DEBUG
383  fprintf(stderr,"Cache for Rules\n");
384#endif 
385  while (tmp) {
386    def = tmp->def;
387    while (def) {
388      i = 0;
389      while (rulesAddress[def->fieldType][i] != NULL){
390        i++;
391      }
392      rulesAddress[def->fieldType][i] = def;
393      def = def->next;
394#ifdef DEBUG
395      fprintf(stderr,"%d: %d ", def->fieldType, i);
396#endif     
397    }
398#ifdef DEBUG
399    fprintf(stderr,"\n");
400#endif     
401    tmp = tmp->next;
402  }
403}
404
405/*
406 * initStream()
407 */
408void 
409initStream()
410{
411  static unsigned short n0, n1, n2, n3;
412
413  initSocket();
414  if (sscanf(receptAddress,"%hu.%hu.%hu.%hu",&n0,&n1,&n2,&n3)==0) {
415    perror("sscanf");
416  }             
417  buffer4[0] = (unsigned char)n3;
418  buffer4[1] = (unsigned char)n2;
419  buffer4[2] = (unsigned char)n1;
420  buffer4[3] = (unsigned char)n0;
421}
422
423/*
424 * socketLoop()
425 */
426int 
427socketLoop()
428{
429  short shift;
430  short version = 0;
431  int regRouter = 0;
432  time_t now = time((time_t *)NULL);
433  int loopNb = 0;
434  int gardeFou = 0;
435  time_t lastIPOutput, lastMPLSOutput;
436
437  now = time((time_t *)NULL);
438  tmPtr = localtime(&now);
439  currentIntervalle = tmPtr->tm_min;
440  lastMPLSOutput = now;
441  lastIPOutput = now;
442  do {
443#ifdef DEBUG   
444    fprintf (stderr, "[");
445#endif
446    if ( ((tmPtr->tm_min)%STEP == 0) && (currentIntervalle != tmPtr->tm_min)){
447      currentIntervalle = tmPtr->tm_min;
448      if (shmForAgg->currentTable == 0) {
449        shmForAgg->currentTable = 1;
450        shmForAgg->secondTable = 0;
451      }else{
452        shmForAgg->currentTable = 0;
453        shmForAgg->secondTable = 1;
454      }
455      shmForAgg->readed = 1;
456#ifdef ASACC
457      myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
458#endif
459#ifdef MATRIX
460      myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
461#endif
462    }
463    if (sigusr1Up == 1){
464      sigusr1Up = 0;
465      initRule();
466    }
467    socketReading();
468    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
469    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb);
470    getUdpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
471    if ( checkUdpHeader(myPtrs.pcktPtr, regRouter, receptPort) == 1 ){
472      continue;
473    }
474   
475    switch( version =
476            getNetFlowHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer,
477                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){
478    case 9:
479      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,
480                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) {
481        myPtrs.currentRouterPtr = routersListPtr;
482      }
483      currentFlowsetNumber = 0;
484      shift = 0;
485      gardeFou=0;
486      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) {
487        gardeFou++;
488        curTplFlSetPtr = NULL;
489        currentFlowsetId=getFlowsetId(currentFlowsetNumber,
490                                      myPtrs.offsetV9Ptr, myPtrs.ptr_buffer);
491        if ( currentFlowsetId == 0 ) {
492          if ( (shift = checkTemplateFlowSet(myPtrs.currentRouterPtr,
493                                             myPtrs.offsetV9Ptr,
494                                             myPtrs.ptr_buffer,
495                                             myPtrs.currentHeaderV9Ptr,
496                                             curTplFlSetPtr,
497                                             myPtrs.currentFlowsetNumberPtr,
498                                             myQueue)) < 0 ) {
499#ifdef DEBUG
500            fprintf (stderr, "w>\n");
501#endif
502            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
503          };
504          writeAllTplFlSet();
505        } else if (currentFlowsetId == 1) {
506          if ( (shift = checkTemplateOption(myPtrs.currentRouterPtr,
507                                            myPtrs.offsetV9Ptr,
508                                            myPtrs.ptr_buffer,
509                                            myPtrs.currentHeaderV9Ptr,
510                                            curTplOptionPtr,
511                                            myPtrs.currentFlowsetNumberPtr) ) < 0 ) {
512#ifdef DEBUG
513            fprintf (stderr, "wo>\n");
514#endif 
515            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
516          }
517        } else if (currentFlowsetId > 255) {
518          if ( (shift = checkDataFlowSet(shift,
519                                         &myPtrs,
520                                         myQueue,
521                                         shmForAgg->prefixV4Tab[shmForAgg->currentTable],
522                                         (size_t) shmForAgg->v4PrefixNb
523                                         ) ) < 0 ) {
524#ifdef DEBUG   
525            fprintf (stderr, "wd>\n");
526#endif
527            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
528          }
529        } else {
530#ifdef DEBUG   
531          fprintf (stderr, "1<<255\n");
532#endif
533          currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
534        }
535        if ( gardeFou > 200) { exit(-1); }
536      } /* end while flowset exist */
537      break;
538    default:
539      syslog(LOG_INFO,
540             "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu",
541             (unsigned short) version,
542             (myPtrs.pcktPtr->ipH->srcAdd>>24),
543             (myPtrs.pcktPtr->ipH->srcAdd<<8>>24),
544             (myPtrs.pcktPtr->ipH->srcAdd<<16>>24),
545             (myPtrs.pcktPtr->ipH->srcAdd<<24>>24));
546      break;
547    }
548    if (loopNb  > 1000 ){
549      /* FIXME perhaps call this function via the compilation options */
550      writeAllTplFlSet();
551#ifdef DEBUG   
552      fprintf(stderr, "W");
553#endif
554      loopNb = 0;
555    }
556    loopNb++;
557
558    now = time((time_t *)NULL);
559    tmPtr = localtime(&now);
560#ifdef DEBUG   
561    fprintf (stderr, "]\n");
562#endif
563  } while (1);
564}
565
566/*
567 * initSocket()
568 */
569short 
570initSocket()
571{
572  inputSock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
573  if (inputSock < 0)
574    {
575      syslog(LOG_ERR,"socket : %s", strerror(errno));
576      exit(1);
577    }
578  memset((void*)&name, 0, sizeof(name));
579  name.sin_family = AF_INET;
580  name.sin_addr.s_addr = htonl(INADDR_ANY);
581  if (name.sin_addr.s_addr == INADDR_NONE){
582    syslog(LOG_ERR, " INADDR_NONE ");
583    exit(1);
584  }
585  name.sin_port = htons(receptPort);
586  if (bind(inputSock,(struct sockaddr *)(&name), sizeof(name)) < 0)
587    {
588      syslog(LOG_ERR, "bind : %s", strerror(errno));
589      exit(1);
590    }                                                           
591  sockNamelg = sizeof(name);
592  if (getsockname(inputSock, (struct sockaddr *) (&name),
593                  (socklen_t *)&sockNamelg) < 0)
594    {
595      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
596      exit(1);
597    }
598  /* Here socket DGRAM creation, only to not have a unreachable service */
599  /* message in return */
600  inputSock2 = socket(AF_INET, SOCK_DGRAM, 0);
601  if (inputSock2 < 0)
602    {
603      syslog(LOG_ERR,"socket : %s", strerror(errno));
604      exit(1);
605    }
606  memset((void*)&name, 0, sizeof(name));
607  name2.sin_family = AF_INET;
608  name2.sin_addr.s_addr = htonl(INADDR_ANY);
609  if (name2.sin_addr.s_addr == INADDR_NONE){
610    syslog(LOG_ERR, " INADDR_NONE ");
611    exit(1);
612  }
613  name2.sin_port = htons(receptPort);
614  if (bind(inputSock2,(struct sockaddr *)(&name2), sizeof(name2)) < 0)
615    {
616      syslog(LOG_ERR, "bind : %s", strerror(errno));
617      exit(1);
618    }                                                           
619  sockNamelg = sizeof(name2);
620  if (getsockname(inputSock2, (struct sockaddr *) (&name2),
621                  (socklen_t *)&sockNamelg) < 0)
622    {
623      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
624      exit(1);
625    }
626  return(0);
627}
628
629
630/*
631 * init socket
632 */
633short 
634socketReading()
635{
636  signed short sockLg;
637
638  sockNameFromlg = sizeof(fromName);
639  rcv = recvfrom(inputSock, myPtrs.ptr_buffer, sockBufSize, 0,
640                 (struct sockaddr *)(&fromName),
641                 (socklen_t *)&sockNameFromlg);   
642  sockLg = rcv;
643  if (sockLg < 0) {
644    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
645    exit(1);
646  }
647  if (sockLg == 0) {
648    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
649    exit(1);
650  }
651  return(0);
652}
653 
654/*
655 * check up flow datagramme 
656 */
657short 
658checkFlow(short flowNumber)
659{
660  return(0); /* FIXME : why this function ??? */
661}
662
663/*
664 * showAllTplFlSet
665 *
666 * to use only in debug mode
667 */
668void 
669showAllTplFlSet()
670{
671  RouterPtr tmp = routersListPtr;
672  TplFlowSetPtr tmpFS;
673  TplOptionPtr tmpOP;
674  fprintf(stderr,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
675  for (; tmp; tmp=tmp->next) {
676    fprintf(stderr,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
677            (tmp->IpAddress>>24),
678            (tmp->IpAddress<<8>>24),
679            (tmp->IpAddress<<16>>24),
680            (tmp->IpAddress<<24>>24));
681    tmpFS =  tmp->tplList;
682    for (; tmpFS; tmpFS=tmpFS->next) {
683      fprintf(stderr,"TId %hu (sourceId: %lu):\n",
684              tmpFS->templateFlowSetId,
685              tmpFS->sourceId);
686      printFieldSet(stderr, tmpFS->fieldSet);
687      fprintf(stderr,"\n");
688    }
689    if ((tmpOP = tmp->tplOptList) != NULL){
690      for (; tmpOP; tmpOP=tmpOP->next) {
691        fprintf(stderr,"OpTId %hu (sourceId: %lu) >\n",
692                tmpOP->templateOptionId,
693                tmpOP->sourceId);
694        printFieldSet(stderr, tmpOP->fieldSet);
695        fprintf(stderr,"\n");
696      }
697      fprintf(stderr,"\n");
698    }
699  }
700}
701
702
703/*
704 * writeAllTplFlSet
705 *
706 */
707void 
708writeAllTplFlSet()
709{
710
711  RouterPtr tmp = routersListPtr;
712  TplFlowSetPtr tmpFS;
713  TplOptionPtr tmpOP;
714  FILE *TPLFILE;
715  if (!(TPLFILE = fopen("/tmp/TemplateDef.txt", "w"))) {
716    syslog (LOG_ERR, "error during %s opening", "/tmp/TemplateDef.txt");
717  }
718  fprintf(TPLFILE,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
719  for (; tmp; tmp=tmp->next) {
720    fprintf(TPLFILE,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
721            (tmp->IpAddress>>24),
722            (tmp->IpAddress<<8>>24),
723            (tmp->IpAddress<<16>>24),
724            (tmp->IpAddress<<24>>24));
725    tmpFS =  tmp->tplList;
726    for (; tmpFS; tmpFS=tmpFS->next) {
727      fprintf(TPLFILE,"TId %hu (sourceId: %lu):\n",
728              tmpFS->templateFlowSetId,
729              tmpFS->sourceId);
730      printFieldSet(TPLFILE, tmpFS->fieldSet);
731      fprintf(TPLFILE,"\n");
732    }
733    if ((tmpOP = tmp->tplOptList) != NULL){
734      for (; tmpOP; tmpOP=tmpOP->next) {
735        fprintf(TPLFILE,"OpTId %hu (sourceId: %lu) last %d brackets are Scope >\n lg: %hu, opScopeLg: %hu, opLg: %hu\n",
736                tmpOP->templateOptionId,
737                tmpOP->sourceId,
738                tmpOP->optionScopeLg/4,
739                tmpOP->length,
740                tmpOP->optionScopeLg,
741                tmpOP->optionLg);
742        printFieldSet(TPLFILE, tmpOP->fieldSet);
743        fprintf(TPLFILE,"\n");
744      }
745      fprintf(TPLFILE,"\n");
746    }
747  }
748  fclose(TPLFILE);
749}
Note: See TracBrowser for help on using the browser.