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