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 | |
| 278 | //printf("Det= %s \n",comp_ptr1); |
| 279 | |
| 280 | if(!strcmp((char *)comp_ptr1,"info")) |
| 281 | { |
| 282 | process_incoming_interest_info(selfp,info); |
| 283 | } |
| 284 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 285 | { |
| 286 | process_incoming_interest_lsdb(selfp,info); |
| 287 | } |
| 288 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 289 | { |
| 290 | process_incoming_interest_lsa(selfp,info); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | void |
| 295 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 296 | { |
| 297 | if ( nlsr->debugging ) |
| 298 | { |
| 299 | printf("process_incoming_interest_info called \n"); |
| 300 | printf("Sending Info Content back.....\n"); |
| 301 | } |
| 302 | if ( nlsr->detailed_logging ) |
| 303 | { |
| 304 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n"); |
| 305 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | int res; |
| 310 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 311 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 312 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 313 | |
| 314 | 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]); |
| 315 | if (res >= 0) |
| 316 | { |
| 317 | sp.template_ccnb=ccn_charbuf_create(); |
| 318 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 319 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 320 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 321 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 322 | |
| 323 | |
| 324 | char *raw_data=(char *)malloc(16); |
| 325 | memset(raw_data,0,16); |
| 326 | sprintf(raw_data,"%ld", nlsr->lsdb_synch_interval); |
| 327 | |
| 328 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data)); |
| 329 | if(res >= 0) |
| 330 | { |
| 331 | if ( nlsr->debugging ) |
| 332 | printf("Signing info Content is successful \n"); |
| 333 | if ( nlsr->detailed_logging ) |
| 334 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n"); |
| 335 | |
| 336 | } |
| 337 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 338 | if(res >= 0) |
| 339 | { |
| 340 | if ( nlsr->debugging ) |
| 341 | printf("Sending Info Content is successful \n"); |
| 342 | if ( nlsr->detailed_logging ) |
| 343 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n"); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | |
| 348 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
| 349 | get_lsa_identifier(nbr,selfp,info,-1); |
| 350 | |
| 351 | if ( nlsr->debugging ) |
| 352 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 353 | if ( nlsr->detailed_logging ) |
| 354 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 355 | |
| 356 | //printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 357 | |
| 358 | |
| 359 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 360 | { |
| 361 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 362 | send_info_interest_to_neighbor(nbr); |
| 363 | } |
| 364 | |
| 365 | free(nbr); |
| 366 | free(raw_data); |
| 367 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 368 | } |
| 369 | |
| 370 | ccn_charbuf_destroy(&data); |
| 371 | ccn_charbuf_destroy(&name); |
| 372 | |
| 373 | } |
| 374 | |
| 375 | |
| 376 | void |
| 377 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 378 | { |
| 379 | //printf("process_incoming_interest_lsdb called \n"); |
| 380 | |
| 381 | if ( nlsr->debugging ) |
| 382 | printf("process_incoming_interest_lsdb called \n"); |
| 383 | if ( nlsr->detailed_logging ) |
| 384 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsdb called \n"); |
| 385 | |
| 386 | |
| 387 | int l,res; |
| 388 | const unsigned char *exclbase; |
| 389 | size_t size; |
| 390 | struct ccn_buf_decoder decoder; |
| 391 | struct ccn_buf_decoder *d; |
| 392 | const unsigned char *comp; |
| 393 | int dbcmp=0; |
| 394 | |
| 395 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 396 | if (l > 0) |
| 397 | { |
| 398 | comp = NULL; |
| 399 | size = 0; |
| 400 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 401 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 402 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 403 | { |
| 404 | ccn_buf_advance(d); |
| 405 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 406 | ccn_buf_advance_past_element(d); |
| 407 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 408 | { |
| 409 | ccn_buf_advance(d); |
| 410 | ccn_buf_match_blob(d, &comp, &size); |
| 411 | ccn_buf_check_close(d); |
| 412 | |
| 413 | |
| 414 | } |
| 415 | ccn_buf_check_close(d); |
| 416 | } |
| 417 | if (comp != NULL) |
| 418 | { |
| 419 | if ( nlsr->debugging ) |
| 420 | { |
| 421 | printf("LSDB Version in Exclusion Filter is %s\n",comp); |
| 422 | printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 423 | } |
| 424 | if ( nlsr->detailed_logging ) |
| 425 | { |
| 426 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is %s\n",comp); |
| 427 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 428 | } |
| 429 | dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp); |
| 430 | } |
| 431 | /* Now comp points to the start of your potential number, and size is its length */ |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | if ( nlsr->debugging ) |
| 436 | printf("LSDB Version in Exclusion Filter is: None Added\n"); |
| 437 | if ( nlsr->detailed_logging ) |
| 438 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is: None Added\n"); |
| 439 | dbcmp=1; |
| 440 | |
| 441 | } |
| 442 | |
| 443 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 444 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 445 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 446 | |
| 447 | 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]); |
| 448 | |
| 449 | sp.template_ccnb=ccn_charbuf_create(); |
| 450 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 451 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 452 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 453 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 454 | |
| 455 | |
| 456 | if(dbcmp>0) |
| 457 | { |
| 458 | if ( nlsr->debugging ) |
| 459 | { |
| 460 | printf("Has Updated Database than Neighbor\n"); |
| 461 | printf("Sending LSDB Summary of Updated LSDB Content...\n"); |
| 462 | } |
| 463 | if ( nlsr->detailed_logging ) |
| 464 | { |
| 465 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Has Updated Database than Neighbor\n"); |
| 466 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content...\n"); |
| 467 | } |
| 468 | ccn_name_append_str(name,nlsr->lsdb->lsdb_version); |
| 469 | |
| 470 | struct ccn_charbuf *lsdb_data=ccn_charbuf_create(); |
| 471 | get_lsdb_summary(lsdb_data); |
| 472 | |
| 473 | char *raw_data=ccn_charbuf_as_string(lsdb_data); |
| 474 | |
| 475 | //printf("Content Data to be sent: %s \n",raw_data); |
| 476 | |
| 477 | if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 ) |
| 478 | { |
| 479 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT")); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 484 | } |
| 485 | |
| 486 | if(res >= 0) |
| 487 | { |
| 488 | if ( nlsr->debugging ) |
| 489 | printf("Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 490 | if ( nlsr->detailed_logging ) |
| 491 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 492 | } |
| 493 | |
| 494 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 495 | |
| 496 | if(res >= 0) |
| 497 | { |
| 498 | if ( nlsr->debugging ) |
| 499 | printf("Sending LSDB Summary of Updated LSDB Content is successful \n"); |
| 500 | if ( nlsr->detailed_logging ) |
| 501 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content is successful \n"); |
| 502 | } |
| 503 | |
| 504 | ccn_charbuf_destroy(&lsdb_data); |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | if ( nlsr->debugging ) |
| 509 | { |
| 510 | printf("Does not have Updated Database than Neighbor\n"); |
| 511 | printf("Sending NACK Content.....\n"); |
| 512 | } |
| 513 | if ( nlsr->detailed_logging ) |
| 514 | { |
| 515 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Does not have Updated Database than Neighbor\n"); |
| 516 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content.....\n"); |
| 517 | } |
| 518 | |
| 519 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
| 520 | |
| 521 | if(res >= 0) |
| 522 | { |
| 523 | if ( nlsr->debugging ) |
| 524 | printf("Signing NACK Content is successful \n"); |
| 525 | if ( nlsr->detailed_logging ) |
| 526 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing NACK Content is successful \n"); |
| 527 | } |
| 528 | |
| 529 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 530 | |
| 531 | if(res >= 0) |
| 532 | { |
| 533 | if ( nlsr->debugging ) |
| 534 | printf("Sending NACK Content is successful \n"); |
| 535 | if ( nlsr->detailed_logging ) |
| 536 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content is successful \n"); |
| 537 | } |
| 538 | |
| 539 | |
| 540 | } |
| 541 | |
| 542 | ccn_charbuf_destroy(&data); |
| 543 | ccn_charbuf_destroy(&name); |
| 544 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 545 | |
| 546 | |
| 547 | } |
| 548 | |
| 549 | |
| 550 | void |
| 551 | process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 552 | { |
| 553 | if ( nlsr->debugging ) |
| 554 | printf("process_incoming_interest_lsa called \n"); |
| 555 | if ( nlsr->detailed_logging ) |
| 556 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsa called \n"); |
| 557 | |
| 558 | int res; |
| 559 | |
| 560 | struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 561 | get_lsa_identifier(lsaId,selfp,info,0); |
| 562 | |
| 563 | //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length); |
| 564 | int ls_type=get_ls_type(selfp, info); |
| 565 | |
| 566 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 567 | |
| 568 | if ( ls_type == LS_TYPE_NAME ) |
| 569 | { |
| 570 | if ( nlsr->debugging ) |
| 571 | printf("Interest Received for NAME LSA \n"); |
| 572 | if ( nlsr->detailed_logging ) |
| 573 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for NAME LSA \n"); |
| 574 | get_name_lsa_data(lsa_data,lsaId); |
| 575 | } |
| 576 | else if ( ls_type == LS_TYPE_ADJ ) |
| 577 | { |
| 578 | if ( nlsr->debugging ) |
| 579 | printf("Interest Received for ADJ LSA \n"); |
| 580 | if ( nlsr->detailed_logging ) |
| 581 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for ADJ LSA \n"); |
| 582 | get_adj_lsa_data(lsa_data,lsaId); |
| 583 | } |
| 584 | |
| 585 | char *rdata=ccn_charbuf_as_string(lsa_data); |
| 586 | char *raw_data=(char *)malloc(strlen(rdata)+1); |
| 587 | memset(raw_data,0,strlen(rdata)+1); |
| 588 | memcpy(raw_data,(char *)rdata,strlen(rdata)+1); |
| 589 | //printf("Content Data to be sent: %s\n",raw_data); |
| 590 | |
| 591 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 592 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 593 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 594 | |
| 595 | 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]); |
| 596 | |
| 597 | sp.template_ccnb=ccn_charbuf_create(); |
| 598 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 599 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 600 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 601 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 602 | |
| 603 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 604 | |
| 605 | if(res >= 0) |
| 606 | { |
| 607 | if ( nlsr->debugging ) |
| 608 | printf("Signing LSA Content is successful \n"); |
| 609 | if ( nlsr->detailed_logging ) |
| 610 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSA Content is successful \n"); |
| 611 | } |
| 612 | |
| 613 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 614 | |
| 615 | if(res >= 0) |
| 616 | { |
| 617 | if ( nlsr->debugging ) |
| 618 | printf("Sending LSA Content is successful \n"); |
| 619 | if ( nlsr->detailed_logging ) |
| 620 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSA Content is successful \n"); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | |
| 625 | ccn_charbuf_destroy(&data); |
| 626 | ccn_charbuf_destroy(&name); |
| 627 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 628 | ccn_charbuf_destroy(&lsa_data); |
| 629 | |
| 630 | free(raw_data); |
| 631 | free(lsaId); |
| 632 | } |
| 633 | |
| 634 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 635 | |
| 636 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 637 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 638 | { |
| 639 | |
| 640 | nlsr_lock(); |
| 641 | |
| 642 | switch(kind) { |
| 643 | case CCN_UPCALL_FINAL: |
| 644 | break; |
| 645 | case CCN_UPCALL_CONTENT: |
| 646 | if ( nlsr->debugging ) |
| 647 | printf("Content Received for Name: "); |
| 648 | if ( nlsr->detailed_logging ) |
| 649 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 650 | |
| 651 | struct ccn_charbuf*c; |
| 652 | c=ccn_charbuf_create(); |
| 653 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 654 | if ( nlsr->debugging ) |
| 655 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 656 | if ( nlsr->detailed_logging ) |
| 657 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 658 | |
| 659 | ccn_charbuf_destroy(&c); |
| 660 | |
| 661 | process_incoming_content(selfp,info); |
| 662 | |
| 663 | break; |
| 664 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
| 665 | //printf("Interest Timed Out Received for Name: "); |
| 666 | if ( nlsr->debugging ) |
| 667 | printf("Interest Timed Out Received for Name: "); |
| 668 | if ( nlsr->detailed_logging ) |
| 669 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: "); |
| 670 | |
| 671 | struct ccn_charbuf*ito; |
| 672 | ito=ccn_charbuf_create(); |
| 673 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 674 | |
| 675 | if ( nlsr->debugging ) |
| 676 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 677 | if ( nlsr->detailed_logging ) |
| 678 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
| 679 | |
| 680 | //printf("%s\n",ccn_charbuf_as_string(ito)); |
| 681 | ccn_charbuf_destroy(&ito); |
| 682 | |
| 683 | process_incoming_timed_out_interest(selfp,info); |
| 684 | |
| 685 | break; |
| 686 | default: |
| 687 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 688 | if ( nlsr->debugging ) |
| 689 | printf("Unexpected response of kind %d\n", kind); |
| 690 | if ( nlsr->detailed_logging ) |
| 691 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind); |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | nlsr_unlock(); |
| 696 | |
| 697 | return CCN_UPCALL_RESULT_OK; |
| 698 | } |
| 699 | |
| 700 | |
| 701 | void |
| 702 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 703 | { |
| 704 | //printf("process_incoming_content called \n"); |
| 705 | if ( nlsr->debugging ) |
| 706 | printf("process_incoming_content called \n"); |
| 707 | if ( nlsr->detailed_logging ) |
| 708 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
| 709 | |
| 710 | const unsigned char *comp_ptr1; |
| 711 | size_t comp_size; |
| 712 | int res,i; |
| 713 | int nlsr_position=0; |
| 714 | int name_comps=(int)info->interest_comps->n; |
| 715 | |
| 716 | for(i=0;i<name_comps;i++) |
| 717 | { |
| 718 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 719 | if( res == 0) |
| 720 | { |
| 721 | nlsr_position=i; |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 727 | |
| 728 | //printf("Det= %s \n",comp_ptr1); |
| 729 | |
| 730 | if(!strcmp((char *)comp_ptr1,"info")) |
| 731 | { |
| 732 | process_incoming_content_info(selfp,info); |
| 733 | } |
akmhoque | 4ae1694 | 2012-12-10 11:50:43 -0600 | [diff] [blame^] | 734 | /*if(!strcmp((char *)comp_ptr1,"lsdb")) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 735 | { |
| 736 | process_incoming_content_lsdb(selfp,info); |
| 737 | } |
| 738 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 739 | { |
| 740 | process_incoming_content_lsa(selfp,info); |
akmhoque | 4ae1694 | 2012-12-10 11:50:43 -0600 | [diff] [blame^] | 741 | }*/ |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 742 | |
| 743 | } |
| 744 | |
| 745 | |
| 746 | void |
| 747 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 748 | { |
| 749 | //printf("process_incoming_content_info called \n"); |
| 750 | if ( nlsr->debugging ) |
| 751 | printf("process_incoming_content_info called \n"); |
| 752 | if ( nlsr->detailed_logging ) |
| 753 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n"); |
| 754 | |
| 755 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 756 | get_nbr(nbr,selfp,info); |
| 757 | |
| 758 | if ( nlsr->debugging ) |
| 759 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 760 | if ( nlsr->detailed_logging ) |
| 761 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 762 | |
| 763 | |
| 764 | const unsigned char *ptr; |
| 765 | size_t length; |
| 766 | 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); |
| 767 | //printf("Content data: %s\n",ptr); |
| 768 | |
| 769 | long int interval=atoi((char *)ptr); |
| 770 | |
| 771 | |
| 772 | |
| 773 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 774 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 775 | update_lsdb_synch_interval_to_adl(nbr,interval); |
| 776 | print_adjacent_from_adl(); |
| 777 | |
| 778 | |
| 779 | |
| 780 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 781 | { |
| 782 | if ( nlsr->debugging ) |
| 783 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 784 | if ( nlsr->detailed_logging ) |
| 785 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n"); |
| 786 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 787 | nlsr->is_build_adj_lsa_sheduled=1; |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | if ( nlsr->debugging ) |
| 792 | printf("Build and Install Adj LSA already scheduled\n"); |
| 793 | if ( nlsr->detailed_logging ) |
| 794 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n"); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | free(nbr); |
| 799 | |
| 800 | |
| 801 | } |
| 802 | |
| 803 | |
| 804 | void |
| 805 | process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 806 | { |
| 807 | if ( nlsr->debugging ) |
| 808 | printf("process_incoming_content_lsdb called \n"); |
| 809 | if ( nlsr->detailed_logging ) |
| 810 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_lsdb called \n"); |
| 811 | |
| 812 | const unsigned char *ptr; |
| 813 | size_t length; |
| 814 | 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); |
| 815 | //printf("Content data: %s\n",ptr); |
| 816 | |
| 817 | if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) ) |
| 818 | { |
| 819 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 820 | get_nbr(nbr,selfp,info); |
| 821 | |
| 822 | char *nl; |
| 823 | int num_element; |
| 824 | int i; |
| 825 | char *rem; |
| 826 | const char *sep="|"; |
| 827 | char *orig_router; |
| 828 | char *lst; |
| 829 | int ls_type; |
| 830 | char *lsid; |
| 831 | long int ls_id; |
| 832 | char *orig_time; |
| 833 | |
| 834 | nl=strtok_r((char *)ptr,sep,&rem); |
| 835 | num_element=atoi(nl); |
| 836 | |
| 837 | for(i = 0 ; i < num_element ; i++) |
| 838 | { |
| 839 | orig_router=strtok_r(NULL,sep,&rem); |
| 840 | lst=strtok_r(NULL,sep,&rem); |
| 841 | ls_type=atoi(lst); |
| 842 | |
| 843 | if ( nlsr->debugging ) |
| 844 | printf("Orig Router: %s ls Type: %d",orig_router,ls_type); |
| 845 | if ( nlsr->detailed_logging ) |
| 846 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig Router: %s ls Type: %d",orig_router,ls_type); |
| 847 | |
| 848 | |
| 849 | if(ls_type == LS_TYPE_NAME) |
| 850 | { |
| 851 | lsid=strtok_r(NULL,sep,&rem); |
| 852 | ls_id=atoi(lsid); |
| 853 | orig_time=strtok_r(NULL,sep,&rem); |
| 854 | |
| 855 | if ( nlsr->debugging ) |
| 856 | printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time); |
| 857 | if ( nlsr->detailed_logging ) |
| 858 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld Orig Time: %s\n",ls_id ,orig_time); |
| 859 | |
| 860 | |
| 861 | int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time); |
| 862 | if ( is_new_name_lsa == 1 ) |
| 863 | { |
| 864 | if ( nlsr->debugging ) |
| 865 | printf("New NAME LSA.....\n"); |
| 866 | if ( nlsr->detailed_logging ) |
| 867 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New NAME LSA.....\n"); |
| 868 | |
| 869 | send_interest_for_name_lsa(nbr,orig_router,lst,lsid); |
| 870 | } |
| 871 | else |
| 872 | { |
| 873 | if ( nlsr->debugging ) |
| 874 | printf("Name LSA already exists in LSDB\n"); |
| 875 | if ( nlsr->detailed_logging ) |
| 876 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA already exists in LSDB\n"); |
| 877 | |
| 878 | } |
| 879 | } |
| 880 | else |
| 881 | { |
| 882 | orig_time=strtok_r(NULL,sep,&rem); |
| 883 | |
| 884 | if ( nlsr->debugging ) |
| 885 | printf(" Orig Time: %s\n",orig_time); |
| 886 | if ( nlsr->detailed_logging ) |
| 887 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Orig Time: %s\n",orig_time); |
| 888 | |
| 889 | |
| 890 | int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time); |
| 891 | if ( is_new_adj_lsa == 1 ) |
| 892 | { |
| 893 | if ( nlsr->debugging ) |
| 894 | printf("New Adj LSA.....\n"); |
| 895 | if ( nlsr->detailed_logging ) |
| 896 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Adj LSA.....\n"); |
| 897 | send_interest_for_adj_lsa(nbr,orig_router,lst); |
| 898 | } |
| 899 | else |
| 900 | { |
| 901 | if ( nlsr->debugging ) |
| 902 | printf("Adj LSA already exists in LSDB\n"); |
| 903 | if ( nlsr->detailed_logging ) |
| 904 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA already exists in LSDB\n"); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | } |
| 909 | |
| 910 | char *lsdb_version=(char *)malloc(20); |
| 911 | memset(lsdb_version,0,20); |
| 912 | get_lsdb_version(lsdb_version,selfp,info); |
| 913 | |
| 914 | if ( nlsr->debugging ) |
| 915 | printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
| 916 | if ( nlsr->detailed_logging ) |
| 917 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
| 918 | |
| 919 | update_adjacent_lsdb_version_to_adl(nbr,lsdb_version); |
| 920 | |
| 921 | if ( nlsr->debugging ) |
| 922 | printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
| 923 | if ( nlsr->detailed_logging ) |
| 924 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
| 925 | |
| 926 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
| 927 | |
| 928 | free(lsdb_version); |
| 929 | free(nbr); |
| 930 | } |
| 931 | else if (strcmp("WAIT",(char *)ptr) == 0) |
| 932 | { |
| 933 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 934 | get_nbr(nbr,selfp,info); |
| 935 | long int interval=get_lsdb_synch_interval(nbr->name); |
| 936 | adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2); |
| 937 | |
| 938 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
| 939 | free(nbr); |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | |
| 944 | if ( nlsr->debugging ) |
| 945 | printf("NACK Content Received\n"); |
| 946 | if ( nlsr->detailed_logging ) |
| 947 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"NACK Content Received\n"); |
| 948 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 949 | get_nbr(nbr,selfp,info); |
| 950 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
| 951 | free(nbr); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | |
| 956 | void |
| 957 | process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 958 | { |
| 959 | |
| 960 | |
| 961 | if ( nlsr->debugging ) |
| 962 | printf("process_incoming_content_lsa called \n"); |
| 963 | if ( nlsr->detailed_logging ) |
| 964 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_lsa called \n"); |
| 965 | |
| 966 | char *sep="|"; |
| 967 | char *rem; |
| 968 | char *orig_router; |
| 969 | char *orl; |
| 970 | int orig_router_length; |
| 971 | char *lst; |
| 972 | int ls_type; |
| 973 | char *lsid; |
| 974 | long int ls_id; |
| 975 | char *isvld; |
| 976 | int isValid; |
| 977 | char *num_link; |
| 978 | int no_link; |
| 979 | char *np; |
| 980 | char *np_length; |
| 981 | int name_length; |
| 982 | char *data; |
| 983 | char *orig_time; |
| 984 | |
| 985 | const unsigned char *ptr; |
| 986 | size_t length; |
| 987 | 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); |
| 988 | //printf("Content data Received: %s\n",ptr); |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | if ( nlsr->debugging ) |
| 994 | printf("LSA Data \n"); |
| 995 | if ( nlsr->detailed_logging ) |
| 996 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Data\n"); |
| 997 | |
| 998 | if( strlen((char *) ptr ) > 0 ) |
| 999 | { |
| 1000 | |
| 1001 | orig_router=strtok_r((char *)ptr,sep,&rem); |
| 1002 | orl=strtok_r(NULL,sep,&rem); |
| 1003 | orig_router_length=atoi(orl); |
| 1004 | |
| 1005 | if ( nlsr->debugging ) |
| 1006 | { |
| 1007 | printf(" Orig Router Name : %s\n",orig_router); |
| 1008 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 1009 | } |
| 1010 | |
| 1011 | lst=strtok_r(NULL,sep,&rem); |
| 1012 | ls_type=atoi(lst); |
| 1013 | |
| 1014 | if ( nlsr->debugging ) |
| 1015 | printf(" LS Type : %d\n",ls_type); |
| 1016 | |
| 1017 | if ( ls_type == LS_TYPE_NAME ) |
| 1018 | { |
| 1019 | lsid=strtok_r(NULL,sep,&rem); |
| 1020 | ls_id=atoi(lsid); |
| 1021 | orig_time=strtok_r(NULL,sep,&rem); |
| 1022 | isvld=strtok_r(NULL,sep,&rem); |
| 1023 | isValid=atoi(isvld); |
| 1024 | np=strtok_r(NULL,sep,&rem); |
| 1025 | np_length=strtok_r(NULL,sep,&rem); |
| 1026 | name_length=atoi(np_length); |
| 1027 | if ( nlsr->debugging ) |
| 1028 | { |
| 1029 | printf(" LS ID : %ld\n",ls_id); |
| 1030 | printf(" isValid : %d\n",isValid); |
| 1031 | printf(" Name Prefix : %s\n",np); |
| 1032 | printf(" Orig Time : %s\n",orig_time); |
| 1033 | printf(" Name Prefix length: %d\n",name_length); |
| 1034 | } |
| 1035 | |
| 1036 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np); |
| 1037 | |
| 1038 | } |
| 1039 | else if ( ls_type == LS_TYPE_ADJ ) |
| 1040 | { |
| 1041 | orig_time=strtok_r(NULL,sep,&rem); |
| 1042 | num_link=strtok_r(NULL,sep,&rem); |
| 1043 | no_link=atoi(num_link); |
| 1044 | data=rem; |
| 1045 | |
| 1046 | if ( nlsr->debugging ) |
| 1047 | { |
| 1048 | printf(" No Link : %d\n",no_link); |
| 1049 | printf(" Data : %s\n",data); |
| 1050 | } |
| 1051 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | void |
| 1058 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1059 | { |
| 1060 | |
| 1061 | |
| 1062 | if ( nlsr->debugging ) |
| 1063 | printf("process_incoming_timed_out_interest called \n"); |
| 1064 | if ( nlsr->detailed_logging ) |
| 1065 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n"); |
| 1066 | |
| 1067 | int res,i; |
| 1068 | int nlsr_position=0; |
| 1069 | int name_comps=(int)info->interest_comps->n; |
| 1070 | |
| 1071 | for(i=0;i<name_comps;i++) |
| 1072 | { |
| 1073 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 1074 | if( res == 0) |
| 1075 | { |
| 1076 | nlsr_position=i; |
| 1077 | break; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 1082 | { |
| 1083 | process_incoming_timed_out_interest_info(selfp,info); |
| 1084 | } |
| 1085 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0) |
| 1086 | { |
| 1087 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 1088 | } |
| 1089 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsa") == 0) |
| 1090 | { |
| 1091 | process_incoming_timed_out_interest_lsa(selfp,info); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | void |
| 1096 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1097 | { |
| 1098 | |
| 1099 | if ( nlsr->debugging ) |
| 1100 | printf("process_incoming_timed_out_interest_info called \n"); |
| 1101 | if ( nlsr->detailed_logging ) |
| 1102 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n"); |
| 1103 | |
| 1104 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1105 | get_nbr(nbr,selfp,info); |
| 1106 | |
| 1107 | if ( nlsr->debugging ) |
| 1108 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 1109 | if ( nlsr->detailed_logging ) |
| 1110 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | update_adjacent_timed_out_to_adl(nbr,1); |
| 1115 | print_adjacent_from_adl(); |
| 1116 | int timed_out=get_timed_out_number(nbr); |
| 1117 | |
| 1118 | if ( nlsr->debugging ) |
| 1119 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 1120 | if ( nlsr->detailed_logging ) |
| 1121 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 1122 | |
| 1123 | |
| 1124 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 1125 | { |
| 1126 | send_info_interest_to_neighbor(nbr); |
| 1127 | } |
| 1128 | else |
| 1129 | { |
| 1130 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 1131 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 1132 | { |
| 1133 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 1134 | nlsr->is_build_adj_lsa_sheduled=1; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | free(nbr); |
| 1139 | |
| 1140 | |
| 1141 | } |
| 1142 | |
| 1143 | void |
| 1144 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1145 | { |
| 1146 | if ( nlsr->debugging ) |
| 1147 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
| 1148 | if ( nlsr->detailed_logging ) |
| 1149 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_lsdb called \n"); |
| 1150 | |
| 1151 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1152 | get_nbr(nbr,selfp,info); |
| 1153 | |
| 1154 | if ( nlsr->debugging ) |
| 1155 | printf("LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 1156 | if ( nlsr->detailed_logging ) |
| 1157 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 1158 | |
| 1159 | |
| 1160 | update_lsdb_interest_timed_out_to_adl(nbr,1); |
| 1161 | |
| 1162 | int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr); |
| 1163 | |
| 1164 | if ( nlsr->debugging ) |
| 1165 | printf("Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry); |
| 1166 | if ( nlsr->detailed_logging ) |
| 1167 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry); |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | if( interst_timed_out_num >= nlsr->interest_retry ) |
| 1172 | { |
| 1173 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 1174 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 1175 | { |
| 1176 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 1177 | nlsr->is_build_adj_lsa_sheduled=1; |
| 1178 | } |
| 1179 | } |
| 1180 | free(nbr->name); |
| 1181 | free(nbr); |
| 1182 | } |
| 1183 | |
| 1184 | void |
| 1185 | process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1186 | { |
| 1187 | if ( nlsr->debugging ) |
| 1188 | printf("process_incoming_timed_out_interest_lsa called \n"); |
| 1189 | if ( nlsr->detailed_logging ) |
| 1190 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_lsa called \n"); |
| 1191 | |
| 1192 | } |
| 1193 | |
| 1194 | int |
| 1195 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1196 | { |
| 1197 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1198 | { |
| 1199 | return -1; |
| 1200 | } |
| 1201 | |
| 1202 | nlsr_lock(); |
| 1203 | |
| 1204 | if ( nlsr->debugging ) |
| 1205 | printf("send_info_interest called \n"); |
| 1206 | if ( nlsr->detailed_logging ) |
| 1207 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 1208 | |
| 1209 | if ( nlsr->debugging ) |
| 1210 | printf("\n"); |
| 1211 | if ( nlsr->detailed_logging ) |
| 1212 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 1213 | |
| 1214 | int adl_element,i; |
| 1215 | struct ndn_neighbor *nbr; |
| 1216 | |
| 1217 | struct hashtb_enumerator ee; |
| 1218 | struct hashtb_enumerator *e = ⅇ |
| 1219 | |
| 1220 | hashtb_start(nlsr->adl, e); |
| 1221 | adl_element=hashtb_n(nlsr->adl); |
| 1222 | |
| 1223 | for(i=0;i<adl_element;i++) |
| 1224 | { |
| 1225 | nbr=e->data; |
| 1226 | send_info_interest_to_neighbor(nbr->neighbor); |
| 1227 | hashtb_next(e); |
| 1228 | } |
| 1229 | hashtb_end(e); |
| 1230 | |
| 1231 | nlsr_unlock(); |
| 1232 | |
| 1233 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
| 1238 | void |
| 1239 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 1240 | { |
| 1241 | |
| 1242 | if ( nlsr->debugging ) |
| 1243 | printf("send_info_interest_to_neighbor called \n"); |
| 1244 | if ( nlsr->detailed_logging ) |
| 1245 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n"); |
| 1246 | |
| 1247 | |
| 1248 | int res; |
| 1249 | char info_str[5]; |
| 1250 | char nlsr_str[5]; |
| 1251 | |
| 1252 | memset(&nlsr_str,0,5); |
| 1253 | sprintf(nlsr_str,"nlsr"); |
| 1254 | memset(&info_str,0,5); |
| 1255 | sprintf(info_str,"info"); |
| 1256 | |
| 1257 | |
| 1258 | struct ccn_charbuf *name; |
| 1259 | name=ccn_charbuf_create(); |
| 1260 | |
| 1261 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 1262 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 1263 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 1264 | memcpy(int_name+strlen(int_name),"/",1); |
| 1265 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1266 | memcpy(int_name+strlen(int_name),"/",1); |
| 1267 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
| 1268 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
| 1269 | |
| 1270 | |
| 1271 | res=ccn_name_from_uri(name,int_name); |
| 1272 | if ( res >=0 ) |
| 1273 | { |
| 1274 | /* adding InterestLifeTime and InterestScope filter */ |
| 1275 | |
| 1276 | struct ccn_charbuf *templ; |
| 1277 | templ = ccn_charbuf_create(); |
| 1278 | |
| 1279 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1280 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1281 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1282 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1283 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1284 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1285 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1286 | |
| 1287 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1288 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1289 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 1290 | |
| 1291 | if ( nlsr->debugging ) |
| 1292 | printf("Sending info interest on name prefix : %s \n",int_name); |
| 1293 | if ( nlsr->detailed_logging ) |
| 1294 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s \n",int_name); |
| 1295 | |
| 1296 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1297 | |
| 1298 | if ( res >= 0 ) |
| 1299 | { |
| 1300 | if ( nlsr->debugging ) |
| 1301 | printf("Info interest sending Successfull .... \n"); |
| 1302 | if ( nlsr->detailed_logging ) |
| 1303 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n"); |
| 1304 | } |
| 1305 | ccn_charbuf_destroy(&templ); |
| 1306 | } |
| 1307 | ccn_charbuf_destroy(&name); |
| 1308 | free(int_name); |
| 1309 | |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | int |
| 1314 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1315 | { |
| 1316 | if ( nlsr->debugging ) |
| 1317 | printf("send_lsdb_interest called \n"); |
| 1318 | if ( nlsr->detailed_logging ) |
| 1319 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest called \n"); |
| 1320 | |
| 1321 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1322 | { |
| 1323 | return -1; |
| 1324 | } |
| 1325 | |
| 1326 | nlsr_lock(); |
| 1327 | |
| 1328 | int i, adl_element; |
| 1329 | struct ndn_neighbor *nbr; |
| 1330 | |
| 1331 | struct hashtb_enumerator ee; |
| 1332 | struct hashtb_enumerator *e = ⅇ |
| 1333 | |
| 1334 | hashtb_start(nlsr->adl, e); |
| 1335 | adl_element=hashtb_n(nlsr->adl); |
| 1336 | |
| 1337 | for(i=0;i<adl_element;i++) |
| 1338 | { |
| 1339 | nbr=e->data; |
| 1340 | |
| 1341 | if(nbr->status == NBR_ACTIVE) |
| 1342 | { |
| 1343 | if(nbr->is_lsdb_send_interest_scheduled == 0) |
| 1344 | { |
| 1345 | long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name); |
| 1346 | if ( nlsr->debugging ) |
| 1347 | printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1348 | if ( nlsr->detailed_logging ) |
| 1349 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1350 | |
| 1351 | |
| 1352 | if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) ) |
| 1353 | { |
| 1354 | nbr->is_lsdb_send_interest_scheduled=1; |
| 1355 | send_lsdb_interest_to_nbr(nbr->neighbor); |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | hashtb_next(e); |
| 1360 | } |
| 1361 | |
| 1362 | hashtb_end(e); |
| 1363 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0); |
| 1364 | |
| 1365 | nlsr_unlock(); |
| 1366 | |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | void |
| 1371 | send_lsdb_interest_to_nbr(struct name_prefix *nbr) |
| 1372 | { |
| 1373 | if ( nlsr->debugging ) |
| 1374 | printf("send_lsdb_interest_to_nbr called \n"); |
| 1375 | if ( nlsr->detailed_logging ) |
| 1376 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest_to_nbr called \n"); |
| 1377 | |
| 1378 | char *last_lsdb_version=get_nbr_lsdb_version(nbr->name); |
| 1379 | |
| 1380 | if(last_lsdb_version !=NULL) |
| 1381 | { |
| 1382 | |
| 1383 | |
| 1384 | if ( nlsr->debugging ) |
| 1385 | printf("Last LSDB Version: %s \n",last_lsdb_version); |
| 1386 | if ( nlsr->detailed_logging ) |
| 1387 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Last LSDB Version: %s \n",last_lsdb_version); |
| 1388 | |
| 1389 | struct ccn_charbuf *name; |
| 1390 | int res; |
| 1391 | char lsdb_str[5]; |
| 1392 | char nlsr_str[5]; |
| 1393 | |
| 1394 | memset(&nlsr_str,0,5); |
| 1395 | sprintf(nlsr_str,"nlsr"); |
| 1396 | memset(&lsdb_str,0,5); |
| 1397 | sprintf(lsdb_str,"lsdb"); |
| 1398 | //make and send interest with exclusion filter as last_lsdb_version |
| 1399 | if ( nlsr->debugging ) |
| 1400 | printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1401 | if ( nlsr->detailed_logging ) |
| 1402 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1403 | |
| 1404 | name=ccn_charbuf_create(); |
| 1405 | res=ccn_name_from_uri(name,nbr->name); |
| 1406 | |
| 1407 | if( res >= 0) |
| 1408 | { |
| 1409 | ccn_name_append_str(name,nlsr_str); |
| 1410 | ccn_name_append_str(name,lsdb_str); |
| 1411 | /* adding Exclusion filter */ |
| 1412 | |
| 1413 | struct ccn_charbuf *templ; |
| 1414 | templ = ccn_charbuf_create(); |
| 1415 | |
| 1416 | struct ccn_charbuf *c; |
| 1417 | c = ccn_charbuf_create(); |
| 1418 | |
| 1419 | |
| 1420 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1421 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1422 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1423 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 1424 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 1425 | ccn_charbuf_reset(c); |
| 1426 | ccn_charbuf_putf(c, "%s", last_lsdb_version); |
| 1427 | |
| 1428 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 1429 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
| 1430 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1431 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1432 | ccn_charbuf_append(templ, "2", 1); |
| 1433 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1434 | |
| 1435 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1436 | |
| 1437 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1438 | |
| 1439 | |
| 1440 | /* Adding Exclusion filter done */ |
| 1441 | |
| 1442 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1443 | |
| 1444 | if ( res >= 0 ) |
| 1445 | { |
| 1446 | if ( nlsr->debugging ) |
| 1447 | printf("Interest sending Successfull .... \n"); |
| 1448 | if ( nlsr->detailed_logging ) |
| 1449 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest sending Successfull .... \n"); |
| 1450 | update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec()); |
| 1451 | |
| 1452 | } |
| 1453 | ccn_charbuf_destroy(&c); |
| 1454 | ccn_charbuf_destroy(&templ); |
| 1455 | } |
| 1456 | ccn_charbuf_destroy(&name); |
| 1457 | } |
| 1458 | set_is_lsdb_send_interest_scheduled_to_zero(nbr->name); |
| 1459 | } |
| 1460 | |
| 1461 | void |
| 1462 | send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id) |
| 1463 | { |
| 1464 | if ( nlsr->debugging ) |
| 1465 | printf("send_interest_for_name_lsa called\n"); |
| 1466 | if ( nlsr->detailed_logging ) |
| 1467 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_interest_for_name_lsa called\n"); |
| 1468 | |
| 1469 | int res; |
| 1470 | char lsa_str[5]; |
| 1471 | char nlsr_str[5]; |
| 1472 | |
| 1473 | memset(&nlsr_str,0,5); |
| 1474 | sprintf(nlsr_str,"nlsr"); |
| 1475 | memset(&lsa_str,0,5); |
| 1476 | sprintf(lsa_str,"lsa"); |
| 1477 | |
| 1478 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3); |
| 1479 | memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3); |
| 1480 | |
| 1481 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1482 | memcpy(int_name+strlen(int_name),"/",1); |
| 1483 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1484 | memcpy(int_name+strlen(int_name),"/",1); |
| 1485 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
| 1486 | memcpy(int_name+strlen(int_name),"/",1); |
| 1487 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
| 1488 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
| 1489 | |
| 1490 | |
| 1491 | struct ccn_charbuf *name; |
| 1492 | name=ccn_charbuf_create(); |
| 1493 | |
| 1494 | |
| 1495 | res=ccn_name_from_uri(name,int_name); |
| 1496 | ccn_name_append_str(name,ls_type); |
| 1497 | ccn_name_append_str(name,ls_id); |
| 1498 | |
| 1499 | |
| 1500 | /* adding InterestLifeTime and InterestScope filter */ |
| 1501 | |
| 1502 | struct ccn_charbuf *templ; |
| 1503 | templ = ccn_charbuf_create(); |
| 1504 | |
| 1505 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1506 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1507 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1508 | //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 1509 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1510 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1511 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1512 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1513 | |
| 1514 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1515 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1516 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 1517 | |
| 1518 | if ( nlsr->debugging ) |
| 1519 | printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id); |
| 1520 | if ( nlsr->detailed_logging ) |
| 1521 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id); |
| 1522 | |
| 1523 | |
| 1524 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1525 | |
| 1526 | if ( res >= 0 ) |
| 1527 | { |
| 1528 | if ( nlsr->debugging ) |
| 1529 | printf("NAME LSA interest sending Successfull .... \n"); |
| 1530 | if ( nlsr->detailed_logging ) |
| 1531 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"NAME LSA interest sending Successfull .... \n"); |
| 1532 | |
| 1533 | } |
| 1534 | ccn_charbuf_destroy(&templ); |
| 1535 | ccn_charbuf_destroy(&name); |
| 1536 | free(int_name); |
| 1537 | |
| 1538 | |
| 1539 | } |
| 1540 | |
| 1541 | void |
| 1542 | send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type) |
| 1543 | { |
| 1544 | if ( nlsr->debugging ) |
| 1545 | printf("send_interest_for_name_lsa called\n"); |
| 1546 | if ( nlsr->detailed_logging ) |
| 1547 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_interest_for_name_lsa called\n"); |
| 1548 | |
| 1549 | int res; |
| 1550 | char lsa_str[5]; |
| 1551 | char nlsr_str[5]; |
| 1552 | |
| 1553 | memset(&nlsr_str,0,5); |
| 1554 | sprintf(nlsr_str,"nlsr"); |
| 1555 | memset(&lsa_str,0,5); |
| 1556 | sprintf(lsa_str,"lsa"); |
| 1557 | |
| 1558 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1); |
| 1559 | memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1); |
| 1560 | |
| 1561 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1562 | memcpy(int_name+strlen(int_name),"/",1); |
| 1563 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1564 | memcpy(int_name+strlen(int_name),"/",1); |
| 1565 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
| 1566 | memcpy(int_name+strlen(int_name),"/",1); |
| 1567 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
| 1568 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
| 1569 | memcpy(int_name+strlen(int_name),"/",1); |
| 1570 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
| 1571 | |
| 1572 | struct ccn_charbuf *name; |
| 1573 | name=ccn_charbuf_create(); |
| 1574 | |
| 1575 | |
| 1576 | ccn_name_from_uri(name,int_name); |
| 1577 | |
| 1578 | /* adding InterestLifeTime and InterestScope filter */ |
| 1579 | |
| 1580 | struct ccn_charbuf *templ; |
| 1581 | templ = ccn_charbuf_create(); |
| 1582 | |
| 1583 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1584 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1585 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1586 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1587 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1588 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1589 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1590 | |
| 1591 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1592 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1593 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 1594 | |
| 1595 | if ( nlsr->debugging ) |
| 1596 | printf("Sending ADJ LSA interest on name prefix : %s\n",int_name); |
| 1597 | if ( nlsr->detailed_logging ) |
| 1598 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending ADJ LSA interest on name prefix : %s\n",int_name); |
| 1599 | |
| 1600 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1601 | |
| 1602 | if ( res >= 0 ) |
| 1603 | { |
| 1604 | if ( nlsr->debugging ) |
| 1605 | printf("ADJ LSA interest sending Successfull .... \n"); |
| 1606 | if ( nlsr->detailed_logging ) |
| 1607 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"ADJ LSA interest sending Successfull .... \n"); |
| 1608 | } |
| 1609 | |
| 1610 | ccn_charbuf_destroy(&templ); |
| 1611 | ccn_charbuf_destroy(&name); |
| 1612 | free(int_name); |
| 1613 | } |