blob: c63aa9e91f79a6b233f5ec8fd3593195e661c5b7 [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"
akmhoque3560cb62012-09-09 10:52:30 -050044
45
akmhoque81c25e02012-09-10 14:50:33 -050046#define ON_ERROR_DESTROY(resval) \
47{ \
Obaid Amin2a928a52013-02-20 11:06:51 -060048 if ((resval) < 0) { \
49 nlsr_destroy(); \
50 exit(1);\
51 } \
akmhoque81c25e02012-09-10 14:50:33 -050052}
53
54
55#define ON_ERROR_EXIT(resval) \
56{ \
Obaid Amin2a928a52013-02-20 11:06:51 -060057 if ((resval) < 0) { \
58 exit(1); \
59 } \
akmhoque81c25e02012-09-10 14:50:33 -050060}
akmhoque59980a52012-08-09 12:36:09 -050061
62struct option longopts[] =
63{
Obaid Amin2a928a52013-02-20 11:06:51 -060064 { "daemon", no_argument, NULL, 'd'},
65 { "config_file", required_argument, NULL, 'f'},
66 { "api_port", required_argument, NULL, 'p'},
67 { "help", no_argument, NULL, 'h'},
68 { 0 }
akmhoque59980a52012-08-09 12:36:09 -050069};
70
Obaid Amin2a928a52013-02-20 11:06:51 -060071 static int
akmhoque59980a52012-08-09 12:36:09 -050072usage(char *progname)
73{
74
Obaid Amin2a928a52013-02-20 11:06:51 -060075 printf("Usage: %s [OPTIONS...]\n\
76 NDN routing....\n\
77 -d, --daemon Run in daemon mode\n\
78 -f, --config_file Specify configuration file name\n\
79 -p, --api_port port where api client will connect\n\
80 -h, --help Display this help message\n", progname);
akmhoque59980a52012-08-09 12:36:09 -050081
Obaid Amin2a928a52013-02-20 11:06:51 -060082 exit(1);
akmhoque59980a52012-08-09 12:36:09 -050083}
84
85void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result)
86{
Obaid Amin2a928a52013-02-20 11:06:51 -060087 struct timeval now = {0};
88 gettimeofday(&now, 0);
89 result->s = now.tv_sec;
90 result->micros = now.tv_usec;
akmhoque59980a52012-08-09 12:36:09 -050091}
92
93static struct ccn_gettime ndn_rtr_ticker = {
Obaid Amin2a928a52013-02-20 11:06:51 -060094 "timer",
95 &ndn_rtr_gettime,
96 1000000,
97 NULL
akmhoque59980a52012-08-09 12:36:09 -050098};
99
Obaid Amin2a928a52013-02-20 11:06:51 -0600100 void
akmhoqueffacaa82012-09-13 17:48:30 -0500101nlsr_lock(void)
102{
103 nlsr->semaphor=NLSR_LOCKED;
104}
105
Obaid Amin2a928a52013-02-20 11:06:51 -0600106 void
akmhoqueffacaa82012-09-13 17:48:30 -0500107nlsr_unlock(void)
108{
109 nlsr->semaphor=NLSR_UNLOCKED;
110}
akmhoque42098b12012-08-27 22:54:23 -0500111
Obaid Amin2a928a52013-02-20 11:06:51 -0600112 void
akmhoque03004e62012-09-06 01:12:28 -0500113nlsr_stop_signal_handler(int sig)
akmhoque42098b12012-08-27 22:54:23 -0500114{
akmhoque03004e62012-09-06 01:12:28 -0500115 signal(sig, SIG_IGN);
Obaid Amin2a928a52013-02-20 11:06:51 -0600116 nlsr_destroy();
akmhoqueffacaa82012-09-13 17:48:30 -0500117 exit(0);
akmhoque59980a52012-08-09 12:36:09 -0500118}
119
Obaid Amin2a928a52013-02-20 11:06:51 -0600120 void
akmhoquebfefef22012-09-26 10:09:34 -0500121daemonize_nlsr(void)
122{
akmhoqueb28579d2013-02-12 11:15:52 -0600123 //int ret;
akmhoquebfefef22012-09-26 10:09:34 -0500124 pid_t process_id = 0;
125 pid_t sid = 0;
126 process_id = fork();
127 if (process_id < 0)
128 {
akmhoque7b791452012-10-30 11:24:56 -0500129 printf("Daemonization failed!\n");
akmhoquebfefef22012-09-26 10:09:34 -0500130 ON_ERROR_DESTROY(process_id);
131 }
132 if (process_id > 0)
133 {
134 printf("Process daemonized. Process id: %d \n", process_id);
akmhoqueb28579d2013-02-12 11:15:52 -0600135 //ret=process_id;
akmhoquebfefef22012-09-26 10:09:34 -0500136 exit(0);
137 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600138
akmhoquebfefef22012-09-26 10:09:34 -0500139 umask(0);
140 sid = setsid();
141 if(sid < 0)
142 {
143 ON_ERROR_DESTROY(sid);
144 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600145
akmhoquebfefef22012-09-26 10:09:34 -0500146 chdir("/");
akmhoqueb63a41e2013-03-01 12:00:20 -0600147 //close(STDIN_FILENO);
148 //close(STDOUT_FILENO);
149 //close(STDERR_FILENO);
akmhoquebfefef22012-09-26 10:09:34 -0500150}
151
Obaid Amin2a928a52013-02-20 11:06:51 -0600152 void
akmhoque59980a52012-08-09 12:36:09 -0500153process_command_ccnneighbor(char *command)
154{
155 if(command==NULL)
156 {
akmhoque28c45022012-08-09 15:38:02 -0500157 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
akmhoque59980a52012-08-09 12:36:09 -0500158 return;
159 }
160 char *rem;
161 const char *sep=" \t\n";
akmhoqueb77b95f2013-02-08 12:28:47 -0600162 char *rtr_name;
163 char *nbr_ip_addr;
164 int is_ip_configured=0;
akmhoque7c234e02013-02-13 11:23:56 -0600165 char *ip_addr=(char *)calloc(20,sizeof(char));
akmhoque59980a52012-08-09 12:36:09 -0500166
akmhoque28c45022012-08-09 15:38:02 -0500167 rtr_name=strtok_r(command,sep,&rem);
168 if(rtr_name==NULL)
akmhoque59980a52012-08-09 12:36:09 -0500169 {
akmhoque28c45022012-08-09 15:38:02 -0500170 printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
akmhoque59980a52012-08-09 12:36:09 -0500171 return;
172 }
akmhoqued5152122012-09-19 06:44:23 -0500173 if ( rtr_name[strlen(rtr_name)-1] == '/' )
174 {
175 rtr_name[strlen(rtr_name)-1]='\0';
176 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600177
178 if (rem != NULL )
179 {
180 nbr_ip_addr=strtok_r(NULL,sep,&rem);
akmhoque958ccf72013-02-11 10:42:03 -0600181 if ( nbr_ip_addr != NULL)
182 is_ip_configured=1;
akmhoqueb77b95f2013-02-08 12:28:47 -0600183 }
akmhoque7c234e02013-02-13 11:23:56 -0600184 struct name_prefix *nbr=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
185 nbr->name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -0500186 memcpy(nbr->name,rtr_name,strlen(rtr_name)+1);
187 nbr->length=strlen(rtr_name)+1;
188
Obaid Amin2a928a52013-02-20 11:06:51 -0600189
akmhoqueb77b95f2013-02-08 12:28:47 -0600190 if ( !is_ip_configured )
191 {
akmhoque7c234e02013-02-13 11:23:56 -0600192 struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoqueb77b95f2013-02-08 12:28:47 -0600193 get_host_name_from_command_string(nbr_name,nbr->name,0);
akmhoque018692c2013-02-11 11:33:39 -0600194 if ( nlsr->debugging)
195 printf("Hostname of neighbor: %s ",nbr_name->name);
akmhoqueb77b95f2013-02-08 12:28:47 -0600196 get_ip_from_hostname_02(nbr_name->name,ip_addr);
akmhoque018692c2013-02-11 11:33:39 -0600197 if ( nlsr->debugging)
198 printf("IP Address: %s \n",ip_addr);
akmhoqueb77b95f2013-02-08 12:28:47 -0600199 free(nbr_name->name);
200 free(nbr_name);
201 }
202 else
203 {
akmhoque6682ca32013-02-22 00:29:35 -0600204 memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr)+1);
akmhoque018692c2013-02-11 11:33:39 -0600205 if (nlsr->debugging)
206 {
207 printf("Name of neighbor: %s ",nbr->name);
208 printf("IP Address: %s \n",ip_addr);
209 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600210 }
211 add_nbr_to_adl(nbr,0,ip_addr);
Obaid Amin2a928a52013-02-20 11:06:51 -0600212
akmhoquececba942013-02-25 17:33:34 -0600213 free(ip_addr);
akmhoque03004e62012-09-06 01:12:28 -0500214 free(nbr->name);
215 free(nbr);
216}
217
Obaid Amin2a928a52013-02-20 11:06:51 -0600218 void
akmhoque03004e62012-09-06 01:12:28 -0500219process_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
akmhoqued5152122012-09-19 06:44:23 -0500239 if ( name[strlen(name)-1] == '/' )
240 name[strlen(name)-1]='\0';
241
akmhoque7c234e02013-02-13 11:23:56 -0600242 struct name_prefix *np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
243 np->name=(char *)calloc(strlen(name)+1,sizeof(char));
244 //memset(np->name,0,strlen(name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500245 memcpy(np->name,name,strlen(name)+1);
246 np->length=strlen(name)+1;
akmhoque386081b2012-08-10 10:53:21 -0500247
akmhoque03004e62012-09-06 01:12:28 -0500248 add_name_to_npl(np);
akmhoque28c45022012-08-09 15:38:02 -0500249
akmhoque03004e62012-09-06 01:12:28 -0500250 free(np->name);
akmhoque53f64222012-09-05 13:57:51 -0500251 free(np);
akmhoque59980a52012-08-09 12:36:09 -0500252}
253
akmhoque03004e62012-09-06 01:12:28 -0500254
Obaid Amin2a928a52013-02-20 11:06:51 -0600255 void
akmhoque03004e62012-09-06 01:12:28 -0500256process_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 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600273
akmhoque03004e62012-09-06 01:12:28 -0500274
akmhoqued5152122012-09-19 06:44:23 -0500275 if ( rtr_name[strlen(rtr_name)-1] == '/' )
276 rtr_name[strlen(rtr_name)-1]='\0';
277
akmhoque7c234e02013-02-13 11:23:56 -0600278 nlsr->router_name=(char *)calloc(strlen(rtr_name)+1,sizeof(char));
279 //memset(nlsr->router_name,0,strlen(rtr_name)+1);
akmhoque03004e62012-09-06 01:12:28 -0500280 memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1);
281
282
283}
284
Obaid Amin2a928a52013-02-20 11:06:51 -0600285
286 void
akmhoqued79438d2012-08-27 13:31:42 -0500287process_command_interest_retry(char *command)
288{
289 if(command==NULL)
290 {
291 printf(" Wrong Command Format ( interest-retry number )\n");
292 return;
293 }
294 char *rem;
295 const char *sep=" \t\n";
akmhoqueffacaa82012-09-13 17:48:30 -0500296 char *retry;
297 long int retry_number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600298
akmhoqueffacaa82012-09-13 17:48:30 -0500299 retry=strtok_r(command,sep,&rem);
300 if(retry==NULL)
akmhoqued79438d2012-08-27 13:31:42 -0500301 {
302 printf(" Wrong Command Format ( interest-retry number)\n");
303 return;
304 }
305
akmhoqueffacaa82012-09-13 17:48:30 -0500306 retry_number=atoi(retry);
307 if ( retry_number >= 1 && retry_number<=10 )
308 {
309 nlsr->interest_retry=retry_number;
310 }
akmhoqued79438d2012-08-27 13:31:42 -0500311
312}
313
Obaid Amin2a928a52013-02-20 11:06:51 -0600314 void
akmhoqued79438d2012-08-27 13:31:42 -0500315process_command_interest_resend_time(char *command)
316{
317 if(command==NULL)
318 {
319 printf(" Wrong Command Format ( interest-resend-time secs )\n");
320 return;
321 }
322 char *rem;
323 const char *sep=" \t\n";
324 char *secs;
325 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600326
akmhoqued79438d2012-08-27 13:31:42 -0500327 secs=strtok_r(command,sep,&rem);
328 if(secs==NULL)
329 {
330 printf(" Wrong Command Format ( interest-resend-time secs)\n");
331 return;
332 }
333
334 seconds=atoi(secs);
akmhoqueffacaa82012-09-13 17:48:30 -0500335 if ( seconds <= 60 && seconds >= 1 )
336 {
337 nlsr->interest_resend_time=seconds;
338 }
akmhoqued79438d2012-08-27 13:31:42 -0500339}
340
akmhoque03004e62012-09-06 01:12:28 -0500341
Obaid Amin2a928a52013-02-20 11:06:51 -0600342 void
akmhoqued5152122012-09-19 06:44:23 -0500343process_command_lsa_refresh_time(char *command)
344{
345 if(command==NULL)
346 {
347 printf(" Wrong Command Format ( lsa-refresh-time secs )\n");
348 return;
349 }
350 char *rem;
351 const char *sep=" \t\n";
352 char *secs;
353 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600354
akmhoqued5152122012-09-19 06:44:23 -0500355 secs=strtok_r(command,sep,&rem);
356 if(secs==NULL)
357 {
358 printf(" Wrong Command Format ( lsa-refresh-time secs)\n");
359 return;
360 }
361
362 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600363 if ( seconds >= 240)
akmhoqued5152122012-09-19 06:44:23 -0500364 {
365 nlsr->lsa_refresh_time=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600366 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
367 {
368 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
369 }
akmhoqued5152122012-09-19 06:44:23 -0500370 }
371
372}
373
Obaid Amin2a928a52013-02-20 11:06:51 -0600374 void
akmhoqued5152122012-09-19 06:44:23 -0500375process_command_router_dead_interval(char *command)
376{
377 if(command==NULL)
378 {
379 printf(" Wrong Command Format ( router-dead-interval secs )\n");
380 return;
381 }
382 char *rem;
383 const char *sep=" \t\n";
384 char *secs;
385 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600386
akmhoqued5152122012-09-19 06:44:23 -0500387 secs=strtok_r(command,sep,&rem);
388 if(secs==NULL)
389 {
390 printf(" Wrong Command Format ( router-dead-interval secs)\n");
391 return;
392 }
393
394 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600395 if ( seconds >= 480 )
akmhoqued5152122012-09-19 06:44:23 -0500396 {
397 nlsr->router_dead_interval=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600398 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
399 {
400 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
401 }
akmhoqued5152122012-09-19 06:44:23 -0500402 }
403
404}
akmhoque03004e62012-09-06 01:12:28 -0500405
Obaid Amin2a928a52013-02-20 11:06:51 -0600406 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600407process_command_max_faces_per_prefix(char *command)
akmhoque3cced642012-09-24 16:20:20 -0500408{
409 if(command==NULL)
410 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600411 printf(" Wrong Command Format ( max-faces-per-prefix n )\n");
akmhoque3cced642012-09-24 16:20:20 -0500412 return;
413 }
414 char *rem;
415 const char *sep=" \t\n";
416 char *num;
417 long int number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600418
akmhoque3cced642012-09-24 16:20:20 -0500419 num=strtok_r(command,sep,&rem);
420 if(num==NULL)
421 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600422 printf(" Wrong Command Format ( max-faces-per-prefix n)\n");
akmhoque3cced642012-09-24 16:20:20 -0500423 return;
424 }
425
426 number=atoi(num);
427 if ( number >= 0 && number <= 60 )
428 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600429 nlsr->max_faces_per_prefix=number;
akmhoque3cced642012-09-24 16:20:20 -0500430 }
431
432}
433
Obaid Amin2a928a52013-02-20 11:06:51 -0600434 void
akmhoquebfefef22012-09-26 10:09:34 -0500435process_command_logdir(char *command)
436{
437 if(command==NULL)
438 {
439 printf(" Wrong Command Format ( logdir /path/to/logdir )\n");
440 return;
441 }
442 char *rem;
443 const char *sep=" \t\n";
444 char *dir;
445
446 dir=strtok_r(command,sep,&rem);
447 if(dir==NULL)
448 {
449 printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
450 return;
451 }
akmhoque0b60ba92013-02-25 17:55:35 -0600452 //if ( nlsr->logDir)
453 //free(nlsr->logDir);
akmhoque7c234e02013-02-13 11:23:56 -0600454 nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600455 memcpy(nlsr->logDir,dir,strlen(dir)+1);
akmhoquebfefef22012-09-26 10:09:34 -0500456}
457
Obaid Amin2a928a52013-02-20 11:06:51 -0600458 void
akmhoque7b791452012-10-30 11:24:56 -0500459process_command_detailed_log(char *command)
460{
461 if(command==NULL)
462 {
463 printf(" Wrong Command Format ( detailed-log on/off )\n");
464 return;
465 }
466 char *rem;
467 const char *sep=" \t\n";
468 char *on_off;
469
470 on_off=strtok_r(command,sep,&rem);
471 if(on_off==NULL)
472 {
473 printf(" Wrong Command Format ( detailed-log on/off )\n");
474 return;
475 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600476
akmhoque7b791452012-10-30 11:24:56 -0500477 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0)
478 {
479 nlsr->detailed_logging=1;
480 }
481}
482
Obaid Amin2a928a52013-02-20 11:06:51 -0600483 void
akmhoque7b791452012-10-30 11:24:56 -0500484process_command_debug(char *command)
485{
486 if(command==NULL)
487 {
488 printf(" Wrong Command Format ( debug on/off )\n");
489 return;
490 }
491 char *rem;
492 const char *sep=" \t\n";
493 char *on_off;
494
495 on_off=strtok_r(command,sep,&rem);
496 if(on_off==NULL)
497 {
498 printf(" Wrong Command Format ( debug on/off )\n");
499 return;
500 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600501
akmhoque7b791452012-10-30 11:24:56 -0500502 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
503 {
504 nlsr->debugging=1;
505 }
506}
507
akmhoqueb77b95f2013-02-08 12:28:47 -0600508
Obaid Amin2a928a52013-02-20 11:06:51 -0600509 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600510process_command_topo_prefix(char *command)
511{
512 if(command==NULL)
513 {
514 printf(" Wrong Command Format ( topo-prefix )\n");
515 return;
516 }
517 char *rem;
518 const char *sep=" \t\n";
519 char *topo_prefix;
520
521 topo_prefix=strtok_r(command,sep,&rem);
522 if(topo_prefix==NULL)
523 {
524 printf(" Wrong Command Format ( topo-prefix /name/prefix )\n");
525 return;
526 }
527 else
528 {
529 if( nlsr->topo_prefix != NULL)
530 free(nlsr->topo_prefix);
531 if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
532 topo_prefix[strlen(topo_prefix)-1]='\0';
akmhoque829228c2013-02-25 17:39:40 -0600533 //if(nlsr->topo_prefix)
534 //free(nlsr->topo_prefix);
akmhoque7c234e02013-02-13 11:23:56 -0600535 nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600536 memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600537 printf ("Topo prefix is: %s\n", nlsr->topo_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600538 }
539}
540
541
Obaid Amin2a928a52013-02-20 11:06:51 -0600542 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600543process_command_slice_prefix(char *command)
544{
545 if(command==NULL)
546 {
547 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
548 return;
549 }
550 char *rem;
551 const char *sep=" \t\n";
552 char *slice_prefix;
553
554 slice_prefix=strtok_r(command,sep,&rem);
555 if(slice_prefix==NULL)
556 {
557 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
558 return;
559 }
560 else
561 {
562 if ( nlsr->slice_prefix != NULL)
563 free(nlsr->slice_prefix);
564 if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
565 slice_prefix[strlen(slice_prefix)-1]='\0';
akmhoque829228c2013-02-25 17:39:40 -0600566 //if( nlsr->slice_prefix)
567 //free(nlsr->slice_prefix);
akmhoque7c234e02013-02-13 11:23:56 -0600568 nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600569 memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600570 printf("Slice prefix: %s \n",nlsr->slice_prefix);
571 }
572}
573
574
575 void
576process_command_root_key_prefix(char *command)
577{
578 if(command==NULL)
579 {
580 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
581 return;
582 }
583 char *rem;
584 const char *sep=" \t\n";
585 char *root_key_prefix;
586
587 root_key_prefix=strtok_r(command,sep,&rem);
588 if(root_key_prefix==NULL)
589 {
590 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
591 return;
592 }
593 else
594 {
595 if ( nlsr->root_key_prefix != NULL)
596 free(nlsr->root_key_prefix);
597 if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' )
598 root_key_prefix[strlen(root_key_prefix)-1]='\0';
599 nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char));
600 memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1);
601 printf("Root key prefix: %s \n",nlsr->root_key_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600602 }
603}
604
Obaid Amin2a928a52013-02-20 11:06:51 -0600605 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600606process_command_hyperbolic_routing(char *command)
607{
608 if(command==NULL)
609 {
610 printf(" Wrong Command Format ( hyperbolic-routing on)\n");
611 return;
612 }
613 char *rem;
614 const char *sep=" \t\n";
615 char *on_off;
616
617 on_off=strtok_r(command,sep,&rem);
618 if(on_off==NULL)
619 {
620 printf(" Wrong Command Format ( hyperbolic-routing on )\n");
621 return;
622 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600623
akmhoqueb77b95f2013-02-08 12:28:47 -0600624 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
625 {
626 nlsr->is_hyperbolic_calc=1;
627 }
628}
629
Obaid Amin2a928a52013-02-20 11:06:51 -0600630 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600631process_command_hyperbolic_cordinate(char *command)
632{
633 if(command==NULL)
634 {
635 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
636 return;
637 }
638
639 char *rem;
640 const char *sep=" \t\n\r";
641 char *radious;
642 char *theta;
643
644 radious=strtok_r(command,sep,&rem);
645 if (radious == NULL )
646 {
647 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
648 return;
649 }
650
651 theta=strtok_r(NULL,sep,&rem);
652 if (theta == NULL )
653 {
654 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
655 return;
656 }
657
658 nlsr->cor_r=strtof(radious,NULL);
659 nlsr->cor_theta=strtof(theta,NULL);
660
661}
662
Obaid Amin2a928a52013-02-20 11:06:51 -0600663 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600664process_command_tunnel_type(char *command)
665{
666 if(command==NULL)
667 {
668 printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
669 return;
670 }
671 char *rem;
672 const char *sep=" \t\n";
673 char *on_off;
674
675 on_off=strtok_r(command,sep,&rem);
676 if(on_off==NULL)
677 {
678 printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
679 return;
680 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600681
akmhoqueb77b95f2013-02-08 12:28:47 -0600682 if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
683 {
684 nlsr->tunnel_type=IPPROTO_TCP;
685 }
686 else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 )
687 {
688 nlsr->tunnel_type=IPPROTO_UDP;
689 }
690}
691
akmhoque7adb2772013-03-05 16:30:59 -0600692void
693process_command_keystore_passphrase(char *command)
694{
695 if(command==NULL)
696 {
697 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
698 return;
699 }
700 char *rem;
701 const char *sep=" \t\n";
702 char *passphrase;
703
704 passphrase=strtok_r(command,sep,&rem);
705 if(passphrase==NULL)
706 {
707 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
708 return;
709 }
710
711 if( nlsr->keystore_passphrase)
712 free(nlsr->keystore_passphrase);
713 nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char));
714 memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase));
715
716
717}
718
719
720void
721process_command_keystore_path(char *command)
722{
723 if(command==NULL)
724 {
725 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
726 return;
727 }
728 char *rem;
729 const char *sep=" \t\n";
730 char *path;
731
732 path=strtok_r(command,sep,&rem);
733 if(path==NULL)
734 {
735 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
736 return;
737 }
738
739 if( nlsr->keystore_path)
740 free(nlsr->keystore_path);
741 nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char));
742 memcpy(nlsr->keystore_path,path,strlen(path));
743
744}
745
746
747
748void
749process_command_site_name(char *command)
750{
751 if(command==NULL)
752 {
753 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
754 return;
755 }
756 char *rem;
757 const char *sep=" \t\n";
758 char *site_name;
759
760 site_name=strtok_r(command,sep,&rem);
761 if(site_name==NULL)
762 {
763 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
764 return;
765 }
766
767 if( nlsr->site_name)
768 free(nlsr->site_name);
769
770 if ( site_name[strlen(site_name)-1] == '/' )
771 site_name[strlen(site_name)-1]='\0';
772
773 nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char));
774 memcpy(nlsr->site_name,site_name,strlen(site_name));
775 printf("Site Name prefix: %s \n",nlsr->site_name);
776
777}
778
779
Obaid Amin2a928a52013-02-20 11:06:51 -0600780 void
akmhoque59980a52012-08-09 12:36:09 -0500781process_conf_command(char *command)
782{
783 const char *separators=" \t\n";
784 char *remainder=NULL;
785 char *cmd_type=NULL;
786
787 if(command==NULL || strlen(command)==0 || command[0]=='!')
788 return;
789
790 cmd_type=strtok_r(command,separators,&remainder);
791
792 if(!strcmp(cmd_type,"router-name") )
793 {
794 process_command_router_name(remainder);
795 }
796 else if(!strcmp(cmd_type,"ccnneighbor") )
797 {
798 process_command_ccnneighbor(remainder);
799 }
800 else if(!strcmp(cmd_type,"ccnname") )
801 {
802 process_command_ccnname(remainder);
803 }
akmhoqued79438d2012-08-27 13:31:42 -0500804 else if(!strcmp(cmd_type,"interest-retry") )
805 {
806 process_command_interest_retry(remainder);
807 }
808 else if(!strcmp(cmd_type,"interest-resend-time") )
809 {
810 process_command_interest_resend_time(remainder);
811 }
akmhoqued5152122012-09-19 06:44:23 -0500812 else if(!strcmp(cmd_type,"lsa-refresh-time") )
813 {
814 process_command_lsa_refresh_time(remainder);
815 }
816 else if(!strcmp(cmd_type,"router-dead-interval") )
817 {
818 process_command_router_dead_interval(remainder);
819 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600820 else if(!strcmp(cmd_type,"max-faces-per-prefix") )
akmhoque3cced642012-09-24 16:20:20 -0500821 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600822 process_command_max_faces_per_prefix(remainder);
akmhoque3cced642012-09-24 16:20:20 -0500823 }
akmhoquebfefef22012-09-26 10:09:34 -0500824 else if(!strcmp(cmd_type,"logdir") )
825 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600826 process_command_logdir(remainder);
akmhoquebfefef22012-09-26 10:09:34 -0500827 }
akmhoque7b791452012-10-30 11:24:56 -0500828 else if(!strcmp(cmd_type,"detailed-log") )
829 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600830 process_command_detailed_log(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500831 }
832 else if(!strcmp(cmd_type,"debug") )
833 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600834 process_command_debug(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500835 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600836 else if(!strcmp(cmd_type,"topo-prefix") )
837 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600838 process_command_topo_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600839 }
840 else if(!strcmp(cmd_type,"slice-prefix") )
841 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600842 process_command_slice_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600843 }
844 else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
845 {
846 process_command_hyperbolic_cordinate(remainder);
847 }
848 else if(!strcmp(cmd_type,"hyperbolic-routing") )
849 {
850 process_command_hyperbolic_routing(remainder);
851 }
852 else if(!strcmp(cmd_type,"tunnel-type") )
853 {
854 process_command_tunnel_type(remainder);
855 }
akmhoque7adb2772013-03-05 16:30:59 -0600856 else if(!strcmp(cmd_type,"site-name") )
857 {
858 process_command_site_name(remainder);
859 }
860 else if(!strcmp(cmd_type,"keystore-path") )
861 {
862 process_command_keystore_path(remainder);
863 }
864 else if(!strcmp(cmd_type,"keystore-passphrase") )
865 {
866 process_command_keystore_passphrase(remainder);
867 }
868 else if(!strcmp(cmd_type,"root-key-prefix") )
869 {
870 process_command_root_key_prefix(remainder);
871 }
akmhoqued5152122012-09-19 06:44:23 -0500872 else
akmhoque59980a52012-08-09 12:36:09 -0500873 {
874 printf("Wrong configuration Command %s \n",cmd_type);
875 }
876}
877
akmhoque03004e62012-09-06 01:12:28 -0500878
Obaid Amin0e9a3002013-02-20 14:55:37 -0600879 int
akmhoque59980a52012-08-09 12:36:09 -0500880readConfigFile(const char *filename)
881{
882 FILE *cfg;
883 char buf[1024];
884 int len;
885
886 cfg=fopen(filename, "r");
887
888 if(cfg == NULL)
889 {
890 printf("\nConfiguration File does not exists\n");
Obaid Amin0e9a3002013-02-20 14:55:37 -0600891 return -1;
akmhoque59980a52012-08-09 12:36:09 -0500892 }
893
894 while(fgets((char *)buf, sizeof(buf), cfg))
895 {
896 len=strlen(buf);
897 if(buf[len-1] == '\n')
Obaid Amin2a928a52013-02-20 11:06:51 -0600898 buf[len-1]='\0';
akmhoqued5152122012-09-19 06:44:23 -0500899 if ( buf[0] != '#' && buf[0] != '!')
900 process_conf_command(buf);
akmhoque59980a52012-08-09 12:36:09 -0500901 }
902
903 fclose(cfg);
904
905 return 0;
906}
907
akmhoqueb77b95f2013-02-08 12:28:47 -0600908
Obaid Amin0e9a3002013-02-20 14:55:37 -0600909 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600910add_faces_for_nbrs(void)
911{
912 int i, adl_element;
913 struct ndn_neighbor *nbr;
914
915 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600916 struct hashtb_enumerator *e = &ee;
917
918 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600919 adl_element=hashtb_n(nlsr->adl);
920
921 for(i=0;i<adl_element;i++)
922 {
923 nbr=e->data;
Obaid Amin2a928a52013-02-20 11:06:51 -0600924 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600925 (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
akmhoqueb77b95f2013-02-08 12:28:47 -0600926 update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);
Obaid Amin2a928a52013-02-20 11:06:51 -0600927 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600928 (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600929 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600930 (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600931 hashtb_next(e);
932 }
933
934 hashtb_end(e);
935
936}
937
Obaid Amin0e9a3002013-02-20 14:55:37 -0600938 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600939destroy_faces_for_nbrs(void)
940{
941 int i, adl_element;
942 struct ndn_neighbor *nbr;
943
944 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600945 struct hashtb_enumerator *e = &ee;
946
947 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600948 adl_element=hashtb_n(nlsr->adl);
949
950 for(i=0;i<adl_element;i++)
951 {
952 nbr=e->data;
953 if ( nbr->face > 0 )
954 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600955 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600956 (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600957 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600958 (const char *)nbr->neighbor->name,OP_UNREG,nbr->face,(~0U) >> 1);
Obaid Amin2a928a52013-02-20 11:06:51 -0600959 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600960 (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600961 }
962 hashtb_next(e);
963 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600964 hashtb_end(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600965}
966
Obaid Amin0e9a3002013-02-20 14:55:37 -0600967 char *
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
akmhoquee6f98a12013-02-22 10:33:26 -06001202 destroy_adl();
akmhoquee6f98a12013-02-22 10:33:26 -06001203 destroy_npl();
akmhoquead584782013-02-22 10:56:03 -06001204 destroy_lsdb();
akmhoque54a14f42013-02-24 06:16:20 -06001205 destroy_npt();
1206 destroy_routing_table();
Obaid Amin2a928a52013-02-20 11:06:51 -06001207
akmhoque7c234e02013-02-13 11:23:56 -06001208 if ( nlsr->ccns != NULL )
1209 ccns_close(&nlsr->ccns, NULL, NULL);
1210 if ( nlsr->slice != NULL )
1211 ccns_slice_destroy(&nlsr->slice);
akmhoque3560cb62012-09-09 10:52:30 -05001212
akmhoque7c234e02013-02-13 11:23:56 -06001213 close(nlsr->nlsr_api_server_sock_fd);
akmhoque95041802012-11-16 09:18:02 -06001214
akmhoque866c2222013-02-12 10:49:33 -06001215 ccn_destroy(&nlsr->ccn);
akmhoque7adb2772013-03-05 16:30:59 -06001216
1217 free(nlsr->root_key_prefix);
1218 free(nlsr->keystore_path);
1219 free(nlsr->keystore_passphrase);
1220 if( nlsr->site_name )
1221 free(nlsr->site_name);
1222
akmhoque03004e62012-09-06 01:12:28 -05001223 free(nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001224 if ( nlsr->debugging )
1225 {
1226 printf("Finished freeing allocated memory\n");
1227 }
akmhoque9e9fc722012-09-26 14:03:25 -05001228 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001229
akmhoque7c234e02013-02-13 11:23:56 -06001230 free(nlsr);
akmhoque53f64222012-09-05 13:57:51 -05001231
akmhoque386081b2012-08-10 10:53:21 -05001232}
1233
akmhoque03004e62012-09-06 01:12:28 -05001234
akmhoqueb77b95f2013-02-08 12:28:47 -06001235
Obaid Amin0e9a3002013-02-20 14:55:37 -06001236 void
akmhoque1771c412012-11-09 13:06:08 -06001237init_api_server(int ccn_fd)
1238{
1239 int server_sockfd;
1240 int server_len;
akmhoque95041802012-11-16 09:18:02 -06001241 struct sockaddr_in server_address;
akmhoquef31f13b2012-11-16 09:42:24 -06001242 unsigned int yes=1;
1243
akmhoque95041802012-11-16 09:18:02 -06001244 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
akmhoque1771c412012-11-09 13:06:08 -06001245
1246 int flags = fcntl(server_sockfd, F_GETFL, 0);
1247 fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);
1248
akmhoquef31f13b2012-11-16 09:42:24 -06001249 if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
1250 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001251 ON_ERROR_DESTROY(-1);
1252 }
akmhoque95041802012-11-16 09:18:02 -06001253
1254 server_address.sin_family = AF_INET;
Adam Alyyanb5fff372013-01-09 14:32:52 -06001255 server_address.sin_addr.s_addr = INADDR_ANY;
1256 server_address.sin_port = htons(nlsr->api_port);
akmhoque95041802012-11-16 09:18:02 -06001257
akmhoque1771c412012-11-09 13:06:08 -06001258 server_len = sizeof(server_address);
1259 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
1260 listen(server_sockfd, 100);
1261 FD_ZERO(&nlsr->readfds);
1262 FD_SET(server_sockfd, &nlsr->readfds);
1263 FD_SET(ccn_fd, &nlsr->readfds);
1264 nlsr->nlsr_api_server_sock_fd=server_sockfd;
akmhoque1771c412012-11-09 13:06:08 -06001265}
1266
Obaid Amin0e9a3002013-02-20 14:55:37 -06001267 int
akmhoque902d57e2012-08-17 09:24:38 -05001268init_nlsr(void)
akmhoque59980a52012-08-09 12:36:09 -05001269{
akmhoque03004e62012-09-06 01:12:28 -05001270 if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
1271 {
1272 perror("SIGQUIT install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001273 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001274 }
1275 if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
1276 {
1277 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001278 return -1;
Obaid Amin2a928a52013-02-20 11:06:51 -06001279 }
1280 if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
akmhoque03004e62012-09-06 01:12:28 -05001281 {
1282 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001283 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001284 }
akmhoque902d57e2012-08-17 09:24:38 -05001285
akmhoque7c234e02013-02-13 11:23:56 -06001286 nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr));
Obaid Amin2a928a52013-02-20 11:06:51 -06001287
1288 nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), NULL);
1289 nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001290 nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
1291 nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
akmhoque29c1db52012-09-07 14:47:43 -05001292
akmhoque03004e62012-09-06 01:12:28 -05001293 nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
akmhoque54a14f42013-02-24 06:16:20 -06001294 nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
1295 nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
1296 nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
akmhoque07dd8cc2012-08-16 10:23:01 -05001297
akmhoque7adb2772013-03-05 16:30:59 -06001298
akmhoque902d57e2012-08-17 09:24:38 -05001299
akmhoque54a14f42013-02-24 06:16:20 -06001300 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
1301
1302 nlsr->in_interest.p = &incoming_interest;
1303 nlsr->in_content.p = &incoming_content;
akmhoque53f64222012-09-05 13:57:51 -05001304
akmhoque59980a52012-08-09 12:36:09 -05001305 nlsr->is_synch_init=1;
akmhoquec9286692012-08-16 09:57:58 -05001306 nlsr->nlsa_id=0;
akmhoqued79438d2012-08-27 13:31:42 -05001307 nlsr->adj_build_flag=0;
akmhoque53f64222012-09-05 13:57:51 -05001308 nlsr->adj_build_count=0;
1309 nlsr->is_build_adj_lsa_sheduled=0;
akmhoque29c1db52012-09-07 14:47:43 -05001310 nlsr->is_send_lsdb_interest_scheduled=0;
1311 nlsr->is_route_calculation_scheduled=0;
akmhoqued79438d2012-08-27 13:31:42 -05001312
akmhoque7b791452012-10-30 11:24:56 -05001313 nlsr->detailed_logging=0;
1314 nlsr->debugging=0;
1315
akmhoqued79438d2012-08-27 13:31:42 -05001316 nlsr->interest_retry = INTEREST_RETRY;
1317 nlsr->interest_resend_time = INTEREST_RESEND_TIME;
akmhoqueda5b6832012-09-13 22:33:55 -05001318 nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
1319 nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
akmhoqueb77b95f2013-02-08 12:28:47 -06001320 nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
akmhoqueffacaa82012-09-13 17:48:30 -05001321 nlsr->semaphor=NLSR_UNLOCKED;
akmhoque81c25e02012-09-10 14:50:33 -05001322
akmhoque95041802012-11-16 09:18:02 -06001323 nlsr->api_port=API_PORT;
1324
akmhoque7c234e02013-02-13 11:23:56 -06001325 nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001326 memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
1327
akmhoque7c234e02013-02-13 11:23:56 -06001328 nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001329 memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
1330
1331 nlsr->is_hyperbolic_calc=0;
1332 nlsr->cor_r=-1.0;
1333 nlsr->cor_theta=-1.0;
1334
1335 nlsr->tunnel_type=IPPROTO_UDP;
1336
akmhoque7adb2772013-03-05 16:30:59 -06001337 nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char));
1338 memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys"));
1339 nlsr->keystore_path=get_current_user_default_keystore();
1340 nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1
1341 ,sizeof(char));
1342 memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.",
1343 strlen("Th1s1sn0t8g00dp8ssw0rd."));
1344
akmhoque81c25e02012-09-10 14:50:33 -05001345 return 0;
akmhoque902d57e2012-08-17 09:24:38 -05001346}
1347
Obaid Amin0e9a3002013-02-20 14:55:37 -06001348 int
akmhoque902d57e2012-08-17 09:24:38 -05001349main(int argc, char *argv[])
1350{
Obaid Amin2a928a52013-02-20 11:06:51 -06001351 int res, ret;
1352 char *config_file;
akmhoquebfefef22012-09-26 10:09:34 -05001353 int daemon_mode=0;
akmhoque95041802012-11-16 09:18:02 -06001354 int port=0;
akmhoque902d57e2012-08-17 09:24:38 -05001355
akmhoque95041802012-11-16 09:18:02 -06001356 while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1)
akmhoque59980a52012-08-09 12:36:09 -05001357 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001358 switch (res)
akmhoque59980a52012-08-09 12:36:09 -05001359 {
1360 case 'd':
akmhoquebfefef22012-09-26 10:09:34 -05001361 daemon_mode = 1;
akmhoque59980a52012-08-09 12:36:09 -05001362 break;
1363 case 'f':
1364 config_file = optarg;
1365 break;
akmhoque95041802012-11-16 09:18:02 -06001366 case 'p':
1367 port = atoi(optarg);
1368 break;
akmhoque59980a52012-08-09 12:36:09 -05001369 case 'h':
1370 default:
1371 usage(argv[0]);
1372 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001373 }
akmhoque59980a52012-08-09 12:36:09 -05001374
Obaid Amin2a928a52013-02-20 11:06:51 -06001375 ret = init_nlsr();
1376 ON_ERROR_EXIT(ret);
akmhoque95041802012-11-16 09:18:02 -06001377
1378 if ( port !=0 )
1379 nlsr->api_port=port;
1380
Obaid Amin0e9a3002013-02-20 14:55:37 -06001381 ON_ERROR_DESTROY(readConfigFile(config_file));
akmhoqueb77b95f2013-02-08 12:28:47 -06001382
1383 ON_ERROR_DESTROY(check_config_validity());
1384
1385 print_adjacent_from_adl();
1386
akmhoquebfefef22012-09-26 10:09:34 -05001387 if ( daemon_mode == 1 )
1388 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001389 nlsr->debugging=0;
akmhoquebfefef22012-09-26 10:09:34 -05001390 daemonize_nlsr();
1391 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001392
akmhoquebfefef22012-09-26 10:09:34 -05001393 startLogging(nlsr->logDir);
Obaid Amin2a928a52013-02-20 11:06:51 -06001394
akmhoque59980a52012-08-09 12:36:09 -05001395 nlsr->ccn=ccn_create();
akmhoque1771c412012-11-09 13:06:08 -06001396 int ccn_fd=ccn_connect(nlsr->ccn, NULL);
Obaid Amin0e9a3002013-02-20 14:55:37 -06001397
akmhoque1771c412012-11-09 13:06:08 -06001398 if(ccn_fd == -1)
akmhoque03004e62012-09-06 01:12:28 -05001399 {
1400 fprintf(stderr,"Could not connect to ccnd\n");
akmhoquebfefef22012-09-26 10:09:34 -05001401 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
akmhoque81c25e02012-09-10 14:50:33 -05001402 ON_ERROR_DESTROY(-1);
akmhoque03004e62012-09-06 01:12:28 -05001403 }
akmhoque1771c412012-11-09 13:06:08 -06001404
1405 init_api_server(ccn_fd);
akmhoqueb77b95f2013-02-08 12:28:47 -06001406
1407 res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001408
akmhoqueb77b95f2013-02-08 12:28:47 -06001409 if(res<0)
1410 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001411 fprintf(stderr, "Can not create slice for prefix %s\n",
Obaid Amin0e9a3002013-02-20 14:55:37 -06001412 nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001413 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for"
Obaid Amin0e9a3002013-02-20 14:55:37 -06001414 "prefix %s\n",nlsr->slice_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06001415 ON_ERROR_DESTROY(res);
1416 }
Obaid Amin0e9a3002013-02-20 14:55:37 -06001417
akmhoque53f64222012-09-05 13:57:51 -05001418 struct ccn_charbuf *router_prefix;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001419
akmhoque03004e62012-09-06 01:12:28 -05001420 router_prefix=ccn_charbuf_create();
1421 res=ccn_name_from_uri(router_prefix,nlsr->router_name);
akmhoque59980a52012-08-09 12:36:09 -05001422 if(res<0)
akmhoque03004e62012-09-06 01:12:28 -05001423 {
1424 fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
Obaid Amin2a928a52013-02-20 11:06:51 -06001425 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001426 "Bad ccn URI: %s\n", nlsr->router_name);
akmhoque81c25e02012-09-10 14:50:33 -05001427 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001428 }
akmhoque59980a52012-08-09 12:36:09 -05001429
1430 ccn_name_append_str(router_prefix,"nlsr");
akmhoque03004e62012-09-06 01:12:28 -05001431 nlsr->in_interest.data=nlsr->router_name;
akmhoque59980a52012-08-09 12:36:09 -05001432 res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
1433 if ( res < 0 )
akmhoque03004e62012-09-06 01:12:28 -05001434 {
1435 fprintf(stderr,"Failed to register interest for router\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001436 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001437 "Failed to register interest for router\n");
akmhoque81c25e02012-09-10 14:50:33 -05001438 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001439 }
1440 ccn_charbuf_destroy(&router_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001441
akmhoque7b791452012-10-30 11:24:56 -05001442 if ( nlsr->debugging )
1443 printf("Router Name : %s\n",nlsr->router_name);
akmhoque9e9fc722012-09-26 14:03:25 -05001444 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001445 if ( nlsr->debugging )
1446 printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque9e9fc722012-09-26 14:03:25 -05001447 writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque59980a52012-08-09 12:36:09 -05001448
akmhoqueb77b95f2013-02-08 12:28:47 -06001449 add_faces_for_nbrs();
akmhoque53f64222012-09-05 13:57:51 -05001450 print_name_prefix_from_npl();
1451 print_adjacent_from_adl();
akmhoqueb77b95f2013-02-08 12:28:47 -06001452 build_and_install_name_lsas();
1453
akmhoqueb77b95f2013-02-08 12:28:47 -06001454 print_name_lsdb();
1455 if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0)
1456 {
1457 build_and_install_cor_lsa();
1458 }
1459 write_name_lsdb_to_repo(nlsr->slice_prefix);
akmhoque53f64222012-09-05 13:57:51 -05001460
1461 nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
akmhoque184dde02013-02-14 15:53:24 -06001462 ccn_set_schedule(nlsr->ccn,nlsr->sched);
akmhoque03004e62012-09-06 01:12:28 -05001463 nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
akmhoqueffacaa82012-09-13 17:48:30 -05001464 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
Obaid Amin2a928a52013-02-20 11:06:51 -06001465
akmhoque0678c5d2013-02-18 11:03:31 -06001466 res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
1467 ON_ERROR_DESTROY(res);
akmhoque1c9b92f2012-08-13 10:57:50 -05001468
akmhoque59980a52012-08-09 12:36:09 -05001469 while(1)
akmhoque29c1db52012-09-07 14:47:43 -05001470 {
akmhoqueffacaa82012-09-13 17:48:30 -05001471 if ( nlsr->semaphor == NLSR_UNLOCKED )
akmhoque29c1db52012-09-07 14:47:43 -05001472 {
akmhoqueffacaa82012-09-13 17:48:30 -05001473 if( nlsr->sched != NULL )
1474 {
akmhoque1771c412012-11-09 13:06:08 -06001475 long int micro_sec=ccn_schedule_run(nlsr->sched);
1476 res=nlsr_api_server_poll(micro_sec,ccn_fd);
1477 ON_ERROR_DESTROY(res);
akmhoqueffacaa82012-09-13 17:48:30 -05001478 }
1479 if(nlsr->ccn != NULL)
1480 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001481 res = ccn_run(nlsr->ccn, 1);
akmhoqueffacaa82012-09-13 17:48:30 -05001482 }
1483 if (!(nlsr->sched && nlsr->ccn))
1484 {
1485 break;
1486 }
akmhoque29c1db52012-09-07 14:47:43 -05001487 }
1488
akmhoque59980a52012-08-09 12:36:09 -05001489 }
akmhoque59980a52012-08-09 12:36:09 -05001490 return 0;
1491}
1492