Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reindent.
[simgrid.git] / src / surf / surf_routing_cluster.c
index 2ea9e51..2154448 100644 (file)
@@ -4,9 +4,9 @@
 /* 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_private.h"
+#include "xbt/graph.h"
 
 /* Global vars */
-extern routing_global_t global_routing;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
 
@@ -14,50 +14,239 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
  * Note that a router is created, easing the interconnexion with the rest of the world.
  */
 
-static xbt_dict_t cluster_host_link = NULL;
-
 /* Business methods */
-static route_extended_t cluster_get_route(AS_t as,
-                                          const char *src,
-                                          const char *dst) {
-
-         xbt_dynar_t links_list = xbt_dynar_new(global_routing->size_of_link, NULL);
-
-         surf_parsing_link_up_down_t info;
-
-         info = xbt_dict_get_or_null(cluster_host_link,src);
-         if(info) xbt_dynar_push_as(links_list,void*,info->link_up); //link_up
+static void cluster_get_route_and_latency(AS_t as,
+                                          sg_routing_edge_t src,
+                                          sg_routing_edge_t dst,
+                                          sg_platf_route_cbarg_t route,
+                                          double *lat)
+{
 
-         info = xbt_dict_get_or_null(cluster_host_link,as->name);
-         if(info)  xbt_dynar_push_as(links_list,void*,info->link_up); //link_bb
+  s_surf_parsing_link_up_down_t info;
+  XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
+            src->name, src->id, dst->name, dst->id);
+
+  if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
+    info =
+        xbt_dynar_get_as(as->link_up_down_list, src->id,
+                         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 +=
+            surf_network_model->extension.network.get_link_latency(info.
+                                                                   link_up);
+    }
+  }
+
+  if (((as_cluster_t) as)->backbone) {
+    xbt_dynar_push_as(route->link_list, void *, ((as_cluster_t) as)->backbone);
+    if (lat)
+      *lat +=
+          surf_network_model->extension.network.
+          get_link_latency(((as_cluster_t) as)->backbone);
+  }
+
+  if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
+    info =
+        xbt_dynar_get_as(as->link_up_down_list, dst->id,
+                         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 +=
+            surf_network_model->extension.network.get_link_latency(info.
+                                                                   link_down);
+    }
+  }
+}
 
