blob: 1184cb620309ae09581d5722197f1cef7a57f62f [file] [log] [blame]
akmhoque8a5babe2012-08-16 17:39:33 -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>
19
20#include "nlsr.h"
akmhoque03004e62012-09-06 01:12:28 -050021#include "nlsr_npl.h"
akmhoque8a5babe2012-08-16 17:39:33 -050022#include "nlsr_adl.h"
akmhoque03004e62012-09-06 01:12:28 -050023#include "utility.h"
akmhoquefbfd0982012-09-09 20:59:03 -050024#include "nlsr_npt.h"
akmhoque8a5babe2012-08-16 17:39:33 -050025
akmhoque03004e62012-09-06 01:12:28 -050026void
27add_nbr_to_adl(struct name_prefix *new_nbr,int face)
akmhoque8a5babe2012-08-16 17:39:33 -050028{
akmhoque03004e62012-09-06 01:12:28 -050029 struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free
akmhoque53f64222012-09-05 13:57:51 -050030
akmhoque8a5babe2012-08-16 17:39:33 -050031 struct hashtb_enumerator ee;
32 struct hashtb_enumerator *e = &ee;
33 int res;
34
35 hashtb_start(nlsr->adl, e);
akmhoque03004e62012-09-06 01:12:28 -050036 res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0);
akmhoque2852a222012-08-21 12:09:00 -040037
akmhoquee7c4b6d2012-08-21 12:30:25 -040038 if(res == HT_NEW_ENTRY )
39 {
akmhoque8a5babe2012-08-16 17:39:33 -050040
akmhoque53f64222012-09-05 13:57:51 -050041 nbr = e->data;
akmhoque8a5babe2012-08-16 17:39:33 -050042
akmhoque03004e62012-09-06 01:12:28 -050043 nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free
44 nbr->neighbor->name=(char *)malloc(new_nbr->length);
45 memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length);
46 nbr->neighbor->length=new_nbr->length;
akmhoque53f64222012-09-05 13:57:51 -050047 nbr->face=face;
48 nbr->status=NBR_DOWN;
49 nbr->info_interest_timed_out=0;
akmhoque14b3f342012-09-14 10:39:02 -050050 nbr->lsdb_interest_timed_out=0;
51 nbr->lsdb_random_time_component=(int)(LSDB_SYNCH_INTERVAL/2);
52 nbr->lsdb_synch_interval=LSDB_SYNCH_INTERVAL;
53 nbr->metric=LINK_METRIC;
akmhoque53f64222012-09-05 13:57:51 -050054 nbr->is_lsdb_send_interest_scheduled=0;
55
akmhoque8a5babe2012-08-16 17:39:33 -050056
akmhoque03004e62012-09-06 01:12:28 -050057 char *time_stamp=(char *)malloc(20);
58 get_current_timestamp_micro(time_stamp);
59 nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -050060 memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
61 memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
akmhoque03004e62012-09-06 01:12:28 -050062 nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free
63 memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
64 memset(nbr->last_info_version,'0',strlen(time_stamp));
65 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050066
67 nbr->last_lsdb_requested=0;
akmhoquee7c4b6d2012-08-21 12:30:25 -040068 }
akmhoque53f64222012-09-05 13:57:51 -050069
akmhoque8a5babe2012-08-16 17:39:33 -050070 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -050071}
akmhoque8a5babe2012-08-16 17:39:33 -050072
akmhoque03004e62012-09-06 01:12:28 -050073
akmhoque53f64222012-09-05 13:57:51 -050074void
75print_adjacent(struct ndn_neighbor *nbr)
76{
akmhoque03004e62012-09-06 01:12:28 -050077 printf("print_adjacent called\n");
akmhoque53f64222012-09-05 13:57:51 -050078 printf("--------Neighbor---------------------------\n");
79 printf(" Neighbor: %s \n",nbr->neighbor->name);
80 printf(" Length : %d \n",nbr->neighbor->length);
81 printf(" Face : %d \n",nbr->face);
82 printf(" Metric : %d \n",nbr->metric);
83 printf(" Status : %d \n",nbr->status);
84 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
akmhoque03004e62012-09-06 01:12:28 -050085 printf(" Info Version: %s \n",nbr->last_info_version);
akmhoque53f64222012-09-05 13:57:51 -050086 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
akmhoque14b3f342012-09-14 10:39:02 -050087 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
akmhoque53f64222012-09-05 13:57:51 -050088 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
akmhoque14b3f342012-09-14 10:39:02 -050089 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
akmhoque53f64222012-09-05 13:57:51 -050090 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
akmhoque03004e62012-09-06 01:12:28 -050091 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
92
93 printf("\n");
akmhoque8a5babe2012-08-16 17:39:33 -050094
95}
96
97void
98print_adjacent_from_adl(void)
99{
akmhoque53f64222012-09-05 13:57:51 -0500100
akmhoque8a5babe2012-08-16 17:39:33 -0500101 printf("print_adjacent_from_adl called \n");
102 int i, adl_element;
103 struct ndn_neighbor *nbr;
104
105 struct hashtb_enumerator ee;
106 struct hashtb_enumerator *e = &ee;
107
108 hashtb_start(nlsr->adl, e);
109 adl_element=hashtb_n(nlsr->adl);
110
111 for(i=0;i<adl_element;i++)
112 {
113 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500114 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500115 hashtb_next(e);
116 }
117
118 hashtb_end(e);
119
akmhoque8a5babe2012-08-16 17:39:33 -0500120}
121
akmhoque03004e62012-09-06 01:12:28 -0500122int
123get_adjacent_status(struct name_prefix *nbr)
124{
125 printf("get_adjacent_status called \n");
126
127 int res;
128 int status=-1;
129 struct ndn_neighbor *nnbr;
130
131 struct hashtb_enumerator ee;
132 struct hashtb_enumerator *e = &ee;
133
134 hashtb_start(nlsr->adl, e);
135 res = hashtb_seek(e, nbr->name, nbr->length, 0);
136
137 if (res == HT_OLD_ENTRY)
138 {
139 nnbr=e->data;
140 status=nnbr->status;
141 }
142 else if(res == HT_NEW_ENTRY)
143 {
144 hashtb_delete(e);
145 }
146
147 hashtb_end(e);
148
149 return status;
150
151}
152
153int
154get_timed_out_number(struct name_prefix *nbr)
155{
156 printf("get_timed_out_number called \n");
157
158 int res,ret=-1;
159 struct ndn_neighbor *nnbr;
160
161 struct hashtb_enumerator ee;
162 struct hashtb_enumerator *e = &ee;
163
164 hashtb_start(nlsr->adl, e);
165 res = hashtb_seek(e, nbr->name, nbr->length, 0);
166
167 if( res == HT_OLD_ENTRY )
168 {
169 nnbr=e->data;
170 ret=nnbr->info_interest_timed_out;
171 }
172 else if(res == HT_NEW_ENTRY)
173 {
174 hashtb_delete(e);
175 }
176
177 hashtb_end(e);
178
179 return ret;
180}
181
akmhoque14b3f342012-09-14 10:39:02 -0500182int
183get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
184{
185 printf("get_timed_out_number called \n");
186
187 int res,ret=-1;
188 struct ndn_neighbor *nnbr;
189
190 struct hashtb_enumerator ee;
191 struct hashtb_enumerator *e = &ee;
192
193 hashtb_start(nlsr->adl, e);
194 res = hashtb_seek(e, nbr->name, nbr->length, 0);
195
196 if( res == HT_OLD_ENTRY )
197 {
198 nnbr=e->data;
199 ret=nnbr->lsdb_interest_timed_out;
200 }
201 else if(res == HT_NEW_ENTRY)
202 {
203 hashtb_delete(e);
204 }
205
206 hashtb_end(e);
207
208 return ret;
209}
akmhoque03004e62012-09-06 01:12:28 -0500210
211void
212update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
213{
214 printf("update_adjacent_timed_out_to_adl called \n");
215
216 int res;
217 struct ndn_neighbor *nnbr;
218
219 struct hashtb_enumerator ee;
220 struct hashtb_enumerator *e = &ee;
221
222 hashtb_start(nlsr->adl, e);
223 res = hashtb_seek(e, nbr->name, nbr->length, 0);
224
225 if( res == HT_OLD_ENTRY )
226 {
227 nnbr=e->data;
228 nnbr->info_interest_timed_out += increment;
229 }
230 else if(res == HT_NEW_ENTRY)
231 {
232 hashtb_delete(e);
233 }
234
235 hashtb_end(e);
236}
237
238void
239update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
240{
241 printf("update_adjacent_timed_out_zero_to_adl called \n");
242 int time_out_number=get_timed_out_number(nbr);
243 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
244
245}
246
akmhoque14b3f342012-09-14 10:39:02 -0500247
248void
249update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
250{
akmhoque62c0c192012-09-24 07:49:25 -0500251 printf("update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500252
253 int res;
254 struct ndn_neighbor *nnbr;
255
256 struct hashtb_enumerator ee;
257 struct hashtb_enumerator *e = &ee;
258
259 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500260
261 //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length);
262
akmhoque14b3f342012-09-14 10:39:02 -0500263 res = hashtb_seek(e, nbr->name, nbr->length, 0);
264
265 if( res == HT_OLD_ENTRY )
266 {
akmhoque62c0c192012-09-24 07:49:25 -0500267 //printf("Old Neighbor\n");
akmhoque14b3f342012-09-14 10:39:02 -0500268 nnbr=e->data;
269 nnbr->lsdb_interest_timed_out += increment;
akmhoque62c0c192012-09-24 07:49:25 -0500270 //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out);
akmhoque14b3f342012-09-14 10:39:02 -0500271 }
272 else if(res == HT_NEW_ENTRY)
273 {
274 hashtb_delete(e);
275 }
276
akmhoque62c0c192012-09-24 07:49:25 -0500277 //print_adjacent_from_adl();
akmhoque14b3f342012-09-14 10:39:02 -0500278 hashtb_end(e);
279}
280
281void
282update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
283{
284 printf("update_adjacent_timed_out_zero_to_adl called \n");
285 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
286 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
287
288}
289
akmhoque8a5babe2012-08-16 17:39:33 -0500290void
akmhoque53f64222012-09-05 13:57:51 -0500291update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500292{
293 printf("update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500294
akmhoque8a5babe2012-08-16 17:39:33 -0500295 int res;
296 struct ndn_neighbor *nnbr;
297
298 struct hashtb_enumerator ee;
299 struct hashtb_enumerator *e = &ee;
300
301 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500302 res = hashtb_seek(e, nbr->name, nbr->length, 0);
303
akmhoque918ff9a2012-08-21 11:34:49 -0400304
akmhoquee7c4b6d2012-08-21 12:30:25 -0400305 if (res == HT_OLD_ENTRY)
306 {
307 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500308 if ( nnbr->status!=status )
309 {
310 nnbr->status=status;
311 nlsr->adj_build_flag++;
312 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400313 }
akmhoqueb903ded2012-08-21 12:56:28 -0400314 else if(res == HT_NEW_ENTRY)
315 {
316 hashtb_delete(e);
317 }
akmhoque53f64222012-09-05 13:57:51 -0500318
akmhoque8a5babe2012-08-16 17:39:33 -0500319 hashtb_end(e);
320}
321
akmhoque8a5babe2012-08-16 17:39:33 -0500322void
akmhoque53f64222012-09-05 13:57:51 -0500323update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500324{
akmhoque53f64222012-09-05 13:57:51 -0500325 printf("uupdate_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500326
327 int res;
328 struct ndn_neighbor *nnbr;
329
330 struct hashtb_enumerator ee;
331 struct hashtb_enumerator *e = &ee;
332
333 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500334 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500335
akmhoque53f64222012-09-05 13:57:51 -0500336
337 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400338 {
339 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500340 if ( nnbr->lsdb_synch_interval!= interval )
341 {
342 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500343 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500344
akmhoque53f64222012-09-05 13:57:51 -0500345 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400346 }
akmhoqueb903ded2012-08-21 12:56:28 -0400347 else if(res == HT_NEW_ENTRY)
348 {
349 hashtb_delete(e);
350 }
akmhoque53f64222012-09-05 13:57:51 -0500351
akmhoque8a5babe2012-08-16 17:39:33 -0500352 hashtb_end(e);
353}
akmhoqued79438d2012-08-27 13:31:42 -0500354
akmhoque53f64222012-09-05 13:57:51 -0500355
akmhoque53f64222012-09-05 13:57:51 -0500356int
akmhoque03004e62012-09-06 01:12:28 -0500357no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500358{
akmhoque03004e62012-09-06 01:12:28 -0500359 int i, adl_element;
360 int no_link=0;
361 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500362 struct hashtb_enumerator ee;
363 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500364 hashtb_start(nlsr->adl, e);
365 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500366
akmhoque03004e62012-09-06 01:12:28 -0500367 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500368 {
akmhoque03004e62012-09-06 01:12:28 -0500369 nbr=e->data;
370 if( nbr->status == 1 )
371 no_link++;
372 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500373 }
akmhoque53f64222012-09-05 13:57:51 -0500374
akmhoqued79438d2012-08-27 13:31:42 -0500375 hashtb_end(e);
376
akmhoque03004e62012-09-06 01:12:28 -0500377 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500378
akmhoqued79438d2012-08-27 13:31:42 -0500379}
akmhoque53f64222012-09-05 13:57:51 -0500380
381int
382is_adj_lsa_build(void)
383{
384 int ret=0;
385
386 int nbr_count=0;
387
388 int i, adl_element;
389 struct ndn_neighbor *nbr;
390
391 struct hashtb_enumerator ee;
392 struct hashtb_enumerator *e = &ee;
393
394 hashtb_start(nlsr->adl, e);
395 adl_element=hashtb_n(nlsr->adl);
396
397 for(i=0;i<adl_element;i++)
398 {
399 nbr=e->data;
400 if(nbr->status == 1 )
401 {
402 nbr_count++;
403 }
akmhoque62c0c192012-09-24 07:49:25 -0500404 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 -0500405 {
406 nbr_count++;
407 }
408 hashtb_next(e);
409 }
410
411 hashtb_end(e);
412 if(nbr_count == adl_element)
413 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500414
akmhoque53f64222012-09-05 13:57:51 -0500415 return ret;
416}
417
akmhoque53f64222012-09-05 13:57:51 -0500418
419void
420get_active_nbr_adj_data(struct ccn_charbuf *c)
421{
422
423 int i, adl_element;
424 struct ndn_neighbor *nbr;
425 struct hashtb_enumerator ee;
426 struct hashtb_enumerator *e = &ee;
427 hashtb_start(nlsr->adl, e);
428 adl_element=hashtb_n(nlsr->adl);
429
430 for(i=0;i<adl_element;i++)
431 {
432 nbr=e->data;
433 if( nbr->status == 1 )
434 {
435 ccn_charbuf_append_string(c,nbr->neighbor->name);
436 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500437
akmhoque53f64222012-09-05 13:57:51 -0500438 char *temp_length=(char *)malloc(20);
439 memset(temp_length,0,20);
440 sprintf(temp_length,"%d",nbr->neighbor->length);
441 ccn_charbuf_append_string(c,temp_length);
442 free(temp_length);
443 ccn_charbuf_append_string(c,"|");
444
445 char *temp_face=(char *)malloc(20);
446 memset(temp_face,0,20);
447 sprintf(temp_face,"%d",nbr->face);
448 ccn_charbuf_append_string(c,temp_face);
449 free(temp_face);
450 ccn_charbuf_append_string(c,"|");
451
452 char *temp_metric=(char *)malloc(20);
453 memset(temp_metric,0,20);
454 sprintf(temp_metric,"%d",nbr->metric);
455 ccn_charbuf_append_string(c,temp_metric);
456 free(temp_metric);
457 ccn_charbuf_append_string(c,"|");
458
459 }
460 hashtb_next(e);
461 }
462
463 hashtb_end(e);
464}
465
akmhoque03004e62012-09-06 01:12:28 -0500466long int
467get_nbr_time_diff_lsdb_req(char *nbr)
468{
469 printf("get_nbr_time_diff_lsdb_req called \n");
470
471 long int time_diff=get_lsdb_synch_interval(nbr)+1;
472 int res;
473 struct ndn_neighbor *nnbr;
474
475 struct hashtb_enumerator ee;
476 struct hashtb_enumerator *e = &ee;
477
478 hashtb_start(nlsr->adl, e);
479 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
480
481 if (res == HT_OLD_ENTRY)
482 {
483 nnbr=e->data;
484
485 if (nnbr->last_lsdb_requested == 0)
486 time_diff=get_lsdb_synch_interval(nbr)+1;
487 else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
488
489 }
490 else if(res == HT_NEW_ENTRY)
491 {
492 hashtb_delete(e);
493 }
494
495 hashtb_end(e);
496
497 return time_diff;
498}
499
500long int
501get_nbr_last_lsdb_requested(char *nbr)
502{
503 printf("get_timed_out_number called \n");
504
505 long int last_lsdb_requested=0;
506
507 int res;
508 struct ndn_neighbor *nnbr;
509
510 struct hashtb_enumerator ee;
511 struct hashtb_enumerator *e = &ee;
512
513 hashtb_start(nlsr->adl, e);
514 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
515
516 if (res == HT_OLD_ENTRY)
517 {
518 nnbr=e->data;
519 last_lsdb_requested=nnbr->last_lsdb_requested;
520 }
521 else if(res == HT_NEW_ENTRY)
522 {
523 hashtb_delete(e);
524 }
525
526 hashtb_end(e);
527
528 return last_lsdb_requested;
529}
530
akmhoque14b3f342012-09-14 10:39:02 -0500531
532int
533get_nbr_random_time_component(char *nbr)
534{
535 printf("get_timed_out_number called \n");
536
537 int time=0;
538
539 int res;
540 struct ndn_neighbor *nnbr;
541
542 struct hashtb_enumerator ee;
543 struct hashtb_enumerator *e = &ee;
544
545 hashtb_start(nlsr->adl, e);
546 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
547
548 if (res == HT_OLD_ENTRY)
549 {
550 nnbr=e->data;
551 time=nnbr->lsdb_random_time_component * nnbr->lsdb_interest_timed_out;
552 }
553 else if(res == HT_NEW_ENTRY)
554 {
555 hashtb_delete(e);
556 }
557
558 hashtb_end(e);
559
560 return time;
561}
562
akmhoque03004e62012-09-06 01:12:28 -0500563long int
564get_lsdb_synch_interval(char *nbr)
565{
566 printf("get_lsdb_synch_interval called \n");
567
568 long int lsdb_synch_interval=300;
569
570
571 int res;
572 struct ndn_neighbor *nnbr;
573
574 struct hashtb_enumerator ee;
575 struct hashtb_enumerator *e = &ee;
576
577 hashtb_start(nlsr->adl, e);
578 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
579
580 if (res == HT_OLD_ENTRY)
581 {
582 nnbr=e->data;
583 lsdb_synch_interval=nnbr->lsdb_synch_interval;
584 }
585 else if(res == HT_NEW_ENTRY)
586 {
587 hashtb_delete(e);
588 }
589
590 hashtb_end(e);
591
592 return lsdb_synch_interval;
593
594}
595
akmhoque53f64222012-09-05 13:57:51 -0500596char *
597get_nbr_lsdb_version(char *nbr)
598{
599 printf("get_timed_out_number called \n");
600
601 char *version=NULL;
602
603 int res;
604 struct ndn_neighbor *nnbr;
605
606 struct hashtb_enumerator ee;
607 struct hashtb_enumerator *e = &ee;
608
609 hashtb_start(nlsr->adl, e);
610 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
akmhoque03004e62012-09-06 01:12:28 -0500611
akmhoque53f64222012-09-05 13:57:51 -0500612 if (res == HT_OLD_ENTRY)
613 {
614 nnbr=e->data;
615 version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
616 memset(version,0,strlen(nnbr->last_lsdb_version)+1);
617 memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
618 }
619 else if(res == HT_NEW_ENTRY)
620 {
621 hashtb_delete(e);
622 }
623
624 hashtb_end(e);
625
626 return version;
627}
628
629void
630update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
631{
632 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
633
634 int res;
635 struct ndn_neighbor *nnbr;
636
637 struct hashtb_enumerator ee;
638 struct hashtb_enumerator *e = &ee;
639
640 hashtb_start(nlsr->adl, e);
641 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
642
643 if( res == HT_OLD_ENTRY )
644 {
645 nnbr=e->data;
646 nnbr->last_lsdb_requested=timestamp;
akmhoque03004e62012-09-06 01:12:28 -0500647
648 }
649 else if(res == HT_NEW_ENTRY)
650 {
651 hashtb_delete(e);
652 }
653
654 hashtb_end(e);
655}
656
657void
658set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
659{
660 printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
661
662 int res;
663 struct ndn_neighbor *nnbr;
664
665 struct hashtb_enumerator ee;
666 struct hashtb_enumerator *e = &ee;
667
668 hashtb_start(nlsr->adl, e);
669 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
670
671 if (res == HT_OLD_ENTRY)
672 {
673 nnbr=e->data;
674 nnbr->is_lsdb_send_interest_scheduled=0;
675 }
676 else if(res == HT_NEW_ENTRY)
677 {
678 hashtb_delete(e);
679 }
680
681 hashtb_end(e);
682}
683
684void
685update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
686{
687 printf("update_adjacent_timed_out_to_adl called \n");
688
689 int res;
690 struct ndn_neighbor *nnbr;
691
692 struct hashtb_enumerator ee;
693 struct hashtb_enumerator *e = &ee;
694
695 hashtb_start(nlsr->adl, e);
696 res = hashtb_seek(e, nbr->name, nbr->length, 0);
697
698 if( res == HT_OLD_ENTRY )
699 {
700 nnbr=e->data;
701 free(nnbr->last_lsdb_version);
702 nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
703 memset(nnbr->last_lsdb_version,0,strlen(version)+1);
704 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoque53f64222012-09-05 13:57:51 -0500705 }
706 else if(res == HT_NEW_ENTRY)
707 {
708 hashtb_delete(e);
709 }
710
711 hashtb_end(e);
712
713}
714
715void
716adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
717{
718 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
719
720 int res;
721 struct ndn_neighbor *nnbr;
722
723 struct hashtb_enumerator ee;
724 struct hashtb_enumerator *e = &ee;
725
726 hashtb_start(nlsr->adl, e);
727 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
728
729 if( res == HT_OLD_ENTRY )
730 {
731 nnbr=e->data;
732 nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
akmhoque03004e62012-09-06 01:12:28 -0500733
akmhoque53f64222012-09-05 13:57:51 -0500734 }
735 else if(res == HT_NEW_ENTRY)
736 {
737 hashtb_delete(e);
738 }
739
740 hashtb_end(e);
741
742}
743
akmhoquefbfd0982012-09-09 20:59:03 -0500744int
745get_next_hop_face_from_adl(char *nbr)
746{
747 int res;
748 int connecting_face=NO_FACE;
749 struct ndn_neighbor *nnbr;
750
751 struct hashtb_enumerator ee;
752 struct hashtb_enumerator *e = &ee;
753
754 hashtb_start(nlsr->adl, e);
755 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
756
757 if( res == HT_OLD_ENTRY )
758 {
759 nnbr=e->data;
760 connecting_face=nnbr->face;
761
762 }
763 else if(res == HT_NEW_ENTRY)
764 {
765 hashtb_delete(e);
766 }
767
768 hashtb_end(e);
769 return connecting_face;
770}
771
akmhoquede61ba92012-09-20 22:19:12 -0500772int
773is_neighbor(char *nbr)
774{
775 int ret=0;
776
777 int res;
778 struct hashtb_enumerator ee;
779 struct hashtb_enumerator *e = &ee;
780
781 hashtb_start(nlsr->adl, e);
782 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
783
784 if( res == HT_OLD_ENTRY )
785 {
786 ret=1;
787 }
788 else if(res == HT_NEW_ENTRY)
789 {
790 hashtb_delete(e);
791 }
792
793 hashtb_end(e);
794
795 return ret;
796}
akmhoque53f64222012-09-05 13:57:51 -0500797