X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5faf49cdf3f8ad8751317b857a6d3134fe07eda3..efbbd7433e0f1dc72d63f821fbbcaf12962469c8:/src/surf/surf_routing_dijkstra.cpp diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index 70c084f8c5..9cececcbce 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -1,12 +1,11 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. +/* Copyright (c) 2009-2013. 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; @@ -15,19 +14,6 @@ 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 */ static void route_cache_elem_free(void *e) @@ -54,6 +40,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) @@ -161,7 +184,7 @@ xbt_dynar_t AsDijkstra::getOnelinkRoutes() 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 +194,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); } } @@ -207,7 +228,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); @@ -237,7 +258,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 += dynamic_cast(static_cast(link))->getLatency(); } } @@ -345,7 +366,7 @@ void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_p xbt_dynar_foreach(links, cpt, link) { xbt_dynar_insert_at(route->link_list, pos, &link); if (lat) - *lat += link->getLatency(); + *lat += dynamic_cast(static_cast(link))->getLatency(); pos++; } } @@ -354,7 +375,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 += dynamic_cast(static_cast(link))->getLatency(); } size++; } @@ -388,10 +409,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 +442,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 +458,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);