Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix warnings about comparisons of integers of different types.
[simgrid.git] / src / surf / surf_routing_dijkstra.cpp
index 70c084f..417e3c9 100644 (file)
@@ -1,11 +1,10 @@
-/* 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"
 
 /* Global vars */
@@ -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<AsDijkstraPtr>(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<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(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<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(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<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
     }
     size++;
   }
@@ -430,6 +451,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);