blob: 9af0a0525b9d9fc5d52bdd261609273d3a84d9be [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);
akmhoque3171d652012-11-13 11:44:33 -0600842
843 if ( nlsr->debugging )
844 printf("Orig Router: %s ls Type: %d",orig_router,ls_type);
845 if ( nlsr->detailed_logging )
846 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig Router: %s ls Type: %d",orig_router,ls_type);
847
akmhoque53f64222012-09-05 13:57:51 -0500848
849 if(ls_type == LS_TYPE_NAME)
850 {
851 lsid=strtok_r(NULL,sep,&rem);
852 ls_id=atoi(lsid);
akmhoque03004e62012-09-06 01:12:28 -0500853 orig_time=strtok_r(NULL,sep,&rem);
akmhoque3171d652012-11-13 11:44:33 -0600854
855 if ( nlsr->debugging )
856 printf(" LS Id: %ld Orig Time: %s\n",ls_id ,orig_time);
857 if ( nlsr->detailed_logging )
858 writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld Orig Time: %s\n",ls_id ,orig_time);
859
860
akmhoque03004e62012-09-06 01:12:28 -0500861 int is_new_name_lsa=check_is_new_name_lsa(orig_router,lst,lsid,orig_time);
862 if ( is_new_name_lsa == 1 )
863 {
akmhoque3171d652012-11-13 11:44:33 -0600864 if ( nlsr->debugging )
865 printf("New NAME LSA.....\n");
866 if ( nlsr->detailed_logging )
867 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New NAME LSA.....\n");
868
akmhoque03004e62012-09-06 01:12:28 -0500869 send_interest_for_name_lsa(nbr,orig_router,lst,lsid);
870 }
871 else
872 {
akmhoque3171d652012-11-13 11:44:33 -0600873 if ( nlsr->debugging )
874 printf("Name LSA already exists in LSDB\n");
875 if ( nlsr->detailed_logging )
876 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA already exists in LSDB\n");
877
akmhoque03004e62012-09-06 01:12:28 -0500878 }
akmhoque53f64222012-09-05 13:57:51 -0500879 }
880 else
881 {
akmhoque03004e62012-09-06 01:12:28 -0500882 orig_time=strtok_r(NULL,sep,&rem);
akmhoque3171d652012-11-13 11:44:33 -0600883
884 if ( nlsr->debugging )
885 printf(" Orig Time: %s\n",orig_time);
886 if ( nlsr->detailed_logging )
887 writeLogg(__FILE__,__FUNCTION__,__LINE__," Orig Time: %s\n",orig_time);
888
889
akmhoque03004e62012-09-06 01:12:28 -0500890 int is_new_adj_lsa=check_is_new_adj_lsa(orig_router,lst,orig_time);
891 if ( is_new_adj_lsa == 1 )
892 {
akmhoque3171d652012-11-13 11:44:33 -0600893 if ( nlsr->debugging )
894 printf("New Adj LSA.....\n");
895 if ( nlsr->detailed_logging )
896 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Adj LSA.....\n");
akmhoque03004e62012-09-06 01:12:28 -0500897 send_interest_for_adj_lsa(nbr,orig_router,lst);
898 }
899 else
900 {
akmhoque3171d652012-11-13 11:44:33 -0600901 if ( nlsr->debugging )
902 printf("Adj LSA already exists in LSDB\n");
903 if ( nlsr->detailed_logging )
904 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA already exists in LSDB\n");
akmhoque03004e62012-09-06 01:12:28 -0500905 }
akmhoque53f64222012-09-05 13:57:51 -0500906 }
akmhoque03004e62012-09-06 01:12:28 -0500907
akmhoque53f64222012-09-05 13:57:51 -0500908 }
akmhoque53f64222012-09-05 13:57:51 -0500909
akmhoque03004e62012-09-06 01:12:28 -0500910 char *lsdb_version=(char *)malloc(20);
911 memset(lsdb_version,0,20);
912 get_lsdb_version(lsdb_version,selfp,info);
913
akmhoque3171d652012-11-13 11:44:33 -0600914 if ( nlsr->debugging )
915 printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
916 if ( nlsr->detailed_logging )
917 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
918
akmhoque03004e62012-09-06 01:12:28 -0500919 update_adjacent_lsdb_version_to_adl(nbr,lsdb_version);
akmhoque3171d652012-11-13 11:44:33 -0600920
921 if ( nlsr->debugging )
922 printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
923 if ( nlsr->detailed_logging )
924 writeLogg(__FILE__,__FUNCTION__,__LINE__,"New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
akmhoque53f64222012-09-05 13:57:51 -0500925
akmhoque62c0c192012-09-24 07:49:25 -0500926 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500927
928 free(lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500929 free(nbr);
930 }
931 else if (strcmp("WAIT",(char *)ptr) == 0)
932 {
933 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
934 get_nbr(nbr,selfp,info);
935 long int interval=get_lsdb_synch_interval(nbr->name);
936 adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500937
akmhoque62c0c192012-09-24 07:49:25 -0500938 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500939 free(nbr);
940 }
941 else
942 {
akmhoque3171d652012-11-13 11:44:33 -0600943
944 if ( nlsr->debugging )
945 printf("NACK Content Received\n");
946 if ( nlsr->detailed_logging )
947 writeLogg(__FILE__,__FUNCTION__,__LINE__,"NACK Content Received\n");
akmhoque62c0c192012-09-24 07:49:25 -0500948 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
949 get_nbr(nbr,selfp,info);
950 update_lsdb_interest_timed_out_zero_to_adl(nbr);
akmhoque3cced642012-09-24 16:20:20 -0500951 free(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500952 }
akmhoque53f64222012-09-05 13:57:51 -0500953}
954
akmhoque03004e62012-09-06 01:12:28 -0500955
akmhoque53f64222012-09-05 13:57:51 -0500956void
957process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info)
958{
akmhoque3171d652012-11-13 11:44:33 -0600959
960
961 if ( nlsr->debugging )
962 printf("process_incoming_content_lsa called \n");
963 if ( nlsr->detailed_logging )
964 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_lsa called \n");
akmhoque53f64222012-09-05 13:57:51 -0500965
966 char *sep="|";
967 char *rem;
968 char *orig_router;
969 char *orl;
970 int orig_router_length;
971 char *lst;
972 int ls_type;
973 char *lsid;
974 long int ls_id;
975 char *isvld;
976 int isValid;
977 char *num_link;
978 int no_link;
979 char *np;
980 char *np_length;
981 int name_length;
982 char *data;
983 char *orig_time;
984
985 const unsigned char *ptr;
986 size_t length;
987 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 -0500988 //printf("Content data Received: %s\n",ptr);
akmhoque53f64222012-09-05 13:57:51 -0500989
akmhoque29c1db52012-09-07 14:47:43 -0500990
991
992
akmhoque3171d652012-11-13 11:44:33 -0600993 if ( nlsr->debugging )
994 printf("LSA Data \n");
995 if ( nlsr->detailed_logging )
996 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Data\n");
akmhoque53f64222012-09-05 13:57:51 -0500997
998 if( strlen((char *) ptr ) > 0 )
999 {
1000
1001 orig_router=strtok_r((char *)ptr,sep,&rem);
1002 orl=strtok_r(NULL,sep,&rem);
1003 orig_router_length=atoi(orl);
1004
akmhoque3171d652012-11-13 11:44:33 -06001005 if ( nlsr->debugging )
1006 {
1007 printf(" Orig Router Name : %s\n",orig_router);
1008 printf(" Orig Router Length: %d\n",orig_router_length);
1009 }
akmhoque53f64222012-09-05 13:57:51 -05001010
1011 lst=strtok_r(NULL,sep,&rem);
1012 ls_type=atoi(lst);
1013
akmhoque3171d652012-11-13 11:44:33 -06001014 if ( nlsr->debugging )
1015 printf(" LS Type : %d\n",ls_type);
akmhoque53f64222012-09-05 13:57:51 -05001016
akmhoque03004e62012-09-06 01:12:28 -05001017 if ( ls_type == LS_TYPE_NAME )
akmhoque53f64222012-09-05 13:57:51 -05001018 {
1019 lsid=strtok_r(NULL,sep,&rem);
1020 ls_id=atoi(lsid);
akmhoque03004e62012-09-06 01:12:28 -05001021 orig_time=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001022 isvld=strtok_r(NULL,sep,&rem);
1023 isValid=atoi(isvld);
1024 np=strtok_r(NULL,sep,&rem);
1025 np_length=strtok_r(NULL,sep,&rem);
1026 name_length=atoi(np_length);
akmhoque3171d652012-11-13 11:44:33 -06001027 if ( nlsr->debugging )
1028 {
1029 printf(" LS ID : %ld\n",ls_id);
1030 printf(" isValid : %d\n",isValid);
1031 printf(" Name Prefix : %s\n",np);
1032 printf(" Orig Time : %s\n",orig_time);
1033 printf(" Name Prefix length: %d\n",name_length);
1034 }
akmhoque53f64222012-09-05 13:57:51 -05001035
akmhoque03004e62012-09-06 01:12:28 -05001036 build_and_install_others_name_lsa(orig_router,ls_type,ls_id,orig_time,isValid,np);
1037
akmhoque53f64222012-09-05 13:57:51 -05001038 }
akmhoque03004e62012-09-06 01:12:28 -05001039 else if ( ls_type == LS_TYPE_ADJ )
akmhoque53f64222012-09-05 13:57:51 -05001040 {
1041 orig_time=strtok_r(NULL,sep,&rem);
1042 num_link=strtok_r(NULL,sep,&rem);
1043 no_link=atoi(num_link);
1044 data=rem;
1045
akmhoque3171d652012-11-13 11:44:33 -06001046 if ( nlsr->debugging )
1047 {
1048 printf(" No Link : %d\n",no_link);
1049 printf(" Data : %s\n",data);
1050 }
akmhoque53f64222012-09-05 13:57:51 -05001051 build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
1052 }
akmhoque53f64222012-09-05 13:57:51 -05001053 }
akmhoque53f64222012-09-05 13:57:51 -05001054}
1055
akmhoque03004e62012-09-06 01:12:28 -05001056
akmhoque53f64222012-09-05 13:57:51 -05001057void
1058process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1059{
akmhoque3171d652012-11-13 11:44:33 -06001060
1061
1062 if ( nlsr->debugging )
1063 printf("process_incoming_timed_out_interest called \n");
1064 if ( nlsr->detailed_logging )
1065 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n");
1066
akmhoque53f64222012-09-05 13:57:51 -05001067 int res,i;
1068 int nlsr_position=0;
1069 int name_comps=(int)info->interest_comps->n;
1070
1071 for(i=0;i<name_comps;i++)
1072 {
1073 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
1074 if( res == 0)
1075 {
1076 nlsr_position=i;
1077 break;
1078 }
1079 }
1080
1081 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
1082 {
1083 process_incoming_timed_out_interest_info(selfp,info);
1084 }
akmhoque29c1db52012-09-07 14:47:43 -05001085 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
1086 {
1087 process_incoming_timed_out_interest_lsdb(selfp,info);
1088 }
1089 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsa") == 0)
1090 {
1091 process_incoming_timed_out_interest_lsa(selfp,info);
1092 }
akmhoque53f64222012-09-05 13:57:51 -05001093}
1094
1095void
1096process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1097{
akmhoque3171d652012-11-13 11:44:33 -06001098
1099 if ( nlsr->debugging )
1100 printf("process_incoming_timed_out_interest_info called \n");
1101 if ( nlsr->detailed_logging )
1102 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n");
akmhoque53f64222012-09-05 13:57:51 -05001103
1104 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1105 get_nbr(nbr,selfp,info);
1106
akmhoque3171d652012-11-13 11:44:33 -06001107 if ( nlsr->debugging )
1108 printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
1109 if ( nlsr->detailed_logging )
1110 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
1111
akmhoque03004e62012-09-06 01:12:28 -05001112
1113
akmhoque53f64222012-09-05 13:57:51 -05001114 update_adjacent_timed_out_to_adl(nbr,1);
1115 print_adjacent_from_adl();
1116 int timed_out=get_timed_out_number(nbr);
akmhoque03004e62012-09-06 01:12:28 -05001117
akmhoque3171d652012-11-13 11:44:33 -06001118 if ( nlsr->debugging )
1119 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
1120 if ( nlsr->detailed_logging )
1121 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
1122
akmhoque53f64222012-09-05 13:57:51 -05001123
1124 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
1125 {
akmhoque53f64222012-09-05 13:57:51 -05001126 send_info_interest_to_neighbor(nbr);
1127 }
1128 else
akmhoque3171d652012-11-13 11:44:33 -06001129 {
akmhoque53f64222012-09-05 13:57:51 -05001130 update_adjacent_status_to_adl(nbr,NBR_DOWN);
1131 if(!nlsr->is_build_adj_lsa_sheduled)
1132 {
1133 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1134 nlsr->is_build_adj_lsa_sheduled=1;
1135 }
1136 }
1137
1138 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -05001139
akmhoque53f64222012-09-05 13:57:51 -05001140
1141}
1142
akmhoque29c1db52012-09-07 14:47:43 -05001143void
1144process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1145{
akmhoque3171d652012-11-13 11:44:33 -06001146 if ( nlsr->debugging )
1147 printf("process_incoming_timed_out_interest_lsdb called \n");
1148 if ( nlsr->detailed_logging )
1149 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_lsdb called \n");
akmhoque14b3f342012-09-14 10:39:02 -05001150
1151 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
1152 get_nbr(nbr,selfp,info);
1153
akmhoque3171d652012-11-13 11:44:33 -06001154 if ( nlsr->debugging )
1155 printf("LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
1156 if ( nlsr->detailed_logging )
1157 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
1158
akmhoque14b3f342012-09-14 10:39:02 -05001159
akmhoque62c0c192012-09-24 07:49:25 -05001160 update_lsdb_interest_timed_out_to_adl(nbr,1);
1161
akmhoque14b3f342012-09-14 10:39:02 -05001162 int interst_timed_out_num=get_lsdb_interest_timed_out_number(nbr);
1163
akmhoque3171d652012-11-13 11:44:33 -06001164 if ( nlsr->debugging )
1165 printf("Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry);
1166 if ( nlsr->detailed_logging )
1167 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed out number : %d Interest Retry: %d \n",interst_timed_out_num,nlsr->interest_retry);
1168
1169
akmhoque62c0c192012-09-24 07:49:25 -05001170
1171 if( interst_timed_out_num >= nlsr->interest_retry )
akmhoque14b3f342012-09-14 10:39:02 -05001172 {
akmhoque14b3f342012-09-14 10:39:02 -05001173 update_adjacent_status_to_adl(nbr,NBR_DOWN);
1174 if(!nlsr->is_build_adj_lsa_sheduled)
1175 {
1176 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
1177 nlsr->is_build_adj_lsa_sheduled=1;
1178 }
1179 }
1180 free(nbr->name);
1181 free(nbr);
akmhoque29c1db52012-09-07 14:47:43 -05001182}
1183
1184void
1185process_incoming_timed_out_interest_lsa(struct ccn_closure* selfp, struct ccn_upcall_info* info)
1186{
akmhoque3171d652012-11-13 11:44:33 -06001187 if ( nlsr->debugging )
1188 printf("process_incoming_timed_out_interest_lsa called \n");
1189 if ( nlsr->detailed_logging )
1190 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_lsa called \n");
akmhoque29c1db52012-09-07 14:47:43 -05001191
1192}
1193
akmhoque03004e62012-09-06 01:12:28 -05001194int
akmhoque53f64222012-09-05 13:57:51 -05001195send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1196{
akmhoqueffacaa82012-09-13 17:48:30 -05001197 if(flags == CCN_SCHEDULE_CANCEL)
1198 {
1199 return -1;
1200 }
1201
1202 nlsr_lock();
1203
akmhoque3171d652012-11-13 11:44:33 -06001204 if ( nlsr->debugging )
1205 printf("send_info_interest called \n");
1206 if ( nlsr->detailed_logging )
1207 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n");
1208
1209 if ( nlsr->debugging )
1210 printf("\n");
1211 if ( nlsr->detailed_logging )
1212 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoqued79438d2012-08-27 13:31:42 -05001213
akmhoque53f64222012-09-05 13:57:51 -05001214 int adl_element,i;
akmhoque53f64222012-09-05 13:57:51 -05001215 struct ndn_neighbor *nbr;
1216
1217 struct hashtb_enumerator ee;
1218 struct hashtb_enumerator *e = &ee;
1219
1220 hashtb_start(nlsr->adl, e);
1221 adl_element=hashtb_n(nlsr->adl);
1222
1223 for(i=0;i<adl_element;i++)
1224 {
1225 nbr=e->data;
1226 send_info_interest_to_neighbor(nbr->neighbor);
1227 hashtb_next(e);
1228 }
akmhoque53f64222012-09-05 13:57:51 -05001229 hashtb_end(e);
1230
akmhoqueffacaa82012-09-13 17:48:30 -05001231 nlsr_unlock();
1232
akmhoque9fa58a82012-10-05 07:56:02 -05001233 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0);
1234
akmhoque53f64222012-09-05 13:57:51 -05001235 return 0;
1236}
1237
1238void
1239send_info_interest_to_neighbor(struct name_prefix *nbr)
1240{
akmhoque3171d652012-11-13 11:44:33 -06001241
1242 if ( nlsr->debugging )
1243 printf("send_info_interest_to_neighbor called \n");
1244 if ( nlsr->detailed_logging )
1245 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n");
1246
akmhoqued79438d2012-08-27 13:31:42 -05001247
1248 int res;
akmhoque53f64222012-09-05 13:57:51 -05001249 char info_str[5];
1250 char nlsr_str[5];
akmhoque53f64222012-09-05 13:57:51 -05001251
akmhoqued79438d2012-08-27 13:31:42 -05001252 memset(&nlsr_str,0,5);
1253 sprintf(nlsr_str,"nlsr");
1254 memset(&info_str,0,5);
1255 sprintf(info_str,"info");
1256
akmhoque53f64222012-09-05 13:57:51 -05001257
1258 struct ccn_charbuf *name;
akmhoqued79438d2012-08-27 13:31:42 -05001259 name=ccn_charbuf_create();
akmhoqued79438d2012-08-27 13:31:42 -05001260
akmhoque03004e62012-09-06 01:12:28 -05001261 char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
1262 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 -05001263 memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
1264 memcpy(int_name+strlen(int_name),"/",1);
1265 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1266 memcpy(int_name+strlen(int_name),"/",1);
1267 memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
akmhoque03004e62012-09-06 01:12:28 -05001268 memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name));
akmhoque53f64222012-09-05 13:57:51 -05001269
1270
1271 res=ccn_name_from_uri(name,int_name);
1272 if ( res >=0 )
1273 {
akmhoque53f64222012-09-05 13:57:51 -05001274 /* adding InterestLifeTime and InterestScope filter */
1275
1276 struct ccn_charbuf *templ;
1277 templ = ccn_charbuf_create();
1278
1279 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1280 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1281 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque03004e62012-09-06 01:12:28 -05001282 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1283 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1284 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1285 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque53f64222012-09-05 13:57:51 -05001286
1287 appendLifetime(templ,nlsr->interest_resend_time);
1288 ccn_charbuf_append_closer(templ); /* </Interest> */
1289 /* Adding InterestLifeTime and InterestScope filter done */
1290
akmhoque3171d652012-11-13 11:44:33 -06001291 if ( nlsr->debugging )
1292 printf("Sending info interest on name prefix : %s \n",int_name);
1293 if ( nlsr->detailed_logging )
1294 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s \n",int_name);
akmhoque53f64222012-09-05 13:57:51 -05001295
1296 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1297
1298 if ( res >= 0 )
akmhoque3171d652012-11-13 11:44:33 -06001299 {
1300 if ( nlsr->debugging )
1301 printf("Info interest sending Successfull .... \n");
1302 if ( nlsr->detailed_logging )
1303 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n");
1304 }
akmhoque53f64222012-09-05 13:57:51 -05001305 ccn_charbuf_destroy(&templ);
1306 }
1307 ccn_charbuf_destroy(&name);
1308 free(int_name);
1309
1310}
1311
1312
1313int
1314send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1315{
akmhoque3171d652012-11-13 11:44:33 -06001316 if ( nlsr->debugging )
1317 printf("send_lsdb_interest called \n");
1318 if ( nlsr->detailed_logging )
1319 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest called \n");
akmhoque53f64222012-09-05 13:57:51 -05001320
Obaid Amin485277a2012-09-07 01:08:28 -04001321 if(flags == CCN_SCHEDULE_CANCEL)
akmhoque29c1db52012-09-07 14:47:43 -05001322 {
1323 return -1;
1324 }
Obaid Amin485277a2012-09-07 01:08:28 -04001325
akmhoqueffacaa82012-09-13 17:48:30 -05001326 nlsr_lock();
1327
akmhoque53f64222012-09-05 13:57:51 -05001328 int i, adl_element;
1329 struct ndn_neighbor *nbr;
1330
1331 struct hashtb_enumerator ee;
1332 struct hashtb_enumerator *e = &ee;
1333
1334 hashtb_start(nlsr->adl, e);
1335 adl_element=hashtb_n(nlsr->adl);
1336
1337 for(i=0;i<adl_element;i++)
1338 {
1339 nbr=e->data;
1340
1341 if(nbr->status == NBR_ACTIVE)
1342 {
1343 if(nbr->is_lsdb_send_interest_scheduled == 0)
1344 {
akmhoque3171d652012-11-13 11:44:33 -06001345 long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name);
1346 if ( nlsr->debugging )
1347 printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
1348 if ( nlsr->detailed_logging )
1349 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
1350
akmhoque53f64222012-09-05 13:57:51 -05001351
akmhoque14b3f342012-09-14 10:39:02 -05001352 if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) )
akmhoque53f64222012-09-05 13:57:51 -05001353 {
1354 nbr->is_lsdb_send_interest_scheduled=1;
1355 send_lsdb_interest_to_nbr(nbr->neighbor);
1356 }
1357 }
1358 }
1359 hashtb_next(e);
1360 }
1361
1362 hashtb_end(e);
1363 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
1364
akmhoqueffacaa82012-09-13 17:48:30 -05001365 nlsr_unlock();
1366
akmhoque53f64222012-09-05 13:57:51 -05001367 return 0;
1368}
1369
1370void
1371send_lsdb_interest_to_nbr(struct name_prefix *nbr)
1372{
akmhoque3171d652012-11-13 11:44:33 -06001373 if ( nlsr->debugging )
1374 printf("send_lsdb_interest_to_nbr called \n");
1375 if ( nlsr->detailed_logging )
1376 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest_to_nbr called \n");
akmhoque03004e62012-09-06 01:12:28 -05001377
akmhoque53f64222012-09-05 13:57:51 -05001378 char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
1379
1380 if(last_lsdb_version !=NULL)
1381 {
akmhoque3171d652012-11-13 11:44:33 -06001382
akmhoque53f64222012-09-05 13:57:51 -05001383
akmhoque3171d652012-11-13 11:44:33 -06001384 if ( nlsr->debugging )
1385 printf("Last LSDB Version: %s \n",last_lsdb_version);
1386 if ( nlsr->detailed_logging )
1387 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Last LSDB Version: %s \n",last_lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -05001388
1389 struct ccn_charbuf *name;
1390 int res;
akmhoque53f64222012-09-05 13:57:51 -05001391 char lsdb_str[5];
1392 char nlsr_str[5];
akmhoque03004e62012-09-06 01:12:28 -05001393
akmhoque53f64222012-09-05 13:57:51 -05001394 memset(&nlsr_str,0,5);
1395 sprintf(nlsr_str,"nlsr");
1396 memset(&lsdb_str,0,5);
1397 sprintf(lsdb_str,"lsdb");
1398 //make and send interest with exclusion filter as last_lsdb_version
akmhoque3171d652012-11-13 11:44:33 -06001399 if ( nlsr->debugging )
1400 printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1401 if ( nlsr->detailed_logging )
1402 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1403
akmhoque53f64222012-09-05 13:57:51 -05001404 name=ccn_charbuf_create();
1405 res=ccn_name_from_uri(name,nbr->name);
1406
1407 if( res >= 0)
1408 {
1409 ccn_name_append_str(name,nlsr_str);
1410 ccn_name_append_str(name,lsdb_str);
akmhoque53f64222012-09-05 13:57:51 -05001411 /* adding Exclusion filter */
1412
1413 struct ccn_charbuf *templ;
1414 templ = ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001415
akmhoque53f64222012-09-05 13:57:51 -05001416 struct ccn_charbuf *c;
1417 c = ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001418
akmhoque53f64222012-09-05 13:57:51 -05001419
1420 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1421 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1422 ccn_charbuf_append_closer(templ); /* </Name> */
1423 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
1424 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
1425 ccn_charbuf_reset(c);
1426 ccn_charbuf_putf(c, "%s", last_lsdb_version);
akmhoque03004e62012-09-06 01:12:28 -05001427
akmhoque53f64222012-09-05 13:57:51 -05001428 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
1429 ccn_charbuf_append_closer(templ); /* </Exclude> */
1430 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1431 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1432 ccn_charbuf_append(templ, "2", 1);
1433 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque03004e62012-09-06 01:12:28 -05001434
akmhoque53f64222012-09-05 13:57:51 -05001435 appendLifetime(templ,nlsr->interest_resend_time);
akmhoque03004e62012-09-06 01:12:28 -05001436
akmhoque53f64222012-09-05 13:57:51 -05001437 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque03004e62012-09-06 01:12:28 -05001438
1439
akmhoque53f64222012-09-05 13:57:51 -05001440 /* Adding Exclusion filter done */
akmhoque03004e62012-09-06 01:12:28 -05001441
akmhoque53f64222012-09-05 13:57:51 -05001442 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1443
1444 if ( res >= 0 )
1445 {
akmhoque3171d652012-11-13 11:44:33 -06001446 if ( nlsr->debugging )
1447 printf("Interest sending Successfull .... \n");
1448 if ( nlsr->detailed_logging )
1449 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest sending Successfull .... \n");
akmhoque53f64222012-09-05 13:57:51 -05001450 update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec());
1451
1452 }
1453 ccn_charbuf_destroy(&c);
1454 ccn_charbuf_destroy(&templ);
1455 }
1456 ccn_charbuf_destroy(&name);
1457 }
1458 set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
akmhoque53f64222012-09-05 13:57:51 -05001459}
1460
1461void
1462send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id)
1463{
akmhoque3171d652012-11-13 11:44:33 -06001464 if ( nlsr->debugging )
1465 printf("send_interest_for_name_lsa called\n");
1466 if ( nlsr->detailed_logging )
1467 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_interest_for_name_lsa called\n");
akmhoque53f64222012-09-05 13:57:51 -05001468
1469 int res;
akmhoque53f64222012-09-05 13:57:51 -05001470 char lsa_str[5];
1471 char nlsr_str[5];
1472
akmhoque53f64222012-09-05 13:57:51 -05001473 memset(&nlsr_str,0,5);
1474 sprintf(nlsr_str,"nlsr");
1475 memset(&lsa_str,0,5);
1476 sprintf(lsa_str,"lsa");
1477
akmhoque03004e62012-09-06 01:12:28 -05001478 char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3);
1479 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 -05001480
1481 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1482 memcpy(int_name+strlen(int_name),"/",1);
1483 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1484 memcpy(int_name+strlen(int_name),"/",1);
1485 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
akmhoque03004e62012-09-06 01:12:28 -05001486 memcpy(int_name+strlen(int_name),"/",1);
1487 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
1488 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
akmhoque53f64222012-09-05 13:57:51 -05001489
akmhoque03004e62012-09-06 01:12:28 -05001490
akmhoque53f64222012-09-05 13:57:51 -05001491 struct ccn_charbuf *name;
1492 name=ccn_charbuf_create();
1493
1494
1495 res=ccn_name_from_uri(name,int_name);
1496 ccn_name_append_str(name,ls_type);
1497 ccn_name_append_str(name,ls_id);
akmhoque53f64222012-09-05 13:57:51 -05001498
1499
1500 /* adding InterestLifeTime and InterestScope filter */
1501
akmhoqued79438d2012-08-27 13:31:42 -05001502 struct ccn_charbuf *templ;
1503 templ = ccn_charbuf_create();
1504
akmhoqued79438d2012-08-27 13:31:42 -05001505 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1506 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1507 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque53f64222012-09-05 13:57:51 -05001508 //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
1509 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1510 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1511 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1512 ccn_charbuf_append_closer(templ); /* </Scope> */
1513
1514 appendLifetime(templ,nlsr->interest_resend_time);
akmhoqued79438d2012-08-27 13:31:42 -05001515 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque53f64222012-09-05 13:57:51 -05001516 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque03004e62012-09-06 01:12:28 -05001517
akmhoque3171d652012-11-13 11:44:33 -06001518 if ( nlsr->debugging )
1519 printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
1520 if ( nlsr->detailed_logging )
1521 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
1522
akmhoqued79438d2012-08-27 13:31:42 -05001523
akmhoqued79438d2012-08-27 13:31:42 -05001524 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
akmhoque53f64222012-09-05 13:57:51 -05001525
akmhoqued79438d2012-08-27 13:31:42 -05001526 if ( res >= 0 )
akmhoque3171d652012-11-13 11:44:33 -06001527 {
1528 if ( nlsr->debugging )
1529 printf("NAME LSA interest sending Successfull .... \n");
1530 if ( nlsr->detailed_logging )
1531 writeLogg(__FILE__,__FUNCTION__,__LINE__,"NAME LSA interest sending Successfull .... \n");
akmhoque53f64222012-09-05 13:57:51 -05001532
akmhoque3171d652012-11-13 11:44:33 -06001533 }
akmhoqued79438d2012-08-27 13:31:42 -05001534 ccn_charbuf_destroy(&templ);
1535 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -05001536 free(int_name);
akmhoque03004e62012-09-06 01:12:28 -05001537
1538
akmhoqued79438d2012-08-27 13:31:42 -05001539}
akmhoque53f64222012-09-05 13:57:51 -05001540
1541void
1542send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type)
1543{
akmhoque3171d652012-11-13 11:44:33 -06001544 if ( nlsr->debugging )
1545 printf("send_interest_for_name_lsa called\n");
1546 if ( nlsr->detailed_logging )
1547 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_interest_for_name_lsa called\n");
akmhoque53f64222012-09-05 13:57:51 -05001548
1549 int res;
akmhoque53f64222012-09-05 13:57:51 -05001550 char lsa_str[5];
1551 char nlsr_str[5];
1552
akmhoque53f64222012-09-05 13:57:51 -05001553 memset(&nlsr_str,0,5);
1554 sprintf(nlsr_str,"nlsr");
1555 memset(&lsa_str,0,5);
1556 sprintf(lsa_str,"lsa");
1557
akmhoque29c1db52012-09-07 14:47:43 -05001558 char *int_name=(char *)malloc(nbr->length + strlen(ls_type)+strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+3+strlen(ls_type)+1);
1559 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 -05001560
1561 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1562 memcpy(int_name+strlen(int_name),"/",1);
1563 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1564 memcpy(int_name+strlen(int_name),"/",1);
1565 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
akmhoque03004e62012-09-06 01:12:28 -05001566 memcpy(int_name+strlen(int_name),"/",1);
1567 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
akmhoque53f64222012-09-05 13:57:51 -05001568 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
akmhoque29c1db52012-09-07 14:47:43 -05001569 memcpy(int_name+strlen(int_name),"/",1);
1570 memcpy(int_name+strlen(int_name),ls_type,strlen(ls_type));
akmhoque03004e62012-09-06 01:12:28 -05001571
akmhoque53f64222012-09-05 13:57:51 -05001572 struct ccn_charbuf *name;
1573 name=ccn_charbuf_create();
akmhoque03004e62012-09-06 01:12:28 -05001574
akmhoque53f64222012-09-05 13:57:51 -05001575
1576 ccn_name_from_uri(name,int_name);
akmhoque03004e62012-09-06 01:12:28 -05001577
akmhoque53f64222012-09-05 13:57:51 -05001578 /* adding InterestLifeTime and InterestScope filter */
1579
1580 struct ccn_charbuf *templ;
1581 templ = ccn_charbuf_create();
1582
1583 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1584 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1585 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque53f64222012-09-05 13:57:51 -05001586 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1587 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1588 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1589 ccn_charbuf_append_closer(templ); /* </Scope> */
1590
1591 appendLifetime(templ,nlsr->interest_resend_time);
1592 ccn_charbuf_append_closer(templ); /* </Interest> */
1593 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque03004e62012-09-06 01:12:28 -05001594
akmhoque3171d652012-11-13 11:44:33 -06001595 if ( nlsr->debugging )
1596 printf("Sending ADJ LSA interest on name prefix : %s\n",int_name);
1597 if ( nlsr->detailed_logging )
1598 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending ADJ LSA interest on name prefix : %s\n",int_name);
akmhoque53f64222012-09-05 13:57:51 -05001599
1600 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1601
1602 if ( res >= 0 )
akmhoque29c1db52012-09-07 14:47:43 -05001603 {
akmhoque3171d652012-11-13 11:44:33 -06001604 if ( nlsr->debugging )
1605 printf("ADJ LSA interest sending Successfull .... \n");
1606 if ( nlsr->detailed_logging )
1607 writeLogg(__FILE__,__FUNCTION__,__LINE__,"ADJ LSA interest sending Successfull .... \n");
akmhoque29c1db52012-09-07 14:47:43 -05001608 }
akmhoque53f64222012-09-05 13:57:51 -05001609
akmhoque53f64222012-09-05 13:57:51 -05001610 ccn_charbuf_destroy(&templ);
1611 ccn_charbuf_destroy(&name);
1612 free(int_name);
akmhoque53f64222012-09-05 13:57:51 -05001613}