akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | #include <sys/types.h> |
| 12 | #include <signal.h> |
| 13 | |
| 14 | |
| 15 | |
| 16 | #include <ccn/ccn.h> |
| 17 | #include <ccn/uri.h> |
| 18 | #include <ccn/keystore.h> |
| 19 | #include <ccn/signing.h> |
| 20 | #include <ccn/schedule.h> |
| 21 | #include <ccn/hashtb.h> |
| 22 | |
| 23 | #include "nlsr.h" |
| 24 | #include "nlsr_npt.h" |
| 25 | #include "nlsr_fib.h" |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 26 | #include "nlsr_route.h" |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 27 | #include "nlsr_adl.h" |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 28 | #include "utility.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 29 | |
| 30 | int |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 31 | add_npt_entry(char *orig_router, char *name_prefix, int num_face, int *faces, int *route_costs) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 32 | { |
| 33 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 34 | { |
| 35 | return -1; |
| 36 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 37 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 38 | struct npt_entry *ne;//=(struct npt_entry*)calloc(1,sizeof(struct npt_entry )); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 39 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 40 | int res,res_nle,res_fle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 41 | struct hashtb_enumerator ee; |
| 42 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 43 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 44 | |
| 45 | hashtb_start(nlsr->npt, e); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 46 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 47 | |
| 48 | if(res == HT_NEW_ENTRY) |
| 49 | { |
| 50 | ne=e->data; |
| 51 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 52 | ne->orig_router=(char *)malloc(strlen(orig_router)+1); |
| 53 | memset(ne->orig_router,0,strlen(orig_router)+1); |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 54 | memcpy(ne->orig_router,orig_router,strlen(orig_router)+1); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 55 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 56 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 57 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 58 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 59 | //struct hashtb_param param_nle = {0}; |
| 60 | ne->name_list= hashtb_create(sizeof(struct name_list_entry ),NULL); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 61 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 62 | struct hashtb_enumerator eenle; |
| 63 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 64 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 65 | hashtb_start(ne->name_list, enle); |
| 66 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 67 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 68 | if(res_nle == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 69 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 70 | struct name_list_entry *nle;//=(struct name_list_entry *)calloc(1,sizeof(struct name_list_entry)); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 71 | nle=enle->data; |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 72 | nle->name=(char *)calloc(strlen(name_prefix)+1,sizeof(char)); |
| 73 | //memset(nle->name,0,strlen(name_prefix)+1); |
| 74 | memcpy(nle->name,name_prefix,strlen(name_prefix)+1); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 75 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 76 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 77 | |
| 78 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 79 | hashtb_end(enle); |
| 80 | |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 81 | //struct hashtb_param param_fle = {0}; |
| 82 | ne->face_list=hashtb_create(sizeof(struct face_list_entry), NULL); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 83 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 84 | if ( num_face > 0 ) |
| 85 | { |
| 86 | struct hashtb_enumerator eef; |
| 87 | struct hashtb_enumerator *ef = &eef; |
| 88 | |
| 89 | hashtb_start(ne->face_list, ef); |
| 90 | int i; |
| 91 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 92 | for ( i=0; i < num_face ; i++) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 93 | { |
| 94 | int face=faces[i]; |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 95 | if ( face != NO_FACE && face != ZERO_FACE) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 96 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 97 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 98 | |
| 99 | if ( res_fle == HT_NEW_ENTRY ) |
| 100 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 101 | struct face_list_entry *fle;//=(struct face_list_entry *)calloc(1,sizeof(struct face_list_entry)); |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 102 | fle=ef->data; |
| 103 | fle->next_hop_face=face; |
| 104 | fle->route_cost=route_costs[i]; |
| 105 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } |
| 109 | hashtb_end(ef); |
| 110 | } |
| 111 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 112 | } |
| 113 | else if (res == HT_OLD_ENTRY) |
| 114 | { |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 115 | struct npt_entry *one; |
| 116 | |
| 117 | one=e->data; |
| 118 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 119 | struct hashtb_enumerator eenle; |
| 120 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 121 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 122 | hashtb_start(one->name_list, enle); |
| 123 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 124 | |
| 125 | if(res_nle == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 126 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 127 | 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] | 128 | nle=enle->data; |
| 129 | nle->name=(char *)malloc(strlen(name_prefix)+1); |
| 130 | memset(nle->name,0,strlen(name_prefix)+1); |
| 131 | memcpy(nle->name,name_prefix,strlen(name_prefix)); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 132 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 133 | else if(res_nle == HT_OLD_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 134 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 135 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 136 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 137 | hashtb_end(enle); |
| 138 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 139 | if ( num_face > 0 ) |
| 140 | { |
| 141 | struct hashtb_enumerator eef; |
| 142 | struct hashtb_enumerator *ef = &eef; |
| 143 | |
| 144 | hashtb_start(one->face_list, ef); |
| 145 | int i; |
| 146 | |
| 147 | for ( i=0; i< num_face ; i ++) |
| 148 | { |
| 149 | int face=faces[i]; |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 150 | if ( face != NO_FACE && face != ZERO_FACE) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 151 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 152 | res_fle = hashtb_seek(ef, &face, sizeof(face), 0); |
| 153 | |
| 154 | if ( res_fle == HT_NEW_ENTRY ) |
| 155 | { |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 156 | 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] | 157 | fle=ef->data; |
| 158 | fle->next_hop_face=face; |
| 159 | fle->route_cost=route_costs[i]; |
| 160 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 161 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 162 | } |
| 163 | hashtb_end(ef); |
| 164 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 165 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 166 | |
| 167 | } |
| 168 | hashtb_end(e); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 169 | |
| 170 | update_ccnd_fib_for_orig_router(orig_router); |
| 171 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 172 | return res; |
| 173 | } |
| 174 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 175 | void |
| 176 | update_ccnd_fib_for_orig_router(char *orig_router) |
| 177 | { |
| 178 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 179 | if ( nlsr->debugging ) |
| 180 | { |
| 181 | printf("update_ccnd_fib_for_orig_router called\n"); |
| 182 | } |
| 183 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 184 | int res; |
| 185 | struct hashtb_enumerator ee; |
| 186 | struct hashtb_enumerator *e = ⅇ |
| 187 | |
| 188 | |
| 189 | hashtb_start(nlsr->npt, e); |
| 190 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 191 | |
| 192 | if(res == HT_NEW_ENTRY) |
| 193 | { |
| 194 | hashtb_delete(e); |
| 195 | } |
| 196 | else if ( res == HT_OLD_ENTRY ) |
| 197 | { |
| 198 | struct npt_entry *ne; |
| 199 | ne=e->data; |
| 200 | int num_face=hashtb_n(ne->face_list); |
| 201 | int last_face,first_face; |
| 202 | |
| 203 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 204 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 205 | |
| 206 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 207 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 208 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 209 | if ( nlsr->debugging ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 210 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 211 | int m; |
| 212 | for ( m =0 ; m< num_face ; m++) |
| 213 | { |
| 214 | printf("Dest_router: %s Next_Hop_Face: %d Route_cost: %d \n",orig_router,faces[m],route_costs[m]); |
| 215 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 216 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 217 | |
| 218 | last_face=0; |
| 219 | 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] | 220 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 221 | first_face=num_face-1; |
| 222 | } |
| 223 | else if( nlsr->max_faces_per_prefix > 0) |
| 224 | { |
| 225 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 226 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 227 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 228 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 229 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 230 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 231 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 232 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 233 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | int i,j, nl_element; |
| 237 | struct name_list_entry *nle; |
| 238 | struct hashtb_enumerator eenle; |
| 239 | struct hashtb_enumerator *enle = &eenle; |
| 240 | |
| 241 | hashtb_start(ne->name_list, enle); |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 242 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 243 | |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 244 | for (i=0;i<nl_element;i++) |
| 245 | { |
| 246 | nle=enle->data; |
| 247 | |
| 248 | for( j=num_face-1; j>= 0; j--) |
| 249 | { |
| 250 | |
| 251 | if ( !( is_neighbor(nle->name) == 1 && get_next_hop_face_from_adl(nle->name) == faces[j] ) ) |
| 252 | { |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame^] | 253 | 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] | 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | hashtb_next(enle); |
| 259 | } |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 260 | hashtb_end(enle); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 261 | |
akmhoque | 726197c | 2013-02-18 11:49:24 -0600 | [diff] [blame] | 262 | |
| 263 | if ( nlsr->debugging ) |
| 264 | { |
| 265 | printf("First Face Index: %d Last Face Index: %d\n",first_face,last_face); |
| 266 | } |
| 267 | |
| 268 | hashtb_start(ne->name_list, enle); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 269 | nl_element=hashtb_n(ne->name_list); |
| 270 | |
| 271 | for (i=0;i<nl_element;i++) |
| 272 | { |
| 273 | nle=enle->data; |
| 274 | |
| 275 | for( j=first_face; j>= last_face; j--) |
| 276 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 277 | if ( nlsr->debugging ) |
| 278 | { |
| 279 | printf("Possible FIB Entry name: %s face: %d route cost: %d \n",nle->name,faces[j],route_costs[j]); |
| 280 | } |
| 281 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 282 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 283 | if ( nlsr->debugging ) |
| 284 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 285 | if ( nlsr->detailed_logging ) |
| 286 | 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^] | 287 | 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] | 288 | } |
| 289 | else |
| 290 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 291 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 292 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 293 | if ( nlsr->debugging ) |
| 294 | printf("Adding face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 295 | if ( nlsr->detailed_logging ) |
| 296 | 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^] | 297 | 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] | 298 | } |
| 299 | } |
| 300 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 301 | |
| 302 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 303 | hashtb_next(enle); |
| 304 | } |
| 305 | hashtb_end(enle); |
| 306 | |
| 307 | |
| 308 | |
| 309 | free(faces); |
| 310 | free(route_costs); |
| 311 | |
| 312 | } |
| 313 | hashtb_end(e); |
| 314 | |
| 315 | } |
| 316 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 317 | int |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 318 | 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] | 319 | { |
| 320 | if ( strcmp(orig_router,nlsr->router_name)== 0) |
| 321 | { |
| 322 | return -1; |
| 323 | } |
| 324 | |
| 325 | struct npt_entry *ne; |
| 326 | |
| 327 | int res,res_nle; |
| 328 | struct hashtb_enumerator ee; |
| 329 | struct hashtb_enumerator *e = ⅇ |
| 330 | |
| 331 | |
| 332 | hashtb_start(nlsr->npt, e); |
| 333 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 334 | |
| 335 | if(res == HT_NEW_ENTRY) |
| 336 | { |
| 337 | hashtb_delete(e); |
| 338 | return -1; |
| 339 | } |
| 340 | else if (res == HT_OLD_ENTRY) |
| 341 | { |
| 342 | ne=e->data; |
| 343 | |
| 344 | struct hashtb_enumerator eenle; |
| 345 | struct hashtb_enumerator *enle = &eenle; |
| 346 | |
| 347 | hashtb_start(ne->name_list, enle); |
| 348 | res_nle = hashtb_seek(enle, name_prefix, strlen(name_prefix), 0); |
| 349 | |
| 350 | if(res_nle == HT_NEW_ENTRY ) |
| 351 | { |
| 352 | hashtb_delete(enle); |
| 353 | } |
| 354 | else if(res_nle == HT_OLD_ENTRY ) |
| 355 | { |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 356 | struct name_list_entry *nle; |
| 357 | |
| 358 | nle=enle->data; |
| 359 | |
| 360 | int j; |
| 361 | int num_face=hashtb_n(ne->face_list); |
| 362 | int last_face,first_face; |
| 363 | |
| 364 | int *faces=(int *)malloc(num_face*sizeof(int)); |
| 365 | int *route_costs=(int *)malloc(num_face*sizeof(int)); |
| 366 | |
| 367 | get_all_faces_for_orig_router_from_npt(orig_router,faces,route_costs,num_face); |
| 368 | sort_faces_by_distance(faces,route_costs,0,num_face); |
| 369 | |
| 370 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 371 | last_face=0; |
| 372 | 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] | 373 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 374 | first_face=num_face-1; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 375 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 376 | else if( nlsr->max_faces_per_prefix > 0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 377 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 378 | if ( nlsr->max_faces_per_prefix >= num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 379 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 380 | first_face=num_face-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 381 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 382 | else if ( nlsr->max_faces_per_prefix < num_face) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 383 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 384 | first_face=nlsr->max_faces_per_prefix-1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 385 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 386 | |
| 387 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 388 | for( j=first_face; j>= last_face; j--) |
| 389 | { |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 390 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 391 | if ( is_active_neighbor(orig_router) == 0 ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 392 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 393 | if ( nlsr->debugging ) |
| 394 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 395 | if ( nlsr->detailed_logging ) |
| 396 | 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^] | 397 | 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] | 398 | } |
| 399 | else |
| 400 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 401 | if ( j == last_face && is_active_neighbor(nle->name)==0) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 402 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 403 | if ( nlsr->debugging ) |
| 404 | printf("Deleting face: Name:%s Face: %d\n",nle->name,faces[j]); |
| 405 | if ( nlsr->detailed_logging ) |
| 406 | 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^] | 407 | 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] | 408 | } |
| 409 | } |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 410 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 411 | } |
| 412 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | hashtb_end(enle); |
| 416 | } |
| 417 | |
| 418 | hashtb_end(e); |
| 419 | |
| 420 | return 0; |
| 421 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 422 | |
| 423 | void |
| 424 | print_npt(void) |
| 425 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 426 | |
| 427 | if ( nlsr->debugging ) |
| 428 | { |
| 429 | printf("\n"); |
| 430 | printf("print_npt called\n"); |
| 431 | } |
| 432 | if ( nlsr->detailed_logging ) |
| 433 | { |
| 434 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 435 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_npt called\n"); |
| 436 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 437 | int i, npt_element; |
| 438 | |
| 439 | struct npt_entry *ne; |
| 440 | |
| 441 | struct hashtb_enumerator ee; |
| 442 | struct hashtb_enumerator *e = ⅇ |
| 443 | |
| 444 | hashtb_start(nlsr->npt, e); |
| 445 | npt_element=hashtb_n(nlsr->npt); |
| 446 | |
| 447 | for(i=0;i<npt_element;i++) |
| 448 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 449 | if ( nlsr->debugging ) |
| 450 | { |
| 451 | printf("\n"); |
| 452 | printf("----------NPT ENTRY %d------------------\n",i+1); |
| 453 | } |
| 454 | if ( nlsr->detailed_logging ) |
| 455 | { |
| 456 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 457 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------NPT ENTRY %d------------------\n",i+1); |
| 458 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 459 | ne=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 460 | if ( nlsr->debugging ) |
| 461 | printf(" Origination Router: %s \n",ne->orig_router); |
| 462 | if ( nlsr->detailed_logging ) |
| 463 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s \n",ne->orig_router); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 464 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 465 | int j, nl_element,face_list_element; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 466 | struct name_list_entry *nle; |
| 467 | struct hashtb_enumerator eenle; |
| 468 | struct hashtb_enumerator *enle = &eenle; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 469 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 470 | hashtb_start(ne->name_list, enle); |
| 471 | nl_element=hashtb_n(ne->name_list); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 472 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 473 | for (j=0;j<nl_element;j++) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 474 | { |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 475 | nle=enle->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 476 | if ( nlsr->debugging ) |
| 477 | printf(" Name Prefix: %s \n",nle->name); |
| 478 | if ( nlsr->detailed_logging ) |
| 479 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s \n",nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 480 | hashtb_next(enle); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 481 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 482 | hashtb_end(enle); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 483 | |
| 484 | struct face_list_entry *fle; |
| 485 | |
| 486 | struct hashtb_enumerator eef; |
| 487 | struct hashtb_enumerator *ef = &eef; |
| 488 | |
| 489 | hashtb_start(ne->face_list, ef); |
| 490 | face_list_element=hashtb_n(ne->face_list); |
| 491 | if ( face_list_element <= 0 ) |
| 492 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 493 | if ( nlsr->debugging ) |
| 494 | printf(" Face: No Face \n"); |
| 495 | if ( nlsr->detailed_logging ) |
| 496 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
| 497 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
| 501 | for(j=0;j<face_list_element;j++) |
| 502 | { |
| 503 | fle=ef->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 504 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 505 | 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] | 506 | if ( nlsr->detailed_logging ) |
| 507 | 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] | 508 | hashtb_next(ef); |
| 509 | } |
| 510 | } |
| 511 | hashtb_end(ef); |
| 512 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 513 | |
| 514 | hashtb_next(e); |
| 515 | } |
| 516 | |
| 517 | hashtb_end(e); |
| 518 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 519 | if ( nlsr->debugging ) |
| 520 | printf("\n"); |
| 521 | if ( nlsr->detailed_logging ) |
| 522 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 523 | } |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 524 | |
| 525 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 526 | delete_orig_router_from_npt(char *orig_router) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 527 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 528 | int res,num_face,num_prefix; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 529 | struct npt_entry *ne; |
| 530 | |
| 531 | struct hashtb_enumerator ee; |
| 532 | struct hashtb_enumerator *e = ⅇ |
| 533 | |
| 534 | hashtb_start(nlsr->npt, e); |
| 535 | res = hashtb_seek(e, orig_router, strlen(orig_router), 0); |
| 536 | |
| 537 | if ( res == HT_OLD_ENTRY ) |
| 538 | { |
| 539 | ne=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 540 | num_prefix=hashtb_n(ne->name_list); |
| 541 | if ( num_prefix > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 542 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 543 | num_face=hashtb_n(ne->face_list); |
| 544 | |
| 545 | if ( num_face > 0 ) |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 546 | { |
| 547 | int j, nl_element; |
| 548 | struct name_list_entry *nle; |
| 549 | struct hashtb_enumerator eenle; |
| 550 | struct hashtb_enumerator *enle = &eenle; |
| 551 | |
| 552 | hashtb_start(ne->name_list, enle); |
| 553 | nl_element=hashtb_n(ne->name_list); |
| 554 | |
| 555 | for (j=0;j<nl_element;j++) |
| 556 | { |
| 557 | nle=enle->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 558 | delete_npt_entry_by_router_and_name_prefix(ne->orig_router,nle->name); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 559 | hashtb_next(enle); |
| 560 | } |
| 561 | hashtb_end(enle); |
| 562 | |
| 563 | } |
| 564 | |
| 565 | } |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 566 | //hashtb_destroy(&ne->name_list); |
| 567 | //hashtb_destroy(&ne->face_list); |
| 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 | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1143 | destroy_name_list(ne->name_list); |
| 1144 | destroy_face_list(ne->face_list); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1145 | hashtb_next(e); |
| 1146 | } |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1147 | hashtb_end(e); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1148 | |
| 1149 | hashtb_destroy(&nlsr->npt); |
akmhoque | 0ed6d98 | 2013-02-22 14:28:01 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |