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 | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 52 | ne->orig_router=(char *)calloc(strlen(orig_router)+1,sizeof(char)); |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 53 | memcpy(ne->orig_router,orig_router,strlen(orig_router)+1); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 54 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 55 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 56 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 57 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 58 | //struct hashtb_param param_nle = {0}; |
| 59 | ne->name_list= hashtb_create(sizeof(struct name_list_entry ),NULL); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 60 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 61 | struct hashtb_enumerator eenle; |
| 62 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 63 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 64 | hashtb_start(ne->name_list, enle); |
| 65 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 66 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 67 | if(res_nle == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 68 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 69 | 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] | 70 | nle=enle->data; |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 71 | nle->name=(char *)calloc(strlen(name_prefix)+1,sizeof(char)); |
| 72 | //memset(nle->name,0,strlen(name_prefix)+1); |
| 73 | memcpy(nle->name,name_prefix,strlen(name_prefix)+1); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 74 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 75 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 76 | |
| 77 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 78 | hashtb_end(enle); |
| 79 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 80 | //struct hashtb_param param_fle = {0}; |
| 81 | ne->face_list=hashtb_create(sizeof(struct face_list_entry), NULL); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 82 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 83 | if ( num_face > 0 ) |
| 84 | { |
| 85 | struct hashtb_enumerator eef; |
| 86 | struct hashtb_enumerator *ef = &eef; |
| 87 | |
| 88 | hashtb_start(ne->face_list, ef); |
| 89 | int i; |
| 90 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 91 | for ( i=0; i < num_face ; i++) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 92 | { |
| 93 | int face=faces[i]; |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 94 | if ( face != NO_FACE && face != ZERO_FACE) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 95 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 96 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 97 | |
| 98 | if ( res_fle == HT_NEW_ENTRY ) |
| 99 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 100 | 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] | 101 | fle=ef->data; |
| 102 | fle->next_hop_face=face; |
| 103 | fle->route_cost=route_costs[i]; |
| 104 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | } |
| 108 | hashtb_end(ef); |
| 109 | } |
| 110 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 111 | } |
| 112 | else if (res == HT_OLD_ENTRY) |
| 113 | { |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 114 | struct npt_entry *one; |
| 115 | |
| 116 | one=e->data; |
| 117 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 118 | struct hashtb_enumerator eenle; |
| 119 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 120 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 121 | hashtb_start(one->name_list, enle); |
| 122 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 123 | |
| 124 | if(res_nle == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 125 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 126 | 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] | 127 | nle=enle->data; |
| 128 | nle->name=(char *)malloc(strlen(name_prefix)+1); |
| 129 | memset(nle->name,0,strlen(name_prefix)+1); |
| 130 | memcpy(nle->name,name_prefix,strlen(name_prefix)); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 131 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 132 | else if(res_nle == HT_OLD_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 133 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 134 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 135 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 136 | hashtb_end(enle); |
| 137 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 138 | if ( num_face > 0 ) |
| 139 | { |
| 140 | struct hashtb_enumerator eef; |
| 141 | struct hashtb_enumerator *ef = &eef; |
| 142 | |
| 143 | hashtb_start(one->face_list, ef); |
| 144 | int i; |
| 145 | |
| 146 | for ( i=0; i< num_face ; i ++) |
| 147 | { |
| 148 | int face=faces[i]; |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 149 | if ( face != NO_FACE && face != ZERO_FACE) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 150 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 151 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 152 | |
| 153 | if ( res_fle == HT_NEW_ENTRY ) |
| 154 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 155 | 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] | 156 | fle=ef->data; |
| 157 | fle->next_hop_face=face; |
| 158 | fle->route_cost=route_costs[i]; |
| 159 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 160 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 161 | } |
| 162 | hashtb_end(ef); |
| 163 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 164 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 165 | |
| 166 | } |
| 167 | hashtb_end(e); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 168 | |
| 169 | update_ccnd_fib_for_orig_router(orig_router); |
| 170 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 171 | return res; |
| 172 | } |
| 173 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 174 | void |
| 175 | update_ccnd_fib_for_orig_router(char *orig_router) |
| 176 | { |
| 177 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 178 | if ( nlsr->debugging ) |
| 179 | { |
| 180 | printf("update_ccnd_fib_for_orig_router called\n"); |
| 181 | } |
| 182 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 183 | int res; |
| 184 | struct hashtb_enumerator ee; |
| 185 | struct hashtb_enumerator *e = ⅇ |
| 186 | |
| 187 | |
| 188 | hashtb_start(nlsr->npt, e); |
| 189 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 190 | |
| 191 | if(res == HT_NEW_ENTRY) |
| 192 | { |
| 193 | hashtb_delete(e); |
| 194 | } |
| 195 | else if ( res == HT_OLD_ENTRY ) |
| 196 | { |
| 197 | struct npt_entry *ne; |
| 198 | ne=e->data; |
| 199 | int num_face=hashtb_n(ne->face_list); |
| 200 | int last_face,first_face; |
| 201 | |
| 202 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 203 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 204 | |
| 205 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 206 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 207 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 208 | if ( nlsr->debugging ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 209 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 210 | int m; |
| 211 | for ( m =0 ; m< num_face ; m++) |
| 212 | { |
| 213 | printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]); |
| 214 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 215 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 216 | |
| 217 | last_face=0; |
| 218 | 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] | 219 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 220 | first_face=num_face-1; |
| 221 | } |
| 222 | else if( nlsr->max_faces_per_prefix > 0) |
| 223 | { |
| 224 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 225 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 226 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 227 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 228 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 229 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 230 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 231 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 232 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | int i,j, nl_element; |
| 236 | struct name_list_entry *nle; |
| 237 | struct hashtb_enumerator eenle; |
| 238 | struct hashtb_enumerator *enle = &eenle; |
| 239 | |
| 240 | hashtb_start(ne->name_list, enle); |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 241 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 242 | |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 243 | for (i=0;i<nl_element;i++) |
| 244 | { |
| 245 | nle=enle->data; |
| 246 | |
| 247 | for( j=num_face-1; j>= 0; j--) |
| 248 | { |
| 249 | |
| 250 | if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) ) |
| 251 | { |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 252 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval); |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | |
| 257 | hashtb_next(enle); |
| 258 | } |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 259 | hashtb_end(enle); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 260 | |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 261 | |
| 262 | if ( nlsr->debugging ) |
| 263 | { |
| 264 | printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face); |
| 265 | } |
| 266 | |
| 267 | hashtb_start(ne->name_list, enle); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 268 | nl_element=hashtb_n(ne->name_list); |
| 269 | |
| 270 | for (i=0;i<nl_element;i++) |
| 271 | { |
| 272 | nle=enle->data; |
| 273 | |
| 274 | for( j=first_face; j>= last_face; j--) |
| 275 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 276 | if ( nlsr->debugging ) |
| 277 | { |
| 278 | printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]); |
| 279 | } |
| 280 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 281 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 282 | if ( nlsr->debugging ) |
| 283 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 284 | if ( nlsr->detailed_logging ) |
| 285 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 286 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 287 | } |
| 288 | else |
| 289 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 290 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 291 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 292 | if ( nlsr->debugging ) |
| 293 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 294 | if ( nlsr->detailed_logging ) |
| 295 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 296 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_REG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 300 | |
| 301 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 302 | hashtb_next(enle); |
| 303 | } |
| 304 | hashtb_end(enle); |
| 305 | |
| 306 | |
| 307 | |
| 308 | free(faces); |
| 309 | free(route_costs); |
| 310 | |
| 311 | } |
| 312 | hashtb_end(e); |
| 313 | |
| 314 | } |
| 315 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 316 | int |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 317 | 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] | 318 | { |
| 319 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 320 | { |
| 321 | return -1; |
| 322 | } |
| 323 | |
| 324 | struct npt_entry *ne; |
| 325 | |
| 326 | int res,res_nle; |
| 327 | struct hashtb_enumerator ee; |
| 328 | struct hashtb_enumerator *e = ⅇ |
| 329 | |
| 330 | |
| 331 | hashtb_start(nlsr->npt, e); |
| 332 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 333 | |
| 334 | if(res == HT_NEW_ENTRY) |
| 335 | { |
| 336 | hashtb_delete(e); |
| 337 | return -1; |
| 338 | } |
| 339 | else if (res == HT_OLD_ENTRY) |
| 340 | { |
| 341 | ne=e->data; |
| 342 | |
| 343 | struct hashtb_enumerator eenle; |
| 344 | struct hashtb_enumerator *enle = &eenle; |
| 345 | |
| 346 | hashtb_start(ne->name_list, enle); |
| 347 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 348 | |
| 349 | if(res_nle == HT_NEW_ENTRY ) |
| 350 | { |
| 351 | hashtb_delete(enle); |
| 352 | } |
| 353 | else if(res_nle == HT_OLD_ENTRY ) |
| 354 | { |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 355 | struct name_list_entry *nle; |
| 356 | |
| 357 | nle=enle->data; |
| 358 | |
| 359 | int j; |
| 360 | int num_face=hashtb_n(ne->face_list); |
| 361 | int last_face,first_face; |
| 362 | |
| 363 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 364 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 365 | |
| 366 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 367 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 368 | |
| 369 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 370 | last_face=0; |
| 371 | 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] | 372 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 373 | first_face=num_face-1; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 374 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 375 | else if( nlsr->max_faces_per_prefix > 0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 376 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 377 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 378 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 379 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 380 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 381 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 382 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 383 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 384 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 385 | |
| 386 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 387 | for( j=first_face; j>= last_face; j--) |
| 388 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 389 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 390 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 391 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 392 | if ( nlsr->debugging ) |
| 393 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 394 | if ( nlsr->detailed_logging ) |
| 395 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 396 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 397 | } |
| 398 | else |
| 399 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 400 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 401 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 402 | if ( nlsr->debugging ) |
| 403 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 404 | if ( nlsr->detailed_logging ) |
| 405 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 406 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 407 | } |
| 408 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 409 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 410 | } |
| 411 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | hashtb_end(enle); |
| 415 | } |
| 416 | |
| 417 | hashtb_end(e); |
| 418 | |
| 419 | return 0; |
| 420 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 421 | |
| 422 | void |
| 423 | print_npt(void) |
| 424 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 425 | |
| 426 | if ( nlsr->debugging ) |
| 427 | { |
| 428 | printf("\n"); |
| 429 | printf("print_npt called\n"); |
| 430 | } |
| 431 | if ( nlsr->detailed_logging ) |
| 432 | { |
| 433 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 434 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n"); |
| 435 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 436 | int i, npt_element; |
| 437 | |
| 438 | struct npt_entry *ne; |
| 439 | |
| 440 | struct hashtb_enumerator ee; |
| 441 | struct hashtb_enumerator *e = ⅇ |
| 442 | |
| 443 | hashtb_start(nlsr->npt, e); |
| 444 | npt_element=hashtb_n(nlsr->npt); |
| 445 | |
| 446 | for(i=0;i<npt_element;i++) |
| 447 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 448 | if ( nlsr->debugging ) |
| 449 | { |
| 450 | printf("\n"); |
| 451 | printf("----------NPT ENTRY %d------------------\n",i+1); |
| 452 | } |
| 453 | if ( nlsr->detailed_logging ) |
| 454 | { |
| 455 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 456 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1); |
| 457 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 458 | ne=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 459 | if ( nlsr->debugging ) |
| 460 | printf(" Origination Router: %s \n",ne->orig_router); |
| 461 | if ( nlsr->detailed_logging ) |
| 462 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 463 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 464 | int j, nl_element,face_list_element; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 465 | struct name_list_entry *nle; |
| 466 | struct hashtb_enumerator eenle; |
| 467 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 468 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 469 | hashtb_start(ne->name_list, enle); |
| 470 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 471 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 472 | for (j=0;j<nl_element;j++) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 473 | { |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 474 | nle=enle->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 475 | if ( nlsr->debugging ) |
| 476 | printf(" Name Prefix: %s \n",nle->name); |
| 477 | if ( nlsr->detailed_logging ) |
| 478 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 479 | hashtb_next(enle); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 480 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 481 | hashtb_end(enle); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 482 | |
| 483 | struct face_list_entry *fle; |
| 484 | |
| 485 | struct hashtb_enumerator eef; |
| 486 | struct hashtb_enumerator *ef = &eef; |
| 487 | |
| 488 | hashtb_start(ne->face_list, ef); |
| 489 | face_list_element=hashtb_n(ne->face_list); |
| 490 | if ( face_list_element <= 0 ) |
| 491 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 492 | if ( nlsr->debugging ) |
| 493 | printf(" Face: No Face \n"); |
| 494 | if ( nlsr->detailed_logging ) |
| 495 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 496 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 497 | } |
| 498 | else |
| 499 | { |
| 500 | for(j=0;j<face_list_element;j++) |
| 501 | { |
| 502 | fle=ef->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 503 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 504 | 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] | 505 | if ( nlsr->detailed_logging ) |
| 506 | 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] | 507 | hashtb_next(ef); |
| 508 | } |
| 509 | } |
| 510 | hashtb_end(ef); |
| 511 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 512 | |
| 513 | hashtb_next(e); |
| 514 | } |
| 515 | |
| 516 | hashtb_end(e); |
| 517 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 518 | if ( nlsr->debugging ) |
| 519 | printf("\n"); |
| 520 | if ( nlsr->detailed_logging ) |
| 521 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 522 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 523 | |
| 524 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 525 | delete_orig_router_from_npt(char *orig_router) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 526 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 527 | int res,num_face,num_prefix; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 528 | struct npt_entry *ne; |
| 529 | |
| 530 | struct hashtb_enumerator ee; |
| 531 | struct hashtb_enumerator *e = ⅇ |
| 532 | |
| 533 | hashtb_start(nlsr->npt, e); |
| 534 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 535 | |
| 536 | if ( res == HT_OLD_ENTRY ) |
| 537 | { |
| 538 | ne=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 539 | num_prefix=hashtb_n(ne->name_list); |
| 540 | if ( num_prefix > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 541 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 542 | num_face=hashtb_n(ne->face_list); |
| 543 | |
| 544 | if ( num_face > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 545 | { |
| 546 | int j, nl_element; |
| 547 | struct name_list_entry *nle; |
| 548 | struct hashtb_enumerator eenle; |
| 549 | struct hashtb_enumerator *enle = &eenle; |
| 550 | |
| 551 | hashtb_start(ne->name_list, enle); |
| 552 | nl_element=hashtb_n(ne->name_list); |
| 553 | |
| 554 | for (j=0;j<nl_element;j++) |
| 555 | { |
| 556 | nle=enle->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 557 | delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 558 | hashtb_next(enle); |
| 559 | } |
| 560 | hashtb_end(enle); |
| 561 | |
| 562 | } |
| 563 | |
| 564 | } |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 565 | //hashtb_destroy(&ne->name_list); |
| 566 | //hashtb_destroy(&ne->face_list); |
akmhoque | 80817e2 | 2013-03-15 08:13:41 -0500 | [diff] [blame] | 567 | free(ne->orig_router); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 568 | destroy_name_list(ne->name_list); |
| 569 | destroy_face_list(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 | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 636 | struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 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 | { |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 738 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 739 | hashtb_delete(ef); |
| 740 | } |
| 741 | else if ( res1 == HT_NEW_ENTRY ) |
| 742 | { |
| 743 | hashtb_delete(ef); |
| 744 | } |
| 745 | hashtb_end(ef); |
| 746 | } |
| 747 | else if (res == HT_NEW_ENTRY) |
| 748 | { |
| 749 | hashtb_delete(e); |
| 750 | } |
| 751 | |
| 752 | hashtb_end(e); |
| 753 | } |
| 754 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 755 | |
| 756 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 757 | clean_old_fib_entries_from_npt(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 758 | { |
| 759 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 760 | |
| 761 | if ( nlsr->debugging ) |
| 762 | printf("clean_old_fib_entries_from_npt called\n\n"); |
| 763 | if ( nlsr->detailed_logging ) |
| 764 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"clean_old_fib_entries_from_npt called\n\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 765 | int i, npt_element; |
| 766 | |
| 767 | struct npt_entry *ne; |
| 768 | |
| 769 | struct hashtb_enumerator ee; |
| 770 | struct hashtb_enumerator *e = ⅇ |
| 771 | |
| 772 | hashtb_start(nlsr->npt, e); |
| 773 | npt_element=hashtb_n(nlsr->npt); |
| 774 | |
| 775 | for(i=0;i<npt_element;i++) |
| 776 | { |
| 777 | ne=e->data; |
| 778 | |
| 779 | int j,k, nl_element,face_list_element; |
| 780 | struct face_list_entry *fle; |
| 781 | |
| 782 | struct hashtb_enumerator eef; |
| 783 | struct hashtb_enumerator *ef = &eef; |
| 784 | |
| 785 | hashtb_start(ne->face_list, ef); |
| 786 | face_list_element=hashtb_n(ne->face_list); |
| 787 | if ( face_list_element <= 0 ) |
| 788 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 789 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 790 | printf(" Face: No Face \n"); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 791 | if ( nlsr->detailed_logging ) |
| 792 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 793 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 794 | } |
| 795 | else |
| 796 | { |
| 797 | for(j=0;j<face_list_element;j++) |
| 798 | { |
| 799 | fle=ef->data; |
| 800 | int check=does_face_exist_for_router(ne->orig_router,fle->next_hop_face); |
| 801 | if ( check == 0 ) |
| 802 | { |
| 803 | struct name_list_entry *nle; |
| 804 | struct hashtb_enumerator eenle; |
| 805 | struct hashtb_enumerator *enle = &eenle; |
| 806 | |
| 807 | hashtb_start(ne->name_list, enle); |
| 808 | nl_element=hashtb_n(ne->name_list); |
| 809 | |
| 810 | for (k=0;k<nl_element;k++) |
| 811 | { |
| 812 | nle=enle->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 813 | if( is_neighbor(nle->name) == 0 ) |
| 814 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 815 | if ( nlsr->debugging ) |
| 816 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 817 | if ( nlsr->detailed_logging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 818 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 819 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face,nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 820 | } |
| 821 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 822 | |
| 823 | hashtb_next(enle); |
| 824 | } |
| 825 | hashtb_end(enle); |
| 826 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 827 | |
| 828 | hashtb_delete(ef); |
| 829 | j++; |
| 830 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 831 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 832 | else |
| 833 | { |
| 834 | struct name_list_entry *nle; |
| 835 | struct hashtb_enumerator eenle; |
| 836 | struct hashtb_enumerator *enle = &eenle; |
| 837 | |
| 838 | hashtb_start(ne->name_list, enle); |
| 839 | nl_element=hashtb_n(ne->name_list); |
| 840 | |
| 841 | for (k=0;k<nl_element;k++) |
| 842 | { |
| 843 | nle=enle->data; |
| 844 | if( is_active_neighbor(ne->orig_router) && get_next_hop_face_from_adl( ne->orig_router ) != fle->next_hop_face ) |
| 845 | { |
| 846 | if ( nlsr->debugging ) |
| 847 | printf("Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
| 848 | if ( nlsr->detailed_logging ) |
| 849 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,fle->next_hop_face); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 850 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, fle->next_hop_face,nlsr->router_dead_interval); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | |
| 854 | hashtb_next(enle); |
| 855 | } |
| 856 | hashtb_end(enle); |
| 857 | |
| 858 | hashtb_next(ef); |
| 859 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | hashtb_end(ef); |
| 863 | |
| 864 | |
| 865 | hashtb_next(e); |
| 866 | } |
| 867 | |
| 868 | hashtb_end(e); |
| 869 | |
| 870 | } |
| 871 | |
| 872 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 873 | update_npt_with_new_route(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 874 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 875 | if ( nlsr->debugging ) |
| 876 | printf("update_npt_with_new_route called\n"); |
| 877 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 878 | clean_old_fib_entries_from_npt(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 879 | print_npt(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 880 | add_new_fib_entries_to_npt(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 881 | print_npt(); |
| 882 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 883 | int i, npt_element; |
| 884 | |
| 885 | struct npt_entry *ne; |
| 886 | |
| 887 | struct hashtb_enumerator ee; |
| 888 | struct hashtb_enumerator *e = ⅇ |
| 889 | |
| 890 | hashtb_start(nlsr->npt, e); |
| 891 | npt_element=hashtb_n(nlsr->npt); |
| 892 | |
| 893 | for(i=0;i<npt_element;i++) |
| 894 | { |
| 895 | |
| 896 | ne=e->data; |
| 897 | update_ccnd_fib_for_orig_router(ne->orig_router); |
| 898 | hashtb_next(e); |
| 899 | } |
| 900 | |
| 901 | hashtb_end(e); |
| 902 | } |
| 903 | |
| 904 | |
| 905 | |
| 906 | void |
| 907 | sort_faces_by_distance(int *faces,int *route_costs,int start,int element) |
| 908 | { |
| 909 | int i,j; |
| 910 | int temp_cost; |
| 911 | int temp_face; |
| 912 | |
| 913 | for ( i=start ; i < element ; i ++) |
| 914 | { |
| 915 | for( j=i+1; j<element; j ++) |
| 916 | { |
| 917 | if (route_costs[j] < route_costs[i] ) |
| 918 | { |
| 919 | temp_cost=route_costs[j]; |
| 920 | route_costs[j]=route_costs[i]; |
| 921 | route_costs[i]=temp_cost; |
| 922 | |
| 923 | temp_face=faces[j]; |
| 924 | faces[j]=faces[i]; |
| 925 | faces[i]=temp_face; |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | } |
| 931 | |
| 932 | void |
| 933 | get_all_faces_for_orig_router_from_npt(char *orig_router, int *faces, int *route_costs, int num_faces) |
| 934 | { |
| 935 | |
| 936 | int res,face_list_element,j; |
| 937 | struct hashtb_enumerator ee; |
| 938 | struct hashtb_enumerator *e = ⅇ |
| 939 | |
| 940 | |
| 941 | hashtb_start(nlsr->npt, e); |
| 942 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 943 | |
| 944 | if(res == HT_NEW_ENTRY) |
| 945 | { |
| 946 | hashtb_delete(e); |
| 947 | } |
| 948 | else if ( res == HT_OLD_ENTRY ) |
| 949 | { |
| 950 | struct npt_entry *ne; |
| 951 | ne=e->data; |
| 952 | |
| 953 | struct face_list_entry *fle; |
| 954 | |
| 955 | struct hashtb_enumerator eef; |
| 956 | struct hashtb_enumerator *ef = &eef; |
| 957 | |
| 958 | hashtb_start(ne->face_list, ef); |
| 959 | face_list_element=hashtb_n(ne->face_list); |
| 960 | for(j=0;j<face_list_element;j++) |
| 961 | { |
| 962 | fle=ef->data; |
| 963 | faces[j]=fle->next_hop_face; |
| 964 | route_costs[j]=fle->route_cost; |
| 965 | hashtb_next(ef); |
| 966 | } |
| 967 | hashtb_end(ef); |
| 968 | |
| 969 | |
| 970 | } |
| 971 | hashtb_end(e); |
| 972 | |
| 973 | } |
| 974 | |
| 975 | void |
| 976 | destroy_faces_by_orig_router(char *orig_router) |
| 977 | { |
| 978 | |
| 979 | int res; |
| 980 | struct hashtb_enumerator ee; |
| 981 | struct hashtb_enumerator *e = ⅇ |
| 982 | |
| 983 | |
| 984 | hashtb_start(nlsr->npt, e); |
| 985 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 986 | |
| 987 | if(res == HT_NEW_ENTRY) |
| 988 | { |
| 989 | hashtb_delete(e); |
| 990 | } |
| 991 | else if ( res == HT_OLD_ENTRY ) |
| 992 | { |
| 993 | struct npt_entry *ne; |
| 994 | ne=e->data; |
| 995 | int num_face=hashtb_n(ne->face_list); |
| 996 | int last_face,first_face; |
| 997 | |
| 998 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 999 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 1000 | |
| 1001 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 1002 | sort_faces_by_distance(faces,route_costs,0,num_face); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1003 | last_face=0; |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1004 | if ( nlsr->max_faces_per_prefix == 0) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1005 | { |
| 1006 | first_face=num_face-1; |
| 1007 | } |
| 1008 | else if( nlsr->max_faces_per_prefix > 0) |
| 1009 | { |
| 1010 | if ( nlsr->max_faces_per_prefix >= num_face) |
| 1011 | { |
| 1012 | first_face=num_face-1; |
| 1013 | } |
| 1014 | else if ( nlsr->max_faces_per_prefix < num_face) |
| 1015 | { |
| 1016 | first_face=nlsr->max_faces_per_prefix-1; |
| 1017 | } |
| 1018 | |
| 1019 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1020 | |
| 1021 | int i,j, nl_element; |
| 1022 | struct name_list_entry *nle; |
| 1023 | struct hashtb_enumerator eenle; |
| 1024 | struct hashtb_enumerator *enle = &eenle; |
| 1025 | |
| 1026 | hashtb_start(ne->name_list, enle); |
| 1027 | nl_element=hashtb_n(ne->name_list); |
| 1028 | |
| 1029 | for (i=0;i<nl_element;i++) |
| 1030 | { |
| 1031 | nle=enle->data; |
| 1032 | |
| 1033 | for( j=first_face; j>= last_face; j--) |
| 1034 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1035 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1036 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1037 | if ( nlsr->debugging ) |
| 1038 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1039 | if ( nlsr->detailed_logging ) |
| 1040 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 1041 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1042 | } |
| 1043 | else |
| 1044 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1045 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1046 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1047 | if ( nlsr->debugging ) |
| 1048 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 1049 | if ( nlsr->detailed_logging ) |
| 1050 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 1051 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nle->name, OP_UNREG, faces[j],nlsr->router_dead_interval); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | hashtb_next(enle); |
| 1057 | } |
| 1058 | hashtb_end(enle); |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | free(faces); |
| 1063 | free(route_costs); |
| 1064 | |
| 1065 | } |
| 1066 | hashtb_end(e); |
| 1067 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1068 | } |
| 1069 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1070 | void |
| 1071 | destroy_all_face_by_nlsr(void) |
| 1072 | { |
| 1073 | int i, npt_element; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1074 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1075 | struct npt_entry *ne; |
| 1076 | |
| 1077 | struct hashtb_enumerator ee; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1078 | struct hashtb_enumerator *e = ⅇ |
| 1079 | |
| 1080 | hashtb_start(nlsr->npt, e); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1081 | npt_element=hashtb_n(nlsr->npt); |
| 1082 | |
| 1083 | for(i=0;i<npt_element;i++) |
| 1084 | { |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1085 | ne=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1086 | destroy_faces_by_orig_router(ne->orig_router); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1087 | hashtb_next(e); |
| 1088 | } |
| 1089 | |
| 1090 | hashtb_end(e); |
| 1091 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1092 | if ( nlsr->debugging ) |
| 1093 | printf("\n"); |
| 1094 | if ( nlsr->detailed_logging ) |
| 1095 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1096 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1097 | |
| 1098 | void |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1099 | destroy_name_list(struct hashtb *name_list) |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1100 | { |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1101 | int j,nl_element; |
| 1102 | struct name_list_entry *nle; |
| 1103 | struct hashtb_enumerator eenle; |
| 1104 | struct hashtb_enumerator *enle = &eenle; |
| 1105 | |
| 1106 | hashtb_start(name_list, enle); |
| 1107 | nl_element=hashtb_n(name_list); |
| 1108 | |
| 1109 | for (j=0;j<nl_element;j++) |
| 1110 | { |
| 1111 | nle=enle->data; |
| 1112 | free(nle->name); |
| 1113 | hashtb_next(enle); |
| 1114 | } |
| 1115 | hashtb_end(enle); |
| 1116 | |
| 1117 | hashtb_destroy(&name_list); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | void |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1121 | destroy_face_list(struct hashtb *face_list) |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1122 | { |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1123 | hashtb_destroy(&face_list); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void |
| 1127 | destroy_npt(void) |
| 1128 | { |
| 1129 | |
| 1130 | |
| 1131 | int i, npt_element; |
| 1132 | struct npt_entry *ne; |
| 1133 | |
| 1134 | struct hashtb_enumerator ee; |
| 1135 | struct hashtb_enumerator *e = ⅇ |
| 1136 | |
| 1137 | hashtb_start(nlsr->npt, e); |
| 1138 | npt_element=hashtb_n(nlsr->npt); |
| 1139 | |
| 1140 | for(i=0;i<npt_element;i++) |
| 1141 | { |
| 1142 | ne=e->data; |
akmhoque | 557b8c5 | 2013-03-15 08:18:52 -0500 | [diff] [blame] | 1143 | free(ne->orig_router); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1144 | destroy_name_list(ne->name_list); |
| 1145 | destroy_face_list(ne->face_list); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1146 | hashtb_next(e); |
| 1147 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1148 | hashtb_end(e); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1149 | |
| 1150 | hashtb_destroy(&nlsr->npt); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1151 | } |
| 1152 | |