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