Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function get_route_or_null that catches any exception before returning
[simgrid.git] / src / surf / surf_routing.c
index 2f2c375..8794bbc 100644 (file)
@@ -809,6 +809,26 @@ static xbt_dynar_t get_route(const char *src, const char *dst)
   return route;
 }
 
+/**
+ * \brief Generic method: find a route between hosts
+ *
+ * \param src the source host name
+ * \param dst the destination host name
+ *
+ * same as get_route, but return NULL if any exception is raised.
+ */
+static xbt_dynar_t get_route_or_null(const char *src, const char *dst)
+{
+  xbt_dynar_t route = NULL;
+  xbt_ex_t exception;
+  TRY {
+    get_route_latency(src, dst, &route, NULL, 1);
+  }CATCH(exception) {
+    return NULL;
+  }
+  return route;
+}
+
 /**
  * \brief Generic method: find a route between hosts
  *
@@ -935,6 +955,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_
   global_routing = xbt_new0(s_routing_global_t, 1);
   global_routing->root = NULL;
   global_routing->get_route = get_route;
+  global_routing->get_route_or_null = get_route_or_null;
   global_routing->get_latency = get_latency;
   global_routing->get_route_no_cleanup = get_route_no_cleanup;
   global_routing->get_onelink_routes = get_onelink_routes;
@@ -1507,7 +1528,7 @@ void routing_parse_Scluster(void)
   char *cluster_availability_file = A_surfxml_cluster_availability_file;
   char *cluster_state_file = A_surfxml_cluster_state_file;
   char *host_id, *groups, *link_id = NULL;
-  char *router_id;
+  char *router_id = xbt_strdup(A_surfxml_cluster_router_id);
   char *availability_file = xbt_strdup(cluster_availability_file);
   char *state_file = xbt_strdup(cluster_state_file);
 
@@ -1686,9 +1707,8 @@ void routing_parse_Scluster(void)
   xbt_dynar_free(&radical_elements);
 
   XBT_DEBUG(" ");
-  router_id =
-      bprintf("%s%s_router%s", cluster_prefix, cluster_id,
-              cluster_suffix);
+  if(!strcmp(router_id,""))
+         router_id = bprintf("%s%s_router%s", cluster_prefix, cluster_id, cluster_suffix);
 
   XBT_DEBUG("<router id=\"%s\"/>", router_id);
   SURFXML_BUFFER_SET(router_id, router_id);