Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
you have to plug the memleaks from time to time
[simgrid.git] / src / surf / surf_routing_dijkstra.c
index 0c6c78c..4e51e93 100644 (file)
@@ -8,8 +8,6 @@
 
 /* Global vars */
 extern routing_global_t global_routing;
-extern AS_t current_routing;
-extern routing_model_description_t current_routing_model;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf -- dijkstra routing logic");
 
@@ -376,7 +374,7 @@ static route_extended_t dijkstra_get_route(AS_t asg,
     if (asg->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
         && strcmp(gw_dst, prev_gw_src)) {
       xbt_dynar_t e_route_as_to_as =
-          (*(global_routing->get_route)) (gw_dst, prev_gw_src);
+          routing_get_route(gw_dst, prev_gw_src);
       xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
                   gw_dst, prev_gw_src);
       links = e_route_as_to_as;
@@ -419,19 +417,13 @@ static void dijkstra_finalize(AS_t asg)
 {
   as_dijkstra_t as = (as_dijkstra_t) asg;
 
-  if (as) {
-    xbt_graph_free_graph(as->route_graph, &xbt_free,
-                         &graph_edge_data_free, &xbt_free);
-    xbt_dict_free(&as->graph_node_map);
-    if (as->cached)
-      xbt_dict_free(&as->route_cache);
-    /* Delete bypass dict */
-    xbt_dict_free(&as->generic_routing.bypassRoutes);
-    /* Delete index dict */
-    xbt_dict_free(&(as->generic_routing.to_index));
-    /* Delete structure */
-    xbt_free(as);
-  }
+  xbt_graph_free_graph(as->route_graph, &xbt_free,
+      &graph_edge_data_free, &xbt_free);
+  xbt_dict_free(&as->graph_node_map);
+  if (as->cached)
+    xbt_dict_free(&as->route_cache);
+
+  model_generic_finalize(asg);
 }
 
 /* Creation routing model functions */
@@ -439,7 +431,7 @@ static void dijkstra_finalize(AS_t asg)
 AS_t model_dijkstra_both_create(int cached)
 {
   as_dijkstra_t new_component = (as_dijkstra_t)
-      routmod_generic_create(sizeof(s_as_dijkstra_t));
+      model_generic_create_sized(sizeof(s_as_dijkstra_t));
 
   new_component->generic_routing.parse_route = model_dijkstra_both_parse_route;
   new_component->generic_routing.parse_ASroute = model_dijkstra_both_parse_route;
@@ -462,30 +454,29 @@ AS_t model_dijkstracache_create(void)
   return model_dijkstra_both_create(1);
 }
 
-void model_dijkstra_both_end(void)
+void model_dijkstra_both_end(AS_t as)
 {
-  as_dijkstra_t routing =
-      (as_dijkstra_t) current_routing;
+  as_dijkstra_t THIS = (as_dijkstra_t) as;
 
   xbt_node_t node = NULL;
   unsigned int cursor2;
   xbt_dynar_t nodes = NULL;
 
   /* Create the topology graph */
-  if(!routing->route_graph)
-  routing->route_graph = xbt_graph_new_graph(1, NULL);
-  if(!routing->graph_node_map)
-  routing->graph_node_map = xbt_dict_new();
+  if(!THIS->route_graph)
+  THIS->route_graph = xbt_graph_new_graph(1, NULL);
+  if(!THIS->graph_node_map)
+  THIS->graph_node_map = xbt_dict_new();
 
-  if (routing->cached && !routing->route_cache)
-  routing->route_cache = xbt_dict_new();
+  if (THIS->cached && !THIS->route_cache)
+  THIS->route_cache = xbt_dict_new();
 
   /* Add the loopback if needed */
-  if (current_routing->hierarchy == SURF_ROUTING_BASE)
-    add_loopback_dijkstra(routing);
+  if (as->hierarchy == SURF_ROUTING_BASE)
+    add_loopback_dijkstra(THIS);
 
   /* initialize graph indexes in nodes after graph has been built */
-  nodes = xbt_graph_get_nodes(routing->route_graph);
+  nodes = xbt_graph_get_nodes(THIS->route_graph);
 
   xbt_dynar_foreach(nodes, cursor2, node) {
     graph_node_data_t data = xbt_graph_node_get_data(node);
@@ -522,13 +513,13 @@ void model_dijkstra_both_parse_route (AS_t asg, const char *src,
        else{
          XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
                         route->src_gateway, dst, route->dst_gateway);
-         if(global_routing->get_network_element_type((const char*)route->dst_gateway) == SURF_NETWORK_ELEMENT_NULL)
+         if(routing_get_network_element_type((const char*)route->dst_gateway) == SURF_NETWORK_ELEMENT_NULL)
                  xbt_die("The dst_gateway '%s' does not exist!",route->dst_gateway);
-         if(global_routing->get_network_element_type((const char*)route->src_gateway) == SURF_NETWORK_ELEMENT_NULL)
+         if(routing_get_network_element_type((const char*)route->src_gateway) == SURF_NETWORK_ELEMENT_NULL)
                  xbt_die("The src_gateway '%s' does not exist!",route->src_gateway);
        }
 
        route_extended_t e_route =
-               generic_new_extended_route(current_routing->hierarchy, route, 1);
+               generic_new_extended_route(asg->hierarchy, route, 1);
        route_new_dijkstra(as, *src_id, *dst_id, e_route);
 }