blob: 096c8a292577d0ffdecfc5b3df584734f81f5927 [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"
akmhoqueedb68d92013-03-05 10:18:16 -060026#include "nlsr_km.h"
27#include "nlsr_km_util.h"
akmhoque53f64222012-09-05 13:57:51 -050028
akmhoqueedb68d92013-03-05 10:18:16 -060029
akmhoque59980a52012-08-09 12:36:09 -050030
akmhoque3d319d42013-02-20 11:08:32 -060031/**
32* get neighbor name prefix from interest/content name and put into nbr
33*/
akmhoque53f64222012-09-05 13:57:51 -050034
35void
akmhoque3d319d42013-02-20 11:08:32 -060036get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp,
37 struct ccn_upcall_info *info)
akmhoque53f64222012-09-05 13:57:51 -050038{
akmhoque7b791452012-10-30 11:24:56 -050039 if ( nlsr->debugging )
40 printf("get_nbr called\n");
41 if ( nlsr->detailed_logging )
42 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr called\n");
akmhoque53f64222012-09-05 13:57:51 -050043
akmhoque53f64222012-09-05 13:57:51 -050044 int res,i;
45 int nlsr_position=0;
46 int name_comps=(int)info->interest_comps->n;
47 int len=0;
48
49 for(i=0;i<name_comps;i++)
50 {
51 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
52 if( res == 0)
53 {
54 nlsr_position=i;
55 break;
56 }
57 }
58
59
60 const unsigned char *comp_ptr1;
61 size_t comp_size;
62 for(i=0;i<nlsr_position;i++)
63 {
akmhoque3d319d42013-02-20 11:08:32 -060064 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&
65 comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -050066 len+=1;
67 len+=(int)comp_size;
68 }
69 len++;
70
71 char *neighbor=(char *)malloc(len);
72 memset(neighbor,0,len);
73
74 for(i=0; i<nlsr_position;i++)
75 {
akmhoque3d319d42013-02-20 11:08:32 -060076 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,
77 &comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -050078 memcpy(neighbor+strlen(neighbor),"/",1);
79 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
80
81 }
akmhoque53f64222012-09-05 13:57:51 -050082
akmhoque284056b2013-03-15 01:20:16 -050083 nbr->name=(char *)calloc(strlen(neighbor)+1,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -050084 memcpy(nbr->name,neighbor,strlen(neighbor)+1);
85 nbr->length=strlen(neighbor)+1;
86
akmhoque7b791452012-10-30 11:24:56 -050087 if ( nlsr->debugging )
88 printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length);
89 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -060090 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n",
91 nbr->name,nbr->length);
akmhoquececba942013-02-25 17:33:34 -060092 free(neighbor);
akmhoque53f64222012-09-05 13:57:51 -050093}
94
akmhoque3d319d42013-02-20 11:08:32 -060095/**
96* Retrieve LSA identifier from content name
97*/
akmhoque53f64222012-09-05 13:57:51 -050098
akmhoque3d319d42013-02-20 11:08:32 -060099void
100get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp,
101 struct ccn_upcall_info *info, int offset)
102{
akmhoque7b791452012-10-30 11:24:56 -0500103
104 if ( nlsr->debugging )
105 printf("get_lsa_identifier called\n");
106 if ( nlsr->detailed_logging )
107 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsa_identifier called\n");
108
akmhoque53f64222012-09-05 13:57:51 -0500109 int res,i;
110 int nlsr_position=0;
111 int name_comps=(int)info->interest_comps->n;
112 int len=0;
113
114 for(i=0;i<name_comps;i++)
115 {
116 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
117 if( res == 0)
118 {
119 nlsr_position=i;
120 break;
121 }
122 }
123
124
125 const unsigned char *comp_ptr1;
126 size_t comp_size;
akmhoque03004e62012-09-06 01:12:28 -0500127 for(i=nlsr_position+3+offset;i<info->interest_comps->n-1;i++)
akmhoque53f64222012-09-05 13:57:51 -0500128 {
akmhoque3d319d42013-02-20 11:08:32 -0600129 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,
130 &comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500131 len+=1;
132 len+=(int)comp_size;
133 }
134 len++;
135
akmhoquececba942013-02-25 17:33:34 -0600136 char *neighbor=(char *)calloc(len,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500137
akmhoque03004e62012-09-06 01:12:28 -0500138 for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++)
akmhoque53f64222012-09-05 13:57:51 -0500139 {
akmhoque3d319d42013-02-20 11:08:32 -0600140 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,
141 &comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500142 memcpy(neighbor+strlen(neighbor),"/",1);
143 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
144
145 }
akmhoque53f64222012-09-05 13:57:51 -0500146
akmhoque83a94da2013-03-15 01:38:21 -0500147 lsaId->name=(char *)calloc(strlen(neighbor)+1,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -0500148 memcpy(lsaId->name,neighbor,strlen(neighbor)+1);
149 lsaId->length=strlen(neighbor)+1;
150
akmhoque7b791452012-10-30 11:24:56 -0500151 if ( nlsr->debugging )
152 printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
153 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600154 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: "
155 "%d\n",lsaId->name,lsaId->length-1);
akmhoque03004e62012-09-06 01:12:28 -0500156
akmhoquececba942013-02-25 17:33:34 -0600157 free(neighbor);
akmhoque03004e62012-09-06 01:12:28 -0500158}
159
160
akmhoque9635b852013-04-04 23:29:48 -0500161int
162get_ls_type(struct ccn_closure *selfp, struct ccn_upcall_info *info)
163{
164 int res,i;
165 int nlsr_position=0;
166 int name_comps=(int)info->interest_comps->n;
167
168 int ret=0;
169
170 for(i=0;i<name_comps;i++)
171 {
172 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
173 if( res == 0)
174 {
175 nlsr_position=i;
176 break;
177 }
178 }
179
180
181 const unsigned char *comp_ptr1;
182 size_t comp_size;
183 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+2,&comp_ptr1, &comp_size);
184
185 ret=atoi((char *)comp_ptr1);
186
187 return ret;
188
189}
akmhoque3d319d42013-02-20 11:08:32 -0600190
191/**
192* Call back function registered in ccnd to get all interest coming to NLSR
193* application
194*/
akmhoque03004e62012-09-06 01:12:28 -0500195
akmhoque59980a52012-08-09 12:36:09 -0500196enum ccn_upcall_res
197incoming_interest(struct ccn_closure *selfp,
198 enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
199{
akmhoqueffacaa82012-09-13 17:48:30 -0500200
201 nlsr_lock();
202
akmhoque59980a52012-08-09 12:36:09 -0500203 switch (kind) {
204 case CCN_UPCALL_FINAL:
205 break;
206 case CCN_UPCALL_INTEREST:
akmhoque03004e62012-09-06 01:12:28 -0500207 // printing the name prefix for which it received interest
akmhoque7b791452012-10-30 11:24:56 -0500208 if ( nlsr->debugging )
209 printf("Interest Received for name: ");
210 if ( nlsr->detailed_logging )
211 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for name: ");
212
akmhoque03004e62012-09-06 01:12:28 -0500213 struct ccn_charbuf*c;
214 c=ccn_charbuf_create();
215 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque7b791452012-10-30 11:24:56 -0500216
217 if ( nlsr->debugging )
218 printf("%s\n",ccn_charbuf_as_string(c));
219 if ( nlsr->detailed_logging )
220 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c));
221
akmhoque03004e62012-09-06 01:12:28 -0500222 ccn_charbuf_destroy(&c);
223
akmhoque1c9b92f2012-08-13 10:57:50 -0500224 process_incoming_interest(selfp, info);
akmhoque03004e62012-09-06 01:12:28 -0500225
akmhoque59980a52012-08-09 12:36:09 -0500226 break;
akmhoque03004e62012-09-06 01:12:28 -0500227
akmhoque59980a52012-08-09 12:36:09 -0500228 default:
229 break;
230 }
akmhoque03004e62012-09-06 01:12:28 -0500231
akmhoqueffacaa82012-09-13 17:48:30 -0500232 nlsr_unlock();
233
akmhoque59980a52012-08-09 12:36:09 -0500234 return CCN_UPCALL_RESULT_OK;
235}
236
akmhoque3d319d42013-02-20 11:08:32 -0600237/**
238* Function for processing incoming interest and reply with content/NACK content
239*/
akmhoque59980a52012-08-09 12:36:09 -0500240
akmhoqued79438d2012-08-27 13:31:42 -0500241void
akmhoque1c9b92f2012-08-13 10:57:50 -0500242process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
243{
akmhoque7b791452012-10-30 11:24:56 -0500244 if ( nlsr->debugging )
245 printf("process_incoming_interest called \n");
246 if ( nlsr->detailed_logging )
247 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest called \n");
248
akmhoque1c9b92f2012-08-13 10:57:50 -0500249 const unsigned char *comp_ptr1;
250 size_t comp_size;
251 int res,i;
252 int nlsr_position=0;
253 int name_comps=(int)info->interest_comps->n;
akmhoque53f64222012-09-05 13:57:51 -0500254
akmhoque1c9b92f2012-08-13 10:57:50 -0500255 for(i=0;i<name_comps;i++)
256 {
257 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
258 if( res == 0)
259 {
akmhoqueea3603e2012-08-13 11:24:09 -0500260 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500261 break;
262 }
263 }
264
akmhoque3d319d42013-02-20 11:08:32 -0600265 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,
266 &comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500267
akmhoque1c9b92f2012-08-13 10:57:50 -0500268
akmhoqued79438d2012-08-27 13:31:42 -0500269 if(!strcmp((char *)comp_ptr1,"info"))
270 {
271 process_incoming_interest_info(selfp,info);
272 }
akmhoque9635b852013-04-04 23:29:48 -0500273 if(!strcmp((char *)comp_ptr1,"lsdb"))
274 {
275 process_incoming_interest_lsdb(selfp,info);
276 }
277 if(!strcmp((char *)comp_ptr1,"lsa"))
278 {
279 process_incoming_interest_lsa(selfp,info);
280 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600281
akmhoque53f64222012-09-05 13:57:51 -0500282}
283
akmhoque3d319d42013-02-20 11:08:32 -0600284/**
akmhoque7ab49a32013-02-20 11:27:51 -0600285* Processes incoming interest for "info" interest. Send back reply content back,
286* if interest comes from a neighbor with status down, NLSR will send "info"
287* ineterst to that neighbor
akmhoque3d319d42013-02-20 11:08:32 -0600288*/
289
akmhoque53f64222012-09-05 13:57:51 -0500290void
291process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
292{
akmhoque7b791452012-10-30 11:24:56 -0500293 if ( nlsr->debugging )
294 {
295 printf("process_incoming_interest_info called \n");
296 printf("Sending Info Content back.....\n");
297 }
298 if ( nlsr->detailed_logging )
299 {
akmhoque3d319d42013-02-20 11:08:32 -0600300 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_info"
301 " called \n");
akmhoque7b791452012-10-30 11:24:56 -0500302 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending Info Content back.....\n");
303 }
304
akmhoque53f64222012-09-05 13:57:51 -0500305
akmhoque53f64222012-09-05 13:57:51 -0500306 int res;
akmhoque6e2ba842013-03-05 19:35:26 -0600307 //struct ccn_charbuf *data=ccn_charbuf_create();
akmhoque53f64222012-09-05 13:57:51 -0500308 struct ccn_charbuf *name=ccn_charbuf_create();
akmhoquedd7a7a72013-02-20 08:25:41 -0600309
akmhoque03004e62012-09-06 01:12:28 -0500310
akmhoque3d319d42013-02-20 11:08:32 -0600311 res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
312 info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
akmhoque53f64222012-09-05 13:57:51 -0500313 if (res >= 0)
314 {
akmhoquedd7a7a72013-02-20 08:25:41 -0600315
akmhoque6e2ba842013-03-05 19:35:26 -0600316 /*
akmhoquec06dcf12013-02-20 08:13:37 -0600317 struct ccn_charbuf *pubid = ccn_charbuf_create();
318 struct ccn_charbuf *pubkey = ccn_charbuf_create();
319
akmhoque7ca519b2013-02-20 09:49:43 -0600320 //pubid is the digest_result pubkey is result
321 ccn_get_public_key(nlsr->ccn, NULL, pubid, pubkey);
akmhoque4ef95e72013-03-22 09:51:54 -0500322 */
akmhoque7ca519b2013-02-20 09:49:43 -0600323
akmhoquedd7a7a72013-02-20 08:25:41 -0600324
325 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
326 sp.template_ccnb=ccn_charbuf_create();
akmhoque3d319d42013-02-20 11:08:32 -0600327
akmhoqueb63a41e2013-03-01 12:00:20 -0600328 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
akmhoque3d319d42013-02-20 11:08:32 -0600329 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
330 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
331 ccn_charbuf_append_closer(sp.template_ccnb);
akmhoqueb63a41e2013-03-01 12:00:20 -0600332
akmhoque4ef95e72013-03-22 09:51:54 -0500333 /*
akmhoqueb77b95f2013-02-08 12:28:47 -0600334 char *raw_data=(char *)malloc(20);
335 memset(raw_data,0,20);
akmhoque6e2ba842013-03-05 19:35:26 -0600336 sprintf(raw_data,"%s", nlsr->lsdb->lsdb_version);
337 */
akmhoque53f64222012-09-05 13:57:51 -0500338
akmhoque6e2ba842013-03-05 19:35:26 -0600339 struct ccn_charbuf *resultbuf=ccn_charbuf_create();
340
akmhoque4ef95e72013-03-22 09:51:54 -0500341 /*
akmhoque6e2ba842013-03-05 19:35:26 -0600342 res=sign_content_with_user_defined_keystore(name,
343 resultbuf,
344 "info",
345 strlen("info"),
346 nlsr->keystore_path,
347 nlsr->keystore_passphrase,
348 nlsr->root_key_prefix,
349 nlsr->site_name,
akmhoque2fafaa52013-03-22 05:10:52 -0500350 nlsr->router_name,
351 10);
akmhoque4ef95e72013-03-22 09:51:54 -0500352
353 */
354 res= ccn_sign_content(nlsr->ccn, resultbuf, name, &sp, "info",strlen("info"));
akmhoque53f64222012-09-05 13:57:51 -0500355 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500356 {
357 if ( nlsr->debugging )
358 printf("Signing info Content is successful \n");
359 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600360 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing info Content"
361 " is successful \n");
akmhoque53f64222012-09-05 13:57:51 -0500362
akmhoque7b791452012-10-30 11:24:56 -0500363 }
akmhoque4ef95e72013-03-22 09:51:54 -0500364
365 res=ccn_put(nlsr->ccn,resultbuf->buf,resultbuf->length);
akmhoque53f64222012-09-05 13:57:51 -0500366 if(res >= 0)
akmhoque7b791452012-10-30 11:24:56 -0500367 {
368 if ( nlsr->debugging )
369 printf("Sending Info Content is successful \n");
370 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600371 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info Content"
372 " is successful \n");
akmhoque7b791452012-10-30 11:24:56 -0500373 }
374
akmhoque53f64222012-09-05 13:57:51 -0500375
376
akmhoquee1dd7772013-02-24 14:21:49 -0600377 struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix));
akmhoque03004e62012-09-06 01:12:28 -0500378 get_lsa_identifier(nbr,selfp,info,-1);
akmhoque7b791452012-10-30 11:24:56 -0500379
380 if ( nlsr->debugging )
akmhoque3d319d42013-02-20 11:08:32 -0600381 printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,
382 get_adjacent_status(nbr));
akmhoque7b791452012-10-30 11:24:56 -0500383 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600384 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor : %s Length : %d"
385 " Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
akmhoque03004e62012-09-06 01:12:28 -0500386
akmhoque53f64222012-09-05 13:57:51 -0500387
akmhoque3d319d42013-02-20 11:08:32 -0600388 if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr) >=
389 nlsr->interest_retry )
akmhoque53f64222012-09-05 13:57:51 -0500390 {
akmhoqueb8195202012-09-25 11:53:23 -0500391 update_adjacent_timed_out_zero_to_adl(nbr);
akmhoque53f64222012-09-05 13:57:51 -0500392 send_info_interest_to_neighbor(nbr);
393 }
394
akmhoque83a94da2013-03-15 01:38:21 -0500395 if ( nbr->name != NULL )
396 free(nbr->name);
397 if ( nbr != NULL )
398 free(nbr);
akmhoque284056b2013-03-15 01:20:16 -0500399 ccn_charbuf_destroy(&resultbuf);
akmhoque53f64222012-09-05 13:57:51 -0500400 }
akmhoque03004e62012-09-06 01:12:28 -0500401
akmhoque6e2ba842013-03-05 19:35:26 -0600402 //ccn_charbuf_destroy(&data);
akmhoque03004e62012-09-06 01:12:28 -0500403 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -0500404
akmhoquebf1aa832012-08-13 13:26:59 -0500405}
406
407
akmhoque9635b852013-04-04 23:29:48 -0500408
409void
410process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
411{
412 //printf("process_incoming_interest_lsdb called \n");
413
414 if ( nlsr->debugging )
415 printf("process_incoming_interest_lsdb called \n");
416 if ( nlsr->detailed_logging )
417 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsdb called \n");
418
419
420 int l,res;
421 const unsigned char *exclbase;
422 size_t size;
423 struct ccn_buf_decoder decoder;
424 struct ccn_buf_decoder *d;
425 const unsigned char *comp;
426 int dbcmp=0;
427
428 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
429 if (l > 0)
430 {
431 comp = NULL;
432 size = 0;
433 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
434 d = ccn_buf_decoder_start(&decoder, exclbase, l);
435 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
436 {
437 ccn_buf_advance(d);
438 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
439 ccn_buf_advance_past_element(d);
440 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
441 {
442 ccn_buf_advance(d);
443 ccn_buf_match_blob(d, &comp, &size);
444 ccn_buf_check_close(d);
445
446
447 }
448 ccn_buf_check_close(d);
449 }
450 if (comp != NULL)
451 {
452 if ( nlsr->debugging )
453 {
454 printf("LSDB Version in Exclusion Filter is %s\n",comp);
455 printf("LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version);
456 }
457 if ( nlsr->detailed_logging )
458 {
459 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is %s\n",comp);
460 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version of own NLSR is: %s \n",nlsr->lsdb->lsdb_version);
461 }
462 dbcmp=strcmp(nlsr->lsdb->lsdb_version,(char *)comp);
463 }
464 /* Now comp points to the start of your potential number, and size is its length */
465 }
466 else
467 {
468 if ( nlsr->debugging )
469 printf("LSDB Version in Exclusion Filter is: None Added\n");
470 if ( nlsr->detailed_logging )
471 writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSDB Version in Exclusion Filter is: None Added\n");
472 dbcmp=1;
473
474 }
475
476 struct ccn_charbuf *data=ccn_charbuf_create();
477 struct ccn_charbuf *name=ccn_charbuf_create();
478 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
479
480 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]);
481
482 sp.template_ccnb=ccn_charbuf_create();
483 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
484 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
485 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
486 ccn_charbuf_append_closer(sp.template_ccnb);
487
488
489 if(dbcmp>0)
490 {
491 if ( nlsr->debugging )
492 {
493 printf("Has Updated Database than Neighbor\n");
494 printf("Sending LSDB Summary of Updated LSDB Content...\n");
495 }
496 if ( nlsr->detailed_logging )
497 {
498 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Has Updated Database than Neighbor\n");
499 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content...\n");
500 }
501 ccn_name_append_str(name,nlsr->lsdb->lsdb_version);
502
503 struct ccn_charbuf *lsdb_data=ccn_charbuf_create();
504 get_lsdb_summary(lsdb_data);
505
506 char *raw_data=ccn_charbuf_as_string(lsdb_data);
507
508 //printf("Content Data to be sent: %s \n",raw_data);
509
510 if( nlsr->is_build_adj_lsa_sheduled == 1 || strlen((char *)raw_data) == 0 )
511 {
512 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT"));
513 }
514 else
515 {
516 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
517 }
518
519 if(res >= 0)
520 {
521 if ( nlsr->debugging )
522 printf("Signing LSDB Summary of Updated LSDB Content is successful \n");
523 if ( nlsr->detailed_logging )
524 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSDB Summary of Updated LSDB Content is successful \n");
525 }
526
527 res=ccn_put(nlsr->ccn,data->buf,data->length);
528
529 if(res >= 0)
530 {
531 if ( nlsr->debugging )
532 printf("Sending LSDB Summary of Updated LSDB Content is successful \n");
533 if ( nlsr->detailed_logging )
534 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSDB Summary of Updated LSDB Content is successful \n");
535 }
536
537 ccn_charbuf_destroy(&lsdb_data);
538 }
539 else
540 {
541 if ( nlsr->debugging )
542 {
543 printf("Does not have Updated Database than Neighbor\n");
544 printf("Sending NACK Content.....\n");
545 }
546 if ( nlsr->detailed_logging )
547 {
548 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Does not have Updated Database than Neighbor\n");
549 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content.....\n");
550 }
551
552 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
553
554 if(res >= 0)
555 {
556 if ( nlsr->debugging )
557 printf("Signing NACK Content is successful \n");
558 if ( nlsr->detailed_logging )
559 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing NACK Content is successful \n");
560 }
561
562 res=ccn_put(nlsr->ccn,data->buf,data->length);
563
564 if(res >= 0)
565 {
566 if ( nlsr->debugging )
567 printf("Sending NACK Content is successful \n");
568 if ( nlsr->detailed_logging )
569 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending NACK Content is successful \n");
570 }
571
572
573 }
574
575 ccn_charbuf_destroy(&data);
576 ccn_charbuf_destroy(&name);
577 ccn_charbuf_destroy(&sp.template_ccnb);
578
579
580}
581
582
583void
584process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info)
585{
586 if ( nlsr->debugging )
587 printf("process_incoming_interest_lsa called \n");
588 if ( nlsr->detailed_logging )
589 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_interest_lsa called \n");
590
591 int res;
592
593 struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
594 get_lsa_identifier(lsaId,selfp,info,0);
595
596 //printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length);
597 int ls_type=get_ls_type(selfp, info);
598
599 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
600
601 if ( ls_type == LS_TYPE_NAME )
602 {
603 if ( nlsr->debugging )
604 printf("Interest Received for NAME LSA \n");
605 if ( nlsr->detailed_logging )
606 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for NAME LSA \n");
607 get_name_lsa_data(lsa_data,lsaId);
608 }
609 else if ( ls_type == LS_TYPE_ADJ )
610 {
611 if ( nlsr->debugging )
612 printf("Interest Received for ADJ LSA \n");
613 if ( nlsr->detailed_logging )
614 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Received for ADJ LSA \n");
615 get_adj_lsa_data(lsa_data,lsaId);
616 }
617
618 char *rdata=ccn_charbuf_as_string(lsa_data);
619 char *raw_data=(char *)malloc(strlen(rdata)+1);
620 memset(raw_data,0,strlen(rdata)+1);
621 memcpy(raw_data,(char *)rdata,strlen(rdata)+1);
622 //printf("Content Data to be sent: %s\n",raw_data);
623
624 struct ccn_charbuf *data=ccn_charbuf_create();
625 struct ccn_charbuf *name=ccn_charbuf_create();
626 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
627
628 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]);
629
630 sp.template_ccnb=ccn_charbuf_create();
631 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
632 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
633 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
634 ccn_charbuf_append_closer(sp.template_ccnb);
635
636 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
637
638 if(res >= 0)
639 {
640 if ( nlsr->debugging )
641 printf("Signing LSA Content is successful \n");
642 if ( nlsr->detailed_logging )
643 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Signing LSA Content is successful \n");
644 }
645
646 res=ccn_put(nlsr->ccn,data->buf,data->length);
647
648 if(res >= 0)
649 {
650 if ( nlsr->debugging )
651 printf("Sending LSA Content is successful \n");
652 if ( nlsr->detailed_logging )
653 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending LSA Content is successful \n");
654 }
655
656
657
658 ccn_charbuf_destroy(&data);
659 ccn_charbuf_destroy(&name);
660 ccn_charbuf_destroy(&sp.template_ccnb);
661 ccn_charbuf_destroy(&lsa_data);
662
663 free(raw_data);
664 free(lsaId);
665}
666
667
668
akmhoque7ab49a32013-02-20 11:27:51 -0600669/**
670* Call back function registered in ccnd to get all content coming to NLSR
671* application
672*/
akmhoque03004e62012-09-06 01:12:28 -0500673
akmhoque53f64222012-09-05 13:57:51 -0500674enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
675 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500676{
677
akmhoqueffacaa82012-09-13 17:48:30 -0500678 nlsr_lock();
akmhoque03004e62012-09-06 01:12:28 -0500679
akmhoque53f64222012-09-05 13:57:51 -0500680 switch(kind) {
681 case CCN_UPCALL_FINAL:
682 break;
683 case CCN_UPCALL_CONTENT:
akmhoque7b791452012-10-30 11:24:56 -0500684 if ( nlsr->debugging )
685 printf("Content Received for Name: ");
686 if ( nlsr->detailed_logging )
687 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Content Received for Name: ");
688
akmhoque03004e62012-09-06 01:12:28 -0500689 struct ccn_charbuf*c;
690 c=ccn_charbuf_create();
691 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
akmhoque7b791452012-10-30 11:24:56 -0500692 if ( nlsr->debugging )
693 printf("%s\n",ccn_charbuf_as_string(c));
694 if ( nlsr->detailed_logging )
695 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(c));
696
akmhoque03004e62012-09-06 01:12:28 -0500697 ccn_charbuf_destroy(&c);
698
699 process_incoming_content(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500700
akmhoque53f64222012-09-05 13:57:51 -0500701 break;
702 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoqueedb68d92013-03-05 10:18:16 -0600703 //printf("Interest Timed Out Received for Name: ");
704 if ( nlsr->debugging )
705 printf("Interest Timed Out Received for Name: ");
706 if ( nlsr->detailed_logging )
707 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest Timed Out Receiv"
akmhoque3d319d42013-02-20 11:08:32 -0600708 "ed for Name: ");
akmhoque03004e62012-09-06 01:12:28 -0500709
akmhoqueedb68d92013-03-05 10:18:16 -0600710 struct ccn_charbuf*ito;
711 ito=ccn_charbuf_create();
712 ccn_uri_append(ito,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
713 if ( nlsr->debugging )
714 printf("%s\n",ccn_charbuf_as_string(ito));
715 if ( nlsr->detailed_logging )
716 writeLogg(__FILE__,__FUNCTION__,__LINE__,"%s\n",ccn_charbuf_as_string(ito));
717 ccn_charbuf_destroy(&ito);
akmhoque03004e62012-09-06 01:12:28 -0500718
akmhoqueedb68d92013-03-05 10:18:16 -0600719 process_incoming_timed_out_interest(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500720
akmhoque53f64222012-09-05 13:57:51 -0500721 break;
akmhoqueedb68d92013-03-05 10:18:16 -0600722
723 case CCN_UPCALL_CONTENT_UNVERIFIED:
724 if ( nlsr->debugging )
725 printf("Unverified Content Received ..Waiting for verification\n");
726 if ( nlsr->detailed_logging )
727 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unverified Content"
728 " Received ..Waiting for verification\n");
akmhoque6e2ba842013-03-05 19:35:26 -0600729 //return CCN_UPCALL_RESULT_VERIFY;
akmhoque4637d9d2013-03-08 06:52:00 -0600730 process_incoming_content(selfp,info);
akmhoqueedb68d92013-03-05 10:18:16 -0600731 break;
732
akmhoque53f64222012-09-05 13:57:51 -0500733 default:
734 fprintf(stderr, "Unexpected response of kind %d\n", kind);
akmhoqueedb68d92013-03-05 10:18:16 -0600735 if ( nlsr->debugging )
736 printf("Unexpected response of kind %d\n", kind);
737 if ( nlsr->detailed_logging )
738 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Unexpected response of "
akmhoque3d319d42013-02-20 11:08:32 -0600739 "kind %d\n", kind);
akmhoqueffacaa82012-09-13 17:48:30 -0500740 break;
akmhoque53f64222012-09-05 13:57:51 -0500741 }
akmhoqueffacaa82012-09-13 17:48:30 -0500742
743 nlsr_unlock();
akmhoqued79438d2012-08-27 13:31:42 -0500744
akmhoque53f64222012-09-05 13:57:51 -0500745 return CCN_UPCALL_RESULT_OK;
akmhoqued79438d2012-08-27 13:31:42 -0500746}
747
akmhoque7ab49a32013-02-20 11:27:51 -0600748/**
749* process any incoming content to NLSR from ccnd
750*/
akmhoque03004e62012-09-06 01:12:28 -0500751
akmhoqued79438d2012-08-27 13:31:42 -0500752void
akmhoque53f64222012-09-05 13:57:51 -0500753process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500754{
akmhoque7b791452012-10-30 11:24:56 -0500755 if ( nlsr->debugging )
756 printf("process_incoming_content called \n");
757 if ( nlsr->detailed_logging )
758 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content called \n");
akmhoque53f64222012-09-05 13:57:51 -0500759
760 const unsigned char *comp_ptr1;
761 size_t comp_size;
762 int res,i;
763 int nlsr_position=0;
764 int name_comps=(int)info->interest_comps->n;
765
766 for(i=0;i<name_comps;i++)
767 {
768 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
769 if( res == 0)
770 {
771 nlsr_position=i;
772 break;
773 }
774 }
775
akmhoque3d319d42013-02-20 11:08:32 -0600776 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,
777 nlsr_position+1,&comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500778
akmhoque53f64222012-09-05 13:57:51 -0500779
780 if(!strcmp((char *)comp_ptr1,"info"))
781 {
782 process_incoming_content_info(selfp,info);
783 }
akmhoque03004e62012-09-06 01:12:28 -0500784
akmhoque53f64222012-09-05 13:57:51 -0500785}
786
akmhoque7ab49a32013-02-20 11:27:51 -0600787/**
788* process any incoming "info" content to NLSR from ccnd
789*/
akmhoque03004e62012-09-06 01:12:28 -0500790
akmhoque53f64222012-09-05 13:57:51 -0500791void
akmhoque3d319d42013-02-20 11:08:32 -0600792process_incoming_content_info(struct ccn_closure *selfp,
793 struct ccn_upcall_info* info)
akmhoque53f64222012-09-05 13:57:51 -0500794{
akmhoque7b791452012-10-30 11:24:56 -0500795 if ( nlsr->debugging )
796 printf("process_incoming_content_info called \n");
797 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600798 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_content_info"
799 " called \n");
akmhoque03004e62012-09-06 01:12:28 -0500800
akmhoque53f64222012-09-05 13:57:51 -0500801 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
802 get_nbr(nbr,selfp,info);
akmhoque03004e62012-09-06 01:12:28 -0500803
akmhoque7b791452012-10-30 11:24:56 -0500804 if ( nlsr->debugging )
akmhoque3d319d42013-02-20 11:08:32 -0600805 printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,
806 nbr->length);
akmhoque7b791452012-10-30 11:24:56 -0500807 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600808 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Content Received For Nei"
809 "ghbor: %s Length:%d\n",nbr->name,nbr->length);
akmhoque03004e62012-09-06 01:12:28 -0500810
akmhoquefc7016f2013-03-08 07:17:14 -0600811
akmhoque4ef95e72013-03-22 09:51:54 -0500812 /*
akmhoque6e2ba842013-03-05 19:35:26 -0600813 if ( contain_key_name(info->content_ccnb, info->pco) == 1){
akmhoque237239c2013-03-18 10:29:26 -0500814 int res_verify=-1;
815 int key_exists=0;
816 struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco);
817 struct ccn_charbuf *key_uri = ccn_charbuf_create();
818 ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
819 key_exists=does_key_exist(ccn_charbuf_as_string(key_uri));
820 int key_type=get_key_type_from_key_name(key_name);
821
822 if ( res_verify == 1 && key_type == NLSR_KEY ){
823 res_verify=0;
824 }
825 else{
826 res_verify=verify_key(info->content_ccnb,info->pco,0);
827 }
akmhoque6e2ba842013-03-05 19:35:26 -0600828
akmhoque237239c2013-03-18 10:29:26 -0500829 //int res_verify=verify_key(info->content_ccnb,info->pco,0);
akmhoque03004e62012-09-06 01:12:28 -0500830
akmhoqueb7958182013-03-11 12:03:54 -0500831 if ( res_verify != 0 ){
akmhoque1162d852013-03-15 01:07:00 -0500832 if ( nlsr->debugging )
833 printf("Error in verfiying keys !! :( \n");
akmhoque237239c2013-03-18 10:29:26 -0500834 ccn_charbuf_destroy(&key_name);
835 ccn_charbuf_destroy(&key_uri);
akmhoqueb7958182013-03-11 12:03:54 -0500836 }
837 else{
akmhoque237239c2013-03-18 10:29:26 -0500838 if ( key_exists == 0 )
839 add_key(ccn_charbuf_as_string(key_uri));
840 ccn_charbuf_destroy(&key_name);
841 ccn_charbuf_destroy(&key_uri);
akmhoque1162d852013-03-15 01:07:00 -0500842 if ( nlsr->debugging )
843 printf("Key verification is successful :)\n");
akmhoqueb7958182013-03-11 12:03:54 -0500844 update_adjacent_timed_out_zero_to_adl(nbr);
845 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
846 print_adjacent_from_adl();
akmhoque53f64222012-09-05 13:57:51 -0500847
akmhoqueb7958182013-03-11 12:03:54 -0500848 if(!nlsr->is_build_adj_lsa_sheduled){
849 if ( nlsr->debugging )
850 printf("Scheduling Build and Install Adj LSA...\n");
851 if ( nlsr->detailed_logging )
852 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling"
akmhoque6e2ba842013-03-05 19:35:26 -0600853 "Build and Install Adj LSA...\n");
akmhoqueb7958182013-03-11 12:03:54 -0500854 nlsr->event_build_adj_lsa = ccn_schedule_event(
akmhoque6e2ba842013-03-05 19:35:26 -0600855 nlsr->sched, 100000,
akmhoque3d319d42013-02-20 11:08:32 -0600856 &build_and_install_adj_lsa, NULL, 0);
akmhoqueb7958182013-03-11 12:03:54 -0500857 nlsr->is_build_adj_lsa_sheduled=1;
858 }
859 else{
860 if ( nlsr->debugging )
861 printf("Build and Install Adj LSA already scheduled\n");
862 if ( nlsr->detailed_logging )
863 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA"
akmhoque3d319d42013-02-20 11:08:32 -0600864 " already scheduled\n");
akmhoqueb7958182013-03-11 12:03:54 -0500865 }
akmhoque6e2ba842013-03-05 19:35:26 -0600866
akmhoqueb7958182013-03-11 12:03:54 -0500867 }
akmhoque53f64222012-09-05 13:57:51 -0500868 }
akmhoque4ef95e72013-03-22 09:51:54 -0500869 */
870
akmhoque10c9a212013-03-08 07:05:18 -0600871 update_adjacent_timed_out_zero_to_adl(nbr);
872 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
873 print_adjacent_from_adl();
874
875 if(!nlsr->is_build_adj_lsa_sheduled){
876 if ( nlsr->debugging )
877 printf("Scheduling Build and Install Adj LSA...\n");
878 if ( nlsr->detailed_logging )
879 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Scheduling"
880 "Build and Install Adj LSA...\n");
881 nlsr->event_build_adj_lsa = ccn_schedule_event(
882 nlsr->sched, 100000,
883 &build_and_install_adj_lsa, NULL, 0);
884 nlsr->is_build_adj_lsa_sheduled=1;
885 }
886 else{
887 if ( nlsr->debugging )
888 printf("Build and Install Adj LSA already scheduled\n");
889 if ( nlsr->detailed_logging )
890 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Build and Install Adj LSA"
891 " already scheduled\n");
892 }
akmhoque03004e62012-09-06 01:12:28 -0500893
akmhoque4ef95e72013-03-22 09:51:54 -0500894
akmhoque83a94da2013-03-15 01:38:21 -0500895 if ( nbr->name != NULL )
896 free(nbr->name);
897 if ( nbr != NULL )
898 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500899
akmhoque53f64222012-09-05 13:57:51 -0500900
901}
902
akmhoque7ab49a32013-02-20 11:27:51 -0600903/**
904* process any incoming interest timed out content to NLSR from ccnd
905*/
akmhoque53f64222012-09-05 13:57:51 -0500906
akmhoque03004e62012-09-06 01:12:28 -0500907
akmhoque53f64222012-09-05 13:57:51 -0500908void
akmhoque3d319d42013-02-20 11:08:32 -0600909process_incoming_timed_out_interest(struct ccn_closure* selfp,
910 struct ccn_upcall_info* info)
akmhoque53f64222012-09-05 13:57:51 -0500911{
akmhoque3171d652012-11-13 11:44:33 -0600912
913
914 if ( nlsr->debugging )
915 printf("process_incoming_timed_out_interest called \n");
916 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600917 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int"
918 "erest called \n");
akmhoque3171d652012-11-13 11:44:33 -0600919
akmhoque53f64222012-09-05 13:57:51 -0500920 int res,i;
921 int nlsr_position=0;
922 int name_comps=(int)info->interest_comps->n;
923
924 for(i=0;i<name_comps;i++)
925 {
926 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
927 if( res == 0)
928 {
929 nlsr_position=i;
930 break;
931 }
932 }
933
akmhoque3d319d42013-02-20 11:08:32 -0600934 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,
935 nlsr_position+1,"info") == 0)
akmhoque53f64222012-09-05 13:57:51 -0500936 {
937 process_incoming_timed_out_interest_info(selfp,info);
938 }
939}
940
akmhoque7ab49a32013-02-20 11:27:51 -0600941/**
942* process any incoming "info" interest timed out content to NLSR from ccnd
943*/
944
akmhoque53f64222012-09-05 13:57:51 -0500945void
akmhoque3d319d42013-02-20 11:08:32 -0600946process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct
947 ccn_upcall_info* info)
akmhoque53f64222012-09-05 13:57:51 -0500948{
akmhoque3171d652012-11-13 11:44:33 -0600949
950 if ( nlsr->debugging )
951 printf("process_incoming_timed_out_interest_info called \n");
952 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600953 writeLogg(__FILE__,__FUNCTION__,__LINE__,"process_incoming_timed_out_int"
954 "erest_info called \n");
akmhoque53f64222012-09-05 13:57:51 -0500955
956 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
957 get_nbr(nbr,selfp,info);
958
akmhoque3171d652012-11-13 11:44:33 -0600959 if ( nlsr->debugging )
akmhoque3d319d42013-02-20 11:08:32 -0600960 printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",
961 nbr->name,nbr->length);
akmhoque3171d652012-11-13 11:44:33 -0600962 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600963 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info Interest Timed Out for"
964 " Neighbor: %s Length:%d\n",nbr->name,nbr->length);
akmhoque3171d652012-11-13 11:44:33 -0600965
akmhoque03004e62012-09-06 01:12:28 -0500966
967
akmhoque53f64222012-09-05 13:57:51 -0500968 update_adjacent_timed_out_to_adl(nbr,1);
969 print_adjacent_from_adl();
970 int timed_out=get_timed_out_number(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500971
akmhoque3171d652012-11-13 11:44:33 -0600972 if ( nlsr->debugging )
akmhoque3d319d42013-02-20 11:08:32 -0600973 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,
974 timed_out);
akmhoque3171d652012-11-13 11:44:33 -0600975 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -0600976 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Info Interest "
977 "Timed Out: %d times\n",nbr->name,timed_out);
akmhoque3171d652012-11-13 11:44:33 -0600978
akmhoque53f64222012-09-05 13:57:51 -0500979
980 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
981 {
akmhoque53f64222012-09-05 13:57:51 -0500982 send_info_interest_to_neighbor(nbr);
983 }
984 else
akmhoque3171d652012-11-13 11:44:33 -0600985 {
akmhoque53f64222012-09-05 13:57:51 -0500986 update_adjacent_status_to_adl(nbr,NBR_DOWN);
987 if(!nlsr->is_build_adj_lsa_sheduled)
988 {
akmhoque3d319d42013-02-20 11:08:32 -0600989 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000,
990 &build_and_install_adj_lsa, NULL, 0);
akmhoque53f64222012-09-05 13:57:51 -0500991 nlsr->is_build_adj_lsa_sheduled=1;
992 }
993 }
994
akmhoque284056b2013-03-15 01:20:16 -0500995 if ( nbr->name != NULL )
996 free(nbr->name);
997 if ( nbr != NULL )
998 free(nbr);
akmhoque03004e62012-09-06 01:12:28 -0500999
akmhoque53f64222012-09-05 13:57:51 -05001000
1001}
1002
akmhoque7ab49a32013-02-20 11:27:51 -06001003/**
1004* send "info" interest to each and every neighbor in ADL and also schedule for
1005* itself for periodical sending of "info" interest
1006*/
akmhoque29c1db52012-09-07 14:47:43 -05001007
akmhoque03004e62012-09-06 01:12:28 -05001008int
akmhoque3d319d42013-02-20 11:08:32 -06001009send_info_interest(struct ccn_schedule *sched, void *clienth,
1010 struct ccn_scheduled_event *ev, int flags)
akmhoque53f64222012-09-05 13:57:51 -05001011{
akmhoqueffacaa82012-09-13 17:48:30 -05001012 if(flags == CCN_SCHEDULE_CANCEL)
1013 {
1014 return -1;
1015 }
1016
1017 nlsr_lock();
1018
akmhoque3171d652012-11-13 11:44:33 -06001019 if ( nlsr->debugging )
1020 printf("send_info_interest called \n");
1021 if ( nlsr->detailed_logging )
1022 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest called \n");
1023
1024 if ( nlsr->debugging )
1025 printf("\n");
1026 if ( nlsr->detailed_logging )
1027 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoqued79438d2012-08-27 13:31:42 -05001028
akmhoque53f64222012-09-05 13:57:51 -05001029 int adl_element,i;
akmhoque53f64222012-09-05 13:57:51 -05001030 struct ndn_neighbor *nbr;
1031
1032 struct hashtb_enumerator ee;
1033 struct hashtb_enumerator *e = &ee;
1034
1035 hashtb_start(nlsr->adl, e);
1036 adl_element=hashtb_n(nlsr->adl);
1037
1038 for(i=0;i<adl_element;i++)
1039 {
1040 nbr=e->data;
1041 send_info_interest_to_neighbor(nbr->neighbor);
1042 hashtb_next(e);
1043 }
akmhoque53f64222012-09-05 13:57:51 -05001044 hashtb_end(e);
1045
akmhoqueffacaa82012-09-13 17:48:30 -05001046 nlsr_unlock();
1047
akmhoque3d319d42013-02-20 11:08:32 -06001048 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &send_info_interest,
1049 NULL, 0);
akmhoque9fa58a82012-10-05 07:56:02 -05001050
akmhoque53f64222012-09-05 13:57:51 -05001051 return 0;
1052}
1053
akmhoque7ab49a32013-02-20 11:27:51 -06001054
1055/**
1056* send "info" interest neighbor nbr
1057*
1058*/
1059
akmhoque53f64222012-09-05 13:57:51 -05001060void
1061send_info_interest_to_neighbor(struct name_prefix *nbr)
1062{
akmhoque3171d652012-11-13 11:44:33 -06001063
1064 if ( nlsr->debugging )
1065 printf("send_info_interest_to_neighbor called \n");
1066 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -06001067 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_info_interest_to_neighbor"
1068 " called \n");
akmhoque3171d652012-11-13 11:44:33 -06001069
akmhoqued79438d2012-08-27 13:31:42 -05001070
1071 int res;
akmhoque53f64222012-09-05 13:57:51 -05001072 char info_str[5];
1073 char nlsr_str[5];
akmhoque53f64222012-09-05 13:57:51 -05001074
akmhoqued79438d2012-08-27 13:31:42 -05001075 memset(&nlsr_str,0,5);
1076 sprintf(nlsr_str,"nlsr");
1077 memset(&info_str,0,5);
1078 sprintf(info_str,"info");
1079
akmhoque53f64222012-09-05 13:57:51 -05001080
1081 struct ccn_charbuf *name;
akmhoqued79438d2012-08-27 13:31:42 -05001082 name=ccn_charbuf_create();
akmhoqued79438d2012-08-27 13:31:42 -05001083
akmhoque3d319d42013-02-20 11:08:32 -06001084 char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+
1085 strlen(info_str)+strlen(nlsr->router_name)+1);
1086 memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+
1087 strlen(nlsr->router_name)+1);
akmhoque53f64222012-09-05 13:57:51 -05001088 memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
1089 memcpy(int_name+strlen(int_name),"/",1);
1090 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1091 memcpy(int_name+strlen(int_name),"/",1);
1092 memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
akmhoque03004e62012-09-06 01:12:28 -05001093 memcpy(int_name+strlen(int_name),nlsr->router_name,strlen(nlsr->router_name));
akmhoque53f64222012-09-05 13:57:51 -05001094
1095
1096 res=ccn_name_from_uri(name,int_name);
1097 if ( res >=0 )
1098 {
akmhoque53f64222012-09-05 13:57:51 -05001099 /* adding InterestLifeTime and InterestScope filter */
1100
1101 struct ccn_charbuf *templ;
1102 templ = ccn_charbuf_create();
1103
1104 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1105 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1106 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque03004e62012-09-06 01:12:28 -05001107 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1108 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
akmhoqueb77b95f2013-02-08 12:28:47 -06001109 /* Adding InterestLifeTime and InterestScope filter done */
akmhoque3d319d42013-02-20 11:08:32 -06001110 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2
1111 //(not further than next host)
akmhoque03004e62012-09-06 01:12:28 -05001112 ccn_charbuf_append_closer(templ); /* </Scope> */
akmhoque53f64222012-09-05 13:57:51 -05001113
1114 appendLifetime(templ,nlsr->interest_resend_time);
akmhoqueb77b95f2013-02-08 12:28:47 -06001115 unsigned int face_id=get_next_hop_face_from_adl(nbr->name);
1116 ccnb_tagged_putf(templ, CCN_DTAG_FaceID, "%u", face_id);
akmhoque53f64222012-09-05 13:57:51 -05001117 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoqueb77b95f2013-02-08 12:28:47 -06001118
akmhoque53f64222012-09-05 13:57:51 -05001119
akmhoque3171d652012-11-13 11:44:33 -06001120 if ( nlsr->debugging )
akmhoque3d319d42013-02-20 11:08:32 -06001121 printf("Sending info interest on name prefix : %s through Face:%u\n"
1122 ,int_name,face_id);
akmhoque3171d652012-11-13 11:44:33 -06001123 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -06001124 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending info interest on"
1125 "name prefix : %s through Face:%u\n",int_name,face_id);
akmhoque53f64222012-09-05 13:57:51 -05001126
1127 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1128
1129 if ( res >= 0 )
akmhoque3171d652012-11-13 11:44:33 -06001130 {
1131 if ( nlsr->debugging )
1132 printf("Info interest sending Successfull .... \n");
1133 if ( nlsr->detailed_logging )
akmhoque3d319d42013-02-20 11:08:32 -06001134 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Info"
1135 "interest sending Successfull .... \n");
akmhoque3171d652012-11-13 11:44:33 -06001136 }
akmhoque53f64222012-09-05 13:57:51 -05001137 ccn_charbuf_destroy(&templ);
1138 }
akmhoque7adb2772013-03-05 16:30:59 -06001139
akmhoque53f64222012-09-05 13:57:51 -05001140 ccn_charbuf_destroy(&name);
1141 free(int_name);
akmhoquec06dcf12013-02-20 08:13:37 -06001142}
akmhoque9635b852013-04-04 23:29:48 -05001143
1144
1145void
1146send_lsdb_interest_to_nbr(struct name_prefix *nbr)
1147{
1148 /*
1149 if ( nlsr->debugging )
1150 printf("send_lsdb_interest_to_nbr called \n");
1151 if ( nlsr->detailed_logging )
1152 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest_to_nbr called \n");
1153
1154 char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
1155
1156 if(last_lsdb_version !=NULL)
1157 {
1158
1159
1160 if ( nlsr->debugging )
1161 printf("Last LSDB Version: %s \n",last_lsdb_version);
1162 if ( nlsr->detailed_logging )
1163 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Last LSDB Version: %s \n",last_lsdb_version);
1164
1165 struct ccn_charbuf *name;
1166 int res;
1167 char lsdb_str[5];
1168 char nlsr_str[5];
1169
1170 memset(&nlsr_str,0,5);
1171 sprintf(nlsr_str,"nlsr");
1172 memset(&lsdb_str,0,5);
1173 sprintf(lsdb_str,"lsdb");
1174 //make and send interest with exclusion filter as last_lsdb_version
1175 if ( nlsr->debugging )
1176 printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1177 if ( nlsr->detailed_logging )
1178 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1179
1180 name=ccn_charbuf_create();
1181 res=ccn_name_from_uri(name,nbr->name);
1182
1183 if( res >= 0)
1184 {
1185 ccn_name_append_str(name,nlsr_str);
1186 ccn_name_append_str(name,lsdb_str);
1187 // adding Exclusion filter
1188
1189 struct ccn_charbuf *templ;
1190 templ = ccn_charbuf_create();
1191
1192 struct ccn_charbuf *c;
1193 c = ccn_charbuf_create();
1194
1195
1196 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1197 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1198 ccn_charbuf_append_closer(templ); // </Name>
1199 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
1200 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
1201 ccn_charbuf_reset(c);
1202 ccn_charbuf_putf(c, "%s", last_lsdb_version);
1203
1204 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
1205 ccn_charbuf_append_closer(templ); // </Exclude>
1206 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1207 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1208 ccn_charbuf_append(templ, "2", 1);
1209 ccn_charbuf_append_closer(templ); // </Scope>
1210
1211 appendLifetime(templ,nlsr->interest_resend_time);
1212
1213 ccn_charbuf_append_closer(templ); // </Interest>
1214
1215
1216 // Adding Exclusion filter done
1217
1218 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1219
1220 if ( res >= 0 )
1221 {
1222 if ( nlsr->debugging )
1223 printf("Interest sending Successfull .... \n");
1224 if ( nlsr->detailed_logging )
1225 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Interest sending Successfull .... \n");
1226 update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec());
1227
1228 }
1229 ccn_charbuf_destroy(&c);
1230 ccn_charbuf_destroy(&templ);
1231 }
1232 ccn_charbuf_destroy(&name);
1233 }
1234 set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
1235 */
1236}
1237
1238
1239
1240int
1241send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1242{
1243
1244 /*
1245 if ( nlsr->debugging )
1246 printf("send_lsdb_interest called \n");
1247 if ( nlsr->detailed_logging )
1248 writeLogg(__FILE__,__FUNCTION__,__LINE__,"send_lsdb_interest called \n");
1249
1250 if(flags == CCN_SCHEDULE_CANCEL)
1251 {
1252 return -1;
1253 }
1254
1255 nlsr_lock();
1256
1257 int i, adl_element;
1258 struct ndn_neighbor *nbr;
1259
1260 struct hashtb_enumerator ee;
1261 struct hashtb_enumerator *e = &ee;
1262
1263 hashtb_start(nlsr->adl, e);
1264 adl_element=hashtb_n(nlsr->adl);
1265
1266 for(i=0;i<adl_element;i++)
1267 {
1268 nbr=e->data;
1269
1270 if(nbr->status == NBR_ACTIVE)
1271 {
1272 if(nbr->is_lsdb_send_interest_scheduled == 0)
1273 {
1274 long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name);
1275 if ( nlsr->debugging )
1276 printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
1277 if ( nlsr->detailed_logging )
1278 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
1279
1280
1281 if( time_diff >= ( get_lsdb_synch_interval(nbr->neighbor->name) + get_nbr_random_time_component(nbr->neighbor->name) ) )
1282 {
1283 nbr->is_lsdb_send_interest_scheduled=1;
1284 send_lsdb_interest_to_nbr(nbr->neighbor);
1285 }
1286 }
1287 }
1288 hashtb_next(e);
1289 }
1290
1291 hashtb_end(e);
1292 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
1293
1294 nlsr_unlock();
1295
1296 */
1297 return 0;
1298
1299}
1300
1301