X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6a9513d2cc6e9c0bd4f9fb042e0b315dfede50b3..53dd673a07059d04f7ee5c280470958856fdf8d8:/src/surf/surf_routing_RoutedGraph.cpp diff --git a/src/surf/surf_routing_RoutedGraph.cpp b/src/surf/surf_routing_RoutedGraph.cpp index 5da9ba1b0a..6af5f560a9 100644 --- a/src/surf/surf_routing_RoutedGraph.cpp +++ b/src/surf/surf_routing_RoutedGraph.cpp @@ -10,15 +10,12 @@ #include -#include -#include -#include -#include -#include +#include "xbt/dict.h" +#include "xbt/log.h" +#include "xbt/sysdep.h" +#include "xbt/dynar.h" +#include "xbt/graph.h" -#include "simgrid/platf_interface.h" // platform creation API internal interface - -#include "surf_routing_private.hpp" #include "network_interface.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing"); @@ -41,43 +38,8 @@ AsRoutedGraph::AsRoutedGraph(const char*name) AsRoutedGraph::~AsRoutedGraph() { - xbt_dict_free(&bypassRoutes_); } -void AsRoutedGraph::parseBypassroute(sg_platf_route_cbarg_t e_route) -{ - char *src = (char*)(e_route->src); - char *dst = (char*)(e_route->dst); - - if(bypassRoutes_ == nullptr) - bypassRoutes_ = xbt_dict_new_homogeneous((void (*)(void *)) routing_route_free); - - if(e_route->gw_dst) - XBT_DEBUG("Load bypassASroute from \"%s\" to \"%s\"", src, dst); - else - XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst); - xbt_dict_t dict_bypassRoutes = bypassRoutes_; - char *route_name; - - route_name = bprintf("%s#%s", src, dst); - xbt_assert(!xbt_dynar_is_empty(e_route->link_list), - "Invalid count of links, must be greater than zero (%s,%s)", - src, dst); - xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name), - "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists", - src, e_route->gw_src->name(), dst, e_route->gw_dst->name()); - - sg_platf_route_cbarg_t new_e_route = NULL; - if(e_route->gw_dst) - new_e_route = newExtendedRoute(SURF_ROUTING_RECURSIVE, e_route, 1); - else - new_e_route = newExtendedRoute(SURF_ROUTING_BASE, e_route, 1); - - xbt_dynar_free(&(e_route->link_list)); - - xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, NULL); - xbt_free(route_name); -} } } @@ -196,130 +158,6 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg } } -sg_platf_route_cbarg_t AsRoutedGraph::getBypassRoute(NetCard *src, NetCard *dst, double *lat) -{ - // If never set a bypass route return NULL without any further computations - XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name(), dst->name()); - if (bypassRoutes_ == nullptr) - return NULL; - - sg_platf_route_cbarg_t e_route_bypass = NULL; - - if(dst->containingAS() == this && src->containingAS() == this ){ - char *route_name = bprintf("%s#%s", src->name(), dst->name()); - e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(bypassRoutes_, route_name); - if(e_route_bypass) - XBT_DEBUG("Find bypass route with %ld links",xbt_dynar_length(e_route_bypass->link_list)); - free(route_name); - } - else{ - As *src_as, *dst_as; - int index_src, index_dst; - xbt_dynar_t path_src = NULL; - xbt_dynar_t path_dst = NULL; - As *current = NULL; - As **current_src = NULL; - As **current_dst = NULL; - - if (src == NULL || dst == NULL) - xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"", - src ? src->name() : "(null)", - dst ? dst->name() : "(null)", name_); - - src_as = src->containingAS(); - dst_as = dst->containingAS(); - - /* (2) find the path to the root routing component */ - path_src = xbt_dynar_new(sizeof(As*), NULL); - current = src_as; - while (current != NULL) { - xbt_dynar_push(path_src, ¤t); - current = current->father_; - } - path_dst = xbt_dynar_new(sizeof(As*), NULL); - current = dst_as; - while (current != NULL) { - xbt_dynar_push(path_dst, ¤t); - current = current->father_; - } - - /* (3) find the common father */ - index_src = path_src->used - 1; - index_dst = path_dst->used - 1; - current_src = (As **) xbt_dynar_get_ptr(path_src, index_src); - current_dst = (As **) xbt_dynar_get_ptr(path_dst, index_dst); - while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) { - xbt_dynar_pop_ptr(path_src); - xbt_dynar_pop_ptr(path_dst); - index_src--; - index_dst--; - current_src = (As **) xbt_dynar_get_ptr(path_src, index_src); - current_dst = (As **) xbt_dynar_get_ptr(path_dst, index_dst); - } - - int max_index_src = path_src->used - 1; - int max_index_dst = path_dst->used - 1; - - int max_index = std::max(max_index_src, max_index_dst); - - for (int max = 0; max <= max_index; max++) { - for (int i = 0; i < max; i++) { - if (i <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(As **) (xbt_dynar_get_ptr(path_src, i)))->name_, - (*(As **) (xbt_dynar_get_ptr(path_dst, max)))->name_); - e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(bypassRoutes_, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - if (max <= max_index_src && i <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(As **) (xbt_dynar_get_ptr(path_src, max)))->name_, - (*(As **) (xbt_dynar_get_ptr(path_dst, i)))->name_); - e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(bypassRoutes_, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - } - - if (e_route_bypass) - break; - - if (max <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(As **) (xbt_dynar_get_ptr(path_src, max)))->name_, - (*(As **) (xbt_dynar_get_ptr(path_dst, max)))->name_); - e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(bypassRoutes_, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - } - - xbt_dynar_free(&path_src); - xbt_dynar_free(&path_dst); - } - - sg_platf_route_cbarg_t new_e_route = NULL; - if (e_route_bypass) { - Link* link; - unsigned int cpt = 0; - new_e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - new_e_route->gw_src = e_route_bypass->gw_src; - new_e_route->gw_dst = e_route_bypass->gw_dst; - new_e_route->link_list = - xbt_dynar_new(sizeof(Link*), NULL); - xbt_dynar_foreach(e_route_bypass->link_list, cpt, link) { - xbt_dynar_push(new_e_route->link_list, &link); - if (lat) - *lat += link->getLatency(); - } - } - - return new_e_route; -} /* ************************************************************************** */ /* ************************* GENERIC AUX FUNCTIONS ************************** */