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) |
---|
55 | { |
---|
56 | RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router)); |
---|
57 | if (tmp==NULL) { |
---|
58 | |
---|
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 | |
---|
73 | TplFlowSetPtr newRouterTplList() |
---|
74 | { |
---|
75 | TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet)); |
---|
76 | tmp->sourceId = 0; |
---|
77 | tmp->templateFlowSetId = 99; |
---|
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 | |
---|
86 | TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl) |
---|
87 | { |
---|
88 | FieldPtr tmp = NULL; |
---|
89 | if (ptpl) { |
---|
90 | while ( ptpl->fieldSet != NULL ){ |
---|
91 | if (!(ptpl->lastField->prev)) { |
---|
92 | freeField(ptpl->lastField); |
---|
93 | ptpl->lastField = NULL; |
---|
94 | ptpl->fieldSet = NULL; |
---|
95 | } else { |
---|
96 | tmp = ptpl->lastField->prev; |
---|
97 | tmp->next = NULL; |
---|
98 | freeField(ptpl->lastField); |
---|
99 | ptpl->lastField = tmp; |
---|
100 | } |
---|
101 | } |
---|
102 | free(ptpl); |
---|
103 | ptpl = NULL; |
---|
104 | } |
---|
105 | return NULL; |
---|
106 | } |
---|
107 | |
---|
108 | TplOptionPtr newRouterTplOptList() |
---|
109 | { |
---|
110 | TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption)); |
---|
111 | tmp->sourceId = 0; |
---|
112 | tmp->templateOptionId = 66; |
---|
113 | tmp->length = 0; |
---|
114 | tmp->optionScopeLg = 0; |
---|
115 | tmp->optionLg = 0; |
---|
116 | tmp->fieldSet = NULL; |
---|
117 | tmp->lastField = NULL; |
---|
118 | tmp->next = NULL; |
---|
119 | tmp->prev = NULL; |
---|
120 | return tmp; |
---|
121 | } |
---|
122 | |
---|
123 | TplOptionPtr deleteTplOption(TplOptionPtr ptplo) |
---|
124 | { |
---|
125 | FieldPtr tmp = NULL; |
---|
126 | if (ptplo) { |
---|
127 | while ( ptplo->fieldSet != NULL ){ |
---|
128 | if (!(ptplo->lastField->prev)) { |
---|
129 | freeField(ptplo->lastField); |
---|
130 | ptplo->lastField = NULL; |
---|
131 | ptplo->fieldSet = NULL; |
---|
132 | } else { |
---|
133 | tmp = ptplo->lastField->prev; |
---|
134 | tmp->next = NULL; |
---|
135 | freeField(ptplo->lastField); |
---|
136 | ptplo->lastField = tmp; |
---|
137 | } |
---|
138 | } |
---|
139 | free(ptplo); |
---|
140 | ptplo = NULL; |
---|
141 | } |
---|
142 | return NULL; |
---|
143 | } |
---|