blob: 1c30be83bd8d31ed00f0c67b5b93de2f9fe1bcd4 [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
akmhoque8a5babe2012-08-16 17:39:33 -0500381void
akmhoque53f64222012-09-05 13:57:51 -0500382update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500383{
akmhoque7b791452012-10-30 11:24:56 -0500384 if ( nlsr->debugging )
385 printf("update_lsdb_synch_interval_to_adl called\n");
386 if ( nlsr->detailed_logging )
387 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500388
389 int res;
390 struct ndn_neighbor *nnbr;
391
392 struct hashtb_enumerator ee;
393 struct hashtb_enumerator *e = &ee;
394
395 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500396 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500397
akmhoque53f64222012-09-05 13:57:51 -0500398
399 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400400 {
401 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500402 if ( nnbr->lsdb_synch_interval!= interval )
403 {
404 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500405 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500406
akmhoque53f64222012-09-05 13:57:51 -0500407 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400408 }
akmhoqueb903ded2012-08-21 12:56:28 -0400409 else if(res == HT_NEW_ENTRY)
410 {
411 hashtb_delete(e);
412 }
akmhoque53f64222012-09-05 13:57:51 -0500413
akmhoque8a5babe2012-08-16 17:39:33 -0500414 hashtb_end(e);
415}
akmhoqued79438d2012-08-27 13:31:42 -0500416
akmhoque53f64222012-09-05 13:57:51 -0500417
akmhoque53f64222012-09-05 13:57:51 -0500418int
akmhoque03004e62012-09-06 01:12:28 -0500419no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500420{
akmhoque03004e62012-09-06 01:12:28 -0500421 int i, adl_element;
422 int no_link=0;
423 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500424 struct hashtb_enumerator ee;
425 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500426 hashtb_start(nlsr->adl, e);
427 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500428
akmhoque03004e62012-09-06 01:12:28 -0500429 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500430 {
akmhoque03004e62012-09-06 01:12:28 -0500431 nbr=e->data;
432 if( nbr->status == 1 )
433 no_link++;
434 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500435 }
akmhoque53f64222012-09-05 13:57:51 -0500436
akmhoqued79438d2012-08-27 13:31:42 -0500437 hashtb_end(e);
438
akmhoque03004e62012-09-06 01:12:28 -0500439 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500440
akmhoqued79438d2012-08-27 13:31:42 -0500441}
akmhoque53f64222012-09-05 13:57:51 -0500442
443int
444is_adj_lsa_build(void)
445{
446 int ret=0;
447
448 int nbr_count=0;
449
450 int i, adl_element;
451 struct ndn_neighbor *nbr;
452
453 struct hashtb_enumerator ee;
454 struct hashtb_enumerator *e = &ee;
455
456 hashtb_start(nlsr->adl, e);
457 adl_element=hashtb_n(nlsr->adl);
458
459 for(i=0;i<adl_element;i++)
460 {
461 nbr=e->data;
462 if(nbr->status == 1 )
463 {
464 nbr_count++;
465 }
akmhoque62c0c192012-09-24 07:49:25 -0500466 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 -0500467 {
468 nbr_count++;
469 }
470 hashtb_next(e);
471 }
472
473 hashtb_end(e);
474 if(nbr_count == adl_element)
475 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500476
akmhoque53f64222012-09-05 13:57:51 -0500477 return ret;
478}
479
akmhoque53f64222012-09-05 13:57:51 -0500480
481void
482get_active_nbr_adj_data(struct ccn_charbuf *c)
483{
484
485 int i, adl_element;
486 struct ndn_neighbor *nbr;
487 struct hashtb_enumerator ee;
488 struct hashtb_enumerator *e = &ee;
489 hashtb_start(nlsr->adl, e);
490 adl_element=hashtb_n(nlsr->adl);
491
492 for(i=0;i<adl_element;i++)
493 {
494 nbr=e->data;
495 if( nbr->status == 1 )
496 {
497 ccn_charbuf_append_string(c,nbr->neighbor->name);
498 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500499
akmhoque53f64222012-09-05 13:57:51 -0500500 char *temp_length=(char *)malloc(20);
501 memset(temp_length,0,20);
502 sprintf(temp_length,"%d",nbr->neighbor->length);
503 ccn_charbuf_append_string(c,temp_length);
504 free(temp_length);
505 ccn_charbuf_append_string(c,"|");
506
507 char *temp_face=(char *)malloc(20);
508 memset(temp_face,0,20);
509 sprintf(temp_face,"%d",nbr->face);
510 ccn_charbuf_append_string(c,temp_face);
511 free(temp_face);
512 ccn_charbuf_append_string(c,"|");
513
514 char *temp_metric=(char *)malloc(20);
515 memset(temp_metric,0,20);
516 sprintf(temp_metric,"%d",nbr->metric);
517 ccn_charbuf_append_string(c,temp_metric);
518 free(temp_metric);
519 ccn_charbuf_append_string(c,"|");
520
521 }
522 hashtb_next(e);
523 }
524
525 hashtb_end(e);
526}
527
akmhoque03004e62012-09-06 01:12:28 -0500528long int
529get_nbr_time_diff_lsdb_req(char *nbr)
530{
akmhoque7b791452012-10-30 11:24:56 -0500531 if ( nlsr->debugging )
532 printf("get_nbr_time_diff_lsdb_req called\n");
533 if ( nlsr->detailed_logging )
534 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n");
akmhoque03004e62012-09-06 01:12:28 -0500535
536 long int time_diff=get_lsdb_synch_interval(nbr)+1;
537 int res;
538 struct ndn_neighbor *nnbr;
539
540 struct hashtb_enumerator ee;
541 struct hashtb_enumerator *e = &ee;
542
543 hashtb_start(nlsr->adl, e);
544 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
545
546 if (res == HT_OLD_ENTRY)
547 {
548 nnbr=e->data;
549
550 if (nnbr->last_lsdb_requested == 0)
551 time_diff=get_lsdb_synch_interval(nbr)+1;
552 else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
553
554 }
555 else if(res == HT_NEW_ENTRY)
556 {
557 hashtb_delete(e);
558 }
559
560 hashtb_end(e);
561
562 return time_diff;
563}
564
565long int
566get_nbr_last_lsdb_requested(char *nbr)
567{
akmhoque7b791452012-10-30 11:24:56 -0500568 if ( nlsr->debugging )
569 printf("get_timed_out_number called\n");
570 if ( nlsr->detailed_logging )
571 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n");
akmhoque03004e62012-09-06 01:12:28 -0500572
573 long int last_lsdb_requested=0;
574
575 int res;
576 struct ndn_neighbor *nnbr;
577
578 struct hashtb_enumerator ee;
579 struct hashtb_enumerator *e = &ee;
580
581 hashtb_start(nlsr->adl, e);
582 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
583
584 if (res == HT_OLD_ENTRY)
585 {
586 nnbr=e->data;
587 last_lsdb_requested=nnbr->last_lsdb_requested;
588 }
589 else if(res == HT_NEW_ENTRY)
590 {
591 hashtb_delete(e);
592 }
593
594 hashtb_end(e);
595
596 return last_lsdb_requested;
597}
598
akmhoque14b3f342012-09-14 10:39:02 -0500599
600int
601get_nbr_random_time_component(char *nbr)
602{
akmhoque7b791452012-10-30 11:24:56 -0500603 if ( nlsr->debugging )
604 printf("get_nbr_random_time_component called\n");
605 if ( nlsr->detailed_logging )
606 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n");
akmhoque14b3f342012-09-14 10:39:02 -0500607
608 int time=0;
609
610 int res;
611 struct ndn_neighbor *nnbr;
612
613 struct hashtb_enumerator ee;
614 struct hashtb_enumerator *e = &ee;
615
616 hashtb_start(nlsr->adl, e);
617 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
618
619 if (res == HT_OLD_ENTRY)
620 {
621 nnbr=e->data;
akmhoque9fa58a82012-10-05 07:56:02 -0500622 time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1);
akmhoque14b3f342012-09-14 10:39:02 -0500623 }
624 else if(res == HT_NEW_ENTRY)
625 {
626 hashtb_delete(e);
627 }
628
629 hashtb_end(e);
630
631 return time;
632}
633
akmhoque03004e62012-09-06 01:12:28 -0500634long int
635get_lsdb_synch_interval(char *nbr)
636{
akmhoque7b791452012-10-30 11:24:56 -0500637 if ( nlsr->debugging )
638 printf("get_lsdb_synch_interval called \n");
639 if ( nlsr->detailed_logging )
640 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n");
akmhoque03004e62012-09-06 01:12:28 -0500641
642 long int lsdb_synch_interval=300;
643
644
645 int res;
646 struct ndn_neighbor *nnbr;
647
648 struct hashtb_enumerator ee;
649 struct hashtb_enumerator *e = &ee;
650
651 hashtb_start(nlsr->adl, e);
652 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
653
654 if (res == HT_OLD_ENTRY)
655 {
656 nnbr=e->data;
657 lsdb_synch_interval=nnbr->lsdb_synch_interval;
658 }
659 else if(res == HT_NEW_ENTRY)
660 {
661 hashtb_delete(e);
662 }
663
664 hashtb_end(e);
665
666 return lsdb_synch_interval;
667
668}
669
akmhoque53f64222012-09-05 13:57:51 -0500670char *
671get_nbr_lsdb_version(char *nbr)
672{
akmhoque7b791452012-10-30 11:24:56 -0500673 if ( nlsr->debugging )
674 printf("get_nbr_lsdb_version called \n");
675 if ( nlsr->detailed_logging )
676 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n");
akmhoque53f64222012-09-05 13:57:51 -0500677
678 char *version=NULL;
679
680 int res;
681 struct ndn_neighbor *nnbr;
682
683 struct hashtb_enumerator ee;
684 struct hashtb_enumerator *e = &ee;
685
686 hashtb_start(nlsr->adl, e);
687 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
akmhoque03004e62012-09-06 01:12:28 -0500688
akmhoque53f64222012-09-05 13:57:51 -0500689 if (res == HT_OLD_ENTRY)
690 {
691 nnbr=e->data;
692 version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
693 memset(version,0,strlen(nnbr->last_lsdb_version)+1);
694 memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
695 }
696 else if(res == HT_NEW_ENTRY)
697 {
698 hashtb_delete(e);
699 }
700
701 hashtb_end(e);
702
703 return version;
704}
705
706void
707update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
708{
akmhoque7b791452012-10-30 11:24:56 -0500709 if ( nlsr->debugging )
710 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
711 if ( nlsr->detailed_logging )
712 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n");
akmhoque53f64222012-09-05 13:57:51 -0500713
714 int res;
715 struct ndn_neighbor *nnbr;
716
717 struct hashtb_enumerator ee;
718 struct hashtb_enumerator *e = &ee;
719
720 hashtb_start(nlsr->adl, e);
721 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
722
723 if( res == HT_OLD_ENTRY )
724 {
725 nnbr=e->data;
726 nnbr->last_lsdb_requested=timestamp;
akmhoque03004e62012-09-06 01:12:28 -0500727
728 }
729 else if(res == HT_NEW_ENTRY)
730 {
731 hashtb_delete(e);
732 }
733
734 hashtb_end(e);
735}
736
737void
738set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
739{
akmhoque7b791452012-10-30 11:24:56 -0500740 if ( nlsr->debugging )
741 printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
742 if ( nlsr->detailed_logging )
743 writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n");
744
akmhoque03004e62012-09-06 01:12:28 -0500745
746 int res;
747 struct ndn_neighbor *nnbr;
748
749 struct hashtb_enumerator ee;
750 struct hashtb_enumerator *e = &ee;
751
752 hashtb_start(nlsr->adl, e);
753 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
754
755 if (res == HT_OLD_ENTRY)
756 {
757 nnbr=e->data;
758 nnbr->is_lsdb_send_interest_scheduled=0;
759 }
760 else if(res == HT_NEW_ENTRY)
761 {
762 hashtb_delete(e);
763 }
764
765 hashtb_end(e);
766}
767
768void
769update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
770{
akmhoque7b791452012-10-30 11:24:56 -0500771 if ( nlsr->debugging )
772 printf("update_adjacent_timed_out_to_adl called \n");
773 if ( nlsr->detailed_logging )
774 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n");
akmhoque03004e62012-09-06 01:12:28 -0500775
776 int res;
777 struct ndn_neighbor *nnbr;
778
779 struct hashtb_enumerator ee;
780 struct hashtb_enumerator *e = &ee;
781
782 hashtb_start(nlsr->adl, e);
783 res = hashtb_seek(e, nbr->name, nbr->length, 0);
784
785 if( res == HT_OLD_ENTRY )
786 {
787 nnbr=e->data;
788 free(nnbr->last_lsdb_version);
789 nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
790 memset(nnbr->last_lsdb_version,0,strlen(version)+1);
791 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoque53f64222012-09-05 13:57:51 -0500792 }
793 else if(res == HT_NEW_ENTRY)
794 {
795 hashtb_delete(e);
796 }
797
798 hashtb_end(e);
799
800}
801
802void
803adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
804{
805 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
806
akmhoque7b791452012-10-30 11:24:56 -0500807 if ( nlsr->debugging )
808 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
809 if ( nlsr->detailed_logging )
810 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n");
811
812
akmhoque53f64222012-09-05 13:57:51 -0500813 int res;
814 struct ndn_neighbor *nnbr;
815
816 struct hashtb_enumerator ee;
817 struct hashtb_enumerator *e = &ee;
818
819 hashtb_start(nlsr->adl, e);
820 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
821
822 if( res == HT_OLD_ENTRY )
823 {
824 nnbr=e->data;
825 nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
akmhoque03004e62012-09-06 01:12:28 -0500826
akmhoque53f64222012-09-05 13:57:51 -0500827 }
828 else if(res == HT_NEW_ENTRY)
829 {
830 hashtb_delete(e);
831 }
832
833 hashtb_end(e);
834
835}
836
akmhoquefbfd0982012-09-09 20:59:03 -0500837int
838get_next_hop_face_from_adl(char *nbr)
839{
840 int res;
841 int connecting_face=NO_FACE;
842 struct ndn_neighbor *nnbr;
843
844 struct hashtb_enumerator ee;
845 struct hashtb_enumerator *e = &ee;
846
847 hashtb_start(nlsr->adl, e);
848 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
849
850 if( res == HT_OLD_ENTRY )
851 {
852 nnbr=e->data;
853 connecting_face=nnbr->face;
854
855 }
856 else if(res == HT_NEW_ENTRY)
857 {
858 hashtb_delete(e);
859 }
860
861 hashtb_end(e);
862 return connecting_face;
863}
864
akmhoquede61ba92012-09-20 22:19:12 -0500865int
866is_neighbor(char *nbr)
867{
868 int ret=0;
869
870 int res;
871 struct hashtb_enumerator ee;
872 struct hashtb_enumerator *e = &ee;
873
874 hashtb_start(nlsr->adl, e);
875 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
876
877 if( res == HT_OLD_ENTRY )
878 {
879 ret=1;
880 }
881 else if(res == HT_NEW_ENTRY)
882 {
883 hashtb_delete(e);
884 }
885
886 hashtb_end(e);
887
888 return ret;
889}
akmhoque53f64222012-09-05 13:57:51 -0500890