blob: 948e0fb4ce3c84af5d2a99a4197aa48b6f6391df [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);
54 memcpy(ne->orig_router,orig_router,strlen(orig_router));
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 {
115 free(ne);
116 struct npt_entry *one;
117
118 one=e->data;
119
akmhoque810a5b52012-09-09 16:53:14 -0500120 struct hashtb_enumerator eenle;
121 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500122
akmhoque810a5b52012-09-09 16:53:14 -0500123 hashtb_start(one->name_list, enle);
124 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
125
126 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500127 {
akmhoque0ed6d982013-02-22 14:28:01 -0600128 struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -0500129 nle=enle->data;
130 nle->name=(char *)malloc(strlen(name_prefix)+1);
131 memset(nle->name,0,strlen(name_prefix)+1);
132 memcpy(nle->name,name_prefix,strlen(name_prefix));
akmhoque3560cb62012-09-09 10:52:30 -0500133 }
akmhoque810a5b52012-09-09 16:53:14 -0500134 else if(res_nle == HT_OLD_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500135 {
akmhoquede61ba92012-09-20 22:19:12 -0500136
akmhoque3560cb62012-09-09 10:52:30 -0500137 }
akmhoque810a5b52012-09-09 16:53:14 -0500138 hashtb_end(enle);
139
akmhoquede61ba92012-09-20 22:19:12 -0500140 if ( num_face > 0 )
141 {
142 struct hashtb_enumerator eef;
143 struct hashtb_enumerator *ef = &eef;
144
145 hashtb_start(one->face_list, ef);
146 int i;
147
148 for ( i=0; i< num_face ; i ++)
149 {
150 int face=faces[i];
akmhoquea30cb772012-10-07 09:50:34 -0500151 if ( face != NO_FACE && face != ZERO_FACE)
akmhoquede61ba92012-09-20 22:19:12 -0500152 {
akmhoquea30cb772012-10-07 09:50:34 -0500153 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
154
155 if ( res_fle == HT_NEW_ENTRY )
156 {
akmhoque0ed6d982013-02-22 14:28:01 -0600157 struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry));
akmhoquea30cb772012-10-07 09:50:34 -0500158 fle=ef->data;
159 fle->next_hop_face=face;
160 fle->route_cost=route_costs[i];
161 }
akmhoquede61ba92012-09-20 22:19:12 -0500162 }
akmhoquede61ba92012-09-20 22:19:12 -0500163 }
164 hashtb_end(ef);
165 }
akmhoque810a5b52012-09-09 16:53:14 -0500166
akmhoque3560cb62012-09-09 10:52:30 -0500167
168 }
169 hashtb_end(e);
akmhoque3cced642012-09-24 16:20:20 -0500170
171 update_ccnd_fib_for_orig_router(orig_router);
172
akmhoque3560cb62012-09-09 10:52:30 -0500173 return res;
174}
175
akmhoque3cced642012-09-24 16:20:20 -0500176void
177update_ccnd_fib_for_orig_router(char *orig_router)
178{
179
akmhoqueb77b95f2013-02-08 12:28:47 -0600180 if ( nlsr->debugging )
181 {
182 printf("update_ccnd_fib_for_orig_router called\n");
183 }
184
akmhoque3cced642012-09-24 16:20:20 -0500185 int res;
186 struct hashtb_enumerator ee;
187 struct hashtb_enumerator *e = &ee;
188
189
190 hashtb_start(nlsr->npt, e);
191 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
192
193 if(res == HT_NEW_ENTRY)
194 {
195 hashtb_delete(e);
196 }
197 else if ( res == HT_OLD_ENTRY )
198 {
199 struct npt_entry *ne;
200 ne=e->data;
201 int num_face=hashtb_n(ne->face_list);
202 int last_face,first_face;
203
204 int *faces=(int *)malloc(num_face*sizeof(int));
205 int *route_costs=(int *)malloc(num_face*sizeof(int));
206
207 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
208 sort_faces_by_distance(faces,route_costs,0,num_face);
209
akmhoqueb77b95f2013-02-08 12:28:47 -0600210 if ( nlsr->debugging )
akmhoque3cced642012-09-24 16:20:20 -0500211 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600212 int m;
213 for ( m =0 ; m< num_face ; m++)
214 {
215 printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]);
216 }
akmhoque3cced642012-09-24 16:20:20 -0500217 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600218
219 last_face=0;
220 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoque3cced642012-09-24 16:20:20 -0500221 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600222 first_face=num_face-1;
223 }
224 else if( nlsr->max_faces_per_prefix > 0)
225 {
226 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500227 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600228 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500229 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600230 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500231 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600232 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500233 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600234
akmhoque3cced642012-09-24 16:20:20 -0500235 }
236
237 int i,j, nl_element;
238 struct name_list_entry *nle;
239 struct hashtb_enumerator eenle;
240 struct hashtb_enumerator *enle = &eenle;
241
242 hashtb_start(ne->name_list, enle);
akmhoque726197c2013-02-18 11:49:24 -0600243 nl_element=hashtb_n(ne->name_list);
akmhoque54a14f42013-02-24 06:16:20 -0600244
akmhoque726197c2013-02-18 11:49:24 -0600245 for (i=0;i<nl_element;i++)
246 {
247 nle=enle->data;
248
249 for( j=num_face-1; j>= 0; j--)
250 {
251
252 if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) )
253 {
254 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
255 }
256 }
257
258
259 hashtb_next(enle);
260 }
akmhoque726197c2013-02-18 11:49:24 -0600261 hashtb_end(enle);
akmhoque54a14f42013-02-24 06:16:20 -0600262
akmhoque726197c2013-02-18 11:49:24 -0600263
264 if ( nlsr->debugging )
265 {
266 printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face);
267 }
268
269 hashtb_start(ne->name_list, enle);
akmhoque3cced642012-09-24 16:20:20 -0500270 nl_element=hashtb_n(ne->name_list);
271
272 for (i=0;i<nl_element;i++)
273 {
274 nle=enle->data;
275
276 for( j=first_face; j>= last_face; j--)
277 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600278 if ( nlsr->debugging )
279 {
280 printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]);
281 }
282 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500283 {
akmhoque1771c412012-11-09 13:06:08 -0600284 if ( nlsr->debugging )
285 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
286 if ( nlsr->detailed_logging )
287 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -0500288 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500289 }
290 else
291 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600292 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500293 {
akmhoque1771c412012-11-09 13:06:08 -0600294 if ( nlsr->debugging )
295 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
296 if ( nlsr->detailed_logging )
297 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500298 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]);
299 }
300 }
301 }
akmhoquea30cb772012-10-07 09:50:34 -0500302
303
akmhoque3cced642012-09-24 16:20:20 -0500304 hashtb_next(enle);
305 }
306 hashtb_end(enle);
307
308
309
310 free(faces);
311 free(route_costs);
312
313 }
314 hashtb_end(e);
315
316}
317
akmhoqueffacaa82012-09-13 17:48:30 -0500318int
akmhoque3cced642012-09-24 16:20:20 -0500319delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix)
akmhoqueffacaa82012-09-13 17:48:30 -0500320{
321 if ( strcmp(orig_router,nlsr->router_name)== 0)
322 {
323 return -1;
324 }
325
326 struct npt_entry *ne;
327
328 int res,res_nle;
329 struct hashtb_enumerator ee;
330 struct hashtb_enumerator *e = &ee;
331
332
333 hashtb_start(nlsr->npt, e);
334 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
335
336 if(res == HT_NEW_ENTRY)
337 {
338 hashtb_delete(e);
339 return -1;
340 }
341 else if (res == HT_OLD_ENTRY)
342 {
343 ne=e->data;
344
345 struct hashtb_enumerator eenle;
346 struct hashtb_enumerator *enle = &eenle;
347
348 hashtb_start(ne->name_list, enle);
349 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
350
351 if(res_nle == HT_NEW_ENTRY )
352 {
353 hashtb_delete(enle);
354 }
355 else if(res_nle == HT_OLD_ENTRY )
356 {
akmhoque3cced642012-09-24 16:20:20 -0500357 struct name_list_entry *nle;
358
359 nle=enle->data;
360
361 int j;
362 int num_face=hashtb_n(ne->face_list);
363 int last_face,first_face;
364
365 int *faces=(int *)malloc(num_face*sizeof(int));
366 int *route_costs=(int *)malloc(num_face*sizeof(int));
367
368 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
369 sort_faces_by_distance(faces,route_costs,0,num_face);
370
371
akmhoqueb77b95f2013-02-08 12:28:47 -0600372 last_face=0;
373 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoqueffacaa82012-09-13 17:48:30 -0500374 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600375 first_face=num_face-1;
akmhoqueffacaa82012-09-13 17:48:30 -0500376 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600377 else if( nlsr->max_faces_per_prefix > 0)
akmhoque3cced642012-09-24 16:20:20 -0500378 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600379 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500380 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600381 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500382 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600383 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500384 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600385 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500386 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600387
388 }
akmhoque3cced642012-09-24 16:20:20 -0500389 for( j=first_face; j>= last_face; j--)
390 {
akmhoquea30cb772012-10-07 09:50:34 -0500391
akmhoqueb77b95f2013-02-08 12:28:47 -0600392 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500393 {
akmhoque1771c412012-11-09 13:06:08 -0600394 if ( nlsr->debugging )
395 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
396 if ( nlsr->detailed_logging )
397 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -0500398 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500399 }
400 else
401 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600402 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500403 {
akmhoque1771c412012-11-09 13:06:08 -0600404 if ( nlsr->debugging )
405 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
406 if ( nlsr->detailed_logging )
407 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -0500408 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
409 }
410 }
akmhoquea30cb772012-10-07 09:50:34 -0500411
akmhoque3cced642012-09-24 16:20:20 -0500412 }
413
akmhoqueffacaa82012-09-13 17:48:30 -0500414 }
415
416 hashtb_end(enle);
417 }
418
419 hashtb_end(e);
420
421 return 0;
422}
akmhoque3560cb62012-09-09 10:52:30 -0500423
424void
425print_npt(void)
426{
akmhoque1771c412012-11-09 13:06:08 -0600427
428 if ( nlsr->debugging )
429 {
430 printf("\n");
431 printf("print_npt called\n");
432 }
433 if ( nlsr->detailed_logging )
434 {
435 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
436 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n");
437 }
akmhoque3560cb62012-09-09 10:52:30 -0500438 int i, npt_element;
439
440 struct npt_entry *ne;
441
442 struct hashtb_enumerator ee;
443 struct hashtb_enumerator *e = &ee;
444
445 hashtb_start(nlsr->npt, e);
446 npt_element=hashtb_n(nlsr->npt);
447
448 for(i=0;i<npt_element;i++)
449 {
akmhoque1771c412012-11-09 13:06:08 -0600450 if ( nlsr->debugging )
451 {
452 printf("\n");
453 printf("----------NPT ENTRY %d------------------\n",i+1);
454 }
455 if ( nlsr->detailed_logging )
456 {
457 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
458 writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1);
459 }
akmhoque3560cb62012-09-09 10:52:30 -0500460 ne=e->data;
akmhoque1771c412012-11-09 13:06:08 -0600461 if ( nlsr->debugging )
462 printf(" Origination Router: %s \n",ne->orig_router);
463 if ( nlsr->detailed_logging )
464 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router);
akmhoque3560cb62012-09-09 10:52:30 -0500465
akmhoquede61ba92012-09-20 22:19:12 -0500466 int j, nl_element,face_list_element;
akmhoque810a5b52012-09-09 16:53:14 -0500467 struct name_list_entry *nle;
468 struct hashtb_enumerator eenle;
469 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500470
akmhoque810a5b52012-09-09 16:53:14 -0500471 hashtb_start(ne->name_list, enle);
472 nl_element=hashtb_n(ne->name_list);
akmhoque3560cb62012-09-09 10:52:30 -0500473
akmhoque810a5b52012-09-09 16:53:14 -0500474 for (j=0;j<nl_element;j++)
akmhoque3560cb62012-09-09 10:52:30 -0500475 {
akmhoque810a5b52012-09-09 16:53:14 -0500476 nle=enle->data;
akmhoque1771c412012-11-09 13:06:08 -0600477 if ( nlsr->debugging )
478 printf(" Name Prefix: %s \n",nle->name);
479 if ( nlsr->detailed_logging )
480 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500481 hashtb_next(enle);
akmhoque3560cb62012-09-09 10:52:30 -0500482 }
akmhoque810a5b52012-09-09 16:53:14 -0500483 hashtb_end(enle);
akmhoquede61ba92012-09-20 22:19:12 -0500484
485 struct face_list_entry *fle;
486
487 struct hashtb_enumerator eef;
488 struct hashtb_enumerator *ef = &eef;
489
490 hashtb_start(ne->face_list, ef);
491 face_list_element=hashtb_n(ne->face_list);
492 if ( face_list_element <= 0 )
493 {
akmhoque1771c412012-11-09 13:06:08 -0600494 if ( nlsr->debugging )
495 printf(" Face: No Face \n");
496 if ( nlsr->detailed_logging )
497 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
498
akmhoquede61ba92012-09-20 22:19:12 -0500499 }
500 else
501 {
502 for(j=0;j<face_list_element;j++)
503 {
504 fle=ef->data;
akmhoque1771c412012-11-09 13:06:08 -0600505 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600506 printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost);
akmhoque1771c412012-11-09 13:06:08 -0600507 if ( nlsr->detailed_logging )
508 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
akmhoquede61ba92012-09-20 22:19:12 -0500509 hashtb_next(ef);
510 }
511 }
512 hashtb_end(ef);
513
akmhoque3560cb62012-09-09 10:52:30 -0500514
515 hashtb_next(e);
516 }
517
518 hashtb_end(e);
519
akmhoque3171d652012-11-13 11:44:33 -0600520 if ( nlsr->debugging )
521 printf("\n");
522 if ( nlsr->detailed_logging )
523 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque3560cb62012-09-09 10:52:30 -0500524}
akmhoque810a5b52012-09-09 16:53:14 -0500525
526void
akmhoquede61ba92012-09-20 22:19:12 -0500527delete_orig_router_from_npt(char *orig_router)
akmhoque810a5b52012-09-09 16:53:14 -0500528{
akmhoquede61ba92012-09-20 22:19:12 -0500529 int res,num_face,num_prefix;
akmhoque810a5b52012-09-09 16:53:14 -0500530 struct npt_entry *ne;
531
532 struct hashtb_enumerator ee;
533 struct hashtb_enumerator *e = &ee;
534
535 hashtb_start(nlsr->npt, e);
536 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
537
538 if ( res == HT_OLD_ENTRY )
539 {
540 ne=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500541 num_prefix=hashtb_n(ne->name_list);
542 if ( num_prefix > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500543 {
akmhoquede61ba92012-09-20 22:19:12 -0500544 num_face=hashtb_n(ne->face_list);
545
546 if ( num_face > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500547 {
548 int j, nl_element;
549 struct name_list_entry *nle;
550 struct hashtb_enumerator eenle;
551 struct hashtb_enumerator *enle = &eenle;
552
553 hashtb_start(ne->name_list, enle);
554 nl_element=hashtb_n(ne->name_list);
555
556 for (j=0;j<nl_element;j++)
557 {
558 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500559 delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500560 hashtb_next(enle);
561 }
562 hashtb_end(enle);
563
564 }
565
566 }
akmhoque54a14f42013-02-24 06:16:20 -0600567 //hashtb_destroy(&ne->name_list);
568 //hashtb_destroy(&ne->face_list);
569 destroy_name_list(ne->name_list);
570 destroy_face_list(ne->face_list);
akmhoque810a5b52012-09-09 16:53:14 -0500571 hashtb_delete(e);
572 }
573 else if ( res == HT_NEW_ENTRY )
574 {
575 hashtb_delete(e);
576 }
577 hashtb_end(e);
578}
akmhoquefbfd0982012-09-09 20:59:03 -0500579
akmhoquede61ba92012-09-20 22:19:12 -0500580
581void
582add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
583{
akmhoque1771c412012-11-09 13:06:08 -0600584 if ( nlsr->debugging )
585 {
586 printf("add_face_to_npt_by_face_id called\n");
587 printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
588 }
589 if ( nlsr->detailed_logging )
590 {
591 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n");
592 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
593 }
akmhoquede61ba92012-09-20 22:19:12 -0500594
akmhoque1771c412012-11-09 13:06:08 -0600595
akmhoquede61ba92012-09-20 22:19:12 -0500596 int res,res1;
597 struct npt_entry *ne;
598
599 struct hashtb_enumerator ee;
600 struct hashtb_enumerator *e = &ee;
601
602 hashtb_start(nlsr->npt, e);
603 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
604
605 if ( res == HT_OLD_ENTRY )
606 {
akmhoque1771c412012-11-09 13:06:08 -0600607 if ( nlsr->debugging )
608 printf("Dest Router Found \n");
609 if ( nlsr->detailed_logging )
610 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n");
611
akmhoquede61ba92012-09-20 22:19:12 -0500612 ne=e->data;
613
614 struct hashtb_enumerator eef;
615 struct hashtb_enumerator *ef = &eef;
616
617 hashtb_start(ne->face_list, ef);
618 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
619
620 if ( res1 == HT_OLD_ENTRY )
621 {
akmhoque1771c412012-11-09 13:06:08 -0600622 if ( nlsr->debugging )
623 printf("Face Found \n");
624 if ( nlsr->detailed_logging )
625 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n");
akmhoqueb77b95f2013-02-08 12:28:47 -0600626 struct face_list_entry *fle;
akmhoquede61ba92012-09-20 22:19:12 -0500627 fle=ef->data;
628 fle->next_hop_face=face_id;
629 fle->route_cost=route_cost;
630 }
631 else if ( res1 == HT_NEW_ENTRY )
632 {
akmhoque1771c412012-11-09 13:06:08 -0600633 if ( nlsr->debugging )
634 printf("Face Not Found \n");
635 if ( nlsr->detailed_logging )
636 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n");
akmhoquede61ba92012-09-20 22:19:12 -0500637 struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
638 fle=ef->data;
639 fle->next_hop_face=face_id;
640 fle->route_cost=route_cost;
akmhoqueb77b95f2013-02-08 12:28:47 -0600641
642
643
644
akmhoquede61ba92012-09-20 22:19:12 -0500645 }
646 hashtb_end(ef);
647 }
648 else if (res == HT_NEW_ENTRY)
649 {
650 hashtb_delete(e);
651 }
652
653 hashtb_end(e);
654}
655
656
657void
akmhoque3cced642012-09-24 16:20:20 -0500658add_new_fib_entries_to_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500659{
akmhoque1771c412012-11-09 13:06:08 -0600660 if ( nlsr->debugging )
661 printf("add_new_fib_entries_to_npt called\n");
662 if ( nlsr->detailed_logging )
663 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n");
akmhoquede61ba92012-09-20 22:19:12 -0500664 int i,j, rt_element,face_list_element;
665
666 struct routing_table_entry *rte;
667
668 struct hashtb_enumerator ee;
669 struct hashtb_enumerator *e = &ee;
670
671 hashtb_start(nlsr->routing_table, e);
672 rt_element=hashtb_n(nlsr->routing_table);
673
674 for(i=0;i<rt_element;i++)
675 {
akmhoquede61ba92012-09-20 22:19:12 -0500676 rte=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500677
678 struct face_list_entry *fle;
679
680 struct hashtb_enumerator eef;
681 struct hashtb_enumerator *ef = &eef;
682
683 hashtb_start(rte->face_list, ef);
684 face_list_element=hashtb_n(rte->face_list);
685 if ( face_list_element <= 0 )
686 {
akmhoque1771c412012-11-09 13:06:08 -0600687 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600688 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600689 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600690 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
akmhoquede61ba92012-09-20 22:19:12 -0500691 }
692 else
693 {
694 for(j=0;j<face_list_element;j++)
695 {
696 fle=ef->data;
akmhoquede61ba92012-09-20 22:19:12 -0500697 add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost);
698 hashtb_next(ef);
699 }
700 }
701 hashtb_end(ef);
702
703 hashtb_next(e);
704 }
705
706 hashtb_end(e);
707
708}
709
710
711void
712delete_face_from_npt_by_face_id(char *dest_router, int face_id)
713{
akmhoque1771c412012-11-09 13:06:08 -0600714 if ( nlsr->debugging )
715 printf("delete_face_from_npt_by_face_id\n");
716 if ( nlsr->detailed_logging )
717 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n");
akmhoquede61ba92012-09-20 22:19:12 -0500718
719 int res,res1;
720 struct npt_entry *ne;
721
722 struct hashtb_enumerator ee;
723 struct hashtb_enumerator *e = &ee;
724
725 hashtb_start(nlsr->npt, e);
726 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
727
728 if ( res == HT_OLD_ENTRY )
729 {
730 ne=e->data;
731
732 struct hashtb_enumerator eef;
733 struct hashtb_enumerator *ef = &eef;
734
735 hashtb_start(ne->face_list, ef);
736 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
akmhoquede61ba92012-09-20 22:19:12 -0500737 if ( res1 == HT_OLD_ENTRY )
738 {
akmhoque54a14f42013-02-24 06:16:20 -0600739
akmhoquede61ba92012-09-20 22:19:12 -0500740 hashtb_delete(ef);
741 }
742 else if ( res1 == HT_NEW_ENTRY )
743 {
744 hashtb_delete(ef);
745 }
746 hashtb_end(ef);
747 }
748 else if (res == HT_NEW_ENTRY)
749 {
750 hashtb_delete(e);
751 }
752
753 hashtb_end(e);
754}
755
akmhoquede61ba92012-09-20 22:19:12 -0500756
757void
akmhoque3cced642012-09-24 16:20:20 -0500758clean_old_fib_entries_from_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500759{
760
akmhoque1771c412012-11-09 13:06:08 -0600761
762 if ( nlsr->debugging )
763 printf("clean_old_fib_entries_from_npt called\n\n");
764 if ( nlsr->detailed_logging )
765 writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n");
akmhoquede61ba92012-09-20 22:19:12 -0500766 int i, npt_element;
767
768 struct npt_entry *ne;
769
770 struct hashtb_enumerator ee;
771 struct hashtb_enumerator *e = &ee;
772
773 hashtb_start(nlsr->npt, e);
774 npt_element=hashtb_n(nlsr->npt);
775
776 for(i=0;i<npt_element;i++)
777 {
778 ne=e->data;
779
780 int j,k, nl_element,face_list_element;
781 struct face_list_entry *fle;
782
783 struct hashtb_enumerator eef;
784 struct hashtb_enumerator *ef = &eef;
785
786 hashtb_start(ne->face_list, ef);
787 face_list_element=hashtb_n(ne->face_list);
788 if ( face_list_element <= 0 )
789 {
akmhoque1771c412012-11-09 13:06:08 -0600790 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600791 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600792 if ( nlsr->detailed_logging )
793 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
794
akmhoquede61ba92012-09-20 22:19:12 -0500795 }
796 else
797 {
798 for(j=0;j<face_list_element;j++)
799 {
800 fle=ef->data;
801 int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face);
802 if ( check == 0 )
803 {
804 struct name_list_entry *nle;
805 struct hashtb_enumerator eenle;
806 struct hashtb_enumerator *enle = &eenle;
807
808 hashtb_start(ne->name_list, enle);
809 nl_element=hashtb_n(ne->name_list);
810
811 for (k=0;k<nl_element;k++)
812 {
813 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500814 if( is_neighbor(nle->name) == 0 )
815 {
akmhoque1771c412012-11-09 13:06:08 -0600816 if ( nlsr->debugging )
817 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
818 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600819 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
akmhoque3cced642012-09-24 16:20:20 -0500820 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
821 }
822
akmhoquede61ba92012-09-20 22:19:12 -0500823
824 hashtb_next(enle);
825 }
826 hashtb_end(enle);
827
akmhoqueb77b95f2013-02-08 12:28:47 -0600828
829 hashtb_delete(ef);
830 j++;
831
akmhoquede61ba92012-09-20 22:19:12 -0500832 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600833 else
834 {
835 struct name_list_entry *nle;
836 struct hashtb_enumerator eenle;
837 struct hashtb_enumerator *enle = &eenle;
838
839 hashtb_start(ne->name_list, enle);
840 nl_element=hashtb_n(ne->name_list);
841
842 for (k=0;k<nl_element;k++)
843 {
844 nle=enle->data;
845 if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face )
846 {
847 if ( nlsr->debugging )
848 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
849 if ( nlsr->detailed_logging )
850 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
851 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face);
852 }
853
854
855 hashtb_next(enle);
856 }
857 hashtb_end(enle);
858
859 hashtb_next(ef);
860 }
akmhoquede61ba92012-09-20 22:19:12 -0500861 }
862 }
863 hashtb_end(ef);
864
865
866 hashtb_next(e);
867 }
868
869 hashtb_end(e);
870
871}
872
873void
akmhoque3cced642012-09-24 16:20:20 -0500874update_npt_with_new_route(void)
akmhoquede61ba92012-09-20 22:19:12 -0500875{
akmhoqueb77b95f2013-02-08 12:28:47 -0600876 if ( nlsr->debugging )
877 printf("update_npt_with_new_route called\n");
878
akmhoquede61ba92012-09-20 22:19:12 -0500879 clean_old_fib_entries_from_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600880 print_npt();
akmhoquede61ba92012-09-20 22:19:12 -0500881 add_new_fib_entries_to_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600882 print_npt();
883
akmhoque3cced642012-09-24 16:20:20 -0500884 int i, npt_element;
885
886 struct npt_entry *ne;
887
888 struct hashtb_enumerator ee;
889 struct hashtb_enumerator *e = &ee;
890
891 hashtb_start(nlsr->npt, e);
892 npt_element=hashtb_n(nlsr->npt);
893
894 for(i=0;i<npt_element;i++)
895 {
896
897 ne=e->data;
898 update_ccnd_fib_for_orig_router(ne->orig_router);
899 hashtb_next(e);
900 }
901
902 hashtb_end(e);
903}
904
905
906
907void
908sort_faces_by_distance(int *faces,int *route_costs,int start,int element)
909{
910 int i,j;
911 int temp_cost;
912 int temp_face;
913
914 for ( i=start ; i < element ; i ++)
915 {
916 for( j=i+1; j<element; j ++)
917 {
918 if (route_costs[j] < route_costs[i] )
919 {
920 temp_cost=route_costs[j];
921 route_costs[j]=route_costs[i];
922 route_costs[i]=temp_cost;
923
924 temp_face=faces[j];
925 faces[j]=faces[i];
926 faces[i]=temp_face;
927 }
928 }
929 }
930
931}
932
933void
934get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces)
935{
936
937 int res,face_list_element,j;
938 struct hashtb_enumerator ee;
939 struct hashtb_enumerator *e = &ee;
940
941
942 hashtb_start(nlsr->npt, e);
943 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
944
945 if(res == HT_NEW_ENTRY)
946 {
947 hashtb_delete(e);
948 }
949 else if ( res == HT_OLD_ENTRY )
950 {
951 struct npt_entry *ne;
952 ne=e->data;
953
954 struct face_list_entry *fle;
955
956 struct hashtb_enumerator eef;
957 struct hashtb_enumerator *ef = &eef;
958
959 hashtb_start(ne->face_list, ef);
960 face_list_element=hashtb_n(ne->face_list);
961 for(j=0;j<face_list_element;j++)
962 {
963 fle=ef->data;
964 faces[j]=fle->next_hop_face;
965 route_costs[j]=fle->route_cost;
966 hashtb_next(ef);
967 }
968 hashtb_end(ef);
969
970
971 }
972 hashtb_end(e);
973
974}
975
976void
977destroy_faces_by_orig_router(char *orig_router)
978{
979
980 int res;
981 struct hashtb_enumerator ee;
982 struct hashtb_enumerator *e = &ee;
983
984
985 hashtb_start(nlsr->npt, e);
986 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
987
988 if(res == HT_NEW_ENTRY)
989 {
990 hashtb_delete(e);
991 }
992 else if ( res == HT_OLD_ENTRY )
993 {
994 struct npt_entry *ne;
995 ne=e->data;
996 int num_face=hashtb_n(ne->face_list);
997 int last_face,first_face;
998
999 int *faces=(int *)malloc(num_face*sizeof(int));
1000 int *route_costs=(int *)malloc(num_face*sizeof(int));
1001
1002 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
1003 sort_faces_by_distance(faces,route_costs,0,num_face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001004 last_face=0;
akmhoque0ed6d982013-02-22 14:28:01 -06001005 if ( nlsr->max_faces_per_prefix == 0)
akmhoqueb77b95f2013-02-08 12:28:47 -06001006 {
1007 first_face=num_face-1;
1008 }
1009 else if( nlsr->max_faces_per_prefix > 0)
1010 {
1011 if ( nlsr->max_faces_per_prefix >= num_face)
1012 {
1013 first_face=num_face-1;
1014 }
1015 else if ( nlsr->max_faces_per_prefix < num_face)
1016 {
1017 first_face=nlsr->max_faces_per_prefix-1;
1018 }
1019
1020 }
akmhoque3cced642012-09-24 16:20:20 -05001021
1022 int i,j, nl_element;
1023 struct name_list_entry *nle;
1024 struct hashtb_enumerator eenle;
1025 struct hashtb_enumerator *enle = &eenle;
1026
1027 hashtb_start(ne->name_list, enle);
1028 nl_element=hashtb_n(ne->name_list);
1029
1030 for (i=0;i<nl_element;i++)
1031 {
1032 nle=enle->data;
1033
1034 for( j=first_face; j>= last_face; j--)
1035 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001036 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -05001037 {
akmhoque1771c412012-11-09 13:06:08 -06001038 if ( nlsr->debugging )
1039 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1040 if ( nlsr->detailed_logging )
1041 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoquea30cb772012-10-07 09:50:34 -05001042 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
akmhoque3cced642012-09-24 16:20:20 -05001043 }
1044 else
1045 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001046 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -05001047 {
akmhoque1771c412012-11-09 13:06:08 -06001048 if ( nlsr->debugging )
1049 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1050 if ( nlsr->detailed_logging )
1051 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque3cced642012-09-24 16:20:20 -05001052 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]);
1053 }
1054 }
1055 }
1056
1057 hashtb_next(enle);
1058 }
1059 hashtb_end(enle);
1060
1061
1062
1063 free(faces);
1064 free(route_costs);
1065
1066 }
1067 hashtb_end(e);
1068
akmhoquede61ba92012-09-20 22:19:12 -05001069}
1070
akmhoquefbfd0982012-09-09 20:59:03 -05001071void
1072destroy_all_face_by_nlsr(void)
1073{
1074 int i, npt_element;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001075
akmhoquefbfd0982012-09-09 20:59:03 -05001076 struct npt_entry *ne;
1077
1078 struct hashtb_enumerator ee;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001079 struct hashtb_enumerator *e = &ee;
1080
1081 hashtb_start(nlsr->npt, e);
akmhoquefbfd0982012-09-09 20:59:03 -05001082 npt_element=hashtb_n(nlsr->npt);
1083
1084 for(i=0;i<npt_element;i++)
1085 {
akmhoquefbfd0982012-09-09 20:59:03 -05001086 ne=e->data;
akmhoque3cced642012-09-24 16:20:20 -05001087 destroy_faces_by_orig_router(ne->orig_router);
akmhoquefbfd0982012-09-09 20:59:03 -05001088 hashtb_next(e);
1089 }
1090
1091 hashtb_end(e);
1092
akmhoque3171d652012-11-13 11:44:33 -06001093 if ( nlsr->debugging )
1094 printf("\n");
1095 if ( nlsr->detailed_logging )
1096 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoquefbfd0982012-09-09 20:59:03 -05001097}
akmhoque0ed6d982013-02-22 14:28:01 -06001098
1099void
akmhoque54a14f42013-02-24 06:16:20 -06001100destroy_name_list(struct hashtb *name_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001101{
akmhoque54a14f42013-02-24 06:16:20 -06001102 int j,nl_element;
1103 struct name_list_entry *nle;
1104 struct hashtb_enumerator eenle;
1105 struct hashtb_enumerator *enle = &eenle;
1106
1107 hashtb_start(name_list, enle);
1108 nl_element=hashtb_n(name_list);
1109
1110 for (j=0;j<nl_element;j++)
1111 {
1112 nle=enle->data;
1113 free(nle->name);
1114 hashtb_next(enle);
1115 }
1116 hashtb_end(enle);
1117
1118 hashtb_destroy(&name_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001119}
1120
1121void
akmhoque54a14f42013-02-24 06:16:20 -06001122destroy_face_list(struct hashtb *face_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001123{
akmhoque54a14f42013-02-24 06:16:20 -06001124 hashtb_destroy(&face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001125}
1126
1127void
1128destroy_npt(void)
1129{
1130
1131
1132 int i, npt_element;
1133 struct npt_entry *ne;
1134
1135 struct hashtb_enumerator ee;
1136 struct hashtb_enumerator *e = &ee;
1137
1138 hashtb_start(nlsr->npt, e);
1139 npt_element=hashtb_n(nlsr->npt);
1140
1141 for(i=0;i<npt_element;i++)
1142 {
1143 ne=e->data;
akmhoque54a14f42013-02-24 06:16:20 -06001144 destroy_name_list(ne->name_list);
1145 destroy_face_list(ne->face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001146 hashtb_next(e);
1147 }
akmhoque0ed6d982013-02-22 14:28:01 -06001148 hashtb_end(e);
akmhoque54a14f42013-02-24 06:16:20 -06001149
1150 hashtb_destroy(&nlsr->npt);
akmhoque0ed6d982013-02-22 14:28:01 -06001151}
1152