Changeset 94 for trunk/src

Show
Ignore:
Timestamp:
02/06/09 16:58:57 (14 years ago)
Author:
andreu
Message:

IPv6 aggregation : prefix reading

Location:
trunk/src
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dataFlowSet.c

    r93 r94  
    44 * Authors: ANDREU Francois-Xavier  
    55 * 
    6  * Copyright (C) 2005 2006 2007 GIP RENATER  
     6 * Copyright (C) 2005 - 2009 GIP RENATER  
    77 */ 
    88 
     
    494494          } 
    495495          j++; 
    496           pos = (pftmp->fieldType)*10+j; 
     496          pos = (pftmp->fieldType)*MAX_RULES_PER_FIELD+j; 
    497497        } /* end while myPtrs->rulesAddressPtr */ 
    498498      } else { 
  • trunk/src/get_conf.c

    r86 r94  
    2727#include <string.h> 
    2828#include <stdlib.h> 
     29#include <arpa/inet.h> 
    2930 
    3031#include "get_conf.h" 
     
    488489} 
    489490 
     491/*  
     492 * prefixV6Cmp 
     493 */ 
     494int 
     495prefixV6Cmp(const void *elem1, const void *elem2){ 
     496  struct PrefixV6 *el1 = (struct PrefixV6 *) elem1; 
     497  struct PrefixV6 *el2 = (struct PrefixV6 *) elem2; 
     498 
     499  if (ntohl(el1->start[0]) < ntohl(el2->start[0])) { 
     500    return (-1); 
     501  } else if (ntohl(el1->start[0]) > ntohl(el2->start[0])) { 
     502    return (1); 
     503  } else { 
     504    if (ntohl(el1->start[1]) < ntohl(el2->start[1])) { 
     505      return (-1); 
     506    } else if (ntohl(el1->start[1]) > ntohl(el2->start[1])) { 
     507      return (1); 
     508    } else { 
     509      if (ntohl(el1->start[2]) < ntohl(el2->start[2])) { 
     510        return (-1); 
     511      } else if (ntohl(el1->start[2]) > ntohl(el2->start[2])) { 
     512        return (1); 
     513      } else { 
     514        if (ntohl(el1->start[3]) < ntohl(el2->start[3])) { 
     515          return (-1); 
     516        } else if (ntohl(el1->start[3]) > ntohl(el2->start[3])) { 
     517          return (1); 
     518        } else { 
     519          if (ntohl(el1->start[4]) < ntohl(el2->start[4])) { 
     520            return (-1); 
     521          } else if (ntohl(el1->start[4]) > ntohl(el2->start[4])) { 
     522            return (1); 
     523          } else { 
     524            if (ntohl(el1->start[5]) < ntohl(el2->start[5])) { 
     525             return (-1); 
     526            } else if (ntohl(el1->start[5]) > ntohl(el2->start[5])) { 
     527              return (1); 
     528            } else { 
     529              if (ntohl(el1->start[6]) < ntohl(el2->start[6])) { 
     530               return (-1); 
     531              } else if (ntohl(el1->start[6]) > ntohl(el2->start[6])) { 
     532                return (1); 
     533              } else { 
     534                if (ntohl(el1->start[7]) < ntohl(el2->start[7])) { 
     535                 return (-1); 
     536                } else if (ntohl(el1->start[7]) > ntohl(el2->start[7])) { 
     537                  return (1); 
     538                } else { 
     539                  return 0; 
     540                } /* 7 */ 
     541              } /* 6 */ 
     542            } /* 5 */ 
     543          } /* 4 */ 
     544        } /* 3 */ 
     545      } /* 2 */ 
     546    } /* 1 */ 
     547  } /* 0 */ 
     548} 
     549 
     550/*  
     551 * getPrefixV6() 
     552 * 
     553 * read IPv6 prefix file and sort the list 
     554 */ 
     555unsigned short getPrefixV6(char *filename, 
     556                           struct PrefixV6 *pV6TabPtr) 
     557{ 
     558  FILE *prefixFile; 
     559  char line[200]; 
     560  unsigned short counter = 0; 
     561  char s0[40]; 
     562  unsigned short n0; 
     563#if defined(MULTISAMPLING) 
     564  unsigned short n1; 
     565#endif 
     566  struct in6_addr in6addr; 
     567  struct in6_addr in6addr16; 
     568  int i = 0; 
     569  char prefixStrTab[MAX_IPV6_PREFIX][50]; 
     570  unsigned short prefixIndex = 0; 
     571  int res = 0; 
     572 
     573  if (!(prefixFile = fopen(filename, "r"))) { 
     574    fprintf (stderr, "error during file \"%s\" opening\n", filename); 
     575    exit(1); 
     576  } 
     577 
     578  for(i=0;i<MAX_IPV6_PREFIX;i++){ 
     579    pV6TabPtr[i].start[0] = 0; 
     580    pV6TabPtr[i].start[1] = 0; 
     581    pV6TabPtr[i].start[2] = 0; 
     582    pV6TabPtr[i].start[3] = 0; 
     583    pV6TabPtr[i].end[0] = 0; 
     584    pV6TabPtr[i].end[1] = 0; 
     585    pV6TabPtr[i].end[2] = 0; 
     586    pV6TabPtr[i].end[3] = 0; 
     587    pV6TabPtr[i].mask = 0; 
     588    pV6TabPtr[i].hasSubnet = 0; 
     589    pV6TabPtr[i].sampling = 0; 
     590    pV6TabPtr[i].flowNbIN = 0; 
     591    pV6TabPtr[i].bytesNbIN = 0; 
     592    pV6TabPtr[i].pktsNbIN = 0; 
     593    pV6TabPtr[i].flowNbOUT = 0; 
     594    pV6TabPtr[i].bytesNbOUT = 0; 
     595    pV6TabPtr[i].pktsNbOUT = 0; 
     596    pV6TabPtr[i].firstCoSIN = 0; 
     597    pV6TabPtr[i].secondCoSIN = 0; 
     598    pV6TabPtr[i].thirdCoSIN = 0; 
     599    pV6TabPtr[i].fourthCoSIN = 0; 
     600    pV6TabPtr[i].firstCoSOUT = 0; 
     601    pV6TabPtr[i].secondCoSOUT = 0; 
     602    pV6TabPtr[i].thirdCoSOUT = 0; 
     603    pV6TabPtr[i].fourthCoSOUT = 0; 
     604  } 
     605 
     606  while (fgets(line, 50, prefixFile) != 0) 
     607    { 
     608      strcpy(prefixStrTab[counter], line); 
     609      counter++; 
     610      if (counter == MAX_IPV6_PREFIX) { 
     611        fprintf(stderr, "bufferoverflow in getPrefixV6 function (get_conf.c)\ 
     612change the value of MAX_IPV6_PREFIX  declaration and make again a compilation \n"); 
     613        exit(1); 
     614      } 
     615    } 
     616#ifdef DEBUG 
     617  for(i=0;i<counter;i++) { 
     618    fprintf(stderr,"i : %hu - line : %s\n", i,prefixStrTab[i]); 
     619  } 
     620#endif 
     621  for(i=0;i<counter;i++) 
     622    { 
     623#if defined(IPV4AGGIDSNMP) 
     624#if defined(MULTISAMPLING) 
     625      sscanf(prefixStrTab[i],"%s %hu %hu\n", 
     626             s0,&n0,&n1); 
     627#else 
     628      sscanf(prefixStrTab[i],"%s %hu\n", 
     629             s0,&n0); 
     630#endif 
     631#endif 
     632      res = inet_pton(AF_INET6, 
     633                      s0, 
     634                      &in6addr16); 
     635      res = inet_pton(AF_INET6, 
     636                      s0, 
     637                      &in6addr); 
     638      if (res != 1){ 
     639        fprintf(stderr,"BAD Prefix %s \n",s0); 
     640      } else { 
     641        pV6TabPtr[prefixIndex].start[0] = in6addr.s6_addr32[0]; 
     642        pV6TabPtr[prefixIndex].start[1] = in6addr.s6_addr32[1]; 
     643        pV6TabPtr[prefixIndex].start[2] = in6addr.s6_addr32[2]; 
     644        pV6TabPtr[prefixIndex].start[3] = in6addr.s6_addr32[3]; 
     645        if ((unsigned short)n0 <= 16) { 
     646            in6addr16.s6_addr16[0] = htons( ntohs(in6addr16.s6_addr16[0]) |~((~0)<<(16-(n0)))); 
     647            in6addr16.s6_addr16[1] = (~0); 
     648            in6addr16.s6_addr16[2] = (~0); 
     649            in6addr16.s6_addr16[3] = (~0); 
     650            in6addr16.s6_addr16[4] = (~0); 
     651            in6addr16.s6_addr16[5] = (~0); 
     652            in6addr16.s6_addr16[6] = (~0); 
     653            in6addr16.s6_addr16[7] = (~0); 
     654        } else if ((unsigned short)n0 <= 32) { 
     655            in6addr16.s6_addr16[1] = htons( ntohs(in6addr16.s6_addr16[1]) |~((~0)<<(32-(n0)))); 
     656            in6addr16.s6_addr16[2] = (~0); 
     657            in6addr16.s6_addr16[3] = (~0); 
     658            in6addr16.s6_addr16[4] = (~0); 
     659            in6addr16.s6_addr16[5] = (~0); 
     660            in6addr16.s6_addr16[6] = (~0); 
     661            in6addr16.s6_addr16[7] = (~0); 
     662        } else if ((unsigned short)n0 <= 48) { 
     663            in6addr16.s6_addr16[2] = htons( ntohs(in6addr16.s6_addr16[2]) |~((~0)<<(48-(n0)))); 
     664            in6addr16.s6_addr16[3] = (~0); 
     665            in6addr16.s6_addr16[4] = (~0); 
     666            in6addr16.s6_addr16[5] = (~0); 
     667            in6addr16.s6_addr16[6] = (~0); 
     668            in6addr16.s6_addr16[7] = (~0); 
     669        } else if ((unsigned short)n0 <= 64) { 
     670            in6addr16.s6_addr16[3] = htons( ntohs(in6addr16.s6_addr16[3]) |~((~0)<<(64-(n0)))); 
     671            in6addr16.s6_addr16[4] = (~0); 
     672            in6addr16.s6_addr16[5] = (~0); 
     673            in6addr16.s6_addr16[6] = (~0); 
     674            in6addr16.s6_addr16[7] = (~0); 
     675        } else if ((unsigned short)n0 <= 80) { 
     676            in6addr16.s6_addr16[4] = htons( ntohs(in6addr16.s6_addr16[4]) |~((~0)<<(80-(n0)))); 
     677            in6addr16.s6_addr16[5] = (~0); 
     678            in6addr16.s6_addr16[6] = (~0); 
     679            in6addr16.s6_addr16[7] = (~0); 
     680        } else if ((unsigned short)n0 <= 96) { 
     681            in6addr16.s6_addr16[5] = htons( ntohs(in6addr16.s6_addr16[5]) |~((~0)<<(96-(n0)))); 
     682            in6addr16.s6_addr16[6] = (~0); 
     683            in6addr16.s6_addr16[7] = (~0); 
     684        } else if ((unsigned short)n0 <= 112) { 
     685            in6addr16.s6_addr16[6] = htons( ntohs(in6addr16.s6_addr16[6]) |~((~0)<<(112-(n0)))); 
     686            in6addr16.s6_addr16[7] = (~0); 
     687        } else { 
     688            in6addr16.s6_addr16[7] = htons( ntohs(in6addr16.s6_addr16[7]) |~((~0)<<(128-(n0)))); 
     689        } 
     690        pV6TabPtr[prefixIndex].end[0] = in6addr16.s6_addr32[0]; 
     691        pV6TabPtr[prefixIndex].end[1] = in6addr16.s6_addr32[1]; 
     692        pV6TabPtr[prefixIndex].end[2] = in6addr16.s6_addr32[2]; 
     693        pV6TabPtr[prefixIndex].end[3] = in6addr16.s6_addr32[3]; 
     694        pV6TabPtr[prefixIndex].mask = n0; 
     695#if defined(MULTISAMPLING) 
     696        pV6TabPtr[prefixIndex].sampling = n1; 
     697#else 
     698        pV6TabPtr[prefixIndex].sampling = 0; 
     699#endif 
     700        prefixIndex++; 
     701      } 
     702    } 
     703  qsort(prefixStrTab, prefixIndex, sizeof(struct PrefixV6), prefixV6Cmp); 
     704  if( fclose(prefixFile) == 0) { 
     705    return (prefixIndex); 
     706  } else { 
     707    fprintf(stderr,"%s not closed, \n", filename); 
     708    exit(1); 
     709    return(prefixIndex); 
     710  } 
     711} 
  • trunk/src/get_conf.h

    r61 r94  
    5454}; 
    5555 
     56struct PrefixV6{ 
     57  unsigned long start[4]; 
     58  unsigned long end[4]; 
     59  unsigned short mask;     
     60  unsigned short hasSubnet;  
     61  unsigned long sampling;  
     62  unsigned long long flowNbIN;  /* WARNING !!! */ 
     63  unsigned long long bytesNbIN; /* Here, IN means "to the prefix" */ 
     64  unsigned long long pktsNbIN;  
     65  unsigned long long flowNbOUT;  /* WARNING !!! */ 
     66  unsigned long long bytesNbOUT;  /* Here, OUT means "from the prefix" */ 
     67  unsigned long long pktsNbOUT; 
     68  unsigned long long firstCoSIN; /* only the bytes for CoS */ 
     69  unsigned long long secondCoSIN; 
     70  unsigned long long thirdCoSIN; 
     71  unsigned long long fourthCoSIN; 
     72  unsigned long long firstCoSOUT; 
     73  unsigned long long secondCoSOUT; 
     74  unsigned long long thirdCoSOUT; 
     75  unsigned long long fourthCoSOUT; 
     76}; 
     77 
    5678void initConf(char *); 
    5779int longCmp(const void *, const void *); 
     
    5981unsigned short getPrefixV4(char *, struct PrefixV4 *, struct PrefixV4 *, 
    6082                           unsigned short *); 
     83unsigned short getPrefixV6(char *, struct PrefixV6 *); 
    6184unsigned short getAS(char *, struct AS *); 
    6285 
  • trunk/src/prefix_mgmt.c

    r28 r94  
    5959} 
    6060 
     61/* 
     62 * prefV6Cmp() 
     63 */ 
     64int 
     65prefV6Cmp(const void *elem1, const void *elem2){ 
     66  struct PrefixV6 *el1 = (struct PrefixV6 *) elem1; 
     67  struct PrefixV6 *el2 = (struct PrefixV6 *) elem2; 
     68  int i; 
     69  int moreIsNecessary = 1; 
     70 
     71  for (i=0;i<4;i++) { 
     72    switch(i){ 
     73    case 0: 
     74      if ( el2->mask <= 32 ) { 
     75        if ( el2->start[i] == el1->start[i] ) { 
     76          return 0; 
     77        }else{  
     78          if (el2->end[i] < el1->start[i]) { 
     79            return 1; 
     80          }else{ 
     81            return 1; 
     82          } 
     83        } 
     84      } else { /* el2 > /32 */ 
     85        if ( el2->start[i] != el1->start[i] ) { 
     86          if (el2->end[i] < el1->start[i]) { 
     87            return 1; 
     88          }else{ 
     89            return 1; 
     90          } 
     91        } /* here we don't return, we'll continue in case */ 
     92      } 
     93      break; 
     94    case 1: 
     95      if ( el2->mask <= 64 ) { 
     96        if ( el2->start[i] == el1->start[i] ) { 
     97          return 0; 
     98        }else{  
     99          if (el2->end[i] < el1->start[i]) { 
     100            return 1; 
     101          }else{ 
     102            return 1; 
     103          } 
     104        } 
     105      } else { /* el2 > /64 */ 
     106        if ( el2->start[i] != el1->start[i] ) { 
     107          if (el2->end[i] < el1->start[i]) { 
     108            return 1; 
     109          }else{ 
     110            return 1; 
     111          } 
     112        } /* here we don't return, we'll continue in case */ 
     113      } 
     114      break; 
     115    case 2: 
     116      if ( el2->mask <= 96 ) { 
     117        if ( el2->start[i] == el1->start[i] ) { 
     118          return 0; 
     119        }else{  
     120          if (el2->end[i] < el1->start[i]) { 
     121            return 1; 
     122          }else{ 
     123            return 1; 
     124          } 
     125        } 
     126      } else { /* el2 > /96 */ 
     127        if ( el2->start[i] != el1->start[i] ) { 
     128          if (el2->end[i] < el1->start[i]) { 
     129            return 1; 
     130          }else{ 
     131            return 1; 
     132          } 
     133        } /* here we don't return, we'll continue in case */ 
     134      } 
     135      break; 
     136    case 3: 
     137      if ( el2->mask <= 128 ) { 
     138        if ( el2->start[i] == el1->start[i] ) { 
     139          return 0; 
     140        }else{  
     141          if (el2->end[i] < el1->start[i]) { 
     142            return 1; 
     143          }else{ 
     144            return 1; 
     145          } 
     146        } 
     147      } else { /* el2 > /128 */ 
     148        if ( el2->start[i] != el1->start[i] ) { 
     149          if (el2->end[i] < el1->start[i]) { 
     150            return 1; 
     151          }else{ 
     152            return 1; 
     153          } 
     154        } /* here we don't return, we'll continue in case */ 
     155      } 
     156      break; 
     157    default: 
     158      syslog(LOG_ERR,"You have won !!! This IPv6 case doesn't exist !!!!"); 
     159      exit(1); 
     160      return 0; 
     161      break; 
     162    } 
     163  } 
     164} 
  • trunk/src/renetcol.c

    r88 r94  
    44 * Authors: ANDREU Francois-Xavier  
    55 * 
    6  * Copyright (C) 2005 2006 2007 GIP RENATER  
     6 * Copyright (C) 2005 - 2009 GIP RENATER  
    77 */ 
    88 
     
    106106  fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST); 
    107107#endif 
     108#if defined(IPV6AGGIDSNMP) 
     109  fprintf(stderr, "renetcol compilation and execution with IPv6 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST); 
     110#endif 
    108111   
    109112  openlog(argv[0], LOG_PID, LOG_USER); 
     
    158161    exit(1); 
    159162  } 
     163#if defined(IPV6AGGIDSNMP) 
     164  if ( (shmForAgg->v6PrefixNb =  
     165        getPrefixV6(SUBNETS_V6_LIST,  
     166                    &(shmForAgg->prefixV6Tab[0][0]) 
     167                    )) < 1){ 
     168    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_V6_LIST); 
     169  } else { 
     170    fprintf(stderr, "We have found %hu IPv6 prefixes from %s\n",  
     171            shmForAgg->v6PrefixNb, 
     172            SUBNETS_V6_LIST); 
     173  } 
     174  if ( (shmForAgg->v6PrefixNb =  
     175        getPrefixV6(SUBNETS_V6_LIST,  
     176                    &(shmForAgg->prefixV6Tab[1][0]) 
     177                    )) < 1){ 
     178    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_V6_LIST); 
     179    exit(1); 
     180  } 
     181#endif 
     182 
    160183/*   for (i=0; i<shmForAgg->v4PrefixNb; i++){ */ 
    161184/*    fprintf(stderr, "SUPERNET : %lu, %hu\n",shmForAgg->prefixV4Tab[0][i].beginning, shmForAgg->prefixV4Tab[0][i].hasSubnet); */ 
  • trunk/src/renetcol.h

    r61 r94  
    44 * Authors: ANDREU Francois-Xavier  
    55 * 
    6  * Copyright (C) 2005 2006 2007 GIP RENATER  
     6 * Copyright (C) 2005 - 2009 GIP RENATER  
    77 */ 
    88 
     
    6969  unsigned short v4PrefixNb; 
    7070  unsigned short v4SubnetNb; 
     71  unsigned short v6PrefixNb; 
    7172#ifdef ASACC 
    7273  unsigned short ASNb; 
     
    7879  struct POP matrixPOP[2][ROUTER_INDEX_MAX][ROUTER_INDEX_MAX]; 
    7980#endif 
    80   /*  struct PrefixV6 ; */ 
     81  struct PrefixV6 prefixV6Tab[2][MAX_IPV6_PREFIX]; 
    8182}; 
    8283 
  • trunk/src/renetcolAgg.h

    r61 r94  
    5050  unsigned short v4PrefixNb; 
    5151  unsigned short v4SubnetNb; 
     52  unsigned short v6PrefixNb; 
    5253#ifdef ASACC 
    5354  unsigned short ASNb; 
     
    5960  struct POP matrixPOP[2][ROUTER_INDEX_MAX][ROUTER_INDEX_MAX]; 
    6061#endif 
    61   /*  struct PrefixV6 ; */ 
     62 struct PrefixV6 prefixV6Tab[2][MAX_IPV6_PREFIX]; 
    6263};  
  • trunk/src/renetcolParam.h

    r93 r94  
    44 * Authors: ANDREU Francois-Xavier  
    55 * 
    6  * Copyright (C) 2007 GIP RENATER  
     6 * Copyright (C) 2007-2009 GIP RENATER  
    77 */ 
    88 
     
    3333*/ 
    3434#define RECEPTION_ADDRESS "" 
     35 
    3536/*  
    3637 * your collector port to recept netflow export  
    3738 */  
    3839#define RECEPTION_PORT 1111 
     40 
    3941/*  
    4042 * routers index max + 1 (index of the beginning of the lines, and not number of routers) 
    4143 */ 
    4244#define ROUTER_INDEX_MAX 55 
     45 
    4346/*  
    4447 * FILE with your routers IP address  
    4548*/  
    4649#define ROUTERS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/routers.txt" 
     50 
    4751/*  
    4852 * FILE with your prefix/subnet  
    4953 */ 
    5054#define SUBNETS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/IPv4_Subnet_Aggregation_based_on_SNMP_index.txt" 
     55 
     56/*  
     57 * FILE with your IPv6 prefixes list 
     58 */ 
     59#define SUBNETS_V6_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/IPv6_Subnet_Aggregation_based_on_SNMP_index.txt" 
     60 
    5161/*  
    5262 * FILE with the list of AS with accounting 
    5363 */ 
    5464#define AS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/AS.txt" 
     65 
    5566/*  
    5667 * constants, here a subnet is include in a prefix  
     
    5970#define MAX_IPV4_SUBNET 1000 
    6071#define MAX_AS 3 
     72#define MAX_IPV6_PREFIX 500 
     73#define MAX_IPV6_SUBNET 100 
     74 
    6175/*  
    6276 * FILE for the rules  
    6377 */ 
    6478#define RULES_FILE "<path to renetcol>/renetcol-0.0.14beta/conf/rules.txt" 
     79 
    6580/*  
    6681 * FILE with SNMP index of the interfaces 
     
    6883 */ 
    6984#define INTERFACES_TYPE_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/SNMP_INDEX.txt" 
     85 
    7086/*  
    71  * maximum SNMP index  
     87 * maximum SNMP index for one router 
    7288 */ 
    7389#define MAX_SNMP_INDEX 900 
     90 
    7491/* 
    7592 * Path to the rrd file 
     
    92109#define STEP 5 
    93110#define FIELD_TYPE_NUMBER 216 
    94 #define MAX_RULES_PER_FIELD 10 
     111#define MAX_RULES_PER_FIELD 100 
    95112#define SHMSIZE 33554432 
    96113#define SOCKET_BUFFER_SIZE 1500 
  • trunk/src/renetcolSender.c

    r77 r94  
    7272  char filters[249]; 
    7373/*  char operator[2]; */ 
    74   char lines[256][256]; 
     74  char lines[1024][256]; /* FIXME : here perhaps use a constante like MAX_FILTERS *3 */ 
    7575  char line[256]; 
    7676  char lineCopy[256];