blob: 5f6ee260da54e4f9e4c96109eb329866c1344804 [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"
akmhoque3560cb62012-09-09 10:52:30 -050027
28int
akmhoquede61ba92012-09-20 22:19:12 -050029add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs)
akmhoque3560cb62012-09-09 10:52:30 -050030{
31 if ( strcmp(orig_router,nlsr->router_name)== 0)
32 {
33 return -1;
34 }
35
36 struct npt_entry *ne=(struct npt_entry*)malloc(sizeof(struct npt_entry ));
37
akmhoquede61ba92012-09-20 22:19:12 -050038 int res,res_nle,res_fle;
akmhoque3560cb62012-09-09 10:52:30 -050039 struct hashtb_enumerator ee;
40 struct hashtb_enumerator *e = &ee;
akmhoque810a5b52012-09-09 16:53:14 -050041
akmhoque3560cb62012-09-09 10:52:30 -050042
43 hashtb_start(nlsr->npt, e);
akmhoque810a5b52012-09-09 16:53:14 -050044 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
akmhoque3560cb62012-09-09 10:52:30 -050045
46 if(res == HT_NEW_ENTRY)
47 {
48 ne=e->data;
49
akmhoque810a5b52012-09-09 16:53:14 -050050 ne->orig_router=(char *)malloc(strlen(orig_router)+1);
51 memset(ne->orig_router,0,strlen(orig_router)+1);
52 memcpy(ne->orig_router,orig_router,strlen(orig_router));
akmhoque3560cb62012-09-09 10:52:30 -050053
akmhoque810a5b52012-09-09 16:53:14 -050054
akmhoquede61ba92012-09-20 22:19:12 -050055
akmhoque3560cb62012-09-09 10:52:30 -050056
akmhoque810a5b52012-09-09 16:53:14 -050057 struct hashtb_param param_nle = {0};
58 ne->name_list= hashtb_create(sizeof(struct name_list_entry ), &param_nle);
akmhoque3560cb62012-09-09 10:52:30 -050059
akmhoque810a5b52012-09-09 16:53:14 -050060 struct hashtb_enumerator eenle;
61 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -050062
akmhoque810a5b52012-09-09 16:53:14 -050063 hashtb_start(ne->name_list, enle);
64 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
akmhoque3560cb62012-09-09 10:52:30 -050065
akmhoque810a5b52012-09-09 16:53:14 -050066 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -050067 {
akmhoquede61ba92012-09-20 22:19:12 -050068 struct name_list_entry *nle=(struct name_list_entry *)malloc(sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -050069 nle=enle->data;
70 nle->name=(char *)malloc(strlen(name_prefix)+1);
71 memset(nle->name,0,strlen(name_prefix)+1);
72 memcpy(nle->name,name_prefix,strlen(name_prefix));
akmhoque3560cb62012-09-09 10:52:30 -050073
akmhoque810a5b52012-09-09 16:53:14 -050074
akmhoque3560cb62012-09-09 10:52:30 -050075
76 }
akmhoque810a5b52012-09-09 16:53:14 -050077 hashtb_end(enle);
78
akmhoquede61ba92012-09-20 22:19:12 -050079 struct hashtb_param param_fle = {0};
80 ne->face_list=hashtb_create(sizeof(struct face_list_entry), &param_fle);
akmhoque3560cb62012-09-09 10:52:30 -050081
akmhoquede61ba92012-09-20 22:19:12 -050082 if ( num_face > 0 )
83 {
84 struct hashtb_enumerator eef;
85 struct hashtb_enumerator *ef = &eef;
86
87 hashtb_start(ne->face_list, ef);
88 int i;
89
90 for ( i=0; i< num_face ; i ++)
91 {
92 int face=faces[i];
93 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
94
95 if ( res_fle == HT_NEW_ENTRY )
96 {
97 struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
98 fle=ef->data;
99 fle->next_hop_face=face;
100 fle->route_cost=route_costs[i];
101 }
102
103 }
104 hashtb_end(ef);
105 }
106
107
108 //ne->next_hop_face=face;
109
110 /*
akmhoque3560cb62012-09-09 10:52:30 -0500111 if ( face != NO_FACE )
112 {
113 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
114 }
akmhoquede61ba92012-09-20 22:19:12 -0500115 */
akmhoque3560cb62012-09-09 10:52:30 -0500116 }
117 else if (res == HT_OLD_ENTRY)
118 {
119 free(ne);
120 struct npt_entry *one;
121
122 one=e->data;
123
akmhoque810a5b52012-09-09 16:53:14 -0500124 struct hashtb_enumerator eenle;
125 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500126
akmhoque810a5b52012-09-09 16:53:14 -0500127 hashtb_start(one->name_list, enle);
128 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
129
130 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500131 {
akmhoquede61ba92012-09-20 22:19:12 -0500132 struct name_list_entry *nle=(struct name_list_entry *)malloc(sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -0500133 nle=enle->data;
134 nle->name=(char *)malloc(strlen(name_prefix)+1);
135 memset(nle->name,0,strlen(name_prefix)+1);
136 memcpy(nle->name,name_prefix,strlen(name_prefix));
akmhoquede61ba92012-09-20 22:19:12 -0500137 /*
akmhoque3560cb62012-09-09 10:52:30 -0500138 if ( face != NO_FACE )
139 {
140 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_REG, face);
141 }
akmhoquede61ba92012-09-20 22:19:12 -0500142 */
akmhoque3560cb62012-09-09 10:52:30 -0500143 }
akmhoque810a5b52012-09-09 16:53:14 -0500144 else if(res_nle == HT_OLD_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500145 {
akmhoquede61ba92012-09-20 22:19:12 -0500146
akmhoque3560cb62012-09-09 10:52:30 -0500147 }
akmhoque810a5b52012-09-09 16:53:14 -0500148 hashtb_end(enle);
149
akmhoquede61ba92012-09-20 22:19:12 -0500150 if ( num_face > 0 )
151 {
152 struct hashtb_enumerator eef;
153 struct hashtb_enumerator *ef = &eef;
154
155 hashtb_start(one->face_list, ef);
156 int i;
157
158 for ( i=0; i< num_face ; i ++)
159 {
160 int face=faces[i];
161 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
162
163 if ( res_fle == HT_NEW_ENTRY )
164 {
165 struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
166 fle=ef->data;
167 fle->next_hop_face=face;
168 fle->route_cost=route_costs[i];
169 }
170
171 }
172 hashtb_end(ef);
173 }
akmhoque810a5b52012-09-09 16:53:14 -0500174
akmhoque3560cb62012-09-09 10:52:30 -0500175
176 }
177 hashtb_end(e);
akmhoque3560cb62012-09-09 10:52:30 -0500178 return res;
179}
180
akmhoqueffacaa82012-09-13 17:48:30 -0500181int
182delete_npt_entry(char *orig_router, char *name_prefix)
183{
184 if ( strcmp(orig_router,nlsr->router_name)== 0)
185 {
186 return -1;
187 }
188
189 struct npt_entry *ne;
190
191 int res,res_nle;
192 struct hashtb_enumerator ee;
193 struct hashtb_enumerator *e = &ee;
194
195
196 hashtb_start(nlsr->npt, e);
197 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
198
199 if(res == HT_NEW_ENTRY)
200 {
201 hashtb_delete(e);
202 return -1;
203 }
204 else if (res == HT_OLD_ENTRY)
205 {
206 ne=e->data;
207
208 struct hashtb_enumerator eenle;
209 struct hashtb_enumerator *enle = &eenle;
210
211 hashtb_start(ne->name_list, enle);
212 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
213
214 if(res_nle == HT_NEW_ENTRY )
215 {
216 hashtb_delete(enle);
217 }
218 else if(res_nle == HT_OLD_ENTRY )
219 {
akmhoquede61ba92012-09-20 22:19:12 -0500220 /*
akmhoqueffacaa82012-09-13 17:48:30 -0500221 if (ne->next_hop_face != NO_FACE )
222 {
223 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)name_prefix, OP_UNREG, ne->next_hop_face);
224 }
akmhoquede61ba92012-09-20 22:19:12 -0500225 */
akmhoqueffacaa82012-09-13 17:48:30 -0500226 hashtb_delete(enle);
227 }
228
229 hashtb_end(enle);
akmhoqueda5b6832012-09-13 22:33:55 -0500230
231 if ( hashtb_n(ne->name_list) == 0 )
232 {
233 hashtb_delete(e);
234 }
akmhoqueffacaa82012-09-13 17:48:30 -0500235 }
236
237 hashtb_end(e);
238
239 return 0;
240}
akmhoque3560cb62012-09-09 10:52:30 -0500241
242void
243print_npt(void)
244{
245 printf("\n");
246 printf("print_npt called\n\n");
247 int i, npt_element;
248
249 struct npt_entry *ne;
250
251 struct hashtb_enumerator ee;
252 struct hashtb_enumerator *e = &ee;
253
254 hashtb_start(nlsr->npt, e);
255 npt_element=hashtb_n(nlsr->npt);
256
257 for(i=0;i<npt_element;i++)
258 {
259 printf("\n");
260 printf("----------NPT ENTRY %d------------------\n",i+1);
261 ne=e->data;
akmhoque810a5b52012-09-09 16:53:14 -0500262 printf(" Origination Router: %s \n",ne->orig_router);
akmhoquede61ba92012-09-20 22:19:12 -0500263 //ne->next_hop_face == NO_FACE ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", ne->next_hop_face);
akmhoque3560cb62012-09-09 10:52:30 -0500264
akmhoquede61ba92012-09-20 22:19:12 -0500265 int j, nl_element,face_list_element;
akmhoque810a5b52012-09-09 16:53:14 -0500266 struct name_list_entry *nle;
267 struct hashtb_enumerator eenle;
268 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500269
akmhoque810a5b52012-09-09 16:53:14 -0500270 hashtb_start(ne->name_list, enle);
271 nl_element=hashtb_n(ne->name_list);
akmhoque3560cb62012-09-09 10:52:30 -0500272
akmhoque810a5b52012-09-09 16:53:14 -0500273 for (j=0;j<nl_element;j++)
akmhoque3560cb62012-09-09 10:52:30 -0500274 {
akmhoque810a5b52012-09-09 16:53:14 -0500275 nle=enle->data;
276 printf(" Name Prefix: %s \n",nle->name);
277 hashtb_next(enle);
akmhoque3560cb62012-09-09 10:52:30 -0500278 }
akmhoque810a5b52012-09-09 16:53:14 -0500279 hashtb_end(enle);
akmhoquede61ba92012-09-20 22:19:12 -0500280
281 struct face_list_entry *fle;
282
283 struct hashtb_enumerator eef;
284 struct hashtb_enumerator *ef = &eef;
285
286 hashtb_start(ne->face_list, ef);
287 face_list_element=hashtb_n(ne->face_list);
288 if ( face_list_element <= 0 )
289 {
290 printf(" Face: No Face \n");
291 }
292 else
293 {
294 for(j=0;j<face_list_element;j++)
295 {
296 fle=ef->data;
297 printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
298 hashtb_next(ef);
299 }
300 }
301 hashtb_end(ef);
302
akmhoque3560cb62012-09-09 10:52:30 -0500303
304 hashtb_next(e);
305 }
306
307 hashtb_end(e);
308
309 printf("\n");
310}
akmhoque810a5b52012-09-09 16:53:14 -0500311
312void
akmhoquede61ba92012-09-20 22:19:12 -0500313delete_orig_router_from_npt(char *orig_router)
akmhoque810a5b52012-09-09 16:53:14 -0500314{
akmhoquede61ba92012-09-20 22:19:12 -0500315 int res,num_face,num_prefix;
akmhoque810a5b52012-09-09 16:53:14 -0500316 struct npt_entry *ne;
317
318 struct hashtb_enumerator ee;
319 struct hashtb_enumerator *e = &ee;
320
321 hashtb_start(nlsr->npt, e);
322 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
323
324 if ( res == HT_OLD_ENTRY )
325 {
326 ne=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500327 num_prefix=hashtb_n(ne->name_list);
328 if ( num_prefix > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500329 {
akmhoquede61ba92012-09-20 22:19:12 -0500330 num_face=hashtb_n(ne->face_list);
331
332 if ( num_face > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500333 {
334 int j, nl_element;
335 struct name_list_entry *nle;
336 struct hashtb_enumerator eenle;
337 struct hashtb_enumerator *enle = &eenle;
338
339 hashtb_start(ne->name_list, enle);
340 nl_element=hashtb_n(ne->name_list);
341
342 for (j=0;j<nl_element;j++)
343 {
344 nle=enle->data;
akmhoquede61ba92012-09-20 22:19:12 -0500345
346 int k,face_list_element;
347 struct face_list_entry *fle;
348
349 struct hashtb_enumerator eef;
350 struct hashtb_enumerator *ef = &eef;
351
352 hashtb_start(ne->face_list, ef);
353 face_list_element=hashtb_n(ne->face_list);
354 for(k=0;k<face_list_element;k++)
355 {
356 fle=ef->data;
357 //printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
358 //add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , next_hop_face);
359 hashtb_next(ef);
360 }
361 hashtb_end(ef);
362
363 //add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , next_hop_face);
364
akmhoque810a5b52012-09-09 16:53:14 -0500365 hashtb_next(enle);
366 }
367 hashtb_end(enle);
368
369 }
370
371 }
372 hashtb_destroy(&ne->name_list);
akmhoquede61ba92012-09-20 22:19:12 -0500373 hashtb_destroy(&ne->face_list);
akmhoque810a5b52012-09-09 16:53:14 -0500374 hashtb_delete(e);
375 }
376 else if ( res == HT_NEW_ENTRY )
377 {
378 hashtb_delete(e);
379 }
380 hashtb_end(e);
381}
akmhoquefbfd0982012-09-09 20:59:03 -0500382
akmhoquede61ba92012-09-20 22:19:12 -0500383/*
akmhoquefbfd0982012-09-09 20:59:03 -0500384
385void
386update_npt_with_new_route(char * orig_router,int next_hop_face)
387{
388 int res;
389 struct npt_entry *ne;
390
391 struct hashtb_enumerator ee;
392 struct hashtb_enumerator *e = &ee;
393
394 hashtb_start(nlsr->npt, e);
395 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
396
397 if ( res == HT_OLD_ENTRY )
398 {
399 ne=e->data;
400
401 if ( next_hop_face != ne->next_hop_face )
402 {
403 int j, nl_element;
404 struct name_list_entry *nle;
405 struct hashtb_enumerator eenle;
406 struct hashtb_enumerator *enle = &eenle;
407
408 hashtb_start(ne->name_list, enle);
409 nl_element=hashtb_n(ne->name_list);
410
411 for (j=0;j<nl_element;j++)
412 {
413 nle=enle->data;
414 if (ne->next_hop_face != NO_FACE )
415 {
416 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , ne->next_hop_face);
417 }
418 if (next_hop_face != NO_FACE )
419 {
420 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG , next_hop_face);
421 }
422 hashtb_next(enle);
423 }
424 hashtb_end(enle);
425 ne->next_hop_face=next_hop_face;
426 }
427
428 }
429 else if ( res == HT_NEW_ENTRY )
430 {
431 hashtb_delete(e);
432 }
433 hashtb_end(e);
434}
435
akmhoquede61ba92012-09-20 22:19:12 -0500436*/
437
438
439void
440add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
441{
442 printf("add_face_to_npt_by_face_id called\n");
443
444 printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
445 int res,res1;
446 struct npt_entry *ne;
447
448 struct hashtb_enumerator ee;
449 struct hashtb_enumerator *e = &ee;
450
451 hashtb_start(nlsr->npt, e);
452 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
453
454 if ( res == HT_OLD_ENTRY )
455 {
456 printf("Dest Router Found \n");
457 ne=e->data;
458
459 struct hashtb_enumerator eef;
460 struct hashtb_enumerator *ef = &eef;
461
462 hashtb_start(ne->face_list, ef);
463 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
464
465 if ( res1 == HT_OLD_ENTRY )
466 {
467 printf("Face Found \n");
468 struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
469 fle=ef->data;
470 fle->next_hop_face=face_id;
471 fle->route_cost=route_cost;
472 }
473 else if ( res1 == HT_NEW_ENTRY )
474 {
475 printf("Face Not Found \n");
476 struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
477 fle=ef->data;
478 fle->next_hop_face=face_id;
479 fle->route_cost=route_cost;
480 //hashtb_delete(ef);
481 }
482 hashtb_end(ef);
483 }
484 else if (res == HT_NEW_ENTRY)
485 {
486 hashtb_delete(e);
487 }
488
489 hashtb_end(e);
490}
491
492
493void
494add_new_fib_entries_to_npt()
495{
496 printf("add_new_fib_entries_to_npt called\n");
497 int i,j, rt_element,face_list_element;
498
499 struct routing_table_entry *rte;
500
501 struct hashtb_enumerator ee;
502 struct hashtb_enumerator *e = &ee;
503
504 hashtb_start(nlsr->routing_table, e);
505 rt_element=hashtb_n(nlsr->routing_table);
506
507 for(i=0;i<rt_element;i++)
508 {
509 //printf("----------Routing Table Entry %d------------------\n",i+1);
510 rte=e->data;
511 //printf(" Destination Router: %s \n",rte->dest_router);
512 //rte->next_hop_face == NO_NEXT_HOP ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", rte->next_hop_face);
513
514 struct face_list_entry *fle;
515
516 struct hashtb_enumerator eef;
517 struct hashtb_enumerator *ef = &eef;
518
519 hashtb_start(rte->face_list, ef);
520 face_list_element=hashtb_n(rte->face_list);
521 if ( face_list_element <= 0 )
522 {
523 printf(" Face: No Face \n");
524 }
525 else
526 {
527 for(j=0;j<face_list_element;j++)
528 {
529 fle=ef->data;
530 //printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
531 add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost);
532 hashtb_next(ef);
533 }
534 }
535 hashtb_end(ef);
536
537 hashtb_next(e);
538 }
539
540 hashtb_end(e);
541
542}
543
544
545void
546delete_face_from_npt_by_face_id(char *dest_router, int face_id)
547{
548 printf("delete_face_from_npt_by_face_id called\n");
549
550 int res,res1;
551 struct npt_entry *ne;
552
553 struct hashtb_enumerator ee;
554 struct hashtb_enumerator *e = &ee;
555
556 hashtb_start(nlsr->npt, e);
557 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
558
559 if ( res == HT_OLD_ENTRY )
560 {
561 ne=e->data;
562
563 struct hashtb_enumerator eef;
564 struct hashtb_enumerator *ef = &eef;
565
566 hashtb_start(ne->face_list, ef);
567 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
568
569 if ( res1 == HT_OLD_ENTRY )
570 {
571 hashtb_delete(ef);
572 }
573 else if ( res1 == HT_NEW_ENTRY )
574 {
575 hashtb_delete(ef);
576 }
577 hashtb_end(ef);
578 }
579 else if (res == HT_NEW_ENTRY)
580 {
581 hashtb_delete(e);
582 }
583
584 hashtb_end(e);
585}
586
587int
588delete_old_face_from_npt(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
589{
590 if(flags == CCN_SCHEDULE_CANCEL)
591 {
592 return -1;
593 }
594
595 nlsr_lock();
596
597 printf("delete_old_face_from_npt called\n");
598 if ( ev->evdata != NULL )
599 {
600 printf("Event Data: %s \n",(char *)ev->evdata);
601 char *sep="|";
602 char *rem;
603 char *orig_router;
604 char *faceid;
605 int face_id;
606
607 char *face_data=(char *)malloc(strlen((char *)ev->evdata)+1);
608 memset(face_data,0,strlen((char *)ev->evdata)+1);
609 memcpy(face_data+strlen(face_data),(char *)ev->evdata,strlen((char *)ev->evdata));
610
611 orig_router=strtok_r(face_data,sep,&rem);
612 faceid=strtok_r(NULL,sep,&rem);
613 face_id=atoi(faceid);
614 printf("Orig Router: %s Face: %d \n",orig_router,face_id);
615
616 delete_face_from_npt_by_face_id(orig_router,face_id);
617 }
618
619 nlsr_unlock();
620
621 return 0;
622}
623
624void
625clean_old_fib_entries_from_npt()
626{
627
628 printf("clean_old_fib_entries_from_npt called\n\n");
629 int i, npt_element;
630
631 struct npt_entry *ne;
632
633 struct hashtb_enumerator ee;
634 struct hashtb_enumerator *e = &ee;
635
636 hashtb_start(nlsr->npt, e);
637 npt_element=hashtb_n(nlsr->npt);
638
639 for(i=0;i<npt_element;i++)
640 {
641 ne=e->data;
642
643 int j,k, nl_element,face_list_element;
644 struct face_list_entry *fle;
645
646 struct hashtb_enumerator eef;
647 struct hashtb_enumerator *ef = &eef;
648
649 hashtb_start(ne->face_list, ef);
650 face_list_element=hashtb_n(ne->face_list);
651 if ( face_list_element <= 0 )
652 {
653 printf(" Face: No Face \n");
654 }
655 else
656 {
657 for(j=0;j<face_list_element;j++)
658 {
659 fle=ef->data;
660 int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face);
661 if ( check == 0 )
662 {
663 struct name_list_entry *nle;
664 struct hashtb_enumerator eenle;
665 struct hashtb_enumerator *enle = &eenle;
666
667 hashtb_start(ne->name_list, enle);
668 nl_element=hashtb_n(ne->name_list);
669
670 for (k=0;k<nl_element;k++)
671 {
672 nle=enle->data;
673
674 //delete all the fib entries here
675
676 hashtb_next(enle);
677 }
678 hashtb_end(enle);
679
680 char faceid[20];
681 memset(faceid,0,20);
682 sprintf(faceid,"%d",fle->next_hop_face);
683 char *evdata=(char *)malloc(strlen(ne->orig_router)+strlen(faceid)+2);
684 memset(evdata,0,strlen(ne->orig_router)+strlen(faceid)+2);
685 memcpy(evdata+strlen(evdata),ne->orig_router,strlen(ne->orig_router));
686 memcpy(evdata+strlen(evdata),"|",1);
687 memcpy(evdata+strlen(evdata),faceid,strlen(faceid));
688
689 nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_old_face_from_npt, (void *)evdata, 0);
690
691 }
692
693 hashtb_next(ef);
694 }
695 }
696 hashtb_end(ef);
697
698
699 hashtb_next(e);
700 }
701
702 hashtb_end(e);
703
704}
705
706void
707update_npt_with_new_route()
708{
709 clean_old_fib_entries_from_npt();
710 add_new_fib_entries_to_npt();
711}
712
akmhoquefbfd0982012-09-09 20:59:03 -0500713void
714destroy_all_face_by_nlsr(void)
715{
716 int i, npt_element;
717
718 struct npt_entry *ne;
719
720 struct hashtb_enumerator ee;
721 struct hashtb_enumerator *e = &ee;
722
723 hashtb_start(nlsr->npt, e);
724 npt_element=hashtb_n(nlsr->npt);
725
726 for(i=0;i<npt_element;i++)
727 {
akmhoquefbfd0982012-09-09 20:59:03 -0500728 ne=e->data;
akmhoquefbfd0982012-09-09 20:59:03 -0500729
730 int j, nl_element;
731 struct name_list_entry *nle;
732 struct hashtb_enumerator eenle;
733 struct hashtb_enumerator *enle = &eenle;
734
735 hashtb_start(ne->name_list, enle);
736 nl_element=hashtb_n(ne->name_list);
737
738 for (j=0;j<nl_element;j++)
739 {
740 nle=enle->data;
akmhoquede61ba92012-09-20 22:19:12 -0500741 /*
akmhoquefbfd0982012-09-09 20:59:03 -0500742 if ( ne->next_hop_face != NO_FACE)
743 {
744 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG , ne->next_hop_face);
745 }
akmhoquede61ba92012-09-20 22:19:12 -0500746 */
akmhoqueffacaa82012-09-13 17:48:30 -0500747 //printf(" Name Prefix: %s Face: %d \n",nle->name,ne->next_hop_face);
akmhoquefbfd0982012-09-09 20:59:03 -0500748 hashtb_next(enle);
749 }
750 hashtb_end(enle);
751
752 hashtb_next(e);
753 }
754
755 hashtb_end(e);
756
757 printf("\n");
758}