blob: 00b1c42a71e74e31d27d0d288e3071948218d96e [file] [log] [blame]
akmhoque3560cb62012-09-09 10:52:30 -05001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
4#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
7#include <assert.h>
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11#include <sys/types.h>
12#include <signal.h>
13
14
15
16#include <ccn/ccn.h>
17#include <ccn/uri.h>
18#include <ccn/keystore.h>
19#include <ccn/signing.h>
20#include <ccn/schedule.h>
21#include <ccn/hashtb.h>
22
23#include "nlsr.h"
24#include "nlsr_npt.h"
25#include "nlsr_fib.h"
akmhoque810a5b52012-09-09 16:53:14 -050026#include "nlsr_route.h"
akmhoque3cced642012-09-24 16:20:20 -050027#include "nlsr_adl.h"
akmhoque1771c412012-11-09 13:06:08 -060028#include "utility.h"
akmhoque3560cb62012-09-09 10:52:30 -050029
30int
akmhoquede61ba92012-09-20 22:19:12 -050031add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs)
akmhoque3560cb62012-09-09 10:52:30 -050032{
33 if ( strcmp(orig_router,nlsr->router_name)== 0)
34 {
35 return -1;
36 }
akmhoque3cced642012-09-24 16:20:20 -050037
akmhoque0ed6d982013-02-22 14:28:01 -060038 struct npt_entry *ne;//=(struct npt_entry*)calloc(1,sizeof(struct npt_entry ));
akmhoque3560cb62012-09-09 10:52:30 -050039
akmhoquede61ba92012-09-20 22:19:12 -050040 int res,res_nle,res_fle;
akmhoque3560cb62012-09-09 10:52:30 -050041 struct hashtb_enumerator ee;
42 struct hashtb_enumerator *e = &ee;
akmhoque810a5b52012-09-09 16:53:14 -050043
akmhoque3560cb62012-09-09 10:52:30 -050044
45 hashtb_start(nlsr->npt, e);
akmhoque810a5b52012-09-09 16:53:14 -050046 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
akmhoque3560cb62012-09-09 10:52:30 -050047
48 if(res == HT_NEW_ENTRY)
49 {
50 ne=e->data;
51
akmhoque83a94da2013-03-15 01:38:21 -050052 ne->orig_router=(char *)calloc(strlen(orig_router)+1,sizeof(char));
akmhoquececba942013-02-25 17:33:34 -060053 memcpy(ne->orig_router,orig_router,strlen(orig_router)+1);
akmhoque3560cb62012-09-09 10:52:30 -050054
akmhoque810a5b52012-09-09 16:53:14 -050055
akmhoquede61ba92012-09-20 22:19:12 -050056
akmhoque3560cb62012-09-09 10:52:30 -050057
akmhoque0ed6d982013-02-22 14:28:01 -060058 //struct hashtb_param param_nle = {0};
59 ne->name_list= hashtb_create(sizeof(struct name_list_entry ),NULL);
akmhoque3560cb62012-09-09 10:52:30 -050060
akmhoque810a5b52012-09-09 16:53:14 -050061 struct hashtb_enumerator eenle;
62 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -050063
akmhoque810a5b52012-09-09 16:53:14 -050064 hashtb_start(ne->name_list, enle);
65 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
akmhoque3560cb62012-09-09 10:52:30 -050066
akmhoque810a5b52012-09-09 16:53:14 -050067 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -050068 {
akmhoque0ed6d982013-02-22 14:28:01 -060069 struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -050070 nle=enle->data;
akmhoque0ed6d982013-02-22 14:28:01 -060071 nle->name=(char *)calloc(strlen(name_prefix)+1,sizeof(char));
72 //memset(nle->name,0,strlen(name_prefix)+1);
73 memcpy(nle->name,name_prefix,strlen(name_prefix)+1);
akmhoque3560cb62012-09-09 10:52:30 -050074
akmhoque810a5b52012-09-09 16:53:14 -050075
akmhoque3560cb62012-09-09 10:52:30 -050076
77 }
akmhoque810a5b52012-09-09 16:53:14 -050078 hashtb_end(enle);
79
akmhoque0ed6d982013-02-22 14:28:01 -060080 //struct hashtb_param param_fle = {0};
81 ne->face_list=hashtb_create(sizeof(struct face_list_entry), NULL);
akmhoque3560cb62012-09-09 10:52:30 -050082
akmhoquede61ba92012-09-20 22:19:12 -050083 if ( num_face > 0 )
84 {
85 struct hashtb_enumerator eef;
86 struct hashtb_enumerator *ef = &eef;
87
88 hashtb_start(ne->face_list, ef);
89 int i;
90
akmhoque3cced642012-09-24 16:20:20 -050091 for ( i=0; i < num_face ; i++)
akmhoquede61ba92012-09-20 22:19:12 -050092 {
93 int face=faces[i];
akmhoquea30cb772012-10-07 09:50:34 -050094 if ( face != NO_FACE && face != ZERO_FACE)
akmhoquede61ba92012-09-20 22:19:12 -050095 {
akmhoquea30cb772012-10-07 09:50:34 -050096 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
97
98 if ( res_fle == HT_NEW_ENTRY )
99 {
akmhoque0ed6d982013-02-22 14:28:01 -0600100 struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry));
akmhoquea30cb772012-10-07 09:50:34 -0500101 fle=ef->data;
102 fle->next_hop_face=face;
103 fle->route_cost=route_costs[i];
104 }
akmhoquede61ba92012-09-20 22:19:12 -0500105 }
106
107 }
108 hashtb_end(ef);
109 }
110
akmhoque3560cb62012-09-09 10:52:30 -0500111 }
112 else if (res == HT_OLD_ENTRY)
113 {
akmhoque3560cb62012-09-09 10:52:30 -0500114 struct npt_entry *one;
115
116 one=e->data;
117
akmhoque810a5b52012-09-09 16:53:14 -0500118 struct hashtb_enumerator eenle;
119 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500120
akmhoque810a5b52012-09-09 16:53:14 -0500121 hashtb_start(one->name_list, enle);
122 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
123
124 if(res_nle == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500125 {
akmhoque0ed6d982013-02-22 14:28:01 -0600126 struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry));
akmhoque810a5b52012-09-09 16:53:14 -0500127 nle=enle->data;
128 nle->name=(char *)malloc(strlen(name_prefix)+1);
129 memset(nle->name,0,strlen(name_prefix)+1);
130 memcpy(nle->name,name_prefix,strlen(name_prefix));
akmhoque3560cb62012-09-09 10:52:30 -0500131 }
akmhoque810a5b52012-09-09 16:53:14 -0500132 else if(res_nle == HT_OLD_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500133 {
akmhoquede61ba92012-09-20 22:19:12 -0500134
akmhoque3560cb62012-09-09 10:52:30 -0500135 }
akmhoque810a5b52012-09-09 16:53:14 -0500136 hashtb_end(enle);
137
akmhoquede61ba92012-09-20 22:19:12 -0500138 if ( num_face > 0 )
139 {
140 struct hashtb_enumerator eef;
141 struct hashtb_enumerator *ef = &eef;
142
143 hashtb_start(one->face_list, ef);
144 int i;
145
146 for ( i=0; i< num_face ; i ++)
147 {
148 int face=faces[i];
akmhoquea30cb772012-10-07 09:50:34 -0500149 if ( face != NO_FACE && face != ZERO_FACE)
akmhoquede61ba92012-09-20 22:19:12 -0500150 {
akmhoquea30cb772012-10-07 09:50:34 -0500151 res_fle = hashtb_seek(ef, &face, sizeof(face), 0);
152
153 if ( res_fle == HT_NEW_ENTRY )
154 {
akmhoque0ed6d982013-02-22 14:28:01 -0600155 struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry));
akmhoquea30cb772012-10-07 09:50:34 -0500156 fle=ef->data;
157 fle->next_hop_face=face;
158 fle->route_cost=route_costs[i];
159 }
akmhoquede61ba92012-09-20 22:19:12 -0500160 }
akmhoquede61ba92012-09-20 22:19:12 -0500161 }
162 hashtb_end(ef);
163 }
akmhoque810a5b52012-09-09 16:53:14 -0500164
akmhoque3560cb62012-09-09 10:52:30 -0500165
166 }
167 hashtb_end(e);
akmhoque3cced642012-09-24 16:20:20 -0500168
169 update_ccnd_fib_for_orig_router(orig_router);
170
akmhoque3560cb62012-09-09 10:52:30 -0500171 return res;
172}
173
akmhoque3cced642012-09-24 16:20:20 -0500174void
175update_ccnd_fib_for_orig_router(char *orig_router)
176{
177
akmhoqueb77b95f2013-02-08 12:28:47 -0600178 if ( nlsr->debugging )
179 {
180 printf("update_ccnd_fib_for_orig_router called\n");
181 }
182
akmhoque3cced642012-09-24 16:20:20 -0500183 int res;
184 struct hashtb_enumerator ee;
185 struct hashtb_enumerator *e = &ee;
186
187
188 hashtb_start(nlsr->npt, e);
189 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
190
191 if(res == HT_NEW_ENTRY)
192 {
193 hashtb_delete(e);
194 }
195 else if ( res == HT_OLD_ENTRY )
196 {
197 struct npt_entry *ne;
198 ne=e->data;
199 int num_face=hashtb_n(ne->face_list);
200 int last_face,first_face;
201
202 int *faces=(int *)malloc(num_face*sizeof(int));
203 int *route_costs=(int *)malloc(num_face*sizeof(int));
204
205 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
206 sort_faces_by_distance(faces,route_costs,0,num_face);
207
akmhoqueb77b95f2013-02-08 12:28:47 -0600208 if ( nlsr->debugging )
akmhoque3cced642012-09-24 16:20:20 -0500209 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600210 int m;
211 for ( m =0 ; m< num_face ; m++)
212 {
213 printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]);
214 }
akmhoque3cced642012-09-24 16:20:20 -0500215 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600216
217 last_face=0;
218 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoque3cced642012-09-24 16:20:20 -0500219 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600220 first_face=num_face-1;
221 }
222 else if( nlsr->max_faces_per_prefix > 0)
223 {
224 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500225 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600226 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500227 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600228 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500229 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600230 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500231 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600232
akmhoque3cced642012-09-24 16:20:20 -0500233 }
234
235 int i,j, nl_element;
236 struct name_list_entry *nle;
237 struct hashtb_enumerator eenle;
238 struct hashtb_enumerator *enle = &eenle;
239
240 hashtb_start(ne->name_list, enle);
akmhoque726197c2013-02-18 11:49:24 -0600241 nl_element=hashtb_n(ne->name_list);
akmhoque54a14f42013-02-24 06:16:20 -0600242
akmhoque726197c2013-02-18 11:49:24 -0600243 for (i=0;i<nl_element;i++)
244 {
245 nle=enle->data;
246
247 for( j=num_face-1; j>= 0; j--)
248 {
249
250 if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) )
251 {
akmhoque483c1eb2013-03-08 00:51:09 -0600252 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval);
akmhoque726197c2013-02-18 11:49:24 -0600253 }
254 }
255
256
257 hashtb_next(enle);
258 }
akmhoque726197c2013-02-18 11:49:24 -0600259 hashtb_end(enle);
akmhoque54a14f42013-02-24 06:16:20 -0600260
akmhoque726197c2013-02-18 11:49:24 -0600261
262 if ( nlsr->debugging )
263 {
264 printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face);
265 }
266
267 hashtb_start(ne->name_list, enle);
akmhoque3cced642012-09-24 16:20:20 -0500268 nl_element=hashtb_n(ne->name_list);
269
270 for (i=0;i<nl_element;i++)
271 {
272 nle=enle->data;
273
274 for( j=first_face; j>= last_face; j--)
275 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600276 if ( nlsr->debugging )
277 {
278 printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]);
279 }
280 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500281 {
akmhoque1771c412012-11-09 13:06:08 -0600282 if ( nlsr->debugging )
283 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
284 if ( nlsr->detailed_logging )
285 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -0600286 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -0500287 }
288 else
289 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600290 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500291 {
akmhoque1771c412012-11-09 13:06:08 -0600292 if ( nlsr->debugging )
293 printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
294 if ( nlsr->detailed_logging )
295 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -0600296 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -0500297 }
298 }
299 }
akmhoquea30cb772012-10-07 09:50:34 -0500300
301
akmhoque3cced642012-09-24 16:20:20 -0500302 hashtb_next(enle);
303 }
304 hashtb_end(enle);
305
306
307
308 free(faces);
309 free(route_costs);
310
311 }
312 hashtb_end(e);
313
314}
315
akmhoqueffacaa82012-09-13 17:48:30 -0500316int
akmhoque3cced642012-09-24 16:20:20 -0500317delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix)
akmhoqueffacaa82012-09-13 17:48:30 -0500318{
319 if ( strcmp(orig_router,nlsr->router_name)== 0)
320 {
321 return -1;
322 }
323
324 struct npt_entry *ne;
325
326 int res,res_nle;
327 struct hashtb_enumerator ee;
328 struct hashtb_enumerator *e = &ee;
329
330
331 hashtb_start(nlsr->npt, e);
332 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
333
334 if(res == HT_NEW_ENTRY)
335 {
336 hashtb_delete(e);
337 return -1;
338 }
339 else if (res == HT_OLD_ENTRY)
340 {
341 ne=e->data;
342
343 struct hashtb_enumerator eenle;
344 struct hashtb_enumerator *enle = &eenle;
345
346 hashtb_start(ne->name_list, enle);
347 res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0);
348
349 if(res_nle == HT_NEW_ENTRY )
350 {
351 hashtb_delete(enle);
352 }
353 else if(res_nle == HT_OLD_ENTRY )
354 {
akmhoque3cced642012-09-24 16:20:20 -0500355 struct name_list_entry *nle;
356
357 nle=enle->data;
358
359 int j;
360 int num_face=hashtb_n(ne->face_list);
361 int last_face,first_face;
362
363 int *faces=(int *)malloc(num_face*sizeof(int));
364 int *route_costs=(int *)malloc(num_face*sizeof(int));
365
366 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
367 sort_faces_by_distance(faces,route_costs,0,num_face);
368
369
akmhoqueb77b95f2013-02-08 12:28:47 -0600370 last_face=0;
371 if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table
akmhoqueffacaa82012-09-13 17:48:30 -0500372 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600373 first_face=num_face-1;
akmhoqueffacaa82012-09-13 17:48:30 -0500374 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600375 else if( nlsr->max_faces_per_prefix > 0)
akmhoque3cced642012-09-24 16:20:20 -0500376 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600377 if ( nlsr->max_faces_per_prefix >= num_face)
akmhoque3cced642012-09-24 16:20:20 -0500378 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600379 first_face=num_face-1;
akmhoque3cced642012-09-24 16:20:20 -0500380 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600381 else if ( nlsr->max_faces_per_prefix < num_face)
akmhoque3cced642012-09-24 16:20:20 -0500382 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600383 first_face=nlsr->max_faces_per_prefix-1;
akmhoque3cced642012-09-24 16:20:20 -0500384 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600385
386 }
akmhoque3cced642012-09-24 16:20:20 -0500387 for( j=first_face; j>= last_face; j--)
388 {
akmhoquea30cb772012-10-07 09:50:34 -0500389
akmhoqueb77b95f2013-02-08 12:28:47 -0600390 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -0500391 {
akmhoque1771c412012-11-09 13:06:08 -0600392 if ( nlsr->debugging )
393 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
394 if ( nlsr->detailed_logging )
395 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -0600396 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -0500397 }
398 else
399 {
akmhoqueb77b95f2013-02-08 12:28:47 -0600400 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -0500401 {
akmhoque1771c412012-11-09 13:06:08 -0600402 if ( nlsr->debugging )
403 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
404 if ( nlsr->detailed_logging )
405 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -0600406 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -0500407 }
408 }
akmhoquea30cb772012-10-07 09:50:34 -0500409
akmhoque3cced642012-09-24 16:20:20 -0500410 }
411
akmhoqueffacaa82012-09-13 17:48:30 -0500412 }
413
414 hashtb_end(enle);
415 }
416
417 hashtb_end(e);
418
419 return 0;
420}
akmhoque3560cb62012-09-09 10:52:30 -0500421
422void
423print_npt(void)
424{
akmhoque1771c412012-11-09 13:06:08 -0600425
426 if ( nlsr->debugging )
427 {
428 printf("\n");
429 printf("print_npt called\n");
430 }
431 if ( nlsr->detailed_logging )
432 {
433 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
434 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n");
435 }
akmhoque3560cb62012-09-09 10:52:30 -0500436 int i, npt_element;
437
438 struct npt_entry *ne;
439
440 struct hashtb_enumerator ee;
441 struct hashtb_enumerator *e = &ee;
442
443 hashtb_start(nlsr->npt, e);
444 npt_element=hashtb_n(nlsr->npt);
445
446 for(i=0;i<npt_element;i++)
447 {
akmhoque1771c412012-11-09 13:06:08 -0600448 if ( nlsr->debugging )
449 {
450 printf("\n");
451 printf("----------NPT ENTRY %d------------------\n",i+1);
452 }
453 if ( nlsr->detailed_logging )
454 {
455 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
456 writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1);
457 }
akmhoque3560cb62012-09-09 10:52:30 -0500458 ne=e->data;
akmhoque1771c412012-11-09 13:06:08 -0600459 if ( nlsr->debugging )
460 printf(" Origination Router: %s \n",ne->orig_router);
461 if ( nlsr->detailed_logging )
462 writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router);
akmhoque3560cb62012-09-09 10:52:30 -0500463
akmhoquede61ba92012-09-20 22:19:12 -0500464 int j, nl_element,face_list_element;
akmhoque810a5b52012-09-09 16:53:14 -0500465 struct name_list_entry *nle;
466 struct hashtb_enumerator eenle;
467 struct hashtb_enumerator *enle = &eenle;
akmhoque3560cb62012-09-09 10:52:30 -0500468
akmhoque810a5b52012-09-09 16:53:14 -0500469 hashtb_start(ne->name_list, enle);
470 nl_element=hashtb_n(ne->name_list);
akmhoque3560cb62012-09-09 10:52:30 -0500471
akmhoque810a5b52012-09-09 16:53:14 -0500472 for (j=0;j<nl_element;j++)
akmhoque3560cb62012-09-09 10:52:30 -0500473 {
akmhoque810a5b52012-09-09 16:53:14 -0500474 nle=enle->data;
akmhoque1771c412012-11-09 13:06:08 -0600475 if ( nlsr->debugging )
476 printf(" Name Prefix: %s \n",nle->name);
477 if ( nlsr->detailed_logging )
478 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500479 hashtb_next(enle);
akmhoque3560cb62012-09-09 10:52:30 -0500480 }
akmhoque810a5b52012-09-09 16:53:14 -0500481 hashtb_end(enle);
akmhoquede61ba92012-09-20 22:19:12 -0500482
483 struct face_list_entry *fle;
484
485 struct hashtb_enumerator eef;
486 struct hashtb_enumerator *ef = &eef;
487
488 hashtb_start(ne->face_list, ef);
489 face_list_element=hashtb_n(ne->face_list);
490 if ( face_list_element <= 0 )
491 {
akmhoque1771c412012-11-09 13:06:08 -0600492 if ( nlsr->debugging )
493 printf(" Face: No Face \n");
494 if ( nlsr->detailed_logging )
495 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
496
akmhoquede61ba92012-09-20 22:19:12 -0500497 }
498 else
499 {
500 for(j=0;j<face_list_element;j++)
501 {
502 fle=ef->data;
akmhoque1771c412012-11-09 13:06:08 -0600503 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600504 printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost);
akmhoque1771c412012-11-09 13:06:08 -0600505 if ( nlsr->detailed_logging )
506 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost);
akmhoquede61ba92012-09-20 22:19:12 -0500507 hashtb_next(ef);
508 }
509 }
510 hashtb_end(ef);
511
akmhoque3560cb62012-09-09 10:52:30 -0500512
513 hashtb_next(e);
514 }
515
516 hashtb_end(e);
517
akmhoque3171d652012-11-13 11:44:33 -0600518 if ( nlsr->debugging )
519 printf("\n");
520 if ( nlsr->detailed_logging )
521 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque3560cb62012-09-09 10:52:30 -0500522}
akmhoque810a5b52012-09-09 16:53:14 -0500523
524void
akmhoquede61ba92012-09-20 22:19:12 -0500525delete_orig_router_from_npt(char *orig_router)
akmhoque810a5b52012-09-09 16:53:14 -0500526{
akmhoquede61ba92012-09-20 22:19:12 -0500527 int res,num_face,num_prefix;
akmhoque810a5b52012-09-09 16:53:14 -0500528 struct npt_entry *ne;
529
530 struct hashtb_enumerator ee;
531 struct hashtb_enumerator *e = &ee;
532
533 hashtb_start(nlsr->npt, e);
534 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
535
536 if ( res == HT_OLD_ENTRY )
537 {
538 ne=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500539 num_prefix=hashtb_n(ne->name_list);
540 if ( num_prefix > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500541 {
akmhoquede61ba92012-09-20 22:19:12 -0500542 num_face=hashtb_n(ne->face_list);
543
544 if ( num_face > 0 )
akmhoque810a5b52012-09-09 16:53:14 -0500545 {
546 int j, nl_element;
547 struct name_list_entry *nle;
548 struct hashtb_enumerator eenle;
549 struct hashtb_enumerator *enle = &eenle;
550
551 hashtb_start(ne->name_list, enle);
552 nl_element=hashtb_n(ne->name_list);
553
554 for (j=0;j<nl_element;j++)
555 {
556 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500557 delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name);
akmhoque810a5b52012-09-09 16:53:14 -0500558 hashtb_next(enle);
559 }
560 hashtb_end(enle);
561
562 }
563
564 }
akmhoque54a14f42013-02-24 06:16:20 -0600565 //hashtb_destroy(&ne->name_list);
566 //hashtb_destroy(&ne->face_list);
akmhoque80817e22013-03-15 08:13:41 -0500567 free(ne->orig_router);
akmhoque54a14f42013-02-24 06:16:20 -0600568 destroy_name_list(ne->name_list);
569 destroy_face_list(ne->face_list);
akmhoque810a5b52012-09-09 16:53:14 -0500570 hashtb_delete(e);
571 }
572 else if ( res == HT_NEW_ENTRY )
573 {
574 hashtb_delete(e);
575 }
576 hashtb_end(e);
577}
akmhoquefbfd0982012-09-09 20:59:03 -0500578
akmhoquede61ba92012-09-20 22:19:12 -0500579
580void
581add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost)
582{
akmhoque1771c412012-11-09 13:06:08 -0600583 if ( nlsr->debugging )
584 {
585 printf("add_face_to_npt_by_face_id called\n");
586 printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
587 }
588 if ( nlsr->detailed_logging )
589 {
590 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n");
591 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost);
592 }
akmhoquede61ba92012-09-20 22:19:12 -0500593
akmhoque1771c412012-11-09 13:06:08 -0600594
akmhoquede61ba92012-09-20 22:19:12 -0500595 int res,res1;
596 struct npt_entry *ne;
597
598 struct hashtb_enumerator ee;
599 struct hashtb_enumerator *e = &ee;
600
601 hashtb_start(nlsr->npt, e);
602 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
603
604 if ( res == HT_OLD_ENTRY )
605 {
akmhoque1771c412012-11-09 13:06:08 -0600606 if ( nlsr->debugging )
607 printf("Dest Router Found \n");
608 if ( nlsr->detailed_logging )
609 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n");
610
akmhoquede61ba92012-09-20 22:19:12 -0500611 ne=e->data;
612
613 struct hashtb_enumerator eef;
614 struct hashtb_enumerator *ef = &eef;
615
616 hashtb_start(ne->face_list, ef);
617 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
618
619 if ( res1 == HT_OLD_ENTRY )
620 {
akmhoque1771c412012-11-09 13:06:08 -0600621 if ( nlsr->debugging )
622 printf("Face Found \n");
623 if ( nlsr->detailed_logging )
624 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n");
akmhoqueb77b95f2013-02-08 12:28:47 -0600625 struct face_list_entry *fle;
akmhoquede61ba92012-09-20 22:19:12 -0500626 fle=ef->data;
627 fle->next_hop_face=face_id;
628 fle->route_cost=route_cost;
629 }
630 else if ( res1 == HT_NEW_ENTRY )
631 {
akmhoque1771c412012-11-09 13:06:08 -0600632 if ( nlsr->debugging )
633 printf("Face Not Found \n");
634 if ( nlsr->detailed_logging )
635 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n");
akmhoquececba942013-02-25 17:33:34 -0600636 struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
akmhoquede61ba92012-09-20 22:19:12 -0500637 fle=ef->data;
638 fle->next_hop_face=face_id;
639 fle->route_cost=route_cost;
akmhoqueb77b95f2013-02-08 12:28:47 -0600640
641
642
643
akmhoquede61ba92012-09-20 22:19:12 -0500644 }
645 hashtb_end(ef);
646 }
647 else if (res == HT_NEW_ENTRY)
648 {
649 hashtb_delete(e);
650 }
651
652 hashtb_end(e);
653}
654
655
656void
akmhoque3cced642012-09-24 16:20:20 -0500657add_new_fib_entries_to_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500658{
akmhoque1771c412012-11-09 13:06:08 -0600659 if ( nlsr->debugging )
660 printf("add_new_fib_entries_to_npt called\n");
661 if ( nlsr->detailed_logging )
662 writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n");
akmhoquede61ba92012-09-20 22:19:12 -0500663 int i,j, rt_element,face_list_element;
664
665 struct routing_table_entry *rte;
666
667 struct hashtb_enumerator ee;
668 struct hashtb_enumerator *e = &ee;
669
670 hashtb_start(nlsr->routing_table, e);
671 rt_element=hashtb_n(nlsr->routing_table);
672
673 for(i=0;i<rt_element;i++)
674 {
akmhoquede61ba92012-09-20 22:19:12 -0500675 rte=e->data;
akmhoquede61ba92012-09-20 22:19:12 -0500676
677 struct face_list_entry *fle;
678
679 struct hashtb_enumerator eef;
680 struct hashtb_enumerator *ef = &eef;
681
682 hashtb_start(rte->face_list, ef);
683 face_list_element=hashtb_n(rte->face_list);
684 if ( face_list_element <= 0 )
685 {
akmhoque1771c412012-11-09 13:06:08 -0600686 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600687 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600688 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600689 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
akmhoquede61ba92012-09-20 22:19:12 -0500690 }
691 else
692 {
693 for(j=0;j<face_list_element;j++)
694 {
695 fle=ef->data;
akmhoquede61ba92012-09-20 22:19:12 -0500696 add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost);
697 hashtb_next(ef);
698 }
699 }
700 hashtb_end(ef);
701
702 hashtb_next(e);
703 }
704
705 hashtb_end(e);
706
707}
708
709
710void
711delete_face_from_npt_by_face_id(char *dest_router, int face_id)
712{
akmhoque1771c412012-11-09 13:06:08 -0600713 if ( nlsr->debugging )
714 printf("delete_face_from_npt_by_face_id\n");
715 if ( nlsr->detailed_logging )
716 writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n");
akmhoquede61ba92012-09-20 22:19:12 -0500717
718 int res,res1;
719 struct npt_entry *ne;
720
721 struct hashtb_enumerator ee;
722 struct hashtb_enumerator *e = &ee;
723
724 hashtb_start(nlsr->npt, e);
725 res = hashtb_seek(e, dest_router, strlen(dest_router), 0);
726
727 if ( res == HT_OLD_ENTRY )
728 {
729 ne=e->data;
730
731 struct hashtb_enumerator eef;
732 struct hashtb_enumerator *ef = &eef;
733
734 hashtb_start(ne->face_list, ef);
735 res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0);
akmhoquede61ba92012-09-20 22:19:12 -0500736 if ( res1 == HT_OLD_ENTRY )
737 {
akmhoque54a14f42013-02-24 06:16:20 -0600738
akmhoquede61ba92012-09-20 22:19:12 -0500739 hashtb_delete(ef);
740 }
741 else if ( res1 == HT_NEW_ENTRY )
742 {
743 hashtb_delete(ef);
744 }
745 hashtb_end(ef);
746 }
747 else if (res == HT_NEW_ENTRY)
748 {
749 hashtb_delete(e);
750 }
751
752 hashtb_end(e);
753}
754
akmhoquede61ba92012-09-20 22:19:12 -0500755
756void
akmhoque3cced642012-09-24 16:20:20 -0500757clean_old_fib_entries_from_npt(void)
akmhoquede61ba92012-09-20 22:19:12 -0500758{
759
akmhoque1771c412012-11-09 13:06:08 -0600760
761 if ( nlsr->debugging )
762 printf("clean_old_fib_entries_from_npt called\n\n");
763 if ( nlsr->detailed_logging )
764 writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n");
akmhoquede61ba92012-09-20 22:19:12 -0500765 int i, npt_element;
766
767 struct npt_entry *ne;
768
769 struct hashtb_enumerator ee;
770 struct hashtb_enumerator *e = &ee;
771
772 hashtb_start(nlsr->npt, e);
773 npt_element=hashtb_n(nlsr->npt);
774
775 for(i=0;i<npt_element;i++)
776 {
777 ne=e->data;
778
779 int j,k, nl_element,face_list_element;
780 struct face_list_entry *fle;
781
782 struct hashtb_enumerator eef;
783 struct hashtb_enumerator *ef = &eef;
784
785 hashtb_start(ne->face_list, ef);
786 face_list_element=hashtb_n(ne->face_list);
787 if ( face_list_element <= 0 )
788 {
akmhoque1771c412012-11-09 13:06:08 -0600789 if ( nlsr->debugging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600790 printf(" Face: No Face \n");
akmhoque1771c412012-11-09 13:06:08 -0600791 if ( nlsr->detailed_logging )
792 writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n");
793
akmhoquede61ba92012-09-20 22:19:12 -0500794 }
795 else
796 {
797 for(j=0;j<face_list_element;j++)
798 {
799 fle=ef->data;
800 int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face);
801 if ( check == 0 )
802 {
803 struct name_list_entry *nle;
804 struct hashtb_enumerator eenle;
805 struct hashtb_enumerator *enle = &eenle;
806
807 hashtb_start(ne->name_list, enle);
808 nl_element=hashtb_n(ne->name_list);
809
810 for (k=0;k<nl_element;k++)
811 {
812 nle=enle->data;
akmhoque3cced642012-09-24 16:20:20 -0500813 if( is_neighbor(nle->name) == 0 )
814 {
akmhoque1771c412012-11-09 13:06:08 -0600815 if ( nlsr->debugging )
816 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
817 if ( nlsr->detailed_logging )
akmhoqueb77b95f2013-02-08 12:28:47 -0600818 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
akmhoque483c1eb2013-03-08 00:51:09 -0600819 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face,nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -0500820 }
821
akmhoquede61ba92012-09-20 22:19:12 -0500822
823 hashtb_next(enle);
824 }
825 hashtb_end(enle);
826
akmhoqueb77b95f2013-02-08 12:28:47 -0600827
828 hashtb_delete(ef);
829 j++;
830
akmhoquede61ba92012-09-20 22:19:12 -0500831 }
akmhoqueb77b95f2013-02-08 12:28:47 -0600832 else
833 {
834 struct name_list_entry *nle;
835 struct hashtb_enumerator eenle;
836 struct hashtb_enumerator *enle = &eenle;
837
838 hashtb_start(ne->name_list, enle);
839 nl_element=hashtb_n(ne->name_list);
840
841 for (k=0;k<nl_element;k++)
842 {
843 nle=enle->data;
844 if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face )
845 {
846 if ( nlsr->debugging )
847 printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
848 if ( nlsr->detailed_logging )
849 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face);
akmhoque483c1eb2013-03-08 00:51:09 -0600850 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face,nlsr->router_dead_interval);
akmhoqueb77b95f2013-02-08 12:28:47 -0600851 }
852
853
854 hashtb_next(enle);
855 }
856 hashtb_end(enle);
857
858 hashtb_next(ef);
859 }
akmhoquede61ba92012-09-20 22:19:12 -0500860 }
861 }
862 hashtb_end(ef);
863
864
865 hashtb_next(e);
866 }
867
868 hashtb_end(e);
869
870}
871
872void
akmhoque3cced642012-09-24 16:20:20 -0500873update_npt_with_new_route(void)
akmhoquede61ba92012-09-20 22:19:12 -0500874{
akmhoqueb77b95f2013-02-08 12:28:47 -0600875 if ( nlsr->debugging )
876 printf("update_npt_with_new_route called\n");
877
akmhoquede61ba92012-09-20 22:19:12 -0500878 clean_old_fib_entries_from_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600879 print_npt();
akmhoquede61ba92012-09-20 22:19:12 -0500880 add_new_fib_entries_to_npt();
akmhoqueb77b95f2013-02-08 12:28:47 -0600881 print_npt();
882
akmhoque3cced642012-09-24 16:20:20 -0500883 int i, npt_element;
884
885 struct npt_entry *ne;
886
887 struct hashtb_enumerator ee;
888 struct hashtb_enumerator *e = &ee;
889
890 hashtb_start(nlsr->npt, e);
891 npt_element=hashtb_n(nlsr->npt);
892
893 for(i=0;i<npt_element;i++)
894 {
895
896 ne=e->data;
897 update_ccnd_fib_for_orig_router(ne->orig_router);
898 hashtb_next(e);
899 }
900
901 hashtb_end(e);
902}
903
904
905
906void
907sort_faces_by_distance(int *faces,int *route_costs,int start,int element)
908{
909 int i,j;
910 int temp_cost;
911 int temp_face;
912
913 for ( i=start ; i < element ; i ++)
914 {
915 for( j=i+1; j<element; j ++)
916 {
917 if (route_costs[j] < route_costs[i] )
918 {
919 temp_cost=route_costs[j];
920 route_costs[j]=route_costs[i];
921 route_costs[i]=temp_cost;
922
923 temp_face=faces[j];
924 faces[j]=faces[i];
925 faces[i]=temp_face;
926 }
927 }
928 }
929
930}
931
932void
933get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces)
934{
935
936 int res,face_list_element,j;
937 struct hashtb_enumerator ee;
938 struct hashtb_enumerator *e = &ee;
939
940
941 hashtb_start(nlsr->npt, e);
942 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
943
944 if(res == HT_NEW_ENTRY)
945 {
946 hashtb_delete(e);
947 }
948 else if ( res == HT_OLD_ENTRY )
949 {
950 struct npt_entry *ne;
951 ne=e->data;
952
953 struct face_list_entry *fle;
954
955 struct hashtb_enumerator eef;
956 struct hashtb_enumerator *ef = &eef;
957
958 hashtb_start(ne->face_list, ef);
959 face_list_element=hashtb_n(ne->face_list);
960 for(j=0;j<face_list_element;j++)
961 {
962 fle=ef->data;
963 faces[j]=fle->next_hop_face;
964 route_costs[j]=fle->route_cost;
965 hashtb_next(ef);
966 }
967 hashtb_end(ef);
968
969
970 }
971 hashtb_end(e);
972
973}
974
975void
976destroy_faces_by_orig_router(char *orig_router)
977{
978
979 int res;
980 struct hashtb_enumerator ee;
981 struct hashtb_enumerator *e = &ee;
982
983
984 hashtb_start(nlsr->npt, e);
985 res = hashtb_seek(e, orig_router, strlen(orig_router), 0);
986
987 if(res == HT_NEW_ENTRY)
988 {
989 hashtb_delete(e);
990 }
991 else if ( res == HT_OLD_ENTRY )
992 {
993 struct npt_entry *ne;
994 ne=e->data;
995 int num_face=hashtb_n(ne->face_list);
996 int last_face,first_face;
997
998 int *faces=(int *)malloc(num_face*sizeof(int));
999 int *route_costs=(int *)malloc(num_face*sizeof(int));
1000
1001 get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face);
1002 sort_faces_by_distance(faces,route_costs,0,num_face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001003 last_face=0;
akmhoque0ed6d982013-02-22 14:28:01 -06001004 if ( nlsr->max_faces_per_prefix == 0)
akmhoqueb77b95f2013-02-08 12:28:47 -06001005 {
1006 first_face=num_face-1;
1007 }
1008 else if( nlsr->max_faces_per_prefix > 0)
1009 {
1010 if ( nlsr->max_faces_per_prefix >= num_face)
1011 {
1012 first_face=num_face-1;
1013 }
1014 else if ( nlsr->max_faces_per_prefix < num_face)
1015 {
1016 first_face=nlsr->max_faces_per_prefix-1;
1017 }
1018
1019 }
akmhoque3cced642012-09-24 16:20:20 -05001020
1021 int i,j, nl_element;
1022 struct name_list_entry *nle;
1023 struct hashtb_enumerator eenle;
1024 struct hashtb_enumerator *enle = &eenle;
1025
1026 hashtb_start(ne->name_list, enle);
1027 nl_element=hashtb_n(ne->name_list);
1028
1029 for (i=0;i<nl_element;i++)
1030 {
1031 nle=enle->data;
1032
1033 for( j=first_face; j>= last_face; j--)
1034 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001035 if ( is_active_neighbor(orig_router) == 0 )
akmhoque3cced642012-09-24 16:20:20 -05001036 {
akmhoque1771c412012-11-09 13:06:08 -06001037 if ( nlsr->debugging )
1038 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1039 if ( nlsr->detailed_logging )
1040 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -06001041 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -05001042 }
1043 else
1044 {
akmhoqueb77b95f2013-02-08 12:28:47 -06001045 if ( j == last_face && is_active_neighbor(nle->name)==0)
akmhoque3cced642012-09-24 16:20:20 -05001046 {
akmhoque1771c412012-11-09 13:06:08 -06001047 if ( nlsr->debugging )
1048 printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
1049 if ( nlsr->detailed_logging )
1050 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]);
akmhoque483c1eb2013-03-08 00:51:09 -06001051 add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval);
akmhoque3cced642012-09-24 16:20:20 -05001052 }
1053 }
1054 }
1055
1056 hashtb_next(enle);
1057 }
1058 hashtb_end(enle);
1059
1060
1061
1062 free(faces);
1063 free(route_costs);
1064
1065 }
1066 hashtb_end(e);
1067
akmhoquede61ba92012-09-20 22:19:12 -05001068}
1069
akmhoquefbfd0982012-09-09 20:59:03 -05001070void
1071destroy_all_face_by_nlsr(void)
1072{
1073 int i, npt_element;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001074
akmhoquefbfd0982012-09-09 20:59:03 -05001075 struct npt_entry *ne;
1076
1077 struct hashtb_enumerator ee;
Obaid Amin0e9a3002013-02-20 14:55:37 -06001078 struct hashtb_enumerator *e = &ee;
1079
1080 hashtb_start(nlsr->npt, e);
akmhoquefbfd0982012-09-09 20:59:03 -05001081 npt_element=hashtb_n(nlsr->npt);
1082
1083 for(i=0;i<npt_element;i++)
1084 {
akmhoquefbfd0982012-09-09 20:59:03 -05001085 ne=e->data;
akmhoque3cced642012-09-24 16:20:20 -05001086 destroy_faces_by_orig_router(ne->orig_router);
akmhoquefbfd0982012-09-09 20:59:03 -05001087 hashtb_next(e);
1088 }
1089
1090 hashtb_end(e);
1091
akmhoque3171d652012-11-13 11:44:33 -06001092 if ( nlsr->debugging )
1093 printf("\n");
1094 if ( nlsr->detailed_logging )
1095 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoquefbfd0982012-09-09 20:59:03 -05001096}
akmhoque0ed6d982013-02-22 14:28:01 -06001097
1098void
akmhoque54a14f42013-02-24 06:16:20 -06001099destroy_name_list(struct hashtb *name_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001100{
akmhoque54a14f42013-02-24 06:16:20 -06001101 int j,nl_element;
1102 struct name_list_entry *nle;
1103 struct hashtb_enumerator eenle;
1104 struct hashtb_enumerator *enle = &eenle;
1105
1106 hashtb_start(name_list, enle);
1107 nl_element=hashtb_n(name_list);
1108
1109 for (j=0;j<nl_element;j++)
1110 {
1111 nle=enle->data;
1112 free(nle->name);
1113 hashtb_next(enle);
1114 }
1115 hashtb_end(enle);
1116
1117 hashtb_destroy(&name_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001118}
1119
1120void
akmhoque54a14f42013-02-24 06:16:20 -06001121destroy_face_list(struct hashtb *face_list)
akmhoque0ed6d982013-02-22 14:28:01 -06001122{
akmhoque54a14f42013-02-24 06:16:20 -06001123 hashtb_destroy(&face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001124}
1125
1126void
1127destroy_npt(void)
1128{
1129
1130
1131 int i, npt_element;
1132 struct npt_entry *ne;
1133
1134 struct hashtb_enumerator ee;
1135 struct hashtb_enumerator *e = &ee;
1136
1137 hashtb_start(nlsr->npt, e);
1138 npt_element=hashtb_n(nlsr->npt);
1139
1140 for(i=0;i<npt_element;i++)
1141 {
1142 ne=e->data;
akmhoque557b8c52013-03-15 08:18:52 -05001143 free(ne->orig_router);
akmhoque54a14f42013-02-24 06:16:20 -06001144 destroy_name_list(ne->name_list);
1145 destroy_face_list(ne->face_list);
akmhoque0ed6d982013-02-22 14:28:01 -06001146 hashtb_next(e);
1147 }
akmhoque0ed6d982013-02-22 14:28:01 -06001148 hashtb_end(e);
akmhoque54a14f42013-02-24 06:16:20 -06001149
1150 hashtb_destroy(&nlsr->npt);
akmhoque0ed6d982013-02-22 14:28:01 -06001151}
1152