Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'parser'
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 10 Nov 2011 21:40:23 +0000 (22:40 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 10 Nov 2011 21:40:23 +0000 (22:40 +0100)
src/surf/surf_private.h
src/surf/surf_routing.c
src/surf/surf_routing_cluster.c
src/surf/surf_routing_dijkstra.c
src/surf/surf_routing_floyd.c
src/surf/surf_routing_full.c
src/surf/surf_routing_generic.c
src/surf/surf_routing_none.c
src/surf/surf_routing_private.h
src/surf/surf_routing_rulebased.c

index 15f9cbf..d96ba82 100644 (file)
@@ -130,7 +130,7 @@ typedef enum {
 typedef struct s_as {
   xbt_dict_t to_index;                 /* char* -> network_element_t */
   xbt_dict_t bypassRoutes;             /* store bypass routes */
-  routing_model_description_t routing;
+  routing_model_description_t model_desc;
   e_surf_routing_hierarchy_t hierarchy;
   char *name;
   struct s_as *routing_father;
index f20ed82..4514283 100644 (file)
@@ -292,7 +292,7 @@ static void routing_parse_E_bypassRoute(void)
  */
 void routing_AS_begin(const char *AS_id, const char *wanted_routing_type)
 {
-  AS_t new_routing;
+  AS_t new_as;
   routing_model_description_t model = NULL;
   int cpt;
 
@@ -311,17 +311,16 @@ void routing_AS_begin(const char *AS_id, const char *wanted_routing_type)
   }
 
   /* make a new routing component */
-  new_routing = (AS_t) (*(model->create)) ();
-  new_routing->routing = model;
-  new_routing->hierarchy = SURF_ROUTING_NULL;
-  new_routing->name = xbt_strdup(AS_id);
-  new_routing->routing_sons = xbt_dict_new();
+  new_as = (AS_t) (*(model->create)) ();
+  new_as->model_desc = model;
+  new_as->hierarchy = SURF_ROUTING_NULL;
+  new_as->name = xbt_strdup(AS_id);
 
   if (current_routing == NULL && global_routing->root == NULL) {
 
     /* it is the first one */
-    new_routing->routing_father = NULL;
-    global_routing->root = new_routing;
+    new_as->routing_father = NULL;
+    global_routing->root = new_as;
 
   } else if (current_routing != NULL && global_routing->root != NULL) {
 
@@ -329,20 +328,20 @@ void routing_AS_begin(const char *AS_id, const char *wanted_routing_type)
                (current_routing->routing_sons, AS_id),
                "The AS \"%s\" already exists", AS_id);
     /* it is a part of the tree */
-    new_routing->routing_father = current_routing;
+    new_as->routing_father = current_routing;
     /* set the father behavior */
     if (current_routing->hierarchy == SURF_ROUTING_NULL)
       current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
     /* add to the sons dictionary */
     xbt_dict_set(current_routing->routing_sons, AS_id,
-                 (void *) new_routing, NULL);
+                 (void *) new_as, NULL);
     /* add to the father element list */
     (*(current_routing->parse_AS)) (current_routing, AS_id);
   } else {
     THROWF(arg_error, 0, "All defined components must be belong to a AS");
   }
   /* set the new current component of the tree */
-  current_routing = new_routing;
+  current_routing = new_as;
 }
 
 /**
@@ -372,8 +371,8 @@ void routing_AS_end()
     xbt_lib_set(as_router_lib, current_routing->name, ROUTING_ASR_LEVEL,
                 (void *) info);
 
-    if (current_routing->routing->end)
-      (*(current_routing->routing->end)) (current_routing);
+    if (current_routing->model_desc->end)
+      (*(current_routing->model_desc->end)) (current_routing);
     current_routing = current_routing->routing_father;
   }
 }
@@ -928,12 +927,7 @@ static void routing_parse_cluster(void)
 
     sg_platf_new_link(&link);
 
-    surf_parsing_link_up_down_t info =
-        xbt_new0(s_surf_parsing_link_up_down_t, 1);
-    info->link_up =
-        xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL);
-    info->link_down = info->link_up;
-    surf_routing_cluster_add_link(struct_cluster->id, info);
+    surf_routing_cluster_add_backbone(current_routing, xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL));
 
     free(link_backbone);
   }
@@ -1222,11 +1216,10 @@ static void finalize_rec(AS_t as) {
   char *key;
   AS_t elem;
 
-  xbt_dict_foreach(as->routing_sons, cursor, key, elem)
-  finalize_rec(elem);
+  xbt_dict_foreach(as->routing_sons, cursor, key, elem) {
+    finalize_rec(elem);
+  }
 
-  xbt_dict_free(&as->routing_sons);
-  xbt_free(as->name);
   as->finalize(as);
 }
 
index d5658b6..883b887 100644 (file)
@@ -14,6 +14,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
  * Note that a router is created, easing the interconnexion with the rest of the world.
  */
 
