Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add two new tag for routing cluster (only):
[simgrid.git] / src / surf / surf_routing_cluster.c
index 08416a8..09b74f2 100644 (file)
@@ -6,93 +6,73 @@
 #include "surf_routing_private.h"
 
 /* Global vars */
-extern routing_global_t global_routing;
-extern routing_component_t current_routing;
-extern model_type_t current_routing_model;
-extern xbt_dynar_t link_list;
-extern xbt_dict_t cluster_host_link;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
 
-/* Routing model structure */
-
-typedef struct {
-  s_routing_component_t generic_routing;
-  xbt_dict_t dict_processing_units;
-  xbt_dict_t dict_autonomous_systems;
-} s_routing_component_cluster_t, *routing_component_cluster_t;
-
-/* Parse routing model functions */
-
-static route_extended_t cluster_get_route(routing_component_t rc,
-                                            const char *src,
-                                            const char *dst);
+/* 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.
+ */
 
 /* Business methods */
-static route_extended_t cluster_get_route(routing_component_t rc,
-                                            const char *src,
-                                            const char *dst)
-{
-         xbt_assert(rc && src
-                     && dst,
-                     "Invalid params for \"get_route\" function at AS \"%s\"",
-                     rc->name);
-
-
-         xbt_dynar_t links_list =
-             xbt_dynar_new(global_routing->size_of_link, NULL);
-
-         char *cluster_is_fd = xbt_dict_get_or_null(cluster_host_link,rc->name);
-         char *link_src,*link_bb,*link_dst,*link_src_up,*link_dst_down;
-
-         if(!cluster_is_fd){ //        NOT FULLDUPLEX
-                 link_src = xbt_dict_get_or_null(cluster_host_link,src);
-                 if( !link_src && (global_routing->get_network_element_type(src) != SURF_NETWORK_ELEMENT_ROUTER) )
-                         xbt_die("No link for '%s' found!",src);
-                 if(link_src) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_src, SURF_LINK_LEVEL)); //link_up
-
-                 link_bb = bprintf("%s_backbone",rc->name);
-                 xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_bb, SURF_LINK_LEVEL)); //link_bb
-                 free(link_bb);
-
-                 link_dst = xbt_dict_get_or_null(cluster_host_link,dst);
-                 if( !link_dst && (global_routing->get_network_element_type(dst) != SURF_NETWORK_ELEMENT_ROUTER) )
-                         xbt_die("No link for '%s' found!",dst);
-                 if(link_dst) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_dst, SURF_LINK_LEVEL)); //link_down
-         }
-         else //       FULLDUPLEX
-         {
-                 link_src = xbt_dict_get_or_null(cluster_host_link,src);
-                 if( !link_src  && (global_routing->get_network_element_type(src) != SURF_NETWORK_ELEMENT_ROUTER) )
-                         xbt_die("No link for '%s' found!",src);
-                 link_src_up = bprintf("%s_UP",link_src);
-                 if(link_src) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_src_up, SURF_LINK_LEVEL)); //link_up
-                 free(link_src_up);
-
-                 link_bb = bprintf("%s_backbone",rc->name);
-                 if(link_bb)  xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_bb, SURF_LINK_LEVEL)); //link_bb
-                 free(link_bb);
+static void cluster_get_route_and_latency(AS_t as,
+    sg_routing_edge_t src, sg_routing_edge_t dst,
+                                          route_t route, double *lat) {
+
+      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);
+        }
+    }
+}
 
-                 link_dst = xbt_dict_get_or_null(cluster_host_link,dst);
-                 if(!link_dst  && (global_routing->get_network_element_type(dst) != SURF_NETWORK_ELEMENT_ROUTER))
-                         xbt_die("No link for '%s' found!",dst);
-                 link_dst_down = bprintf("%s_DOWN",link_dst);
-                 if(link_dst) xbt_dynar_push_as(links_list,void*,xbt_lib_get_or_null(link_lib, link_dst_down, SURF_LINK_LEVEL)); //link_down
-                 free(link_dst_down);
-         }
+static void model_cluster_finalize(AS_t as) {
+  xbt_dynar_free(&(as->link_up_down_list));
+  model_none_finalize(as);
+}
 
-         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 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;
+}
 
-         return new_e_route;
+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 */
-void *model_cluster_create(void)
+AS_t model_cluster_create(void)
 {
-  routing_component_cluster_t new_component = model_rulebased_create();
-  new_component->generic_routing.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->parse_AS = cluster_parse_AS;
+  result->parse_PU = cluster_parse_PU;
 
-  return new_component;
+  return (AS_t) result;
 }