Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memleak
[simgrid.git] / src / surf / surf_routing.cpp
index 545b75f..6216697 100644 (file)
@@ -1,7 +1,16 @@
+/* Copyright (c) 2009, 2010, 2011, 2013. 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. */
+
 #include "surf_routing.hpp"
 #include "surf_routing_private.hpp"
 #include "surf_routing.hpp"
 #include "surf_routing_private.hpp"
+
+#include "simgrid/platf_interface.h"    // platform creation API internal interface
+#include "simgrid/sg_config.h"
+
 #include "surf/surfxml_parse_values.h"
 #include "surf/surfxml_parse_values.h"
-#include "surf/random_mgr.h"
 
 /**
  * @ingroup SURF_build_api
 
 /**
  * @ingroup SURF_build_api
@@ -12,14 +21,15 @@ xbt_lib_t host_lib;
 int ROUTING_HOST_LEVEL;         //Routing level
 int SURF_CPU_LEVEL;             //Surf cpu level
 int SURF_WKS_LEVEL;             //Surf workstation level
 int ROUTING_HOST_LEVEL;         //Routing level
 int SURF_CPU_LEVEL;             //Surf cpu level
 int SURF_WKS_LEVEL;             //Surf workstation level
-int SIMIX_HOST_LEVEL;           //Simix level
-int MSG_HOST_LEVEL;             //Msg level
-int SD_HOST_LEVEL;              //Simdag level
+int SIMIX_HOST_LEVEL;           //Simix host level
+int SIMIX_STORAGE_LEVEL;        //Simix storage level
+int MSG_HOST_LEVEL;             //Msg host level
+int MSG_STORAGE_LEVEL;          //Msg storage level
+int SD_HOST_LEVEL;              //Simdag host level
+int SD_STORAGE_LEVEL;           //Simdag storage level
 int COORD_HOST_LEVEL=0;         //Coordinates level
 int NS3_HOST_LEVEL;             //host node for ns3
 
 int COORD_HOST_LEVEL=0;         //Coordinates level
 int NS3_HOST_LEVEL;             //host node for ns3
 
-xbt_dict_t watched_hosts_lib;
-
 /**
  * @ingroup SURF_build_api
  * @brief A library containing all known links
 /**
  * @ingroup SURF_build_api
  * @brief A library containing all known links
@@ -103,7 +113,7 @@ struct s_model_type routing_models[] = {
  */
 static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
 {
  */
 static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
 {
-  RoutingEdgePtr info = (RoutingEdgePtr) xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL);
+  RoutingEdgePtr info = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL));
   xbt_assert(info, "Host '%s' not found!", host->id);
   xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
       current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
   xbt_assert(info, "Host '%s' not found!", host->id);
   xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
       current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
@@ -122,7 +132,7 @@ static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
     current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
 
   // If dynar is is greater than edge id and if the host_link is already defined
     current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
 
   // If dynar is is greater than edge id and if the host_link is already defined
-  if(xbt_dynar_length(current_routing->p_linkUpDownList) > info->m_id &&
+  if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > info->m_id &&
       xbt_dynar_get_as(current_routing->p_linkUpDownList, info->m_id, void*))
     xbt_die("Host_link for '%s' is already defined!",host->id);
 
       xbt_dynar_get_as(current_routing->p_linkUpDownList, info->m_id, void*))
     xbt_die("Host_link for '%s' is already defined!",host->id);
 
@@ -312,8 +322,6 @@ static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_con
   }
 }
 
   }
 }
 
