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