blob: 54d895462d1c96ed344d32b394e4e54124490e4f [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{
akmhoque7b791452012-10-30 11:24:56 -050078 if ( nlsr->debugging )
79 {
80 printf("print_adjacent called\n");
81 printf("--------Neighbor---------------------------\n");
82 printf(" Neighbor: %s \n",nbr->neighbor->name);
83 printf(" Length : %d \n",nbr->neighbor->length);
84 printf(" Face : %d \n",nbr->face);
85 printf(" Metric : %d \n",nbr->metric);
86 printf(" Status : %d \n",nbr->status);
87 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
88 printf(" Info Version: %s \n",nbr->last_info_version);
89 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
90 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
91 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
92 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
93 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
94 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
akmhoque03004e62012-09-06 01:12:28 -050095
akmhoque7b791452012-10-30 11:24:56 -050096 printf("\n");
97 }
98
99 if ( nlsr->detailed_logging )
100 {
101
102 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n");
103 writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n");
104 writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name);
105 writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length);
106 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face);
107 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric);
108 writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status);
109 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version);
110 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version);
111 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
112 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
113 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
114 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
115 writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
116 writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
117
118 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
119 }
akmhoque8a5babe2012-08-16 17:39:33 -0500120
121}
122
123void
124print_adjacent_from_adl(void)
125{
akmhoque7b791452012-10-30 11:24:56 -0500126 if ( nlsr->debugging )
127 printf("print_adjacent_from_adl called \n");
128 if ( nlsr->detailed_logging )
129 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n");
130
akmhoque8a5babe2012-08-16 17:39:33 -0500131 int i, adl_element;
132 struct ndn_neighbor *nbr;
133
134 struct hashtb_enumerator ee;
135 struct hashtb_enumerator *e = &ee;
136
137 hashtb_start(nlsr->adl, e);
138 adl_element=hashtb_n(nlsr->adl);
139
140 for(i=0;i<adl_element;i++)
141 {
142 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500143 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500144 hashtb_next(e);
145 }
146
147 hashtb_end(e);
148
akmhoque8a5babe2012-08-16 17:39:33 -0500149}
150
akmhoque03004e62012-09-06 01:12:28 -0500151int
152get_adjacent_status(struct name_prefix *nbr)
153{
akmhoque7b791452012-10-30 11:24:56 -0500154
155 if ( nlsr->debugging )
156 printf("get_adjacent_status called \n");
157 if ( nlsr->detailed_logging )
158 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n");
akmhoque03004e62012-09-06 01:12:28 -0500159
160 int res;
161 int status=-1;
162 struct ndn_neighbor *nnbr;
163
164 struct hashtb_enumerator ee;
165 struct hashtb_enumerator *e = &ee;
166
167 hashtb_start(nlsr->adl, e);
168 res = hashtb_seek(e, nbr->name, nbr->length, 0);
169
170 if (res == HT_OLD_ENTRY)
171 {
172 nnbr=e->data;
173 status=nnbr->status;
174 }
175 else if(res == HT_NEW_ENTRY)
176 {
177 hashtb_delete(e);
178 }
179
180 hashtb_end(e);
181
182 return status;
183
184}
185
186int
187get_timed_out_number(struct name_prefix *nbr)
188{
akmhoque7b791452012-10-30 11:24:56 -0500189
190 if ( nlsr->debugging )
191 printf("get_timed_out_number called \n");
192 if ( nlsr->detailed_logging )
193 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n");
194
akmhoque03004e62012-09-06 01:12:28 -0500195
196 int res,ret=-1;
197 struct ndn_neighbor *nnbr;
198
199 struct hashtb_enumerator ee;
200 struct hashtb_enumerator *e = &ee;
201
202 hashtb_start(nlsr->adl, e);
203 res = hashtb_seek(e, nbr->name, nbr->length, 0);
204
205 if( res == HT_OLD_ENTRY )
206 {
207 nnbr=e->data;
208 ret=nnbr->info_interest_timed_out;
209 }
210 else if(res == HT_NEW_ENTRY)
211 {
212 hashtb_delete(e);
213 }
214
215 hashtb_end(e);
216
217 return ret;
218}
219
akmhoque14b3f342012-09-14 10:39:02 -0500220int
221get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
222{
akmhoque7b791452012-10-30 11:24:56 -0500223
224 if ( nlsr->debugging )
225 printf("get_lsdb_interest_timed_out_number called \n");
226 if ( nlsr->detailed_logging )
227 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500228
229 int res,ret=-1;
230 struct ndn_neighbor *nnbr;
231
232 struct hashtb_enumerator ee;
233 struct hashtb_enumerator *e = &ee;
234
235 hashtb_start(nlsr->adl, e);
236 res = hashtb_seek(e, nbr->name, nbr->length, 0);
237
238 if( res == HT_OLD_ENTRY )
239 {
240 nnbr=e->data;
241 ret=nnbr->lsdb_interest_timed_out;
242 }
243 else if(res == HT_NEW_ENTRY)
244 {
245 hashtb_delete(e);
246 }
247
248 hashtb_end(e);
249
250 return ret;
251}
akmhoque03004e62012-09-06 01:12:28 -0500252
253void
254update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
255{
akmhoque7b791452012-10-30 11:24:56 -0500256 if ( nlsr->debugging )
257 printf("update_adjacent_timed_out_to_adl called \n");
258 if ( nlsr->detailed_logging )
259 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500260
261 int res;
262 struct ndn_neighbor *nnbr;
263
264 struct hashtb_enumerator ee;
265 struct hashtb_enumerator *e = &ee;
266
267 hashtb_start(nlsr->adl, e);
268 res = hashtb_seek(e, nbr->name, nbr->length, 0);
269
270 if( res == HT_OLD_ENTRY )
271 {
272 nnbr=e->data;
273 nnbr->info_interest_timed_out += increment;
274 }
275 else if(res == HT_NEW_ENTRY)
276 {
277 hashtb_delete(e);
278 }
279
280 hashtb_end(e);
281}
282
283void
284update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
285{
akmhoque7b791452012-10-30 11:24:56 -0500286 if ( nlsr->debugging )
287 printf("update_adjacent_timed_out_zero_to_adl called \n");
288 if ( nlsr->detailed_logging )
289 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n");
290
akmhoque03004e62012-09-06 01:12:28 -0500291 int time_out_number=get_timed_out_number(nbr);
292 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
293
294}
295
akmhoque14b3f342012-09-14 10:39:02 -0500296
297void
298update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
299{
akmhoque7b791452012-10-30 11:24:56 -0500300 if ( nlsr->debugging )
301 printf("update_lsdb_interest_timed_out_to_adl called\n");
302 if ( nlsr->detailed_logging )
303 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500304
305 int res;
306 struct ndn_neighbor *nnbr;
307
308 struct hashtb_enumerator ee;
309 struct hashtb_enumerator *e = &ee;
310
311 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500312
313 //printf("Neighbor: %s , Length: %d \n",nbr->name, nbr->length);
314
akmhoque14b3f342012-09-14 10:39:02 -0500315 res = hashtb_seek(e, nbr->name, nbr->length, 0);
316
317 if( res == HT_OLD_ENTRY )
318 {
akmhoque62c0c192012-09-24 07:49:25 -0500319 //printf("Old Neighbor\n");
akmhoque14b3f342012-09-14 10:39:02 -0500320 nnbr=e->data;
321 nnbr->lsdb_interest_timed_out += increment;
akmhoque62c0c192012-09-24 07:49:25 -0500322 //printf("lsdb_interest_timed_out: %d \n",nnbr->lsdb_interest_timed_out);
akmhoque14b3f342012-09-14 10:39:02 -0500323 }
324 else if(res == HT_NEW_ENTRY)
325 {
326 hashtb_delete(e);
327 }
328
akmhoque62c0c192012-09-24 07:49:25 -0500329 //print_adjacent_from_adl();
akmhoque14b3f342012-09-14 10:39:02 -0500330 hashtb_end(e);
331}
332
333void
334update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
335{
akmhoque7b791452012-10-30 11:24:56 -0500336 if ( nlsr->debugging )
337 printf("update_adjacent_timed_out_zero_to_adl called\n");
338 if ( nlsr->detailed_logging )
339 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n");
340
akmhoque14b3f342012-09-14 10:39:02 -0500341 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
342 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
343
344}
345
akmhoque8a5babe2012-08-16 17:39:33 -0500346void
akmhoque53f64222012-09-05 13:57:51 -0500347update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500348{
akmhoque7b791452012-10-30 11:24:56 -0500349 if ( nlsr->debugging )
350 printf("update_adjacent_status_to_adl called\n");
351 if ( nlsr->detailed_logging )
352 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500353
akmhoque8a5babe2012-08-16 17:39:33 -0500354 int res;
355 struct ndn_neighbor *nnbr;
356
357 struct hashtb_enumerator ee;
358 struct hashtb_enumerator *e = &ee;
359
360 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500361 res = hashtb_seek(e, nbr->name, nbr->length, 0);
362
akmhoque918ff9a2012-08-21 11:34:49 -0400363
akmhoquee7c4b6d2012-08-21 12:30:25 -0400364 if (res == HT_OLD_ENTRY)
365 {
366 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500367 if ( nnbr->status!=status )
368 {
369 nnbr->status=status;
370 nlsr->adj_build_flag++;
371 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400372 }
akmhoqueb903ded2012-08-21 12:56:28 -0400373 else if(res == HT_NEW_ENTRY)
374 {
375 hashtb_delete(e);
376 }
akmhoque53f64222012-09-05 13:57:51 -0500377
akmhoque8a5babe2012-08-16 17:39:33 -0500378 hashtb_end(e);
379}
380
akmhoque3171d652012-11-13 11:44:33 -0600381
382void
383delete_nbr_from_adl(struct name_prefix *nbr)
384{
385 if ( nlsr->debugging )
386 printf("delete_nbr_from_adl called\n");
387 if ( nlsr->detailed_logging )
388 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n");
389
390 int res;
391 struct hashtb_enumerator ee;
392 struct hashtb_enumerator *e = &ee;
393
394 hashtb_start(nlsr->adl, e);
395 res = hashtb_seek(e, nbr->name, nbr->length, 0);
396
397
398 if (res == HT_OLD_ENTRY)
399 {
400 hashtb_delete(e);
401 }
402 else if(res == HT_NEW_ENTRY)
403 {
404 hashtb_delete(e);
405 }
406
407 hashtb_end(e);
408}
409
akmhoque8a5babe2012-08-16 17:39:33 -0500410void
akmhoque53f64222012-09-05 13:57:51 -0500411update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500412{
akmhoque7b791452012-10-30 11:24:56 -0500413 if ( nlsr->debugging )
414 printf("update_lsdb_synch_interval_to_adl called\n");
415 if ( nlsr->detailed_logging )
416 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500417
418 int res;
419 struct ndn_neighbor *nnbr;
420
421 struct hashtb_enumerator ee;
422 struct hashtb_enumerator *e = &ee;
423
424 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500425 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500426
akmhoque53f64222012-09-05 13:57:51 -0500427
428 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400429 {
430 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500431 if ( nnbr->lsdb_synch_interval!= interval )
432 {
433 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500434 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500435
akmhoque53f64222012-09-05 13:57:51 -0500436 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400437 }
akmhoqueb903ded2012-08-21 12:56:28 -0400438 else if(res == HT_NEW_ENTRY)
439 {
440 hashtb_delete(e);
441 }
akmhoque53f64222012-09-05 13:57:51 -0500442
akmhoque8a5babe2012-08-16 17:39:33 -0500443 hashtb_end(e);
444}
akmhoqued79438d2012-08-27 13:31:42 -0500445
akmhoque53f64222012-09-05 13:57:51 -0500446
akmhoque53f64222012-09-05 13:57:51 -0500447int
akmhoque03004e62012-09-06 01:12:28 -0500448no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500449{
akmhoque03004e62012-09-06 01:12:28 -0500450 int i, adl_element;
451 int no_link=0;
452 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500453 struct hashtb_enumerator ee;
454 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500455 hashtb_start(nlsr->adl, e);
456 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500457
akmhoque03004e62012-09-06 01:12:28 -0500458 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500459 {
akmhoque03004e62012-09-06 01:12:28 -0500460 nbr=e->data;
461 if( nbr->status == 1 )
462 no_link++;
463 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500464 }
akmhoque53f64222012-09-05 13:57:51 -0500465
akmhoqued79438d2012-08-27 13:31:42 -0500466 hashtb_end(e);
467
akmhoque03004e62012-09-06 01:12:28 -0500468 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500469
akmhoqued79438d2012-08-27 13:31:42 -0500470}
akmhoque53f64222012-09-05 13:57:51 -0500471
472int
473is_adj_lsa_build(void)
474{
475 int ret=0;
476
477 int nbr_count=0;
478
479 int i, adl_element;
480 struct ndn_neighbor *nbr;
481
482 struct hashtb_enumerator ee;
483 struct hashtb_enumerator *e = &ee;
484
485 hashtb_start(nlsr->adl, e);
486 adl_element=hashtb_n(nlsr->adl);
487
488 for(i=0;i<adl_element;i++)
489 {
490 nbr=e->data;
491 if(nbr->status == 1 )
492 {
493 nbr_count++;
494 }
akmhoque62c0c192012-09-24 07:49:25 -0500495 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 -0500496 {
497 nbr_count++;
498 }
499 hashtb_next(e);
500 }
501
502 hashtb_end(e);
503 if(nbr_count == adl_element)
504 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500505
akmhoque53f64222012-09-05 13:57:51 -0500506 return ret;
507}
508
akmhoque53f64222012-09-05 13:57:51 -0500509
510void
511get_active_nbr_adj_data(struct ccn_charbuf *c)
512{
513
514 int i, adl_element;
515 struct ndn_neighbor *nbr;
516 struct hashtb_enumerator ee;
517 struct hashtb_enumerator *e = &ee;
518 hashtb_start(nlsr->adl, e);
519 adl_element=hashtb_n(nlsr->adl);
520
521 for(i=0;i<adl_element;i++)
522 {
523 nbr=e->data;
524 if( nbr->status == 1 )
525 {
526 ccn_charbuf_append_string(c,nbr->neighbor->name);
527 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500528
akmhoque53f64222012-09-05 13:57:51 -0500529 char *temp_length=(char *)malloc(20);
530 memset(temp_length,0,20);
531 sprintf(temp_length,"%d",nbr->neighbor->length);
532 ccn_charbuf_append_string(c,temp_length);
533 free(temp_length);
534 ccn_charbuf_append_string(c,"|");
535
536 char *temp_face=(char *)malloc(20);
537 memset(temp_face,0,20);
538 sprintf(temp_face,"%d",nbr->face);
539 ccn_charbuf_append_string(c,temp_face);
540 free(temp_face);
541 ccn_charbuf_append_string(c,"|");
542
543 char *temp_metric=(char *)malloc(20);
544 memset(temp_metric,0,20);
545 sprintf(temp_metric,"%d",nbr->metric);
546 ccn_charbuf_append_string(c,temp_metric);
547 free(temp_metric);
548 ccn_charbuf_append_string(c,"|");
549
550 }
551 hashtb_next(e);
552 }
553
554 hashtb_end(e);
555}
556
akmhoque03004e62012-09-06 01:12:28 -0500557long int
558get_nbr_time_diff_lsdb_req(char *nbr)
559{
akmhoque7b791452012-10-30 11:24:56 -0500560 if ( nlsr->debugging )
561 printf("get_nbr_time_diff_lsdb_req called\n");
562 if ( nlsr->detailed_logging )
563 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n");
akmhoque03004e62012-09-06 01:12:28 -0500564
565 long int time_diff=get_lsdb_synch_interval(nbr)+1;
566 int res;
567 struct ndn_neighbor *nnbr;
568
569 struct hashtb_enumerator ee;
570 struct hashtb_enumerator *e = &ee;
571
572 hashtb_start(nlsr->adl, e);
573 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
574
575 if (res == HT_OLD_ENTRY)
576 {
577 nnbr=e->data;
578
579 if (nnbr->last_lsdb_requested == 0)
580 time_diff=get_lsdb_synch_interval(nbr)+1;
581 else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
582
583 }
584 else if(res == HT_NEW_ENTRY)
585 {
586 hashtb_delete(e);
587 }
588
589 hashtb_end(e);
590
591 return time_diff;
592}
593
594long int
595get_nbr_last_lsdb_requested(char *nbr)
596{
akmhoque7b791452012-10-30 11:24:56 -0500597 if ( nlsr->debugging )
598 printf("get_timed_out_number called\n");
599 if ( nlsr->detailed_logging )
600 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n");
akmhoque03004e62012-09-06 01:12:28 -0500601
602 long int last_lsdb_requested=0;
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);
612
613 if (res == HT_OLD_ENTRY)
614 {
615 nnbr=e->data;
616 last_lsdb_requested=nnbr->last_lsdb_requested;
617 }
618 else if(res == HT_NEW_ENTRY)
619 {
620 hashtb_delete(e);
621 }
622
623 hashtb_end(e);
624
625 return last_lsdb_requested;
626}
627
akmhoque14b3f342012-09-14 10:39:02 -0500628
629int
630get_nbr_random_time_component(char *nbr)
631{
akmhoque7b791452012-10-30 11:24:56 -0500632 if ( nlsr->debugging )
633 printf("get_nbr_random_time_component called\n");
634 if ( nlsr->detailed_logging )
635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n");
akmhoque14b3f342012-09-14 10:39:02 -0500636
637 int time=0;
638
639 int res;
640 struct ndn_neighbor *nnbr;
641
642 struct hashtb_enumerator ee;
643 struct hashtb_enumerator *e = &ee;
644
645 hashtb_start(nlsr->adl, e);
646 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
647
648 if (res == HT_OLD_ENTRY)
649 {
650 nnbr=e->data;
akmhoque9fa58a82012-10-05 07:56:02 -0500651 time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1);
akmhoque14b3f342012-09-14 10:39:02 -0500652 }
653 else if(res == HT_NEW_ENTRY)
654 {
655 hashtb_delete(e);
656 }
657
658 hashtb_end(e);
659
660 return time;
661}
662
akmhoque03004e62012-09-06 01:12:28 -0500663long int
664get_lsdb_synch_interval(char *nbr)
665{
akmhoque7b791452012-10-30 11:24:56 -0500666 if ( nlsr->debugging )
667 printf("get_lsdb_synch_interval called \n");
668 if ( nlsr->detailed_logging )
669 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n");
akmhoque03004e62012-09-06 01:12:28 -0500670
671 long int lsdb_synch_interval=300;
672
673
674 int res;
675 struct ndn_neighbor *nnbr;
676
677 struct hashtb_enumerator ee;
678 struct hashtb_enumerator *e = &ee;
679
680 hashtb_start(nlsr->adl, e);
681 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
682
683 if (res == HT_OLD_ENTRY)
684 {
685 nnbr=e->data;
686 lsdb_synch_interval=nnbr->lsdb_synch_interval;
687 }
688 else if(res == HT_NEW_ENTRY)
689 {
690 hashtb_delete(e);
691 }
692
693 hashtb_end(e);
694
695 return lsdb_synch_interval;
696
697}
698
akmhoque53f64222012-09-05 13:57:51 -0500699char *
700get_nbr_lsdb_version(char *nbr)
701{
akmhoque7b791452012-10-30 11:24:56 -0500702 if ( nlsr->debugging )
703 printf("get_nbr_lsdb_version called \n");
704 if ( nlsr->detailed_logging )
705 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n");
akmhoque53f64222012-09-05 13:57:51 -0500706
707 char *version=NULL;
708
709 int res;
710 struct ndn_neighbor *nnbr;
711
712 struct hashtb_enumerator ee;
713 struct hashtb_enumerator *e = &ee;
714
715 hashtb_start(nlsr->adl, e);
716 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
akmhoque03004e62012-09-06 01:12:28 -0500717
akmhoque53f64222012-09-05 13:57:51 -0500718 if (res == HT_OLD_ENTRY)
719 {
720 nnbr=e->data;
721 version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
722 memset(version,0,strlen(nnbr->last_lsdb_version)+1);
723 memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
724 }
725 else if(res == HT_NEW_ENTRY)
726 {
727 hashtb_delete(e);
728 }
729
730 hashtb_end(e);
731
732 return version;
733}
734
735void
736update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
737{
akmhoque7b791452012-10-30 11:24:56 -0500738 if ( nlsr->debugging )
739 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
740 if ( nlsr->detailed_logging )
741 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n");
akmhoque53f64222012-09-05 13:57:51 -0500742
743 int res;
744 struct ndn_neighbor *nnbr;
745
746 struct hashtb_enumerator ee;
747 struct hashtb_enumerator *e = &ee;
748
749 hashtb_start(nlsr->adl, e);
750 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
751
752 if( res == HT_OLD_ENTRY )
753 {
754 nnbr=e->data;
755 nnbr->last_lsdb_requested=timestamp;
akmhoque03004e62012-09-06 01:12:28 -0500756
757 }
758 else if(res == HT_NEW_ENTRY)
759 {
760 hashtb_delete(e);
761 }
762
763 hashtb_end(e);
764}
765
766void
767set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
768{
akmhoque7b791452012-10-30 11:24:56 -0500769 if ( nlsr->debugging )
770 printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
771 if ( nlsr->detailed_logging )
772 writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n");
773
akmhoque03004e62012-09-06 01:12:28 -0500774
775 int res;
776 struct ndn_neighbor *nnbr;
777
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 nnbr=e->data;
787 nnbr->is_lsdb_send_interest_scheduled=0;
788 }
789 else if(res == HT_NEW_ENTRY)
790 {
791 hashtb_delete(e);
792 }
793
794 hashtb_end(e);
795}
796
797void
798update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
799{
akmhoque7b791452012-10-30 11:24:56 -0500800 if ( nlsr->debugging )
801 printf("update_adjacent_timed_out_to_adl called \n");
802 if ( nlsr->detailed_logging )
803 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n");
akmhoque03004e62012-09-06 01:12:28 -0500804
805 int res;
806 struct ndn_neighbor *nnbr;
807
808 struct hashtb_enumerator ee;
809 struct hashtb_enumerator *e = &ee;
810
811 hashtb_start(nlsr->adl, e);
812 res = hashtb_seek(e, nbr->name, nbr->length, 0);
813
814 if( res == HT_OLD_ENTRY )
815 {
816 nnbr=e->data;
817 free(nnbr->last_lsdb_version);
818 nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
819 memset(nnbr->last_lsdb_version,0,strlen(version)+1);
820 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoque53f64222012-09-05 13:57:51 -0500821 }
822 else if(res == HT_NEW_ENTRY)
823 {
824 hashtb_delete(e);
825 }
826
827 hashtb_end(e);
828
829}
830
831void
832adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
833{
834 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
835
akmhoque7b791452012-10-30 11:24:56 -0500836 if ( nlsr->debugging )
837 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
838 if ( nlsr->detailed_logging )
839 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n");
840
841
akmhoque53f64222012-09-05 13:57:51 -0500842 int res;
843 struct ndn_neighbor *nnbr;
844
845 struct hashtb_enumerator ee;
846 struct hashtb_enumerator *e = &ee;
847
848 hashtb_start(nlsr->adl, e);
849 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
850
851 if( res == HT_OLD_ENTRY )
852 {
853 nnbr=e->data;
854 nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
akmhoque03004e62012-09-06 01:12:28 -0500855
akmhoque53f64222012-09-05 13:57:51 -0500856 }
857 else if(res == HT_NEW_ENTRY)
858 {
859 hashtb_delete(e);
860 }
861
862 hashtb_end(e);
863
864}
865
akmhoquefbfd0982012-09-09 20:59:03 -0500866int
867get_next_hop_face_from_adl(char *nbr)
868{
869 int res;
870 int connecting_face=NO_FACE;
871 struct ndn_neighbor *nnbr;
872
873 struct hashtb_enumerator ee;
874 struct hashtb_enumerator *e = &ee;
875
876 hashtb_start(nlsr->adl, e);
877 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
878
879 if( res == HT_OLD_ENTRY )
880 {
881 nnbr=e->data;
882 connecting_face=nnbr->face;
883
884 }
885 else if(res == HT_NEW_ENTRY)
886 {
887 hashtb_delete(e);
888 }
889
890 hashtb_end(e);
891 return connecting_face;
892}
893
akmhoquede61ba92012-09-20 22:19:12 -0500894int
895is_neighbor(char *nbr)
896{
897 int ret=0;
898
899 int res;
900 struct hashtb_enumerator ee;
901 struct hashtb_enumerator *e = &ee;
902
903 hashtb_start(nlsr->adl, e);
904 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
905
906 if( res == HT_OLD_ENTRY )
907 {
908 ret=1;
909 }
910 else if(res == HT_NEW_ENTRY)
911 {
912 hashtb_delete(e);
913 }
914
915 hashtb_end(e);
916
917 return ret;
918}
akmhoque53f64222012-09-05 13:57:51 -0500919