blob: 82e8df8fb5e06c8e8c4ce1b797056ee4a1b0d33e [file] [log] [blame]
akmhoque59980a52012-08-09 12:36:09 -05001#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"
akmhoque03004e62012-09-06 01:12:28 -050022#include "nlsr_npl.h"
akmhoque8a5babe2012-08-16 17:39:33 -050023#include "nlsr_adl.h"
akmhoqued79438d2012-08-27 13:31:42 -050024#include "nlsr_lsdb.h"
akmhoque53f64222012-09-05 13:57:51 -050025#include "utility.h"
26
akmhoqued79438d2012-08-27 13:31:42 -050027int
28appendLifetime(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}
akmhoque59980a52012-08-09 12:36:09 -050043
akmhoque53f64222012-09-05 13:57:51 -050044
45void
46get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info)
47{
akmhoque7b791452012-10-30 11:24:56 -050048 if ( nlsr->debugging )
49 printf("get_nbr called\n");
50 if ( nlsr->detailed_logging )
51 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n");
akmhoque53f64222012-09-05 13:57:51 -050052
akmhoque53f64222012-09-05 13:57:51 -050053 int res,i;
54 int nlsr_position=0;
55 int name_comps=(int)info->interest_comps->n;
56 int len=0;
57
58 for(i=0;i<name_comps;i++)
59 {
60 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
61 if( res == 0)
62 {
63 nlsr_position=i;
64 break;
65 }
66 }
67
68
69 const unsigned char *comp_ptr1;
70 size_t comp_size;
71 for(i=0;i<nlsr_position;i++)
72 {
73 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
74 len+=1;
75 len+=(int)comp_size;
76 }
77 len++;
78
79 char *neighbor=(char *)malloc(len);
80 memset(neighbor,0,len);
81
82 for(i=0; i<nlsr_position;i++)
83 {
84 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
85 memcpy(neighbor+strlen(neighbor),"/",1);
86 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
87
88 }
akmhoque53f64222012-09-05 13:57:51 -050089
90 nbr->name=(char *)malloc(strlen(neighbor)+1);
91 memcpy(nbr->name,neighbor,strlen(neighbor)+1);
92 nbr->length=strlen(neighbor)+1;
93
akmhoque7b791452012-10-30 11:24:56 -050094 if ( nlsr->debugging )
95 printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length);
96 if ( nlsr->detailed_logging )
97 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n",nbr->name,nbr->length);
98
akmhoque53f64222012-09-05 13:57:51 -050099
100
101}
102
103void
akmhoque03004e62012-09-06 01:12:28 -0500104get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info, int offset)
akmhoque53f64222012-09-05 13:57:51 -0500105{
106
akmhoque7b791452012-10-30 11:24:56 -0500107 //printf("get_lsa_identifier called\n");
108
109 if ( nlsr->debugging )
110 printf("get_lsa_identifier called\n");
111 if ( nlsr->detailed_logging )
112 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsa_identifier called\n");
113
akmhoque53f64222012-09-05 13:57:51 -0500114 int res,i;
115 int nlsr_position=0;
116 int name_comps=(int)info->interest_comps->n;
117 int len=0;
118
119 for(i=0;i<name_comps;i++)
120 {
121 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
122 if( res == 0)
123 {
124 nlsr_position=i;
125 break;
126 }
127 }
128
129
130 const unsigned char *comp_ptr1;
131 size_t comp_size;
akmhoque03004e62012-09-06 01:12:28 -0500132 for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++)
akmhoque53f64222012-09-05 13:57:51 -0500133 {
134 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
135 len+=1;
136 len+=(int)comp_size;
137 }
138 len++;
139
140 char *neighbor=(char *)malloc(len);
141 memset(neighbor,0,len);
142
akmhoque03004e62012-09-06 01:12:28 -0500143 for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++)
akmhoque53f64222012-09-05 13:57:51 -0500144 {
145 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
146 memcpy(neighbor+strlen(neighbor),"/",1);
147 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
148
149 }
akmhoque53f64222012-09-05 13:57:51 -0500150
151 lsaId->name=(char *)malloc(strlen(neighbor)+1);
152 memset(lsaId->name,0,strlen(neighbor)+1);
153 memcpy(lsaId->name,neighbor,strlen(neighbor)+1);
154 lsaId->length=strlen(neighbor)+1;
155
akmhoque7b791452012-10-30 11:24:56 -0500156 if ( nlsr->debugging )
157 printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
158 if ( nlsr->detailed_logging )
159 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
160
161 //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
akmhoque03004e62012-09-06 01:12:28 -0500162
akmhoque53f64222012-09-05 13:57:51 -0500163
164}
165
akmhoque03004e62012-09-06 01:12:28 -0500166int
167get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info)
168{
169 int res,i;
170 int nlsr_position=0;
171 int name_comps=(int)info->interest_comps->n;
172
173 int ret=0;
174
175 for(i=0;i<name_comps;i++)
176 {
177 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
178 if( res == 0)
179 {
180 nlsr_position=i;
181 break;
182 }
183 }
184
185
186 const unsigned char *comp_ptr1;
187 size_t comp_size;
188 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size);
189
190 ret=atoi((char *)comp_ptr1);
191
192 return ret;
193
194}
195
196void
197get_lsdb_version(char *lsdb_version,struct ccn_closure *selfp, struct ccn_upcall_info *info )
198{
199 const unsigned char *comp_ptr1;
200 size_t comp_size;
201 ccn_name_comp_get(info->content_ccnb, info->content_comps,info->content_comps->n-2,&comp_ptr1, &comp_size);
202 memcpy(lsdb_version,(char *)comp_ptr1,(int)comp_size);
203
204}
205
206
207/* Call back function registered in ccnd to get all interest coming to NLSR application */
208
akmhoque59980a52012-08-09 12:36:09 -0500209enum ccn_upcall_res
210incoming_interest(struct ccn_closure *selfp,
211 enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
212{
akmhoqueffacaa82012-09-13 17:48:30 -0500213
214 nlsr_lock();
215
akmhoque59980a52012-08-09 12:36:09 -0500216 switch (kind) {
217 case CCN_UPCALL_FINAL:
218 break;
219 case CCN_UPCALL_INTEREST:
akmhoque03004e62012-09-06 01:12:28 -0500220 // printing the name prefix for which it received interest
akmhoque7b791452012-10-30 11:24:56 -0500221 if ( nlsr->debugging )
222 printf("Interest Received for name: ");
223 if ( nlsr->detailed_logging )
224 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: ");
225
akmhoque03004e62012-09-06 01:12:28 -0500226 struct ccn_charbuf*c;
227 c=ccn_charbuf_create();
228 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque7b791452012-10-30 11:24:56 -0500229
230 if ( nlsr->debugging )
231 printf("%s\n",ccn_charbuf_as_string(c));
232 if ( nlsr->detailed_logging )
233 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c));
234
akmhoque03004e62012-09-06 01:12:28 -0500235 ccn_charbuf_destroy(&c);
236
akmhoque1c9b92f2012-08-13 10:57:50 -0500237 process_incoming_interest(selfp, info);
akmhoque03004e62012-09-06 01:12:28 -0500238
akmhoque59980a52012-08-09 12:36:09 -0500239 break;
akmhoque03004e62012-09-06 01:12:28 -0500240
akmhoque59980a52012-08-09 12:36:09 -0500241 default:
242 break;
243 }
akmhoque03004e62012-09-06 01:12:28 -0500244
akmhoqueffacaa82012-09-13 17:48:30 -0500245 nlsr_unlock();
246
akmhoque59980a52012-08-09 12:36:09 -0500247 return CCN_UPCALL_RESULT_OK;
248}
249
akmhoque03004e62012-09-06 01:12:28 -0500250/* Function for processing incoming interest and reply with content/NACK content */
akmhoque59980a52012-08-09 12:36:09 -0500251
akmhoqued79438d2012-08-27 13:31:42 -0500252void
akmhoque1c9b92f2012-08-13 10:57:50 -0500253process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
254{
akmhoque7b791452012-10-30 11:24:56 -0500255 if ( nlsr->debugging )
256 printf("process_incoming_interest called \n");
257 if ( nlsr->detailed_logging )
258 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n");
259
akmhoque1c9b92f2012-08-13 10:57:50 -0500260 const unsigned char *comp_ptr1;
261 size_t comp_size;
262 int res,i;
263 int nlsr_position=0;
264 int name_comps=(int)info->interest_comps->n;
akmhoque53f64222012-09-05 13:57:51 -0500265
akmhoque1c9b92f2012-08-13 10:57:50 -0500266 for(i=0;i<name_comps;i++)
267 {
268 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
269 if( res == 0)
270 {
akmhoqueea3603e2012-08-13 11:24:09 -0500271 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500272 break;
273 }
274 }
275
276 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500277
akmhoque7b791452012-10-30 11:24:56 -0500278 //printf("Det= %s \n",comp_ptr1);
akmhoque1c9b92f2012-08-13 10:57:50 -0500279
akmhoqued79438d2012-08-27 13:31:42 -0500280 if(!strcmp((char *)comp_ptr1,"info"))
281 {
282 process_incoming_interest_info(selfp,info);
283 }
akmhoque53f64222012-09-05 13:57:51 -0500284 if(!strcmp((char *)comp_ptr1,"lsdb"))
285 {
286 process_incoming_interest_lsdb(selfp,info);
287 }
288 if(!strcmp((char *)comp_ptr1,"lsa"))
289 {
290 process_incoming_interest_lsa(selfp,info);
291 }
akmhoque53f64222012-09-05 13:57:51 -0500292}
293
294void
295process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
296{
akmhoque7b791452012-10-30 11:24:56 -0500297 if ( nlsr->debugging )
298 {
299 printf("process_incoming_interest_info called \n");
300 printf("Sending Info Content back.....\n");
301 }
302 if ( nlsr->detailed_logging )
303 {
304 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n");
305 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n");
306 }
307
akmhoque53f64222012-09-05 13:57:51 -0500308
akmhoque53f64222012-09-05 13:57:51 -0500309 int res;
310 struct ccn_charbuf *data=ccn_charbuf_create();
311 struct ccn_charbuf *name=ccn_charbuf_create();
312 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
akmhoque03004e62012-09-06 01:12:28 -0500313
akmhoque53f64222012-09-05 13:57:51 -0500314 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]);
315 if (res >= 0)
316 {
317 sp.template_ccnb=ccn_charbuf_create();
318 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
319 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
320 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
321 ccn_charbuf_append_closer(sp.template_ccnb);
322
323
324 char *raw_data=(char *)malloc(16);
325 memset(raw_data,0,16);
326 sprintf(raw_data,"%ld", nlsr->lsdb_synch_interval);
327
328 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data));
329 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500330 {
331 if ( nlsr->debugging )
332 printf("Signing info Content is successful \n");
333 if ( nlsr->detailed_logging )
334 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n");
akmhoque53f64222012-09-05 13:57:51 -0500335
akmhoque7b791452012-10-30 11:24:56 -0500336 }
akmhoque53f64222012-09-05 13:57:51 -0500337 res=ccn_put(nlsr->ccn,data->buf,data->length);
338 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500339 {
340 if ( nlsr->debugging )
341 printf("Sending Info Content is successful \n");
342 if ( nlsr->detailed_logging )
343 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n");
344 }
345
akmhoque53f64222012-09-05 13:57:51 -0500346
347
348 struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *));
akmhoque03004e62012-09-06 01:12:28 -0500349 get_lsa_identifier(nbr,selfp,info,-1);
akmhoque7b791452012-10-30 11:24:56 -0500350
351 if ( nlsr->debugging )
352 printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
353 if ( nlsr->detailed_logging )
354 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
355
356 //printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
akmhoque03004e62012-09-06 01:12:28 -0500357
akmhoque53f64222012-09-05 13:57:51 -0500358
359 if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry )
360 {
akmhoqueb8195202012-09-25 11:53:23 -0500361 update_adjacent_timed_out_zero_to_adl(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500362 send_info_interest_to_neighbor(nbr);
363 }
364
365 free(nbr);
366 free(raw_data);
367 ccn_charbuf_destroy(&sp.template_ccnb);
368 }
akmhoque03004e62012-09-06 01:12:28 -0500369
akmhoque53f64222012-09-05 13:57:51 -0500370 ccn_charbuf_destroy(&data);
akmhoque03004e62012-09-06 01:12:28 -0500371 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -0500372
akmhoquebf1aa832012-08-13 13:26:59 -0500373}
374
375
376void
377process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
378{
akmhoque7b791452012-10-30 11:24:56 -0500379 //printf("process_incoming_interest_lsdb called \n");
380
381 if ( nlsr->debugging )
382 printf("process_incoming_interest_lsdb called \n");
383 if ( nlsr->detailed_logging )
384 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsdb called \n");
385
akmhoque53f64222012-09-05 13:57:51 -0500386
387 int l,res;
akmhoquefce8cfc2012-08-14 14:00:33 -0500388 const unsigned char *exclbase;
akmhoque6d49e4d2012-08-14 13:49:30 -0500389 size_t size;
akmhoquefce8cfc2012-08-14 14:00:33 -0500390 struct ccn_buf_decoder decoder;
391 struct ccn_buf_decoder *d;
akmhoque53f64222012-09-05 13:57:51 -0500392 const unsigned char *comp;
393 int dbcmp=0;
akmhoque6d49e4d2012-08-14 13:49:30 -0500394
395 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
396 if (l > 0)
397 {
398 comp = NULL;
399 size = 0;
400 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
401 d = ccn_buf_decoder_start(&decoder, exclbase, l);
402 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
403 {
404 ccn_buf_advance(d);
405 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
406 ccn_buf_advance_past_element(d);
407 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
408 {
409 ccn_buf_advance(d);
410 ccn_buf_match_blob(d, &comp, &size);
akmhoquec9286692012-08-16 09:57:58 -0500411 ccn_buf_check_close(d);
akmhoque53f64222012-09-05 13:57:51 -0500412
413
akmhoque6d49e4d2012-08-14 13:49:30 -0500414 }
415 ccn_buf_check_close(d);
416 }
akmhoque6d49e4d2012-08-14 13:49:30 -0500417 if (comp != NULL)
akmhoque53f64222012-09-05 13:57:51 -0500418 {
akmhoque7b791452012-10-30 11:24:56 -0500419 if ( nlsr->debugging )
420 {
421 printf("LSDB Version in Exclusion Filter is %s\n",comp);
422 printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version);
423 }
424 if ( nlsr->detailed_logging )
425 {
426 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is %s\n",comp);
427 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version);
428 }
akmhoque03004e62012-09-06 01:12:28 -0500429 dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp);
akmhoque53f64222012-09-05 13:57:51 -0500430 }
akmhoque6d49e4d2012-08-14 13:49:30 -0500431 /* Now comp points to the start of your potential number, and size is its length */
432 }
akmhoque53f64222012-09-05 13:57:51 -0500433 else
akmhoquecb017752012-08-16 11:03:45 -0500434 {
akmhoque7b791452012-10-30 11:24:56 -0500435 if ( nlsr->debugging )
436 printf("LSDB Version in Exclusion Filter is: None Added\n");
437 if ( nlsr->detailed_logging )
438 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is: None Added\n");
akmhoque53f64222012-09-05 13:57:51 -0500439 dbcmp=1;
akmhoquecb017752012-08-16 11:03:45 -0500440
441 }
442
akmhoqued79438d2012-08-27 13:31:42 -0500443 struct ccn_charbuf *data=ccn_charbuf_create();
akmhoque53f64222012-09-05 13:57:51 -0500444 struct ccn_charbuf *name=ccn_charbuf_create();
445 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
446
akmhoque03004e62012-09-06 01:12:28 -0500447 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]);
akmhoque887fc0c2012-08-27 15:06:06 -0500448
akmhoqued79438d2012-08-27 13:31:42 -0500449 sp.template_ccnb=ccn_charbuf_create();
450 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
451 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
akmhoque53f64222012-09-05 13:57:51 -0500452 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
453 ccn_charbuf_append_closer(sp.template_ccnb);
akmhoqued79438d2012-08-27 13:31:42 -0500454
akmhoqued79438d2012-08-27 13:31:42 -0500455
akmhoque53f64222012-09-05 13:57:51 -0500456 if(dbcmp>0)
457 {
akmhoque7b791452012-10-30 11:24:56 -0500458 if ( nlsr->debugging )
459 {
460 printf("Has Updated Database than Neighbor\n");
461 printf("Sending LSDB Summary of Updated LSDB Content...\n");
462 }
463 if ( nlsr->detailed_logging )
464 {
465 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Has Updated Database than Neighbor\n");
466 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content...\n");
467 }
akmhoque03004e62012-09-06 01:12:28 -0500468 ccn_name_append_str(name,nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500469
akmhoque03004e62012-09-06 01:12:28 -0500470 struct ccn_charbuf *lsdb_data=ccn_charbuf_create();
471 get_lsdb_summary(lsdb_data);
akmhoque53f64222012-09-05 13:57:51 -0500472
akmhoque03004e62012-09-06 01:12:28 -0500473 char *raw_data=ccn_charbuf_as_string(lsdb_data);
akmhoque53f64222012-09-05 13:57:51 -0500474
akmhoque03004e62012-09-06 01:12:28 -0500475 //printf("Content Data to be sent: %s \n",raw_data);
akmhoque53f64222012-09-05 13:57:51 -0500476
akmhoque29c1db52012-09-07 14:47:43 -0500477 if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 )
akmhoque53f64222012-09-05 13:57:51 -0500478 {
479 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT"));
480 }
481 else
482 {
483 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
484 }
akmhoque7b791452012-10-30 11:24:56 -0500485
akmhoque53f64222012-09-05 13:57:51 -0500486 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500487 {
488 if ( nlsr->debugging )
489 printf("Signing LSDB Summary of Updated LSDB Content is successful \n");
490 if ( nlsr->detailed_logging )
491 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSDB Summary of Updated LSDB Content is successful \n");
492 }
akmhoque53f64222012-09-05 13:57:51 -0500493
494 res=ccn_put(nlsr->ccn,data->buf,data->length);
495
496 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500497 {
498 if ( nlsr->debugging )
499 printf("Sending LSDB Summary of Updated LSDB Content is successful \n");
500 if ( nlsr->detailed_logging )
501 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content is successful \n");
502 }
akmhoque03004e62012-09-06 01:12:28 -0500503
504 ccn_charbuf_destroy(&lsdb_data);
akmhoque53f64222012-09-05 13:57:51 -0500505 }
506 else
507 {
akmhoque7b791452012-10-30 11:24:56 -0500508 if ( nlsr->debugging )
509 {
510 printf("Does not have Updated Database than Neighbor\n");
511 printf("Sending NACK Content.....\n");
512 }
513 if ( nlsr->detailed_logging )
514 {
515 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Does not have Updated Database than Neighbor\n");
516 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content.....\n");
517 }
518
akmhoque53f64222012-09-05 13:57:51 -0500519 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
akmhoque7b791452012-10-30 11:24:56 -0500520
akmhoque53f64222012-09-05 13:57:51 -0500521 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500522 {
523 if ( nlsr->debugging )
524 printf("Signing NACK Content is successful \n");
525 if ( nlsr->detailed_logging )
526 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing NACK Content is successful \n");
527 }
akmhoque53f64222012-09-05 13:57:51 -0500528
529 res=ccn_put(nlsr->ccn,data->buf,data->length);
530
531 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500532 {
533 if ( nlsr->debugging )
534 printf("Sending NACK Content is successful \n");
535 if ( nlsr->detailed_logging )
536 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content is successful \n");
537 }
akmhoque53f64222012-09-05 13:57:51 -0500538
539
540 }
akmhoqued79438d2012-08-27 13:31:42 -0500541
542 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500543 ccn_charbuf_destroy(&name);
544 ccn_charbuf_destroy(&sp.template_ccnb);
545
akmhoque03004e62012-09-06 01:12:28 -0500546
akmhoqued79438d2012-08-27 13:31:42 -0500547}
548
akmhoque03004e62012-09-06 01:12:28 -0500549
akmhoque53f64222012-09-05 13:57:51 -0500550void
551process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info)
akmhoque1c9b92f2012-08-13 10:57:50 -0500552{
akmhoque7b791452012-10-30 11:24:56 -0500553 if ( nlsr->debugging )
554 printf("process_incoming_interest_lsa called \n");
555 if ( nlsr->detailed_logging )
556 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsa called \n");
akmhoque1c9b92f2012-08-13 10:57:50 -0500557
akmhoque53f64222012-09-05 13:57:51 -0500558 int res;
akmhoque1c9b92f2012-08-13 10:57:50 -0500559
akmhoque53f64222012-09-05 13:57:51 -0500560 struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500561 get_lsa_identifier(lsaId,selfp,info,0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500562
akmhoque7b791452012-10-30 11:24:56 -0500563 //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length);
akmhoque03004e62012-09-06 01:12:28 -0500564 int ls_type=get_ls_type(selfp, info);
akmhoque1c9b92f2012-08-13 10:57:50 -0500565
akmhoque53f64222012-09-05 13:57:51 -0500566 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
567
akmhoque03004e62012-09-06 01:12:28 -0500568 if ( ls_type == LS_TYPE_NAME )
akmhoque1c9b92f2012-08-13 10:57:50 -0500569 {
akmhoque7b791452012-10-30 11:24:56 -0500570 if ( nlsr->debugging )
571 printf("Interest Received for NAME LSA \n");
572 if ( nlsr->detailed_logging )
573 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for NAME LSA \n");
akmhoque53f64222012-09-05 13:57:51 -0500574 get_name_lsa_data(lsa_data,lsaId);
575 }
akmhoque03004e62012-09-06 01:12:28 -0500576 else if ( ls_type == LS_TYPE_ADJ )
akmhoque53f64222012-09-05 13:57:51 -0500577 {
akmhoque7b791452012-10-30 11:24:56 -0500578 if ( nlsr->debugging )
579 printf("Interest Received for ADJ LSA \n");
580 if ( nlsr->detailed_logging )
581 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for ADJ LSA \n");
akmhoque53f64222012-09-05 13:57:51 -0500582 get_adj_lsa_data(lsa_data,lsaId);
akmhoque1c9b92f2012-08-13 10:57:50 -0500583 }
584
akmhoque53f64222012-09-05 13:57:51 -0500585 char *rdata=ccn_charbuf_as_string(lsa_data);
586 char *raw_data=(char *)malloc(strlen(rdata)+1);
587 memset(raw_data,0,strlen(rdata)+1);
588 memcpy(raw_data,(char *)rdata,strlen(rdata)+1);
akmhoque03004e62012-09-06 01:12:28 -0500589 //printf("Content Data to be sent: %s\n",raw_data);
akmhoque1c9b92f2012-08-13 10:57:50 -0500590
akmhoque53f64222012-09-05 13:57:51 -0500591 struct ccn_charbuf *data=ccn_charbuf_create();
592 struct ccn_charbuf *name=ccn_charbuf_create();
593 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
akmhoque03004e62012-09-06 01:12:28 -0500594
akmhoque53f64222012-09-05 13:57:51 -0500595 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]);
akmhoque1c9b92f2012-08-13 10:57:50 -0500596
akmhoque53f64222012-09-05 13:57:51 -0500597 sp.template_ccnb=ccn_charbuf_create();
598 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
599 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
600 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
601 ccn_charbuf_append_closer(sp.template_ccnb);
akmhoque1c9b92f2012-08-13 10:57:50 -0500602
akmhoque53f64222012-09-05 13:57:51 -0500603 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
akmhoque7b791452012-10-30 11:24:56 -0500604
akmhoque53f64222012-09-05 13:57:51 -0500605 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500606 {
607 if ( nlsr->debugging )
608 printf("Signing LSA Content is successful \n");
609 if ( nlsr->detailed_logging )
610 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSA Content is successful \n");
611 }
akmhoque53f64222012-09-05 13:57:51 -0500612
613 res=ccn_put(nlsr->ccn,data->buf,data->length);
akmhoque7b791452012-10-30 11:24:56 -0500614
akmhoque53f64222012-09-05 13:57:51 -0500615 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500616 {
617 if ( nlsr->debugging )
618 printf("Sending LSA Content is successful \n");
619 if ( nlsr->detailed_logging )
620 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSA Content is successful \n");
621 }
akmhoque53f64222012-09-05 13:57:51 -0500622
akmhoque03004e62012-09-06 01:12:28 -0500623
624
akmhoque53f64222012-09-05 13:57:51 -0500625 ccn_charbuf_destroy(&data);
626 ccn_charbuf_destroy(&name);
627 ccn_charbuf_destroy(&sp.template_ccnb);
628 ccn_charbuf_destroy(&lsa_data);
629
630 free(raw_data);
631 free(lsaId);
akmhoque1c9b92f2012-08-13 10:57:50 -0500632}
633
akmhoque03004e62012-09-06 01:12:28 -0500634/* Call back function registered in ccnd to get all content coming to NLSR application */
635
akmhoque53f64222012-09-05 13:57:51 -0500636enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
637 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500638{
639
akmhoqueffacaa82012-09-13 17:48:30 -0500640 nlsr_lock();
akmhoque03004e62012-09-06 01:12:28 -0500641
akmhoque53f64222012-09-05 13:57:51 -0500642 switch(kind) {
643 case CCN_UPCALL_FINAL:
644 break;
645 case CCN_UPCALL_CONTENT:
akmhoque7b791452012-10-30 11:24:56 -0500646 if ( nlsr->debugging )
647 printf("Content Received for Name: ");
648 if ( nlsr->detailed_logging )
649 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: ");
650
akmhoque03004e62012-09-06 01:12:28 -0500651 struct ccn_charbuf*c;
652 c=ccn_charbuf_create();
653 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
akmhoque7b791452012-10-30 11:24:56 -0500654 if ( nlsr->debugging )
655 printf("%s\n",ccn_charbuf_as_string(c));
656 if ( nlsr->detailed_logging )
657 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c));
658
akmhoque03004e62012-09-06 01:12:28 -0500659 ccn_charbuf_destroy(&c);
660
661 process_incoming_content(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500662
akmhoque53f64222012-09-05 13:57:51 -0500663 break;
664 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoque7b791452012-10-30 11:24:56 -0500665 //printf("Interest Timed Out Received for Name: ");
666 if ( nlsr->debugging )
667 printf("Interest Timed Out Received for Name: ");
668 if ( nlsr->detailed_logging )
669 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: ");
akmhoque03004e62012-09-06 01:12:28 -0500670
671 struct ccn_charbuf*ito;
672 ito=ccn_charbuf_create();
673 ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
akmhoque7b791452012-10-30 11:24:56 -0500674
675 if ( nlsr->debugging )
676 printf("%s\n",ccn_charbuf_as_string(ito));
677 if ( nlsr->detailed_logging )
678 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito));
679
680 //printf("%s\n",ccn_charbuf_as_string(ito));
akmhoque03004e62012-09-06 01:12:28 -0500681 ccn_charbuf_destroy(&ito);
682
akmhoque53f64222012-09-05 13:57:51 -0500683 process_incoming_timed_out_interest(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500684
akmhoque53f64222012-09-05 13:57:51 -0500685 break;
686 default:
687 fprintf(stderr, "Unexpected response of kind %d\n", kind);
akmhoque7b791452012-10-30 11:24:56 -0500688 if ( nlsr->debugging )
689 printf("Unexpected response of kind %d\n", kind);
690 if ( nlsr->detailed_logging )
691 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind);
akmhoqueffacaa82012-09-13 17:48:30 -0500692 break;
akmhoque53f64222012-09-05 13:57:51 -0500693 }
akmhoqueffacaa82012-09-13 17:48:30 -0500694
695 nlsr_unlock();
akmhoqued79438d2012-08-27 13:31:42 -0500696
akmhoque53f64222012-09-05 13:57:51 -0500697 return CCN_UPCALL_RESULT_OK;
akmhoqued79438d2012-08-27 13:31:42 -0500698}
699
akmhoque03004e62012-09-06 01:12:28 -0500700
akmhoqued79438d2012-08-27 13:31:42 -0500701void
akmhoque53f64222012-09-05 13:57:51 -0500702process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500703{
akmhoque7b791452012-10-30 11:24:56 -0500704 //printf("process_incoming_content called \n");
705 if ( nlsr->debugging )
706 printf("process_incoming_content called \n");
707 if ( nlsr->detailed_logging )
708 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n");
akmhoque53f64222012-09-05 13:57:51 -0500709
710 const unsigned char *comp_ptr1;
711 size_t comp_size;
712 int res,i;
713 int nlsr_position=0;
714 int name_comps=(int)info->interest_comps->n;
715
716 for(i=0;i<name_comps;i++)
717 {
718 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
719 if( res == 0)
720 {
721 nlsr_position=i;
722 break;
723 }
724 }
725
726 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
727
akmhoque7b791452012-10-30 11:24:56 -0500728 //printf("Det= %s \n",comp_ptr1);
akmhoque53f64222012-09-05 13:57:51 -0500729
730 if(!strcmp((char *)comp_ptr1,"info"))
731 {
732 process_incoming_content_info(selfp,info);
733 }
734 if(!strcmp((char *)comp_ptr1,"lsdb"))
735 {
736 process_incoming_content_lsdb(selfp,info);
737 }
738 if(!strcmp((char *)comp_ptr1,"lsa"))
739 {
740 process_incoming_content_lsa(selfp,info);
741 }
akmhoque03004e62012-09-06 01:12:28 -0500742
akmhoque53f64222012-09-05 13:57:51 -0500743}
744
akmhoque03004e62012-09-06 01:12:28 -0500745
akmhoque53f64222012-09-05 13:57:51 -0500746void
747process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info)
748{
akmhoque7b791452012-10-30 11:24:56 -0500749 //printf("process_incoming_content_info called \n");
750 if ( nlsr->debugging )
751 printf("process_incoming_content_info called \n");
752 if ( nlsr->detailed_logging )
753 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n");
akmhoque03004e62012-09-06 01:12:28 -0500754
akmhoque53f64222012-09-05 13:57:51 -0500755 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
756 get_nbr(nbr,selfp,info);
akmhoque03004e62012-09-06 01:12:28 -0500757
akmhoque7b791452012-10-30 11:24:56 -0500758 if ( nlsr->debugging )
759 printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
760 if ( nlsr->detailed_logging )
761 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
akmhoque03004e62012-09-06 01:12:28 -0500762
akmhoque53f64222012-09-05 13:57:51 -0500763
764 const unsigned char *ptr;
765 size_t length;
766 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);
akmhoque03004e62012-09-06 01:12:28 -0500767 //printf("Content data: %s\n",ptr);
akmhoque53f64222012-09-05 13:57:51 -0500768
769 long int interval=atoi((char *)ptr);
770
771
akmhoque03004e62012-09-06 01:12:28 -0500772
akmhoque53f64222012-09-05 13:57:51 -0500773 update_adjacent_timed_out_zero_to_adl(nbr);
774 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
775 update_lsdb_synch_interval_to_adl(nbr,interval);
776 print_adjacent_from_adl();
777
akmhoque03004e62012-09-06 01:12:28 -0500778
779
akmhoque53f64222012-09-05 13:57:51 -0500780 if(!nlsr->is_build_adj_lsa_sheduled)
781 {
akmhoque7b791452012-10-30 11:24:56 -0500782 if ( nlsr->debugging )
783 printf("Scheduling Build and Install Adj LSA...\n");
784 if ( nlsr->detailed_logging )
785 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n");
akmhoque53f64222012-09-05 13:57:51 -0500786 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0);
787 nlsr->is_build_adj_lsa_sheduled=1;
788 }
789 else
790 {
akmhoque7b791452012-10-30 11:24:56 -0500791 if ( nlsr->debugging )
792 printf("Build and Install Adj LSA already scheduled\n");
793 if ( nlsr->detailed_logging )
794 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n");
akmhoque53f64222012-09-05 13:57:51 -0500795 }
796
akmhoque03004e62012-09-06 01:12:28 -0500797
akmhoque53f64222012-09-05 13:57:51 -0500798 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500799
akmhoque53f64222012-09-05 13:57:51 -0500800
801}
802
akmhoque03004e62012-09-06 01:12:28 -0500803
akmhoque53f64222012-09-05 13:57:51 -0500804void
805process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info)
806{
akmhoque7b791452012-10-30 11:24:56 -0500807 if ( nlsr->debugging )
808 printf("process_incoming_content_lsdb called \n");
809 if ( nlsr->detailed_logging )
810 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500811
akmhoque53f64222012-09-05 13:57:51 -0500812 const unsigned char *ptr;
813 size_t length;
814 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);
akmhoque03004e62012-09-06 01:12:28 -0500815 //printf("Content data: %s\n",ptr);
akmhoque53f64222012-09-05 13:57:51 -0500816
817 if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) )
818 {
819 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
820 get_nbr(nbr,selfp,info);
821
822 char *nl;
823 int num_element;
824 int i;
825 char *rem;
826 const char *sep="|";
827 char *orig_router;
828 char *lst;
829 int ls_type;
830 char *lsid;
831 long int ls_id;
akmhoque03004e62012-09-06 01:12:28 -0500832 char *orig_time;
akmhoque53f64222012-09-05 13:57:51 -0500833
834 nl=strtok_r((char *)ptr,sep,&rem);
835 num_element=atoi(nl);
836
837 for(i = 0 ; i < num_element ; i++)
838 {
839 orig_router=strtok_r(NULL,sep,&rem);
840 lst=strtok_r(NULL,sep,&rem);
841 ls_type=atoi(lst);
842 printf("Orig Router: %s ls Type: %d",orig_router,ls_type);
843
844 if(ls_type == LS_TYPE_NAME)
845 {
846 lsid=strtok_r(NULL,sep,&rem);
847 ls_id=atoi(lsid);
akmhoque03004e62012-09-06 01:12:28 -0500848 orig_time=strtok_r(NULL,sep,&rem);
849 printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time);
850 int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time);
851 if ( is_new_name_lsa == 1 )
852 {
853 printf("New NAME LSA.....\n");
854 send_interest_for_name_lsa(nbr,orig_router,lst,lsid);
855 }
856 else
857 {
858 printf("Name LSA already exists in LSDB\n");
859 }
akmhoque53f64222012-09-05 13:57:51 -0500860 }
861 else
862 {
akmhoque03004e62012-09-06 01:12:28 -0500863 orig_time=strtok_r(NULL,sep,&rem);
864 printf(" Orig Time: %s\n",orig_time);
865 int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time);
866 if ( is_new_adj_lsa == 1 )
867 {
868 printf("New ADJ LSA.....\n");
869 send_interest_for_adj_lsa(nbr,orig_router,lst);
870 }
871 else
872 {
873 printf("ADJ LSA already exists in LSDB\n");
874 }
akmhoque53f64222012-09-05 13:57:51 -0500875 }
akmhoque03004e62012-09-06 01:12:28 -0500876
akmhoque53f64222012-09-05 13:57:51 -0500877 }
akmhoque53f64222012-09-05 13:57:51 -0500878
akmhoque03004e62012-09-06 01:12:28 -0500879 char *lsdb_version=(char *)malloc(20);
880 memset(lsdb_version,0,20);
881 get_lsdb_version(lsdb_version,selfp,info);
882
akmhoque53f64222012-09-05 13:57:51 -0500883 printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
akmhoque03004e62012-09-06 01:12:28 -0500884 update_adjacent_lsdb_version_to_adl(nbr,lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500885 printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
akmhoque53f64222012-09-05 13:57:51 -0500886
akmhoque62c0c192012-09-24 07:49:25 -0500887 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500888
889 free(lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500890 free(nbr);
891 }
892 else if (strcmp("WAIT",(char *)ptr) == 0)
893 {
894 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
895 get_nbr(nbr,selfp,info);
896 long int interval=get_lsdb_synch_interval(nbr->name);
897 adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500898
akmhoque62c0c192012-09-24 07:49:25 -0500899 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500900 free(nbr);
901 }
902 else
903 {
904 printf("NACK Content Received\n");
akmhoque62c0c192012-09-24 07:49:25 -0500905 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
906 get_nbr(nbr,selfp,info);
907 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque3cced642012-09-24 16:20:20 -0500908 free(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500909 }
akmhoque53f64222012-09-05 13:57:51 -0500910}
911
akmhoque03004e62012-09-06 01:12:28 -0500912
akmhoque53f64222012-09-05 13:57:51 -0500913void
914process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info)
915{
916 printf("process_incoming_content_lsa called \n");
917
918 char *sep="|";
919 char *rem;
920 char *orig_router;
921 char *orl;
922 int orig_router_length;
923 char *lst;
924 int ls_type;
925 char *lsid;
926 long int ls_id;
927 char *isvld;
928 int isValid;
929 char *num_link;
930 int no_link;
931 char *np;
932 char *np_length;
933 int name_length;
934 char *data;
935 char *orig_time;
936
937 const unsigned char *ptr;
938 size_t length;
939 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);
akmhoque03004e62012-09-06 01:12:28 -0500940 //printf("Content data Received: %s\n",ptr);
akmhoque53f64222012-09-05 13:57:51 -0500941
akmhoque29c1db52012-09-07 14:47:43 -0500942
943
944
945
946
akmhoque53f64222012-09-05 13:57:51 -0500947 printf("LSA Data\n");
948
949 if( strlen((char *) ptr ) > 0 )
950 {
951
952 orig_router=strtok_r((char *)ptr,sep,&rem);
953 orl=strtok_r(NULL,sep,&rem);
954 orig_router_length=atoi(orl);
955
956 printf(" Orig Router Name : %s\n",orig_router);
957 printf(" Orig Router Length: %d\n",orig_router_length);
958
959 lst=strtok_r(NULL,sep,&rem);
960 ls_type=atoi(lst);
961
962 printf(" LS Type : %d\n",ls_type);
963
akmhoque03004e62012-09-06 01:12:28 -0500964 if ( ls_type == LS_TYPE_NAME )
akmhoque53f64222012-09-05 13:57:51 -0500965 {
966 lsid=strtok_r(NULL,sep,&rem);
967 ls_id=atoi(lsid);
akmhoque03004e62012-09-06 01:12:28 -0500968 orig_time=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -0500969 isvld=strtok_r(NULL,sep,&rem);
970 isValid=atoi(isvld);
971 np=strtok_r(NULL,sep,&rem);
972 np_length=strtok_r(NULL,sep,&rem);
973 name_length=atoi(np_length);
akmhoque53f64222012-09-05 13:57:51 -0500974 printf(" LS ID : %ld\n",ls_id);
975 printf(" isValid : %d\n",isValid);
976 printf(" Name Prefix : %s\n",np);
akmhoque03004e62012-09-06 01:12:28 -0500977 printf(" Orig Time : %s\n",orig_time);
akmhoque53f64222012-09-05 13:57:51 -0500978 printf(" Name Prefix length: %d\n",name_length);
979
akmhoque03004e62012-09-06 01:12:28 -0500980 build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np);
981
akmhoque53f64222012-09-05 13:57:51 -0500982 }
akmhoque03004e62012-09-06 01:12:28 -0500983 else if ( ls_type == LS_TYPE_ADJ )
akmhoque53f64222012-09-05 13:57:51 -0500984 {
985 orig_time=strtok_r(NULL,sep,&rem);
986 num_link=strtok_r(NULL,sep,&rem);
987 no_link=atoi(num_link);
988 data=rem;
989
990 printf(" No Link : %d\n",no_link);
991 printf(" Data : %s\n",data);
992
993 build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
994 }
akmhoque53f64222012-09-05 13:57:51 -0500995 }
akmhoque53f64222012-09-05 13:57:51 -0500996}
997
akmhoque03004e62012-09-06 01:12:28 -0500998
akmhoque53f64222012-09-05 13:57:51 -0500999void
1000process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1001{
1002 printf("process_incoming_timed_out_interest called \n");
akmhoque53f64222012-09-05 13:57:51 -05001003 int res,i;
1004 int nlsr_position=0;
1005 int name_comps=(int)info->interest_comps->n;
1006
1007 for(i=0;i<name_comps;i++)
1008 {
1009 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
1010 if( res == 0)
1011 {
1012 nlsr_position=i;
1013 break;
1014 }
1015 }
1016
1017 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
1018 {
1019 process_incoming_timed_out_interest_info(selfp,info);
1020 }
akmhoque29c1db52012-09-07 14:47:43 -05001021 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
1022 {
1023 process_incoming_timed_out_interest_lsdb(selfp,info);
1024 }
1025 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsa") == 0)
1026 {
1027 process_incoming_timed_out_interest_lsa(selfp,info);
1028 }
akmhoque53f64222012-09-05 13:57:51 -05001029}
1030
1031void
1032process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1033{
1034 printf("process_incoming_timed_out_interest_info called \n");
1035
1036 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1037 get_nbr(nbr,selfp,info);
1038
1039 printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
akmhoque03004e62012-09-06 01:12:28 -05001040
1041
akmhoque53f64222012-09-05 13:57:51 -05001042 update_adjacent_timed_out_to_adl(nbr,1);
1043 print_adjacent_from_adl();
1044 int timed_out=get_timed_out_number(nbr);
akmhoque03004e62012-09-06 01:12:28 -05001045
akmhoque53f64222012-09-05 13:57:51 -05001046
1047 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
1048 {
1049 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
1050 send_info_interest_to_neighbor(nbr);
1051 }
1052 else
1053 {
1054 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
1055 update_adjacent_status_to_adl(nbr,NBR_DOWN);
1056 if(!nlsr->is_build_adj_lsa_sheduled)
1057 {
1058 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1059 nlsr->is_build_adj_lsa_sheduled=1;
1060 }
1061 }
1062
1063 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -05001064
akmhoque53f64222012-09-05 13:57:51 -05001065
1066}
1067
akmhoque29c1db52012-09-07 14:47:43 -05001068void
1069process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1070{
1071 printf("process_incoming_timed_out_interest_lsdb called \n");
akmhoque14b3f342012-09-14 10:39:02 -05001072
1073 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1074 get_nbr(nbr,selfp,info);
1075
1076 printf("LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
1077
akmhoque62c0c192012-09-24 07:49:25 -05001078 update_lsdb_interest_timed_out_to_adl(nbr,1);
1079
akmhoque14b3f342012-09-14 10:39:02 -05001080 int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr);
1081
akmhoque62c0c192012-09-24 07:49:25 -05001082 printf("Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry);
1083
1084 if( interst_timed_out_num >= nlsr->interest_retry )
akmhoque14b3f342012-09-14 10:39:02 -05001085 {
akmhoque14b3f342012-09-14 10:39:02 -05001086 update_adjacent_status_to_adl(nbr,NBR_DOWN);
1087 if(!nlsr->is_build_adj_lsa_sheduled)
1088 {
1089 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1090 nlsr->is_build_adj_lsa_sheduled=1;
1091 }
1092 }
1093 free(nbr->name);
1094 free(nbr);
akmhoque29c1db52012-09-07 14:47:43 -05001095}
1096
1097void
1098process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1099{
1100 printf("process_incoming_timed_out_interest_lsa called \n");
1101
1102}
1103
akmhoque03004e62012-09-06 01:12:28 -05001104int
akmhoque53f64222012-09-05 13:57:51 -05001105send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1106{
akmhoqueffacaa82012-09-13 17:48:30 -05001107 if(flags == CCN_SCHEDULE_CANCEL)
1108 {
1109 return -1;
1110 }
1111
1112 nlsr_lock();
1113
akmhoque53f64222012-09-05 13:57:51 -05001114 printf("send_info_interest called \n");
1115 printf("\n");
akmhoqued79438d2012-08-27 13:31:42 -05001116
akmhoque53f64222012-09-05 13:57:51 -05001117 int adl_element,i;
akmhoque53f64222012-09-05 13:57:51 -05001118 struct ndn_neighbor *nbr;
1119
1120 struct hashtb_enumerator ee;
1121 struct hashtb_enumerator *e = &ee;
1122
1123 hashtb_start(nlsr->adl, e);
1124 adl_element=hashtb_n(nlsr->adl);
1125
1126 for(i=0;i<adl_element;i++)
1127 {
1128 nbr=e->data;
1129 send_info_interest_to_neighbor(nbr->neighbor);
1130 hashtb_next(e);
1131 }
akmhoque53f64222012-09-05 13:57:51 -05001132 hashtb_end(e);
1133
akmhoqueffacaa82012-09-13 17:48:30 -05001134 nlsr_unlock();
1135
akmhoque9fa58a82012-10-05 07:56:02 -05001136 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0);
1137
akmhoque53f64222012-09-05 13:57:51 -05001138 return 0;
1139}
1140
1141void
1142send_info_interest_to_neighbor(struct name_prefix *nbr)
1143{
1144 printf("send_info_interest_to_neighbor called \n");
akmhoqued79438d2012-08-27 13:31:42 -05001145
1146 int res;
akmhoque53f64222012-09-05 13:57:51 -05001147 char info_str[5];
1148 char nlsr_str[5];
akmhoque53f64222012-09-05 13:57:51 -05001149
akmhoqued79438d2012-08-27 13:31:42 -05001150 memset(&nlsr_str,0,5);
1151 sprintf(nlsr_str,"nlsr");
1152 memset(&info_str,0,5);
1153 sprintf(info_str,"info");
1154
akmhoque53f64222012-09-05 13:57:51 -05001155
1156 struct ccn_charbuf *name;
akmhoqued79438d2012-08-27 13:31:42 -05001157 name=ccn_charbuf_create();
akmhoqued79438d2012-08-27 13:31:42 -05001158
akmhoque03004e62012-09-06 01:12:28 -05001159 char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
1160 memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
akmhoque53f64222012-09-05 13:57:51 -05001161 memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
1162 memcpy(int_name+strlen(int_name),"/",1);
1163 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1164 memcpy(int_name+strlen(int_name),"/",1);
1165 memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
akmhoque03004e62012-09-06 01:12:28 -05001166 memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name));
akmhoque53f64222012-09-05 13:57:51 -05001167
1168
1169 res=ccn_name_from_uri(name,int_name);
1170 if ( res >=0 )
1171 {
akmhoque53f64222012-09-05 13:57:51 -05001172 /* adding InterestLifeTime and InterestScope filter */
1173
1174 struct ccn_charbuf *templ;
1175 templ = ccn_charbuf_create();
1176
1177 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1178 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1179 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque03004e62012-09-06 01:12:28 -05001180 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1181 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1182 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1183 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque53f64222012-09-05 13:57:51 -05001184
1185 appendLifetime(templ,nlsr->interest_resend_time);
1186 ccn_charbuf_append_closer(templ); /* </Interest> */
1187 /* Adding InterestLifeTime and InterestScope filter done */
1188
1189 printf("Sending info interest on name prefix : %s \n",int_name);
1190
1191 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1192
1193 if ( res >= 0 )
1194 printf("Info interest sending Successfull .... \n");
1195 ccn_charbuf_destroy(&templ);
1196 }
1197 ccn_charbuf_destroy(&name);
1198 free(int_name);
1199
1200}
1201
1202
1203int
1204send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1205{
1206 printf("send_lsdb_interest called \n");
1207
Obaid Amin485277a2012-09-07 01:08:28 -04001208 if(flags == CCN_SCHEDULE_CANCEL)
akmhoque29c1db52012-09-07 14:47:43 -05001209 {
1210 return -1;
1211 }
Obaid Amin485277a2012-09-07 01:08:28 -04001212
akmhoqueffacaa82012-09-13 17:48:30 -05001213 nlsr_lock();
1214
akmhoque53f64222012-09-05 13:57:51 -05001215 int i, adl_element;
1216 struct ndn_neighbor *nbr;
1217
1218 struct hashtb_enumerator ee;
1219 struct hashtb_enumerator *e = &ee;
1220
1221 hashtb_start(nlsr->adl, e);
1222 adl_element=hashtb_n(nlsr->adl);
1223
1224 for(i=0;i<adl_element;i++)
1225 {
1226 nbr=e->data;
1227
1228 if(nbr->status == NBR_ACTIVE)
1229 {
1230 if(nbr->is_lsdb_send_interest_scheduled == 0)
1231 {
1232 long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name);
1233 printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
1234
akmhoque14b3f342012-09-14 10:39:02 -05001235 if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) )
akmhoque53f64222012-09-05 13:57:51 -05001236 {
1237 nbr->is_lsdb_send_interest_scheduled=1;
1238 send_lsdb_interest_to_nbr(nbr->neighbor);
1239 }
1240 }
1241 }
1242 hashtb_next(e);
1243 }
1244
1245 hashtb_end(e);
1246 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
1247
akmhoqueffacaa82012-09-13 17:48:30 -05001248 nlsr_unlock();
1249
akmhoque53f64222012-09-05 13:57:51 -05001250 return 0;
1251}
1252
1253void
1254send_lsdb_interest_to_nbr(struct name_prefix *nbr)
1255{
1256 printf("send_lsdb_interest_to_nbr called \n");
akmhoque03004e62012-09-06 01:12:28 -05001257
akmhoque53f64222012-09-05 13:57:51 -05001258 char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
1259
1260 if(last_lsdb_version !=NULL)
1261 {
1262 printf("Last LSDB Version: %s \n",last_lsdb_version);
1263
1264
1265 struct ccn_charbuf *name;
1266 int res;
akmhoque53f64222012-09-05 13:57:51 -05001267 char lsdb_str[5];
1268 char nlsr_str[5];
akmhoque03004e62012-09-06 01:12:28 -05001269
akmhoque53f64222012-09-05 13:57:51 -05001270 memset(&nlsr_str,0,5);
1271 sprintf(nlsr_str,"nlsr");
1272 memset(&lsdb_str,0,5);
1273 sprintf(lsdb_str,"lsdb");
1274 //make and send interest with exclusion filter as last_lsdb_version
1275 printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1276 name=ccn_charbuf_create();
1277 res=ccn_name_from_uri(name,nbr->name);
1278
1279 if( res >= 0)
1280 {
1281 ccn_name_append_str(name,nlsr_str);
1282 ccn_name_append_str(name,lsdb_str);
akmhoque53f64222012-09-05 13:57:51 -05001283 /* adding Exclusion filter */
1284
1285 struct ccn_charbuf *templ;
1286 templ = ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001287
akmhoque53f64222012-09-05 13:57:51 -05001288 struct ccn_charbuf *c;
1289 c = ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001290
akmhoque53f64222012-09-05 13:57:51 -05001291
1292 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1293 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1294 ccn_charbuf_append_closer(templ); /* </Name> */
1295 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
1296 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
1297 ccn_charbuf_reset(c);
1298 ccn_charbuf_putf(c, "%s", last_lsdb_version);
akmhoque03004e62012-09-06 01:12:28 -05001299
akmhoque53f64222012-09-05 13:57:51 -05001300 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
1301 ccn_charbuf_append_closer(templ); /* </Exclude> */
1302 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1303 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1304 ccn_charbuf_append(templ, "2", 1);
1305 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque03004e62012-09-06 01:12:28 -05001306
akmhoque53f64222012-09-05 13:57:51 -05001307 appendLifetime(templ,nlsr->interest_resend_time);
akmhoque03004e62012-09-06 01:12:28 -05001308
akmhoque53f64222012-09-05 13:57:51 -05001309 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque03004e62012-09-06 01:12:28 -05001310
1311
akmhoque53f64222012-09-05 13:57:51 -05001312 /* Adding Exclusion filter done */
akmhoque03004e62012-09-06 01:12:28 -05001313
akmhoque53f64222012-09-05 13:57:51 -05001314 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1315
1316 if ( res >= 0 )
1317 {
1318 printf("Interest sending Successfull .... \n");
1319 update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec());
1320
1321 }
1322 ccn_charbuf_destroy(&c);
1323 ccn_charbuf_destroy(&templ);
1324 }
1325 ccn_charbuf_destroy(&name);
1326 }
1327 set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
akmhoque53f64222012-09-05 13:57:51 -05001328}
1329
1330void
1331send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id)
1332{
1333 printf("send_interest_for_name_lsa called\n");
1334
1335 int res;
akmhoque53f64222012-09-05 13:57:51 -05001336 char lsa_str[5];
1337 char nlsr_str[5];
1338
akmhoque53f64222012-09-05 13:57:51 -05001339 memset(&nlsr_str,0,5);
1340 sprintf(nlsr_str,"nlsr");
1341 memset(&lsa_str,0,5);
1342 sprintf(lsa_str,"lsa");
1343
akmhoque03004e62012-09-06 01:12:28 -05001344 char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
1345 memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
akmhoque53f64222012-09-05 13:57:51 -05001346
1347 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1348 memcpy(int_name+strlen(int_name),"/",1);
1349 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1350 memcpy(int_name+strlen(int_name),"/",1);
1351 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
akmhoque03004e62012-09-06 01:12:28 -05001352 memcpy(int_name+strlen(int_name),"/",1);
1353 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
1354 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
akmhoque53f64222012-09-05 13:57:51 -05001355
akmhoque03004e62012-09-06 01:12:28 -05001356
akmhoque53f64222012-09-05 13:57:51 -05001357 struct ccn_charbuf *name;
1358 name=ccn_charbuf_create();
1359
1360
1361 res=ccn_name_from_uri(name,int_name);
1362 ccn_name_append_str(name,ls_type);
1363 ccn_name_append_str(name,ls_id);
akmhoque53f64222012-09-05 13:57:51 -05001364
1365
1366 /* adding InterestLifeTime and InterestScope filter */
1367
akmhoqued79438d2012-08-27 13:31:42 -05001368 struct ccn_charbuf *templ;
1369 templ = ccn_charbuf_create();
1370
akmhoqued79438d2012-08-27 13:31:42 -05001371 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1372 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1373 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque53f64222012-09-05 13:57:51 -05001374 //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
1375 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1376 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1377 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1378 ccn_charbuf_append_closer(templ); /* </Scope> */
1379
1380 appendLifetime(templ,nlsr->interest_resend_time);
akmhoqued79438d2012-08-27 13:31:42 -05001381 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque53f64222012-09-05 13:57:51 -05001382 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque03004e62012-09-06 01:12:28 -05001383
akmhoque53f64222012-09-05 13:57:51 -05001384 printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
akmhoqued79438d2012-08-27 13:31:42 -05001385
akmhoqued79438d2012-08-27 13:31:42 -05001386 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
akmhoque53f64222012-09-05 13:57:51 -05001387
akmhoqued79438d2012-08-27 13:31:42 -05001388 if ( res >= 0 )
akmhoque53f64222012-09-05 13:57:51 -05001389 printf("NAME LSA interest sending Successfull .... \n");
1390
akmhoqued79438d2012-08-27 13:31:42 -05001391 ccn_charbuf_destroy(&templ);
1392 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -05001393 free(int_name);
akmhoque03004e62012-09-06 01:12:28 -05001394
1395
akmhoqued79438d2012-08-27 13:31:42 -05001396}
akmhoque53f64222012-09-05 13:57:51 -05001397
1398void
1399send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type)
1400{
1401 printf("send_interest_for_adj_lsa called\n");
1402
1403 int res;
akmhoque53f64222012-09-05 13:57:51 -05001404 char lsa_str[5];
1405 char nlsr_str[5];
1406
akmhoque53f64222012-09-05 13:57:51 -05001407 memset(&nlsr_str,0,5);
1408 sprintf(nlsr_str,"nlsr");
1409 memset(&lsa_str,0,5);
1410 sprintf(lsa_str,"lsa");
1411
akmhoque29c1db52012-09-07 14:47:43 -05001412 char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1);
1413 memset(int_name,0,nbr->length +strlen(ls_type)+ strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1);
akmhoque53f64222012-09-05 13:57:51 -05001414
1415 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1416 memcpy(int_name+strlen(int_name),"/",1);
1417 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1418 memcpy(int_name+strlen(int_name),"/",1);
1419 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
akmhoque03004e62012-09-06 01:12:28 -05001420 memcpy(int_name+strlen(int_name),"/",1);
1421 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
akmhoque53f64222012-09-05 13:57:51 -05001422 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
akmhoque29c1db52012-09-07 14:47:43 -05001423 memcpy(int_name+strlen(int_name),"/",1);
1424 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
akmhoque03004e62012-09-06 01:12:28 -05001425
akmhoque53f64222012-09-05 13:57:51 -05001426 struct ccn_charbuf *name;
1427 name=ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001428
akmhoque53f64222012-09-05 13:57:51 -05001429
1430 ccn_name_from_uri(name,int_name);
akmhoque03004e62012-09-06 01:12:28 -05001431
akmhoque53f64222012-09-05 13:57:51 -05001432 /* adding InterestLifeTime and InterestScope filter */
1433
1434 struct ccn_charbuf *templ;
1435 templ = ccn_charbuf_create();
1436
1437 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1438 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1439 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque53f64222012-09-05 13:57:51 -05001440 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1441 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1442 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1443 ccn_charbuf_append_closer(templ); /* </Scope> */
1444
1445 appendLifetime(templ,nlsr->interest_resend_time);
1446 ccn_charbuf_append_closer(templ); /* </Interest> */
1447 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque03004e62012-09-06 01:12:28 -05001448
akmhoque29c1db52012-09-07 14:47:43 -05001449 printf("Sending ADJ LSA interest on name prefix : %s\n",int_name);
akmhoque53f64222012-09-05 13:57:51 -05001450
1451 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1452
1453 if ( res >= 0 )
akmhoque29c1db52012-09-07 14:47:43 -05001454 {
akmhoque53f64222012-09-05 13:57:51 -05001455 printf("ADJ LSA interest sending Successfull .... \n");
akmhoque29c1db52012-09-07 14:47:43 -05001456 }
akmhoque53f64222012-09-05 13:57:51 -05001457
akmhoque53f64222012-09-05 13:57:51 -05001458 ccn_charbuf_destroy(&templ);
1459 ccn_charbuf_destroy(&name);
1460 free(int_name);
akmhoque53f64222012-09-05 13:57:51 -05001461}