blob: 14244af2e420b3cc54551f16bbc9e4ffd9a35920 [file] [log] [blame]
akmhoque8fdd6412012-12-04 15:05:33 -06001#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 <sys/stat.h>
8#include <assert.h>
9#include <sys/types.h>
10#include <signal.h>
11#include <sys/socket.h>
12#include <sys/un.h>
13#include <fcntl.h>
14#include <sys/ioctl.h>
15#include <netinet/in.h>
16#include <netdb.h>
17#include <arpa/inet.h>
18
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23#include <ccn/ccn.h>
24#include <ccn/uri.h>
25#include <ccn/keystore.h>
26#include <ccn/signing.h>
27#include <ccn/schedule.h>
28#include <ccn/hashtb.h>
29#include <ccn/sync.h>
30#include <ccn/seqwriter.h>
31
32#include "nlsr.h"
33#include "nlsr_ndn.h"
34#include "nlsr_lsdb.h"
35#include "utility.h"
36#include "nlsr_npl.h"
37#include "nlsr_adl.h"
38#include "nlsr_npt.h"
39#include "nlsr_route.h"
40#include "nlsr_sync.h"
akmhoquea37b52c2012-12-14 11:16:36 -060041#include "nlsr_face.h"
42#include "nlsr_fib.h"
akmhoque8fdd6412012-12-04 15:05:33 -060043
44
45#define ON_ERROR_DESTROY(resval) \
46{ \
47 if ((resval) < 0) { \
48 nlsr_destroy(); \
49 exit(1);\
50 } \
51}
52
53
54#define ON_ERROR_EXIT(resval) \
55{ \
56 if ((resval) < 0) { \
57 exit(1); \
58 } \
59}
60
61struct option longopts[] =
62{
63 { "daemon", no_argument, NULL, 'd'},
64 { "config_file", required_argument, NULL, 'f'},
65 { "api_port", required_argument, NULL, 'p'},
66 { "help", no_argument, NULL, 'h'},
67 { 0 }
68};
69
70static int
71usage(char *progname)
72{
73
74 printf("Usage: %s [OPTIONS...]\n\
75 NDN routing....\n\
76 -d, --daemon Run in daemon mode\n\
77 -f, --config_file Specify configuration file name\n\
78 -p, --api_port port where api client will connect\n\
79 -h, --help Display this help message\n", progname);
80
81 exit(1);
82}
83
84void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result)
85{
86 struct timeval now = {0};
87 gettimeofday(&now, 0);
88 result->s = now.tv_sec;
89 result->micros = now.tv_usec;
90}
91
92static struct ccn_gettime ndn_rtr_ticker = {
93 "timer",
94 &ndn_rtr_gettime,
95 1000000,
96 NULL
97};
98
99void
100nlsr_lock(void)
101{
102 nlsr->semaphor=NLSR_LOCKED;
103}
104
105void
106nlsr_unlock(void)
107{
108 nlsr->semaphor=NLSR_UNLOCKED;
109}
110
111void
112nlsr_stop_signal_handler(int sig)
113{
114 signal(sig, SIG_IGN);
115 nlsr_destroy();
116 exit(0);
117}
118
119void
120daemonize_nlsr(void)
121{
122 int ret;
123 pid_t process_id = 0;
124 pid_t sid = 0;
125 process_id = fork();
126 if (process_id < 0)
127 {
128 printf("Daemonization failed!\n");
129 ON_ERROR_DESTROY(process_id);
130 }
131 if (process_id > 0)
132 {
133 printf("Process daemonized. Process id: %d \n", process_id);
134 ret=process_id;
135 exit(0);
136 }
137
138 umask(0);
139 sid = setsid();
140 if(sid < 0)
141 {
142 ON_ERROR_DESTROY(sid);
143 }
144
145 chdir("/");
146 close(STDIN_FILENO);
147 close(STDOUT_FILENO);
148 close(STDERR_FILENO);
149}
150
151void
152process_command_ccnneighbor(char *command)
153{
154 if(command==NULL)
155 {
156 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
157 return;
158 }
159 char *rem;
160 const char *sep=" \t\n";
akmhoquea37b52c2012-12-14 11:16:36 -0600161 char *rtr_name;
162 //char *face;
akmhoque8fdd6412012-12-04 15:05:33 -0600163
164 rtr_name=strtok_r(command,sep,&rem);
165 if(rtr_name==NULL)
166 {
167 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
168 return;
169 }
170
akmhoquea37b52c2012-12-14 11:16:36 -0600171 /*face=strtok_r(NULL,sep,&rem);
akmhoque8fdd6412012-12-04 15:05:33 -0600172 if(face==NULL)
173 {
174 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
175 return;
176 }
177
178 printf("Router: %s face: %s\n",rtr_name,face);
179 int face_id;
180 int res;
181 res=sscanf(face,"face%d",&face_id);
182
183 if(res != 1 )
184 {
185 printf(" Wrong Command Format ( ccnneighbor router_name faceX) where X is integer\n");
186 return;
akmhoquea37b52c2012-12-14 11:16:36 -0600187 }*/
akmhoque8fdd6412012-12-04 15:05:33 -0600188
189 if ( rtr_name[strlen(rtr_name)-1] == '/' )
190 {
191 rtr_name[strlen(rtr_name)-1]='\0';
192 }
193 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
194 nbr->name=(char *)malloc(strlen(rtr_name)+1);
195 memset(nbr->name,0,strlen(rtr_name)+1);
196 memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
197 nbr->length=strlen(rtr_name)+1;
198
akmhoque09c0afa2012-12-14 09:27:00 -0600199 //add_nbr_to_adl(nbr,face_id);
200
201 struct name_prefix *nbr_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
202 get_host_name_from_command_string(nbr_name,nbr->name,0);
203 printf("Hostname of neighbor: %s ",nbr_name->name);
204
akmhoque09c0afa2012-12-14 09:27:00 -0600205
akmhoquea37b52c2012-12-14 11:16:36 -0600206 char *ip_addr=(char *)malloc(13);
Syed Obaid Amin4c959562012-12-21 16:43:21 -0600207 memset(ip_addr,0,13);
akmhoquea37b52c2012-12-14 11:16:36 -0600208 get_ip_from_hostname_02(nbr_name->name,ip_addr);
209 printf("IP Address: %s \n",ip_addr);
210
211 add_nbr_to_adl(nbr,0,ip_addr);
akmhoque09c0afa2012-12-14 09:27:00 -0600212
akmhoque8fdd6412012-12-04 15:05:33 -0600213
214 free(nbr->name);
215 free(nbr);
216}
217
218void
219process_command_ccnname(char *command)
220{
221
222 if(command==NULL)
223 {
224 printf(" Wrong Command Format ( ccnname /name/prefix)\n");
225 return;
226 }
227 char *rem;
228 const char *sep=" \t\n";
229 char *name;
230 name=strtok_r(command,sep,&rem);
231 if(name==NULL)
232 {
233 printf(" Wrong Command Format ( ccnname /name/prefix/ )\n");
234 return;
235 }
236
237 printf("Name Prefix: %s \n",name);
238
239 if ( name[strlen(name)-1] == '/' )
240 name[strlen(name)-1]='\0';
241
242 struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
243 np->name=(char *)malloc(strlen(name)+1);
244 memset(np->name,0,strlen(name)+1);
245 memcpy(np->name,name,strlen(name)+1);
246 np->length=strlen(name)+1;
247
248 add_name_to_npl(np);
249
250 free(np->name);
251 free(np);
252}
253
254
255void
256process_command_router_name(char *command)
257{
258 if(command==NULL)
259 {
260 printf(" Wrong Command Format ( router-name /router/name )\n");
261 return;
262 }
263 char *rem;
264 const char *sep=" \t\n";
265 char *rtr_name;
266
267 rtr_name=strtok_r(command,sep,&rem);
268 if(rtr_name==NULL)
269 {
270 printf(" Wrong Command Format ( router-name /router/name )\n");
271 return;
272 }
273
274
275 if ( rtr_name[strlen(rtr_name)-1] == '/' )
276 rtr_name[strlen(rtr_name)-1]='\0';
277
278 nlsr->router_name=(char *)malloc(strlen(rtr_name)+1);
279 memset(nlsr->router_name,0,strlen(rtr_name)+1);
280 memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1);
281
282
283}
284
285void
286process_command_lsdb_synch_interval(char *command)
287{
288 if(command==NULL)
289 {
290 printf(" Wrong Command Format ( lsdb-synch-interval secs )\n");
291 return;
292 }
293 char *rem;
294 const char *sep=" \t\n";
295 char *secs;
296 long int seconds;
297
298 secs=strtok_r(command,sep,&rem);
299 if(secs==NULL)
300 {
301 printf(" Wrong Command Format ( lsdb-synch-interval secs)\n");
302 return;
303 }
304
305 seconds=atoi(secs);
306 if ( seconds >= 120 && seconds <= 3600 )
307 {
308 nlsr->lsdb_synch_interval=seconds;
309 }
310
311}
312
313
314void
315process_command_interest_retry(char *command)
316{
317 if(command==NULL)
318 {
319 printf(" Wrong Command Format ( interest-retry number )\n");
320 return;
321 }
322 char *rem;
323 const char *sep=" \t\n";
324 char *retry;
325 long int retry_number;
326
327 retry=strtok_r(command,sep,&rem);
328 if(retry==NULL)
329 {
330 printf(" Wrong Command Format ( interest-retry number)\n");
331 return;
332 }
333
334 retry_number=atoi(retry);
335 if ( retry_number >= 1 && retry_number<=10 )
336 {
337 nlsr->interest_retry=retry_number;
338 }
339
340}
341
342void
343process_command_interest_resend_time(char *command)
344{
345 if(command==NULL)
346 {
347 printf(" Wrong Command Format ( interest-resend-time secs )\n");
348 return;
349 }
350 char *rem;
351 const char *sep=" \t\n";
352 char *secs;
353 long int seconds;
354
355 secs=strtok_r(command,sep,&rem);
356 if(secs==NULL)
357 {
358 printf(" Wrong Command Format ( interest-resend-time secs)\n");
359 return;
360 }
361
362 seconds=atoi(secs);
363 if ( seconds <= 60 && seconds >= 1 )
364 {
365 nlsr->interest_resend_time=seconds;
366 }
367}
368
369
370void
371process_command_lsa_refresh_time(char *command)
372{
373 if(command==NULL)
374 {
375 printf(" Wrong Command Format ( lsa-refresh-time secs )\n");
376 return;
377 }
378 char *rem;
379 const char *sep=" \t\n";
380 char *secs;
381 long int seconds;
382
383 secs=strtok_r(command,sep,&rem);
384 if(secs==NULL)
385 {
386 printf(" Wrong Command Format ( lsa-refresh-time secs)\n");
387 return;
388 }
389
390 seconds=atoi(secs);
391 if ( seconds >= 240 && seconds <= 3600 )
392 {
393 nlsr->lsa_refresh_time=seconds;
394 }
395
396}
397
398void
399process_command_router_dead_interval(char *command)
400{
401 if(command==NULL)
402 {
403 printf(" Wrong Command Format ( router-dead-interval secs )\n");
404 return;
405 }
406 char *rem;
407 const char *sep=" \t\n";
408 char *secs;
409 long int seconds;
410
411 secs=strtok_r(command,sep,&rem);
412 if(secs==NULL)
413 {
414 printf(" Wrong Command Format ( router-dead-interval secs)\n");
415 return;
416 }
417
418 seconds=atoi(secs);
419 if ( seconds >= 360 && seconds <= 5400 )
420 {
421 nlsr->router_dead_interval=seconds;
422 }
423
424}
425
426void
427process_command_multi_path_face_num(char *command)
428{
429 if(command==NULL)
430 {
431 printf(" Wrong Command Format ( multi-path-face-num n )\n");
432 return;
433 }
434 char *rem;
435 const char *sep=" \t\n";
436 char *num;
437 long int number;
438
439 num=strtok_r(command,sep,&rem);
440 if(num==NULL)
441 {
442 printf(" Wrong Command Format ( multi-path-face-num n)\n");
443 return;
444 }
445
446 number=atoi(num);
447 if ( number >= 0 && number <= 60 )
448 {
449 nlsr->multi_path_face_num=number;
450 }
451
452}
453
454void
455process_command_logdir(char *command)
456{
457 if(command==NULL)
458 {
459 printf(" Wrong Command Format ( logdir /path/to/logdir )\n");
460 return;
461 }
462 char *rem;
463 const char *sep=" \t\n";
464 char *dir;
465
466 dir=strtok_r(command,sep,&rem);
467 if(dir==NULL)
468 {
469 printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
470 return;
471 }
472
473 nlsr->logDir=(char *)malloc(strlen(dir)+1);
474 memset(nlsr->logDir,0,strlen(dir)+1);
475 memcpy(nlsr->logDir,dir,strlen(dir));
476}
477
478void
479process_command_detailed_log(char *command)
480{
481 if(command==NULL)
482 {
483 printf(" Wrong Command Format ( detailed-log on/off )\n");
484 return;
485 }
486 char *rem;
487 const char *sep=" \t\n";
488 char *on_off;
489
490 on_off=strtok_r(command,sep,&rem);
491 if(on_off==NULL)
492 {
493 printf(" Wrong Command Format ( detailed-log on/off )\n");
494 return;
495 }
496
497 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0)
498 {
499 nlsr->detailed_logging=1;
500 }
501}
502
503void
504process_command_debug(char *command)
505{
506 if(command==NULL)
507 {
508 printf(" Wrong Command Format ( debug on/off )\n");
509 return;
510 }
511 char *rem;
512 const char *sep=" \t\n";
513 char *on_off;
514
515 on_off=strtok_r(command,sep,&rem);
516 if(on_off==NULL)
517 {
518 printf(" Wrong Command Format ( debug on/off )\n");
519 return;
520 }
521
522 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
523 {
524 nlsr->debugging=1;
525 }
526}
527
akmhoque09c0afa2012-12-14 09:27:00 -0600528
529void
530process_command_topo_prefix(char *command)
531{
532 if(command==NULL)
533 {
534 printf(" Wrong Command Format ( topo-prefix )\n");
535 return;
536 }
537 char *rem;
538 const char *sep=" \t\n";
539 char *topo_prefix;
540
541 topo_prefix=strtok_r(command,sep,&rem);
542 if(topo_prefix==NULL)
543 {
544 printf(" Wrong Command Format ( topo-prefix /name/prefix )\n");
545 return;
546 }
547 else
548 {
549 if( nlsr->topo_prefix != NULL)
550 free(nlsr->topo_prefix);
akmhoqueb29edd82013-01-14 20:54:11 -0600551 if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
552 topo_prefix[strlen(topo_prefix)-1]='\0';
553
akmhoque09c0afa2012-12-14 09:27:00 -0600554 nlsr->topo_prefix=(char *)malloc(strlen(topo_prefix)+1);
Syed Obaid Amin7a176c62012-12-21 15:56:00 -0600555 memset(nlsr->topo_prefix,0,strlen(topo_prefix)+1);
556 puts(topo_prefix);
akmhoque09c0afa2012-12-14 09:27:00 -0600557 memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix));
558
akmhoque09c0afa2012-12-14 09:27:00 -0600559 }
560}
561
562
563void
564process_command_slice_prefix(char *command)
565{
566 if(command==NULL)
567 {
568 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
569 return;
570 }
571 char *rem;
572 const char *sep=" \t\n";
573 char *slice_prefix;
574
575 slice_prefix=strtok_r(command,sep,&rem);
576 if(slice_prefix==NULL)
577 {
578 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
579 return;
580 }
581 else
582 {
583 if ( nlsr->slice_prefix != NULL)
584 free(nlsr->slice_prefix);
akmhoqueb29edd82013-01-14 20:54:11 -0600585 if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
586 slice_prefix[strlen(slice_prefix)-1]='\0';
587
akmhoque09c0afa2012-12-14 09:27:00 -0600588 nlsr->slice_prefix=(char *)malloc(strlen(slice_prefix)+1);
Syed Obaid Amin4c959562012-12-21 16:43:21 -0600589 memset(nlsr->slice_prefix,0,strlen(slice_prefix)+1);
akmhoque09c0afa2012-12-14 09:27:00 -0600590 memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix));
akmhoque09c0afa2012-12-14 09:27:00 -0600591 }
592}
593
594void
akmhoque596f7082013-02-04 13:34:13 -0600595process_command_hyperbolic_routing(char *command)
akmhoque09c0afa2012-12-14 09:27:00 -0600596{
597 if(command==NULL)
598 {
akmhoque596f7082013-02-04 13:34:13 -0600599 printf(" Wrong Command Format ( hyperbolic-routing on)\n");
akmhoque09c0afa2012-12-14 09:27:00 -0600600 return;
601 }
602 char *rem;
603 const char *sep=" \t\n";
604 char *on_off;
605
606 on_off=strtok_r(command,sep,&rem);
607 if(on_off==NULL)
608 {
akmhoque596f7082013-02-04 13:34:13 -0600609 printf(" Wrong Command Format ( hyperbolic-routing on )\n");
akmhoque09c0afa2012-12-14 09:27:00 -0600610 return;
611 }
612
613 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
614 {
615 nlsr->is_hyperbolic_calc=1;
616 }
617}
618
akmhoqueed418f32013-01-30 12:25:04 -0600619void
620process_command_hyperbolic_cordinate(char *command)
621{
622 if(command==NULL)
623 {
624 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
625 return;
626 }
627
628 char *rem;
629 const char *sep=" \t\n\r";
630 char *radious;
631 char *theta;
632
633 radious=strtok_r(command,sep,&rem);
634 if (radious == NULL )
635 {
636 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
637 return;
638 }
639
640 theta=strtok_r(NULL,sep,&rem);
641 if (theta == NULL )
642 {
643 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
644 return;
645 }
646
647 nlsr->cor_r=strtof(radious,NULL);
648 nlsr->cor_theta=strtof(theta,NULL);
649
650}
651
akmhoque8fdd6412012-12-04 15:05:33 -0600652void
akmhoque596f7082013-02-04 13:34:13 -0600653process_command_tunnel_type(char *command)
654{
655 if(command==NULL)
656 {
657 printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
658 return;
659 }
660 char *rem;
661 const char *sep=" \t\n";
662 char *on_off;
663
664 on_off=strtok_r(command,sep,&rem);
665 if(on_off==NULL)
666 {
667 printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
668 return;
669 }
670
671 if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
672 {
673 nlsr->tunnel_type=IPPROTO_TCP;
674 }
675}
676
677void
akmhoque8fdd6412012-12-04 15:05:33 -0600678process_conf_command(char *command)
679{
680 const char *separators=" \t\n";
681 char *remainder=NULL;
682 char *cmd_type=NULL;
683
684 if(command==NULL || strlen(command)==0 || command[0]=='!')
685 return;
686
687 cmd_type=strtok_r(command,separators,&remainder);
688
689 if(!strcmp(cmd_type,"router-name") )
690 {
691 process_command_router_name(remainder);
692 }
693 else if(!strcmp(cmd_type,"ccnneighbor") )
694 {
695 process_command_ccnneighbor(remainder);
696 }
697 else if(!strcmp(cmd_type,"ccnname") )
698 {
699 process_command_ccnname(remainder);
700 }
701 else if(!strcmp(cmd_type,"lsdb-synch-interval") )
702 {
703 process_command_lsdb_synch_interval(remainder);
704 }
705 else if(!strcmp(cmd_type,"interest-retry") )
706 {
707 process_command_interest_retry(remainder);
708 }
709 else if(!strcmp(cmd_type,"interest-resend-time") )
710 {
711 process_command_interest_resend_time(remainder);
712 }
713 else if(!strcmp(cmd_type,"lsa-refresh-time") )
714 {
715 process_command_lsa_refresh_time(remainder);
716 }
717 else if(!strcmp(cmd_type,"router-dead-interval") )
718 {
719 process_command_router_dead_interval(remainder);
720 }
721 else if(!strcmp(cmd_type,"multi-path-face-num") )
722 {
723 process_command_multi_path_face_num(remainder);
724 }
725 else if(!strcmp(cmd_type,"logdir") )
726 {
727 process_command_logdir(remainder);
728 }
729 else if(!strcmp(cmd_type,"detailed-log") )
730 {
731 process_command_detailed_log(remainder);
732 }
733 else if(!strcmp(cmd_type,"debug") )
734 {
735 process_command_debug(remainder);
736 }
akmhoque09c0afa2012-12-14 09:27:00 -0600737 else if(!strcmp(cmd_type,"topo-prefix") )
738 {
739 process_command_topo_prefix(remainder);
740 }
741 else if(!strcmp(cmd_type,"slice-prefix") )
742 {
743 process_command_slice_prefix(remainder);
744 }
akmhoqueed418f32013-01-30 12:25:04 -0600745 else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
746 {
747 process_command_hyperbolic_cordinate(remainder);
748 }
akmhoque596f7082013-02-04 13:34:13 -0600749 else if(!strcmp(cmd_type,"hyperbolic-routing") )
750 {
751 process_command_hyperbolic_routing(remainder);
752 }
753 else if(!strcmp(cmd_type,"tunnel-type") )
754 {
755 process_command_tunnel_type(remainder);
756 }
akmhoque8fdd6412012-12-04 15:05:33 -0600757 else
758 {
759 printf("Wrong configuration Command %s \n",cmd_type);
760 }
761}
762
763
764int
765readConfigFile(const char *filename)
766{
767 FILE *cfg;
768 char buf[1024];
769 int len;
770
771 cfg=fopen(filename, "r");
772
773 if(cfg == NULL)
774 {
775 printf("\nConfiguration File does not exists\n");
776 exit(1);
777 }
778
779 while(fgets((char *)buf, sizeof(buf), cfg))
780 {
781 len=strlen(buf);
782 if(buf[len-1] == '\n')
783 buf[len-1]='\0';
784 if ( buf[0] != '#' && buf[0] != '!')
785 process_conf_command(buf);
786 }
787
788 fclose(cfg);
789
790 return 0;
791}
792
akmhoquea37b52c2012-12-14 11:16:36 -0600793
794void
795add_faces_for_nbrs(void)
796{
797 int i, adl_element;
798 struct ndn_neighbor *nbr;
799
800 struct hashtb_enumerator ee;
801 struct hashtb_enumerator *e = &ee;
802
803 hashtb_start(nlsr->adl, e);
804 adl_element=hashtb_n(nlsr->adl);
805
806 for(i=0;i<adl_element;i++)
807 {
808 nbr=e->data;
akmhoque596f7082013-02-04 13:34:13 -0600809 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name, (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
akmhoquea37b52c2012-12-14 11:16:36 -0600810 update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);
811 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id);
akmhoquea37b52c2012-12-14 11:16:36 -0600812 hashtb_next(e);
813 }
814
815 hashtb_end(e);
816
817}
818
akmhoque61a57f22013-01-18 07:44:05 -0600819void
820destroy_faces_for_nbrs(void)
821{
822 int i, adl_element;
823 struct ndn_neighbor *nbr;
824
825 struct hashtb_enumerator ee;
826 struct hashtb_enumerator *e = &ee;
827
828 hashtb_start(nlsr->adl, e);
829 adl_element=hashtb_n(nlsr->adl);
830
831 for(i=0;i<adl_element;i++)
832 {
akmhoqueed418f32013-01-30 12:25:04 -0600833 nbr=e->data;
834 if ( nbr->face > 0 )
835 {
akmhoqueed418f32013-01-30 12:25:04 -0600836 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face);
akmhoque596f7082013-02-04 13:34:13 -0600837 add_delete_ccn_face_by_face_id(nlsr->ccn,(const char *)nbr->neighbor->name,OP_UNREG,nbr->face);
akmhoqueed418f32013-01-30 12:25:04 -0600838 }
akmhoque61a57f22013-01-18 07:44:05 -0600839 hashtb_next(e);
840 }
841
842 hashtb_end(e);
843
844}
845
akmhoque8fdd6412012-12-04 15:05:33 -0600846char *
847process_api_client_command(char *command)
848{
849 char *msg;
850 msg=(char *)malloc(100);
Syed Obaid Amin4c959562012-12-21 16:43:21 -0600851 memset(msg,0,100);
akmhoque8fdd6412012-12-04 15:05:33 -0600852
853 const char *sep=" \t\n";
854 char *rem=NULL;
855 char *cmd_type=NULL;
856 char *op_type=NULL;
857 char *name=NULL;
858 char *face=NULL;
859 int face_id;
860 int res;
861
862 op_type=strtok_r(command,sep,&rem);
863 cmd_type=strtok_r(NULL,sep,&rem);
864 name=strtok_r(NULL,sep,&rem);
865 if ( name[strlen(name)-1] == '/' )
866 name[strlen(name)-1]='\0';
867
868 struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
869 np->name=(char *)malloc(strlen(name)+1);
870 memset(np->name,0,strlen(name)+1);
871 memcpy(np->name,name,strlen(name)+1);
872 np->length=strlen(name)+1;
873
874 if ( strcmp(cmd_type,"name")!= 0 )
875 {
876 face=strtok_r(NULL,sep,&rem);
877 sscanf(face,"face%d",&face_id);
878 }
879
880 if ( strcmp(cmd_type,"name")== 0 )
881 {
882 if ( strcmp(op_type,"del") == 0 )
883 {
884 res=does_name_exist_in_npl(np);
885 if ( res == 0)
886 {
887 sprintf(msg,"Name %s does not exist !!",name);
888 }
889 else
890 {
891 long int ls_id=get_lsa_id_from_npl(np);
892 if ( ls_id != 0 )
893 {
894 make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id);
895 sprintf(msg,"Name %s has been deleted and Advertised.",name);
896 }
897 else
898 {
899 sprintf(msg,"Name %s does not have an Name LSA yet !!",name);
900 }
901 }
902 }
903 else if ( strcmp(op_type,"add") == 0 )
904 {
905 res=does_name_exist_in_npl(np);
906 if ( res == 0)
907 {
908 add_name_to_npl(np);
909 build_and_install_single_name_lsa(np);
910 sprintf(msg,"Name %s has been added to advertise.",name);
911 }
912 else
913 {
914 sprintf(msg,"Name %s has already been advertised from this router !!",name);
915 }
916 }
917 }
918 else if ( strcmp(cmd_type,"neighbor") == 0 )
919 {
920 if ( strcmp(op_type,"del") == 0 )
921 {
922 res=is_neighbor(np->name);
923 if ( res == 0)
924 {
925 sprintf(msg,"Neighbor %s does not exist !!",name);
926 }
927 else
928 {
929 update_adjacent_status_to_adl(np,NBR_DOWN);
930 delete_nbr_from_adl(np);
931 if(!nlsr->is_build_adj_lsa_sheduled)
932 {
933 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
934 nlsr->is_build_adj_lsa_sheduled=1;
935 }
936 sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name);
937 }
938 }
939 else if ( strcmp(op_type,"add") == 0 )
940 {
941 res=is_neighbor(np->name);
942 if ( res == 0 )
943 {
akmhoque09c0afa2012-12-14 09:27:00 -0600944 struct name_prefix *nbr_name=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
945 get_host_name_from_command_string(nbr_name,np->name,0);
946 printf("Hostname of neighbor: %s ",nbr_name->name);
947
akmhoquea37b52c2012-12-14 11:16:36 -0600948 char *ip_addr=(char *)malloc(13);
Syed Obaid Amin4c959562012-12-21 16:43:21 -0600949 memset(ip_addr,0,13);
akmhoquea37b52c2012-12-14 11:16:36 -0600950 get_ip_from_hostname_02(nbr_name->name,ip_addr);
951 printf("IP Address: %s \n",ip_addr);
akmhoque596f7082013-02-04 13:34:13 -0600952 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type);
akmhoquea37b52c2012-12-14 11:16:36 -0600953 update_face_to_adl_for_nbr(nbr_name->name, face_id);
954 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id);
955
956 add_nbr_to_adl(np,face_id,ip_addr);
957
akmhoque8fdd6412012-12-04 15:05:33 -0600958 sprintf(msg,"Neighbor %s has been added to adjacency list.",name);
akmhoquea37b52c2012-12-14 11:16:36 -0600959
akmhoque8fdd6412012-12-04 15:05:33 -0600960 }
961 else
962 {
963 sprintf(msg,"Neighbor %s already exists in adjacency list.",name);
964 }
965 }
966 }
967
968
969 return msg;
970}
971
972int
973nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
974{
975 struct timeval timeout;
akmhoque21ffec22013-01-31 18:22:10 -0600976 if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
akmhoque8fdd6412012-12-04 15:05:33 -0600977 {
akmhoque21ffec22013-01-31 18:22:10 -0600978 timeout.tv_sec=0;
979 timeout.tv_usec=time_out_micro_sec;
akmhoque8fdd6412012-12-04 15:05:33 -0600980 }
akmhoque21ffec22013-01-31 18:22:10 -0600981 else
akmhoque8fdd6412012-12-04 15:05:33 -0600982 {
akmhoque21ffec22013-01-31 18:22:10 -0600983 timeout.tv_sec = 0;
984 timeout.tv_usec = 500000;
akmhoque8fdd6412012-12-04 15:05:33 -0600985 }
akmhoque8fdd6412012-12-04 15:05:33 -0600986
987 int fd;
988 int nread;
989 int result;
990 fd_set testfds;
991 unsigned int client_len;
992 int client_sockfd;
993 char recv_buffer[1024];
994 bzero(recv_buffer,1024);
995 struct sockaddr_in client_address;
996
997 testfds=nlsr->readfds;
998 result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);
999
soamin29b8e392013-01-22 17:12:07 -06001000 for(fd = 0; fd < FD_SETSIZE && result > 0; fd++)
akmhoque8fdd6412012-12-04 15:05:33 -06001001 {
1002 if(FD_ISSET(fd,&testfds))
1003 {
1004 if ( fd == ccn_fd )
1005 {
1006 return 0;
1007 }
1008 else if(fd == nlsr->nlsr_api_server_sock_fd)
1009 {
1010 client_len = sizeof(client_address);
1011 client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len);
1012 FD_SET(client_sockfd, &nlsr->readfds);
1013 }
1014 else
1015 {
1016
1017 ioctl(fd, FIONREAD, &nread);
1018 if(nread == 0)
1019 {
1020 close(fd);
1021 FD_CLR(fd, &nlsr->readfds);
1022 }
1023 else
1024 {
1025 recv(fd, recv_buffer, 1024, 0);
1026 printf("Received Data from NLSR API cleint: %s \n",recv_buffer);
1027 char *msg=process_api_client_command(recv_buffer);
1028 send(fd, msg, strlen(msg),0);
1029 free(msg);
1030 close(fd);
1031 FD_CLR(fd, &nlsr->readfds);
1032 }
1033 }
1034 }
1035 }
1036
1037 return 0;
1038}
1039
1040void
1041nlsr_destroy( void )
1042{
1043 if ( nlsr->debugging )
1044 {
1045 printf("Freeing Allocated Memory....\n");
1046 }
1047 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n");
1048 /* Destroying all face created by nlsr in CCND */
1049 destroy_all_face_by_nlsr();
akmhoque61a57f22013-01-18 07:44:05 -06001050 destroy_faces_for_nbrs();
akmhoque8fdd6412012-12-04 15:05:33 -06001051 /* Destroying every hash table attached to each neighbor in ADL before destorying ADL */
1052 hashtb_destroy(&nlsr->npl);
1053 hashtb_destroy(&nlsr->adl);
1054 hashtb_destroy(&nlsr->lsdb->name_lsdb);
1055 hashtb_destroy(&nlsr->lsdb->adj_lsdb);
1056 hashtb_destroy(&nlsr->pit_alsa);
1057
akmhoqueed418f32013-01-30 12:25:04 -06001058
akmhoque8fdd6412012-12-04 15:05:33 -06001059
1060 hashtb_destroy(&nlsr->routing_table);
1061
1062
1063 int i, npt_element;
1064 struct npt_entry *ne;
1065 struct hashtb_enumerator ee;
1066 struct hashtb_enumerator *e = &ee;
1067 hashtb_start(nlsr->npt, e);
1068 npt_element=hashtb_n(nlsr->npt);
1069 for(i=0;i<npt_element;i++)
1070 {
1071 ne=e->data;
1072 hashtb_destroy(&ne->name_list);
1073 hashtb_destroy(&ne->face_list);
1074 hashtb_next(e);
1075 }
1076
1077 hashtb_end(e);
1078 hashtb_destroy(&nlsr->npt);
1079
1080
1081 ccns_close(&nlsr->ccns, NULL, NULL);
1082 ccns_slice_destroy(&nlsr->slice);
1083
1084
1085
1086 close(nlsr->nlsr_api_server_sock_fd);
1087
1088 ccn_schedule_destroy(&nlsr->sched);
1089 ccn_destroy(&nlsr->ccn);
1090
1091 free(nlsr->lsdb->lsdb_version);
1092 free(nlsr->lsdb);
1093 free(nlsr->router_name);
1094 free(nlsr);
1095 if ( nlsr->debugging )
1096 {
1097 printf("Finished freeing allocated memory\n");
1098 }
1099 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");
1100
1101}
1102
1103
1104
1105void
1106init_api_server(int ccn_fd)
1107{
1108 int server_sockfd;
1109 int server_len;
1110 struct sockaddr_in server_address;
1111 unsigned int yes=1;
1112
1113 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
1114
1115 int flags = fcntl(server_sockfd, F_GETFL, 0);
1116 fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);
1117
1118 if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
1119 {
1120 ON_ERROR_DESTROY(-1);
1121 }
1122
1123 server_address.sin_family = AF_INET;
Adam Alyyanc350e3a2013-01-14 14:35:57 -06001124 server_address.sin_addr.s_addr = INADDR_ANY;
1125 server_address.sin_port = htons(nlsr->api_port);
akmhoque8fdd6412012-12-04 15:05:33 -06001126
1127 server_len = sizeof(server_address);
1128 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
1129 listen(server_sockfd, 100);
1130 FD_ZERO(&nlsr->readfds);
1131 FD_SET(server_sockfd, &nlsr->readfds);
1132 FD_SET(ccn_fd, &nlsr->readfds);
1133 nlsr->nlsr_api_server_sock_fd=server_sockfd;
1134
1135}
1136
1137int
1138init_nlsr(void)
1139{
1140 if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
1141 {
1142 perror("SIGQUIT install error\n");
1143 return -1;
1144 }
1145 if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
1146 {
1147 perror("SIGTERM install error\n");
1148 return -1;
1149 }
1150 if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
1151 {
1152 perror("SIGTERM install error\n");
1153 return -1;
1154 }
1155
1156 nlsr=(struct nlsr *)malloc(sizeof(struct nlsr));
1157
1158 struct hashtb_param param_adl = {0};
1159 nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), &param_adl);
1160 struct hashtb_param param_npl = {0};
1161 nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), &param_npl);
1162 struct hashtb_param param_pit_alsa = {0};
1163 nlsr->pit_alsa = hashtb_create(sizeof(struct pending_interest), &param_pit_alsa);
1164 struct hashtb_param param_npt = {0};
1165 nlsr->npt = hashtb_create(sizeof(struct npt_entry), &param_npt);
1166 struct hashtb_param param_rte = {0};
1167 nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), &param_rte);
1168
1169 nlsr->in_interest.p = &incoming_interest;
1170 nlsr->in_content.p = &incoming_content;
1171
1172 nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
1173
1174 char *time_stamp=(char *)malloc(20);
1175 memset(time_stamp,0,20);
1176 get_current_timestamp_micro(time_stamp);
1177 nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1);
akmhoqueed418f32013-01-30 12:25:04 -06001178 memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp));
akmhoque8fdd6412012-12-04 15:05:33 -06001179 free(time_stamp);
1180
1181 struct hashtb_param param_adj_lsdb = {0};
1182 nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), &param_adj_lsdb);
1183 struct hashtb_param param_name_lsdb = {0};
1184 nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), &param_name_lsdb);
akmhoqueed418f32013-01-30 12:25:04 -06001185 struct hashtb_param param_cor_lsdb = {0};
1186 nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), &param_cor_lsdb);
akmhoque8fdd6412012-12-04 15:05:33 -06001187
1188
1189
1190
1191 nlsr->is_synch_init=1;
1192 nlsr->nlsa_id=0;
1193 nlsr->adj_build_flag=0;
1194 nlsr->adj_build_count=0;
1195 nlsr->is_build_adj_lsa_sheduled=0;
1196 nlsr->is_send_lsdb_interest_scheduled=0;
1197 nlsr->is_route_calculation_scheduled=0;
1198
1199 nlsr->detailed_logging=0;
1200 nlsr->debugging=0;
1201
1202 nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
1203 nlsr->interest_retry = INTEREST_RETRY;
1204 nlsr->interest_resend_time = INTEREST_RESEND_TIME;
1205 nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
1206 nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
1207 nlsr->multi_path_face_num=MULTI_PATH_FACE_NUM;
1208 nlsr->semaphor=NLSR_UNLOCKED;
1209
1210 nlsr->api_port=API_PORT;
1211
akmhoque8fdd6412012-12-04 15:05:33 -06001212 nlsr->topo_prefix=(char *)malloc(strlen("/ndn/routing/nlsr")+1);
Syed Obaid Amin4c959562012-12-21 16:43:21 -06001213 memset(nlsr->topo_prefix,0,strlen("/ndn/routing/nlsr")+1);
akmhoque8fdd6412012-12-04 15:05:33 -06001214 memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
1215
1216 nlsr->slice_prefix=(char *)malloc(strlen("/ndn/routing/nlsr/LSA")+1);
Syed Obaid Amin4c959562012-12-21 16:43:21 -06001217 memset(nlsr->slice_prefix, 0, strlen("/ndn/routing/nlsr/LSA")+1);
akmhoque8fdd6412012-12-04 15:05:33 -06001218 memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
1219
akmhoque09c0afa2012-12-14 09:27:00 -06001220 nlsr->is_hyperbolic_calc=0;
akmhoqueed418f32013-01-30 12:25:04 -06001221 nlsr->cor_r=-1.0;
1222 nlsr->cor_theta=-1.0;
akmhoque09c0afa2012-12-14 09:27:00 -06001223
akmhoque596f7082013-02-04 13:34:13 -06001224 nlsr->tunnel_type=IPPROTO_UDP;
1225
akmhoque8fdd6412012-12-04 15:05:33 -06001226 return 0;
1227}
1228
1229
1230int
1231main(int argc, char *argv[])
1232{
1233 int res, ret;
1234 char *config_file;
1235 int daemon_mode=0;
1236 int port=0;
1237
1238
1239
1240 while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1)
1241 {
1242 switch (res)
1243 {
1244 case 'd':
1245 daemon_mode = 1;
1246 break;
1247 case 'f':
1248 config_file = optarg;
1249 break;
1250 case 'p':
1251 port = atoi(optarg);
1252 break;
1253 case 'h':
1254 default:
1255 usage(argv[0]);
1256 }
1257 }
1258
1259 ret=init_nlsr();
1260 ON_ERROR_EXIT(ret);
1261
1262 if ( port !=0 )
1263 nlsr->api_port=port;
1264
1265 readConfigFile(config_file);
akmhoque09c0afa2012-12-14 09:27:00 -06001266
akmhoque596f7082013-02-04 13:34:13 -06001267 if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) )
akmhoqueed418f32013-01-30 12:25:04 -06001268 {
1269 fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
1270 ON_ERROR_DESTROY(-1);
1271 }
akmhoquea37b52c2012-12-14 11:16:36 -06001272 print_adjacent_from_adl();
1273
akmhoque8fdd6412012-12-04 15:05:33 -06001274 if ( daemon_mode == 1 )
1275 {
akmhoquebaf53f12013-01-24 11:06:18 -06001276 nlsr->debugging=0;
akmhoque8fdd6412012-12-04 15:05:33 -06001277 daemonize_nlsr();
1278 }
1279
1280 startLogging(nlsr->logDir);
1281
1282 nlsr->ccn=ccn_create();
1283 int ccn_fd=ccn_connect(nlsr->ccn, NULL);
1284 if(ccn_fd == -1)
1285 {
1286 fprintf(stderr,"Could not connect to ccnd\n");
1287 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
1288 ON_ERROR_DESTROY(-1);
1289 }
1290
1291 init_api_server(ccn_fd);
1292
akmhoquefc5176d2013-01-18 09:50:12 -06001293 res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
1294 if(res<0)
1295 {
1296 fprintf(stderr, "Can not create slice for prefix %s\n",nlsr->slice_prefix);
1297 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for prefix %s\n",nlsr->slice_prefix);
1298 ON_ERROR_DESTROY(res);
1299 }
akmhoque8fdd6412012-12-04 15:05:33 -06001300 struct ccn_charbuf *router_prefix;
1301 router_prefix=ccn_charbuf_create();
1302 res=ccn_name_from_uri(router_prefix,nlsr->router_name);
1303 if(res<0)
1304 {
1305 fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
1306 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Bad ccn URI: %s\n",nlsr->router_name);
1307 ON_ERROR_DESTROY(res);
1308 }
1309
1310 ccn_name_append_str(router_prefix,"nlsr");
1311 nlsr->in_interest.data=nlsr->router_name;
1312 res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
1313 if ( res < 0 )
1314 {
1315 fprintf(stderr,"Failed to register interest for router\n");
1316 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Failed to register interest for router\n");
1317 ON_ERROR_DESTROY(res);
1318 }
1319 ccn_charbuf_destroy(&router_prefix);
1320
1321 if ( nlsr->debugging )
1322 printf("Router Name : %s\n",nlsr->router_name);
1323 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
1324 if ( nlsr->debugging )
1325 printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
1326 writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
1327
akmhoquea37b52c2012-12-14 11:16:36 -06001328 add_faces_for_nbrs();
akmhoque8fdd6412012-12-04 15:05:33 -06001329 print_name_prefix_from_npl();
1330 print_adjacent_from_adl();
akmhoque596f7082013-02-04 13:34:13 -06001331 build_and_install_name_lsas();
akmhoque8fdd6412012-12-04 15:05:33 -06001332
1333 sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
1334
akmhoque596f7082013-02-04 13:34:13 -06001335
1336 print_name_lsdb();
1337 build_and_install_cor_lsa();
akmhoque8fdd6412012-12-04 15:05:33 -06001338 write_name_lsdb_to_repo(nlsr->slice_prefix);
1339
akmhoque8fdd6412012-12-04 15:05:33 -06001340 nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
akmhoque4ae16942012-12-10 11:50:43 -06001341 nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
1342 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoque8fdd6412012-12-04 15:05:33 -06001343
1344
1345 while(1)
1346 {
1347 if ( nlsr->semaphor == NLSR_UNLOCKED )
1348 {
1349 if( nlsr->sched != NULL )
1350 {
1351 long int micro_sec=ccn_schedule_run(nlsr->sched);
1352 res=nlsr_api_server_poll(micro_sec,ccn_fd);
1353 ON_ERROR_DESTROY(res);
1354 }
1355 if(nlsr->ccn != NULL)
1356 {
akmhoque719a4fc2013-01-31 16:11:52 -06001357 res = ccn_run(nlsr->ccn, 1);
akmhoque8fdd6412012-12-04 15:05:33 -06001358 }
1359 if (!(nlsr->sched && nlsr->ccn))
1360 {
1361 break;
1362 }
1363 }
1364
1365 }
1366
1367
1368 return 0;
1369}
1370