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