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 | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 278 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 279 | if(!strcmp((char *)comp_ptr1,"info")) |
| 280 | { |
| 281 | process_incoming_interest_info(selfp,info); |
| 282 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 283 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void |
| 287 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 288 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 289 | if ( nlsr->debugging ) |
| 290 | { |
| 291 | printf("process_incoming_interest_info called \n"); |
| 292 | printf("Sending Info Content back.....\n"); |
| 293 | } |
| 294 | if ( nlsr->detailed_logging ) |
| 295 | { |
| 296 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n"); |
| 297 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 298 | } |
| 299 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 300 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 301 | int res; |
| 302 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 303 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 304 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 305 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 306 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 307 | if (res >= 0) |
| 308 | { |
| 309 | sp.template_ccnb=ccn_charbuf_create(); |
| 310 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 311 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 312 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 313 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 314 | |
| 315 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 316 | char *raw_data=(char *)malloc(20); |
| 317 | memset(raw_data,0,20); |
| 318 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 319 | |
| 320 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data)); |
| 321 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 322 | { |
| 323 | if ( nlsr->debugging ) |
| 324 | printf("Signing info Content is successful \n"); |
| 325 | if ( nlsr->detailed_logging ) |
| 326 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 327 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 328 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 329 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 330 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 331 | { |
| 332 | if ( nlsr->debugging ) |
| 333 | printf("Sending Info Content is successful \n"); |
| 334 | if ( nlsr->detailed_logging ) |
| 335 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n"); |
| 336 | } |
| 337 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 338 | |
| 339 | |
| 340 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 341 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 342 | |
| 343 | if ( nlsr->debugging ) |
| 344 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 345 | if ( nlsr->detailed_logging ) |
| 346 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 347 | |
| 348 | //printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 349 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 350 | |
| 351 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 352 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 353 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 354 | send_info_interest_to_neighbor(nbr); |
| 355 | } |
| 356 | |
| 357 | free(nbr); |
| 358 | free(raw_data); |
| 359 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 360 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 361 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 362 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 363 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 364 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 368 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 369 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 370 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 371 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 372 | { |
| 373 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 374 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 375 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 376 | switch(kind) { |
| 377 | case CCN_UPCALL_FINAL: |
| 378 | break; |
| 379 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 380 | if ( nlsr->debugging ) |
| 381 | printf("Content Received for Name: "); |
| 382 | if ( nlsr->detailed_logging ) |
| 383 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 384 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 385 | struct ccn_charbuf*c; |
| 386 | c=ccn_charbuf_create(); |
| 387 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 388 | if ( nlsr->debugging ) |
| 389 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 390 | if ( nlsr->detailed_logging ) |
| 391 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 392 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 393 | ccn_charbuf_destroy(&c); |
| 394 | |
| 395 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 396 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 397 | break; |
| 398 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 399 | //printf("Interest Timed Out Received for Name: "); |
| 400 | if ( nlsr->debugging ) |
| 401 | printf("Interest Timed Out Received for Name: "); |
| 402 | if ( nlsr->detailed_logging ) |
| 403 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 404 | |
| 405 | struct ccn_charbuf*ito; |
| 406 | ito=ccn_charbuf_create(); |
| 407 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 408 | |
| 409 | if ( nlsr->debugging ) |
| 410 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 411 | if ( nlsr->detailed_logging ) |
| 412 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
| 413 | |
| 414 | //printf("%s\n",ccn_charbuf_as_string(ito)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 415 | ccn_charbuf_destroy(&ito); |
| 416 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 417 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 418 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 419 | break; |
| 420 | default: |
| 421 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 422 | if ( nlsr->debugging ) |
| 423 | printf("Unexpected response of kind %d\n", kind); |
| 424 | if ( nlsr->detailed_logging ) |
| 425 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 426 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 427 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 428 | |
| 429 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 430 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 431 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 432 | } |
| 433 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 434 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 435 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 436 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 437 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 438 | if ( nlsr->debugging ) |
| 439 | printf("process_incoming_content called \n"); |
| 440 | if ( nlsr->detailed_logging ) |
| 441 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 442 | |
| 443 | const unsigned char *comp_ptr1; |
| 444 | size_t comp_size; |
| 445 | int res,i; |
| 446 | int nlsr_position=0; |
| 447 | int name_comps=(int)info->interest_comps->n; |
| 448 | |
| 449 | for(i=0;i<name_comps;i++) |
| 450 | { |
| 451 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 452 | if( res == 0) |
| 453 | { |
| 454 | nlsr_position=i; |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 460 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 461 | |
| 462 | if(!strcmp((char *)comp_ptr1,"info")) |
| 463 | { |
| 464 | process_incoming_content_info(selfp,info); |
| 465 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 466 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 467 | } |
| 468 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 469 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 470 | void |
| 471 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 472 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 473 | if ( nlsr->debugging ) |
| 474 | printf("process_incoming_content_info called \n"); |
| 475 | if ( nlsr->detailed_logging ) |
| 476 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 477 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 478 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 479 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 480 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 481 | if ( nlsr->debugging ) |
| 482 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 483 | if ( nlsr->detailed_logging ) |
| 484 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 485 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 486 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 487 | //const unsigned char *ptr; |
| 488 | //size_t length; |
| 489 | //ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 490 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 491 | //long int interval=atoi((char *)ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 492 | |
| 493 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 494 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 495 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 496 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 497 | //update_lsdb_synch_interval_to_adl(nbr,interval); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 498 | print_adjacent_from_adl(); |
| 499 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 500 | |
| 501 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 502 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 503 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 504 | if ( nlsr->debugging ) |
| 505 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 506 | if ( nlsr->detailed_logging ) |
| 507 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 508 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 509 | nlsr->is_build_adj_lsa_sheduled=1; |
| 510 | } |
| 511 | else |
| 512 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 513 | if ( nlsr->debugging ) |
| 514 | printf("Build and Install Adj LSA already scheduled\n"); |
| 515 | if ( nlsr->detailed_logging ) |
| 516 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 517 | } |
| 518 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 519 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 520 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 521 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 522 | |
| 523 | } |
| 524 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 525 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 526 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 527 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 528 | void |
| 529 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 530 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 531 | |
| 532 | |
| 533 | if ( nlsr->debugging ) |
| 534 | printf("process_incoming_timed_out_interest called \n"); |
| 535 | if ( nlsr->detailed_logging ) |
| 536 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n"); |
| 537 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 538 | int res,i; |
| 539 | int nlsr_position=0; |
| 540 | int name_comps=(int)info->interest_comps->n; |
| 541 | |
| 542 | for(i=0;i<name_comps;i++) |
| 543 | { |
| 544 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 545 | if( res == 0) |
| 546 | { |
| 547 | nlsr_position=i; |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 553 | { |
| 554 | process_incoming_timed_out_interest_info(selfp,info); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void |
| 559 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 560 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 561 | |
| 562 | if ( nlsr->debugging ) |
| 563 | printf("process_incoming_timed_out_interest_info called \n"); |
| 564 | if ( nlsr->detailed_logging ) |
| 565 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 566 | |
| 567 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 568 | get_nbr(nbr,selfp,info); |
| 569 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 570 | if ( nlsr->debugging ) |
| 571 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 572 | if ( nlsr->detailed_logging ) |
| 573 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 574 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 575 | |
| 576 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 577 | update_adjacent_timed_out_to_adl(nbr,1); |
| 578 | print_adjacent_from_adl(); |
| 579 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 580 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 581 | if ( nlsr->debugging ) |
| 582 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 583 | if ( nlsr->detailed_logging ) |
| 584 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 585 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 586 | |
| 587 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 588 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 589 | send_info_interest_to_neighbor(nbr); |
| 590 | } |
| 591 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 592 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 593 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 594 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 595 | { |
| 596 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 597 | nlsr->is_build_adj_lsa_sheduled=1; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 602 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 603 | |
| 604 | } |
| 605 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 606 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 607 | int |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 608 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 609 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 610 | if(flags == CCN_SCHEDULE_CANCEL) |
| 611 | { |
| 612 | return -1; |
| 613 | } |
| 614 | |
| 615 | nlsr_lock(); |
| 616 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 617 | if ( nlsr->debugging ) |
| 618 | printf("send_info_interest called \n"); |
| 619 | if ( nlsr->detailed_logging ) |
| 620 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 621 | |
| 622 | if ( nlsr->debugging ) |
| 623 | printf("\n"); |
| 624 | if ( nlsr->detailed_logging ) |
| 625 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 626 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 627 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 628 | struct ndn_neighbor *nbr; |
| 629 | |
| 630 | struct hashtb_enumerator ee; |
| 631 | struct hashtb_enumerator *e = ⅇ |
| 632 | |
| 633 | hashtb_start(nlsr->adl, e); |
| 634 | adl_element=hashtb_n(nlsr->adl); |
| 635 | |
| 636 | for(i=0;i<adl_element;i++) |
| 637 | { |
| 638 | nbr=e->data; |
| 639 | send_info_interest_to_neighbor(nbr->neighbor); |
| 640 | hashtb_next(e); |
| 641 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 642 | hashtb_end(e); |
| 643 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 644 | nlsr_unlock(); |
| 645 | |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 646 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 647 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | void |
| 652 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 653 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 654 | |
| 655 | if ( nlsr->debugging ) |
| 656 | printf("send_info_interest_to_neighbor called \n"); |
| 657 | if ( nlsr->detailed_logging ) |
| 658 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n"); |
| 659 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 660 | |
| 661 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 662 | char info_str[5]; |
| 663 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 664 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 665 | memset(&nlsr_str,0,5); |
| 666 | sprintf(nlsr_str,"nlsr"); |
| 667 | memset(&info_str,0,5); |
| 668 | sprintf(info_str,"info"); |
| 669 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 670 | |
| 671 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 672 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 673 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 674 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 675 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 676 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 677 | memcpy(int_name+strlen(int_name),"/",1); |
| 678 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 679 | memcpy(int_name+strlen(int_name),"/",1); |
| 680 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 681 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 682 | |
| 683 | |
| 684 | res=ccn_name_from_uri(name,int_name); |
| 685 | if ( res >=0 ) |
| 686 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 687 | /* adding InterestLifeTime and InterestScope filter */ |
| 688 | |
| 689 | struct ccn_charbuf *templ; |
| 690 | templ = ccn_charbuf_create(); |
| 691 | |
| 692 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 693 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 694 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 695 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 696 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 697 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 698 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 699 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 700 | |
| 701 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 702 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 703 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 704 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 705 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 707 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 708 | printf("Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 709 | if ( nlsr->detailed_logging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 710 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 711 | |
| 712 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 713 | |
| 714 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 715 | { |
| 716 | if ( nlsr->debugging ) |
| 717 | printf("Info interest sending Successfull .... \n"); |
| 718 | if ( nlsr->detailed_logging ) |
| 719 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n"); |
| 720 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 721 | ccn_charbuf_destroy(&templ); |
| 722 | } |
| 723 | ccn_charbuf_destroy(&name); |
| 724 | free(int_name); |
| 725 | |
| 726 | } |