blob: f45c20b900248df1e1df4f0e7e4cc60fad9dc5a6 [file] [log] [blame]
akmhoque29c1db52012-09-07 14:47:43 -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
13
14#include <ccn/ccn.h>
15#include <ccn/uri.h>
16#include <ccn/keystore.h>
17#include <ccn/signing.h>
18#include <ccn/schedule.h>
19#include <ccn/hashtb.h>
20
21
22#include "nlsr.h"
23#include "nlsr_route.h"
24#include "nlsr_lsdb.h"
akmhoque3560cb62012-09-09 10:52:30 -050025#include "nlsr_npt.h"
akmhoquefbfd0982012-09-09 20:59:03 -050026#include "nlsr_adl.h"
akmhoque29c1db52012-09-07 14:47:43 -050027
28int
29route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
30{
akmhoqueffacaa82012-09-13 17:48:30 -050031
32 if(flags == CCN_SCHEDULE_CANCEL)
33 {
34 return -1;
35 }
36
37 nlsr_lock();
38
akmhoque29c1db52012-09-07 14:47:43 -050039 printf("route_calculate called\n");
40
41 if( ! nlsr->is_build_adj_lsa_sheduled )
42 {
43 /* Calculate Route here */
akmhoque3560cb62012-09-09 10:52:30 -050044 print_routing_table();
45 print_npt();
46
akmhoque29c1db52012-09-07 14:47:43 -050047 struct hashtb_param param_me = {0};
48 nlsr->map = hashtb_create(sizeof(struct map_entry), &param_me);
akmhoquefbfd0982012-09-09 20:59:03 -050049 nlsr->rev_map = hashtb_create(sizeof(struct map_entry), &param_me);
akmhoque29c1db52012-09-07 14:47:43 -050050 make_map();
51 assign_mapping_number();
52 print_map();
akmhoquefbfd0982012-09-09 20:59:03 -050053 print_rev_map();
akmhoque29c1db52012-09-07 14:47:43 -050054
akmhoque3560cb62012-09-09 10:52:30 -050055 do_old_routing_table_updates();
56
57
akmhoque29c1db52012-09-07 14:47:43 -050058 int i;
59 int **adj_matrix;
60 int map_element=hashtb_n(nlsr->map);
61 adj_matrix=malloc(map_element * sizeof(int *));
62 for(i = 0; i < map_element; i++)
63 {
64 adj_matrix[i] = malloc(map_element * sizeof(int));
65 }
66 make_adj_matrix(adj_matrix,map_element);
67 print_adj_matrix(adj_matrix,map_element);
68
69 long int source=get_mapping_no(nlsr->router_name);
70 long int *parent=(long int *)malloc(map_element * sizeof(long int));
71
72 calculate_path(adj_matrix,parent, map_element, source);
73
74 print_all_path_from_source(parent,source);
75
akmhoquefbfd0982012-09-09 20:59:03 -050076 print_all_next_hop(parent,source);
77
78 update_routing_table_with_new_route(parent,source);
79
akmhoqueffacaa82012-09-13 17:48:30 -050080 print_routing_table();
81 print_npt();
akmhoquefbfd0982012-09-09 20:59:03 -050082
akmhoque29c1db52012-09-07 14:47:43 -050083 for(i = 0; i < map_element; i++)
84 {
85 free(adj_matrix[i]);
86 }
87 free(parent);
88 free(adj_matrix);
89 hashtb_destroy(&nlsr->map);
akmhoquefbfd0982012-09-09 20:59:03 -050090 hashtb_destroy(&nlsr->rev_map);
akmhoque29c1db52012-09-07 14:47:43 -050091
92 }
93 nlsr->is_route_calculation_scheduled=0;
94
akmhoqueffacaa82012-09-13 17:48:30 -050095 nlsr_unlock();
96
akmhoque29c1db52012-09-07 14:47:43 -050097 return 0;
98}
99
100void
101calculate_path(int **adj_matrix, long int *parent, long int V, long int S)
102{
103 int i;
104 long int v,u;
105 long int *dist=(long int *)malloc(V * sizeof(long int));
106 long int *Q=(long int *)malloc(V * sizeof(long int));
107 long int head=0;
108 /* Initial the Parent */
109 for (i = 0 ; i < V; i++)
110 {
111 parent[i]=EMPTY_PARENT;
112 dist[i]=INF_DISTANCE;
113 Q[i]=i;
114 }
115
116 dist[S]=0;
117 sort_queue_by_distance(Q,dist,head,V);
118
119 while (head < V )
120 {
121 u=Q[head];
122 if(dist[u] == INF_DISTANCE)
123 {
124 break;
125 }
126
127 for(v=0 ; v <V; v++)
128 {
129 if( adj_matrix[u][v] > 0 ) //
130 {
131 if ( is_not_explored(Q,v,head+1,V) )
132 {
133
134 if( dist[u] + adj_matrix[u][v] < dist[v])
135 {
136 dist[v]=dist[u] + adj_matrix[u][v] ;
137 parent[v]=u;
138 }
139
140 }
141
142 }
143
144 }
145
146 head++;
147 sort_queue_by_distance(Q,dist,head,V);
148 }
149
150 free(Q);
151 free(dist);
152}
153
154void
155print_all_path_from_source(long int *parent,long int source)
156{
157 int i, map_element;
158 struct map_entry *me;
159
160 struct hashtb_enumerator ee;
161 struct hashtb_enumerator *e = &ee;
162
163 hashtb_start(nlsr->map, e);
164 map_element=hashtb_n(nlsr->map);
165
166 for(i=0;i<map_element;i++)
167 {
168 me=e->data;
169 if(me->mapping != source)
170 {
171 print_path(parent,(long int)me->mapping);
172 printf("\n");
173 }
174 hashtb_next(e);
175 }
176
177 hashtb_end(e);
178
179}
180
akmhoquefbfd0982012-09-09 20:59:03 -0500181void
182print_all_next_hop(long int *parent,long int source)
183{
184 int i, map_element;
185 struct map_entry *me;
186
187 struct hashtb_enumerator ee;
188 struct hashtb_enumerator *e = &ee;
189
190 hashtb_start(nlsr->map, e);
191 map_element=hashtb_n(nlsr->map);
192
193 for(i=0;i<map_element;i++)
194 {
195 me=e->data;
196 if(me->mapping != source)
197 {
198
199 printf("Dest: %d Next Hop: %ld\n",me->mapping,get_next_hop_from_calculation(parent,me->mapping,source));
200 }
201 hashtb_next(e);
202 }
203
204 hashtb_end(e);
205
206}
207
208long int
209get_next_hop_from_calculation(long int *parent, long int dest,long int source)
210{
211 long int next_hop;
212 while ( parent[dest] != EMPTY_PARENT )
213 {
214 next_hop=dest;
215 dest=parent[dest];
216
217 }
218
219 if ( dest != source )
220 {
221 next_hop=NO_NEXT_HOP;
222 }
223
224 return next_hop;
225
226}
227
akmhoque29c1db52012-09-07 14:47:43 -0500228void
229print_path(long int *parent, long int dest)
230{
231 if (parent[dest] != EMPTY_PARENT )
232 print_path(parent,parent[dest]);
233
234 printf(" %ld",dest);
235}
236
237int
238is_not_explored(long int *Q, long int u,long int start, long int element)
239{
240 int ret=0;
241 long int i;
242 for(i=start; i< element; i++)
243 {
244 if ( Q[i] == u )
245 {
246 ret=1;
247 break;
248 }
249 }
250 return ret;
251}
252
253void
254sort_queue_by_distance(long int *Q,long int *dist,long int start,long int element)
255{
256 long int i,j;
257 long int temp_u;
258
259 for ( i=start ; i < element ; i ++)
260 {
261 for( j=i+1; j<element; j ++)
262 {
263 if (dist[Q[j]] < dist[Q[i]])
264 {
265 temp_u=Q[j];
266 Q[j]=Q[i];
267 Q[i]=temp_u;
268 }
269 }
270 }
271
272}
273
274void
275print_map(void)
276{
277 int i, map_element;
278 struct map_entry *me;
279
280 struct hashtb_enumerator ee;
281 struct hashtb_enumerator *e = &ee;
282
283 hashtb_start(nlsr->map, e);
284 map_element=hashtb_n(nlsr->map);
285
286 for(i=0;i<map_element;i++)
287 {
288 me=e->data;
289 printf("Router: %s Mapping Number: %d \n",me->router,me->mapping);
290 hashtb_next(e);
291 }
292
293 hashtb_end(e);
294}
295
296
297void
298assign_mapping_number(void)
299{
300 int i, map_element;
301 struct map_entry *me;
302
303 struct hashtb_enumerator ee;
304 struct hashtb_enumerator *e = &ee;
305
306 hashtb_start(nlsr->map, e);
307 map_element=hashtb_n(nlsr->map);
308
309 for(i=0;i<map_element;i++)
310 {
311 me=e->data;
312 me->mapping=i;
akmhoquefbfd0982012-09-09 20:59:03 -0500313 add_rev_map_entry(i,me->router);
akmhoque29c1db52012-09-07 14:47:43 -0500314 hashtb_next(e);
315 }
316
317 hashtb_end(e);
318}
319
320void
321make_map(void)
322{
323
324
325 int i, adj_lsdb_element;
326 struct alsa *adj_lsa;
327
328 struct hashtb_enumerator ee;
329 struct hashtb_enumerator *e = &ee;
330
331 hashtb_start(nlsr->lsdb->adj_lsdb, e);
332 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
333
334 for(i=0;i<adj_lsdb_element;i++)
335 {
336 adj_lsa=e->data;
337 add_adj_data_to_map(adj_lsa->header->orig_router->name,adj_lsa->body,adj_lsa->no_link);
338 hashtb_next(e);
339 }
340
341 hashtb_end(e);
342
343}
344
345void
346add_map_entry(char *router)
347{
348
349 struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry ));
350
351 struct hashtb_enumerator ee;
352 struct hashtb_enumerator *e = &ee;
353 int res;
354
355 hashtb_start(nlsr->map, e);
356 res = hashtb_seek(e, router, strlen(router), 0);
357
358 if(res == HT_NEW_ENTRY)
359 {
360 me=e->data;
361 me->router=(char *)malloc(strlen(router)+1);
362 memset(me->router,0,strlen(router)+1);
363 memcpy(me->router,router,strlen(router));
364 me->mapping=0;
365 }
366
367 hashtb_end(e);
368
369}
370
371
372void
373add_adj_data_to_map(char *orig_router, char *body, int no_link)
374{
375 add_map_entry(orig_router);
376
377 int i=0;
378 char *lsa_data=(char *)malloc(strlen(body)+1);
379 memset( lsa_data,0,strlen(body)+1);
380 memcpy(lsa_data,body,strlen(body)+1);
381 char *sep="|";
382 char *rem;
383 char *rtr_id;
384 char *length;
385 char *face;
386 char *metric;
387
388 if(no_link >0 )
389 {
390 rtr_id=strtok_r(lsa_data,sep,&rem);
391 length=strtok_r(NULL,sep,&rem);
392 face=strtok_r(NULL,sep,&rem);
393 metric=strtok_r(NULL,sep,&rem);
394
395 add_map_entry(rtr_id);
396
397 for(i=1;i<no_link;i++)
398 {
399 rtr_id=strtok_r(NULL,sep,&rem);
400 length=strtok_r(NULL,sep,&rem);
401 face=strtok_r(NULL,sep,&rem);
402 metric=strtok_r(NULL,sep,&rem);
403
404 add_map_entry(rtr_id);
405
406 }
407 }
408
409 free(lsa_data);
410}
411
412int
413get_mapping_no(char *router)
414{
415 struct map_entry *me;
416
417 struct hashtb_enumerator ee;
418 struct hashtb_enumerator *e = &ee;
akmhoque0315f982012-09-09 11:28:05 -0500419 int res;
akmhoque810a5b52012-09-09 16:53:14 -0500420 int ret;
akmhoque29c1db52012-09-07 14:47:43 -0500421
akmhoque63152c62012-09-18 08:43:42 -0500422 int n = hashtb_n(nlsr->map);
423
424 if ( n < 1)
425 {
426 return NO_MAPPING_NUM;
427 }
428
akmhoque29c1db52012-09-07 14:47:43 -0500429 hashtb_start(nlsr->map, e);
430 res = hashtb_seek(e, router, strlen(router), 0);
431
432 if( res == HT_OLD_ENTRY )
433 {
434 me=e->data;
435 ret=me->mapping;
436 }
437 else if(res == HT_NEW_ENTRY)
438 {
439 hashtb_delete(e);
akmhoque810a5b52012-09-09 16:53:14 -0500440 ret=NO_MAPPING_NUM;
akmhoque29c1db52012-09-07 14:47:43 -0500441 }
442
443 hashtb_end(e);
444
445 return ret;
446
447}
448
akmhoquefbfd0982012-09-09 20:59:03 -0500449
450void
451add_rev_map_entry(long int mapping_number, char *router)
452{
453
454 struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry ));
455
456 struct hashtb_enumerator ee;
457 struct hashtb_enumerator *e = &ee;
458 int res;
459
460 hashtb_start(nlsr->rev_map, e);
461 res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0);
462
463 if(res == HT_NEW_ENTRY)
464 {
465 me=e->data;
466 me->router=(char *)malloc(strlen(router)+1);
467 memset(me->router,0,strlen(router)+1);
468 memcpy(me->router,router,strlen(router));
469 me->mapping=mapping_number;
470 }
471
472 hashtb_end(e);
473
474}
475
476
477
478char *
479get_router_from_rev_map(long int mapping_number)
480{
481
482 struct map_entry *me;
483
484 struct hashtb_enumerator ee;
485 struct hashtb_enumerator *e = &ee;
486 int res;
487
488 hashtb_start(nlsr->rev_map, e);
489 res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0);
490
491 if(res == HT_OLD_ENTRY)
492 {
493 me=e->data;
494 hashtb_end(e);
495 return me->router;
496 }
497 else if(res == HT_NEW_ENTRY)
498 {
499 hashtb_delete(e);
500 hashtb_end(e);
501 }
502
503 return NULL;
504}
505
506void
507print_rev_map(void)
508{
509 int i, map_element;
510 struct map_entry *me;
511
512 struct hashtb_enumerator ee;
513 struct hashtb_enumerator *e = &ee;
514
515 hashtb_start(nlsr->map, e);
516 map_element=hashtb_n(nlsr->map);
517
518 for(i=0;i<map_element;i++)
519 {
520 me=e->data;
521 printf("Mapping Number: %d Router: %s \n",me->mapping,me->router);
522 hashtb_next(e);
523 }
524
525 hashtb_end(e);
526}
527
528
akmhoque29c1db52012-09-07 14:47:43 -0500529void
530assign_adj_matrix_for_lsa(struct alsa *adj_lsa, int **adj_matrix)
531{
532 int mapping_orig_router=get_mapping_no(adj_lsa->header->orig_router->name);
533 int mapping_nbr_router;
534
535 int i;
536 char *lsa_data=(char *)malloc(strlen(adj_lsa->body)+1);
537 memset( lsa_data,0,strlen(adj_lsa->body)+1);
538 memcpy(lsa_data,adj_lsa->body,strlen(adj_lsa->body)+1);
539 char *sep="|";
540 char *rem;
541 char *rtr_id;
542 char *length;
543 char *face;
544 char *metric;
545
546 if(adj_lsa->no_link >0 )
547 {
548 rtr_id=strtok_r(lsa_data,sep,&rem);
549 length=strtok_r(NULL,sep,&rem);
550 face=strtok_r(NULL,sep,&rem);
551 metric=strtok_r(NULL,sep,&rem);
552
553 mapping_nbr_router=get_mapping_no(rtr_id);
554 adj_matrix[mapping_orig_router][mapping_nbr_router]=atoi(metric);
555
556 for(i=1;i<adj_lsa->no_link;i++)
557 {
558 rtr_id=strtok_r(NULL,sep,&rem);
559 length=strtok_r(NULL,sep,&rem);
560 face=strtok_r(NULL,sep,&rem);
561 metric=strtok_r(NULL,sep,&rem);
562
563 mapping_nbr_router=get_mapping_no(rtr_id);
564 adj_matrix[mapping_orig_router][mapping_nbr_router]=atoi(metric);
565
566 }
567 }
568
569 free(lsa_data);
570}
571
572void
573make_adj_matrix(int **adj_matrix,int map_element)
574{
575
576 init_adj_matrix(adj_matrix,map_element);
577
578 int i, adj_lsdb_element;
579 struct alsa *adj_lsa;
580
581 struct hashtb_enumerator ee;
582 struct hashtb_enumerator *e = &ee;
583
584 hashtb_start(nlsr->lsdb->adj_lsdb, e);
585 adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb);
586
587 for(i=0;i<adj_lsdb_element;i++)
588 {
589 adj_lsa=e->data;
590 assign_adj_matrix_for_lsa(adj_lsa,adj_matrix);
591 hashtb_next(e);
592 }
593
594 hashtb_end(e);
595
596}
597
598void
599init_adj_matrix(int **adj_matrix,int map_element)
600{
601 int i, j;
602 for(i=0;i<map_element;i++)
603 for(j=0;j<map_element;j++)
604 adj_matrix[i][j]=0;
605}
606
607void print_adj_matrix(int **adj_matrix, int map_element)
608{
609 int i, j;
610 for(i=0;i<map_element;i++)
611 {
612 for(j=0;j<map_element;j++)
613 printf("%d ",adj_matrix[i][j]);
614 printf("\n");
615 }
616}
617
akmhoque3560cb62012-09-09 10:52:30 -0500618int
619get_next_hop(char *dest_router)
620{
621 struct routing_table_entry *rte;
622
623 struct hashtb_enumerator ee;
624 struct hashtb_enumerator *e = &ee;
625 int res,ret;
626
627 hashtb_start(nlsr->routing_table, e);
628 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
629
630 if( res == HT_OLD_ENTRY )
631 {
632 rte=e->data;
633 ret=rte->next_hop_face;
634 }
635 else if(res == HT_NEW_ENTRY)
636 {
637 hashtb_delete(e);
638 ret=NO_NEXT_HOP;
639 }
640
641 hashtb_end(e);
642
643 return ret;
644}
645
646void
647add_next_hop_router(char *dest_router)
648{
649 if ( strcmp(dest_router,nlsr->router_name)== 0)
650 {
651 return ;
652 }
653
654 struct routing_table_entry *rte=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry));
655
656 struct hashtb_enumerator ee;
657 struct hashtb_enumerator *e = &ee;
658 int res;
659
660 hashtb_start(nlsr->routing_table, e);
661 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
662
663 if( res == HT_NEW_ENTRY )
664 {
665 rte=e->data;
666 rte->dest_router=(char *)malloc(strlen(dest_router)+1);
667 memset(rte->dest_router,0,strlen(dest_router)+1);
668 memcpy(rte->dest_router,dest_router,strlen(dest_router));
669 rte->next_hop_face=NO_NEXT_HOP;
670 }
671 hashtb_end(e);
672
673}
674
675void
676add_next_hop_from_lsa_adj_body(char *body, int no_link)
677{
678
679 int i=0;
680 char *lsa_data=(char *)malloc(strlen(body)+1);
681 memset( lsa_data,0,strlen(body)+1);
682 memcpy(lsa_data,body,strlen(body)+1);
683 char *sep="|";
684 char *rem;
685 char *rtr_id;
686 char *length;
687 char *face;
688 char *metric;
689
690 if(no_link >0 )
691 {
692 rtr_id=strtok_r(lsa_data,sep,&rem);
693 length=strtok_r(NULL,sep,&rem);
694 face=strtok_r(NULL,sep,&rem);
695 metric=strtok_r(NULL,sep,&rem);
696
akmhoque3560cb62012-09-09 10:52:30 -0500697
698 add_next_hop_router(rtr_id);
699
700 for(i=1;i<no_link;i++)
701 {
702 rtr_id=strtok_r(NULL,sep,&rem);
703 length=strtok_r(NULL,sep,&rem);
704 face=strtok_r(NULL,sep,&rem);
705 metric=strtok_r(NULL,sep,&rem);
akmhoque3560cb62012-09-09 10:52:30 -0500706
707 add_next_hop_router(rtr_id);
708
709 }
710 }
711
712 free(lsa_data);
713
714
715}
716
717void
akmhoqueffacaa82012-09-13 17:48:30 -0500718update_routing_table(char * dest_router,int next_hop_face)
719{
720 int res;
721 struct routing_table_entry *rte;
722
723 struct hashtb_enumerator ee;
724 struct hashtb_enumerator *e = &ee;
725
726 hashtb_start(nlsr->routing_table, e);
727 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
728
729 if( res == HT_OLD_ENTRY )
730 {
731 rte=e->data;
732 rte->next_hop_face=next_hop_face;
733 }
734 else if ( res == HT_OLD_ENTRY )
735 {
736 hashtb_delete(e);
737 }
738
739 hashtb_end(e);
740
741}
742
743void
akmhoque3560cb62012-09-09 10:52:30 -0500744print_routing_table(void)
745{
746 printf("\n");
747 printf("print_routing_table called\n");
748 int i, rt_element;
749
750 struct routing_table_entry *rte;
751
752 struct hashtb_enumerator ee;
753 struct hashtb_enumerator *e = &ee;
754
755 hashtb_start(nlsr->routing_table, e);
756 rt_element=hashtb_n(nlsr->routing_table);
757
758 for(i=0;i<rt_element;i++)
759 {
760 printf("----------Routing Table Entry %d------------------\n",i+1);
761 rte=e->data;
762 printf(" Destination Router: %s \n",rte->dest_router);
763 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);
764 hashtb_next(e);
765 }
766
767 hashtb_end(e);
768
769 printf("\n");
770}
771
akmhoque63152c62012-09-18 08:43:42 -0500772
773int
774delete_empty_rte(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
775{
776 printf("delete_empty_rte called\n");
777 printf("Router: %s \n",(char *)ev->evdata);
778 if(flags == CCN_SCHEDULE_CANCEL)
779 {
780 return -1;
781 }
782
783 int res;
784 struct hashtb_enumerator ee;
785 struct hashtb_enumerator *e = &ee;
786
787 hashtb_start(nlsr->routing_table, e);
788 res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0);
789
790 if ( res == HT_OLD_ENTRY )
791 {
792 hashtb_delete(e);
793 }
794 else if ( res == HT_NEW_ENTRY )
795 {
796 hashtb_delete(e);
797 }
798
799 return 0;
800}
801
802
akmhoque3560cb62012-09-09 10:52:30 -0500803void
804do_old_routing_table_updates()
805{
akmhoque810a5b52012-09-09 16:53:14 -0500806 printf("do_old_routing_table_updates called\n");
807 int i, rt_element;
808 int mapping_no;
809
810 struct routing_table_entry *rte;
811
812 struct hashtb_enumerator ee;
813 struct hashtb_enumerator *e = &ee;
814
815 hashtb_start(nlsr->routing_table, e);
816 rt_element=hashtb_n(nlsr->routing_table);
817
818 for(i=0;i<rt_element;i++)
819 {
820 rte=e->data;
821 mapping_no=get_mapping_no(rte->dest_router);
822 if ( mapping_no == NO_MAPPING_NUM)
823 {
824 delete_orig_router_from_npt(rte->dest_router,rte->next_hop_face);
akmhoque63152c62012-09-18 08:43:42 -0500825 char *router=(char *)malloc(strlen(rte->dest_router)+1);
826 memset(router,0,strlen(rte->dest_router)+1);
827 memcpy(router,rte->dest_router,strlen(rte->dest_router)+1);
828 nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_empty_rte, (void *)router , 0);
akmhoque810a5b52012-09-09 16:53:14 -0500829 }
830 hashtb_next(e);
831 }
832
833 hashtb_end(e);
akmhoque3560cb62012-09-09 10:52:30 -0500834}
akmhoque29c1db52012-09-07 14:47:43 -0500835
akmhoquefbfd0982012-09-09 20:59:03 -0500836void
837update_routing_table_with_new_route(long int *parent, long int source)
838{
839 printf("update_routing_table_with_new_route called\n");
840 int i, map_element;
841 struct map_entry *me;
842
843 struct hashtb_enumerator ee;
844 struct hashtb_enumerator *e = &ee;
845
846 hashtb_start(nlsr->rev_map, e);
847 map_element=hashtb_n(nlsr->rev_map);
848
849 for(i=0;i<map_element;i++)
850 {
851 me=e->data;
852 if(me->mapping != source)
853 {
854
855 char *orig_router=get_router_from_rev_map(me->mapping);
856 if (orig_router != NULL )
857 {
858 int next_hop_router_num=get_next_hop_from_calculation(parent,me->mapping,source);
859 //printf(" Next hop router Num: %d ",next_hop_router_num);
860 if ( next_hop_router_num == NO_NEXT_HOP )
861 {
862 update_npt_with_new_route(orig_router,NO_FACE);
863 printf ("\nOrig_router: %s Next Hop Face: %d \n",orig_router,NO_FACE);
864 }
865 else
866 {
867 char *next_hop_router=get_router_from_rev_map(next_hop_router_num);
868 //printf("Next hop router name: %s \n",next_hop_router);
869 int next_hop_face=get_next_hop_face_from_adl(next_hop_router);
870 update_npt_with_new_route(orig_router,next_hop_face);
akmhoqueffacaa82012-09-13 17:48:30 -0500871 update_routing_table(orig_router,next_hop_face);
akmhoquefbfd0982012-09-09 20:59:03 -0500872 printf ("Orig_router: %s Next Hop Face: %d \n",orig_router,next_hop_face);
873
874 }
875 }
876 }
877 hashtb_next(e);
878 }
879
880 hashtb_end(e);
881}
882