blob: 913e0c05dd1da8273e9c3c3442d0d129f1cf1739 [file] [log] [blame]
akmhoque8a5babe2012-08-16 17:39:33 -05001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
akmhoque9fa58a82012-10-05 07:56:02 -05004#include<math.h>
akmhoque8a5babe2012-08-16 17:39:33 -05005#include <unistd.h>
6#include <getopt.h>
7#include <sys/time.h>
8#include <assert.h>
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13
14#include <ccn/ccn.h>
15#include <ccn/uri.h>
16#include <ccn/keystore.h>
17#include <ccn/signing.h>
18#include <ccn/schedule.h>
19#include <ccn/hashtb.h>
20
21#include "nlsr.h"
akmhoque03004e62012-09-06 01:12:28 -050022#include "nlsr_npl.h"
akmhoque8a5babe2012-08-16 17:39:33 -050023#include "nlsr_adl.h"
akmhoque03004e62012-09-06 01:12:28 -050024#include "utility.h"
akmhoquefbfd0982012-09-09 20:59:03 -050025#include "nlsr_npt.h"
akmhoque8a5babe2012-08-16 17:39:33 -050026
akmhoque03004e62012-09-06 01:12:28 -050027void
28add_nbr_to_adl(struct name_prefix *new_nbr,int face)
akmhoque8a5babe2012-08-16 17:39:33 -050029{
akmhoque03004e62012-09-06 01:12:28 -050030 struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free
akmhoque53f64222012-09-05 13:57:51 -050031
akmhoque8a5babe2012-08-16 17:39:33 -050032 struct hashtb_enumerator ee;
33 struct hashtb_enumerator *e = &ee;
34 int res;
35
36 hashtb_start(nlsr->adl, e);
akmhoque03004e62012-09-06 01:12:28 -050037 res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0);
akmhoque2852a222012-08-21 12:09:00 -040038
akmhoquee7c4b6d2012-08-21 12:30:25 -040039 if(res == HT_NEW_ENTRY )
40 {
akmhoque8a5babe2012-08-16 17:39:33 -050041
akmhoque53f64222012-09-05 13:57:51 -050042 nbr = e->data;
akmhoque8a5babe2012-08-16 17:39:33 -050043
akmhoque03004e62012-09-06 01:12:28 -050044 nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free
45 nbr->neighbor->name=(char *)malloc(new_nbr->length);
46 memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length);
47 nbr->neighbor->length=new_nbr->length;
akmhoque53f64222012-09-05 13:57:51 -050048 nbr->face=face;
49 nbr->status=NBR_DOWN;
50 nbr->info_interest_timed_out=0;
akmhoque14b3f342012-09-14 10:39:02 -050051 nbr->lsdb_interest_timed_out=0;
52 nbr->lsdb_random_time_component=(int)(LSDB_SYNCH_INTERVAL/2);
53 nbr->lsdb_synch_interval=LSDB_SYNCH_INTERVAL;
54 nbr->metric=LINK_METRIC;
akmhoque53f64222012-09-05 13:57:51 -050055 nbr->is_lsdb_send_interest_scheduled=0;
56
akmhoque8a5babe2012-08-16 17:39:33 -050057
akmhoque03004e62012-09-06 01:12:28 -050058 char *time_stamp=(char *)malloc(20);
59 get_current_timestamp_micro(time_stamp);
60 nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -050061 memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
62 memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
akmhoque03004e62012-09-06 01:12:28 -050063 nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free
64 memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
65 memset(nbr->last_info_version,'0',strlen(time_stamp));
66 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050067
68 nbr->last_lsdb_requested=0;
akmhoquee7c4b6d2012-08-21 12:30:25 -040069 }
akmhoque53f64222012-09-05 13:57:51 -050070
akmhoque8a5babe2012-08-16 17:39:33 -050071 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -050072}
akmhoque8a5babe2012-08-16 17:39:33 -050073
akmhoque03004e62012-09-06 01:12:28 -050074
akmhoque53f64222012-09-05 13:57:51 -050075void
76print_adjacent(struct ndn_neighbor *nbr)
77{
akmhoque03004e62012-09-06 01:12:28 -050078 printf("print_adjacent called\n");
akmhoque53f64222012-09-05 13:57:51 -050079 printf("--------Neighbor---------------------------\n");
80 printf(" Neighbor: %s \n",nbr->neighbor->name);
81 printf(" Length : %d \n",nbr->neighbor->length);
82 printf(" Face : %d \n",nbr->face);
83 printf(" Metric : %d \n",nbr->metric);
84 printf(" Status : %d \n",nbr->status);
85 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
akmhoque03004e62012-09-06 01:12:28 -050086 printf(" Info Version: %s \n",nbr->last_info_version);
akmhoque53f64222012-09-05 13:57:51 -050087 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
akmhoque14b3f342012-09-14 10:39:02 -050088 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
akmhoque53f64222012-09-05 13:57:51 -050089 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
akmhoque14b3f342012-09-14 10:39:02 -050090 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
akmhoque53f64222012-09-05 13:57:51 -050091 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
akmhoque03004e62012-09-06 01:12:28 -050092 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
93
94 printf("\n");
akmhoque8a5babe2012-08-16 17:39:33 -050095
96}
97
98void
99print_adjacent_from_adl(void)
100{
akmhoque53f64222012-09-05 13:57:51 -0500101
akmhoque8a5babe2012-08-16 17:39:33 -0500102 printf("print_adjacent_from_adl called \n");
103 int i, adl_element;
104 struct ndn_neighbor *nbr;
105
106 struct hashtb_enumerator ee;
107 struct hashtb_enumerator *e = &ee;
108
109 hashtb_start(nlsr->adl, e);
110 adl_element=hashtb_n(nlsr->adl);
111
112 for(i=0;i<adl_element;i++)
113 {
114 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500115 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500116 hashtb_next(e);
117 }
118
119 hashtb_end(e);
120
akmhoque8a5babe2012-08-16 17:39:33 -0500121}
122
akmhoque03004e62012-09-06 01:12:28 -0500123int
124get_adjacent_status(struct name_prefix *nbr)
125{
126 printf("get_adjacent_status called \n");
127
128 int res;
129 int status=-1;
130 struct ndn_neighbor *nnbr;
131
132 struct hashtb_enumerator ee;
133 struct hashtb_enumerator *e = &ee;
134
135 hashtb_start(nlsr->adl, e);
136 res = hashtb_seek(e, nbr->name, nbr->length, 0);
137
138 if (res == HT_OLD_ENTRY)
139 {
140 nnbr=e->data;
141 status=nnbr->status;
142 }
143 else if(res == HT_NEW_ENTRY)
144 {
145 hashtb_delete(e);
146 }
147
148 hashtb_end(e);
149
150 return status;
151
152}
153
154int
155get_timed_out_number(struct name_prefix *nbr)
156{
157 printf("get_timed_out_number called \n");
158
159 int res,ret=-1;
160 struct ndn_neighbor *nnbr;
161
162 struct hashtb_enumerator ee;
163 struct hashtb_enumerator *e = &ee;
164
165 hashtb_start(nlsr->adl, e);
166 res = hashtb_seek(e, nbr->name, nbr->length, 0);
167
168 if( res == HT_OLD_ENTRY )
169 {
170 nnbr=e->data;
171 ret=nnbr->info_interest_timed_out;
172 }
173 else if(res == HT_NEW_ENTRY)
174 {
175 hashtb_delete(e);
176 }
177
178 hashtb_end(e);
179
180 return ret;
181}
182
akmhoque14b3f342012-09-14 10:39:02 -0500183int
184get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
185{
186 printf("get_timed_out_number called \n");
187
188 int res,ret=-1;
189 struct ndn_neighbor *nnbr;
190
191 struct hashtb_enumerator ee;
192 struct hashtb_enumerator *e = &ee;
193
194 hashtb_start(nlsr->adl, e);
195 res = hashtb_seek(e, nbr->name, nbr->length, 0);
196
197 if( res == HT_OLD_ENTRY )
198 {
199 nnbr=e->data;
200 ret=nnbr->lsdb_interest_timed_out;
201 }
202 else if(res == HT_NEW_ENTRY)
203 {
204 hashtb_delete(e);
205 }
206
207 hashtb_end(e);
208
209 return ret;
210}
akmhoque03004e62012-09-06 01:12:28 -0500211
212void
213update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
214{
215 printf("update_adjacent_timed_out_to_adl called \n");
216
217 int res;
218 struct ndn_neighbor *nnbr;
219
220 struct hashtb_enumerator ee;
221 struct hashtb_enumerator *e = &ee;
222
223 hashtb_start(nlsr->adl, e);
224 res = hashtb_seek(e, nbr->name, nbr->length, 0);
225
226 if( res == HT_OLD_ENTRY )
227 {
228 nnbr=e->data;
229 nnbr->info_interest_timed_out += increment;
230 }
231 else if(res == HT_NEW_ENTRY)
232 {
233 hashtb_delete(e);
234 }
235
236 hashtb_end(e);
237}
238
239void
240update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
241{
242 printf("update_adjacent_timed_out_zero_to_adl called \n");
243 int time_out_number=get_timed_out_number(nbr);
244 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
245
246}
247
akmhoque14b3f342012-09-14 10:39:02 -0500248
249void
250update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
251{
akmhoque62c0c192012-09-24 07:49:25 -0500252 printf("update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500253
254 int res;
255 struct ndn_neighbor *nnbr;
256
257 struct hashtb_enumerator ee;
258 struct hashtb_enumerator *e = &ee;
259
260 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500261
262 //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length);
263
akmhoque14b3f342012-09-14 10:39:02 -0500264 res = hashtb_seek(e, nbr->name, nbr->length, 0);
265
266 if( res == HT_OLD_ENTRY )
267 {
akmhoque62c0c192012-09-24 07:49:25 -0500268 //printf("Old Neighbor\n");
akmhoque14b3f342012-09-14 10:39:02 -0500269 nnbr=e->data;
270 nnbr->lsdb_interest_timed_out += increment;
akmhoque62c0c192012-09-24 07:49:25 -0500271 //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out);
akmhoque14b3f342012-09-14 10:39:02 -0500272 }
273 else if(res == HT_NEW_ENTRY)
274 {
275 hashtb_delete(e);
276 }
277
akmhoque62c0c192012-09-24 07:49:25 -0500278 //print_adjacent_from_adl();
akmhoque14b3f342012-09-14 10:39:02 -0500279 hashtb_end(e);
280}
281
282void
283update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
284{
285 printf("update_adjacent_timed_out_zero_to_adl called \n");
286 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
287 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
288
289}
290
akmhoque8a5babe2012-08-16 17:39:33 -0500291void
akmhoque53f64222012-09-05 13:57:51 -0500292update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500293{
294 printf("update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500295
akmhoque8a5babe2012-08-16 17:39:33 -0500296 int res;
297 struct ndn_neighbor *nnbr;
298
299 struct hashtb_enumerator ee;
300 struct hashtb_enumerator *e = &ee;
301
302 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500303 res = hashtb_seek(e, nbr->name, nbr->length, 0);
304
akmhoque918ff9a2012-08-21 11:34:49 -0400305
akmhoquee7c4b6d2012-08-21 12:30:25 -0400306 if (res == HT_OLD_ENTRY)
307 {
308 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500309 if ( nnbr->status!=status )
310 {
311 nnbr->status=status;
312 nlsr->adj_build_flag++;
313 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400314 }
akmhoqueb903ded2012-08-21 12:56:28 -0400315 else if(res == HT_NEW_ENTRY)
316 {
317 hashtb_delete(e);
318 }
akmhoque53f64222012-09-05 13:57:51 -0500319
akmhoque8a5babe2012-08-16 17:39:33 -0500320 hashtb_end(e);
321}
322
akmhoque8a5babe2012-08-16 17:39:33 -0500323void
akmhoque53f64222012-09-05 13:57:51 -0500324update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500325{
akmhoque53f64222012-09-05 13:57:51 -0500326 printf("uupdate_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500327
328 int res;
329 struct ndn_neighbor *nnbr;
330
331 struct hashtb_enumerator ee;
332 struct hashtb_enumerator *e = &ee;
333
334 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500335 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500336
akmhoque53f64222012-09-05 13:57:51 -0500337
338 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400339 {
340 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500341 if ( nnbr->lsdb_synch_interval!= interval )
342 {
343 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500344 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500345
akmhoque53f64222012-09-05 13:57:51 -0500346 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400347 }
akmhoqueb903ded2012-08-21 12:56:28 -0400348 else if(res == HT_NEW_ENTRY)
349 {
350 hashtb_delete(e);
351 }
akmhoque53f64222012-09-05 13:57:51 -0500352
akmhoque8a5babe2012-08-16 17:39:33 -0500353 hashtb_end(e);
354}
akmhoqued79438d2012-08-27 13:31:42 -0500355
akmhoque53f64222012-09-05 13:57:51 -0500356
akmhoque53f64222012-09-05 13:57:51 -0500357int
akmhoque03004e62012-09-06 01:12:28 -0500358no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500359{
akmhoque03004e62012-09-06 01:12:28 -0500360 int i, adl_element;
361 int no_link=0;
362 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500363 struct hashtb_enumerator ee;
364 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500365 hashtb_start(nlsr->adl, e);
366 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500367
akmhoque03004e62012-09-06 01:12:28 -0500368 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500369 {
akmhoque03004e62012-09-06 01:12:28 -0500370 nbr=e->data;
371 if( nbr->status == 1 )
372 no_link++;
373 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500374 }
akmhoque53f64222012-09-05 13:57:51 -0500375
akmhoqued79438d2012-08-27 13:31:42 -0500376 hashtb_end(e);
377
akmhoque03004e62012-09-06 01:12:28 -0500378 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500379
akmhoqued79438d2012-08-27 13:31:42 -0500380}
akmhoque53f64222012-09-05 13:57:51 -0500381
382int
383is_adj_lsa_build(void)
384{
385 int ret=0;
386
387 int nbr_count=0;
388
389 int i, adl_element;
390 struct ndn_neighbor *nbr;
391
392 struct hashtb_enumerator ee;
393 struct hashtb_enumerator *e = &ee;
394
395 hashtb_start(nlsr->adl, e);
396 adl_element=hashtb_n(nlsr->adl);
397
398 for(i=0;i<adl_element;i++)
399 {
400 nbr=e->data;
401 if(nbr->status == 1 )
402 {
403 nbr_count++;
404 }
akmhoque62c0c192012-09-24 07:49:25 -0500405 else if ( (nbr->status == 0) && (nbr->info_interest_timed_out >= nlsr->interest_retry || nbr->lsdb_interest_timed_out >= nlsr->interest_retry))
akmhoque53f64222012-09-05 13:57:51 -0500406 {
407 nbr_count++;
408 }
409 hashtb_next(e);
410 }
411
412 hashtb_end(e);
413 if(nbr_count == adl_element)
414 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500415
akmhoque53f64222012-09-05 13:57:51 -0500416 return ret;
417}
418
akmhoque53f64222012-09-05 13:57:51 -0500419
420void
421get_active_nbr_adj_data(struct ccn_charbuf *c)
422{
423
424 int i, adl_element;
425 struct ndn_neighbor *nbr;
426 struct hashtb_enumerator ee;
427 struct hashtb_enumerator *e = &ee;
428 hashtb_start(nlsr->adl, e);
429 adl_element=hashtb_n(nlsr->adl);
430
431 for(i=0;i<adl_element;i++)
432 {
433 nbr=e->data;
434 if( nbr->status == 1 )
435 {
436 ccn_charbuf_append_string(c,nbr->neighbor->name);
437 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500438
akmhoque53f64222012-09-05 13:57:51 -0500439 char *temp_length=(char *)malloc(20);
440 memset(temp_length,0,20);
441 sprintf(temp_length,"%d",nbr->neighbor->length);
442 ccn_charbuf_append_string(c,temp_length);
443 free(temp_length);
444 ccn_charbuf_append_string(c,"|");
445
446 char *temp_face=(char *)malloc(20);
447 memset(temp_face,0,20);
448 sprintf(temp_face,"%d",nbr->face);
449 ccn_charbuf_append_string(c,temp_face);
450 free(temp_face);
451 ccn_charbuf_append_string(c,"|");
452
453 char *temp_metric=(char *)malloc(20);
454 memset(temp_metric,0,20);
455 sprintf(temp_metric,"%d",nbr->metric);
456 ccn_charbuf_append_string(c,temp_metric);
457 free(temp_metric);
458 ccn_charbuf_append_string(c,"|");
459
460 }
461 hashtb_next(e);
462 }
463
464 hashtb_end(e);
465}
466
akmhoque03004e62012-09-06 01:12:28 -0500467long int
468get_nbr_time_diff_lsdb_req(char *nbr)
469{
470 printf("get_nbr_time_diff_lsdb_req called \n");
471
472 long int time_diff=get_lsdb_synch_interval(nbr)+1;
473 int res;
474 struct ndn_neighbor *nnbr;
475
476 struct hashtb_enumerator ee;
477 struct hashtb_enumerator *e = &ee;
478
479 hashtb_start(nlsr->adl, e);
480 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
481
482 if (res == HT_OLD_ENTRY)
483 {
484 nnbr=e->data;
485
486 if (nnbr->last_lsdb_requested == 0)
487 time_diff=get_lsdb_synch_interval(nbr)+1;
488 else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
489
490 }
491 else if(res == HT_NEW_ENTRY)
492 {
493 hashtb_delete(e);
494 }
495
496 hashtb_end(e);
497
498 return time_diff;
499}
500
501long int
502get_nbr_last_lsdb_requested(char *nbr)
503{
504 printf("get_timed_out_number called \n");
505
506 long int last_lsdb_requested=0;
507
508 int res;
509 struct ndn_neighbor *nnbr;
510
511 struct hashtb_enumerator ee;
512 struct hashtb_enumerator *e = &ee;
513
514 hashtb_start(nlsr->adl, e);
515 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
516
517 if (res == HT_OLD_ENTRY)
518 {
519 nnbr=e->data;
520 last_lsdb_requested=nnbr->last_lsdb_requested;
521 }
522 else if(res == HT_NEW_ENTRY)
523 {
524 hashtb_delete(e);
525 }
526
527 hashtb_end(e);
528
529 return last_lsdb_requested;
530}
531
akmhoque14b3f342012-09-14 10:39:02 -0500532
533int
534get_nbr_random_time_component(char *nbr)
535{
536 printf("get_timed_out_number called \n");
537
538 int time=0;
539
540 int res;
541 struct ndn_neighbor *nnbr;
542
543 struct hashtb_enumerator ee;
544 struct hashtb_enumerator *e = &ee;
545
546 hashtb_start(nlsr->adl, e);
547 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
548
549 if (res == HT_OLD_ENTRY)
550 {
551 nnbr=e->data;
akmhoque9fa58a82012-10-05 07:56:02 -0500552 time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1);
akmhoque14b3f342012-09-14 10:39:02 -0500553 }
554 else if(res == HT_NEW_ENTRY)
555 {
556 hashtb_delete(e);
557 }
558
559 hashtb_end(e);
560
561 return time;
562}
563
akmhoque03004e62012-09-06 01:12:28 -0500564long int
565get_lsdb_synch_interval(char *nbr)
566{
567 printf("get_lsdb_synch_interval called \n");
568
569 long int lsdb_synch_interval=300;
570
571
572 int res;
573 struct ndn_neighbor *nnbr;
574
575 struct hashtb_enumerator ee;
576 struct hashtb_enumerator *e = &ee;
577
578 hashtb_start(nlsr->adl, e);
579 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
580
581 if (res == HT_OLD_ENTRY)
582 {
583 nnbr=e->data;
584 lsdb_synch_interval=nnbr->lsdb_synch_interval;
585 }
586 else if(res == HT_NEW_ENTRY)
587 {
588 hashtb_delete(e);
589 }
590
591 hashtb_end(e);
592
593 return lsdb_synch_interval;
594
595}
596
akmhoque53f64222012-09-05 13:57:51 -0500597char *
598get_nbr_lsdb_version(char *nbr)
599{
600 printf("get_timed_out_number called \n");
601
602 char *version=NULL;
603
604 int res;
605 struct ndn_neighbor *nnbr;
606
607 struct hashtb_enumerator ee;
608 struct hashtb_enumerator *e = &ee;
609
610 hashtb_start(nlsr->adl, e);
611 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
akmhoque03004e62012-09-06 01:12:28 -0500612
akmhoque53f64222012-09-05 13:57:51 -0500613 if (res == HT_OLD_ENTRY)
614 {
615 nnbr=e->data;
616 version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
617 memset(version,0,strlen(nnbr->last_lsdb_version)+1);
618 memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
619 }
620 else if(res == HT_NEW_ENTRY)
621 {
622 hashtb_delete(e);
623 }
624
625 hashtb_end(e);
626
627 return version;
628}
629
630void
631update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
632{
633 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
634
635 int res;
636 struct ndn_neighbor *nnbr;
637
638 struct hashtb_enumerator ee;
639 struct hashtb_enumerator *e = &ee;
640
641 hashtb_start(nlsr->adl, e);
642 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
643
644 if( res == HT_OLD_ENTRY )
645 {
646 nnbr=e->data;
647 nnbr->last_lsdb_requested=timestamp;
akmhoque03004e62012-09-06 01:12:28 -0500648
649 }
650 else if(res == HT_NEW_ENTRY)
651 {
652 hashtb_delete(e);
653 }
654
655 hashtb_end(e);
656}
657
658void
659set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
660{
661 printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
662
663 int res;
664 struct ndn_neighbor *nnbr;
665
666 struct hashtb_enumerator ee;
667 struct hashtb_enumerator *e = &ee;
668
669 hashtb_start(nlsr->adl, e);
670 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
671
672 if (res == HT_OLD_ENTRY)
673 {
674 nnbr=e->data;
675 nnbr->is_lsdb_send_interest_scheduled=0;
676 }
677 else if(res == HT_NEW_ENTRY)
678 {
679 hashtb_delete(e);
680 }
681
682 hashtb_end(e);
683}
684
685void
686update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
687{
688 printf("update_adjacent_timed_out_to_adl called \n");
689
690 int res;
691 struct ndn_neighbor *nnbr;
692
693 struct hashtb_enumerator ee;
694 struct hashtb_enumerator *e = &ee;
695
696 hashtb_start(nlsr->adl, e);
697 res = hashtb_seek(e, nbr->name, nbr->length, 0);
698
699 if( res == HT_OLD_ENTRY )
700 {
701 nnbr=e->data;
702 free(nnbr->last_lsdb_version);
703 nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
704 memset(nnbr->last_lsdb_version,0,strlen(version)+1);
705 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoque53f64222012-09-05 13:57:51 -0500706 }
707 else if(res == HT_NEW_ENTRY)
708 {
709 hashtb_delete(e);
710 }
711
712 hashtb_end(e);
713
714}
715
716void
717adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
718{
719 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
720
721 int res;
722 struct ndn_neighbor *nnbr;
723
724 struct hashtb_enumerator ee;
725 struct hashtb_enumerator *e = &ee;
726
727 hashtb_start(nlsr->adl, e);
728 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
729
730 if( res == HT_OLD_ENTRY )
731 {
732 nnbr=e->data;
733 nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
akmhoque03004e62012-09-06 01:12:28 -0500734
akmhoque53f64222012-09-05 13:57:51 -0500735 }
736 else if(res == HT_NEW_ENTRY)
737 {
738 hashtb_delete(e);
739 }
740
741 hashtb_end(e);
742
743}
744
akmhoquefbfd0982012-09-09 20:59:03 -0500745int
746get_next_hop_face_from_adl(char *nbr)
747{
748 int res;
749 int connecting_face=NO_FACE;
750 struct ndn_neighbor *nnbr;
751
752 struct hashtb_enumerator ee;
753 struct hashtb_enumerator *e = &ee;
754
755 hashtb_start(nlsr->adl, e);
756 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
757
758 if( res == HT_OLD_ENTRY )
759 {
760 nnbr=e->data;
761 connecting_face=nnbr->face;
762
763 }
764 else if(res == HT_NEW_ENTRY)
765 {
766 hashtb_delete(e);
767 }
768
769 hashtb_end(e);
770 return connecting_face;
771}
772
akmhoquede61ba92012-09-20 22:19:12 -0500773int
774is_neighbor(char *nbr)
775{
776 int ret=0;
777
778 int res;
779 struct hashtb_enumerator ee;
780 struct hashtb_enumerator *e = &ee;
781
782 hashtb_start(nlsr->adl, e);
783 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
784
785 if( res == HT_OLD_ENTRY )
786 {
787 ret=1;
788 }
789 else if(res == HT_NEW_ENTRY)
790 {
791 hashtb_delete(e);
792 }
793
794 hashtb_end(e);
795
796 return ret;
797}
akmhoque53f64222012-09-05 13:57:51 -0500798