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> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
| 20 | #include "nlsr.h" |
| 21 | #include "nlsr_ndn.h" |
| 22 | #include "utility.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 23 | #include "nlsr_adl.h" |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 24 | #include "nlsr_lsdb.h" |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 25 | |
| 26 | |
| 27 | struct option longopts[] = |
| 28 | { |
| 29 | { "daemon", no_argument, NULL, 'd'}, |
| 30 | { "config_file", required_argument, NULL, 'f'}, |
| 31 | { "help", no_argument, NULL, 'h'}, |
| 32 | { 0 } |
| 33 | }; |
| 34 | |
| 35 | static int |
| 36 | usage(char *progname) |
| 37 | { |
| 38 | |
| 39 | printf("Usage: %s [OPTIONS...]\n\ |
| 40 | NDN routing....\n\ |
| 41 | -d, --daemon Run in daemon mode\n\ |
| 42 | -f, --config_file Specify configuration file name\n\ |
| 43 | -h, --help Display this help message\n", progname); |
| 44 | |
| 45 | exit(1); |
| 46 | } |
| 47 | |
| 48 | void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result) |
| 49 | { |
| 50 | struct timeval now = {0}; |
| 51 | gettimeofday(&now, 0); |
| 52 | result->s = now.tv_sec; |
| 53 | result->micros = now.tv_usec; |
| 54 | } |
| 55 | |
| 56 | static struct ccn_gettime ndn_rtr_ticker = { |
| 57 | "timer", |
| 58 | &ndn_rtr_gettime, |
| 59 | 1000000, |
| 60 | NULL |
| 61 | }; |
| 62 | |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame^] | 63 | void |
| 64 | my_lock(void) |
| 65 | { |
| 66 | nlsr->semaphor=1; |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | my_unlock(void) |
| 71 | { |
| 72 | nlsr->semaphor=0; |
| 73 | } |
| 74 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 75 | void |
| 76 | process_command_router_name(char *command) |
| 77 | { |
| 78 | if(command==NULL) |
| 79 | { |
| 80 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 81 | return; |
| 82 | } |
| 83 | char *rem; |
| 84 | const char *sep=" \t\n"; |
| 85 | char *rtr_name; |
| 86 | |
| 87 | rtr_name=strtok_r(command,sep,&rem); |
| 88 | if(rtr_name==NULL) |
| 89 | { |
| 90 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 91 | return; |
| 92 | } |
| 93 | nlsr->router_name=(char *)malloc(strlen(rtr_name)+1); |
| 94 | memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1); |
| 95 | printf("Router Name: %s\n",nlsr->router_name); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | process_command_ccnname(char *command) |
| 100 | { |
| 101 | |
| 102 | if(command==NULL) |
| 103 | { |
| 104 | printf(" Wrong Command Format ( ccnname /name/prefix)\n"); |
| 105 | return; |
| 106 | } |
| 107 | char *rem; |
| 108 | const char *sep=" \t\n"; |
| 109 | char *name_prefix; |
| 110 | name_prefix=strtok_r(command,sep,&rem); |
| 111 | if(name_prefix==NULL) |
| 112 | { |
| 113 | printf(" Wrong Command Format ( ccnname /name/prefix/ )\n"); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | printf("Name Prefix: %s \n",name_prefix); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 118 | |
| 119 | struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix *)); |
| 120 | np->name=(char *)malloc(strlen(name_prefix)+1); |
| 121 | memcpy(np->name,name_prefix,strlen(name_prefix)+1); |
| 122 | np->length=strlen(name_prefix)+1; |
| 123 | |
| 124 | add_name_prefix_to_npl(np); |
| 125 | /* Debugging Purpose */ |
| 126 | print_name_prefix_from_npl(); |
| 127 | |
| 128 | free(np->name); |
| 129 | free(np); |
| 130 | |
| 131 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
| 135 | process_command_ccnneighbor(char *command) |
| 136 | { |
| 137 | if(command==NULL) |
| 138 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 139 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | char *rem; |
| 143 | const char *sep=" \t\n"; |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 144 | char *rtr_name,*face; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 145 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 146 | rtr_name=strtok_r(command,sep,&rem); |
| 147 | if(rtr_name==NULL) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 148 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 149 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 150 | return; |
| 151 | } |
| 152 | |
| 153 | face=strtok_r(NULL,sep,&rem); |
| 154 | if(face==NULL) |
| 155 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 156 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 160 | printf("Router: %s face: %s\n",rtr_name,face); |
| 161 | int face_id; |
| 162 | int res; |
| 163 | res=sscanf(face,"face%d",&face_id); |
| 164 | |
| 165 | if(res != 1 ) |
| 166 | { |
| 167 | printf(" Wrong Command Format ( ccnneighbor router_name faceX) where X is integer\n"); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*)); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 172 | nbr->neighbor=ccn_charbuf_create(); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 173 | ccn_charbuf_append_string(nbr->neighbor,rtr_name); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 174 | nbr->face=face_id; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame^] | 175 | nbr->status=NBR_DOWN; |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 176 | |
| 177 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 178 | |
| 179 | add_adjacent_to_adl(nbr); |
| 180 | print_adjacent_from_adl(); |
| 181 | |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 182 | //free(nbr->neighbor->name); |
| 183 | ccn_charbuf_destroy(&nbr->neighbor); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 184 | free(nbr->neighbor); |
| 185 | free(nbr); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 186 | |
| 187 | } |
| 188 | |
| 189 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 190 | process_command_lsdb_synch_interval(char *command) |
| 191 | { |
| 192 | if(command==NULL) |
| 193 | { |
| 194 | printf(" Wrong Command Format ( lsdb-synch-interval secs )\n"); |
| 195 | return; |
| 196 | } |
| 197 | char *rem; |
| 198 | const char *sep=" \t\n"; |
| 199 | char *secs; |
| 200 | long int seconds; |
| 201 | |
| 202 | secs=strtok_r(command,sep,&rem); |
| 203 | if(secs==NULL) |
| 204 | { |
| 205 | printf(" Wrong Command Format ( lsdb-synch-interval secs)\n"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | seconds=atoi(secs); |
| 210 | nlsr->lsdb_synch_interval=seconds; |
| 211 | |
| 212 | } |
| 213 | |
| 214 | |
| 215 | void |
| 216 | process_command_interest_retry(char *command) |
| 217 | { |
| 218 | if(command==NULL) |
| 219 | { |
| 220 | printf(" Wrong Command Format ( interest-retry number )\n"); |
| 221 | return; |
| 222 | } |
| 223 | char *rem; |
| 224 | const char *sep=" \t\n"; |
| 225 | char *secs; |
| 226 | long int seconds; |
| 227 | |
| 228 | secs=strtok_r(command,sep,&rem); |
| 229 | if(secs==NULL) |
| 230 | { |
| 231 | printf(" Wrong Command Format ( interest-retry number)\n"); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | seconds=atoi(secs); |
| 236 | nlsr->interest_retry=seconds; |
| 237 | |
| 238 | } |
| 239 | |
| 240 | void |
| 241 | process_command_interest_resend_time(char *command) |
| 242 | { |
| 243 | if(command==NULL) |
| 244 | { |
| 245 | printf(" Wrong Command Format ( interest-resend-time secs )\n"); |
| 246 | return; |
| 247 | } |
| 248 | char *rem; |
| 249 | const char *sep=" \t\n"; |
| 250 | char *secs; |
| 251 | long int seconds; |
| 252 | |
| 253 | secs=strtok_r(command,sep,&rem); |
| 254 | if(secs==NULL) |
| 255 | { |
| 256 | printf(" Wrong Command Format ( interest-resend-time secs)\n"); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | seconds=atoi(secs); |
| 261 | nlsr->interest_resend_time=seconds; |
| 262 | |
| 263 | } |
| 264 | |
| 265 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 266 | process_conf_command(char *command) |
| 267 | { |
| 268 | const char *separators=" \t\n"; |
| 269 | char *remainder=NULL; |
| 270 | char *cmd_type=NULL; |
| 271 | |
| 272 | if(command==NULL || strlen(command)==0 || command[0]=='!') |
| 273 | return; |
| 274 | |
| 275 | cmd_type=strtok_r(command,separators,&remainder); |
| 276 | |
| 277 | if(!strcmp(cmd_type,"router-name") ) |
| 278 | { |
| 279 | process_command_router_name(remainder); |
| 280 | } |
| 281 | else if(!strcmp(cmd_type,"ccnneighbor") ) |
| 282 | { |
| 283 | process_command_ccnneighbor(remainder); |
| 284 | } |
| 285 | else if(!strcmp(cmd_type,"ccnname") ) |
| 286 | { |
| 287 | process_command_ccnname(remainder); |
| 288 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 289 | else if(!strcmp(cmd_type,"lsdb-synch-interval") ) |
| 290 | { |
| 291 | process_command_lsdb_synch_interval(remainder); |
| 292 | } |
| 293 | else if(!strcmp(cmd_type,"interest-retry") ) |
| 294 | { |
| 295 | process_command_interest_retry(remainder); |
| 296 | } |
| 297 | else if(!strcmp(cmd_type,"interest-resend-time") ) |
| 298 | { |
| 299 | process_command_interest_resend_time(remainder); |
| 300 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 301 | else |
| 302 | { |
| 303 | printf("Wrong configuration Command %s \n",cmd_type); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | int |
| 308 | readConfigFile(const char *filename) |
| 309 | { |
| 310 | FILE *cfg; |
| 311 | char buf[1024]; |
| 312 | int len; |
| 313 | |
| 314 | cfg=fopen(filename, "r"); |
| 315 | |
| 316 | if(cfg == NULL) |
| 317 | { |
| 318 | printf("\nConfiguration File does not exists\n"); |
| 319 | exit(1); |
| 320 | } |
| 321 | |
| 322 | while(fgets((char *)buf, sizeof(buf), cfg)) |
| 323 | { |
| 324 | len=strlen(buf); |
| 325 | if(buf[len-1] == '\n') |
| 326 | buf[len-1]='\0'; |
| 327 | process_conf_command(buf); |
| 328 | } |
| 329 | |
| 330 | fclose(cfg); |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 335 | void |
| 336 | add_name_prefix_to_npl(struct name_prefix *np) |
| 337 | { |
| 338 | |
| 339 | |
| 340 | printf("\nadd_name_prefix called\n"); |
| 341 | printf("Name Prefix: %s and length: %d \n",np->name,np->length); |
| 342 | |
| 343 | struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix *)); |
| 344 | |
| 345 | struct hashtb_enumerator ee; |
| 346 | struct hashtb_enumerator *e = ⅇ |
| 347 | int res; |
| 348 | |
| 349 | hashtb_start(nlsr->npl, e); |
| 350 | res = hashtb_seek(e, np->name, strlen(np->name), 0); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 351 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 352 | if(res == HT_NEW_ENTRY) |
| 353 | { |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 354 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 355 | hnp = e->data; |
| 356 | hnp->name=(char *)malloc(np->length); |
| 357 | memcpy(hnp->name,np->name,np->length); |
| 358 | hnp->length=np->length; |
| 359 | } |
| 360 | |
| 361 | hashtb_end(e); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 362 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 363 | |
| 364 | printf("\n"); |
| 365 | |
| 366 | } |
| 367 | |
| 368 | void |
| 369 | print_name_prefix_from_npl(void) |
| 370 | { |
| 371 | printf("print_name_prefix_from_npl called \n"); |
| 372 | int i, npl_element; |
| 373 | struct name_prefix *np; |
| 374 | |
| 375 | struct hashtb_enumerator ee; |
| 376 | struct hashtb_enumerator *e = ⅇ |
| 377 | |
| 378 | hashtb_start(nlsr->npl, e); |
| 379 | npl_element=hashtb_n(nlsr->npl); |
| 380 | |
| 381 | for(i=0;i<npl_element;i++) |
| 382 | { |
| 383 | np=e->data; |
| 384 | printf("Name Prefix: %s and Length: %d \n",np->name,np->length); |
| 385 | hashtb_next(e); |
| 386 | } |
| 387 | |
| 388 | hashtb_end(e); |
| 389 | |
| 390 | printf("\n"); |
| 391 | } |
| 392 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 393 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 394 | void |
| 395 | nlsr_destroy( void ) |
| 396 | { |
| 397 | |
| 398 | /* Destroying every hash table attached to each neighbor in ADL before destorying ADL */ |
| 399 | |
| 400 | int i, element; |
| 401 | struct ndn_neighbor *nbr; |
| 402 | |
| 403 | struct hashtb_enumerator ee; |
| 404 | struct hashtb_enumerator *e = ⅇ |
| 405 | |
| 406 | hashtb_start(nlsr->adl, e); |
| 407 | element=hashtb_n(nlsr->adl); |
| 408 | |
| 409 | for(i=0;i<element;i++) |
| 410 | { |
| 411 | nbr=e->data; |
| 412 | hashtb_destroy(&nbr->lsa_update_queue); |
akmhoque | 49c0e7d | 2012-08-21 13:57:26 -0400 | [diff] [blame] | 413 | ccn_charbuf_destroy(&nbr->neighbor); |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 414 | hashtb_next(e); |
| 415 | } |
| 416 | hashtb_end(e); |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 417 | hashtb_destroy(&nlsr->adl); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 418 | |
| 419 | /* Destroying every element in Name LSDB Hash Table */ |
| 420 | hashtb_start(nlsr->adl, e); |
| 421 | element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 422 | |
| 423 | struct nlsa *name_lsa; |
| 424 | |
| 425 | for(i=0;i<element;i++) |
| 426 | { |
| 427 | name_lsa=e->data; |
| 428 | ccn_charbuf_destroy(&name_lsa->name_prefix); |
| 429 | ccn_charbuf_destroy(&name_lsa->header->orig_router); |
| 430 | free(name_lsa->header); |
| 431 | free(name_lsa); |
| 432 | hashtb_next(e); |
| 433 | } |
| 434 | hashtb_end(e); |
| 435 | |
| 436 | hashtb_destroy(&nlsr->lsdb->name_lsdb); |
| 437 | |
| 438 | hashtb_destroy(&nlsr->lsdb->adj_lsdb); |
| 439 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 440 | hashtb_destroy(&nlsr->npl); |
| 441 | ccn_schedule_destroy(&nlsr->sched); |
| 442 | ccn_destroy(&nlsr->ccn); |
| 443 | free(nlsr); |
| 444 | |
| 445 | } |
| 446 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 447 | void |
| 448 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 449 | { |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 450 | struct hashtb_param param_adl = {0}; |
| 451 | struct hashtb_param param_npl = {0}; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 452 | |
| 453 | struct hashtb_param param_adj_lsdb = {0}; |
| 454 | struct hashtb_param param_name_lsdb = {0}; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 455 | |
| 456 | nlsr=(struct nlsr *)malloc(sizeof(struct nlsr)); |
| 457 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 458 | nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), ¶m_adl); |
akmhoque | 8c50d0d | 2012-08-09 13:38:03 -0500 | [diff] [blame] | 459 | nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 460 | nlsr->in_interest.p = &incoming_interest; |
| 461 | nlsr->in_content.p = &incoming_content; |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 462 | |
| 463 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase *)); |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 464 | nlsr->lsdb->version=0; |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 465 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 466 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), ¶m_adj_lsdb); |
| 467 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), ¶m_name_lsdb); |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 468 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 469 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 470 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 471 | nlsr->adj_build_flag=0; |
| 472 | nlsr->adj_build_count=0; |
| 473 | |
| 474 | nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL; |
| 475 | nlsr->interest_retry = INTEREST_RETRY; |
| 476 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame^] | 477 | |
| 478 | nlsr->semaphor=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 479 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 480 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | int |
| 484 | main(int argc, char *argv[]) |
| 485 | { |
| 486 | int res; |
| 487 | char *config_file; |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 488 | //int daemon_mode; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 489 | struct ccn_charbuf *router_prefix; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 490 | |
| 491 | init_nlsr(); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 492 | |
| 493 | while ((res = getopt_long(argc, argv, "df:h", longopts, 0)) != -1) |
| 494 | { |
| 495 | switch (res) |
| 496 | { |
| 497 | case 'd': |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 498 | //daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 499 | break; |
| 500 | case 'f': |
| 501 | config_file = optarg; |
| 502 | break; |
| 503 | case 'h': |
| 504 | default: |
| 505 | usage(argv[0]); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | readConfigFile(config_file); |
| 510 | |
| 511 | nlsr->ccn=ccn_create(); |
| 512 | if(ccn_connect(nlsr->ccn, NULL) == -1) |
| 513 | { |
| 514 | fprintf(stderr,"Could not connect to ccnd\n"); |
| 515 | exit(1); |
| 516 | } |
| 517 | router_prefix=ccn_charbuf_create(); |
| 518 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
| 519 | if(res<0) |
| 520 | { |
| 521 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
| 522 | exit(1); |
| 523 | } |
| 524 | |
| 525 | ccn_name_append_str(router_prefix,"nlsr"); |
| 526 | nlsr->in_interest.data=nlsr->router_name; |
| 527 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 528 | if ( res < 0 ) |
| 529 | { |
| 530 | fprintf(stderr,"Failed to register interest for router\n"); |
| 531 | exit(1); |
| 532 | } |
| 533 | |
| 534 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
| 535 | |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame^] | 536 | nlsr->event_build_name_lsa = ccn_schedule_event(nlsr->sched, 100, &initial_build_name_lsa, NULL, 0); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 537 | nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1000000, &send_info_interest, NULL, 0); |
| 538 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 539 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 540 | while(1) |
| 541 | { |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame^] | 542 | if(nlsr->semaphor !=1) |
| 543 | { |
| 544 | ccn_schedule_run(nlsr->sched); |
| 545 | res = ccn_run(nlsr->ccn, 500); |
| 546 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 547 | |
| 548 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 549 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 550 | nlsr_destroy(); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |