Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implementing recursive call to get_onelink_routes
[simgrid.git] / src / surf / surf_routing.c
index eaa3f87..a0b74ee 100644 (file)
@@ -4,8 +4,14 @@
 /* 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 <float.h>
-#include <pcre.h> /* regular expresion library */
+#include "gras_config.h"
+
+#ifdef HAVE_PCRE_LIB
+       #include <pcre.h> /* regular expresion library */
+#endif
 #include "surf_private.h"
 #include "xbt/dynar.h"
 #include "xbt/str.h"
@@ -86,7 +92,7 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* ************************************************************************** */
 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
 
-static xbt_dict_t generic_get_onelink_routes (void);
+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);
 
@@ -671,9 +677,38 @@ static void finalize(void) {
   xbt_free(global_routing);
 }
 
-static xbt_dict_t get_onelink_routes(void)
+static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc)
+{
+  xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
+
+  //adding my one link routes
+  unsigned int cpt;
+  void *link;
+  xbt_dynar_t onelink_mine = rc->get_onelink_routes (rc);
+  if (onelink_mine){
+    xbt_dynar_foreach(onelink_mine, cpt, link) {
+      xbt_dynar_push(ret,&link);
+    }
+  }
+
+  //recursing
+  char *key;
+  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);
+    if (onelink_child){
+      xbt_dynar_foreach(onelink_child, cpt, link) {
+        xbt_dynar_push(ret,&link);
+      }
+    }
+  }
+  return ret;
+}
+
+static xbt_dynar_t get_onelink_routes(void)
 {
-       xbt_die("global \"get_onelink_routes\" function not implemented yet");
+  return recursive_get_onelink_routes (global_routing->root);
 }
 
 static int is_router(const char *name)
@@ -740,9 +775,34 @@ typedef struct {
 } s_routing_component_full_t,*routing_component_full_t;
 
 /* Business methods */
-static xbt_dict_t full_get_onelink_routes(void)
+static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
 {
-  xbt_die("\"full_get_onelink_routes\" function not implemented yet");
+  xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
+
+  routing_component_full_t routing = (routing_component_full_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) {
+      int *src_id = xbt_dict_get_or_null(routing->to_index, k1);
+      int *dst_id = xbt_dict_get_or_null(routing->to_index, k2);
+      xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",src,dst);
+      route_extended_t route = TO_ROUTE_FULL(*src_id,*dst_id);
+      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 int full_is_router(const char *name)
@@ -910,7 +970,7 @@ typedef struct {
 } s_routing_component_floyd_t,*routing_component_floyd_t;
 
 /* Business methods */
-static xbt_dict_t floyd_get_onelink_routes(void)
+static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
 {
   xbt_die("\"floyd_get_onelink_routes\" function not implemented yet");
 }
@@ -1269,7 +1329,7 @@ static void add_loopback_dijkstra(routing_component_dijkstra_t rc) {
 }
 
 /* Business methods */
-static xbt_dict_t dijkstra_get_onelink_routes(void)
+static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
 {
   xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
 }
@@ -1728,7 +1788,7 @@ static char* remplace(char* value, const char** src_list, int src_size, const ch
   return xbt_strdup(result_result);
 }
 
-static xbt_dict_t rulebased_get_onelink_routes(void)
+static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
 {
   xbt_die("\"rulebased_get_onelink_routes\" function not implemented yet");
 }
@@ -1873,7 +1933,7 @@ typedef struct {
 } s_routing_component_none_t,*routing_component_none_t;
 
 /* Business methods */
-static xbt_dict_t none_get_onelink_routes(void){
+static xbt_dynar_t none_get_onelink_routes(routing_component_t rc){
   return NULL;
 }
 static int none_is_router(const char *name){
@@ -2101,7 +2161,7 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* ************************************************************************** */
 /* *********************** GENERIC BUSINESS METHODS ************************* */
 
-static xbt_dict_t generic_get_onelink_routes (void)
+static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc)
 {
   xbt_die("\"generic_get_onelink_routes\" not implemented yet");
 }
@@ -2376,6 +2436,11 @@ static void routing_full_parse_Scluster(void)
        int start, end, i;
        xbt_dynar_t radical_elements;
        xbt_dynar_t radical_ends;
+       #ifndef HAVE_PCRE_LIB
+               xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+               char *route_src,*route_dst;
+               int j;
+       #endif
 
        static unsigned int surfxml_buffer_stack_stack_ptr = 1;
        static unsigned int surfxml_buffer_stack_stack[1024];
@@ -2384,9 +2449,14 @@ static void routing_full_parse_Scluster(void)
 
        surfxml_bufferstack_push(1);
 
-       DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
        SURFXML_BUFFER_SET(AS_id, cluster_id);
+#ifdef HAVE_PCRE_LIB
        SURFXML_BUFFER_SET(AS_routing, "RuleBased");
+       DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
+#else
+       SURFXML_BUFFER_SET(AS_routing, "Full");
+       DEBUG1("<AS id=\"%s\"\trouting=\"Full\">",cluster_id);
+#endif
        SURFXML_START_TAG(AS);
 
        radical_elements = xbt_str_split(cluster_radical, ",");
@@ -2398,6 +2468,9 @@ 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);
+                         #ifndef HAVE_PCRE_LIB
+                         xbt_dynar_push_as(tab_elements_num, int, start);
+                         #endif
                          link_id = bprintf("%s_link_%d", cluster_id, start);
 
                          DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
@@ -2436,6 +2509,9 @@ static void routing_full_parse_Scluster(void)
                          for (i = start; i <= end; i++)
                          {
                                  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
                                  link_id = bprintf("%s_link_%d", cluster_id, i);
 
                                  DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
@@ -2521,6 +2597,8 @@ static void routing_full_parse_Scluster(void)
 
        DEBUG0(" ");
 
+#ifdef HAVE_PCRE_LIB
+
        DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
        SURFXML_BUFFER_SET(route_src, route_src_dst);
        SURFXML_BUFFER_SET(route_dst, route_src_dst);
@@ -2543,6 +2621,43 @@ static void routing_full_parse_Scluster(void)
 
        DEBUG0("</route>");
        SURFXML_END_TAG(route);
+#else
+       for(i=0 ; i<=tab_elements_num->elmsize ; i++)
+       {
+               for(j=0 ; j<=tab_elements_num->elmsize ; 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);
+
+                       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)));
+                       SURFXML_START_TAG(link_ctn);
+                       SURFXML_END_TAG(link_ctn);
+
+                       DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
+                       SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone",cluster_id));
+                       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)));
+                       SURFXML_START_TAG(link_ctn);
+                       SURFXML_END_TAG(link_ctn);
+
+                       DEBUG0("</route>");
+                       SURFXML_END_TAG(route);
+               }
+       }
+       xbt_dynar_free(&tab_elements_num);
+#endif
 
        DEBUG0("</AS>");
        SURFXML_END_TAG(AS);