akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <math.h> |
| 4 | #include <stdlib.h> |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 5 | #include <unistd.h> |
| 6 | #include <getopt.h> |
| 7 | #include <sys/time.h> |
| 8 | #include <assert.h> |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include <config.h> |
| 11 | #endif |
| 12 | #include <sys/types.h> |
| 13 | |
| 14 | |
| 15 | #include <ccn/ccn.h> |
| 16 | #include <ccn/uri.h> |
| 17 | #include <ccn/keystore.h> |
| 18 | #include <ccn/signing.h> |
| 19 | #include <ccn/schedule.h> |
| 20 | #include <ccn/hashtb.h> |
| 21 | |
| 22 | |
| 23 | #include "nlsr.h" |
| 24 | #include "nlsr_route.h" |
| 25 | #include "nlsr_lsdb.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 26 | #include "nlsr_npt.h" |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 27 | #include "nlsr_adl.h" |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 28 | #include "nlsr_fib.h" |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 29 | #include "utility.h" |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 30 | |
| 31 | int |
| 32 | route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 33 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 34 | |
| 35 | if(flags == CCN_SCHEDULE_CANCEL) |
| 36 | { |
| 37 | return -1; |
| 38 | } |
| 39 | |
| 40 | nlsr_lock(); |
| 41 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 42 | if ( nlsr->debugging ) |
| 43 | printf("route_calculate called\n"); |
| 44 | if ( nlsr->detailed_logging ) |
| 45 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"route_calculate called\n"); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 46 | |
| 47 | if( ! nlsr->is_build_adj_lsa_sheduled ) |
| 48 | { |
| 49 | /* Calculate Route here */ |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 50 | print_routing_table(); |
| 51 | print_npt(); |
| 52 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 53 | struct hashtb_param param_me = {0}; |
| 54 | nlsr->map = hashtb_create(sizeof(struct map_entry), ¶m_me); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 55 | nlsr->rev_map = hashtb_create(sizeof(struct map_entry), ¶m_me); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 56 | make_map(); |
| 57 | assign_mapping_number(); |
| 58 | print_map(); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 59 | print_rev_map(); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 60 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 61 | do_old_routing_table_updates(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 62 | clear_old_routing_table(); |
| 63 | print_routing_table(); |
akmhoque | a30cb77 | 2012-10-07 09:50:34 -0500 | [diff] [blame] | 64 | print_npt(); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 65 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 66 | int i; |
| 67 | int **adj_matrix; |
| 68 | int map_element=hashtb_n(nlsr->map); |
| 69 | adj_matrix=malloc(map_element * sizeof(int *)); |
| 70 | for(i = 0; i < map_element; i++) |
| 71 | { |
| 72 | adj_matrix[i] = malloc(map_element * sizeof(int)); |
| 73 | } |
| 74 | make_adj_matrix(adj_matrix,map_element); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 75 | if ( nlsr->debugging ) |
| 76 | print_adj_matrix(adj_matrix,map_element); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 77 | |
| 78 | long int source=get_mapping_no(nlsr->router_name); |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 79 | int num_link=get_no_link_from_adj_matrix(adj_matrix, map_element ,source); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 80 | |
| 81 | if ( nlsr->is_hyperbolic_calc == 1) |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 82 | { |
| 83 | long int *links=(long int *)malloc(num_link*sizeof(long int)); |
| 84 | long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); |
| 85 | get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 86 | |
| 87 | struct hashtb_enumerator ee; |
| 88 | struct hashtb_enumerator *e = ⅇ |
| 89 | for (hashtb_start(nlsr->rev_map, e); e->key != NULL; hashtb_next(e)) |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 90 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 91 | struct map_entry *me=e->data; |
| 92 | if ( me->mapping != source ) |
| 93 | { |
| 94 | long int *faces=(long int *)calloc(num_link,sizeof(long int)); |
| 95 | double *nbr_dist=(double *)calloc(num_link,sizeof(double)); |
| 96 | double *nbr_to_dest=(double *)calloc(num_link,sizeof(double)); |
| 97 | for ( i=0 ; i < num_link; i++) |
| 98 | { |
| 99 | int face=get_next_hop_face_from_adl(get_router_from_rev_map(links[i])); |
| 100 | double dist_to_nbr=get_hyperbolic_distance(source,links[i]); |
| 101 | double dist_to_dest_from_nbr=get_hyperbolic_distance(links[i],me->mapping); |
| 102 | faces[i]=face; |
| 103 | nbr_dist[i]=dist_to_nbr; |
| 104 | nbr_to_dest[i]= dist_to_dest_from_nbr; |
| 105 | |
| 106 | |
| 107 | } |
| 108 | sort_hyperbolic_route(nbr_to_dest,nbr_dist, faces,0,num_link); |
| 109 | if (nlsr->max_faces_per_prefix == 0 ) |
| 110 | { |
| 111 | for ( i=0 ; i < num_link; i++) |
| 112 | { |
| 113 | update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); |
| 114 | } |
| 115 | } |
| 116 | else if ( nlsr->max_faces_per_prefix > 0 ) |
| 117 | { |
| 118 | if ( num_link <= nlsr->max_faces_per_prefix ) |
| 119 | { |
| 120 | for ( i=0 ; i < num_link; i++) |
| 121 | { |
| 122 | update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); |
| 123 | } |
| 124 | } |
| 125 | else if (num_link > nlsr->max_faces_per_prefix) |
| 126 | { |
| 127 | for ( i=0 ; i < nlsr->max_faces_per_prefix; i++) |
| 128 | { |
| 129 | update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | free(faces); |
| 135 | free(nbr_dist); |
| 136 | free(nbr_to_dest); |
| 137 | } |
| 138 | } |
| 139 | hashtb_end(e); |
| 140 | |
| 141 | |
| 142 | free(links); |
| 143 | free(link_costs); |
| 144 | } |
| 145 | else if (nlsr->is_hyperbolic_calc == 0 ) |
| 146 | { |
| 147 | |
| 148 | long int *parent=(long int *)malloc(map_element * sizeof(long int)); |
| 149 | long int *dist=(long int *)malloc(map_element * sizeof(long int)); |
| 150 | |
| 151 | |
| 152 | if ( (num_link == 0) || (nlsr->max_faces_per_prefix == 1 ) ) |
| 153 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 154 | calculate_path(adj_matrix,parent,dist, map_element, source); |
| 155 | print_all_path_from_source(parent,source); |
| 156 | print_all_next_hop(parent,source); |
| 157 | update_routing_table_with_new_route(parent, dist,source); |
| 158 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 159 | else if ( (num_link != 0) && (nlsr->max_faces_per_prefix == 0 || nlsr->max_faces_per_prefix > 1 ) ) |
| 160 | { |
| 161 | long int *links=(long int *)malloc(num_link*sizeof(long int)); |
| 162 | long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); |
| 163 | get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); |
| 164 | for ( i=0 ; i < num_link; i++) |
| 165 | { |
| 166 | adjust_adj_matrix(adj_matrix, map_element,source,links[i],link_costs[i]); |
| 167 | calculate_path(adj_matrix,parent,dist, map_element, source); |
| 168 | print_all_path_from_source(parent,source); |
| 169 | print_all_next_hop(parent,source); |
| 170 | update_routing_table_with_new_route(parent, dist,source); |
| 171 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 172 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 173 | free(links); |
| 174 | free(link_costs); |
| 175 | } |
| 176 | free(parent); |
| 177 | free(dist); |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 178 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 179 | |
| 180 | print_routing_table(); |
| 181 | print_npt(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 182 | |
| 183 | update_npt_with_new_route(); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 184 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 185 | print_routing_table(); |
| 186 | print_npt(); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 187 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 188 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 189 | for(i = 0; i < map_element; i++) |
| 190 | { |
| 191 | free(adj_matrix[i]); |
| 192 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 193 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 194 | free(adj_matrix); |
| 195 | hashtb_destroy(&nlsr->map); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 196 | hashtb_destroy(&nlsr->rev_map); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 197 | |
| 198 | } |
| 199 | nlsr->is_route_calculation_scheduled=0; |
| 200 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 201 | nlsr_unlock(); |
| 202 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 207 | calculate_path(int **adj_matrix, long int *parent,long int *dist ,long int V, long int S) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 208 | { |
| 209 | int i; |
| 210 | long int v,u; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 211 | //long int *dist=(long int *)malloc(V * sizeof(long int)); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 212 | long int *Q=(long int *)malloc(V * sizeof(long int)); |
| 213 | long int head=0; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 214 | /* Initiate the Parent */ |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 215 | for (i = 0 ; i < V; i++) |
| 216 | { |
| 217 | parent[i]=EMPTY_PARENT; |
| 218 | dist[i]=INF_DISTANCE; |
| 219 | Q[i]=i; |
| 220 | } |
| 221 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 222 | if ( S != NO_MAPPING_NUM ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 223 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 224 | dist[S]=0; |
| 225 | sort_queue_by_distance(Q,dist,head,V); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 226 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 227 | while (head < V ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 228 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 229 | u=Q[head]; |
| 230 | if(dist[u] == INF_DISTANCE) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 231 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | |
| 235 | for(v=0 ; v <V; v++) |
| 236 | { |
| 237 | if( adj_matrix[u][v] > 0 ) // |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 238 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 239 | if ( is_not_explored(Q,v,head+1,V) ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 240 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 241 | |
| 242 | if( dist[u] + adj_matrix[u][v] < dist[v]) |
| 243 | { |
| 244 | dist[v]=dist[u] + adj_matrix[u][v] ; |
| 245 | parent[v]=u; |
| 246 | } |
| 247 | |
| 248 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 249 | |
| 250 | } |
| 251 | |
| 252 | } |
| 253 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 254 | head++; |
| 255 | sort_queue_by_distance(Q,dist,head,V); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 256 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 257 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 258 | free(Q); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void |
| 262 | print_all_path_from_source(long int *parent,long int source) |
| 263 | { |
| 264 | int i, map_element; |
| 265 | struct map_entry *me; |
| 266 | |
| 267 | struct hashtb_enumerator ee; |
| 268 | struct hashtb_enumerator *e = ⅇ |
| 269 | |
| 270 | hashtb_start(nlsr->map, e); |
| 271 | map_element=hashtb_n(nlsr->map); |
| 272 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 273 | if ( source != NO_MAPPING_NUM) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 274 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 275 | for(i=0;i<map_element;i++) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 276 | { |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 277 | me=e->data; |
| 278 | if(me->mapping != source) |
| 279 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 280 | |
| 281 | if ( nlsr->debugging ) |
| 282 | { |
| 283 | print_path(parent,(long int)me->mapping); |
| 284 | printf("\n"); |
| 285 | } |
| 286 | if ( nlsr->detailed_logging ) |
| 287 | { |
| 288 | print_path(parent,(long int)me->mapping); |
| 289 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 290 | } |
| 291 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 292 | } |
| 293 | hashtb_next(e); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 294 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 295 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 296 | hashtb_end(e); |
| 297 | |
| 298 | } |
| 299 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 300 | void |
| 301 | print_all_next_hop(long int *parent,long int source) |
| 302 | { |
| 303 | int i, map_element; |
| 304 | struct map_entry *me; |
| 305 | |
| 306 | struct hashtb_enumerator ee; |
| 307 | struct hashtb_enumerator *e = ⅇ |
| 308 | |
| 309 | hashtb_start(nlsr->map, e); |
| 310 | map_element=hashtb_n(nlsr->map); |
| 311 | |
| 312 | for(i=0;i<map_element;i++) |
| 313 | { |
| 314 | me=e->data; |
| 315 | if(me->mapping != source) |
| 316 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 317 | if ( nlsr->debugging ) |
| 318 | printf("Dest: %d Next Hop: %ld\n",me->mapping,get_next_hop_from_calculation(parent,me->mapping,source)); |
| 319 | if ( nlsr->detailed_logging ) |
| 320 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest: %d Next Hop: %ld\n",me->mapping,get_next_hop_from_calculation(parent,me->mapping,source)); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 321 | } |
| 322 | hashtb_next(e); |
| 323 | } |
| 324 | |
| 325 | hashtb_end(e); |
| 326 | |
| 327 | } |
| 328 | |
| 329 | long int |
| 330 | get_next_hop_from_calculation(long int *parent, long int dest,long int source) |
| 331 | { |
| 332 | long int next_hop; |
| 333 | while ( parent[dest] != EMPTY_PARENT ) |
| 334 | { |
| 335 | next_hop=dest; |
| 336 | dest=parent[dest]; |
| 337 | |
| 338 | } |
| 339 | |
| 340 | if ( dest != source ) |
| 341 | { |
| 342 | next_hop=NO_NEXT_HOP; |
| 343 | } |
| 344 | |
| 345 | return next_hop; |
| 346 | |
| 347 | } |
| 348 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 349 | void |
| 350 | print_path(long int *parent, long int dest) |
| 351 | { |
| 352 | if (parent[dest] != EMPTY_PARENT ) |
| 353 | print_path(parent,parent[dest]); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 354 | |
| 355 | if ( nlsr->debugging ) |
| 356 | printf(" %ld",dest); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | int |
| 360 | is_not_explored(long int *Q, long int u,long int start, long int element) |
| 361 | { |
| 362 | int ret=0; |
| 363 | long int i; |
| 364 | for(i=start; i< element; i++) |
| 365 | { |
| 366 | if ( Q[i] == u ) |
| 367 | { |
| 368 | ret=1; |
| 369 | break; |
| 370 | } |
| 371 | } |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | void |
| 376 | sort_queue_by_distance(long int *Q,long int *dist,long int start,long int element) |
| 377 | { |
| 378 | long int i,j; |
| 379 | long int temp_u; |
| 380 | |
| 381 | for ( i=start ; i < element ; i ++) |
| 382 | { |
| 383 | for( j=i+1; j<element; j ++) |
| 384 | { |
| 385 | if (dist[Q[j]] < dist[Q[i]]) |
| 386 | { |
| 387 | temp_u=Q[j]; |
| 388 | Q[j]=Q[i]; |
| 389 | Q[i]=temp_u; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | } |
| 395 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 396 | void |
| 397 | sort_hyperbolic_route(double *dist_dest,double *dist_nbr, long int *faces,long int start,long int element) |
| 398 | { |
| 399 | long int i,j; |
| 400 | double temp_dist; |
| 401 | long int temp_face; |
| 402 | |
| 403 | for ( i=start ; i < element ; i ++) |
| 404 | { |
| 405 | for( j=i+1; j<element; j ++) |
| 406 | { |
| 407 | if (dist_dest[i] < dist_dest[j]) |
| 408 | { |
| 409 | temp_dist=dist_dest[j]; |
| 410 | dist_dest[j]=dist_dest[i]; |
| 411 | dist_dest[i]=temp_dist; |
| 412 | |
| 413 | temp_dist=dist_nbr[j]; |
| 414 | dist_nbr[j]=dist_nbr[i]; |
| 415 | dist_nbr[i]=temp_dist; |
| 416 | |
| 417 | temp_face=faces[j]; |
| 418 | faces[j]=faces[i]; |
| 419 | faces[i]=temp_face; |
| 420 | } |
| 421 | if ( (dist_dest[i] == dist_dest[j]) && (dist_nbr[i] < dist_nbr[j]) ) |
| 422 | { |
| 423 | temp_dist=dist_dest[j]; |
| 424 | dist_dest[j]=dist_dest[i]; |
| 425 | dist_dest[i]=temp_dist; |
| 426 | |
| 427 | temp_dist=dist_nbr[j]; |
| 428 | dist_nbr[j]=dist_nbr[i]; |
| 429 | dist_nbr[i]=temp_dist; |
| 430 | |
| 431 | temp_face=faces[j]; |
| 432 | faces[j]=faces[i]; |
| 433 | faces[i]=temp_face; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | } |
| 439 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 440 | void |
| 441 | print_map(void) |
| 442 | { |
| 443 | int i, map_element; |
| 444 | struct map_entry *me; |
| 445 | |
| 446 | struct hashtb_enumerator ee; |
| 447 | struct hashtb_enumerator *e = ⅇ |
| 448 | |
| 449 | hashtb_start(nlsr->map, e); |
| 450 | map_element=hashtb_n(nlsr->map); |
| 451 | |
| 452 | for(i=0;i<map_element;i++) |
| 453 | { |
| 454 | me=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 455 | if ( nlsr->debugging ) |
| 456 | printf("Router: %s Mapping Number: %d \n",me->router,me->mapping); |
| 457 | if ( nlsr->detailed_logging ) |
| 458 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router: %s Mapping Number: %d \n",me->router,me->mapping); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 459 | hashtb_next(e); |
| 460 | } |
| 461 | |
| 462 | hashtb_end(e); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void |
| 467 | assign_mapping_number(void) |
| 468 | { |
| 469 | int i, map_element; |
| 470 | struct map_entry *me; |
| 471 | |
| 472 | struct hashtb_enumerator ee; |
| 473 | struct hashtb_enumerator *e = ⅇ |
| 474 | |
| 475 | hashtb_start(nlsr->map, e); |
| 476 | map_element=hashtb_n(nlsr->map); |
| 477 | |
| 478 | for(i=0;i<map_element;i++) |
| 479 | { |
| 480 | me=e->data; |
| 481 | me->mapping=i; |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 482 | add_rev_map_entry(i,me->router); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 483 | hashtb_next(e); |
| 484 | } |
| 485 | |
| 486 | hashtb_end(e); |
| 487 | } |
| 488 | |
| 489 | void |
| 490 | make_map(void) |
| 491 | { |
| 492 | |
| 493 | |
| 494 | int i, adj_lsdb_element; |
| 495 | struct alsa *adj_lsa; |
| 496 | |
| 497 | struct hashtb_enumerator ee; |
| 498 | struct hashtb_enumerator *e = ⅇ |
| 499 | |
| 500 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 501 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 502 | |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 503 | add_map_entry(nlsr->router_name); |
| 504 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 505 | for(i=0;i<adj_lsdb_element;i++) |
| 506 | { |
| 507 | adj_lsa=e->data; |
| 508 | add_adj_data_to_map(adj_lsa->header->orig_router->name,adj_lsa->body,adj_lsa->no_link); |
| 509 | hashtb_next(e); |
| 510 | } |
| 511 | |
| 512 | hashtb_end(e); |
| 513 | |
| 514 | } |
| 515 | |
| 516 | void |
| 517 | add_map_entry(char *router) |
| 518 | { |
| 519 | |
| 520 | struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry )); |
| 521 | |
| 522 | struct hashtb_enumerator ee; |
| 523 | struct hashtb_enumerator *e = ⅇ |
| 524 | int res; |
| 525 | |
| 526 | hashtb_start(nlsr->map, e); |
| 527 | res = hashtb_seek(e, router, strlen(router), 0); |
| 528 | |
| 529 | if(res == HT_NEW_ENTRY) |
| 530 | { |
| 531 | me=e->data; |
| 532 | me->router=(char *)malloc(strlen(router)+1); |
| 533 | memset(me->router,0,strlen(router)+1); |
| 534 | memcpy(me->router,router,strlen(router)); |
| 535 | me->mapping=0; |
| 536 | } |
| 537 | |
| 538 | hashtb_end(e); |
| 539 | |
| 540 | } |
| 541 | |
| 542 | |
| 543 | void |
| 544 | add_adj_data_to_map(char *orig_router, char *body, int no_link) |
| 545 | { |
| 546 | add_map_entry(orig_router); |
| 547 | |
| 548 | int i=0; |
| 549 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 550 | memset( lsa_data,0,strlen(body)+1); |
| 551 | memcpy(lsa_data,body,strlen(body)+1); |
| 552 | char *sep="|"; |
| 553 | char *rem; |
| 554 | char *rtr_id; |
| 555 | char *length; |
| 556 | char *face; |
| 557 | char *metric; |
| 558 | |
| 559 | if(no_link >0 ) |
| 560 | { |
| 561 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 562 | length=strtok_r(NULL,sep,&rem); |
| 563 | face=strtok_r(NULL,sep,&rem); |
| 564 | metric=strtok_r(NULL,sep,&rem); |
| 565 | |
| 566 | add_map_entry(rtr_id); |
| 567 | |
| 568 | for(i=1;i<no_link;i++) |
| 569 | { |
| 570 | rtr_id=strtok_r(NULL,sep,&rem); |
| 571 | length=strtok_r(NULL,sep,&rem); |
| 572 | face=strtok_r(NULL,sep,&rem); |
| 573 | metric=strtok_r(NULL,sep,&rem); |
| 574 | |
| 575 | add_map_entry(rtr_id); |
| 576 | |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | free(lsa_data); |
| 581 | } |
| 582 | |
| 583 | int |
| 584 | get_mapping_no(char *router) |
| 585 | { |
| 586 | struct map_entry *me; |
| 587 | |
| 588 | struct hashtb_enumerator ee; |
| 589 | struct hashtb_enumerator *e = ⅇ |
akmhoque | 0315f98 | 2012-09-09 11:28:05 -0500 | [diff] [blame] | 590 | int res; |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 591 | int ret; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 592 | |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 593 | int n = hashtb_n(nlsr->map); |
| 594 | |
| 595 | if ( n < 1) |
| 596 | { |
| 597 | return NO_MAPPING_NUM; |
| 598 | } |
| 599 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 600 | hashtb_start(nlsr->map, e); |
| 601 | res = hashtb_seek(e, router, strlen(router), 0); |
| 602 | |
| 603 | if( res == HT_OLD_ENTRY ) |
| 604 | { |
| 605 | me=e->data; |
| 606 | ret=me->mapping; |
| 607 | } |
| 608 | else if(res == HT_NEW_ENTRY) |
| 609 | { |
| 610 | hashtb_delete(e); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 611 | ret=NO_MAPPING_NUM; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | hashtb_end(e); |
| 615 | |
| 616 | return ret; |
| 617 | |
| 618 | } |
| 619 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 620 | |
| 621 | void |
| 622 | add_rev_map_entry(long int mapping_number, char *router) |
| 623 | { |
| 624 | |
| 625 | struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry )); |
| 626 | |
| 627 | struct hashtb_enumerator ee; |
| 628 | struct hashtb_enumerator *e = ⅇ |
| 629 | int res; |
| 630 | |
| 631 | hashtb_start(nlsr->rev_map, e); |
| 632 | res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0); |
| 633 | |
| 634 | if(res == HT_NEW_ENTRY) |
| 635 | { |
| 636 | me=e->data; |
| 637 | me->router=(char *)malloc(strlen(router)+1); |
| 638 | memset(me->router,0,strlen(router)+1); |
| 639 | memcpy(me->router,router,strlen(router)); |
| 640 | me->mapping=mapping_number; |
| 641 | } |
| 642 | |
| 643 | hashtb_end(e); |
| 644 | |
| 645 | } |
| 646 | |
| 647 | |
| 648 | |
| 649 | char * |
| 650 | get_router_from_rev_map(long int mapping_number) |
| 651 | { |
| 652 | |
| 653 | struct map_entry *me; |
| 654 | |
| 655 | struct hashtb_enumerator ee; |
| 656 | struct hashtb_enumerator *e = ⅇ |
| 657 | int res; |
| 658 | |
| 659 | hashtb_start(nlsr->rev_map, e); |
| 660 | res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0); |
| 661 | |
| 662 | if(res == HT_OLD_ENTRY) |
| 663 | { |
| 664 | me=e->data; |
| 665 | hashtb_end(e); |
| 666 | return me->router; |
| 667 | } |
| 668 | else if(res == HT_NEW_ENTRY) |
| 669 | { |
| 670 | hashtb_delete(e); |
| 671 | hashtb_end(e); |
| 672 | } |
| 673 | |
| 674 | return NULL; |
| 675 | } |
| 676 | |
| 677 | void |
| 678 | print_rev_map(void) |
| 679 | { |
| 680 | int i, map_element; |
| 681 | struct map_entry *me; |
| 682 | |
| 683 | struct hashtb_enumerator ee; |
| 684 | struct hashtb_enumerator *e = ⅇ |
| 685 | |
| 686 | hashtb_start(nlsr->map, e); |
| 687 | map_element=hashtb_n(nlsr->map); |
| 688 | |
| 689 | for(i=0;i<map_element;i++) |
| 690 | { |
| 691 | me=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 692 | if ( nlsr->debugging ) |
| 693 | printf("Mapping Number: %d Router: %s \n",me->mapping,me->router); |
| 694 | if ( nlsr->detailed_logging ) |
| 695 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Mapping Number: %d Router: %s \n",me->mapping,me->router); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 696 | hashtb_next(e); |
| 697 | } |
| 698 | |
| 699 | hashtb_end(e); |
| 700 | } |
| 701 | |
| 702 | |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 703 | void |
| 704 | assign_adj_matrix_for_lsa(struct alsa *adj_lsa, int **adj_matrix) |
| 705 | { |
| 706 | int mapping_orig_router=get_mapping_no(adj_lsa->header->orig_router->name); |
| 707 | int mapping_nbr_router; |
| 708 | |
| 709 | int i; |
| 710 | char *lsa_data=(char *)malloc(strlen(adj_lsa->body)+1); |
| 711 | memset( lsa_data,0,strlen(adj_lsa->body)+1); |
| 712 | memcpy(lsa_data,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 713 | char *sep="|"; |
| 714 | char *rem; |
| 715 | char *rtr_id; |
| 716 | char *length; |
| 717 | char *face; |
| 718 | char *metric; |
| 719 | |
| 720 | if(adj_lsa->no_link >0 ) |
| 721 | { |
| 722 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 723 | length=strtok_r(NULL,sep,&rem); |
| 724 | face=strtok_r(NULL,sep,&rem); |
| 725 | metric=strtok_r(NULL,sep,&rem); |
| 726 | |
| 727 | mapping_nbr_router=get_mapping_no(rtr_id); |
| 728 | adj_matrix[mapping_orig_router][mapping_nbr_router]=atoi(metric); |
| 729 | |
| 730 | for(i=1;i<adj_lsa->no_link;i++) |
| 731 | { |
| 732 | rtr_id=strtok_r(NULL,sep,&rem); |
| 733 | length=strtok_r(NULL,sep,&rem); |
| 734 | face=strtok_r(NULL,sep,&rem); |
| 735 | metric=strtok_r(NULL,sep,&rem); |
| 736 | |
| 737 | mapping_nbr_router=get_mapping_no(rtr_id); |
| 738 | adj_matrix[mapping_orig_router][mapping_nbr_router]=atoi(metric); |
| 739 | |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | free(lsa_data); |
| 744 | } |
| 745 | |
| 746 | void |
| 747 | make_adj_matrix(int **adj_matrix,int map_element) |
| 748 | { |
| 749 | |
| 750 | init_adj_matrix(adj_matrix,map_element); |
| 751 | |
| 752 | int i, adj_lsdb_element; |
| 753 | struct alsa *adj_lsa; |
| 754 | |
| 755 | struct hashtb_enumerator ee; |
| 756 | struct hashtb_enumerator *e = ⅇ |
| 757 | |
| 758 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 759 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 760 | |
| 761 | for(i=0;i<adj_lsdb_element;i++) |
| 762 | { |
| 763 | adj_lsa=e->data; |
| 764 | assign_adj_matrix_for_lsa(adj_lsa,adj_matrix); |
| 765 | hashtb_next(e); |
| 766 | } |
| 767 | |
| 768 | hashtb_end(e); |
| 769 | |
| 770 | } |
| 771 | |
| 772 | void |
| 773 | init_adj_matrix(int **adj_matrix,int map_element) |
| 774 | { |
| 775 | int i, j; |
| 776 | for(i=0;i<map_element;i++) |
| 777 | for(j=0;j<map_element;j++) |
| 778 | adj_matrix[i][j]=0; |
| 779 | } |
| 780 | |
| 781 | void print_adj_matrix(int **adj_matrix, int map_element) |
| 782 | { |
| 783 | int i, j; |
| 784 | for(i=0;i<map_element;i++) |
| 785 | { |
| 786 | for(j=0;j<map_element;j++) |
| 787 | printf("%d ",adj_matrix[i][j]); |
| 788 | printf("\n"); |
| 789 | } |
| 790 | } |
| 791 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 792 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 793 | int |
akmhoque | 9fe296b | 2012-09-24 09:52:08 -0500 | [diff] [blame] | 794 | get_no_link_from_adj_matrix(int **adj_matrix,long int V, long int S) |
| 795 | { |
| 796 | int no_link=0; |
| 797 | int i; |
| 798 | |
| 799 | for(i=0;i<V;i++) |
| 800 | { |
| 801 | if ( adj_matrix[S][i] > 0 ) |
| 802 | { |
| 803 | no_link++; |
| 804 | } |
| 805 | } |
| 806 | return no_link; |
| 807 | } |
| 808 | |
| 809 | void |
| 810 | get_links_from_adj_matrix(int **adj_matrix, long int V ,long int *links, long int *link_costs,long int S) |
| 811 | { |
| 812 | int i,j; |
| 813 | j=0; |
| 814 | for (i=0; i <V; i++) |
| 815 | { |
| 816 | if ( adj_matrix[S][i] > 0 ) |
| 817 | { |
| 818 | links[j]=i; |
| 819 | link_costs[j]=adj_matrix[S][i]; |
| 820 | j++; |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | void adjust_adj_matrix(int **adj_matrix, long int V, long int S, long int link,long int link_cost) |
| 826 | { |
| 827 | int i; |
| 828 | for ( i = 0; i < V; i++ ) |
| 829 | { |
| 830 | if ( i == link ) |
| 831 | { |
| 832 | adj_matrix[S][i]=link_cost; |
| 833 | } |
| 834 | else |
| 835 | { |
| 836 | adj_matrix[S][i]=0; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | } |
| 841 | |
| 842 | int |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 843 | get_number_of_next_hop(char *dest_router) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 844 | { |
| 845 | struct routing_table_entry *rte; |
| 846 | |
| 847 | struct hashtb_enumerator ee; |
| 848 | struct hashtb_enumerator *e = ⅇ |
| 849 | int res,ret; |
| 850 | |
| 851 | hashtb_start(nlsr->routing_table, e); |
| 852 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 853 | |
| 854 | if( res == HT_OLD_ENTRY ) |
| 855 | { |
| 856 | rte=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 857 | ret=hashtb_n(rte->face_list); |
| 858 | //nhl=rte->face_list; |
| 859 | } |
| 860 | else if(res == HT_NEW_ENTRY) |
| 861 | { |
| 862 | hashtb_delete(e); |
| 863 | ret=NO_NEXT_HOP; |
| 864 | } |
| 865 | |
| 866 | hashtb_end(e); |
| 867 | |
| 868 | return ret; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | int |
| 873 | get_next_hop(char *dest_router,int *faces, int *route_costs) |
| 874 | { |
| 875 | struct routing_table_entry *rte; |
| 876 | |
| 877 | struct hashtb_enumerator ee; |
| 878 | struct hashtb_enumerator *e = ⅇ |
| 879 | int res,ret; |
| 880 | |
| 881 | hashtb_start(nlsr->routing_table, e); |
| 882 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 883 | |
| 884 | if( res == HT_OLD_ENTRY ) |
| 885 | { |
| 886 | rte=e->data; |
| 887 | ret=hashtb_n(rte->face_list); |
| 888 | //nhl=rte->face_list; |
| 889 | int j,face_list_element; |
| 890 | struct face_list_entry *fle; |
| 891 | |
| 892 | struct hashtb_enumerator eef; |
| 893 | struct hashtb_enumerator *ef = &eef; |
| 894 | |
| 895 | hashtb_start(rte->face_list, ef); |
| 896 | face_list_element=hashtb_n(rte->face_list); |
| 897 | for(j=0;j<face_list_element;j++) |
| 898 | { |
| 899 | fle=ef->data; |
| 900 | //printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost); |
| 901 | faces[j]=fle->next_hop_face; |
| 902 | route_costs[j]=fle->route_cost; |
| 903 | hashtb_next(ef); |
| 904 | } |
| 905 | hashtb_end(ef); |
| 906 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 907 | } |
| 908 | else if(res == HT_NEW_ENTRY) |
| 909 | { |
| 910 | hashtb_delete(e); |
| 911 | ret=NO_NEXT_HOP; |
| 912 | } |
| 913 | |
| 914 | hashtb_end(e); |
| 915 | |
| 916 | return ret; |
| 917 | } |
| 918 | |
| 919 | void |
| 920 | add_next_hop_router(char *dest_router) |
| 921 | { |
| 922 | if ( strcmp(dest_router,nlsr->router_name)== 0) |
| 923 | { |
| 924 | return ; |
| 925 | } |
| 926 | |
| 927 | struct routing_table_entry *rte=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry)); |
| 928 | |
| 929 | struct hashtb_enumerator ee; |
| 930 | struct hashtb_enumerator *e = ⅇ |
| 931 | int res; |
| 932 | |
| 933 | hashtb_start(nlsr->routing_table, e); |
| 934 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 935 | |
| 936 | if( res == HT_NEW_ENTRY ) |
| 937 | { |
| 938 | rte=e->data; |
| 939 | rte->dest_router=(char *)malloc(strlen(dest_router)+1); |
| 940 | memset(rte->dest_router,0,strlen(dest_router)+1); |
| 941 | memcpy(rte->dest_router,dest_router,strlen(dest_router)); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 942 | //rte->next_hop_face=NO_NEXT_HOP; |
| 943 | struct hashtb_param param_fle = {0}; |
| 944 | rte->face_list=hashtb_create(sizeof(struct face_list_entry), ¶m_fle); |
| 945 | |
| 946 | add_npt_entry(dest_router, dest_router, 0, NULL, NULL); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 947 | } |
| 948 | hashtb_end(e); |
| 949 | |
| 950 | } |
| 951 | |
| 952 | void |
| 953 | add_next_hop_from_lsa_adj_body(char *body, int no_link) |
| 954 | { |
| 955 | |
| 956 | int i=0; |
| 957 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 958 | memset( lsa_data,0,strlen(body)+1); |
| 959 | memcpy(lsa_data,body,strlen(body)+1); |
| 960 | char *sep="|"; |
| 961 | char *rem; |
| 962 | char *rtr_id; |
| 963 | char *length; |
| 964 | char *face; |
| 965 | char *metric; |
| 966 | |
| 967 | if(no_link >0 ) |
| 968 | { |
| 969 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 970 | length=strtok_r(NULL,sep,&rem); |
| 971 | face=strtok_r(NULL,sep,&rem); |
| 972 | metric=strtok_r(NULL,sep,&rem); |
| 973 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 974 | |
| 975 | add_next_hop_router(rtr_id); |
| 976 | |
| 977 | for(i=1;i<no_link;i++) |
| 978 | { |
| 979 | rtr_id=strtok_r(NULL,sep,&rem); |
| 980 | length=strtok_r(NULL,sep,&rem); |
| 981 | face=strtok_r(NULL,sep,&rem); |
| 982 | metric=strtok_r(NULL,sep,&rem); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 983 | |
| 984 | add_next_hop_router(rtr_id); |
| 985 | |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | free(lsa_data); |
| 990 | |
| 991 | |
| 992 | } |
| 993 | |
| 994 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 995 | update_routing_table(char * dest_router,int next_hop_face, int route_cost) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 996 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 997 | if ( nlsr->debugging ) |
| 998 | { |
| 999 | printf("update_routing_table called \n"); |
| 1000 | printf("Dest Router: %s Next Hop face: %d Route Cost: %d \n",dest_router,next_hop_face,route_cost); |
| 1001 | } |
| 1002 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1003 | int res,res1; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1004 | struct routing_table_entry *rte; |
| 1005 | |
| 1006 | struct hashtb_enumerator ee; |
| 1007 | struct hashtb_enumerator *e = ⅇ |
| 1008 | |
| 1009 | hashtb_start(nlsr->routing_table, e); |
| 1010 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 1011 | |
| 1012 | if( res == HT_OLD_ENTRY ) |
| 1013 | { |
| 1014 | rte=e->data; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1015 | |
| 1016 | struct hashtb_enumerator eef; |
| 1017 | struct hashtb_enumerator *ef = &eef; |
| 1018 | |
| 1019 | hashtb_start(rte->face_list, ef); |
| 1020 | res1 = hashtb_seek(ef, &next_hop_face, sizeof(next_hop_face), 0); |
| 1021 | if( res1 == HT_NEW_ENTRY) |
| 1022 | { |
| 1023 | struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry)); |
| 1024 | fle=ef->data; |
| 1025 | fle->next_hop_face=next_hop_face; |
| 1026 | fle->route_cost=route_cost; |
| 1027 | } |
| 1028 | else if ( res1 == HT_OLD_ENTRY ) |
| 1029 | { |
| 1030 | struct face_list_entry *fle; |
| 1031 | fle=ef->data; |
| 1032 | fle->route_cost=route_cost; |
| 1033 | } |
| 1034 | hashtb_end(ef); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1035 | } |
| 1036 | else if ( res == HT_OLD_ENTRY ) |
| 1037 | { |
| 1038 | hashtb_delete(e); |
| 1039 | } |
| 1040 | |
| 1041 | hashtb_end(e); |
| 1042 | |
| 1043 | } |
| 1044 | |
| 1045 | void |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1046 | print_routing_table(void) |
| 1047 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1048 | if ( nlsr->debugging ) |
| 1049 | printf("print_routing_table called\n"); |
| 1050 | if ( nlsr->detailed_logging ) |
| 1051 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_routing_table called\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1052 | int i,j, rt_element,face_list_element; |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1053 | |
| 1054 | struct routing_table_entry *rte; |
| 1055 | |
| 1056 | struct hashtb_enumerator ee; |
| 1057 | struct hashtb_enumerator *e = ⅇ |
| 1058 | |
| 1059 | hashtb_start(nlsr->routing_table, e); |
| 1060 | rt_element=hashtb_n(nlsr->routing_table); |
| 1061 | |
| 1062 | for(i=0;i<rt_element;i++) |
| 1063 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1064 | if ( nlsr->debugging ) |
| 1065 | printf("----------Routing Table Entry %d------------------\n",i+1); |
| 1066 | if ( nlsr->detailed_logging ) |
| 1067 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------Routing Table Entry %d------------------\n",i+1); |
| 1068 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1069 | rte=e->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1070 | |
| 1071 | if ( nlsr->debugging ) |
| 1072 | printf(" Destination Router: %s \n",rte->dest_router); |
| 1073 | if ( nlsr->detailed_logging ) |
| 1074 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Destination Router: %s \n",rte->dest_router); |
| 1075 | |
| 1076 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1077 | //rte->next_hop_face == NO_NEXT_HOP ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", rte->next_hop_face); |
| 1078 | |
| 1079 | struct face_list_entry *fle; |
| 1080 | |
| 1081 | struct hashtb_enumerator eef; |
| 1082 | struct hashtb_enumerator *ef = &eef; |
| 1083 | |
| 1084 | hashtb_start(rte->face_list, ef); |
| 1085 | face_list_element=hashtb_n(rte->face_list); |
| 1086 | if ( face_list_element <= 0 ) |
| 1087 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1088 | if ( nlsr->debugging ) |
| 1089 | printf(" Face: No Face \n"); |
| 1090 | if ( nlsr->detailed_logging ) |
| 1091 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | for(j=0;j<face_list_element;j++) |
| 1096 | { |
| 1097 | fle=ef->data; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1098 | if ( nlsr->debugging ) |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1099 | 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] | 1100 | if ( nlsr->detailed_logging ) |
| 1101 | 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] | 1102 | hashtb_next(ef); |
| 1103 | } |
| 1104 | } |
| 1105 | hashtb_end(ef); |
| 1106 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1107 | hashtb_next(e); |
| 1108 | } |
| 1109 | |
| 1110 | hashtb_end(e); |
| 1111 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1112 | if ( nlsr->debugging ) |
| 1113 | printf("\n"); |
| 1114 | if ( nlsr->detailed_logging ) |
| 1115 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1118 | |
| 1119 | int |
| 1120 | delete_empty_rte(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1121 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1122 | if ( nlsr->debugging ) |
| 1123 | { |
| 1124 | printf("delete_empty_rte called\n"); |
| 1125 | printf("Router: %s \n",(char *)ev->evdata); |
| 1126 | } |
| 1127 | if ( nlsr->detailed_logging ) |
| 1128 | { |
| 1129 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_empty_rte called\n"); |
| 1130 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router: %s \n",(char *)ev->evdata); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1131 | } |
| 1132 | |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1133 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1134 | { |
| 1135 | return -1; |
| 1136 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1137 | |
| 1138 | nlsr_lock(); |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1139 | int res; |
| 1140 | struct hashtb_enumerator ee; |
| 1141 | struct hashtb_enumerator *e = ⅇ |
| 1142 | |
| 1143 | hashtb_start(nlsr->routing_table, e); |
| 1144 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1145 | |
| 1146 | if ( res == HT_OLD_ENTRY ) |
| 1147 | { |
| 1148 | hashtb_delete(e); |
| 1149 | } |
| 1150 | else if ( res == HT_NEW_ENTRY ) |
| 1151 | { |
| 1152 | hashtb_delete(e); |
| 1153 | } |
| 1154 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1155 | print_routing_table(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1156 | |
| 1157 | nlsr_unlock(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1158 | |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1159 | return 0; |
| 1160 | } |
| 1161 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1162 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1163 | clear_old_routing_table(void) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1164 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1165 | if ( nlsr->debugging ) |
| 1166 | printf("clear_old_routing_table called\n"); |
| 1167 | if ( nlsr->detailed_logging ) |
| 1168 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"clear_old_routing_table called\n"); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1169 | int i,rt_element; |
| 1170 | |
| 1171 | struct routing_table_entry *rte; |
| 1172 | |
| 1173 | struct hashtb_enumerator ee; |
| 1174 | struct hashtb_enumerator *e = ⅇ |
| 1175 | |
| 1176 | hashtb_start(nlsr->routing_table, e); |
| 1177 | rt_element=hashtb_n(nlsr->routing_table); |
| 1178 | |
| 1179 | for(i=0;i<rt_element;i++) |
| 1180 | { |
| 1181 | rte=e->data; |
| 1182 | hashtb_destroy(&rte->face_list); |
| 1183 | struct hashtb_param param_fle = {0}; |
| 1184 | rte->face_list=hashtb_create(sizeof(struct face_list_entry), ¶m_fle); |
| 1185 | |
| 1186 | hashtb_next(e); |
| 1187 | } |
| 1188 | |
| 1189 | hashtb_end(e); |
| 1190 | } |
| 1191 | |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1192 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1193 | void |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1194 | do_old_routing_table_updates(void) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1195 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1196 | if ( nlsr->debugging ) |
| 1197 | printf("do_old_routing_table_updates called\n"); |
| 1198 | if ( nlsr->detailed_logging ) |
| 1199 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"do_old_routing_table_updates called\n"); |
| 1200 | |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 1201 | int i, rt_element; |
| 1202 | int mapping_no; |
| 1203 | |
| 1204 | struct routing_table_entry *rte; |
| 1205 | |
| 1206 | struct hashtb_enumerator ee; |
| 1207 | struct hashtb_enumerator *e = ⅇ |
| 1208 | |
| 1209 | hashtb_start(nlsr->routing_table, e); |
| 1210 | rt_element=hashtb_n(nlsr->routing_table); |
| 1211 | |
| 1212 | for(i=0;i<rt_element;i++) |
| 1213 | { |
| 1214 | rte=e->data; |
| 1215 | mapping_no=get_mapping_no(rte->dest_router); |
| 1216 | if ( mapping_no == NO_MAPPING_NUM) |
| 1217 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1218 | delete_orig_router_from_npt(rte->dest_router); |
akmhoque | 63152c6 | 2012-09-18 08:43:42 -0500 | [diff] [blame] | 1219 | char *router=(char *)malloc(strlen(rte->dest_router)+1); |
| 1220 | memset(router,0,strlen(rte->dest_router)+1); |
| 1221 | memcpy(router,rte->dest_router,strlen(rte->dest_router)+1); |
| 1222 | nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_empty_rte, (void *)router , 0); |
akmhoque | 810a5b5 | 2012-09-09 16:53:14 -0500 | [diff] [blame] | 1223 | } |
| 1224 | hashtb_next(e); |
| 1225 | } |
| 1226 | |
| 1227 | hashtb_end(e); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1228 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1229 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1230 | void |
| 1231 | update_routing_table_with_new_hyperbolic_route(long int dest_router_rev_map_index, long int face, double nbr_to_dest_dist) |
| 1232 | { |
| 1233 | if ( nlsr->debugging ) |
| 1234 | printf("update_routing_table_with_new_hyperbolic_route called\n"); |
| 1235 | if ( nlsr->detailed_logging ) |
| 1236 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_routing_table_with_new_hyperbolic_route called\n"); |
| 1237 | |
| 1238 | char *orig_router=get_router_from_rev_map(dest_router_rev_map_index); |
| 1239 | |
| 1240 | if (face != NO_NEXT_HOP && face != NO_FACE ) |
| 1241 | { |
| 1242 | update_routing_table(orig_router,face,nbr_to_dest_dist); |
| 1243 | if ( nlsr->debugging ) |
| 1244 | printf ("Orig_router: %s Next Hop Face: %ld \n",orig_router,face); |
| 1245 | if ( nlsr->detailed_logging ) |
| 1246 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %ld \n",orig_router,face); |
| 1247 | |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1252 | |
| 1253 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1254 | void |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1255 | update_routing_table_with_new_route(long int *parent, long int *dist,long int source) |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1256 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1257 | if ( nlsr->debugging ) |
| 1258 | printf("update_routing_table_with_new_route called\n"); |
| 1259 | if ( nlsr->detailed_logging ) |
| 1260 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_routing_table_with_new_route called\n"); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1261 | int i, map_element; |
| 1262 | struct map_entry *me; |
| 1263 | |
| 1264 | struct hashtb_enumerator ee; |
| 1265 | struct hashtb_enumerator *e = ⅇ |
| 1266 | |
| 1267 | hashtb_start(nlsr->rev_map, e); |
| 1268 | map_element=hashtb_n(nlsr->rev_map); |
| 1269 | |
| 1270 | for(i=0;i<map_element;i++) |
| 1271 | { |
| 1272 | me=e->data; |
| 1273 | if(me->mapping != source) |
| 1274 | { |
| 1275 | |
| 1276 | char *orig_router=get_router_from_rev_map(me->mapping); |
| 1277 | if (orig_router != NULL ) |
| 1278 | { |
| 1279 | int next_hop_router_num=get_next_hop_from_calculation(parent,me->mapping,source); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1280 | if ( next_hop_router_num == NO_NEXT_HOP ) |
| 1281 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1282 | if ( nlsr->debugging ) |
| 1283 | printf ("Orig_router: %s Next Hop Face: %d \n",orig_router,NO_FACE); |
| 1284 | if ( nlsr->detailed_logging ) |
| 1285 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %d \n",orig_router,NO_FACE); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1286 | } |
| 1287 | else |
| 1288 | { |
| 1289 | char *next_hop_router=get_router_from_rev_map(next_hop_router_num); |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1290 | int next_hop_face=get_next_hop_face_from_adl(next_hop_router); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1291 | update_routing_table(orig_router,next_hop_face,dist[me->mapping]); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1292 | if ( nlsr->debugging ) |
| 1293 | printf ("Orig_router: %s Next Hop Face: %d \n",orig_router,next_hop_face); |
| 1294 | if ( nlsr->detailed_logging ) |
| 1295 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %d \n",orig_router,next_hop_face); |
| 1296 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1297 | |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | hashtb_next(e); |
| 1302 | } |
| 1303 | |
| 1304 | hashtb_end(e); |
| 1305 | } |
| 1306 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1307 | int |
| 1308 | does_face_exist_for_router(char *dest_router, int face_id) |
| 1309 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1310 | if (nlsr->debugging) |
| 1311 | { |
| 1312 | printf("does_face_exist_for_router called\n"); |
| 1313 | printf("Dest Router: %s and Face id: %d \n",dest_router, face_id); |
| 1314 | } |
| 1315 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1316 | int ret=0; |
| 1317 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1318 | int res; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1319 | struct routing_table_entry *rte; |
| 1320 | |
| 1321 | struct hashtb_enumerator ee; |
| 1322 | struct hashtb_enumerator *e = ⅇ |
| 1323 | |
| 1324 | hashtb_start(nlsr->routing_table, e); |
| 1325 | res = hashtb_seek(e, dest_router, strlen(dest_router), 0); |
| 1326 | |
| 1327 | if( res == HT_OLD_ENTRY ) |
| 1328 | { |
| 1329 | rte=e->data; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1330 | unsigned *v; |
| 1331 | v = hashtb_lookup(rte->face_list, &face_id, sizeof(face_id)); |
| 1332 | if (v != NULL) |
| 1333 | ret = 1; |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1334 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1335 | else |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 1336 | { |
| 1337 | hashtb_delete(e); |
| 1338 | } |
| 1339 | |
| 1340 | hashtb_end(e); |
| 1341 | |
| 1342 | return ret; |
| 1343 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame^] | 1344 | |
| 1345 | double |
| 1346 | get_hyperbolic_distance(long int source, long int dest) |
| 1347 | { |
| 1348 | double distance; |
| 1349 | char *src_router=get_router_from_rev_map(source); |
| 1350 | char *dest_router=get_router_from_rev_map(dest); |
| 1351 | |
| 1352 | double src_r=get_hyperbolic_r(src_router); |
| 1353 | double src_theta=get_hyperbolic_r(src_router); |
| 1354 | |
| 1355 | double dest_r=get_hyperbolic_r(dest_router); |
| 1356 | double dest_theta=get_hyperbolic_r(dest_router); |
| 1357 | if ( src_r != -1 && dest_r != -1 ) |
| 1358 | { |
| 1359 | distance=acosh(cosh(src_r)*cosh(dest_r)-sinh(src_r)*sinh(dest_r)*cos(src_theta-dest_theta)); |
| 1360 | } |
| 1361 | else |
| 1362 | { |
| 1363 | distance= -1.0; |
| 1364 | } |
| 1365 | |
| 1366 | return distance; |
| 1367 | } |