+typedef struct {
+  s_as_t generic_routing;
+  void *backbone;
+} s_as_cluster_t, *as_cluster_t;
+
+
 static xbt_dict_t cluster_host_link = NULL;
 
 /* Business methods */
@@ -28,8 +34,8 @@ static route_extended_t cluster_get_route(AS_t as,
          info = xbt_dict_get_or_null(cluster_host_link,src);
          if(info) xbt_dynar_push_as(links_list,void*,info->link_up); //link_up
 
-         info = xbt_dict_get_or_null(cluster_host_link,as->name);
-         if(info)  xbt_dynar_push_as(links_list,void*,info->link_up); //link_bb
+         if ( ((as_cluster_t)as)->backbone )
+           xbt_dynar_push_as(links_list,void*, ((as_cluster_t)as)->backbone) ;
 
          info = xbt_dict_get_or_null(cluster_host_link,dst);
          if(info) xbt_dynar_push_as(links_list,void*,info->link_down); //link_down
@@ -41,11 +47,16 @@ static route_extended_t cluster_get_route(AS_t as,
          return new_e_route;
 }
 
+static void model_cluster_finalize(AS_t as) {
+  xbt_dict_free(&cluster_host_link);
+  model_none_finalize(as);
+}
 /* Creation routing model functions */
 AS_t model_cluster_create(void)
 {
-  AS_t result = model_none_create();
+  AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
   result->get_route = cluster_get_route;
+  result->finalize = model_cluster_finalize;
 
   return (AS_t) result;
 }
@@ -56,3 +67,7 @@ void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down
 
  xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
 }
+
+void surf_routing_cluster_add_backbone(AS_t as, void* bb) {
+  ((as_cluster_t)as)->backbone = bb;
+}
index 33cf01b..4e51e93 100644 (file)
@@ -417,19 +417,13 @@ static void dijkstra_finalize(AS_t asg)
 {
   as_dijkstra_t as = (as_dijkstra_t) asg;
 
-  if (as) {
-    xbt_graph_free_graph(as->route_graph, &xbt_free,
-                         &graph_edge_data_free, &xbt_free);
-    xbt_dict_free(&as->graph_node_map);
-    if (as->cached)
-      xbt_dict_free(&as->route_cache);
-    /* Delete bypass dict */
-    xbt_dict_free(&as->generic_routing.bypassRoutes);
-    /* Delete index dict */
-    xbt_dict_free(&(as->generic_routing.to_index));
-    /* Delete structure */
-    xbt_free(as);
-  }
+  xbt_graph_free_graph(as->route_graph, &xbt_free,
+      &graph_edge_data_free, &xbt_free);
+  xbt_dict_free(&as->graph_node_map);
+  if (as->cached)
+    xbt_dict_free(&as->route_cache);
+
+  model_generic_finalize(asg);
 }
 
 /* Creation routing model functions */
@@ -437,7 +431,7 @@ static void dijkstra_finalize(AS_t asg)
 AS_t model_dijkstra_both_create(int cached)
 {
   as_dijkstra_t new_component = (as_dijkstra_t)
-      routmod_generic_create(sizeof(s_as_dijkstra_t));
+      model_generic_create_sized(sizeof(s_as_dijkstra_t));
 
   new_component->generic_routing.parse_route = model_dijkstra_both_parse_route;
   new_component->generic_routing.parse_ASroute = model_dijkstra_both_parse_route;
index 23bb9c4..87d2bfa 100644 (file)
@@ -171,7 +171,7 @@ static void floyd_finalize(AS_t rc)
 
 AS_t model_floyd_create(void)
 {
-  as_floyd_t new_component = (as_floyd_t)routmod_generic_create(sizeof(s_as_floyd_t));
+  as_floyd_t new_component = (as_floyd_t)model_generic_create_sized(sizeof(s_as_floyd_t));
   new_component->generic_routing.parse_route = model_floyd_parse_route;
   new_component->generic_routing.parse_ASroute = model_floyd_parse_route;
   new_component->generic_routing.get_route = floyd_get_route;
index 2bd5b2d..bfc4e41 100644 (file)
@@ -111,12 +111,7 @@ static void full_finalize(AS_t rc)
       for (j = 0; j < table_size; j++)
         generic_free_extended_route(TO_ROUTE_FULL(i, j));
     xbt_free(routing->routing_table);
-    /* Delete bypass dict */
-    xbt_dict_free(&rc->bypassRoutes);
-    /* Delete index dict */
-    xbt_dict_free(&rc->to_index);
-    /* Delete structure */
-    xbt_free(rc);
+    model_generic_finalize(rc);
   }
 }
 
