root/trunk/src/renetcol.c @ 59

Revision 59, 18.4 KB (checked in by andreu, 15 years ago)

new aggregation method, based on SNMP index. New parameters in renetcolParam.h and new compilation options in configure.in.

  • 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  /* the fork */
170  fprintf(stderr, "renetcol: I become a deamon, next messages via syslogd. By.\n");
171  if (fork () != 0)
172    exit (0);
173  if (setsid() == -1){
174    exit(4);
175  }
176
177  /* handler, SIGUSR1 from renetcolSender */
178  myAction.sa_handler = sigusr1Mgmt;
179  myAction.sa_flags = SA_RESTART;
180  sigemptyset (&(myAction.sa_mask));
181  sigaddset (&(myAction.sa_mask), SIGALRM);
182  sigaction (SIGUSR1, &myAction, NULL);
183
184  /* Cache for fast rules access */
185  setCache(myPtrs.rulesListPtr);
186  myPtrs.rulesAddressPtr = (RuleDefPtr *)rulesAddress;
187
188  /* IPC messages queue init */
189  myKey = createKey(argv[0]);
190  myQueue = createQueue(myKey);
191  sendMyPid(myQueue);
192
193  /* get SNMP index information */
194  k = getSNMPIndexList(INTERFACES_TYPE_LIST, routersListPtr);
195
196  /* INIT THE CURRENTS VARIABLES*/
197  myPtrs.currentRouterPtr = routersListPtr;
198  myPtrs.currentHeaderV9Ptr = (NetFlowV9HeaderPtr)
199    malloc(sizeof(struct NetFlowV9Header));
200  myPtrs.offsetV9Ptr = &offsetV9;
201  myPtrs.currentFlowsetIdPtr = &currentFlowsetId;
202  myPtrs.pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram));
203  myPtrs.currentFlowsetNumberPtr = &currentFlowsetNumber;
204#ifdef IPV4AGGIDR
205  myPtrs.routersID = &indexedRouterList;
206#endif
207  myPtrs.currentV4Tab = shmForAgg->prefixV4Tab[shmForAgg->currentTable];
208  myPtrs.secondV4Tab = shmForAgg->prefixV4Tab[shmForAgg->secondTable];
209#ifdef MATRIX
210  myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
211#endif
212
213  /* INIT MATRIX TABLES */
214#ifdef MATRIX
215  for (i=0; i<ROUTER_INDEX_MAX; i++){
216    for (j=0; j<ROUTER_INDEX_MAX; j++) {
217      shmForAgg->matrixPOP[0][i][j].bytesNb = 0;
218      shmForAgg->matrixPOP[0][i][j].pktsNb = 0;
219      shmForAgg->matrixPOP[0][i][j].flowNb = 0;
220      shmForAgg->matrixPOP[1][i][j].bytesNb = 0;
221      shmForAgg->matrixPOP[1][i][j].pktsNb = 0;
222      shmForAgg->matrixPOP[1][i][j].flowNb = 0;
223    }
224  }
225#endif
226
227  /* Checkup */
228  if (myPtrs.pcktPtr==NULL) {
229    fprintf(stderr, "ERROR in struct Datagram allocation\n");
230    exit(1);
231  } else {
232    myPtrs.pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader));
233    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader));
234  }
235  if (! (myPtrs.ptr_buffer = malloc(sockBufSize))) 
236    {
237      printf("ERROR during socket buffer allocation\n");
238      exit(2);
239    }
240
241  /* INIT INPUT STREAM*/
242  initStream();
243
244  socketLoop(); /* all work on datagram is made here */
245
246  closelog();
247
248  fprintf(stderr, "END\n");
249
250  return (0);
251}
252
253/*
254 * send his PID to another program via IPC message queue
255 *
256 * @param queueID the IPC queue ident
257 *
258 */
259void 
260sendMyPid(int queueID)
261{
262  msgType myMsg;
263  char *msgTextIndex;
264  unsigned short tplMsgType = 12;
265  pid_t myPID;
266 
267  myPID = getpid();
268  msgTextIndex = mempcpy(mempcpy(myMsg.text,
269                                 &tplMsgType,
270                                 sizeof (unsigned short)
271                                 ),
272                         &myPID,
273                         sizeof(pid_t)
274                         );
275  myMsg.type = 1;
276  msgSend(queueID, myMsg);
277}
278
279/*
280 * Send the "read rules list" message to another program
281 *
282 * @param queueID the IPC queue ident
283 *
284 */
285void sendReadRulesSignal(int queueID)
286{
287  msgType myMsg;
288  char *msgTextIndex;
289  unsigned short tplMsgType = 13;
290 
291  msgTextIndex = mempcpy(myMsg.text,
292                         &tplMsgType,
293                         sizeof (unsigned short)
294                         );
295  myMsg.type = 1;
296  msgSend(queueID, myMsg);
297}
298
299/*
300 *
301 */
302void 
303sigusr1Mgmt(int num)
304{
305  sigusr1Up = 1;
306}
307
308/*
309 * init the rule structure
310 */
311void 
312initRule()
313{
314  RulesPtr tmp = NULL;
315  initCache();
316  tmp = myPtrs.rulesListPtr;
317  for ( ; tmp; tmp=tmp->next) {
318    myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
319  }
320  myPtrs.rulesListPtr = NULL;
321  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
322  tmp = myPtrs.rulesListPtr;
323  for ( ; tmp; tmp=tmp->next) {
324    if (tmp->type != 2) {
325      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
326    }
327  }
328  tmp = NULL;
329  initCache();
330  setCache(myPtrs.rulesListPtr);
331  sendReadRulesSignal(myQueue);
332#ifdef DEBUG
333  printRule(myPtrs.rulesListPtr);
334#endif
335}
336
337/*
338 * init cache table
339 */
340void
341initCache()
342{
343  int i,j;
344  for (i=0; i<FIELD_TYPE_NUMBER+1; i++){
345    for (j=0; j<MAX_RULES_PER_FIELD; j++){
346      rulesAddress[i][j] = NULL;
347    }
348  }
349}
350
351/*
352 * setCache()
353 */
354void
355setCache(RulesPtr rPtr)
356{
357  int i=0;
358  RulesPtr tmp = rPtr;
359  RuleDefPtr def = NULL;
360
361#ifdef DEBUG
362  fprintf(stderr,"Cache for Rules\n");
363#endif 
364  while (tmp) {
365    def = tmp->def;
366    while (def) {
367      i = 0;
368      while (rulesAddress[def->fieldType][i] != NULL){
369        i++;
370      }
371      rulesAddress[def->fieldType][i] = def;
372      def = def->next;
373#ifdef DEBUG
374      fprintf(stderr,"%d: %d ", def->fieldType, i);
375#endif     
376    }
377#ifdef DEBUG
378    fprintf(stderr,"\n");
379#endif     
380    tmp = tmp->next;
381  }
382}
383
384/*
385 * initStream()
386 */
387void 
388initStream()
389{
390  static unsigned short n0, n1, n2, n3;
391
392  initSocket();
393  if (sscanf(receptAddress,"%hu.%hu.%hu.%hu",&n0,&n1,&n2,&n3)==0) {
394    perror("sscanf");
395  }             
396  buffer4[0] = (unsigned char)n3;
397  buffer4[1] = (unsigned char)n2;
398  buffer4[2] = (unsigned char)n1;
399  buffer4[3] = (unsigned char)n0;
400}
401
402/*
403 * socketLoop()
404 */
405int 
406socketLoop()
407{
408  short shift;
409  short version = 0;
410  int regRouter = 0;
411  time_t now = time((time_t *)NULL);
412  int loopNb = 0;
413  int gardeFou = 0;
414  time_t lastIPOutput, lastMPLSOutput;
415
416  now = time((time_t *)NULL);
417  tmPtr = localtime(&now);
418  currentIntervalle = tmPtr->tm_min;
419  lastMPLSOutput = now;
420  lastIPOutput = now;
421  do {
422#ifdef DEBUG   
423    fprintf (stderr, "[");
424#endif
425    if ( ((tmPtr->tm_min)%STEP == 0) && (currentIntervalle != tmPtr->tm_min)){
426      currentIntervalle = tmPtr->tm_min;
427      if (shmForAgg->currentTable == 0) {
428        shmForAgg->currentTable = 1;
429        shmForAgg->secondTable = 0;
430      }else{
431        shmForAgg->currentTable = 0;
432        shmForAgg->secondTable = 1;
433      }
434      shmForAgg->readed = 1;
435#ifdef MATRIX
436      myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
437#endif
438    }
439    if (sigusr1Up == 1){
440      sigusr1Up = 0;
441      initRule();
442    }
443    socketReading();
444    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
445    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb);
446    getUdpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
447    if ( checkUdpHeader(myPtrs.pcktPtr, regRouter, receptPort) == 1 ){
448      continue;
449    }
450   
451    switch( version =
452            getNetFlowHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer,
453                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){
454    case 9:
455      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,
456                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) {
457        myPtrs.currentRouterPtr = routersListPtr;
458      }
459      currentFlowsetNumber = 0;
460      shift = 0;
461      gardeFou=0;
462      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) {
463        gardeFou++;
464        curTplFlSetPtr = NULL;
465        currentFlowsetId=getFlowsetId(currentFlowsetNumber,
466                                      myPtrs.offsetV9Ptr, myPtrs.ptr_buffer);
467        if ( currentFlowsetId == 0 ) {
468          if ( (shift = checkTemplateFlowSet(myPtrs.currentRouterPtr,
469                                             myPtrs.offsetV9Ptr,
470                                             myPtrs.ptr_buffer,
471                                             myPtrs.currentHeaderV9Ptr,
472                                             curTplFlSetPtr,
473                                             myPtrs.currentFlowsetNumberPtr,
474                                             myQueue)) < 0 ) {
475#ifdef DEBUG
476            fprintf (stderr, "w>\n");
477#endif
478            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
479          };
480          writeAllTplFlSet();
481        } else if (currentFlowsetId == 1) {
482          if ( (shift = checkTemplateOption(myPtrs.currentRouterPtr,
483                                            myPtrs.offsetV9Ptr,
484                                            myPtrs.ptr_buffer,
485                                            myPtrs.currentHeaderV9Ptr,
486                                            curTplOptionPtr,
487                                            myPtrs.currentFlowsetNumberPtr) ) < 0 ) {
488#ifdef DEBUG
489            fprintf (stderr, "wo>\n");
490#endif 
491            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
492          }
493        } else if (currentFlowsetId > 255) {
494          if ( (shift = checkDataFlowSet(shift,
495                                         &myPtrs,
496                                         myQueue,
497                                         shmForAgg->prefixV4Tab[shmForAgg->currentTable],
498                                         (size_t) shmForAgg->v4PrefixNb
499                                         ) ) < 0 ) {
500#ifdef DEBUG   
501            fprintf (stderr, "wd>\n");
502#endif
503            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
504          }
505        } else {
506#ifdef DEBUG   
507          fprintf (stderr, "1<<255\n");
508#endif
509          currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
510        }
511        if ( gardeFou > 200) { exit(-1); }
512      } /* end while flowset exist */
513      break;
514    default:
515      syslog(LOG_INFO,
516             "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu",
517             (unsigned short) version,
518             (myPtrs.pcktPtr->ipH->srcAdd>>24),
519             (myPtrs.pcktPtr->ipH->srcAdd<<8>>24),
520             (myPtrs.pcktPtr->ipH->srcAdd<<16>>24),
521             (myPtrs.pcktPtr->ipH->srcAdd<<24>>24));
522      break;
523    }
524    if (loopNb  > 1000 ){
525      /* FIXME perhaps call this function via the compilation options */
526      writeAllTplFlSet();
527#ifdef DEBUG   
528      fprintf(stderr, "W");
529#endif
530      loopNb = 0;
531    }
532    loopNb++;
533
534    now = time((time_t *)NULL);
535    tmPtr = localtime(&now);
536#ifdef DEBUG   
537    fprintf (stderr, "]\n");
538#endif
539  } while (1);
540}
541
542/*
543 * initSocket()
544 */
545short 
546initSocket()
547{
548  inputSock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
549  if (inputSock < 0)
550    {
551      syslog(LOG_ERR,"socket : %s", strerror(errno));
552      exit(1);
553    }
554  memset((void*)&name, 0, sizeof(name));
555  name.sin_family = AF_INET;
556  name.sin_addr.s_addr = htonl(INADDR_ANY);
557  if (name.sin_addr.s_addr == INADDR_NONE){
558    syslog(LOG_ERR, " INADDR_NONE ");
559    exit(1);
560  }
561  name.sin_port = htons(receptPort);
562  if (bind(inputSock,(struct sockaddr *)(&name), sizeof(name)) < 0)
563    {
564      syslog(LOG_ERR, "bind : %s", strerror(errno));
565      exit(1);
566    }                                                           
567  sockNamelg = sizeof(name);
568  if (getsockname(inputSock, (struct sockaddr *) (&name),
569                  (socklen_t *)&sockNamelg) < 0)
570    {
571      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
572      exit(1);
573    }
574  /* Here socket DGRAM creation, only to not have a unreachable service */
575  /* message in return */
576  inputSock2 = socket(AF_INET, SOCK_DGRAM, 0);
577  if (inputSock2 < 0)
578    {
579      syslog(LOG_ERR,"socket : %s", strerror(errno));
580      exit(1);
581    }
582  memset((void*)&name, 0, sizeof(name));
583  name2.sin_family = AF_INET;
584  name2.sin_addr.s_addr = htonl(INADDR_ANY);
585  if (name2.sin_addr.s_addr == INADDR_NONE){
586    syslog(LOG_ERR, " INADDR_NONE ");
587    exit(1);
588  }
589  name2.sin_port = htons(receptPort);
590  if (bind(inputSock2,(struct sockaddr *)(&name2), sizeof(name2)) < 0)
591    {
592      syslog(LOG_ERR, "bind : %s", strerror(errno));
593      exit(1);
594    }                                                           
595  sockNamelg = sizeof(name2);
596  if (getsockname(inputSock2, (struct sockaddr *) (&name2),
597                  (socklen_t *)&sockNamelg) < 0)
598    {
599      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
600      exit(1);
601    }
602  return(0);
603}
604
605
606/*
607 * init socket
608 */
609short 
610socketReading()
611{
612  signed short sockLg;
613
614  sockNameFromlg = sizeof(fromName);
615  rcv = recvfrom(inputSock, myPtrs.ptr_buffer, sockBufSize, 0,
616                 (struct sockaddr *)(&fromName),
617                 (socklen_t *)&sockNameFromlg);   
618  sockLg = rcv;
619  if (sockLg < 0) {
620    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
621    exit(1);
622  }
623  if (sockLg == 0) {
624    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
625    exit(1);
626  }
627  return(0);
628}
629 
630/*
631 * check up flow datagramme 
632 */
633short 
634checkFlow(short flowNumber)
635{
636  return(0); /* FIXME : why this function ??? */
637}
638
639/*
640 * showAllTplFlSet
641 *
642 * to use only in debug mode
643 */
644void 
645showAllTplFlSet()
646{
647  RouterPtr tmp = routersListPtr;
648  TplFlowSetPtr tmpFS;
649  TplOptionPtr tmpOP;
650  fprintf(stderr,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
651  for (; tmp; tmp=tmp->next) {
652    fprintf(stderr,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
653            (tmp->IpAddress>>24),
654            (tmp->IpAddress<<8>>24),
655            (tmp->IpAddress<<16>>24),
656            (tmp->IpAddress<<24>>24));
657    tmpFS =  tmp->tplList;
658    for (; tmpFS; tmpFS=tmpFS->next) {
659      fprintf(stderr,"TId %hu (sourceId: %lu):\n",
660              tmpFS->templateFlowSetId,
661              tmpFS->sourceId);
662      printFieldSet(stderr, tmpFS->fieldSet);
663      fprintf(stderr,"\n");
664    }
665    if ((tmpOP = tmp->tplOptList) != NULL){
666      for (; tmpOP; tmpOP=tmpOP->next) {
667        fprintf(stderr,"OpTId %hu (sourceId: %lu) >\n",
668                tmpOP->templateOptionId,
669                tmpOP->sourceId);
670        printFieldSet(stderr, tmpOP->fieldSet);
671        fprintf(stderr,"\n");
672      }
673      fprintf(stderr,"\n");
674    }
675  }
676}
677
678
679/*
680 * writeAllTplFlSet
681 *
682 */
683void 
684writeAllTplFlSet()
685{
686
687  RouterPtr tmp = routersListPtr;
688  TplFlowSetPtr tmpFS;
689  TplOptionPtr tmpOP;
690  FILE *TPLFILE;
691  if (!(TPLFILE = fopen("/tmp/TemplateDef.txt", "w"))) {
692    syslog (LOG_ERR, "error during %s opening", "/tmp/TemplateDef.txt");
693  }
694  fprintf(TPLFILE,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
695  for (; tmp; tmp=tmp->next) {
696    fprintf(TPLFILE,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
697            (tmp->IpAddress>>24),
698            (tmp->IpAddress<<8>>24),
699            (tmp->IpAddress<<16>>24),
700            (tmp->IpAddress<<24>>24));
701    tmpFS =  tmp->tplList;
702    for (; tmpFS; tmpFS=tmpFS->next) {
703      fprintf(TPLFILE,"TId %hu (sourceId: %lu):\n",
704              tmpFS->templateFlowSetId,
705              tmpFS->sourceId);
706      printFieldSet(TPLFILE, tmpFS->fieldSet);
707      fprintf(TPLFILE,"\n");
708    }
709    if ((tmpOP = tmp->tplOptList) != NULL){
710      for (; tmpOP; tmpOP=tmpOP->next) {
711        fprintf(TPLFILE,"OpTId %hu (sourceId: %lu) last %d brackets are Scope >\n lg: %hu, opScopeLg: %hu, opLg: %hu\n",
712                tmpOP->templateOptionId,
713                tmpOP->sourceId,
714                tmpOP->optionScopeLg/4,
715                tmpOP->length,
716                tmpOP->optionScopeLg,
717                tmpOP->optionLg);
718        printFieldSet(TPLFILE, tmpOP->fieldSet);
719        fprintf(TPLFILE,"\n");
720      }
721      fprintf(TPLFILE,"\n");
722    }
723  }
724  fclose(TPLFILE);
725}
Note: See TracBrowser for help on using the browser.