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