blob: 258c954ad13dab9644fa5c63c315a8e98d622c76 [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
akmhoque1c9b92f2012-08-13 10:57:50 -0500278
akmhoqued79438d2012-08-27 13:31:42 -0500279 if(!strcmp((char *)comp_ptr1,"info"))
280 {
281 process_incoming_interest_info(selfp,info);
282 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600283
akmhoque53f64222012-09-05 13:57:51 -0500284}
285
286void
287process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
288{
akmhoque7b791452012-10-30 11:24:56 -0500289 if ( nlsr->debugging )
290 {
291 printf("process_incoming_interest_info called \n");
292 printf("Sending Info Content back.....\n");
293 }
294 if ( nlsr->detailed_logging )
295 {
296 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info called \n");
297 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n");
298 }
299
akmhoque53f64222012-09-05 13:57:51 -0500300
akmhoque53f64222012-09-05 13:57:51 -0500301 int res;
302 struct ccn_charbuf *data=ccn_charbuf_create();
303 struct ccn_charbuf *name=ccn_charbuf_create();
304 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
akmhoque03004e62012-09-06 01:12:28 -0500305
akmhoque53f64222012-09-05 13:57:51 -0500306 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]);
307 if (res >= 0)
308 {
309 sp.template_ccnb=ccn_charbuf_create();
310 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
311 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
312 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
313 ccn_charbuf_append_closer(sp.template_ccnb);
314
315
akmhoqueb77b95f2013-02-08 12:28:47 -0600316 char *raw_data=(char *)malloc(20);
317 memset(raw_data,0,20);
318 sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version);
akmhoque53f64222012-09-05 13:57:51 -0500319
320 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data));
321 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500322 {
323 if ( nlsr->debugging )
324 printf("Signing info Content is successful \n");
325 if ( nlsr->detailed_logging )
326 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content is successful \n");
akmhoque53f64222012-09-05 13:57:51 -0500327
akmhoque7b791452012-10-30 11:24:56 -0500328 }
akmhoque53f64222012-09-05 13:57:51 -0500329 res=ccn_put(nlsr->ccn,data->buf,data->length);
330 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500331 {
332 if ( nlsr->debugging )
333 printf("Sending Info Content is successful \n");
334 if ( nlsr->detailed_logging )
335 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content is successful \n");
336 }
337
akmhoque53f64222012-09-05 13:57:51 -0500338
339
340 struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *));
akmhoque03004e62012-09-06 01:12:28 -0500341 get_lsa_identifier(nbr,selfp,info,-1);
akmhoque7b791452012-10-30 11:24:56 -0500342
343 if ( nlsr->debugging )
344 printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
345 if ( nlsr->detailed_logging )
346 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
347
348 //printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
akmhoque03004e62012-09-06 01:12:28 -0500349
akmhoque53f64222012-09-05 13:57:51 -0500350
351 if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry )
352 {
akmhoqueb8195202012-09-25 11:53:23 -0500353 update_adjacent_timed_out_zero_to_adl(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500354 send_info_interest_to_neighbor(nbr);
355 }
356
357 free(nbr);
358 free(raw_data);
359 ccn_charbuf_destroy(&sp.template_ccnb);
360 }
akmhoque03004e62012-09-06 01:12:28 -0500361
akmhoque53f64222012-09-05 13:57:51 -0500362 ccn_charbuf_destroy(&data);
akmhoque03004e62012-09-06 01:12:28 -0500363 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -0500364
akmhoquebf1aa832012-08-13 13:26:59 -0500365}
366
367
akmhoque03004e62012-09-06 01:12:28 -0500368/* Call back function registered in ccnd to get all content coming to NLSR application */
369
akmhoque53f64222012-09-05 13:57:51 -0500370enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
371 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500372{
373
akmhoqueffacaa82012-09-13 17:48:30 -0500374 nlsr_lock();
akmhoque03004e62012-09-06 01:12:28 -0500375
akmhoque53f64222012-09-05 13:57:51 -0500376 switch(kind) {
377 case CCN_UPCALL_FINAL:
378 break;
379 case CCN_UPCALL_CONTENT:
akmhoque7b791452012-10-30 11:24:56 -0500380 if ( nlsr->debugging )
381 printf("Content Received for Name: ");
382 if ( nlsr->detailed_logging )
383 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: ");
384
akmhoque03004e62012-09-06 01:12:28 -0500385 struct ccn_charbuf*c;
386 c=ccn_charbuf_create();
387 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
akmhoque7b791452012-10-30 11:24:56 -0500388 if ( nlsr->debugging )
389 printf("%s\n",ccn_charbuf_as_string(c));
390 if ( nlsr->detailed_logging )
391 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c));
392
akmhoque03004e62012-09-06 01:12:28 -0500393 ccn_charbuf_destroy(&c);
394
395 process_incoming_content(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500396
akmhoque53f64222012-09-05 13:57:51 -0500397 break;
398 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoque7b791452012-10-30 11:24:56 -0500399 //printf("Interest Timed Out Received for Name: ");
400 if ( nlsr->debugging )
401 printf("Interest Timed Out Received for Name: ");
402 if ( nlsr->detailed_logging )
403 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Received for Name: ");
akmhoque03004e62012-09-06 01:12:28 -0500404
405 struct ccn_charbuf*ito;
406 ito=ccn_charbuf_create();
407 ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
akmhoque7b791452012-10-30 11:24:56 -0500408
409 if ( nlsr->debugging )
410 printf("%s\n",ccn_charbuf_as_string(ito));
411 if ( nlsr->detailed_logging )
412 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito));
413
414 //printf("%s\n",ccn_charbuf_as_string(ito));
akmhoque03004e62012-09-06 01:12:28 -0500415 ccn_charbuf_destroy(&ito);
416
akmhoque53f64222012-09-05 13:57:51 -0500417 process_incoming_timed_out_interest(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500418
akmhoque53f64222012-09-05 13:57:51 -0500419 break;
420 default:
421 fprintf(stderr, "Unexpected response of kind %d\n", kind);
akmhoque7b791452012-10-30 11:24:56 -0500422 if ( nlsr->debugging )
423 printf("Unexpected response of kind %d\n", kind);
424 if ( nlsr->detailed_logging )
425 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of kind %d\n", kind);
akmhoqueffacaa82012-09-13 17:48:30 -0500426 break;
akmhoque53f64222012-09-05 13:57:51 -0500427 }
akmhoqueffacaa82012-09-13 17:48:30 -0500428
429 nlsr_unlock();
akmhoqued79438d2012-08-27 13:31:42 -0500430
akmhoque53f64222012-09-05 13:57:51 -0500431 return CCN_UPCALL_RESULT_OK;
akmhoqued79438d2012-08-27 13:31:42 -0500432}
433
akmhoque03004e62012-09-06 01:12:28 -0500434
akmhoqued79438d2012-08-27 13:31:42 -0500435void
akmhoque53f64222012-09-05 13:57:51 -0500436process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500437{
akmhoque7b791452012-10-30 11:24:56 -0500438 if ( nlsr->debugging )
439 printf("process_incoming_content called \n");
440 if ( nlsr->detailed_logging )
441 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n");
akmhoque53f64222012-09-05 13:57:51 -0500442
443 const unsigned char *comp_ptr1;
444 size_t comp_size;
445 int res,i;
446 int nlsr_position=0;
447 int name_comps=(int)info->interest_comps->n;
448
449 for(i=0;i<name_comps;i++)
450 {
451 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
452 if( res == 0)
453 {
454 nlsr_position=i;
455 break;
456 }
457 }
458
459 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
460
akmhoque53f64222012-09-05 13:57:51 -0500461
462 if(!strcmp((char *)comp_ptr1,"info"))
463 {
464 process_incoming_content_info(selfp,info);
465 }
akmhoque03004e62012-09-06 01:12:28 -0500466
akmhoque53f64222012-09-05 13:57:51 -0500467}
468
akmhoque03004e62012-09-06 01:12:28 -0500469
akmhoque53f64222012-09-05 13:57:51 -0500470void
471process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info)
472{
akmhoque7b791452012-10-30 11:24:56 -0500473 if ( nlsr->debugging )
474 printf("process_incoming_content_info called \n");
475 if ( nlsr->detailed_logging )
476 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info called \n");
akmhoque03004e62012-09-06 01:12:28 -0500477
akmhoque53f64222012-09-05 13:57:51 -0500478 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
479 get_nbr(nbr,selfp,info);
akmhoque03004e62012-09-06 01:12:28 -0500480
akmhoque7b791452012-10-30 11:24:56 -0500481 if ( nlsr->debugging )
482 printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
483 if ( nlsr->detailed_logging )
484 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
akmhoque03004e62012-09-06 01:12:28 -0500485
akmhoque53f64222012-09-05 13:57:51 -0500486
akmhoqueb77b95f2013-02-08 12:28:47 -0600487 //const unsigned char *ptr;
488 //size_t length;
489 //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);
akmhoque53f64222012-09-05 13:57:51 -0500490
akmhoqueb77b95f2013-02-08 12:28:47 -0600491 //long int interval=atoi((char *)ptr);
akmhoque53f64222012-09-05 13:57:51 -0500492
493
akmhoque03004e62012-09-06 01:12:28 -0500494
akmhoque53f64222012-09-05 13:57:51 -0500495 update_adjacent_timed_out_zero_to_adl(nbr);
496 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
akmhoqueb77b95f2013-02-08 12:28:47 -0600497 //update_lsdb_synch_interval_to_adl(nbr,interval);
akmhoque53f64222012-09-05 13:57:51 -0500498 print_adjacent_from_adl();
499
akmhoque03004e62012-09-06 01:12:28 -0500500
501
akmhoque53f64222012-09-05 13:57:51 -0500502 if(!nlsr->is_build_adj_lsa_sheduled)
503 {
akmhoque7b791452012-10-30 11:24:56 -0500504 if ( nlsr->debugging )
505 printf("Scheduling Build and Install Adj LSA...\n");
506 if ( nlsr->detailed_logging )
507 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling Build and Install Adj LSA...\n");
akmhoque53f64222012-09-05 13:57:51 -0500508 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0);
509 nlsr->is_build_adj_lsa_sheduled=1;
510 }
511 else
512 {
akmhoque7b791452012-10-30 11:24:56 -0500513 if ( nlsr->debugging )
514 printf("Build and Install Adj LSA already scheduled\n");
515 if ( nlsr->detailed_logging )
516 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA already scheduled\n");
akmhoque53f64222012-09-05 13:57:51 -0500517 }
518
akmhoque03004e62012-09-06 01:12:28 -0500519
akmhoque53f64222012-09-05 13:57:51 -0500520 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500521
akmhoque53f64222012-09-05 13:57:51 -0500522
523}
524
akmhoque03004e62012-09-06 01:12:28 -0500525
akmhoque53f64222012-09-05 13:57:51 -0500526
akmhoque03004e62012-09-06 01:12:28 -0500527
akmhoque53f64222012-09-05 13:57:51 -0500528void
529process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
530{
akmhoque3171d652012-11-13 11:44:33 -0600531
532
533 if ( nlsr->debugging )
534 printf("process_incoming_timed_out_interest called \n");
535 if ( nlsr->detailed_logging )
536 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest called \n");
537
akmhoque53f64222012-09-05 13:57:51 -0500538 int res,i;
539 int nlsr_position=0;
540 int name_comps=(int)info->interest_comps->n;
541
542 for(i=0;i<name_comps;i++)
543 {
544 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
545 if( res == 0)
546 {
547 nlsr_position=i;
548 break;
549 }
550 }
551
552 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
553 {
554 process_incoming_timed_out_interest_info(selfp,info);
555 }
556}
557
558void
559process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
560{
akmhoque3171d652012-11-13 11:44:33 -0600561
562 if ( nlsr->debugging )
563 printf("process_incoming_timed_out_interest_info called \n");
564 if ( nlsr->detailed_logging )
565 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_interest_info called \n");
akmhoque53f64222012-09-05 13:57:51 -0500566
567 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
568 get_nbr(nbr,selfp,info);
569
akmhoque3171d652012-11-13 11:44:33 -0600570 if ( nlsr->debugging )
571 printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
572 if ( nlsr->detailed_logging )
573 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
574
akmhoque03004e62012-09-06 01:12:28 -0500575
576
akmhoque53f64222012-09-05 13:57:51 -0500577 update_adjacent_timed_out_to_adl(nbr,1);
578 print_adjacent_from_adl();
579 int timed_out=get_timed_out_number(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500580
akmhoque3171d652012-11-13 11:44:33 -0600581 if ( nlsr->debugging )
582 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
583 if ( nlsr->detailed_logging )
584 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
585
akmhoque53f64222012-09-05 13:57:51 -0500586
587 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
588 {
akmhoque53f64222012-09-05 13:57:51 -0500589 send_info_interest_to_neighbor(nbr);
590 }
591 else
akmhoque3171d652012-11-13 11:44:33 -0600592 {
akmhoque53f64222012-09-05 13:57:51 -0500593 update_adjacent_status_to_adl(nbr,NBR_DOWN);
594 if(!nlsr->is_build_adj_lsa_sheduled)
595 {
596 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
597 nlsr->is_build_adj_lsa_sheduled=1;
598 }
599 }
600
601 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500602
akmhoque53f64222012-09-05 13:57:51 -0500603
604}
605
akmhoque29c1db52012-09-07 14:47:43 -0500606
akmhoque03004e62012-09-06 01:12:28 -0500607int
akmhoque53f64222012-09-05 13:57:51 -0500608send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
609{
akmhoqueffacaa82012-09-13 17:48:30 -0500610 if(flags == CCN_SCHEDULE_CANCEL)
611 {
612 return -1;
613 }
614
615 nlsr_lock();
616
akmhoque3171d652012-11-13 11:44:33 -0600617 if ( nlsr->debugging )
618 printf("send_info_interest called \n");
619 if ( nlsr->detailed_logging )
620 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n");
621
622 if ( nlsr->debugging )
623 printf("\n");
624 if ( nlsr->detailed_logging )
625 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoqued79438d2012-08-27 13:31:42 -0500626
akmhoque53f64222012-09-05 13:57:51 -0500627 int adl_element,i;
akmhoque53f64222012-09-05 13:57:51 -0500628 struct ndn_neighbor *nbr;
629
630 struct hashtb_enumerator ee;
631 struct hashtb_enumerator *e = &ee;
632
633 hashtb_start(nlsr->adl, e);
634 adl_element=hashtb_n(nlsr->adl);
635
636 for(i=0;i<adl_element;i++)
637 {
638 nbr=e->data;
639 send_info_interest_to_neighbor(nbr->neighbor);
640 hashtb_next(e);
641 }
akmhoque53f64222012-09-05 13:57:51 -0500642 hashtb_end(e);
643
akmhoqueffacaa82012-09-13 17:48:30 -0500644 nlsr_unlock();
645
akmhoque9fa58a82012-10-05 07:56:02 -0500646 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest, NULL, 0);
647
akmhoque53f64222012-09-05 13:57:51 -0500648 return 0;
649}
650
651void
652send_info_interest_to_neighbor(struct name_prefix *nbr)
653{
akmhoque3171d652012-11-13 11:44:33 -0600654
655 if ( nlsr->debugging )
656 printf("send_info_interest_to_neighbor called \n");
657 if ( nlsr->detailed_logging )
658 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor called \n");
659
akmhoqued79438d2012-08-27 13:31:42 -0500660
661 int res;
akmhoque53f64222012-09-05 13:57:51 -0500662 char info_str[5];
663 char nlsr_str[5];
akmhoque53f64222012-09-05 13:57:51 -0500664
akmhoqued79438d2012-08-27 13:31:42 -0500665 memset(&nlsr_str,0,5);
666 sprintf(nlsr_str,"nlsr");
667 memset(&info_str,0,5);
668 sprintf(info_str,"info");
669
akmhoque53f64222012-09-05 13:57:51 -0500670
671 struct ccn_charbuf *name;
akmhoqued79438d2012-08-27 13:31:42 -0500672 name=ccn_charbuf_create();
akmhoqued79438d2012-08-27 13:31:42 -0500673
akmhoque03004e62012-09-06 01:12:28 -0500674 char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name)+1);
675 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 -0500676 memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
677 memcpy(int_name+strlen(int_name),"/",1);
678 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
679 memcpy(int_name+strlen(int_name),"/",1);
680 memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
akmhoque03004e62012-09-06 01:12:28 -0500681 memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name));
akmhoque53f64222012-09-05 13:57:51 -0500682
683
684 res=ccn_name_from_uri(name,int_name);
685 if ( res >=0 )
686 {
akmhoque53f64222012-09-05 13:57:51 -0500687 /* adding InterestLifeTime and InterestScope filter */
688
689 struct ccn_charbuf *templ;
690 templ = ccn_charbuf_create();
691
692 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
693 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
694 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque03004e62012-09-06 01:12:28 -0500695 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
696 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
akmhoqueb77b95f2013-02-08 12:28:47 -0600697 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque03004e62012-09-06 01:12:28 -0500698 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
699 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque53f64222012-09-05 13:57:51 -0500700
701 appendLifetime(templ,nlsr->interest_resend_time);
akmhoqueb77b95f2013-02-08 12:28:47 -0600702 unsigned int face_id=get_next_hop_face_from_adl(nbr->name);
703 ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id);
akmhoque53f64222012-09-05 13:57:51 -0500704 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoqueb77b95f2013-02-08 12:28:47 -0600705
akmhoque53f64222012-09-05 13:57:51 -0500706
akmhoque3171d652012-11-13 11:44:33 -0600707 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600708 printf("Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id);
akmhoque3171d652012-11-13 11:44:33 -0600709 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600710 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on name prefix : %s through Face:%u\n",int_name,face_id);
akmhoque53f64222012-09-05 13:57:51 -0500711
712 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
713
714 if ( res >= 0 )
akmhoque3171d652012-11-13 11:44:33 -0600715 {
716 if ( nlsr->debugging )
717 printf("Info interest sending Successfull .... \n");
718 if ( nlsr->detailed_logging )
719 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info interest sending Successfull .... \n");
720 }
akmhoque53f64222012-09-05 13:57:51 -0500721 ccn_charbuf_destroy(&templ);
722 }
723 ccn_charbuf_destroy(&name);
724 free(int_name);
725
726}