blob: 2babc55745cecf0a800995bd3e2a8b059dc3067c [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));
akmhoquee41ffc12013-02-24 14:35:33 -060067 memcpy(nbr->last_lsdb_version,"0000000000000000",16);
akmhoque6682ca32013-02-22 00:29:35 -060068 nbr->last_info_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
akmhoquee41ffc12013-02-24 14:35:33 -060069 memcpy(nbr->last_info_version,"0000000000000000",16);
akmhoque03004e62012-09-06 01:12:28 -050070 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050071
72 nbr->last_lsdb_requested=0;
akmhoquee7c4b6d2012-08-21 12:30:25 -040073 }
akmhoque53f64222012-09-05 13:57:51 -050074
akmhoque8a5babe2012-08-16 17:39:33 -050075 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -050076}
akmhoque8a5babe2012-08-16 17:39:33 -050077
akmhoque03004e62012-09-06 01:12:28 -050078
akmhoque53f64222012-09-05 13:57:51 -050079void
80print_adjacent(struct ndn_neighbor *nbr)
81{
akmhoque7b791452012-10-30 11:24:56 -050082 if ( nlsr->debugging )
83 {
84 printf("print_adjacent called\n");
85 printf("--------Neighbor---------------------------\n");
86 printf(" Neighbor: %s \n",nbr->neighbor->name);
87 printf(" Length : %d \n",nbr->neighbor->length);
akmhoqueb77b95f2013-02-08 12:28:47 -060088 printf(" Ip Address: %s \n",nbr->ip_address);
akmhoque7b791452012-10-30 11:24:56 -050089 printf(" Face : %d \n",nbr->face);
90 printf(" Metric : %d \n",nbr->metric);
91 printf(" Status : %d \n",nbr->status);
92 printf(" LSDB Version: %s \n",nbr->last_lsdb_version);
93 printf(" Info Version: %s \n",nbr->last_info_version);
94 printf(" Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
95 printf(" LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
96 printf(" LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
97 printf(" LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
98 printf(" Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
99 printf(" IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
akmhoque03004e62012-09-06 01:12:28 -0500100
akmhoque7b791452012-10-30 11:24:56 -0500101 printf("\n");
102 }
103
104 if ( nlsr->detailed_logging )
105 {
106
107 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent called\n");
108 writeLogg(__FILE__,__FUNCTION__,__LINE__,"--------Neighbor---------------------------\n");
109 writeLogg(__FILE__,__FUNCTION__,__LINE__," Neighbor: %s \n",nbr->neighbor->name);
110 writeLogg(__FILE__,__FUNCTION__,__LINE__," Length : %d \n",nbr->neighbor->length);
111 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face : %d \n",nbr->face);
112 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric : %d \n",nbr->metric);
113 writeLogg(__FILE__,__FUNCTION__,__LINE__," Status : %d \n",nbr->status);
114 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Version: %s \n",nbr->last_lsdb_version);
115 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Version: %s \n",nbr->last_info_version);
116 writeLogg(__FILE__,__FUNCTION__,__LINE__," Info Interest Timed Out : %d \n",nbr->info_interest_timed_out);
117 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Interest Timed Out : %d \n",nbr->lsdb_interest_timed_out);
118 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Synch Interval : %ld \n",nbr->lsdb_synch_interval);
119 writeLogg(__FILE__,__FUNCTION__,__LINE__," LSDB Random Time comp : %d \n",nbr->lsdb_random_time_component);
120 writeLogg(__FILE__,__FUNCTION__,__LINE__," Las Time LSDB Requested: %ld \n",nbr->last_lsdb_requested);
121 writeLogg(__FILE__,__FUNCTION__,__LINE__," IS_lsdb_send_interest_scheduled : %d \n",nbr->is_lsdb_send_interest_scheduled);
122
123 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
124 }
akmhoque8a5babe2012-08-16 17:39:33 -0500125
126}
127
128void
129print_adjacent_from_adl(void)
130{
akmhoque7b791452012-10-30 11:24:56 -0500131 if ( nlsr->debugging )
132 printf("print_adjacent_from_adl called \n");
133 if ( nlsr->detailed_logging )
134 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_adjacent_from_adl called \n");
135
akmhoque8a5babe2012-08-16 17:39:33 -0500136 int i, adl_element;
137 struct ndn_neighbor *nbr;
138
139 struct hashtb_enumerator ee;
140 struct hashtb_enumerator *e = &ee;
141
142 hashtb_start(nlsr->adl, e);
143 adl_element=hashtb_n(nlsr->adl);
144
145 for(i=0;i<adl_element;i++)
146 {
147 nbr=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500148 print_adjacent(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500149 hashtb_next(e);
150 }
151
152 hashtb_end(e);
153
akmhoque8a5babe2012-08-16 17:39:33 -0500154}
155
akmhoque03004e62012-09-06 01:12:28 -0500156int
157get_adjacent_status(struct name_prefix *nbr)
158{
akmhoque7b791452012-10-30 11:24:56 -0500159
160 if ( nlsr->debugging )
161 printf("get_adjacent_status called \n");
162 if ( nlsr->detailed_logging )
163 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adjacent_status called \n");
akmhoque03004e62012-09-06 01:12:28 -0500164
165 int res;
166 int status=-1;
167 struct ndn_neighbor *nnbr;
168
169 struct hashtb_enumerator ee;
170 struct hashtb_enumerator *e = &ee;
171
172 hashtb_start(nlsr->adl, e);
173 res = hashtb_seek(e, nbr->name, nbr->length, 0);
174
175 if (res == HT_OLD_ENTRY)
176 {
177 nnbr=e->data;
178 status=nnbr->status;
179 }
180 else if(res == HT_NEW_ENTRY)
181 {
182 hashtb_delete(e);
183 }
184
185 hashtb_end(e);
186
187 return status;
188
189}
190
191int
192get_timed_out_number(struct name_prefix *nbr)
193{
akmhoque7b791452012-10-30 11:24:56 -0500194
195 if ( nlsr->debugging )
196 printf("get_timed_out_number called \n");
197 if ( nlsr->detailed_logging )
198 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_timed_out_number called \n");
199
akmhoque03004e62012-09-06 01:12:28 -0500200
201 int res,ret=-1;
202 struct ndn_neighbor *nnbr;
203
204 struct hashtb_enumerator ee;
205 struct hashtb_enumerator *e = &ee;
206
207 hashtb_start(nlsr->adl, e);
208 res = hashtb_seek(e, nbr->name, nbr->length, 0);
209
210 if( res == HT_OLD_ENTRY )
211 {
212 nnbr=e->data;
213 ret=nnbr->info_interest_timed_out;
214 }
215 else if(res == HT_NEW_ENTRY)
216 {
217 hashtb_delete(e);
218 }
219
220 hashtb_end(e);
221
222 return ret;
223}
224
akmhoque14b3f342012-09-14 10:39:02 -0500225int
226get_lsdb_interest_timed_out_number(struct name_prefix *nbr)
227{
akmhoque7b791452012-10-30 11:24:56 -0500228
229 if ( nlsr->debugging )
230 printf("get_lsdb_interest_timed_out_number called \n");
231 if ( nlsr->detailed_logging )
232 writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_lsdb_interest_timed_out_number called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500233
234 int res,ret=-1;
235 struct ndn_neighbor *nnbr;
236
237 struct hashtb_enumerator ee;
238 struct hashtb_enumerator *e = &ee;
239
240 hashtb_start(nlsr->adl, e);
241 res = hashtb_seek(e, nbr->name, nbr->length, 0);
242
243 if( res == HT_OLD_ENTRY )
244 {
245 nnbr=e->data;
246 ret=nnbr->lsdb_interest_timed_out;
247 }
248 else if(res == HT_NEW_ENTRY)
249 {
250 hashtb_delete(e);
251 }
252
253 hashtb_end(e);
254
255 return ret;
256}
akmhoque03004e62012-09-06 01:12:28 -0500257
258void
259update_adjacent_timed_out_to_adl(struct name_prefix *nbr, int increment)
260{
akmhoque7b791452012-10-30 11:24:56 -0500261 if ( nlsr->debugging )
262 printf("update_adjacent_timed_out_to_adl called \n");
263 if ( nlsr->detailed_logging )
264 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500265
266 int res;
267 struct ndn_neighbor *nnbr;
268
269 struct hashtb_enumerator ee;
270 struct hashtb_enumerator *e = &ee;
271
272 hashtb_start(nlsr->adl, e);
273 res = hashtb_seek(e, nbr->name, nbr->length, 0);
274
275 if( res == HT_OLD_ENTRY )
276 {
277 nnbr=e->data;
278 nnbr->info_interest_timed_out += increment;
279 }
280 else if(res == HT_NEW_ENTRY)
281 {
282 hashtb_delete(e);
283 }
284
285 hashtb_end(e);
286}
287
288void
289update_adjacent_timed_out_zero_to_adl(struct name_prefix *nbr)
290{
akmhoque7b791452012-10-30 11:24:56 -0500291 if ( nlsr->debugging )
292 printf("update_adjacent_timed_out_zero_to_adl called \n");
293 if ( nlsr->detailed_logging )
294 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called \n");
295
akmhoque03004e62012-09-06 01:12:28 -0500296 int time_out_number=get_timed_out_number(nbr);
297 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
298
299}
300
akmhoque14b3f342012-09-14 10:39:02 -0500301
302void
303update_lsdb_interest_timed_out_to_adl(struct name_prefix *nbr, int increment)
304{
akmhoque7b791452012-10-30 11:24:56 -0500305 if ( nlsr->debugging )
306 printf("update_lsdb_interest_timed_out_to_adl called\n");
307 if ( nlsr->detailed_logging )
308 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_lsdb_interest_timed_out_to_adl called \n");
akmhoque14b3f342012-09-14 10:39:02 -0500309
310 int res;
311 struct ndn_neighbor *nnbr;
312
313 struct hashtb_enumerator ee;
314 struct hashtb_enumerator *e = &ee;
315
316 hashtb_start(nlsr->adl, e);
akmhoque62c0c192012-09-24 07:49:25 -0500317
akmhoque14b3f342012-09-14 10:39:02 -0500318 res = hashtb_seek(e, nbr->name, nbr->length, 0);
319
320 if( res == HT_OLD_ENTRY )
321 {
322 nnbr=e->data;
323 nnbr->lsdb_interest_timed_out += increment;
324 }
325 else if(res == HT_NEW_ENTRY)
326 {
327 hashtb_delete(e);
akmhoqueb77b95f2013-02-08 12:28:47 -0600328 }
akmhoque14b3f342012-09-14 10:39:02 -0500329 hashtb_end(e);
330}
331
332void
333update_lsdb_interest_timed_out_zero_to_adl(struct name_prefix *nbr)
334{
akmhoque7b791452012-10-30 11:24:56 -0500335 if ( nlsr->debugging )
336 printf("update_adjacent_timed_out_zero_to_adl called\n");
337 if ( nlsr->detailed_logging )
338 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_timed_out_zero_to_adl called\n");
339
akmhoque14b3f342012-09-14 10:39:02 -0500340 int time_out_number=get_lsdb_interest_timed_out_number(nbr);
341 update_lsdb_interest_timed_out_to_adl(nbr,-time_out_number);
342
343}
344
akmhoque8a5babe2012-08-16 17:39:33 -0500345void
akmhoque53f64222012-09-05 13:57:51 -0500346update_adjacent_status_to_adl(struct name_prefix *nbr, int status)
akmhoque8a5babe2012-08-16 17:39:33 -0500347{
akmhoque7b791452012-10-30 11:24:56 -0500348 if ( nlsr->debugging )
349 printf("update_adjacent_status_to_adl called\n");
350 if ( nlsr->detailed_logging )
351 writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_adjacent_status_to_adl called \n");
akmhoque03004e62012-09-06 01:12:28 -0500352
akmhoque8a5babe2012-08-16 17:39:33 -0500353 int res;
354 struct ndn_neighbor *nnbr;
355
356 struct hashtb_enumerator ee;
357 struct hashtb_enumerator *e = &ee;
358
359 hashtb_start(nlsr->adl, e);
akmhoque53f64222012-09-05 13:57:51 -0500360 res = hashtb_seek(e, nbr->name, nbr->length, 0);
361
akmhoque918ff9a2012-08-21 11:34:49 -0400362
akmhoquee7c4b6d2012-08-21 12:30:25 -0400363 if (res == HT_OLD_ENTRY)
364 {
365 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500366 if ( nnbr->status!=status )
367 {
368 nnbr->status=status;
369 nlsr->adj_build_flag++;
370 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400371 }
akmhoqueb903ded2012-08-21 12:56:28 -0400372 else if(res == HT_NEW_ENTRY)
373 {
374 hashtb_delete(e);
375 }
akmhoque53f64222012-09-05 13:57:51 -0500376
akmhoque8a5babe2012-08-16 17:39:33 -0500377 hashtb_end(e);
378}
379
akmhoque3171d652012-11-13 11:44:33 -0600380
381void
382delete_nbr_from_adl(struct name_prefix *nbr)
383{
384 if ( nlsr->debugging )
385 printf("delete_nbr_from_adl called\n");
386 if ( nlsr->detailed_logging )
387 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_nbr_from_adl called \n");
388
389 int res;
390 struct hashtb_enumerator ee;
391 struct hashtb_enumerator *e = &ee;
392
393 hashtb_start(nlsr->adl, e);
394 res = hashtb_seek(e, nbr->name, nbr->length, 0);
395
396
397 if (res == HT_OLD_ENTRY)
398 {
akmhoque6682ca32013-02-22 00:29:35 -0600399 struct ndn_neighbor *nbr=e->data;
akmhoquee6f98a12013-02-22 10:33:26 -0600400 /*free(nbr->neighbor->name);
akmhoque6682ca32013-02-22 00:29:35 -0600401 free(nbr->neighbor);
402 free(nbr->last_lsdb_version);
403 free(nbr->last_info_version);
404 free(nbr->ip_address);
akmhoquee6f98a12013-02-22 10:33:26 -0600405 */
406 destroy_nbr_component(nbr);
akmhoque6682ca32013-02-22 00:29:35 -0600407 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
akmhoquee6f98a12013-02-22 10:33:26 -0600727void
728destroy_nbr_component(struct ndn_neighbor *nbr)
729{
730 if ( nbr->neighbor->name )
731 free(nbr->neighbor->name);
732 if ( nbr->neighbor )
733 free(nbr->neighbor);
734 if ( nbr->last_lsdb_version)
735 free(nbr->last_lsdb_version);
736 if ( nbr->last_info_version)
737 free(nbr->last_info_version);
738 if ( nbr->ip_address)
739 free(nbr->ip_address);
740}
741
742void
743destroy_adl(void)
744{
745 int i, adl_element;
746 struct ndn_neighbor *nbr;
747
748 struct hashtb_enumerator ee;
749 struct hashtb_enumerator *e = &ee;
750
751 hashtb_start(nlsr->adl, e);
752 adl_element=hashtb_n(nlsr->adl);
753
754 for(i=0;i<adl_element;i++)
755 {
756 nbr=e->data;
757 destroy_nbr_component(nbr);
758 hashtb_next(e);
759 }
760
761 hashtb_end(e);
762
763 if( nlsr->adl )
764 hashtb_destroy(&nlsr->adl);
765
766}
767
768