Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initialize another bunch of variables.
[simgrid.git] / src / surf / surf_routing_dijkstra.cpp
index da697be..f5f7206 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);
       }
     }
@@ -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);