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 <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
| 20 | #include "nlsr.h" |
| 21 | #include "nlsr_ndn.h" |
| 22 | #include "nlsr_npl.h" |
| 23 | #include "nlsr_adl.h" |
| 24 | #include "nlsr_lsdb.h" |
| 25 | #include "utility.h" |
| 26 | |
| 27 | int |
| 28 | appendLifetime(struct ccn_charbuf *cb, int lifetime) |
| 29 | { |
| 30 | unsigned char buf[sizeof(int32_t)]; |
| 31 | int32_t dreck = lifetime << 12; |
| 32 | int pos = sizeof(int32_t); |
| 33 | int res = 0; |
| 34 | while (dreck > 0 && pos > 0) |
| 35 | { |
| 36 | pos--; |
| 37 | buf[pos] = dreck & 255; |
| 38 | dreck = dreck >> 8; |
| 39 | } |
| 40 | res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos, sizeof(buf)-pos); |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | void |
| 46 | get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 47 | { |
| 48 | if ( nlsr->debugging ) |
| 49 | printf("get_nbr called\n"); |
| 50 | if ( nlsr->detailed_logging ) |
| 51 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n"); |
| 52 | |
| 53 | int res,i; |
| 54 | int nlsr_position=0; |
| 55 | int name_comps=(int)info->interest_comps->n; |
| 56 | int len=0; |
| 57 | |
| 58 | for(i=0;i<name_comps;i++) |
| 59 | { |
| 60 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 61 | if( res == 0) |
| 62 | { |
| 63 | nlsr_position=i; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | const unsigned char *comp_ptr1; |
| 70 | size_t comp_size; |
| 71 | for(i=0;i<nlsr_position;i++) |
| 72 | { |
| 73 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 74 | len+=1; |
| 75 | len+=(int)comp_size; |
| 76 | } |
| 77 | len++; |
| 78 | |
| 79 | char *neighbor=(char *)malloc(len); |
| 80 | memset(neighbor,0,len); |
| 81 | |
| 82 | for(i=0; i<nlsr_position;i++) |
| 83 | { |
| 84 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 85 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 86 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 87 | |
| 88 | } |
| 89 | |
| 90 | nbr->name=(char *)malloc(strlen(neighbor)+1); |
| 91 | memcpy(nbr->name,neighbor,strlen(neighbor)+1); |
| 92 | nbr->length=strlen(neighbor)+1; |
| 93 | |
| 94 | if ( nlsr->debugging ) |
| 95 | printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length); |
| 96 | if ( nlsr->detailed_logging ) |
| 97 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n",nbr->name,nbr->length); |
| 98 | |
| 99 | |
| 100 | |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info, int offset) |
| 105 | { |
| 106 | |
| 107 | //printf("get_lsa_identifier called\n"); |
| 108 | |
| 109 | if ( nlsr->debugging ) |
| 110 | printf("get_lsa_identifier called\n"); |
| 111 | if ( nlsr->detailed_logging ) |
| 112 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsa_identifier called\n"); |
| 113 | |
| 114 | int res,i; |
| 115 | int nlsr_position=0; |
| 116 | int name_comps=(int)info->interest_comps->n; |
| 117 | int len=0; |
| 118 | |
| 119 | for(i=0;i<name_comps;i++) |
| 120 | { |
| 121 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 122 | if( res == 0) |
| 123 | { |
| 124 | nlsr_position=i; |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
| 130 | const unsigned char *comp_ptr1; |
| 131 | size_t comp_size; |
| 132 | for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++) |
| 133 | { |
| 134 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 135 | len+=1; |
| 136 | len+=(int)comp_size; |
| 137 | } |
| 138 | len++; |
| 139 | |
| 140 | char *neighbor=(char *)malloc(len); |
| 141 | memset(neighbor,0,len); |
| 142 | |
| 143 | for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++) |
| 144 | { |
| 145 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 146 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 147 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 148 | |
| 149 | } |
| 150 | |
| 151 | lsaId->name=(char *)malloc(strlen(neighbor)+1); |
| 152 | memset(lsaId->name,0,strlen(neighbor)+1); |
| 153 | memcpy(lsaId->name,neighbor,strlen(neighbor)+1); |
| 154 | lsaId->length=strlen(neighbor)+1; |
| 155 | |
| 156 | if ( nlsr->debugging ) |
| 157 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
| 158 | if ( nlsr->detailed_logging ) |
| 159 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
| 160 | |
| 161 | //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
| 162 | |
| 163 | |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 168 | { |
| 169 | int res,i; |
| 170 | int nlsr_position=0; |
| 171 | int name_comps=(int)info->interest_comps->n; |
| 172 | |
| 173 | int ret=0; |
| 174 | |
| 175 | for(i=0;i<name_comps;i++) |
| 176 | { |
| 177 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 178 | if( res == 0) |
| 179 | { |
| 180 | nlsr_position=i; |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | |
| 186 | const unsigned char *comp_ptr1; |
| 187 | size_t comp_size; |
| 188 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size); |
| 189 | |
| 190 | ret=atoi((char *)comp_ptr1); |
| 191 | |
| 192 | return ret; |
| 193 | |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info ) |
| 198 | { |
| 199 | const unsigned char *comp_ptr1; |
| 200 | size_t comp_size; |
| 201 | ccn_name_comp_get(info->content_ccnb, info->content_comps,info->content_comps->n-2,&comp_ptr1, &comp_size); |
| 202 | memcpy(lsdb_version,(char *)comp_ptr1,(int)comp_size); |
| 203 | |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /* Call back function registered in ccnd to get all interest coming to NLSR application */ |
| 208 | |
| 209 | enum ccn_upcall_res |
| 210 | incoming_interest(struct ccn_closure *selfp, |
| 211 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 212 | { |
| 213 | |
| 214 | nlsr_lock(); |
| 215 | |
| 216 | switch (kind) { |
| 217 | case CCN_UPCALL_FINAL: |
| 218 | break; |
| 219 | case CCN_UPCALL_INTEREST: |
| 220 | // printing the name prefix for which it received interest |
| 221 | if ( nlsr->debugging ) |
| 222 | printf("Interest Received for name: "); |
| 223 | if ( nlsr->detailed_logging ) |
| 224 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: "); |
| 225 | |
| 226 | struct ccn_charbuf*c; |
| 227 | c=ccn_charbuf_create(); |
| 228 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 229 | |
| 230 | if ( nlsr->debugging ) |
| 231 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 232 | if ( nlsr->detailed_logging ) |
| 233 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 234 | |
| 235 | ccn_charbuf_destroy(&c); |
| 236 | |
| 237 | process_incoming_interest(selfp, info); |
| 238 | |
| 239 | break; |
| 240 | |
| 241 | default: |
| 242 | break; |
| 243 | } |
| 244 | |
| 245 | nlsr_unlock(); |
| 246 | |
| 247 | return CCN_UPCALL_RESULT_OK; |
| 248 | } |
| 249 | |
| 250 | /* Function for processing incoming interest and reply with content/NACK content */ |
| 251 | |
| 252 | void |
| 253 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 254 | { |
| 255 | if ( nlsr->debugging ) |
| 256 | printf("process_incoming_interest called \n"); |
| 257 | if ( nlsr->detailed_logging ) |
| 258 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n"); |
| 259 | |
| 260 | const unsigned char *comp_ptr1; |
| 261 | size_t comp_size; |
| 262 | int res,i; |
| 263 | int nlsr_position=0; |
| 264 | int name_comps=(int)info->interest_comps->n; |
| 265 | |
| 266 | for(i=0;i<name_comps;i++) |
| 267 | { |
| 268 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 269 | if( res == 0) |
| 270 | { |
| 271 | nlsr_position=i; |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 277 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 278 | |
| 279 | if(!strcmp((char *)comp_ptr1,"info")) |
| 280 | { |
| 281 | process_incoming_interest_info(selfp,info); |
| 282 | } |
akmhoque | fd255f4 | 2013-01-29 10:41:31 -0600 | [diff] [blame] | 283 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void |
| 287 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 288 | { |
| 289 | if ( nlsr->debugging ) |
| 290 | { |
| 291 | printf("process_incoming_interest_info called \n"); |
| 292 | printf("Sending Info Content back.....\n"); |
| 293 | } |
| 294 | if ( nlsr->detailed_logging ) |
| 295 | { |
| 296 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n"); |
| 297 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | int res; |
| 302 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 303 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 304 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 305 | |
| 306 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 307 | if (res >= 0) |
| 308 | { |
| 309 | sp.template_ccnb=ccn_charbuf_create(); |
| 310 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 311 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 312 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 313 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 314 | |
| 315 | |
akmhoque | 865d93c | 2013-02-08 06:00:10 -0600 | [diff] [blame^] | 316 | char *raw_data=(char *)malloc(20); |
| 317 | memset(raw_data,0,20); |
| 318 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 319 | |
| 320 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data)); |
| 321 | if(res >= 0) |
| 322 | { |
| 323 | if ( nlsr->debugging ) |
| 324 | printf("Signing info Content is successful \n"); |
| 325 | if ( nlsr->detailed_logging ) |
| 326 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n"); |
| 327 | |
| 328 | } |
| 329 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 330 | if(res >= 0) |
| 331 | { |
| 332 | if ( nlsr->debugging ) |
| 333 | printf("Sending Info Content is successful \n"); |
| 334 | if ( nlsr->detailed_logging ) |
| 335 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n"); |
| 336 | } |
| 337 | |
| 338 | |
| 339 | |
| 340 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
| 341 | get_lsa_identifier(nbr,selfp,info,-1); |
| 342 | |
| 343 | if ( nlsr->debugging ) |
| 344 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 345 | if ( nlsr->detailed_logging ) |
| 346 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 347 | |
| 348 | //printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 349 | |
| 350 | |
| 351 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 352 | { |
| 353 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 354 | send_info_interest_to_neighbor(nbr); |
| 355 | } |
| 356 | |
| 357 | free(nbr); |
| 358 | free(raw_data); |
| 359 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 360 | } |
| 361 | |
| 362 | ccn_charbuf_destroy(&data); |
| 363 | ccn_charbuf_destroy(&name); |
| 364 | |
| 365 | } |
| 366 | |
| 367 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 368 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 369 | |
| 370 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 371 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 372 | { |
| 373 | |
| 374 | nlsr_lock(); |
| 375 | |
| 376 | switch(kind) { |
| 377 | case CCN_UPCALL_FINAL: |
| 378 | break; |
| 379 | case CCN_UPCALL_CONTENT: |
| 380 | if ( nlsr->debugging ) |
| 381 | printf("Content Received for Name: "); |
| 382 | if ( nlsr->detailed_logging ) |
| 383 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 384 | |
| 385 | struct ccn_charbuf*c; |
| 386 | c=ccn_charbuf_create(); |
| 387 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 388 | if ( nlsr->debugging ) |
| 389 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 390 | if ( nlsr->detailed_logging ) |
| 391 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 392 | |
| 393 | ccn_charbuf_destroy(&c); |
| 394 | |
| 395 | process_incoming_content(selfp,info); |
| 396 | |
| 397 | break; |
| 398 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
| 399 | //printf("Interest Timed Out Received for Name: "); |
| 400 | if ( nlsr->debugging ) |
| 401 | printf("Interest Timed Out Received for Name: "); |
| 402 | if ( nlsr->detailed_logging ) |
| 403 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: "); |
| 404 | |
| 405 | struct ccn_charbuf*ito; |
| 406 | ito=ccn_charbuf_create(); |
| 407 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 408 | |
| 409 | if ( nlsr->debugging ) |
| 410 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 411 | if ( nlsr->detailed_logging ) |
| 412 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
| 413 | |
| 414 | //printf("%s\n",ccn_charbuf_as_string(ito)); |
| 415 | ccn_charbuf_destroy(&ito); |
| 416 | |
| 417 | process_incoming_timed_out_interest(selfp,info); |
| 418 | |
| 419 | break; |
| 420 | default: |
| 421 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 422 | if ( nlsr->debugging ) |
| 423 | printf("Unexpected response of kind %d\n", kind); |
| 424 | if ( nlsr->detailed_logging ) |
| 425 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind); |
| 426 | break; |
| 427 | } |
| 428 | |
| 429 | nlsr_unlock(); |
| 430 | |
| 431 | return CCN_UPCALL_RESULT_OK; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | void |
| 436 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 437 | { |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 438 | if ( nlsr->debugging ) |
| 439 | printf("process_incoming_content called \n"); |
| 440 | if ( nlsr->detailed_logging ) |
| 441 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
| 442 | |
| 443 | const unsigned char *comp_ptr1; |
| 444 | size_t comp_size; |
| 445 | int res,i; |
| 446 | int nlsr_position=0; |
| 447 | int name_comps=(int)info->interest_comps->n; |
| 448 | |
| 449 | for(i=0;i<name_comps;i++) |
| 450 | { |
| 451 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 452 | if( res == 0) |
| 453 | { |
| 454 | nlsr_position=i; |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 460 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 461 | |
| 462 | if(!strcmp((char *)comp_ptr1,"info")) |
| 463 | { |
| 464 | process_incoming_content_info(selfp,info); |
| 465 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 466 | |
| 467 | } |
| 468 | |
| 469 | |
| 470 | void |
| 471 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 472 | { |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 473 | if ( nlsr->debugging ) |
| 474 | printf("process_incoming_content_info called \n"); |
| 475 | if ( nlsr->detailed_logging ) |
| 476 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n"); |
| 477 | |
| 478 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 479 | get_nbr(nbr,selfp,info); |
| 480 | |
| 481 | if ( nlsr->debugging ) |
| 482 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 483 | if ( nlsr->detailed_logging ) |
| 484 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 485 | |
| 486 | |
akmhoque | 865d93c | 2013-02-08 06:00:10 -0600 | [diff] [blame^] | 487 | //const unsigned char *ptr; |
| 488 | //size_t length; |
| 489 | //ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 490 | |
akmhoque | 865d93c | 2013-02-08 06:00:10 -0600 | [diff] [blame^] | 491 | //long int interval=atoi((char *)ptr); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 492 | |
| 493 | |
| 494 | |
| 495 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 496 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
akmhoque | 865d93c | 2013-02-08 06:00:10 -0600 | [diff] [blame^] | 497 | //update_lsdb_synch_interval_to_adl(nbr,interval); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 498 | print_adjacent_from_adl(); |
| 499 | |
| 500 | |
| 501 | |
| 502 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 503 | { |
| 504 | if ( nlsr->debugging ) |
| 505 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 506 | if ( nlsr->detailed_logging ) |
| 507 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n"); |
| 508 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 509 | nlsr->is_build_adj_lsa_sheduled=1; |
| 510 | } |
| 511 | else |
| 512 | { |
| 513 | if ( nlsr->debugging ) |
| 514 | printf("Build and Install Adj LSA already scheduled\n"); |
| 515 | if ( nlsr->detailed_logging ) |
| 516 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n"); |
| 517 | } |
| 518 | |
| 519 | |
| 520 | free(nbr); |
| 521 | |
| 522 | |
| 523 | } |
| 524 | |
| 525 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 526 | |
| 527 | |
| 528 | void |
| 529 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 530 | { |
| 531 | |
| 532 | |
| 533 | if ( nlsr->debugging ) |
| 534 | printf("process_incoming_timed_out_interest called \n"); |
| 535 | if ( nlsr->detailed_logging ) |
| 536 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n"); |
| 537 | |
| 538 | int res,i; |
| 539 | int nlsr_position=0; |
| 540 | int name_comps=(int)info->interest_comps->n; |
| 541 | |
| 542 | for(i=0;i<name_comps;i++) |
| 543 | { |
| 544 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 545 | if( res == 0) |
| 546 | { |
| 547 | nlsr_position=i; |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 553 | { |
| 554 | process_incoming_timed_out_interest_info(selfp,info); |
| 555 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void |
| 559 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 560 | { |
| 561 | |
| 562 | if ( nlsr->debugging ) |
| 563 | printf("process_incoming_timed_out_interest_info called \n"); |
| 564 | if ( nlsr->detailed_logging ) |
| 565 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n"); |
| 566 | |
| 567 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 568 | get_nbr(nbr,selfp,info); |
| 569 | |
| 570 | if ( nlsr->debugging ) |
| 571 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 572 | if ( nlsr->detailed_logging ) |
| 573 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 574 | |
| 575 | |
| 576 | |
| 577 | update_adjacent_timed_out_to_adl(nbr,1); |
| 578 | print_adjacent_from_adl(); |
| 579 | int timed_out=get_timed_out_number(nbr); |
| 580 | |
| 581 | if ( nlsr->debugging ) |
| 582 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 583 | if ( nlsr->detailed_logging ) |
| 584 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 585 | |
| 586 | |
| 587 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 588 | { |
| 589 | send_info_interest_to_neighbor(nbr); |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 594 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 595 | { |
| 596 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 597 | nlsr->is_build_adj_lsa_sheduled=1; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | free(nbr); |
| 602 | |
| 603 | |
| 604 | } |
| 605 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 606 | |
| 607 | int |
| 608 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 609 | { |
| 610 | if(flags == CCN_SCHEDULE_CANCEL) |
| 611 | { |
| 612 | return -1; |
| 613 | } |
| 614 | |
| 615 | nlsr_lock(); |
| 616 | |
| 617 | if ( nlsr->debugging ) |
| 618 | printf("send_info_interest called \n"); |
| 619 | if ( nlsr->detailed_logging ) |
| 620 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 621 | |
| 622 | if ( nlsr->debugging ) |
| 623 | printf("\n"); |
| 624 | if ( nlsr->detailed_logging ) |
| 625 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 626 | |
| 627 | int adl_element,i; |
| 628 | struct ndn_neighbor *nbr; |
| 629 | |
| 630 | struct hashtb_enumerator ee; |
| 631 | struct hashtb_enumerator *e = ⅇ |
| 632 | |
| 633 | hashtb_start(nlsr->adl, e); |
| 634 | adl_element=hashtb_n(nlsr->adl); |
| 635 | |
| 636 | for(i=0;i<adl_element;i++) |
| 637 | { |
| 638 | nbr=e->data; |
| 639 | send_info_interest_to_neighbor(nbr->neighbor); |
| 640 | hashtb_next(e); |
| 641 | } |
| 642 | hashtb_end(e); |
| 643 | |
| 644 | nlsr_unlock(); |
| 645 | |
| 646 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | void |
| 652 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 653 | { |
| 654 | |
| 655 | if ( nlsr->debugging ) |
| 656 | printf("send_info_interest_to_neighbor called \n"); |
| 657 | if ( nlsr->detailed_logging ) |
| 658 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n"); |
| 659 | |
| 660 | |
| 661 | int res; |
| 662 | char info_str[5]; |
| 663 | char nlsr_str[5]; |
| 664 | |
| 665 | memset(&nlsr_str,0,5); |
| 666 | sprintf(nlsr_str,"nlsr"); |
| 667 | memset(&info_str,0,5); |
| 668 | sprintf(info_str,"info"); |
| 669 | |
| 670 | |
| 671 | struct ccn_charbuf *name; |
| 672 | name=ccn_charbuf_create(); |
| 673 | |
| 674 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 675 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 676 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 677 | memcpy(int_name+strlen(int_name),"/",1); |
| 678 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 679 | memcpy(int_name+strlen(int_name),"/",1); |
| 680 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
| 681 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
| 682 | |
| 683 | |
| 684 | res=ccn_name_from_uri(name,int_name); |
| 685 | if ( res >=0 ) |
| 686 | { |
| 687 | /* adding InterestLifeTime and InterestScope filter */ |
| 688 | |
| 689 | struct ccn_charbuf *templ; |
| 690 | templ = ccn_charbuf_create(); |
| 691 | |
| 692 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 693 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 694 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 695 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 696 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | ed418f3 | 2013-01-30 12:25:04 -0600 | [diff] [blame] | 697 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 698 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 699 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 700 | |
| 701 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | ed418f3 | 2013-01-30 12:25:04 -0600 | [diff] [blame] | 702 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 703 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 704 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | ed418f3 | 2013-01-30 12:25:04 -0600 | [diff] [blame] | 705 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 706 | |
| 707 | if ( nlsr->debugging ) |
akmhoque | ed418f3 | 2013-01-30 12:25:04 -0600 | [diff] [blame] | 708 | printf("Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 709 | if ( nlsr->detailed_logging ) |
akmhoque | ed418f3 | 2013-01-30 12:25:04 -0600 | [diff] [blame] | 710 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 711 | |
| 712 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 713 | |
| 714 | if ( res >= 0 ) |
| 715 | { |
| 716 | if ( nlsr->debugging ) |
| 717 | printf("Info interest sending Successfull .... \n"); |
| 718 | if ( nlsr->detailed_logging ) |
| 719 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n"); |
| 720 | } |
| 721 | ccn_charbuf_destroy(&templ); |
| 722 | } |
| 723 | ccn_charbuf_destroy(&name); |
| 724 | free(int_name); |
| 725 | |
| 726 | } |