Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix bug when call function get_route.
[simgrid.git] / src / surf / surf_routing.c
index a0b74ee..9f198f2 100644 (file)
@@ -56,13 +56,20 @@ static void  model_none_end(void);    /* none routing model */
 
 static void routing_full_parse_Scluster(void);/*cluster bypass*/
 
-/* this lines are olny for replace use like index in the model table */
-#define SURF_MODEL_FULL           0
-#define SURF_MODEL_FLOYD          1
-#define SURF_MODEL_DIJKSTRA       2
-#define SURF_MODEL_DIJKSTRACACHE  3
-#define SURF_MODEL_RULEBASED      4
-#define SURF_MODEL_NONE           5
+static void parse_Sconfig(void);/*config Tag*/
+
+/* this lines are only for replace use like index in the model table */
+typedef enum {
+       SURF_MODEL_FULL=0,
+       SURF_MODEL_FLOYD,
+       SURF_MODEL_DIJKSTRA,
+       SURF_MODEL_DIJKSTRACACHE,
+       SURF_MODEL_NONE,
+#ifdef HAVE_PCRE_LIB
+       SURF_MODEL_RULEBASED
+#endif
+} e_routing_types;
+
 
 /* must be finish with null and carefull if change de order */
 struct s_model_type routing_models[] =
@@ -74,10 +81,11 @@ struct s_model_type routing_models[] =
   model_dijkstra_create ,model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
   {"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
   model_dijkstracache_create, model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
-  {"RuleBased", "Rule-Based routing data (...)",
-  model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end },
   {"none", "No routing (usable with Constant network only)",
   model_none_create, model_none_load, model_none_unload, model_none_end },
+#ifdef HAVE_PCRE_LIB
+  {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end },
+#endif
   {NULL,NULL,NULL,NULL,NULL,NULL}};
 
 /* ************************************************************************** */
@@ -93,7 +101,6 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
 
 static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc);
-static int generic_is_router (const char *name);
 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst);
 
 /* ************************************************************************** */
@@ -120,13 +127,17 @@ static xbt_dynar_t link_list = NULL; /* temporary store of current list link of
  * \brief Add a "host" to the network element list
  */
 static void  parse_S_host(char* host_id) {
-  if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
+       network_element_info_t info = NULL;
+       if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,host_id),
       "Reading a host, processing unit \"%s\" already exist",host_id);
   xbt_assert1(current_routing->set_processing_unit,
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
   (*(current_routing->set_processing_unit))(current_routing,host_id);
-  xbt_dict_set(global_routing->where_network_elements,host_id,(void*)current_routing,NULL);
+  info = xbt_new0(s_network_element_info_t,1);
+  info->rc_component=current_routing;
+  info->rc_type=SURF_NETWORK_ELEMENT_HOST;
+  xbt_dict_set(global_routing->where_network_elements,host_id,(void*)info,NULL);
 }
 
 /*
@@ -152,13 +163,18 @@ static void parse_S_host_lua(char *host_id)
  * \brief Add a "router" to the network element list
  */
 static void parse_S_router(void) {
+  network_element_info_t info = NULL;
+
   if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_router_id),
       "Reading a router, processing unit \"%s\" already exist",A_surfxml_router_id);
   xbt_assert1(current_routing->set_processing_unit,
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
   (*(current_routing->set_processing_unit))(current_routing,A_surfxml_router_id);
-  xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)current_routing,NULL); 
+  info = xbt_new0(s_network_element_info_t,1);
+  info->rc_component=current_routing;
+  info->rc_type=SURF_NETWORK_ELEMENT_ROUTER;
+  xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)info,NULL);
   #ifdef HAVE_TRACING
     TRACE_surf_host_declaration (A_surfxml_router_id, 0);
   #endif
@@ -344,7 +360,7 @@ static void parse_S_AS(char* AS_id,char* AS_routing) {
     new_routing->routing_father = NULL;
     global_routing->root = new_routing;
     
-  } else if( current_routing != NULL && global_routing->root != NULL ) { 
+  } else if( current_routing != NULL && global_routing->root != NULL ) {
     
     xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,AS_id),
            "The AS \"%s\" already exist",AS_id);
