akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 7 | #include <sys/stat.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include <config.h> |
| 11 | #endif |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 12 | #include <sys/types.h> |
| 13 | #include <signal.h> |
| 14 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 15 | |
| 16 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 17 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 18 | #include <ccn/ccn.h> |
| 19 | #include <ccn/uri.h> |
| 20 | #include <ccn/keystore.h> |
| 21 | #include <ccn/signing.h> |
| 22 | #include <ccn/schedule.h> |
| 23 | #include <ccn/hashtb.h> |
| 24 | |
| 25 | #include "nlsr.h" |
| 26 | #include "nlsr_ndn.h" |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 27 | #include "nlsr_lsdb.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 28 | #include "utility.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 29 | #include "nlsr_npl.h" |
| 30 | #include "nlsr_adl.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 31 | #include "nlsr_npt.h" |
| 32 | #include "nlsr_route.h" |
| 33 | |
| 34 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 35 | #define ON_ERROR_DESTROY(resval) \ |
| 36 | { \ |
| 37 | if ((resval) < 0) { \ |
| 38 | nlsr_destroy(); \ |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 39 | exit(1);\ |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 40 | } \ |
| 41 | } |
| 42 | |
| 43 | |
| 44 | #define ON_ERROR_EXIT(resval) \ |
| 45 | { \ |
| 46 | if ((resval) < 0) { \ |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 47 | exit(1); \ |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 48 | } \ |
| 49 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 50 | |
| 51 | struct option longopts[] = |
| 52 | { |
| 53 | { "daemon", no_argument, NULL, 'd'}, |
| 54 | { "config_file", required_argument, NULL, 'f'}, |
| 55 | { "help", no_argument, NULL, 'h'}, |
| 56 | { 0 } |
| 57 | }; |
| 58 | |
| 59 | static int |
| 60 | usage(char *progname) |
| 61 | { |
| 62 | |
| 63 | printf("Usage: %s [OPTIONS...]\n\ |
| 64 | NDN routing....\n\ |
| 65 | -d, --daemon Run in daemon mode\n\ |
| 66 | -f, --config_file Specify configuration file name\n\ |
| 67 | -h, --help Display this help message\n", progname); |
| 68 | |
| 69 | exit(1); |
| 70 | } |
| 71 | |
| 72 | void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result) |
| 73 | { |
| 74 | struct timeval now = {0}; |
| 75 | gettimeofday(&now, 0); |
| 76 | result->s = now.tv_sec; |
| 77 | result->micros = now.tv_usec; |
| 78 | } |
| 79 | |
| 80 | static struct ccn_gettime ndn_rtr_ticker = { |
| 81 | "timer", |
| 82 | &ndn_rtr_gettime, |
| 83 | 1000000, |
| 84 | NULL |
| 85 | }; |
| 86 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 87 | void |
| 88 | nlsr_lock(void) |
| 89 | { |
| 90 | nlsr->semaphor=NLSR_LOCKED; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | nlsr_unlock(void) |
| 95 | { |
| 96 | nlsr->semaphor=NLSR_UNLOCKED; |
| 97 | } |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 98 | |
| 99 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 100 | nlsr_stop_signal_handler(int sig) |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 101 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 102 | signal(sig, SIG_IGN); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 103 | nlsr_destroy(); |
| 104 | exit(0); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 105 | } |
| 106 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 107 | void |
| 108 | daemonize_nlsr(void) |
| 109 | { |
| 110 | int ret; |
| 111 | pid_t process_id = 0; |
| 112 | pid_t sid = 0; |
| 113 | process_id = fork(); |
| 114 | if (process_id < 0) |
| 115 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 116 | printf("Daemonization failed!\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 117 | ON_ERROR_DESTROY(process_id); |
| 118 | } |
| 119 | if (process_id > 0) |
| 120 | { |
| 121 | printf("Process daemonized. Process id: %d \n", process_id); |
| 122 | ret=process_id; |
| 123 | exit(0); |
| 124 | } |
| 125 | |
| 126 | umask(0); |
| 127 | sid = setsid(); |
| 128 | if(sid < 0) |
| 129 | { |
| 130 | ON_ERROR_DESTROY(sid); |
| 131 | } |
| 132 | |
| 133 | chdir("/"); |
| 134 | close(STDIN_FILENO); |
| 135 | close(STDOUT_FILENO); |
| 136 | close(STDERR_FILENO); |
| 137 | } |
| 138 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 139 | void |
| 140 | process_command_ccnneighbor(char *command) |
| 141 | { |
| 142 | if(command==NULL) |
| 143 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 144 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | char *rem; |
| 148 | const char *sep=" \t\n"; |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 149 | char *rtr_name,*face; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 150 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 151 | rtr_name=strtok_r(command,sep,&rem); |
| 152 | if(rtr_name==NULL) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 153 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 154 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
| 158 | face=strtok_r(NULL,sep,&rem); |
| 159 | if(face==NULL) |
| 160 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 161 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 165 | printf("Router: %s face: %s\n",rtr_name,face); |
| 166 | int face_id; |
| 167 | int res; |
| 168 | res=sscanf(face,"face%d",&face_id); |
| 169 | |
| 170 | if(res != 1 ) |
| 171 | { |
| 172 | printf(" Wrong Command Format ( ccnneighbor router_name faceX) where X is integer\n"); |
| 173 | return; |
| 174 | } |
| 175 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 176 | if ( rtr_name[strlen(rtr_name)-1] == '/' ) |
| 177 | { |
| 178 | rtr_name[strlen(rtr_name)-1]='\0'; |
| 179 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 180 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 181 | nbr->name=(char *)malloc(strlen(rtr_name)+1); |
| 182 | memset(nbr->name,0,strlen(rtr_name)+1); |
| 183 | memcpy(nbr->name,rtr_name,strlen(rtr_name)+1); |
| 184 | nbr->length=strlen(rtr_name)+1; |
| 185 | |
| 186 | add_nbr_to_adl(nbr,face_id); |
| 187 | |
| 188 | free(nbr->name); |
| 189 | free(nbr); |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | process_command_ccnname(char *command) |
| 194 | { |
| 195 | |
| 196 | if(command==NULL) |
| 197 | { |
| 198 | printf(" Wrong Command Format ( ccnname /name/prefix)\n"); |
| 199 | return; |
| 200 | } |
| 201 | char *rem; |
| 202 | const char *sep=" \t\n"; |
| 203 | char *name; |
| 204 | name=strtok_r(command,sep,&rem); |
| 205 | if(name==NULL) |
| 206 | { |
| 207 | printf(" Wrong Command Format ( ccnname /name/prefix/ )\n"); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | printf("Name Prefix: %s \n",name); |
| 212 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 213 | if ( name[strlen(name)-1] == '/' ) |
| 214 | name[strlen(name)-1]='\0'; |
| 215 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 216 | struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 217 | np->name=(char *)malloc(strlen(name)+1); |
| 218 | memset(np->name,0,strlen(name)+1); |
| 219 | memcpy(np->name,name,strlen(name)+1); |
| 220 | np->length=strlen(name)+1; |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 221 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 222 | add_name_to_npl(np); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 223 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 224 | free(np->name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 225 | free(np); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 226 | } |
| 227 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 228 | |
| 229 | void |
| 230 | process_command_router_name(char *command) |
| 231 | { |
| 232 | if(command==NULL) |
| 233 | { |
| 234 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 235 | return; |
| 236 | } |
| 237 | char *rem; |
| 238 | const char *sep=" \t\n"; |
| 239 | char *rtr_name; |
| 240 | |
| 241 | rtr_name=strtok_r(command,sep,&rem); |
| 242 | if(rtr_name==NULL) |
| 243 | { |
| 244 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 249 | if ( rtr_name[strlen(rtr_name)-1] == '/' ) |
| 250 | rtr_name[strlen(rtr_name)-1]='\0'; |
| 251 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 252 | nlsr->router_name=(char *)malloc(strlen(rtr_name)+1); |
| 253 | memset(nlsr->router_name,0,strlen(rtr_name)+1); |
| 254 | memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1); |
| 255 | |
| 256 | |
| 257 | } |
| 258 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 259 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 260 | process_command_lsdb_synch_interval(char *command) |
| 261 | { |
| 262 | if(command==NULL) |
| 263 | { |
| 264 | printf(" Wrong Command Format ( lsdb-synch-interval secs )\n"); |
| 265 | return; |
| 266 | } |
| 267 | char *rem; |
| 268 | const char *sep=" \t\n"; |
| 269 | char *secs; |
| 270 | long int seconds; |
| 271 | |
| 272 | secs=strtok_r(command,sep,&rem); |
| 273 | if(secs==NULL) |
| 274 | { |
| 275 | printf(" Wrong Command Format ( lsdb-synch-interval secs)\n"); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | seconds=atoi(secs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 280 | if ( seconds >= 120 && seconds <= 3600 ) |
| 281 | { |
| 282 | nlsr->lsdb_synch_interval=seconds; |
| 283 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 284 | |
| 285 | } |
| 286 | |
| 287 | |
| 288 | void |
| 289 | process_command_interest_retry(char *command) |
| 290 | { |
| 291 | if(command==NULL) |
| 292 | { |
| 293 | printf(" Wrong Command Format ( interest-retry number )\n"); |
| 294 | return; |
| 295 | } |
| 296 | char *rem; |
| 297 | const char *sep=" \t\n"; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 298 | char *retry; |
| 299 | long int retry_number; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 300 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 301 | retry=strtok_r(command,sep,&rem); |
| 302 | if(retry==NULL) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 303 | { |
| 304 | printf(" Wrong Command Format ( interest-retry number)\n"); |
| 305 | return; |
| 306 | } |
| 307 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 308 | retry_number=atoi(retry); |
| 309 | if ( retry_number >= 1 && retry_number<=10 ) |
| 310 | { |
| 311 | nlsr->interest_retry=retry_number; |
| 312 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 313 | |
| 314 | } |
| 315 | |
| 316 | void |
| 317 | process_command_interest_resend_time(char *command) |
| 318 | { |
| 319 | if(command==NULL) |
| 320 | { |
| 321 | printf(" Wrong Command Format ( interest-resend-time secs )\n"); |
| 322 | return; |
| 323 | } |
| 324 | char *rem; |
| 325 | const char *sep=" \t\n"; |
| 326 | char *secs; |
| 327 | long int seconds; |
| 328 | |
| 329 | secs=strtok_r(command,sep,&rem); |
| 330 | if(secs==NULL) |
| 331 | { |
| 332 | printf(" Wrong Command Format ( interest-resend-time secs)\n"); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | seconds=atoi(secs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 337 | if ( seconds <= 60 && seconds >= 1 ) |
| 338 | { |
| 339 | nlsr->interest_resend_time=seconds; |
| 340 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 341 | } |
| 342 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 343 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 344 | void |
| 345 | process_command_lsa_refresh_time(char *command) |
| 346 | { |
| 347 | if(command==NULL) |
| 348 | { |
| 349 | printf(" Wrong Command Format ( lsa-refresh-time secs )\n"); |
| 350 | return; |
| 351 | } |
| 352 | char *rem; |
| 353 | const char *sep=" \t\n"; |
| 354 | char *secs; |
| 355 | long int seconds; |
| 356 | |
| 357 | secs=strtok_r(command,sep,&rem); |
| 358 | if(secs==NULL) |
| 359 | { |
| 360 | printf(" Wrong Command Format ( lsa-refresh-time secs)\n"); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | seconds=atoi(secs); |
| 365 | if ( seconds >= 240 && seconds <= 3600 ) |
| 366 | { |
| 367 | nlsr->lsa_refresh_time=seconds; |
| 368 | } |
| 369 | |
| 370 | } |
| 371 | |
| 372 | void |
| 373 | process_command_router_dead_interval(char *command) |
| 374 | { |
| 375 | if(command==NULL) |
| 376 | { |
| 377 | printf(" Wrong Command Format ( router-dead-interval secs )\n"); |
| 378 | return; |
| 379 | } |
| 380 | char *rem; |
| 381 | const char *sep=" \t\n"; |
| 382 | char *secs; |
| 383 | long int seconds; |
| 384 | |
| 385 | secs=strtok_r(command,sep,&rem); |
| 386 | if(secs==NULL) |
| 387 | { |
| 388 | printf(" Wrong Command Format ( router-dead-interval secs)\n"); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | seconds=atoi(secs); |
| 393 | if ( seconds >= 360 && seconds <= 5400 ) |
| 394 | { |
| 395 | nlsr->router_dead_interval=seconds; |
| 396 | } |
| 397 | |
| 398 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 399 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 400 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 401 | process_command_multi_path_face_num(char *command) |
| 402 | { |
| 403 | if(command==NULL) |
| 404 | { |
| 405 | printf(" Wrong Command Format ( multi-path-face-num n )\n"); |
| 406 | return; |
| 407 | } |
| 408 | char *rem; |
| 409 | const char *sep=" \t\n"; |
| 410 | char *num; |
| 411 | long int number; |
| 412 | |
| 413 | num=strtok_r(command,sep,&rem); |
| 414 | if(num==NULL) |
| 415 | { |
| 416 | printf(" Wrong Command Format ( multi-path-face-num n)\n"); |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | number=atoi(num); |
| 421 | if ( number >= 0 && number <= 60 ) |
| 422 | { |
| 423 | nlsr->multi_path_face_num=number; |
| 424 | } |
| 425 | |
| 426 | } |
| 427 | |
| 428 | void |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 429 | process_command_logdir(char *command) |
| 430 | { |
| 431 | if(command==NULL) |
| 432 | { |
| 433 | printf(" Wrong Command Format ( logdir /path/to/logdir )\n"); |
| 434 | return; |
| 435 | } |
| 436 | char *rem; |
| 437 | const char *sep=" \t\n"; |
| 438 | char *dir; |
| 439 | |
| 440 | dir=strtok_r(command,sep,&rem); |
| 441 | if(dir==NULL) |
| 442 | { |
| 443 | printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n"); |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | nlsr->logDir=(char *)malloc(strlen(dir)+1); |
| 448 | memset(nlsr->logDir,0,strlen(dir)+1); |
| 449 | memcpy(nlsr->logDir,dir,strlen(dir)); |
| 450 | } |
| 451 | |
| 452 | void |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 453 | process_command_detailed_log(char *command) |
| 454 | { |
| 455 | if(command==NULL) |
| 456 | { |
| 457 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 458 | return; |
| 459 | } |
| 460 | char *rem; |
| 461 | const char *sep=" \t\n"; |
| 462 | char *on_off; |
| 463 | |
| 464 | on_off=strtok_r(command,sep,&rem); |
| 465 | if(on_off==NULL) |
| 466 | { |
| 467 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 468 | return; |
| 469 | } |
| 470 | |
| 471 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0) |
| 472 | { |
| 473 | nlsr->detailed_logging=1; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | void |
| 478 | process_command_debug(char *command) |
| 479 | { |
| 480 | if(command==NULL) |
| 481 | { |
| 482 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 483 | return; |
| 484 | } |
| 485 | char *rem; |
| 486 | const char *sep=" \t\n"; |
| 487 | char *on_off; |
| 488 | |
| 489 | on_off=strtok_r(command,sep,&rem); |
| 490 | if(on_off==NULL) |
| 491 | { |
| 492 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 493 | return; |
| 494 | } |
| 495 | |
| 496 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 497 | { |
| 498 | nlsr->debugging=1; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 503 | process_conf_command(char *command) |
| 504 | { |
| 505 | const char *separators=" \t\n"; |
| 506 | char *remainder=NULL; |
| 507 | char *cmd_type=NULL; |
| 508 | |
| 509 | if(command==NULL || strlen(command)==0 || command[0]=='!') |
| 510 | return; |
| 511 | |
| 512 | cmd_type=strtok_r(command,separators,&remainder); |
| 513 | |
| 514 | if(!strcmp(cmd_type,"router-name") ) |
| 515 | { |
| 516 | process_command_router_name(remainder); |
| 517 | } |
| 518 | else if(!strcmp(cmd_type,"ccnneighbor") ) |
| 519 | { |
| 520 | process_command_ccnneighbor(remainder); |
| 521 | } |
| 522 | else if(!strcmp(cmd_type,"ccnname") ) |
| 523 | { |
| 524 | process_command_ccnname(remainder); |
| 525 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 526 | else if(!strcmp(cmd_type,"lsdb-synch-interval") ) |
| 527 | { |
| 528 | process_command_lsdb_synch_interval(remainder); |
| 529 | } |
| 530 | else if(!strcmp(cmd_type,"interest-retry") ) |
| 531 | { |
| 532 | process_command_interest_retry(remainder); |
| 533 | } |
| 534 | else if(!strcmp(cmd_type,"interest-resend-time") ) |
| 535 | { |
| 536 | process_command_interest_resend_time(remainder); |
| 537 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 538 | else if(!strcmp(cmd_type,"lsa-refresh-time") ) |
| 539 | { |
| 540 | process_command_lsa_refresh_time(remainder); |
| 541 | } |
| 542 | else if(!strcmp(cmd_type,"router-dead-interval") ) |
| 543 | { |
| 544 | process_command_router_dead_interval(remainder); |
| 545 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 546 | else if(!strcmp(cmd_type,"multi-path-face-num") ) |
| 547 | { |
| 548 | process_command_multi_path_face_num(remainder); |
| 549 | } |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 550 | else if(!strcmp(cmd_type,"logdir") ) |
| 551 | { |
| 552 | process_command_logdir(remainder); |
| 553 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 554 | else if(!strcmp(cmd_type,"detailed-log") ) |
| 555 | { |
| 556 | process_command_detailed_log(remainder); |
| 557 | } |
| 558 | else if(!strcmp(cmd_type,"debug") ) |
| 559 | { |
| 560 | process_command_debug(remainder); |
| 561 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 562 | else |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 563 | { |
| 564 | printf("Wrong configuration Command %s \n",cmd_type); |
| 565 | } |
| 566 | } |
| 567 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 568 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 569 | int |
| 570 | readConfigFile(const char *filename) |
| 571 | { |
| 572 | FILE *cfg; |
| 573 | char buf[1024]; |
| 574 | int len; |
| 575 | |
| 576 | cfg=fopen(filename, "r"); |
| 577 | |
| 578 | if(cfg == NULL) |
| 579 | { |
| 580 | printf("\nConfiguration File does not exists\n"); |
| 581 | exit(1); |
| 582 | } |
| 583 | |
| 584 | while(fgets((char *)buf, sizeof(buf), cfg)) |
| 585 | { |
| 586 | len=strlen(buf); |
| 587 | if(buf[len-1] == '\n') |
| 588 | buf[len-1]='\0'; |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 589 | if ( buf[0] != '#' && buf[0] != '!') |
| 590 | process_conf_command(buf); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | fclose(cfg); |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 598 | void |
| 599 | nlsr_destroy( void ) |
| 600 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 601 | if ( nlsr->debugging ) |
| 602 | { |
| 603 | printf("Freeing Allocated Memory....\n"); |
| 604 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 605 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n"); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 606 | /* Destroying all face created by nlsr in CCND */ |
| 607 | destroy_all_face_by_nlsr(); |
| 608 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 609 | /* Destroying every hash table attached to each neighbor in ADL before destorying ADL */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 610 | hashtb_destroy(&nlsr->npl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 611 | hashtb_destroy(&nlsr->adl); |
| 612 | hashtb_destroy(&nlsr->lsdb->name_lsdb); |
| 613 | hashtb_destroy(&nlsr->lsdb->adj_lsdb); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 614 | hashtb_destroy(&nlsr->pit_alsa); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 615 | |
| 616 | //To Do: has to destroy the face_list one by one |
| 617 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 618 | hashtb_destroy(&nlsr->routing_table); |
| 619 | |
| 620 | |
| 621 | int i, npt_element; |
| 622 | struct npt_entry *ne; |
| 623 | struct hashtb_enumerator ee; |
| 624 | struct hashtb_enumerator *e = ⅇ |
| 625 | hashtb_start(nlsr->npt, e); |
| 626 | npt_element=hashtb_n(nlsr->npt); |
| 627 | for(i=0;i<npt_element;i++) |
| 628 | { |
| 629 | ne=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 630 | hashtb_destroy(&ne->name_list); |
| 631 | hashtb_destroy(&ne->face_list); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 632 | hashtb_next(e); |
| 633 | } |
| 634 | |
| 635 | hashtb_end(e); |
| 636 | hashtb_destroy(&nlsr->npt); |
| 637 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 638 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 639 | ccn_schedule_destroy(&nlsr->sched); |
| 640 | ccn_destroy(&nlsr->ccn); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 641 | |
| 642 | free(nlsr->lsdb->lsdb_version); |
| 643 | free(nlsr->lsdb); |
| 644 | free(nlsr->router_name); |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 645 | free(nlsr); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 646 | if ( nlsr->debugging ) |
| 647 | { |
| 648 | printf("Finished freeing allocated memory\n"); |
| 649 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 650 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 651 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 652 | } |
| 653 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 654 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 655 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 656 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 657 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 658 | if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 659 | { |
| 660 | perror("SIGQUIT install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 661 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 662 | } |
| 663 | if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) |
| 664 | { |
| 665 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 666 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 667 | } |
| 668 | if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 669 | { |
| 670 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 671 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 672 | } |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 673 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 674 | nlsr=(struct nlsr *)malloc(sizeof(struct nlsr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 675 | |
| 676 | struct hashtb_param param_adl = {0}; |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 677 | nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), ¶m_adl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 678 | struct hashtb_param param_npl = {0}; |
| 679 | nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 680 | struct hashtb_param param_pit_alsa = {0}; |
akmhoque | 1ce7105 | 2012-09-13 22:51:32 -0500 | [diff] [blame] | 681 | nlsr->pit_alsa = hashtb_create(sizeof(struct pending_interest), ¶m_pit_alsa); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 682 | struct hashtb_param param_npt = {0}; |
| 683 | nlsr->npt = hashtb_create(sizeof(struct npt_entry), ¶m_npt); |
| 684 | struct hashtb_param param_rte = {0}; |
| 685 | nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), ¶m_rte); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 686 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 687 | nlsr->in_interest.p = &incoming_interest; |
| 688 | nlsr->in_content.p = &incoming_content; |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 689 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 690 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase)); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 691 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 692 | char *time_stamp=(char *)malloc(20); |
| 693 | memset(time_stamp,0,20); |
| 694 | get_current_timestamp_micro(time_stamp); |
| 695 | nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
| 696 | memset(nlsr->lsdb->lsdb_version,'0',strlen(time_stamp)); |
| 697 | free(time_stamp); |
| 698 | |
| 699 | struct hashtb_param param_adj_lsdb = {0}; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 700 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), ¶m_adj_lsdb); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 701 | struct hashtb_param param_name_lsdb = {0}; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 702 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), ¶m_name_lsdb); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 703 | |
| 704 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 705 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 707 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 708 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 709 | nlsr->adj_build_flag=0; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 710 | nlsr->adj_build_count=0; |
| 711 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 712 | nlsr->is_send_lsdb_interest_scheduled=0; |
| 713 | nlsr->is_route_calculation_scheduled=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 714 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 715 | nlsr->detailed_logging=0; |
| 716 | nlsr->debugging=0; |
| 717 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 718 | nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL; |
| 719 | nlsr->interest_retry = INTEREST_RETRY; |
| 720 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 721 | nlsr->lsa_refresh_time=LSA_REFRESH_TIME; |
| 722 | nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 723 | nlsr->multi_path_face_num=MULTI_PATH_FACE_NUM; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 724 | |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 725 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 726 | nlsr->semaphor=NLSR_UNLOCKED; |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 727 | |
| 728 | return 0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 729 | } |
| 730 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 731 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 732 | int |
| 733 | main(int argc, char *argv[]) |
| 734 | { |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 735 | int res, ret; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 736 | char *config_file; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 737 | int daemon_mode=0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 738 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 739 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 740 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 741 | while ((res = getopt_long(argc, argv, "df:h", longopts, 0)) != -1) |
| 742 | { |
| 743 | switch (res) |
| 744 | { |
| 745 | case 'd': |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 746 | daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 747 | break; |
| 748 | case 'f': |
| 749 | config_file = optarg; |
| 750 | break; |
| 751 | case 'h': |
| 752 | default: |
| 753 | usage(argv[0]); |
| 754 | } |
| 755 | } |
| 756 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 757 | ret=init_nlsr(); |
| 758 | ON_ERROR_EXIT(ret); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 759 | readConfigFile(config_file); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 760 | |
| 761 | if ( daemon_mode == 1 ) |
| 762 | { |
| 763 | daemonize_nlsr(); |
| 764 | } |
| 765 | |
| 766 | startLogging(nlsr->logDir); |
| 767 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 768 | nlsr->ccn=ccn_create(); |
| 769 | if(ccn_connect(nlsr->ccn, NULL) == -1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 770 | { |
| 771 | fprintf(stderr,"Could not connect to ccnd\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 772 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 773 | ON_ERROR_DESTROY(-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 774 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 775 | struct ccn_charbuf *router_prefix; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 776 | router_prefix=ccn_charbuf_create(); |
| 777 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 778 | if(res<0) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 779 | { |
| 780 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 781 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Bad ccn URI: %s\n",nlsr->router_name); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 782 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 783 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 784 | |
| 785 | ccn_name_append_str(router_prefix,"nlsr"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 786 | nlsr->in_interest.data=nlsr->router_name; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 787 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 788 | if ( res < 0 ) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 789 | { |
| 790 | fprintf(stderr,"Failed to register interest for router\n"); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 791 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Failed to register interest for router\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 792 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 793 | } |
| 794 | ccn_charbuf_destroy(&router_prefix); |
| 795 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 796 | if ( nlsr->debugging ) |
| 797 | printf("Router Name : %s\n",nlsr->router_name); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 798 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 799 | if ( nlsr->debugging ) |
| 800 | printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 801 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 802 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 803 | print_name_prefix_from_npl(); |
| 804 | print_adjacent_from_adl(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 805 | build_and_install_name_lsas(); |
| 806 | print_name_lsdb(); |
| 807 | |
| 808 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 809 | nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 810 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 811 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 812 | while(1) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 813 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 814 | if ( nlsr->semaphor == NLSR_UNLOCKED ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 815 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 816 | if( nlsr->sched != NULL ) |
| 817 | { |
| 818 | ccn_schedule_run(nlsr->sched); |
| 819 | } |
| 820 | if(nlsr->ccn != NULL) |
| 821 | { |
| 822 | res = ccn_run(nlsr->ccn, 500); |
| 823 | } |
| 824 | if (!(nlsr->sched && nlsr->ccn)) |
| 825 | { |
| 826 | break; |
| 827 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 828 | } |
| 829 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 830 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 831 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |