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