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(); |
| 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"); |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 339 | /* Destroying every hash table attached to each neighbor in ADL before destorying ADL */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 340 | hashtb_destroy(&nlsr->npl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 341 | hashtb_destroy(&nlsr->adl); |
| 342 | hashtb_destroy(&nlsr->lsdb->name_lsdb); |
| 343 | hashtb_destroy(&nlsr->lsdb->adj_lsdb); |
| 344 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 345 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 346 | ccn_schedule_destroy(&nlsr->sched); |
| 347 | ccn_destroy(&nlsr->ccn); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 348 | |
| 349 | free(nlsr->lsdb->lsdb_version); |
| 350 | free(nlsr->lsdb); |
| 351 | free(nlsr->router_name); |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 352 | free(nlsr); |
| 353 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 354 | printf("Finished freeing allocated memory\n"); |
| 355 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 356 | } |
| 357 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 358 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 359 | void |
| 360 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 361 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 362 | if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 363 | { |
| 364 | perror("SIGQUIT install error\n"); |
| 365 | exit(1); |
| 366 | } |
| 367 | if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) |
| 368 | { |
| 369 | perror("SIGTERM install error\n"); |
| 370 | exit(1); |
| 371 | } |
| 372 | if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 373 | { |
| 374 | perror("SIGTERM install error\n"); |
| 375 | exit(1); |
| 376 | } |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 377 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 378 | nlsr=(struct nlsr *)malloc(sizeof(struct nlsr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 379 | |
| 380 | struct hashtb_param param_adl = {0}; |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 381 | nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), ¶m_adl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 382 | struct hashtb_param param_npl = {0}; |
| 383 | nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 384 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 385 | nlsr->in_interest.p = &incoming_interest; |
| 386 | nlsr->in_content.p = &incoming_content; |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 387 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 388 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase)); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 389 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 390 | char *time_stamp=(char *)malloc(20); |
| 391 | memset(time_stamp,0,20); |
| 392 | get_current_timestamp_micro(time_stamp); |
| 393 | nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
| 394 | memset(nlsr->lsdb->lsdb_version,'0',strlen(time_stamp)); |
| 395 | free(time_stamp); |
| 396 | |
| 397 | struct hashtb_param param_adj_lsdb = {0}; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 398 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), ¶m_adj_lsdb); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 399 | struct hashtb_param param_name_lsdb = {0}; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 400 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), ¶m_name_lsdb); |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 401 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 402 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 403 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 404 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 405 | nlsr->adj_build_flag=0; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 406 | nlsr->adj_build_count=0; |
| 407 | nlsr->is_build_adj_lsa_sheduled=0; |
| 408 | nlsr->is_send_lsdb_interest_scheduled=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 409 | |
| 410 | nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL; |
| 411 | nlsr->interest_retry = INTEREST_RETRY; |
| 412 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 413 | |
| 414 | nlsr->semaphor=0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 415 | } |
| 416 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 417 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 418 | int |
| 419 | main(int argc, char *argv[]) |
| 420 | { |
| 421 | int res; |
| 422 | char *config_file; |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 423 | //int daemon_mode; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 424 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 425 | init_nlsr(); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 426 | |
| 427 | while ((res = getopt_long(argc, argv, "df:h", longopts, 0)) != -1) |
| 428 | { |
| 429 | switch (res) |
| 430 | { |
| 431 | case 'd': |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 432 | //daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 433 | break; |
| 434 | case 'f': |
| 435 | config_file = optarg; |
| 436 | break; |
| 437 | case 'h': |
| 438 | default: |
| 439 | usage(argv[0]); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | readConfigFile(config_file); |
| 444 | |
| 445 | nlsr->ccn=ccn_create(); |
| 446 | if(ccn_connect(nlsr->ccn, NULL) == -1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 447 | { |
| 448 | fprintf(stderr,"Could not connect to ccnd\n"); |
| 449 | exit(1); |
| 450 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 451 | struct ccn_charbuf *router_prefix; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 452 | router_prefix=ccn_charbuf_create(); |
| 453 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 454 | if(res<0) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 455 | { |
| 456 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
| 457 | exit(1); |
| 458 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 459 | |
| 460 | ccn_name_append_str(router_prefix,"nlsr"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 461 | nlsr->in_interest.data=nlsr->router_name; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 462 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 463 | if ( res < 0 ) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 464 | { |
| 465 | fprintf(stderr,"Failed to register interest for router\n"); |
| 466 | exit(1); |
| 467 | } |
| 468 | ccn_charbuf_destroy(&router_prefix); |
| 469 | |
| 470 | printf("Router Name : %s\n",nlsr->router_name); |
| 471 | printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 472 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 473 | print_name_prefix_from_npl(); |
| 474 | print_adjacent_from_adl(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 475 | build_and_install_name_lsas(); |
| 476 | print_name_lsdb(); |
| 477 | |
| 478 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 479 | 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] | 480 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 481 | while(1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 482 | { |
| 483 | ccn_schedule_run(nlsr->sched); |
| 484 | res = ccn_run(nlsr->ccn, 500); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 485 | |
| 486 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 487 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame^] | 488 | |
| 489 | nlsr_destroy(); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |