akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1 | #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" |
| 26 | #include "nlsr_route.h" |
| 27 | #include "nlsr_adl.h" |
| 28 | #include "utility.h" |
| 29 | |
| 30 | int |
| 31 | add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs) |
| 32 | { |
| 33 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 34 | { |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | struct npt_entry *ne=(struct npt_entry*)malloc(sizeof(struct npt_entry )); |
| 39 | |
| 40 | int res,res_nle,res_fle; |
| 41 | struct hashtb_enumerator ee; |
| 42 | struct hashtb_enumerator *e = ⅇ |
| 43 | |
| 44 | |
| 45 | hashtb_start(nlsr->npt, e); |
| 46 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 47 | |
| 48 | if(res == HT_NEW_ENTRY) |
| 49 | { |
| 50 | ne=e->data; |
| 51 | |
| 52 | ne->orig_router=(char *)malloc(strlen(orig_router)+1); |
| 53 | memset(ne->orig_router,0,strlen(orig_router)+1); |
| 54 | memcpy(ne->orig_router,orig_router,strlen(orig_router)); |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | struct hashtb_param param_nle = {0}; |
| 60 | ne->name_list= hashtb_create(sizeof(struct name_list_entry ), ¶m_nle); |
| 61 | |
| 62 | struct hashtb_enumerator eenle; |
| 63 | struct hashtb_enumerator *enle = &eenle; |
| 64 | |
| 65 | hashtb_start(ne->name_list, enle); |
| 66 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 67 | |
| 68 | if(res_nle == HT_NEW_ENTRY ) |
| 69 | { |
| 70 | struct name_list_entry *nle=(struct name_list_entry *)malloc(sizeof(struct name_list_entry)); |
| 71 | nle=enle->data; |
| 72 | nle->name=(char *)malloc(strlen(name_prefix)+1); |
| 73 | memset(nle->name,0,strlen(name_prefix)+1); |
| 74 | memcpy(nle->name,name_prefix,strlen(name_prefix)); |
| 75 | |
| 76 | |
| 77 | |
| 78 | } |
| 79 | hashtb_end(enle); |
| 80 | |
| 81 | struct hashtb_param param_fle = {0}; |
| 82 | ne->face_list=hashtb_create(sizeof(struct face_list_entry), ¶m_fle); |
| 83 | |
| 84 | if ( num_face > 0 ) |
| 85 | { |
| 86 | struct hashtb_enumerator eef; |
| 87 | struct hashtb_enumerator *ef = &eef; |
| 88 | |
| 89 | hashtb_start(ne->face_list, ef); |
| 90 | int i; |
| 91 | |
| 92 | for ( i=0; i < num_face ; i++) |
| 93 | { |
| 94 | int face=faces[i]; |
| 95 | if ( face != NO_FACE && face != ZERO_FACE) |
| 96 | { |
| 97 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 98 | |
| 99 | if ( res_fle == HT_NEW_ENTRY ) |
| 100 | { |
| 101 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 102 | fle=ef->data; |
| 103 | fle->next_hop_face=face; |
| 104 | fle->route_cost=route_costs[i]; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | hashtb_end(ef); |
| 110 | } |
| 111 | |
| 112 | } |
| 113 | else if (res == HT_OLD_ENTRY) |
| 114 | { |
| 115 | free(ne); |
| 116 | struct npt_entry *one; |
| 117 | |
| 118 | one=e->data; |
| 119 | |
| 120 | struct hashtb_enumerator eenle; |
| 121 | struct hashtb_enumerator *enle = &eenle; |
| 122 | |
| 123 | hashtb_start(one->name_list, enle); |
| 124 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 125 | |
| 126 | if(res_nle == HT_NEW_ENTRY ) |
| 127 | { |
| 128 | struct name_list_entry *nle=(struct name_list_entry *)malloc(sizeof(struct name_list_entry)); |
| 129 | nle=enle->data; |
| 130 | nle->name=(char *)malloc(strlen(name_prefix)+1); |
| 131 | memset(nle->name,0,strlen(name_prefix)+1); |
| 132 | memcpy(nle->name,name_prefix,strlen(name_prefix)); |
| 133 | } |
| 134 | else if(res_nle == HT_OLD_ENTRY ) |
| 135 | { |
| 136 | |
| 137 | } |
| 138 | hashtb_end(enle); |
| 139 | |
| 140 | if ( num_face > 0 ) |
| 141 | { |
| 142 | struct hashtb_enumerator eef; |
| 143 | struct hashtb_enumerator *ef = &eef; |
| 144 | |
| 145 | hashtb_start(one->face_list, ef); |
| 146 | int i; |
| 147 | |
| 148 | for ( i=0; i< num_face ; i ++) |
| 149 | { |
| 150 | int face=faces[i]; |
| 151 | if ( face != NO_FACE && face != ZERO_FACE) |
| 152 | { |
| 153 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 154 | |
| 155 | if ( res_fle == HT_NEW_ENTRY ) |
| 156 | { |
| 157 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 158 | fle=ef->data; |
| 159 | fle->next_hop_face=face; |
| 160 | fle->route_cost=route_costs[i]; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | hashtb_end(ef); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | } |
| 169 | hashtb_end(e); |
| 170 | |
| 171 | update_ccnd_fib_for_orig_router(orig_router); |
| 172 | |
| 173 | return res; |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | update_ccnd_fib_for_orig_router(char *orig_router) |
| 178 | { |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 179 | |
| 180 | if ( nlsr->debugging ) |
| 181 | { |
| 182 | printf("update_ccnd_fib_for_orig_router called\n"); |
| 183 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 184 | |
| 185 | int res; |
| 186 | struct hashtb_enumerator ee; |
| 187 | struct hashtb_enumerator *e = ⅇ |
| 188 | |
| 189 | |
| 190 | hashtb_start(nlsr->npt, e); |
| 191 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 192 | |
| 193 | if(res == HT_NEW_ENTRY) |
| 194 | { |
| 195 | hashtb_delete(e); |
| 196 | } |
| 197 | else if ( res == HT_OLD_ENTRY ) |
| 198 | { |
| 199 | struct npt_entry *ne; |
| 200 | ne=e->data; |
| 201 | int num_face=hashtb_n(ne->face_list); |
| 202 | int last_face,first_face; |
| 203 | |
| 204 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 205 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 206 | |
| 207 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 208 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 209 | |
akmhoque | baf53f1 | 2013-01-24 11:06:18 -0600 | [diff] [blame] | 210 | if ( nlsr->debugging ) |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 211 | { |
akmhoque | baf53f1 | 2013-01-24 11:06:18 -0600 | [diff] [blame] | 212 | int m; |
| 213 | for ( m =0 ; m< num_face ; m++) |
| 214 | { |
| 215 | printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]); |
| 216 | } |
| 217 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 218 | |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 219 | last_face=0; |
| 220 | if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 221 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 222 | first_face=num_face-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 223 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 224 | else if( nlsr->max_faces_per_prefix > 0) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 225 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 226 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 227 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 228 | first_face=num_face-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 229 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 230 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 231 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 232 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 233 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 234 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | int i,j, nl_element; |
| 238 | struct name_list_entry *nle; |
| 239 | struct hashtb_enumerator eenle; |
| 240 | struct hashtb_enumerator *enle = &eenle; |
| 241 | |
| 242 | hashtb_start(ne->name_list, enle); |
| 243 | nl_element=hashtb_n(ne->name_list); |
| 244 | |
| 245 | for (i=0;i<nl_element;i++) |
| 246 | { |
| 247 | nle=enle->data; |
| 248 | |
| 249 | for( j=first_face; j>= last_face; j--) |
| 250 | { |
akmhoque | baf53f1 | 2013-01-24 11:06:18 -0600 | [diff] [blame] | 251 | if ( nlsr->debugging ) |
| 252 | { |
| 253 | printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]); |
| 254 | } |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 255 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 256 | { |
| 257 | if ( nlsr->debugging ) |
| 258 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 259 | if ( nlsr->detailed_logging ) |
| 260 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 261 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 262 | } |
| 263 | else |
| 264 | { |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 265 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 266 | { |
| 267 | if ( nlsr->debugging ) |
| 268 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 269 | if ( nlsr->detailed_logging ) |
| 270 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 271 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | |
| 277 | hashtb_next(enle); |
| 278 | } |
| 279 | hashtb_end(enle); |
| 280 | |
| 281 | |
| 282 | |
| 283 | free(faces); |
| 284 | free(route_costs); |
| 285 | |
| 286 | } |
| 287 | hashtb_end(e); |
| 288 | |
| 289 | } |
| 290 | |
| 291 | int |
| 292 | delete_npt_entry_by_router_and_name_prefix(char *orig_router, char *name_prefix) |
| 293 | { |
| 294 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 295 | { |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | struct npt_entry *ne; |
| 300 | |
| 301 | int res,res_nle; |
| 302 | struct hashtb_enumerator ee; |
| 303 | struct hashtb_enumerator *e = ⅇ |
| 304 | |
| 305 | |
| 306 | hashtb_start(nlsr->npt, e); |
| 307 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 308 | |
| 309 | if(res == HT_NEW_ENTRY) |
| 310 | { |
| 311 | hashtb_delete(e); |
| 312 | return -1; |
| 313 | } |
| 314 | else if (res == HT_OLD_ENTRY) |
| 315 | { |
| 316 | ne=e->data; |
| 317 | |
| 318 | struct hashtb_enumerator eenle; |
| 319 | struct hashtb_enumerator *enle = &eenle; |
| 320 | |
| 321 | hashtb_start(ne->name_list, enle); |
| 322 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 323 | |
| 324 | if(res_nle == HT_NEW_ENTRY ) |
| 325 | { |
| 326 | hashtb_delete(enle); |
| 327 | } |
| 328 | else if(res_nle == HT_OLD_ENTRY ) |
| 329 | { |
| 330 | struct name_list_entry *nle; |
| 331 | |
| 332 | nle=enle->data; |
| 333 | |
| 334 | int j; |
| 335 | int num_face=hashtb_n(ne->face_list); |
| 336 | int last_face,first_face; |
| 337 | |
| 338 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 339 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 340 | |
| 341 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 342 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 343 | |
| 344 | |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 345 | last_face=0; |
| 346 | if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 347 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 348 | first_face=num_face-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 349 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 350 | else if( nlsr->max_faces_per_prefix > 0) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 351 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 352 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 353 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 354 | first_face=num_face-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 355 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 356 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 357 | { |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 358 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 359 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 360 | |
| 361 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 362 | for( j=first_face; j>= last_face; j--) |
| 363 | { |
| 364 | |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 365 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 366 | { |
| 367 | if ( nlsr->debugging ) |
| 368 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 369 | if ( nlsr->detailed_logging ) |
| 370 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 371 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 372 | } |
| 373 | else |
| 374 | { |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 375 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 376 | { |
| 377 | if ( nlsr->debugging ) |
| 378 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 379 | if ( nlsr->detailed_logging ) |
| 380 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 381 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
| 385 | } |
| 386 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | hashtb_end(enle); |
| 390 | } |
| 391 | |
| 392 | hashtb_end(e); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | void |
| 398 | print_npt(void) |
| 399 | { |
| 400 | |
| 401 | if ( nlsr->debugging ) |
| 402 | { |
| 403 | printf("\n"); |
| 404 | printf("print_npt called\n"); |
| 405 | } |
| 406 | if ( nlsr->detailed_logging ) |
| 407 | { |
| 408 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 409 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n"); |
| 410 | } |
| 411 | int i, npt_element; |
| 412 | |
| 413 | struct npt_entry *ne; |
| 414 | |
| 415 | struct hashtb_enumerator ee; |
| 416 | struct hashtb_enumerator *e = ⅇ |
| 417 | |
| 418 | hashtb_start(nlsr->npt, e); |
| 419 | npt_element=hashtb_n(nlsr->npt); |
| 420 | |
| 421 | for(i=0;i<npt_element;i++) |
| 422 | { |
| 423 | if ( nlsr->debugging ) |
| 424 | { |
| 425 | printf("\n"); |
| 426 | printf("----------NPT ENTRY %d------------------\n",i+1); |
| 427 | } |
| 428 | if ( nlsr->detailed_logging ) |
| 429 | { |
| 430 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 431 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1); |
| 432 | } |
| 433 | ne=e->data; |
| 434 | if ( nlsr->debugging ) |
| 435 | printf(" Origination Router: %s \n",ne->orig_router); |
| 436 | if ( nlsr->detailed_logging ) |
| 437 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 438 | |
| 439 | int j, nl_element,face_list_element; |
| 440 | struct name_list_entry *nle; |
| 441 | struct hashtb_enumerator eenle; |
| 442 | struct hashtb_enumerator *enle = &eenle; |
| 443 | |
| 444 | hashtb_start(ne->name_list, enle); |
| 445 | nl_element=hashtb_n(ne->name_list); |
| 446 | |
| 447 | for (j=0;j<nl_element;j++) |
| 448 | { |
| 449 | nle=enle->data; |
| 450 | if ( nlsr->debugging ) |
| 451 | printf(" Name Prefix: %s \n",nle->name); |
| 452 | if ( nlsr->detailed_logging ) |
| 453 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name); |
| 454 | hashtb_next(enle); |
| 455 | } |
| 456 | hashtb_end(enle); |
| 457 | |
| 458 | struct face_list_entry *fle; |
| 459 | |
| 460 | struct hashtb_enumerator eef; |
| 461 | struct hashtb_enumerator *ef = &eef; |
| 462 | |
| 463 | hashtb_start(ne->face_list, ef); |
| 464 | face_list_element=hashtb_n(ne->face_list); |
| 465 | if ( face_list_element <= 0 ) |
| 466 | { |
| 467 | if ( nlsr->debugging ) |
| 468 | printf(" Face: No Face \n"); |
| 469 | if ( nlsr->detailed_logging ) |
| 470 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 471 | |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | for(j=0;j<face_list_element;j++) |
| 476 | { |
| 477 | fle=ef->data; |
| 478 | if ( nlsr->debugging ) |
akmhoque | f06586e | 2013-02-05 12:09:38 -0600 | [diff] [blame] | 479 | printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 480 | if ( nlsr->detailed_logging ) |
| 481 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost); |
| 482 | hashtb_next(ef); |
| 483 | } |
| 484 | } |
| 485 | hashtb_end(ef); |
| 486 | |
| 487 | |
| 488 | hashtb_next(e); |
| 489 | } |
| 490 | |
| 491 | hashtb_end(e); |
| 492 | |
| 493 | if ( nlsr->debugging ) |
| 494 | printf("\n"); |
| 495 | if ( nlsr->detailed_logging ) |
| 496 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 497 | } |
| 498 | |
| 499 | void |
| 500 | delete_orig_router_from_npt(char *orig_router) |
| 501 | { |
| 502 | int res,num_face,num_prefix; |
| 503 | struct npt_entry *ne; |
| 504 | |
| 505 | struct hashtb_enumerator ee; |
| 506 | struct hashtb_enumerator *e = ⅇ |
| 507 | |
| 508 | hashtb_start(nlsr->npt, e); |
| 509 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 510 | |
| 511 | if ( res == HT_OLD_ENTRY ) |
| 512 | { |
| 513 | ne=e->data; |
| 514 | num_prefix=hashtb_n(ne->name_list); |
| 515 | if ( num_prefix > 0 ) |
| 516 | { |
| 517 | num_face=hashtb_n(ne->face_list); |
| 518 | |
| 519 | if ( num_face > 0 ) |
| 520 | { |
| 521 | int j, nl_element; |
| 522 | struct name_list_entry *nle; |
| 523 | struct hashtb_enumerator eenle; |
| 524 | struct hashtb_enumerator *enle = &eenle; |
| 525 | |
| 526 | hashtb_start(ne->name_list, enle); |
| 527 | nl_element=hashtb_n(ne->name_list); |
| 528 | |
| 529 | for (j=0;j<nl_element;j++) |
| 530 | { |
| 531 | nle=enle->data; |
| 532 | delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name); |
| 533 | hashtb_next(enle); |
| 534 | } |
| 535 | hashtb_end(enle); |
| 536 | |
| 537 | } |
| 538 | |
| 539 | } |
| 540 | hashtb_destroy(&ne->name_list); |
| 541 | hashtb_destroy(&ne->face_list); |
| 542 | hashtb_delete(e); |
| 543 | } |
| 544 | else if ( res == HT_NEW_ENTRY ) |
| 545 | { |
| 546 | hashtb_delete(e); |
| 547 | } |
| 548 | hashtb_end(e); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | void |
| 553 | add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost) |
| 554 | { |
| 555 | if ( nlsr->debugging ) |
| 556 | { |
| 557 | printf("add_face_to_npt_by_face_id called\n"); |
| 558 | printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost); |
| 559 | } |
| 560 | if ( nlsr->detailed_logging ) |
| 561 | { |
| 562 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n"); |
| 563 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | int res,res1; |
| 568 | struct npt_entry *ne; |
| 569 | |
| 570 | struct hashtb_enumerator ee; |
| 571 | struct hashtb_enumerator *e = ⅇ |
| 572 | |
| 573 | hashtb_start(nlsr->npt, e); |
| 574 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 575 | |
| 576 | if ( res == HT_OLD_ENTRY ) |
| 577 | { |
| 578 | if ( nlsr->debugging ) |
| 579 | printf("Dest Router Found \n"); |
| 580 | if ( nlsr->detailed_logging ) |
| 581 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n"); |
| 582 | |
| 583 | ne=e->data; |
| 584 | |
| 585 | struct hashtb_enumerator eef; |
| 586 | struct hashtb_enumerator *ef = &eef; |
| 587 | |
| 588 | hashtb_start(ne->face_list, ef); |
| 589 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
| 590 | |
| 591 | if ( res1 == HT_OLD_ENTRY ) |
| 592 | { |
| 593 | if ( nlsr->debugging ) |
| 594 | printf("Face Found \n"); |
| 595 | if ( nlsr->detailed_logging ) |
| 596 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n"); |
akmhoque | baf53f1 | 2013-01-24 11:06:18 -0600 | [diff] [blame] | 597 | struct face_list_entry *fle; |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 598 | fle=ef->data; |
| 599 | fle->next_hop_face=face_id; |
| 600 | fle->route_cost=route_cost; |
| 601 | } |
| 602 | else if ( res1 == HT_NEW_ENTRY ) |
| 603 | { |
| 604 | if ( nlsr->debugging ) |
| 605 | printf("Face Not Found \n"); |
| 606 | if ( nlsr->detailed_logging ) |
| 607 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n"); |
| 608 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 609 | fle=ef->data; |
| 610 | fle->next_hop_face=face_id; |
| 611 | fle->route_cost=route_cost; |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 612 | |
| 613 | |
| 614 | |
| 615 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 616 | } |
| 617 | hashtb_end(ef); |
| 618 | } |
| 619 | else if (res == HT_NEW_ENTRY) |
| 620 | { |
| 621 | hashtb_delete(e); |
| 622 | } |
| 623 | |
| 624 | hashtb_end(e); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | void |
| 629 | add_new_fib_entries_to_npt(void) |
| 630 | { |
| 631 | if ( nlsr->debugging ) |
| 632 | printf("add_new_fib_entries_to_npt called\n"); |
| 633 | if ( nlsr->detailed_logging ) |
| 634 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n"); |
| 635 | int i,j, rt_element,face_list_element; |
| 636 | |
| 637 | struct routing_table_entry *rte; |
| 638 | |
| 639 | struct hashtb_enumerator ee; |
| 640 | struct hashtb_enumerator *e = ⅇ |
| 641 | |
| 642 | hashtb_start(nlsr->routing_table, e); |
| 643 | rt_element=hashtb_n(nlsr->routing_table); |
| 644 | |
| 645 | for(i=0;i<rt_element;i++) |
| 646 | { |
| 647 | rte=e->data; |
| 648 | |
| 649 | struct face_list_entry *fle; |
| 650 | |
| 651 | struct hashtb_enumerator eef; |
| 652 | struct hashtb_enumerator *ef = &eef; |
| 653 | |
| 654 | hashtb_start(rte->face_list, ef); |
| 655 | face_list_element=hashtb_n(rte->face_list); |
| 656 | if ( face_list_element <= 0 ) |
| 657 | { |
| 658 | if ( nlsr->debugging ) |
akmhoque | e19e3ee | 2013-01-22 14:38:45 -0600 | [diff] [blame] | 659 | printf(" Face: No Face \n"); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 660 | if ( nlsr->detailed_logging ) |
akmhoque | e19e3ee | 2013-01-22 14:38:45 -0600 | [diff] [blame] | 661 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 662 | } |
| 663 | else |
| 664 | { |
| 665 | for(j=0;j<face_list_element;j++) |
| 666 | { |
| 667 | fle=ef->data; |
akmhoque | eda9c36 | 2013-01-23 08:54:29 -0600 | [diff] [blame] | 668 | add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 669 | hashtb_next(ef); |
| 670 | } |
| 671 | } |
| 672 | hashtb_end(ef); |
| 673 | |
| 674 | hashtb_next(e); |
| 675 | } |
| 676 | |
| 677 | hashtb_end(e); |
| 678 | |
| 679 | } |
| 680 | |
| 681 | |
| 682 | void |
| 683 | delete_face_from_npt_by_face_id(char *dest_router, int face_id) |
| 684 | { |
| 685 | if ( nlsr->debugging ) |
| 686 | printf("delete_face_from_npt_by_face_id\n"); |
| 687 | if ( nlsr->detailed_logging ) |
| 688 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n"); |
| 689 | |
| 690 | int res,res1; |
| 691 | struct npt_entry *ne; |
| 692 | |
| 693 | struct hashtb_enumerator ee; |
| 694 | struct hashtb_enumerator *e = ⅇ |
| 695 | |
| 696 | hashtb_start(nlsr->npt, e); |
| 697 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 698 | |
| 699 | if ( res == HT_OLD_ENTRY ) |
| 700 | { |
| 701 | ne=e->data; |
| 702 | |
| 703 | struct hashtb_enumerator eef; |
| 704 | struct hashtb_enumerator *ef = &eef; |
| 705 | |
| 706 | hashtb_start(ne->face_list, ef); |
| 707 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 708 | if ( res1 == HT_OLD_ENTRY ) |
| 709 | { |
| 710 | hashtb_delete(ef); |
| 711 | } |
| 712 | else if ( res1 == HT_NEW_ENTRY ) |
| 713 | { |
| 714 | hashtb_delete(ef); |
| 715 | } |
| 716 | hashtb_end(ef); |
| 717 | } |
| 718 | else if (res == HT_NEW_ENTRY) |
| 719 | { |
| 720 | hashtb_delete(e); |
| 721 | } |
| 722 | |
| 723 | hashtb_end(e); |
| 724 | } |
| 725 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 726 | |
| 727 | void |
| 728 | clean_old_fib_entries_from_npt(void) |
| 729 | { |
| 730 | |
| 731 | |
| 732 | if ( nlsr->debugging ) |
| 733 | printf("clean_old_fib_entries_from_npt called\n\n"); |
| 734 | if ( nlsr->detailed_logging ) |
| 735 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n"); |
| 736 | int i, npt_element; |
| 737 | |
| 738 | struct npt_entry *ne; |
| 739 | |
| 740 | struct hashtb_enumerator ee; |
| 741 | struct hashtb_enumerator *e = ⅇ |
| 742 | |
| 743 | hashtb_start(nlsr->npt, e); |
| 744 | npt_element=hashtb_n(nlsr->npt); |
| 745 | |
| 746 | for(i=0;i<npt_element;i++) |
| 747 | { |
| 748 | ne=e->data; |
| 749 | |
| 750 | int j,k, nl_element,face_list_element; |
| 751 | struct face_list_entry *fle; |
| 752 | |
| 753 | struct hashtb_enumerator eef; |
| 754 | struct hashtb_enumerator *ef = &eef; |
| 755 | |
| 756 | hashtb_start(ne->face_list, ef); |
| 757 | face_list_element=hashtb_n(ne->face_list); |
| 758 | if ( face_list_element <= 0 ) |
| 759 | { |
| 760 | if ( nlsr->debugging ) |
akmhoque | e49af7a | 2013-01-22 14:58:37 -0600 | [diff] [blame] | 761 | printf(" Face: No Face \n"); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 762 | if ( nlsr->detailed_logging ) |
| 763 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 764 | |
| 765 | } |
| 766 | else |
| 767 | { |
| 768 | for(j=0;j<face_list_element;j++) |
| 769 | { |
| 770 | fle=ef->data; |
| 771 | int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face); |
| 772 | if ( check == 0 ) |
| 773 | { |
| 774 | struct name_list_entry *nle; |
| 775 | struct hashtb_enumerator eenle; |
| 776 | struct hashtb_enumerator *enle = &eenle; |
| 777 | |
| 778 | hashtb_start(ne->name_list, enle); |
| 779 | nl_element=hashtb_n(ne->name_list); |
| 780 | |
| 781 | for (k=0;k<nl_element;k++) |
| 782 | { |
| 783 | nle=enle->data; |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 784 | if( is_neighbor(nle->name) == 0 ) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 785 | { |
| 786 | if ( nlsr->debugging ) |
| 787 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 788 | if ( nlsr->detailed_logging ) |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 789 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 790 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | |
| 794 | hashtb_next(enle); |
| 795 | } |
| 796 | hashtb_end(enle); |
| 797 | |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 798 | |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 799 | hashtb_delete(ef); |
| 800 | j++; |
| 801 | |
| 802 | } |
| 803 | else |
| 804 | { |
akmhoque | aadd5ee | 2013-01-24 10:47:35 -0600 | [diff] [blame] | 805 | struct name_list_entry *nle; |
| 806 | struct hashtb_enumerator eenle; |
| 807 | struct hashtb_enumerator *enle = &eenle; |
| 808 | |
| 809 | hashtb_start(ne->name_list, enle); |
| 810 | nl_element=hashtb_n(ne->name_list); |
| 811 | |
| 812 | for (k=0;k<nl_element;k++) |
| 813 | { |
| 814 | nle=enle->data; |
| 815 | if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face ) |
| 816 | { |
| 817 | if ( nlsr->debugging ) |
| 818 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 819 | if ( nlsr->detailed_logging ) |
| 820 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 821 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face); |
| 822 | } |
| 823 | |
| 824 | |
| 825 | hashtb_next(enle); |
| 826 | } |
| 827 | hashtb_end(enle); |
| 828 | |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 829 | hashtb_next(ef); |
| 830 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | hashtb_end(ef); |
| 834 | |
| 835 | |
| 836 | hashtb_next(e); |
| 837 | } |
| 838 | |
| 839 | hashtb_end(e); |
| 840 | |
| 841 | } |
| 842 | |
| 843 | void |
| 844 | update_npt_with_new_route(void) |
| 845 | { |
akmhoque | 580ccf3 | 2013-01-23 09:12:33 -0600 | [diff] [blame] | 846 | if ( nlsr->debugging ) |
| 847 | printf("update_npt_with_new_route called\n"); |
| 848 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 849 | clean_old_fib_entries_from_npt(); |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 850 | print_npt(); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 851 | add_new_fib_entries_to_npt(); |
akmhoque | aaa1055 | 2013-01-24 08:00:42 -0600 | [diff] [blame] | 852 | print_npt(); |
| 853 | |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 854 | int i, npt_element; |
| 855 | |
| 856 | struct npt_entry *ne; |
| 857 | |
| 858 | struct hashtb_enumerator ee; |
| 859 | struct hashtb_enumerator *e = ⅇ |
| 860 | |
| 861 | hashtb_start(nlsr->npt, e); |
| 862 | npt_element=hashtb_n(nlsr->npt); |
| 863 | |
| 864 | for(i=0;i<npt_element;i++) |
| 865 | { |
| 866 | |
| 867 | ne=e->data; |
akmhoque | 613446f | 2013-01-23 10:40:12 -0600 | [diff] [blame] | 868 | update_ccnd_fib_for_orig_router(ne->orig_router); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 869 | hashtb_next(e); |
| 870 | } |
| 871 | |
| 872 | hashtb_end(e); |
| 873 | } |
| 874 | |
| 875 | |
| 876 | |
| 877 | void |
| 878 | sort_faces_by_distance(int *faces,int *route_costs,int start,int element) |
| 879 | { |
| 880 | int i,j; |
| 881 | int temp_cost; |
| 882 | int temp_face; |
| 883 | |
| 884 | for ( i=start ; i < element ; i ++) |
| 885 | { |
| 886 | for( j=i+1; j<element; j ++) |
| 887 | { |
| 888 | if (route_costs[j] < route_costs[i] ) |
| 889 | { |
| 890 | temp_cost=route_costs[j]; |
| 891 | route_costs[j]=route_costs[i]; |
| 892 | route_costs[i]=temp_cost; |
| 893 | |
| 894 | temp_face=faces[j]; |
| 895 | faces[j]=faces[i]; |
| 896 | faces[i]=temp_face; |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | } |
| 902 | |
| 903 | void |
| 904 | get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces) |
| 905 | { |
| 906 | |
| 907 | int res,face_list_element,j; |
| 908 | struct hashtb_enumerator ee; |
| 909 | struct hashtb_enumerator *e = ⅇ |
| 910 | |
| 911 | |
| 912 | hashtb_start(nlsr->npt, e); |
| 913 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 914 | |
| 915 | if(res == HT_NEW_ENTRY) |
| 916 | { |
| 917 | hashtb_delete(e); |
| 918 | } |
| 919 | else if ( res == HT_OLD_ENTRY ) |
| 920 | { |
| 921 | struct npt_entry *ne; |
| 922 | ne=e->data; |
| 923 | |
| 924 | struct face_list_entry *fle; |
| 925 | |
| 926 | struct hashtb_enumerator eef; |
| 927 | struct hashtb_enumerator *ef = &eef; |
| 928 | |
| 929 | hashtb_start(ne->face_list, ef); |
| 930 | face_list_element=hashtb_n(ne->face_list); |
| 931 | for(j=0;j<face_list_element;j++) |
| 932 | { |
| 933 | fle=ef->data; |
| 934 | faces[j]=fle->next_hop_face; |
| 935 | route_costs[j]=fle->route_cost; |
| 936 | hashtb_next(ef); |
| 937 | } |
| 938 | hashtb_end(ef); |
| 939 | |
| 940 | |
| 941 | } |
| 942 | hashtb_end(e); |
| 943 | |
| 944 | } |
| 945 | |
| 946 | void |
| 947 | destroy_faces_by_orig_router(char *orig_router) |
| 948 | { |
| 949 | |
| 950 | int res; |
| 951 | struct hashtb_enumerator ee; |
| 952 | struct hashtb_enumerator *e = ⅇ |
| 953 | |
| 954 | |
| 955 | hashtb_start(nlsr->npt, e); |
| 956 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 957 | |
| 958 | if(res == HT_NEW_ENTRY) |
| 959 | { |
| 960 | hashtb_delete(e); |
| 961 | } |
| 962 | else if ( res == HT_OLD_ENTRY ) |
| 963 | { |
| 964 | struct npt_entry *ne; |
| 965 | ne=e->data; |
| 966 | int num_face=hashtb_n(ne->face_list); |
| 967 | int last_face,first_face; |
| 968 | |
| 969 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 970 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 971 | |
| 972 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 973 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 974 | |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 975 | /* |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 976 | first_face=num_face-1; |
| 977 | |
| 978 | if ( nlsr->multi_path_face_num == 0 ) |
| 979 | { |
| 980 | last_face=first_face; |
| 981 | } |
| 982 | else |
| 983 | { |
| 984 | if ( num_face <= nlsr->multi_path_face_num) |
| 985 | { |
| 986 | last_face=0; |
| 987 | } |
| 988 | else if ( nlsr->multi_path_face_num == 0) |
| 989 | { |
| 990 | last_face=num_face-nlsr->multi_path_face_num; |
| 991 | } |
| 992 | } |
akmhoque | 496c88f | 2013-02-08 05:24:18 -0600 | [diff] [blame^] | 993 | */ |
| 994 | |
| 995 | last_face=0; |
| 996 | if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table |
| 997 | { |
| 998 | first_face=num_face-1; |
| 999 | } |
| 1000 | else if( nlsr->max_faces_per_prefix > 0) |
| 1001 | { |
| 1002 | if ( nlsr->max_faces_per_prefix >= num_face) |
| 1003 | { |
| 1004 | first_face=num_face-1; |
| 1005 | } |
| 1006 | else if ( nlsr->max_faces_per_prefix < num_face) |
| 1007 | { |
| 1008 | first_face=nlsr->max_faces_per_prefix-1; |
| 1009 | } |
| 1010 | |
| 1011 | } |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1012 | |
| 1013 | int i,j, nl_element; |
| 1014 | struct name_list_entry *nle; |
| 1015 | struct hashtb_enumerator eenle; |
| 1016 | struct hashtb_enumerator *enle = &eenle; |
| 1017 | |
| 1018 | hashtb_start(ne->name_list, enle); |
| 1019 | nl_element=hashtb_n(ne->name_list); |
| 1020 | |
| 1021 | for (i=0;i<nl_element;i++) |
| 1022 | { |
| 1023 | nle=enle->data; |
| 1024 | |
| 1025 | for( j=first_face; j>= last_face; j--) |
| 1026 | { |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 1027 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1028 | { |
| 1029 | if ( nlsr->debugging ) |
| 1030 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1031 | if ( nlsr->detailed_logging ) |
| 1032 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 1033 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1034 | } |
| 1035 | else |
| 1036 | { |
akmhoque | 9ca1bb8 | 2013-01-24 09:57:57 -0600 | [diff] [blame] | 1037 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1038 | { |
| 1039 | if ( nlsr->debugging ) |
| 1040 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1041 | if ( nlsr->detailed_logging ) |
| 1042 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | f9b35b3 | 2013-01-24 10:25:48 -0600 | [diff] [blame] | 1043 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
akmhoque | 8fdd641 | 2012-12-04 15:05:33 -0600 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | hashtb_next(enle); |
| 1049 | } |
| 1050 | hashtb_end(enle); |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | free(faces); |
| 1055 | free(route_costs); |
| 1056 | |
| 1057 | } |
| 1058 | hashtb_end(e); |
| 1059 | |
| 1060 | } |
| 1061 | |
| 1062 | void |
| 1063 | destroy_all_face_by_nlsr(void) |
| 1064 | { |
| 1065 | int i, npt_element; |
| 1066 | |
| 1067 | struct npt_entry *ne; |
| 1068 | |
| 1069 | struct hashtb_enumerator ee; |
| 1070 | struct hashtb_enumerator *e = ⅇ |
| 1071 | |
| 1072 | hashtb_start(nlsr->npt, e); |
| 1073 | npt_element=hashtb_n(nlsr->npt); |
| 1074 | |
| 1075 | for(i=0;i<npt_element;i++) |
| 1076 | { |
| 1077 | ne=e->data; |
| 1078 | destroy_faces_by_orig_router(ne->orig_router); |
| 1079 | hashtb_next(e); |
| 1080 | } |
| 1081 | |
| 1082 | hashtb_end(e); |
| 1083 | |
| 1084 | if ( nlsr->debugging ) |
| 1085 | printf("\n"); |
| 1086 | if ( nlsr->detailed_logging ) |
| 1087 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 1088 | } |