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 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 161 | } |
| 162 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 163 | int |
| 164 | get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 165 | { |
| 166 | int res,i; |
| 167 | int nlsr_position=0; |
| 168 | int name_comps=(int)info->interest_comps->n; |
| 169 | |
| 170 | int ret=0; |
| 171 | |
| 172 | for(i=0;i<name_comps;i++) |
| 173 | { |
| 174 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 175 | if( res == 0) |
| 176 | { |
| 177 | nlsr_position=i; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | const unsigned char *comp_ptr1; |
| 184 | size_t comp_size; |
| 185 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size); |
| 186 | |
| 187 | ret=atoi((char *)comp_ptr1); |
| 188 | |
| 189 | return ret; |
| 190 | |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info ) |
| 195 | { |
| 196 | const unsigned char *comp_ptr1; |
| 197 | size_t comp_size; |
| 198 | ccn_name_comp_get(info->content_ccnb, info->content_comps,info->content_comps->n-2,&comp_ptr1, &comp_size); |
| 199 | memcpy(lsdb_version,(char *)comp_ptr1,(int)comp_size); |
| 200 | |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /* Call back function registered in ccnd to get all interest coming to NLSR application */ |
| 205 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 206 | enum ccn_upcall_res |
| 207 | incoming_interest(struct ccn_closure *selfp, |
| 208 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 209 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 210 | |
| 211 | nlsr_lock(); |
| 212 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 213 | switch (kind) { |
| 214 | case CCN_UPCALL_FINAL: |
| 215 | break; |
| 216 | case CCN_UPCALL_INTEREST: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 217 | // printing the name prefix for which it received interest |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 218 | if ( nlsr->debugging ) |
| 219 | printf("Interest Received for name: "); |
| 220 | if ( nlsr->detailed_logging ) |
| 221 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: "); |
| 222 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 223 | struct ccn_charbuf*c; |
| 224 | c=ccn_charbuf_create(); |
| 225 | 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] | 226 | |
| 227 | if ( nlsr->debugging ) |
| 228 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 229 | if ( nlsr->detailed_logging ) |
| 230 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 231 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 232 | ccn_charbuf_destroy(&c); |
| 233 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 234 | process_incoming_interest(selfp, info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 235 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 236 | break; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 237 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 238 | default: |
| 239 | break; |
| 240 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 241 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 242 | nlsr_unlock(); |
| 243 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 244 | return CCN_UPCALL_RESULT_OK; |
| 245 | } |
| 246 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 247 | /* Function for processing incoming interest and reply with content/NACK content */ |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 248 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 249 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 250 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 251 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 252 | if ( nlsr->debugging ) |
| 253 | printf("process_incoming_interest called \n"); |
| 254 | if ( nlsr->detailed_logging ) |
| 255 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n"); |
| 256 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 257 | const unsigned char *comp_ptr1; |
| 258 | size_t comp_size; |
| 259 | int res,i; |
| 260 | int nlsr_position=0; |
| 261 | int name_comps=(int)info->interest_comps->n; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 262 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 263 | for(i=0;i<name_comps;i++) |
| 264 | { |
| 265 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 266 | if( res == 0) |
| 267 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 268 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 269 | break; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | 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] | 274 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 275 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 276 | if(!strcmp((char *)comp_ptr1,"info")) |
| 277 | { |
| 278 | process_incoming_interest_info(selfp,info); |
| 279 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 280 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void |
| 284 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 285 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 286 | if ( nlsr->debugging ) |
| 287 | { |
| 288 | printf("process_incoming_interest_info called \n"); |
| 289 | printf("Sending Info Content back.....\n"); |
| 290 | } |
| 291 | if ( nlsr->detailed_logging ) |
| 292 | { |
| 293 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n"); |
| 294 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n"); |
| 295 | } |
| 296 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 297 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 298 | int res; |
| 299 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 300 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 301 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 302 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 303 | 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]); |
| 304 | if (res >= 0) |
| 305 | { |
| 306 | sp.template_ccnb=ccn_charbuf_create(); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 307 | |
| 308 | struct ccn_charbuf *pubid = ccn_charbuf_create(); |
| 309 | struct ccn_charbuf *pubkey = ccn_charbuf_create(); |
| 310 | |
| 311 | int res1; |
| 312 | res1 = ccn_get_public_key(nlsr->ccn, NULL, pubid, pubkey); |
| 313 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG); |
| 314 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyLocator, CCN_DTAG); |
| 315 | ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_KeyName, CCN_DTAG); |
| 316 | ccn_charbuf_append_charbuf(sp.template_ccnb, pubid); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 317 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 318 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 319 | |
| 320 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 321 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 322 | |
| 323 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 324 | |
| 325 | sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR; |
| 326 | sp.sp_flags |= CCN_SP_FINAL_BLOCK; |
| 327 | sp.type = CCN_CONTENT_KEY; |
| 328 | |
| 329 | //ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 330 | //ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 331 | //sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 332 | //ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 333 | |
| 334 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 335 | char *raw_data=(char *)malloc(20); |
| 336 | memset(raw_data,0,20); |
| 337 | sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 338 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 339 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, pubkey->buf,pubkey->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 340 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 341 | { |
| 342 | if ( nlsr->debugging ) |
| 343 | printf("Signing info Content is successful \n"); |
| 344 | if ( nlsr->detailed_logging ) |
| 345 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 346 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 347 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 348 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 349 | if(res >= 0) |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 350 | { |
| 351 | if ( nlsr->debugging ) |
| 352 | printf("Sending Info Content is successful \n"); |
| 353 | if ( nlsr->detailed_logging ) |
| 354 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n"); |
| 355 | } |
| 356 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 357 | |
| 358 | |
| 359 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 360 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 361 | |
| 362 | if ( nlsr->debugging ) |
| 363 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 364 | if ( nlsr->detailed_logging ) |
| 365 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
| 366 | |
| 367 | //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] | 368 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 369 | |
| 370 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 371 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 372 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 373 | send_info_interest_to_neighbor(nbr); |
| 374 | } |
| 375 | |
| 376 | free(nbr); |
| 377 | free(raw_data); |
| 378 | ccn_charbuf_destroy(&sp.template_ccnb); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 379 | ccn_charbuf_destroy(&pubid); |
| 380 | ccn_charbuf_destroy(&pubkey); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 381 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 382 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 383 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 384 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 385 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 389 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 390 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 391 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 392 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 393 | { |
| 394 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 395 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 396 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 397 | switch(kind) { |
| 398 | case CCN_UPCALL_FINAL: |
| 399 | break; |
| 400 | case CCN_UPCALL_CONTENT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 401 | if ( nlsr->debugging ) |
| 402 | printf("Content Received for Name: "); |
| 403 | if ( nlsr->detailed_logging ) |
| 404 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: "); |
| 405 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 406 | struct ccn_charbuf*c; |
| 407 | c=ccn_charbuf_create(); |
| 408 | 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] | 409 | if ( nlsr->debugging ) |
| 410 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 411 | if ( nlsr->detailed_logging ) |
| 412 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c)); |
| 413 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 414 | ccn_charbuf_destroy(&c); |
| 415 | |
| 416 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 417 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 418 | break; |
| 419 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 420 | //printf("Interest Timed Out Received for Name: "); |
| 421 | if ( nlsr->debugging ) |
| 422 | printf("Interest Timed Out Received for Name: "); |
| 423 | if ( nlsr->detailed_logging ) |
| 424 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: "); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 425 | |
| 426 | struct ccn_charbuf*ito; |
| 427 | ito=ccn_charbuf_create(); |
| 428 | 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] | 429 | if ( nlsr->debugging ) |
| 430 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 431 | if ( nlsr->detailed_logging ) |
| 432 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 433 | ccn_charbuf_destroy(&ito); |
| 434 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 435 | |
| 436 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 437 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 438 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 439 | break; |
| 440 | default: |
| 441 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 442 | if ( nlsr->debugging ) |
| 443 | printf("Unexpected response of kind %d\n", kind); |
| 444 | if ( nlsr->detailed_logging ) |
| 445 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 446 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 447 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 448 | |
| 449 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 450 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 451 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 452 | } |
| 453 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 454 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 455 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 456 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 457 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 458 | if ( nlsr->debugging ) |
| 459 | printf("process_incoming_content called \n"); |
| 460 | if ( nlsr->detailed_logging ) |
| 461 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 462 | |
| 463 | const unsigned char *comp_ptr1; |
| 464 | size_t comp_size; |
| 465 | int res,i; |
| 466 | int nlsr_position=0; |
| 467 | int name_comps=(int)info->interest_comps->n; |
| 468 | |
| 469 | for(i=0;i<name_comps;i++) |
| 470 | { |
| 471 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 472 | if( res == 0) |
| 473 | { |
| 474 | nlsr_position=i; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 480 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 481 | |
| 482 | if(!strcmp((char *)comp_ptr1,"info")) |
| 483 | { |
| 484 | process_incoming_content_info(selfp,info); |
| 485 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 486 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 487 | } |
| 488 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 489 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 490 | void |
| 491 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 492 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 493 | if ( nlsr->debugging ) |
| 494 | printf("process_incoming_content_info called \n"); |
| 495 | if ( nlsr->detailed_logging ) |
| 496 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 497 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 498 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 499 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 500 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 501 | if ( nlsr->debugging ) |
| 502 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 503 | if ( nlsr->detailed_logging ) |
| 504 | 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] | 505 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 506 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 507 | if ( contain_key_name(info->content_ccnb, info->pco) == 1) |
| 508 | { |
| 509 | struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco); |
| 510 | if(nlsr->debugging) |
| 511 | printf("Key Name: %s\n",ccn_charbuf_as_string(key_name)); |
| 512 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 513 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 514 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 515 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 516 | print_adjacent_from_adl(); |
| 517 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 518 | |
| 519 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 520 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 521 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 522 | if ( nlsr->debugging ) |
| 523 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 524 | if ( nlsr->detailed_logging ) |
| 525 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 526 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 527 | nlsr->is_build_adj_lsa_sheduled=1; |
| 528 | } |
| 529 | else |
| 530 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 531 | if ( nlsr->debugging ) |
| 532 | printf("Build and Install Adj LSA already scheduled\n"); |
| 533 | if ( nlsr->detailed_logging ) |
| 534 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 535 | } |
| 536 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 537 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 538 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 539 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 540 | |
| 541 | } |
| 542 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 543 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 544 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 545 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 546 | void |
| 547 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 548 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 549 | |
| 550 | |
| 551 | if ( nlsr->debugging ) |
| 552 | printf("process_incoming_timed_out_interest called \n"); |
| 553 | if ( nlsr->detailed_logging ) |
| 554 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n"); |
| 555 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 556 | int res,i; |
| 557 | int nlsr_position=0; |
| 558 | int name_comps=(int)info->interest_comps->n; |
| 559 | |
| 560 | for(i=0;i<name_comps;i++) |
| 561 | { |
| 562 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 563 | if( res == 0) |
| 564 | { |
| 565 | nlsr_position=i; |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 571 | { |
| 572 | process_incoming_timed_out_interest_info(selfp,info); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | void |
| 577 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 578 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 579 | |
| 580 | if ( nlsr->debugging ) |
| 581 | printf("process_incoming_timed_out_interest_info called \n"); |
| 582 | if ( nlsr->detailed_logging ) |
| 583 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 584 | |
| 585 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 586 | get_nbr(nbr,selfp,info); |
| 587 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 588 | if ( nlsr->debugging ) |
| 589 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 590 | if ( nlsr->detailed_logging ) |
| 591 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 592 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 593 | |
| 594 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 595 | update_adjacent_timed_out_to_adl(nbr,1); |
| 596 | print_adjacent_from_adl(); |
| 597 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 598 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 599 | if ( nlsr->debugging ) |
| 600 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 601 | if ( nlsr->detailed_logging ) |
| 602 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 603 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 604 | |
| 605 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 606 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 607 | send_info_interest_to_neighbor(nbr); |
| 608 | } |
| 609 | else |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 610 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 611 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 612 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 613 | { |
| 614 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 615 | nlsr->is_build_adj_lsa_sheduled=1; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 620 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 621 | |
| 622 | } |
| 623 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 624 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 625 | int |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 626 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 627 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 628 | if(flags == CCN_SCHEDULE_CANCEL) |
| 629 | { |
| 630 | return -1; |
| 631 | } |
| 632 | |
| 633 | nlsr_lock(); |
| 634 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 635 | if ( nlsr->debugging ) |
| 636 | printf("send_info_interest called \n"); |
| 637 | if ( nlsr->detailed_logging ) |
| 638 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n"); |
| 639 | |
| 640 | if ( nlsr->debugging ) |
| 641 | printf("\n"); |
| 642 | if ( nlsr->detailed_logging ) |
| 643 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 644 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 645 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 646 | struct ndn_neighbor *nbr; |
| 647 | |
| 648 | struct hashtb_enumerator ee; |
| 649 | struct hashtb_enumerator *e = ⅇ |
| 650 | |
| 651 | hashtb_start(nlsr->adl, e); |
| 652 | adl_element=hashtb_n(nlsr->adl); |
| 653 | |
| 654 | for(i=0;i<adl_element;i++) |
| 655 | { |
| 656 | nbr=e->data; |
| 657 | send_info_interest_to_neighbor(nbr->neighbor); |
| 658 | hashtb_next(e); |
| 659 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 660 | hashtb_end(e); |
| 661 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 662 | nlsr_unlock(); |
| 663 | |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 664 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 665 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | void |
| 670 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 671 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 672 | |
| 673 | if ( nlsr->debugging ) |
| 674 | printf("send_info_interest_to_neighbor called \n"); |
| 675 | if ( nlsr->detailed_logging ) |
| 676 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n"); |
| 677 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 678 | |
| 679 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 680 | char info_str[5]; |
| 681 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 682 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 683 | memset(&nlsr_str,0,5); |
| 684 | sprintf(nlsr_str,"nlsr"); |
| 685 | memset(&info_str,0,5); |
| 686 | sprintf(info_str,"info"); |
| 687 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 688 | |
| 689 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 690 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 691 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 692 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 693 | 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] | 694 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 695 | memcpy(int_name+strlen(int_name),"/",1); |
| 696 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 697 | memcpy(int_name+strlen(int_name),"/",1); |
| 698 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 699 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 700 | |
| 701 | |
| 702 | res=ccn_name_from_uri(name,int_name); |
| 703 | if ( res >=0 ) |
| 704 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 705 | /* adding InterestLifeTime and InterestScope filter */ |
| 706 | |
| 707 | struct ccn_charbuf *templ; |
| 708 | templ = ccn_charbuf_create(); |
| 709 | |
| 710 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 711 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 712 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 713 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 714 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 715 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 716 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 717 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 718 | |
| 719 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 720 | unsigned int face_id=get_next_hop_face_from_adl(nbr->name); |
| 721 | ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 722 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 723 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 724 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 725 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 726 | 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] | 727 | if ( nlsr->detailed_logging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 728 | 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] | 729 | |
| 730 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 731 | |
| 732 | if ( res >= 0 ) |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 733 | { |
| 734 | if ( nlsr->debugging ) |
| 735 | printf("Info interest sending Successfull .... \n"); |
| 736 | if ( nlsr->detailed_logging ) |
| 737 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n"); |
| 738 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 739 | ccn_charbuf_destroy(&templ); |
| 740 | } |
| 741 | ccn_charbuf_destroy(&name); |
| 742 | free(int_name); |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 743 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 744 | |
akmhoque | c06dcf1 | 2013-02-20 08:13:37 -0600 | [diff] [blame^] | 745 | int |
| 746 | contain_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 747 | { |
| 748 | if (pco->offset[CCN_PCO_B_KeyLocator] == pco->offset[CCN_PCO_E_KeyLocator]) |
| 749 | return -1; |
| 750 | |
| 751 | struct ccn_buf_decoder decoder; |
| 752 | struct ccn_buf_decoder *d; |
| 753 | d = ccn_buf_decoder_start(&decoder, ccnb + pco->offset[CCN_PCO_B_Key_Certificate_KeyName], pco->offset[CCN_PCO_E_Key_Certificate_KeyName] - pco->offset[CCN_PCO_B_Key_Certificate_KeyName]); |
| 754 | if (ccn_buf_match_dtag(d, CCN_DTAG_KeyName)) |
| 755 | return 1; |
| 756 | |
| 757 | return -1; |
| 758 | } |
| 759 | |
| 760 | struct ccn_charbuf * |
| 761 | get_key_name(const unsigned char *ccnb, struct ccn_parsed_ContentObject *pco) |
| 762 | { |
| 763 | struct ccn_charbuf *key_name = ccn_charbuf_create(); |
| 764 | ccn_charbuf_append(key_name, ccnb + pco->offset[CCN_PCO_B_KeyName_Name], pco->offset[CCN_PCO_E_KeyName_Name] - pco->offset[CCN_PCO_B_KeyName_Name]); |
| 765 | |
| 766 | return key_name; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 767 | } |