blob: 3f9269839ccbc1d6ff8dade20f372f1c22667983 [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{
48
49 switch (kind) {
50 case CCN_UPCALL_FINAL:
51 break;
52 case CCN_UPCALL_INTEREST:
53 // printing the name prefix for which it received interest
54 printf("Interest Received for name: ");
55 struct ccn_charbuf*c;
56 c=ccn_charbuf_create();
57 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
58 //ccn_name_chop(c,NULL,-1);
59 printf("%s\n",ccn_charbuf_as_string(c));
60 ccn_charbuf_destroy(&c);
61
akmhoque1c9b92f2012-08-13 10:57:50 -050062 process_incoming_interest(selfp, info);
akmhoque59980a52012-08-09 12:36:09 -050063
64 /*
65 struct ccn_charbuf *data=ccn_charbuf_create();
66 struct ccn_charbuf *name=ccn_charbuf_create();
67 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
68
69 ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
70 info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
71
72 sp.template_ccnb=ccn_charbuf_create();
73 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
74 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010);
75 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
76 ccn_charbuf_append_closer(sp.template_ccnb);
77
78 res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello"));
79 res=ccn_put(ospfndn->ccn,data->buf,data->length);
80 ccn_charbuf_destroy(&data);
81
82 */
83 break;
84
85 default:
86 break;
87 }
88
89 return CCN_UPCALL_RESULT_OK;
90}
91
92
93enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
94 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
95{
96
97
98 switch(kind) {
99 case CCN_UPCALL_FINAL:
100 break;
101 case CCN_UPCALL_CONTENT:
102 printf("Content Received for name: ");
103 struct ccn_charbuf*c;
104 c=ccn_charbuf_create();
105 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
106 printf("%s\n",ccn_charbuf_as_string(c));
107 ccn_charbuf_destroy(&c);
akmhoquecb017752012-08-16 11:03:45 -0500108
109 process_incoming_content(selfp, info);
110
akmhoque59980a52012-08-09 12:36:09 -0500111 break;
112 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoquecb017752012-08-16 11:03:45 -0500113 printf("Interest timed out \n");
114 struct ccn_charbuf*ic;
115 ic=ccn_charbuf_create();
116 ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
117 printf("%s\n",ccn_charbuf_as_string(ic));
118 ccn_charbuf_destroy(&ic);
119 process_incoming_timed_out_interest(selfp,info);
akmhoque59980a52012-08-09 12:36:09 -0500120
akmhoque59980a52012-08-09 12:36:09 -0500121 break;
122 default:
123 fprintf(stderr, "Unexpected response of kind %d\n", kind);
124 return CCN_UPCALL_RESULT_ERR;
125 }
126
127 return CCN_UPCALL_RESULT_OK;
128}
akmhoque61fe4472012-08-10 10:13:34 -0500129
akmhoquecb017752012-08-16 11:03:45 -0500130
131void
132process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info)
133{
134 printf("process_incoming_content called \n");
135
akmhoque638c20a2012-08-16 11:57:48 -0500136 struct ccn_charbuf*c;
137 c=ccn_charbuf_create();
akmhoquedde7e322012-08-16 13:57:06 -0500138 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
139 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque638c20a2012-08-16 11:57:48 -0500140 printf("%s\n",ccn_charbuf_as_string(c));
141 ccn_charbuf_destroy(&c);
142
143 const unsigned char *comp_ptr1;
144 size_t comp_size;
145 int res,i;
146 int nlsr_position=0;
147 int name_comps=(int)info->interest_comps->n;
148
149 for(i=0;i<name_comps;i++)
150 {
151 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
152 if( res == 0)
153 {
154 nlsr_position=i;
155 break;
156 }
157 }
158
159 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
160
161
162 printf("Det= %s \n",comp_ptr1);
163
164 if(!strcmp((char *)comp_ptr1,"lsdb"))
165 {
166 process_incoming_content_lsdb(selfp,info);
167 }
akmhoqued79438d2012-08-27 13:31:42 -0500168 if(!strcmp((char *)comp_ptr1,"info"))
169 {
170 process_incoming_content_info(selfp,info);
171 }
akmhoque638c20a2012-08-16 11:57:48 -0500172
173}
174
175
176void
177process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
178{
179 printf("process_incoming_content_lsdb called \n");
180
181 const unsigned char *content_data;
182 size_t length;
183 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);
184
akmhoquedde7e322012-08-16 13:57:06 -0500185
186 if ( !strcmp((char *)content_data,"NACK"))
187 {
188 printf("NACK received for LSDB request. Do nothing \n");
189 }
190 else
191 {
192 // Do the LSDB processing here
193
akmhoque8a5babe2012-08-16 17:39:33 -0500194 const unsigned char *comp_ptr1;
195 size_t comp_size;
196 int res;
197
198 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 -0400199 if ( res >=0)
akmhoque8a5babe2012-08-16 17:39:33 -0500200 printf("Received Database Version: %s \n",(char *)comp_ptr1);
201
akmhoquedde7e322012-08-16 13:57:06 -0500202 }
akmhoque638c20a2012-08-16 11:57:48 -0500203
akmhoque8a5babe2012-08-16 17:39:33 -0500204
akmhoque638c20a2012-08-16 11:57:48 -0500205
akmhoquecb017752012-08-16 11:03:45 -0500206}
207
208
akmhoqued79438d2012-08-27 13:31:42 -0500209
210void
211process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
212{
213 printf("process_incoming_content_info called \n");
214
215 const unsigned char *content_data;
216 size_t length;
217 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);
218
219 printf("Info Value: %s \n",(char *)content_data);
220
221
222}
223
akmhoquecb017752012-08-16 11:03:45 -0500224void
225process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
226{
227 printf("process_incoming_timed_out_interest called \n");
228
akmhoquedde7e322012-08-16 13:57:06 -0500229 struct ccn_charbuf*c;
230 c=ccn_charbuf_create();
231 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
232 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
233 printf("%s\n",ccn_charbuf_as_string(c));
234 ccn_charbuf_destroy(&c);
235
akmhoqueb2e3a332012-08-21 12:17:20 -0400236 //const unsigned char *comp_ptr1;
237 //size_t comp_size;
akmhoquedde7e322012-08-16 13:57:06 -0500238 int res,i;
239 int nlsr_position=0;
240 int name_comps=(int)info->interest_comps->n;
241
242 for(i=0;i<name_comps;i++)
243 {
244 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
245 if( res == 0)
246 {
247 nlsr_position=i;
248 break;
249 }
250 }
251
akmhoqueb2e3a332012-08-21 12:17:20 -0400252 //res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquedde7e322012-08-16 13:57:06 -0500253
254
akmhoqueb2e3a332012-08-21 12:17:20 -0400255 //printf("Det= %s \n",comp_ptr1);
akmhoquedde7e322012-08-16 13:57:06 -0500256
akmhoqueb2e3a332012-08-21 12:17:20 -0400257 //if(!strcmp((char *)comp_ptr1,"lsdb"))
258 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
akmhoquedde7e322012-08-16 13:57:06 -0500259 {
260 process_incoming_timed_out_interest_lsdb(selfp,info);
261 }
akmhoqued79438d2012-08-27 13:31:42 -0500262 else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
263 {
264 process_incoming_timed_out_interest_info(selfp,info);
265 }
akmhoquecb017752012-08-16 11:03:45 -0500266}
267
268
akmhoque1c9b92f2012-08-13 10:57:50 -0500269void
akmhoquedde7e322012-08-16 13:57:06 -0500270process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
271{
272 printf("process_incoming_timed_out_interest_lsdb called \n");
273
274
275 int res,i;
276 int nlsr_position=0;
277 int name_comps=(int)info->interest_comps->n;
278
279 //const unsigned char *comp_ptr1;
280 //size_t comp_size;
281
282 for(i=0;i<name_comps;i++)
283 {
284 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
285 if( res == 0)
286 {
287 nlsr_position=i;
288 break;
289 }
290 }
291
292
akmhoque8a5babe2012-08-16 17:39:33 -0500293 struct ccn_charbuf *nbr;
294 nbr=ccn_charbuf_create();
295
akmhoquedde7e322012-08-16 13:57:06 -0500296
akmhoque8a5babe2012-08-16 17:39:33 -0500297 const unsigned char *comp_ptr1;
298 size_t comp_size;
299 for(i=0;i<nlsr_position;i++)
300 {
301 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
akmhoque6dc9a242012-08-21 11:23:57 -0400302 //printf("%s \n",comp_ptr1);
akmhoque8a5babe2012-08-16 17:39:33 -0500303 ccn_charbuf_append_string(nbr,"/");
304 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
305 }
306
akmhoque71b552d2012-08-21 11:44:34 -0400307 ccn_charbuf_append_string(nbr,"\0");
akmhoque8a5babe2012-08-16 17:39:33 -0500308 printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
309
310 update_adjacent_status_to_adl(nbr,1);
311
312 ccn_charbuf_destroy(&nbr);
akmhoquedde7e322012-08-16 13:57:06 -0500313}
314
315void
akmhoqued79438d2012-08-27 13:31:42 -0500316process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
317{
318
319 printf("process_incoming_timed_out_interest_info called \n");
320
321 int res,i;
322 int nlsr_position=0;
323 int name_comps=(int)info->interest_comps->n;
324
325 for(i=0;i<name_comps;i++)
326 {
327 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
328 if( res == 0)
329 {
330 nlsr_position=i;
331 break;
332 }
333 }
334
335 struct ccn_charbuf *nbr;
336 nbr=ccn_charbuf_create();
337
338
339 const unsigned char *comp_ptr1;
340 size_t comp_size;
341 for(i=0;i<nlsr_position;i++)
342 {
343 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
344 //printf("%s \n",comp_ptr1);
345 ccn_charbuf_append_string(nbr,"/");
346 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
347 }
348
349 ccn_charbuf_append_string(nbr,"\0");
350 printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
351
352 update_adjacent_timed_out_to_adl(nbr,1);
353 int timed_out=get_timed_out_number(nbr);
354 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
355 {
356 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
357 send_info_interest_to_neighbor(nbr);
358 }
359 else
360 {
361 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
362 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
363 }
364
365 ccn_charbuf_destroy(&nbr);
366}
367
368
369void
akmhoque1c9b92f2012-08-13 10:57:50 -0500370process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
371{
372 printf("process_incoming_interest called \n");
373
374
375 struct ccn_charbuf*c;
376 c=ccn_charbuf_create();
377 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
378 printf("%s\n",ccn_charbuf_as_string(c));
379 ccn_charbuf_destroy(&c);
380
381 const unsigned char *comp_ptr1;
382 size_t comp_size;
383 int res,i;
384 int nlsr_position=0;
385 int name_comps=(int)info->interest_comps->n;
386
387 for(i=0;i<name_comps;i++)
388 {
389 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
390 if( res == 0)
391 {
akmhoqueea3603e2012-08-13 11:24:09 -0500392 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500393 break;
394 }
395 }
396
397 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquee0789862012-08-16 14:23:32 -0500398
akmhoque1c9b92f2012-08-13 10:57:50 -0500399 printf("Det= %s \n",comp_ptr1);
400
401 if(!strcmp((char *)comp_ptr1,"lsdb"))
402 {
akmhoquebf1aa832012-08-13 13:26:59 -0500403 process_incoming_interest_lsdb(selfp,info);
akmhoque1c9b92f2012-08-13 10:57:50 -0500404 }
akmhoqued79438d2012-08-27 13:31:42 -0500405 if(!strcmp((char *)comp_ptr1,"info"))
406 {
407 process_incoming_interest_info(selfp,info);
408 }
akmhoquebf1aa832012-08-13 13:26:59 -0500409}
410
411
412void
413process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
414{
415 printf("process_incoming_interest_lsdb called \n");
416
akmhoquecb017752012-08-16 11:03:45 -0500417 int l, res;
akmhoquefce8cfc2012-08-14 14:00:33 -0500418 const unsigned char *exclbase;
akmhoque6d49e4d2012-08-14 13:49:30 -0500419 size_t size;
akmhoquefce8cfc2012-08-14 14:00:33 -0500420 struct ccn_buf_decoder decoder;
421 struct ccn_buf_decoder *d;
422 const unsigned char *comp;
423
akmhoque6d49e4d2012-08-14 13:49:30 -0500424
425 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
426 if (l > 0)
427 {
428 comp = NULL;
429 size = 0;
430 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
431 d = ccn_buf_decoder_start(&decoder, exclbase, l);
432 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
433 {
434 ccn_buf_advance(d);
435 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
436 ccn_buf_advance_past_element(d);
437 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
438 {
439 ccn_buf_advance(d);
440 ccn_buf_match_blob(d, &comp, &size);
akmhoquec9286692012-08-16 09:57:58 -0500441 ccn_buf_check_close(d);
442
443
akmhoque6d49e4d2012-08-14 13:49:30 -0500444 }
445 ccn_buf_check_close(d);
446 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500447 //if (d->decoder.state < 0)
448 //printf("Parse Failed\n");
akmhoque6d49e4d2012-08-14 13:49:30 -0500449 if (comp != NULL)
akmhoque37e3adf2012-08-14 15:52:50 -0500450 printf("Number in Exclusion Filter is %s\n",comp);
akmhoque6d49e4d2012-08-14 13:49:30 -0500451
452 /* Now comp points to the start of your potential number, and size is its length */
453 }
454
akmhoquef6432c22012-08-21 13:18:05 -0400455 int excl_db_version=atoi((char *)comp);
456 int dbcmp=nlsr->lsdb->version-excl_db_version;
457 //int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16);
458
459
akmhoque898d4aa2012-08-16 10:26:15 -0500460
akmhoque6dc9a242012-08-21 11:23:57 -0400461 printf (" dbcmp = %d \n",dbcmp);
akmhoque898d4aa2012-08-16 10:26:15 -0500462
akmhoque07dd8cc2012-08-16 10:23:01 -0500463 if(dbcmp > 0)
akmhoquecb017752012-08-16 11:03:45 -0500464 {
akmhoquef6432c22012-08-21 13:18:05 -0400465 printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
akmhoquecb017752012-08-16 11:03:45 -0500466 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500467 else
akmhoquecb017752012-08-16 11:03:45 -0500468 {
akmhoquef6432c22012-08-21 13:18:05 -0400469 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 -0500470 printf("Sending NACK Content back.....\n");
akmhoque07dd8cc2012-08-16 10:23:01 -0500471
akmhoquecb017752012-08-16 11:03:45 -0500472 struct ccn_charbuf *data=ccn_charbuf_create();
473 struct ccn_charbuf *name=ccn_charbuf_create();
474 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
475
akmhoque638c20a2012-08-16 11:57:48 -0500476 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]);
akmhoque8a5babe2012-08-16 17:39:33 -0500477 //ccn_name_append_str(name,"0000000000000001");
akmhoquecb017752012-08-16 11:03:45 -0500478
479 sp.template_ccnb=ccn_charbuf_create();
480 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
481 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
482 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
483 ccn_charbuf_append_closer(sp.template_ccnb);
484
485 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
akmhoquedde7e322012-08-16 13:57:06 -0500486 if(res >= 0)
487 printf("Signing Content is successful \n");
488
akmhoquecb017752012-08-16 11:03:45 -0500489 res=ccn_put(nlsr->ccn,data->buf,data->length);
akmhoquebf11b1d2012-08-16 11:11:17 -0500490
491 if(res >= 0)
492 printf("Sending NACK Content is successful \n");
493
akmhoquecb017752012-08-16 11:03:45 -0500494 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500495 ccn_charbuf_destroy(&name);
akmhoquecb017752012-08-16 11:03:45 -0500496 ccn_charbuf_destroy(&sp.template_ccnb);
497
498 }
499
akmhoque1c9b92f2012-08-13 10:57:50 -0500500}
501
akmhoqued79438d2012-08-27 13:31:42 -0500502
503void
504process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
505{
506 printf("process_incoming_interest_info called \n");
507 int res;
508
509 printf("Sending Info Content back.....\n");
510
511 struct ccn_charbuf *data=ccn_charbuf_create();
512 struct ccn_charbuf *name=ccn_charbuf_create();
513 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
514
515 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]);
516
517
518 sp.template_ccnb=ccn_charbuf_create();
519 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
520 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
521 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
522 ccn_charbuf_append_closer(sp.template_ccnb);
523
524 struct ccn_charbuf *c=ccn_charbuf_create();
525 ccn_charbuf_reset(c);
526 ccn_charbuf_putf(c, "%ld", nlsr->lsdb_synch_interval);
527 ccn_charbuf_append_string(data,ccn_charbuf_as_string(c));
528
529 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "info", strlen("info"));
530 if(res >= 0)
531 printf("Signing Content is successful \n");
532
533 res=ccn_put(nlsr->ccn,data->buf,data->length);
534 if(res >= 0)
535 printf("Sending NACK Content is successful \n");
536
537 ccn_charbuf_destroy(&data);
538 ccn_charbuf_destroy(&c);
539 ccn_charbuf_destroy(&name);
540 ccn_charbuf_destroy(&sp.template_ccnb);
541
542}
543
akmhoque1c9b92f2012-08-13 10:57:50 -0500544int
545send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
546 struct ccn_scheduled_event *ev, int flags)
547{
548
549 struct ccn_charbuf *name;
550 long int rnum;
551 char rnumstr[20];
akmhoqueea3603e2012-08-13 11:24:09 -0500552 char lsdb_str[5];
553 char nlsr_str[5];
akmhoque1c9b92f2012-08-13 10:57:50 -0500554
555 int res,i;
556 int adl_element;
557
558 rnum=random();
559 memset(&rnumstr,0,20);
560 sprintf(rnumstr,"%ld",rnum);
akmhoqueea3603e2012-08-13 11:24:09 -0500561 memset(&nlsr_str,0,5);
562 sprintf(nlsr_str,"nlsr");
563 memset(&lsdb_str,0,5);
564 sprintf(lsdb_str,"lsdb");
565
akmhoque1c9b92f2012-08-13 10:57:50 -0500566
567 struct ndn_neighbor *nbr;
568
569 struct hashtb_enumerator ee;
570 struct hashtb_enumerator *e = &ee;
571
572 hashtb_start(nlsr->adl, e);
573 adl_element=hashtb_n(nlsr->adl);
akmhoque07dd8cc2012-08-16 10:23:01 -0500574 //int mynumber=15;
akmhoque1c9b92f2012-08-13 10:57:50 -0500575
576 for(i=0;i<adl_element;i++)
577 {
578 nbr=e->data;
akmhoquea6817692012-08-21 13:50:01 -0400579 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 -0500580 name=ccn_charbuf_create();
akmhoquea6817692012-08-21 13:50:01 -0400581 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
akmhoqueea3603e2012-08-13 11:24:09 -0500582 ccn_name_append_str(name,nlsr_str);
583 ccn_name_append_str(name,lsdb_str);
akmhoquef6432c22012-08-21 13:18:05 -0400584 //ccn_name_append_str(name,rnumstr);
akmhoque1c9b92f2012-08-13 10:57:50 -0500585
akmhoque6d49e4d2012-08-14 13:49:30 -0500586 /* adding Exclusion filter */
akmhoquebf1aa832012-08-13 13:26:59 -0500587
akmhoque6d49e4d2012-08-14 13:49:30 -0500588 struct ccn_charbuf *templ;
589 templ = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500590
akmhoque6d49e4d2012-08-14 13:49:30 -0500591 struct ccn_charbuf *c;
592 c = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500593
594
595 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
596 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
597 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque6d49e4d2012-08-14 13:49:30 -0500598 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
599 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
600 ccn_charbuf_reset(c);
akmhoque07dd8cc2012-08-16 10:23:01 -0500601 //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
akmhoquea6817692012-08-21 13:50:01 -0400602 //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
603 ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
akmhoque6d49e4d2012-08-14 13:49:30 -0500604 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
605 ccn_charbuf_append_closer(templ); /* </Exclude> */
akmhoque7f337272012-08-14 15:16:30 -0500606 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque37e3adf2012-08-14 15:52:50 -0500607
akmhoque6d49e4d2012-08-14 13:49:30 -0500608
609 /* Adding Exclusion filter done */
610
akmhoque7f337272012-08-14 15:16:30 -0500611 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
612
akmhoque1c9b92f2012-08-13 10:57:50 -0500613 if ( res >= 0 )
614 printf("Interest sending Successfull .... \n");
akmhoque37e3adf2012-08-14 15:52:50 -0500615 ccn_charbuf_destroy(&c);
akmhoque7f337272012-08-14 15:16:30 -0500616 ccn_charbuf_destroy(&templ);
akmhoque1c9b92f2012-08-13 10:57:50 -0500617 ccn_charbuf_destroy(&name);
618
akmhoque1d7343f2012-08-21 10:46:35 -0400619 hashtb_next(e);
akmhoque1c9b92f2012-08-13 10:57:50 -0500620 }
621
622 hashtb_end(e);
623
akmhoquebf11b1d2012-08-16 11:11:17 -0500624 nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500625
626 return 0;
627
628}
629
akmhoqued79438d2012-08-27 13:31:42 -0500630
631int
632send_info_interest(struct ccn_schedule *sched, void *clienth,
633 struct ccn_scheduled_event *ev, int flags)
634{
635
636 struct ccn_charbuf *name;
637 long int rnum;
638 char rnumstr[20];
639 char info_str[5];
640 char nlsr_str[5];
641
642 int res,i;
643 int adl_element;
644 int scope = 2; //no further than the next host
645
646 rnum=random();
647 memset(&rnumstr,0,20);
648 sprintf(rnumstr,"%ld",rnum);
649 memset(&nlsr_str,0,5);
650 sprintf(nlsr_str,"nlsr");
651 memset(&info_str,0,5);
652 sprintf(info_str,"info");
653
654
655 struct ndn_neighbor *nbr;
656
657 struct hashtb_enumerator ee;
658 struct hashtb_enumerator *e = &ee;
659
660 hashtb_start(nlsr->adl, e);
661 adl_element=hashtb_n(nlsr->adl);
662 //int mynumber=15;
663
664 for(i=0;i<adl_element;i++)
665 {
666 nbr=e->data;
667 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str);
668 name=ccn_charbuf_create();
669 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
670 ccn_name_append_str(name,nlsr_str);
671 ccn_name_append_str(name,info_str);
672 //ccn_name_append_str(name,rnumstr);
673
674 /* adding Exclusion filter */
675
676 struct ccn_charbuf *templ;
677 templ = ccn_charbuf_create();
678
679// struct ccn_charbuf *c;
680// c = ccn_charbuf_create();
681
682
683 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
684 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
685 ccn_charbuf_append_closer(templ); /* </Name> */
686// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
687// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
688// ccn_charbuf_reset(c);
689// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
690// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
691// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
692// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
693// ccn_charbuf_append_closer(templ); /* </Exclude> */
694 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
695 appendLifetime(templ,nlsr->interest_resend_time);
696 ccn_charbuf_append_closer(templ); /* </Interest> */
697
698
699 /* Adding Exclusion filter done */
700
701 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
702
703 if ( res >= 0 )
704 printf("Interest sending Successfull .... \n");
705// ccn_charbuf_destroy(&c);
706 ccn_charbuf_destroy(&templ);
707 ccn_charbuf_destroy(&name);
708
709 hashtb_next(e);
710 }
711
712 hashtb_end(e);
713
714 //nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);
715
716 return 0;
717
718}
719
720
721void
722send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
723{
724
725 struct ccn_charbuf *name;
726 long int rnum;
727 char rnumstr[20];
728 char info_str[5];
729 char nlsr_str[5];
730
731 int res;
732 int scope = 2; //no further than the next host
733
734 rnum=random();
735 memset(&rnumstr,0,20);
736 sprintf(rnumstr,"%ld",rnum);
737 memset(&nlsr_str,0,5);
738 sprintf(nlsr_str,"nlsr");
739 memset(&info_str,0,5);
740 sprintf(info_str,"info");
741
742 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str);
743 name=ccn_charbuf_create();
744 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr));
745 ccn_name_append_str(name,nlsr_str);
746 ccn_name_append_str(name,info_str);
747 //ccn_name_append_str(name,rnumstr);
748
749 /* adding Exclusion filter */
750
751 struct ccn_charbuf *templ;
752 templ = ccn_charbuf_create();
753
754// struct ccn_charbuf *c;
755// c = ccn_charbuf_create();
756
757
758 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
759 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
760 ccn_charbuf_append_closer(templ); /* </Name> */
761// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
762// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
763// ccn_charbuf_reset(c);
764// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
765// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
766// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
767// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
768// ccn_charbuf_append_closer(templ); /* </Exclude> */
769 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
770 appendLifetime(templ,15);
771 ccn_charbuf_append_closer(templ); /* </Interest> */
772
773
774 /* Adding Exclusion filter done */
775
776 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
777
778 if ( res >= 0 )
779 printf("Interest sending Successfull .... \n");
780// ccn_charbuf_destroy(&c);
781 ccn_charbuf_destroy(&templ);
782 ccn_charbuf_destroy(&name);
783
784}