X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5faf49cdf3f8ad8751317b857a6d3134fe07eda3..3dbeba193df2e406bd9eff5be73c8bce0db0185e:/src/surf/surf_routing_dijkstra.cpp diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index 70c084f8c5..7c1ae30534 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -1,32 +1,16 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. +/* Copyright (c) 2009-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include "surf_routing_dijkstra.hpp" -#include "surf_routing_private.h" -#include "network.hpp" +#include "network_interface.hpp" /* Global vars */ extern routing_platf_t routing_platf; -extern "C" { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf -- dijkstra routing logic"); -} - -AS_t model_dijkstra_create(void){ - return new AsDijkstra(0); -} - -AS_t model_dijkstracache_create(void){ - return new AsDijkstra(1); -} - -void model_dijkstra_both_end(AS_t as) -{ - delete as; -} /* Free functions */ @@ -54,6 +38,43 @@ static void graph_edge_data_free(void *e) // FIXME: useless code duplication } } +AS_t model_dijkstra_create(void){ + return new AsDijkstra(0); +} + +AS_t model_dijkstracache_create(void){ + return new AsDijkstra(1); +} + +void model_dijkstra_both_end(AS_t as) +{ + AsDijkstraPtr THIS_AS = static_cast(as); + xbt_node_t node = NULL; + unsigned int cursor2; + xbt_dynar_t nodes = NULL; + + /* Create the topology graph */ + if(!THIS_AS->p_routeGraph) + THIS_AS->p_routeGraph = xbt_graph_new_graph(1, NULL); + if(!THIS_AS->p_graphNodeMap) + THIS_AS->p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free); + + if (THIS_AS->m_cached && !THIS_AS->p_routeCache) + THIS_AS->p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free); + + /* Add the loopback if needed */ + if (routing_platf->p_loopback && as->p_hierarchy == SURF_ROUTING_BASE) + THIS_AS->addLoopback(); + + /* initialize graph indexes in nodes after graph has been built */ + nodes = xbt_graph_get_nodes(THIS_AS->p_routeGraph); + + xbt_dynar_foreach(nodes, cursor2, node) { + graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(node); + data->graph_id = cursor2; + } +} + /* Utility functions */ xbt_node_t AsDijkstra::routeGraphNewNode(int id, int graph_id) @@ -155,13 +176,13 @@ void AsDijkstra::addLoopback() { xbt_dynar_t AsDijkstra::getOnelinkRoutes() { - xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free); + xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free_f); sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1); route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL); int src,dst; RoutingEdgePtr src_elm, dst_elm; - size_t table_size = xbt_dynar_length(p_indexNetworkElm); + int table_size = (int)xbt_dynar_length(p_indexNetworkElm); for(src=0; src < table_size; src++) { for(dst=0; dst< table_size; dst++) { xbt_dynar_reset(route->link_list); @@ -171,15 +192,13 @@ xbt_dynar_t AsDijkstra::getOnelinkRoutes() if (xbt_dynar_length(route->link_list) == 1) { void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); - OnelinkPtr onelink = new Onelink(); - onelink->p_linkPtr = link; - if (p_hierarchy == SURF_ROUTING_BASE) { - onelink->p_src = src_elm; - onelink->p_dst = dst_elm; - } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) { - onelink->p_src = route->gw_src; - onelink->p_dst = route->gw_dst; - } + OnelinkPtr onelink; + if (p_hierarchy == SURF_ROUTING_BASE) + onelink = new Onelink(link, src_elm, dst_elm); + else if (p_hierarchy == SURF_ROUTING_RECURSIVE) + onelink = new Onelink(link, route->gw_src, route->gw_dst); + else + onelink = new Onelink(link, NULL, NULL); xbt_dynar_push(ret, &onelink); } } @@ -193,11 +212,11 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p /* set utils vars */ srcDstCheck(src, dst); - int *src_id = &(src->m_id); - int *dst_id = &(dst->m_id); + int *src_id = src->getIdPtr(); + int *dst_id = dst->getIdPtr(); if (!src_id || !dst_id) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->p_name,dst->p_name); + THROWF(arg_error,0,"No route from '%s' to '%s'",src->getName(),dst->getName()); int *pred_arr = NULL; int src_node_id = 0; @@ -207,7 +226,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p sg_platf_route_cbarg_t e_route; int size = 0; unsigned int cpt; - NetworkCm02LinkPtr link; + void *link; xbt_dynar_t links = NULL; route_cache_element_t elm = NULL; xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph); @@ -229,7 +248,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_s_v, node_e_v); if (edge == NULL) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->p_name, dst->p_name); + THROWF(arg_error, 0, "No route from '%s' to '%s'", src->getName(), dst->getName()); e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); @@ -237,7 +256,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p xbt_dynar_foreach(links, cpt, link) { xbt_dynar_unshift(route->link_list, &link); if (lat) - *lat += link->getLatency(); + *lat += static_cast(link)->getLatency(); } } @@ -259,7 +278,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p int nr_nodes = xbt_dynar_length(nodes); cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */ pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */ - pqueue = xbt_heap_new(nr_nodes, xbt_free); + pqueue = xbt_heap_new(nr_nodes, xbt_free_f); /* initialize */ cost_arr[src_node_id] = 0.0; @@ -322,7 +341,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p xbt_graph_get_edge(p_routeGraph, node_pred_v, node_v); if (edge == NULL) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->p_name, dst->p_name); + THROWF(arg_error, 0, "No route from '%s' to '%s'", src->getName(), dst->getName()); prev_gw_src = gw_src; @@ -334,18 +353,18 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p first_gw = gw_dst; if (p_hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id - && strcmp(gw_dst->p_name, prev_gw_src->p_name)) { + && strcmp(gw_dst->getName(), prev_gw_src->getName())) { xbt_dynar_t e_route_as_to_as=NULL; routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL); if (edge == NULL) - THROWF(arg_error,0,"No route from '%s' to '%s'", src->p_name, dst->p_name); + THROWF(arg_error,0,"No route from '%s' to '%s'", src->getName(), dst->getName()); links = e_route_as_to_as; int pos = 0; xbt_dynar_foreach(links, cpt, link) { xbt_dynar_insert_at(route->link_list, pos, &link); if (lat) - *lat += link->getLatency(); + *lat += static_cast(link)->getLatency(); pos++; } } @@ -354,7 +373,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p xbt_dynar_foreach(links, cpt, link) { xbt_dynar_unshift(route->link_list, &link); if (lat) - *lat += link->getLatency(); + *lat += static_cast(link)->getLatency(); } size++; } @@ -379,8 +398,8 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p AsDijkstra::~AsDijkstra() { - xbt_graph_free_graph(p_routeGraph, &xbt_free, - &graph_edge_data_free, &xbt_free); + xbt_graph_free_graph(p_routeGraph, &xbt_free_f, + &graph_edge_data_free, &xbt_free_f); xbt_dict_free(&p_graphNodeMap); if (m_cached) xbt_dict_free(&p_routeCache); @@ -388,10 +407,17 @@ AsDijkstra::~AsDijkstra() /* Creation routing model functions */ -AsDijkstra::AsDijkstra() : AsGeneric(), m_cached(0) {} +AsDijkstra::AsDijkstra() : AsGeneric(), m_cached(0) { + p_routeGraph = NULL; + p_graphNodeMap = NULL; + p_routeCache = NULL; +} AsDijkstra::AsDijkstra(int cached) : AsGeneric(), m_cached(cached) { + p_routeGraph = NULL; + p_graphNodeMap = NULL; + p_routeCache = NULL; /*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_and_latency = dijkstra_get_route_and_latency; @@ -414,7 +440,7 @@ void AsDijkstra::end() if(!p_graphNodeMap) p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free); - if (m_cached && p_routeCache) + if (m_cached && !p_routeCache) p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free); /* Add the loopback if needed */ @@ -430,6 +456,12 @@ void AsDijkstra::end() } } + +void AsDijkstra::parseASroute(sg_platf_route_cbarg_t route) +{ + parseRoute(route); +} + void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route) { char *src = (char*)(route->src); @@ -440,12 +472,12 @@ void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route) XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst); else{ XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src, - route->gw_src->p_name, dst, route->gw_dst->p_name); + route->gw_src->getName(), dst, route->gw_dst->getName()); as_route = 1; - if(route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The gw_dst '%s' does not exist!",route->gw_dst->p_name); - if(route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The gw_src '%s' does not exist!",route->gw_src->p_name); + if(route->gw_dst->getRcType() == SURF_NETWORK_ELEMENT_NULL) + surf_parse_error("The gw_dst '%s' does not exist!",route->gw_dst->getName()); + if(route->gw_src->getRcType() == SURF_NETWORK_ELEMENT_NULL) + surf_parse_error("The gw_src '%s' does not exist!",route->gw_src->getName()); } RoutingEdgePtr src_net_elm, dst_net_elm; @@ -466,7 +498,7 @@ void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route) p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free); sg_platf_route_cbarg_t e_route = newExtendedRoute(p_hierarchy, route, 1); - newRoute(src_net_elm->m_id, dst_net_elm->m_id, e_route); + newRoute(src_net_elm->getId(), dst_net_elm->getId(), e_route); // Symmetrical YES if ( (route->symmetrical == TRUE && as_route == 0) @@ -477,11 +509,11 @@ void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route) XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src); else XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst, - route->gw_dst->p_name, src, route->gw_src->p_name); + route->gw_dst->getName(), src, route->gw_src->getName()); xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph); - xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->m_id, xbt_node_t); - xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->m_id, xbt_node_t); + xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->getId(), xbt_node_t); + xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->getId(), xbt_node_t); xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_e_v, node_s_v); @@ -495,7 +527,7 @@ void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route) route->gw_dst = gw_tmp; } sg_platf_route_cbarg_t link_route_back = newExtendedRoute(p_hierarchy, route, 0); - newRoute(dst_net_elm->m_id, src_net_elm->m_id, link_route_back); + newRoute(dst_net_elm->getId(), src_net_elm->getId(), link_route_back); } xbt_dynar_free(&route->link_list); }