root/trunk/src/routers_mgmt.c @ 31

Revision 31, 3.8 KB (checked in by andreu, 16 years ago)

now, only subnets rrd files from routers who are seeing will be created - new scripts in tool

  • 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/*       fprintf (stderr, "ExistRouter %d parcours %lu.%lu.%lu.%lu\ \n",  */
36/*             i, */
37/*             address>>24, */
38/*             address<<8>>24, */
39/*             address<<16>>24, */
40/*             address<<24>>24 */
41/*             ); */
42      return tmp;
43    }
44  }
45/*   fprintf (stderr, "notExistRouter %lu.%lu.%lu.%lu\n", */
46/*         address>>24, */
47/*         address<<8>>24, */
48/*         address<<16>>24, */
49/*         address<<24>>24); */
50  return NULL;
51}
52
53RouterPtr addRouter(RouterPtr routersList, unsigned long address,
54                unsigned long spled, struct PrefixV4 *V4PTab,
55                 size_t nbPV4, struct MyPtrs *myPtrs)
56{
57  int i = 0;
58  RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router));
59  if (tmp==NULL) {
60    /* FIXME : syslog here */
61    fprintf(stderr, "ERROR in malloc in add_routers function\n");
62    exit(1);
63  } else {
64    tmp->IpAddress = address;
65    tmp->tplList = NULL;
66    tmp->tplOptList = NULL;
67    tmp->sampled = spled;
68    tmp->next = routersList;
69    if (routersList!=NULL) { routersList->prev = tmp;}
70    tmp->prev = NULL;
71    /* initialization of the subnets which depend on this routers, aim: to create the rrd files */
72    for (i=0; i<nbPV4; i++) {
73      if ( tmp->IpAddress == myPtrs->routersID[V4PTab[i].routerNb]) {
74        V4PTab[i].sampling = 1;
75        myPtrs->secondV4Tab[i].sampling = 1;
76      }
77    }
78    return tmp;
79  }
80}
81
82TplFlowSetPtr newRouterTplList()
83{
84  TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet));
85  tmp->sourceId = 0;
86  tmp->templateFlowSetId = 99;
87  tmp->fieldCount = 0;
88  tmp->fieldSet = NULL;
89  tmp->lastField = NULL;
90  tmp->next = NULL;
91  tmp->prev = NULL;
92  return tmp;
93}
94
95TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl)
96{
97  FieldPtr tmp = NULL;
98  if (ptpl) {
99    while ( ptpl->fieldSet != NULL ){
100      if (!(ptpl->lastField->prev)) {
101        freeField(ptpl->lastField);
102        ptpl->lastField = NULL;
103        ptpl->fieldSet = NULL;
104      } else {
105        tmp = ptpl->lastField->prev;
106        tmp->next = NULL;
107        freeField(ptpl->lastField);
108        ptpl->lastField = tmp;
109      }
110    }
111    free(ptpl);
112    ptpl = NULL;
113  }
114  return NULL;
115}
116
117TplOptionPtr newRouterTplOptList()
118{
119  TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption));
120  tmp->sourceId = 0;
121  tmp->templateOptionId = 66;
122  tmp->length = 0;
123  tmp->optionScopeLg = 0;
124  tmp->optionLg = 0;
125  tmp->fieldSet = NULL;
126  tmp->lastField = NULL;
127  tmp->next = NULL;
128  tmp->prev = NULL;
129  return tmp;
130}
131
132TplOptionPtr deleteTplOption(TplOptionPtr ptplo)
133{
134  FieldPtr tmp = NULL;
135  if (ptplo) {
136    while ( ptplo->fieldSet != NULL ){
137      if (!(ptplo->lastField->prev)) {
138        freeField(ptplo->lastField);
139        ptplo->lastField = NULL;
140        ptplo->fieldSet = NULL;
141      } else {
142        tmp = ptplo->lastField->prev;
143        tmp->next = NULL;
144        freeField(ptplo->lastField);
145        ptplo->lastField = tmp;
146      }
147    }
148    free(ptplo);
149    ptplo = NULL;
150  }
151  return NULL; /* FIXME I don't known */
152}
Note: See TracBrowser for help on using the browser.