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 | { |
akmhoque | b819520 | 2012-09-25 11:53:23 -0500 | [diff] [blame] | 306 | update_adjacent_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 307 | send_info_interest_to_neighbor(nbr); |
| 308 | } |
| 309 | |
| 310 | free(nbr); |
| 311 | free(raw_data); |
| 312 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 313 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 314 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 315 | ccn_charbuf_destroy(&data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 316 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 317 | |
akmhoque | bf1aa83 | 2012-08-13 13:26:59 -0500 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | |
| 321 | void |
| 322 | process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
| 323 | { |
| 324 | printf("process_incoming_interest_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 325 | |
| 326 | int l,res; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 327 | const unsigned char *exclbase; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 328 | size_t size; |
akmhoque | fce8cfc | 2012-08-14 14:00:33 -0500 | [diff] [blame] | 329 | struct ccn_buf_decoder decoder; |
| 330 | struct ccn_buf_decoder *d; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 331 | const unsigned char *comp; |
| 332 | int dbcmp=0; |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 333 | |
| 334 | l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude]; |
| 335 | if (l > 0) |
| 336 | { |
| 337 | comp = NULL; |
| 338 | size = 0; |
| 339 | exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude]; |
| 340 | d = ccn_buf_decoder_start(&decoder, exclbase, l); |
| 341 | if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) |
| 342 | { |
| 343 | ccn_buf_advance(d); |
| 344 | if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) |
| 345 | ccn_buf_advance_past_element(d); |
| 346 | if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) |
| 347 | { |
| 348 | ccn_buf_advance(d); |
| 349 | ccn_buf_match_blob(d, &comp, &size); |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 350 | ccn_buf_check_close(d); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 351 | |
| 352 | |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 353 | } |
| 354 | ccn_buf_check_close(d); |
| 355 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 356 | if (comp != NULL) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 357 | { |
| 358 | printf("LSDB Version in Exclusion Filter is %s\n",comp); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 359 | printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version); |
| 360 | dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 361 | } |
akmhoque | 6d49e4d | 2012-08-14 13:49:30 -0500 | [diff] [blame] | 362 | /* Now comp points to the start of your potential number, and size is its length */ |
| 363 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 364 | else |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 365 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 366 | printf("LSDB Version in Exclusion Filter is: None Added\n"); |
| 367 | dbcmp=1; |
akmhoque | cb01775 | 2012-08-16 11:03:45 -0500 | [diff] [blame] | 368 | |
| 369 | } |
| 370 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 371 | struct ccn_charbuf *data=ccn_charbuf_create(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 372 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 373 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
| 374 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 375 | 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] | 376 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 377 | sp.template_ccnb=ccn_charbuf_create(); |
| 378 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 379 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 380 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 381 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 382 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 383 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 384 | if(dbcmp>0) |
| 385 | { |
| 386 | printf("Has Updated Database than Neighbor\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 387 | printf("Sending LSDB Summary of Updated LSDB Content...\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 388 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 389 | ccn_name_append_str(name,nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 390 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 391 | struct ccn_charbuf *lsdb_data=ccn_charbuf_create(); |
| 392 | get_lsdb_summary(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 393 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 394 | char *raw_data=ccn_charbuf_as_string(lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 395 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 396 | //printf("Content Data to be sent: %s \n",raw_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 397 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 398 | if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 399 | { |
| 400 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT")); |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 405 | } |
| 406 | if(res >= 0) |
| 407 | printf("Signing LSDB Summary of Updated LSDB Content is successful \n"); |
| 408 | |
| 409 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 410 | |
| 411 | if(res >= 0) |
| 412 | printf("Sending LSDB Summary of Updated LSDB Content is successful \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 413 | |
| 414 | ccn_charbuf_destroy(&lsdb_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 415 | } |
| 416 | else |
| 417 | { |
| 418 | printf("Does not have Updated Database than Neighbor\n"); |
| 419 | |
| 420 | printf("Sending NACK Content.....\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 421 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK")); |
| 422 | if(res >= 0) |
| 423 | printf("Signing NACK Content is successful \n"); |
| 424 | |
| 425 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 426 | |
| 427 | if(res >= 0) |
| 428 | printf("Sending NACK Content is successful \n"); |
| 429 | |
| 430 | |
| 431 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 432 | |
| 433 | ccn_charbuf_destroy(&data); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 434 | ccn_charbuf_destroy(&name); |
| 435 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 436 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 437 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 438 | } |
| 439 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 440 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 441 | void |
| 442 | process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 443 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 444 | printf("process_incoming_interest_lsa called \n"); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 445 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 446 | int res; |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 447 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 448 | struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 449 | get_lsa_identifier(lsaId,selfp,info,0); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 450 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 451 | printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length); |
| 452 | int ls_type=get_ls_type(selfp, info); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 453 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 454 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 455 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 456 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 457 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 458 | printf("Interest Received for NAME LSA\n"); |
| 459 | get_name_lsa_data(lsa_data,lsaId); |
| 460 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 461 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 462 | { |
| 463 | printf("Interest Received for ADJ LSA\n"); |
| 464 | get_adj_lsa_data(lsa_data,lsaId); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 465 | } |
| 466 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 467 | char *rdata=ccn_charbuf_as_string(lsa_data); |
| 468 | char *raw_data=(char *)malloc(strlen(rdata)+1); |
| 469 | memset(raw_data,0,strlen(rdata)+1); |
| 470 | memcpy(raw_data,(char *)rdata,strlen(rdata)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 471 | //printf("Content Data to be sent: %s\n",raw_data); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 472 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 473 | struct ccn_charbuf *data=ccn_charbuf_create(); |
| 474 | struct ccn_charbuf *name=ccn_charbuf_create(); |
| 475 | struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 476 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 477 | 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] | 478 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 479 | sp.template_ccnb=ccn_charbuf_create(); |
| 480 | ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG); |
| 481 | ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10); |
| 482 | sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; |
| 483 | ccn_charbuf_append_closer(sp.template_ccnb); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 484 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 485 | res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data)); |
| 486 | if(res >= 0) |
| 487 | printf("Signing LSA Content is successful \n"); |
| 488 | |
| 489 | res=ccn_put(nlsr->ccn,data->buf,data->length); |
| 490 | if(res >= 0) |
| 491 | printf("Sending LSA Content is successful \n"); |
| 492 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 493 | |
| 494 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 495 | ccn_charbuf_destroy(&data); |
| 496 | ccn_charbuf_destroy(&name); |
| 497 | ccn_charbuf_destroy(&sp.template_ccnb); |
| 498 | ccn_charbuf_destroy(&lsa_data); |
| 499 | |
| 500 | free(raw_data); |
| 501 | free(lsaId); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 502 | } |
| 503 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 504 | /* Call back function registered in ccnd to get all content coming to NLSR application */ |
| 505 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 506 | enum ccn_upcall_res incoming_content(struct ccn_closure* selfp, |
| 507 | enum ccn_upcall_kind kind, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 508 | { |
| 509 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 510 | nlsr_lock(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 511 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 512 | switch(kind) { |
| 513 | case CCN_UPCALL_FINAL: |
| 514 | break; |
| 515 | case CCN_UPCALL_CONTENT: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 516 | printf("Content Received for Name: "); |
| 517 | struct ccn_charbuf*c; |
| 518 | c=ccn_charbuf_create(); |
| 519 | ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 520 | printf("%s\n",ccn_charbuf_as_string(c)); |
| 521 | ccn_charbuf_destroy(&c); |
| 522 | |
| 523 | process_incoming_content(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 524 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 525 | break; |
| 526 | case CCN_UPCALL_INTEREST_TIMED_OUT: |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 527 | printf("Interest Timed Out Received for Name: "); |
| 528 | |
| 529 | struct ccn_charbuf*ito; |
| 530 | ito=ccn_charbuf_create(); |
| 531 | ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0); |
| 532 | printf("%s\n",ccn_charbuf_as_string(ito)); |
| 533 | ccn_charbuf_destroy(&ito); |
| 534 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 535 | process_incoming_timed_out_interest(selfp,info); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 536 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 537 | break; |
| 538 | default: |
| 539 | fprintf(stderr, "Unexpected response of kind %d\n", kind); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 540 | //return CCN_UPCALL_RESULT_ERR; |
| 541 | break; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 542 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 543 | |
| 544 | nlsr_unlock(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 545 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 546 | return CCN_UPCALL_RESULT_OK; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 547 | } |
| 548 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 549 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 550 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 551 | process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 552 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 553 | printf("process_incoming_content called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 554 | |
| 555 | const unsigned char *comp_ptr1; |
| 556 | size_t comp_size; |
| 557 | int res,i; |
| 558 | int nlsr_position=0; |
| 559 | int name_comps=(int)info->interest_comps->n; |
| 560 | |
| 561 | for(i=0;i<name_comps;i++) |
| 562 | { |
| 563 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 564 | if( res == 0) |
| 565 | { |
| 566 | nlsr_position=i; |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size); |
| 572 | |
| 573 | printf("Det= %s \n",comp_ptr1); |
| 574 | |
| 575 | if(!strcmp((char *)comp_ptr1,"info")) |
| 576 | { |
| 577 | process_incoming_content_info(selfp,info); |
| 578 | } |
| 579 | if(!strcmp((char *)comp_ptr1,"lsdb")) |
| 580 | { |
| 581 | process_incoming_content_lsdb(selfp,info); |
| 582 | } |
| 583 | if(!strcmp((char *)comp_ptr1,"lsa")) |
| 584 | { |
| 585 | process_incoming_content_lsa(selfp,info); |
| 586 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 587 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 588 | } |
| 589 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 590 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 591 | void |
| 592 | process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 593 | { |
| 594 | printf("process_incoming_content_info called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 595 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 596 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 597 | get_nbr(nbr,selfp,info); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 598 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 599 | 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] | 600 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 601 | |
| 602 | const unsigned char *ptr; |
| 603 | size_t length; |
| 604 | 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] | 605 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 606 | |
| 607 | long int interval=atoi((char *)ptr); |
| 608 | |
| 609 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 610 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 611 | update_adjacent_timed_out_zero_to_adl(nbr); |
| 612 | update_adjacent_status_to_adl(nbr,NBR_ACTIVE); |
| 613 | update_lsdb_synch_interval_to_adl(nbr,interval); |
| 614 | print_adjacent_from_adl(); |
| 615 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 616 | |
| 617 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 618 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 619 | { |
| 620 | printf("Scheduling Build and Install Adj LSA...\n"); |
| 621 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0); |
| 622 | nlsr->is_build_adj_lsa_sheduled=1; |
| 623 | } |
| 624 | else |
| 625 | { |
| 626 | printf("Build and Install Adj LSA already scheduled\n"); |
| 627 | } |
| 628 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 629 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 630 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 631 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 632 | |
| 633 | } |
| 634 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 635 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 636 | void |
| 637 | process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 638 | { |
| 639 | printf("process_incoming_content_lsdb called \n"); |
| 640 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 641 | const unsigned char *ptr; |
| 642 | size_t length; |
| 643 | 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] | 644 | //printf("Content data: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 645 | |
| 646 | if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) ) |
| 647 | { |
| 648 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 649 | get_nbr(nbr,selfp,info); |
| 650 | |
| 651 | char *nl; |
| 652 | int num_element; |
| 653 | int i; |
| 654 | char *rem; |
| 655 | const char *sep="|"; |
| 656 | char *orig_router; |
| 657 | char *lst; |
| 658 | int ls_type; |
| 659 | char *lsid; |
| 660 | long int ls_id; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 661 | char *orig_time; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 662 | |
| 663 | nl=strtok_r((char *)ptr,sep,&rem); |
| 664 | num_element=atoi(nl); |
| 665 | |
| 666 | for(i = 0 ; i < num_element ; i++) |
| 667 | { |
| 668 | orig_router=strtok_r(NULL,sep,&rem); |
| 669 | lst=strtok_r(NULL,sep,&rem); |
| 670 | ls_type=atoi(lst); |
| 671 | printf("Orig Router: %s ls Type: %d",orig_router,ls_type); |
| 672 | |
| 673 | if(ls_type == LS_TYPE_NAME) |
| 674 | { |
| 675 | lsid=strtok_r(NULL,sep,&rem); |
| 676 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 677 | orig_time=strtok_r(NULL,sep,&rem); |
| 678 | printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time); |
| 679 | int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time); |
| 680 | if ( is_new_name_lsa == 1 ) |
| 681 | { |
| 682 | printf("New NAME LSA.....\n"); |
| 683 | send_interest_for_name_lsa(nbr,orig_router,lst,lsid); |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | printf("Name LSA already exists in LSDB\n"); |
| 688 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 689 | } |
| 690 | else |
| 691 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 692 | orig_time=strtok_r(NULL,sep,&rem); |
| 693 | printf(" Orig Time: %s\n",orig_time); |
| 694 | int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time); |
| 695 | if ( is_new_adj_lsa == 1 ) |
| 696 | { |
| 697 | printf("New ADJ LSA.....\n"); |
| 698 | send_interest_for_adj_lsa(nbr,orig_router,lst); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | printf("ADJ LSA already exists in LSDB\n"); |
| 703 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 704 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 705 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 706 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 707 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 708 | char *lsdb_version=(char *)malloc(20); |
| 709 | memset(lsdb_version,0,20); |
| 710 | get_lsdb_version(lsdb_version,selfp,info); |
| 711 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 712 | 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] | 713 | update_adjacent_lsdb_version_to_adl(nbr,lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 714 | 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] | 715 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 716 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 717 | |
| 718 | free(lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 719 | free(nbr); |
| 720 | } |
| 721 | else if (strcmp("WAIT",(char *)ptr) == 0) |
| 722 | { |
| 723 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 724 | get_nbr(nbr,selfp,info); |
| 725 | long int interval=get_lsdb_synch_interval(nbr->name); |
| 726 | adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 727 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 728 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 729 | free(nbr); |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | printf("NACK Content Received\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 734 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 735 | get_nbr(nbr,selfp,info); |
| 736 | update_lsdb_interest_timed_out_zero_to_adl(nbr); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 737 | free(nbr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 738 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 739 | } |
| 740 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 741 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 742 | void |
| 743 | process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info) |
| 744 | { |
| 745 | printf("process_incoming_content_lsa called \n"); |
| 746 | |
| 747 | char *sep="|"; |
| 748 | char *rem; |
| 749 | char *orig_router; |
| 750 | char *orl; |
| 751 | int orig_router_length; |
| 752 | char *lst; |
| 753 | int ls_type; |
| 754 | char *lsid; |
| 755 | long int ls_id; |
| 756 | char *isvld; |
| 757 | int isValid; |
| 758 | char *num_link; |
| 759 | int no_link; |
| 760 | char *np; |
| 761 | char *np_length; |
| 762 | int name_length; |
| 763 | char *data; |
| 764 | char *orig_time; |
| 765 | |
| 766 | const unsigned char *ptr; |
| 767 | size_t length; |
| 768 | 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] | 769 | //printf("Content data Received: %s\n",ptr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 770 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 776 | printf("LSA Data\n"); |
| 777 | |
| 778 | if( strlen((char *) ptr ) > 0 ) |
| 779 | { |
| 780 | |
| 781 | orig_router=strtok_r((char *)ptr,sep,&rem); |
| 782 | orl=strtok_r(NULL,sep,&rem); |
| 783 | orig_router_length=atoi(orl); |
| 784 | |
| 785 | printf(" Orig Router Name : %s\n",orig_router); |
| 786 | printf(" Orig Router Length: %d\n",orig_router_length); |
| 787 | |
| 788 | lst=strtok_r(NULL,sep,&rem); |
| 789 | ls_type=atoi(lst); |
| 790 | |
| 791 | printf(" LS Type : %d\n",ls_type); |
| 792 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 793 | if ( ls_type == LS_TYPE_NAME ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 794 | { |
| 795 | lsid=strtok_r(NULL,sep,&rem); |
| 796 | ls_id=atoi(lsid); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 797 | orig_time=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 798 | isvld=strtok_r(NULL,sep,&rem); |
| 799 | isValid=atoi(isvld); |
| 800 | np=strtok_r(NULL,sep,&rem); |
| 801 | np_length=strtok_r(NULL,sep,&rem); |
| 802 | name_length=atoi(np_length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 803 | printf(" LS ID : %ld\n",ls_id); |
| 804 | printf(" isValid : %d\n",isValid); |
| 805 | printf(" Name Prefix : %s\n",np); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 806 | printf(" Orig Time : %s\n",orig_time); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 807 | printf(" Name Prefix length: %d\n",name_length); |
| 808 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 809 | build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np); |
| 810 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 811 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 812 | else if ( ls_type == LS_TYPE_ADJ ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 813 | { |
| 814 | orig_time=strtok_r(NULL,sep,&rem); |
| 815 | num_link=strtok_r(NULL,sep,&rem); |
| 816 | no_link=atoi(num_link); |
| 817 | data=rem; |
| 818 | |
| 819 | printf(" No Link : %d\n",no_link); |
| 820 | printf(" Data : %s\n",data); |
| 821 | |
| 822 | build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data); |
| 823 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 824 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 825 | } |
| 826 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 827 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 828 | void |
| 829 | process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 830 | { |
| 831 | printf("process_incoming_timed_out_interest called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 832 | int res,i; |
| 833 | int nlsr_position=0; |
| 834 | int name_comps=(int)info->interest_comps->n; |
| 835 | |
| 836 | for(i=0;i<name_comps;i++) |
| 837 | { |
| 838 | res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr"); |
| 839 | if( res == 0) |
| 840 | { |
| 841 | nlsr_position=i; |
| 842 | break; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0) |
| 847 | { |
| 848 | process_incoming_timed_out_interest_info(selfp,info); |
| 849 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 850 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0) |
| 851 | { |
| 852 | process_incoming_timed_out_interest_lsdb(selfp,info); |
| 853 | } |
| 854 | if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsa") == 0) |
| 855 | { |
| 856 | process_incoming_timed_out_interest_lsa(selfp,info); |
| 857 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | void |
| 861 | process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 862 | { |
| 863 | printf("process_incoming_timed_out_interest_info called \n"); |
| 864 | |
| 865 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 866 | get_nbr(nbr,selfp,info); |
| 867 | |
| 868 | 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] | 869 | |
| 870 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 871 | update_adjacent_timed_out_to_adl(nbr,1); |
| 872 | print_adjacent_from_adl(); |
| 873 | int timed_out=get_timed_out_number(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 874 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 875 | |
| 876 | if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables |
| 877 | { |
| 878 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 879 | send_info_interest_to_neighbor(nbr); |
| 880 | } |
| 881 | else |
| 882 | { |
| 883 | printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out); |
| 884 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 885 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 886 | { |
| 887 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 888 | nlsr->is_build_adj_lsa_sheduled=1; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | free(nbr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 893 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 894 | |
| 895 | } |
| 896 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 897 | void |
| 898 | process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 899 | { |
| 900 | printf("process_incoming_timed_out_interest_lsdb called \n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 901 | |
| 902 | struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 903 | get_nbr(nbr,selfp,info); |
| 904 | |
| 905 | printf("LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length); |
| 906 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 907 | update_lsdb_interest_timed_out_to_adl(nbr,1); |
| 908 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 909 | int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr); |
| 910 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 911 | printf("Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry); |
| 912 | |
| 913 | if( interst_timed_out_num >= nlsr->interest_retry ) |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 914 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 915 | update_adjacent_status_to_adl(nbr,NBR_DOWN); |
| 916 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 917 | { |
| 918 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 919 | nlsr->is_build_adj_lsa_sheduled=1; |
| 920 | } |
| 921 | } |
| 922 | free(nbr->name); |
| 923 | free(nbr); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void |
| 927 | process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info) |
| 928 | { |
| 929 | printf("process_incoming_timed_out_interest_lsa called \n"); |
| 930 | |
| 931 | } |
| 932 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 933 | int |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 934 | send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 935 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 936 | if(flags == CCN_SCHEDULE_CANCEL) |
| 937 | { |
| 938 | return -1; |
| 939 | } |
| 940 | |
| 941 | nlsr_lock(); |
| 942 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 943 | printf("send_info_interest called \n"); |
| 944 | printf("\n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 945 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 946 | int adl_element,i; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 947 | struct ndn_neighbor *nbr; |
| 948 | |
| 949 | struct hashtb_enumerator ee; |
| 950 | struct hashtb_enumerator *e = ⅇ |
| 951 | |
| 952 | hashtb_start(nlsr->adl, e); |
| 953 | adl_element=hashtb_n(nlsr->adl); |
| 954 | |
| 955 | for(i=0;i<adl_element;i++) |
| 956 | { |
| 957 | nbr=e->data; |
| 958 | send_info_interest_to_neighbor(nbr->neighbor); |
| 959 | hashtb_next(e); |
| 960 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 961 | hashtb_end(e); |
| 962 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 963 | nlsr_unlock(); |
| 964 | |
akmhoque | 9fa58a8 | 2012-10-05 07:56:02 -0500 | [diff] [blame] | 965 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0); |
| 966 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | void |
| 971 | send_info_interest_to_neighbor(struct name_prefix *nbr) |
| 972 | { |
| 973 | printf("send_info_interest_to_neighbor called \n"); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 974 | |
| 975 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 976 | char info_str[5]; |
| 977 | char nlsr_str[5]; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 978 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 979 | memset(&nlsr_str,0,5); |
| 980 | sprintf(nlsr_str,"nlsr"); |
| 981 | memset(&info_str,0,5); |
| 982 | sprintf(info_str,"info"); |
| 983 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 984 | |
| 985 | struct ccn_charbuf *name; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 986 | name=ccn_charbuf_create(); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 987 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 988 | char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1); |
| 989 | 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] | 990 | memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name)); |
| 991 | memcpy(int_name+strlen(int_name),"/",1); |
| 992 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 993 | memcpy(int_name+strlen(int_name),"/",1); |
| 994 | memcpy(int_name+strlen(int_name),info_str,strlen(info_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 995 | memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 996 | |
| 997 | |
| 998 | res=ccn_name_from_uri(name,int_name); |
| 999 | if ( res >=0 ) |
| 1000 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1001 | /* adding InterestLifeTime and InterestScope filter */ |
| 1002 | |
| 1003 | struct ccn_charbuf *templ; |
| 1004 | templ = ccn_charbuf_create(); |
| 1005 | |
| 1006 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1007 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1008 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1009 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1010 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1011 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1012 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1013 | |
| 1014 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1015 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1016 | /* Adding InterestLifeTime and InterestScope filter done */ |
| 1017 | |
| 1018 | printf("Sending info interest on name prefix : %s \n",int_name); |
| 1019 | |
| 1020 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1021 | |
| 1022 | if ( res >= 0 ) |
| 1023 | printf("Info interest sending Successfull .... \n"); |
| 1024 | ccn_charbuf_destroy(&templ); |
| 1025 | } |
| 1026 | ccn_charbuf_destroy(&name); |
| 1027 | free(int_name); |
| 1028 | |
| 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | int |
| 1033 | send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1034 | { |
| 1035 | printf("send_lsdb_interest called \n"); |
| 1036 | |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1037 | if(flags == CCN_SCHEDULE_CANCEL) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1038 | { |
| 1039 | return -1; |
| 1040 | } |
Obaid Amin | 485277a | 2012-09-07 01:08:28 -0400 | [diff] [blame] | 1041 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1042 | nlsr_lock(); |
| 1043 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1044 | int i, adl_element; |
| 1045 | struct ndn_neighbor *nbr; |
| 1046 | |
| 1047 | struct hashtb_enumerator ee; |
| 1048 | struct hashtb_enumerator *e = ⅇ |
| 1049 | |
| 1050 | hashtb_start(nlsr->adl, e); |
| 1051 | adl_element=hashtb_n(nlsr->adl); |
| 1052 | |
| 1053 | for(i=0;i<adl_element;i++) |
| 1054 | { |
| 1055 | nbr=e->data; |
| 1056 | |
| 1057 | if(nbr->status == NBR_ACTIVE) |
| 1058 | { |
| 1059 | if(nbr->is_lsdb_send_interest_scheduled == 0) |
| 1060 | { |
| 1061 | long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name); |
| 1062 | printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name); |
| 1063 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1064 | if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1065 | { |
| 1066 | nbr->is_lsdb_send_interest_scheduled=1; |
| 1067 | send_lsdb_interest_to_nbr(nbr->neighbor); |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | hashtb_next(e); |
| 1072 | } |
| 1073 | |
| 1074 | hashtb_end(e); |
| 1075 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0); |
| 1076 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1077 | nlsr_unlock(); |
| 1078 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | void |
| 1083 | send_lsdb_interest_to_nbr(struct name_prefix *nbr) |
| 1084 | { |
| 1085 | printf("send_lsdb_interest_to_nbr called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1086 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1087 | char *last_lsdb_version=get_nbr_lsdb_version(nbr->name); |
| 1088 | |
| 1089 | if(last_lsdb_version !=NULL) |
| 1090 | { |
| 1091 | printf("Last LSDB Version: %s \n",last_lsdb_version); |
| 1092 | |
| 1093 | |
| 1094 | struct ccn_charbuf *name; |
| 1095 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1096 | char lsdb_str[5]; |
| 1097 | char nlsr_str[5]; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1098 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1099 | memset(&nlsr_str,0,5); |
| 1100 | sprintf(nlsr_str,"nlsr"); |
| 1101 | memset(&lsdb_str,0,5); |
| 1102 | sprintf(lsdb_str,"lsdb"); |
| 1103 | //make and send interest with exclusion filter as last_lsdb_version |
| 1104 | printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str); |
| 1105 | name=ccn_charbuf_create(); |
| 1106 | res=ccn_name_from_uri(name,nbr->name); |
| 1107 | |
| 1108 | if( res >= 0) |
| 1109 | { |
| 1110 | ccn_name_append_str(name,nlsr_str); |
| 1111 | ccn_name_append_str(name,lsdb_str); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1112 | /* adding Exclusion filter */ |
| 1113 | |
| 1114 | struct ccn_charbuf *templ; |
| 1115 | templ = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1116 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1117 | struct ccn_charbuf *c; |
| 1118 | c = ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1119 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1120 | |
| 1121 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1122 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1123 | ccn_charbuf_append_closer(templ); /* </Name> */ |
| 1124 | ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); |
| 1125 | ccnb_tagged_putf(templ, CCN_DTAG_Any, ""); |
| 1126 | ccn_charbuf_reset(c); |
| 1127 | ccn_charbuf_putf(c, "%s", last_lsdb_version); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1128 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1129 | ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length); |
| 1130 | ccn_charbuf_append_closer(templ); /* </Exclude> */ |
| 1131 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1132 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1133 | ccn_charbuf_append(templ, "2", 1); |
| 1134 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1135 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1136 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1137 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1138 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1139 | |
| 1140 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1141 | /* Adding Exclusion filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1142 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1143 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1144 | |
| 1145 | if ( res >= 0 ) |
| 1146 | { |
| 1147 | printf("Interest sending Successfull .... \n"); |
| 1148 | update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec()); |
| 1149 | |
| 1150 | } |
| 1151 | ccn_charbuf_destroy(&c); |
| 1152 | ccn_charbuf_destroy(&templ); |
| 1153 | } |
| 1154 | ccn_charbuf_destroy(&name); |
| 1155 | } |
| 1156 | set_is_lsdb_send_interest_scheduled_to_zero(nbr->name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void |
| 1160 | send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id) |
| 1161 | { |
| 1162 | printf("send_interest_for_name_lsa called\n"); |
| 1163 | |
| 1164 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1165 | char lsa_str[5]; |
| 1166 | char nlsr_str[5]; |
| 1167 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1168 | memset(&nlsr_str,0,5); |
| 1169 | sprintf(nlsr_str,"nlsr"); |
| 1170 | memset(&lsa_str,0,5); |
| 1171 | sprintf(lsa_str,"lsa"); |
| 1172 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1173 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3); |
| 1174 | 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] | 1175 | |
| 1176 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1177 | memcpy(int_name+strlen(int_name),"/",1); |
| 1178 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1179 | memcpy(int_name+strlen(int_name),"/",1); |
| 1180 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1181 | memcpy(int_name+strlen(int_name),"/",1); |
| 1182 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
| 1183 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1184 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1185 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1186 | struct ccn_charbuf *name; |
| 1187 | name=ccn_charbuf_create(); |
| 1188 | |
| 1189 | |
| 1190 | res=ccn_name_from_uri(name,int_name); |
| 1191 | ccn_name_append_str(name,ls_type); |
| 1192 | ccn_name_append_str(name,ls_id); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1193 | |
| 1194 | |
| 1195 | /* adding InterestLifeTime and InterestScope filter */ |
| 1196 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1197 | struct ccn_charbuf *templ; |
| 1198 | templ = ccn_charbuf_create(); |
| 1199 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1200 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1201 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1202 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1203 | //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope); |
| 1204 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1205 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1206 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1207 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1208 | |
| 1209 | appendLifetime(templ,nlsr->interest_resend_time); |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1210 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1211 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1212 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1213 | 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] | 1214 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1215 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1216 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1217 | if ( res >= 0 ) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1218 | printf("NAME LSA interest sending Successfull .... \n"); |
| 1219 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1220 | ccn_charbuf_destroy(&templ); |
| 1221 | ccn_charbuf_destroy(&name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1222 | free(int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1223 | |
| 1224 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1225 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1226 | |
| 1227 | void |
| 1228 | send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type) |
| 1229 | { |
| 1230 | printf("send_interest_for_adj_lsa called\n"); |
| 1231 | |
| 1232 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1233 | char lsa_str[5]; |
| 1234 | char nlsr_str[5]; |
| 1235 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1236 | memset(&nlsr_str,0,5); |
| 1237 | sprintf(nlsr_str,"nlsr"); |
| 1238 | memset(&lsa_str,0,5); |
| 1239 | sprintf(lsa_str,"lsa"); |
| 1240 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1241 | char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1); |
| 1242 | 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] | 1243 | |
| 1244 | memcpy(int_name+strlen(int_name),nbr->name,nbr->length); |
| 1245 | memcpy(int_name+strlen(int_name),"/",1); |
| 1246 | memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str)); |
| 1247 | memcpy(int_name+strlen(int_name),"/",1); |
| 1248 | memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1249 | memcpy(int_name+strlen(int_name),"/",1); |
| 1250 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1251 | memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router)); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1252 | memcpy(int_name+strlen(int_name),"/",1); |
| 1253 | memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1254 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1255 | struct ccn_charbuf *name; |
| 1256 | name=ccn_charbuf_create(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1257 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1258 | |
| 1259 | ccn_name_from_uri(name,int_name); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1260 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1261 | /* adding InterestLifeTime and InterestScope filter */ |
| 1262 | |
| 1263 | struct ccn_charbuf *templ; |
| 1264 | templ = ccn_charbuf_create(); |
| 1265 | |
| 1266 | ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); |
| 1267 | ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); |
| 1268 | ccn_charbuf_append_closer(templ); /* </Name> */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1269 | ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG); |
| 1270 | ccn_charbuf_append_tt(templ, 1, CCN_UDATA); |
| 1271 | ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host) |
| 1272 | ccn_charbuf_append_closer(templ); /* </Scope> */ |
| 1273 | |
| 1274 | appendLifetime(templ,nlsr->interest_resend_time); |
| 1275 | ccn_charbuf_append_closer(templ); /* </Interest> */ |
| 1276 | /* Adding InterestLifeTime and InterestScope filter done */ |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1277 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1278 | printf("Sending ADJ LSA interest on name prefix : %s\n",int_name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1279 | |
| 1280 | res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ); |
| 1281 | |
| 1282 | if ( res >= 0 ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1283 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1284 | printf("ADJ LSA interest sending Successfull .... \n"); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1285 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1286 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1287 | ccn_charbuf_destroy(&templ); |
| 1288 | ccn_charbuf_destroy(&name); |
| 1289 | free(int_name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1290 | } |