Changeset 58 for trunk/src/renetcol.c

Show
Ignore:
Timestamp:
10/09/07 12:01:26 (15 years ago)
Author:
andreu
Message:

new aggregation method, new configuration files, corrections on the php script for graph generation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/renetcol.c

    r57 r58  
    3636FILE *fIP;                                 /* pointer on the IP output file */ 
    3737FILE *fMPLS;                              /* pointer on the MPLS output file */ 
    38  
    39 char *rulesFileName;                    /* file name of the rules (like acl) */ 
    40 char *configFileName;                   /* file name where routers list is */ 
    41 char *prefixV4FileName;                 /* IPv4 prefix list */ 
    4238 
    4339struct sigaction myAction; /* handler for renetcolSender communication */ 
     
    10197  key_t key; 
    10298  int i,j; 
    103    
    104   if ( argc != 4) { 
    105     fprintf (stderr, 
    106              "%s: Usage: %s <routers file> <prefix IPv4 file> <rules file>\n exp: %s routers.txt IPv4_prefix.txt rules.txt\n",  
    107              argv[0], argv[0], argv[0]); 
    108     exit(1); 
    109   } 
     99  int k; 
    110100 
    111101#ifdef IPV4AGG 
     
    114104   
    115105  openlog(argv[0], LOG_PID, LOG_USER); 
     106 
     107  initCache(); 
     108  /* GET the list of routers who are available to send NDE to the collector */ 
     109  if ( (routerNb = getRegisteredRouters(ROUTERS_LIST,  
     110                                        &sortedRouterList[0],  
     111                                        &indexedRouterList[0])) == -1) { 
     112    fprintf(stderr,  
     113            "ERROR in getRegisteredRouters from file %s\n",  
     114            ROUTERS_LIST); 
     115    exit(-1); 
     116  } 
     117  /* Create the list of routers */ 
     118  for (i=0; i<routerNb; i++){ 
     119    fprintf(stderr, "add router : %lu\n", sortedRouterList[i]); 
     120    routersListPtr = addRouter(routersListPtr, sortedRouterList[i]); 
     121  } 
    116122   
    117   configFileName = (char *) malloc((strlen(argv[1])+1) * sizeof(char)); 
    118   strcpy (configFileName, argv[1]); 
    119   prefixV4FileName = (char *) malloc((strlen(argv[2])+1) * sizeof(char)); 
    120   strcpy (prefixV4FileName, argv[2]); 
    121   rulesFileName = (char *) malloc((strlen(argv[3])+1) * sizeof(char)); 
    122   strcpy (rulesFileName, argv[3]); 
    123  
    124   initCache(); 
    125   routerNb = getRegisteredRouters(configFileName, &sortedRouterList[0],  
    126                                   &indexedRouterList[0]); 
     123  /* Shared memory */ 
    127124  key = 8765; 
    128125  if ((shmid = shmget(key, SHMSIZE, IPC_CREAT | 0666)) < 0) { 
     
    135132  } 
    136133 
    137   if ( (shmForAgg->v4PrefixNb = getPrefixV4(prefixV4FileName, &(shmForAgg->prefixV4Tab[0][0]))) < 1){ 
     134  if ( (shmForAgg->v4PrefixNb = getPrefixV4(SUBNETS_LIST, &(shmForAgg->prefixV4Tab[0][0]))) < 1){ 
    138135    fprintf(stderr, "renetcol: Error \n"); 
    139136    exit(1); 
    140137  } 
    141   if ( (shmForAgg->v4PrefixNb = getPrefixV4(prefixV4FileName, &(shmForAgg->prefixV4Tab[1][0]))) < 1){ 
     138  if ( (shmForAgg->v4PrefixNb = getPrefixV4(SUBNETS_LIST, &(shmForAgg->prefixV4Tab[1][0]))) < 1){ 
    142139    fprintf(stderr, "renetcol:  Error \n"); 
    143140    exit(1); 
     
    148145  shmForAgg->readed = 0; 
    149146 
     147  /* get the rules */ 
    150148  myPtrs.rulesListPtr = NULL; 
    151 /*   myPtrs.rulesListPtr = getLightRules(myPtrs.rulesListPtr, rulesFileName); */ 
    152   myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, rulesFileName); 
     149  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE); 
    153150  tmp = myPtrs.rulesListPtr; 
    154151  for ( ; tmp->next; tmp=tmp->next) { 
     
    162159#endif 
    163160 
    164  
     161  /* the fork */ 
    165162  fprintf(stderr, "renetcol: I become a deamon, next messages via syslogd. By.\n"); 
    166163  if (fork () != 0) 
     
    177174  sigaction (SIGUSR1, &myAction, NULL); 
    178175 
    179   /* Pointer on rules Table */ 
     176  /* Cache for fast rules access */ 
    180177  setCache(myPtrs.rulesListPtr); 
    181178  myPtrs.rulesAddressPtr = (RuleDefPtr *)rulesAddress; 
    182179 
    183   /* init IPC messages queue */ 
     180  /* IPC messages queue init */ 
    184181  myKey = createKey(argv[0]); 
    185182  myQueue = createQueue(myKey); 
    186183  sendMyPid(myQueue); 
     184 
     185  /* get SNMP index information */ 
     186  k = getSNMPIndexList(INTERFACES_TYPE_LIST, routersListPtr); 
    187187 
    188188  /* INIT THE CURRENTS VARIABLES*/ 
     
    199199  myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]); 
    200200 
     201  /* INIT MATRIX TABLES */ 
    201202  for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    202203    for (j=0; j<ROUTER_INDEX_MAX; j++) { 
     
    210211  } 
    211212 
     213  /* Checkup */ 
    212214  if (myPtrs.pcktPtr==NULL) { 
    213215    fprintf(stderr, "ERROR in struct Datagram allocation\n"); 
     
    217219    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader)); 
    218220  } 
    219  
    220221  if (! (myPtrs.ptr_buffer = malloc(sockBufSize)))   
    221222    { 
     
    304305  } 
    305306  myPtrs.rulesListPtr = NULL; 
    306   myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, rulesFileName); 
     307  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE); 
    307308  tmp = myPtrs.rulesListPtr; 
    308309  for ( ; tmp; tmp=tmp->next) { 
     
    438439      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,  
    439440                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) { 
    440         routersListPtr = addRouter(routersListPtr,  
    441                                    myPtrs.pcktPtr->ipH->srcAdd,  
    442                                    (unsigned long) 0, 
    443                                    shmForAgg->prefixV4Tab[shmForAgg->currentTable], 
    444                                    (size_t) shmForAgg->v4PrefixNb, 
    445                                    &myPtrs 
    446                                    ); 
    447441        myPtrs.currentRouterPtr = routersListPtr; 
    448442      }