root/trunk/src/routers_mgmt.c @ 16

Revision 2, 3.1 KB (checked in by andreu, 17 years ago)

First RENETCOL CVS Integration

  • Property svn:eol-style set to native
Line 
1/*
2 * File: routers_mgmt.c
3 *
4 * Authors: ANDREU François-Xavier
5 *
6 * Copyright (C) 2005 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  for ( ; tmp; tmp=tmp->next) {
32    if ( tmp->IpAddress == address ){
33      return tmp;
34    }
35  }
36  return NULL;
37}
38
39RouterPtr addRouter(RouterPtr routersList, unsigned long address,
40                unsigned long spled)
41{
42  RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router));
43  if (tmp==NULL) {
44    fprintf(stderr, "ERROR in malloc in add_routers function\n");
45    exit(1);
46  } else {
47    tmp->IpAddress = address;
48    tmp->tplList = NULL;
49    tmp->tplOptList = NULL;
50    tmp->sampled = spled;
51    tmp->next = routersList;
52    if (routersList!=NULL) { routersList->prev = tmp;}
53    tmp->prev = NULL;
54    return tmp;
55  }
56}
57
58TplFlowSetPtr newRouterTplList()
59{
60  TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet));
61  tmp->sourceId = 0;
62  tmp->templateFlowSetId = 0;
63  tmp->fieldCount = 0;
64  tmp->fieldSet = NULL;
65  tmp->lastField = NULL;
66  tmp->next = NULL;
67  tmp->prev = NULL;
68  return tmp;
69}
70
71TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl)
72{
73  FieldPtr tmp = NULL;
74  if (ptpl) {
75    while ( ptpl->fieldSet != NULL ){
76      if (!(ptpl->lastField->prev)) {
77        freeField(ptpl->lastField);
78        ptpl->lastField = NULL;
79        ptpl->fieldSet = NULL;
80      } else {
81        tmp = ptpl->lastField->prev;
82        tmp->next = NULL;
83        freeField(ptpl->lastField);
84        ptpl->lastField = tmp;
85      }
86    }
87    free(ptpl);
88    ptpl = NULL;
89  }
90  return NULL; /* FIXME I don't known */
91}
92
93TplOptionPtr newRouterTplOptList()
94{
95  TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption));
96  tmp->sourceId = 0;
97  tmp->templateOptionId = 0;
98  tmp->length = 0;
99  tmp->optionScopeLg = 0;
100  tmp->optionLg = 0;
101  tmp->fieldSet = NULL;
102  tmp->lastField = NULL;
103  tmp->next = NULL;
104  tmp->prev = NULL;
105  return tmp;
106}
107
108TplOptionPtr deleteTplOption(TplOptionPtr ptplo)
109{
110  FieldPtr tmp = NULL;
111  if (ptplo) {
112    while ( ptplo->fieldSet != NULL ){
113      if (!(ptplo->lastField->prev)) {
114        freeField(ptplo->lastField);
115        ptplo->lastField = NULL;
116        ptplo->fieldSet = NULL;
117      } else {
118        tmp = ptplo->lastField->prev;
119        tmp->next = NULL;
120        freeField(ptplo->lastField);
121        ptplo->lastField = tmp;
122      }
123    }
124    free(ptplo);
125    ptplo = NULL;
126  }
127  return NULL; /* FIXME I don't known */
128}
Note: See TracBrowser for help on using the browser.