@@ -396,9 +412,13 @@ static void parse_E_AS(char *AS_id) {
   if( current_routing == NULL ) {
     THROW1(arg_error,0,"Close AS(%s), that never open",AS_id);
   } else {
+         network_element_info_t info = NULL;
       xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,current_routing->name),
           "The AS \"%s\" already exist",current_routing->name);
-      xbt_dict_set(global_routing->where_network_elements,current_routing->name,current_routing->routing_father,NULL);
+      info = xbt_new0(s_network_element_info_t,1);
+      info->rc_component=current_routing->routing_father;
+      info->rc_type=SURF_NETWORK_ELEMENT_AS;
+      xbt_dict_set(global_routing->where_network_elements,current_routing->name,info,NULL);
       (*(current_routing->routing->unload))();
       (*(current_routing->routing->end))();
       current_routing = current_routing->routing_father;
@@ -450,8 +470,8 @@ static xbt_dynar_t elements_father(const char* src,const char* dst) {
   routing_component_t* father = NULL;
   
   /* (1) find the as where the src and dst are located */
-  src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
-  dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst); 
+  src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component;
+  dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component;
   xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst);
   
   /* (2) find the path to the root routing component */
@@ -696,7 +716,7 @@ static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc)
   xbt_dict_cursor_t cursor=NULL;
   routing_component_t rc_child;
   xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
-    xbt_dynar_t onelink_child = recursive_get_onelink_routes (rc_child);//->get_onelink_routes (rc_child);
+    xbt_dynar_t onelink_child = recursive_get_onelink_routes (rc_child);
     if (onelink_child){
       xbt_dynar_foreach(onelink_child, cpt, link) {
         xbt_dynar_push(ret,&link);
@@ -711,9 +731,11 @@ static xbt_dynar_t get_onelink_routes(void)
   return recursive_get_onelink_routes (global_routing->root);
 }
 
-static int is_router(const char *name)
+static e_surf_network_element_type_t get_network_element_type(const char *name)
 {
-       xbt_die("global \"is_router\" function not implemented yet");
+       network_element_info_t rc=NULL;
+       rc = xbt_dict_get(global_routing->where_network_elements,name);
+       return rc->rc_type;
 }
 
 /**
@@ -729,7 +751,7 @@ void routing_model_create(size_t size_of_links, void* loopback) {
   global_routing->root = NULL;
   global_routing->get_route = get_route;
   global_routing->get_onelink_routes = get_onelink_routes;
-  global_routing->is_router = is_router;
+  global_routing->get_network_element_type = get_network_element_type;
   global_routing->finalize = finalize;
   global_routing->loopback = loopback;
   global_routing->size_of_link = size_of_links;
@@ -757,6 +779,7 @@ void routing_model_create(size_t size_of_links, void* loopback) {
 
   surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
 
+  surfxml_add_callback(STag_surfxml_config_cb_list, &parse_Sconfig);
 }
 
 /* ************************************************************************** */
@@ -805,11 +828,6 @@ static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
   return ret;
 }
 
-static int full_is_router(const char *name)
-{
-  xbt_die("\"full_is_router\" function not implemented yet");
-}
-
 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
   
@@ -871,7 +889,6 @@ static void* model_full_create(void) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = full_get_route;
   new_component->generic_routing.get_onelink_routes = full_get_onelink_routes;
-  new_component->generic_routing.is_router = full_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = full_finalize;
   new_component->to_index = xbt_dict_new();
@@ -969,15 +986,33 @@ typedef struct {
   xbt_dict_t parse_routes; 
 } s_routing_component_floyd_t,*routing_component_floyd_t;
 
+static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst);
+
 /* Business methods */
 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
 {
-  xbt_die("\"floyd_get_onelink_routes\" function not implemented yet");
-}
+  xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
 
