From: Martin Quinson Date: Tue, 15 Nov 2011 09:36:22 +0000 (+0100) Subject: merge get_route and get_latency in routings too X-Git-Tag: exp_20120216~272 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/293f64574aef0e51a16ed3ba8187c650765dfd99 merge get_route and get_latency in routings too --- diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index 6c0528ff5b..784bf3dd13 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -139,7 +139,7 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t route_t route = xbt_new0(s_route_t,1); route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - rc->get_route (rc, child1_name, child2_name, route); + rc->get_route_and_latency (rc, child1_name, child2_name, route,NULL); unsigned int cpt; void *link; container_t previous = getContainerByName(route->src_gateway); @@ -446,7 +446,7 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb route_t route = xbt_new0(s_route_t,1); route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - rc->get_route (rc, child1_name, child2_name,route); + rc->get_route_and_latency (rc, child1_name, child2_name,route, NULL); unsigned int cpt; void *link; xbt_node_t current, previous = new_xbt_graph_node(graph, route->src_gateway, nodes); diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index b527e5c48f..d8a993cc96 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -132,10 +132,8 @@ typedef struct s_as { struct s_as *routing_father; xbt_dict_t routing_sons; - void (*get_route) (AS_t as, const char *src, const char *dst, route_t into); - double(*get_latency) (AS_t as, - const char *src, const char *dst, - route_t e_route); + void (*get_route_and_latency) (AS_t as, const char *src, const char *dst, route_t into, double *latency); + xbt_dynar_t(*get_onelink_routes) (AS_t as); route_t(*get_bypass_route) (AS_t as, const char *src, const char *dst); void (*finalize) (AS_t as); diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 66a0d1a231..55e773caf7 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -504,12 +504,9 @@ static void _get_route_and_latency(const char *src, const char *dst, route.link_list = xbt_dynar_new(global_routing->size_of_link, NULL); - common_father->get_route(common_father, src, dst, &route); + common_father->get_route_and_latency(common_father, src, dst, &route,latency); *links = route.link_list; - if (latency) - *latency += common_father->get_latency(common_father, src, dst, &route); - xbt_free(route.src_gateway); xbt_free(route.dst_gateway); return; @@ -540,7 +537,7 @@ static void _get_route_and_latency(const char *src, const char *dst, route_t e_route_cnt = xbt_new0(s_route_t, 1); e_route_cnt->link_list = xbt_dynar_new(global_routing->size_of_link, NULL); - common_father->get_route(common_father, src_father->name, dst_father->name, e_route_cnt); + common_father->get_route_and_latency(common_father, src_father->name, dst_father->name, e_route_cnt,latency); xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"", src_father->name, dst_father->name); @@ -551,13 +548,6 @@ static void _get_route_and_latency(const char *src, const char *dst, *links = xbt_dynar_new(global_routing->size_of_link, NULL); - if (latency) { - *latency += common_father->get_latency(common_father, - src_father->name, dst_father->name, - e_route_cnt); - } - - /* If source gateway is not our source, we have to recursively find our way up to this point */ if (strcmp(src, e_route_cnt->src_gateway)) { xbt_dynar_t route_src; diff --git a/src/surf/surf_routing_cluster.c b/src/surf/surf_routing_cluster.c index 3af7568158..bc11f8fe2f 100644 --- a/src/surf/surf_routing_cluster.c +++ b/src/surf/surf_routing_cluster.c @@ -23,20 +23,31 @@ typedef struct { static xbt_dict_t cluster_host_link = NULL; /* Business methods */ -static void cluster_get_route(AS_t as, - const char *src, const char *dst, - route_t route) { +static void cluster_get_route_and_latency(AS_t as, + const char *src, const char *dst, + route_t route, double *lat) { surf_parsing_link_up_down_t info; info = xbt_dict_get_or_null(cluster_host_link,src); - if(info) xbt_dynar_push_as(route->link_list,void*,info->link_up); //link_up + if(info) { // link up + xbt_dynar_push_as(route->link_list,void*,info->link_up); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(info->link_up); + } - if ( ((as_cluster_t)as)->backbone ) + if ( ((as_cluster_t)as)->backbone ) { xbt_dynar_push_as(route->link_list,void*, ((as_cluster_t)as)->backbone) ; + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(((as_cluster_t)as)->backbone); + } info = xbt_dict_get_or_null(cluster_host_link,dst); - if(info) xbt_dynar_push_as(route->link_list,void*,info->link_down); //link_down + if(info) { // link down + xbt_dynar_push_as(route->link_list,void*,info->link_down); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(info->link_down); + } } static void model_cluster_finalize(AS_t as) { @@ -47,8 +58,7 @@ static void model_cluster_finalize(AS_t as) { AS_t model_cluster_create(void) { AS_t result = model_none_create_sized(sizeof(s_as_cluster_t)); - result->get_route = cluster_get_route; - result->get_latency = generic_get_link_latency; + result->get_route_and_latency = cluster_get_route_and_latency; result->finalize = model_cluster_finalize; return (AS_t) result; diff --git a/src/surf/surf_routing_dijkstra.c b/src/surf/surf_routing_dijkstra.c index 3c98c82291..778f37d629 100644 --- a/src/surf/surf_routing_dijkstra.c +++ b/src/surf/surf_routing_dijkstra.c @@ -165,12 +165,11 @@ static void add_loopback_dijkstra(as_dijkstra_t as) { } } -static void dijkstra_get_route(AS_t as_generic, - const char *src, const char *dst, route_t route); +static void dijkstra_get_route_and_latency(AS_t as_generic, + const char *src, const char *dst, route_t route, double *lat); static xbt_dynar_t dijkstra_get_onelink_routes(AS_t as) { - // xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet"); xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); //size_t table_size = xbt_dict_length(routing->generic_routing.to_index); @@ -180,7 +179,7 @@ static xbt_dynar_t dijkstra_get_onelink_routes(AS_t as) xbt_dict_foreach(as->to_index, c2, k2, d2) { route_t route = xbt_new0(s_route_t,1); route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - dijkstra_get_route(as, k1, k2,route); + dijkstra_get_route_and_latency(as, k1, k2,route, NULL); if (xbt_dynar_length(route->link_list) == 1) { void *link = @@ -202,9 +201,9 @@ static xbt_dynar_t dijkstra_get_onelink_routes(AS_t as) return ret; } -static void dijkstra_get_route(AS_t asg, +static void dijkstra_get_route_and_latency(AS_t asg, const char *src, const char *dst, - route_t route) + route_t route, double *lat) { /* set utils vars */ @@ -256,6 +255,8 @@ static void dijkstra_get_route(AS_t asg, links = e_route->link_list; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_unshift(route->link_list, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); } } @@ -360,6 +361,8 @@ static void dijkstra_get_route(AS_t asg, int pos = 0; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_insert_at(route->link_list, pos, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); pos++; } } @@ -367,6 +370,8 @@ static void dijkstra_get_route(AS_t asg, links = e_route->link_list; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_unshift(route->link_list, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); } size++; } @@ -411,7 +416,7 @@ AS_t model_dijkstra_both_create(int cached) new_component->generic_routing.parse_route = model_dijkstra_both_parse_route; new_component->generic_routing.parse_ASroute = model_dijkstra_both_parse_route; - new_component->generic_routing.get_route = dijkstra_get_route; + new_component->generic_routing.get_route_and_latency = dijkstra_get_route_and_latency; new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes; new_component->generic_routing.finalize = dijkstra_finalize; diff --git a/src/surf/surf_routing_floyd.c b/src/surf/surf_routing_floyd.c index ab3706d60e..a4e1fa3609 100644 --- a/src/surf/surf_routing_floyd.c +++ b/src/surf/surf_routing_floyd.c @@ -25,7 +25,8 @@ typedef struct { route_t *link_table; } s_as_floyd_t, *as_floyd_t; -static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t res); +static void floyd_get_route_and_latency(AS_t asg, const char *src, const char *dst, + route_t res, double *lat); /* Business methods */ static xbt_dynar_t floyd_get_onelink_routes(AS_t asg) @@ -40,7 +41,7 @@ static xbt_dynar_t floyd_get_onelink_routes(AS_t asg) xbt_dict_foreach(asg->to_index, c1, k1, d1) { xbt_dict_foreach(asg->to_index, c2, k2, d2) { xbt_dynar_reset(route->link_list); - floyd_get_route(asg, k1, k2, route); + floyd_get_route_and_latency(asg, k1, k2, route, NULL); if (xbt_dynar_length(route->link_list) == 1) { void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); onelink_t onelink = xbt_new0(s_onelink_t, 1); @@ -59,7 +60,8 @@ static xbt_dynar_t floyd_get_onelink_routes(AS_t asg) return ret; } -static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t res) +static void floyd_get_route_and_latency(AS_t asg, const char *src, const char *dst, + route_t res, double *lat) { /* set utils vars */ @@ -108,6 +110,8 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t int pos = 0; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_insert_at(res->link_list, pos, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); pos++; } } @@ -115,6 +119,8 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t links = e_route->link_list; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_unshift(res->link_list, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); } first = 0; @@ -156,7 +162,7 @@ AS_t model_floyd_create(void) as_floyd_t new_component = (as_floyd_t)model_generic_create_sized(sizeof(s_as_floyd_t)); new_component->generic_routing.parse_route = model_floyd_parse_route; new_component->generic_routing.parse_ASroute = model_floyd_parse_route; - new_component->generic_routing.get_route = floyd_get_route; + new_component->generic_routing.get_route_and_latency = floyd_get_route_and_latency; new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes; new_component->generic_routing.finalize = floyd_finalize; diff --git a/src/surf/surf_routing_full.c b/src/surf/surf_routing_full.c index 1263e94e9f..60dff10a57 100644 --- a/src/surf/surf_routing_full.c +++ b/src/surf/surf_routing_full.c @@ -61,9 +61,9 @@ static xbt_dynar_t full_get_onelink_routes(AS_t rc) return ret; } -static void full_get_route(AS_t rc, +static void full_get_route_and_latency(AS_t rc, const char *src, const char *dst, - route_t res) + route_t res,double *lat) { /* set utils vars */ @@ -87,6 +87,8 @@ static void full_get_route(AS_t rc, res->dst_gateway = xbt_strdup(e_route->dst_gateway); xbt_dynar_foreach(e_route->link_list, cpt, link) { xbt_dynar_push(res->link_list, &link); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); } } } @@ -115,7 +117,7 @@ AS_t model_full_create(void) new_component->generic_routing.parse_route = model_full_set_route; new_component->generic_routing.parse_ASroute = model_full_set_route; - new_component->generic_routing.get_route = full_get_route; + new_component->generic_routing.get_route_and_latency = full_get_route_and_latency; new_component->generic_routing.get_onelink_routes = full_get_onelink_routes; new_component->generic_routing.finalize = full_finalize; diff --git a/src/surf/surf_routing_generic.c b/src/surf/surf_routing_generic.c index 459d4ad127..b3fbf54521 100644 --- a/src/surf/surf_routing_generic.c +++ b/src/surf/surf_routing_generic.c @@ -22,8 +22,7 @@ AS_t model_generic_create_sized(size_t childsize) { new_component->parse_route = NULL; new_component->parse_ASroute = NULL; new_component->parse_bypassroute = generic_parse_bypassroute; - new_component->get_route = NULL; - new_component->get_latency = generic_get_link_latency; + new_component->get_route_and_latency = NULL; new_component->get_onelink_routes = NULL; new_component->get_bypass_route = generic_get_bypassroute; @@ -89,31 +88,7 @@ void generic_parse_bypassroute(AS_t rc, /* ************************************************************************** */ /* *********************** GENERIC BUSINESS METHODS ************************* */ -double generic_get_link_latency(AS_t rc, - const char *src, const char *dst, - route_t route) -{ - int need_to_clean = route ? 0 : 1; - void *link; - unsigned int i; - double latency = 0.0; - - if (route == NULL) { - route = xbt_new0(s_route_t, 1); - route->link_list = xbt_dynar_new(global_routing->size_of_link, NULL); - rc->get_route(rc, src, dst, route); - } - - xbt_dynar_foreach(route->link_list, i, link) { - latency += surf_network_model->extension.network.get_link_latency(link); - } - if (need_to_clean) - generic_free_route(route); - return latency; -} - -xbt_dynar_t generic_get_onelink_routes(AS_t rc) -{ +xbt_dynar_t generic_get_onelink_routes(AS_t rc) { // FIXME: kill that stub xbt_die("\"generic_get_onelink_routes\" not implemented yet"); } diff --git a/src/surf/surf_routing_none.c b/src/surf/surf_routing_none.c index 3c2f02a3aa..85776de552 100644 --- a/src/surf/surf_routing_none.c +++ b/src/surf/surf_routing_none.c @@ -12,8 +12,8 @@ static xbt_dynar_t none_get_onelink_routes(AS_t rc) { return NULL; } -static void none_get_route(AS_t rc, const char *src, const char *dst, - route_t res) +static void none_get_route_and_latency(AS_t rc, const char *src, const char *dst, + route_t res,double *lat) { } @@ -42,7 +42,7 @@ AS_t model_none_create_sized(size_t childsize) { new_component->parse_route = NULL; new_component->parse_ASroute = NULL; new_component->parse_bypassroute = NULL; - new_component->get_route = none_get_route; + new_component->get_route_and_latency = none_get_route_and_latency; new_component->get_onelink_routes = none_get_onelink_routes; new_component->get_bypass_route = none_get_bypass_route; new_component->finalize = model_none_finalize; diff --git a/src/surf/surf_routing_private.h b/src/surf/surf_routing_private.h index 10dbeb627c..6f2fd75cba 100644 --- a/src/surf/surf_routing_private.h +++ b/src/surf/surf_routing_private.h @@ -37,8 +37,6 @@ void generic_parse_bypassroute(AS_t rc, const char *src, const char *dst, /* ************************************************************************** */ /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */ -double generic_get_link_latency(AS_t rc, const char *src, const char *dst, - route_t e_route); xbt_dynar_t generic_get_onelink_routes(AS_t rc); route_t generic_get_bypassroute(AS_t rc, const char *src, diff --git a/src/surf/surf_routing_rulebased.c b/src/surf/surf_routing_rulebased.c index 46309a6a5a..9b7c4200fe 100644 --- a/src/surf/surf_routing_rulebased.c +++ b/src/surf/surf_routing_rulebased.c @@ -205,9 +205,9 @@ static char *remplace(char *value, const char **src_list, int src_size, return memcpy(res, result, i_res); } -static void rulebased_get_route(AS_t rc, +static void rulebased_get_route_and_latency(AS_t rc, const char *src, const char *dst, - route_t res); + route_t res,double*lat); static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc) { xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free); @@ -236,7 +236,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc) xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) { route_t route = xbt_new0(s_route_t,1); route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - rulebased_get_route (rc, router, k1, route); + rulebased_get_route_and_latency (rc, router, k1, route,NULL); int number_of_links = xbt_dynar_length(route->link_list); @@ -261,9 +261,9 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc) } /* Business methods */ -static void rulebased_get_route(AS_t rc, +static void rulebased_get_route_and_latency(AS_t rc, const char *src, const char *dst, - route_t route) + route_t route, double *lat) { xbt_assert(rc && src && dst, @@ -318,9 +318,11 @@ static void rulebased_get_route(AS_t rc, remplace(link_name, list_src, rc_src, list_dst, rc_dst); void *link = xbt_lib_get_or_null(link_lib, new_link_name, SURF_LINK_LEVEL); - if (link) + if (link) { xbt_dynar_push(route->link_list, &link); - else + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); + } else THROWF(mismatch_error, 0, "Link %s not found", new_link_name); xbt_free(new_link_name); } @@ -334,6 +336,8 @@ static void rulebased_get_route(AS_t rc, /* matched src and dest, nothing more to do (?) */ } else if (!strcmp(src, dst) && are_processing_units) { xbt_dynar_push(route->link_list, &(global_routing->loopback)); + if (lat) + *lat += surf_network_model->extension.network.get_link_latency(link); } else { THROWF(arg_error,0,"No route from '%s' to '%s'??",src,dst); //xbt_dynar_reset(route->link_list); @@ -386,7 +390,7 @@ AS_t model_rulebased_create(void) { new_component->generic_routing.parse_ASroute = model_rulebased_parse_ASroute; new_component->generic_routing.parse_bypassroute = model_rulebased_parse_bypassroute; new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes; - new_component->generic_routing.get_route = rulebased_get_route; + new_component->generic_routing.get_route_and_latency = rulebased_get_route_and_latency; new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route; new_component->generic_routing.finalize = rulebased_finalize; /* initialization of internal structures */ diff --git a/src/surf/surf_routing_vivaldi.c b/src/surf/surf_routing_vivaldi.c index 22b9616eb1..05af06e0bd 100644 --- a/src/surf/surf_routing_vivaldi.c +++ b/src/surf/surf_routing_vivaldi.c @@ -7,32 +7,29 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_vivaldi, surf, "Routing part of surf"); -/* Business methods */ -static void vivaldi_get_route(AS_t rc, const char *src, const char *dst, - route_t route) -{ - xbt_assert(rc && src - && dst, - "Invalid params for \"get_route\" function at AS \"%s\"", - rc->name); - - route->src_gateway = ROUTER_PEER(src); - route->dst_gateway = ROUTER_PEER(dst); -} - -static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) -{ - double src_coord, dst_coord; +static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) { + double src_coord, dst_coord; src_coord = xbt_dynar_get_as(src, index, double); dst_coord = xbt_dynar_get_as(dst, index, double); - return (src_coord-dst_coord)*(src_coord-dst_coord); + return (src_coord-dst_coord)*(src_coord-dst_coord); } -static double base_vivaldi_get_latency (const char *src, const char *dst) + +static void vivaldi_get_route_and_latency( + AS_t rc, const char *src_p, const char *dst_p, + route_t route, double *lat) { + char *src = (char*)src_p; + char *dst = (char*)dst_p; + + if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) { + src = route->src_gateway = ROUTER_PEER(src); + dst = route->dst_gateway = ROUTER_PEER(dst); + } + double euclidean_dist; xbt_dynar_t src_ctn, dst_ctn; src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL); @@ -41,31 +38,21 @@ static double base_vivaldi_get_latency (const char *src, const char *dst) if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL); if(dst_ctn == NULL || src_ctn == NULL) - xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn); + xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn); euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn)) - + fabs(xbt_dynar_get_as(src_ctn, 2, double))+fabs(xbt_dynar_get_as(dst_ctn, 2, double)); + + fabs(xbt_dynar_get_as(src_ctn, 2, double))+fabs(xbt_dynar_get_as(dst_ctn, 2, double)); - //From .ms to .s - return euclidean_dist / 1000; -} + if (lat) + *lat += euclidean_dist / 1000; //From .ms to .s -static double vivaldi_get_latency (AS_t rc,const char *src, const char *dst, route_t e_route) -{ - if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) { - if (e_route) - return base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway); - return base_vivaldi_get_latency(ROUTER_PEER(src),ROUTER_PEER(dst)); - } else { - return base_vivaldi_get_latency(src,dst); - } } + /* Creation routing model functions */ AS_t model_vivaldi_create(void) { AS_t new_component = model_rulebased_create(); - new_component->get_route = vivaldi_get_route; - new_component->get_latency = vivaldi_get_latency; + new_component->get_route_and_latency = vivaldi_get_route_and_latency; return new_component; }