akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 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" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 22 | #include "nlsr_npl.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 23 | #include "nlsr_adl.h" |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 24 | #include "nlsr_lsdb.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 25 | #include "utility.h" |
| 26 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 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 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 43 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 44 | |
| 45 | void |
| 46 | get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 47 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 48 | if ( nlsr->debugging ) |
| 49 | printf("get_nbr called\n"); |
| 50 | if ( nlsr->detailed_logging ) |
| 51 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 52 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 89 | |
| 90 | nbr->name=(char *)malloc(strlen(neighbor)+1); |
| 91 | memcpy(nbr->name,neighbor,strlen(neighbor)+1); |
| 92 | nbr->length=strlen(neighbor)+1; |
| 93 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 99 | |
| 100 | |
| 101 | } |
| 102 | |
| 103 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 104 | get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info, int offset) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 105 | { |
| 106 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 132 | for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 143 | for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 162 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 163 | |
| 164 | } |
| 165 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 209 | enum ccn_upcall_res |
| 210 | incoming_interest(struct ccn_closure *selfp, |
| 211 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 212 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 213 | |
| 214 | nlsr_lock(); |
| 215 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 216 | switch (kind) { |
| 217 | case CCN_UPCALL_FINAL: |
| 218 | break; |
| 219 | case CCN_UPCALL_INTEREST: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 220 | // printing the name prefix for which it received interest |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 235 | ccn_charbuf_destroy(&c); |
| 236 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 237 | process_incoming_interest(selfp, info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 238 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 239 | break; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 240 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 241 | default: |
| 242 | break; |
| 243 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 244 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 245 | nlsr_unlock(); |
| 246 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 247 | return CCN_UPCALL_RESULT_OK; |
| 248 | } |
| 249 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 250 | /* Function for processing incoming interest and reply with content/NACK content */ |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 251 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 252 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 253 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 254 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 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; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 265 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 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 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 271 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 277 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 278 | //printf("Det= %s \n",comp_ptr1); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 279 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 280 | if(!strcmp((char *)comp_ptr1,"info")) |
| 281 | { |
| 282 | process_incoming_interest_info(selfp,info); |
| 283 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void |
| 295 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 296 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 308 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 313 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 335 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 336 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 337 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 338 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 346 | |
| 347 | |
| 348 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 349 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 357 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 358 | |
| 359 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 360 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 361 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 362 | send_info_interest_to_neighbor(nbr); |
| 363 | } |
| 364 | |
| 365 | free(nbr); |
| 366 | free(raw_data); |
| 367 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 368 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 369 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 370 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 371 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 372 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | |
| 376 | void |
| 377 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 378 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 386 | |
| 387 | int l,res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 388 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 389 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 390 | struct ccn_buf_decoder decoder; |
| 391 | struct ccn_buf_decoder *d; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 392 | const unsigned char *comp; |
| 393 | int dbcmp=0; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 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); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 411 | ccn_buf_check_close(d); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 412 | |
| 413 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 414 | } |
| 415 | ccn_buf_check_close(d); |
| 416 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 417 | if (comp != NULL) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 418 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 429 | dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 430 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 431 | /* Now comp points to the start of your potential number, and size is its length */ |
| 432 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 433 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 434 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 439 | dbcmp=1; |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 440 | |
| 441 | } |
| 442 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 443 | struct ccn_charbuf *data=ccn_charbuf_create(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 444 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 445 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 446 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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]); |
akmhoque | 887fc0c | 2012-08-27 15:06:06 -0500 | [diff] [blame] | 448 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 452 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 453 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 454 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 455 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 456 | if(dbcmp>0) |
| 457 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 468 | ccn_name_append_str(name,nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 469 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 470 | struct ccn_charbuf *lsdb_data=ccn_charbuf_create(); |
| 471 | get_lsdb_summary(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 472 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 473 | char *raw_data=ccn_charbuf_as_string(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 474 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 475 | //printf("Content Data to be sent: %s \n",raw_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 476 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 477 | if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 485 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 486 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 493 | |
| 494 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 495 | |
| 496 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 503 | |
| 504 | ccn_charbuf_destroy(&lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 505 | } |
| 506 | else |
| 507 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 519 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 520 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 521 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 528 | |
| 529 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 530 | |
| 531 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 538 | |
| 539 | |
| 540 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 541 | |
| 542 | ccn_charbuf_destroy(&data); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 543 | ccn_charbuf_destroy(&name); |
| 544 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 545 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 546 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 547 | } |
| 548 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 549 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 550 | void |
| 551 | process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 552 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 557 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 558 | int res; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 559 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 560 | struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 561 | get_lsa_identifier(lsaId,selfp,info,0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 562 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 563 | //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 564 | int ls_type=get_ls_type(selfp, info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 565 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 566 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 567 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 568 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 569 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 574 | get_name_lsa_data(lsa_data,lsaId); |
| 575 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 576 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 577 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 582 | get_adj_lsa_data(lsa_data,lsaId); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 583 | } |
| 584 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 589 | //printf("Content Data to be sent: %s\n",raw_data); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 590 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 594 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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]); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 596 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 602 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 603 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 604 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 605 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 612 | |
| 613 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 614 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 615 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 622 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 623 | |
| 624 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 632 | } |
| 633 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 634 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 635 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 636 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 637 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 638 | { |
| 639 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 640 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 641 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 642 | switch(kind) { |
| 643 | case CCN_UPCALL_FINAL: |
| 644 | break; |
| 645 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 659 | ccn_charbuf_destroy(&c); |
| 660 | |
| 661 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 662 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 663 | break; |
| 664 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 681 | ccn_charbuf_destroy(&ito); |
| 682 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 683 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 684 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 685 | break; |
| 686 | default: |
| 687 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 692 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 693 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 694 | |
| 695 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 696 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 697 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 698 | } |
| 699 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 700 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 701 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 702 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 703 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 728 | //printf("Det= %s \n",comp_ptr1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 729 | |
| 730 | if(!strcmp((char *)comp_ptr1,"info")) |
| 731 | { |
| 732 | process_incoming_content_info(selfp,info); |
| 733 | } |
| 734 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 735 | { |
| 736 | process_incoming_content_lsdb(selfp,info); |
| 737 | } |
| 738 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 739 | { |
| 740 | process_incoming_content_lsa(selfp,info); |
| 741 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 742 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 743 | } |
| 744 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 745 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 746 | void |
| 747 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 748 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 754 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 755 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 756 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 757 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 762 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 767 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 768 | |
| 769 | long int interval=atoi((char *)ptr); |
| 770 | |
| 771 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 772 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 778 | |
| 779 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 780 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 781 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 795 | } |
| 796 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 797 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 798 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 799 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 800 | |
| 801 | } |
| 802 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 803 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 804 | void |
| 805 | process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 806 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 811 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 815 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 832 | char *orig_time; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 848 | |
| 849 | if(ls_type == LS_TYPE_NAME) |
| 850 | { |
| 851 | lsid=strtok_r(NULL,sep,&rem); |
| 852 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 853 | orig_time=strtok_r(NULL,sep,&rem); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 869 | send_interest_for_name_lsa(nbr,orig_router,lst,lsid); |
| 870 | } |
| 871 | else |
| 872 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 878 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 879 | } |
| 880 | else |
| 881 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 882 | orig_time=strtok_r(NULL,sep,&rem); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 890 | int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time); |
| 891 | if ( is_new_adj_lsa == 1 ) |
| 892 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 893 | if ( nlsr->debugging ) |
| 894 | printf("New Adj LSA.....\n"); |
| 895 | if ( nlsr->detailed_logging ) |
| 896 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Adj LSA.....\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 897 | send_interest_for_adj_lsa(nbr,orig_router,lst); |
| 898 | } |
| 899 | else |
| 900 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 905 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 906 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 907 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 908 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 909 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 910 | char *lsdb_version=(char *)malloc(20); |
| 911 | memset(lsdb_version,0,20); |
| 912 | get_lsdb_version(lsdb_version,selfp,info); |
| 913 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 919 | update_adjacent_lsdb_version_to_adl(nbr,lsdb_version); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 925 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 926 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 927 | |
| 928 | free(lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 937 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 938 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 939 | free(nbr); |
| 940 | } |
| 941 | else |
| 942 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 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); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 951 | free(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 952 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 953 | } |
| 954 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 955 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 956 | void |
| 957 | process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 958 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 988 | //printf("Content data Received: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 989 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 990 | |
| 991 | |
| 992 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 993 | if ( nlsr->debugging ) |
| 994 | printf("LSA Data \n"); |
| 995 | if ( nlsr->detailed_logging ) |
| 996 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Data\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1010 | |
| 1011 | lst=strtok_r(NULL,sep,&rem); |
| 1012 | ls_type=atoi(lst); |
| 1013 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1014 | if ( nlsr->debugging ) |
| 1015 | printf(" LS Type : %d\n",ls_type); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1016 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1017 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1018 | { |
| 1019 | lsid=strtok_r(NULL,sep,&rem); |
| 1020 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1021 | orig_time=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1035 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1036 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np); |
| 1037 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1038 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1039 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1046 | if ( nlsr->debugging ) |
| 1047 | { |
| 1048 | printf(" No Link : %d\n",no_link); |
| 1049 | printf(" Data : %s\n",data); |
| 1050 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1051 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data); |
| 1052 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1053 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1056 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1057 | void |
| 1058 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1059 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | void |
| 1096 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1097 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1103 | |
| 1104 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1105 | get_nbr(nbr,selfp,info); |
| 1106 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1112 | |
| 1113 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1114 | update_adjacent_timed_out_to_adl(nbr,1); |
| 1115 | print_adjacent_from_adl(); |
| 1116 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1117 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1123 | |
| 1124 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 1125 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1126 | send_info_interest_to_neighbor(nbr); |
| 1127 | } |
| 1128 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1129 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1139 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1140 | |
| 1141 | } |
| 1142 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1143 | void |
| 1144 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1145 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1150 | |
| 1151 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1152 | get_nbr(nbr,selfp,info); |
| 1153 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1159 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 1160 | update_lsdb_interest_timed_out_to_adl(nbr,1); |
| 1161 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1162 | int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr); |
| 1163 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 1170 | |
| 1171 | if( interst_timed_out_num >= nlsr->interest_retry ) |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1172 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 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); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | void |
| 1185 | process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 1186 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1191 | |
| 1192 | } |
| 1193 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1194 | int |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1195 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1196 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1197 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1198 | { |
| 1199 | return -1; |
| 1200 | } |
| 1201 | |
| 1202 | nlsr_lock(); |
| 1203 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1213 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1214 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1229 | hashtb_end(e); |
| 1230 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1231 | nlsr_unlock(); |
| 1232 | |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 1233 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 1234 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1235 | return 0; |
| 1236 | } |
| 1237 | |
| 1238 | void |
| 1239 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 1240 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1247 | |
| 1248 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1249 | char info_str[5]; |
| 1250 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1251 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1252 | memset(&nlsr_str,0,5); |
| 1253 | sprintf(nlsr_str,"nlsr"); |
| 1254 | memset(&info_str,0,5); |
| 1255 | sprintf(info_str,"info"); |
| 1256 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1257 | |
| 1258 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1259 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1260 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1268 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1269 | |
| 1270 | |
| 1271 | res=ccn_name_from_uri(name,int_name); |
| 1272 | if ( res >=0 ) |
| 1273 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1286 | |
| 1287 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1288 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1289 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 1290 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1295 | |
| 1296 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1297 | |
| 1298 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1320 | |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1321 | if(flags == CCN_SCHEDULE_CANCEL) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1322 | { |
| 1323 | return -1; |
| 1324 | } |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1325 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1326 | nlsr_lock(); |
| 1327 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1351 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1352 | if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1365 | nlsr_unlock(); |
| 1366 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | void |
| 1371 | send_lsdb_interest_to_nbr(struct name_prefix *nbr) |
| 1372 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1377 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1378 | char *last_lsdb_version=get_nbr_lsdb_version(nbr->name); |
| 1379 | |
| 1380 | if(last_lsdb_version !=NULL) |
| 1381 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1382 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1383 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1388 | |
| 1389 | struct ccn_charbuf *name; |
| 1390 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1391 | char lsdb_str[5]; |
| 1392 | char nlsr_str[5]; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1393 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1411 | /* adding Exclusion filter */ |
| 1412 | |
| 1413 | struct ccn_charbuf *templ; |
| 1414 | templ = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1415 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1416 | struct ccn_charbuf *c; |
| 1417 | c = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1418 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1427 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1434 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1435 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1436 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1437 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1438 | |
| 1439 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1440 | /* Adding Exclusion filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1441 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1442 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1443 | |
| 1444 | if ( res >= 0 ) |
| 1445 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1446 | if ( nlsr->debugging ) |
| 1447 | printf("Interest sending Successfull .... \n"); |
| 1448 | if ( nlsr->detailed_logging ) |
| 1449 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest sending Successfull .... \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | void |
| 1462 | send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id) |
| 1463 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1468 | |
| 1469 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1470 | char lsa_str[5]; |
| 1471 | char nlsr_str[5]; |
| 1472 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1473 | memset(&nlsr_str,0,5); |
| 1474 | sprintf(nlsr_str,"nlsr"); |
| 1475 | memset(&lsa_str,0,5); |
| 1476 | sprintf(lsa_str,"lsa"); |
| 1477 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1489 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1490 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1498 | |
| 1499 | |
| 1500 | /* adding InterestLifeTime and InterestScope filter */ |
| 1501 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1502 | struct ccn_charbuf *templ; |
| 1503 | templ = ccn_charbuf_create(); |
| 1504 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 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> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1515 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1516 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1517 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1523 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1524 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1525 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1526 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1532 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1533 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1534 | ccn_charbuf_destroy(&templ); |
| 1535 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1536 | free(int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1537 | |
| 1538 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1539 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1540 | |
| 1541 | void |
| 1542 | send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type) |
| 1543 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1548 | |
| 1549 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1550 | char lsa_str[5]; |
| 1551 | char nlsr_str[5]; |
| 1552 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1553 | memset(&nlsr_str,0,5); |
| 1554 | sprintf(nlsr_str,"nlsr"); |
| 1555 | memset(&lsa_str,0,5); |
| 1556 | sprintf(lsa_str,"lsa"); |
| 1557 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1566 | memcpy(int_name+strlen(int_name),"/",1); |
| 1567 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1568 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1569 | memcpy(int_name+strlen(int_name),"/",1); |
| 1570 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1571 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1572 | struct ccn_charbuf *name; |
| 1573 | name=ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1574 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1575 | |
| 1576 | ccn_name_from_uri(name,int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1577 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 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 */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1594 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1599 | |
| 1600 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1601 | |
| 1602 | if ( res >= 0 ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1603 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 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"); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1608 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1609 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1610 | ccn_charbuf_destroy(&templ); |
| 1611 | ccn_charbuf_destroy(&name); |
| 1612 | free(int_name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1613 | } |