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