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 | |
| 372 | if ( hashtb_n(ne->name_list) == 0 ) |
| 373 | { |
| 374 | hashtb_delete(e); |
| 375 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | hashtb_end(e); |
| 379 | |
| 380 | return 0; |
| 381 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 382 | |
| 383 | void |
| 384 | print_npt(void) |
| 385 | { |
| 386 | printf("\n"); |
| 387 | printf("print_npt called\n\n"); |
| 388 | int i, npt_element; |
| 389 | |
| 390 | struct npt_entry *ne; |
| 391 | |
| 392 | struct hashtb_enumerator ee; |
| 393 | struct hashtb_enumerator *e = ⅇ |
| 394 | |
| 395 | hashtb_start(nlsr->npt, e); |
| 396 | npt_element=hashtb_n(nlsr->npt); |
| 397 | |
| 398 | for(i=0;i<npt_element;i++) |
| 399 | { |
| 400 | printf("\n"); |
| 401 | printf("----------NPT ENTRY %d------------------\n",i+1); |
| 402 | ne=e->data; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 403 | printf(" Origination Router: %s \n",ne->orig_router); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 404 | //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] | 405 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 406 | int j, nl_element,face_list_element; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 407 | struct name_list_entry *nle; |
| 408 | struct hashtb_enumerator eenle; |
| 409 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 410 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 411 | hashtb_start(ne->name_list, enle); |
| 412 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 413 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 414 | for (j=0;j<nl_element;j++) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 415 | { |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 416 | nle=enle->data; |
| 417 | printf(" Name Prefix: %s \n",nle->name); |
| 418 | hashtb_next(enle); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 419 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 420 | hashtb_end(enle); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 421 | |
| 422 | struct face_list_entry *fle; |
| 423 | |
| 424 | struct hashtb_enumerator eef; |
| 425 | struct hashtb_enumerator *ef = &eef; |
| 426 | |
| 427 | hashtb_start(ne->face_list, ef); |
| 428 | face_list_element=hashtb_n(ne->face_list); |
| 429 | if ( face_list_element <= 0 ) |
| 430 | { |
| 431 | printf(" Face: No Face \n"); |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | for(j=0;j<face_list_element;j++) |
| 436 | { |
| 437 | fle=ef->data; |
| 438 | printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost); |
| 439 | hashtb_next(ef); |
| 440 | } |
| 441 | } |
| 442 | hashtb_end(ef); |
| 443 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 444 | |
| 445 | hashtb_next(e); |
| 446 | } |
| 447 | |
| 448 | hashtb_end(e); |
| 449 | |
| 450 | printf("\n"); |
| 451 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 452 | |
| 453 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 454 | delete_orig_router_from_npt(char *orig_router) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 455 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 456 | int res,num_face,num_prefix; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 457 | struct npt_entry *ne; |
| 458 | |
| 459 | struct hashtb_enumerator ee; |
| 460 | struct hashtb_enumerator *e = ⅇ |
| 461 | |
| 462 | hashtb_start(nlsr->npt, e); |
| 463 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 464 | |
| 465 | if ( res == HT_OLD_ENTRY ) |
| 466 | { |
| 467 | ne=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 468 | num_prefix=hashtb_n(ne->name_list); |
| 469 | if ( num_prefix > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 470 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 471 | num_face=hashtb_n(ne->face_list); |
| 472 | |
| 473 | if ( num_face > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 474 | { |
| 475 | int j, nl_element; |
| 476 | struct name_list_entry *nle; |
| 477 | struct hashtb_enumerator eenle; |
| 478 | struct hashtb_enumerator *enle = &eenle; |
| 479 | |
| 480 | hashtb_start(ne->name_list, enle); |
| 481 | nl_element=hashtb_n(ne->name_list); |
| 482 | |
| 483 | for (j=0;j<nl_element;j++) |
| 484 | { |
| 485 | nle=enle->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 486 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 487 | delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name); |
| 488 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 489 | hashtb_next(enle); |
| 490 | } |
| 491 | hashtb_end(enle); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | } |
| 496 | hashtb_destroy(&ne->name_list); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 497 | hashtb_destroy(&ne->face_list); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 498 | hashtb_delete(e); |
| 499 | } |
| 500 | else if ( res == HT_NEW_ENTRY ) |
| 501 | { |
| 502 | hashtb_delete(e); |
| 503 | } |
| 504 | hashtb_end(e); |
| 505 | } |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 506 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 507 | |
| 508 | void |
| 509 | add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost) |
| 510 | { |
| 511 | printf("add_face_to_npt_by_face_id called\n"); |
| 512 | |
| 513 | printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost); |
| 514 | int res,res1; |
| 515 | struct npt_entry *ne; |
| 516 | |
| 517 | struct hashtb_enumerator ee; |
| 518 | struct hashtb_enumerator *e = ⅇ |
| 519 | |
| 520 | hashtb_start(nlsr->npt, e); |
| 521 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 522 | |
| 523 | if ( res == HT_OLD_ENTRY ) |
| 524 | { |
| 525 | printf("Dest Router Found \n"); |
| 526 | ne=e->data; |
| 527 | |
| 528 | struct hashtb_enumerator eef; |
| 529 | struct hashtb_enumerator *ef = &eef; |
| 530 | |
| 531 | hashtb_start(ne->face_list, ef); |
| 532 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
| 533 | |
| 534 | if ( res1 == HT_OLD_ENTRY ) |
| 535 | { |
| 536 | printf("Face 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 | } |
| 542 | else if ( res1 == HT_NEW_ENTRY ) |
| 543 | { |
| 544 | printf("Face Not Found \n"); |
| 545 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 546 | fle=ef->data; |
| 547 | fle->next_hop_face=face_id; |
| 548 | fle->route_cost=route_cost; |
| 549 | //hashtb_delete(ef); |
| 550 | } |
| 551 | hashtb_end(ef); |
| 552 | } |
| 553 | else if (res == HT_NEW_ENTRY) |
| 554 | { |
| 555 | hashtb_delete(e); |
| 556 | } |
| 557 | |
| 558 | hashtb_end(e); |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 563 | add_new_fib_entries_to_npt(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 564 | { |
| 565 | printf("add_new_fib_entries_to_npt called\n"); |
| 566 | int i,j, rt_element,face_list_element; |
| 567 | |
| 568 | struct routing_table_entry *rte; |
| 569 | |
| 570 | struct hashtb_enumerator ee; |
| 571 | struct hashtb_enumerator *e = ⅇ |
| 572 | |
| 573 | hashtb_start(nlsr->routing_table, e); |
| 574 | rt_element=hashtb_n(nlsr->routing_table); |
| 575 | |
| 576 | for(i=0;i<rt_element;i++) |
| 577 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 578 | rte=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 579 | |
| 580 | struct face_list_entry *fle; |
| 581 | |
| 582 | struct hashtb_enumerator eef; |
| 583 | struct hashtb_enumerator *ef = &eef; |
| 584 | |
| 585 | hashtb_start(rte->face_list, ef); |
| 586 | face_list_element=hashtb_n(rte->face_list); |
| 587 | if ( face_list_element <= 0 ) |
| 588 | { |
| 589 | printf(" Face: No Face \n"); |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | for(j=0;j<face_list_element;j++) |
| 594 | { |
| 595 | fle=ef->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 596 | add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost); |
| 597 | hashtb_next(ef); |
| 598 | } |
| 599 | } |
| 600 | hashtb_end(ef); |
| 601 | |
| 602 | hashtb_next(e); |
| 603 | } |
| 604 | |
| 605 | hashtb_end(e); |
| 606 | |
| 607 | } |
| 608 | |
| 609 | |
| 610 | void |
| 611 | delete_face_from_npt_by_face_id(char *dest_router, int face_id) |
| 612 | { |
| 613 | printf("delete_face_from_npt_by_face_id called\n"); |
| 614 | |
| 615 | int res,res1; |
| 616 | struct npt_entry *ne; |
| 617 | |
| 618 | struct hashtb_enumerator ee; |
| 619 | struct hashtb_enumerator *e = ⅇ |
| 620 | |
| 621 | hashtb_start(nlsr->npt, e); |
| 622 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 623 | |
| 624 | if ( res == HT_OLD_ENTRY ) |
| 625 | { |
| 626 | ne=e->data; |
| 627 | |
| 628 | struct hashtb_enumerator eef; |
| 629 | struct hashtb_enumerator *ef = &eef; |
| 630 | |
| 631 | hashtb_start(ne->face_list, ef); |
| 632 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
| 633 | |
| 634 | if ( res1 == HT_OLD_ENTRY ) |
| 635 | { |
| 636 | hashtb_delete(ef); |
| 637 | } |
| 638 | else if ( res1 == HT_NEW_ENTRY ) |
| 639 | { |
| 640 | hashtb_delete(ef); |
| 641 | } |
| 642 | hashtb_end(ef); |
| 643 | } |
| 644 | else if (res == HT_NEW_ENTRY) |
| 645 | { |
| 646 | hashtb_delete(e); |
| 647 | } |
| 648 | |
| 649 | hashtb_end(e); |
| 650 | } |
| 651 | |
| 652 | int |
| 653 | delete_old_face_from_npt(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 654 | { |
| 655 | if(flags == CCN_SCHEDULE_CANCEL) |
| 656 | { |
| 657 | return -1; |
| 658 | } |
| 659 | |
| 660 | nlsr_lock(); |
| 661 | |
| 662 | printf("delete_old_face_from_npt called\n"); |
| 663 | if ( ev->evdata != NULL ) |
| 664 | { |
| 665 | printf("Event Data: %s \n",(char *)ev->evdata); |
| 666 | char *sep="|"; |
| 667 | char *rem; |
| 668 | char *orig_router; |
| 669 | char *faceid; |
| 670 | int face_id; |
| 671 | |
| 672 | char *face_data=(char *)malloc(strlen((char *)ev->evdata)+1); |
| 673 | memset(face_data,0,strlen((char *)ev->evdata)+1); |
| 674 | memcpy(face_data+strlen(face_data),(char *)ev->evdata,strlen((char *)ev->evdata)); |
| 675 | |
| 676 | orig_router=strtok_r(face_data,sep,&rem); |
| 677 | faceid=strtok_r(NULL,sep,&rem); |
| 678 | face_id=atoi(faceid); |
| 679 | printf("Orig Router: %s Face: %d \n",orig_router,face_id); |
| 680 | |
| 681 | delete_face_from_npt_by_face_id(orig_router,face_id); |
| 682 | } |
| 683 | |
| 684 | nlsr_unlock(); |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 690 | clean_old_fib_entries_from_npt(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 691 | { |
| 692 | |
| 693 | printf("clean_old_fib_entries_from_npt called\n\n"); |
| 694 | int i, npt_element; |
| 695 | |
| 696 | struct npt_entry *ne; |
| 697 | |
| 698 | struct hashtb_enumerator ee; |
| 699 | struct hashtb_enumerator *e = ⅇ |
| 700 | |
| 701 | hashtb_start(nlsr->npt, e); |
| 702 | npt_element=hashtb_n(nlsr->npt); |
| 703 | |
| 704 | for(i=0;i<npt_element;i++) |
| 705 | { |
| 706 | ne=e->data; |
| 707 | |
| 708 | int j,k, nl_element,face_list_element; |
| 709 | struct face_list_entry *fle; |
| 710 | |
| 711 | struct hashtb_enumerator eef; |
| 712 | struct hashtb_enumerator *ef = &eef; |
| 713 | |
| 714 | hashtb_start(ne->face_list, ef); |
| 715 | face_list_element=hashtb_n(ne->face_list); |
| 716 | if ( face_list_element <= 0 ) |
| 717 | { |
| 718 | printf(" Face: No Face \n"); |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | for(j=0;j<face_list_element;j++) |
| 723 | { |
| 724 | fle=ef->data; |
| 725 | int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face); |
| 726 | if ( check == 0 ) |
| 727 | { |
| 728 | struct name_list_entry *nle; |
| 729 | struct hashtb_enumerator eenle; |
| 730 | struct hashtb_enumerator *enle = &eenle; |
| 731 | |
| 732 | hashtb_start(ne->name_list, enle); |
| 733 | nl_element=hashtb_n(ne->name_list); |
| 734 | |
| 735 | for (k=0;k<nl_element;k++) |
| 736 | { |
| 737 | nle=enle->data; |
| 738 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 739 | //delete all the fib entries here |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 740 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 741 | |
| 742 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 743 | if( is_neighbor(nle->name) == 0 ) |
| 744 | { |
akmhoque | 0820a2e | 2012-09-24 20:23:01 -0500 | [diff] [blame] | 745 | 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] | 746 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face); |
| 747 | } |
| 748 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 749 | |
| 750 | hashtb_next(enle); |
| 751 | } |
| 752 | hashtb_end(enle); |
| 753 | |
| 754 | char faceid[20]; |
| 755 | memset(faceid,0,20); |
| 756 | sprintf(faceid,"%d",fle->next_hop_face); |
| 757 | char *evdata=(char *)malloc(strlen(ne->orig_router)+strlen(faceid)+2); |
| 758 | memset(evdata,0,strlen(ne->orig_router)+strlen(faceid)+2); |
| 759 | memcpy(evdata+strlen(evdata),ne->orig_router,strlen(ne->orig_router)); |
| 760 | memcpy(evdata+strlen(evdata),"|",1); |
| 761 | memcpy(evdata+strlen(evdata),faceid,strlen(faceid)); |
| 762 | |
| 763 | nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_old_face_from_npt, (void *)evdata, 0); |
| 764 | |
| 765 | } |
| 766 | |
| 767 | hashtb_next(ef); |
| 768 | } |
| 769 | } |
| 770 | hashtb_end(ef); |
| 771 | |
| 772 | |
| 773 | hashtb_next(e); |
| 774 | } |
| 775 | |
| 776 | hashtb_end(e); |
| 777 | |
| 778 | } |
| 779 | |
| 780 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 781 | update_npt_with_new_route(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 782 | { |
| 783 | clean_old_fib_entries_from_npt(); |
| 784 | add_new_fib_entries_to_npt(); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 785 | |
| 786 | int i, npt_element; |
| 787 | |
| 788 | struct npt_entry *ne; |
| 789 | |
| 790 | struct hashtb_enumerator ee; |
| 791 | struct hashtb_enumerator *e = ⅇ |
| 792 | |
| 793 | hashtb_start(nlsr->npt, e); |
| 794 | npt_element=hashtb_n(nlsr->npt); |
| 795 | |
| 796 | for(i=0;i<npt_element;i++) |
| 797 | { |
| 798 | |
| 799 | ne=e->data; |
| 800 | update_ccnd_fib_for_orig_router(ne->orig_router); |
| 801 | hashtb_next(e); |
| 802 | } |
| 803 | |
| 804 | hashtb_end(e); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | |
| 809 | void |
| 810 | sort_faces_by_distance(int *faces,int *route_costs,int start,int element) |
| 811 | { |
| 812 | int i,j; |
| 813 | int temp_cost; |
| 814 | int temp_face; |
| 815 | |
| 816 | for ( i=start ; i < element ; i ++) |
| 817 | { |
| 818 | for( j=i+1; j<element; j ++) |
| 819 | { |
| 820 | if (route_costs[j] < route_costs[i] ) |
| 821 | { |
| 822 | temp_cost=route_costs[j]; |
| 823 | route_costs[j]=route_costs[i]; |
| 824 | route_costs[i]=temp_cost; |
| 825 | |
| 826 | temp_face=faces[j]; |
| 827 | faces[j]=faces[i]; |
| 828 | faces[i]=temp_face; |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | } |
| 834 | |
| 835 | void |
| 836 | get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces) |
| 837 | { |
| 838 | |
| 839 | int res,face_list_element,j; |
| 840 | struct hashtb_enumerator ee; |
| 841 | struct hashtb_enumerator *e = ⅇ |
| 842 | |
| 843 | |
| 844 | hashtb_start(nlsr->npt, e); |
| 845 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 846 | |
| 847 | if(res == HT_NEW_ENTRY) |
| 848 | { |
| 849 | hashtb_delete(e); |
| 850 | } |
| 851 | else if ( res == HT_OLD_ENTRY ) |
| 852 | { |
| 853 | struct npt_entry *ne; |
| 854 | ne=e->data; |
| 855 | |
| 856 | struct face_list_entry *fle; |
| 857 | |
| 858 | struct hashtb_enumerator eef; |
| 859 | struct hashtb_enumerator *ef = &eef; |
| 860 | |
| 861 | hashtb_start(ne->face_list, ef); |
| 862 | face_list_element=hashtb_n(ne->face_list); |
| 863 | for(j=0;j<face_list_element;j++) |
| 864 | { |
| 865 | fle=ef->data; |
| 866 | faces[j]=fle->next_hop_face; |
| 867 | route_costs[j]=fle->route_cost; |
| 868 | hashtb_next(ef); |
| 869 | } |
| 870 | hashtb_end(ef); |
| 871 | |
| 872 | |
| 873 | } |
| 874 | hashtb_end(e); |
| 875 | |
| 876 | } |
| 877 | |
| 878 | void |
| 879 | destroy_faces_by_orig_router(char *orig_router) |
| 880 | { |
| 881 | |
| 882 | int res; |
| 883 | struct hashtb_enumerator ee; |
| 884 | struct hashtb_enumerator *e = ⅇ |
| 885 | |
| 886 | |
| 887 | hashtb_start(nlsr->npt, e); |
| 888 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 889 | |
| 890 | if(res == HT_NEW_ENTRY) |
| 891 | { |
| 892 | hashtb_delete(e); |
| 893 | } |
| 894 | else if ( res == HT_OLD_ENTRY ) |
| 895 | { |
| 896 | struct npt_entry *ne; |
| 897 | ne=e->data; |
| 898 | int num_face=hashtb_n(ne->face_list); |
| 899 | int last_face,first_face; |
| 900 | |
| 901 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 902 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 903 | |
| 904 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 905 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 906 | |
| 907 | |
| 908 | first_face=num_face-1; |
| 909 | |
| 910 | if ( nlsr->multi_path_face_num == 0 ) |
| 911 | { |
| 912 | last_face=first_face; |
| 913 | } |
| 914 | else |
| 915 | { |
| 916 | if ( num_face <= nlsr->multi_path_face_num) |
| 917 | { |
| 918 | last_face=0; |
| 919 | } |
| 920 | else if ( nlsr->multi_path_face_num == 0) |
| 921 | { |
| 922 | last_face=num_face-nlsr->multi_path_face_num; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | int i,j, nl_element; |
| 927 | struct name_list_entry *nle; |
| 928 | struct hashtb_enumerator eenle; |
| 929 | struct hashtb_enumerator *enle = &eenle; |
| 930 | |
| 931 | hashtb_start(ne->name_list, enle); |
| 932 | nl_element=hashtb_n(ne->name_list); |
| 933 | |
| 934 | for (i=0;i<nl_element;i++) |
| 935 | { |
| 936 | nle=enle->data; |
| 937 | |
| 938 | for( j=first_face; j>= last_face; j--) |
| 939 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 940 | if ( is_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 941 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 942 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 943 | 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] | 944 | } |
| 945 | else |
| 946 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 947 | if ( j == last_face && is_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 948 | { |
akmhoque | 0820a2e | 2012-09-24 20:23:01 -0500 | [diff] [blame] | 949 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 950 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | hashtb_next(enle); |
| 956 | } |
| 957 | hashtb_end(enle); |
| 958 | |
| 959 | |
| 960 | |
| 961 | free(faces); |
| 962 | free(route_costs); |
| 963 | |
| 964 | } |
| 965 | hashtb_end(e); |
| 966 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 967 | } |
| 968 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 969 | void |
| 970 | destroy_all_face_by_nlsr(void) |
| 971 | { |
| 972 | int i, npt_element; |
| 973 | |
| 974 | struct npt_entry *ne; |
| 975 | |
| 976 | struct hashtb_enumerator ee; |
| 977 | struct hashtb_enumerator *e = ⅇ |
| 978 | |
| 979 | hashtb_start(nlsr->npt, e); |
| 980 | npt_element=hashtb_n(nlsr->npt); |
| 981 | |
| 982 | for(i=0;i<npt_element;i++) |
| 983 | { |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 984 | ne=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 985 | destroy_faces_by_orig_router(ne->orig_router); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 986 | hashtb_next(e); |
| 987 | } |
| 988 | |
| 989 | hashtb_end(e); |
| 990 | |
| 991 | printf("\n"); |
| 992 | } |