Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add handling of the torus topology inside clusters
[simgrid.git] / src / surf / surf_routing_cluster.cpp
index 0e7a67a..93503a1 100644 (file)
@@ -1,14 +1,12 @@
-/* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
+/* Copyright (c) 2009, 2010, 2011, 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_cluster.hpp"
-#include "surf_routing_private.h"
 
-extern "C" {
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
-}
 
 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
  * Note that a router is created, easing the interconnexion with the rest of the world.
@@ -22,6 +20,12 @@ AS_t model_cluster_create(void)
 /* Creation routing model functions */
 AsCluster::AsCluster() : AsNone()
 {
+  p_backbone = 0;
+  p_loopback = 0;
+  p_router = 0;
+  p_dimensions = NULL;
+  p_has_limiter = 0;
+  p_has_loopback = 0;
 }
 
 /* Business methods */
@@ -31,45 +35,53 @@ void AsCluster::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_pl
   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
             src->p_name, src->m_id, dst->p_name, dst->m_id);
 
+  //retrieve the number of links we stored for each node
+  int nb_links_per_node = p_has_loopback + p_has_limiter +
+      (p_dimensions ? xbt_dynar_length(p_dimensions) : 1);
+
   if (src->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
-    info = xbt_dynar_get_as(p_linkUpDownList, src->m_id, s_surf_parsing_link_up_down_t);
 
-    if((src->m_id == dst->m_id) && info.loopback_link  ){
-      xbt_dynar_push_as(route->link_list, void *, info.loopback_link);
+    if((src->m_id == dst->m_id) && p_has_loopback  ){
+      info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node, s_surf_parsing_link_up_down_t);
+      xbt_dynar_push_as(route->link_list, void *, info.link_up);
       if (lat)
-        *lat += static_cast<NetworkCm02LinkPtr>(info.loopback_link)->getLatency();
+        *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
       return;
     }
 
 
-    if (info.limiter_link)          // limiter for sender
-      xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
+    if (p_has_limiter){          // limiter for sender
+      info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
+      xbt_dynar_push_as(route->link_list, void *, info.link_up);
+    }
 
+    info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
     if (info.link_up) {         // link up
       xbt_dynar_push_as(route->link_list, void *, info.link_up);
       if (lat)
-        *lat += static_cast<NetworkCm02LinkPtr>(info.link_up)->getLatency();
+        *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
     }
+
   }
 
   if (p_backbone) {
-    xbt_dynar_push_as(route->link_list, void *, p_backbone);
+    xbt_dynar_push_as(route->link_list, void *, static_cast<ResourcePtr>(p_backbone));
     if (lat)
-      *lat += static_cast<NetworkCm02LinkPtr>(p_backbone)->getLatency();
+      *lat += p_backbone->getLatency();
   }
 
   if (dst->p_rcType != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
-    info =
-        xbt_dynar_get_as(p_linkUpDownList, dst->m_id, s_surf_parsing_link_up_down_t);
+    info = xbt_dynar_get_as(p_linkUpDownList, dst->m_id * nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
+
     if (info.link_down) {       // link down
       xbt_dynar_push_as(route->link_list, void *, info.link_down);
       if (lat)
-        *lat += static_cast<NetworkCm02LinkPtr>(info.link_down)->getLatency();
+        *lat += static_cast<NetworkLinkPtr>(info.link_down)->getLatency();
+    }
+    if (p_has_limiter){          // limiter for receiver
+        info = xbt_dynar_get_as(p_linkUpDownList, dst->m_id * nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
+        xbt_dynar_push_as(route->link_list, void *, info.link_up);
     }
-
-    if (info.limiter_link)          // limiter for receiver
-      xbt_dynar_push_as(route->link_list, void *, info.limiter_link);
-
   }
 }
 
@@ -89,7 +101,7 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
   routerNode = new_xbt_graph_node(graph, link_name, nodes);
 
   if(p_backbone) {
-    const char *link_nameR = p_backbone->m_name;
+    const char *link_nameR = p_backbone->getName();
     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
 
     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
@@ -105,7 +117,7 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
 
       if (info.link_up) {     // link up
 
-        const char *link_name = ((ResourcePtr) info.link_up)->m_name;
+        const char *link_name = static_cast<ResourcePtr>(info.link_up)->getName();
         current = new_xbt_graph_node(graph, link_name, nodes);
         new_xbt_graph_edge(graph, previous, current, edges);
 
@@ -118,7 +130,7 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
       }
 
       if (info.link_down) {    // link down
-        const char *link_name = ((ResourcePtr) info.link_down)->m_name;
+        const char *link_name = static_cast<ResourcePtr>(info.link_down)->getName();
         current = new_xbt_graph_node(graph, link_name, nodes);
         new_xbt_graph_edge(graph, previous, current, edges);