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 | for ( ; tmp; tmp=tmp->next) { |
---|
32 | if ( tmp->IpAddress == address ){ |
---|
33 | return tmp; |
---|
34 | } |
---|
35 | } |
---|
36 | return NULL; |
---|
37 | } |
---|
38 | |
---|
39 | RouterPtr 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 | |
---|
58 | TplFlowSetPtr 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 | |
---|
71 | TplFlowSetPtr 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; |
---|
91 | } |
---|
92 | |
---|
93 | TplOptionPtr 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 | |
---|
108 | TplOptionPtr 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; |
---|
128 | } |
---|