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