blob: a30c016d7994bdf76a79e0693e1d17405d97bc7f [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';
akmhoque7c234e02013-02-13 11:23:56 -0600566 nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600567 memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600568 printf("Slice prefix: %s \n",nlsr->slice_prefix);
569 }
570}
571
572
573 void
574process_command_root_key_prefix(char *command)
575{
576 if(command==NULL)
577 {
578 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
579 return;
580 }
581 char *rem;
582 const char *sep=" \t\n";
583 char *root_key_prefix;
584
585 root_key_prefix=strtok_r(command,sep,&rem);
586 if(root_key_prefix==NULL)
587 {
588 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
589 return;
590 }
591 else
592 {
593 if ( nlsr->root_key_prefix != NULL)
594 free(nlsr->root_key_prefix);
595 if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' )
596 root_key_prefix[strlen(root_key_prefix)-1]='\0';
597 nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char));
598 memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1);
599 printf("Root key prefix: %s \n",nlsr->root_key_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600600 }
601}
602
Obaid Amin2a928a52013-02-20 11:06:51 -0600603 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600604process_command_hyperbolic_routing(char *command)
605{
606 if(command==NULL)
607 {
608 printf(" Wrong Command Format ( hyperbolic-routing on)\n");
609 return;
610 }
611 char *rem;
612 const char *sep=" \t\n";
613 char *on_off;
614
615 on_off=strtok_r(command,sep,&rem);
616 if(on_off==NULL)
617 {
618 printf(" Wrong Command Format ( hyperbolic-routing on )\n");
619 return;
620 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600621
akmhoqueb77b95f2013-02-08 12:28:47 -0600622 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
623 {
624 nlsr->is_hyperbolic_calc=1;
625 }
626}
627
Obaid Amin2a928a52013-02-20 11:06:51 -0600628 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600629process_command_hyperbolic_cordinate(char *command)
630{
631 if(command==NULL)
632 {
633 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
634 return;
635 }
636
637 char *rem;
638 const char *sep=" \t\n\r";
639 char *radious;
640 char *theta;
641
642 radious=strtok_r(command,sep,&rem);
643 if (radious == NULL )
644 {
645 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
646 return;
647 }
648
649 theta=strtok_r(NULL,sep,&rem);
650 if (theta == NULL )
651 {
652 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
653 return;
654 }
655
656 nlsr->cor_r=strtof(radious,NULL);
657 nlsr->cor_theta=strtof(theta,NULL);
658
659}
660
Obaid Amin2a928a52013-02-20 11:06:51 -0600661 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600662process_command_tunnel_type(char *command)
663{
664 if(command==NULL)
665 {
666 printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
667 return;
668 }
669 char *rem;
670 const char *sep=" \t\n";
671 char *on_off;
672
673 on_off=strtok_r(command,sep,&rem);
674 if(on_off==NULL)
675 {
676 printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
677 return;
678 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600679
akmhoqueb77b95f2013-02-08 12:28:47 -0600680 if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
681 {
682 nlsr->tunnel_type=IPPROTO_TCP;
683 }
684 else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 )
685 {
686 nlsr->tunnel_type=IPPROTO_UDP;
687 }
688}
689
akmhoque7adb2772013-03-05 16:30:59 -0600690void
691process_command_keystore_passphrase(char *command)
692{
693 if(command==NULL)
694 {
695 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
696 return;
697 }
698 char *rem;
699 const char *sep=" \t\n";
700 char *passphrase;
701
702 passphrase=strtok_r(command,sep,&rem);
703 if(passphrase==NULL)
704 {
705 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
706 return;
707 }
708
709 if( nlsr->keystore_passphrase)
710 free(nlsr->keystore_passphrase);
711 nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char));
712 memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase));
713
714
715}
716
717
718void
719process_command_keystore_path(char *command)
720{
721 if(command==NULL)
722 {
723 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
724 return;
725 }
726 char *rem;
727 const char *sep=" \t\n";
728 char *path;
729
730 path=strtok_r(command,sep,&rem);
731 if(path==NULL)
732 {
733 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
734 return;
735 }
736
737 if( nlsr->keystore_path)
738 free(nlsr->keystore_path);
739 nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char));
740 memcpy(nlsr->keystore_path,path,strlen(path));
741
742}
743
744
745
746void
747process_command_site_name(char *command)
748{
749 if(command==NULL)
750 {
751 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
752 return;
753 }
754 char *rem;
755 const char *sep=" \t\n";
756 char *site_name;
757
758 site_name=strtok_r(command,sep,&rem);
759 if(site_name==NULL)
760 {
761 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
762 return;
763 }
764
765 if( nlsr->site_name)
766 free(nlsr->site_name);
767
768 if ( site_name[strlen(site_name)-1] == '/' )
769 site_name[strlen(site_name)-1]='\0';
770
771 nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char));
772 memcpy(nlsr->site_name,site_name,strlen(site_name));
773 printf("Site Name prefix: %s \n",nlsr->site_name);
774
775}
776
777
Obaid Amin2a928a52013-02-20 11:06:51 -0600778 void
akmhoque59980a52012-08-09 12:36:09 -0500779process_conf_command(char *command)
780{
781 const char *separators=" \t\n";
782 char *remainder=NULL;
783 char *cmd_type=NULL;
784
785 if(command==NULL || strlen(command)==0 || command[0]=='!')
786 return;
787
788 cmd_type=strtok_r(command,separators,&remainder);
789
790 if(!strcmp(cmd_type,"router-name") )
791 {
792 process_command_router_name(remainder);
793 }
794 else if(!strcmp(cmd_type,"ccnneighbor") )
795 {
796 process_command_ccnneighbor(remainder);
797 }
798 else if(!strcmp(cmd_type,"ccnname") )
799 {
800 process_command_ccnname(remainder);
801 }
akmhoqued79438d2012-08-27 13:31:42 -0500802 else if(!strcmp(cmd_type,"interest-retry") )
803 {
804 process_command_interest_retry(remainder);
805 }
806 else if(!strcmp(cmd_type,"interest-resend-time") )
807 {
808 process_command_interest_resend_time(remainder);
809 }
akmhoqued5152122012-09-19 06:44:23 -0500810 else if(!strcmp(cmd_type,"lsa-refresh-time") )
811 {
812 process_command_lsa_refresh_time(remainder);
813 }
814 else if(!strcmp(cmd_type,"router-dead-interval") )
815 {
816 process_command_router_dead_interval(remainder);
817 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600818 else if(!strcmp(cmd_type,"max-faces-per-prefix") )
akmhoque3cced642012-09-24 16:20:20 -0500819 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600820 process_command_max_faces_per_prefix(remainder);
akmhoque3cced642012-09-24 16:20:20 -0500821 }
akmhoquebfefef22012-09-26 10:09:34 -0500822 else if(!strcmp(cmd_type,"logdir") )
823 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600824 process_command_logdir(remainder);
akmhoquebfefef22012-09-26 10:09:34 -0500825 }
akmhoque7b791452012-10-30 11:24:56 -0500826 else if(!strcmp(cmd_type,"detailed-log") )
827 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600828 process_command_detailed_log(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500829 }
830 else if(!strcmp(cmd_type,"debug") )
831 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600832 process_command_debug(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500833 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600834 else if(!strcmp(cmd_type,"topo-prefix") )
835 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600836 process_command_topo_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600837 }
838 else if(!strcmp(cmd_type,"slice-prefix") )
839 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600840 process_command_slice_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600841 }
842 else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
843 {
844 process_command_hyperbolic_cordinate(remainder);
845 }
846 else if(!strcmp(cmd_type,"hyperbolic-routing") )
847 {
848 process_command_hyperbolic_routing(remainder);
849 }
850 else if(!strcmp(cmd_type,"tunnel-type") )
851 {
852 process_command_tunnel_type(remainder);
853 }
akmhoque7adb2772013-03-05 16:30:59 -0600854 else if(!strcmp(cmd_type,"site-name") )
855 {
856 process_command_site_name(remainder);
857 }
858 else if(!strcmp(cmd_type,"keystore-path") )
859 {
860 process_command_keystore_path(remainder);
861 }
862 else if(!strcmp(cmd_type,"keystore-passphrase") )
863 {
864 process_command_keystore_passphrase(remainder);
865 }
866 else if(!strcmp(cmd_type,"root-key-prefix") )
867 {
868 process_command_root_key_prefix(remainder);
869 }
akmhoqued5152122012-09-19 06:44:23 -0500870 else
akmhoque59980a52012-08-09 12:36:09 -0500871 {
872 printf("Wrong configuration Command %s \n",cmd_type);
873 }
874}
875
akmhoque03004e62012-09-06 01:12:28 -0500876
Obaid Amin0e9a3002013-02-20 14:55:37 -0600877 int
akmhoque59980a52012-08-09 12:36:09 -0500878readConfigFile(const char *filename)
879{
880 FILE *cfg;
881 char buf[1024];
882 int len;
883
884 cfg=fopen(filename, "r");
885
886 if(cfg == NULL)
887 {
888 printf("\nConfiguration File does not exists\n");
Obaid Amin0e9a3002013-02-20 14:55:37 -0600889 return -1;
akmhoque59980a52012-08-09 12:36:09 -0500890 }
891
892 while(fgets((char *)buf, sizeof(buf), cfg))
893 {
894 len=strlen(buf);
895 if(buf[len-1] == '\n')
Obaid Amin2a928a52013-02-20 11:06:51 -0600896 buf[len-1]='\0';
akmhoqued5152122012-09-19 06:44:23 -0500897 if ( buf[0] != '#' && buf[0] != '!')
898 process_conf_command(buf);
akmhoque59980a52012-08-09 12:36:09 -0500899 }
900
901 fclose(cfg);
902
903 return 0;
904}
905
akmhoqueb77b95f2013-02-08 12:28:47 -0600906
Obaid Amin0e9a3002013-02-20 14:55:37 -0600907 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600908add_faces_for_nbrs(void)
909{
910 int i, adl_element;
911 struct ndn_neighbor *nbr;
912
913 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600914 struct hashtb_enumerator *e = &ee;
915
916 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600917 adl_element=hashtb_n(nlsr->adl);
918
919 for(i=0;i<adl_element;i++)
920 {
921 nbr=e->data;
Obaid Amin2a928a52013-02-20 11:06:51 -0600922 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600923 (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
akmhoqueb77b95f2013-02-08 12:28:47 -0600924 update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);
Obaid Amin2a928a52013-02-20 11:06:51 -0600925 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600926 (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1);
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->slice_prefix, OP_REG, face_id,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600929 hashtb_next(e);
930 }
931
932 hashtb_end(e);
933
934}
935
Obaid Amin0e9a3002013-02-20 14:55:37 -0600936 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600937destroy_faces_for_nbrs(void)
938{
939 int i, adl_element;
940 struct ndn_neighbor *nbr;
941
942 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600943 struct hashtb_enumerator *e = &ee;
944
945 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600946 adl_element=hashtb_n(nlsr->adl);
947
948 for(i=0;i<adl_element;i++)
949 {
950 nbr=e->data;
951 if ( nbr->face > 0 )
952 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600953 add_delete_ccn_face_by_face_id(nlsr->ccn,
akmhoque483c1eb2013-03-08 00:51:09 -0600954 (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
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 *)nbr->neighbor->name,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 *)nlsr->slice_prefix, OP_UNREG, nbr->face,(~0U) >> 1);
akmhoqueb77b95f2013-02-08 12:28:47 -0600959 }
960 hashtb_next(e);
961 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600962 hashtb_end(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600963}
964
akmhoquead6d5692013-03-11 19:43:33 -0500965
966char *
akmhoque562caef2012-11-09 13:29:06 -0600967process_api_client_command(char *command)
968{
969 char *msg;
970 msg=(char *)malloc(100);
akmhoqueb77b95f2013-02-08 12:28:47 -0600971 memset(msg,0,100);
Obaid Amin2a928a52013-02-20 11:06:51 -0600972
akmhoque3171d652012-11-13 11:44:33 -0600973 const char *sep=" \t\n";
974 char *rem=NULL;
975 char *cmd_type=NULL;
976 char *op_type=NULL;
977 char *name=NULL;
978 char *face=NULL;
979 int face_id;
980 int res;
981
982 op_type=strtok_r(command,sep,&rem);
983 cmd_type=strtok_r(NULL,sep,&rem);
984 name=strtok_r(NULL,sep,&rem);
985 if ( name[strlen(name)-1] == '/' )
986 name[strlen(name)-1]='\0';
987
Obaid Amin2a928a52013-02-20 11:06:51 -0600988 struct name_prefix *np=(struct name_prefix *) calloc (1,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600989 sizeof(struct name_prefix ));
Obaid Amin2a928a52013-02-20 11:06:51 -0600990 np->name = (char *) calloc (strlen(name)+1,sizeof(char));
akmhoque3171d652012-11-13 11:44:33 -0600991 memcpy(np->name,name,strlen(name)+1);
992 np->length=strlen(name)+1;
993
994 if ( strcmp(cmd_type,"name")!= 0 )
995 {
996 face=strtok_r(NULL,sep,&rem);
997 sscanf(face,"face%d",&face_id);
998 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600999
akmhoque3171d652012-11-13 11:44:33 -06001000 if ( strcmp(cmd_type,"name")== 0 )
1001 {
1002 if ( strcmp(op_type,"del") == 0 )
1003 {
1004 res=does_name_exist_in_npl(np);
1005 if ( res == 0)
1006 {
1007 sprintf(msg,"Name %s does not exist !!",name);
1008 }
1009 else
1010 {
1011 long int ls_id=get_lsa_id_from_npl(np);
1012 if ( ls_id != 0 )
1013 {
1014 make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id);
1015 sprintf(msg,"Name %s has been deleted and Advertised.",name);
1016 }
1017 else
1018 {
1019 sprintf(msg,"Name %s does not have an Name LSA yet !!",name);
1020 }
1021 }
1022 }
1023 else if ( strcmp(op_type,"add") == 0 )
1024 {
1025 res=does_name_exist_in_npl(np);
1026 if ( res == 0)
1027 {
1028 add_name_to_npl(np);
1029 build_and_install_single_name_lsa(np);
1030 sprintf(msg,"Name %s has been added to advertise.",name);
1031 }
1032 else
1033 {
1034 sprintf(msg,"Name %s has already been advertised from this router !!",name);
1035 }
1036 }
1037 }
1038 else if ( strcmp(cmd_type,"neighbor") == 0 )
1039 {
1040 if ( strcmp(op_type,"del") == 0 )
1041 {
1042 res=is_neighbor(np->name);
1043 if ( res == 0)
1044 {
1045 sprintf(msg,"Neighbor %s does not exist !!",name);
1046 }
1047 else
1048 {
1049 update_adjacent_status_to_adl(np,NBR_DOWN);
akmhoqueb77b95f2013-02-08 12:28:47 -06001050 int face_id=get_next_hop_face_from_adl(np->name);
akmhoque483c1eb2013-03-08 00:51:09 -06001051 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id,(~0U) >> 1);
1052 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id,(~0U) >> 1);
1053 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 -06001054 delete_nbr_from_adl(np);
1055 if(!nlsr->is_build_adj_lsa_sheduled)
1056 {
1057 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1058 nlsr->is_build_adj_lsa_sheduled=1;
1059 }
1060 sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name);
1061 }
1062 }
1063 else if ( strcmp(op_type,"add") == 0 )
1064 {
1065 res=is_neighbor(np->name);
1066 if ( res == 0 )
1067 {
akmhoque7c234e02013-02-13 11:23:56 -06001068 struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoqueb77b95f2013-02-08 12:28:47 -06001069 get_host_name_from_command_string(nbr_name,np->name,0);
1070 printf("Hostname of neighbor: %s ",nbr_name->name);
1071
akmhoque7c234e02013-02-13 11:23:56 -06001072 char *ip_addr=(char *)calloc(20,sizeof(char));
1073 //memset(ip_addr,0,20);
akmhoqueb77b95f2013-02-08 12:28:47 -06001074 get_ip_from_hostname_02(nbr_name->name,ip_addr);
1075 printf("IP Address: %s \n",ip_addr);
1076 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type);
1077 update_face_to_adl_for_nbr(nbr_name->name, face_id);
akmhoque483c1eb2013-03-08 00:51:09 -06001078 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1);
1079 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 -06001080
1081 add_nbr_to_adl(np,face_id,ip_addr);
1082
akmhoque3171d652012-11-13 11:44:33 -06001083 sprintf(msg,"Neighbor %s has been added to adjacency list.",name);
akmhoque7c234e02013-02-13 11:23:56 -06001084 free(ip_addr);
akmhoqueb77b95f2013-02-08 12:28:47 -06001085
akmhoque3171d652012-11-13 11:44:33 -06001086 }
1087 else
1088 {
1089 sprintf(msg,"Neighbor %s already exists in adjacency list.",name);
1090 }
1091 }
1092 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001093
akmhoque562caef2012-11-09 13:29:06 -06001094
1095 return msg;
1096}
akmhoque1771c412012-11-09 13:06:08 -06001097
Obaid Amin2a928a52013-02-20 11:06:51 -06001098 int
akmhoque1771c412012-11-09 13:06:08 -06001099nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
1100{
1101 struct timeval timeout;
akmhoqueb77b95f2013-02-08 12:28:47 -06001102 if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
akmhoque1771c412012-11-09 13:06:08 -06001103 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001104 timeout.tv_sec=0;
1105 timeout.tv_usec=time_out_micro_sec;
akmhoque1771c412012-11-09 13:06:08 -06001106 }
akmhoqueb77b95f2013-02-08 12:28:47 -06001107 else
akmhoque1771c412012-11-09 13:06:08 -06001108 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001109 timeout.tv_sec = 0;
1110 timeout.tv_usec = 500000;
akmhoque1771c412012-11-09 13:06:08 -06001111 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001112
akmhoque1771c412012-11-09 13:06:08 -06001113 int fd;
1114 int nread;
1115 int result;
1116 fd_set testfds;
1117 unsigned int client_len;
1118 int client_sockfd;
1119 char recv_buffer[1024];
1120 bzero(recv_buffer,1024);
akmhoque95041802012-11-16 09:18:02 -06001121 struct sockaddr_in client_address;
akmhoque1771c412012-11-09 13:06:08 -06001122
1123 testfds=nlsr->readfds;
1124 result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);
Obaid Amin2a928a52013-02-20 11:06:51 -06001125
akmhoqueb77b95f2013-02-08 12:28:47 -06001126 for(fd = 0; fd < FD_SETSIZE && result > 0; fd++)
akmhoque1771c412012-11-09 13:06:08 -06001127 {
1128 if(FD_ISSET(fd,&testfds))
1129 {
1130 if ( fd == ccn_fd )
1131 {
1132 return 0;
1133 }
1134 else if(fd == nlsr->nlsr_api_server_sock_fd)
1135 {
1136 client_len = sizeof(client_address);
1137 client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len);
1138 FD_SET(client_sockfd, &nlsr->readfds);
1139 }
1140 else
1141 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001142
akmhoque1771c412012-11-09 13:06:08 -06001143 ioctl(fd, FIONREAD, &nread);
1144 if(nread == 0)
1145 {
1146 close(fd);
1147 FD_CLR(fd, &nlsr->readfds);
1148 }
1149 else
1150 {
1151 recv(fd, recv_buffer, 1024, 0);
akmhoqueb77b95f2013-02-08 12:28:47 -06001152 printf("Received Data from NLSR API cleint: %s \n",recv_buffer);
akmhoque562caef2012-11-09 13:29:06 -06001153 char *msg=process_api_client_command(recv_buffer);
1154 send(fd, msg, strlen(msg),0);
1155 free(msg);
akmhoque1771c412012-11-09 13:06:08 -06001156 close(fd);
1157 FD_CLR(fd, &nlsr->readfds);
akmhoque1771c412012-11-09 13:06:08 -06001158 }
1159 }
1160 }
1161 }
1162
1163 return 0;
1164}
1165
Obaid Amin2a928a52013-02-20 11:06:51 -06001166 int
akmhoqueb77b95f2013-02-08 12:28:47 -06001167check_config_validity()
1168{
1169 if (nlsr->router_name == NULL )
1170 {
1171 fprintf(stderr,"Router name has not been configured :(\n");
1172 return -1;
1173 }
1174 if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) )
1175 {
1176 fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
1177 return -1;
1178 }
akmhoque7adb2772013-03-05 16:30:59 -06001179 if (nlsr->site_name == NULL )
1180 {
1181 fprintf(stderr,"Site name has not been configured :(\n");
1182 return -1;
1183 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001184
akmhoqueb77b95f2013-02-08 12:28:47 -06001185 return 0;
1186}
1187
Obaid Amin2a928a52013-02-20 11:06:51 -06001188 void
akmhoque386081b2012-08-10 10:53:21 -05001189nlsr_destroy( void )
1190{
akmhoque7b791452012-10-30 11:24:56 -05001191 if ( nlsr->debugging )
1192 {
1193 printf("Freeing Allocated Memory....\n");
1194 }
akmhoque9e9fc722012-09-26 14:03:25 -05001195 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n");
akmhoquead584782013-02-22 10:56:03 -06001196
akmhoquefbfd0982012-09-09 20:59:03 -05001197 /* Destroying all face created by nlsr in CCND */
1198 destroy_all_face_by_nlsr();
akmhoqueb77b95f2013-02-08 12:28:47 -06001199 destroy_faces_for_nbrs();
Obaid Amin0e9a3002013-02-20 14:55:37 -06001200
akmhoquee6f98a12013-02-22 10:33:26 -06001201 destroy_adl();
akmhoquee6f98a12013-02-22 10:33:26 -06001202 destroy_npl();
akmhoquead584782013-02-22 10:56:03 -06001203 destroy_lsdb();
akmhoque54a14f42013-02-24 06:16:20 -06001204 destroy_npt();
1205 destroy_routing_table();
Obaid Amin2a928a52013-02-20 11:06:51 -06001206
akmhoque7c234e02013-02-13 11:23:56 -06001207 if ( nlsr->ccns != NULL )
1208 ccns_close(&nlsr->ccns, NULL, NULL);
1209 if ( nlsr->slice != NULL )
1210 ccns_slice_destroy(&nlsr->slice);
akmhoque3560cb62012-09-09 10:52:30 -05001211
akmhoque7c234e02013-02-13 11:23:56 -06001212 close(nlsr->nlsr_api_server_sock_fd);
akmhoque95041802012-11-16 09:18:02 -06001213
akmhoque866c2222013-02-12 10:49:33 -06001214 ccn_destroy(&nlsr->ccn);
akmhoque7adb2772013-03-05 16:30:59 -06001215
1216 free(nlsr->root_key_prefix);
1217 free(nlsr->keystore_path);
1218 free(nlsr->keystore_passphrase);
1219 if( nlsr->site_name )
1220 free(nlsr->site_name);
1221
akmhoque03004e62012-09-06 01:12:28 -05001222 free(nlsr->router_name);
akmhoque83a94da2013-03-15 01:38:21 -05001223
1224
1225 free(nlsr->slice_prefix);
1226 free(nlsr->topo_prefix);
1227 free(nlsr->logDir);
1228
akmhoque7b791452012-10-30 11:24:56 -05001229 if ( nlsr->debugging )
1230 {
1231 printf("Finished freeing allocated memory\n");
1232 }
akmhoque9e9fc722012-09-26 14:03:25 -05001233 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001234
akmhoque7c234e02013-02-13 11:23:56 -06001235 free(nlsr);
akmhoque53f64222012-09-05 13:57:51 -05001236
akmhoque386081b2012-08-10 10:53:21 -05001237}
1238
akmhoque03004e62012-09-06 01:12:28 -05001239
akmhoqueb77b95f2013-02-08 12:28:47 -06001240
Obaid Amin0e9a3002013-02-20 14:55:37 -06001241 void
akmhoque1771c412012-11-09 13:06:08 -06001242init_api_server(int ccn_fd)
1243{
1244 int server_sockfd;
1245 int server_len;
akmhoque95041802012-11-16 09:18:02 -06001246 struct sockaddr_in server_address;
akmhoquef31f13b2012-11-16 09:42:24 -06001247 unsigned int yes=1;
1248
akmhoque95041802012-11-16 09:18:02 -06001249 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
akmhoque1771c412012-11-09 13:06:08 -06001250
1251 int flags = fcntl(server_sockfd, F_GETFL, 0);
1252 fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);
1253
akmhoquef31f13b2012-11-16 09:42:24 -06001254 if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
1255 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001256 ON_ERROR_DESTROY(-1);
1257 }
akmhoque95041802012-11-16 09:18:02 -06001258
1259 server_address.sin_family = AF_INET;
Adam Alyyanb5fff372013-01-09 14:32:52 -06001260 server_address.sin_addr.s_addr = INADDR_ANY;
1261 server_address.sin_port = htons(nlsr->api_port);
akmhoque95041802012-11-16 09:18:02 -06001262
akmhoque1771c412012-11-09 13:06:08 -06001263 server_len = sizeof(server_address);
1264 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
1265 listen(server_sockfd, 100);
1266 FD_ZERO(&nlsr->readfds);
1267 FD_SET(server_sockfd, &nlsr->readfds);
1268 FD_SET(ccn_fd, &nlsr->readfds);
1269 nlsr->nlsr_api_server_sock_fd=server_sockfd;
akmhoque1771c412012-11-09 13:06:08 -06001270}
1271
Obaid Amin0e9a3002013-02-20 14:55:37 -06001272 int
akmhoque902d57e2012-08-17 09:24:38 -05001273init_nlsr(void)
akmhoque59980a52012-08-09 12:36:09 -05001274{
akmhoque03004e62012-09-06 01:12:28 -05001275 if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
1276 {
1277 perror("SIGQUIT install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001278 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001279 }
1280 if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
1281 {
1282 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001283 return -1;
Obaid Amin2a928a52013-02-20 11:06:51 -06001284 }
1285 if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
akmhoque03004e62012-09-06 01:12:28 -05001286 {
1287 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001288 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001289 }
akmhoque902d57e2012-08-17 09:24:38 -05001290
akmhoque7c234e02013-02-13 11:23:56 -06001291 nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr));
Obaid Amin2a928a52013-02-20 11:06:51 -06001292
akmhoqueae388862013-03-15 01:46:22 -05001293 nlsr->adl= hashtb_create(sizeof(struct ndn_neighbor), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001294 nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001295 nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
1296 nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
akmhoque29c1db52012-09-07 14:47:43 -05001297
akmhoque03004e62012-09-06 01:12:28 -05001298 nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
akmhoque54a14f42013-02-24 06:16:20 -06001299 nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
1300 nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
1301 nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
akmhoque07dd8cc2012-08-16 10:23:01 -05001302
akmhoque7adb2772013-03-05 16:30:59 -06001303
akmhoque902d57e2012-08-17 09:24:38 -05001304
akmhoque54a14f42013-02-24 06:16:20 -06001305 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
1306
1307 nlsr->in_interest.p = &incoming_interest;
1308 nlsr->in_content.p = &incoming_content;
akmhoque53f64222012-09-05 13:57:51 -05001309
akmhoque59980a52012-08-09 12:36:09 -05001310 nlsr->is_synch_init=1;
akmhoquec9286692012-08-16 09:57:58 -05001311 nlsr->nlsa_id=0;
akmhoqued79438d2012-08-27 13:31:42 -05001312 nlsr->adj_build_flag=0;
akmhoque53f64222012-09-05 13:57:51 -05001313 nlsr->adj_build_count=0;
1314 nlsr->is_build_adj_lsa_sheduled=0;
akmhoque29c1db52012-09-07 14:47:43 -05001315 nlsr->is_send_lsdb_interest_scheduled=0;
1316 nlsr->is_route_calculation_scheduled=0;
akmhoqued79438d2012-08-27 13:31:42 -05001317
akmhoque7b791452012-10-30 11:24:56 -05001318 nlsr->detailed_logging=0;
1319 nlsr->debugging=0;
1320
akmhoqueb8dbba82013-03-11 11:34:17 -05001321 nlsr->isStrictHierchicalKeyCheck=1;
1322
akmhoqued79438d2012-08-27 13:31:42 -05001323 nlsr->interest_retry = INTEREST_RETRY;
1324 nlsr->interest_resend_time = INTEREST_RESEND_TIME;
akmhoqueda5b6832012-09-13 22:33:55 -05001325 nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
1326 nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
akmhoqueb77b95f2013-02-08 12:28:47 -06001327 nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
akmhoqueffacaa82012-09-13 17:48:30 -05001328 nlsr->semaphor=NLSR_UNLOCKED;
akmhoque81c25e02012-09-10 14:50:33 -05001329
akmhoque95041802012-11-16 09:18:02 -06001330 nlsr->api_port=API_PORT;
1331
akmhoque7c234e02013-02-13 11:23:56 -06001332 nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001333 memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
1334
akmhoque7c234e02013-02-13 11:23:56 -06001335 nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001336 memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
1337
1338 nlsr->is_hyperbolic_calc=0;
1339 nlsr->cor_r=-1.0;
1340 nlsr->cor_theta=-1.0;
1341
1342 nlsr->tunnel_type=IPPROTO_UDP;
1343
akmhoque7adb2772013-03-05 16:30:59 -06001344 nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char));
1345 memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys"));
1346 nlsr->keystore_path=get_current_user_default_keystore();
1347 nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1
1348 ,sizeof(char));
1349 memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.",
1350 strlen("Th1s1sn0t8g00dp8ssw0rd."));
1351
akmhoque81c25e02012-09-10 14:50:33 -05001352 return 0;
akmhoque902d57e2012-08-17 09:24:38 -05001353}
1354
Obaid Amin0e9a3002013-02-20 14:55:37 -06001355 int
akmhoque902d57e2012-08-17 09:24:38 -05001356main(int argc, char *argv[])
1357{
Obaid Amin2a928a52013-02-20 11:06:51 -06001358 int res, ret;
1359 char *config_file;
akmhoquebfefef22012-09-26 10:09:34 -05001360 int daemon_mode=0;
akmhoque95041802012-11-16 09:18:02 -06001361 int port=0;
akmhoque902d57e2012-08-17 09:24:38 -05001362
akmhoque95041802012-11-16 09:18:02 -06001363 while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1)
akmhoque59980a52012-08-09 12:36:09 -05001364 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001365 switch (res)
akmhoque59980a52012-08-09 12:36:09 -05001366 {
1367 case 'd':
akmhoquebfefef22012-09-26 10:09:34 -05001368 daemon_mode = 1;
akmhoque59980a52012-08-09 12:36:09 -05001369 break;
1370 case 'f':
1371 config_file = optarg;
1372 break;
akmhoque95041802012-11-16 09:18:02 -06001373 case 'p':
1374 port = atoi(optarg);
1375 break;
akmhoque59980a52012-08-09 12:36:09 -05001376 case 'h':
1377 default:
1378 usage(argv[0]);
1379 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001380 }
akmhoque59980a52012-08-09 12:36:09 -05001381
Obaid Amin2a928a52013-02-20 11:06:51 -06001382 ret = init_nlsr();
1383 ON_ERROR_EXIT(ret);
akmhoque95041802012-11-16 09:18:02 -06001384
1385 if ( port !=0 )
1386 nlsr->api_port=port;
1387
Obaid Amin0e9a3002013-02-20 14:55:37 -06001388 ON_ERROR_DESTROY(readConfigFile(config_file));
akmhoqueb77b95f2013-02-08 12:28:47 -06001389
1390 ON_ERROR_DESTROY(check_config_validity());
1391
1392 print_adjacent_from_adl();
1393
akmhoquebfefef22012-09-26 10:09:34 -05001394 if ( daemon_mode == 1 )
1395 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001396 nlsr->debugging=0;
akmhoquebfefef22012-09-26 10:09:34 -05001397 daemonize_nlsr();
1398 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001399
akmhoquebfefef22012-09-26 10:09:34 -05001400 startLogging(nlsr->logDir);
Obaid Amin2a928a52013-02-20 11:06:51 -06001401
akmhoque59980a52012-08-09 12:36:09 -05001402 nlsr->ccn=ccn_create();
akmhoque1771c412012-11-09 13:06:08 -06001403 int ccn_fd=ccn_connect(nlsr->ccn, NULL);
Obaid Amin0e9a3002013-02-20 14:55:37 -06001404
akmhoque1771c412012-11-09 13:06:08 -06001405 if(ccn_fd == -1)
akmhoque03004e62012-09-06 01:12:28 -05001406 {
1407 fprintf(stderr,"Could not connect to ccnd\n");
akmhoquebfefef22012-09-26 10:09:34 -05001408 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
akmhoque81c25e02012-09-10 14:50:33 -05001409 ON_ERROR_DESTROY(-1);
akmhoque03004e62012-09-06 01:12:28 -05001410 }
akmhoque1771c412012-11-09 13:06:08 -06001411
1412 init_api_server(ccn_fd);
akmhoqueb77b95f2013-02-08 12:28:47 -06001413
1414 res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001415
akmhoqueb77b95f2013-02-08 12:28:47 -06001416 if(res<0)
1417 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001418 fprintf(stderr, "Can not create slice for prefix %s\n",
Obaid Amin0e9a3002013-02-20 14:55:37 -06001419 nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001420 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for"
Obaid Amin0e9a3002013-02-20 14:55:37 -06001421 "prefix %s\n",nlsr->slice_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06001422 ON_ERROR_DESTROY(res);
1423 }
Obaid Amin0e9a3002013-02-20 14:55:37 -06001424
akmhoque53f64222012-09-05 13:57:51 -05001425 struct ccn_charbuf *router_prefix;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001426
akmhoque03004e62012-09-06 01:12:28 -05001427 router_prefix=ccn_charbuf_create();
1428 res=ccn_name_from_uri(router_prefix,nlsr->router_name);
akmhoque59980a52012-08-09 12:36:09 -05001429 if(res<0)
akmhoque03004e62012-09-06 01:12:28 -05001430 {
1431 fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
Obaid Amin2a928a52013-02-20 11:06:51 -06001432 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001433 "Bad ccn URI: %s\n", nlsr->router_name);
akmhoque81c25e02012-09-10 14:50:33 -05001434 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001435 }
akmhoque59980a52012-08-09 12:36:09 -05001436
1437 ccn_name_append_str(router_prefix,"nlsr");
akmhoque03004e62012-09-06 01:12:28 -05001438 nlsr->in_interest.data=nlsr->router_name;
akmhoque59980a52012-08-09 12:36:09 -05001439 res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
1440 if ( res < 0 )
akmhoque03004e62012-09-06 01:12:28 -05001441 {
1442 fprintf(stderr,"Failed to register interest for router\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001443 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001444 "Failed to register interest for router\n");
akmhoque81c25e02012-09-10 14:50:33 -05001445 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001446 }
1447 ccn_charbuf_destroy(&router_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001448
akmhoque7b791452012-10-30 11:24:56 -05001449 if ( nlsr->debugging )
1450 printf("Router Name : %s\n",nlsr->router_name);
akmhoque9e9fc722012-09-26 14:03:25 -05001451 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001452 if ( nlsr->debugging )
1453 printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque9e9fc722012-09-26 14:03:25 -05001454 writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque59980a52012-08-09 12:36:09 -05001455
akmhoqueb77b95f2013-02-08 12:28:47 -06001456 add_faces_for_nbrs();
akmhoque53f64222012-09-05 13:57:51 -05001457 print_name_prefix_from_npl();
1458 print_adjacent_from_adl();
akmhoqueb77b95f2013-02-08 12:28:47 -06001459 build_and_install_name_lsas();
1460
akmhoqueb77b95f2013-02-08 12:28:47 -06001461 print_name_lsdb();
1462 if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0)
1463 {
1464 build_and_install_cor_lsa();
1465 }
1466 write_name_lsdb_to_repo(nlsr->slice_prefix);
akmhoque53f64222012-09-05 13:57:51 -05001467
1468 nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
akmhoque184dde02013-02-14 15:53:24 -06001469 ccn_set_schedule(nlsr->ccn,nlsr->sched);
akmhoque03004e62012-09-06 01:12:28 -05001470 nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
akmhoqueffacaa82012-09-13 17:48:30 -05001471 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
Obaid Amin2a928a52013-02-20 11:06:51 -06001472
akmhoque0678c5d2013-02-18 11:03:31 -06001473 res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
1474 ON_ERROR_DESTROY(res);
akmhoque1c9b92f2012-08-13 10:57:50 -05001475
akmhoque59980a52012-08-09 12:36:09 -05001476 while(1)
akmhoque29c1db52012-09-07 14:47:43 -05001477 {
akmhoqueffacaa82012-09-13 17:48:30 -05001478 if ( nlsr->semaphor == NLSR_UNLOCKED )
akmhoque29c1db52012-09-07 14:47:43 -05001479 {
akmhoqueffacaa82012-09-13 17:48:30 -05001480 if( nlsr->sched != NULL )
1481 {
akmhoque1771c412012-11-09 13:06:08 -06001482 long int micro_sec=ccn_schedule_run(nlsr->sched);
1483 res=nlsr_api_server_poll(micro_sec,ccn_fd);
1484 ON_ERROR_DESTROY(res);
akmhoqueffacaa82012-09-13 17:48:30 -05001485 }
1486 if(nlsr->ccn != NULL)
1487 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001488 res = ccn_run(nlsr->ccn, 1);
akmhoqueffacaa82012-09-13 17:48:30 -05001489 }
1490 if (!(nlsr->sched && nlsr->ccn))
1491 {
1492 break;
1493 }
akmhoque29c1db52012-09-07 14:47:43 -05001494 }
1495
akmhoque59980a52012-08-09 12:36:09 -05001496 }
akmhoque59980a52012-08-09 12:36:09 -05001497 return 0;
1498}
1499