root/trunk/src/routers_mgmt.c @ 29

Revision 28, 3.6 KB (checked in by andreu, 16 years ago)

debug mode in compilation option - Wno-long-long - copyright update

  • 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)
55{
56  RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router));
57  if (tmp==NULL) {
58    /* FIXME : syslog here */
59    fprintf(stderr, "ERROR in malloc in add_routers function\n");
60    exit(1);
61  } else {
62    tmp->IpAddress = address;
63    tmp->tplList = NULL;
64    tmp->tplOptList = NULL;
65    tmp->sampled = spled;
66    tmp->next = routersList;
67    if (routersList!=NULL) { routersList->prev = tmp;}
68    tmp->prev = NULL;
69    return tmp;
70  }
71}
72
73TplFlowSetPtr newRouterTplList()
74{
75  TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet));
76  tmp->sourceId = 0;
77  tmp->templateFlowSetId = 0;
78  tmp->fieldCount = 0;
79  tmp->fieldSet = NULL;
80  tmp->lastField = NULL;
81  tmp->next = NULL;
82  tmp->prev = NULL;
83  return tmp;
84}
85
86TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl)
87{
88  FieldPtr tmp = NULL;
89  if (ptpl) {
90    while ( ptpl->fieldSet != NULL ){
91/*       fprintf(stderr, "deleteTplFlSet\n"); */
92      if (!(ptpl->lastField->prev)) {
93        freeField(ptpl->lastField);
94        ptpl->lastField = NULL;
95        ptpl->fieldSet = NULL;
96      } else {
97        tmp = ptpl->lastField->prev;
98        tmp->next = NULL;
99        freeField(ptpl->lastField);
100        ptpl->lastField = tmp;
101      }
102    }
103    free(ptpl);
104    ptpl = NULL;
105  }
106  return NULL; /* FIXME I don't known */
107}
108
109TplOptionPtr newRouterTplOptList()
110{
111  TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption));
112  tmp->sourceId = 0;
113  tmp->templateOptionId = 0;
114  tmp->length = 0;
115  tmp->optionScopeLg = 0;
116  tmp->optionLg = 0;
117  tmp->fieldSet = NULL;
118  tmp->lastField = NULL;
119  tmp->next = NULL;
120  tmp->prev = NULL;
121  return tmp;
122}
123
124TplOptionPtr deleteTplOption(TplOptionPtr ptplo)
125{
126  FieldPtr tmp = NULL;
127  if (ptplo) {
128    while ( ptplo->fieldSet != NULL ){
129/*       fprintf(stderr, "deleteTplFlSet\n"); */
130      if (!(ptplo->lastField->prev)) {
131        freeField(ptplo->lastField);
132        ptplo->lastField = NULL;
133        ptplo->fieldSet = NULL;
134      } else {
135        tmp = ptplo->lastField->prev;
136        tmp->next = NULL;
137        freeField(ptplo->lastField);
138        ptplo->lastField = tmp;
139      }
140    }
141    free(ptplo);
142    ptplo = NULL;
143  }
144  return NULL; /* FIXME I don't known */
145}
Note: See TracBrowser for help on using the browser.