akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include<math.h> |
| 5 | #include <unistd.h> |
| 6 | #include <getopt.h> |
| 7 | #include <sys/time.h> |
| 8 | #include <assert.h> |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include <config.h> |
akmhoque | 09c0afa | 2012-12-14 09:27:00 -0600 | [diff] [blame] | 11 | #include <sys/socket.h> |
| 12 | #include <netdb.h> |
| 13 | #include <netinet/in.h> |
| 14 | #include <arpa/inet.h> |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 15 | #endif |
| 16 | |
| 17 | |
| 18 | #include <ccn/ccn.h> |
| 19 | #include <ccn/uri.h> |
| 20 | #include <ccn/keystore.h> |
| 21 | #include <ccn/signing.h> |
| 22 | #include <ccn/schedule.h> |
| 23 | #include <ccn/hashtb.h> |
| 24 | |
| 25 | #include "nlsr.h" |
| 26 | #include "nlsr_npl.h" |
| 27 | #include "nlsr_adl.h" |
| 28 | #include "utility.h" |
| 29 | #include "nlsr_npt.h" |
| 30 | |
| 31 | void |
akmhoque | 09c0afa | 2012-12-14 09:27:00 -0600 | [diff] [blame] | 32 | add_nbr_to_adl(struct name_prefix *new_nbr,int face,char *ip) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 33 | { |
| 34 | struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free |
| 35 | |
| 36 | struct hashtb_enumerator ee; |
| 37 | struct hashtb_enumerator *e = ⅇ |
| 38 | int res; |
| 39 | |
| 40 | hashtb_start(nlsr->adl, e); |
| 41 | res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0); |
| 42 | |
| 43 | if(res == HT_NEW_ENTRY ) |
| 44 | { |
| 45 | |
| 46 | nbr = e->data; |
| 47 | |
| 48 | nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free |
| 49 | nbr->neighbor->name=(char *)malloc(new_nbr->length); |
| 50 | memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length); |
| 51 | nbr->neighbor->length=new_nbr->length; |
| 52 | nbr->face=face; |
| 53 | nbr->status=NBR_DOWN; |
| 54 | nbr->info_interest_timed_out=0; |
| 55 | nbr->lsdb_interest_timed_out=0; |
| 56 | nbr->lsdb_random_time_component=(int)(LSDB_SYNCH_INTERVAL/2); |
| 57 | nbr->lsdb_synch_interval=LSDB_SYNCH_INTERVAL; |
| 58 | nbr->metric=LINK_METRIC; |
| 59 | nbr->is_lsdb_send_interest_scheduled=0; |
| 60 | |
akmhoque | 09c0afa | 2012-12-14 09:27:00 -0600 | [diff] [blame] | 61 | nbr->ip_address=(char *)malloc(13); |
| 62 | memset(nbr->ip_address,13,0); |
| 63 | memcpy(nbr->ip_address,ip,strlen(ip)); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 64 | |
| 65 | char *time_stamp=(char *)malloc(20); |
| 66 | get_current_timestamp_micro(time_stamp); |
| 67 | nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free |
| 68 | memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1); |
| 69 | memset(nbr->last_lsdb_version,'0',strlen(time_stamp)); |
| 70 | nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free |
| 71 | memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1); |
| 72 | memset(nbr->last_info_version,'0',strlen(time_stamp)); |
| 73 | free(time_stamp); |
| 74 | |
| 75 | nbr->last_lsdb_requested=0; |
| 76 | } |
| 77 | |
| 78 | hashtb_end(e); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void |
| 83 | print_adjacent(struct ndn_neighbor *nbr) |
| 84 | { |
| 85 | if ( nlsr->debugging ) |
| 86 | { |
| 87 | printf("print_adjacent called\n"); |
| 88 | printf("--------Neighbor---------------------------\n"); |
| 89 | printf(" Neighbor: %s \n",nbr->neighbor->name); |
| 90 | printf(" Length : %d \n",nbr->neighbor->length); |
akmhoque | 09c0afa | 2012-12-14 09:27:00 -0600 | [diff] [blame] | 91 | printf(" Ip Address: %s \n",nbr->ip_address); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 92 | printf(" Face : %d \n",nbr->face); |
| 93 | printf(" Metric : %d \n",nbr->metric); |
| 94 | printf(" Status : %d \n",nbr->status); |
| 95 | printf(" LSDB Version: %s \n",nbr->last_lsdb_version); |
| 96 | printf(" Info Version: %s \n",nbr->last_info_version); |
| 97 | printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 98 | printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out); |
| 99 | printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 100 | printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component); |
| 101 | printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
| 102 | printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled); |
| 103 | |
| 104 | printf("\n"); |
| 105 | } |
| 106 | |
| 107 | if ( nlsr->detailed_logging ) |
| 108 | { |
| 109 | |
| 110 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n"); |
| 111 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n"); |
| 112 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name); |
| 113 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length); |
| 114 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face); |
| 115 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric); |
| 116 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status); |
| 117 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version); |
| 118 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version); |
| 119 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out); |
| 120 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out); |
| 121 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval); |
| 122 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component); |
| 123 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested); |
| 124 | writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled); |
| 125 | |
| 126 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | |
| 131 | void |
| 132 | print_adjacent_from_adl(void) |
| 133 | { |
| 134 | if ( nlsr->debugging ) |
| 135 | printf("print_adjacent_from_adl called \n"); |
| 136 | if ( nlsr->detailed_logging ) |
| 137 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n"); |
| 138 | |
| 139 | int i, adl_element; |
| 140 | struct ndn_neighbor *nbr; |
| 141 | |
| 142 | struct hashtb_enumerator ee; |
| 143 | struct hashtb_enumerator *e = ⅇ |
| 144 | |
| 145 | hashtb_start(nlsr->adl, e); |
| 146 | adl_element=hashtb_n(nlsr->adl); |
| 147 | |
| 148 | for(i=0;i<adl_element;i++) |
| 149 | { |
| 150 | nbr=e->data; |
| 151 | print_adjacent(nbr); |
| 152 | hashtb_next(e); |
| 153 | } |
| 154 | |
| 155 | hashtb_end(e); |
| 156 | |
| 157 | } |
| 158 | |
| 159 | int |
| 160 | get_adjacent_status(struct name_prefix *nbr) |
| 161 | { |
| 162 | |
| 163 | if ( nlsr->debugging ) |
| 164 | printf("get_adjacent_status called \n"); |
| 165 | if ( nlsr->detailed_logging ) |
| 166 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n"); |
| 167 | |
| 168 | int res; |
| 169 | int status=-1; |
| 170 | struct ndn_neighbor *nnbr; |
| 171 | |
| 172 | struct hashtb_enumerator ee; |
| 173 | struct hashtb_enumerator *e = ⅇ |
| 174 | |
| 175 | hashtb_start(nlsr->adl, e); |
| 176 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 177 | |
| 178 | if (res == HT_OLD_ENTRY) |
| 179 | { |
| 180 | nnbr=e->data; |
| 181 | status=nnbr->status; |
| 182 | } |
| 183 | else if(res == HT_NEW_ENTRY) |
| 184 | { |
| 185 | hashtb_delete(e); |
| 186 | } |
| 187 | |
| 188 | hashtb_end(e); |
| 189 | |
| 190 | return status; |
| 191 | |
| 192 | } |
| 193 | |
| 194 | int |
| 195 | get_timed_out_number(struct name_prefix *nbr) |
| 196 | { |
| 197 | |
| 198 | if ( nlsr->debugging ) |
| 199 | printf("get_timed_out_number called \n"); |
| 200 | if ( nlsr->detailed_logging ) |
| 201 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n"); |
| 202 | |
| 203 | |
| 204 | int res,ret=-1; |
| 205 | struct ndn_neighbor *nnbr; |
| 206 | |
| 207 | struct hashtb_enumerator ee; |
| 208 | struct hashtb_enumerator *e = ⅇ |
| 209 | |
| 210 | hashtb_start(nlsr->adl, e); |
| 211 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 212 | |
| 213 | if( res == HT_OLD_ENTRY ) |
| 214 | { |
| 215 | nnbr=e->data; |
| 216 | ret=nnbr->info_interest_timed_out; |
| 217 | } |
| 218 | else if(res == HT_NEW_ENTRY) |
| 219 | { |
| 220 | hashtb_delete(e); |
| 221 | } |
| 222 | |
| 223 | hashtb_end(e); |
| 224 | |
| 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | int |
| 229 | get_lsdb_interest_timed_out_number(struct name_prefix *nbr) |
| 230 | { |
| 231 | |
| 232 | if ( nlsr->debugging ) |
| 233 | printf("get_lsdb_interest_timed_out_number called \n"); |
| 234 | if ( nlsr->detailed_logging ) |
| 235 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n"); |
| 236 | |
| 237 | int res,ret=-1; |
| 238 | struct ndn_neighbor *nnbr; |
| 239 | |
| 240 | struct hashtb_enumerator ee; |
| 241 | struct hashtb_enumerator *e = ⅇ |
| 242 | |
| 243 | hashtb_start(nlsr->adl, e); |
| 244 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 245 | |
| 246 | if( res == HT_OLD_ENTRY ) |
| 247 | { |
| 248 | nnbr=e->data; |
| 249 | ret=nnbr->lsdb_interest_timed_out; |
| 250 | } |
| 251 | else if(res == HT_NEW_ENTRY) |
| 252 | { |
| 253 | hashtb_delete(e); |
| 254 | } |
| 255 | |
| 256 | hashtb_end(e); |
| 257 | |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | void |
| 262 | update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment) |
| 263 | { |
| 264 | if ( nlsr->debugging ) |
| 265 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 266 | if ( nlsr->detailed_logging ) |
| 267 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n"); |
| 268 | |
| 269 | int res; |
| 270 | struct ndn_neighbor *nnbr; |
| 271 | |
| 272 | struct hashtb_enumerator ee; |
| 273 | struct hashtb_enumerator *e = ⅇ |
| 274 | |
| 275 | hashtb_start(nlsr->adl, e); |
| 276 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 277 | |
| 278 | if( res == HT_OLD_ENTRY ) |
| 279 | { |
| 280 | nnbr=e->data; |
| 281 | nnbr->info_interest_timed_out += increment; |
| 282 | } |
| 283 | else if(res == HT_NEW_ENTRY) |
| 284 | { |
| 285 | hashtb_delete(e); |
| 286 | } |
| 287 | |
| 288 | hashtb_end(e); |
| 289 | } |
| 290 | |
| 291 | void |
| 292 | update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 293 | { |
| 294 | if ( nlsr->debugging ) |
| 295 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 296 | if ( nlsr->detailed_logging ) |
| 297 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n"); |
| 298 | |
| 299 | int time_out_number=get_timed_out_number(nbr); |
| 300 | update_adjacent_timed_out_to_adl(nbr,-time_out_number); |
| 301 | |
| 302 | } |
| 303 | |
| 304 | |
| 305 | void |
| 306 | update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment) |
| 307 | { |
| 308 | if ( nlsr->debugging ) |
| 309 | printf("update_lsdb_interest_timed_out_to_adl called\n"); |
| 310 | if ( nlsr->detailed_logging ) |
| 311 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n"); |
| 312 | |
| 313 | int res; |
| 314 | struct ndn_neighbor *nnbr; |
| 315 | |
| 316 | struct hashtb_enumerator ee; |
| 317 | struct hashtb_enumerator *e = ⅇ |
| 318 | |
| 319 | hashtb_start(nlsr->adl, e); |
| 320 | |
| 321 | //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length); |
| 322 | |
| 323 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 324 | |
| 325 | if( res == HT_OLD_ENTRY ) |
| 326 | { |
| 327 | //printf("Old Neighbor\n"); |
| 328 | nnbr=e->data; |
| 329 | nnbr->lsdb_interest_timed_out += increment; |
| 330 | //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out); |
| 331 | } |
| 332 | else if(res == HT_NEW_ENTRY) |
| 333 | { |
| 334 | hashtb_delete(e); |
| 335 | } |
| 336 | |
| 337 | //print_adjacent_from_adl(); |
| 338 | hashtb_end(e); |
| 339 | } |
| 340 | |
| 341 | void |
| 342 | update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr) |
| 343 | { |
| 344 | if ( nlsr->debugging ) |
| 345 | printf("update_adjacent_timed_out_zero_to_adl called\n"); |
| 346 | if ( nlsr->detailed_logging ) |
| 347 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n"); |
| 348 | |
| 349 | int time_out_number=get_lsdb_interest_timed_out_number(nbr); |
| 350 | update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number); |
| 351 | |
| 352 | } |
| 353 | |
| 354 | void |
| 355 | update_adjacent_status_to_adl(struct name_prefix *nbr, int status) |
| 356 | { |
| 357 | if ( nlsr->debugging ) |
| 358 | printf("update_adjacent_status_to_adl called\n"); |
| 359 | if ( nlsr->detailed_logging ) |
| 360 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n"); |
| 361 | |
| 362 | int res; |
| 363 | struct ndn_neighbor *nnbr; |
| 364 | |
| 365 | struct hashtb_enumerator ee; |
| 366 | struct hashtb_enumerator *e = ⅇ |
| 367 | |
| 368 | hashtb_start(nlsr->adl, e); |
| 369 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 370 | |
| 371 | |
| 372 | if (res == HT_OLD_ENTRY) |
| 373 | { |
| 374 | nnbr=e->data; |
| 375 | if ( nnbr->status!=status ) |
| 376 | { |
| 377 | nnbr->status=status; |
| 378 | nlsr->adj_build_flag++; |
| 379 | } |
| 380 | } |
| 381 | else if(res == HT_NEW_ENTRY) |
| 382 | { |
| 383 | hashtb_delete(e); |
| 384 | } |
| 385 | |
| 386 | hashtb_end(e); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | void |
| 391 | delete_nbr_from_adl(struct name_prefix *nbr) |
| 392 | { |
| 393 | if ( nlsr->debugging ) |
| 394 | printf("delete_nbr_from_adl called\n"); |
| 395 | if ( nlsr->detailed_logging ) |
| 396 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n"); |
| 397 | |
| 398 | int res; |
| 399 | struct hashtb_enumerator ee; |
| 400 | struct hashtb_enumerator *e = ⅇ |
| 401 | |
| 402 | hashtb_start(nlsr->adl, e); |
| 403 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 404 | |
| 405 | |
| 406 | if (res == HT_OLD_ENTRY) |
| 407 | { |
| 408 | hashtb_delete(e); |
| 409 | } |
| 410 | else if(res == HT_NEW_ENTRY) |
| 411 | { |
| 412 | hashtb_delete(e); |
| 413 | } |
| 414 | |
| 415 | hashtb_end(e); |
| 416 | } |
| 417 | |
| 418 | void |
| 419 | update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval) |
| 420 | { |
| 421 | if ( nlsr->debugging ) |
| 422 | printf("update_lsdb_synch_interval_to_adl called\n"); |
| 423 | if ( nlsr->detailed_logging ) |
| 424 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n"); |
| 425 | |
| 426 | int res; |
| 427 | struct ndn_neighbor *nnbr; |
| 428 | |
| 429 | struct hashtb_enumerator ee; |
| 430 | struct hashtb_enumerator *e = ⅇ |
| 431 | |
| 432 | hashtb_start(nlsr->adl, e); |
| 433 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 434 | |
| 435 | |
| 436 | if (res == HT_OLD_ENTRY) |
| 437 | { |
| 438 | nnbr=e->data; |
| 439 | if ( nnbr->lsdb_synch_interval!= interval ) |
| 440 | { |
| 441 | nnbr->lsdb_synch_interval=interval; |
| 442 | nnbr->lsdb_random_time_component=(int)(interval/2); |
| 443 | |
| 444 | } |
| 445 | } |
| 446 | else if(res == HT_NEW_ENTRY) |
| 447 | { |
| 448 | hashtb_delete(e); |
| 449 | } |
| 450 | |
| 451 | hashtb_end(e); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | int |
| 456 | no_active_nbr(void) |
| 457 | { |
| 458 | int i, adl_element; |
| 459 | int no_link=0; |
| 460 | struct ndn_neighbor *nbr; |
| 461 | struct hashtb_enumerator ee; |
| 462 | struct hashtb_enumerator *e = ⅇ |
| 463 | hashtb_start(nlsr->adl, e); |
| 464 | adl_element=hashtb_n(nlsr->adl); |
| 465 | |
| 466 | for(i=0;i<adl_element;i++) |
| 467 | { |
| 468 | nbr=e->data; |
| 469 | if( nbr->status == 1 ) |
| 470 | no_link++; |
| 471 | hashtb_next(e); |
| 472 | } |
| 473 | |
| 474 | hashtb_end(e); |
| 475 | |
| 476 | return no_link; |
| 477 | |
| 478 | } |
| 479 | |
| 480 | int |
| 481 | is_adj_lsa_build(void) |
| 482 | { |
| 483 | int ret=0; |
| 484 | |
| 485 | int nbr_count=0; |
| 486 | |
| 487 | int i, adl_element; |
| 488 | struct ndn_neighbor *nbr; |
| 489 | |
| 490 | struct hashtb_enumerator ee; |
| 491 | struct hashtb_enumerator *e = ⅇ |
| 492 | |
| 493 | hashtb_start(nlsr->adl, e); |
| 494 | adl_element=hashtb_n(nlsr->adl); |
| 495 | |
| 496 | for(i=0;i<adl_element;i++) |
| 497 | { |
| 498 | nbr=e->data; |
| 499 | if(nbr->status == 1 ) |
| 500 | { |
| 501 | nbr_count++; |
| 502 | } |
| 503 | else if ( (nbr->status == 0) && (nbr->info_interest_timed_out >= nlsr->interest_retry || nbr->lsdb_interest_timed_out >= nlsr->interest_retry)) |
| 504 | { |
| 505 | nbr_count++; |
| 506 | } |
| 507 | hashtb_next(e); |
| 508 | } |
| 509 | |
| 510 | hashtb_end(e); |
| 511 | if(nbr_count == adl_element) |
| 512 | ret=1; |
| 513 | |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | void |
| 519 | get_active_nbr_adj_data(struct ccn_charbuf *c) |
| 520 | { |
| 521 | |
| 522 | int i, adl_element; |
| 523 | struct ndn_neighbor *nbr; |
| 524 | struct hashtb_enumerator ee; |
| 525 | struct hashtb_enumerator *e = ⅇ |
| 526 | hashtb_start(nlsr->adl, e); |
| 527 | adl_element=hashtb_n(nlsr->adl); |
| 528 | |
| 529 | for(i=0;i<adl_element;i++) |
| 530 | { |
| 531 | nbr=e->data; |
| 532 | if( nbr->status == 1 ) |
| 533 | { |
| 534 | ccn_charbuf_append_string(c,nbr->neighbor->name); |
| 535 | ccn_charbuf_append_string(c,"|"); |
| 536 | |
| 537 | char *temp_length=(char *)malloc(20); |
| 538 | memset(temp_length,0,20); |
| 539 | sprintf(temp_length,"%d",nbr->neighbor->length); |
| 540 | ccn_charbuf_append_string(c,temp_length); |
| 541 | free(temp_length); |
| 542 | ccn_charbuf_append_string(c,"|"); |
| 543 | |
| 544 | char *temp_face=(char *)malloc(20); |
| 545 | memset(temp_face,0,20); |
| 546 | sprintf(temp_face,"%d",nbr->face); |
| 547 | ccn_charbuf_append_string(c,temp_face); |
| 548 | free(temp_face); |
| 549 | ccn_charbuf_append_string(c,"|"); |
| 550 | |
| 551 | char *temp_metric=(char *)malloc(20); |
| 552 | memset(temp_metric,0,20); |
| 553 | sprintf(temp_metric,"%d",nbr->metric); |
| 554 | ccn_charbuf_append_string(c,temp_metric); |
| 555 | free(temp_metric); |
| 556 | ccn_charbuf_append_string(c,"|"); |
| 557 | |
| 558 | } |
| 559 | hashtb_next(e); |
| 560 | } |
| 561 | |
| 562 | hashtb_end(e); |
| 563 | } |
| 564 | |
| 565 | long int |
| 566 | get_nbr_time_diff_lsdb_req(char *nbr) |
| 567 | { |
| 568 | if ( nlsr->debugging ) |
| 569 | printf("get_nbr_time_diff_lsdb_req called\n"); |
| 570 | if ( nlsr->detailed_logging ) |
| 571 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n"); |
| 572 | |
| 573 | long int time_diff=get_lsdb_synch_interval(nbr)+1; |
| 574 | int res; |
| 575 | struct ndn_neighbor *nnbr; |
| 576 | |
| 577 | struct hashtb_enumerator ee; |
| 578 | struct hashtb_enumerator *e = ⅇ |
| 579 | |
| 580 | hashtb_start(nlsr->adl, e); |
| 581 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 582 | |
| 583 | if (res == HT_OLD_ENTRY) |
| 584 | { |
| 585 | nnbr=e->data; |
| 586 | |
| 587 | if (nnbr->last_lsdb_requested == 0) |
| 588 | time_diff=get_lsdb_synch_interval(nbr)+1; |
| 589 | else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr); |
| 590 | |
| 591 | } |
| 592 | else if(res == HT_NEW_ENTRY) |
| 593 | { |
| 594 | hashtb_delete(e); |
| 595 | } |
| 596 | |
| 597 | hashtb_end(e); |
| 598 | |
| 599 | return time_diff; |
| 600 | } |
| 601 | |
| 602 | long int |
| 603 | get_nbr_last_lsdb_requested(char *nbr) |
| 604 | { |
| 605 | if ( nlsr->debugging ) |
| 606 | printf("get_timed_out_number called\n"); |
| 607 | if ( nlsr->detailed_logging ) |
| 608 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n"); |
| 609 | |
| 610 | long int last_lsdb_requested=0; |
| 611 | |
| 612 | int res; |
| 613 | struct ndn_neighbor *nnbr; |
| 614 | |
| 615 | struct hashtb_enumerator ee; |
| 616 | struct hashtb_enumerator *e = ⅇ |
| 617 | |
| 618 | hashtb_start(nlsr->adl, e); |
| 619 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 620 | |
| 621 | if (res == HT_OLD_ENTRY) |
| 622 | { |
| 623 | nnbr=e->data; |
| 624 | last_lsdb_requested=nnbr->last_lsdb_requested; |
| 625 | } |
| 626 | else if(res == HT_NEW_ENTRY) |
| 627 | { |
| 628 | hashtb_delete(e); |
| 629 | } |
| 630 | |
| 631 | hashtb_end(e); |
| 632 | |
| 633 | return last_lsdb_requested; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | int |
| 638 | get_nbr_random_time_component(char *nbr) |
| 639 | { |
| 640 | if ( nlsr->debugging ) |
| 641 | printf("get_nbr_random_time_component called\n"); |
| 642 | if ( nlsr->detailed_logging ) |
| 643 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n"); |
| 644 | |
| 645 | int time=0; |
| 646 | |
| 647 | int res; |
| 648 | struct ndn_neighbor *nnbr; |
| 649 | |
| 650 | struct hashtb_enumerator ee; |
| 651 | struct hashtb_enumerator *e = ⅇ |
| 652 | |
| 653 | hashtb_start(nlsr->adl, e); |
| 654 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 655 | |
| 656 | if (res == HT_OLD_ENTRY) |
| 657 | { |
| 658 | nnbr=e->data; |
| 659 | time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1); |
| 660 | } |
| 661 | else if(res == HT_NEW_ENTRY) |
| 662 | { |
| 663 | hashtb_delete(e); |
| 664 | } |
| 665 | |
| 666 | hashtb_end(e); |
| 667 | |
| 668 | return time; |
| 669 | } |
| 670 | |
| 671 | long int |
| 672 | get_lsdb_synch_interval(char *nbr) |
| 673 | { |
| 674 | if ( nlsr->debugging ) |
| 675 | printf("get_lsdb_synch_interval called \n"); |
| 676 | if ( nlsr->detailed_logging ) |
| 677 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n"); |
| 678 | |
| 679 | long int lsdb_synch_interval=300; |
| 680 | |
| 681 | |
| 682 | int res; |
| 683 | struct ndn_neighbor *nnbr; |
| 684 | |
| 685 | struct hashtb_enumerator ee; |
| 686 | struct hashtb_enumerator *e = ⅇ |
| 687 | |
| 688 | hashtb_start(nlsr->adl, e); |
| 689 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 690 | |
| 691 | if (res == HT_OLD_ENTRY) |
| 692 | { |
| 693 | nnbr=e->data; |
| 694 | lsdb_synch_interval=nnbr->lsdb_synch_interval; |
| 695 | } |
| 696 | else if(res == HT_NEW_ENTRY) |
| 697 | { |
| 698 | hashtb_delete(e); |
| 699 | } |
| 700 | |
| 701 | hashtb_end(e); |
| 702 | |
| 703 | return lsdb_synch_interval; |
| 704 | |
| 705 | } |
| 706 | |
| 707 | char * |
| 708 | get_nbr_lsdb_version(char *nbr) |
| 709 | { |
| 710 | if ( nlsr->debugging ) |
| 711 | printf("get_nbr_lsdb_version called \n"); |
| 712 | if ( nlsr->detailed_logging ) |
| 713 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n"); |
| 714 | |
| 715 | char *version=NULL; |
| 716 | |
| 717 | int res; |
| 718 | struct ndn_neighbor *nnbr; |
| 719 | |
| 720 | struct hashtb_enumerator ee; |
| 721 | struct hashtb_enumerator *e = ⅇ |
| 722 | |
| 723 | hashtb_start(nlsr->adl, e); |
| 724 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 725 | |
| 726 | if (res == HT_OLD_ENTRY) |
| 727 | { |
| 728 | nnbr=e->data; |
| 729 | version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1); |
| 730 | memset(version,0,strlen(nnbr->last_lsdb_version)+1); |
| 731 | memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1); |
| 732 | } |
| 733 | else if(res == HT_NEW_ENTRY) |
| 734 | { |
| 735 | hashtb_delete(e); |
| 736 | } |
| 737 | |
| 738 | hashtb_end(e); |
| 739 | |
| 740 | return version; |
| 741 | } |
| 742 | |
| 743 | void |
| 744 | update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp) |
| 745 | { |
| 746 | if ( nlsr->debugging ) |
| 747 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 748 | if ( nlsr->detailed_logging ) |
| 749 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 750 | |
| 751 | int res; |
| 752 | struct ndn_neighbor *nnbr; |
| 753 | |
| 754 | struct hashtb_enumerator ee; |
| 755 | struct hashtb_enumerator *e = ⅇ |
| 756 | |
| 757 | hashtb_start(nlsr->adl, e); |
| 758 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 759 | |
| 760 | if( res == HT_OLD_ENTRY ) |
| 761 | { |
| 762 | nnbr=e->data; |
| 763 | nnbr->last_lsdb_requested=timestamp; |
| 764 | |
| 765 | } |
| 766 | else if(res == HT_NEW_ENTRY) |
| 767 | { |
| 768 | hashtb_delete(e); |
| 769 | } |
| 770 | |
| 771 | hashtb_end(e); |
| 772 | } |
| 773 | |
| 774 | void |
| 775 | set_is_lsdb_send_interest_scheduled_to_zero(char *nbr) |
| 776 | { |
| 777 | if ( nlsr->debugging ) |
| 778 | printf("set_is_lsdb_send_interest_scheduled_to_zero called \n"); |
| 779 | if ( nlsr->detailed_logging ) |
| 780 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n"); |
| 781 | |
| 782 | |
| 783 | int res; |
| 784 | struct ndn_neighbor *nnbr; |
| 785 | |
| 786 | struct hashtb_enumerator ee; |
| 787 | struct hashtb_enumerator *e = ⅇ |
| 788 | |
| 789 | hashtb_start(nlsr->adl, e); |
| 790 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 791 | |
| 792 | if (res == HT_OLD_ENTRY) |
| 793 | { |
| 794 | nnbr=e->data; |
| 795 | nnbr->is_lsdb_send_interest_scheduled=0; |
| 796 | } |
| 797 | else if(res == HT_NEW_ENTRY) |
| 798 | { |
| 799 | hashtb_delete(e); |
| 800 | } |
| 801 | |
| 802 | hashtb_end(e); |
| 803 | } |
| 804 | |
| 805 | void |
| 806 | update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version) |
| 807 | { |
| 808 | if ( nlsr->debugging ) |
| 809 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 810 | if ( nlsr->detailed_logging ) |
| 811 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n"); |
| 812 | |
| 813 | int res; |
| 814 | struct ndn_neighbor *nnbr; |
| 815 | |
| 816 | struct hashtb_enumerator ee; |
| 817 | struct hashtb_enumerator *e = ⅇ |
| 818 | |
| 819 | hashtb_start(nlsr->adl, e); |
| 820 | res = hashtb_seek(e, nbr->name, nbr->length, 0); |
| 821 | |
| 822 | if( res == HT_OLD_ENTRY ) |
| 823 | { |
| 824 | nnbr=e->data; |
| 825 | free(nnbr->last_lsdb_version); |
| 826 | nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1); |
| 827 | memset(nnbr->last_lsdb_version,0,strlen(version)+1); |
| 828 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
| 829 | } |
| 830 | else if(res == HT_NEW_ENTRY) |
| 831 | { |
| 832 | hashtb_delete(e); |
| 833 | } |
| 834 | |
| 835 | hashtb_end(e); |
| 836 | |
| 837 | } |
| 838 | |
| 839 | void |
| 840 | adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec) |
| 841 | { |
| 842 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 843 | |
| 844 | if ( nlsr->debugging ) |
| 845 | printf("update_adjacent_last_lsdb_requested_to_adl called \n"); |
| 846 | if ( nlsr->detailed_logging ) |
| 847 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n"); |
| 848 | |
| 849 | |
| 850 | int res; |
| 851 | struct ndn_neighbor *nnbr; |
| 852 | |
| 853 | struct hashtb_enumerator ee; |
| 854 | struct hashtb_enumerator *e = ⅇ |
| 855 | |
| 856 | hashtb_start(nlsr->adl, e); |
| 857 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 858 | |
| 859 | if( res == HT_OLD_ENTRY ) |
| 860 | { |
| 861 | nnbr=e->data; |
| 862 | nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec; |
| 863 | |
| 864 | } |
| 865 | else if(res == HT_NEW_ENTRY) |
| 866 | { |
| 867 | hashtb_delete(e); |
| 868 | } |
| 869 | |
| 870 | hashtb_end(e); |
| 871 | |
| 872 | } |
| 873 | |
| 874 | int |
| 875 | get_next_hop_face_from_adl(char *nbr) |
| 876 | { |
| 877 | int res; |
| 878 | int connecting_face=NO_FACE; |
| 879 | struct ndn_neighbor *nnbr; |
| 880 | |
| 881 | struct hashtb_enumerator ee; |
| 882 | struct hashtb_enumerator *e = ⅇ |
| 883 | |
| 884 | hashtb_start(nlsr->adl, e); |
| 885 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 886 | |
| 887 | if( res == HT_OLD_ENTRY ) |
| 888 | { |
| 889 | nnbr=e->data; |
| 890 | connecting_face=nnbr->face; |
| 891 | |
| 892 | } |
| 893 | else if(res == HT_NEW_ENTRY) |
| 894 | { |
| 895 | hashtb_delete(e); |
| 896 | } |
| 897 | |
| 898 | hashtb_end(e); |
| 899 | return connecting_face; |
| 900 | } |
| 901 | |
akmhoque | a37b52c | 2012-12-14 11:16:36 -0600 | [diff] [blame] | 902 | void |
| 903 | update_face_to_adl_for_nbr(char *nbr, int face) |
| 904 | { |
| 905 | int res; |
| 906 | struct ndn_neighbor *nnbr; |
| 907 | |
| 908 | struct hashtb_enumerator ee; |
| 909 | struct hashtb_enumerator *e = ⅇ |
| 910 | |
| 911 | hashtb_start(nlsr->adl, e); |
| 912 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 913 | |
| 914 | if( res == HT_OLD_ENTRY ) |
| 915 | { |
| 916 | nnbr=e->data; |
| 917 | nnbr->face=face; |
| 918 | |
| 919 | } |
| 920 | else if(res == HT_NEW_ENTRY) |
| 921 | { |
| 922 | hashtb_delete(e); |
| 923 | } |
| 924 | |
| 925 | hashtb_end(e); |
| 926 | } |
| 927 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 928 | int |
| 929 | is_neighbor(char *nbr) |
| 930 | { |
| 931 | int ret=0; |
| 932 | |
| 933 | int res; |
| 934 | struct hashtb_enumerator ee; |
| 935 | struct hashtb_enumerator *e = ⅇ |
| 936 | |
| 937 | hashtb_start(nlsr->adl, e); |
| 938 | res = hashtb_seek(e, nbr, strlen(nbr)+1, 0); |
| 939 | |
| 940 | if( res == HT_OLD_ENTRY ) |
| 941 | { |
| 942 | ret=1; |
| 943 | } |
| 944 | else if(res == HT_NEW_ENTRY) |
| 945 | { |
| 946 | hashtb_delete(e); |
| 947 | } |
| 948 | |
| 949 | hashtb_end(e); |
| 950 | |
| 951 | return ret; |
| 952 | } |
| 953 | |