-static int floyd_is_router(const char *name)
-{
-  xbt_die("\"floyd_is_router\" function not implemented yet");
+  routing_component_floyd_t routing = (routing_component_floyd_t)rc;
+  //int table_size = xbt_dict_length(routing->to_index);
+  xbt_dict_cursor_t c1 = NULL, c2 = NULL;
+  char *k1, *d1, *k2, *d2;
+  xbt_dict_foreach(routing->to_index, c1, k1, d1) {
+    xbt_dict_foreach (routing->to_index, c2, k2, d2) {
+      route_extended_t route = floyd_get_route (rc, k1, k2);
+      if (route){
+        if (xbt_dynar_length(route->generic_route.link_list) == 1){
+          void *link = *(void**)xbt_dynar_get_ptr(route->generic_route.link_list,0);
+          onelink_t onelink = xbt_new0 (s_onelink_t, 1);
+          onelink->src = xbt_strdup (k1);
+          onelink->dst = xbt_strdup (k2);
+          onelink->link_ptr = link;
+          xbt_dynar_push (ret, &onelink);
+        }
+      }
+    }
+  }
+  return ret;
 }
 
 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
@@ -1080,7 +1115,6 @@ static void* model_floyd_create(void) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = floyd_get_route;
   new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes;
-  new_component->generic_routing.is_router = floyd_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = floyd_finalize;
   new_component->to_index = xbt_dict_new();
@@ -1334,11 +1368,6 @@ static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
   xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
 }
 
-static int dijkstra_is_router(const char *name)
-{
-  xbt_die("\"dijkstra_is_router\" function not implemented yet");
-}
-
 static route_extended_t dijkstra_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
   
@@ -1545,7 +1574,6 @@ static void* model_dijkstra_both_create(int cached) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = dijkstra_get_route;
   new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes;
-  new_component->generic_routing.is_router = dijkstra_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = dijkstra_finalize;
   new_component->cached = cached;
@@ -1624,6 +1652,7 @@ static void  model_dijkstra_both_end(void) {
   
 }
 
+#ifdef HAVE_PCRE_LIB
 /* ************************************************** */
 /* ************** RULE-BASED ROUTING **************** */
 
@@ -1793,11 +1822,6 @@ static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
   xbt_die("\"rulebased_get_onelink_routes\" function not implemented yet");
 }
 
-static int rulebased_is_router(const char *name)
-{
-  xbt_die("\"rulebased_is_router\" function not implemented yet");
-}
-
 /* Business methods */
 static route_extended_t rulebased_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
@@ -1901,7 +1925,6 @@ static void* model_rulebased_create(void) {
   new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
   new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
   new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
-  new_component->generic_routing.is_router = rulebased_is_router;
   new_component->generic_routing.get_route = rulebased_get_route;
   new_component->generic_routing.get_bypass_route = NULL; //rulebased_get_bypass_route;
   new_component->generic_routing.finalize = rulebased_finalize;
@@ -1924,6 +1947,8 @@ static void  model_rulebased_unload(void) {
 static void  model_rulebased_end(void) {
 }
 
+#endif /* HAVE_PCRE_LIB */
+
 /* ************************************************************************** */
 /* ******************************* NO ROUTING ******************************* */
 
@@ -1936,9 +1961,6 @@ typedef struct {
 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc){
   return NULL;
 }
-static int none_is_router(const char *name){
-  return -1;
-}
 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
   return NULL;
 }
@@ -1962,7 +1984,6 @@ static void* model_none_create(void) {
   new_component->generic_routing.set_bypassroute = NULL;
   new_component->generic_routing.get_route = none_get_route;
   new_component->generic_routing.get_onelink_routes = none_get_onelink_routes;
-  new_component->generic_routing.is_router = none_is_router;
   new_component->generic_routing.get_bypass_route = none_get_bypass_route;
   new_component->generic_routing.finalize = none_finalize;
   return new_component;
@@ -2166,11 +2187,6 @@ static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc)
   xbt_die("\"generic_get_onelink_routes\" not implemented yet");
 }
 