@@ -125,7 +120,7 @@ static void full_finalize(AS_t rc)
 AS_t model_full_create(void)
 {
   routing_component_full_t new_component = (routing_component_full_t)
-      routmod_generic_create(sizeof(s_routing_component_full_t));
+      model_generic_create_sized(sizeof(s_routing_component_full_t));
 
   new_component->generic_routing.parse_route = model_full_set_route;
   new_component->generic_routing.parse_ASroute = model_full_set_route;
index a6501cb..4355976 100644 (file)
@@ -14,8 +14,8 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing");
 
-AS_t routmod_generic_create(size_t childsize) {
-  AS_t new_component = xbt_malloc0(childsize);
+AS_t model_generic_create_sized(size_t childsize) {
+  AS_t new_component = model_none_create_sized(childsize);
 
   new_component->parse_PU = generic_parse_PU;
   new_component->parse_AS = generic_parse_AS;
@@ -27,13 +27,18 @@ AS_t routmod_generic_create(size_t childsize) {
   new_component->get_onelink_routes = NULL;
   new_component->get_bypass_route =
       generic_get_bypassroute;
-  new_component->finalize = NULL;
+  new_component->finalize = model_generic_finalize;
+
   new_component->to_index = xbt_dict_new();
   new_component->bypassRoutes = xbt_dict_new();
 
   return new_component;
 }
-
+void model_generic_finalize(AS_t as) {
+  xbt_dict_free(&as->to_index);
+  xbt_dict_free(&as->bypassRoutes);
+  model_none_finalize(as);
+}
 
 void generic_parse_PU(AS_t as, const char *name)
 {
index c6394d8..f4d9516 100644 (file)
@@ -8,10 +8,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf");
 
-/* Routing model structure */
-/* Business methods */
-static xbt_dynar_t none_get_onelink_routes(AS_t rc)
-{
+static xbt_dynar_t none_get_onelink_routes(AS_t rc) {
   return NULL;
 }
 
@@ -23,30 +20,24 @@ static route_extended_t none_get_route(AS_t rc,
 
 static route_extended_t none_get_bypass_route(AS_t rc,
                                               const char *src,
-                                              const char *dst)
-{
+                                              const char *dst) {
   return NULL;
 }
 
-static void none_finalize(AS_t rc)
-{
-  xbt_free(rc);
+static void none_parse_PU(AS_t rc, const char *name) {
+  /* don't care about PUs */
 }
 
-static void none_parse_PU(AS_t rc,
-                                     const char *name)
-{
-}
-
-static void none_parse_AS(AS_t rc,
-                                       const char *name)
-{
+static void none_parse_AS(AS_t rc, const char *name) {
+  /* even don't care about sub-ASes */
 }
 
 /* Creation routing model functions */
-AS_t model_none_create(void)
-{
-  AS_t new_component = xbt_new(s_as_t, 1);
+AS_t model_none_create() {
+  return model_none_create_sized(sizeof(s_as_t));
+}
+AS_t model_none_create_sized(size_t childsize) {
+  AS_t new_component = xbt_malloc0(childsize);
   new_component->parse_PU = none_parse_PU;
   new_component->parse_AS = none_parse_AS;
   new_component->parse_route = NULL;
@@ -55,7 +46,16 @@ AS_t model_none_create(void)
   new_component->get_route = none_get_route;
   new_component->get_onelink_routes = none_get_onelink_routes;
   new_component->get_bypass_route = none_get_bypass_route;
-  new_component->finalize = none_finalize;
+  new_component->finalize = model_none_finalize;
+
+  new_component->routing_sons = xbt_dict_new();
+
   return new_component;
 }
 
+void model_none_finalize(AS_t as) {
+  xbt_dict_free(&as->routing_sons);
+  xbt_free(as->name);
+  xbt_free(as);
+}
+
index 7e7405a..c12b6e3 100644 (file)
@@ -1,9 +1,8 @@
-/*
- * surf_routing_private.h
- *
- *  Created on: 14 avr. 2011
- *      Author: navarrop
- */
+/* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* 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. */
 
 #ifndef _SURF_SURF_ROUTING_PRIVATE_H
 #define _SURF_SURF_ROUTING_PRIVATE_H
 #include "xbt/set.h"
 #include "surf/surfxml_parse.h"
 
+/* ************************************************************************** */
+/* ******************************* NO ROUTING ******************************* */
+/* Only save the AS tree, and forward calls to child ASes */
+AS_t model_none_create(void);
+AS_t model_none_create_sized(size_t childsize);
+void model_none_finalize(AS_t as);
 /* ************************************************************************** */
 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
-AS_t routmod_generic_create(size_t childsize);
+AS_t model_generic_create_sized(size_t childsize);
+void model_generic_finalize(AS_t as);
 
-void generic_parse_PU(AS_t rc,
-                                        const char *name);
-void generic_parse_AS(AS_t rc,
-                                          const char *name);
-void generic_parse_bypassroute(AS_t rc,
-                                    const char *src, const char *dst,
-                                    route_extended_t e_route);
+void generic_parse_PU(AS_t rc, const char *name);
+void generic_parse_AS(AS_t rc, const char *name);
+void generic_parse_bypassroute(AS_t rc, const char *src, const char *dst,
+                               route_extended_t e_route);
 
 /* ************************************************************************** */
 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
@@ -75,7 +78,9 @@ AS_t model_rulebased_create(void);      /* create structures for rulebased routi
 /* **************  Cluster ROUTING   **************** */
 AS_t model_cluster_create(void);      /* create structures for cluster routing model */
 
+/* Pass info from the cluster parser to the cluster routing */
 void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info);
+void surf_routing_cluster_add_backbone(AS_t as, void* bb);
 
 /* ************************************************** */
 /* **************  Vivaldi ROUTING   **************** */
@@ -101,8 +106,5 @@ void model_full_end(AS_t as);       /* finalize the creation of full routing mod
 void model_full_set_route(     /* Set the route and ASroute between src and dst */
                AS_t rc, const char *src, const char *dst, route_extended_t route);
 
-/* ************************************************************************** */
-/* ******************************* NO ROUTING ******************************* */
-AS_t model_none_create(void);           /* none routing model */
 
 #endif                          /* _SURF_SURF_ROUTING_PRIVATE_H */
index 9fad2dc..357c33d 100644 (file)
@@ -92,7 +92,7 @@ static void model_rulebased_parse_route(AS_t rc,
   const char *error;
   int erroffset;
 
-  if(!strcmp(rc->routing->name,"Vivaldi")){
+  if(!strcmp(rc->model_desc->name,"Vivaldi")){
          if(xbt_dynar_length(route->generic_route.link_list) != 0)
                  xbt_die("You can't have link_ctn with Model Vivaldi.");
   }
@@ -120,7 +120,7 @@ static void model_rulebased_parse_ASroute(AS_t rc,
   const char *error;
   int erroffset;
 
-  if(!strcmp(rc->routing->name,"Vivaldi")){
+  if(!strcmp(rc->model_desc->name,"Vivaldi")){
          if(xbt_dynar_length(route->generic_route.link_list) != 0)
                  xbt_die("You can't have link_ctn with Model Vivaldi.");
   }
@@ -395,7 +395,7 @@ static void rulebased_finalize(AS_t rc)
 AS_t model_rulebased_create(void) {
 
   routing_component_rulebased_t new_component = (routing_component_rulebased_t)
-      routmod_generic_create(sizeof(s_routing_component_rulebased_t));
+      model_generic_create_sized(sizeof(s_routing_component_rulebased_t));
 
   new_component->generic_routing.parse_PU = model_rulebased_parse_PU;
   new_component->generic_routing.parse_AS = model_rulebased_parse_AS;