Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix identation of comments.
[simgrid.git] / src / surf / surf_routing.c
index b8dff62..8e68cf3 100644 (file)
@@ -10,7 +10,7 @@
 #include "gras_config.h"
 
 #ifdef HAVE_PCRE_LIB
-#include <pcre.h>               /* regular expresion library */
+#include <pcre.h>               /* regular expression library */
 #endif
 #include "surf_private.h"
 #include "xbt/dynar.h"
@@ -36,7 +36,7 @@ static void *model_full_create(void);   /* create structures for full routing mo
 static void model_full_load(void);      /* load parse functions for full routing model */
 static void model_full_unload(void);    /* unload parse functions for full routing model */
 static void model_full_end(void);       /* finalize the creation of full routing model */
-static void model_full_set_route(              /* Set the route and ASroute between src and dst */
+static void model_full_set_route(      /* Set the route and ASroute between src and dst */
                routing_component_t rc, const char *src, const char *dst, name_route_extended_t route);
 
 static void *model_floyd_create(void);  /* create structures for floyd routing model */
@@ -56,22 +56,22 @@ static void model_dijkstra_both_set_route (routing_component_t rc, const char *s
                      const char *dst, name_route_extended_t route);
 
 static void *model_rulebased_create(void);      /* create structures for rulebased routing model */
-static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
+static void model_rulebased_load(void);         /* load parse functions for rulebased routing model */
 static void model_rulebased_unload(void);       /* unload parse functions for rulebased routing model */
-static void model_rulebased_end(void);  /* finalize the creation of rulebased routing model */
+static void model_rulebased_end(void);          /* finalize the creation of rulebased routing model */
 
-static void *model_none_create(void);   /* none routing model */
-static void model_none_load(void);      /* none routing model */
-static void model_none_unload(void);    /* none routing model */
-static void model_none_end(void);       /* none routing model */
+static void *model_none_create(void);           /* none routing model */
+static void model_none_load(void);              /* none routing model */
+static void model_none_unload(void);            /* none routing model */
+static void model_none_end(void);               /* none routing model */
 
-static void routing_parse_Scluster(void);  /*cluster bypass */
-static void routing_parse_Speer(void);         /*peer bypass */
-static void routing_parse_Srandom(void);       /*random bypass */
-static void routing_parse_Erandom(void);       /*random bypass */
+static void routing_parse_Scluster(void);       /* cluster bypass */
+static void routing_parse_Speer(void);          /* peer bypass */
+static void routing_parse_Srandom(void);        /* random bypass */
+static void routing_parse_Erandom(void);        /* random bypass */
 
-static void routing_parse_Sconfig(void);        /*config Tag */
-static void routing_parse_Econfig(void);        /*config Tag */
+static void routing_parse_Sconfig(void);        /* config Tag */
+static void routing_parse_Econfig(void);        /* config Tag */
 
 static char* replace_random_parameter(char * chaine);
 static void clean_dict_random(void);
@@ -89,7 +89,7 @@ typedef enum {
 } e_routing_types;
 
 
-/* must be finish with null and carefull if change de order */
+/* must finish with NULL and be careful if the order is changed */
 struct s_model_type routing_models[] = { {"Full",
                                           "Full routing data (fast, large memory requirements, fully expressive)",
                                           model_full_create,
@@ -171,7 +171,7 @@ static char *gw_dst = NULL;     /* temporary store the gateway destination name
 static xbt_dynar_t link_list = NULL;    /* temporary store of current list link of a route */
 
 
-static double eculidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
+static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
 {
        double src_coord, dst_coord;
 
@@ -194,25 +194,12 @@ static double vivaldi_get_link_latency (routing_component_t rc,const char *src,
   if(dst_ctn == NULL || src_ctn == NULL)
   xbt_die("Coord src '%s' :%p   dst '%s' :%p",src,src_ctn,dst,dst_ctn);
 
-  euclidean_dist = sqrt (eculidean_dist_comp(0,src_ctn,dst_ctn)+eculidean_dist_comp(1,src_ctn,dst_ctn))
+  euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
                                                                +fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
 
   xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
 
   return euclidean_dist;
-
-  /*
-  x = atof(xbt_dynar_get_as(src_ctn, 0, char *))-atof(xbt_dynar_get_as(dst_ctn, 0, char *));
-  y = atof(xbt_dynar_get_as(src_ctn, 1, char *));
-  h = atof(xbt_dynar_get_as(ctn, 2, char *));
-  sqrt((c1->x - c2->x) * (c1->x - c2->x) + (c1->y - c2->y) * (c1->y - c2->y)) + fabs(c1->h) + fabs(c2->h);
-
-         if (strcmp(coord,"")) {
-       xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
-       xbt_dynar_shrink(ctn,0);
-       xbt_lib_set(host_lib, host_id, COORD_HOST_LEVEL, ctn);
-  }
-       */
 }
 
 /**
@@ -564,13 +551,6 @@ static void parse_S_AS(char *AS_id, char *AS_routing)
 static void parse_S_AS_XML(void)
 {
   parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
-
-  if (strcmp(A_surfxml_AS_coordinates,"")) {
-       if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
-    xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_AS_coordinates, " ");
-    xbt_dynar_shrink(ctn, 0);
-    xbt_lib_set(as_router_lib,A_surfxml_AS_id,COORD_ASR_LEVEL,(void *) ctn);
-  }
 }
 
 /*
@@ -741,8 +721,8 @@ static xbt_dynar_t elements_father(const char *src, const char *dst)
  * \param src the source host name 
  * \param dst the destination host name
  * 
- * This fuction is call by "get_route". It allow to walk through the 
- * routing components tree.
+ * This function is called by "get_route". It allows to walk recursively
+ * through the routing components tree.
  */
 static route_extended_t _get_route(const char *src, const char *dst)
 {
@@ -1161,7 +1141,7 @@ void surf_parse_add_callback_config(void)
 {
        surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
        surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
-       surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
+       surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
        surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
        surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
 }
@@ -1412,10 +1392,10 @@ static void model_full_set_route(routing_component_t rc, const char *src,
        {
                if(route->dst_gateway && route->src_gateway)
                {
-                  char *gw_src = xbt_strdup(route->src_gateway);
-                  char *gw_dst = xbt_strdup(route->dst_gateway);
-                  route->src_gateway = gw_dst;
-                  route->dst_gateway = gw_src;
+                  char *gw_tmp ;
+                  gw_tmp = route->src_gateway;
+                  route->src_gateway = route->dst_gateway;
+                  route->dst_gateway = gw_tmp;
                }
                if(TO_ROUTE_FULL(*dst_id, *src_id))
                {
@@ -1445,8 +1425,10 @@ static void model_full_set_route(routing_component_t rc, const char *src,
                      TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
                      xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
                }
-
        }
+
+       if (rc->hierarchy == SURF_ROUTING_BASE) generic_free_route((route_t)route) ;
+       else generic_free_extended_route((route_extended_t)route);
 }
 
 /* ************************************************************************** */
@@ -2435,6 +2417,12 @@ static void model_rulebased_set_route(routing_component_t rc,
   rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
   const char *error;
   int erroffset;
+
+  if(!strcmp(rc->routing->name,"Vivaldi")){
+         if(xbt_dynar_length(route->generic_route.link_list) != 0)
+                 xbt_die("You can't have link_ctn with Model Vivaldi.");
+  }
+
   ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
   xbt_assert(ruleroute->re_src,
               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
@@ -2457,6 +2445,12 @@ static void model_rulebased_set_ASroute(routing_component_t rc,
   rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
   const char *error;
   int erroffset;
+
+  if(!strcmp(rc->routing->name,"Vivaldi")){
+         if(xbt_dynar_length(route->generic_route.link_list) != 0)
+                 xbt_die("You can't have link_ctn with Model Vivaldi.");
+  }
+
   ruleroute_e->generic_rule_route.re_src =
       pcre_compile(src, 0, &error, &erroffset, NULL);
   xbt_assert(ruleroute_e->generic_rule_route.re_src,
@@ -3186,8 +3180,8 @@ generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
     links = e_route->generic_route.link_list;
 
     /* remeber not erase the gateway names */
-    new_e_route->src_gateway = e_route->src_gateway;
-    new_e_route->dst_gateway = e_route->dst_gateway;
+    new_e_route->src_gateway = strdup(e_route->src_gateway);
+    new_e_route->dst_gateway = strdup(e_route->dst_gateway);
   }
 
   links_id = new_e_route->generic_route.link_list;
@@ -3305,8 +3299,8 @@ static void generic_src_dst_check(routing_component_t rc, const char *src,
          xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
               src, src_as->name, dst, dst_as->name);
   if(rc != dst_as)
-        xbt_die("The routing component of src and dst is not the same as the network elements belong (%s==%s)",
-     rc->name, dst_as->name);
+        xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
+     src,dst,src_as->name, dst_as->name,rc->name);
 }
 
 static void routing_parse_Sconfig(void)
@@ -3388,11 +3382,9 @@ static void routing_parse_Scluster(void)
   SURFXML_BUFFER_SET(AS_id, cluster_id);
 #ifdef HAVE_PCRE_LIB
   SURFXML_BUFFER_SET(AS_routing, "RuleBased");
-  SURFXML_BUFFER_SET(AS_coordinates, "");
   XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
 #else
   SURFXML_BUFFER_SET(AS_routing, "Full");
-  SURFXML_BUFFER_SET(AS_coordinates, "");
   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
 #endif
   SURFXML_START_TAG(AS);
@@ -3781,7 +3773,6 @@ static void routing_parse_Speer(void)
   surfxml_bufferstack_push(1);
 
   SURFXML_BUFFER_SET(AS_id, peer_id);
-  SURFXML_BUFFER_SET(AS_coordinates, peer_coord);
 
   SURFXML_BUFFER_SET(AS_routing, "Full");
   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);