blob: d67cd1dfd28070ca87120eb67191f07970835593 [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"
akmhoque8a5babe2012-08-16 17:39:33 -050023#include "nlsr_adl.h"
akmhoqued79438d2012-08-27 13:31:42 -050024#include "nlsr_lsdb.h"
akmhoque53f64222012-09-05 13:57:51 -050025#include "utility.h"
26
akmhoqued79438d2012-08-27 13:31:42 -050027
28int
29appendLifetime(struct ccn_charbuf *cb, int lifetime)
30{
31 unsigned char buf[sizeof(int32_t)];
32 int32_t dreck = lifetime << 12;
33 int pos = sizeof(int32_t);
34 int res = 0;
35 while (dreck > 0 && pos > 0)
36 {
37 pos--;
38 buf[pos] = dreck & 255;
39 dreck = dreck >> 8;
40 }
41 res |= ccnb_append_tagged_blob(cb, CCN_DTAG_InterestLifetime, buf+pos, sizeof(buf)-pos);
42 return res;
43}
akmhoque59980a52012-08-09 12:36:09 -050044
akmhoque53f64222012-09-05 13:57:51 -050045
46void
47get_nbr(struct name_prefix *nbr,struct ccn_closure *selfp, struct ccn_upcall_info *info)
48{
49
50 printf("get_nbr called\n");
51 int res,i;
52 int nlsr_position=0;
53 int name_comps=(int)info->interest_comps->n;
54 int len=0;
55
56 for(i=0;i<name_comps;i++)
57 {
58 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
59 if( res == 0)
60 {
61 nlsr_position=i;
62 break;
63 }
64 }
65
66
67 const unsigned char *comp_ptr1;
68 size_t comp_size;
69 for(i=0;i<nlsr_position;i++)
70 {
71 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
72 len+=1;
73 len+=(int)comp_size;
74 }
75 len++;
76
77 char *neighbor=(char *)malloc(len);
78 memset(neighbor,0,len);
79
80 for(i=0; i<nlsr_position;i++)
81 {
82 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
83 memcpy(neighbor+strlen(neighbor),"/",1);
84 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
85
86 }
87
88 //neighbor[strlen(neighbor)]='\0';
89
90 nbr->name=(char *)malloc(strlen(neighbor)+1);
91 memcpy(nbr->name,neighbor,strlen(neighbor)+1);
92 nbr->length=strlen(neighbor)+1;
93
94 printf("Neighbor: %s Length: %d\n",nbr->name,nbr->length);
95
96
97}
98
99void
100get_lsa_identifier(struct name_prefix *lsaId,struct ccn_closure *selfp, struct ccn_upcall_info *info)
101{
102
103 printf("get_nbr called\n");
104 int res,i;
105 int nlsr_position=0;
106 int name_comps=(int)info->interest_comps->n;
107 int len=0;
108
109 for(i=0;i<name_comps;i++)
110 {
111 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
112 if( res == 0)
113 {
114 nlsr_position=i;
115 break;
116 }
117 }
118
119
120 const unsigned char *comp_ptr1;
121 size_t comp_size;
122 for(i=nlsr_position+2;i<info->interest_comps->n-2;i++)
123 {
124 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
125 len+=1;
126 len+=(int)comp_size;
127 }
128 len++;
129
130 char *neighbor=(char *)malloc(len);
131 memset(neighbor,0,len);
132
133 for(i=nlsr_position+2; i<info->interest_comps->n-2;i++)
134 {
135 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
136 memcpy(neighbor+strlen(neighbor),"/",1);
137 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,strlen((char *)comp_ptr1));
138
139 }
140
141 //neighbor[strlen(neighbor)]='\0';
142
143 lsaId->name=(char *)malloc(strlen(neighbor)+1);
144 memset(lsaId->name,0,strlen(neighbor)+1);
145 memcpy(lsaId->name,neighbor,strlen(neighbor)+1);
146 lsaId->length=strlen(neighbor)+1;
147
148 printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
149
150
151}
152
akmhoque59980a52012-08-09 12:36:09 -0500153enum ccn_upcall_res
154incoming_interest(struct ccn_closure *selfp,
155 enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
156{
akmhoque53f64222012-09-05 13:57:51 -0500157 my_lock();
akmhoque59980a52012-08-09 12:36:09 -0500158 switch (kind) {
159 case CCN_UPCALL_FINAL:
160 break;
161 case CCN_UPCALL_INTEREST:
akmhoque53f64222012-09-05 13:57:51 -0500162 printf("Interest Received \n");
akmhoque1c9b92f2012-08-13 10:57:50 -0500163 process_incoming_interest(selfp, info);
akmhoque59980a52012-08-09 12:36:09 -0500164 break;
akmhoque59980a52012-08-09 12:36:09 -0500165 default:
166 break;
167 }
akmhoque42098b12012-08-27 22:54:23 -0500168 my_unlock();
akmhoque59980a52012-08-09 12:36:09 -0500169 return CCN_UPCALL_RESULT_OK;
170}
171
172
akmhoqued79438d2012-08-27 13:31:42 -0500173void
akmhoque1c9b92f2012-08-13 10:57:50 -0500174process_incoming_interest(struct ccn_closure *selfp, struct ccn_upcall_info *info)
175{
176 printf("process_incoming_interest called \n");
177
akmhoque53f64222012-09-05 13:57:51 -0500178 /*
akmhoque1c9b92f2012-08-13 10:57:50 -0500179 struct ccn_charbuf*c;
180 c=ccn_charbuf_create();
akmhoque53f64222012-09-05 13:57:51 -0500181 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
akmhoque1c9b92f2012-08-13 10:57:50 -0500182 printf("%s\n",ccn_charbuf_as_string(c));
183 ccn_charbuf_destroy(&c);
akmhoque53f64222012-09-05 13:57:51 -0500184 */
akmhoque1c9b92f2012-08-13 10:57:50 -0500185 const unsigned char *comp_ptr1;
186 size_t comp_size;
187 int res,i;
188 int nlsr_position=0;
189 int name_comps=(int)info->interest_comps->n;
akmhoque53f64222012-09-05 13:57:51 -0500190
akmhoque1c9b92f2012-08-13 10:57:50 -0500191 for(i=0;i<name_comps;i++)
192 {
193 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
194 if( res == 0)
195 {
akmhoqueea3603e2012-08-13 11:24:09 -0500196 nlsr_position=i;
akmhoque1c9b92f2012-08-13 10:57:50 -0500197 break;
198 }
199 }
200
201 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
akmhoque53f64222012-09-05 13:57:51 -0500202
akmhoque1c9b92f2012-08-13 10:57:50 -0500203 printf("Det= %s \n",comp_ptr1);
204
akmhoqued79438d2012-08-27 13:31:42 -0500205 if(!strcmp((char *)comp_ptr1,"info"))
206 {
207 process_incoming_interest_info(selfp,info);
208 }
akmhoque53f64222012-09-05 13:57:51 -0500209 if(!strcmp((char *)comp_ptr1,"lsdb"))
210 {
211 process_incoming_interest_lsdb(selfp,info);
212 }
213 if(!strcmp((char *)comp_ptr1,"lsa"))
214 {
215 process_incoming_interest_lsa(selfp,info);
216 }
217
218}
219
220void
221process_incoming_interest_info(struct ccn_closure *selfp, struct ccn_upcall_info *info)
222{
223 printf("process_incoming_interest_info called \n");
224
225
226 printf("Sending info Content Back ...\n");
227 int res;
228 struct ccn_charbuf *data=ccn_charbuf_create();
229 struct ccn_charbuf *name=ccn_charbuf_create();
230 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
231
232 res=ccn_charbuf_append(name, info->interest_ccnb + info->pi->offset[CCN_PI_B_Name],info->pi->offset[CCN_PI_E_Name] - info->pi->offset[CCN_PI_B_Name]);
233 if (res >= 0)
234 {
235 sp.template_ccnb=ccn_charbuf_create();
236 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
237 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
238 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
239 ccn_charbuf_append_closer(sp.template_ccnb);
240
241
242 char *raw_data=(char *)malloc(16);
243 memset(raw_data,0,16);
244 sprintf(raw_data,"%ld", nlsr->lsdb_synch_interval);
245
246 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data,strlen(raw_data));
247 if(res >= 0)
248 printf("Signing Content is successful \n");
249
250 res=ccn_put(nlsr->ccn,data->buf,data->length);
251 if(res >= 0)
252 printf("Sending Info Content is successful \n");
253
254 printf("Info Content sending done....\n");
255
256
257 struct name_prefix *nbr=(struct name_prefix * )malloc(sizeof(struct name_prefix *));
258 get_lsa_identifier(nbr,selfp,info);
259 printf("Neighbor : %s Length : %d Status : %d\n",nbr->name,nbr->length,get_adjacent_status(nbr));
260
261
262 if( get_adjacent_status(nbr) == 0 && get_timed_out_number(nbr)>=nlsr->interest_retry )
263 {
264 send_info_interest_to_neighbor(nbr);
265 }
266
267 free(nbr);
268 free(raw_data);
269 ccn_charbuf_destroy(&sp.template_ccnb);
270 }
271
272 ccn_charbuf_destroy(&data);
273 ccn_charbuf_destroy(&name);
274
275
276
277
akmhoquebf1aa832012-08-13 13:26:59 -0500278}
279
280
281void
282process_incoming_interest_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info *info)
283{
284 printf("process_incoming_interest_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500285
286 int l,res;
akmhoquefce8cfc2012-08-14 14:00:33 -0500287 const unsigned char *exclbase;
akmhoque6d49e4d2012-08-14 13:49:30 -0500288 size_t size;
akmhoquefce8cfc2012-08-14 14:00:33 -0500289 struct ccn_buf_decoder decoder;
290 struct ccn_buf_decoder *d;
akmhoque53f64222012-09-05 13:57:51 -0500291 const unsigned char *comp;
292 int dbcmp=0;
akmhoque6d49e4d2012-08-14 13:49:30 -0500293
294 l = info->pi->offset[CCN_PI_E_Exclude] - info->pi->offset[CCN_PI_B_Exclude];
295 if (l > 0)
296 {
297 comp = NULL;
298 size = 0;
299 exclbase = info->interest_ccnb + info->pi->offset[CCN_PI_B_Exclude];
300 d = ccn_buf_decoder_start(&decoder, exclbase, l);
301 if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude))
302 {
303 ccn_buf_advance(d);
304 if (ccn_buf_match_dtag(d, CCN_DTAG_Any))
305 ccn_buf_advance_past_element(d);
306 if (ccn_buf_match_dtag(d, CCN_DTAG_Component))
307 {
308 ccn_buf_advance(d);
309 ccn_buf_match_blob(d, &comp, &size);
akmhoquec9286692012-08-16 09:57:58 -0500310 ccn_buf_check_close(d);
akmhoque53f64222012-09-05 13:57:51 -0500311
312
akmhoque6d49e4d2012-08-14 13:49:30 -0500313 }
314 ccn_buf_check_close(d);
315 }
akmhoque6d49e4d2012-08-14 13:49:30 -0500316 if (comp != NULL)
akmhoque53f64222012-09-05 13:57:51 -0500317 {
318 printf("LSDB Version in Exclusion Filter is %s\n",comp);
319 dbcmp=strcmp(nlsr->lsdb->version,(char *)comp);
320 }
akmhoque6d49e4d2012-08-14 13:49:30 -0500321 /* Now comp points to the start of your potential number, and size is its length */
322 }
akmhoque53f64222012-09-05 13:57:51 -0500323 else
akmhoquecb017752012-08-16 11:03:45 -0500324 {
akmhoque53f64222012-09-05 13:57:51 -0500325 printf("LSDB Version in Exclusion Filter is: None Added\n");
326 dbcmp=1;
akmhoquecb017752012-08-16 11:03:45 -0500327
328 }
329
akmhoqued79438d2012-08-27 13:31:42 -0500330 struct ccn_charbuf *data=ccn_charbuf_create();
akmhoque53f64222012-09-05 13:57:51 -0500331 struct ccn_charbuf *name=ccn_charbuf_create();
332 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
333
334 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]);
akmhoque887fc0c2012-08-27 15:06:06 -0500335
akmhoqued79438d2012-08-27 13:31:42 -0500336 sp.template_ccnb=ccn_charbuf_create();
337 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
338 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
akmhoque53f64222012-09-05 13:57:51 -0500339 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
340 ccn_charbuf_append_closer(sp.template_ccnb);
akmhoqued79438d2012-08-27 13:31:42 -0500341
akmhoqued79438d2012-08-27 13:31:42 -0500342
akmhoque53f64222012-09-05 13:57:51 -0500343 if(dbcmp>0)
344 {
345 printf("Has Updated Database than Neighbor\n");
346 printf("Sending LSDB Summary of Updated LSDB Content...\n");
347 /*
348 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]);
349
350 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
351 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
352 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
353 ccn_charbuf_append_closer(sp.template_ccnb);
354 */
355
356 //ccn_charbuf_append_string(name,nlsr->lsdb->version);
357
358
359
360 long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element();
361 char *num_element=(char *)malloc(15);
362 memset(num_element,0,15);
363 sprintf(num_element,"%ld|",num_lsa);
364
365 char *name_lsdb_summary=get_name_lsdb_summary();
366 char *adj_lsdb_summary=get_adj_lsdb_summary();
367
368 char *raw_data=(char *)malloc(strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
369 memset(raw_data,0,strlen(num_element) + strlen(name_lsdb_summary)+strlen(adj_lsdb_summary)+1);
370
371 memcpy(raw_data+strlen(raw_data),num_element,strlen(num_element)+1);
372
373 if( strlen(name_lsdb_summary) >0 )
374 {
375 memcpy(raw_data+strlen(raw_data),name_lsdb_summary,strlen(name_lsdb_summary)+1);
376 }
377 if( strlen(adj_lsdb_summary) >0 )
378 {
379 memcpy(raw_data+strlen(raw_data),adj_lsdb_summary,strlen(adj_lsdb_summary)+1);
380 }
381
382 printf("Content Data to be sent: %s \n",raw_data);
383
384 if(nlsr->adj_build_count == 0 && nlsr->is_build_adj_lsa_sheduled == 1)
385 {
386 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "WAIT" , strlen("WAIT"));
387 }
388 else
389 {
390 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
391 }
392 if(res >= 0)
393 printf("Signing LSDB Summary of Updated LSDB Content is successful \n");
394
395 res=ccn_put(nlsr->ccn,data->buf,data->length);
396
397 if(res >= 0)
398 printf("Sending LSDB Summary of Updated LSDB Content is successful \n");
399
400 //ccn_charbuf_destroy(&nlsd);
401 //ccn_charbuf_destroy(&alsd);
402 free(num_element);
403 }
404 else
405 {
406 printf("Does not have Updated Database than Neighbor\n");
407
408 printf("Sending NACK Content.....\n");
409 //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]);
410
411 /*
412 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
413 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
414 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
415 ccn_charbuf_append_closer(sp.template_ccnb);
416 */
417 res= ccn_sign_content(nlsr->ccn, data, name, &sp, "NACK", strlen("NACK"));
418 if(res >= 0)
419 printf("Signing NACK Content is successful \n");
420
421 res=ccn_put(nlsr->ccn,data->buf,data->length);
422
423 if(res >= 0)
424 printf("Sending NACK Content is successful \n");
425
426
427 }
akmhoqued79438d2012-08-27 13:31:42 -0500428
429 ccn_charbuf_destroy(&data);
akmhoqued79438d2012-08-27 13:31:42 -0500430 ccn_charbuf_destroy(&name);
431 ccn_charbuf_destroy(&sp.template_ccnb);
432
433}
434
akmhoque53f64222012-09-05 13:57:51 -0500435void
436process_incoming_interest_lsa(struct ccn_closure *selfp, struct ccn_upcall_info *info)
akmhoque1c9b92f2012-08-13 10:57:50 -0500437{
akmhoque53f64222012-09-05 13:57:51 -0500438 printf("process_incoming_interest_lsa called \n");
akmhoque1c9b92f2012-08-13 10:57:50 -0500439
akmhoque53f64222012-09-05 13:57:51 -0500440 /*
441 struct ccn_charbuf*c;
442 c=ccn_charbuf_create();
443 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
444 printf("%s\n",ccn_charbuf_as_string(c));
445 ccn_charbuf_destroy(&c);
446 */
447 int res;
akmhoque1c9b92f2012-08-13 10:57:50 -0500448
akmhoque53f64222012-09-05 13:57:51 -0500449 struct name_prefix *lsaId=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
450 get_lsa_identifier(lsaId,selfp,info);
akmhoque1c9b92f2012-08-13 10:57:50 -0500451
akmhoque53f64222012-09-05 13:57:51 -0500452 printf("LSA Identifier: %s Length: %d\n",lsaId->name,lsaId->length-1);
453 printf("Router Name : %s Length: %d\n",nlsr->router_name->name,nlsr->router_name->length);
akmhoque1c9b92f2012-08-13 10:57:50 -0500454
akmhoque53f64222012-09-05 13:57:51 -0500455 char lsa_type=lsaId->name[nlsr->router_name->length];
456 printf("LSA Type: %c\n",lsa_type);
457 int ls_type=atoi(&lsa_type);
akmhoque1c9b92f2012-08-13 10:57:50 -0500458
akmhoque53f64222012-09-05 13:57:51 -0500459 struct ccn_charbuf *lsa_data=ccn_charbuf_create();
460
461 if ( ls_type == LSA_NAME_TYPE )
akmhoque1c9b92f2012-08-13 10:57:50 -0500462 {
akmhoque53f64222012-09-05 13:57:51 -0500463 printf("Interest Received for NAME LSA\n");
464 get_name_lsa_data(lsa_data,lsaId);
465 }
466 else if ( ls_type == LSA_ADJ_TYPE )
467 {
468 printf("Interest Received for ADJ LSA\n");
469 get_adj_lsa_data(lsa_data,lsaId);
akmhoque1c9b92f2012-08-13 10:57:50 -0500470 }
471
akmhoque53f64222012-09-05 13:57:51 -0500472 char *rdata=ccn_charbuf_as_string(lsa_data);
473 char *raw_data=(char *)malloc(strlen(rdata)+1);
474 memset(raw_data,0,strlen(rdata)+1);
475 memcpy(raw_data,(char *)rdata,strlen(rdata)+1);
476 printf("Content Data to be sent: %s\n",raw_data);
akmhoque1c9b92f2012-08-13 10:57:50 -0500477
akmhoque53f64222012-09-05 13:57:51 -0500478 struct ccn_charbuf *data=ccn_charbuf_create();
479 struct ccn_charbuf *name=ccn_charbuf_create();
480 struct ccn_signing_params sp=CCN_SIGNING_PARAMS_INIT;
481
482 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]);
akmhoque1c9b92f2012-08-13 10:57:50 -0500483
akmhoque53f64222012-09-05 13:57:51 -0500484 sp.template_ccnb=ccn_charbuf_create();
485 ccn_charbuf_append_tt(sp.template_ccnb,CCN_DTAG_SignedInfo, CCN_DTAG);
486 ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", 10);
487 sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
488 ccn_charbuf_append_closer(sp.template_ccnb);
akmhoque1c9b92f2012-08-13 10:57:50 -0500489
akmhoque53f64222012-09-05 13:57:51 -0500490 res= ccn_sign_content(nlsr->ccn, data, name, &sp, raw_data , strlen(raw_data));
491 if(res >= 0)
492 printf("Signing LSA Content is successful \n");
493
494 res=ccn_put(nlsr->ccn,data->buf,data->length);
495 if(res >= 0)
496 printf("Sending LSA Content is successful \n");
497
498
499
500 ccn_charbuf_destroy(&data);
501 ccn_charbuf_destroy(&name);
502 ccn_charbuf_destroy(&sp.template_ccnb);
503 ccn_charbuf_destroy(&lsa_data);
504
505 free(raw_data);
506 free(lsaId);
akmhoque1c9b92f2012-08-13 10:57:50 -0500507}
508
akmhoque53f64222012-09-05 13:57:51 -0500509enum ccn_upcall_res incoming_content(struct ccn_closure* selfp,
510 enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500511{
512
akmhoque42098b12012-08-27 22:54:23 -0500513 my_lock();
akmhoque53f64222012-09-05 13:57:51 -0500514 switch(kind) {
515 case CCN_UPCALL_FINAL:
516 break;
517 case CCN_UPCALL_CONTENT:
518 printf("Content Received \n");
akmhoqued79438d2012-08-27 13:31:42 -0500519
akmhoque53f64222012-09-05 13:57:51 -0500520 process_incoming_content(selfp, info);
akmhoqued79438d2012-08-27 13:31:42 -0500521
akmhoque53f64222012-09-05 13:57:51 -0500522 break;
523 case CCN_UPCALL_INTEREST_TIMED_OUT:
524 printf("Interest timed out \n");
525 process_incoming_timed_out_interest(selfp,info);
akmhoqued79438d2012-08-27 13:31:42 -0500526
akmhoque53f64222012-09-05 13:57:51 -0500527 break;
528 default:
529 fprintf(stderr, "Unexpected response of kind %d\n", kind);
530 //return CCN_UPCALL_RESULT_ERR;
531 }
akmhoqued79438d2012-08-27 13:31:42 -0500532
akmhoque42098b12012-08-27 22:54:23 -0500533 my_unlock();
akmhoque53f64222012-09-05 13:57:51 -0500534 return CCN_UPCALL_RESULT_OK;
akmhoqued79438d2012-08-27 13:31:42 -0500535}
536
akmhoqued79438d2012-08-27 13:31:42 -0500537void
akmhoque53f64222012-09-05 13:57:51 -0500538process_incoming_content(struct ccn_closure *selfp, struct ccn_upcall_info* info)
akmhoqued79438d2012-08-27 13:31:42 -0500539{
akmhoque53f64222012-09-05 13:57:51 -0500540 printf("process_incoming_content called \n");
541
542 /*
543 struct ccn_charbuf*c;
544 c=ccn_charbuf_create();
545 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
546 printf("%s\n",ccn_charbuf_as_string(c));
547 ccn_charbuf_destroy(&c);
548 */
549
550 const unsigned char *comp_ptr1;
551 size_t comp_size;
552 int res,i;
553 int nlsr_position=0;
554 int name_comps=(int)info->interest_comps->n;
555
556 for(i=0;i<name_comps;i++)
557 {
558 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
559 if( res == 0)
560 {
561 nlsr_position=i;
562 break;
563 }
564 }
565
566 res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,nlsr_position+1,&comp_ptr1, &comp_size);
567
568 printf("Det= %s \n",comp_ptr1);
569
570 if(!strcmp((char *)comp_ptr1,"info"))
571 {
572 process_incoming_content_info(selfp,info);
573 }
574 if(!strcmp((char *)comp_ptr1,"lsdb"))
575 {
576 process_incoming_content_lsdb(selfp,info);
577 }
578 if(!strcmp((char *)comp_ptr1,"lsa"))
579 {
580 process_incoming_content_lsa(selfp,info);
581 }
582
583}
584
585void
586process_incoming_content_info(struct ccn_closure *selfp, struct ccn_upcall_info* info)
587{
588 printf("process_incoming_content_info called \n");
589
590 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
591 get_nbr(nbr,selfp,info);
592
593 printf("Info Content Received For Neighbor: %s Length:%d\n",nbr->name,nbr->length);
594
595
596 const unsigned char *ptr;
597 size_t length;
598 ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
599 printf("Content data: %s\n",ptr);
600
601 long int interval=atoi((char *)ptr);
602
603
604 update_adjacent_timed_out_zero_to_adl(nbr);
605 update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
606 update_lsdb_synch_interval_to_adl(nbr,interval);
607 print_adjacent_from_adl();
608
609 if(!nlsr->is_build_adj_lsa_sheduled)
610 {
611 printf("Scheduling Build and Install Adj LSA...\n");
612 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 100000, &build_and_install_adj_lsa, NULL, 0);
613 nlsr->is_build_adj_lsa_sheduled=1;
614 }
615 else
616 {
617 printf("Build and Install Adj LSA already scheduled\n");
618 }
619
620 free(nbr);
621
622
623}
624
625void
626process_incoming_content_lsdb(struct ccn_closure *selfp, struct ccn_upcall_info* info)
627{
628 printf("process_incoming_content_lsdb called \n");
629
630
631 const unsigned char *ptr;
632 size_t length;
633 ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
634 printf("Content data: %s\n",ptr);
635
636 if( (strcmp("NACK",(char *)ptr) != 0 ) && (strcmp("WAIT",(char *)ptr) != 0 ) )
637 {
638 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
639 get_nbr(nbr,selfp,info);
640
641 char *nl;
642 int num_element;
643 int i;
644 char *rem;
645 const char *sep="|";
646 char *orig_router;
647 char *lst;
648 int ls_type;
649 char *lsid;
650 long int ls_id;
651
652 nl=strtok_r((char *)ptr,sep,&rem);
653 num_element=atoi(nl);
654
655 for(i = 0 ; i < num_element ; i++)
656 {
657 orig_router=strtok_r(NULL,sep,&rem);
658 lst=strtok_r(NULL,sep,&rem);
659 ls_type=atoi(lst);
660 printf("Orig Router: %s ls Type: %d",orig_router,ls_type);
661
662 if(ls_type == LS_TYPE_NAME)
663 {
664 lsid=strtok_r(NULL,sep,&rem);
665 ls_id=atoi(lsid);
666 printf(" LS Id: %ld\n",ls_id);
667 send_interest_for_name_lsa(nbr,orig_router,lst,lsid);
668 }
669 else
670 {
671 printf("\n");
672 send_interest_for_adj_lsa(nbr,orig_router,lst);
673 }
674
675 }
676
677
678
679 char *version=get_current_timestamp_micro();
680 printf("Old LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
681 update_adjacent_lsdb_version_to_adl(nbr,version);
682 printf("New LSDB Version of Neighbor: %s is :%s\n",nbr->name,get_nbr_lsdb_version(nbr->name));
683
684
685
686 free(nbr);
687 }
688 else if (strcmp("WAIT",(char *)ptr) == 0)
689 {
690 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
691 get_nbr(nbr,selfp,info);
692 long int interval=get_lsdb_synch_interval(nbr->name);
693 adjust_adjacent_last_lsdb_requested_to_adl(nbr->name,(long int)interval/2);
694
695
696 free(nbr);
697 }
698 else
699 {
700 printf("NACK Content Received\n");
701 }
702
703
704}
705
706void
707process_incoming_content_lsa(struct ccn_closure *selfp, struct ccn_upcall_info* info)
708{
709 printf("process_incoming_content_lsa called \n");
710
711 char *sep="|";
712 char *rem;
713 char *orig_router;
714 char *orl;
715 int orig_router_length;
716 char *lst;
717 int ls_type;
718 char *lsid;
719 long int ls_id;
720 char *isvld;
721 int isValid;
722 char *num_link;
723 int no_link;
724 char *np;
725 char *np_length;
726 int name_length;
727 char *data;
728 char *orig_time;
729
730 const unsigned char *ptr;
731 size_t length;
732 ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &ptr, &length);
733 printf("Content data Received: %s\n",ptr);
734
735 printf("LSA Data\n");
736
737 if( strlen((char *) ptr ) > 0 )
738 {
739
740 orig_router=strtok_r((char *)ptr,sep,&rem);
741 orl=strtok_r(NULL,sep,&rem);
742 orig_router_length=atoi(orl);
743
744 printf(" Orig Router Name : %s\n",orig_router);
745 printf(" Orig Router Length: %d\n",orig_router_length);
746
747 lst=strtok_r(NULL,sep,&rem);
748 ls_type=atoi(lst);
749
750 printf(" LS Type : %d\n",ls_type);
751
752 if ( ls_type == LSA_NAME_TYPE )
753 {
754 lsid=strtok_r(NULL,sep,&rem);
755 ls_id=atoi(lsid);
756 isvld=strtok_r(NULL,sep,&rem);
757 isValid=atoi(isvld);
758 np=strtok_r(NULL,sep,&rem);
759 np_length=strtok_r(NULL,sep,&rem);
760 name_length=atoi(np_length);
761
762 printf(" LS ID : %ld\n",ls_id);
763 printf(" isValid : %d\n",isValid);
764 printf(" Name Prefix : %s\n",np);
765 printf(" Name Prefix length: %d\n",name_length);
766
767 build_and_install_others_name_lsa(orig_router,ls_type,ls_id,isValid,np);
768
769 }
770 else if ( ls_type == LSA_ADJ_TYPE )
771 {
772 orig_time=strtok_r(NULL,sep,&rem);
773 num_link=strtok_r(NULL,sep,&rem);
774 no_link=atoi(num_link);
775 data=rem;
776
777 printf(" No Link : %d\n",no_link);
778 printf(" Data : %s\n",data);
779
780 build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,no_link,data);
781 }
782
783
784 }
785
786}
787
788void
789process_incoming_timed_out_interest(struct ccn_closure* selfp, struct ccn_upcall_info* info)
790{
791 printf("process_incoming_timed_out_interest called \n");
792
793 /*
794 struct ccn_charbuf*c;
795 c=ccn_charbuf_create();
796 ccn_uri_append(c,info->interest_ccnb,info->pi->offset[CCN_PI_E_Name]-info->pi->offset[CCN_PI_B_Name],0);
797 printf("%s\n",ccn_charbuf_as_string(c));
798 ccn_charbuf_destroy(&c);
799 */
800
801 int res,i;
802 int nlsr_position=0;
803 int name_comps=(int)info->interest_comps->n;
804
805 for(i=0;i<name_comps;i++)
806 {
807 res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
808 if( res == 0)
809 {
810 nlsr_position=i;
811 break;
812 }
813 }
814
815 if(ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,nlsr_position+1,"info") == 0)
816 {
817 process_incoming_timed_out_interest_info(selfp,info);
818 }
819}
820
821void
822process_incoming_timed_out_interest_info(struct ccn_closure* selfp, struct ccn_upcall_info* info)
823{
824 printf("process_incoming_timed_out_interest_info called \n");
825
826 struct name_prefix *nbr=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
827 get_nbr(nbr,selfp,info);
828
829 printf("Info Interest Timed Out for for Neighbor: %s Length:%d\n",nbr->name,nbr->length);
830
831
832 update_adjacent_timed_out_to_adl(nbr,1);
833 print_adjacent_from_adl();
834 int timed_out=get_timed_out_number(nbr);
835
836
837 if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables
838 {
839 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
840 send_info_interest_to_neighbor(nbr);
841 }
842 else
843 {
844 printf("Neighbor: %s Info Interest Timed Out: %d times\n",nbr->name,timed_out);
845 update_adjacent_status_to_adl(nbr,NBR_DOWN);
846 if(!nlsr->is_build_adj_lsa_sheduled)
847 {
848 nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0);
849 nlsr->is_build_adj_lsa_sheduled=1;
850 }
851 }
852
853 free(nbr);
854
855
856}
857
858int
859send_info_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
860{
861 printf("send_info_interest called \n");
862 printf("\n");
akmhoqued79438d2012-08-27 13:31:42 -0500863
akmhoque42098b12012-08-27 22:54:23 -0500864 my_lock();
akmhoque53f64222012-09-05 13:57:51 -0500865
866 int adl_element,i;
867
868 struct ndn_neighbor *nbr;
869
870 struct hashtb_enumerator ee;
871 struct hashtb_enumerator *e = &ee;
872
873 hashtb_start(nlsr->adl, e);
874 adl_element=hashtb_n(nlsr->adl);
875
876 for(i=0;i<adl_element;i++)
877 {
878 nbr=e->data;
879 send_info_interest_to_neighbor(nbr->neighbor);
880 hashtb_next(e);
881 }
882
883 hashtb_end(e);
884
885 my_unlock();
886
887 return 0;
888}
889
890void
891send_info_interest_to_neighbor(struct name_prefix *nbr)
892{
893 printf("send_info_interest_to_neighbor called \n");
akmhoqued79438d2012-08-27 13:31:42 -0500894
895 int res;
akmhoque53f64222012-09-05 13:57:51 -0500896 //int scope = 2; //no further than the next host
897
898 char info_str[5];
899 char nlsr_str[5];
900 long int rnum;
901 char rnumstr[20];
akmhoqued79438d2012-08-27 13:31:42 -0500902
903 rnum=random();
904 memset(&rnumstr,0,20);
905 sprintf(rnumstr,"%ld",rnum);
akmhoque53f64222012-09-05 13:57:51 -0500906
akmhoqued79438d2012-08-27 13:31:42 -0500907 memset(&nlsr_str,0,5);
908 sprintf(nlsr_str,"nlsr");
909 memset(&info_str,0,5);
910 sprintf(info_str,"info");
911
akmhoque53f64222012-09-05 13:57:51 -0500912
913 struct ccn_charbuf *name;
akmhoqued79438d2012-08-27 13:31:42 -0500914 name=ccn_charbuf_create();
akmhoqued79438d2012-08-27 13:31:42 -0500915
akmhoque53f64222012-09-05 13:57:51 -0500916 char *int_name=(char *)malloc(strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
917 memset(int_name,0,strlen(nbr->name)+1+strlen(nlsr_str)+1+strlen(info_str)+strlen(nlsr->router_name->name)+1);
918 memcpy(int_name+strlen(int_name),nbr->name,strlen(nbr->name));
919 memcpy(int_name+strlen(int_name),"/",1);
920 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
921 memcpy(int_name+strlen(int_name),"/",1);
922 memcpy(int_name+strlen(int_name),info_str,strlen(info_str));
923 memcpy(int_name+strlen(int_name),nlsr->router_name->name,strlen(nlsr->router_name->name));
924
925
926 res=ccn_name_from_uri(name,int_name);
927 if ( res >=0 )
928 {
929 ccn_name_append_str(name,rnumstr);
930
931 /* adding InterestLifeTime and InterestScope filter */
932
933 struct ccn_charbuf *templ;
934 templ = ccn_charbuf_create();
935
936 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
937 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
938 ccn_charbuf_append_closer(templ); /* </Name> */
939 //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
940 //ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
941 //ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
942 //ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
943 //ccn_charbuf_append_closer(templ); /* </Scope> */
944
945 appendLifetime(templ,nlsr->interest_resend_time);
946 ccn_charbuf_append_closer(templ); /* </Interest> */
947 /* Adding InterestLifeTime and InterestScope filter done */
948
949 printf("Sending info interest on name prefix : %s \n",int_name);
950
951 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
952
953 if ( res >= 0 )
954 printf("Info interest sending Successfull .... \n");
955 ccn_charbuf_destroy(&templ);
956 }
957 ccn_charbuf_destroy(&name);
958 free(int_name);
959
960}
961
962
963int
964send_lsdb_interest(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
965{
966 printf("send_lsdb_interest called \n");
967
968 my_lock();
969
970 int i, adl_element;
971 struct ndn_neighbor *nbr;
972
973 struct hashtb_enumerator ee;
974 struct hashtb_enumerator *e = &ee;
975
976 hashtb_start(nlsr->adl, e);
977 adl_element=hashtb_n(nlsr->adl);
978
979 for(i=0;i<adl_element;i++)
980 {
981 nbr=e->data;
982
983 if(nbr->status == NBR_ACTIVE)
984 {
985 if(nbr->is_lsdb_send_interest_scheduled == 0)
986 {
987 long int time_diff=get_nbr_time_diff_lsdb_req(nbr->neighbor->name);
988 printf("Time since last time LSDB requested : %ld Seconds for Neighbor: %s \n",time_diff,nbr->neighbor->name);
989
990 if(time_diff>=get_lsdb_synch_interval(nbr->neighbor->name))
991 {
992 nbr->is_lsdb_send_interest_scheduled=1;
993 send_lsdb_interest_to_nbr(nbr->neighbor);
994 }
995 }
996 }
997 hashtb_next(e);
998 }
999
1000 hashtb_end(e);
1001 nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 30000000, &send_lsdb_interest, NULL, 0);
1002
1003 my_unlock();
1004 return 0;
1005}
1006
1007void
1008send_lsdb_interest_to_nbr(struct name_prefix *nbr)
1009{
1010 printf("send_lsdb_interest_to_nbr called \n");
1011
1012 char *last_lsdb_version=get_nbr_lsdb_version(nbr->name);
1013
1014 if(last_lsdb_version !=NULL)
1015 {
1016 printf("Last LSDB Version: %s \n",last_lsdb_version);
1017
1018
1019 struct ccn_charbuf *name;
1020 int res;
1021 long int rnum;
1022 char rnumstr[20];
1023 char lsdb_str[5];
1024 char nlsr_str[5];
1025
1026 rnum=random();
1027 memset(&rnumstr,0,20);
1028 sprintf(rnumstr,"%ld",rnum);
1029 memset(&nlsr_str,0,5);
1030 sprintf(nlsr_str,"nlsr");
1031 memset(&lsdb_str,0,5);
1032 sprintf(lsdb_str,"lsdb");
1033 //make and send interest with exclusion filter as last_lsdb_version
1034 printf("Sending interest for name prefix:%s/%s/%s\n",nbr->name,nlsr_str,lsdb_str);
1035 name=ccn_charbuf_create();
1036 res=ccn_name_from_uri(name,nbr->name);
1037
1038 if( res >= 0)
1039 {
1040 ccn_name_append_str(name,nlsr_str);
1041 ccn_name_append_str(name,lsdb_str);
1042 ccn_name_append_str(name,rnumstr);
1043
1044 /* adding Exclusion filter */
1045
1046 struct ccn_charbuf *templ;
1047 templ = ccn_charbuf_create();
1048
1049 struct ccn_charbuf *c;
1050 c = ccn_charbuf_create();
1051
1052
1053 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1054 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1055 ccn_charbuf_append_closer(templ); /* </Name> */
1056 ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
1057 ccnb_tagged_putf(templ, CCN_DTAG_Any, "");
1058 ccn_charbuf_reset(c);
1059 ccn_charbuf_putf(c, "%s", last_lsdb_version);
1060 //ccn_charbuf_putf(c, "%u", (unsigned)nbr->last_lsdb_version);
1061 ccnb_append_tagged_blob(templ, CCN_DTAG_Component, c->buf, c->length);
1062 ccn_charbuf_append_closer(templ); /* </Exclude> */
1063 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1064 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1065 ccn_charbuf_append(templ, "2", 1);
1066 ccn_charbuf_append_closer(templ); /* </Scope> */
1067
1068 appendLifetime(templ,nlsr->interest_resend_time);
1069
1070 ccn_charbuf_append_closer(templ); /* </Interest> */
1071
akmhoqued79438d2012-08-27 13:31:42 -05001072
akmhoque53f64222012-09-05 13:57:51 -05001073 /* Adding Exclusion filter done */
1074
1075 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1076
1077 if ( res >= 0 )
1078 {
1079 printf("Interest sending Successfull .... \n");
1080 update_adjacent_last_lsdb_requested_to_adl(nbr->name,get_current_time_sec());
1081
1082 }
1083 ccn_charbuf_destroy(&c);
1084 ccn_charbuf_destroy(&templ);
1085 }
1086 ccn_charbuf_destroy(&name);
1087 }
1088 set_is_lsdb_send_interest_scheduled_to_zero(nbr->name);
1089
1090}
1091
1092void
1093send_interest_for_name_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type, char *ls_id)
1094{
1095 printf("send_interest_for_name_lsa called\n");
1096
1097 int res;
1098 long int rnum;
1099 char rnumstr[20];
1100 char lsa_str[5];
1101 char nlsr_str[5];
1102
1103
1104 rnum=random();
1105 memset(&rnumstr,0,20);
1106 sprintf(rnumstr,"%ld",rnum);
1107 memset(&nlsr_str,0,5);
1108 sprintf(nlsr_str,"nlsr");
1109 memset(&lsa_str,0,5);
1110 sprintf(lsa_str,"lsa");
1111
1112 char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
1113 memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
1114
1115 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1116 memcpy(int_name+strlen(int_name),"/",1);
1117 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1118 memcpy(int_name+strlen(int_name),"/",1);
1119 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
1120 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
1121
1122
1123 struct ccn_charbuf *name;
1124 name=ccn_charbuf_create();
1125
1126
1127 res=ccn_name_from_uri(name,int_name);
1128 ccn_name_append_str(name,ls_type);
1129 ccn_name_append_str(name,ls_id);
1130 ccn_name_append_str(name,rnumstr);
1131
1132
1133 /* adding InterestLifeTime and InterestScope filter */
1134
akmhoqued79438d2012-08-27 13:31:42 -05001135 struct ccn_charbuf *templ;
1136 templ = ccn_charbuf_create();
1137
akmhoqued79438d2012-08-27 13:31:42 -05001138 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1139 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1140 ccn_charbuf_append_closer(templ); /* </Name> */
akmhoque53f64222012-09-05 13:57:51 -05001141 //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
1142 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1143 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1144 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1145 ccn_charbuf_append_closer(templ); /* </Scope> */
1146
1147 appendLifetime(templ,nlsr->interest_resend_time);
akmhoqued79438d2012-08-27 13:31:42 -05001148 ccn_charbuf_append_closer(templ); /* </Interest> */
akmhoque53f64222012-09-05 13:57:51 -05001149 /* Adding InterestLifeTime and InterestScope filter done */
1150
1151 printf("Sending NAME LSA interest on name prefix : %s/%s/%s\n",int_name,ls_type,ls_id);
akmhoqued79438d2012-08-27 13:31:42 -05001152
akmhoqued79438d2012-08-27 13:31:42 -05001153 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
akmhoque53f64222012-09-05 13:57:51 -05001154
akmhoqued79438d2012-08-27 13:31:42 -05001155 if ( res >= 0 )
akmhoque53f64222012-09-05 13:57:51 -05001156 printf("NAME LSA interest sending Successfull .... \n");
1157
1158 //free(lsa_orig_router);
akmhoqued79438d2012-08-27 13:31:42 -05001159 ccn_charbuf_destroy(&templ);
1160 ccn_charbuf_destroy(&name);
akmhoque53f64222012-09-05 13:57:51 -05001161 free(int_name);
1162
1163
akmhoqued79438d2012-08-27 13:31:42 -05001164}
akmhoque53f64222012-09-05 13:57:51 -05001165
1166void
1167send_interest_for_adj_lsa(struct name_prefix *nbr, char *orig_router, char *ls_type)
1168{
1169 printf("send_interest_for_adj_lsa called\n");
1170
1171 int res;
1172 long int rnum;
1173 char rnumstr[20];
1174 char lsa_str[5];
1175 char nlsr_str[5];
1176
1177
1178 rnum=random();
1179 memset(&rnumstr,0,20);
1180 sprintf(rnumstr,"%ld",rnum);
1181 memset(&nlsr_str,0,5);
1182 sprintf(nlsr_str,"nlsr");
1183 memset(&lsa_str,0,5);
1184 sprintf(lsa_str,"lsa");
1185
1186 char *int_name=(char *)malloc(nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
1187 memset(int_name,0,nbr->length + strlen(orig_router)+strlen(nlsr_str)+strlen(lsa_str)+2);
1188
1189 memcpy(int_name+strlen(int_name),nbr->name,nbr->length);
1190 memcpy(int_name+strlen(int_name),"/",1);
1191 memcpy(int_name+strlen(int_name),nlsr_str,strlen(nlsr_str));
1192 memcpy(int_name+strlen(int_name),"/",1);
1193 memcpy(int_name+strlen(int_name),lsa_str,strlen(lsa_str));
1194 memcpy(int_name+strlen(int_name),orig_router,strlen(orig_router));
1195
1196
1197 struct ccn_charbuf *name;
1198 name=ccn_charbuf_create();
1199
1200
1201 ccn_name_from_uri(name,int_name);
1202 ccn_name_append_str(name,ls_type);
1203 ccn_name_append_str(name,rnumstr);
1204
1205 /* adding InterestLifeTime and InterestScope filter */
1206
1207 struct ccn_charbuf *templ;
1208 templ = ccn_charbuf_create();
1209
1210 ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
1211 ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
1212 ccn_charbuf_append_closer(templ); /* </Name> */
1213 //ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
1214 ccn_charbuf_append_tt(templ, CCN_DTAG_Scope, CCN_DTAG);
1215 ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
1216 ccn_charbuf_append(templ, "2", 1); //scope of interest: 2 (not further than next host)
1217 ccn_charbuf_append_closer(templ); /* </Scope> */
1218
1219 appendLifetime(templ,nlsr->interest_resend_time);
1220 ccn_charbuf_append_closer(templ); /* </Interest> */
1221 /* Adding InterestLifeTime and InterestScope filter done */
1222
1223 printf("Sending ADJ LSA interest on name prefix : %s/%s/%s%s/%s/\n",nbr->name,nlsr_str,lsa_str,orig_router,ls_type);
1224
1225 res=ccn_express_interest(nlsr->ccn,name,&(nlsr->in_content),templ);
1226
1227 if ( res >= 0 )
1228 printf("ADJ LSA interest sending Successfull .... \n");
1229
1230 //free(lsa_orig_router);
1231 ccn_charbuf_destroy(&templ);
1232 ccn_charbuf_destroy(&name);
1233 free(int_name);
1234
1235
1236}
1237