-static int generic_is_router (const char *name)
-{
-  xbt_die("\"generic_is_router\" not implemented yet");
-}
-
 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst) {
   model_type_t modeltype = rc->routing;
   xbt_dict_t dict_bypassRoutes;
@@ -2194,8 +2210,8 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc, const ch
   routing_component_t* current_dst = NULL;
 
   /* (1) find the as where the src and dst are located */
-  src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
-  dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst); 
+  src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component;
+  dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component;
   xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst);
  
   /* (2) find the path to the root routing component */
@@ -2380,7 +2396,7 @@ static routing_component_t generic_autonomous_system_exist(routing_component_t r
   routing_component_t element_as, result, elem;
   xbt_dict_cursor_t cursor = NULL;
   char *key;
-  element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
+  element_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,element))->rc_component;
   result = ((routing_component_t)-1);
   if(element_as!=rc)
     result = generic_as_exist(rc,element_as);
@@ -2399,15 +2415,15 @@ static routing_component_t generic_autonomous_system_exist(routing_component_t r
 
 static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element) {
   routing_component_t element_as;
-  element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
+  element_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,element))->rc_component;
   if(element_as==rc) return element_as;
   return generic_as_exist(rc,element_as);
 }
 
 static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst) {
   
-  routing_component_t src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
-  routing_component_t dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
+  routing_component_t src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component;
+  routing_component_t dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component;
    
   xbt_assert3(src_as != NULL && dst_as  != NULL, 
       "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",src,dst,rc->name);
@@ -2417,6 +2433,12 @@ static void generic_src_dst_check(routing_component_t rc, const char* src, const
       "The routing component of src and dst is not the same as the network elements belong (%s==%s)",rc->name,dst_as->name);
 }
 
+static void parse_Sconfig(void)
+{
+       //TODO
+       DEBUG0("WARNING tag config not yet implemented.");
+}
+
 static void routing_full_parse_Scluster(void)
 {
        static int AX_ptr = 0;
@@ -2467,7 +2489,7 @@ static void routing_full_parse_Scluster(void)
                {
                        case 1:
                          surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
-                         host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
+                         host_id = bprintf("%s_%d%s", cluster_prefix, start, cluster_suffix);
                          #ifndef HAVE_PCRE_LIB
                          xbt_dynar_push_as(tab_elements_num, int, start);
                          #endif
@@ -2480,10 +2502,6 @@ static void routing_full_parse_Scluster(void)
                          SURFXML_BUFFER_SET(host_availability_file, "");
                          A_surfxml_host_state = A_surfxml_host_state_ON;
                          SURFXML_BUFFER_SET(host_state_file, "");
-                         SURFXML_BUFFER_SET(host_interference_send, "1.0");
-                         SURFXML_BUFFER_SET(host_interference_recv, "1.0");
-                         SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
-                         SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
                          SURFXML_START_TAG(host);
                          SURFXML_END_TAG(host);
 
@@ -2508,7 +2526,7 @@ static void routing_full_parse_Scluster(void)
                          DEBUG2("Create hosts and links from %d to %d",start,end);
                          for (i = start; i <= end; i++)
                          {
-                                 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
+                                 host_id = bprintf("%s_%d%s", cluster_prefix, i, cluster_suffix);
                                  #ifndef HAVE_PCRE_LIB
                                  xbt_dynar_push_as(tab_elements_num, int, i);
                                  #endif
@@ -2521,10 +2539,6 @@ static void routing_full_parse_Scluster(void)
                                  SURFXML_BUFFER_SET(host_availability_file, "");
                                  A_surfxml_host_state = A_surfxml_host_state_ON;
                                  SURFXML_BUFFER_SET(host_state_file, "");
-                                 SURFXML_BUFFER_SET(host_interference_send, "1.0");
-                                 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
-                                 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
-                                 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
                                  SURFXML_START_TAG(host);
                                  SURFXML_END_TAG(host);
 
@@ -2550,11 +2564,11 @@ static void routing_full_parse_Scluster(void)
        }
 
        DEBUG0(" ");
-       router_id = bprintf("%srouter%s",cluster_prefix,cluster_suffix);
-       link_router = bprintf("%s_link_router",cluster_id);
+       router_id = bprintf("%s_%s_router%s",cluster_prefix,cluster_id,cluster_suffix);
+       link_router = bprintf("%s_link_%s_router",cluster_id,cluster_id);
        link_backbone = bprintf("%s_backbone",cluster_id);
 
-       DEBUG1("<router id=\"%s\"\">",router_id);
+       DEBUG1("<router id=\"%s\"/>",router_id);
        SURFXML_BUFFER_SET(router_id, router_id);;
        SURFXML_START_TAG(router);
        SURFXML_END_TAG(router);
@@ -2593,7 +2607,7 @@ static void routing_full_parse_Scluster(void)
                        new_suffix = bprintf("%s\\.%s",new_suffix,groups);
                    }
        }
