1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | #include "routers_mgmt.h" |
---|
27 | |
---|
28 | RouterPtr 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 | |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | return tmp; |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | return NULL; |
---|
51 | } |
---|
52 | |
---|
53 | RouterPtr 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 | |
---|
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 | |
---|
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 | |
---|
82 | TplFlowSetPtr 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 | |
---|
95 | TplFlowSetPtr 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 | |
---|
117 | TplOptionPtr 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 | |
---|
132 | TplOptionPtr 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; |
---|
152 | } |
---|