blob: 6076f8979d29376661667d4f088cdbb854a9db41 [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;
402 free(nbr->neighbor->name);
403 free(nbr->neighbor);
404 free(nbr->last_lsdb_version);
405 free(nbr->last_info_version);
406 free(nbr->ip_address);
407 hashtb_delete(e);
408
akmhoque3171d652012-11-13 11:44:33 -0600409 }
410 else if(res == HT_NEW_ENTRY)
411 {
412 hashtb_delete(e);
413 }
414
415 hashtb_end(e);
416}
417
akmhoque8a5babe2012-08-16 17:39:33 -0500418void
akmhoque53f64222012-09-05 13:57:51 -0500419update_lsdb_synch_interval_to_adl(struct name_prefix *nbr, long int interval)
akmhoque8a5babe2012-08-16 17:39:33 -0500420{
akmhoque7b791452012-10-30 11:24:56 -0500421 if ( nlsr->debugging )
422 printf("update_lsdb_synch_interval_to_adl called\n");
423 if ( nlsr->detailed_logging )
424 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_synch_interval_to_adl called \n");
akmhoque8a5babe2012-08-16 17:39:33 -0500425
426 int res;
427 struct ndn_neighbor *nnbr;
428
429 struct hashtb_enumerator ee;
430 struct hashtb_enumerator *e = &ee;
431
432 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500433 res = hashtb_seek(e, nbr->name, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500434
akmhoque53f64222012-09-05 13:57:51 -0500435
436 if (res == HT_OLD_ENTRY)
akmhoquee7c4b6d2012-08-21 12:30:25 -0400437 {
438 nnbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500439 if ( nnbr->lsdb_synch_interval!= interval )
440 {
441 nnbr->lsdb_synch_interval=interval;
akmhoque14b3f342012-09-14 10:39:02 -0500442 nnbr->lsdb_random_time_component=(int)(interval/2);
akmhoque03004e62012-09-06 01:12:28 -0500443
akmhoque53f64222012-09-05 13:57:51 -0500444 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400445 }
akmhoqueb903ded2012-08-21 12:56:28 -0400446 else if(res == HT_NEW_ENTRY)
447 {
448 hashtb_delete(e);
449 }
akmhoque53f64222012-09-05 13:57:51 -0500450
akmhoque8a5babe2012-08-16 17:39:33 -0500451 hashtb_end(e);
452}
akmhoqued79438d2012-08-27 13:31:42 -0500453
akmhoque53f64222012-09-05 13:57:51 -0500454
akmhoque53f64222012-09-05 13:57:51 -0500455int
akmhoque03004e62012-09-06 01:12:28 -0500456no_active_nbr(void)
akmhoque53f64222012-09-05 13:57:51 -0500457{
akmhoque03004e62012-09-06 01:12:28 -0500458 int i, adl_element;
459 int no_link=0;
460 struct ndn_neighbor *nbr;
akmhoqued79438d2012-08-27 13:31:42 -0500461 struct hashtb_enumerator ee;
462 struct hashtb_enumerator *e = &ee;
akmhoque03004e62012-09-06 01:12:28 -0500463 hashtb_start(nlsr->adl, e);
464 adl_element=hashtb_n(nlsr->adl);
akmhoqued79438d2012-08-27 13:31:42 -0500465
akmhoque03004e62012-09-06 01:12:28 -0500466 for(i=0;i<adl_element;i++)
akmhoqued79438d2012-08-27 13:31:42 -0500467 {
akmhoque03004e62012-09-06 01:12:28 -0500468 nbr=e->data;
469 if( nbr->status == 1 )
470 no_link++;
471 hashtb_next(e);
akmhoqued79438d2012-08-27 13:31:42 -0500472 }
akmhoque53f64222012-09-05 13:57:51 -0500473
akmhoqued79438d2012-08-27 13:31:42 -0500474 hashtb_end(e);
475
akmhoque03004e62012-09-06 01:12:28 -0500476 return no_link;
akmhoque53f64222012-09-05 13:57:51 -0500477
akmhoqued79438d2012-08-27 13:31:42 -0500478}
akmhoque53f64222012-09-05 13:57:51 -0500479
480int
481is_adj_lsa_build(void)
482{
483 int ret=0;
484
485 int nbr_count=0;
486
487 int i, adl_element;
488 struct ndn_neighbor *nbr;
489
490 struct hashtb_enumerator ee;
491 struct hashtb_enumerator *e = &ee;
492
493 hashtb_start(nlsr->adl, e);
494 adl_element=hashtb_n(nlsr->adl);
495
496 for(i=0;i<adl_element;i++)
497 {
498 nbr=e->data;
499 if(nbr->status == 1 )
500 {
501 nbr_count++;
502 }
akmhoque62c0c192012-09-24 07:49:25 -0500503 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 -0500504 {
505 nbr_count++;
506 }
507 hashtb_next(e);
508 }
509
510 hashtb_end(e);
511 if(nbr_count == adl_element)
512 ret=1;
akmhoque03004e62012-09-06 01:12:28 -0500513
akmhoque53f64222012-09-05 13:57:51 -0500514 return ret;
515}
516
akmhoque53f64222012-09-05 13:57:51 -0500517
518void
519get_active_nbr_adj_data(struct ccn_charbuf *c)
520{
521
522 int i, adl_element;
523 struct ndn_neighbor *nbr;
524 struct hashtb_enumerator ee;
525 struct hashtb_enumerator *e = &ee;
526 hashtb_start(nlsr->adl, e);
527 adl_element=hashtb_n(nlsr->adl);
528
529 for(i=0;i<adl_element;i++)
530 {
531 nbr=e->data;
532 if( nbr->status == 1 )
533 {
534 ccn_charbuf_append_string(c,nbr->neighbor->name);
535 ccn_charbuf_append_string(c,"|");
akmhoque03004e62012-09-06 01:12:28 -0500536
akmhoque53f64222012-09-05 13:57:51 -0500537 char *temp_length=(char *)malloc(20);
538 memset(temp_length,0,20);
539 sprintf(temp_length,"%d",nbr->neighbor->length);
540 ccn_charbuf_append_string(c,temp_length);
541 free(temp_length);
542 ccn_charbuf_append_string(c,"|");
543
akmhoque53f64222012-09-05 13:57:51 -0500544 char *temp_metric=(char *)malloc(20);
545 memset(temp_metric,0,20);
546 sprintf(temp_metric,"%d",nbr->metric);
547 ccn_charbuf_append_string(c,temp_metric);
548 free(temp_metric);
549 ccn_charbuf_append_string(c,"|");
550
551 }
552 hashtb_next(e);
553 }
554
555 hashtb_end(e);
556}
557
akmhoque53f64222012-09-05 13:57:51 -0500558
akmhoquefbfd0982012-09-09 20:59:03 -0500559int
560get_next_hop_face_from_adl(char *nbr)
561{
562 int res;
563 int connecting_face=NO_FACE;
564 struct ndn_neighbor *nnbr;
565
566 struct hashtb_enumerator ee;
567 struct hashtb_enumerator *e = &ee;
568
569 hashtb_start(nlsr->adl, e);
570 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
571
572 if( res == HT_OLD_ENTRY )
573 {
574 nnbr=e->data;
575 connecting_face=nnbr->face;
576
577 }
578 else if(res == HT_NEW_ENTRY)
579 {
580 hashtb_delete(e);
581 }
582
583 hashtb_end(e);
584 return connecting_face;
585}
586
akmhoqueb77b95f2013-02-08 12:28:47 -0600587void
588update_face_to_adl_for_nbr(char *nbr, int face)
589{
590 int res;
591 struct ndn_neighbor *nnbr;
592
593 struct hashtb_enumerator ee;
594 struct hashtb_enumerator *e = &ee;
595
596 hashtb_start(nlsr->adl, e);
597 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
598
599 if( res == HT_OLD_ENTRY )
600 {
601 nnbr=e->data;
602 nnbr->face=face;
603
604 }
605 else if(res == HT_NEW_ENTRY)
606 {
607 hashtb_delete(e);
608 }
609
610 hashtb_end(e);
611}
612
akmhoquede61ba92012-09-20 22:19:12 -0500613int
614is_neighbor(char *nbr)
615{
616 int ret=0;
617
618 int res;
619 struct hashtb_enumerator ee;
620 struct hashtb_enumerator *e = &ee;
621
622 hashtb_start(nlsr->adl, e);
623 res = hashtb_seek(e, nbr, strlen(nbr)+1, 0);
624
625 if( res == HT_OLD_ENTRY )
626 {
627 ret=1;
628 }
629 else if(res == HT_NEW_ENTRY)
630 {
631 hashtb_delete(e);
632 }
633
634 hashtb_end(e);
635
636 return ret;
637}
akmhoque53f64222012-09-05 13:57:51 -0500638
akmhoqueb77b95f2013-02-08 12:28:47 -0600639int
640is_active_neighbor(char *nbr)
641{
642 int ret=0;
643
644 int res;
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 struct ndn_neighbor *nnbr;
654 nnbr=e->data;
655 if (nnbr->status == NBR_ACTIVE )
656 {
657 ret=1;
658 }
659 }
660 else if(res == HT_NEW_ENTRY)
661 {
662 hashtb_delete(e);
663 }
664
665 hashtb_end(e);
666
667 return ret;
668}
669
akmhoqueccb33e92013-02-20 11:44:28 -0600670
671void
672get_host_name_from_command_string(struct name_prefix *name_part,
673 char *nbr_name_uri, int offset)
674{
675
676
677
678 int res,i;
679 int len=0;
680 const unsigned char *comp_ptr1;
681 size_t comp_size;
682
683 struct ccn_charbuf *name=ccn_charbuf_create();
684 name = ccn_charbuf_create();
685 res = ccn_name_from_uri(name,nbr_name_uri);
686 if (res < 0) {
687 fprintf(stderr, "Bad ccn URI: %s\n", nbr_name_uri);
688 exit(1);
689 }
690
691 struct ccn_indexbuf cid={0};
692
693 struct ccn_indexbuf *components=&cid;
694 ccn_name_split (name, components);
695
696 for(i=components->n-2;i> (0+offset);i--)
697 {
698 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
699 len+=1;
700 len+=(int)comp_size;
701 }
702 len++;
703
704 char *neighbor=(char *)malloc(len);
705 memset(neighbor,0,len);
706
707 for(i=components->n-2;i> (0+offset);i--)
708 {
709 res=ccn_name_comp_get(name->buf, components,i,&comp_ptr1, &comp_size);
710 if ( i != components->n-2)
711 memcpy(neighbor+strlen(neighbor),".",1);
712 memcpy(neighbor+strlen(neighbor),(char *)comp_ptr1,
713 strlen((char *)comp_ptr1));
714
715 }
716
akmhoque6682ca32013-02-22 00:29:35 -0600717 name_part->name=(char *)calloc(strlen(neighbor)+1,sizeof(char));
akmhoqueccb33e92013-02-20 11:44:28 -0600718 memcpy(name_part->name,neighbor,strlen(neighbor)+1);
719 name_part->length=strlen(neighbor)+1;
720
721 // 01/31/2013
722 free(neighbor);
723 ccn_charbuf_destroy(&name);
724}
725
726