blob: 52edb16fe910b2628ab3bf4ec4087867337802cf [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);
akmhoque2fd74362012-08-27 14:45:08 -050058 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque59980a52012-08-09 12:36:09 -050059 //ccn_name_chop(c,NULL,-1);
60 printf("%s\n",ccn_charbuf_as_string(c));
61 ccn_charbuf_destroy(&c);
62
akmhoque1c9b92f2012-08-13 10:57:50 -050063 process_incoming_interest(selfp, info);
akmhoque59980a52012-08-09 12:36:09 -050064
65 /*
66 struct ccn_charbuf *data=ccn_charbuf_create();
67 struct ccn_charbuf *name=ccn_charbuf_create();
68 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
69
70 ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],
71 info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
72
73 sp.template_ccnb=ccn_charbuf_create();
74 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
75 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 1010);
76 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
77 ccn_charbuf_append_closer(sp.template_ccnb);
78
79 res= ccn_sign_content(ospfndn->ccn, data, name, &sp, "hello", strlen("hello"));
80 res=ccn_put(ospfndn->ccn,data->buf,data->length);
81 ccn_charbuf_destroy(&data);
82
83 */
84 break;
85
86 default:
87 break;
88 }
89
90 return CCN_UPCALL_RESULT_OK;
91}
92
93
94enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
95 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
96{
97
98
99 switch(kind) {
100 case CCN_UPCALL_FINAL:
101 break;
102 case CCN_UPCALL_CONTENT:
103 printf("Content Received for name: ");
104 struct ccn_charbuf*c;
105 c=ccn_charbuf_create();
106 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E],0);
107 printf("%s\n",ccn_charbuf_as_string(c));
108 ccn_charbuf_destroy(&c);
akmhoquecb017752012-08-16 11:03:45 -0500109
110 process_incoming_content(selfp, info);
111
akmhoque59980a52012-08-09 12:36:09 -0500112 break;
113 case CCN_UPCALL_INTEREST_TIMED_OUT:
akmhoquecb017752012-08-16 11:03:45 -0500114 printf("Interest timed out \n");
115 struct ccn_charbuf*ic;
116 ic=ccn_charbuf_create();
117 ccn_uri_append(ic,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
118 printf("%s\n",ccn_charbuf_as_string(ic));
119 ccn_charbuf_destroy(&ic);
120 process_incoming_timed_out_interest(selfp,info);
akmhoque59980a52012-08-09 12:36:09 -0500121
akmhoque59980a52012-08-09 12:36:09 -0500122 break;
123 default:
124 fprintf(stderr, "Unexpected response of kind %d\n", kind);
125 return CCN_UPCALL_RESULT_ERR;
126 }
127
128 return CCN_UPCALL_RESULT_OK;
129}
akmhoque61fe4472012-08-10 10:13:34 -0500130
akmhoquecb017752012-08-16 11:03:45 -0500131
132void
133process_incoming_content(struct ccn_closure* selfp, struct ccn_upcall_info* info)
134{
135 printf("process_incoming_content called \n");
136
akmhoque638c20a2012-08-16 11:57:48 -0500137 struct ccn_charbuf*c;
138 c=ccn_charbuf_create();
akmhoquedde7e322012-08-16 13:57:06 -0500139 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
140 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque638c20a2012-08-16 11:57:48 -0500141 printf("%s\n",ccn_charbuf_as_string(c));
142 ccn_charbuf_destroy(&c);
143
144 const unsigned char *comp_ptr1;
145 size_t comp_size;
146 int res,i;
147 int nlsr_position=0;
148 int name_comps=(int)info->interest_comps->n;
149
150 for(i=0;i<name_comps;i++)
151 {
152 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
153 if( res == 0)
154 {
155 nlsr_position=i;
156 break;
157 }
158 }
159
160 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
161
162
163 printf("Det= %s \n",comp_ptr1);
164
165 if(!strcmp((char *)comp_ptr1,"lsdb"))
166 {
167 process_incoming_content_lsdb(selfp,info);
168 }
akmhoqued79438d2012-08-27 13:31:42 -0500169 if(!strcmp((char *)comp_ptr1,"info"))
170 {
171 process_incoming_content_info(selfp,info);
172 }
akmhoque638c20a2012-08-16 11:57:48 -0500173
174}
175
176
177void
178process_incoming_content_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
179{
180 printf("process_incoming_content_lsdb called \n");
181
182 const unsigned char *content_data;
183 size_t length;
184 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);
185
akmhoquedde7e322012-08-16 13:57:06 -0500186
187 if ( !strcmp((char *)content_data,"NACK"))
188 {
189 printf("NACK received for LSDB request. Do nothing \n");
190 }
191 else
192 {
193 // Do the LSDB processing here
194
akmhoque8a5babe2012-08-16 17:39:33 -0500195 const unsigned char *comp_ptr1;
196 size_t comp_size;
197 int res;
198
199 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 -0400200 if ( res >=0)
akmhoque8a5babe2012-08-16 17:39:33 -0500201 printf("Received Database Version: %s \n",(char *)comp_ptr1);
202
akmhoquedde7e322012-08-16 13:57:06 -0500203 }
akmhoque638c20a2012-08-16 11:57:48 -0500204
akmhoque8a5babe2012-08-16 17:39:33 -0500205
akmhoque638c20a2012-08-16 11:57:48 -0500206
akmhoquecb017752012-08-16 11:03:45 -0500207}
208
209
akmhoqued79438d2012-08-27 13:31:42 -0500210
211void
212process_incoming_content_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
213{
214 printf("process_incoming_content_info called \n");
215
216 const unsigned char *content_data;
217 size_t length;
218 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);
219
220 printf("Info Value: %s \n",(char *)content_data);
221
222
223}
224
akmhoquecb017752012-08-16 11:03:45 -0500225void
226process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
227{
228 printf("process_incoming_timed_out_interest called \n");
229
akmhoquedde7e322012-08-16 13:57:06 -0500230 struct ccn_charbuf*c;
231 c=ccn_charbuf_create();
232 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
233 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
234 printf("%s\n",ccn_charbuf_as_string(c));
235 ccn_charbuf_destroy(&c);
236
akmhoqueb2e3a332012-08-21 12:17:20 -0400237 //const unsigned char *comp_ptr1;
238 //size_t comp_size;
akmhoquedde7e322012-08-16 13:57:06 -0500239 int res,i;
240 int nlsr_position=0;
241 int name_comps=(int)info->interest_comps->n;
242
243 for(i=0;i<name_comps;i++)
244 {
245 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
246 if( res == 0)
247 {
248 nlsr_position=i;
249 break;
250 }
251 }
252
akmhoqueb2e3a332012-08-21 12:17:20 -0400253 //res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquedde7e322012-08-16 13:57:06 -0500254
255
akmhoqueb2e3a332012-08-21 12:17:20 -0400256 //printf("Det= %s \n",comp_ptr1);
akmhoquedde7e322012-08-16 13:57:06 -0500257
akmhoqueb2e3a332012-08-21 12:17:20 -0400258 //if(!strcmp((char *)comp_ptr1,"lsdb"))
259 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"lsdb") == 0)
akmhoquedde7e322012-08-16 13:57:06 -0500260 {
261 process_incoming_timed_out_interest_lsdb(selfp,info);
262 }
akmhoqued79438d2012-08-27 13:31:42 -0500263 else if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
264 {
265 process_incoming_timed_out_interest_info(selfp,info);
266 }
akmhoquecb017752012-08-16 11:03:45 -0500267}
268
269
akmhoque1c9b92f2012-08-13 10:57:50 -0500270void
akmhoquedde7e322012-08-16 13:57:06 -0500271process_incoming_timed_out_interest_lsdb(struct ccn_closure* selfp, struct ccn_upcall_info* info)
272{
273 printf("process_incoming_timed_out_interest_lsdb called \n");
274
275
276 int res,i;
277 int nlsr_position=0;
278 int name_comps=(int)info->interest_comps->n;
279
280 //const unsigned char *comp_ptr1;
281 //size_t comp_size;
282
283 for(i=0;i<name_comps;i++)
284 {
285 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
286 if( res == 0)
287 {
288 nlsr_position=i;
289 break;
290 }
291 }
292
293
akmhoque8a5babe2012-08-16 17:39:33 -0500294 struct ccn_charbuf *nbr;
295 nbr=ccn_charbuf_create();
296
akmhoquedde7e322012-08-16 13:57:06 -0500297
akmhoque8a5babe2012-08-16 17:39:33 -0500298 const unsigned char *comp_ptr1;
299 size_t comp_size;
300 for(i=0;i<nlsr_position;i++)
301 {
302 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
akmhoque6dc9a242012-08-21 11:23:57 -0400303 //printf("%s \n",comp_ptr1);
akmhoque8a5babe2012-08-16 17:39:33 -0500304 ccn_charbuf_append_string(nbr,"/");
305 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
306 }
307
akmhoque71b552d2012-08-21 11:44:34 -0400308 ccn_charbuf_append_string(nbr,"\0");
akmhoque8a5babe2012-08-16 17:39:33 -0500309 printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
310
311 update_adjacent_status_to_adl(nbr,1);
312
313 ccn_charbuf_destroy(&nbr);
akmhoquedde7e322012-08-16 13:57:06 -0500314}
315
316void
akmhoqued79438d2012-08-27 13:31:42 -0500317process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
318{
319
320 printf("process_incoming_timed_out_interest_info called \n");
321
322 int res,i;
323 int nlsr_position=0;
324 int name_comps=(int)info->interest_comps->n;
325
326 for(i=0;i<name_comps;i++)
327 {
328 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
329 if( res == 0)
330 {
331 nlsr_position=i;
332 break;
333 }
334 }
335
336 struct ccn_charbuf *nbr;
337 nbr=ccn_charbuf_create();
338
339
340 const unsigned char *comp_ptr1;
341 size_t comp_size;
342 for(i=0;i<nlsr_position;i++)
343 {
344 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
345 //printf("%s \n",comp_ptr1);
346 ccn_charbuf_append_string(nbr,"/");
347 ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);
348 }
349
350 ccn_charbuf_append_string(nbr,"\0");
351 printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
352
353 update_adjacent_timed_out_to_adl(nbr,1);
354 int timed_out=get_timed_out_number(nbr);
355 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
356 {
357 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
358 send_info_interest_to_neighbor(nbr);
359 }
360 else
361 {
362 printf("Neighbor: %s Info Interest Timed Out: %d times\n",ccn_charbuf_as_string(nbr),timed_out);
363 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
364 }
365
366 ccn_charbuf_destroy(&nbr);
367}
368
369
370void
akmhoque1c9b92f2012-08-13 10:57:50 -0500371process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
372{
373 printf("process_incoming_interest called \n");
374
375
376 struct ccn_charbuf*c;
377 c=ccn_charbuf_create();
akmhoque2fd74362012-08-27 14:45:08 -0500378 //ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
379 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name],0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500380 printf("%s\n",ccn_charbuf_as_string(c));
381 ccn_charbuf_destroy(&c);
382
383 const unsigned char *comp_ptr1;
384 size_t comp_size;
385 int res,i;
386 int nlsr_position=0;
387 int name_comps=(int)info->interest_comps->n;
388
389 for(i=0;i<name_comps;i++)
390 {
391 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
392 if( res == 0)
393 {
akmhoqueea3603e2012-08-13 11:24:09 -0500394 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500395 break;
396 }
397 }
398
399 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoquee0789862012-08-16 14:23:32 -0500400
akmhoque1c9b92f2012-08-13 10:57:50 -0500401 printf("Det= %s \n",comp_ptr1);
402
403 if(!strcmp((char *)comp_ptr1,"lsdb"))
404 {
akmhoquebf1aa832012-08-13 13:26:59 -0500405 process_incoming_interest_lsdb(selfp,info);
akmhoque1c9b92f2012-08-13 10:57:50 -0500406 }
akmhoqued79438d2012-08-27 13:31:42 -0500407 if(!strcmp((char *)comp_ptr1,"info"))
408 {
409 process_incoming_interest_info(selfp,info);
410 }
akmhoquebf1aa832012-08-13 13:26:59 -0500411}
412
413
414void
415process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
416{
417 printf("process_incoming_interest_lsdb called \n");
418
akmhoquecb017752012-08-16 11:03:45 -0500419 int l, res;
akmhoquefce8cfc2012-08-14 14:00:33 -0500420 const unsigned char *exclbase;
akmhoque6d49e4d2012-08-14 13:49:30 -0500421 size_t size;
akmhoquefce8cfc2012-08-14 14:00:33 -0500422 struct ccn_buf_decoder decoder;
423 struct ccn_buf_decoder *d;
424 const unsigned char *comp;
425
akmhoque6d49e4d2012-08-14 13:49:30 -0500426
427 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
428 if (l > 0)
429 {
430 comp = NULL;
431 size = 0;
432 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
433 d = ccn_buf_decoder_start(&decoder, exclbase, l);
434 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
435 {
436 ccn_buf_advance(d);
437 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
438 ccn_buf_advance_past_element(d);
439 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
440 {
441 ccn_buf_advance(d);
442 ccn_buf_match_blob(d, &comp, &size);
akmhoquec9286692012-08-16 09:57:58 -0500443 ccn_buf_check_close(d);
444
445
akmhoque6d49e4d2012-08-14 13:49:30 -0500446 }
447 ccn_buf_check_close(d);
448 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500449 //if (d->decoder.state < 0)
450 //printf("Parse Failed\n");
akmhoque6d49e4d2012-08-14 13:49:30 -0500451 if (comp != NULL)
akmhoque37e3adf2012-08-14 15:52:50 -0500452 printf("Number in Exclusion Filter is %s\n",comp);
akmhoque6d49e4d2012-08-14 13:49:30 -0500453
454 /* Now comp points to the start of your potential number, and size is its length */
455 }
456
akmhoquef6432c22012-08-21 13:18:05 -0400457 int excl_db_version=atoi((char *)comp);
458 int dbcmp=nlsr->lsdb->version-excl_db_version;
459 //int dbcmp=strncmp(nlsr->lsdb->version,(char *)comp,16);
460
461
akmhoque898d4aa2012-08-16 10:26:15 -0500462
akmhoque6dc9a242012-08-21 11:23:57 -0400463 printf (" dbcmp = %d \n",dbcmp);
akmhoque898d4aa2012-08-16 10:26:15 -0500464
akmhoque07dd8cc2012-08-16 10:23:01 -0500465 if(dbcmp > 0)
akmhoquecb017752012-08-16 11:03:45 -0500466 {
akmhoquef6432c22012-08-21 13:18:05 -0400467 printf("Has Updated database (Older: %s New: %ld)\n",comp,nlsr->lsdb->version);
akmhoquecb017752012-08-16 11:03:45 -0500468 }
akmhoque07dd8cc2012-08-16 10:23:01 -0500469 else
akmhoquecb017752012-08-16 11:03:45 -0500470 {
akmhoquef6432c22012-08-21 13:18:05 -0400471 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 -0500472 printf("Sending NACK Content back.....\n");
akmhoque07dd8cc2012-08-16 10:23:01 -0500473
akmhoquecb017752012-08-16 11:03:45 -0500474 struct ccn_charbuf *data=ccn_charbuf_create();
475 struct ccn_charbuf *name=ccn_charbuf_create();
476 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
477
akmhoque638c20a2012-08-16 11:57:48 -0500478 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 -0500479
480 sp.template_ccnb=ccn_charbuf_create();
481 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
482 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
483 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
484 ccn_charbuf_append_closer(sp.template_ccnb);
485
486 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
akmhoquedde7e322012-08-16 13:57:06 -0500487 if(res >= 0)
488 printf("Signing Content is successful \n");
489
akmhoquecb017752012-08-16 11:03:45 -0500490 res=ccn_put(nlsr->ccn,data->buf,data->length);
akmhoquebf11b1d2012-08-16 11:11:17 -0500491
492 if(res >= 0)
493 printf("Sending NACK Content is successful \n");
494
akmhoquecb017752012-08-16 11:03:45 -0500495 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500496 ccn_charbuf_destroy(&name);
akmhoquecb017752012-08-16 11:03:45 -0500497 ccn_charbuf_destroy(&sp.template_ccnb);
498
499 }
500
akmhoque1c9b92f2012-08-13 10:57:50 -0500501}
502
akmhoqued79438d2012-08-27 13:31:42 -0500503
504void
505process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
506{
507 printf("process_incoming_interest_info called \n");
508 int res;
509
510 printf("Sending Info Content back.....\n");
511
512 struct ccn_charbuf *data=ccn_charbuf_create();
513 struct ccn_charbuf *name=ccn_charbuf_create();
514 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
515
akmhoque887fc0c2012-08-27 15:06:06 -0500516 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]);
517
akmhoqued79438d2012-08-27 13:31:42 -0500518 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
akmhoque869485c2012-08-27 15:23:36 -0500524 res= ccn_sign_content(nlsr->ccn, data, name, &sp,"info",strlen("info") );
akmhoqued79438d2012-08-27 13:31:42 -0500525 if(res >= 0)
526 printf("Signing Content is successful \n");
527
528 res=ccn_put(nlsr->ccn,data->buf,data->length);
529 if(res >= 0)
akmhoque6428c922012-08-27 14:26:13 -0500530 printf("Sending Info Content is successful \n");
akmhoqued79438d2012-08-27 13:31:42 -0500531
532 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500533 ccn_charbuf_destroy(&name);
akmhoque869485c2012-08-27 15:23:36 -0500534 //ccn_charbuf_destroy(&c);
akmhoqued79438d2012-08-27 13:31:42 -0500535 ccn_charbuf_destroy(&sp.template_ccnb);
536
537}
538
akmhoque1c9b92f2012-08-13 10:57:50 -0500539int
540send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
541 struct ccn_scheduled_event *ev, int flags)
542{
543
544 struct ccn_charbuf *name;
545 long int rnum;
546 char rnumstr[20];
akmhoqueea3603e2012-08-13 11:24:09 -0500547 char lsdb_str[5];
548 char nlsr_str[5];
akmhoque1c9b92f2012-08-13 10:57:50 -0500549
550 int res,i;
551 int adl_element;
552
553 rnum=random();
554 memset(&rnumstr,0,20);
555 sprintf(rnumstr,"%ld",rnum);
akmhoqueea3603e2012-08-13 11:24:09 -0500556 memset(&nlsr_str,0,5);
557 sprintf(nlsr_str,"nlsr");
558 memset(&lsdb_str,0,5);
559 sprintf(lsdb_str,"lsdb");
560
akmhoque1c9b92f2012-08-13 10:57:50 -0500561
562 struct ndn_neighbor *nbr;
563
564 struct hashtb_enumerator ee;
565 struct hashtb_enumerator *e = &ee;
566
567 hashtb_start(nlsr->adl, e);
568 adl_element=hashtb_n(nlsr->adl);
akmhoque07dd8cc2012-08-16 10:23:01 -0500569 //int mynumber=15;
akmhoque1c9b92f2012-08-13 10:57:50 -0500570
571 for(i=0;i<adl_element;i++)
572 {
573 nbr=e->data;
akmhoquea6817692012-08-21 13:50:01 -0400574 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 -0500575 name=ccn_charbuf_create();
akmhoquea6817692012-08-21 13:50:01 -0400576 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
akmhoqueea3603e2012-08-13 11:24:09 -0500577 ccn_name_append_str(name,nlsr_str);
578 ccn_name_append_str(name,lsdb_str);
akmhoquef6432c22012-08-21 13:18:05 -0400579 //ccn_name_append_str(name,rnumstr);
akmhoque1c9b92f2012-08-13 10:57:50 -0500580
akmhoque6d49e4d2012-08-14 13:49:30 -0500581 /* adding Exclusion filter */
akmhoquebf1aa832012-08-13 13:26:59 -0500582
akmhoque6d49e4d2012-08-14 13:49:30 -0500583 struct ccn_charbuf *templ;
584 templ = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500585
akmhoque6d49e4d2012-08-14 13:49:30 -0500586 struct ccn_charbuf *c;
587 c = ccn_charbuf_create();
akmhoque7f337272012-08-14 15:16:30 -0500588
589
590 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
591 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
592 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque6d49e4d2012-08-14 13:49:30 -0500593 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
594 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
595 ccn_charbuf_reset(c);
akmhoque07dd8cc2012-08-16 10:23:01 -0500596 //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
akmhoquea6817692012-08-21 13:50:01 -0400597 //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
598 ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
akmhoque6d49e4d2012-08-14 13:49:30 -0500599 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
600 ccn_charbuf_append_closer(templ); /* </Exclude> */
akmhoque7f337272012-08-14 15:16:30 -0500601 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque37e3adf2012-08-14 15:52:50 -0500602
akmhoque6d49e4d2012-08-14 13:49:30 -0500603
604 /* Adding Exclusion filter done */
605
akmhoque7f337272012-08-14 15:16:30 -0500606 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
607
akmhoque1c9b92f2012-08-13 10:57:50 -0500608 if ( res >= 0 )
609 printf("Interest sending Successfull .... \n");
akmhoque37e3adf2012-08-14 15:52:50 -0500610 ccn_charbuf_destroy(&c);
akmhoque7f337272012-08-14 15:16:30 -0500611 ccn_charbuf_destroy(&templ);
akmhoque1c9b92f2012-08-13 10:57:50 -0500612 ccn_charbuf_destroy(&name);
613
akmhoque1d7343f2012-08-21 10:46:35 -0400614 hashtb_next(e);
akmhoque1c9b92f2012-08-13 10:57:50 -0500615 }
616
617 hashtb_end(e);
618
akmhoquebf11b1d2012-08-16 11:11:17 -0500619 nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500620
621 return 0;
622
623}
624
akmhoqued79438d2012-08-27 13:31:42 -0500625
626int
627send_info_interest(struct ccn_schedule *sched, void *clienth,
628 struct ccn_scheduled_event *ev, int flags)
629{
630
631 struct ccn_charbuf *name;
632 long int rnum;
633 char rnumstr[20];
634 char info_str[5];
635 char nlsr_str[5];
636
637 int res,i;
638 int adl_element;
639 int scope = 2; //no further than the next host
640
641 rnum=random();
642 memset(&rnumstr,0,20);
643 sprintf(rnumstr,"%ld",rnum);
644 memset(&nlsr_str,0,5);
645 sprintf(nlsr_str,"nlsr");
646 memset(&info_str,0,5);
647 sprintf(info_str,"info");
648
649
650 struct ndn_neighbor *nbr;
651
652 struct hashtb_enumerator ee;
653 struct hashtb_enumerator *e = &ee;
654
655 hashtb_start(nlsr->adl, e);
656 adl_element=hashtb_n(nlsr->adl);
657 //int mynumber=15;
658
659 for(i=0;i<adl_element;i++)
660 {
661 nbr=e->data;
662 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr->neighbor),nlsr_str,info_str);
663 name=ccn_charbuf_create();
664 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr->neighbor));
665 ccn_name_append_str(name,nlsr_str);
666 ccn_name_append_str(name,info_str);
667 //ccn_name_append_str(name,rnumstr);
668
669 /* adding Exclusion filter */
670
671 struct ccn_charbuf *templ;
672 templ = ccn_charbuf_create();
673
674// struct ccn_charbuf *c;
675// c = ccn_charbuf_create();
676
677
678 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
679 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
680 ccn_charbuf_append_closer(templ); /* </Name> */
681// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
682// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
683// ccn_charbuf_reset(c);
684// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
685// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
686// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
687// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
688// ccn_charbuf_append_closer(templ); /* </Exclude> */
689 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
690 appendLifetime(templ,nlsr->interest_resend_time);
691 ccn_charbuf_append_closer(templ); /* </Interest> */
692
693
694 /* Adding Exclusion filter done */
695
696 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
697
698 if ( res >= 0 )
699 printf("Interest sending Successfull .... \n");
700// ccn_charbuf_destroy(&c);
701 ccn_charbuf_destroy(&templ);
702 ccn_charbuf_destroy(&name);
703
704 hashtb_next(e);
705 }
706
707 hashtb_end(e);
708
709 //nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);
710
711 return 0;
712
713}
714
715
716void
717send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
718{
719
720 struct ccn_charbuf *name;
721 long int rnum;
722 char rnumstr[20];
723 char info_str[5];
724 char nlsr_str[5];
725
726 int res;
727 int scope = 2; //no further than the next host
728
729 rnum=random();
730 memset(&rnumstr,0,20);
731 sprintf(rnumstr,"%ld",rnum);
732 memset(&nlsr_str,0,5);
733 sprintf(nlsr_str,"nlsr");
734 memset(&info_str,0,5);
735 sprintf(info_str,"info");
736
737 printf("Sending interest for name prefix:%s/%s/%s\n",ccn_charbuf_as_string(nbr),nlsr_str,info_str);
738 name=ccn_charbuf_create();
739 res=ccn_name_from_uri(name,ccn_charbuf_as_string(nbr));
740 ccn_name_append_str(name,nlsr_str);
741 ccn_name_append_str(name,info_str);
742 //ccn_name_append_str(name,rnumstr);
743
744 /* adding Exclusion filter */
745
746 struct ccn_charbuf *templ;
747 templ = ccn_charbuf_create();
748
749// struct ccn_charbuf *c;
750// c = ccn_charbuf_create();
751
752
753 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
754 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
755 ccn_charbuf_append_closer(templ); /* </Name> */
756// ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
757// ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
758// ccn_charbuf_reset(c);
759// //ccn_charbuf_putf(c, "%u", (unsigned)mynumber);
760// //ccn_charbuf_putf(c, "%s", nbr->last_lsdb_version);
761// ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
762// ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
763// ccn_charbuf_append_closer(templ); /* </Exclude> */
764 ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
765 appendLifetime(templ,15);
766 ccn_charbuf_append_closer(templ); /* </Interest> */
767
768
769 /* Adding Exclusion filter done */
770
771 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
772
773 if ( res >= 0 )
774 printf("Interest sending Successfull .... \n");
775// ccn_charbuf_destroy(&c);
776 ccn_charbuf_destroy(&templ);
777 ccn_charbuf_destroy(&name);
778
779}