X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3e6c7cad2fecb20fc9e694e63cd915f097bf2b99..8d32c7ffa94dd5e1fc62a06ddab007a7b3f711e3:/src/surf/surf_routing.c diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 50504869e5..702ef14088 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -610,14 +610,14 @@ static void elements_father(const char *src, const char *dst, /* (2) find the path to the root routing component */ for (current = src_as ; current != NULL ; current = current->routing_father) { + if (index_src >= ELEMENTS_FATHER_MAXDEPTH) + xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src"); path_src[index_src++] = current; - xbt_assert(index_src <= ELEMENTS_FATHER_MAXDEPTH, - "ELEMENTS_FATHER_MAXDEPTH should be increased for path_src"); } for (current = dst_as ; current != NULL ; current = current->routing_father) { + if (index_dst >= ELEMENTS_FATHER_MAXDEPTH) + xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst"); path_dst[index_dst++] = current; - xbt_assert(index_dst <= ELEMENTS_FATHER_MAXDEPTH, - "ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst"); } /* (3) find the common father */ @@ -643,7 +643,7 @@ static void elements_father(const char *src, const char *dst, /* Global Business methods */ /** - * \brief Recursive function for get_route and get_latency + * \brief Recursive function for get_route_latency * * \param src the source host name * \param dst the destination host name @@ -775,6 +775,22 @@ static void _get_route_latency(const char *src, const char *dst, } } +/** + * \brief Generic function for get_route, get_route_no_cleanup, and get_latency + */ +static void get_route_latency(const char *src, const char *dst, + xbt_dynar_t *route, double *latency, int cleanup) +{ + _get_route_latency(src, dst, route, latency); + xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst); + xbt_assert(!latency || *latency >= 0.0, + "latency error on route between \"%s\" and \"%s\"", src, dst); + if (route) { + xbt_dynar_free(&global_routing->last_route); + global_routing->last_route = cleanup ? *route : NULL; + } +} + /** * \brief Generic method: find a route between hosts * @@ -787,15 +803,8 @@ static void _get_route_latency(const char *src, const char *dst, */ static xbt_dynar_t get_route(const char *src, const char *dst) { - xbt_dynar_t route = NULL; - - _get_route_latency(src, dst, &route, NULL); - xbt_assert(route, "no route between \"%s\" and \"%s\"", src, dst); - - xbt_dynar_free(&global_routing->last_route); - global_routing->last_route = route; - + get_route_latency(src, dst, &route, NULL, 1); return route; } @@ -811,18 +820,16 @@ static xbt_dynar_t get_route(const char *src, const char *dst) */ static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst) { - xbt_dynar_t d = get_route(src,dst); - global_routing->last_route = NULL; - return d; + xbt_dynar_t route = NULL; + get_route_latency(src, dst, &route, NULL, 0); + return route; } /*Get Latency*/ static double get_latency(const char *src, const char *dst) { - double latency = -1.0; - _get_route_latency(src, dst, NULL, &latency); - xbt_assert(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst); + get_route_latency(src, dst, NULL, &latency, 0); return latency; } @@ -930,6 +937,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ global_routing->get_latency = get_latency; global_routing->get_route_no_cleanup = get_route_no_cleanup; global_routing->get_onelink_routes = get_onelink_routes; + global_routing->get_route_latency = get_route_latency; global_routing->get_network_element_type = get_network_element_type; global_routing->finalize = finalize; global_routing->loopback = loopback;