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