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