-         info = xbt_dict_get_or_null(cluster_host_link,dst);
-         if(info) xbt_dynar_push_as(links_list,void*,info->link_down); //link_down
+static void cluster_get_graph(xbt_graph_t graph, xbt_dict_t nodes,
+                              xbt_dict_t edges, AS_t rc)
+{
+  int isrc;
+  int table_size = xbt_dynar_length(rc->index_network_elm);
+
+  sg_routing_edge_t src;
+  xbt_node_t current, previous, backboneNode,routerNode;
+  s_surf_parsing_link_up_down_t info;
+
+  xbt_assert(((as_cluster_t) rc)->router,"Malformed cluster");
+
+  /* create the router */
+  char *link_name =
+    ((sg_routing_edge_t) ((as_cluster_t) rc)->router)->name;
+  routerNode = new_xbt_graph_node(graph, link_name, nodes);
+
+  if(((as_cluster_t) rc)->backbone) {
+    char *link_nameR =
+      ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
+    backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
+
+    new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
+  }
+
+  for (isrc = 0; isrc < table_size; isrc++) {
+    src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
+
+    if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {
+      previous = new_xbt_graph_node(graph, src->name, nodes);
+
+      info = xbt_dynar_get_as(rc->link_up_down_list, src->id,
+                              s_surf_parsing_link_up_down_t);
+
+      if (info.link_up) {     // link up
+
+        char *link_name = ((surf_resource_t) info.link_up)->name;
+        current = new_xbt_graph_node(graph, link_name, nodes);
+        new_xbt_graph_edge(graph, previous, current, edges);
+
+        if (((as_cluster_t) rc)->backbone) {
+          new_xbt_graph_edge(graph, current, backboneNode, edges);
+        } else {
+          new_xbt_graph_edge(graph, current, routerNode, edges);
+        }
+
+      }
+
+      if (info.link_down) {    // link down
+        char *link_name = ((surf_resource_t) info.link_down)->name;
+        current = new_xbt_graph_node(graph, link_name, nodes);
+        new_xbt_graph_edge(graph, previous, current, edges);
+
+        if (((as_cluster_t) rc)->backbone) {
+          new_xbt_graph_edge(graph, current, backboneNode, edges);
+        } else {
+          new_xbt_graph_edge(graph, current, routerNode, edges);
+        }
+
+      }
+/*
+      if (((as_cluster_t) rc)->backbone) {
+        char *link_name =
+          ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
+
+        current = new_xbt_graph_node(graph, link_name, nodes);
+        new_xbt_graph_edge(graph, previous, current, edges);
+        previous = current;
+
+        revCurrent = new_xbt_graph_node(graph, link_name, nodes);
+        new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
+        revPrevious = revCurrent;
+      } else {
+        info = xbt_dynar_get_as(rc->link_up_down_list, dst->id,
+                                s_surf_parsing_link_up_down_t);
+
+        if (info.link_up) {     // link up
+          char *link_name = ((surf_resource_t) info.link_up)->name;
+          current = new_xbt_graph_node(graph, link_name, nodes);
+          new_xbt_graph_edge(graph, previous, current, edges);
+          previous = current;
+        } else if (info.link_down) {    // link down
+          char *link_name = ((surf_resource_t) info.link_down)->name;
+          revCurrent = new_xbt_graph_node(graph, link_name, nodes);
+          new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
+          revPrevious = revCurrent;
+        }
+      }
+*/
+    }
+  }
+/*
+  if(rc->)
+    for (isrc = 0; isrc < table_size; isrc++) {
+      src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t);
+
+      previous = new_xbt_graph_node(graph, src->name, nodes);
+      revPrevious = new_xbt_graph_node(graph, src->name, nodes);
+
+      for (idst = isrc + 1; idst < table_size; idst++) {
+        dst = xbt_dynar_get_as(rc->index_network_elm, idst, sg_routing_edge_t);
+
+        s_surf_parsing_link_up_down_t info;
+
+        if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {        // No specific link for router
+          info =
+            xbt_dynar_get_as(rc->link_up_down_list, src->id,
+                             s_surf_parsing_link_up_down_t);
+
+          if (info.link_up) {     // link up
+            char *link_name = ((surf_resource_t) info.link_up)->name;
+            current = new_xbt_graph_node(graph, link_name, nodes);
+            new_xbt_graph_edge(graph, previous, current, edges);
+            previous = current;
+          } else if (info.link_down) {    // link down
+            char *link_name = ((surf_resource_t) info.link_down)->name;
+            revCurrent = new_xbt_graph_node(graph, link_name, nodes);
+            new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
+            revPrevious = revCurrent;
+          }
+        }
+
+
+
+        if (((as_cluster_t) rc)->backbone) {
+          char *link_name =
+            ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name;
+
+          current = new_xbt_graph_node(graph, link_name, nodes);
+          new_xbt_graph_edge(graph, previous, current, edges);
+          previous = current;
+
+          revCurrent = new_xbt_graph_node(graph, link_name, nodes);
+          new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
+          revPrevious = revCurrent;
+        }
+
+        if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) {        // No specific link for router
+          info =
+            xbt_dynar_get_as(rc->link_up_down_list, dst->id,
+                             s_surf_parsing_link_up_down_t);
+
+          if (info.link_up) {     // link up
+            char *link_name = ((surf_resource_t) info.link_up)->name;
+            current = new_xbt_graph_node(graph, link_name, nodes);
+            new_xbt_graph_edge(graph, previous, current, edges);
+            previous = current;
+          } else if (info.link_down) {    // link down
+            char *link_name = ((surf_resource_t) info.link_down)->name;
+            revCurrent = new_xbt_graph_node(graph, link_name, nodes);
+            new_xbt_graph_edge(graph, revCurrent, revPrevious, edges);
+            revPrevious = revCurrent;
+          }
+        }
+
+      }
+    }
+*/
+}
 
-         route_extended_t new_e_route = NULL;
-         new_e_route = xbt_new0(s_route_extended_t, 1);
-         new_e_route->generic_route.link_list = links_list;
+static void model_cluster_finalize(AS_t as)
+{
+  model_none_finalize(as);
+}
 
-         return new_e_route;
+static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
+  XBT_DEBUG("Load process unit \"%s\"", elm->name);
+  xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
+  return xbt_dynar_length(rc->index_network_elm)-1;
 }
 
-static void model_cluster_finalize(AS_t as) {
-  xbt_dict_free(&cluster_host_link);
-  model_none_finalize(as);
+static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
+  XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
+  xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
+  return xbt_dynar_length(rc->index_network_elm)-1;
 }
+
 /* Creation routing model functions */
 AS_t model_cluster_create(void)
 {
-  AS_t result = model_none_create();
-  result->get_route = cluster_get_route;
+  AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
+  result->get_route_and_latency = cluster_get_route_and_latency;
   result->finalize = model_cluster_finalize;
+  result->get_graph = cluster_get_graph;
+  result->parse_AS = cluster_parse_AS;
+  result->parse_PU = cluster_parse_PU;
 
   return (AS_t) result;
 }
-
-void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info) {
-  if(!cluster_host_link)
-    cluster_host_link = xbt_dict_new();
-
- xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
-}