blob: e4183eeb6ae68856a0f8b2a3e71be757feddfe4c [file] [log] [blame]
akmhoque1771c412012-11-09 13:06:08 -06001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
akmhoque59980a52012-08-09 12:36:09 -05004#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
akmhoquebfefef22012-09-26 10:09:34 -05007#include <sys/stat.h>
akmhoque59980a52012-08-09 12:36:09 -05008#include <assert.h>
akmhoque1771c412012-11-09 13:06:08 -06009#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>
akmhoque95041802012-11-16 09:18:02 -060015#include <netinet/in.h>
16#include <netdb.h>
17#include <arpa/inet.h>
akmhoque1771c412012-11-09 13:06:08 -060018
akmhoque59980a52012-08-09 12:36:09 -050019#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
akmhoquebfefef22012-09-26 10:09:34 -050022
akmhoque59980a52012-08-09 12:36:09 -050023#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>
akmhoqueb77b95f2013-02-08 12:28:47 -060029#include <ccn/sync.h>
30#include <ccn/seqwriter.h>
akmhoque184dde02013-02-14 15:53:24 -060031#include <ccn/ccn_private.h>
akmhoque59980a52012-08-09 12:36:09 -050032
33#include "nlsr.h"
34#include "nlsr_ndn.h"
akmhoque902d57e2012-08-17 09:24:38 -050035#include "nlsr_lsdb.h"
akmhoque53f64222012-09-05 13:57:51 -050036#include "utility.h"
akmhoque03004e62012-09-06 01:12:28 -050037#include "nlsr_npl.h"
38#include "nlsr_adl.h"
akmhoque3560cb62012-09-09 10:52:30 -050039#include "nlsr_npt.h"
40#include "nlsr_route.h"
akmhoqueb77b95f2013-02-08 12:28:47 -060041#include "nlsr_sync.h"
42#include "nlsr_face.h"
43#include "nlsr_fib.h"
akmhoque237239c2013-03-18 10:29:26 -050044#include "nlsr_km.h"
akmhoque3560cb62012-09-09 10:52:30 -050045
46
akmhoque81c25e02012-09-10 14:50:33 -050047#define ON_ERROR_DESTROY(resval) \
48{ \
Obaid Amin2a928a52013-02-20 11:06:51 -060049 if ((resval) < 0) { \
50 nlsr_destroy(); \
51 exit(1);\
52 } \
akmhoque81c25e02012-09-10 14:50:33 -050053}
54
55
56#define ON_ERROR_EXIT(resval) \
57{ \
Obaid Amin2a928a52013-02-20 11:06:51 -060058 if ((resval) < 0) { \
59 exit(1); \
60 } \
akmhoque81c25e02012-09-10 14:50:33 -050061}
akmhoque59980a52012-08-09 12:36:09 -050062
63struct option longopts[] =
64{
Obaid Amin2a928a52013-02-20 11:06:51 -060065 { "daemon", no_argument, NULL, 'd'},
66 { "config_file", required_argument, NULL, 'f'},
67 { "api_port", required_argument, NULL, 'p'},
68 { "help", no_argument, NULL, 'h'},
69 { 0 }
akmhoque59980a52012-08-09 12:36:09 -050070};
71
Obaid Amin2a928a52013-02-20 11:06:51 -060072 static int
akmhoque59980a52012-08-09 12:36:09 -050073usage(char *progname)
74{
75
Obaid Amin2a928a52013-02-20 11:06:51 -060076 printf("Usage: %s [OPTIONS...]\n\
77 NDN routing....\n\
78 -d, --daemon Run in daemon mode\n\
79 -f, --config_file Specify configuration file name\n\
80 -p, --api_port port where api client will connect\n\
81 -h, --help Display this help message\n", progname);
akmhoque59980a52012-08-09 12:36:09 -050082
Obaid Amin2a928a52013-02-20 11:06:51 -060083 exit(1);
akmhoque59980a52012-08-09 12:36:09 -050084}
85
86void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result)
87{
Obaid Amin2a928a52013-02-20 11:06:51 -060088 struct timeval now = {0};
89 gettimeofday(&now, 0);
90 result->s = now.tv_sec;
91 result->micros = now.tv_usec;
akmhoque59980a52012-08-09 12:36:09 -050092}
93
94static struct ccn_gettime ndn_rtr_ticker = {
Obaid Amin2a928a52013-02-20 11:06:51 -060095 "timer",
96 &ndn_rtr_gettime,
97 1000000,
98 NULL
akmhoque59980a52012-08-09 12:36:09 -050099};
100
Obaid Amin2a928a52013-02-20 11:06:51 -0600101 void
akmhoqueffacaa82012-09-13 17:48:30 -0500102nlsr_lock(void)
103{
104 nlsr->semaphor=NLSR_LOCKED;
105}
106
Obaid Amin2a928a52013-02-20 11:06:51 -0600107 void
akmhoqueffacaa82012-09-13 17:48:30 -0500108nlsr_unlock(void)
109{
110 nlsr->semaphor=NLSR_UNLOCKED;
111}
akmhoque42098b12012-08-27 22:54:23 -0500112
Obaid Amin2a928a52013-02-20 11:06:51 -0600113 void
akmhoque03004e62012-09-06 01:12:28 -0500114nlsr_stop_signal_handler(int sig)
akmhoque42098b12012-08-27 22:54:23 -0500115{
akmhoque03004e62012-09-06 01:12:28 -0500116 signal(sig, SIG_IGN);
Obaid Amin2a928a52013-02-20 11:06:51 -0600117 nlsr_destroy();
akmhoqueffacaa82012-09-13 17:48:30 -0500118 exit(0);
akmhoque59980a52012-08-09 12:36:09 -0500119}
120
Obaid Amin2a928a52013-02-20 11:06:51 -0600121 void
akmhoquebfefef22012-09-26 10:09:34 -0500122daemonize_nlsr(void)
123{
akmhoqueb28579d2013-02-12 11:15:52 -0600124 //int ret;
akmhoquebfefef22012-09-26 10:09:34 -0500125 pid_t process_id = 0;
126 pid_t sid = 0;
127 process_id = fork();
128 if (process_id < 0)
129 {
akmhoque7b791452012-10-30 11:24:56 -0500130 printf("Daemonization failed!\n");
akmhoquebfefef22012-09-26 10:09:34 -0500131 ON_ERROR_DESTROY(process_id);
132 }
133 if (process_id > 0)
134 {
135 printf("Process daemonized. Process id: %d \n", process_id);
akmhoqueb28579d2013-02-12 11:15:52 -0600136 //ret=process_id;
akmhoquebfefef22012-09-26 10:09:34 -0500137 exit(0);
138 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600139
akmhoquebfefef22012-09-26 10:09:34 -0500140 umask(0);
141 sid = setsid();
142 if(sid < 0)
143 {
144 ON_ERROR_DESTROY(sid);
145 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600146
akmhoquebfefef22012-09-26 10:09:34 -0500147 chdir("/");
akmhoqueb63a41e2013-03-01 12:00:20 -0600148 //close(STDIN_FILENO);
149 //close(STDOUT_FILENO);
150 //close(STDERR_FILENO);
akmhoquebfefef22012-09-26 10:09:34 -0500151}
152
Obaid Amin2a928a52013-02-20 11:06:51 -0600153 void
akmhoque59980a52012-08-09 12:36:09 -0500154process_command_ccnneighbor(char *command)
155{
156 if(command==NULL)
157 {
akmhoque28c45022012-08-09 15:38:02 -0500158 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
akmhoque59980a52012-08-09 12:36:09 -0500159 return;
160 }
161 char *rem;
162 const char *sep=" \t\n";
akmhoqueb77b95f2013-02-08 12:28:47 -0600163 char *rtr_name;
164 char *nbr_ip_addr;
165 int is_ip_configured=0;
akmhoque7c234e02013-02-13 11:23:56 -0600166 char *ip_addr=(char *)calloc(20,sizeof(char));
akmhoque59980a52012-08-09 12:36:09 -0500167
akmhoque28c45022012-08-09 15:38:02 -0500168 rtr_name=strtok_r(command,sep,&rem);
169 if(rtr_name==NULL)
akmhoque59980a52012-08-09 12:36:09 -0500170 {
akmhoque28c45022012-08-09 15:38:02 -0500171 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
akmhoque59980a52012-08-09 12:36:09 -0500172 return;
173 }
akmhoqued5152122012-09-19 06:44:23 -0500174 if ( rtr_name[strlen(rtr_name)-1] == '/' )
175 {
176 rtr_name[strlen(rtr_name)-1]='\0';
177 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600178
179 if (rem != NULL )
180 {
181 nbr_ip_addr=strtok_r(NULL,sep,&rem);
akmhoque958ccf72013-02-11 10:42:03 -0600182 if ( nbr_ip_addr != NULL)
183 is_ip_configured=1;
akmhoqueb77b95f2013-02-08 12:28:47 -0600184 }
akmhoque7c234e02013-02-13 11:23:56 -0600185 struct name_prefix *nbr=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
186 nbr->name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -0500187 memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
188 nbr->length=strlen(rtr_name)+1;
189
Obaid Amin2a928a52013-02-20 11:06:51 -0600190
akmhoqueb77b95f2013-02-08 12:28:47 -0600191 if ( !is_ip_configured )
192 {
akmhoque7c234e02013-02-13 11:23:56 -0600193 struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoqueb77b95f2013-02-08 12:28:47 -0600194 get_host_name_from_command_string(nbr_name,nbr->name,0);
akmhoque018692c2013-02-11 11:33:39 -0600195 if ( nlsr->debugging)
196 printf("Hostname of neighbor: %s ",nbr_name->name);
akmhoqueb77b95f2013-02-08 12:28:47 -0600197 get_ip_from_hostname_02(nbr_name->name,ip_addr);
akmhoque018692c2013-02-11 11:33:39 -0600198 if ( nlsr->debugging)
199 printf("IP Address: %s \n",ip_addr);
akmhoqueb77b95f2013-02-08 12:28:47 -0600200 free(nbr_name->name);
201 free(nbr_name);
202 }
203 else
204 {
akmhoque6682ca32013-02-22 00:29:35 -0600205 memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr)+1);
akmhoque018692c2013-02-11 11:33:39 -0600206 if (nlsr->debugging)
207 {
208 printf("Name of neighbor: %s ",nbr->name);
209 printf("IP Address: %s \n",ip_addr);
210 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600211 }
212 add_nbr_to_adl(nbr,0,ip_addr);
Obaid Amin2a928a52013-02-20 11:06:51 -0600213
akmhoquececba942013-02-25 17:33:34 -0600214 free(ip_addr);
akmhoque03004e62012-09-06 01:12:28 -0500215 free(nbr->name);
216 free(nbr);
217}
218
Obaid Amin2a928a52013-02-20 11:06:51 -0600219 void
akmhoque03004e62012-09-06 01:12:28 -0500220process_command_ccnname(char *command)
221{
222
223 if(command==NULL)
224 {
225 printf(" Wrong Command Format ( ccnname /name/prefix)\n");
226 return;
227 }
228 char *rem;
229 const char *sep=" \t\n";
230 char *name;
231 name=strtok_r(command,sep,&rem);
232 if(name==NULL)
233 {
234 printf(" Wrong Command Format ( ccnname /name/prefix/ )\n");
235 return;
236 }
237
238 printf("Name Prefix: %s \n",name);
239
akmhoqued5152122012-09-19 06:44:23 -0500240 if ( name[strlen(name)-1] == '/' )
241 name[strlen(name)-1]='\0';
242
akmhoque7c234e02013-02-13 11:23:56 -0600243 struct name_prefix *np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
244 np->name=(char *)calloc(strlen(name)+1,sizeof(char));
245 //memset(np->name,0,strlen(name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500246 memcpy(np->name,name,strlen(name)+1);
247 np->length=strlen(name)+1;
akmhoque386081b2012-08-10 10:53:21 -0500248
akmhoque03004e62012-09-06 01:12:28 -0500249 add_name_to_npl(np);
akmhoque28c45022012-08-09 15:38:02 -0500250
akmhoque03004e62012-09-06 01:12:28 -0500251 free(np->name);
akmhoque53f64222012-09-05 13:57:51 -0500252 free(np);
akmhoque59980a52012-08-09 12:36:09 -0500253}
254
akmhoque03004e62012-09-06 01:12:28 -0500255
Obaid Amin2a928a52013-02-20 11:06:51 -0600256 void
akmhoque03004e62012-09-06 01:12:28 -0500257process_command_router_name(char *command)
258{
259 if(command==NULL)
260 {
261 printf(" Wrong Command Format ( router-name /router/name )\n");
262 return;
263 }
264 char *rem;
265 const char *sep=" \t\n";
266 char *rtr_name;
267
268 rtr_name=strtok_r(command,sep,&rem);
269 if(rtr_name==NULL)
270 {
271 printf(" Wrong Command Format ( router-name /router/name )\n");
272 return;
273 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600274
akmhoque03004e62012-09-06 01:12:28 -0500275
akmhoqued5152122012-09-19 06:44:23 -0500276 if ( rtr_name[strlen(rtr_name)-1] == '/' )
277 rtr_name[strlen(rtr_name)-1]='\0';
278
akmhoque7c234e02013-02-13 11:23:56 -0600279 nlsr->router_name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
280 //memset(nlsr->router_name,0,strlen(rtr_name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500281 memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1);
282
283
284}
285
Obaid Amin2a928a52013-02-20 11:06:51 -0600286
287 void
akmhoqued79438d2012-08-27 13:31:42 -0500288process_command_interest_retry(char *command)
289{
290 if(command==NULL)
291 {
292 printf(" Wrong Command Format ( interest-retry number )\n");
293 return;
294 }
295 char *rem;
296 const char *sep=" \t\n";
akmhoqueffacaa82012-09-13 17:48:30 -0500297 char *retry;
298 long int retry_number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600299
akmhoqueffacaa82012-09-13 17:48:30 -0500300 retry=strtok_r(command,sep,&rem);
301 if(retry==NULL)
akmhoqued79438d2012-08-27 13:31:42 -0500302 {
303 printf(" Wrong Command Format ( interest-retry number)\n");
304 return;
305 }
306
akmhoqueffacaa82012-09-13 17:48:30 -0500307 retry_number=atoi(retry);
308 if ( retry_number >= 1 && retry_number<=10 )
309 {
310 nlsr->interest_retry=retry_number;
311 }
akmhoqued79438d2012-08-27 13:31:42 -0500312
313}
314
Obaid Amin2a928a52013-02-20 11:06:51 -0600315 void
akmhoqued79438d2012-08-27 13:31:42 -0500316process_command_interest_resend_time(char *command)
317{
318 if(command==NULL)
319 {
320 printf(" Wrong Command Format ( interest-resend-time secs )\n");
321 return;
322 }
323 char *rem;
324 const char *sep=" \t\n";
325 char *secs;
326 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600327
akmhoqued79438d2012-08-27 13:31:42 -0500328 secs=strtok_r(command,sep,&rem);
329 if(secs==NULL)
330 {
331 printf(" Wrong Command Format ( interest-resend-time secs)\n");
332 return;
333 }
334
335 seconds=atoi(secs);
akmhoqueffacaa82012-09-13 17:48:30 -0500336 if ( seconds <= 60 && seconds >= 1 )
337 {
338 nlsr->interest_resend_time=seconds;
339 }
akmhoqued79438d2012-08-27 13:31:42 -0500340}
341
akmhoque03004e62012-09-06 01:12:28 -0500342
Obaid Amin2a928a52013-02-20 11:06:51 -0600343 void
akmhoqued5152122012-09-19 06:44:23 -0500344process_command_lsa_refresh_time(char *command)
345{
346 if(command==NULL)
347 {
348 printf(" Wrong Command Format ( lsa-refresh-time secs )\n");
349 return;
350 }
351 char *rem;
352 const char *sep=" \t\n";
353 char *secs;
354 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600355
akmhoqued5152122012-09-19 06:44:23 -0500356 secs=strtok_r(command,sep,&rem);
357 if(secs==NULL)
358 {
359 printf(" Wrong Command Format ( lsa-refresh-time secs)\n");
360 return;
361 }
362
363 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600364 if ( seconds >= 240)
akmhoqued5152122012-09-19 06:44:23 -0500365 {
366 nlsr->lsa_refresh_time=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600367 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
368 {
369 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
370 }
akmhoqued5152122012-09-19 06:44:23 -0500371 }
372
373}
374
Obaid Amin2a928a52013-02-20 11:06:51 -0600375 void
akmhoqued5152122012-09-19 06:44:23 -0500376process_command_router_dead_interval(char *command)
377{
378 if(command==NULL)
379 {
380 printf(" Wrong Command Format ( router-dead-interval secs )\n");
381 return;
382 }
383 char *rem;
384 const char *sep=" \t\n";
385 char *secs;
386 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600387
akmhoqued5152122012-09-19 06:44:23 -0500388 secs=strtok_r(command,sep,&rem);
389 if(secs==NULL)
390 {
391 printf(" Wrong Command Format ( router-dead-interval secs)\n");
392 return;
393 }
394
395 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600396 if ( seconds >= 480 )
akmhoqued5152122012-09-19 06:44:23 -0500397 {
398 nlsr->router_dead_interval=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600399 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
400 {
401 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
402 }
akmhoqued5152122012-09-19 06:44:23 -0500403 }
404
405}
akmhoque03004e62012-09-06 01:12:28 -0500406
Obaid Amin2a928a52013-02-20 11:06:51 -0600407 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600408process_command_max_faces_per_prefix(char *command)
akmhoque3cced642012-09-24 16:20:20 -0500409{
410 if(command==NULL)
411 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600412 printf(" Wrong Command Format ( max-faces-per-prefix n )\n");
akmhoque3cced642012-09-24 16:20:20 -0500413 return;
414 }
415 char *rem;
416 const char *sep=" \t\n";
417 char *num;
418 long int number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600419
akmhoque3cced642012-09-24 16:20:20 -0500420 num=strtok_r(command,sep,&rem);
421 if(num==NULL)
422 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600423 printf(" Wrong Command Format ( max-faces-per-prefix n)\n");
akmhoque3cced642012-09-24 16:20:20 -0500424 return;
425 }
426
427 number=atoi(num);
428 if ( number >= 0 && number <= 60 )
429 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600430 nlsr->max_faces_per_prefix=number;
akmhoque3cced642012-09-24 16:20:20 -0500431 }
432
433}
434
Obaid Amin2a928a52013-02-20 11:06:51 -0600435 void
akmhoquebfefef22012-09-26 10:09:34 -0500436process_command_logdir(char *command)
437{
438 if(command==NULL)
439 {
440 printf(" Wrong Command Format ( logdir /path/to/logdir )\n");
441 return;
442 }
443 char *rem;
444 const char *sep=" \t\n";
445 char *dir;
446
447 dir=strtok_r(command,sep,&rem);
448 if(dir==NULL)
449 {
450 printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
451 return;
452 }
akmhoque0b60ba92013-02-25 17:55:35 -0600453 //if ( nlsr->logDir)
454 //free(nlsr->logDir);
akmhoque7c234e02013-02-13 11:23:56 -0600455 nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600456 memcpy(nlsr->logDir,dir,strlen(dir)+1);
akmhoquebfefef22012-09-26 10:09:34 -0500457}
458
Obaid Amin2a928a52013-02-20 11:06:51 -0600459 void
akmhoque7b791452012-10-30 11:24:56 -0500460process_command_detailed_log(char *command)
461{
462 if(command==NULL)
463 {
464 printf(" Wrong Command Format ( detailed-log on/off )\n");
465 return;
466 }
467 char *rem;
468 const char *sep=" \t\n";
469 char *on_off;
470
471 on_off=strtok_r(command,sep,&rem);
472 if(on_off==NULL)
473 {
474 printf(" Wrong Command Format ( detailed-log on/off )\n");
475 return;
476 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600477
akmhoque7b791452012-10-30 11:24:56 -0500478 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0)
479 {
480 nlsr->detailed_logging=1;
481 }
482}
483
Obaid Amin2a928a52013-02-20 11:06:51 -0600484 void
akmhoque7b791452012-10-30 11:24:56 -0500485process_command_debug(char *command)
486{
487 if(command==NULL)
488 {
489 printf(" Wrong Command Format ( debug on/off )\n");
490 return;
491 }
492 char *rem;
493 const char *sep=" \t\n";
494 char *on_off;
495
496 on_off=strtok_r(command,sep,&rem);
497 if(on_off==NULL)
498 {
499 printf(" Wrong Command Format ( debug on/off )\n");
500 return;
501 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600502
akmhoque7b791452012-10-30 11:24:56 -0500503 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
504 {
505 nlsr->debugging=1;
506 }
507}
508
akmhoqueb77b95f2013-02-08 12:28:47 -0600509
Obaid Amin2a928a52013-02-20 11:06:51 -0600510 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600511process_command_topo_prefix(char *command)
512{
513 if(command==NULL)
514 {
515 printf(" Wrong Command Format ( topo-prefix )\n");
516 return;
517 }
518 char *rem;
519 const char *sep=" \t\n";
520 char *topo_prefix;
521
522 topo_prefix=strtok_r(command,sep,&rem);
523 if(topo_prefix==NULL)
524 {
525 printf(" Wrong Command Format ( topo-prefix /name/prefix )\n");
526 return;
527 }
528 else
529 {
530 if( nlsr->topo_prefix != NULL)
531 free(nlsr->topo_prefix);
532 if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
533 topo_prefix[strlen(topo_prefix)-1]='\0';
akmhoque829228c2013-02-25 17:39:40 -0600534 //if(nlsr->topo_prefix)
535 //free(nlsr->topo_prefix);
akmhoque7c234e02013-02-13 11:23:56 -0600536 nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600537 memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600538 printf ("Topo prefix is: %s\n", nlsr->topo_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600539 }
540}
541
542
Obaid Amin2a928a52013-02-20 11:06:51 -0600543 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600544process_command_slice_prefix(char *command)
545{
546 if(command==NULL)
547 {
548 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
549 return;
550 }
551 char *rem;
552 const char *sep=" \t\n";
553 char *slice_prefix;
554
555 slice_prefix=strtok_r(command,sep,&rem);
556 if(slice_prefix==NULL)
557 {
558 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
559 return;
560 }
561 else
562 {
563 if ( nlsr->slice_prefix != NULL)
564 free(nlsr->slice_prefix);
565 if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
566 slice_prefix[strlen(slice_prefix)-1]='\0';
akmhoque7c234e02013-02-13 11:23:56 -0600567 nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600568 memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600569 printf("Slice prefix: %s \n",nlsr->slice_prefix);
570 }
571}
572
573
574 void
575process_command_root_key_prefix(char *command)
576{
577 if(command==NULL)
578 {
579 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
580 return;
581 }
582 char *rem;
583 const char *sep=" \t\n";
584 char *root_key_prefix;
585
586 root_key_prefix=strtok_r(command,sep,&rem);
587 if(root_key_prefix==NULL)
588 {
589 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
590 return;
591 }
592 else
593 {
594 if ( nlsr->root_key_prefix != NULL)
595 free(nlsr->root_key_prefix);
596 if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' )
597 root_key_prefix[strlen(root_key_prefix)-1]='\0';
598 nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char));
599 memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1);
600 printf("Root key prefix: %s \n",nlsr->root_key_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600601 }
602}
603
Obaid Amin2a928a52013-02-20 11:06:51 -0600604 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600605process_command_hyperbolic_routing(char *command)
606{
607 if(command==NULL)
608 {
609 printf(" Wrong Command Format ( hyperbolic-routing on)\n");
610 return;
611 }
612 char *rem;
613 const char *sep=" \t\n";
614 char *on_off;
615
616 on_off=strtok_r(command,sep,&rem);
617 if(on_off==NULL)
618 {
619 printf(" Wrong Command Format ( hyperbolic-routing on )\n");
620 return;
621 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600622
akmhoqueb77b95f2013-02-08 12:28:47 -0600623 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
624 {
625 nlsr->is_hyperbolic_calc=1;
626 }
627}
628
Obaid Amin2a928a52013-02-20 11:06:51 -0600629 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600630process_command_hyperbolic_cordinate(char *command)
631{
632 if(command==NULL)
633 {
634 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
635 return;
636 }
637
638 char *rem;
639 const char *sep=" \t\n\r";
640 char *radious;
641 char *theta;
642
643 radious=strtok_r(command,sep,&rem);
644 if (radious == NULL )
645 {
646 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
647 return;
648 }
649
650 theta=strtok_r(NULL,sep,&rem);
651 if (theta == NULL )
652 {
653 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
654 return;
655 }
656
657 nlsr->cor_r=strtof(radious,NULL);
658 nlsr->cor_theta=strtof(theta,NULL);
659
660}
661
Obaid Amin2a928a52013-02-20 11:06:51 -0600662 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600663process_command_tunnel_type(char *command)
664{
665 if(command==NULL)
666 {
667 printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
668 return;
669 }
670 char *rem;
671 const char *sep=" \t\n";
672 char *on_off;
673
674 on_off=strtok_r(command,sep,&rem);
675 if(on_off==NULL)
676 {
677 printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
678 return;
679 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600680
akmhoqueb77b95f2013-02-08 12:28:47 -0600681 if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
682 {
683 nlsr->tunnel_type=IPPROTO_TCP;
684 }
685 else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 )
686 {
687 nlsr->tunnel_type=IPPROTO_UDP;
688 }
689}
690
akmhoque7adb2772013-03-05 16:30:59 -0600691void
692process_command_keystore_passphrase(char *command)
693{
694 if(command==NULL)
695 {
696 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
697 return;
698 }
699 char *rem;
700 const char *sep=" \t\n";
701 char *passphrase;
702
703 passphrase=strtok_r(command,sep,&rem);
704 if(passphrase==NULL)
705 {
706 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
707 return;
708 }
709
710 if( nlsr->keystore_passphrase)
711 free(nlsr->keystore_passphrase);
712 nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char));
713 memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase));
714
715
716}
717
718
719void
720process_command_keystore_path(char *command)
721{
722 if(command==NULL)
723 {
724 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
725 return;
726 }
727 char *rem;
728 const char *sep=" \t\n";
729 char *path;
730
731 path=strtok_r(command,sep,&rem);
732 if(path==NULL)
733 {
734 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
735 return;
736 }
737
738 if( nlsr->keystore_path)
739 free(nlsr->keystore_path);
740 nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char));
741 memcpy(nlsr->keystore_path,path,strlen(path));
742
743}
744
745
746
747void
748process_command_site_name(char *command)
749{
750 if(command==NULL)
751 {
752 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
753 return;
754 }
755 char *rem;
756 const char *sep=" \t\n";
757 char *site_name;
758
759 site_name=strtok_r(command,sep,&rem);
760 if(site_name==NULL)
761 {
762 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
763 return;
764 }
765
766 if( nlsr->site_name)
767 free(nlsr->site_name);
768
769 if ( site_name[strlen(site_name)-1] == '/' )
770 site_name[strlen(site_name)-1]='\0';
771
772 nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char));
773 memcpy(nlsr->site_name,site_name,strlen(site_name));
774 printf("Site Name prefix: %s \n",nlsr->site_name);
775
776}
777
778
Obaid Amin2a928a52013-02-20 11:06:51 -0600779 void
akmhoque59980a52012-08-09 12:36:09 -0500780process_conf_command(char *command)
781{
782 const char *separators=" \t\n";
783 char *remainder=NULL;
784 char *cmd_type=NULL;
785
786 if(command==NULL || strlen(command)==0 || command[0]=='!')
787 return;
788
789 cmd_type=strtok_r(command,separators,&remainder);
790
791 if(!strcmp(cmd_type,"router-name") )
792 {
793 process_command_router_name(remainder);
794 }
795 else if(!strcmp(cmd_type,"ccnneighbor") )
796 {
797 process_command_ccnneighbor(remainder);
798 }
799 else if(!strcmp(cmd_type,"ccnname") )
800 {
801 process_command_ccnname(remainder);
802 }
akmhoqued79438d2012-08-27 13:31:42 -0500803 else if(!strcmp(cmd_type,"interest-retry") )
804 {
805 process_command_interest_retry(remainder);
806 }
807 else if(!strcmp(cmd_type,"interest-resend-time") )
808 {
809 process_command_interest_resend_time(remainder);
810 }
akmhoqued5152122012-09-19 06:44:23 -0500811 else if(!strcmp(cmd_type,"lsa-refresh-time") )
812 {
813 process_command_lsa_refresh_time(remainder);
814 }
815 else if(!strcmp(cmd_type,"router-dead-interval") )
816 {
817 process_command_router_dead_interval(remainder);
818 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600819 else if(!strcmp(cmd_type,"max-faces-per-prefix") )
akmhoque3cced642012-09-24 16:20:20 -0500820 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600821 process_command_max_faces_per_prefix(remainder);
akmhoque3cced642012-09-24 16:20:20 -0500822 }
akmhoquebfefef22012-09-26 10:09:34 -0500823 else if(!strcmp(cmd_type,"logdir") )
824 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600825 process_command_logdir(remainder);
akmhoquebfefef22012-09-26 10:09:34 -0500826 }
akmhoque7b791452012-10-30 11:24:56 -0500827 else if(!strcmp(cmd_type,"detailed-log") )
828 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600829 process_command_detailed_log(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500830 }
831 else if(!strcmp(cmd_type,"debug") )
832 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600833 process_command_debug(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500834 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600835 else if(!strcmp(cmd_type,"topo-prefix") )
836 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600837 process_command_topo_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600838 }
839 else if(!strcmp(cmd_type,"slice-prefix") )
840 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600841 process_command_slice_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600842 }
843 else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
844 {
845 process_command_hyperbolic_cordinate(remainder);
846 }
847 else if(!strcmp(cmd_type,"hyperbolic-routing") )
848 {
849 process_command_hyperbolic_routing(remainder);
850 }
851 else if(!strcmp(cmd_type,"tunnel-type") )
852 {
853 process_command_tunnel_type(remainder);
854 }
akmhoque7adb2772013-03-05 16:30:59 -0600855 else if(!strcmp(cmd_type,"site-name") )
856 {
857 process_command_site_name(remainder);
858 }
859 else if(!strcmp(cmd_type,"keystore-path") )
860 {
861 process_command_keystore_path(remainder);
862 }
863 else if(!strcmp(cmd_type,"keystore-passphrase") )
864 {
865 process_command_keystore_passphrase(remainder);
866 }
867 else if(!strcmp(cmd_type,"root-key-prefix") )
868 {
869 process_command_root_key_prefix(remainder);
870 }
akmhoqued5152122012-09-19 06:44:23 -0500871 else
akmhoque59980a52012-08-09 12:36:09 -0500872 {
873 printf("Wrong configuration Command %s \n",cmd_type);
874 }
875}
876
akmhoque03004e62012-09-06 01:12:28 -0500877
Obaid Amin0e9a3002013-02-20 14:55:37 -0600878 int
akmhoque59980a52012-08-09 12:36:09 -0500879readConfigFile(const char *filename)
880{
881 FILE *cfg;
882 char buf[1024];
883 int len;
884
885 cfg=fopen(filename, "r");
886
887 if(cfg == NULL)
888 {
889 printf("\nConfiguration File does not exists\n");
Obaid Amin0e9a3002013-02-20 14:55:37 -0600890 return -1;
akmhoque59980a52012-08-09 12:36:09 -0500891 }
892
893 while(fgets((char *)buf, sizeof(buf), cfg))
894 {
895 len=strlen(buf);
896 if(buf[len-1] == '\n')
Obaid Amin2a928a52013-02-20 11:06:51 -0600897 buf[len-1]='\0';
akmhoqued5152122012-09-19 06:44:23 -0500898 if ( buf[0] != '#' && buf[0] != '!')
899 process_conf_command(buf);
akmhoque59980a52012-08-09 12:36:09 -0500900 }
901
902 fclose(cfg);
903
904 return 0;
905}
906
akmhoqueb77b95f2013-02-08 12:28:47 -0600907
Obaid Amin0e9a3002013-02-20 14:55:37 -0600908 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600909add_faces_for_nbrs(void)
910{
911 int i, adl_element;
912 struct ndn_neighbor *nbr;
913
914 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600915 struct hashtb_enumerator *e = &ee;
916
917 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600918 adl_element=hashtb_n(nlsr->adl);
919
920 for(i=0;i<adl_element;i++)
921 {
922 nbr=e->data;
Obaid Amin2a928a52013-02-20 11:06:51 -0600923 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600924 (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
akmhoqueb77b95f2013-02-08 12:28:47 -0600925 update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);
Obaid Amin2a928a52013-02-20 11:06:51 -0600926 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600927 (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600928 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600929 (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600930 hashtb_next(e);
931 }
932
933 hashtb_end(e);
934
935}
936
Obaid Amin0e9a3002013-02-20 14:55:37 -0600937 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600938destroy_faces_for_nbrs(void)
939{
940 int i, adl_element;
941 struct ndn_neighbor *nbr;
942
943 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600944 struct hashtb_enumerator *e = &ee;
945
946 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600947 adl_element=hashtb_n(nlsr->adl);
948
949 for(i=0;i<adl_element;i++)
950 {
951 nbr=e->data;
952 if ( nbr->face > 0 )
953 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600954 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600955 (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600956 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600957 (const char *)nbr->neighbor->name,OP_UNREG,nbr->face,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600958 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600959 (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600960 }
961 hashtb_next(e);
962 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600963 hashtb_end(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600964}
965
akmhoquead6d5692013-03-11 19:43:33 -0500966
967char *
akmhoque562caef2012-11-09 13:29:06 -0600968process_api_client_command(char *command)
969{
970 char *msg;
971 msg=(char *)malloc(100);
akmhoqueb77b95f2013-02-08 12:28:47 -0600972 memset(msg,0,100);
Obaid Amin2a928a52013-02-20 11:06:51 -0600973
akmhoque3171d652012-11-13 11:44:33 -0600974 const char *sep=" \t\n";
975 char *rem=NULL;
976 char *cmd_type=NULL;
977 char *op_type=NULL;
978 char *name=NULL;
979 char *face=NULL;
980 int face_id;
981 int res;
982
983 op_type=strtok_r(command,sep,&rem);
984 cmd_type=strtok_r(NULL,sep,&rem);
985 name=strtok_r(NULL,sep,&rem);
986 if ( name[strlen(name)-1] == '/' )
987 name[strlen(name)-1]='\0';
988
Obaid Amin2a928a52013-02-20 11:06:51 -0600989 struct name_prefix *np=(struct name_prefix *) calloc (1,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600990 sizeof(struct name_prefix ));
Obaid Amin2a928a52013-02-20 11:06:51 -0600991 np->name = (char *) calloc (strlen(name)+1,sizeof(char));
akmhoque3171d652012-11-13 11:44:33 -0600992 memcpy(np->name,name,strlen(name)+1);
993 np->length=strlen(name)+1;
994
995 if ( strcmp(cmd_type,"name")!= 0 )
996 {
997 face=strtok_r(NULL,sep,&rem);
998 sscanf(face,"face%d",&face_id);
999 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001000
akmhoque3171d652012-11-13 11:44:33 -06001001 if ( strcmp(cmd_type,"name")== 0 )
1002 {
1003 if ( strcmp(op_type,"del") == 0 )
1004 {
1005 res=does_name_exist_in_npl(np);
1006 if ( res == 0)
1007 {
1008 sprintf(msg,"Name %s does not exist !!",name);
1009 }
1010 else
1011 {
1012 long int ls_id=get_lsa_id_from_npl(np);
1013 if ( ls_id != 0 )
1014 {
1015 make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id);
1016 sprintf(msg,"Name %s has been deleted and Advertised.",name);
1017 }
1018 else
1019 {
1020 sprintf(msg,"Name %s does not have an Name LSA yet !!",name);
1021 }
1022 }
1023 }
1024 else if ( strcmp(op_type,"add") == 0 )
1025 {
1026 res=does_name_exist_in_npl(np);
1027 if ( res == 0)
1028 {
1029 add_name_to_npl(np);
1030 build_and_install_single_name_lsa(np);
1031 sprintf(msg,"Name %s has been added to advertise.",name);
1032 }
1033 else
1034 {
1035 sprintf(msg,"Name %s has already been advertised from this router !!",name);
1036 }
1037 }
1038 }
1039 else if ( strcmp(cmd_type,"neighbor") == 0 )
1040 {
1041 if ( strcmp(op_type,"del") == 0 )
1042 {
1043 res=is_neighbor(np->name);
1044 if ( res == 0)
1045 {
1046 sprintf(msg,"Neighbor %s does not exist !!",name);
1047 }
1048 else
1049 {
1050 update_adjacent_status_to_adl(np,NBR_DOWN);
akmhoqueb77b95f2013-02-08 12:28:47 -06001051 int face_id=get_next_hop_face_from_adl(np->name);
akmhoque483c1eb2013-03-08 00:51:09 -06001052 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id,(~0U) >> 1);
1053 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id,(~0U) >> 1);
1054 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_UNREG, face_id,(~0U) >> 1);
akmhoque3171d652012-11-13 11:44:33 -06001055 delete_nbr_from_adl(np);
1056 if(!nlsr->is_build_adj_lsa_sheduled)
1057 {
1058 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1059 nlsr->is_build_adj_lsa_sheduled=1;
1060 }
1061 sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name);
1062 }
1063 }
1064 else if ( strcmp(op_type,"add") == 0 )
1065 {
1066 res=is_neighbor(np->name);
1067 if ( res == 0 )
1068 {
akmhoque7c234e02013-02-13 11:23:56 -06001069 struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoqueb77b95f2013-02-08 12:28:47 -06001070 get_host_name_from_command_string(nbr_name,np->name,0);
1071 printf("Hostname of neighbor: %s ",nbr_name->name);
1072
akmhoque7c234e02013-02-13 11:23:56 -06001073 char *ip_addr=(char *)calloc(20,sizeof(char));
1074 //memset(ip_addr,0,20);
akmhoqueb77b95f2013-02-08 12:28:47 -06001075 get_ip_from_hostname_02(nbr_name->name,ip_addr);
1076 printf("IP Address: %s \n",ip_addr);
1077 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type);
1078 update_face_to_adl_for_nbr(nbr_name->name, face_id);
akmhoque483c1eb2013-03-08 00:51:09 -06001079 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1);
1080 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -06001081
1082 add_nbr_to_adl(np,face_id,ip_addr);
1083
akmhoque3171d652012-11-13 11:44:33 -06001084 sprintf(msg,"Neighbor %s has been added to adjacency list.",name);
akmhoque7c234e02013-02-13 11:23:56 -06001085 free(ip_addr);
akmhoqueb77b95f2013-02-08 12:28:47 -06001086
akmhoque3171d652012-11-13 11:44:33 -06001087 }
1088 else
1089 {
1090 sprintf(msg,"Neighbor %s already exists in adjacency list.",name);
1091 }
1092 }
1093 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001094
akmhoque562caef2012-11-09 13:29:06 -06001095
1096 return msg;
1097}
akmhoque1771c412012-11-09 13:06:08 -06001098
Obaid Amin2a928a52013-02-20 11:06:51 -06001099 int
akmhoque1771c412012-11-09 13:06:08 -06001100nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
1101{
1102 struct timeval timeout;
akmhoqueb77b95f2013-02-08 12:28:47 -06001103 if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
akmhoque1771c412012-11-09 13:06:08 -06001104 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001105 timeout.tv_sec=0;
1106 timeout.tv_usec=time_out_micro_sec;
akmhoque1771c412012-11-09 13:06:08 -06001107 }
akmhoqueb77b95f2013-02-08 12:28:47 -06001108 else
akmhoque1771c412012-11-09 13:06:08 -06001109 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001110 timeout.tv_sec = 0;
1111 timeout.tv_usec = 500000;
akmhoque1771c412012-11-09 13:06:08 -06001112 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001113
akmhoque1771c412012-11-09 13:06:08 -06001114 int fd;
1115 int nread;
1116 int result;
1117 fd_set testfds;
1118 unsigned int client_len;
1119 int client_sockfd;
1120 char recv_buffer[1024];
1121 bzero(recv_buffer,1024);
akmhoque95041802012-11-16 09:18:02 -06001122 struct sockaddr_in client_address;
akmhoque1771c412012-11-09 13:06:08 -06001123
1124 testfds=nlsr->readfds;
1125 result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);
Obaid Amin2a928a52013-02-20 11:06:51 -06001126
akmhoqueb77b95f2013-02-08 12:28:47 -06001127 for(fd = 0; fd < FD_SETSIZE && result > 0; fd++)
akmhoque1771c412012-11-09 13:06:08 -06001128 {
1129 if(FD_ISSET(fd,&testfds))
1130 {
1131 if ( fd == ccn_fd )
1132 {
1133 return 0;
1134 }
1135 else if(fd == nlsr->nlsr_api_server_sock_fd)
1136 {
1137 client_len = sizeof(client_address);
1138 client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len);
1139 FD_SET(client_sockfd, &nlsr->readfds);
1140 }
1141 else
1142 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001143
akmhoque1771c412012-11-09 13:06:08 -06001144 ioctl(fd, FIONREAD, &nread);
1145 if(nread == 0)
1146 {
1147 close(fd);
1148 FD_CLR(fd, &nlsr->readfds);
1149 }
1150 else
1151 {
1152 recv(fd, recv_buffer, 1024, 0);
akmhoqueb77b95f2013-02-08 12:28:47 -06001153 printf("Received Data from NLSR API cleint: %s \n",recv_buffer);
akmhoque562caef2012-11-09 13:29:06 -06001154 char *msg=process_api_client_command(recv_buffer);
1155 send(fd, msg, strlen(msg),0);
1156 free(msg);
akmhoque1771c412012-11-09 13:06:08 -06001157 close(fd);
1158 FD_CLR(fd, &nlsr->readfds);
akmhoque1771c412012-11-09 13:06:08 -06001159 }
1160 }
1161 }
1162 }
1163
1164 return 0;
1165}
1166
Obaid Amin2a928a52013-02-20 11:06:51 -06001167 int
akmhoqueb77b95f2013-02-08 12:28:47 -06001168check_config_validity()
1169{
1170 if (nlsr->router_name == NULL )
1171 {
1172 fprintf(stderr,"Router name has not been configured :(\n");
1173 return -1;
1174 }
1175 if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) )
1176 {
1177 fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
1178 return -1;
1179 }
akmhoque7adb2772013-03-05 16:30:59 -06001180 if (nlsr->site_name == NULL )
1181 {
1182 fprintf(stderr,"Site name has not been configured :(\n");
1183 return -1;
1184 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001185
akmhoqueb77b95f2013-02-08 12:28:47 -06001186 return 0;
1187}
1188
Obaid Amin2a928a52013-02-20 11:06:51 -06001189 void
akmhoque386081b2012-08-10 10:53:21 -05001190nlsr_destroy( void )
1191{
akmhoque7b791452012-10-30 11:24:56 -05001192 if ( nlsr->debugging )
1193 {
1194 printf("Freeing Allocated Memory....\n");
1195 }
akmhoque9e9fc722012-09-26 14:03:25 -05001196 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n");
akmhoquead584782013-02-22 10:56:03 -06001197
akmhoquefbfd0982012-09-09 20:59:03 -05001198 /* Destroying all face created by nlsr in CCND */
1199 destroy_all_face_by_nlsr();
akmhoqueb77b95f2013-02-08 12:28:47 -06001200 destroy_faces_for_nbrs();
Obaid Amin0e9a3002013-02-20 14:55:37 -06001201
akmhoque237239c2013-03-18 10:29:26 -05001202
akmhoquee6f98a12013-02-22 10:33:26 -06001203 destroy_adl();
akmhoquee6f98a12013-02-22 10:33:26 -06001204 destroy_npl();
akmhoquead584782013-02-22 10:56:03 -06001205 destroy_lsdb();
akmhoque54a14f42013-02-24 06:16:20 -06001206 destroy_npt();
1207 destroy_routing_table();
akmhoque237239c2013-03-18 10:29:26 -05001208 destroy_keys();
Obaid Amin2a928a52013-02-20 11:06:51 -06001209
akmhoque7c234e02013-02-13 11:23:56 -06001210 if ( nlsr->slice != NULL )
1211 ccns_slice_destroy(&nlsr->slice);
akmhoquee48d7072013-03-15 19:44:27 -05001212 if ( nlsr->ccns != NULL )
1213 ccns_close(&nlsr->ccns, NULL, NULL);
akmhoque0ddc8b22013-03-15 20:23:28 -05001214 if (nlsr->closure != NULL )
1215 free(nlsr->closure);
akmhoque3560cb62012-09-09 10:52:30 -05001216
akmhoque7c234e02013-02-13 11:23:56 -06001217 close(nlsr->nlsr_api_server_sock_fd);
akmhoque95041802012-11-16 09:18:02 -06001218
akmhoque866c2222013-02-12 10:49:33 -06001219 ccn_destroy(&nlsr->ccn);
akmhoque7adb2772013-03-05 16:30:59 -06001220
1221 free(nlsr->root_key_prefix);
1222 free(nlsr->keystore_path);
1223 free(nlsr->keystore_passphrase);
1224 if( nlsr->site_name )
1225 free(nlsr->site_name);
1226
akmhoque03004e62012-09-06 01:12:28 -05001227 free(nlsr->router_name);
akmhoque83a94da2013-03-15 01:38:21 -05001228
1229
1230 free(nlsr->slice_prefix);
1231 free(nlsr->topo_prefix);
1232 free(nlsr->logDir);
1233
akmhoque7b791452012-10-30 11:24:56 -05001234 if ( nlsr->debugging )
1235 {
1236 printf("Finished freeing allocated memory\n");
1237 }
akmhoque9e9fc722012-09-26 14:03:25 -05001238 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001239
akmhoque7c234e02013-02-13 11:23:56 -06001240 free(nlsr);
akmhoque53f64222012-09-05 13:57:51 -05001241
akmhoque386081b2012-08-10 10:53:21 -05001242}
1243
akmhoque03004e62012-09-06 01:12:28 -05001244
akmhoqueb77b95f2013-02-08 12:28:47 -06001245
Obaid Amin0e9a3002013-02-20 14:55:37 -06001246 void
akmhoque1771c412012-11-09 13:06:08 -06001247init_api_server(int ccn_fd)
1248{
1249 int server_sockfd;
1250 int server_len;
akmhoque95041802012-11-16 09:18:02 -06001251 struct sockaddr_in server_address;
akmhoquef31f13b2012-11-16 09:42:24 -06001252 unsigned int yes=1;
1253
akmhoque95041802012-11-16 09:18:02 -06001254 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
akmhoque1771c412012-11-09 13:06:08 -06001255
1256 int flags = fcntl(server_sockfd, F_GETFL, 0);
1257 fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);
1258
akmhoquef31f13b2012-11-16 09:42:24 -06001259 if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
1260 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001261 ON_ERROR_DESTROY(-1);
1262 }
akmhoque95041802012-11-16 09:18:02 -06001263
1264 server_address.sin_family = AF_INET;
Adam Alyyanb5fff372013-01-09 14:32:52 -06001265 server_address.sin_addr.s_addr = INADDR_ANY;
1266 server_address.sin_port = htons(nlsr->api_port);
akmhoque95041802012-11-16 09:18:02 -06001267
akmhoque1771c412012-11-09 13:06:08 -06001268 server_len = sizeof(server_address);
1269 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
1270 listen(server_sockfd, 100);
1271 FD_ZERO(&nlsr->readfds);
1272 FD_SET(server_sockfd, &nlsr->readfds);
1273 FD_SET(ccn_fd, &nlsr->readfds);
1274 nlsr->nlsr_api_server_sock_fd=server_sockfd;
akmhoque1771c412012-11-09 13:06:08 -06001275}
1276
Obaid Amin0e9a3002013-02-20 14:55:37 -06001277 int
akmhoque902d57e2012-08-17 09:24:38 -05001278init_nlsr(void)
akmhoque59980a52012-08-09 12:36:09 -05001279{
akmhoque03004e62012-09-06 01:12:28 -05001280 if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
1281 {
1282 perror("SIGQUIT install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001283 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001284 }
1285 if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
1286 {
1287 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001288 return -1;
Obaid Amin2a928a52013-02-20 11:06:51 -06001289 }
1290 if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
akmhoque03004e62012-09-06 01:12:28 -05001291 {
1292 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001293 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001294 }
akmhoque902d57e2012-08-17 09:24:38 -05001295
akmhoque7c234e02013-02-13 11:23:56 -06001296 nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr));
Obaid Amin2a928a52013-02-20 11:06:51 -06001297
akmhoqueae388862013-03-15 01:46:22 -05001298 nlsr->adl= hashtb_create(sizeof(struct ndn_neighbor), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001299 nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001300 nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
1301 nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
akmhoque237239c2013-03-18 10:29:26 -05001302 nlsr->keys = hashtb_create(sizeof(struct nlsr_key), NULL);
akmhoque29c1db52012-09-07 14:47:43 -05001303
akmhoque03004e62012-09-06 01:12:28 -05001304 nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
akmhoque54a14f42013-02-24 06:16:20 -06001305 nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
1306 nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
1307 nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
akmhoque07dd8cc2012-08-16 10:23:01 -05001308
akmhoque7adb2772013-03-05 16:30:59 -06001309
akmhoque902d57e2012-08-17 09:24:38 -05001310
akmhoque54a14f42013-02-24 06:16:20 -06001311 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
1312
1313 nlsr->in_interest.p = &incoming_interest;
1314 nlsr->in_content.p = &incoming_content;
akmhoque53f64222012-09-05 13:57:51 -05001315
akmhoque59980a52012-08-09 12:36:09 -05001316 nlsr->is_synch_init=1;
akmhoquec9286692012-08-16 09:57:58 -05001317 nlsr->nlsa_id=0;
akmhoqued79438d2012-08-27 13:31:42 -05001318 nlsr->adj_build_flag=0;
akmhoque53f64222012-09-05 13:57:51 -05001319 nlsr->adj_build_count=0;
1320 nlsr->is_build_adj_lsa_sheduled=0;
akmhoque29c1db52012-09-07 14:47:43 -05001321 nlsr->is_send_lsdb_interest_scheduled=0;
1322 nlsr->is_route_calculation_scheduled=0;
akmhoqued79438d2012-08-27 13:31:42 -05001323
akmhoque7b791452012-10-30 11:24:56 -05001324 nlsr->detailed_logging=0;
1325 nlsr->debugging=0;
1326
akmhoqueb8dbba82013-03-11 11:34:17 -05001327 nlsr->isStrictHierchicalKeyCheck=1;
1328
akmhoqued79438d2012-08-27 13:31:42 -05001329 nlsr->interest_retry = INTEREST_RETRY;
1330 nlsr->interest_resend_time = INTEREST_RESEND_TIME;
akmhoqueda5b6832012-09-13 22:33:55 -05001331 nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
1332 nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
akmhoqueb77b95f2013-02-08 12:28:47 -06001333 nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
akmhoqueffacaa82012-09-13 17:48:30 -05001334 nlsr->semaphor=NLSR_UNLOCKED;
akmhoque81c25e02012-09-10 14:50:33 -05001335
akmhoque95041802012-11-16 09:18:02 -06001336 nlsr->api_port=API_PORT;
1337
akmhoque7c234e02013-02-13 11:23:56 -06001338 nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001339 memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
1340
akmhoque7c234e02013-02-13 11:23:56 -06001341 nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001342 memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
1343
1344 nlsr->is_hyperbolic_calc=0;
1345 nlsr->cor_r=-1.0;
1346 nlsr->cor_theta=-1.0;
1347
1348 nlsr->tunnel_type=IPPROTO_UDP;
1349
akmhoque7adb2772013-03-05 16:30:59 -06001350 nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char));
1351 memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys"));
1352 nlsr->keystore_path=get_current_user_default_keystore();
1353 nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1
1354 ,sizeof(char));
1355 memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.",
1356 strlen("Th1s1sn0t8g00dp8ssw0rd."));
1357
akmhoque81c25e02012-09-10 14:50:33 -05001358 return 0;
akmhoque902d57e2012-08-17 09:24:38 -05001359}
1360
Obaid Amin0e9a3002013-02-20 14:55:37 -06001361 int
akmhoque902d57e2012-08-17 09:24:38 -05001362main(int argc, char *argv[])
1363{
Obaid Amin2a928a52013-02-20 11:06:51 -06001364 int res, ret;
1365 char *config_file;
akmhoquebfefef22012-09-26 10:09:34 -05001366 int daemon_mode=0;
akmhoque95041802012-11-16 09:18:02 -06001367 int port=0;
akmhoque902d57e2012-08-17 09:24:38 -05001368
akmhoque95041802012-11-16 09:18:02 -06001369 while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1)
akmhoque59980a52012-08-09 12:36:09 -05001370 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001371 switch (res)
akmhoque59980a52012-08-09 12:36:09 -05001372 {
1373 case 'd':
akmhoquebfefef22012-09-26 10:09:34 -05001374 daemon_mode = 1;
akmhoque59980a52012-08-09 12:36:09 -05001375 break;
1376 case 'f':
1377 config_file = optarg;
1378 break;
akmhoque95041802012-11-16 09:18:02 -06001379 case 'p':
1380 port = atoi(optarg);
1381 break;
akmhoque59980a52012-08-09 12:36:09 -05001382 case 'h':
1383 default:
1384 usage(argv[0]);
1385 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001386 }
akmhoque59980a52012-08-09 12:36:09 -05001387
Obaid Amin2a928a52013-02-20 11:06:51 -06001388 ret = init_nlsr();
1389 ON_ERROR_EXIT(ret);
akmhoque95041802012-11-16 09:18:02 -06001390
1391 if ( port !=0 )
1392 nlsr->api_port=port;
1393
Obaid Amin0e9a3002013-02-20 14:55:37 -06001394 ON_ERROR_DESTROY(readConfigFile(config_file));
akmhoqueb77b95f2013-02-08 12:28:47 -06001395
1396 ON_ERROR_DESTROY(check_config_validity());
1397
1398 print_adjacent_from_adl();
1399
akmhoquebfefef22012-09-26 10:09:34 -05001400 if ( daemon_mode == 1 )
1401 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001402 nlsr->debugging=0;
akmhoquebfefef22012-09-26 10:09:34 -05001403 daemonize_nlsr();
1404 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001405
akmhoquebfefef22012-09-26 10:09:34 -05001406 startLogging(nlsr->logDir);
Obaid Amin2a928a52013-02-20 11:06:51 -06001407
akmhoque59980a52012-08-09 12:36:09 -05001408 nlsr->ccn=ccn_create();
akmhoque1771c412012-11-09 13:06:08 -06001409 int ccn_fd=ccn_connect(nlsr->ccn, NULL);
Obaid Amin0e9a3002013-02-20 14:55:37 -06001410
akmhoque1771c412012-11-09 13:06:08 -06001411 if(ccn_fd == -1)
akmhoque03004e62012-09-06 01:12:28 -05001412 {
1413 fprintf(stderr,"Could not connect to ccnd\n");
akmhoquebfefef22012-09-26 10:09:34 -05001414 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
akmhoque81c25e02012-09-10 14:50:33 -05001415 ON_ERROR_DESTROY(-1);
akmhoque03004e62012-09-06 01:12:28 -05001416 }
akmhoque1771c412012-11-09 13:06:08 -06001417
1418 init_api_server(ccn_fd);
akmhoqueb77b95f2013-02-08 12:28:47 -06001419
1420 res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001421
akmhoqueb77b95f2013-02-08 12:28:47 -06001422 if(res<0)
1423 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001424 fprintf(stderr, "Can not create slice for prefix %s\n",
Obaid Amin0e9a3002013-02-20 14:55:37 -06001425 nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001426 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for"
Obaid Amin0e9a3002013-02-20 14:55:37 -06001427 "prefix %s\n",nlsr->slice_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06001428 ON_ERROR_DESTROY(res);
1429 }
Obaid Amin0e9a3002013-02-20 14:55:37 -06001430
akmhoque53f64222012-09-05 13:57:51 -05001431 struct ccn_charbuf *router_prefix;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001432
akmhoque03004e62012-09-06 01:12:28 -05001433 router_prefix=ccn_charbuf_create();
1434 res=ccn_name_from_uri(router_prefix,nlsr->router_name);
akmhoque59980a52012-08-09 12:36:09 -05001435 if(res<0)
akmhoque03004e62012-09-06 01:12:28 -05001436 {
1437 fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
Obaid Amin2a928a52013-02-20 11:06:51 -06001438 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001439 "Bad ccn URI: %s\n", nlsr->router_name);
akmhoque81c25e02012-09-10 14:50:33 -05001440 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001441 }
akmhoque59980a52012-08-09 12:36:09 -05001442
1443 ccn_name_append_str(router_prefix,"nlsr");
akmhoque03004e62012-09-06 01:12:28 -05001444 nlsr->in_interest.data=nlsr->router_name;
akmhoque59980a52012-08-09 12:36:09 -05001445 res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
1446 if ( res < 0 )
akmhoque03004e62012-09-06 01:12:28 -05001447 {
1448 fprintf(stderr,"Failed to register interest for router\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001449 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001450 "Failed to register interest for router\n");
akmhoque81c25e02012-09-10 14:50:33 -05001451 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001452 }
1453 ccn_charbuf_destroy(&router_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001454
akmhoque7b791452012-10-30 11:24:56 -05001455 if ( nlsr->debugging )
1456 printf("Router Name : %s\n",nlsr->router_name);
akmhoque9e9fc722012-09-26 14:03:25 -05001457 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001458 if ( nlsr->debugging )
1459 printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque9e9fc722012-09-26 14:03:25 -05001460 writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque59980a52012-08-09 12:36:09 -05001461
akmhoqueb77b95f2013-02-08 12:28:47 -06001462 add_faces_for_nbrs();
akmhoque53f64222012-09-05 13:57:51 -05001463 print_name_prefix_from_npl();
1464 print_adjacent_from_adl();
akmhoqueb77b95f2013-02-08 12:28:47 -06001465 build_and_install_name_lsas();
1466
akmhoqueb77b95f2013-02-08 12:28:47 -06001467 print_name_lsdb();
1468 if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0)
1469 {
1470 build_and_install_cor_lsa();
1471 }
1472 write_name_lsdb_to_repo(nlsr->slice_prefix);
akmhoque53f64222012-09-05 13:57:51 -05001473
1474 nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
akmhoque184dde02013-02-14 15:53:24 -06001475 ccn_set_schedule(nlsr->ccn,nlsr->sched);
akmhoque03004e62012-09-06 01:12:28 -05001476 nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
akmhoqueffacaa82012-09-13 17:48:30 -05001477 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
Obaid Amin2a928a52013-02-20 11:06:51 -06001478
akmhoque0678c5d2013-02-18 11:03:31 -06001479 res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
1480 ON_ERROR_DESTROY(res);
akmhoque1c9b92f2012-08-13 10:57:50 -05001481
akmhoque59980a52012-08-09 12:36:09 -05001482 while(1)
akmhoque29c1db52012-09-07 14:47:43 -05001483 {
akmhoqueffacaa82012-09-13 17:48:30 -05001484 if ( nlsr->semaphor == NLSR_UNLOCKED )
akmhoque29c1db52012-09-07 14:47:43 -05001485 {
akmhoqueffacaa82012-09-13 17:48:30 -05001486 if( nlsr->sched != NULL )
1487 {
akmhoque1771c412012-11-09 13:06:08 -06001488 long int micro_sec=ccn_schedule_run(nlsr->sched);
1489 res=nlsr_api_server_poll(micro_sec,ccn_fd);
1490 ON_ERROR_DESTROY(res);
akmhoqueffacaa82012-09-13 17:48:30 -05001491 }
1492 if(nlsr->ccn != NULL)
1493 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001494 res = ccn_run(nlsr->ccn, 1);
akmhoqueffacaa82012-09-13 17:48:30 -05001495 }
1496 if (!(nlsr->sched && nlsr->ccn))
1497 {
1498 break;
1499 }
akmhoque29c1db52012-09-07 14:47:43 -05001500 }
1501
akmhoque59980a52012-08-09 12:36:09 -05001502 }
akmhoque59980a52012-08-09 12:36:09 -05001503 return 0;
1504}
1505