blob: 947d5ac805e29a04c0e4e0a19e477c3ecbde8174 [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>
akmhoqueb77b95f2013-02-08 12:28:47 -060011#include <sys/socket.h>
12#include <netdb.h>
13#include <netinet/in.h>
14#include <arpa/inet.h>
akmhoque8a5babe2012-08-16 17:39:33 -050015#endif
16
17
18#include <ccn/ccn.h>
19#include <ccn/uri.h>
20#include <ccn/keystore.h>
21#include <ccn/signing.h>
22#include <ccn/schedule.h>
23#include <ccn/hashtb.h>
24
25#include "nlsr.h"
akmhoque03004e62012-09-06 01:12:28 -050026#include "nlsr_npl.h"
akmhoque8a5babe2012-08-16 17:39:33 -050027#include "nlsr_adl.h"
akmhoque03004e62012-09-06 01:12:28 -050028#include "utility.h"
akmhoquefbfd0982012-09-09 20:59:03 -050029#include "nlsr_npt.h"
akmhoque8a5babe2012-08-16 17:39:33 -050030
akmhoque03004e62012-09-06 01:12:28 -050031void
akmhoqueb77b95f2013-02-08 12:28:47 -060032add_nbr_to_adl(struct name_prefix *new_nbr,int face,char *ip)
akmhoque8a5babe2012-08-16 17:39:33 -050033{
akmhoque8876e982013-02-21 13:35:46 -060034 struct ndn_neighbor *nbr;//=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor )); //free
akmhoque53f64222012-09-05 13:57:51 -050035
akmhoque8a5babe2012-08-16 17:39:33 -050036 struct hashtb_enumerator ee;
37 struct hashtb_enumerator *e = &ee;
38 int res;
39
40 hashtb_start(nlsr->adl, e);
akmhoque03004e62012-09-06 01:12:28 -050041 res = hashtb_seek(e, new_nbr->name, new_nbr->length, 0);
akmhoque2852a222012-08-21 12:09:00 -040042
akmhoquee7c4b6d2012-08-21 12:30:25 -040043 if(res == HT_NEW_ENTRY )
44 {
akmhoque8a5babe2012-08-16 17:39:33 -050045
akmhoque53f64222012-09-05 13:57:51 -050046 nbr = e->data;
akmhoque8a5babe2012-08-16 17:39:33 -050047
akmhoque03004e62012-09-06 01:12:28 -050048 nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix )); //free
49 nbr->neighbor->name=(char *)malloc(new_nbr->length);
50 memcpy(nbr->neighbor->name,new_nbr->name,new_nbr->length);
51 nbr->neighbor->length=new_nbr->length;
akmhoque53f64222012-09-05 13:57:51 -050052 nbr->face=face;
53 nbr->status=NBR_DOWN;
54 nbr->info_interest_timed_out=0;
akmhoque14b3f342012-09-14 10:39:02 -050055 nbr->lsdb_interest_timed_out=0;
56 nbr->lsdb_random_time_component=(int)(LSDB_SYNCH_INTERVAL/2);
57 nbr->lsdb_synch_interval=LSDB_SYNCH_INTERVAL;
58 nbr->metric=LINK_METRIC;
akmhoque53f64222012-09-05 13:57:51 -050059 nbr->is_lsdb_send_interest_scheduled=0;
60
akmhoque018692c2013-02-11 11:33:39 -060061 nbr->ip_address=(char *)malloc(strlen(ip)+1);
62 memset(nbr->ip_address,0,strlen(ip)+1);
akmhoqueb77b95f2013-02-08 12:28:47 -060063 memcpy(nbr->ip_address,ip,strlen(ip));
akmhoque8a5babe2012-08-16 17:39:33 -050064
akmhoque03004e62012-09-06 01:12:28 -050065 char *time_stamp=(char *)malloc(20);
66 get_current_timestamp_micro(time_stamp);
67 nbr->last_lsdb_version=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -050068 memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
69 memset(nbr->last_lsdb_version,'0',strlen(time_stamp));
akmhoque03004e62012-09-06 01:12:28 -050070 nbr->last_info_version=(char *)malloc(strlen(time_stamp)+1); //free
71 memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
72 memset(nbr->last_info_version,'0',strlen(time_stamp));
73 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050074
75 nbr->last_lsdb_requested=0;
akmhoquee7c4b6d2012-08-21 12:30:25 -040076 }
akmhoque53f64222012-09-05 13:57:51 -050077
akmhoque8a5babe2012-08-16 17:39:33 -050078 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -050079}
akmhoque8a5babe2012-08-16 17:39:33 -050080
akmhoque03004e62012-09-06 01:12:28 -050081
akmhoque53f64222012-09-05 13:57:51 -050082void
83print_adjacent(struct ndn_neighbor *nbr)
84{
akmhoque7b791452012-10-30 11:24:56 -050085 if ( nlsr->debugging )
86 {
87 printf("print_adjacent called\n");
88 printf("--------Neighbor---------------------------\n");
89 printf(" Neighbor: %s \n",nbr->neighbor->name);
90 printf(" Length : %d \n",nbr->neighbor->length);
akmhoqueb77b95f2013-02-08 12:28:47 -060091 printf(" Ip Address: %s \n",nbr->ip_address);
akmhoque7b791452012-10-30 11:24:56 -050092 printf(" Face : %d \n",nbr->face);
93 printf(" Metric : %d \n",nbr->metric);
94 printf(" Status : %d \n",nbr->status);
95 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
96 printf(" Info Version: %s \n",nbr->last_info_version);
97 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
98 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
99 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
100 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
101 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
102 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
akmhoque03004e62012-09-06 01:12:28 -0500103
akmhoque7b791452012-10-30 11:24:56 -0500104 printf("\n");
105 }
106
107 if ( nlsr->detailed_logging )
108 {
109
110 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n");
111 writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n");
112 writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name);
113 writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length);
114 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face);
115 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric);
116 writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status);
117 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version);
118 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version);
119 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
120 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
121 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
122 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
123 writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
124 writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
125
126 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
127 }
akmhoque8a5babe2012-08-16 17:39:33 -0500128
129}
130
131void
132print_adjacent_from_adl(void)
133{
akmhoque7b791452012-10-30 11:24:56 -0500134 if ( nlsr->debugging )
135 printf("print_adjacent_from_adl called \n");
136 if ( nlsr->detailed_logging )
137 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n");
138
akmhoque8a5babe2012-08-16 17:39:33 -0500139 int i, adl_element;
140 struct ndn_neighbor *nbr;
141
142 struct hashtb_enumerator ee;
143 struct hashtb_enumerator *e = &ee;
144
145 hashtb_start(nlsr->adl, e);
146 adl_element=hashtb_n(nlsr->adl);
147
148 for(i=0;i<adl_element;i++)
149 {
150 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500151 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500152 hashtb_next(e);
153 }
154
155 hashtb_end(e);
156
akmhoque8a5babe2012-08-16 17:39:33 -0500157}
158
akmhoque03004e62012-09-06 01:12:28 -0500159int
160get_adjacent_status(struct name_prefix *nbr)
161{
akmhoque7b791452012-10-30 11:24:56 -0500162
163 if ( nlsr->debugging )
164 printf("get_adjacent_status called \n");
165 if ( nlsr->detailed_logging )
166 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n");
akmhoque03004e62012-09-06 01:12:28 -0500167
168 int res;
169 int status=-1;
170 struct ndn_neighbor *nnbr;
171
172 struct hashtb_enumerator ee;
173 struct hashtb_enumerator *e = &ee;
174
175 hashtb_start(nlsr->adl, e);
176 res = hashtb_seek(e, nbr->name, nbr->length, 0);
177
178 if (res == HT_OLD_ENTRY)
179 {
180 nnbr=e->data;
181 status=nnbr->status;
182 }
183 else if(res == HT_NEW_ENTRY)
184 {
185 hashtb_delete(e);
186 }
187
188 hashtb_end(e);
189
190 return status;
191
192}
193
194int
195get_timed_out_number(struct name_prefix *nbr)
196{
akmhoque7b791452012-10-30 11:24:56 -0500197
198 if ( nlsr->debugging )
199 printf("get_timed_out_number called \n");
200 if ( nlsr->detailed_logging )
201 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n");
202
akmhoque03004e62012-09-06 01:12:28 -0500203
204 int res,ret=-1;
205 struct ndn_neighbor *nnbr;
206
207 struct hashtb_enumerator ee;
208 struct hashtb_enumerator *e = &ee;
209
210 hashtb_start(nlsr->adl, e);
211 res = hashtb_seek(e, nbr->name, nbr->length, 0);
212
213 if( res == HT_OLD_ENTRY )
214 {
215 nnbr=e->data;
216 ret=nnbr->info_interest_timed_out;
217 }
218 else if(res == HT_NEW_ENTRY)
219 {
220 hashtb_delete(e);
221 }
222
223 hashtb_end(e);
224
225 return ret;
226}
227
akmhoque14b3f342012-09-14 10:39:02 -0500228int
229get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
230{
akmhoque7b791452012-10-30 11:24:56 -0500231
232 if ( nlsr->debugging )
233 printf("get_lsdb_interest_timed_out_number called \n");
234 if ( nlsr->detailed_logging )
235 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500236
237 int res,ret=-1;
238 struct ndn_neighbor *nnbr;
239
240 struct hashtb_enumerator ee;
241 struct hashtb_enumerator *e = &ee;
242
243 hashtb_start(nlsr->adl, e);
244 res = hashtb_seek(e, nbr->name, nbr->length, 0);
245
246 if( res == HT_OLD_ENTRY )
247 {
248 nnbr=e->data;
249 ret=nnbr->lsdb_interest_timed_out;
250 }
251 else if(res == HT_NEW_ENTRY)
252 {
253 hashtb_delete(e);
254 }
255
256 hashtb_end(e);
257
258 return ret;
259}
akmhoque03004e62012-09-06 01:12:28 -0500260
261void
262update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
263{
akmhoque7b791452012-10-30 11:24:56 -0500264 if ( nlsr->debugging )
265 printf("update_adjacent_timed_out_to_adl called \n");
266 if ( nlsr->detailed_logging )
267 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500268
269 int res;
270 struct ndn_neighbor *nnbr;
271
272 struct hashtb_enumerator ee;
273 struct hashtb_enumerator *e = &ee;
274
275 hashtb_start(nlsr->adl, e);
276 res = hashtb_seek(e, nbr->name, nbr->length, 0);
277
278 if( res == HT_OLD_ENTRY )
279 {
280 nnbr=e->data;
281 nnbr->info_interest_timed_out += increment;
282 }
283 else if(res == HT_NEW_ENTRY)
284 {
285 hashtb_delete(e);
286 }
287
288 hashtb_end(e);
289}
290
291void
292update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
293{
akmhoque7b791452012-10-30 11:24:56 -0500294 if ( nlsr->debugging )
295 printf("update_adjacent_timed_out_zero_to_adl called \n");
296 if ( nlsr->detailed_logging )
297 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n");
298
akmhoque03004e62012-09-06 01:12:28 -0500299 int time_out_number=get_timed_out_number(nbr);
300 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
301
302}
303
akmhoque14b3f342012-09-14 10:39:02 -0500304
305void
306update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
307{
akmhoque7b791452012-10-30 11:24:56 -0500308 if ( nlsr->debugging )
309 printf("update_lsdb_interest_timed_out_to_adl called\n");
310 if ( nlsr->detailed_logging )
311 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500312
313 int res;
314 struct ndn_neighbor *nnbr;
315
316 struct hashtb_enumerator ee;
317 struct hashtb_enumerator *e = &ee;
318
319 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500320
akmhoque14b3f342012-09-14 10:39:02 -0500321 res = hashtb_seek(e, nbr->name, nbr->length, 0);
322
323 if( res == HT_OLD_ENTRY )
324 {
325 nnbr=e->data;
326 nnbr->lsdb_interest_timed_out += increment;
327 }
328 else if(res == HT_NEW_ENTRY)
329 {
330 hashtb_delete(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600331 }
akmhoque14b3f342012-09-14 10:39:02 -0500332 hashtb_end(e);
333}
334
335void
336update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
337{
akmhoque7b791452012-10-30 11:24:56 -0500338 if ( nlsr->debugging )
339 printf("update_adjacent_timed_out_zero_to_adl called\n");
340 if ( nlsr->detailed_logging )
341 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n");
342
akmhoque14b3f342012-09-14 10:39:02 -0500343 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
344 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
345
346}
347
akmhoque8a5babe2012-08-16 17:39:33 -0500348void
akmhoque53f64222012-09-05 13:57:51 -0500349update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500350{
akmhoque7b791452012-10-30 11:24:56 -0500351 if ( nlsr->debugging )
352 printf("update_adjacent_status_to_adl called\n");
353 if ( nlsr->detailed_logging )
354 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500355
akmhoque8a5babe2012-08-16 17:39:33 -0500356 int res;
357 struct ndn_neighbor *nnbr;
358
359 struct hashtb_enumerator ee;
360 struct hashtb_enumerator *e = &ee;
361
362 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500363 res = hashtb_seek(e, nbr->name, nbr->length, 0);
364
akmhoque918ff9a2012-08-21 11:34:49 -0400365
akmhoquee7c4b6d2012-08-21 12:30:25 -0400366 if (res == HT_OLD_ENTRY)
367 {
368 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500369 if ( nnbr->status!=status )
370 {
371 nnbr->status=status;
372 nlsr->adj_build_flag++;
373 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400374 }
akmhoqueb903ded2012-08-21 12:56:28 -0400375 else if(res == HT_NEW_ENTRY)
376 {
377 hashtb_delete(e);
378 }
akmhoque53f64222012-09-05 13:57:51 -0500379
akmhoque8a5babe2012-08-16 17:39:33 -0500380 hashtb_end(e);
381}
382
akmhoque3171d652012-11-13 11:44:33 -0600383
384void
385delete_nbr_from_adl(struct name_prefix *nbr)
386{
387 if ( nlsr->debugging )
388 printf("delete_nbr_from_adl called\n");
389 if ( nlsr->detailed_logging )
390 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n");
391
392 int res;
393 struct hashtb_enumerator ee;
394 struct hashtb_enumerator *e = &ee;
395
396 hashtb_start(nlsr->adl, e);
397 res = hashtb_seek(e, nbr->name, nbr->length, 0);
398
399
400 if (res == HT_OLD_ENTRY)
401 {
402 hashtb_delete(e);
403 }
404 else if(res == HT_NEW_ENTRY)
405 {
406 hashtb_delete(e);
407 }
408
409 hashtb_end(e);
410}
411
akmhoque8a5babe2012-08-16 17:39:33 -0500412void
akmhoque53f64222012-09-05 13:57:51 -0500413update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500414{
akmhoque7b791452012-10-30 11:24:56 -0500415 if ( nlsr->debugging )
416 printf("update_lsdb_synch_interval_to_adl called\n");
417 if ( nlsr->detailed_logging )
418 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500419
420 int res;
421 struct ndn_neighbor *nnbr;
422
423 struct hashtb_enumerator ee;
424 struct hashtb_enumerator *e = &ee;
425
426 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500427 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500428
akmhoque53f64222012-09-05 13:57:51 -0500429
430 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400431 {
432 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500433 if ( nnbr->lsdb_synch_interval!= interval )
434 {
435 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500436 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500437
akmhoque53f64222012-09-05 13:57:51 -0500438 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400439 }
akmhoqueb903ded2012-08-21 12:56:28 -0400440 else if(res == HT_NEW_ENTRY)
441 {
442 hashtb_delete(e);
443 }
akmhoque53f64222012-09-05 13:57:51 -0500444
akmhoque8a5babe2012-08-16 17:39:33 -0500445 hashtb_end(e);
446}
akmhoqued79438d2012-08-27 13:31:42 -0500447
akmhoque53f64222012-09-05 13:57:51 -0500448
akmhoque53f64222012-09-05 13:57:51 -0500449int
akmhoque03004e62012-09-06 01:12:28 -0500450no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500451{
akmhoque03004e62012-09-06 01:12:28 -0500452 int i, adl_element;
453 int no_link=0;
454 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500455 struct hashtb_enumerator ee;
456 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500457 hashtb_start(nlsr->adl, e);
458 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500459
akmhoque03004e62012-09-06 01:12:28 -0500460 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500461 {
akmhoque03004e62012-09-06 01:12:28 -0500462 nbr=e->data;
463 if( nbr->status == 1 )
464 no_link++;
465 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500466 }
akmhoque53f64222012-09-05 13:57:51 -0500467
akmhoqued79438d2012-08-27 13:31:42 -0500468 hashtb_end(e);
469
akmhoque03004e62012-09-06 01:12:28 -0500470 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500471
akmhoqued79438d2012-08-27 13:31:42 -0500472}
akmhoque53f64222012-09-05 13:57:51 -0500473
474int
475is_adj_lsa_build(void)
476{
477 int ret=0;
478
479 int nbr_count=0;
480
481 int i, adl_element;
482 struct ndn_neighbor *nbr;
483
484 struct hashtb_enumerator ee;
485 struct hashtb_enumerator *e = &ee;
486
487 hashtb_start(nlsr->adl, e);
488 adl_element=hashtb_n(nlsr->adl);
489
490 for(i=0;i<adl_element;i++)
491 {
492 nbr=e->data;
493 if(nbr->status == 1 )
494 {
495 nbr_count++;
496 }
akmhoque62c0c192012-09-24 07:49:25 -0500497 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 -0500498 {
499 nbr_count++;
500 }
501 hashtb_next(e);
502 }
503
504 hashtb_end(e);
505 if(nbr_count == adl_element)
506 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500507
akmhoque53f64222012-09-05 13:57:51 -0500508 return ret;
509}
510
akmhoque53f64222012-09-05 13:57:51 -0500511
512void
513get_active_nbr_adj_data(struct ccn_charbuf *c)
514{
515
516 int i, adl_element;
517 struct ndn_neighbor *nbr;
518 struct hashtb_enumerator ee;
519 struct hashtb_enumerator *e = &ee;
520 hashtb_start(nlsr->adl, e);
521 adl_element=hashtb_n(nlsr->adl);
522
523 for(i=0;i<adl_element;i++)
524 {
525 nbr=e->data;
526 if( nbr->status == 1 )
527 {
528 ccn_charbuf_append_string(c,nbr->neighbor->name);
529 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500530
akmhoque53f64222012-09-05 13:57:51 -0500531 char *temp_length=(char *)malloc(20);
532 memset(temp_length,0,20);
533 sprintf(temp_length,"%d",nbr->neighbor->length);
534 ccn_charbuf_append_string(c,temp_length);
535 free(temp_length);
536 ccn_charbuf_append_string(c,"|");
537
akmhoque866c2222013-02-12 10:49:33 -0600538 /*char *temp_face=(char *)malloc(20);
akmhoque53f64222012-09-05 13:57:51 -0500539 memset(temp_face,0,20);
540 sprintf(temp_face,"%d",nbr->face);
541 ccn_charbuf_append_string(c,temp_face);
542 free(temp_face);
543 ccn_charbuf_append_string(c,"|");
akmhoque866c2222013-02-12 10:49:33 -0600544 */
akmhoque53f64222012-09-05 13:57:51 -0500545
546 char *temp_metric=(char *)malloc(20);
547 memset(temp_metric,0,20);
548 sprintf(temp_metric,"%d",nbr->metric);
549 ccn_charbuf_append_string(c,temp_metric);
550 free(temp_metric);
551 ccn_charbuf_append_string(c,"|");
552
553 }
554 hashtb_next(e);
555 }
556
557 hashtb_end(e);
558}
559
akmhoque03004e62012-09-06 01:12:28 -0500560long int
561get_nbr_time_diff_lsdb_req(char *nbr)
562{
akmhoque7b791452012-10-30 11:24:56 -0500563 if ( nlsr->debugging )
564 printf("get_nbr_time_diff_lsdb_req called\n");
565 if ( nlsr->detailed_logging )
566 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_time_diff_lsdb_req called\n");
akmhoque03004e62012-09-06 01:12:28 -0500567
568 long int time_diff=get_lsdb_synch_interval(nbr)+1;
569 int res;
570 struct ndn_neighbor *nnbr;
571
572 struct hashtb_enumerator ee;
573 struct hashtb_enumerator *e = &ee;
574
575 hashtb_start(nlsr->adl, e);
576 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
577
578 if (res == HT_OLD_ENTRY)
579 {
580 nnbr=e->data;
581
582 if (nnbr->last_lsdb_requested == 0)
583 time_diff=get_lsdb_synch_interval(nbr)+1;
584 else time_diff=get_current_time_sec() - get_nbr_last_lsdb_requested(nbr);
585
586 }
587 else if(res == HT_NEW_ENTRY)
588 {
589 hashtb_delete(e);
590 }
591
592 hashtb_end(e);
593
594 return time_diff;
595}
596
597long int
598get_nbr_last_lsdb_requested(char *nbr)
599{
akmhoque7b791452012-10-30 11:24:56 -0500600 if ( nlsr->debugging )
601 printf("get_timed_out_number called\n");
602 if ( nlsr->detailed_logging )
603 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called\n");
akmhoque03004e62012-09-06 01:12:28 -0500604
605 long int last_lsdb_requested=0;
606
607 int res;
608 struct ndn_neighbor *nnbr;
609
610 struct hashtb_enumerator ee;
611 struct hashtb_enumerator *e = &ee;
612
613 hashtb_start(nlsr->adl, e);
614 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
615
616 if (res == HT_OLD_ENTRY)
617 {
618 nnbr=e->data;
619 last_lsdb_requested=nnbr->last_lsdb_requested;
620 }
621 else if(res == HT_NEW_ENTRY)
622 {
623 hashtb_delete(e);
624 }
625
626 hashtb_end(e);
627
628 return last_lsdb_requested;
629}
630
akmhoque14b3f342012-09-14 10:39:02 -0500631
632int
633get_nbr_random_time_component(char *nbr)
634{
akmhoque7b791452012-10-30 11:24:56 -0500635 if ( nlsr->debugging )
636 printf("get_nbr_random_time_component called\n");
637 if ( nlsr->detailed_logging )
638 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_random_time_component called\n");
akmhoque14b3f342012-09-14 10:39:02 -0500639
640 int time=0;
641
642 int res;
643 struct ndn_neighbor *nnbr;
644
645 struct hashtb_enumerator ee;
646 struct hashtb_enumerator *e = &ee;
647
648 hashtb_start(nlsr->adl, e);
649 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
650
651 if (res == HT_OLD_ENTRY)
652 {
653 nnbr=e->data;
akmhoque9fa58a82012-10-05 07:56:02 -0500654 time=nnbr->lsdb_random_time_component * (int)pow(-1,nnbr->lsdb_interest_timed_out+1);
akmhoque14b3f342012-09-14 10:39:02 -0500655 }
656 else if(res == HT_NEW_ENTRY)
657 {
658 hashtb_delete(e);
659 }
660
661 hashtb_end(e);
662
663 return time;
664}
665
akmhoque03004e62012-09-06 01:12:28 -0500666long int
667get_lsdb_synch_interval(char *nbr)
668{
akmhoque7b791452012-10-30 11:24:56 -0500669 if ( nlsr->debugging )
670 printf("get_lsdb_synch_interval called \n");
671 if ( nlsr->detailed_logging )
672 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_synch_interval called \n");
akmhoque03004e62012-09-06 01:12:28 -0500673
674 long int lsdb_synch_interval=300;
675
676
677 int res;
678 struct ndn_neighbor *nnbr;
679
680 struct hashtb_enumerator ee;
681 struct hashtb_enumerator *e = &ee;
682
683 hashtb_start(nlsr->adl, e);
684 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
685
686 if (res == HT_OLD_ENTRY)
687 {
688 nnbr=e->data;
689 lsdb_synch_interval=nnbr->lsdb_synch_interval;
690 }
691 else if(res == HT_NEW_ENTRY)
692 {
693 hashtb_delete(e);
694 }
695
696 hashtb_end(e);
697
698 return lsdb_synch_interval;
699
700}
701
akmhoque53f64222012-09-05 13:57:51 -0500702char *
703get_nbr_lsdb_version(char *nbr)
704{
akmhoque7b791452012-10-30 11:24:56 -0500705 if ( nlsr->debugging )
706 printf("get_nbr_lsdb_version called \n");
707 if ( nlsr->detailed_logging )
708 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_nbr_lsdb_version called \n");
akmhoque53f64222012-09-05 13:57:51 -0500709
710 char *version=NULL;
711
712 int res;
713 struct ndn_neighbor *nnbr;
714
715 struct hashtb_enumerator ee;
716 struct hashtb_enumerator *e = &ee;
717
718 hashtb_start(nlsr->adl, e);
719 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
akmhoque03004e62012-09-06 01:12:28 -0500720
akmhoque53f64222012-09-05 13:57:51 -0500721 if (res == HT_OLD_ENTRY)
722 {
723 nnbr=e->data;
724 version=(char *)malloc(strlen(nnbr->last_lsdb_version)+1);
725 memset(version,0,strlen(nnbr->last_lsdb_version)+1);
726 memcpy(version,nnbr->last_lsdb_version,strlen(nnbr->last_lsdb_version)+1);
727 }
728 else if(res == HT_NEW_ENTRY)
729 {
730 hashtb_delete(e);
731 }
732
733 hashtb_end(e);
734
735 return version;
736}
737
738void
739update_adjacent_last_lsdb_requested_to_adl(char *nbr, long int timestamp)
740{
akmhoque7b791452012-10-30 11:24:56 -0500741 if ( nlsr->debugging )
742 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
743 if ( nlsr->detailed_logging )
744 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called \n");
akmhoque53f64222012-09-05 13:57:51 -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->last_lsdb_requested=timestamp;
akmhoque03004e62012-09-06 01:12:28 -0500759
760 }
761 else if(res == HT_NEW_ENTRY)
762 {
763 hashtb_delete(e);
764 }
765
766 hashtb_end(e);
767}
768
769void
770set_is_lsdb_send_interest_scheduled_to_zero(char *nbr)
771{
akmhoque7b791452012-10-30 11:24:56 -0500772 if ( nlsr->debugging )
773 printf("set_is_lsdb_send_interest_scheduled_to_zero called \n");
774 if ( nlsr->detailed_logging )
775 writeLogg(__FILE__,__FUNCTION__,__LINE__,"set_is_lsdb_send_interest_scheduled_to_zero called\n");
776
akmhoque03004e62012-09-06 01:12:28 -0500777
778 int res;
779 struct ndn_neighbor *nnbr;
780
781 struct hashtb_enumerator ee;
782 struct hashtb_enumerator *e = &ee;
783
784 hashtb_start(nlsr->adl, e);
785 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
786
787 if (res == HT_OLD_ENTRY)
788 {
789 nnbr=e->data;
790 nnbr->is_lsdb_send_interest_scheduled=0;
791 }
792 else if(res == HT_NEW_ENTRY)
793 {
794 hashtb_delete(e);
795 }
796
797 hashtb_end(e);
798}
799
800void
801update_adjacent_lsdb_version_to_adl(struct name_prefix *nbr, char *version)
802{
akmhoque7b791452012-10-30 11:24:56 -0500803 if ( nlsr->debugging )
804 printf("update_adjacent_timed_out_to_adl called \n");
805 if ( nlsr->detailed_logging )
806 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called\n");
akmhoque03004e62012-09-06 01:12:28 -0500807
808 int res;
809 struct ndn_neighbor *nnbr;
810
811 struct hashtb_enumerator ee;
812 struct hashtb_enumerator *e = &ee;
813
814 hashtb_start(nlsr->adl, e);
815 res = hashtb_seek(e, nbr->name, nbr->length, 0);
816
817 if( res == HT_OLD_ENTRY )
818 {
819 nnbr=e->data;
820 free(nnbr->last_lsdb_version);
821 nnbr->last_lsdb_version=(char *)malloc(strlen(version)+1);
822 memset(nnbr->last_lsdb_version,0,strlen(version)+1);
823 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoque53f64222012-09-05 13:57:51 -0500824 }
825 else if(res == HT_NEW_ENTRY)
826 {
827 hashtb_delete(e);
828 }
829
830 hashtb_end(e);
831
832}
833
834void
835adjust_adjacent_last_lsdb_requested_to_adl(char *nbr, long int sec)
836{
837 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
838
akmhoque7b791452012-10-30 11:24:56 -0500839 if ( nlsr->debugging )
840 printf("update_adjacent_last_lsdb_requested_to_adl called \n");
841 if ( nlsr->detailed_logging )
842 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_last_lsdb_requested_to_adl called\n");
843
844
akmhoque53f64222012-09-05 13:57:51 -0500845 int res;
846 struct ndn_neighbor *nnbr;
847
848 struct hashtb_enumerator ee;
849 struct hashtb_enumerator *e = &ee;
850
851 hashtb_start(nlsr->adl, e);
852 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
853
854 if( res == HT_OLD_ENTRY )
855 {
856 nnbr=e->data;
857 nnbr->last_lsdb_requested=nnbr->last_lsdb_requested-sec;
akmhoque03004e62012-09-06 01:12:28 -0500858
akmhoque53f64222012-09-05 13:57:51 -0500859 }
860 else if(res == HT_NEW_ENTRY)
861 {
862 hashtb_delete(e);
863 }
864
865 hashtb_end(e);
866
867}
868
akmhoquefbfd0982012-09-09 20:59:03 -0500869int
870get_next_hop_face_from_adl(char *nbr)
871{
872 int res;
873 int connecting_face=NO_FACE;
874 struct ndn_neighbor *nnbr;
875
876 struct hashtb_enumerator ee;
877 struct hashtb_enumerator *e = &ee;
878
879 hashtb_start(nlsr->adl, e);
880 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
881
882 if( res == HT_OLD_ENTRY )
883 {
884 nnbr=e->data;
885 connecting_face=nnbr->face;
886
887 }
888 else if(res == HT_NEW_ENTRY)
889 {
890 hashtb_delete(e);
891 }
892
893 hashtb_end(e);
894 return connecting_face;
895}
896
akmhoqueb77b95f2013-02-08 12:28:47 -0600897void
898update_face_to_adl_for_nbr(char *nbr, int face)
899{
900 int res;
901 struct ndn_neighbor *nnbr;
902
903 struct hashtb_enumerator ee;
904 struct hashtb_enumerator *e = &ee;
905
906 hashtb_start(nlsr->adl, e);
907 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
908
909 if( res == HT_OLD_ENTRY )
910 {
911 nnbr=e->data;
912 nnbr->face=face;
913
914 }
915 else if(res == HT_NEW_ENTRY)
916 {
917 hashtb_delete(e);
918 }
919
920 hashtb_end(e);
921}
922
akmhoquede61ba92012-09-20 22:19:12 -0500923int
924is_neighbor(char *nbr)
925{
926 int ret=0;
927
928 int res;
929 struct hashtb_enumerator ee;
930 struct hashtb_enumerator *e = &ee;
931
932 hashtb_start(nlsr->adl, e);
933 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
934
935 if( res == HT_OLD_ENTRY )
936 {
937 ret=1;
938 }
939 else if(res == HT_NEW_ENTRY)
940 {
941 hashtb_delete(e);
942 }
943
944 hashtb_end(e);
945
946 return ret;
947}
akmhoque53f64222012-09-05 13:57:51 -0500948
akmhoqueb77b95f2013-02-08 12:28:47 -0600949int
950is_active_neighbor(char *nbr)
951{
952 int ret=0;
953
954 int res;
955 struct hashtb_enumerator ee;
956 struct hashtb_enumerator *e = &ee;
957
958 hashtb_start(nlsr->adl, e);
959 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
960
961 if( res == HT_OLD_ENTRY )
962 {
963 struct ndn_neighbor *nnbr;
964 nnbr=e->data;
965 if (nnbr->status == NBR_ACTIVE )
966 {
967 ret=1;
968 }
969 }
970 else if(res == HT_NEW_ENTRY)
971 {
972 hashtb_delete(e);
973 }
974
975 hashtb_end(e);
976
977 return ret;
978}
979
akmhoqueccb33e92013-02-20 11:44:28 -0600980
981void
982get_host_name_from_command_string(struct name_prefix *name_part,
983 char *nbr_name_uri, int offset)
984{
985
986
987
988 int res,i;
989 int len=0;
990 const unsigned char *comp_ptr1;
991 size_t comp_size;
992
993 struct ccn_charbuf *name=ccn_charbuf_create();
994 name = ccn_charbuf_create();
995 res = ccn_name_from_uri(name,nbr_name_uri);
996 if (res < 0) {
997 fprintf(stderr, "Bad ccn URI: %s\n", nbr_name_uri);
998 exit(1);
999 }
1000
1001 struct ccn_indexbuf cid={0};
1002
1003 struct ccn_indexbuf *components=&cid;
1004 ccn_name_split (name, components);
1005
1006 for(i=components->n-2;i> (0+offset);i--)
1007 {
1008 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
1009 len+=1;
1010 len+=(int)comp_size;
1011 }
1012 len++;
1013
1014 char *neighbor=(char *)malloc(len);
1015 memset(neighbor,0,len);
1016
1017 for(i=components->n-2;i> (0+offset);i--)
1018 {
1019 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
1020 if ( i != components->n-2)
1021 memcpy(neighbor+strlen(neighbor),".",1);
1022 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,
1023 strlen((char *)comp_ptr1));
1024
1025 }
1026
1027 name_part->name=(char *)malloc(strlen(neighbor)+1);
1028 memset(name_part->name,0,strlen(neighbor)+1);
1029 memcpy(name_part->name,neighbor,strlen(neighbor)+1);
1030 name_part->length=strlen(neighbor)+1;
1031
1032 // 01/31/2013
1033 free(neighbor);
1034 ccn_charbuf_destroy(&name);
1035}
1036
1037