blob: af79e3a028cb43dd7b4518d0e22da720273e0e05 [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>
akmhoque7f337272012-08-14 15:16:30 -050019#include <ccn/bloom.h>
akmhoque59980a52012-08-09 12:36:09 -050020
21#include "nlsr.h"
22#include "nlsr_ndn.h"
23#include "utility.h"
akmhoque8a5babe2012-08-16 17:39:33 -050024#include "nlsr_adl.h"
akmhoqued79438d2012-08-27 13:31:42 -050025#include "nlsr_lsdb.h"
26
27int
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
44enum ccn_upcall_res
45incoming_interest(struct ccn_closure *selfp,
46 enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
47{
akmhoque42098b12012-08-27 22:54:23 -050048 my_lock();
akmhoque59980a52012-08-09 12:36:09 -050049
50 switch (kind) {
51 case CCN_UPCALL_FINAL:
52 break;
53 case CCN_UPCALL_INTEREST:
54 // printing the name prefix for which it received interest
55 printf("Interest Received for name: ");
56 struct ccn_charbuf*c;
57 c=ccn_charbuf_create();
58 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
akmhoque2fd74362012-08-27 14:45:08 -050059 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque59980a52012-08-09 12:36:09 -050060 //ccn_name_chop(c,NULL,-1);
61 printf("%s\n",ccn_charbuf_as_string(c));
62 ccn_charbuf_destroy(&c);
63
akmhoque1c9b92f2012-08-13 10:57:50 -050064 process_incoming_interest(selfp, info);
akmhoque59980a52012-08-09 12:36:09 -050065
66 /*
67 struct ccn_charbuf *data=ccn_charbuf_create();
68 struct ccn_charbuf *name=ccn_charbuf_create();
69 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
70
71 ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
72 info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
73
74 sp.template_ccnb=ccn_charbuf_create();
75 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
76 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010);
77 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
78 ccn_charbuf_append_closer(sp.template_ccnb);
79
80 res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello"));
81 res=ccn_put(ospfndn->ccn,data->buf,data->length);
82 ccn_charbuf_destroy(&data);
83
84 */
85 break;
86
87 default:
88 break;
89 }
90
akmhoque42098b12012-08-27 22:54:23 -050091 my_unlock();
akmhoque59980a52012-08-09 12:36:09 -050092 return CCN_UPCALL_RESULT_OK;
93}
94
95
96enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
97 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
98{
99
akmhoque42098b12012-08-27 22:54:23 -0500100 my_lock();
akmhoque59980a52012-08-09 12:36:09 -0500101
102 switch(kind) {
103 case CCN_UPCALL_FINAL:
104 break;
105 case CCN_UPCALL_CONTENT:
106 printf("Content Received for name: ");
107 struct ccn_charbuf*c;
108 c=ccn_charbuf_create();
109 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
110 printf("%s\n",ccn_charbuf_as_string(c));
111 ccn_charbuf_destroy(&c);
akmhoquecb017752012-08-16 11:03:45 -0500112
113 process_incoming_content(selfp, info);
114
akmhoque59980a52012-08-09 12:36:09 -0500115 break;
116 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoquecb017752012-08-16 11:03:45 -0500117 printf("Interest timed out \n");
118 struct ccn_charbuf*ic;
119 ic=ccn_charbuf_create();
120 ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
121 printf("%s\n",ccn_charbuf_as_string(ic));
122 ccn_charbuf_destroy(&ic);
123 process_incoming_timed_out_interest(selfp,info);
akmhoque59980a52012-08-09 12:36:09 -0500124
akmhoque59980a52012-08-09 12:36:09 -0500125 break;
126 default:
127 fprintf(stderr, "Unexpected response of kind %d\n", kind);
128 return CCN_UPCALL_RESULT_ERR;
129 }
130
akmhoque42098b12012-08-27 22:54:23 -0500131 my_unlock();
akmhoque59980a52012-08-09 12:36:09 -0500132 return CCN_UPCALL_RESULT_OK;
133}
akmhoque61fe4472012-08-10 10:13:34 -0500134
akmhoquecb017752012-08-16 11:03:45 -0500135
136void
137process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info)
138{
139 printf("process_incoming_content called \n");
140
akmhoque638c20a2012-08-16 11:57:48 -0500141 struct ccn_charbuf*c;
142 c=ccn_charbuf_create();
akmhoquedde7e322012-08-16 13:57:06 -0500143 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
144 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque638c20a2012-08-16 11:57:48 -0500145 printf("%s\n",ccn_charbuf_as_string(c));
146 ccn_charbuf_destroy(&c);
147
148 const unsigned char *comp_ptr1;
149 size_t comp_size;
150 int res,i;
151 int nlsr_position=0;
152 int name_comps=(int)info->interest_comps->n;
153
154 for(i=0;i<name_comps;i++)
155 {
156 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
157 if( res == 0)
158 {
159 nlsr_position=i;
160 break;
161 }
162 }
163
164 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
165
166
167 printf("Det= %s \n",comp_ptr1);
168
169 if(!strcmp((char *)comp_ptr1,"lsdb"))
170 {
171 process_incoming_content_lsdb(selfp,info);
172 }
akmhoqued79438d2012-08-27 13:31:42 -0500173 if(!strcmp((char *)comp_ptr1,"info"))
174 {
175 process_incoming_content_info(selfp,info);
176 }
akmhoque638c20a2012-08-16 11:57:48 -0500177
178}
179
180
181void
182process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
183{
184 printf("process_incoming_content_lsdb called \n");
185
186 const unsigned char *content_data;
187 size_t length;
188 ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);
189
akmhoquedde7e322012-08-16 13:57:06 -0500190
191 if ( !strcmp((char *)content_data,"NACK"))
192 {
193 printf("NACK received for LSDB request. Do nothing \n");
194 }
195 else
196 {
197 // Do the LSDB processing here
198
akmhoque8a5babe2012-08-16 17:39:33 -0500199 const unsigned char *comp_ptr1;
200 size_t comp_size;
201 int res;
202
203 res=ccn_name_comp_get(info->content_ccnb, info->content_comps,info->interest_comps->n-1,&comp_ptr1, &comp_size);
akmhoque2852a222012-08-21 12:09:00 -0400204 if ( res >=0)
akmhoque8a5babe2012-08-16 17:39:33 -0500205 printf("Received Database Version: %s \n",(char *)comp_ptr1);
206
akmhoquedde7e322012-08-16 13:57:06 -0500207 }
akmhoque638c20a2012-08-16 11:57:48 -0500208
akmhoque8a5babe2012-08-16 17:39:33 -0500209
akmhoque638c20a2012-08-16 11:57:48 -0500210
akmhoquecb017752012-08-16 11:03:45 -0500211}
212
213
akmhoqued79438d2012-08-27 13:31:42 -0500214
215void
216process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
217{
218 printf("process_incoming_content_info called \n");
219
220 const unsigned char *content_data;
221 size_t length;
222 ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);
223
224 printf("Info Value: %s \n",(char *)content_data);
akmhoque42098b12012-08-27 22:54:23 -0500225
226
227 int res,i;
228 int nlsr_position=0;
229 int name_comps=(int)info->interest_comps->n;
230
231 for(i=0;i<name_comps;i++)
232 {
233 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
234 if( res == 0)
235 {
236 nlsr_position=i;
237 break;
238 }
239 }
240
241 struct ccn_charbuf *nbr;
242 nbr=ccn_charbuf_create();
243
244
245 const unsigned char *comp_ptr1;
246 size_t comp_size;
247 for(i=0;i<nlsr_position;i++)
248 {
249 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
250 //printf("%s \n",comp_ptr1);
251 ccn_charbuf_append_string(nbr,"/");
252 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
253 }
254
255 ccn_charbuf_append_string(nbr,"\0");
256 printf("Info Content received for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
257
258 update_adjacent_timed_out_zero_to_adl(nbr);
259 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
260
261 print_adjacent_from_adl();
262
263 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
264
265 ccn_charbuf_destroy(&nbr);
akmhoqued79438d2012-08-27 13:31:42 -0500266
267
268}
269
akmhoquecb017752012-08-16 11:03:45 -0500270void
271process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
272{
273 printf("process_incoming_timed_out_interest called \n");
274
akmhoquedde7e322012-08-16 13:57:06 -0500275 struct ccn_charbuf*c;
276 c=ccn_charbuf_create();
277 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
278 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
279 printf("%s\n",ccn_charbuf_as_string(c));
280 ccn_charbuf_destroy(&c);
281
akmhoqueb2e3a332012-08-21 12:17:20 -0400282 //const unsigned char *comp_ptr1;
283 //size_t comp_size;
akmhoquedde7e322012-08-16 13:57:06 -0500284 int res,i;
285 int nlsr_position=0;
286 int name_comps=(int)info->interest_comps->n;
287
288 for(i=0;i<name_comps;i++)
289 {
290 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
291 if( res == 0)
292 {
293 nlsr_position=i;
294 break;
295 }
296 }
297
akmhoqueb2e3a332012-08-21 12:17:20 -0400298 //res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquedde7e322012-08-16 13:57:06 -0500299
300
akmhoqueb2e3a332012-08-21 12:17:20 -0400301 //printf("Det= %s \n",comp_ptr1);
akmhoquedde7e322012-08-16 13:57:06 -0500302
akmhoqueb2e3a332012-08-21 12:17:20 -0400303 //if(!strcmp((char *)comp_ptr1,"lsdb"))
304 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
akmhoquedde7e322012-08-16 13:57:06 -0500305 {
306 process_incoming_timed_out_interest_lsdb(selfp,info);
307 }
akmhoqued79438d2012-08-27 13:31:42 -0500308 else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
309 {
310 process_incoming_timed_out_interest_info(selfp,info);
311 }
akmhoquecb017752012-08-16 11:03:45 -0500312}
313
314
akmhoque1c9b92f2012-08-13 10:57:50 -0500315void
akmhoquedde7e322012-08-16 13:57:06 -0500316process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
317{
318 printf("process_incoming_timed_out_interest_lsdb called \n");
319
320
321 int res,i;
322 int nlsr_position=0;
323 int name_comps=(int)info->interest_comps->n;
324
325 //const unsigned char *comp_ptr1;
326 //size_t comp_size;
327
328 for(i=0;i<name_comps;i++)
329 {
330 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
331 if( res == 0)
332 {
333 nlsr_position=i;
334 break;
335 }
336 }
337
338
akmhoque8a5babe2012-08-16 17:39:33 -0500339 struct ccn_charbuf *nbr;
340 nbr=ccn_charbuf_create();
341
akmhoquedde7e322012-08-16 13:57:06 -0500342
akmhoque8a5babe2012-08-16 17:39:33 -0500343 const unsigned char *comp_ptr1;
344 size_t comp_size;
345 for(i=0;i<nlsr_position;i++)
346 {
347 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
akmhoque6dc9a242012-08-21 11:23:57 -0400348 //printf("%s \n",comp_ptr1);
akmhoque8a5babe2012-08-16 17:39:33 -0500349 ccn_charbuf_append_string(nbr,"/");
350 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
351 }
352
akmhoque71b552d2012-08-21 11:44:34 -0400353 ccn_charbuf_append_string(nbr,"\0");
akmhoque8a5babe2012-08-16 17:39:33 -0500354 printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
355
akmhoque42098b12012-08-27 22:54:23 -0500356 //update_adjacent_status_to_adl(nbr,1);
akmhoque8a5babe2012-08-16 17:39:33 -0500357
358 ccn_charbuf_destroy(&nbr);
akmhoquedde7e322012-08-16 13:57:06 -0500359}
360
361void
akmhoqued79438d2012-08-27 13:31:42 -0500362process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
363{
364
365 printf("process_incoming_timed_out_interest_info called \n");
366
367 int res,i;
368 int nlsr_position=0;
369 int name_comps=(int)info->interest_comps->n;
370
371 for(i=0;i<name_comps;i++)
372 {
373 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
374 if( res == 0)
375 {
376 nlsr_position=i;
377 break;
378 }
379 }
380
381 struct ccn_charbuf *nbr;
382 nbr=ccn_charbuf_create();
383
384
385 const unsigned char *comp_ptr1;
386 size_t comp_size;
387 for(i=0;i<nlsr_position;i++)
388 {
389 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
390 //printf("%s \n",comp_ptr1);
391 ccn_charbuf_append_string(nbr,"/");
392 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
393 }
394
395 ccn_charbuf_append_string(nbr,"\0");
396 printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
397
398 update_adjacent_timed_out_to_adl(nbr,1);
akmhoque42098b12012-08-27 22:54:23 -0500399
400 print_adjacent_from_adl();
401
akmhoqued79438d2012-08-27 13:31:42 -0500402 int timed_out=get_timed_out_number(nbr);
403 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
404 {
405 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
406 send_info_interest_to_neighbor(nbr);
407 }
408 else
409 {
410 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
411 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
412 }
413
414 ccn_charbuf_destroy(&nbr);
415}
416
417
418void
akmhoque1c9b92f2012-08-13 10:57:50 -0500419process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
420{
421 printf("process_incoming_interest called \n");
422
423
424 struct ccn_charbuf*c;
425 c=ccn_charbuf_create();
akmhoque2fd74362012-08-27 14:45:08 -0500426 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
427 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500428 printf("%s\n",ccn_charbuf_as_string(c));
429 ccn_charbuf_destroy(&c);
430
431 const unsigned char *comp_ptr1;
432 size_t comp_size;
433 int res,i;
434 int nlsr_position=0;
435 int name_comps=(int)info->interest_comps->n;
436
437 for(i=0;i<name_comps;i++)
438 {
439 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
440 if( res == 0)
441 {
akmhoqueea3603e2012-08-13 11:24:09 -0500442 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500443 break;
444 }
445 }
446
447 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquee0789862012-08-16 14:23:32 -0500448
akmhoque1c9b92f2012-08-13 10:57:50 -0500449 printf("Det= %s \n",comp_ptr1);
450
451 if(!strcmp((char *)comp_ptr1,"lsdb"))
452 {
akmhoquebf1aa832012-08-13 13:26:59 -0500453 process_incoming_interest_lsdb(selfp,info);
akmhoque1c9b92f2012-08-13 10:57:50 -0500454 }
akmhoqued79438d2012-08-27 13:31:42 -0500455 if(!strcmp((char *)comp_ptr1,"info"))
456 {
457 process_incoming_interest_info(selfp,info);
458 }
akmhoquebf1aa832012-08-13 13:26:59 -0500459}
460
461
462void
463process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
464{
465 printf("process_incoming_interest_lsdb called \n");
466
akmhoquecb017752012-08-16 11:03:45 -0500467 int l, res;
akmhoquefce8cfc2012-08-14 14:00:33 -0500468 const unsigned char *exclbase;
akmhoque6d49e4d2012-08-14 13:49:30 -0500469 size_t size;
akmhoquefce8cfc2012-08-14 14:00:33 -0500470 struct ccn_buf_decoder decoder;
471 struct ccn_buf_decoder *d;
472 const unsigned char *comp;
473
akmhoque6d49e4d2012-08-14 13:49:30 -0500474
475 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
476 if (l > 0)
477 {
478 comp = NULL;
479 size = 0;
480 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
481 d = ccn_buf_decoder_start(&decoder, exclbase, l);
482 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
483 {
484 ccn_buf_advance(d);
485 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
486 ccn_buf_advance_past_element(d);
487 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
488 {
489 ccn_buf_advance(d);
490 ccn_buf_match_blob(d, &comp, &size);
akmhoquec9286692012-08-16 09:57:58 -0500491 ccn_buf_check_close(d);
492
493
akmhoque6d49e4d2012-08-14 13:49:30 -0500494 }
495 ccn_buf_check_close(d);
496 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500497 //if (d->decoder.state < 0)
498 //printf("Parse Failed\n");
akmhoque6d49e4d2012-08-14 13:49:30 -0500499 if (comp != NULL)
akmhoque37e3adf2012-08-14 15:52:50 -0500500 printf("Number in Exclusion Filter is %s\n",comp);
akmhoque6d49e4d2012-08-14 13:49:30 -0500501
502 /* Now comp points to the start of your potential number, and size is its length */
503 }
504
akmhoquef6432c22012-08-21 13:18:05 -0400505 int excl_db_version=atoi((char *)comp);
506 int dbcmp=nlsr->lsdb->version-excl_db_version;
507 //int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16);
508
509
akmhoque898d4aa2012-08-16 10:26:15 -0500510
akmhoque6dc9a242012-08-21 11:23:57 -0400511 printf (" dbcmp = %d \n",dbcmp);
akmhoque898d4aa2012-08-16 10:26:15 -0500512
akmhoque07dd8cc2012-08-16 10:23:01 -0500513 if(dbcmp > 0)
akmhoquecb017752012-08-16 11:03:45 -0500514 {
akmhoquef6432c22012-08-21 13:18:05 -0400515 printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
akmhoquecb017752012-08-16 11:03:45 -0500516 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500517 else
akmhoquecb017752012-08-16 11:03:45 -0500518 {
akmhoquef6432c22012-08-21 13:18:05 -0400519 printf("Data base is not updated than the older one (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
akmhoquecb017752012-08-16 11:03:45 -0500520 printf("Sending NACK Content back.....\n");
akmhoque07dd8cc2012-08-16 10:23:01 -0500521
akmhoquecb017752012-08-16 11:03:45 -0500522 struct ccn_charbuf *data=ccn_charbuf_create();
523 struct ccn_charbuf *name=ccn_charbuf_create();
524 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
525
akmhoque638c20a2012-08-16 11:57:48 -0500526 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]);
akmhoquecb017752012-08-16 11:03:45 -0500527
528 sp.template_ccnb=ccn_charbuf_create();
529 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
530 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
531 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
532 ccn_charbuf_append_closer(sp.template_ccnb);
533
534 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
akmhoquedde7e322012-08-16 13:57:06 -0500535 if(res >= 0)
536 printf("Signing Content is successful \n");
537
akmhoquecb017752012-08-16 11:03:45 -0500538 res=ccn_put(nlsr->ccn,data->buf,data->length);
akmhoquebf11b1d2012-08-16 11:11:17 -0500539
540 if(res >= 0)
541 printf("Sending NACK Content is successful \n");
542
akmhoquecb017752012-08-16 11:03:45 -0500543 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500544 ccn_charbuf_destroy(&name);
akmhoquecb017752012-08-16 11:03:45 -0500545 ccn_charbuf_destroy(&sp.template_ccnb);
546
547 }
548
akmhoque1c9b92f2012-08-13 10:57:50 -0500549}
550
akmhoqued79438d2012-08-27 13:31:42 -0500551
552void
553process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
554{
555 printf("process_incoming_interest_info called \n");
556 int res;
557
558 printf("Sending Info Content back.....\n");
559
560 struct ccn_charbuf *data=ccn_charbuf_create();
561 struct ccn_charbuf *name=ccn_charbuf_create();
562 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
563
akmhoque887fc0c2012-08-27 15:06:06 -0500564 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]);
565
akmhoqued79438d2012-08-27 13:31:42 -0500566 sp.template_ccnb=ccn_charbuf_create();
567 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
568 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
569 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
570 ccn_charbuf_append_closer(sp.template_ccnb);
571
akmhoque869485c2012-08-27 15:23:36 -0500572 res= ccn_sign_content(nlsr->ccn, data, name, &sp,"info",strlen("info") );
akmhoqued79438d2012-08-27 13:31:42 -0500573 if(res >= 0)
574 printf("Signing Content is successful \n");
575
576 res=ccn_put(nlsr->ccn,data->buf,data->length);
577 if(res >= 0)
akmhoque6428c922012-08-27 14:26:13 -0500578 printf("Sending Info Content is successful \n");
akmhoqued79438d2012-08-27 13:31:42 -0500579
580 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500581 ccn_charbuf_destroy(&name);
akmhoque869485c2012-08-27 15:23:36 -0500582 //ccn_charbuf_destroy(&c);
akmhoqued79438d2012-08-27 13:31:42 -0500583 ccn_charbuf_destroy(&sp.template_ccnb);
584
585}
586
akmhoque1c9b92f2012-08-13 10:57:50 -0500587int
588send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
589 struct ccn_scheduled_event *ev, int flags)
590{
akmhoque42098b12012-08-27 22:54:23 -0500591 my_lock();
akmhoque1c9b92f2012-08-13 10:57:50 -0500592 struct ccn_charbuf *name;
593 long int rnum;
594 char rnumstr[20];
akmhoqueea3603e2012-08-13 11:24:09 -0500595 char lsdb_str[5];
596 char nlsr_str[5];
akmhoque1c9b92f2012-08-13 10:57:50 -0500597
598 int res,i;
599 int adl_element;
600
601 rnum=random();
602 memset(&rnumstr,0,20);
603 sprintf(rnumstr,"%ld",rnum);
akmhoqueea3603e2012-08-13 11:24:09 -0500604 memset(&nlsr_str,0,5);
605 sprintf(nlsr_str,"nlsr");
606 memset(&lsdb_str,0,5);
607 sprintf(lsdb_str,"lsdb");
608
akmhoque1c9b92f2012-08-13 10:57:50 -0500609
610 struct ndn_neighbor *nbr;
611
612 struct hashtb_enumerator ee;
613 struct hashtb_enumerator *e = &ee;
614
615 hashtb_start(nlsr->adl, e);
616 adl_element=hashtb_n(nlsr->adl);
akmhoque07dd8cc2012-08-16 10:23:01 -0500617 //int mynumber=15;
akmhoque1c9b92f2012-08-13 10:57:50 -0500618
619 for(i=0;i<adl_element;i++)
620 {
621 nbr=e->data;
akmhoquea6817692012-08-21 13:50:01 -0400622 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,lsdb_str);
akmhoque1c9b92f2012-08-13 10:57:50 -0500623 name=ccn_charbuf_create();
akmhoquea6817692012-08-21 13:50:01 -0400624 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
akmhoqueea3603e2012-08-13 11:24:09 -0500625 ccn_name_append_str(name,nlsr_str);
626 ccn_name_append_str(name,lsdb_str);
akmhoquef6432c22012-08-21 13:18:05 -0400627 //ccn_name_append_str(name,rnumstr);
akmhoque1c9b92f2012-08-13 10:57:50 -0500628
akmhoque6d49e4d2012-08-14 13:49:30 -0500629 /* adding Exclusion filter */
akmhoquebf1aa832012-08-13 13:26:59 -0500630
akmhoque6d49e4d2012-08-14 13:49:30 -0500631 struct ccn_charbuf *templ;
632 templ = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500633
akmhoque6d49e4d2012-08-14 13:49:30 -0500634 struct ccn_charbuf *c;
635 c = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500636
637
638 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
639 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
640 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque6d49e4d2012-08-14 13:49:30 -0500641 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
642 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
643 ccn_charbuf_reset(c);
akmhoque07dd8cc2012-08-16 10:23:01 -0500644 //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
akmhoquea6817692012-08-21 13:50:01 -0400645 //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
646 ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
akmhoque6d49e4d2012-08-14 13:49:30 -0500647 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
648 ccn_charbuf_append_closer(templ); /* </Exclude> */
akmhoque7f337272012-08-14 15:16:30 -0500649 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque37e3adf2012-08-14 15:52:50 -0500650
akmhoque6d49e4d2012-08-14 13:49:30 -0500651
652 /* Adding Exclusion filter done */
653
akmhoque7f337272012-08-14 15:16:30 -0500654 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
655
akmhoque1c9b92f2012-08-13 10:57:50 -0500656 if ( res >= 0 )
657 printf("Interest sending Successfull .... \n");
akmhoque37e3adf2012-08-14 15:52:50 -0500658 ccn_charbuf_destroy(&c);
akmhoque7f337272012-08-14 15:16:30 -0500659 ccn_charbuf_destroy(&templ);
akmhoque1c9b92f2012-08-13 10:57:50 -0500660 ccn_charbuf_destroy(&name);
661
akmhoque1d7343f2012-08-21 10:46:35 -0400662 hashtb_next(e);
akmhoque1c9b92f2012-08-13 10:57:50 -0500663 }
664
665 hashtb_end(e);
666
akmhoquebf11b1d2012-08-16 11:11:17 -0500667 nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500668
akmhoque42098b12012-08-27 22:54:23 -0500669 my_unlock();
akmhoque1c9b92f2012-08-13 10:57:50 -0500670 return 0;
671
672}
673
akmhoqued79438d2012-08-27 13:31:42 -0500674
675int
676send_info_interest(struct ccn_schedule *sched, void *clienth,
677 struct ccn_scheduled_event *ev, int flags)
678{
679
akmhoque42098b12012-08-27 22:54:23 -0500680 my_lock();
akmhoqued79438d2012-08-27 13:31:42 -0500681 struct ccn_charbuf *name;
682 long int rnum;
683 char rnumstr[20];
684 char info_str[5];
685 char nlsr_str[5];
686
687 int res,i;
688 int adl_element;
689 int scope = 2; //no further than the next host
690
691 rnum=random();
692 memset(&rnumstr,0,20);
693 sprintf(rnumstr,"%ld",rnum);
694 memset(&nlsr_str,0,5);
695 sprintf(nlsr_str,"nlsr");
696 memset(&info_str,0,5);
697 sprintf(info_str,"info");
698
699
700 struct ndn_neighbor *nbr;
701
702 struct hashtb_enumerator ee;
703 struct hashtb_enumerator *e = &ee;
704
705 hashtb_start(nlsr->adl, e);
706 adl_element=hashtb_n(nlsr->adl);
707 //int mynumber=15;
708
709 for(i=0;i<adl_element;i++)
710 {
711 nbr=e->data;
712 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str);
713 name=ccn_charbuf_create();
714 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
715 ccn_name_append_str(name,nlsr_str);
716 ccn_name_append_str(name,info_str);
717 //ccn_name_append_str(name,rnumstr);
718
719 /* adding Exclusion filter */
720
721 struct ccn_charbuf *templ;
722 templ = ccn_charbuf_create();
723
724// struct ccn_charbuf *c;
725// c = ccn_charbuf_create();
726
727
728 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
729 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
730 ccn_charbuf_append_closer(templ); /* </Name> */
731// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
732// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
733// ccn_charbuf_reset(c);
734// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
735// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
736// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
737// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
738// ccn_charbuf_append_closer(templ); /* </Exclude> */
739 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
740 appendLifetime(templ,nlsr->interest_resend_time);
741 ccn_charbuf_append_closer(templ); /* </Interest> */
742
743
744 /* Adding Exclusion filter done */
745
746 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
747
748 if ( res >= 0 )
749 printf("Interest sending Successfull .... \n");
750// ccn_charbuf_destroy(&c);
751 ccn_charbuf_destroy(&templ);
752 ccn_charbuf_destroy(&name);
753
754 hashtb_next(e);
755 }
756
757 hashtb_end(e);
758
759 //nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);
760
akmhoque42098b12012-08-27 22:54:23 -0500761 my_unlock();
akmhoqued79438d2012-08-27 13:31:42 -0500762 return 0;
763
764}
765
766
767void
768send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
769{
770
akmhoque42098b12012-08-27 22:54:23 -0500771 my_lock();
akmhoqued79438d2012-08-27 13:31:42 -0500772 struct ccn_charbuf *name;
773 long int rnum;
774 char rnumstr[20];
775 char info_str[5];
776 char nlsr_str[5];
777
778 int res;
779 int scope = 2; //no further than the next host
780
781 rnum=random();
782 memset(&rnumstr,0,20);
783 sprintf(rnumstr,"%ld",rnum);
784 memset(&nlsr_str,0,5);
785 sprintf(nlsr_str,"nlsr");
786 memset(&info_str,0,5);
787 sprintf(info_str,"info");
788
789 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str);
790 name=ccn_charbuf_create();
791 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr));
792 ccn_name_append_str(name,nlsr_str);
793 ccn_name_append_str(name,info_str);
794 //ccn_name_append_str(name,rnumstr);
795
796 /* adding Exclusion filter */
797
798 struct ccn_charbuf *templ;
799 templ = ccn_charbuf_create();
800
801// struct ccn_charbuf *c;
802// c = ccn_charbuf_create();
803
804
805 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
806 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
807 ccn_charbuf_append_closer(templ); /* </Name> */
808// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
809// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
810// ccn_charbuf_reset(c);
811// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
812// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
813// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
814// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
815// ccn_charbuf_append_closer(templ); /* </Exclude> */
816 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
817 appendLifetime(templ,15);
818 ccn_charbuf_append_closer(templ); /* </Interest> */
819
820
821 /* Adding Exclusion filter done */
822
823 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
824
825 if ( res >= 0 )
826 printf("Interest sending Successfull .... \n");
827// ccn_charbuf_destroy(&c);
828 ccn_charbuf_destroy(&templ);
829 ccn_charbuf_destroy(&name);
830
akmhoque42098b12012-08-27 22:54:23 -0500831 my_unlock();
832
akmhoqued79438d2012-08-27 13:31:42 -0500833}