root/trunk/src/routers_mgmt.c @ 96

Revision 96, 6.1 KB (checked in by andreu, 14 years ago)

IPV6 links aggregation UP

  • Property svn:eol-style set to native
Line 
1/*
2 * File: routers_mgmt.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 "routers_mgmt.h"
27
28RouterPtr notExistRouter(RouterPtr rL, unsigned long address)
29{
30  RouterPtr tmp = rL;
31  int i = 0;
32  for ( ; tmp; tmp=tmp->next) {
33    i++;
34    if ( tmp->IpAddress == address ){
35      return tmp;
36    }
37  }
38  return NULL;
39}
40
41RouterPtr addRouter(RouterPtr routersList, unsigned long address, unsigned short id)
42{
43  RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router));
44  if (tmp==NULL) {
45    syslog(LOG_ERR, "ERROR in malloc in addRouter function\n");
46    exit(1);
47  } else {
48    tmp->IpAddress = address;
49    tmp->ID = id;
50    tmp->tplList = NULL;
51    tmp->tplOptList = NULL;
52#if defined(MULTISAMPLING)
53    tmp->sampled = 1;
54#else
55    tmp->sampled = 0;
56#endif
57    tmp->next = routersList;
58    if (routersList!=NULL) { routersList->prev = tmp;}
59    tmp->prev = NULL;
60    return tmp;
61  }
62}
63
64RouterPtr updateRouter(RouterPtr routersList, unsigned long address,
65                       unsigned long spled)
66{
67  RouterPtr tmp = NULL;
68  if ((tmp = notExistRouter(routersList,
69                            address))==NULL) {
70    syslog(LOG_INFO,"Router Address not registered : %lu.%lu.%lu.%lu",
71           (address>>24),
72           (address<<8>>24),
73           (address<<16>>24),
74           (address<<24>>24));
75    return routersList;
76  } else {
77    tmp->sampled = spled;
78    return tmp;
79  }
80  return NULL;
81}
82
83TplFlowSetPtr newRouterTplList()
84{
85  TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet));
86  tmp->sourceId = 0;
87  tmp->templateFlowSetId = 99;
88  tmp->fieldCount = 0;
89  tmp->fieldSet = NULL;
90  tmp->lastField = NULL;
91  tmp->next = NULL;
92  tmp->prev = NULL;
93  return tmp;
94}
95
96TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl)
97{
98  FieldPtr tmp = NULL;
99  if (ptpl) {
100    while ( ptpl->fieldSet != NULL ){
101      if (!(ptpl->lastField->prev)) {
102        freeField(ptpl->lastField);
103        ptpl->lastField = NULL;
104        ptpl->fieldSet = NULL;
105      } else {
106        tmp = ptpl->lastField->prev;
107        tmp->next = NULL;
108        freeField(ptpl->lastField);
109        ptpl->lastField = tmp;
110      }
111    }
112    free(ptpl);
113    ptpl = NULL;
114  }
115  return NULL;
116}
117
118TplOptionPtr newRouterTplOptList()
119{
120  TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption));
121  tmp->sourceId = 0;
122  tmp->templateOptionId = 66;
123  tmp->length = 0;
124  tmp->optionScopeLg = 0;
125  tmp->optionLg = 0;
126  tmp->fieldSet = NULL;
127  tmp->lastField = NULL;
128  tmp->next = NULL;
129  tmp->prev = NULL;
130  return tmp;
131}
132
133TplOptionPtr deleteTplOption(TplOptionPtr ptplo)
134{
135  FieldPtr tmp = NULL;
136  if (ptplo) {
137    while ( ptplo->fieldSet != NULL ){
138      if (!(ptplo->lastField->prev)) {
139        freeField(ptplo->lastField);
140        ptplo->lastField = NULL;
141        ptplo->fieldSet = NULL;
142      } else {
143        tmp = ptplo->lastField->prev;
144        tmp->next = NULL;
145        freeField(ptplo->lastField);
146        ptplo->lastField = tmp;
147      }
148    }
149    free(ptplo);
150    ptplo = NULL;
151  }
152  return NULL; /* FIXME I don't known */
153}
154
155#ifdef IPV4AGGIDSNMP
156int getSNMPIndexList(char *filename, RouterPtr routersListPtr)
157{
158  FILE *indexFile = NULL;
159  char line[200];
160  int cptLine = 0;
161  char tindex[5];
162  char ttoken[2];
163  char tid[2];
164  char tad[16];
165  int index = 0;
166  int i = 0;
167  unsigned short n0, n1, n2, n3;
168  unsigned char buffer4[4];
169  unsigned long ipAddress;
170  RouterPtr routerTmp = NULL;
171  unsigned short snmpIndex = 0;
172  unsigned short snmpCpt = 0;
173
174  if (!(indexFile = fopen(filename, "r"))) {
175    fprintf (stderr, "error during %s opening\n", filename);
176    exit(1);
177  }
178  while ( fgets(line, 200, indexFile) != 0) {   
179    cptLine++;
180    if ( strspn(line, "R") == 1 ) {
181      if (sscanf(line, "%s %s\n",
182                 ttoken,
183                 tad) == 0) {
184        fprintf(stderr, "Error in file %s, line %d\n",
185                filename, cptLine);
186        exit(1);
187      }
188      if (sscanf(tad,"%hu.%hu.%hu.%hu\n",&n0,&n1,&n2,&n3) == 0){
189        fprintf(stderr, "Address error in file %s, line %d\n",
190                filename, cptLine);
191        exit(1);
192      }
193      buffer4[3] = (unsigned char)n0;
194      buffer4[2] = (unsigned char)n1;
195      buffer4[1] = (unsigned char)n2;
196      buffer4[0] = (unsigned char)n3;   
197      ipAddress = *((unsigned long*)(&buffer4));
198      if ((routerTmp = notExistRouter(routersListPtr,
199                                      ipAddress))==NULL){
200        fprintf(stderr, "Error in file %s, line %d : IP unknown : %lu\n",
201                filename, cptLine, ipAddress);
202        exit(1);
203      }
204      for (i=0; i<MAX_INDEX_BY_ROUTER; i++) {
205        routerTmp->snmpIndexType[i] = 2;
206        routerTmp->snmpIndexID[i] = 0;
207      }     
208      snmpCpt = 0;
209    }else{
210      if (snmpCpt==0){
211        routerTmp->snmpIndexType[0] = 1;
212        routerTmp->snmpIndexID[0] = 0;
213        snmpCpt++;
214      }
215      if ( strspn(line, "I") == 1 ) {
216        if (sscanf(line, "%s %s %s\n",
217                   ttoken,
218                   tindex,
219                   tid) == 0) {
220          fprintf(stderr, "Error in file %s, line %d\n",
221                  filename, cptLine);
222          exit(1);
223        }
224        index = atoi(tindex);
225        if ( strcmp(tid, "B") == 0 ) {
226          routerTmp->snmpIndexList[index] = 0;
227          routerTmp->snmpIndexID[snmpCpt] = index;
228          routerTmp->snmpIndexType[snmpCpt] = 0;
229/*        fprintf(stderr, "snmpCpt %hu --> 0 \n", snmpCpt); */
230        } else if ( strcmp(tid, "C") == 0 ) {
231          routerTmp->snmpIndexList[index] = 1;
232          routerTmp->snmpIndexID[snmpCpt] = index;
233          routerTmp->snmpIndexType[snmpCpt] = 1;
234/*        fprintf(stderr, "snmpCpt %hu --> 1 , indexSNMP: %hu\n", snmpCpt, index); */
235        } else {
236          fprintf(stderr, "Error in file %s, line %d : bad code B or C \n",
237                  filename, cptLine);
238          exit(1);
239        }
240        snmpCpt++;
241      } else {
242        fprintf(stderr, "Error in file %s, line %d : bad index line \n",
243                filename, cptLine);
244        exit(1);
245      }
246    }
247  }
248  return 1;
249}
250#endif
Note: See TracBrowser for help on using the browser.