blob: 48577cb5ea759eb5c617d62f2b77caedba6c04a9 [file] [log] [blame]
akmhoque3560cb62012-09-09 10:52:30 -05001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
4#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
7#include <assert.h>
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11#include <sys/types.h>
12#include <signal.h>
13
14
15
16#include <ccn/ccn.h>
17#include <ccn/uri.h>
18#include <ccn/keystore.h>
19#include <ccn/signing.h>
20#include <ccn/schedule.h>
21#include <ccn/hashtb.h>
22
23#include "nlsr.h"
24#include "nlsr_npt.h"
25#include "nlsr_fib.h"
akmhoque810a5b52012-09-09 16:53:14 -050026#include "nlsr_route.h"
akmhoque3cced642012-09-24 16:20:20 -050027#include "nlsr_adl.h"
akmhoque1771c412012-11-09 13:06:08 -060028#include "utility.h"
akmhoque3560cb62012-09-09 10:52:30 -050029
30int
akmhoquede61ba92012-09-20 22:19:12 -050031add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs)
akmhoque3560cb62012-09-09 10:52:30 -050032{
33 if ( strcmp(orig_router,nlsr->router_name)== 0)
34 {
35 return -1;
36 }
akmhoque3cced642012-09-24 16:20:20 -050037
akmhoque0ed6d982013-02-22 14:28:01 -060038 struct npt_entry *ne;//=(struct npt_entry*)calloc(1,sizeof(struct npt_entry ));
akmhoque3560cb62012-09-09 10:52:30 -050039
akmhoquede61ba92012-09-20 22:19:12 -050040 int res,res_nle,res_fle;
akmhoque3560cb62012-09-09 10:52:30 -050041 struct hashtb_enumerator ee;
42 struct hashtb_enumerator *e = &ee;
akmhoque810a5b52012-09-09 16:53:14 -050043
akmhoque3560cb62012-09-09 10:52:30 -050044
45 hashtb_start(nlsr->npt, e);
akmhoque810a5b52012-09-09 16:53:14 -050046 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
akmhoque3560cb62012-09-09 10:52:30 -050047
48 if(res == HT_NEW_ENTRY)
49 {
50 ne=e->data;
51
akmhoque810a5b52012-09-09 16:53:14 -050052 ne->orig_router=(char *)malloc(strlen(orig_router)+1);
53 memset(ne->orig_router,0,strlen(orig_router)+1);
akmhoquececba942013-02-25 17:33:34 -060054 memcpy(ne->orig_router,orig_router,strlen(orig_router)+1);
akmhoque3560cb62012-09-09 10:52:30 -050055
akmhoque810a5b52012-09-09 16:53:14 -050056
akmhoquede61ba92012-09-20 22:19:12 -050057
akmhoque3560cb62012-09-09 10:52:30 -050058
akmhoque0ed6d982013-02-22 14:28:01 -060059 //struct hashtb_param param_nle = {0};
60 ne->name_list= hashtb_create(sizeof(struct name_list_entry ),NULL);
akmhoque3560cb62012-09-09 10:52:30 -050061
akmhoque810a5b52012-09-09 16:53:14 -050062 struct hashtb_enumerator eenle;
63 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -050064
akmhoque810a5b52012-09-09 16:53:14 -050065 hashtb_start(ne->name_list, enle);
66 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
akmhoque3560cb62012-09-09 10:52:30 -050067
akmhoque810a5b52012-09-09 16:53:14 -050068 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -050069 {
akmhoque0ed6d982013-02-22 14:28:01 -060070 struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -050071 nle=enle->data;
akmhoque0ed6d982013-02-22 14:28:01 -060072 nle->name=(char *)calloc(strlen(name_prefix)+1,sizeof(char));
73 //memset(nle->name,0,strlen(name_prefix)+1);
74 memcpy(nle->name,name_prefix,strlen(name_prefix)+1);
akmhoque3560cb62012-09-09 10:52:30 -050075
akmhoque810a5b52012-09-09 16:53:14 -050076
akmhoque3560cb62012-09-09 10:52:30 -050077
78 }
akmhoque810a5b52012-09-09 16:53:14 -050079 hashtb_end(enle);
80
akmhoque0ed6d982013-02-22 14:28:01 -060081 //struct hashtb_param param_fle = {0};
82 ne->face_list=hashtb_create(sizeof(struct face_list_entry), NULL);
akmhoque3560cb62012-09-09 10:52:30 -050083
akmhoquede61ba92012-09-20 22:19:12 -050084 if ( num_face > 0 )
85 {
86 struct hashtb_enumerator eef;
87 struct hashtb_enumerator *ef = &eef;
88
89 hashtb_start(ne->face_list, ef);
90 int i;
91
akmhoque3cced642012-09-24 16:20:20 -050092 for ( i=0; i < num_face ; i++)
akmhoquede61ba92012-09-20 22:19:12 -050093 {
94 int face=faces[i];
akmhoquea30cb772012-10-07 09:50:34 -050095 if ( face != NO_FACE && face != ZERO_FACE)
akmhoquede61ba92012-09-20 22:19:12 -050096 {
akmhoquea30cb772012-10-07 09:50:34 -050097 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
98
99 if ( res_fle == HT_NEW_ENTRY )
100 {
akmhoque0ed6d982013-02-22 14:28:01 -0600101 struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry));
akmhoquea30cb772012-10-07 09:50:34 -0500102 fle=ef->data;
103 fle->next_hop_face=face;
104 fle->route_cost=route_costs[i];
105 }
akmhoquede61ba92012-09-20 22:19:12 -0500106 }
107
108 }
109 hashtb_end(ef);
110 }
111
akmhoque3560cb62012-09-09 10:52:30 -0500112 }
113 else if (res == HT_OLD_ENTRY)
114 {
akmhoque3560cb62012-09-09 10:52:30 -0500115 struct npt_entry *one;
116
117 one=e->data;
118
akmhoque810a5b52012-09-09 16:53:14 -0500119 struct hashtb_enumerator eenle;
120 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500121
akmhoque810a5b52012-09-09 16:53:14 -0500122 hashtb_start(one->name_list, enle);
123 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
124
125 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500126 {
akmhoque0ed6d982013-02-22 14:28:01 -0600127 struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -0500128 nle=enle->data;
129 nle->name=(char *)malloc(strlen(name_prefix)+1);
130 memset(nle->name,0,strlen(name_prefix)+1);
131 memcpy(nle->name,name_prefix,strlen(name_prefix));
akmhoque3560cb62012-09-09 10:52:30 -0500132 }
akmhoque810a5b52012-09-09 16:53:14 -0500133 else if(res_nle == HT_OLD_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500134 {
akmhoquede61ba92012-09-20 22:19:12 -0500135
akmhoque3560cb62012-09-09 10:52:30 -0500136 }
akmhoque810a5b52012-09-09 16:53:14 -0500137 hashtb_end(enle);
138
akmhoquede61ba92012-09-20 22:19:12 -0500139 if ( num_face > 0 )
140 {
141 struct hashtb_enumerator eef;
142 struct hashtb_enumerator *ef = &eef;
143
144 hashtb_start(one->face_list, ef);
145 int i;
146
147 for ( i=0; i< num_face ; i ++)
148 {
149 int face=faces[i];
akmhoquea30cb772012-10-07 09:50:34 -0500150 if ( face != NO_FACE && face != ZERO_FACE)
akmhoquede61ba92012-09-20 22:19:12 -0500151 {
akmhoquea30cb772012-10-07 09:50:34 -0500152 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
153
154 if ( res_fle == HT_NEW_ENTRY )
155 {
akmhoque0ed6d982013-02-22 14:28:01 -0600156 struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry));
akmhoquea30cb772012-10-07 09:50:34 -0500157 fle=ef->data;
158 fle->next_hop_face=face;
159 fle->route_cost=route_costs[i];
160 }
akmhoquede61ba92012-09-20 22:19:12 -0500161 }
akmhoquede61ba92012-09-20 22:19:12 -0500162 }
163 hashtb_end(ef);
164 }
akmhoque810a5b52012-09-09 16:53:14 -0500165
akmhoque3560cb62012-09-09 10:52:30 -0500166
167 }
168 hashtb_end(e);
akmhoque3cced642012-09-24 16:20:20 -0500169
170 update_ccnd_fib_for_orig_router(orig_router);
171
akmhoque3560cb62012-09-09 10:52:30 -0500172 return res;
173}
174
akmhoque3cced642012-09-24 16:20:20 -0500175void
176update_ccnd_fib_for_orig_router(char *orig_router)
177{
178
akmhoqueb77b95f2013-02-08 12:28:47 -0600179 if ( nlsr->debugging )
180 {
181 printf("update_ccnd_fib_for_orig_router called\n");
182 }
183
akmhoque3cced642012-09-24 16:20:20 -0500184 int res;
185 struct hashtb_enumerator ee;
186 struct hashtb_enumerator *e = &ee;
187
188
189 hashtb_start(nlsr->npt, e);
190 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
191
192 if(res == HT_NEW_ENTRY)
193 {
194 hashtb_delete(e);
195 }
196 else if ( res == HT_OLD_ENTRY )
197 {
198 struct npt_entry *ne;
199 ne=e->data;
200 int num_face=hashtb_n(ne->face_list);
201 int last_face,first_face;
202
203 int *faces=(int *)malloc(num_face*sizeof(int));
204 int *route_costs=(int *)malloc(num_face*sizeof(int));
205
206 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
207 sort_faces_by_distance(faces,route_costs,0,num_face);
208
akmhoqueb77b95f2013-02-08 12:28:47 -0600209 if ( nlsr->debugging )
akmhoque3cced642012-09-24 16:20:20 -0500210 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600211 int m;
212 for ( m =0 ; m< num_face ; m++)
213 {
214 printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]);
215 }
akmhoque3cced642012-09-24 16:20:20 -0500216 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600217
218 last_face=0;
219 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoque3cced642012-09-24 16:20:20 -0500220 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600221 first_face=num_face-1;
222 }
223 else if( nlsr->max_faces_per_prefix > 0)
224 {
225 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500226 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600227 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500228 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600229 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500230 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600231 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500232 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600233
akmhoque3cced642012-09-24 16:20:20 -0500234 }
235
236 int i,j, nl_element;
237 struct name_list_entry *nle;
238 struct hashtb_enumerator eenle;
239 struct hashtb_enumerator *enle = &eenle;
240
241 hashtb_start(ne->name_list, enle);
akmhoque726197c2013-02-18 11:49:24 -0600242 nl_element=hashtb_n(ne->name_list);
akmhoque54a14f42013-02-24 06:16:20 -0600243
akmhoque726197c2013-02-18 11:49:24 -0600244 for (i=0;i<nl_element;i++)
245 {
246 nle=enle->data;
247
248 for( j=num_face-1; j>= 0; j--)
249 {
250
251 if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) )
252 {
253 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
254 }
255 }
256
257
258 hashtb_next(enle);
259 }
akmhoque726197c2013-02-18 11:49:24 -0600260 hashtb_end(enle);
akmhoque54a14f42013-02-24 06:16:20 -0600261
akmhoque726197c2013-02-18 11:49:24 -0600262
263 if ( nlsr->debugging )
264 {
265 printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face);
266 }
267
268 hashtb_start(ne->name_list, enle);
akmhoque3cced642012-09-24 16:20:20 -0500269 nl_element=hashtb_n(ne->name_list);
270
271 for (i=0;i<nl_element;i++)
272 {
273 nle=enle->data;
274
275 for( j=first_face; j>= last_face; j--)
276 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600277 if ( nlsr->debugging )
278 {
279 printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]);
280 }
281 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500282 {
akmhoque1771c412012-11-09 13:06:08 -0600283 if ( nlsr->debugging )
284 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
285 if ( nlsr->detailed_logging )
286 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -0500287 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500288 }
289 else
290 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600291 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500292 {
akmhoque1771c412012-11-09 13:06:08 -0600293 if ( nlsr->debugging )
294 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
295 if ( nlsr->detailed_logging )
296 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500297 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
298 }
299 }
300 }
akmhoquea30cb772012-10-07 09:50:34 -0500301
302
akmhoque3cced642012-09-24 16:20:20 -0500303 hashtb_next(enle);
304 }
305 hashtb_end(enle);
306
307
308
309 free(faces);
310 free(route_costs);
311
312 }
313 hashtb_end(e);
314
315}
316
akmhoqueffacaa82012-09-13 17:48:30 -0500317int
akmhoque3cced642012-09-24 16:20:20 -0500318delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix)
akmhoqueffacaa82012-09-13 17:48:30 -0500319{
320 if ( strcmp(orig_router,nlsr->router_name)== 0)
321 {
322 return -1;
323 }
324
325 struct npt_entry *ne;
326
327 int res,res_nle;
328 struct hashtb_enumerator ee;
329 struct hashtb_enumerator *e = &ee;
330
331
332 hashtb_start(nlsr->npt, e);
333 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
334
335 if(res == HT_NEW_ENTRY)
336 {
337 hashtb_delete(e);
338 return -1;
339 }
340 else if (res == HT_OLD_ENTRY)
341 {
342 ne=e->data;
343
344 struct hashtb_enumerator eenle;
345 struct hashtb_enumerator *enle = &eenle;
346
347 hashtb_start(ne->name_list, enle);
348 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
349
350 if(res_nle == HT_NEW_ENTRY )
351 {
352 hashtb_delete(enle);
353 }
354 else if(res_nle == HT_OLD_ENTRY )
355 {
akmhoque3cced642012-09-24 16:20:20 -0500356 struct name_list_entry *nle;
357
358 nle=enle->data;
359
360 int j;
361 int num_face=hashtb_n(ne->face_list);
362 int last_face,first_face;
363
364 int *faces=(int *)malloc(num_face*sizeof(int));
365 int *route_costs=(int *)malloc(num_face*sizeof(int));
366
367 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
368 sort_faces_by_distance(faces,route_costs,0,num_face);
369
370
akmhoqueb77b95f2013-02-08 12:28:47 -0600371 last_face=0;
372 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoqueffacaa82012-09-13 17:48:30 -0500373 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600374 first_face=num_face-1;
akmhoqueffacaa82012-09-13 17:48:30 -0500375 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600376 else if( nlsr->max_faces_per_prefix > 0)
akmhoque3cced642012-09-24 16:20:20 -0500377 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600378 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500379 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600380 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500381 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600382 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500383 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600384 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500385 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600386
387 }
akmhoque3cced642012-09-24 16:20:20 -0500388 for( j=first_face; j>= last_face; j--)
389 {
akmhoquea30cb772012-10-07 09:50:34 -0500390
akmhoqueb77b95f2013-02-08 12:28:47 -0600391 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500392 {
akmhoque1771c412012-11-09 13:06:08 -0600393 if ( nlsr->debugging )
394 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
395 if ( nlsr->detailed_logging )
396 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -0500397 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500398 }
399 else
400 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600401 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500402 {
akmhoque1771c412012-11-09 13:06:08 -0600403 if ( nlsr->debugging )
404 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
405 if ( nlsr->detailed_logging )
406 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500407 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
408 }
409 }
akmhoquea30cb772012-10-07 09:50:34 -0500410
akmhoque3cced642012-09-24 16:20:20 -0500411 }
412
akmhoqueffacaa82012-09-13 17:48:30 -0500413 }
414
415 hashtb_end(enle);
416 }
417
418 hashtb_end(e);
419
420 return 0;
421}
akmhoque3560cb62012-09-09 10:52:30 -0500422
423void
424print_npt(void)
425{
akmhoque1771c412012-11-09 13:06:08 -0600426
427 if ( nlsr->debugging )
428 {
429 printf("\n");
430 printf("print_npt called\n");
431 }
432 if ( nlsr->detailed_logging )
433 {
434 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
435 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n");
436 }
akmhoque3560cb62012-09-09 10:52:30 -0500437 int i, npt_element;
438
439 struct npt_entry *ne;
440
441 struct hashtb_enumerator ee;
442 struct hashtb_enumerator *e = &ee;
443
444 hashtb_start(nlsr->npt, e);
445 npt_element=hashtb_n(nlsr->npt);
446
447 for(i=0;i<npt_element;i++)
448 {
akmhoque1771c412012-11-09 13:06:08 -0600449 if ( nlsr->debugging )
450 {
451 printf("\n");
452 printf("----------NPT ENTRY %d------------------\n",i+1);
453 }
454 if ( nlsr->detailed_logging )
455 {
456 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
457 writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1);
458 }
akmhoque3560cb62012-09-09 10:52:30 -0500459 ne=e->data;
akmhoque1771c412012-11-09 13:06:08 -0600460 if ( nlsr->debugging )
461 printf(" Origination Router: %s \n",ne->orig_router);
462 if ( nlsr->detailed_logging )
463 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router);
akmhoque3560cb62012-09-09 10:52:30 -0500464
akmhoquede61ba92012-09-20 22:19:12 -0500465 int j, nl_element,face_list_element;
akmhoque810a5b52012-09-09 16:53:14 -0500466 struct name_list_entry *nle;
467 struct hashtb_enumerator eenle;
468 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500469
akmhoque810a5b52012-09-09 16:53:14 -0500470 hashtb_start(ne->name_list, enle);
471 nl_element=hashtb_n(ne->name_list);
akmhoque3560cb62012-09-09 10:52:30 -0500472
akmhoque810a5b52012-09-09 16:53:14 -0500473 for (j=0;j<nl_element;j++)
akmhoque3560cb62012-09-09 10:52:30 -0500474 {
akmhoque810a5b52012-09-09 16:53:14 -0500475 nle=enle->data;
akmhoque1771c412012-11-09 13:06:08 -0600476 if ( nlsr->debugging )
477 printf(" Name Prefix: %s \n",nle->name);
478 if ( nlsr->detailed_logging )
479 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500480 hashtb_next(enle);
akmhoque3560cb62012-09-09 10:52:30 -0500481 }
akmhoque810a5b52012-09-09 16:53:14 -0500482 hashtb_end(enle);
akmhoquede61ba92012-09-20 22:19:12 -0500483
484 struct face_list_entry *fle;
485
486 struct hashtb_enumerator eef;
487 struct hashtb_enumerator *ef = &eef;
488
489 hashtb_start(ne->face_list, ef);
490 face_list_element=hashtb_n(ne->face_list);
491 if ( face_list_element <= 0 )
492 {
akmhoque1771c412012-11-09 13:06:08 -0600493 if ( nlsr->debugging )
494 printf(" Face: No Face \n");
495 if ( nlsr->detailed_logging )
496 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
497
akmhoquede61ba92012-09-20 22:19:12 -0500498 }
499 else
500 {
501 for(j=0;j<face_list_element;j++)
502 {
503 fle=ef->data;
akmhoque1771c412012-11-09 13:06:08 -0600504 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600505 printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost);
akmhoque1771c412012-11-09 13:06:08 -0600506 if ( nlsr->detailed_logging )
507 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
akmhoquede61ba92012-09-20 22:19:12 -0500508 hashtb_next(ef);
509 }
510 }
511 hashtb_end(ef);
512
akmhoque3560cb62012-09-09 10:52:30 -0500513
514 hashtb_next(e);
515 }
516
517 hashtb_end(e);
518
akmhoque3171d652012-11-13 11:44:33 -0600519 if ( nlsr->debugging )
520 printf("\n");
521 if ( nlsr->detailed_logging )
522 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque3560cb62012-09-09 10:52:30 -0500523}
akmhoque810a5b52012-09-09 16:53:14 -0500524
525void
akmhoquede61ba92012-09-20 22:19:12 -0500526delete_orig_router_from_npt(char *orig_router)
akmhoque810a5b52012-09-09 16:53:14 -0500527{
akmhoquede61ba92012-09-20 22:19:12 -0500528 int res,num_face,num_prefix;
akmhoque810a5b52012-09-09 16:53:14 -0500529 struct npt_entry *ne;
530
531 struct hashtb_enumerator ee;
532 struct hashtb_enumerator *e = &ee;
533
534 hashtb_start(nlsr->npt, e);
535 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
536
537 if ( res == HT_OLD_ENTRY )
538 {
539 ne=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500540 num_prefix=hashtb_n(ne->name_list);
541 if ( num_prefix > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500542 {
akmhoquede61ba92012-09-20 22:19:12 -0500543 num_face=hashtb_n(ne->face_list);
544
545 if ( num_face > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500546 {
547 int j, nl_element;
548 struct name_list_entry *nle;
549 struct hashtb_enumerator eenle;
550 struct hashtb_enumerator *enle = &eenle;
551
552 hashtb_start(ne->name_list, enle);
553 nl_element=hashtb_n(ne->name_list);
554
555 for (j=0;j<nl_element;j++)
556 {
557 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500558 delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500559 hashtb_next(enle);
560 }
561 hashtb_end(enle);
562
563 }
564
565 }
akmhoque54a14f42013-02-24 06:16:20 -0600566 //hashtb_destroy(&ne->name_list);
567 //hashtb_destroy(&ne->face_list);
568 destroy_name_list(ne->name_list);
569 destroy_face_list(ne->face_list);
akmhoque810a5b52012-09-09 16:53:14 -0500570 hashtb_delete(e);
571 }
572 else if ( res == HT_NEW_ENTRY )
573 {
574 hashtb_delete(e);
575 }
576 hashtb_end(e);
577}
akmhoquefbfd0982012-09-09 20:59:03 -0500578
akmhoquede61ba92012-09-20 22:19:12 -0500579
580void
581add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
582{
akmhoque1771c412012-11-09 13:06:08 -0600583 if ( nlsr->debugging )
584 {
585 printf("add_face_to_npt_by_face_id called\n");
586 printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
587 }
588 if ( nlsr->detailed_logging )
589 {
590 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n");
591 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
592 }
akmhoquede61ba92012-09-20 22:19:12 -0500593
akmhoque1771c412012-11-09 13:06:08 -0600594
akmhoquede61ba92012-09-20 22:19:12 -0500595 int res,res1;
596 struct npt_entry *ne;
597
598 struct hashtb_enumerator ee;
599 struct hashtb_enumerator *e = &ee;
600
601 hashtb_start(nlsr->npt, e);
602 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
603
604 if ( res == HT_OLD_ENTRY )
605 {
akmhoque1771c412012-11-09 13:06:08 -0600606 if ( nlsr->debugging )
607 printf("Dest Router Found \n");
608 if ( nlsr->detailed_logging )
609 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n");
610
akmhoquede61ba92012-09-20 22:19:12 -0500611 ne=e->data;
612
613 struct hashtb_enumerator eef;
614 struct hashtb_enumerator *ef = &eef;
615
616 hashtb_start(ne->face_list, ef);
617 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
618
619 if ( res1 == HT_OLD_ENTRY )
620 {
akmhoque1771c412012-11-09 13:06:08 -0600621 if ( nlsr->debugging )
622 printf("Face Found \n");
623 if ( nlsr->detailed_logging )
624 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n");
akmhoqueb77b95f2013-02-08 12:28:47 -0600625 struct face_list_entry *fle;
akmhoquede61ba92012-09-20 22:19:12 -0500626 fle=ef->data;
627 fle->next_hop_face=face_id;
628 fle->route_cost=route_cost;
629 }
630 else if ( res1 == HT_NEW_ENTRY )
631 {
akmhoque1771c412012-11-09 13:06:08 -0600632 if ( nlsr->debugging )
633 printf("Face Not Found \n");
634 if ( nlsr->detailed_logging )
635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n");
akmhoquececba942013-02-25 17:33:34 -0600636 struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
akmhoquede61ba92012-09-20 22:19:12 -0500637 fle=ef->data;
638 fle->next_hop_face=face_id;
639 fle->route_cost=route_cost;
akmhoqueb77b95f2013-02-08 12:28:47 -0600640
641
642
643
akmhoquede61ba92012-09-20 22:19:12 -0500644 }
645 hashtb_end(ef);
646 }
647 else if (res == HT_NEW_ENTRY)
648 {
649 hashtb_delete(e);
650 }
651
652 hashtb_end(e);
653}
654
655
656void
akmhoque3cced642012-09-24 16:20:20 -0500657add_new_fib_entries_to_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500658{
akmhoque1771c412012-11-09 13:06:08 -0600659 if ( nlsr->debugging )
660 printf("add_new_fib_entries_to_npt called\n");
661 if ( nlsr->detailed_logging )
662 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n");
akmhoquede61ba92012-09-20 22:19:12 -0500663 int i,j, rt_element,face_list_element;
664
665 struct routing_table_entry *rte;
666
667 struct hashtb_enumerator ee;
668 struct hashtb_enumerator *e = &ee;
669
670 hashtb_start(nlsr->routing_table, e);
671 rt_element=hashtb_n(nlsr->routing_table);
672
673 for(i=0;i<rt_element;i++)
674 {
akmhoquede61ba92012-09-20 22:19:12 -0500675 rte=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500676
677 struct face_list_entry *fle;
678
679 struct hashtb_enumerator eef;
680 struct hashtb_enumerator *ef = &eef;
681
682 hashtb_start(rte->face_list, ef);
683 face_list_element=hashtb_n(rte->face_list);
684 if ( face_list_element <= 0 )
685 {
akmhoque1771c412012-11-09 13:06:08 -0600686 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600687 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600688 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600689 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
akmhoquede61ba92012-09-20 22:19:12 -0500690 }
691 else
692 {
693 for(j=0;j<face_list_element;j++)
694 {
695 fle=ef->data;
akmhoquede61ba92012-09-20 22:19:12 -0500696 add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost);
697 hashtb_next(ef);
698 }
699 }
700 hashtb_end(ef);
701
702 hashtb_next(e);
703 }
704
705 hashtb_end(e);
706
707}
708
709
710void
711delete_face_from_npt_by_face_id(char *dest_router, int face_id)
712{
akmhoque1771c412012-11-09 13:06:08 -0600713 if ( nlsr->debugging )
714 printf("delete_face_from_npt_by_face_id\n");
715 if ( nlsr->detailed_logging )
716 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n");
akmhoquede61ba92012-09-20 22:19:12 -0500717
718 int res,res1;
719 struct npt_entry *ne;
720
721 struct hashtb_enumerator ee;
722 struct hashtb_enumerator *e = &ee;
723
724 hashtb_start(nlsr->npt, e);
725 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
726
727 if ( res == HT_OLD_ENTRY )
728 {
729 ne=e->data;
730
731 struct hashtb_enumerator eef;
732 struct hashtb_enumerator *ef = &eef;
733
734 hashtb_start(ne->face_list, ef);
735 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
akmhoquede61ba92012-09-20 22:19:12 -0500736 if ( res1 == HT_OLD_ENTRY )
737 {
akmhoque54a14f42013-02-24 06:16:20 -0600738
akmhoquede61ba92012-09-20 22:19:12 -0500739 hashtb_delete(ef);
740 }
741 else if ( res1 == HT_NEW_ENTRY )
742 {
743 hashtb_delete(ef);
744 }
745 hashtb_end(ef);
746 }
747 else if (res == HT_NEW_ENTRY)
748 {
749 hashtb_delete(e);
750 }
751
752 hashtb_end(e);
753}
754
akmhoquede61ba92012-09-20 22:19:12 -0500755
756void
akmhoque3cced642012-09-24 16:20:20 -0500757clean_old_fib_entries_from_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500758{
759
akmhoque1771c412012-11-09 13:06:08 -0600760
761 if ( nlsr->debugging )
762 printf("clean_old_fib_entries_from_npt called\n\n");
763 if ( nlsr->detailed_logging )
764 writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n");
akmhoquede61ba92012-09-20 22:19:12 -0500765 int i, npt_element;
766
767 struct npt_entry *ne;
768
769 struct hashtb_enumerator ee;
770 struct hashtb_enumerator *e = &ee;
771
772 hashtb_start(nlsr->npt, e);
773 npt_element=hashtb_n(nlsr->npt);
774
775 for(i=0;i<npt_element;i++)
776 {
777 ne=e->data;
778
779 int j,k, nl_element,face_list_element;
780 struct face_list_entry *fle;
781
782 struct hashtb_enumerator eef;
783 struct hashtb_enumerator *ef = &eef;
784
785 hashtb_start(ne->face_list, ef);
786 face_list_element=hashtb_n(ne->face_list);
787 if ( face_list_element <= 0 )
788 {
akmhoque1771c412012-11-09 13:06:08 -0600789 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600790 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600791 if ( nlsr->detailed_logging )
792 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
793
akmhoquede61ba92012-09-20 22:19:12 -0500794 }
795 else
796 {
797 for(j=0;j<face_list_element;j++)
798 {
799 fle=ef->data;
800 int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face);
801 if ( check == 0 )
802 {
803 struct name_list_entry *nle;
804 struct hashtb_enumerator eenle;
805 struct hashtb_enumerator *enle = &eenle;
806
807 hashtb_start(ne->name_list, enle);
808 nl_element=hashtb_n(ne->name_list);
809
810 for (k=0;k<nl_element;k++)
811 {
812 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500813 if( is_neighbor(nle->name) == 0 )
814 {
akmhoque1771c412012-11-09 13:06:08 -0600815 if ( nlsr->debugging )
816 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
817 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600818 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
akmhoque3cced642012-09-24 16:20:20 -0500819 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
820 }
821
akmhoquede61ba92012-09-20 22:19:12 -0500822
823 hashtb_next(enle);
824 }
825 hashtb_end(enle);
826
akmhoqueb77b95f2013-02-08 12:28:47 -0600827
828 hashtb_delete(ef);
829 j++;
830
akmhoquede61ba92012-09-20 22:19:12 -0500831 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600832 else
833 {
834 struct name_list_entry *nle;
835 struct hashtb_enumerator eenle;
836 struct hashtb_enumerator *enle = &eenle;
837
838 hashtb_start(ne->name_list, enle);
839 nl_element=hashtb_n(ne->name_list);
840
841 for (k=0;k<nl_element;k++)
842 {
843 nle=enle->data;
844 if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face )
845 {
846 if ( nlsr->debugging )
847 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
848 if ( nlsr->detailed_logging )
849 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
850 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
851 }
852
853
854 hashtb_next(enle);
855 }
856 hashtb_end(enle);
857
858 hashtb_next(ef);
859 }
akmhoquede61ba92012-09-20 22:19:12 -0500860 }
861 }
862 hashtb_end(ef);
863
864
865 hashtb_next(e);
866 }
867
868 hashtb_end(e);
869
870}
871
872void
akmhoque3cced642012-09-24 16:20:20 -0500873update_npt_with_new_route(void)
akmhoquede61ba92012-09-20 22:19:12 -0500874{
akmhoqueb77b95f2013-02-08 12:28:47 -0600875 if ( nlsr->debugging )
876 printf("update_npt_with_new_route called\n");
877
akmhoquede61ba92012-09-20 22:19:12 -0500878 clean_old_fib_entries_from_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600879 print_npt();
akmhoquede61ba92012-09-20 22:19:12 -0500880 add_new_fib_entries_to_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600881 print_npt();
882
akmhoque3cced642012-09-24 16:20:20 -0500883 int i, npt_element;
884
885 struct npt_entry *ne;
886
887 struct hashtb_enumerator ee;
888 struct hashtb_enumerator *e = &ee;
889
890 hashtb_start(nlsr->npt, e);
891 npt_element=hashtb_n(nlsr->npt);
892
893 for(i=0;i<npt_element;i++)
894 {
895
896 ne=e->data;
897 update_ccnd_fib_for_orig_router(ne->orig_router);
898 hashtb_next(e);
899 }
900
901 hashtb_end(e);
902}
903
904
905
906void
907sort_faces_by_distance(int *faces,int *route_costs,int start,int element)
908{
909 int i,j;
910 int temp_cost;
911 int temp_face;
912
913 for ( i=start ; i < element ; i ++)
914 {
915 for( j=i+1; j<element; j ++)
916 {
917 if (route_costs[j] < route_costs[i] )
918 {
919 temp_cost=route_costs[j];
920 route_costs[j]=route_costs[i];
921 route_costs[i]=temp_cost;
922
923 temp_face=faces[j];
924 faces[j]=faces[i];
925 faces[i]=temp_face;
926 }
927 }
928 }
929
930}
931
932void
933get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces)
934{
935
936 int res,face_list_element,j;
937 struct hashtb_enumerator ee;
938 struct hashtb_enumerator *e = &ee;
939
940
941 hashtb_start(nlsr->npt, e);
942 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
943
944 if(res == HT_NEW_ENTRY)
945 {
946 hashtb_delete(e);
947 }
948 else if ( res == HT_OLD_ENTRY )
949 {
950 struct npt_entry *ne;
951 ne=e->data;
952
953 struct face_list_entry *fle;
954
955 struct hashtb_enumerator eef;
956 struct hashtb_enumerator *ef = &eef;
957
958 hashtb_start(ne->face_list, ef);
959 face_list_element=hashtb_n(ne->face_list);
960 for(j=0;j<face_list_element;j++)
961 {
962 fle=ef->data;
963 faces[j]=fle->next_hop_face;
964 route_costs[j]=fle->route_cost;
965 hashtb_next(ef);
966 }
967 hashtb_end(ef);
968
969
970 }
971 hashtb_end(e);
972
973}
974
975void
976destroy_faces_by_orig_router(char *orig_router)
977{
978
979 int res;
980 struct hashtb_enumerator ee;
981 struct hashtb_enumerator *e = &ee;
982
983
984 hashtb_start(nlsr->npt, e);
985 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
986
987 if(res == HT_NEW_ENTRY)
988 {
989 hashtb_delete(e);
990 }
991 else if ( res == HT_OLD_ENTRY )
992 {
993 struct npt_entry *ne;
994 ne=e->data;
995 int num_face=hashtb_n(ne->face_list);
996 int last_face,first_face;
997
998 int *faces=(int *)malloc(num_face*sizeof(int));
999 int *route_costs=(int *)malloc(num_face*sizeof(int));
1000
1001 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
1002 sort_faces_by_distance(faces,route_costs,0,num_face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001003 last_face=0;
akmhoque0ed6d982013-02-22 14:28:01 -06001004 if ( nlsr->max_faces_per_prefix == 0)
akmhoqueb77b95f2013-02-08 12:28:47 -06001005 {
1006 first_face=num_face-1;
1007 }
1008 else if( nlsr->max_faces_per_prefix > 0)
1009 {
1010 if ( nlsr->max_faces_per_prefix >= num_face)
1011 {
1012 first_face=num_face-1;
1013 }
1014 else if ( nlsr->max_faces_per_prefix < num_face)
1015 {
1016 first_face=nlsr->max_faces_per_prefix-1;
1017 }
1018
1019 }
akmhoque3cced642012-09-24 16:20:20 -05001020
1021 int i,j, nl_element;
1022 struct name_list_entry *nle;
1023 struct hashtb_enumerator eenle;
1024 struct hashtb_enumerator *enle = &eenle;
1025
1026 hashtb_start(ne->name_list, enle);
1027 nl_element=hashtb_n(ne->name_list);
1028
1029 for (i=0;i<nl_element;i++)
1030 {
1031 nle=enle->data;
1032
1033 for( j=first_face; j>= last_face; j--)
1034 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001035 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -05001036 {
akmhoque1771c412012-11-09 13:06:08 -06001037 if ( nlsr->debugging )
1038 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1039 if ( nlsr->detailed_logging )
1040 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -05001041 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -05001042 }
1043 else
1044 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001045 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -05001046 {
akmhoque1771c412012-11-09 13:06:08 -06001047 if ( nlsr->debugging )
1048 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1049 if ( nlsr->detailed_logging )
1050 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -05001051 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
1052 }
1053 }
1054 }
1055
1056 hashtb_next(enle);
1057 }
1058 hashtb_end(enle);
1059
1060
1061
1062 free(faces);
1063 free(route_costs);
1064
1065 }
1066 hashtb_end(e);
1067
akmhoquede61ba92012-09-20 22:19:12 -05001068}
1069
akmhoquefbfd0982012-09-09 20:59:03 -05001070void
1071destroy_all_face_by_nlsr(void)
1072{
1073 int i, npt_element;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001074
akmhoquefbfd0982012-09-09 20:59:03 -05001075 struct npt_entry *ne;
1076
1077 struct hashtb_enumerator ee;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001078 struct hashtb_enumerator *e = &ee;
1079
1080 hashtb_start(nlsr->npt, e);
akmhoquefbfd0982012-09-09 20:59:03 -05001081 npt_element=hashtb_n(nlsr->npt);
1082
1083 for(i=0;i<npt_element;i++)
1084 {
akmhoquefbfd0982012-09-09 20:59:03 -05001085 ne=e->data;
akmhoque3cced642012-09-24 16:20:20 -05001086 destroy_faces_by_orig_router(ne->orig_router);
akmhoquefbfd0982012-09-09 20:59:03 -05001087 hashtb_next(e);
1088 }
1089
1090 hashtb_end(e);
1091
akmhoque3171d652012-11-13 11:44:33 -06001092 if ( nlsr->debugging )
1093 printf("\n");
1094 if ( nlsr->detailed_logging )
1095 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoquefbfd0982012-09-09 20:59:03 -05001096}
akmhoque0ed6d982013-02-22 14:28:01 -06001097
1098void
akmhoque54a14f42013-02-24 06:16:20 -06001099destroy_name_list(struct hashtb *name_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001100{
akmhoque54a14f42013-02-24 06:16:20 -06001101 int j,nl_element;
1102 struct name_list_entry *nle;
1103 struct hashtb_enumerator eenle;
1104 struct hashtb_enumerator *enle = &eenle;
1105
1106 hashtb_start(name_list, enle);
1107 nl_element=hashtb_n(name_list);
1108
1109 for (j=0;j<nl_element;j++)
1110 {
1111 nle=enle->data;
1112 free(nle->name);
1113 hashtb_next(enle);
1114 }
1115 hashtb_end(enle);
1116
1117 hashtb_destroy(&name_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001118}
1119
1120void
akmhoque54a14f42013-02-24 06:16:20 -06001121destroy_face_list(struct hashtb *face_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001122{
akmhoque54a14f42013-02-24 06:16:20 -06001123 hashtb_destroy(&face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001124}
1125
1126void
1127destroy_npt(void)
1128{
1129
1130
1131 int i, npt_element;
1132 struct npt_entry *ne;
1133
1134 struct hashtb_enumerator ee;
1135 struct hashtb_enumerator *e = &ee;
1136
1137 hashtb_start(nlsr->npt, e);
1138 npt_element=hashtb_n(nlsr->npt);
1139
1140 for(i=0;i<npt_element;i++)
1141 {
1142 ne=e->data;
akmhoque54a14f42013-02-24 06:16:20 -06001143 destroy_name_list(ne->name_list);
1144 destroy_face_list(ne->face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001145 hashtb_next(e);
1146 }
akmhoque0ed6d982013-02-22 14:28:01 -06001147 hashtb_end(e);
akmhoque54a14f42013-02-24 06:16:20 -06001148
1149 hashtb_destroy(&nlsr->npt);
akmhoque0ed6d982013-02-22 14:28:01 -06001150}
1151