blob: 6ca3c40617d86a80908c6d189ce370a7c2c45d2b [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
akmhoqueb77b95f2013-02-08 12:28:47 -0600285/*
Obaid Amin2a928a52013-02-20 11:06:51 -0600286 void
287 process_command_lsdb_synch_interval(char *command)
288 {
289 if(command==NULL)
290 {
291 printf(" Wrong Command Format ( lsdb-synch-interval secs )\n");
292 return;
293 }
294 char *rem;
295 const char *sep=" \t\n";
296 char *secs;
297 long int seconds;
akmhoqued79438d2012-08-27 13:31:42 -0500298
Obaid Amin2a928a52013-02-20 11:06:51 -0600299 secs=strtok_r(command,sep,&rem);
300 if(secs==NULL)
301 {
302 printf(" Wrong Command Format ( lsdb-synch-interval secs)\n");
303 return;
304 }
akmhoqued79438d2012-08-27 13:31:42 -0500305
Obaid Amin2a928a52013-02-20 11:06:51 -0600306 seconds=atoi(secs);
307 if ( seconds >= 120 && seconds <= 3600 )
308 {
309 nlsr->lsdb_synch_interval=seconds;
310 }
akmhoqued79438d2012-08-27 13:31:42 -0500311
Obaid Amin2a928a52013-02-20 11:06:51 -0600312 }
313 */
314
315 void
akmhoqued79438d2012-08-27 13:31:42 -0500316process_command_interest_retry(char *command)
317{
318 if(command==NULL)
319 {
320 printf(" Wrong Command Format ( interest-retry number )\n");
321 return;
322 }
323 char *rem;
324 const char *sep=" \t\n";
akmhoqueffacaa82012-09-13 17:48:30 -0500325 char *retry;
326 long int retry_number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600327
akmhoqueffacaa82012-09-13 17:48:30 -0500328 retry=strtok_r(command,sep,&rem);
329 if(retry==NULL)
akmhoqued79438d2012-08-27 13:31:42 -0500330 {
331 printf(" Wrong Command Format ( interest-retry number)\n");
332 return;
333 }
334
akmhoqueffacaa82012-09-13 17:48:30 -0500335 retry_number=atoi(retry);
336 if ( retry_number >= 1 && retry_number<=10 )
337 {
338 nlsr->interest_retry=retry_number;
339 }
akmhoqued79438d2012-08-27 13:31:42 -0500340
341}
342
Obaid Amin2a928a52013-02-20 11:06:51 -0600343 void
akmhoqued79438d2012-08-27 13:31:42 -0500344process_command_interest_resend_time(char *command)
345{
346 if(command==NULL)
347 {
348 printf(" Wrong Command Format ( interest-resend-time secs )\n");
349 return;
350 }
351 char *rem;
352 const char *sep=" \t\n";
353 char *secs;
354 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600355
akmhoqued79438d2012-08-27 13:31:42 -0500356 secs=strtok_r(command,sep,&rem);
357 if(secs==NULL)
358 {
359 printf(" Wrong Command Format ( interest-resend-time secs)\n");
360 return;
361 }
362
363 seconds=atoi(secs);
akmhoqueffacaa82012-09-13 17:48:30 -0500364 if ( seconds <= 60 && seconds >= 1 )
365 {
366 nlsr->interest_resend_time=seconds;
367 }
akmhoqued79438d2012-08-27 13:31:42 -0500368}
369
akmhoque03004e62012-09-06 01:12:28 -0500370
Obaid Amin2a928a52013-02-20 11:06:51 -0600371 void
akmhoqued5152122012-09-19 06:44:23 -0500372process_command_lsa_refresh_time(char *command)
373{
374 if(command==NULL)
375 {
376 printf(" Wrong Command Format ( lsa-refresh-time secs )\n");
377 return;
378 }
379 char *rem;
380 const char *sep=" \t\n";
381 char *secs;
382 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600383
akmhoqued5152122012-09-19 06:44:23 -0500384 secs=strtok_r(command,sep,&rem);
385 if(secs==NULL)
386 {
387 printf(" Wrong Command Format ( lsa-refresh-time secs)\n");
388 return;
389 }
390
391 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600392 if ( seconds >= 240)
akmhoqued5152122012-09-19 06:44:23 -0500393 {
394 nlsr->lsa_refresh_time=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600395 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
396 {
397 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
398 }
akmhoqued5152122012-09-19 06:44:23 -0500399 }
400
401}
402
Obaid Amin2a928a52013-02-20 11:06:51 -0600403 void
akmhoqued5152122012-09-19 06:44:23 -0500404process_command_router_dead_interval(char *command)
405{
406 if(command==NULL)
407 {
408 printf(" Wrong Command Format ( router-dead-interval secs )\n");
409 return;
410 }
411 char *rem;
412 const char *sep=" \t\n";
413 char *secs;
414 long int seconds;
Obaid Amin2a928a52013-02-20 11:06:51 -0600415
akmhoqued5152122012-09-19 06:44:23 -0500416 secs=strtok_r(command,sep,&rem);
417 if(secs==NULL)
418 {
419 printf(" Wrong Command Format ( router-dead-interval secs)\n");
420 return;
421 }
422
423 seconds=atoi(secs);
akmhoqueb77b95f2013-02-08 12:28:47 -0600424 if ( seconds >= 480 )
akmhoqued5152122012-09-19 06:44:23 -0500425 {
426 nlsr->router_dead_interval=seconds;
akmhoqueb77b95f2013-02-08 12:28:47 -0600427 if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 )
428 {
429 nlsr->router_dead_interval=2*nlsr->lsa_refresh_time;
430 }
akmhoqued5152122012-09-19 06:44:23 -0500431 }
432
433}
akmhoque03004e62012-09-06 01:12:28 -0500434
Obaid Amin2a928a52013-02-20 11:06:51 -0600435 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600436process_command_max_faces_per_prefix(char *command)
akmhoque3cced642012-09-24 16:20:20 -0500437{
438 if(command==NULL)
439 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600440 printf(" Wrong Command Format ( max-faces-per-prefix n )\n");
akmhoque3cced642012-09-24 16:20:20 -0500441 return;
442 }
443 char *rem;
444 const char *sep=" \t\n";
445 char *num;
446 long int number;
Obaid Amin2a928a52013-02-20 11:06:51 -0600447
akmhoque3cced642012-09-24 16:20:20 -0500448 num=strtok_r(command,sep,&rem);
449 if(num==NULL)
450 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600451 printf(" Wrong Command Format ( max-faces-per-prefix n)\n");
akmhoque3cced642012-09-24 16:20:20 -0500452 return;
453 }
454
455 number=atoi(num);
456 if ( number >= 0 && number <= 60 )
457 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600458 nlsr->max_faces_per_prefix=number;
akmhoque3cced642012-09-24 16:20:20 -0500459 }
460
461}
462
Obaid Amin2a928a52013-02-20 11:06:51 -0600463 void
akmhoquebfefef22012-09-26 10:09:34 -0500464process_command_logdir(char *command)
465{
466 if(command==NULL)
467 {
468 printf(" Wrong Command Format ( logdir /path/to/logdir )\n");
469 return;
470 }
471 char *rem;
472 const char *sep=" \t\n";
473 char *dir;
474
475 dir=strtok_r(command,sep,&rem);
476 if(dir==NULL)
477 {
478 printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
479 return;
480 }
akmhoque0b60ba92013-02-25 17:55:35 -0600481 //if ( nlsr->logDir)
482 //free(nlsr->logDir);
akmhoque7c234e02013-02-13 11:23:56 -0600483 nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600484 memcpy(nlsr->logDir,dir,strlen(dir)+1);
akmhoquebfefef22012-09-26 10:09:34 -0500485}
486
Obaid Amin2a928a52013-02-20 11:06:51 -0600487 void
akmhoque7b791452012-10-30 11:24:56 -0500488process_command_detailed_log(char *command)
489{
490 if(command==NULL)
491 {
492 printf(" Wrong Command Format ( detailed-log on/off )\n");
493 return;
494 }
495 char *rem;
496 const char *sep=" \t\n";
497 char *on_off;
498
499 on_off=strtok_r(command,sep,&rem);
500 if(on_off==NULL)
501 {
502 printf(" Wrong Command Format ( detailed-log on/off )\n");
503 return;
504 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600505
akmhoque7b791452012-10-30 11:24:56 -0500506 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0)
507 {
508 nlsr->detailed_logging=1;
509 }
510}
511
Obaid Amin2a928a52013-02-20 11:06:51 -0600512 void
akmhoque7b791452012-10-30 11:24:56 -0500513process_command_debug(char *command)
514{
515 if(command==NULL)
516 {
517 printf(" Wrong Command Format ( debug on/off )\n");
518 return;
519 }
520 char *rem;
521 const char *sep=" \t\n";
522 char *on_off;
523
524 on_off=strtok_r(command,sep,&rem);
525 if(on_off==NULL)
526 {
527 printf(" Wrong Command Format ( debug on/off )\n");
528 return;
529 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600530
akmhoque7b791452012-10-30 11:24:56 -0500531 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
532 {
533 nlsr->debugging=1;
534 }
535}
536
akmhoqueb77b95f2013-02-08 12:28:47 -0600537
Obaid Amin2a928a52013-02-20 11:06:51 -0600538 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600539process_command_topo_prefix(char *command)
540{
541 if(command==NULL)
542 {
543 printf(" Wrong Command Format ( topo-prefix )\n");
544 return;
545 }
546 char *rem;
547 const char *sep=" \t\n";
548 char *topo_prefix;
549
550 topo_prefix=strtok_r(command,sep,&rem);
551 if(topo_prefix==NULL)
552 {
553 printf(" Wrong Command Format ( topo-prefix /name/prefix )\n");
554 return;
555 }
556 else
557 {
558 if( nlsr->topo_prefix != NULL)
559 free(nlsr->topo_prefix);
560 if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
561 topo_prefix[strlen(topo_prefix)-1]='\0';
akmhoque829228c2013-02-25 17:39:40 -0600562 //if(nlsr->topo_prefix)
563 //free(nlsr->topo_prefix);
akmhoque7c234e02013-02-13 11:23:56 -0600564 nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600565 memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600566 printf ("Topo prefix is: %s\n", nlsr->topo_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600567 }
568}
569
570
Obaid Amin2a928a52013-02-20 11:06:51 -0600571 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600572process_command_slice_prefix(char *command)
573{
574 if(command==NULL)
575 {
576 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
577 return;
578 }
579 char *rem;
580 const char *sep=" \t\n";
581 char *slice_prefix;
582
583 slice_prefix=strtok_r(command,sep,&rem);
584 if(slice_prefix==NULL)
585 {
586 printf(" Wrong Command Format ( slice-prefix /name/prefix )\n");
587 return;
588 }
589 else
590 {
591 if ( nlsr->slice_prefix != NULL)
592 free(nlsr->slice_prefix);
593 if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
594 slice_prefix[strlen(slice_prefix)-1]='\0';
akmhoque829228c2013-02-25 17:39:40 -0600595 //if( nlsr->slice_prefix)
596 //free(nlsr->slice_prefix);
akmhoque7c234e02013-02-13 11:23:56 -0600597 nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
akmhoque6682ca32013-02-22 00:29:35 -0600598 memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
akmhoque7adb2772013-03-05 16:30:59 -0600599 printf("Slice prefix: %s \n",nlsr->slice_prefix);
600 }
601}
602
603
604 void
605process_command_root_key_prefix(char *command)
606{
607 if(command==NULL)
608 {
609 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
610 return;
611 }
612 char *rem;
613 const char *sep=" \t\n";
614 char *root_key_prefix;
615
616 root_key_prefix=strtok_r(command,sep,&rem);
617 if(root_key_prefix==NULL)
618 {
619 printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n");
620 return;
621 }
622 else
623 {
624 if ( nlsr->root_key_prefix != NULL)
625 free(nlsr->root_key_prefix);
626 if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' )
627 root_key_prefix[strlen(root_key_prefix)-1]='\0';
628 nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char));
629 memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1);
630 printf("Root key prefix: %s \n",nlsr->root_key_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -0600631 }
632}
633
Obaid Amin2a928a52013-02-20 11:06:51 -0600634 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600635process_command_hyperbolic_routing(char *command)
636{
637 if(command==NULL)
638 {
639 printf(" Wrong Command Format ( hyperbolic-routing on)\n");
640 return;
641 }
642 char *rem;
643 const char *sep=" \t\n";
644 char *on_off;
645
646 on_off=strtok_r(command,sep,&rem);
647 if(on_off==NULL)
648 {
649 printf(" Wrong Command Format ( hyperbolic-routing on )\n");
650 return;
651 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600652
akmhoqueb77b95f2013-02-08 12:28:47 -0600653 if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 )
654 {
655 nlsr->is_hyperbolic_calc=1;
656 }
657}
658
Obaid Amin2a928a52013-02-20 11:06:51 -0600659 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600660process_command_hyperbolic_cordinate(char *command)
661{
662 if(command==NULL)
663 {
664 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
665 return;
666 }
667
668 char *rem;
669 const char *sep=" \t\n\r";
670 char *radious;
671 char *theta;
672
673 radious=strtok_r(command,sep,&rem);
674 if (radious == NULL )
675 {
676 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
677 return;
678 }
679
680 theta=strtok_r(NULL,sep,&rem);
681 if (theta == NULL )
682 {
683 printf(" Wrong Command Format ( hyperbolic r 0 )\n");
684 return;
685 }
686
687 nlsr->cor_r=strtof(radious,NULL);
688 nlsr->cor_theta=strtof(theta,NULL);
689
690}
691
Obaid Amin2a928a52013-02-20 11:06:51 -0600692 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600693process_command_tunnel_type(char *command)
694{
695 if(command==NULL)
696 {
697 printf(" Wrong Command Format ( tunnel-type udp/tcp)\n");
698 return;
699 }
700 char *rem;
701 const char *sep=" \t\n";
702 char *on_off;
703
704 on_off=strtok_r(command,sep,&rem);
705 if(on_off==NULL)
706 {
707 printf(" Wrong Command Format ( tunnel-type udp/tcp )\n");
708 return;
709 }
Obaid Amin2a928a52013-02-20 11:06:51 -0600710
akmhoqueb77b95f2013-02-08 12:28:47 -0600711 if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 )
712 {
713 nlsr->tunnel_type=IPPROTO_TCP;
714 }
715 else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 )
716 {
717 nlsr->tunnel_type=IPPROTO_UDP;
718 }
719}
720
akmhoque7adb2772013-03-05 16:30:59 -0600721void
722process_command_keystore_passphrase(char *command)
723{
724 if(command==NULL)
725 {
726 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
727 return;
728 }
729 char *rem;
730 const char *sep=" \t\n";
731 char *passphrase;
732
733 passphrase=strtok_r(command,sep,&rem);
734 if(passphrase==NULL)
735 {
736 printf(" Wrong Command Format ( keystore-passphrase passphrase )\n");
737 return;
738 }
739
740 if( nlsr->keystore_passphrase)
741 free(nlsr->keystore_passphrase);
742 nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char));
743 memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase));
744
745
746}
747
748
749void
750process_command_keystore_path(char *command)
751{
752 if(command==NULL)
753 {
754 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
755 return;
756 }
757 char *rem;
758 const char *sep=" \t\n";
759 char *path;
760
761 path=strtok_r(command,sep,&rem);
762 if(path==NULL)
763 {
764 printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n");
765 return;
766 }
767
768 if( nlsr->keystore_path)
769 free(nlsr->keystore_path);
770 nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char));
771 memcpy(nlsr->keystore_path,path,strlen(path));
772
773}
774
775
776
777void
778process_command_site_name(char *command)
779{
780 if(command==NULL)
781 {
782 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
783 return;
784 }
785 char *rem;
786 const char *sep=" \t\n";
787 char *site_name;
788
789 site_name=strtok_r(command,sep,&rem);
790 if(site_name==NULL)
791 {
792 printf(" Wrong Command Format ( site-name site/name/prefix )\n");
793 return;
794 }
795
796 if( nlsr->site_name)
797 free(nlsr->site_name);
798
799 if ( site_name[strlen(site_name)-1] == '/' )
800 site_name[strlen(site_name)-1]='\0';
801
802 nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char));
803 memcpy(nlsr->site_name,site_name,strlen(site_name));
804 printf("Site Name prefix: %s \n",nlsr->site_name);
805
806}
807
808
Obaid Amin2a928a52013-02-20 11:06:51 -0600809 void
akmhoque59980a52012-08-09 12:36:09 -0500810process_conf_command(char *command)
811{
812 const char *separators=" \t\n";
813 char *remainder=NULL;
814 char *cmd_type=NULL;
815
816 if(command==NULL || strlen(command)==0 || command[0]=='!')
817 return;
818
819 cmd_type=strtok_r(command,separators,&remainder);
820
821 if(!strcmp(cmd_type,"router-name") )
822 {
823 process_command_router_name(remainder);
824 }
825 else if(!strcmp(cmd_type,"ccnneighbor") )
826 {
827 process_command_ccnneighbor(remainder);
828 }
829 else if(!strcmp(cmd_type,"ccnname") )
830 {
831 process_command_ccnname(remainder);
832 }
akmhoqued79438d2012-08-27 13:31:42 -0500833 else if(!strcmp(cmd_type,"interest-retry") )
834 {
835 process_command_interest_retry(remainder);
836 }
837 else if(!strcmp(cmd_type,"interest-resend-time") )
838 {
839 process_command_interest_resend_time(remainder);
840 }
akmhoqued5152122012-09-19 06:44:23 -0500841 else if(!strcmp(cmd_type,"lsa-refresh-time") )
842 {
843 process_command_lsa_refresh_time(remainder);
844 }
845 else if(!strcmp(cmd_type,"router-dead-interval") )
846 {
847 process_command_router_dead_interval(remainder);
848 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600849 else if(!strcmp(cmd_type,"max-faces-per-prefix") )
akmhoque3cced642012-09-24 16:20:20 -0500850 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600851 process_command_max_faces_per_prefix(remainder);
akmhoque3cced642012-09-24 16:20:20 -0500852 }
akmhoquebfefef22012-09-26 10:09:34 -0500853 else if(!strcmp(cmd_type,"logdir") )
854 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600855 process_command_logdir(remainder);
akmhoquebfefef22012-09-26 10:09:34 -0500856 }
akmhoque7b791452012-10-30 11:24:56 -0500857 else if(!strcmp(cmd_type,"detailed-log") )
858 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600859 process_command_detailed_log(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500860 }
861 else if(!strcmp(cmd_type,"debug") )
862 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600863 process_command_debug(remainder);
akmhoque7b791452012-10-30 11:24:56 -0500864 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600865 else if(!strcmp(cmd_type,"topo-prefix") )
866 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600867 process_command_topo_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600868 }
869 else if(!strcmp(cmd_type,"slice-prefix") )
870 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600871 process_command_slice_prefix(remainder);
akmhoqueb77b95f2013-02-08 12:28:47 -0600872 }
873 else if(!strcmp(cmd_type,"hyperbolic-cordinate") )
874 {
875 process_command_hyperbolic_cordinate(remainder);
876 }
877 else if(!strcmp(cmd_type,"hyperbolic-routing") )
878 {
879 process_command_hyperbolic_routing(remainder);
880 }
881 else if(!strcmp(cmd_type,"tunnel-type") )
882 {
883 process_command_tunnel_type(remainder);
884 }
akmhoque7adb2772013-03-05 16:30:59 -0600885 else if(!strcmp(cmd_type,"site-name") )
886 {
887 process_command_site_name(remainder);
888 }
889 else if(!strcmp(cmd_type,"keystore-path") )
890 {
891 process_command_keystore_path(remainder);
892 }
893 else if(!strcmp(cmd_type,"keystore-passphrase") )
894 {
895 process_command_keystore_passphrase(remainder);
896 }
897 else if(!strcmp(cmd_type,"root-key-prefix") )
898 {
899 process_command_root_key_prefix(remainder);
900 }
akmhoqued5152122012-09-19 06:44:23 -0500901 else
akmhoque59980a52012-08-09 12:36:09 -0500902 {
903 printf("Wrong configuration Command %s \n",cmd_type);
904 }
905}
906
akmhoque03004e62012-09-06 01:12:28 -0500907
Obaid Amin0e9a3002013-02-20 14:55:37 -0600908 int
akmhoque59980a52012-08-09 12:36:09 -0500909readConfigFile(const char *filename)
910{
911 FILE *cfg;
912 char buf[1024];
913 int len;
914
915 cfg=fopen(filename, "r");
916
917 if(cfg == NULL)
918 {
919 printf("\nConfiguration File does not exists\n");
Obaid Amin0e9a3002013-02-20 14:55:37 -0600920 return -1;
akmhoque59980a52012-08-09 12:36:09 -0500921 }
922
923 while(fgets((char *)buf, sizeof(buf), cfg))
924 {
925 len=strlen(buf);
926 if(buf[len-1] == '\n')
Obaid Amin2a928a52013-02-20 11:06:51 -0600927 buf[len-1]='\0';
akmhoqued5152122012-09-19 06:44:23 -0500928 if ( buf[0] != '#' && buf[0] != '!')
929 process_conf_command(buf);
akmhoque59980a52012-08-09 12:36:09 -0500930 }
931
932 fclose(cfg);
933
934 return 0;
935}
936
akmhoqueb77b95f2013-02-08 12:28:47 -0600937
Obaid Amin0e9a3002013-02-20 14:55:37 -0600938 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600939add_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;
Obaid Amin2a928a52013-02-20 11:06:51 -0600953 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name,
Obaid Amin0e9a3002013-02-20 14:55:37 -0600954 (const char *)nbr->ip_address, 9695,nlsr->tunnel_type);
akmhoqueb77b95f2013-02-08 12:28:47 -0600955 update_face_to_adl_for_nbr(nbr->neighbor->name, face_id);
Obaid Amin2a928a52013-02-20 11:06:51 -0600956 add_delete_ccn_face_by_face_id(nlsr->ccn,
957 (const char *)nlsr->topo_prefix, OP_REG, face_id);
958 add_delete_ccn_face_by_face_id(nlsr->ccn,
959 (const char *)nlsr->slice_prefix, OP_REG, face_id);
akmhoqueb77b95f2013-02-08 12:28:47 -0600960 hashtb_next(e);
961 }
962
963 hashtb_end(e);
964
965}
966
Obaid Amin0e9a3002013-02-20 14:55:37 -0600967 void
akmhoqueb77b95f2013-02-08 12:28:47 -0600968destroy_faces_for_nbrs(void)
969{
970 int i, adl_element;
971 struct ndn_neighbor *nbr;
972
973 struct hashtb_enumerator ee;
Obaid Amin2a928a52013-02-20 11:06:51 -0600974 struct hashtb_enumerator *e = &ee;
975
976 hashtb_start(nlsr->adl, e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600977 adl_element=hashtb_n(nlsr->adl);
978
979 for(i=0;i<adl_element;i++)
980 {
981 nbr=e->data;
982 if ( nbr->face > 0 )
983 {
Obaid Amin2a928a52013-02-20 11:06:51 -0600984 add_delete_ccn_face_by_face_id(nlsr->ccn,
985 (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face);
986 add_delete_ccn_face_by_face_id(nlsr->ccn,
987 (const char *)nbr->neighbor->name,OP_UNREG,nbr->face);
988 add_delete_ccn_face_by_face_id(nlsr->ccn,
989 (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face);
akmhoqueb77b95f2013-02-08 12:28:47 -0600990 }
991 hashtb_next(e);
992 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600993 hashtb_end(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600994}
995
Obaid Amin0e9a3002013-02-20 14:55:37 -0600996 char *
akmhoque562caef2012-11-09 13:29:06 -0600997process_api_client_command(char *command)
998{
999 char *msg;
1000 msg=(char *)malloc(100);
akmhoqueb77b95f2013-02-08 12:28:47 -06001001 memset(msg,0,100);
Obaid Amin2a928a52013-02-20 11:06:51 -06001002
akmhoque3171d652012-11-13 11:44:33 -06001003 const char *sep=" \t\n";
1004 char *rem=NULL;
1005 char *cmd_type=NULL;
1006 char *op_type=NULL;
1007 char *name=NULL;
1008 char *face=NULL;
1009 int face_id;
1010 int res;
1011
1012 op_type=strtok_r(command,sep,&rem);
1013 cmd_type=strtok_r(NULL,sep,&rem);
1014 name=strtok_r(NULL,sep,&rem);
1015 if ( name[strlen(name)-1] == '/' )
1016 name[strlen(name)-1]='\0';
1017
Obaid Amin2a928a52013-02-20 11:06:51 -06001018 struct name_prefix *np=(struct name_prefix *) calloc (1,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001019 sizeof(struct name_prefix ));
Obaid Amin2a928a52013-02-20 11:06:51 -06001020 np->name = (char *) calloc (strlen(name)+1,sizeof(char));
akmhoque3171d652012-11-13 11:44:33 -06001021 memcpy(np->name,name,strlen(name)+1);
1022 np->length=strlen(name)+1;
1023
1024 if ( strcmp(cmd_type,"name")!= 0 )
1025 {
1026 face=strtok_r(NULL,sep,&rem);
1027 sscanf(face,"face%d",&face_id);
1028 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001029
akmhoque3171d652012-11-13 11:44:33 -06001030 if ( strcmp(cmd_type,"name")== 0 )
1031 {
1032 if ( strcmp(op_type,"del") == 0 )
1033 {
1034 res=does_name_exist_in_npl(np);
1035 if ( res == 0)
1036 {
1037 sprintf(msg,"Name %s does not exist !!",name);
1038 }
1039 else
1040 {
1041 long int ls_id=get_lsa_id_from_npl(np);
1042 if ( ls_id != 0 )
1043 {
1044 make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id);
1045 sprintf(msg,"Name %s has been deleted and Advertised.",name);
1046 }
1047 else
1048 {
1049 sprintf(msg,"Name %s does not have an Name LSA yet !!",name);
1050 }
1051 }
1052 }
1053 else if ( strcmp(op_type,"add") == 0 )
1054 {
1055 res=does_name_exist_in_npl(np);
1056 if ( res == 0)
1057 {
1058 add_name_to_npl(np);
1059 build_and_install_single_name_lsa(np);
1060 sprintf(msg,"Name %s has been added to advertise.",name);
1061 }
1062 else
1063 {
1064 sprintf(msg,"Name %s has already been advertised from this router !!",name);
1065 }
1066 }
1067 }
1068 else if ( strcmp(cmd_type,"neighbor") == 0 )
1069 {
1070 if ( strcmp(op_type,"del") == 0 )
1071 {
1072 res=is_neighbor(np->name);
1073 if ( res == 0)
1074 {
1075 sprintf(msg,"Neighbor %s does not exist !!",name);
1076 }
1077 else
1078 {
1079 update_adjacent_status_to_adl(np,NBR_DOWN);
akmhoqueb77b95f2013-02-08 12:28:47 -06001080 int face_id=get_next_hop_face_from_adl(np->name);
1081 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id);
1082 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id);
1083 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_UNREG, face_id);
akmhoque3171d652012-11-13 11:44:33 -06001084 delete_nbr_from_adl(np);
1085 if(!nlsr->is_build_adj_lsa_sheduled)
1086 {
1087 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1088 nlsr->is_build_adj_lsa_sheduled=1;
1089 }
1090 sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name);
1091 }
1092 }
1093 else if ( strcmp(op_type,"add") == 0 )
1094 {
1095 res=is_neighbor(np->name);
1096 if ( res == 0 )
1097 {
akmhoque7c234e02013-02-13 11:23:56 -06001098 struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoqueb77b95f2013-02-08 12:28:47 -06001099 get_host_name_from_command_string(nbr_name,np->name,0);
1100 printf("Hostname of neighbor: %s ",nbr_name->name);
1101
akmhoque7c234e02013-02-13 11:23:56 -06001102 char *ip_addr=(char *)calloc(20,sizeof(char));
1103 //memset(ip_addr,0,20);
akmhoqueb77b95f2013-02-08 12:28:47 -06001104 get_ip_from_hostname_02(nbr_name->name,ip_addr);
1105 printf("IP Address: %s \n",ip_addr);
1106 int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type);
1107 update_face_to_adl_for_nbr(nbr_name->name, face_id);
1108 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id);
1109 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_REG, face_id);
1110
1111 add_nbr_to_adl(np,face_id,ip_addr);
1112
akmhoque3171d652012-11-13 11:44:33 -06001113 sprintf(msg,"Neighbor %s has been added to adjacency list.",name);
akmhoque7c234e02013-02-13 11:23:56 -06001114 free(ip_addr);
akmhoqueb77b95f2013-02-08 12:28:47 -06001115
akmhoque3171d652012-11-13 11:44:33 -06001116 }
1117 else
1118 {
1119 sprintf(msg,"Neighbor %s already exists in adjacency list.",name);
1120 }
1121 }
1122 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001123
akmhoque562caef2012-11-09 13:29:06 -06001124
1125 return msg;
1126}
akmhoque1771c412012-11-09 13:06:08 -06001127
Obaid Amin2a928a52013-02-20 11:06:51 -06001128 int
akmhoque1771c412012-11-09 13:06:08 -06001129nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd)
1130{
1131 struct timeval timeout;
akmhoqueb77b95f2013-02-08 12:28:47 -06001132 if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 )
akmhoque1771c412012-11-09 13:06:08 -06001133 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001134 timeout.tv_sec=0;
1135 timeout.tv_usec=time_out_micro_sec;
akmhoque1771c412012-11-09 13:06:08 -06001136 }
akmhoqueb77b95f2013-02-08 12:28:47 -06001137 else
akmhoque1771c412012-11-09 13:06:08 -06001138 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001139 timeout.tv_sec = 0;
1140 timeout.tv_usec = 500000;
akmhoque1771c412012-11-09 13:06:08 -06001141 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001142
akmhoque1771c412012-11-09 13:06:08 -06001143 int fd;
1144 int nread;
1145 int result;
1146 fd_set testfds;
1147 unsigned int client_len;
1148 int client_sockfd;
1149 char recv_buffer[1024];
1150 bzero(recv_buffer,1024);
akmhoque95041802012-11-16 09:18:02 -06001151 struct sockaddr_in client_address;
akmhoque1771c412012-11-09 13:06:08 -06001152
1153 testfds=nlsr->readfds;
1154 result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout);
Obaid Amin2a928a52013-02-20 11:06:51 -06001155
akmhoqueb77b95f2013-02-08 12:28:47 -06001156 for(fd = 0; fd < FD_SETSIZE && result > 0; fd++)
akmhoque1771c412012-11-09 13:06:08 -06001157 {
1158 if(FD_ISSET(fd,&testfds))
1159 {
1160 if ( fd == ccn_fd )
1161 {
1162 return 0;
1163 }
1164 else if(fd == nlsr->nlsr_api_server_sock_fd)
1165 {
1166 client_len = sizeof(client_address);
1167 client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len);
1168 FD_SET(client_sockfd, &nlsr->readfds);
1169 }
1170 else
1171 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001172
akmhoque1771c412012-11-09 13:06:08 -06001173 ioctl(fd, FIONREAD, &nread);
1174 if(nread == 0)
1175 {
1176 close(fd);
1177 FD_CLR(fd, &nlsr->readfds);
1178 }
1179 else
1180 {
1181 recv(fd, recv_buffer, 1024, 0);
akmhoqueb77b95f2013-02-08 12:28:47 -06001182 printf("Received Data from NLSR API cleint: %s \n",recv_buffer);
akmhoque562caef2012-11-09 13:29:06 -06001183 char *msg=process_api_client_command(recv_buffer);
1184 send(fd, msg, strlen(msg),0);
1185 free(msg);
akmhoque1771c412012-11-09 13:06:08 -06001186 close(fd);
1187 FD_CLR(fd, &nlsr->readfds);
akmhoque1771c412012-11-09 13:06:08 -06001188 }
1189 }
1190 }
1191 }
1192
1193 return 0;
1194}
1195
Obaid Amin2a928a52013-02-20 11:06:51 -06001196 int
akmhoqueb77b95f2013-02-08 12:28:47 -06001197check_config_validity()
1198{
1199 if (nlsr->router_name == NULL )
1200 {
1201 fprintf(stderr,"Router name has not been configured :(\n");
1202 return -1;
1203 }
1204 if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) )
1205 {
1206 fprintf(stderr,"Hyperbolic codinate has not been defined :(\n");
1207 return -1;
1208 }
akmhoque7adb2772013-03-05 16:30:59 -06001209 if (nlsr->site_name == NULL )
1210 {
1211 fprintf(stderr,"Site name has not been configured :(\n");
1212 return -1;
1213 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001214
akmhoqueb77b95f2013-02-08 12:28:47 -06001215 return 0;
1216}
1217
Obaid Amin2a928a52013-02-20 11:06:51 -06001218 void
akmhoque386081b2012-08-10 10:53:21 -05001219nlsr_destroy( void )
1220{
akmhoque7b791452012-10-30 11:24:56 -05001221 if ( nlsr->debugging )
1222 {
1223 printf("Freeing Allocated Memory....\n");
1224 }
akmhoque9e9fc722012-09-26 14:03:25 -05001225 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n");
akmhoquead584782013-02-22 10:56:03 -06001226
akmhoquefbfd0982012-09-09 20:59:03 -05001227 /* Destroying all face created by nlsr in CCND */
1228 destroy_all_face_by_nlsr();
akmhoqueb77b95f2013-02-08 12:28:47 -06001229 destroy_faces_for_nbrs();
Obaid Amin0e9a3002013-02-20 14:55:37 -06001230
akmhoquee6f98a12013-02-22 10:33:26 -06001231 destroy_adl();
akmhoquee6f98a12013-02-22 10:33:26 -06001232 destroy_npl();
akmhoquead584782013-02-22 10:56:03 -06001233 destroy_lsdb();
akmhoque54a14f42013-02-24 06:16:20 -06001234 destroy_npt();
1235 destroy_routing_table();
Obaid Amin2a928a52013-02-20 11:06:51 -06001236
akmhoque7c234e02013-02-13 11:23:56 -06001237 if ( nlsr->ccns != NULL )
1238 ccns_close(&nlsr->ccns, NULL, NULL);
1239 if ( nlsr->slice != NULL )
1240 ccns_slice_destroy(&nlsr->slice);
akmhoque3560cb62012-09-09 10:52:30 -05001241
akmhoque7c234e02013-02-13 11:23:56 -06001242 close(nlsr->nlsr_api_server_sock_fd);
akmhoque95041802012-11-16 09:18:02 -06001243
akmhoque866c2222013-02-12 10:49:33 -06001244 ccn_destroy(&nlsr->ccn);
akmhoque7adb2772013-03-05 16:30:59 -06001245
1246 free(nlsr->root_key_prefix);
1247 free(nlsr->keystore_path);
1248 free(nlsr->keystore_passphrase);
1249 if( nlsr->site_name )
1250 free(nlsr->site_name);
1251
akmhoque03004e62012-09-06 01:12:28 -05001252 free(nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001253 if ( nlsr->debugging )
1254 {
1255 printf("Finished freeing allocated memory\n");
1256 }
akmhoque9e9fc722012-09-26 14:03:25 -05001257 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001258
akmhoque7c234e02013-02-13 11:23:56 -06001259 free(nlsr);
akmhoque53f64222012-09-05 13:57:51 -05001260
akmhoque386081b2012-08-10 10:53:21 -05001261}
1262
akmhoque03004e62012-09-06 01:12:28 -05001263
akmhoqueb77b95f2013-02-08 12:28:47 -06001264
Obaid Amin0e9a3002013-02-20 14:55:37 -06001265 void
akmhoque1771c412012-11-09 13:06:08 -06001266init_api_server(int ccn_fd)
1267{
1268 int server_sockfd;
1269 int server_len;
akmhoque95041802012-11-16 09:18:02 -06001270 struct sockaddr_in server_address;
akmhoquef31f13b2012-11-16 09:42:24 -06001271 unsigned int yes=1;
1272
akmhoque95041802012-11-16 09:18:02 -06001273 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
akmhoque1771c412012-11-09 13:06:08 -06001274
1275 int flags = fcntl(server_sockfd, F_GETFL, 0);
1276 fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags);
1277
akmhoquef31f13b2012-11-16 09:42:24 -06001278 if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
1279 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001280 ON_ERROR_DESTROY(-1);
1281 }
akmhoque95041802012-11-16 09:18:02 -06001282
1283 server_address.sin_family = AF_INET;
Adam Alyyanb5fff372013-01-09 14:32:52 -06001284 server_address.sin_addr.s_addr = INADDR_ANY;
1285 server_address.sin_port = htons(nlsr->api_port);
akmhoque95041802012-11-16 09:18:02 -06001286
akmhoque1771c412012-11-09 13:06:08 -06001287 server_len = sizeof(server_address);
1288 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
1289 listen(server_sockfd, 100);
1290 FD_ZERO(&nlsr->readfds);
1291 FD_SET(server_sockfd, &nlsr->readfds);
1292 FD_SET(ccn_fd, &nlsr->readfds);
1293 nlsr->nlsr_api_server_sock_fd=server_sockfd;
akmhoque1771c412012-11-09 13:06:08 -06001294}
1295
Obaid Amin0e9a3002013-02-20 14:55:37 -06001296 int
akmhoque902d57e2012-08-17 09:24:38 -05001297init_nlsr(void)
akmhoque59980a52012-08-09 12:36:09 -05001298{
akmhoque03004e62012-09-06 01:12:28 -05001299 if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR)
1300 {
1301 perror("SIGQUIT install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001302 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001303 }
1304 if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR)
1305 {
1306 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001307 return -1;
Obaid Amin2a928a52013-02-20 11:06:51 -06001308 }
1309 if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR)
akmhoque03004e62012-09-06 01:12:28 -05001310 {
1311 perror("SIGTERM install error\n");
akmhoque81c25e02012-09-10 14:50:33 -05001312 return -1;
akmhoque03004e62012-09-06 01:12:28 -05001313 }
akmhoque902d57e2012-08-17 09:24:38 -05001314
akmhoque7c234e02013-02-13 11:23:56 -06001315 nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr));
Obaid Amin2a928a52013-02-20 11:06:51 -06001316
1317 nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), NULL);
1318 nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
Obaid Amin2a928a52013-02-20 11:06:51 -06001319 nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
1320 nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
akmhoque29c1db52012-09-07 14:47:43 -05001321
akmhoque03004e62012-09-06 01:12:28 -05001322 nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
akmhoque54a14f42013-02-24 06:16:20 -06001323 nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
1324 nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL);
1325 nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL);
akmhoque07dd8cc2012-08-16 10:23:01 -05001326
akmhoque7adb2772013-03-05 16:30:59 -06001327
akmhoque902d57e2012-08-17 09:24:38 -05001328
akmhoque54a14f42013-02-24 06:16:20 -06001329 nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2();
1330
1331 nlsr->in_interest.p = &incoming_interest;
1332 nlsr->in_content.p = &incoming_content;
akmhoque53f64222012-09-05 13:57:51 -05001333
akmhoque59980a52012-08-09 12:36:09 -05001334 nlsr->is_synch_init=1;
akmhoquec9286692012-08-16 09:57:58 -05001335 nlsr->nlsa_id=0;
akmhoqued79438d2012-08-27 13:31:42 -05001336 nlsr->adj_build_flag=0;
akmhoque53f64222012-09-05 13:57:51 -05001337 nlsr->adj_build_count=0;
1338 nlsr->is_build_adj_lsa_sheduled=0;
akmhoque29c1db52012-09-07 14:47:43 -05001339 nlsr->is_send_lsdb_interest_scheduled=0;
1340 nlsr->is_route_calculation_scheduled=0;
akmhoqued79438d2012-08-27 13:31:42 -05001341
akmhoque7b791452012-10-30 11:24:56 -05001342 nlsr->detailed_logging=0;
1343 nlsr->debugging=0;
1344
akmhoqued79438d2012-08-27 13:31:42 -05001345 nlsr->interest_retry = INTEREST_RETRY;
1346 nlsr->interest_resend_time = INTEREST_RESEND_TIME;
akmhoqueda5b6832012-09-13 22:33:55 -05001347 nlsr->lsa_refresh_time=LSA_REFRESH_TIME;
1348 nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL;
akmhoqueb77b95f2013-02-08 12:28:47 -06001349 nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX;
akmhoqueffacaa82012-09-13 17:48:30 -05001350 nlsr->semaphor=NLSR_UNLOCKED;
akmhoque81c25e02012-09-10 14:50:33 -05001351
akmhoque95041802012-11-16 09:18:02 -06001352 nlsr->api_port=API_PORT;
1353
akmhoque7c234e02013-02-13 11:23:56 -06001354 nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001355 memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr"));
1356
akmhoque7c234e02013-02-13 11:23:56 -06001357 nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char));
akmhoqueb77b95f2013-02-08 12:28:47 -06001358 memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA"));
1359
1360 nlsr->is_hyperbolic_calc=0;
1361 nlsr->cor_r=-1.0;
1362 nlsr->cor_theta=-1.0;
1363
1364 nlsr->tunnel_type=IPPROTO_UDP;
1365
akmhoque7adb2772013-03-05 16:30:59 -06001366 nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char));
1367 memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys"));
1368 nlsr->keystore_path=get_current_user_default_keystore();
1369 nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1
1370 ,sizeof(char));
1371 memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.",
1372 strlen("Th1s1sn0t8g00dp8ssw0rd."));
1373
akmhoque81c25e02012-09-10 14:50:33 -05001374 return 0;
akmhoque902d57e2012-08-17 09:24:38 -05001375}
1376
Obaid Amin0e9a3002013-02-20 14:55:37 -06001377 int
akmhoque902d57e2012-08-17 09:24:38 -05001378main(int argc, char *argv[])
1379{
Obaid Amin2a928a52013-02-20 11:06:51 -06001380 int res, ret;
1381 char *config_file;
akmhoquebfefef22012-09-26 10:09:34 -05001382 int daemon_mode=0;
akmhoque95041802012-11-16 09:18:02 -06001383 int port=0;
akmhoque902d57e2012-08-17 09:24:38 -05001384
akmhoque95041802012-11-16 09:18:02 -06001385 while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1)
akmhoque59980a52012-08-09 12:36:09 -05001386 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001387 switch (res)
akmhoque59980a52012-08-09 12:36:09 -05001388 {
1389 case 'd':
akmhoquebfefef22012-09-26 10:09:34 -05001390 daemon_mode = 1;
akmhoque59980a52012-08-09 12:36:09 -05001391 break;
1392 case 'f':
1393 config_file = optarg;
1394 break;
akmhoque95041802012-11-16 09:18:02 -06001395 case 'p':
1396 port = atoi(optarg);
1397 break;
akmhoque59980a52012-08-09 12:36:09 -05001398 case 'h':
1399 default:
1400 usage(argv[0]);
1401 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001402 }
akmhoque59980a52012-08-09 12:36:09 -05001403
Obaid Amin2a928a52013-02-20 11:06:51 -06001404 ret = init_nlsr();
1405 ON_ERROR_EXIT(ret);
akmhoque95041802012-11-16 09:18:02 -06001406
1407 if ( port !=0 )
1408 nlsr->api_port=port;
1409
Obaid Amin0e9a3002013-02-20 14:55:37 -06001410 ON_ERROR_DESTROY(readConfigFile(config_file));
akmhoqueb77b95f2013-02-08 12:28:47 -06001411
1412 ON_ERROR_DESTROY(check_config_validity());
1413
1414 print_adjacent_from_adl();
1415
akmhoquebfefef22012-09-26 10:09:34 -05001416 if ( daemon_mode == 1 )
1417 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001418 nlsr->debugging=0;
akmhoquebfefef22012-09-26 10:09:34 -05001419 daemonize_nlsr();
1420 }
Obaid Amin2a928a52013-02-20 11:06:51 -06001421
akmhoquebfefef22012-09-26 10:09:34 -05001422 startLogging(nlsr->logDir);
Obaid Amin2a928a52013-02-20 11:06:51 -06001423
akmhoque59980a52012-08-09 12:36:09 -05001424 nlsr->ccn=ccn_create();
akmhoque1771c412012-11-09 13:06:08 -06001425 int ccn_fd=ccn_connect(nlsr->ccn, NULL);
Obaid Amin0e9a3002013-02-20 14:55:37 -06001426
akmhoque1771c412012-11-09 13:06:08 -06001427 if(ccn_fd == -1)
akmhoque03004e62012-09-06 01:12:28 -05001428 {
1429 fprintf(stderr,"Could not connect to ccnd\n");
akmhoquebfefef22012-09-26 10:09:34 -05001430 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n");
akmhoque81c25e02012-09-10 14:50:33 -05001431 ON_ERROR_DESTROY(-1);
akmhoque03004e62012-09-06 01:12:28 -05001432 }
akmhoque1771c412012-11-09 13:06:08 -06001433
1434 init_api_server(ccn_fd);
akmhoqueb77b95f2013-02-08 12:28:47 -06001435
1436 res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001437
akmhoqueb77b95f2013-02-08 12:28:47 -06001438 if(res<0)
1439 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001440 fprintf(stderr, "Can not create slice for prefix %s\n",
Obaid Amin0e9a3002013-02-20 14:55:37 -06001441 nlsr->slice_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001442 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for"
Obaid Amin0e9a3002013-02-20 14:55:37 -06001443 "prefix %s\n",nlsr->slice_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06001444 ON_ERROR_DESTROY(res);
1445 }
Obaid Amin0e9a3002013-02-20 14:55:37 -06001446
akmhoque53f64222012-09-05 13:57:51 -05001447 struct ccn_charbuf *router_prefix;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001448
akmhoque03004e62012-09-06 01:12:28 -05001449 router_prefix=ccn_charbuf_create();
1450 res=ccn_name_from_uri(router_prefix,nlsr->router_name);
akmhoque59980a52012-08-09 12:36:09 -05001451 if(res<0)
akmhoque03004e62012-09-06 01:12:28 -05001452 {
1453 fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name);
Obaid Amin2a928a52013-02-20 11:06:51 -06001454 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001455 "Bad ccn URI: %s\n", nlsr->router_name);
akmhoque81c25e02012-09-10 14:50:33 -05001456 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001457 }
akmhoque59980a52012-08-09 12:36:09 -05001458
1459 ccn_name_append_str(router_prefix,"nlsr");
akmhoque03004e62012-09-06 01:12:28 -05001460 nlsr->in_interest.data=nlsr->router_name;
akmhoque59980a52012-08-09 12:36:09 -05001461 res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest);
1462 if ( res < 0 )
akmhoque03004e62012-09-06 01:12:28 -05001463 {
1464 fprintf(stderr,"Failed to register interest for router\n");
Obaid Amin2a928a52013-02-20 11:06:51 -06001465 writeLogg(__FILE__,__FUNCTION__,__LINE__,
Obaid Amin0e9a3002013-02-20 14:55:37 -06001466 "Failed to register interest for router\n");
akmhoque81c25e02012-09-10 14:50:33 -05001467 ON_ERROR_DESTROY(res);
akmhoque03004e62012-09-06 01:12:28 -05001468 }
1469 ccn_charbuf_destroy(&router_prefix);
Obaid Amin2a928a52013-02-20 11:06:51 -06001470
akmhoque7b791452012-10-30 11:24:56 -05001471 if ( nlsr->debugging )
1472 printf("Router Name : %s\n",nlsr->router_name);
akmhoque9e9fc722012-09-26 14:03:25 -05001473 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name);
akmhoque7b791452012-10-30 11:24:56 -05001474 if ( nlsr->debugging )
1475 printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque9e9fc722012-09-26 14:03:25 -05001476 writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version);
akmhoque59980a52012-08-09 12:36:09 -05001477
akmhoqueb77b95f2013-02-08 12:28:47 -06001478 add_faces_for_nbrs();
akmhoque53f64222012-09-05 13:57:51 -05001479 print_name_prefix_from_npl();
1480 print_adjacent_from_adl();
akmhoqueb77b95f2013-02-08 12:28:47 -06001481 build_and_install_name_lsas();
1482
akmhoqueb77b95f2013-02-08 12:28:47 -06001483 print_name_lsdb();
1484 if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0)
1485 {
1486 build_and_install_cor_lsa();
1487 }
1488 write_name_lsdb_to_repo(nlsr->slice_prefix);
akmhoque53f64222012-09-05 13:57:51 -05001489
1490 nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
akmhoque184dde02013-02-14 15:53:24 -06001491 ccn_set_schedule(nlsr->ccn,nlsr->sched);
akmhoque03004e62012-09-06 01:12:28 -05001492 nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
akmhoqueffacaa82012-09-13 17:48:30 -05001493 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
Obaid Amin2a928a52013-02-20 11:06:51 -06001494
akmhoque0678c5d2013-02-18 11:03:31 -06001495 res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix);
1496 ON_ERROR_DESTROY(res);
akmhoque1c9b92f2012-08-13 10:57:50 -05001497
akmhoque59980a52012-08-09 12:36:09 -05001498 while(1)
akmhoque29c1db52012-09-07 14:47:43 -05001499 {
akmhoqueffacaa82012-09-13 17:48:30 -05001500 if ( nlsr->semaphor == NLSR_UNLOCKED )
akmhoque29c1db52012-09-07 14:47:43 -05001501 {
akmhoqueffacaa82012-09-13 17:48:30 -05001502 if( nlsr->sched != NULL )
1503 {
akmhoque1771c412012-11-09 13:06:08 -06001504 long int micro_sec=ccn_schedule_run(nlsr->sched);
1505 res=nlsr_api_server_poll(micro_sec,ccn_fd);
1506 ON_ERROR_DESTROY(res);
akmhoqueffacaa82012-09-13 17:48:30 -05001507 }
1508 if(nlsr->ccn != NULL)
1509 {
Obaid Amin2a928a52013-02-20 11:06:51 -06001510 res = ccn_run(nlsr->ccn, 1);
akmhoqueffacaa82012-09-13 17:48:30 -05001511 }
1512 if (!(nlsr->sched && nlsr->ccn))
1513 {
1514 break;
1515 }
akmhoque29c1db52012-09-07 14:47:43 -05001516 }
1517
akmhoque59980a52012-08-09 12:36:09 -05001518 }
akmhoque59980a52012-08-09 12:36:09 -05001519 return 0;
1520}
1521