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