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 | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 38 | struct npt_entry *ne;//=(struct npt_entry*)calloc(1,sizeof(struct npt_entry )); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 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 | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 59 | //struct hashtb_param param_nle = {0}; |
| 60 | ne->name_list= hashtb_create(sizeof(struct name_list_entry ),NULL); |
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 | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 70 | struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry)); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 71 | nle=enle->data; |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 72 | nle->name=(char *)calloc(strlen(name_prefix)+1,sizeof(char)); |
| 73 | //memset(nle->name,0,strlen(name_prefix)+1); |
| 74 | memcpy(nle->name,name_prefix,strlen(name_prefix)+1); |
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 | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 81 | //struct hashtb_param param_fle = {0}; |
| 82 | ne->face_list=hashtb_create(sizeof(struct face_list_entry), NULL); |
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 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 101 | struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry)); |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 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 | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 128 | struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,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 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 157 | struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry)); |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 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 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 180 | if ( nlsr->debugging ) |
| 181 | { |
| 182 | printf("update_ccnd_fib_for_orig_router called\n"); |
| 183 | } |
| 184 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 185 | int res; |
| 186 | struct hashtb_enumerator ee; |
| 187 | struct hashtb_enumerator *e = ⅇ |
| 188 | |
| 189 | |
| 190 | hashtb_start(nlsr->npt, e); |
| 191 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 192 | |
| 193 | if(res == HT_NEW_ENTRY) |
| 194 | { |
| 195 | hashtb_delete(e); |
| 196 | } |
| 197 | else if ( res == HT_OLD_ENTRY ) |
| 198 | { |
| 199 | struct npt_entry *ne; |
| 200 | ne=e->data; |
| 201 | int num_face=hashtb_n(ne->face_list); |
| 202 | int last_face,first_face; |
| 203 | |
| 204 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 205 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 206 | |
| 207 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 208 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 209 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 210 | if ( nlsr->debugging ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 211 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 212 | int m; |
| 213 | for ( m =0 ; m< num_face ; m++) |
| 214 | { |
| 215 | printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]); |
| 216 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 217 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 218 | |
| 219 | last_face=0; |
| 220 | if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 221 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 222 | first_face=num_face-1; |
| 223 | } |
| 224 | else if( nlsr->max_faces_per_prefix > 0) |
| 225 | { |
| 226 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 227 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 228 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 229 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 230 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 231 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 232 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 233 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 234 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | int i,j, nl_element; |
| 238 | struct name_list_entry *nle; |
| 239 | struct hashtb_enumerator eenle; |
| 240 | struct hashtb_enumerator *enle = &eenle; |
| 241 | |
| 242 | hashtb_start(ne->name_list, enle); |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 243 | nl_element=hashtb_n(ne->name_list); |
| 244 | |
| 245 | for (i=0;i<nl_element;i++) |
| 246 | { |
| 247 | nle=enle->data; |
| 248 | |
| 249 | for( j=num_face-1; j>= 0; j--) |
| 250 | { |
| 251 | |
| 252 | if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) ) |
| 253 | { |
| 254 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | |
| 259 | hashtb_next(enle); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | hashtb_end(enle); |
| 264 | |
| 265 | if ( nlsr->debugging ) |
| 266 | { |
| 267 | printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face); |
| 268 | } |
| 269 | |
| 270 | hashtb_start(ne->name_list, enle); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 271 | nl_element=hashtb_n(ne->name_list); |
| 272 | |
| 273 | for (i=0;i<nl_element;i++) |
| 274 | { |
| 275 | nle=enle->data; |
| 276 | |
| 277 | for( j=first_face; j>= last_face; j--) |
| 278 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 279 | if ( nlsr->debugging ) |
| 280 | { |
| 281 | printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]); |
| 282 | } |
| 283 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 284 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 285 | if ( nlsr->debugging ) |
| 286 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 287 | if ( nlsr->detailed_logging ) |
| 288 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 289 | 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] | 290 | } |
| 291 | else |
| 292 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 293 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 294 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 295 | if ( nlsr->debugging ) |
| 296 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 297 | if ( nlsr->detailed_logging ) |
| 298 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 299 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j]); |
| 300 | } |
| 301 | } |
| 302 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 303 | |
| 304 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 305 | hashtb_next(enle); |
| 306 | } |
| 307 | hashtb_end(enle); |
| 308 | |
| 309 | |
| 310 | |
| 311 | free(faces); |
| 312 | free(route_costs); |
| 313 | |
| 314 | } |
| 315 | hashtb_end(e); |
| 316 | |
| 317 | } |
| 318 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 319 | int |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 320 | 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] | 321 | { |
| 322 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 323 | { |
| 324 | return -1; |
| 325 | } |
| 326 | |
| 327 | struct npt_entry *ne; |
| 328 | |
| 329 | int res,res_nle; |
| 330 | struct hashtb_enumerator ee; |
| 331 | struct hashtb_enumerator *e = ⅇ |
| 332 | |
| 333 | |
| 334 | hashtb_start(nlsr->npt, e); |
| 335 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 336 | |
| 337 | if(res == HT_NEW_ENTRY) |
| 338 | { |
| 339 | hashtb_delete(e); |
| 340 | return -1; |
| 341 | } |
| 342 | else if (res == HT_OLD_ENTRY) |
| 343 | { |
| 344 | ne=e->data; |
| 345 | |
| 346 | struct hashtb_enumerator eenle; |
| 347 | struct hashtb_enumerator *enle = &eenle; |
| 348 | |
| 349 | hashtb_start(ne->name_list, enle); |
| 350 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 351 | |
| 352 | if(res_nle == HT_NEW_ENTRY ) |
| 353 | { |
| 354 | hashtb_delete(enle); |
| 355 | } |
| 356 | else if(res_nle == HT_OLD_ENTRY ) |
| 357 | { |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 358 | struct name_list_entry *nle; |
| 359 | |
| 360 | nle=enle->data; |
| 361 | |
| 362 | int j; |
| 363 | int num_face=hashtb_n(ne->face_list); |
| 364 | int last_face,first_face; |
| 365 | |
| 366 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 367 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 368 | |
| 369 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 370 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 371 | |
| 372 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 373 | last_face=0; |
| 374 | if ( nlsr->max_faces_per_prefix == 0) // add all faces available in routing table |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 375 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 376 | first_face=num_face-1; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 377 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 378 | else if( nlsr->max_faces_per_prefix > 0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 379 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 380 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 381 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 382 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 383 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 384 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 385 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 386 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 387 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 388 | |
| 389 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 390 | for( j=first_face; j>= last_face; j--) |
| 391 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 392 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 393 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 394 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 395 | if ( nlsr->debugging ) |
| 396 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 397 | if ( nlsr->detailed_logging ) |
| 398 | 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] | 399 | 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] | 400 | } |
| 401 | else |
| 402 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 403 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 404 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 405 | if ( nlsr->debugging ) |
| 406 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 407 | if ( nlsr->detailed_logging ) |
| 408 | 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] | 409 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
| 410 | } |
| 411 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 412 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 413 | } |
| 414 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | hashtb_end(enle); |
| 418 | } |
| 419 | |
| 420 | hashtb_end(e); |
| 421 | |
| 422 | return 0; |
| 423 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 424 | |
| 425 | void |
| 426 | print_npt(void) |
| 427 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 428 | |
| 429 | if ( nlsr->debugging ) |
| 430 | { |
| 431 | printf("\n"); |
| 432 | printf("print_npt called\n"); |
| 433 | } |
| 434 | if ( nlsr->detailed_logging ) |
| 435 | { |
| 436 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 437 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n"); |
| 438 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 439 | int i, npt_element; |
| 440 | |
| 441 | struct npt_entry *ne; |
| 442 | |
| 443 | struct hashtb_enumerator ee; |
| 444 | struct hashtb_enumerator *e = ⅇ |
| 445 | |
| 446 | hashtb_start(nlsr->npt, e); |
| 447 | npt_element=hashtb_n(nlsr->npt); |
| 448 | |
| 449 | for(i=0;i<npt_element;i++) |
| 450 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 451 | if ( nlsr->debugging ) |
| 452 | { |
| 453 | printf("\n"); |
| 454 | printf("----------NPT ENTRY %d------------------\n",i+1); |
| 455 | } |
| 456 | if ( nlsr->detailed_logging ) |
| 457 | { |
| 458 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 459 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1); |
| 460 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 461 | ne=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 462 | if ( nlsr->debugging ) |
| 463 | printf(" Origination Router: %s \n",ne->orig_router); |
| 464 | if ( nlsr->detailed_logging ) |
| 465 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 466 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 467 | int j, nl_element,face_list_element; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 468 | struct name_list_entry *nle; |
| 469 | struct hashtb_enumerator eenle; |
| 470 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 471 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 472 | hashtb_start(ne->name_list, enle); |
| 473 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 474 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 475 | for (j=0;j<nl_element;j++) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 476 | { |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 477 | nle=enle->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 478 | if ( nlsr->debugging ) |
| 479 | printf(" Name Prefix: %s \n",nle->name); |
| 480 | if ( nlsr->detailed_logging ) |
| 481 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 482 | hashtb_next(enle); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 483 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 484 | hashtb_end(enle); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 485 | |
| 486 | struct face_list_entry *fle; |
| 487 | |
| 488 | struct hashtb_enumerator eef; |
| 489 | struct hashtb_enumerator *ef = &eef; |
| 490 | |
| 491 | hashtb_start(ne->face_list, ef); |
| 492 | face_list_element=hashtb_n(ne->face_list); |
| 493 | if ( face_list_element <= 0 ) |
| 494 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 495 | if ( nlsr->debugging ) |
| 496 | printf(" Face: No Face \n"); |
| 497 | if ( nlsr->detailed_logging ) |
| 498 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 499 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 500 | } |
| 501 | else |
| 502 | { |
| 503 | for(j=0;j<face_list_element;j++) |
| 504 | { |
| 505 | fle=ef->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 506 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 507 | printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 508 | if ( nlsr->detailed_logging ) |
| 509 | 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] | 510 | hashtb_next(ef); |
| 511 | } |
| 512 | } |
| 513 | hashtb_end(ef); |
| 514 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 515 | |
| 516 | hashtb_next(e); |
| 517 | } |
| 518 | |
| 519 | hashtb_end(e); |
| 520 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 521 | if ( nlsr->debugging ) |
| 522 | printf("\n"); |
| 523 | if ( nlsr->detailed_logging ) |
| 524 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 525 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 526 | |
| 527 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 528 | delete_orig_router_from_npt(char *orig_router) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 529 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 530 | int res,num_face,num_prefix; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 531 | struct npt_entry *ne; |
| 532 | |
| 533 | struct hashtb_enumerator ee; |
| 534 | struct hashtb_enumerator *e = ⅇ |
| 535 | |
| 536 | hashtb_start(nlsr->npt, e); |
| 537 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 538 | |
| 539 | if ( res == HT_OLD_ENTRY ) |
| 540 | { |
| 541 | ne=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 542 | num_prefix=hashtb_n(ne->name_list); |
| 543 | if ( num_prefix > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 544 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 545 | num_face=hashtb_n(ne->face_list); |
| 546 | |
| 547 | if ( num_face > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 548 | { |
| 549 | int j, nl_element; |
| 550 | struct name_list_entry *nle; |
| 551 | struct hashtb_enumerator eenle; |
| 552 | struct hashtb_enumerator *enle = &eenle; |
| 553 | |
| 554 | hashtb_start(ne->name_list, enle); |
| 555 | nl_element=hashtb_n(ne->name_list); |
| 556 | |
| 557 | for (j=0;j<nl_element;j++) |
| 558 | { |
| 559 | nle=enle->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 560 | delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 561 | hashtb_next(enle); |
| 562 | } |
| 563 | hashtb_end(enle); |
| 564 | |
| 565 | } |
| 566 | |
| 567 | } |
| 568 | hashtb_destroy(&ne->name_list); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 569 | hashtb_destroy(&ne->face_list); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 570 | hashtb_delete(e); |
| 571 | } |
| 572 | else if ( res == HT_NEW_ENTRY ) |
| 573 | { |
| 574 | hashtb_delete(e); |
| 575 | } |
| 576 | hashtb_end(e); |
| 577 | } |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 578 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 579 | |
| 580 | void |
| 581 | add_face_to_npt_by_face_id(char *dest_router, int face_id, int route_cost) |
| 582 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 583 | if ( nlsr->debugging ) |
| 584 | { |
| 585 | printf("add_face_to_npt_by_face_id called\n"); |
| 586 | printf("Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost); |
| 587 | } |
| 588 | if ( nlsr->detailed_logging ) |
| 589 | { |
| 590 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_face_to_npt_by_face_id called\n"); |
| 591 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router: %s Face: %d Route_cost: %d \n",dest_router, face_id, route_cost); |
| 592 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 593 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 594 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 595 | int res,res1; |
| 596 | struct npt_entry *ne; |
| 597 | |
| 598 | struct hashtb_enumerator ee; |
| 599 | struct hashtb_enumerator *e = ⅇ |
| 600 | |
| 601 | hashtb_start(nlsr->npt, e); |
| 602 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 603 | |
| 604 | if ( res == HT_OLD_ENTRY ) |
| 605 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 606 | if ( nlsr->debugging ) |
| 607 | printf("Dest Router Found \n"); |
| 608 | if ( nlsr->detailed_logging ) |
| 609 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest Router Found \n"); |
| 610 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 611 | ne=e->data; |
| 612 | |
| 613 | struct hashtb_enumerator eef; |
| 614 | struct hashtb_enumerator *ef = &eef; |
| 615 | |
| 616 | hashtb_start(ne->face_list, ef); |
| 617 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
| 618 | |
| 619 | if ( res1 == HT_OLD_ENTRY ) |
| 620 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 621 | if ( nlsr->debugging ) |
| 622 | printf("Face Found \n"); |
| 623 | if ( nlsr->detailed_logging ) |
| 624 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Found \n"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 625 | struct face_list_entry *fle; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 626 | fle=ef->data; |
| 627 | fle->next_hop_face=face_id; |
| 628 | fle->route_cost=route_cost; |
| 629 | } |
| 630 | else if ( res1 == HT_NEW_ENTRY ) |
| 631 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 632 | if ( nlsr->debugging ) |
| 633 | printf("Face Not Found \n"); |
| 634 | if ( nlsr->detailed_logging ) |
| 635 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 636 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 637 | fle=ef->data; |
| 638 | fle->next_hop_face=face_id; |
| 639 | fle->route_cost=route_cost; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 640 | |
| 641 | |
| 642 | |
| 643 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 644 | } |
| 645 | hashtb_end(ef); |
| 646 | } |
| 647 | else if (res == HT_NEW_ENTRY) |
| 648 | { |
| 649 | hashtb_delete(e); |
| 650 | } |
| 651 | |
| 652 | hashtb_end(e); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 657 | add_new_fib_entries_to_npt(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 658 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 659 | if ( nlsr->debugging ) |
| 660 | printf("add_new_fib_entries_to_npt called\n"); |
| 661 | if ( nlsr->detailed_logging ) |
| 662 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"add_new_fib_entries_to_npt called\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 663 | int i,j, rt_element,face_list_element; |
| 664 | |
| 665 | struct routing_table_entry *rte; |
| 666 | |
| 667 | struct hashtb_enumerator ee; |
| 668 | struct hashtb_enumerator *e = ⅇ |
| 669 | |
| 670 | hashtb_start(nlsr->routing_table, e); |
| 671 | rt_element=hashtb_n(nlsr->routing_table); |
| 672 | |
| 673 | for(i=0;i<rt_element;i++) |
| 674 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 675 | rte=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 676 | |
| 677 | struct face_list_entry *fle; |
| 678 | |
| 679 | struct hashtb_enumerator eef; |
| 680 | struct hashtb_enumerator *ef = &eef; |
| 681 | |
| 682 | hashtb_start(rte->face_list, ef); |
| 683 | face_list_element=hashtb_n(rte->face_list); |
| 684 | if ( face_list_element <= 0 ) |
| 685 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 686 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 687 | printf(" Face: No Face \n"); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 688 | if ( nlsr->detailed_logging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 689 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 690 | } |
| 691 | else |
| 692 | { |
| 693 | for(j=0;j<face_list_element;j++) |
| 694 | { |
| 695 | fle=ef->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 696 | add_face_to_npt_by_face_id(rte->dest_router,fle->next_hop_face,fle->route_cost); |
| 697 | hashtb_next(ef); |
| 698 | } |
| 699 | } |
| 700 | hashtb_end(ef); |
| 701 | |
| 702 | hashtb_next(e); |
| 703 | } |
| 704 | |
| 705 | hashtb_end(e); |
| 706 | |
| 707 | } |
| 708 | |
| 709 | |
| 710 | void |
| 711 | delete_face_from_npt_by_face_id(char *dest_router, int face_id) |
| 712 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 713 | if ( nlsr->debugging ) |
| 714 | printf("delete_face_from_npt_by_face_id\n"); |
| 715 | if ( nlsr->detailed_logging ) |
| 716 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_face_from_npt_by_face_id\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 717 | |
| 718 | int res,res1; |
| 719 | struct npt_entry *ne; |
| 720 | |
| 721 | struct hashtb_enumerator ee; |
| 722 | struct hashtb_enumerator *e = ⅇ |
| 723 | |
| 724 | hashtb_start(nlsr->npt, e); |
| 725 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 726 | |
| 727 | if ( res == HT_OLD_ENTRY ) |
| 728 | { |
| 729 | ne=e->data; |
| 730 | |
| 731 | struct hashtb_enumerator eef; |
| 732 | struct hashtb_enumerator *ef = &eef; |
| 733 | |
| 734 | hashtb_start(ne->face_list, ef); |
| 735 | res1=hashtb_seek(ef, &face_id, sizeof(face_id), 0); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 736 | if ( res1 == HT_OLD_ENTRY ) |
| 737 | { |
| 738 | hashtb_delete(ef); |
| 739 | } |
| 740 | else if ( res1 == HT_NEW_ENTRY ) |
| 741 | { |
| 742 | hashtb_delete(ef); |
| 743 | } |
| 744 | hashtb_end(ef); |
| 745 | } |
| 746 | else if (res == HT_NEW_ENTRY) |
| 747 | { |
| 748 | hashtb_delete(e); |
| 749 | } |
| 750 | |
| 751 | hashtb_end(e); |
| 752 | } |
| 753 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 754 | |
| 755 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 756 | clean_old_fib_entries_from_npt(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 757 | { |
| 758 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 759 | |
| 760 | if ( nlsr->debugging ) |
| 761 | printf("clean_old_fib_entries_from_npt called\n\n"); |
| 762 | if ( nlsr->detailed_logging ) |
| 763 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 764 | int i, npt_element; |
| 765 | |
| 766 | struct npt_entry *ne; |
| 767 | |
| 768 | struct hashtb_enumerator ee; |
| 769 | struct hashtb_enumerator *e = ⅇ |
| 770 | |
| 771 | hashtb_start(nlsr->npt, e); |
| 772 | npt_element=hashtb_n(nlsr->npt); |
| 773 | |
| 774 | for(i=0;i<npt_element;i++) |
| 775 | { |
| 776 | ne=e->data; |
| 777 | |
| 778 | int j,k, nl_element,face_list_element; |
| 779 | struct face_list_entry *fle; |
| 780 | |
| 781 | struct hashtb_enumerator eef; |
| 782 | struct hashtb_enumerator *ef = &eef; |
| 783 | |
| 784 | hashtb_start(ne->face_list, ef); |
| 785 | face_list_element=hashtb_n(ne->face_list); |
| 786 | if ( face_list_element <= 0 ) |
| 787 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 788 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 789 | printf(" Face: No Face \n"); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 790 | if ( nlsr->detailed_logging ) |
| 791 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 792 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 793 | } |
| 794 | else |
| 795 | { |
| 796 | for(j=0;j<face_list_element;j++) |
| 797 | { |
| 798 | fle=ef->data; |
| 799 | int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face); |
| 800 | if ( check == 0 ) |
| 801 | { |
| 802 | struct name_list_entry *nle; |
| 803 | struct hashtb_enumerator eenle; |
| 804 | struct hashtb_enumerator *enle = &eenle; |
| 805 | |
| 806 | hashtb_start(ne->name_list, enle); |
| 807 | nl_element=hashtb_n(ne->name_list); |
| 808 | |
| 809 | for (k=0;k<nl_element;k++) |
| 810 | { |
| 811 | nle=enle->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 812 | if( is_neighbor(nle->name) == 0 ) |
| 813 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 814 | if ( nlsr->debugging ) |
| 815 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 816 | if ( nlsr->detailed_logging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 817 | 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] | 818 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face); |
| 819 | } |
| 820 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 821 | |
| 822 | hashtb_next(enle); |
| 823 | } |
| 824 | hashtb_end(enle); |
| 825 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 826 | |
| 827 | hashtb_delete(ef); |
| 828 | j++; |
| 829 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 830 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 831 | else |
| 832 | { |
| 833 | struct name_list_entry *nle; |
| 834 | struct hashtb_enumerator eenle; |
| 835 | struct hashtb_enumerator *enle = &eenle; |
| 836 | |
| 837 | hashtb_start(ne->name_list, enle); |
| 838 | nl_element=hashtb_n(ne->name_list); |
| 839 | |
| 840 | for (k=0;k<nl_element;k++) |
| 841 | { |
| 842 | nle=enle->data; |
| 843 | if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face ) |
| 844 | { |
| 845 | if ( nlsr->debugging ) |
| 846 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 847 | if ( nlsr->detailed_logging ) |
| 848 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 849 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | hashtb_next(enle); |
| 854 | } |
| 855 | hashtb_end(enle); |
| 856 | |
| 857 | hashtb_next(ef); |
| 858 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 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 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 874 | if ( nlsr->debugging ) |
| 875 | printf("update_npt_with_new_route called\n"); |
| 876 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 877 | clean_old_fib_entries_from_npt(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 878 | print_npt(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 879 | add_new_fib_entries_to_npt(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 880 | print_npt(); |
| 881 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 882 | int i, npt_element; |
| 883 | |
| 884 | struct npt_entry *ne; |
| 885 | |
| 886 | struct hashtb_enumerator ee; |
| 887 | struct hashtb_enumerator *e = ⅇ |
| 888 | |
| 889 | hashtb_start(nlsr->npt, e); |
| 890 | npt_element=hashtb_n(nlsr->npt); |
| 891 | |
| 892 | for(i=0;i<npt_element;i++) |
| 893 | { |
| 894 | |
| 895 | ne=e->data; |
| 896 | update_ccnd_fib_for_orig_router(ne->orig_router); |
| 897 | hashtb_next(e); |
| 898 | } |
| 899 | |
| 900 | hashtb_end(e); |
| 901 | } |
| 902 | |
| 903 | |
| 904 | |
| 905 | void |
| 906 | sort_faces_by_distance(int *faces,int *route_costs,int start,int element) |
| 907 | { |
| 908 | int i,j; |
| 909 | int temp_cost; |
| 910 | int temp_face; |
| 911 | |
| 912 | for ( i=start ; i < element ; i ++) |
| 913 | { |
| 914 | for( j=i+1; j<element; j ++) |
| 915 | { |
| 916 | if (route_costs[j] < route_costs[i] ) |
| 917 | { |
| 918 | temp_cost=route_costs[j]; |
| 919 | route_costs[j]=route_costs[i]; |
| 920 | route_costs[i]=temp_cost; |
| 921 | |
| 922 | temp_face=faces[j]; |
| 923 | faces[j]=faces[i]; |
| 924 | faces[i]=temp_face; |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | } |
| 930 | |
| 931 | void |
| 932 | get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces) |
| 933 | { |
| 934 | |
| 935 | int res,face_list_element,j; |
| 936 | struct hashtb_enumerator ee; |
| 937 | struct hashtb_enumerator *e = ⅇ |
| 938 | |
| 939 | |
| 940 | hashtb_start(nlsr->npt, e); |
| 941 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 942 | |
| 943 | if(res == HT_NEW_ENTRY) |
| 944 | { |
| 945 | hashtb_delete(e); |
| 946 | } |
| 947 | else if ( res == HT_OLD_ENTRY ) |
| 948 | { |
| 949 | struct npt_entry *ne; |
| 950 | ne=e->data; |
| 951 | |
| 952 | struct face_list_entry *fle; |
| 953 | |
| 954 | struct hashtb_enumerator eef; |
| 955 | struct hashtb_enumerator *ef = &eef; |
| 956 | |
| 957 | hashtb_start(ne->face_list, ef); |
| 958 | face_list_element=hashtb_n(ne->face_list); |
| 959 | for(j=0;j<face_list_element;j++) |
| 960 | { |
| 961 | fle=ef->data; |
| 962 | faces[j]=fle->next_hop_face; |
| 963 | route_costs[j]=fle->route_cost; |
| 964 | hashtb_next(ef); |
| 965 | } |
| 966 | hashtb_end(ef); |
| 967 | |
| 968 | |
| 969 | } |
| 970 | hashtb_end(e); |
| 971 | |
| 972 | } |
| 973 | |
| 974 | void |
| 975 | destroy_faces_by_orig_router(char *orig_router) |
| 976 | { |
| 977 | |
| 978 | int res; |
| 979 | struct hashtb_enumerator ee; |
| 980 | struct hashtb_enumerator *e = ⅇ |
| 981 | |
| 982 | |
| 983 | hashtb_start(nlsr->npt, e); |
| 984 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 985 | |
| 986 | if(res == HT_NEW_ENTRY) |
| 987 | { |
| 988 | hashtb_delete(e); |
| 989 | } |
| 990 | else if ( res == HT_OLD_ENTRY ) |
| 991 | { |
| 992 | struct npt_entry *ne; |
| 993 | ne=e->data; |
| 994 | int num_face=hashtb_n(ne->face_list); |
| 995 | int last_face,first_face; |
| 996 | |
| 997 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 998 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 999 | |
| 1000 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 1001 | sort_faces_by_distance(faces,route_costs,0,num_face); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1002 | last_face=0; |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 1003 | if ( nlsr->max_faces_per_prefix == 0) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1004 | { |
| 1005 | first_face=num_face-1; |
| 1006 | } |
| 1007 | else if( nlsr->max_faces_per_prefix > 0) |
| 1008 | { |
| 1009 | if ( nlsr->max_faces_per_prefix >= num_face) |
| 1010 | { |
| 1011 | first_face=num_face-1; |
| 1012 | } |
| 1013 | else if ( nlsr->max_faces_per_prefix < num_face) |
| 1014 | { |
| 1015 | first_face=nlsr->max_faces_per_prefix-1; |
| 1016 | } |
| 1017 | |
| 1018 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1019 | |
| 1020 | int i,j, nl_element; |
| 1021 | struct name_list_entry *nle; |
| 1022 | struct hashtb_enumerator eenle; |
| 1023 | struct hashtb_enumerator *enle = &eenle; |
| 1024 | |
| 1025 | hashtb_start(ne->name_list, enle); |
| 1026 | nl_element=hashtb_n(ne->name_list); |
| 1027 | |
| 1028 | for (i=0;i<nl_element;i++) |
| 1029 | { |
| 1030 | nle=enle->data; |
| 1031 | |
| 1032 | for( j=first_face; j>= last_face; j--) |
| 1033 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1034 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1035 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1036 | if ( nlsr->debugging ) |
| 1037 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1038 | if ( nlsr->detailed_logging ) |
| 1039 | 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] | 1040 | 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] | 1041 | } |
| 1042 | else |
| 1043 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1044 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1045 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1046 | if ( nlsr->debugging ) |
| 1047 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1048 | if ( nlsr->detailed_logging ) |
| 1049 | 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] | 1050 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j]); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | hashtb_next(enle); |
| 1056 | } |
| 1057 | hashtb_end(enle); |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | free(faces); |
| 1062 | free(route_costs); |
| 1063 | |
| 1064 | } |
| 1065 | hashtb_end(e); |
| 1066 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1069 | void |
| 1070 | destroy_all_face_by_nlsr(void) |
| 1071 | { |
| 1072 | int i, npt_element; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1073 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1074 | struct npt_entry *ne; |
| 1075 | |
| 1076 | struct hashtb_enumerator ee; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1077 | struct hashtb_enumerator *e = ⅇ |
| 1078 | |
| 1079 | hashtb_start(nlsr->npt, e); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1080 | npt_element=hashtb_n(nlsr->npt); |
| 1081 | |
| 1082 | for(i=0;i<npt_element;i++) |
| 1083 | { |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1084 | ne=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1085 | destroy_faces_by_orig_router(ne->orig_router); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1086 | hashtb_next(e); |
| 1087 | } |
| 1088 | |
| 1089 | hashtb_end(e); |
| 1090 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1091 | if ( nlsr->debugging ) |
| 1092 | printf("\n"); |
| 1093 | if ( nlsr->detailed_logging ) |
| 1094 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1095 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame^] | 1096 | |
| 1097 | void |
| 1098 | destroy_name_list(void) |
| 1099 | { |
| 1100 | |
| 1101 | } |
| 1102 | |
| 1103 | void |
| 1104 | destroy_face_list(void) |
| 1105 | { |
| 1106 | |
| 1107 | } |
| 1108 | |
| 1109 | void |
| 1110 | destroy_npt(void) |
| 1111 | { |
| 1112 | |
| 1113 | |
| 1114 | int i, npt_element; |
| 1115 | struct npt_entry *ne; |
| 1116 | |
| 1117 | struct hashtb_enumerator ee; |
| 1118 | struct hashtb_enumerator *e = ⅇ |
| 1119 | |
| 1120 | hashtb_start(nlsr->npt, e); |
| 1121 | npt_element=hashtb_n(nlsr->npt); |
| 1122 | |
| 1123 | for(i=0;i<npt_element;i++) |
| 1124 | { |
| 1125 | ne=e->data; |
| 1126 | |
| 1127 | int j, nl_element,face_list_element; |
| 1128 | struct name_list_entry *nle; |
| 1129 | struct hashtb_enumerator eenle; |
| 1130 | struct hashtb_enumerator *enle = &eenle; |
| 1131 | |
| 1132 | hashtb_start(ne->name_list, enle); |
| 1133 | nl_element=hashtb_n(ne->name_list); |
| 1134 | |
| 1135 | for (j=0;j<nl_element;j++) |
| 1136 | { |
| 1137 | nle=enle->data; |
| 1138 | hashtb_next(enle); |
| 1139 | } |
| 1140 | hashtb_end(enle); |
| 1141 | |
| 1142 | struct face_list_entry *fle; |
| 1143 | struct hashtb_enumerator eef; |
| 1144 | struct hashtb_enumerator *ef = &eef; |
| 1145 | |
| 1146 | hashtb_start(ne->face_list, ef); |
| 1147 | face_list_element=hashtb_n(ne->face_list); |
| 1148 | |
| 1149 | for(j=0;j<face_list_element;j++) |
| 1150 | { |
| 1151 | fle=ef->data; |
| 1152 | hashtb_next(ef); |
| 1153 | } |
| 1154 | |
| 1155 | hashtb_end(ef); |
| 1156 | |
| 1157 | |
| 1158 | hashtb_next(e); |
| 1159 | } |
| 1160 | |
| 1161 | hashtb_end(e); |
| 1162 | } |
| 1163 | |