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> |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 19 | #include <ccn/bloom.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 20 | |
| 21 | #include "nlsr.h" |
| 22 | #include "nlsr_ndn.h" |
| 23 | #include "utility.h" |
| 24 | |
| 25 | enum ccn_upcall_res |
| 26 | incoming_interest(struct ccn_closure *selfp, |
| 27 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 28 | { |
| 29 | |
| 30 | switch (kind) { |
| 31 | case CCN_UPCALL_FINAL: |
| 32 | break; |
| 33 | case CCN_UPCALL_INTEREST: |
| 34 | // printing the name prefix for which it received interest |
| 35 | printf("Interest Received for name: "); |
| 36 | struct ccn_charbuf*c; |
| 37 | c=ccn_charbuf_create(); |
| 38 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 39 | //ccn_name_chop(c,NULL,-1); |
| 40 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 41 | ccn_charbuf_destroy(&c); |
| 42 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 43 | process_incoming_interest(selfp, info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 47 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 48 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 49 | |
| 50 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 51 | info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 52 | |
| 53 | sp.template_ccnb=ccn_charbuf_create(); |
| 54 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 55 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010); |
| 56 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 57 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 58 | |
| 59 | res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); |
| 60 | res=ccn_put(ospfndn->ccn,data->buf,data->length); |
| 61 | ccn_charbuf_destroy(&data); |
| 62 | |
| 63 | */ |
| 64 | break; |
| 65 | |
| 66 | default: |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | return CCN_UPCALL_RESULT_OK; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 75 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 76 | { |
| 77 | |
| 78 | |
| 79 | switch(kind) { |
| 80 | case CCN_UPCALL_FINAL: |
| 81 | break; |
| 82 | case CCN_UPCALL_CONTENT: |
| 83 | printf("Content Received for name: "); |
| 84 | struct ccn_charbuf*c; |
| 85 | c=ccn_charbuf_create(); |
| 86 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 87 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 88 | ccn_charbuf_destroy(&c); |
| 89 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 90 | printf("Content Received for name: "); |
| 91 | struct ccn_charbuf*cc; |
| 92 | cc=ccn_charbuf_create(); |
| 93 | ccn_uri_append(cc,info->content_ccnb,info->pco->offset[CCN_PCO_E],0); |
| 94 | printf("%s\n",ccn_charbuf_as_string(cc)); |
| 95 | ccn_charbuf_destroy(&cc); |
| 96 | |
| 97 | process_incoming_content(selfp, info); |
| 98 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 99 | break; |
| 100 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 101 | printf("Interest timed out \n"); |
| 102 | struct ccn_charbuf*ic; |
| 103 | ic=ccn_charbuf_create(); |
| 104 | ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 105 | printf("%s\n",ccn_charbuf_as_string(ic)); |
| 106 | ccn_charbuf_destroy(&ic); |
| 107 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 108 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 109 | break; |
| 110 | default: |
| 111 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 112 | return CCN_UPCALL_RESULT_ERR; |
| 113 | } |
| 114 | |
| 115 | return CCN_UPCALL_RESULT_OK; |
| 116 | } |
akmhoque | 61fe447 | 2012-08-10 10:13:34 -0500 | [diff] [blame] | 117 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 118 | |
| 119 | void |
| 120 | process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 121 | { |
| 122 | printf("process_incoming_content called \n"); |
| 123 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 124 | struct ccn_charbuf*c; |
| 125 | c=ccn_charbuf_create(); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 126 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 127 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 128 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 129 | ccn_charbuf_destroy(&c); |
| 130 | |
| 131 | const unsigned char *comp_ptr1; |
| 132 | size_t comp_size; |
| 133 | int res,i; |
| 134 | int nlsr_position=0; |
| 135 | int name_comps=(int)info->interest_comps->n; |
| 136 | |
| 137 | for(i=0;i<name_comps;i++) |
| 138 | { |
| 139 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 140 | if( res == 0) |
| 141 | { |
| 142 | nlsr_position=i; |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 148 | |
| 149 | |
| 150 | printf("Det= %s \n",comp_ptr1); |
| 151 | |
| 152 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 153 | { |
| 154 | process_incoming_content_lsdb(selfp,info); |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | |
| 160 | void |
| 161 | process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 162 | { |
| 163 | printf("process_incoming_content_lsdb called \n"); |
| 164 | |
| 165 | const unsigned char *content_data; |
| 166 | size_t length; |
| 167 | ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length); |
| 168 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 169 | |
| 170 | if ( !strcmp((char *)content_data,"NACK")) |
| 171 | { |
| 172 | printf("NACK received for LSDB request. Do nothing \n"); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | // Do the LSDB processing here |
| 177 | |
| 178 | } |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 179 | |
| 180 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
| 184 | void |
| 185 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 186 | { |
| 187 | printf("process_incoming_timed_out_interest called \n"); |
| 188 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 189 | struct ccn_charbuf*c; |
| 190 | c=ccn_charbuf_create(); |
| 191 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 192 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 193 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 194 | ccn_charbuf_destroy(&c); |
| 195 | |
| 196 | const unsigned char *comp_ptr1; |
| 197 | size_t comp_size; |
| 198 | int res,i; |
| 199 | int nlsr_position=0; |
| 200 | int name_comps=(int)info->interest_comps->n; |
| 201 | |
| 202 | for(i=0;i<name_comps;i++) |
| 203 | { |
| 204 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 205 | if( res == 0) |
| 206 | { |
| 207 | nlsr_position=i; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 213 | |
| 214 | |
| 215 | printf("Det= %s \n",comp_ptr1); |
| 216 | |
| 217 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 218 | { |
| 219 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 220 | } |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 224 | void |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 225 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 226 | { |
| 227 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
| 228 | |
| 229 | |
| 230 | int res,i; |
| 231 | int nlsr_position=0; |
| 232 | int name_comps=(int)info->interest_comps->n; |
| 233 | |
| 234 | //const unsigned char *comp_ptr1; |
| 235 | //size_t comp_size; |
| 236 | |
| 237 | for(i=0;i<name_comps;i++) |
| 238 | { |
| 239 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 240 | if( res == 0) |
| 241 | { |
| 242 | nlsr_position=i; |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | |
| 248 | struct ccn_charbuf*c; |
| 249 | c=ccn_charbuf_create(); |
| 250 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 251 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 252 | ccn_charbuf_destroy(&c); |
| 253 | |
| 254 | |
| 255 | } |
| 256 | |
| 257 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 258 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 259 | { |
| 260 | printf("process_incoming_interest called \n"); |
| 261 | |
| 262 | |
| 263 | struct ccn_charbuf*c; |
| 264 | c=ccn_charbuf_create(); |
| 265 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 266 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 267 | ccn_charbuf_destroy(&c); |
| 268 | |
| 269 | const unsigned char *comp_ptr1; |
| 270 | size_t comp_size; |
| 271 | int res,i; |
| 272 | int nlsr_position=0; |
| 273 | int name_comps=(int)info->interest_comps->n; |
| 274 | |
| 275 | for(i=0;i<name_comps;i++) |
| 276 | { |
| 277 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 278 | if( res == 0) |
| 279 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 280 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 286 | |
| 287 | |
| 288 | printf("Det= %s \n",comp_ptr1); |
| 289 | |
| 290 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 291 | { |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 292 | process_incoming_interest_lsdb(selfp,info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 293 | } |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 294 | |
| 295 | |
| 296 | } |
| 297 | |
| 298 | |
| 299 | void |
| 300 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 301 | { |
| 302 | printf("process_incoming_interest_lsdb called \n"); |
| 303 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 304 | int l, res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 305 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 306 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 307 | struct ccn_buf_decoder decoder; |
| 308 | struct ccn_buf_decoder *d; |
| 309 | const unsigned char *comp; |
| 310 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 311 | |
| 312 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 313 | if (l > 0) |
| 314 | { |
| 315 | comp = NULL; |
| 316 | size = 0; |
| 317 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 318 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 319 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 320 | { |
| 321 | ccn_buf_advance(d); |
| 322 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 323 | ccn_buf_advance_past_element(d); |
| 324 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 325 | { |
| 326 | ccn_buf_advance(d); |
| 327 | ccn_buf_match_blob(d, &comp, &size); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 328 | ccn_buf_check_close(d); |
| 329 | |
| 330 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 331 | } |
| 332 | ccn_buf_check_close(d); |
| 333 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 334 | //if (d->decoder.state < 0) |
| 335 | //printf("Parse Failed\n"); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 336 | if (comp != NULL) |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 337 | printf("Number in Exclusion Filter is %s\n",comp); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 338 | |
| 339 | /* Now comp points to the start of your potential number, and size is its length */ |
| 340 | } |
| 341 | |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 342 | int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16); |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 343 | |
| 344 | printf (" dbcmp = %d \n",dbcmp); |
| 345 | |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 346 | if(dbcmp > 0) |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 347 | { |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 348 | printf("Has Updated database (Older: %s New: %s)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 349 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 350 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 351 | { |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 352 | printf("Data base is not updated than the older one (Older: %s New: %s)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 353 | printf("Sending NACK Content back.....\n"); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 354 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 355 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 356 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 357 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 358 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 359 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 360 | ccn_name_append_str(name,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 361 | |
| 362 | sp.template_ccnb=ccn_charbuf_create(); |
| 363 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 364 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 365 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 366 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 367 | |
| 368 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame^] | 369 | if(res >= 0) |
| 370 | printf("Signing Content is successful \n"); |
| 371 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 372 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 373 | |
| 374 | if(res >= 0) |
| 375 | printf("Sending NACK Content is successful \n"); |
| 376 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 377 | ccn_charbuf_destroy(&data); |
| 378 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 379 | |
| 380 | } |
| 381 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | int |
| 385 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, |
| 386 | struct ccn_scheduled_event *ev, int flags) |
| 387 | { |
| 388 | |
| 389 | struct ccn_charbuf *name; |
| 390 | long int rnum; |
| 391 | char rnumstr[20]; |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 392 | char lsdb_str[5]; |
| 393 | char nlsr_str[5]; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 394 | |
| 395 | int res,i; |
| 396 | int adl_element; |
| 397 | |
| 398 | rnum=random(); |
| 399 | memset(&rnumstr,0,20); |
| 400 | sprintf(rnumstr,"%ld",rnum); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 401 | memset(&nlsr_str,0,5); |
| 402 | sprintf(nlsr_str,"nlsr"); |
| 403 | memset(&lsdb_str,0,5); |
| 404 | sprintf(lsdb_str,"lsdb"); |
| 405 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 406 | |
| 407 | struct ndn_neighbor *nbr; |
| 408 | |
| 409 | struct hashtb_enumerator ee; |
| 410 | struct hashtb_enumerator *e = ⅇ |
| 411 | |
| 412 | hashtb_start(nlsr->adl, e); |
| 413 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 414 | //int mynumber=15; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 415 | |
| 416 | for(i=0;i<adl_element;i++) |
| 417 | { |
| 418 | nbr=e->data; |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 419 | printf("Sending interest for name prefix:%s/%s/%s/%s\n",nbr->neighbor->name,nlsr_str,lsdb_str,rnumstr); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 420 | name=ccn_charbuf_create(); |
| 421 | res=ccn_name_from_uri(name,nbr->neighbor->name); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 422 | ccn_name_append_str(name,nlsr_str); |
| 423 | ccn_name_append_str(name,lsdb_str); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 424 | ccn_name_append_str(name,rnumstr); |
| 425 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 426 | /* adding Exclusion filter */ |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 427 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 428 | struct ccn_charbuf *templ; |
| 429 | templ = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 430 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 431 | struct ccn_charbuf *c; |
| 432 | c = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 433 | |
| 434 | |
| 435 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 436 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 437 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 438 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 439 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 440 | ccn_charbuf_reset(c); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 441 | //ccn_charbuf_putf(c, "%u", (unsigned)mynumber); |
| 442 | ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 443 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 444 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 445 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 446 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 447 | |
| 448 | /* Adding Exclusion filter done */ |
| 449 | |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 450 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 451 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 452 | if ( res >= 0 ) |
| 453 | printf("Interest sending Successfull .... \n"); |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 454 | ccn_charbuf_destroy(&c); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 455 | ccn_charbuf_destroy(&templ); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 456 | ccn_charbuf_destroy(&name); |
| 457 | |
| 458 | hashtb_next(e); |
| 459 | } |
| 460 | |
| 461 | hashtb_end(e); |
| 462 | |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 463 | nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 464 | |
| 465 | return 0; |
| 466 | |
| 467 | } |
| 468 | |