akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
| 20 | #include "nlsr.h" |
| 21 | #include "nlsr_ndn.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 22 | #include "nlsr_npl.h" |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 23 | #include "nlsr_adl.h" |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 24 | #include "nlsr_lsdb.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 25 | #include "utility.h" |
| 26 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 27 | int |
| 28 | appendLifetime(struct ccn_charbuf *cb, int lifetime) |
| 29 | { |
| 30 | unsigned char buf[sizeof(int32_t)]; |
| 31 | int32_t dreck = lifetime << 12; |
| 32 | int pos = sizeof(int32_t); |
| 33 | int res = 0; |
| 34 | while (dreck > 0 && pos > 0) |
| 35 | { |
| 36 | pos--; |
| 37 | buf[pos] = dreck & 255; |
| 38 | dreck = dreck >> 8; |
| 39 | } |
| 40 | res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos, sizeof(buf)-pos); |
| 41 | return res; |
| 42 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 43 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 44 | |
| 45 | void |
| 46 | get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 47 | { |
| 48 | |
| 49 | printf("get_nbr called\n"); |
| 50 | int res,i; |
| 51 | int nlsr_position=0; |
| 52 | int name_comps=(int)info->interest_comps->n; |
| 53 | int len=0; |
| 54 | |
| 55 | for(i=0;i<name_comps;i++) |
| 56 | { |
| 57 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 58 | if( res == 0) |
| 59 | { |
| 60 | nlsr_position=i; |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | |
| 66 | const unsigned char *comp_ptr1; |
| 67 | size_t comp_size; |
| 68 | for(i=0;i<nlsr_position;i++) |
| 69 | { |
| 70 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 71 | len+=1; |
| 72 | len+=(int)comp_size; |
| 73 | } |
| 74 | len++; |
| 75 | |
| 76 | char *neighbor=(char *)malloc(len); |
| 77 | memset(neighbor,0,len); |
| 78 | |
| 79 | for(i=0; i<nlsr_position;i++) |
| 80 | { |
| 81 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 82 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 83 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 84 | |
| 85 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 86 | |
| 87 | nbr->name=(char *)malloc(strlen(neighbor)+1); |
| 88 | memcpy(nbr->name,neighbor,strlen(neighbor)+1); |
| 89 | nbr->length=strlen(neighbor)+1; |
| 90 | |
| 91 | printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length); |
| 92 | |
| 93 | |
| 94 | } |
| 95 | |
| 96 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 97 | get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info, int offset) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 98 | { |
| 99 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 100 | printf("get_lsa_identifier called\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 101 | int res,i; |
| 102 | int nlsr_position=0; |
| 103 | int name_comps=(int)info->interest_comps->n; |
| 104 | int len=0; |
| 105 | |
| 106 | for(i=0;i<name_comps;i++) |
| 107 | { |
| 108 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 109 | if( res == 0) |
| 110 | { |
| 111 | nlsr_position=i; |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | |
| 117 | const unsigned char *comp_ptr1; |
| 118 | size_t comp_size; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 119 | for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 120 | { |
| 121 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 122 | len+=1; |
| 123 | len+=(int)comp_size; |
| 124 | } |
| 125 | len++; |
| 126 | |
| 127 | char *neighbor=(char *)malloc(len); |
| 128 | memset(neighbor,0,len); |
| 129 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 130 | for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 131 | { |
| 132 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size); |
| 133 | memcpy(neighbor+strlen(neighbor),"/",1); |
| 134 | memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1)); |
| 135 | |
| 136 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 137 | |
| 138 | lsaId->name=(char *)malloc(strlen(neighbor)+1); |
| 139 | memset(lsaId->name,0,strlen(neighbor)+1); |
| 140 | memcpy(lsaId->name,neighbor,strlen(neighbor)+1); |
| 141 | lsaId->length=strlen(neighbor)+1; |
| 142 | |
| 143 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 144 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 145 | |
| 146 | } |
| 147 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 148 | int |
| 149 | get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 150 | { |
| 151 | int res,i; |
| 152 | int nlsr_position=0; |
| 153 | int name_comps=(int)info->interest_comps->n; |
| 154 | |
| 155 | int ret=0; |
| 156 | |
| 157 | for(i=0;i<name_comps;i++) |
| 158 | { |
| 159 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 160 | if( res == 0) |
| 161 | { |
| 162 | nlsr_position=i; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | |
| 168 | const unsigned char *comp_ptr1; |
| 169 | size_t comp_size; |
| 170 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size); |
| 171 | |
| 172 | ret=atoi((char *)comp_ptr1); |
| 173 | |
| 174 | return ret; |
| 175 | |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info ) |
| 180 | { |
| 181 | const unsigned char *comp_ptr1; |
| 182 | size_t comp_size; |
| 183 | ccn_name_comp_get(info->content_ccnb, info->content_comps,info->content_comps->n-2,&comp_ptr1, &comp_size); |
| 184 | memcpy(lsdb_version,(char *)comp_ptr1,(int)comp_size); |
| 185 | |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /* Call back function registered in ccnd to get all interest coming to NLSR application */ |
| 190 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 191 | enum ccn_upcall_res |
| 192 | incoming_interest(struct ccn_closure *selfp, |
| 193 | enum ccn_upcall_kind kind, struct ccn_upcall_info *info) |
| 194 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 195 | |
| 196 | nlsr_lock(); |
| 197 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 198 | switch (kind) { |
| 199 | case CCN_UPCALL_FINAL: |
| 200 | break; |
| 201 | case CCN_UPCALL_INTEREST: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 202 | // printing the name prefix for which it received interest |
| 203 | printf("Interest Received for name: "); |
| 204 | struct ccn_charbuf*c; |
| 205 | c=ccn_charbuf_create(); |
| 206 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0); |
| 207 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 208 | ccn_charbuf_destroy(&c); |
| 209 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 210 | process_incoming_interest(selfp, info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 211 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 212 | break; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 213 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 214 | default: |
| 215 | break; |
| 216 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 217 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 218 | nlsr_unlock(); |
| 219 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 220 | return CCN_UPCALL_RESULT_OK; |
| 221 | } |
| 222 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 223 | /* Function for processing incoming interest and reply with content/NACK content */ |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 224 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 225 | void |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 226 | process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 227 | { |
| 228 | printf("process_incoming_interest called \n"); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 229 | const unsigned char *comp_ptr1; |
| 230 | size_t comp_size; |
| 231 | int res,i; |
| 232 | int nlsr_position=0; |
| 233 | int name_comps=(int)info->interest_comps->n; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 234 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 235 | for(i=0;i<name_comps;i++) |
| 236 | { |
| 237 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 238 | if( res == 0) |
| 239 | { |
akmhoque | ea3603e | 2012-08-13 11:24:09 -0500 | [diff] [blame] | 240 | nlsr_position=i; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 241 | break; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 246 | |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 247 | printf("Det= %s \n",comp_ptr1); |
| 248 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 249 | if(!strcmp((char *)comp_ptr1,"info")) |
| 250 | { |
| 251 | process_incoming_interest_info(selfp,info); |
| 252 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 253 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 254 | { |
| 255 | process_incoming_interest_lsdb(selfp,info); |
| 256 | } |
| 257 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 258 | { |
| 259 | process_incoming_interest_lsa(selfp,info); |
| 260 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void |
| 264 | process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 265 | { |
| 266 | printf("process_incoming_interest_info called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 267 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 268 | printf("Sending Info Content back.....\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 269 | int res; |
| 270 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 271 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 272 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 273 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 274 | res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]); |
| 275 | if (res >= 0) |
| 276 | { |
| 277 | sp.template_ccnb=ccn_charbuf_create(); |
| 278 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 279 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 280 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 281 | ccn_charbuf_append_closer(sp.template_ccnb); |
| 282 | |
| 283 | |
| 284 | char *raw_data=(char *)malloc(16); |
| 285 | memset(raw_data,0,16); |
| 286 | sprintf(raw_data,"%ld", nlsr->lsdb_synch_interval); |
| 287 | |
| 288 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data)); |
| 289 | if(res >= 0) |
| 290 | printf("Signing Content is successful \n"); |
| 291 | |
| 292 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 293 | if(res >= 0) |
| 294 | printf("Sending Info Content is successful \n"); |
| 295 | |
| 296 | printf("Info Content sending done....\n"); |
| 297 | |
| 298 | |
| 299 | struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 300 | get_lsa_identifier(nbr,selfp,info,-1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 301 | printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 302 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 303 | |
| 304 | if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry ) |
| 305 | { |
| 306 | send_info_interest_to_neighbor(nbr); |
| 307 | } |
| 308 | |
| 309 | free(nbr); |
| 310 | free(raw_data); |
| 311 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 312 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 313 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 314 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 315 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 316 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | |
| 320 | void |
| 321 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 322 | { |
| 323 | printf("process_incoming_interest_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 324 | |
| 325 | int l,res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 326 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 327 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 328 | struct ccn_buf_decoder decoder; |
| 329 | struct ccn_buf_decoder *d; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 330 | const unsigned char *comp; |
| 331 | int dbcmp=0; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 332 | |
| 333 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 334 | if (l > 0) |
| 335 | { |
| 336 | comp = NULL; |
| 337 | size = 0; |
| 338 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 339 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 340 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 341 | { |
| 342 | ccn_buf_advance(d); |
| 343 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 344 | ccn_buf_advance_past_element(d); |
| 345 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 346 | { |
| 347 | ccn_buf_advance(d); |
| 348 | ccn_buf_match_blob(d, &comp, &size); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 349 | ccn_buf_check_close(d); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 350 | |
| 351 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 352 | } |
| 353 | ccn_buf_check_close(d); |
| 354 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 355 | if (comp != NULL) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 356 | { |
| 357 | printf("LSDB Version in Exclusion Filter is %s\n",comp); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 358 | printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 359 | dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 360 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 361 | /* Now comp points to the start of your potential number, and size is its length */ |
| 362 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 363 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 364 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 365 | printf("LSDB Version in Exclusion Filter is: None Added\n"); |
| 366 | dbcmp=1; |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 367 | |
| 368 | } |
| 369 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 370 | struct ccn_charbuf *data=ccn_charbuf_create(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 371 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 372 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 373 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 374 | 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 | 887fc0c | 2012-08-27 15:06:06 -0500 | [diff] [blame] | 375 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 376 | sp.template_ccnb=ccn_charbuf_create(); |
| 377 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 378 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 379 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 380 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 381 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 382 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 383 | if(dbcmp>0) |
| 384 | { |
| 385 | printf("Has Updated Database than Neighbor\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 386 | printf("Sending LSDB Summary of Updated LSDB Content...\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 387 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 388 | ccn_name_append_str(name,nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 389 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 390 | struct ccn_charbuf *lsdb_data=ccn_charbuf_create(); |
| 391 | get_lsdb_summary(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 392 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 393 | char *raw_data=ccn_charbuf_as_string(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 394 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 395 | //printf("Content Data to be sent: %s \n",raw_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 396 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 397 | if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 398 | { |
| 399 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT")); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 404 | } |
| 405 | if(res >= 0) |
| 406 | printf("Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 407 | |
| 408 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 409 | |
| 410 | if(res >= 0) |
| 411 | printf("Sending LSDB Summary of Updated LSDB Content is successful \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 412 | |
| 413 | ccn_charbuf_destroy(&lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 414 | } |
| 415 | else |
| 416 | { |
| 417 | printf("Does not have Updated Database than Neighbor\n"); |
| 418 | |
| 419 | printf("Sending NACK Content.....\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 420 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
| 421 | if(res >= 0) |
| 422 | printf("Signing NACK Content is successful \n"); |
| 423 | |
| 424 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 425 | |
| 426 | if(res >= 0) |
| 427 | printf("Sending NACK Content is successful \n"); |
| 428 | |
| 429 | |
| 430 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 431 | |
| 432 | ccn_charbuf_destroy(&data); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 433 | ccn_charbuf_destroy(&name); |
| 434 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 435 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 436 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 437 | } |
| 438 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 439 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 440 | void |
| 441 | process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 442 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 443 | printf("process_incoming_interest_lsa called \n"); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 444 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 445 | int res; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 446 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 447 | struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 448 | get_lsa_identifier(lsaId,selfp,info,0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 449 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 450 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length); |
| 451 | int ls_type=get_ls_type(selfp, info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 452 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 453 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 454 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 455 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 456 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 457 | printf("Interest Received for NAME LSA\n"); |
| 458 | get_name_lsa_data(lsa_data,lsaId); |
| 459 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 460 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 461 | { |
| 462 | printf("Interest Received for ADJ LSA\n"); |
| 463 | get_adj_lsa_data(lsa_data,lsaId); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 464 | } |
| 465 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 466 | char *rdata=ccn_charbuf_as_string(lsa_data); |
| 467 | char *raw_data=(char *)malloc(strlen(rdata)+1); |
| 468 | memset(raw_data,0,strlen(rdata)+1); |
| 469 | memcpy(raw_data,(char *)rdata,strlen(rdata)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 470 | //printf("Content Data to be sent: %s\n",raw_data); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 471 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 472 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 473 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 474 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 475 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 476 | 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 | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 477 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 478 | sp.template_ccnb=ccn_charbuf_create(); |
| 479 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 480 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 481 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 482 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 483 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 484 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 485 | if(res >= 0) |
| 486 | printf("Signing LSA Content is successful \n"); |
| 487 | |
| 488 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 489 | if(res >= 0) |
| 490 | printf("Sending LSA Content is successful \n"); |
| 491 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 492 | |
| 493 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 494 | ccn_charbuf_destroy(&data); |
| 495 | ccn_charbuf_destroy(&name); |
| 496 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 497 | ccn_charbuf_destroy(&lsa_data); |
| 498 | |
| 499 | free(raw_data); |
| 500 | free(lsaId); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 501 | } |
| 502 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 503 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 504 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 505 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 506 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 507 | { |
| 508 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 509 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 510 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 511 | switch(kind) { |
| 512 | case CCN_UPCALL_FINAL: |
| 513 | break; |
| 514 | case CCN_UPCALL_CONTENT: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 515 | printf("Content Received for Name: "); |
| 516 | struct ccn_charbuf*c; |
| 517 | c=ccn_charbuf_create(); |
| 518 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 519 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 520 | ccn_charbuf_destroy(&c); |
| 521 | |
| 522 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 523 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 524 | break; |
| 525 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 526 | printf("Interest Timed Out Received for Name: "); |
| 527 | |
| 528 | struct ccn_charbuf*ito; |
| 529 | ito=ccn_charbuf_create(); |
| 530 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 531 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 532 | ccn_charbuf_destroy(&ito); |
| 533 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 534 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 535 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 536 | break; |
| 537 | default: |
| 538 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 539 | //return CCN_UPCALL_RESULT_ERR; |
| 540 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 541 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 542 | |
| 543 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 544 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 545 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 546 | } |
| 547 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 548 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 549 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 550 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 551 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 552 | printf("process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 553 | |
| 554 | const unsigned char *comp_ptr1; |
| 555 | size_t comp_size; |
| 556 | int res,i; |
| 557 | int nlsr_position=0; |
| 558 | int name_comps=(int)info->interest_comps->n; |
| 559 | |
| 560 | for(i=0;i<name_comps;i++) |
| 561 | { |
| 562 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 563 | if( res == 0) |
| 564 | { |
| 565 | nlsr_position=i; |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 571 | |
| 572 | printf("Det= %s \n",comp_ptr1); |
| 573 | |
| 574 | if(!strcmp((char *)comp_ptr1,"info")) |
| 575 | { |
| 576 | process_incoming_content_info(selfp,info); |
| 577 | } |
| 578 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 579 | { |
| 580 | process_incoming_content_lsdb(selfp,info); |
| 581 | } |
| 582 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 583 | { |
| 584 | process_incoming_content_lsa(selfp,info); |
| 585 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 586 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 587 | } |
| 588 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 589 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 590 | void |
| 591 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 592 | { |
| 593 | printf("process_incoming_content_info called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 594 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 595 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 596 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 597 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 598 | printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 599 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 600 | |
| 601 | const unsigned char *ptr; |
| 602 | size_t length; |
| 603 | ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 604 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 605 | |
| 606 | long int interval=atoi((char *)ptr); |
| 607 | |
| 608 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 609 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 610 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 611 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 612 | update_lsdb_synch_interval_to_adl(nbr,interval); |
| 613 | print_adjacent_from_adl(); |
| 614 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 615 | |
| 616 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 617 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 618 | { |
| 619 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 620 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 621 | nlsr->is_build_adj_lsa_sheduled=1; |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | printf("Build and Install Adj LSA already scheduled\n"); |
| 626 | } |
| 627 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 628 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 629 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 630 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 631 | |
| 632 | } |
| 633 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 634 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 635 | void |
| 636 | process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 637 | { |
| 638 | printf("process_incoming_content_lsdb called \n"); |
| 639 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 640 | const unsigned char *ptr; |
| 641 | size_t length; |
| 642 | ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 643 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 644 | |
| 645 | if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) ) |
| 646 | { |
| 647 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 648 | get_nbr(nbr,selfp,info); |
| 649 | |
| 650 | char *nl; |
| 651 | int num_element; |
| 652 | int i; |
| 653 | char *rem; |
| 654 | const char *sep="|"; |
| 655 | char *orig_router; |
| 656 | char *lst; |
| 657 | int ls_type; |
| 658 | char *lsid; |
| 659 | long int ls_id; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 660 | char *orig_time; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 661 | |
| 662 | nl=strtok_r((char *)ptr,sep,&rem); |
| 663 | num_element=atoi(nl); |
| 664 | |
| 665 | for(i = 0 ; i < num_element ; i++) |
| 666 | { |
| 667 | orig_router=strtok_r(NULL,sep,&rem); |
| 668 | lst=strtok_r(NULL,sep,&rem); |
| 669 | ls_type=atoi(lst); |
| 670 | printf("Orig Router: %s ls Type: %d",orig_router,ls_type); |
| 671 | |
| 672 | if(ls_type == LS_TYPE_NAME) |
| 673 | { |
| 674 | lsid=strtok_r(NULL,sep,&rem); |
| 675 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 676 | orig_time=strtok_r(NULL,sep,&rem); |
| 677 | printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time); |
| 678 | int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time); |
| 679 | if ( is_new_name_lsa == 1 ) |
| 680 | { |
| 681 | printf("New NAME LSA.....\n"); |
| 682 | send_interest_for_name_lsa(nbr,orig_router,lst,lsid); |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | printf("Name LSA already exists in LSDB\n"); |
| 687 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 688 | } |
| 689 | else |
| 690 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 691 | orig_time=strtok_r(NULL,sep,&rem); |
| 692 | printf(" Orig Time: %s\n",orig_time); |
| 693 | int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time); |
| 694 | if ( is_new_adj_lsa == 1 ) |
| 695 | { |
| 696 | printf("New ADJ LSA.....\n"); |
| 697 | send_interest_for_adj_lsa(nbr,orig_router,lst); |
| 698 | } |
| 699 | else |
| 700 | { |
| 701 | printf("ADJ LSA already exists in LSDB\n"); |
| 702 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 703 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 704 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 705 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 707 | char *lsdb_version=(char *)malloc(20); |
| 708 | memset(lsdb_version,0,20); |
| 709 | get_lsdb_version(lsdb_version,selfp,info); |
| 710 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 711 | printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 712 | update_adjacent_lsdb_version_to_adl(nbr,lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 713 | printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 714 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 715 | |
| 716 | free(lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 717 | free(nbr); |
| 718 | } |
| 719 | else if (strcmp("WAIT",(char *)ptr) == 0) |
| 720 | { |
| 721 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 722 | get_nbr(nbr,selfp,info); |
| 723 | long int interval=get_lsdb_synch_interval(nbr->name); |
| 724 | adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 725 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 726 | |
| 727 | free(nbr); |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | printf("NACK Content Received\n"); |
| 732 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 733 | } |
| 734 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 735 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 736 | void |
| 737 | process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 738 | { |
| 739 | printf("process_incoming_content_lsa called \n"); |
| 740 | |
| 741 | char *sep="|"; |
| 742 | char *rem; |
| 743 | char *orig_router; |
| 744 | char *orl; |
| 745 | int orig_router_length; |
| 746 | char *lst; |
| 747 | int ls_type; |
| 748 | char *lsid; |
| 749 | long int ls_id; |
| 750 | char *isvld; |
| 751 | int isValid; |
| 752 | char *num_link; |
| 753 | int no_link; |
| 754 | char *np; |
| 755 | char *np_length; |
| 756 | int name_length; |
| 757 | char *data; |
| 758 | char *orig_time; |
| 759 | |
| 760 | const unsigned char *ptr; |
| 761 | size_t length; |
| 762 | ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 763 | //printf("Content data Received: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 764 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 770 | printf("LSA Data\n"); |
| 771 | |
| 772 | if( strlen((char *) ptr ) > 0 ) |
| 773 | { |
| 774 | |
| 775 | orig_router=strtok_r((char *)ptr,sep,&rem); |
| 776 | orl=strtok_r(NULL,sep,&rem); |
| 777 | orig_router_length=atoi(orl); |
| 778 | |
| 779 | printf(" Orig Router Name : %s\n",orig_router); |
| 780 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 781 | |
| 782 | lst=strtok_r(NULL,sep,&rem); |
| 783 | ls_type=atoi(lst); |
| 784 | |
| 785 | printf(" LS Type : %d\n",ls_type); |
| 786 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 787 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 788 | { |
| 789 | lsid=strtok_r(NULL,sep,&rem); |
| 790 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 791 | orig_time=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 792 | isvld=strtok_r(NULL,sep,&rem); |
| 793 | isValid=atoi(isvld); |
| 794 | np=strtok_r(NULL,sep,&rem); |
| 795 | np_length=strtok_r(NULL,sep,&rem); |
| 796 | name_length=atoi(np_length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 797 | printf(" LS ID : %ld\n",ls_id); |
| 798 | printf(" isValid : %d\n",isValid); |
| 799 | printf(" Name Prefix : %s\n",np); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 800 | printf(" Orig Time : %s\n",orig_time); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 801 | printf(" Name Prefix length: %d\n",name_length); |
| 802 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 803 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np); |
| 804 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 805 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 806 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 807 | { |
| 808 | orig_time=strtok_r(NULL,sep,&rem); |
| 809 | num_link=strtok_r(NULL,sep,&rem); |
| 810 | no_link=atoi(num_link); |
| 811 | data=rem; |
| 812 | |
| 813 | printf(" No Link : %d\n",no_link); |
| 814 | printf(" Data : %s\n",data); |
| 815 | |
| 816 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data); |
| 817 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 818 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 819 | } |
| 820 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 821 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 822 | void |
| 823 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 824 | { |
| 825 | printf("process_incoming_timed_out_interest called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 826 | int res,i; |
| 827 | int nlsr_position=0; |
| 828 | int name_comps=(int)info->interest_comps->n; |
| 829 | |
| 830 | for(i=0;i<name_comps;i++) |
| 831 | { |
| 832 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 833 | if( res == 0) |
| 834 | { |
| 835 | nlsr_position=i; |
| 836 | break; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 841 | { |
| 842 | process_incoming_timed_out_interest_info(selfp,info); |
| 843 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 844 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0) |
| 845 | { |
| 846 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 847 | } |
| 848 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsa") == 0) |
| 849 | { |
| 850 | process_incoming_timed_out_interest_lsa(selfp,info); |
| 851 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | void |
| 855 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 856 | { |
| 857 | printf("process_incoming_timed_out_interest_info called \n"); |
| 858 | |
| 859 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 860 | get_nbr(nbr,selfp,info); |
| 861 | |
| 862 | printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 863 | |
| 864 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 865 | update_adjacent_timed_out_to_adl(nbr,1); |
| 866 | print_adjacent_from_adl(); |
| 867 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 868 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 869 | |
| 870 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 871 | { |
| 872 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 873 | send_info_interest_to_neighbor(nbr); |
| 874 | } |
| 875 | else |
| 876 | { |
| 877 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 878 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 879 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 880 | { |
| 881 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 882 | nlsr->is_build_adj_lsa_sheduled=1; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 887 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 888 | |
| 889 | } |
| 890 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 891 | void |
| 892 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 893 | { |
| 894 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
| 895 | } |
| 896 | |
| 897 | void |
| 898 | process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 899 | { |
| 900 | printf("process_incoming_timed_out_interest_lsa called \n"); |
| 901 | |
| 902 | } |
| 903 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 904 | int |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 905 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 906 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 907 | if(flags == CCN_SCHEDULE_CANCEL) |
| 908 | { |
| 909 | return -1; |
| 910 | } |
| 911 | |
| 912 | nlsr_lock(); |
| 913 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 914 | printf("send_info_interest called \n"); |
| 915 | printf("\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 916 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 917 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 918 | struct ndn_neighbor *nbr; |
| 919 | |
| 920 | struct hashtb_enumerator ee; |
| 921 | struct hashtb_enumerator *e = ⅇ |
| 922 | |
| 923 | hashtb_start(nlsr->adl, e); |
| 924 | adl_element=hashtb_n(nlsr->adl); |
| 925 | |
| 926 | for(i=0;i<adl_element;i++) |
| 927 | { |
| 928 | nbr=e->data; |
| 929 | send_info_interest_to_neighbor(nbr->neighbor); |
| 930 | hashtb_next(e); |
| 931 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 932 | hashtb_end(e); |
| 933 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 934 | nlsr_unlock(); |
| 935 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | void |
| 940 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 941 | { |
| 942 | printf("send_info_interest_to_neighbor called \n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 943 | |
| 944 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 945 | char info_str[5]; |
| 946 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 947 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 948 | memset(&nlsr_str,0,5); |
| 949 | sprintf(nlsr_str,"nlsr"); |
| 950 | memset(&info_str,0,5); |
| 951 | sprintf(info_str,"info"); |
| 952 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 953 | |
| 954 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 955 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 956 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 957 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 958 | memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 959 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 960 | memcpy(int_name+strlen(int_name),"/",1); |
| 961 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 962 | memcpy(int_name+strlen(int_name),"/",1); |
| 963 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 964 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 965 | |
| 966 | |
| 967 | res=ccn_name_from_uri(name,int_name); |
| 968 | if ( res >=0 ) |
| 969 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 970 | /* adding InterestLifeTime and InterestScope filter */ |
| 971 | |
| 972 | struct ccn_charbuf *templ; |
| 973 | templ = ccn_charbuf_create(); |
| 974 | |
| 975 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 976 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 977 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 978 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 979 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 980 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 981 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 982 | |
| 983 | appendLifetime(templ,nlsr->interest_resend_time); |
| 984 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 985 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 986 | |
| 987 | printf("Sending info interest on name prefix : %s \n",int_name); |
| 988 | |
| 989 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 990 | |
| 991 | if ( res >= 0 ) |
| 992 | printf("Info interest sending Successfull .... \n"); |
| 993 | ccn_charbuf_destroy(&templ); |
| 994 | } |
| 995 | ccn_charbuf_destroy(&name); |
| 996 | free(int_name); |
| 997 | |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | int |
| 1002 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1003 | { |
| 1004 | printf("send_lsdb_interest called \n"); |
| 1005 | |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1006 | if(flags == CCN_SCHEDULE_CANCEL) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1007 | { |
| 1008 | return -1; |
| 1009 | } |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1010 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1011 | nlsr_lock(); |
| 1012 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1013 | int i, adl_element; |
| 1014 | struct ndn_neighbor *nbr; |
| 1015 | |
| 1016 | struct hashtb_enumerator ee; |
| 1017 | struct hashtb_enumerator *e = ⅇ |
| 1018 | |
| 1019 | hashtb_start(nlsr->adl, e); |
| 1020 | adl_element=hashtb_n(nlsr->adl); |
| 1021 | |
| 1022 | for(i=0;i<adl_element;i++) |
| 1023 | { |
| 1024 | nbr=e->data; |
| 1025 | |
| 1026 | if(nbr->status == NBR_ACTIVE) |
| 1027 | { |
| 1028 | if(nbr->is_lsdb_send_interest_scheduled == 0) |
| 1029 | { |
| 1030 | long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name); |
| 1031 | printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1032 | |
| 1033 | if(time_diff>=get_lsdb_synch_interval(nbr->neighbor->name)) |
| 1034 | { |
| 1035 | nbr->is_lsdb_send_interest_scheduled=1; |
| 1036 | send_lsdb_interest_to_nbr(nbr->neighbor); |
| 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | hashtb_next(e); |
| 1041 | } |
| 1042 | |
| 1043 | hashtb_end(e); |
| 1044 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0); |
| 1045 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1046 | nlsr_unlock(); |
| 1047 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | void |
| 1052 | send_lsdb_interest_to_nbr(struct name_prefix *nbr) |
| 1053 | { |
| 1054 | printf("send_lsdb_interest_to_nbr called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1055 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1056 | char *last_lsdb_version=get_nbr_lsdb_version(nbr->name); |
| 1057 | |
| 1058 | if(last_lsdb_version !=NULL) |
| 1059 | { |
| 1060 | printf("Last LSDB Version: %s \n",last_lsdb_version); |
| 1061 | |
| 1062 | |
| 1063 | struct ccn_charbuf *name; |
| 1064 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1065 | char lsdb_str[5]; |
| 1066 | char nlsr_str[5]; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1067 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1068 | memset(&nlsr_str,0,5); |
| 1069 | sprintf(nlsr_str,"nlsr"); |
| 1070 | memset(&lsdb_str,0,5); |
| 1071 | sprintf(lsdb_str,"lsdb"); |
| 1072 | //make and send interest with exclusion filter as last_lsdb_version |
| 1073 | printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1074 | name=ccn_charbuf_create(); |
| 1075 | res=ccn_name_from_uri(name,nbr->name); |
| 1076 | |
| 1077 | if( res >= 0) |
| 1078 | { |
| 1079 | ccn_name_append_str(name,nlsr_str); |
| 1080 | ccn_name_append_str(name,lsdb_str); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1081 | /* adding Exclusion filter */ |
| 1082 | |
| 1083 | struct ccn_charbuf *templ; |
| 1084 | templ = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1085 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1086 | struct ccn_charbuf *c; |
| 1087 | c = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1088 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1089 | |
| 1090 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1091 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1092 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1093 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 1094 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 1095 | ccn_charbuf_reset(c); |
| 1096 | ccn_charbuf_putf(c, "%s", last_lsdb_version); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1097 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1098 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 1099 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
| 1100 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1101 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1102 | ccn_charbuf_append(templ, "2", 1); |
| 1103 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1104 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1105 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1106 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1107 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1108 | |
| 1109 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1110 | /* Adding Exclusion filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1111 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1112 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1113 | |
| 1114 | if ( res >= 0 ) |
| 1115 | { |
| 1116 | printf("Interest sending Successfull .... \n"); |
| 1117 | update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec()); |
| 1118 | |
| 1119 | } |
| 1120 | ccn_charbuf_destroy(&c); |
| 1121 | ccn_charbuf_destroy(&templ); |
| 1122 | } |
| 1123 | ccn_charbuf_destroy(&name); |
| 1124 | } |
| 1125 | set_is_lsdb_send_interest_scheduled_to_zero(nbr->name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | void |
| 1129 | send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id) |
| 1130 | { |
| 1131 | printf("send_interest_for_name_lsa called\n"); |
| 1132 | |
| 1133 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1134 | char lsa_str[5]; |
| 1135 | char nlsr_str[5]; |
| 1136 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1137 | memset(&nlsr_str,0,5); |
| 1138 | sprintf(nlsr_str,"nlsr"); |
| 1139 | memset(&lsa_str,0,5); |
| 1140 | sprintf(lsa_str,"lsa"); |
| 1141 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1142 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3); |
| 1143 | memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1144 | |
| 1145 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1146 | memcpy(int_name+strlen(int_name),"/",1); |
| 1147 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1148 | memcpy(int_name+strlen(int_name),"/",1); |
| 1149 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1150 | memcpy(int_name+strlen(int_name),"/",1); |
| 1151 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
| 1152 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1153 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1154 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1155 | struct ccn_charbuf *name; |
| 1156 | name=ccn_charbuf_create(); |
| 1157 | |
| 1158 | |
| 1159 | res=ccn_name_from_uri(name,int_name); |
| 1160 | ccn_name_append_str(name,ls_type); |
| 1161 | ccn_name_append_str(name,ls_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1162 | |
| 1163 | |
| 1164 | /* adding InterestLifeTime and InterestScope filter */ |
| 1165 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1166 | struct ccn_charbuf *templ; |
| 1167 | templ = ccn_charbuf_create(); |
| 1168 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1169 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1170 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1171 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1172 | //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 1173 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1174 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1175 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1176 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1177 | |
| 1178 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1179 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1180 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1181 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1182 | printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1183 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1184 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1185 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1186 | if ( res >= 0 ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1187 | printf("NAME LSA interest sending Successfull .... \n"); |
| 1188 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1189 | ccn_charbuf_destroy(&templ); |
| 1190 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1191 | free(int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1192 | |
| 1193 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1194 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1195 | |
| 1196 | void |
| 1197 | send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type) |
| 1198 | { |
| 1199 | printf("send_interest_for_adj_lsa called\n"); |
| 1200 | |
| 1201 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1202 | char lsa_str[5]; |
| 1203 | char nlsr_str[5]; |
| 1204 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1205 | memset(&nlsr_str,0,5); |
| 1206 | sprintf(nlsr_str,"nlsr"); |
| 1207 | memset(&lsa_str,0,5); |
| 1208 | sprintf(lsa_str,"lsa"); |
| 1209 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1210 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1); |
| 1211 | memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1212 | |
| 1213 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1214 | memcpy(int_name+strlen(int_name),"/",1); |
| 1215 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1216 | memcpy(int_name+strlen(int_name),"/",1); |
| 1217 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1218 | memcpy(int_name+strlen(int_name),"/",1); |
| 1219 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1220 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1221 | memcpy(int_name+strlen(int_name),"/",1); |
| 1222 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1223 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1224 | struct ccn_charbuf *name; |
| 1225 | name=ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1226 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1227 | |
| 1228 | ccn_name_from_uri(name,int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1229 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1230 | /* adding InterestLifeTime and InterestScope filter */ |
| 1231 | |
| 1232 | struct ccn_charbuf *templ; |
| 1233 | templ = ccn_charbuf_create(); |
| 1234 | |
| 1235 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1236 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1237 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1238 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1239 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1240 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1241 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1242 | |
| 1243 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1244 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1245 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1246 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1247 | printf("Sending ADJ LSA interest on name prefix : %s\n",int_name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1248 | |
| 1249 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1250 | |
| 1251 | if ( res >= 0 ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1252 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1253 | printf("ADJ LSA interest sending Successfull .... \n"); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1254 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1255 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1256 | ccn_charbuf_destroy(&templ); |
| 1257 | ccn_charbuf_destroy(&name); |
| 1258 | free(int_name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1259 | } |