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" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 24 | #include "nlsr_adl.h" |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 25 | #include "nlsr_lsdb.h" |
| 26 | |
| 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 | |
| 44 | enum ccn_upcall_res |
| 45 | incoming_interest(struct ccn_closure *selfp, |
| 46 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 47 | { |
| 48 | |
| 49 | switch (kind) { |
| 50 | case CCN_UPCALL_FINAL: |
| 51 | break; |
| 52 | case CCN_UPCALL_INTEREST: |
| 53 | // printing the name prefix for which it received interest |
| 54 | printf("Interest Received for name: "); |
| 55 | struct ccn_charbuf*c; |
| 56 | c=ccn_charbuf_create(); |
| 57 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
akmhoque | 2fd7436 | 2012-08-27 14:45:08 -0500 | [diff] [blame] | 58 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 59 | //ccn_name_chop(c,NULL,-1); |
| 60 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 61 | ccn_charbuf_destroy(&c); |
| 62 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 63 | process_incoming_interest(selfp, info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 67 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 68 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 69 | |
| 70 | ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name], |
| 71 | info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 72 | |
| 73 | sp.template_ccnb=ccn_charbuf_create(); |
| 74 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 75 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010); |
| 76 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 77 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 78 | |
| 79 | res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello")); |
| 80 | res=ccn_put(ospfndn->ccn,data->buf,data->length); |
| 81 | ccn_charbuf_destroy(&data); |
| 82 | |
| 83 | */ |
| 84 | break; |
| 85 | |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | return CCN_UPCALL_RESULT_OK; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 95 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
| 96 | { |
| 97 | |
| 98 | |
| 99 | switch(kind) { |
| 100 | case CCN_UPCALL_FINAL: |
| 101 | break; |
| 102 | case CCN_UPCALL_CONTENT: |
| 103 | printf("Content Received for name: "); |
| 104 | struct ccn_charbuf*c; |
| 105 | c=ccn_charbuf_create(); |
| 106 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 107 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 108 | ccn_charbuf_destroy(&c); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 109 | |
| 110 | process_incoming_content(selfp, info); |
| 111 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 112 | break; |
| 113 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 114 | printf("Interest timed out \n"); |
| 115 | struct ccn_charbuf*ic; |
| 116 | ic=ccn_charbuf_create(); |
| 117 | ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 118 | printf("%s\n",ccn_charbuf_as_string(ic)); |
| 119 | ccn_charbuf_destroy(&ic); |
| 120 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 121 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 122 | break; |
| 123 | default: |
| 124 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
| 125 | return CCN_UPCALL_RESULT_ERR; |
| 126 | } |
| 127 | |
| 128 | return CCN_UPCALL_RESULT_OK; |
| 129 | } |
akmhoque | 61fe447 | 2012-08-10 10:13:34 -0500 | [diff] [blame] | 130 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 131 | |
| 132 | void |
| 133 | process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 134 | { |
| 135 | printf("process_incoming_content called \n"); |
| 136 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 137 | struct ccn_charbuf*c; |
| 138 | c=ccn_charbuf_create(); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 139 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 140 | 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] | 141 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 142 | ccn_charbuf_destroy(&c); |
| 143 | |
| 144 | const unsigned char *comp_ptr1; |
| 145 | size_t comp_size; |
| 146 | int res,i; |
| 147 | int nlsr_position=0; |
| 148 | int name_comps=(int)info->interest_comps->n; |
| 149 | |
| 150 | for(i=0;i<name_comps;i++) |
| 151 | { |
| 152 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 153 | if( res == 0) |
| 154 | { |
| 155 | nlsr_position=i; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 161 | |
| 162 | |
| 163 | printf("Det= %s \n",comp_ptr1); |
| 164 | |
| 165 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 166 | { |
| 167 | process_incoming_content_lsdb(selfp,info); |
| 168 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 169 | if(!strcmp((char *)comp_ptr1,"info")) |
| 170 | { |
| 171 | process_incoming_content_info(selfp,info); |
| 172 | } |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | void |
| 178 | process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 179 | { |
| 180 | printf("process_incoming_content_lsdb called \n"); |
| 181 | |
| 182 | const unsigned char *content_data; |
| 183 | size_t length; |
| 184 | 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); |
| 185 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 186 | |
| 187 | if ( !strcmp((char *)content_data,"NACK")) |
| 188 | { |
| 189 | printf("NACK received for LSDB request. Do nothing \n"); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | // Do the LSDB processing here |
| 194 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 195 | const unsigned char *comp_ptr1; |
| 196 | size_t comp_size; |
| 197 | int res; |
| 198 | |
| 199 | res=ccn_name_comp_get(info->content_ccnb, info->content_comps,info->interest_comps->n-1,&comp_ptr1, &comp_size); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 200 | if ( res >=0) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 201 | printf("Received Database Version: %s \n",(char *)comp_ptr1); |
| 202 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 203 | } |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 204 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 205 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 206 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 210 | |
| 211 | void |
| 212 | process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 213 | { |
| 214 | printf("process_incoming_content_info called \n"); |
| 215 | |
| 216 | const unsigned char *content_data; |
| 217 | size_t length; |
| 218 | 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); |
| 219 | |
| 220 | printf("Info Value: %s \n",(char *)content_data); |
| 221 | |
| 222 | |
| 223 | } |
| 224 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 225 | void |
| 226 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 227 | { |
| 228 | printf("process_incoming_timed_out_interest called \n"); |
| 229 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 230 | struct ccn_charbuf*c; |
| 231 | c=ccn_charbuf_create(); |
| 232 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 233 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 234 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 235 | ccn_charbuf_destroy(&c); |
| 236 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 237 | //const unsigned char *comp_ptr1; |
| 238 | //size_t comp_size; |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 239 | int res,i; |
| 240 | int nlsr_position=0; |
| 241 | int name_comps=(int)info->interest_comps->n; |
| 242 | |
| 243 | for(i=0;i<name_comps;i++) |
| 244 | { |
| 245 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 246 | if( res == 0) |
| 247 | { |
| 248 | nlsr_position=i; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 253 | //res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 254 | |
| 255 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 256 | //printf("Det= %s \n",comp_ptr1); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 257 | |
akmhoque | b2e3a33 | 2012-08-21 12:17:20 -0400 | [diff] [blame] | 258 | //if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 259 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0) |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 260 | { |
| 261 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 262 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 263 | else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 264 | { |
| 265 | process_incoming_timed_out_interest_info(selfp,info); |
| 266 | } |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 270 | void |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 271 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 272 | { |
| 273 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
| 274 | |
| 275 | |
| 276 | int res,i; |
| 277 | int nlsr_position=0; |
| 278 | int name_comps=(int)info->interest_comps->n; |
| 279 | |
| 280 | //const unsigned char *comp_ptr1; |
| 281 | //size_t comp_size; |
| 282 | |
| 283 | for(i=0;i<name_comps;i++) |
| 284 | { |
| 285 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 286 | if( res == 0) |
| 287 | { |
| 288 | nlsr_position=i; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 294 | struct ccn_charbuf *nbr; |
| 295 | nbr=ccn_charbuf_create(); |
| 296 | |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 297 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 298 | const unsigned char *comp_ptr1; |
| 299 | size_t comp_size; |
| 300 | for(i=0;i<nlsr_position;i++) |
| 301 | { |
| 302 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 303 | //printf("%s \n",comp_ptr1); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 304 | ccn_charbuf_append_string(nbr,"/"); |
| 305 | ccn_charbuf_append_string(nbr,(const char *)comp_ptr1); |
| 306 | } |
| 307 | |
akmhoque | 71b552d | 2012-08-21 11:44:34 -0400 | [diff] [blame] | 308 | ccn_charbuf_append_string(nbr,"\0"); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 309 | printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr)); |
| 310 | |
| 311 | update_adjacent_status_to_adl(nbr,1); |
| 312 | |
| 313 | ccn_charbuf_destroy(&nbr); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 317 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 318 | { |
| 319 | |
| 320 | printf("process_incoming_timed_out_interest_info called \n"); |
| 321 | |
| 322 | int res,i; |
| 323 | int nlsr_position=0; |
| 324 | int name_comps=(int)info->interest_comps->n; |
| 325 | |
| 326 | for(i=0;i<name_comps;i++) |
| 327 | { |
| 328 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 329 | if( res == 0) |
| 330 | { |
| 331 | nlsr_position=i; |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | struct ccn_charbuf *nbr; |
| 337 | nbr=ccn_charbuf_create(); |
| 338 | |
| 339 | |
| 340 | const unsigned char *comp_ptr1; |
| 341 | size_t comp_size; |
| 342 | for(i=0;i<nlsr_position;i++) |
| 343 | { |
| 344 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 345 | //printf("%s \n",comp_ptr1); |
| 346 | ccn_charbuf_append_string(nbr,"/"); |
| 347 | ccn_charbuf_append_string(nbr,(const char *)comp_ptr1); |
| 348 | } |
| 349 | |
| 350 | ccn_charbuf_append_string(nbr,"\0"); |
| 351 | printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr)); |
| 352 | |
| 353 | update_adjacent_timed_out_to_adl(nbr,1); |
| 354 | int timed_out=get_timed_out_number(nbr); |
| 355 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 356 | { |
| 357 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out); |
| 358 | send_info_interest_to_neighbor(nbr); |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out); |
| 363 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0); |
| 364 | } |
| 365 | |
| 366 | ccn_charbuf_destroy(&nbr); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 371 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 372 | { |
| 373 | printf("process_incoming_interest called \n"); |
| 374 | |
| 375 | |
| 376 | struct ccn_charbuf*c; |
| 377 | c=ccn_charbuf_create(); |
akmhoque | 2fd7436 | 2012-08-27 14:45:08 -0500 | [diff] [blame] | 378 | //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0); |
| 379 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 380 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 381 | ccn_charbuf_destroy(&c); |
| 382 | |
| 383 | const unsigned char *comp_ptr1; |
| 384 | size_t comp_size; |
| 385 | int res,i; |
| 386 | int nlsr_position=0; |
| 387 | int name_comps=(int)info->interest_comps->n; |
| 388 | |
| 389 | for(i=0;i<name_comps;i++) |
| 390 | { |
| 391 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 392 | if( res == 0) |
| 393 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 394 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | e078986 | 2012-08-16 14:23:32 -0500 | [diff] [blame] | 400 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 401 | printf("Det= %s \n",comp_ptr1); |
| 402 | |
| 403 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 404 | { |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 405 | process_incoming_interest_lsdb(selfp,info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 406 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 407 | if(!strcmp((char *)comp_ptr1,"info")) |
| 408 | { |
| 409 | process_incoming_interest_info(selfp,info); |
| 410 | } |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
| 414 | void |
| 415 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 416 | { |
| 417 | printf("process_incoming_interest_lsdb called \n"); |
| 418 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 419 | int l, res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 420 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 421 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 422 | struct ccn_buf_decoder decoder; |
| 423 | struct ccn_buf_decoder *d; |
| 424 | const unsigned char *comp; |
| 425 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 426 | |
| 427 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 428 | if (l > 0) |
| 429 | { |
| 430 | comp = NULL; |
| 431 | size = 0; |
| 432 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 433 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 434 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 435 | { |
| 436 | ccn_buf_advance(d); |
| 437 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 438 | ccn_buf_advance_past_element(d); |
| 439 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 440 | { |
| 441 | ccn_buf_advance(d); |
| 442 | ccn_buf_match_blob(d, &comp, &size); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 443 | ccn_buf_check_close(d); |
| 444 | |
| 445 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 446 | } |
| 447 | ccn_buf_check_close(d); |
| 448 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 449 | //if (d->decoder.state < 0) |
| 450 | //printf("Parse Failed\n"); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 451 | if (comp != NULL) |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 452 | printf("Number in Exclusion Filter is %s\n",comp); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 453 | |
| 454 | /* Now comp points to the start of your potential number, and size is its length */ |
| 455 | } |
| 456 | |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 457 | int excl_db_version=atoi((char *)comp); |
| 458 | int dbcmp=nlsr->lsdb->version-excl_db_version; |
| 459 | //int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16); |
| 460 | |
| 461 | |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 462 | |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 463 | printf (" dbcmp = %d \n",dbcmp); |
akmhoque | 898d4aa | 2012-08-16 10:26:15 -0500 | [diff] [blame] | 464 | |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 465 | if(dbcmp > 0) |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 466 | { |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 467 | printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 468 | } |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 469 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 470 | { |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 471 | printf("Data base is not updated than the older one (Older: %s New: %ld)\n",comp,nlsr->lsdb->version); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 472 | printf("Sending NACK Content back.....\n"); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 473 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 474 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 475 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 476 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 477 | |
akmhoque | 638c20a | 2012-08-16 11:57:48 -0500 | [diff] [blame] | 478 | 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 | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 479 | |
| 480 | sp.template_ccnb=ccn_charbuf_create(); |
| 481 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 482 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 483 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 484 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 485 | |
| 486 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
akmhoque | dde7e32 | 2012-08-16 13:57:06 -0500 | [diff] [blame] | 487 | if(res >= 0) |
| 488 | printf("Signing Content is successful \n"); |
| 489 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 490 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 491 | |
| 492 | if(res >= 0) |
| 493 | printf("Sending NACK Content is successful \n"); |
| 494 | |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 495 | ccn_charbuf_destroy(&data); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 496 | ccn_charbuf_destroy(&name); |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 497 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 498 | |
| 499 | } |
| 500 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 501 | } |
| 502 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 503 | |
| 504 | void |
| 505 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 506 | { |
| 507 | printf("process_incoming_interest_info called \n"); |
| 508 | int res; |
| 509 | |
| 510 | printf("Sending Info Content back.....\n"); |
| 511 | |
| 512 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 513 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 514 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 515 | |
akmhoque | 887fc0c | 2012-08-27 15:06:06 -0500 | [diff] [blame] | 516 | 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]); |
| 517 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 518 | sp.template_ccnb=ccn_charbuf_create(); |
| 519 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 520 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 521 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 522 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 523 | |
akmhoque | 869485c | 2012-08-27 15:23:36 -0500 | [diff] [blame^] | 524 | res= ccn_sign_content(nlsr->ccn, data, name, &sp,"info",strlen("info") ); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 525 | if(res >= 0) |
| 526 | printf("Signing Content is successful \n"); |
| 527 | |
| 528 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 529 | if(res >= 0) |
akmhoque | 6428c92 | 2012-08-27 14:26:13 -0500 | [diff] [blame] | 530 | printf("Sending Info Content is successful \n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 531 | |
| 532 | ccn_charbuf_destroy(&data); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 533 | ccn_charbuf_destroy(&name); |
akmhoque | 869485c | 2012-08-27 15:23:36 -0500 | [diff] [blame^] | 534 | //ccn_charbuf_destroy(&c); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 535 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 536 | |
| 537 | } |
| 538 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 539 | int |
| 540 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, |
| 541 | struct ccn_scheduled_event *ev, int flags) |
| 542 | { |
| 543 | |
| 544 | struct ccn_charbuf *name; |
| 545 | long int rnum; |
| 546 | char rnumstr[20]; |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 547 | char lsdb_str[5]; |
| 548 | char nlsr_str[5]; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 549 | |
| 550 | int res,i; |
| 551 | int adl_element; |
| 552 | |
| 553 | rnum=random(); |
| 554 | memset(&rnumstr,0,20); |
| 555 | sprintf(rnumstr,"%ld",rnum); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 556 | memset(&nlsr_str,0,5); |
| 557 | sprintf(nlsr_str,"nlsr"); |
| 558 | memset(&lsdb_str,0,5); |
| 559 | sprintf(lsdb_str,"lsdb"); |
| 560 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 561 | |
| 562 | struct ndn_neighbor *nbr; |
| 563 | |
| 564 | struct hashtb_enumerator ee; |
| 565 | struct hashtb_enumerator *e = ⅇ |
| 566 | |
| 567 | hashtb_start(nlsr->adl, e); |
| 568 | adl_element=hashtb_n(nlsr->adl); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 569 | //int mynumber=15; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 570 | |
| 571 | for(i=0;i<adl_element;i++) |
| 572 | { |
| 573 | nbr=e->data; |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 574 | printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,lsdb_str); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 575 | name=ccn_charbuf_create(); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 576 | res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor)); |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 577 | ccn_name_append_str(name,nlsr_str); |
| 578 | ccn_name_append_str(name,lsdb_str); |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 579 | //ccn_name_append_str(name,rnumstr); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 580 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 581 | /* adding Exclusion filter */ |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 582 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 583 | struct ccn_charbuf *templ; |
| 584 | templ = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 585 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 586 | struct ccn_charbuf *c; |
| 587 | c = ccn_charbuf_create(); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 588 | |
| 589 | |
| 590 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 591 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 592 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 593 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 594 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 595 | ccn_charbuf_reset(c); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 596 | //ccn_charbuf_putf(c, "%u", (unsigned)mynumber); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 597 | //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version); |
| 598 | ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version); |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 599 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 600 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 601 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 602 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 603 | |
| 604 | /* Adding Exclusion filter done */ |
| 605 | |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 606 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 607 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 608 | if ( res >= 0 ) |
| 609 | printf("Interest sending Successfull .... \n"); |
akmhoque | 37e3adf | 2012-08-14 15:52:50 -0500 | [diff] [blame] | 610 | ccn_charbuf_destroy(&c); |
akmhoque | 7f33727 | 2012-08-14 15:16:30 -0500 | [diff] [blame] | 611 | ccn_charbuf_destroy(&templ); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 612 | ccn_charbuf_destroy(&name); |
| 613 | |
akmhoque | 1d7343f | 2012-08-21 10:46:35 -0400 | [diff] [blame] | 614 | hashtb_next(e); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | hashtb_end(e); |
| 618 | |
akmhoque | bf11b1d | 2012-08-16 11:11:17 -0500 | [diff] [blame] | 619 | 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] | 620 | |
| 621 | return 0; |
| 622 | |
| 623 | } |
| 624 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 625 | |
| 626 | int |
| 627 | send_info_interest(struct ccn_schedule *sched, void *clienth, |
| 628 | struct ccn_scheduled_event *ev, int flags) |
| 629 | { |
| 630 | |
| 631 | struct ccn_charbuf *name; |
| 632 | long int rnum; |
| 633 | char rnumstr[20]; |
| 634 | char info_str[5]; |
| 635 | char nlsr_str[5]; |
| 636 | |
| 637 | int res,i; |
| 638 | int adl_element; |
| 639 | int scope = 2; //no further than the next host |
| 640 | |
| 641 | rnum=random(); |
| 642 | memset(&rnumstr,0,20); |
| 643 | sprintf(rnumstr,"%ld",rnum); |
| 644 | memset(&nlsr_str,0,5); |
| 645 | sprintf(nlsr_str,"nlsr"); |
| 646 | memset(&info_str,0,5); |
| 647 | sprintf(info_str,"info"); |
| 648 | |
| 649 | |
| 650 | struct ndn_neighbor *nbr; |
| 651 | |
| 652 | struct hashtb_enumerator ee; |
| 653 | struct hashtb_enumerator *e = ⅇ |
| 654 | |
| 655 | hashtb_start(nlsr->adl, e); |
| 656 | adl_element=hashtb_n(nlsr->adl); |
| 657 | //int mynumber=15; |
| 658 | |
| 659 | for(i=0;i<adl_element;i++) |
| 660 | { |
| 661 | nbr=e->data; |
| 662 | printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str); |
| 663 | name=ccn_charbuf_create(); |
| 664 | res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor)); |
| 665 | ccn_name_append_str(name,nlsr_str); |
| 666 | ccn_name_append_str(name,info_str); |
| 667 | //ccn_name_append_str(name,rnumstr); |
| 668 | |
| 669 | /* adding Exclusion filter */ |
| 670 | |
| 671 | struct ccn_charbuf *templ; |
| 672 | templ = ccn_charbuf_create(); |
| 673 | |
| 674 | // struct ccn_charbuf *c; |
| 675 | // c = ccn_charbuf_create(); |
| 676 | |
| 677 | |
| 678 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 679 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 680 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 681 | // ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 682 | // ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 683 | // ccn_charbuf_reset(c); |
| 684 | // //ccn_charbuf_putf(c, "%u", (unsigned)mynumber); |
| 685 | // //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version); |
| 686 | // ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version); |
| 687 | // ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 688 | // ccn_charbuf_append_closer(templ); /* </Exclude> */ |
| 689 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 690 | appendLifetime(templ,nlsr->interest_resend_time); |
| 691 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 692 | |
| 693 | |
| 694 | /* Adding Exclusion filter done */ |
| 695 | |
| 696 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 697 | |
| 698 | if ( res >= 0 ) |
| 699 | printf("Interest sending Successfull .... \n"); |
| 700 | // ccn_charbuf_destroy(&c); |
| 701 | ccn_charbuf_destroy(&templ); |
| 702 | ccn_charbuf_destroy(&name); |
| 703 | |
| 704 | hashtb_next(e); |
| 705 | } |
| 706 | |
| 707 | hashtb_end(e); |
| 708 | |
| 709 | //nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0); |
| 710 | |
| 711 | return 0; |
| 712 | |
| 713 | } |
| 714 | |
| 715 | |
| 716 | void |
| 717 | send_info_interest_to_neighbor(struct ccn_charbuf *nbr) |
| 718 | { |
| 719 | |
| 720 | struct ccn_charbuf *name; |
| 721 | long int rnum; |
| 722 | char rnumstr[20]; |
| 723 | char info_str[5]; |
| 724 | char nlsr_str[5]; |
| 725 | |
| 726 | int res; |
| 727 | int scope = 2; //no further than the next host |
| 728 | |
| 729 | rnum=random(); |
| 730 | memset(&rnumstr,0,20); |
| 731 | sprintf(rnumstr,"%ld",rnum); |
| 732 | memset(&nlsr_str,0,5); |
| 733 | sprintf(nlsr_str,"nlsr"); |
| 734 | memset(&info_str,0,5); |
| 735 | sprintf(info_str,"info"); |
| 736 | |
| 737 | printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str); |
| 738 | name=ccn_charbuf_create(); |
| 739 | res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr)); |
| 740 | ccn_name_append_str(name,nlsr_str); |
| 741 | ccn_name_append_str(name,info_str); |
| 742 | //ccn_name_append_str(name,rnumstr); |
| 743 | |
| 744 | /* adding Exclusion filter */ |
| 745 | |
| 746 | struct ccn_charbuf *templ; |
| 747 | templ = ccn_charbuf_create(); |
| 748 | |
| 749 | // struct ccn_charbuf *c; |
| 750 | // c = ccn_charbuf_create(); |
| 751 | |
| 752 | |
| 753 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 754 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 755 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 756 | // ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 757 | // ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 758 | // ccn_charbuf_reset(c); |
| 759 | // //ccn_charbuf_putf(c, "%u", (unsigned)mynumber); |
| 760 | // //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version); |
| 761 | // ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version); |
| 762 | // ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 763 | // ccn_charbuf_append_closer(templ); /* </Exclude> */ |
| 764 | ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 765 | appendLifetime(templ,15); |
| 766 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 767 | |
| 768 | |
| 769 | /* Adding Exclusion filter done */ |
| 770 | |
| 771 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 772 | |
| 773 | if ( res >= 0 ) |
| 774 | printf("Interest sending Successfull .... \n"); |
| 775 | // ccn_charbuf_destroy(&c); |
| 776 | ccn_charbuf_destroy(&templ); |
| 777 | ccn_charbuf_destroy(&name); |
| 778 | |
| 779 | } |