-       route_src_dst = bprintf("%s(.*)%s",cluster_prefix,new_suffix);
+       route_src_dst = bprintf("%s_(.*)%s",cluster_prefix,new_suffix);
 
        DEBUG0(" ");
 
@@ -2622,23 +2636,53 @@ static void routing_full_parse_Scluster(void)
        DEBUG0("</route>");
        SURFXML_END_TAG(route);
 #else
-       for(i=0 ; i<=tab_elements_num->elmsize ; i++)
+       for(i=0 ; i<=xbt_dynar_length(tab_elements_num) ; i++)
        {
-               for(j=0 ; j<=tab_elements_num->elmsize ; j++)
+               for(j=0 ; j<=xbt_dynar_length(tab_elements_num) ; j++)
                {
-                       route_src = bprintf("%s%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,i,int),cluster_suffix);
-                       route_dst = bprintf("%s%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,j,int),cluster_suffix);
+                       if(i == xbt_dynar_length(tab_elements_num))
+                       {
+                               route_src = router_id;
+                       }
+                       else
+                       {
+                               route_src = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,i,int),cluster_suffix);
+                       }
+
+                       if(j == xbt_dynar_length(tab_elements_num))
+                       {
+                               route_dst = router_id;
+                       }
+                       else
+                       {
+                               route_dst = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,j,int),cluster_suffix);
+                       }
 
                        DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src,route_dst);
                        SURFXML_BUFFER_SET(route_src, route_src);
                        SURFXML_BUFFER_SET(route_dst, route_dst);
                        SURFXML_START_TAG(route);
 
-                       route_src = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
-                       route_dst = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
-
-                       DEBUG2("<link:ctn\tid=\"%s_link_%d\"/>",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
-                       SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int)));
+                       if(i == xbt_dynar_length(tab_elements_num))
+                       {
+                               route_src = link_router;
+                       }
+                       else
+                       {
+                               route_src = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
+                       }
+
+                       if(j == xbt_dynar_length(tab_elements_num))
+                       {
+                               route_dst = link_router;
+                       }
+                       else
+                       {
+                               route_dst = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
+                       }
+
+                       DEBUG1("<link:ctn\tid=\"%s\"/>",route_src);
+                       SURFXML_BUFFER_SET(link_ctn_id, route_src);
                        SURFXML_START_TAG(link_ctn);
                        SURFXML_END_TAG(link_ctn);
 
@@ -2647,8 +2691,8 @@ static void routing_full_parse_Scluster(void)
                        SURFXML_START_TAG(link_ctn);
                        SURFXML_END_TAG(link_ctn);
 
-                       DEBUG2("<link:ctn\tid=\"%s_link_%d\"/>",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
-                       SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int)));
+                       DEBUG1("<link:ctn\tid=\"%s\"/>",route_dst);
+                       SURFXML_BUFFER_SET(link_ctn_id, route_dst);
                        SURFXML_START_TAG(link_ctn);
                        SURFXML_END_TAG(link_ctn);