-extern int _sg_init_status; /* yay, this is an horrible hack */
-
 /**
  * \brief Make a new routing component to the platform
  *
 /**
  * \brief Make a new routing component to the platform
  *
@@ -336,7 +344,9 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
              (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
              "The AS \"%s\" already exists", AS->id);
 
              (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
              "The AS \"%s\" already exists", AS->id);
 
-  _sg_init_status = 2; /* horrible hack: direct access to the global controlling the level of configuration to prevent any further config */
+  _sg_cfg_init_status = 2; /* horrible hack: direct access to the global
+                            * controlling the level of configuration to prevent
+                            * any further config */
 
   /* search the routing model */
   switch(AS->routing){
 
   /* search the routing model */
   switch(AS->routing){
@@ -387,7 +397,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
 
   info->p_rcComponent = new_as->p_routingFather;
   info->p_rcType = SURF_NETWORK_ELEMENT_AS;
 
   info->p_rcComponent = new_as->p_routingFather;
   info->p_rcType = SURF_NETWORK_ELEMENT_AS;
-  info->p_name = new_as->p_name;
+  info->p_name = xbt_strdup(new_as->p_name);
 
   xbt_lib_set(as_router_lib, info->p_name, ROUTING_ASR_LEVEL,
               (void *) info);
 
   xbt_lib_set(as_router_lib, info->p_name, ROUTING_ASR_LEVEL,
               (void *) info);
@@ -410,7 +420,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
  * even if you add stuff to a closed AS
  *
  */
  * even if you add stuff to a closed AS
  *
  */
-void routing_AS_end(sg_platf_AS_cbarg_t AS)
+void routing_AS_end(sg_platf_AS_cbarg_t /*AS*/)
 {
 
   if (current_routing == NULL) {
 {
 
   if (current_routing == NULL) {
@@ -440,15 +450,15 @@ static void elements_father(sg_routing_edge_t src, sg_routing_edge_t dst,
 {
   xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
 #define ELEMENTS_FATHER_MAXDEPTH 16     /* increase if it is not enough */
 {
   xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
 #define ELEMENTS_FATHER_MAXDEPTH 16     /* increase if it is not enough */
-  AS_t src_as, dst_as;
-  AS_t path_src[ELEMENTS_FATHER_MAXDEPTH];
-  AS_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
+  AsPtr src_as, dst_as;
+  AsPtr path_src[ELEMENTS_FATHER_MAXDEPTH];
+  AsPtr path_dst[ELEMENTS_FATHER_MAXDEPTH];
   int index_src = 0;
   int index_dst = 0;
   int index_src = 0;
   int index_dst = 0;
-  AS_t current;
-  AS_t current_src;
-  AS_t current_dst;
-  AS_t father;
+  AsPtr current;
+  AsPtr current_src;
+  AsPtr current_dst;
+  AsPtr father;
 
   /* (1) find the as where the src and dst are located */
   sg_routing_edge_t src_data = src;
 
   /* (1) find the as where the src and dst are located */
   sg_routing_edge_t src_data = src;
@@ -526,6 +536,7 @@ static void _get_route_and_latency(RoutingEdgePtr src, RoutingEdgePtr dst,
   /* Check whether a direct bypass is defined */
   sg_platf_route_cbarg_t e_route_bypass = NULL;
   //FIXME:REMOVE:if (common_father->get_bypass_route)
   /* Check whether a direct bypass is defined */
   sg_platf_route_cbarg_t e_route_bypass = NULL;
   //FIXME:REMOVE:if (common_father->get_bypass_route)
+
   e_route_bypass = common_father->getBypassRoute(src, dst, latency);
 
   /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
   e_route_bypass = common_father->getBypassRoute(src, dst, latency);
 
   /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
@@ -609,7 +620,11 @@ void RoutingPlatf::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
              "negative latency on route between \"%s\" and \"%s\"", src->p_name, dst->p_name);
 }
 
              "negative latency on route between \"%s\" and \"%s\"", src->p_name, dst->p_name);
 }
 
-static xbt_dynar_t recursive_get_onelink_routes(AsPtr rc)
+xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
+  return recursiveGetOneLinkRoutes(p_root);
+}
+
+xbt_dynar_t RoutingPlatf::recursiveGetOneLinkRoutes(AsPtr rc)
 {
   xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
 
 {
   xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
 
@@ -623,18 +638,13 @@ static xbt_dynar_t recursive_get_onelink_routes(AsPtr rc)
   xbt_dict_cursor_t cursor = NULL;
   AS_t rc_child;
   xbt_dict_foreach(rc->p_routingSons, cursor, key, rc_child) {
   xbt_dict_cursor_t cursor = NULL;
   AS_t rc_child;
   xbt_dict_foreach(rc->p_routingSons, cursor, key, rc_child) {
-    xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
+    xbt_dynar_t onelink_child = recursiveGetOneLinkRoutes(rc_child);
     if (onelink_child)
       xbt_dynar_merge(&ret,&onelink_child);
   }
   return ret;
 }
 
     if (onelink_child)
       xbt_dynar_merge(&ret,&onelink_child);
   }
   return ret;
 }
 
-static xbt_dynar_t get_onelink_routes(void)
-{
-  return recursive_get_onelink_routes(routing_platf->p_root);
-}
-
 e_surf_network_element_type_t routing_get_network_element_type(const char *name)
 {
   RoutingEdgePtr rc = sg_routing_edge_by_name_or_null(name);
 e_surf_network_element_type_t routing_get_network_element_type(const char *name)
 {
   RoutingEdgePtr rc = sg_routing_edge_by_name_or_null(name);
@@ -654,8 +664,7 @@ void routing_model_create( void *loopback)
   /* config the uniq global routing */
   routing_platf = new RoutingPlatf();
   routing_platf->p_root = NULL;
   /* config the uniq global routing */
   routing_platf = new RoutingPlatf();
   routing_platf->p_root = NULL;
-  //FIXME:routing_platf->get_onelink_routes = get_onelink_routes;
-  //FIXME:routing_platf->loopback = loopback;
+  routing_platf->p_loopback = loopback;
   routing_platf->p_lastRoute = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
   /* no current routing at moment */
   current_routing = NULL;
   routing_platf->p_lastRoute = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
   /* no current routing at moment */
   current_routing = NULL;
@@ -711,9 +720,9 @@ void routing_model_create( void *loopback)
 void routing_cluster_add_backbone(void* bb) {
   xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER],
         "You have to be in model Cluster to use tag backbone!");
 void routing_cluster_add_backbone(void* bb) {
   xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER],
         "You have to be in model Cluster to use tag backbone!");
-  /*FIXME:xbt_assert(!((as_cluster_t)current_routing)->p_backbone, "The backbone link is already defined!");
-  ((as_cluster_t)current_routing)->p_backbone = bb;*/
-  XBT_DEBUG("Add a backbone to AS '%s'",current_routing->p_name);
+  xbt_assert(!surf_as_cluster_get_backbone(current_routing), "The backbone link is already defined!");
+  surf_as_cluster_set_backbone(current_routing, bb);
+  XBT_DEBUG("Add a backbone to AS '%s'", current_routing->p_name);
 }
 
 static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
 }
 
 static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
@@ -745,7 +754,7 @@ static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
     s_sg_platf_host_cbarg_t host;
     memset(&host, 0, sizeof(host));
     host.initial_state = SURF_RESOURCE_ON;
     s_sg_platf_host_cbarg_t host;
     memset(&host, 0, sizeof(host));
     host.initial_state = SURF_RESOURCE_ON;
-    host.power_peak = cabinet->power;
+    host.pstate = 0;
     host.power_scale = 1.0;
     host.core_amount = 1;
 
     host.power_scale = 1.0;
     host.core_amount = 1;
 
@@ -764,6 +773,9 @@ static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
       link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
       host.id = host_id;
       link.id = link_id;
       link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
       host.id = host_id;
       link.id = link_id;
+      xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+      xbt_dynar_push(power_state_list,&cabinet->power);
+      host.power_peak = power_state_list;
       sg_platf_new_host(&host);
       sg_platf_new_link(&link);
 
       sg_platf_new_host(&host);
       sg_platf_new_link(&link);
 
@@ -861,7 +873,12 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
         XBT_DEBUG("\tstate_file=\"\"");
       }
 
         XBT_DEBUG("\tstate_file=\"\"");
       }
 
-      host.power_peak = cluster->power;
+      xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+      xbt_dynar_push(power_state_list,&cluster->power);
+      host.power_peak = power_state_list;
+      host.pstate = 0;
+
+      //host.power_peak = cluster->power;
       host.power_scale = 1.0;
       host.core_amount = cluster->core_amount;
       host.initial_state = SURF_RESOURCE_ON;
       host.power_scale = 1.0;
       host.core_amount = cluster->core_amount;
       host.initial_state = SURF_RESOURCE_ON;
@@ -995,23 +1012,37 @@ static void routing_parse_postparse(void) {
 static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
 {
   char *host_id = NULL;
 static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
 {
   char *host_id = NULL;
-  char *link_id;
+  char *link_id = NULL;
+  char *router_id = NULL;
 
   XBT_DEBUG(" ");
   host_id = HOST_PEER(peer->id);
   link_id = LINK_PEER(peer->id);
 
   XBT_DEBUG(" ");
   host_id = HOST_PEER(peer->id);
   link_id = LINK_PEER(peer->id);
+  router_id = ROUTER_PEER(peer->id);
+
+  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
+  s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
+  AS.id = peer->id;
+  AS.routing = A_surfxml_AS_routing_Cluster;
+  sg_platf_new_AS_begin(&AS);
+
+  current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
 
   XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->power);
   s_sg_platf_host_cbarg_t host;
   memset(&host, 0, sizeof(host));
   host.initial_state = SURF_RESOURCE_ON;
   host.id = host_id;
 
   XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->power);
   s_sg_platf_host_cbarg_t host;
   memset(&host, 0, sizeof(host));
   host.initial_state = SURF_RESOURCE_ON;
   host.id = host_id;
-  host.power_peak = peer->power;
+
+  xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+  xbt_dynar_push(power_state_list,&peer->power);
+  host.power_peak = power_state_list;
+  host.pstate = 0;
+  //host.power_peak = peer->power;
   host.power_scale = 1.0;
   host.power_trace = peer->availability_trace;
   host.state_trace = peer->state_trace;
   host.core_amount = 1;
   host.power_scale = 1.0;
   host.power_trace = peer->availability_trace;
   host.state_trace = peer->state_trace;
   host.core_amount = 1;
-  host.coord = peer->coord;
   sg_platf_new_host(&host);
 
   s_sg_platf_link_cbarg_t link;
   sg_platf_new_host(&host);
 
   s_sg_platf_link_cbarg_t link;
@@ -1042,9 +1073,20 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
   host_link.link_down= link_down;
   sg_platf_new_host_link(&host_link);
 
   host_link.link_down= link_down;
   sg_platf_new_host_link(&host_link);
 
+  XBT_DEBUG("<router id=\"%s\"/>", router_id);
+  s_sg_platf_router_cbarg_t router;
+  memset(&router, 0, sizeof(router));
+  router.id = router_id;
+  router.coord = peer->coord;
+  sg_platf_new_router(&router);
+  static_cast<AsClusterPtr>(current_routing)->p_router = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
+
+  XBT_DEBUG("</AS>");
+  sg_platf_new_AS_end();
   XBT_DEBUG(" ");
 
   //xbt_dynar_free(&tab_elements_num);
   XBT_DEBUG(" ");
 
   //xbt_dynar_free(&tab_elements_num);
+  free(router_id);
   free(host_id);
   free(link_id);
   free(link_up);
   free(host_id);
   free(link_id);
   free(link_up);
@@ -1221,11 +1263,13 @@ static void finalize_rec(AsPtr as) {
 
 /** \brief Frees all memory allocated by the routing module */
 void routing_exit(void) {
 
 /** \brief Frees all memory allocated by the routing module */
 void routing_exit(void) {
-  if (!routing_platf)
-    return;
-  xbt_dynar_free(&routing_platf->p_lastRoute);
-  finalize_rec(routing_platf->p_root);
-  xbt_free(routing_platf);
+  delete routing_platf;
+}
+
+RoutingPlatf::~RoutingPlatf()
+{
+       xbt_dynar_free(&p_lastRoute);
+       finalize_rec(p_root);
 }
 
 AS_t surf_AS_get_routing_root() {
 }
 
 AS_t surf_AS_get_routing_root() {