blob: 3a68ce1a0398329181ae186b646018d139a819c7 [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{
akmhoque6682ca32013-02-22 00:29:35 -060034 struct ndn_neighbor *nbr;
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
akmhoque6682ca32013-02-22 00:29:35 -060048 nbr->neighbor=(struct name_prefix *)malloc(sizeof( struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -050049 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
akmhoque6682ca32013-02-22 00:29:35 -060061 nbr->ip_address=(char *)calloc(strlen(ip)+1,sizeof(char));
62 memcpy(nbr->ip_address,ip,strlen(ip)+1);
akmhoque8a5babe2012-08-16 17:39:33 -050063
akmhoque03004e62012-09-06 01:12:28 -050064 char *time_stamp=(char *)malloc(20);
65 get_current_timestamp_micro(time_stamp);
akmhoque6682ca32013-02-22 00:29:35 -060066 nbr->last_lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
akmhoque53f64222012-09-05 13:57:51 -050067 memcpy(nbr->last_lsdb_version,time_stamp,strlen(time_stamp)+1);
akmhoque6682ca32013-02-22 00:29:35 -060068 memset(nbr->last_lsdb_version,'0',strlen(time_stamp)+1);
69 nbr->last_info_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -050070 memcpy(nbr->last_info_version,time_stamp,strlen(time_stamp)+1);
akmhoque6682ca32013-02-22 00:29:35 -060071 memset(nbr->last_info_version,'0',strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -050072 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050073
74 nbr->last_lsdb_requested=0;
akmhoquee7c4b6d2012-08-21 12:30:25 -040075 }
akmhoque53f64222012-09-05 13:57:51 -050076
akmhoque8a5babe2012-08-16 17:39:33 -050077 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -050078}
akmhoque8a5babe2012-08-16 17:39:33 -050079
akmhoque03004e62012-09-06 01:12:28 -050080
akmhoque53f64222012-09-05 13:57:51 -050081void
82print_adjacent(struct ndn_neighbor *nbr)
83{
akmhoque7b791452012-10-30 11:24:56 -050084 if ( nlsr->debugging )
85 {
86 printf("print_adjacent called\n");
87 printf("--------Neighbor---------------------------\n");
88 printf(" Neighbor: %s \n",nbr->neighbor->name);
89 printf(" Length : %d \n",nbr->neighbor->length);
akmhoqueb77b95f2013-02-08 12:28:47 -060090 printf(" Ip Address: %s \n",nbr->ip_address);
akmhoque7b791452012-10-30 11:24:56 -050091 printf(" Face : %d \n",nbr->face);
92 printf(" Metric : %d \n",nbr->metric);
93 printf(" Status : %d \n",nbr->status);
94 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
95 printf(" Info Version: %s \n",nbr->last_info_version);
96 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
97 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
98 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
99 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
100 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
101 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
akmhoque03004e62012-09-06 01:12:28 -0500102
akmhoque7b791452012-10-30 11:24:56 -0500103 printf("\n");
104 }
105
106 if ( nlsr->detailed_logging )
107 {
108
109 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n");
110 writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n");
111 writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name);
112 writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length);
113 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face);
114 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric);
115 writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status);
116 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version);
117 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version);
118 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
119 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
120 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
121 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
122 writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
123 writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
124
125 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
126 }
akmhoque8a5babe2012-08-16 17:39:33 -0500127
128}
129
130void
131print_adjacent_from_adl(void)
132{
akmhoque7b791452012-10-30 11:24:56 -0500133 if ( nlsr->debugging )
134 printf("print_adjacent_from_adl called \n");
135 if ( nlsr->detailed_logging )
136 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n");
137
akmhoque8a5babe2012-08-16 17:39:33 -0500138 int i, adl_element;
139 struct ndn_neighbor *nbr;
140
141 struct hashtb_enumerator ee;
142 struct hashtb_enumerator *e = &ee;
143
144 hashtb_start(nlsr->adl, e);
145 adl_element=hashtb_n(nlsr->adl);
146
147 for(i=0;i<adl_element;i++)
148 {
149 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500150 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500151 hashtb_next(e);
152 }
153
154 hashtb_end(e);
155
akmhoque8a5babe2012-08-16 17:39:33 -0500156}
157
akmhoque03004e62012-09-06 01:12:28 -0500158int
159get_adjacent_status(struct name_prefix *nbr)
160{
akmhoque7b791452012-10-30 11:24:56 -0500161
162 if ( nlsr->debugging )
163 printf("get_adjacent_status called \n");
164 if ( nlsr->detailed_logging )
165 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n");
akmhoque03004e62012-09-06 01:12:28 -0500166
167 int res;
168 int status=-1;
169 struct ndn_neighbor *nnbr;
170
171 struct hashtb_enumerator ee;
172 struct hashtb_enumerator *e = &ee;
173
174 hashtb_start(nlsr->adl, e);
175 res = hashtb_seek(e, nbr->name, nbr->length, 0);
176
177 if (res == HT_OLD_ENTRY)
178 {
179 nnbr=e->data;
180 status=nnbr->status;
181 }
182 else if(res == HT_NEW_ENTRY)
183 {
184 hashtb_delete(e);
185 }
186
187 hashtb_end(e);
188
189 return status;
190
191}
192
193int
194get_timed_out_number(struct name_prefix *nbr)
195{
akmhoque7b791452012-10-30 11:24:56 -0500196
197 if ( nlsr->debugging )
198 printf("get_timed_out_number called \n");
199 if ( nlsr->detailed_logging )
200 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n");
201
akmhoque03004e62012-09-06 01:12:28 -0500202
203 int res,ret=-1;
204 struct ndn_neighbor *nnbr;
205
206 struct hashtb_enumerator ee;
207 struct hashtb_enumerator *e = &ee;
208
209 hashtb_start(nlsr->adl, e);
210 res = hashtb_seek(e, nbr->name, nbr->length, 0);
211
212 if( res == HT_OLD_ENTRY )
213 {
214 nnbr=e->data;
215 ret=nnbr->info_interest_timed_out;
216 }
217 else if(res == HT_NEW_ENTRY)
218 {
219 hashtb_delete(e);
220 }
221
222 hashtb_end(e);
223
224 return ret;
225}
226
akmhoque14b3f342012-09-14 10:39:02 -0500227int
228get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
229{
akmhoque7b791452012-10-30 11:24:56 -0500230
231 if ( nlsr->debugging )
232 printf("get_lsdb_interest_timed_out_number called \n");
233 if ( nlsr->detailed_logging )
234 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500235
236 int res,ret=-1;
237 struct ndn_neighbor *nnbr;
238
239 struct hashtb_enumerator ee;
240 struct hashtb_enumerator *e = &ee;
241
242 hashtb_start(nlsr->adl, e);
243 res = hashtb_seek(e, nbr->name, nbr->length, 0);
244
245 if( res == HT_OLD_ENTRY )
246 {
247 nnbr=e->data;
248 ret=nnbr->lsdb_interest_timed_out;
249 }
250 else if(res == HT_NEW_ENTRY)
251 {
252 hashtb_delete(e);
253 }
254
255 hashtb_end(e);
256
257 return ret;
258}
akmhoque03004e62012-09-06 01:12:28 -0500259
260void
261update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
262{
akmhoque7b791452012-10-30 11:24:56 -0500263 if ( nlsr->debugging )
264 printf("update_adjacent_timed_out_to_adl called \n");
265 if ( nlsr->detailed_logging )
266 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500267
268 int res;
269 struct ndn_neighbor *nnbr;
270
271 struct hashtb_enumerator ee;
272 struct hashtb_enumerator *e = &ee;
273
274 hashtb_start(nlsr->adl, e);
275 res = hashtb_seek(e, nbr->name, nbr->length, 0);
276
277 if( res == HT_OLD_ENTRY )
278 {
279 nnbr=e->data;
280 nnbr->info_interest_timed_out += increment;
281 }
282 else if(res == HT_NEW_ENTRY)
283 {
284 hashtb_delete(e);
285 }
286
287 hashtb_end(e);
288}
289
290void
291update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
292{
akmhoque7b791452012-10-30 11:24:56 -0500293 if ( nlsr->debugging )
294 printf("update_adjacent_timed_out_zero_to_adl called \n");
295 if ( nlsr->detailed_logging )
296 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n");
297
akmhoque03004e62012-09-06 01:12:28 -0500298 int time_out_number=get_timed_out_number(nbr);
299 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
300
301}
302
akmhoque14b3f342012-09-14 10:39:02 -0500303
304void
305update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
306{
akmhoque7b791452012-10-30 11:24:56 -0500307 if ( nlsr->debugging )
308 printf("update_lsdb_interest_timed_out_to_adl called\n");
309 if ( nlsr->detailed_logging )
310 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500311
312 int res;
313 struct ndn_neighbor *nnbr;
314
315 struct hashtb_enumerator ee;
316 struct hashtb_enumerator *e = &ee;
317
318 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500319
akmhoque14b3f342012-09-14 10:39:02 -0500320 res = hashtb_seek(e, nbr->name, nbr->length, 0);
321
322 if( res == HT_OLD_ENTRY )
323 {
324 nnbr=e->data;
325 nnbr->lsdb_interest_timed_out += increment;
326 }
327 else if(res == HT_NEW_ENTRY)
328 {
329 hashtb_delete(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600330 }
akmhoque14b3f342012-09-14 10:39:02 -0500331 hashtb_end(e);
332}
333
334void
335update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
336{
akmhoque7b791452012-10-30 11:24:56 -0500337 if ( nlsr->debugging )
338 printf("update_adjacent_timed_out_zero_to_adl called\n");
339 if ( nlsr->detailed_logging )
340 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n");
341
akmhoque14b3f342012-09-14 10:39:02 -0500342 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
343 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
344
345}
346
akmhoque8a5babe2012-08-16 17:39:33 -0500347void
akmhoque53f64222012-09-05 13:57:51 -0500348update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500349{
akmhoque7b791452012-10-30 11:24:56 -0500350 if ( nlsr->debugging )
351 printf("update_adjacent_status_to_adl called\n");
352 if ( nlsr->detailed_logging )
353 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500354
akmhoque8a5babe2012-08-16 17:39:33 -0500355 int res;
356 struct ndn_neighbor *nnbr;
357
358 struct hashtb_enumerator ee;
359 struct hashtb_enumerator *e = &ee;
360
361 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500362 res = hashtb_seek(e, nbr->name, nbr->length, 0);
363
akmhoque918ff9a2012-08-21 11:34:49 -0400364
akmhoquee7c4b6d2012-08-21 12:30:25 -0400365 if (res == HT_OLD_ENTRY)
366 {
367 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500368 if ( nnbr->status!=status )
369 {
370 nnbr->status=status;
371 nlsr->adj_build_flag++;
372 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400373 }
akmhoqueb903ded2012-08-21 12:56:28 -0400374 else if(res == HT_NEW_ENTRY)
375 {
376 hashtb_delete(e);
377 }
akmhoque53f64222012-09-05 13:57:51 -0500378
akmhoque8a5babe2012-08-16 17:39:33 -0500379 hashtb_end(e);
380}
381
akmhoque3171d652012-11-13 11:44:33 -0600382
383void
384delete_nbr_from_adl(struct name_prefix *nbr)
385{
386 if ( nlsr->debugging )
387 printf("delete_nbr_from_adl called\n");
388 if ( nlsr->detailed_logging )
389 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n");
390
391 int res;
392 struct hashtb_enumerator ee;
393 struct hashtb_enumerator *e = &ee;
394
395 hashtb_start(nlsr->adl, e);
396 res = hashtb_seek(e, nbr->name, nbr->length, 0);
397
398
399 if (res == HT_OLD_ENTRY)
400 {
akmhoque6682ca32013-02-22 00:29:35 -0600401 struct ndn_neighbor *nbr=e->data;
akmhoquee6f98a12013-02-22 10:33:26 -0600402 /*free(nbr->neighbor->name);
akmhoque6682ca32013-02-22 00:29:35 -0600403 free(nbr->neighbor);
404 free(nbr->last_lsdb_version);
405 free(nbr->last_info_version);
406 free(nbr->ip_address);
akmhoquee6f98a12013-02-22 10:33:26 -0600407 */
408 destroy_nbr_component(nbr);
akmhoque6682ca32013-02-22 00:29:35 -0600409 hashtb_delete(e);
410
akmhoque3171d652012-11-13 11:44:33 -0600411 }
412 else if(res == HT_NEW_ENTRY)
413 {
414 hashtb_delete(e);
415 }
416
417 hashtb_end(e);
418}
419
akmhoque8a5babe2012-08-16 17:39:33 -0500420void
akmhoque53f64222012-09-05 13:57:51 -0500421update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500422{
akmhoque7b791452012-10-30 11:24:56 -0500423 if ( nlsr->debugging )
424 printf("update_lsdb_synch_interval_to_adl called\n");
425 if ( nlsr->detailed_logging )
426 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500427
428 int res;
429 struct ndn_neighbor *nnbr;
430
431 struct hashtb_enumerator ee;
432 struct hashtb_enumerator *e = &ee;
433
434 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500435 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500436
akmhoque53f64222012-09-05 13:57:51 -0500437
438 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400439 {
440 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500441 if ( nnbr->lsdb_synch_interval!= interval )
442 {
443 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500444 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500445
akmhoque53f64222012-09-05 13:57:51 -0500446 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400447 }
akmhoqueb903ded2012-08-21 12:56:28 -0400448 else if(res == HT_NEW_ENTRY)
449 {
450 hashtb_delete(e);
451 }
akmhoque53f64222012-09-05 13:57:51 -0500452
akmhoque8a5babe2012-08-16 17:39:33 -0500453 hashtb_end(e);
454}
akmhoqued79438d2012-08-27 13:31:42 -0500455
akmhoque53f64222012-09-05 13:57:51 -0500456
akmhoque53f64222012-09-05 13:57:51 -0500457int
akmhoque03004e62012-09-06 01:12:28 -0500458no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500459{
akmhoque03004e62012-09-06 01:12:28 -0500460 int i, adl_element;
461 int no_link=0;
462 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500463 struct hashtb_enumerator ee;
464 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500465 hashtb_start(nlsr->adl, e);
466 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500467
akmhoque03004e62012-09-06 01:12:28 -0500468 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500469 {
akmhoque03004e62012-09-06 01:12:28 -0500470 nbr=e->data;
471 if( nbr->status == 1 )
472 no_link++;
473 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500474 }
akmhoque53f64222012-09-05 13:57:51 -0500475
akmhoqued79438d2012-08-27 13:31:42 -0500476 hashtb_end(e);
477
akmhoque03004e62012-09-06 01:12:28 -0500478 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500479
akmhoqued79438d2012-08-27 13:31:42 -0500480}
akmhoque53f64222012-09-05 13:57:51 -0500481
482int
483is_adj_lsa_build(void)
484{
485 int ret=0;
486
487 int nbr_count=0;
488
489 int i, adl_element;
490 struct ndn_neighbor *nbr;
491
492 struct hashtb_enumerator ee;
493 struct hashtb_enumerator *e = &ee;
494
495 hashtb_start(nlsr->adl, e);
496 adl_element=hashtb_n(nlsr->adl);
497
498 for(i=0;i<adl_element;i++)
499 {
500 nbr=e->data;
501 if(nbr->status == 1 )
502 {
503 nbr_count++;
504 }
akmhoque62c0c192012-09-24 07:49:25 -0500505 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 -0500506 {
507 nbr_count++;
508 }
509 hashtb_next(e);
510 }
511
512 hashtb_end(e);
513 if(nbr_count == adl_element)
514 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500515
akmhoque53f64222012-09-05 13:57:51 -0500516 return ret;
517}
518
akmhoque53f64222012-09-05 13:57:51 -0500519
520void
521get_active_nbr_adj_data(struct ccn_charbuf *c)
522{
523
524 int i, adl_element;
525 struct ndn_neighbor *nbr;
526 struct hashtb_enumerator ee;
527 struct hashtb_enumerator *e = &ee;
528 hashtb_start(nlsr->adl, e);
529 adl_element=hashtb_n(nlsr->adl);
530
531 for(i=0;i<adl_element;i++)
532 {
533 nbr=e->data;
534 if( nbr->status == 1 )
535 {
536 ccn_charbuf_append_string(c,nbr->neighbor->name);
537 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500538
akmhoque53f64222012-09-05 13:57:51 -0500539 char *temp_length=(char *)malloc(20);
540 memset(temp_length,0,20);
541 sprintf(temp_length,"%d",nbr->neighbor->length);
542 ccn_charbuf_append_string(c,temp_length);
543 free(temp_length);
544 ccn_charbuf_append_string(c,"|");
545
akmhoque53f64222012-09-05 13:57:51 -0500546 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
akmhoque53f64222012-09-05 13:57:51 -0500560
akmhoquefbfd0982012-09-09 20:59:03 -0500561int
562get_next_hop_face_from_adl(char *nbr)
563{
564 int res;
565 int connecting_face=NO_FACE;
566 struct ndn_neighbor *nnbr;
567
568 struct hashtb_enumerator ee;
569 struct hashtb_enumerator *e = &ee;
570
571 hashtb_start(nlsr->adl, e);
572 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
573
574 if( res == HT_OLD_ENTRY )
575 {
576 nnbr=e->data;
577 connecting_face=nnbr->face;
578
579 }
580 else if(res == HT_NEW_ENTRY)
581 {
582 hashtb_delete(e);
583 }
584
585 hashtb_end(e);
586 return connecting_face;
587}
588
akmhoqueb77b95f2013-02-08 12:28:47 -0600589void
590update_face_to_adl_for_nbr(char *nbr, int face)
591{
592 int res;
593 struct ndn_neighbor *nnbr;
594
595 struct hashtb_enumerator ee;
596 struct hashtb_enumerator *e = &ee;
597
598 hashtb_start(nlsr->adl, e);
599 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
600
601 if( res == HT_OLD_ENTRY )
602 {
603 nnbr=e->data;
604 nnbr->face=face;
605
606 }
607 else if(res == HT_NEW_ENTRY)
608 {
609 hashtb_delete(e);
610 }
611
612 hashtb_end(e);
613}
614
akmhoquede61ba92012-09-20 22:19:12 -0500615int
616is_neighbor(char *nbr)
617{
618 int ret=0;
619
620 int res;
621 struct hashtb_enumerator ee;
622 struct hashtb_enumerator *e = &ee;
623
624 hashtb_start(nlsr->adl, e);
625 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
626
627 if( res == HT_OLD_ENTRY )
628 {
629 ret=1;
630 }
631 else if(res == HT_NEW_ENTRY)
632 {
633 hashtb_delete(e);
634 }
635
636 hashtb_end(e);
637
638 return ret;
639}
akmhoque53f64222012-09-05 13:57:51 -0500640
akmhoqueb77b95f2013-02-08 12:28:47 -0600641int
642is_active_neighbor(char *nbr)
643{
644 int ret=0;
645
646 int res;
647 struct hashtb_enumerator ee;
648 struct hashtb_enumerator *e = &ee;
649
650 hashtb_start(nlsr->adl, e);
651 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
652
653 if( res == HT_OLD_ENTRY )
654 {
655 struct ndn_neighbor *nnbr;
656 nnbr=e->data;
657 if (nnbr->status == NBR_ACTIVE )
658 {
659 ret=1;
660 }
661 }
662 else if(res == HT_NEW_ENTRY)
663 {
664 hashtb_delete(e);
665 }
666
667 hashtb_end(e);
668
669 return ret;
670}
671
akmhoqueccb33e92013-02-20 11:44:28 -0600672
673void
674get_host_name_from_command_string(struct name_prefix *name_part,
675 char *nbr_name_uri, int offset)
676{
677
678
679
680 int res,i;
681 int len=0;
682 const unsigned char *comp_ptr1;
683 size_t comp_size;
684
685 struct ccn_charbuf *name=ccn_charbuf_create();
686 name = ccn_charbuf_create();
687 res = ccn_name_from_uri(name,nbr_name_uri);
688 if (res < 0) {
689 fprintf(stderr, "Bad ccn URI: %s\n", nbr_name_uri);
690 exit(1);
691 }
692
693 struct ccn_indexbuf cid={0};
694
695 struct ccn_indexbuf *components=&cid;
696 ccn_name_split (name, components);
697
698 for(i=components->n-2;i> (0+offset);i--)
699 {
700 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
701 len+=1;
702 len+=(int)comp_size;
703 }
704 len++;
705
706 char *neighbor=(char *)malloc(len);
707 memset(neighbor,0,len);
708
709 for(i=components->n-2;i> (0+offset);i--)
710 {
711 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
712 if ( i != components->n-2)
713 memcpy(neighbor+strlen(neighbor),".",1);
714 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,
715 strlen((char *)comp_ptr1));
716
717 }
718
akmhoque6682ca32013-02-22 00:29:35 -0600719 name_part->name=(char *)calloc(strlen(neighbor)+1,sizeof(char));
akmhoqueccb33e92013-02-20 11:44:28 -0600720 memcpy(name_part->name,neighbor,strlen(neighbor)+1);
721 name_part->length=strlen(neighbor)+1;
722
723 // 01/31/2013
724 free(neighbor);
725 ccn_charbuf_destroy(&name);
726}
727
728
akmhoquee6f98a12013-02-22 10:33:26 -0600729void
730destroy_nbr_component(struct ndn_neighbor *nbr)
731{
732 if ( nbr->neighbor->name )
733 free(nbr->neighbor->name);
734 if ( nbr->neighbor )
735 free(nbr->neighbor);
736 if ( nbr->last_lsdb_version)
737 free(nbr->last_lsdb_version);
738 if ( nbr->last_info_version)
739 free(nbr->last_info_version);
740 if ( nbr->ip_address)
741 free(nbr->ip_address);
742}
743
744void
745destroy_adl(void)
746{
747 int i, adl_element;
748 struct ndn_neighbor *nbr;
749
750 struct hashtb_enumerator ee;
751 struct hashtb_enumerator *e = &ee;
752
753 hashtb_start(nlsr->adl, e);
754 adl_element=hashtb_n(nlsr->adl);
755
756 for(i=0;i<adl_element;i++)
757 {
758 nbr=e->data;
759 destroy_nbr_component(nbr);
760 hashtb_next(e);
761 }
762
763 hashtb_end(e);
764
765 if( nlsr->adl )
766 hashtb_destroy(&nlsr->adl);
767
768}
769
770