Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Remove sg_platf_ASRoute_cb
[simgrid.git] / src / surf / surf_routing.cpp
index 1a63ab6..63daeda 100644 (file)
 
 #include "surf/surfxml_parse_values.h"
 
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, RoutingEdge*) routingEdgeCreatedCallbacks;
+surf_callback(void, As*) asCreatedCallbacks;
 
 /**
  * @ingroup SURF_build_api
@@ -56,14 +62,19 @@ RoutingEdge *sg_routing_edge_by_name_or_null(const char *name) {
 
 /* Global vars */
 RoutingPlatf *routing_platf = NULL;
-As *current_routing = NULL;
 
 /* global parse functions */
 extern xbt_dynar_t mount_list;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 
-static void routing_parse_peer(sg_platf_peer_cbarg_t peer);     /* peer bypass */
+/** The current AS in the parsing */
+static As *current_routing = NULL;
+As* routing_get_current()
+{
+  return current_routing;
+}
+
 // static void routing_parse_Srandom(void);        /* random bypass */
 
 static void routing_parse_postparse(void);
@@ -110,7 +121,7 @@ struct s_model_type routing_models[] = {
 /**
  * \brief Add a "host_link" to the network element list
  */
-static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
+void sg_platf_new_host_link(sg_platf_host_link_cbarg_t host)
 {
   RoutingEdge *info = sg_host_edge(sg_host_by_name(host->id));
   xbt_assert(info, "Host '%s' not found!", host->id);
@@ -140,20 +151,21 @@ static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
 /**
  * \brief Add a "host" to the network element list
  */
-static void parse_S_host(sg_platf_host_cbarg_t host)
+RoutingEdge *routing_add_host(As* current_routing, sg_platf_host_cbarg_t host)
 {
   if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
     current_routing->p_hierarchy = SURF_ROUTING_BASE;
   xbt_assert(!sg_host_by_name(host->id),
                     "Reading a host, processing unit \"%s\" already exists", host->id);
 
-  RoutingEdge *info = new RoutingEdgeImpl(xbt_strdup(host->id),
+  RoutingEdge *routingEdge = new RoutingEdgeImpl(xbt_strdup(host->id),
                                                    -1,
                                                    SURF_NETWORK_ELEMENT_HOST,
                                                    current_routing);
-  info->setId(current_routing->parsePU(info));
-  sg_host_edge_set(sg_host_by_name_or_create(host->id), info);
-  XBT_DEBUG("Having set name '%s' id '%d'", host->id, info->getId());
+  routingEdge->setId(current_routing->parsePU(routingEdge));
+  sg_host_edge_set(sg_host_by_name_or_create(host->id), routingEdge);
+  XBT_DEBUG("Having set name '%s' id '%d'", host->id, routingEdge->getId());
+  routingEdgeCreatedCallbacks(routingEdge);
 
   if(mount_list){
     xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
@@ -178,57 +190,8 @@ static void parse_S_host(sg_platf_host_cbarg_t host)
     xbt_lib_set(host_lib, host->id, COORD_HOST_LEVEL, (void *) ctn);
     XBT_DEBUG("Having set host coordinates for '%s'",host->id);
   }
-}
 
-/**
- * \brief Add a "router" to the network element list
- */
-static void parse_S_router(sg_platf_router_cbarg_t router)
-{
-  if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
-    current_routing->p_hierarchy = SURF_ROUTING_BASE;
-  xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
-             "Reading a router, processing unit \"%s\" already exists",
-             router->id);
-
-  RoutingEdge *info = new RoutingEdgeImpl(xbt_strdup(router->id),
-                                            -1,
-                                            SURF_NETWORK_ELEMENT_ROUTER,
-                                            current_routing);
-  info->setId(current_routing->parsePU(info));
-  xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
-  XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->getId());
-
-  if (router->coord && strcmp(router->coord, "")) {
-    unsigned int cursor;
-    char*str;
-
-    if (!COORD_ASR_LEVEL)
-      xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
-    /* Pre-parse the host coordinates */
-    xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " ");
-    xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
-    xbt_dynar_foreach(ctn_str,cursor, str) {
-      double val = atof(str);
-      xbt_dynar_push(ctn,&val);
-    }
-    xbt_dynar_shrink(ctn, 0);
-    xbt_dynar_free(&ctn_str);
-    xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn);
-    XBT_DEBUG("Having set router coordinates for '%s'",router->id);
-  }
-}
-
-/**
- * \brief Store the route by calling the set_route function of the current routing component
- */
-static void parse_E_route(sg_platf_route_cbarg_t route)
-{
-  /*FIXME:REMOVE:xbt_assert(current_routing->parse_route,
-             "no defined method \"set_route\" in \"%s\"",
-             current_routing->name);*/
-
-  current_routing->parseRoute(route);
+  return routingEdge;
 }
 
 /**
@@ -242,30 +205,7 @@ static void parse_E_ASroute(sg_platf_route_cbarg_t ASroute)
   current_routing->parseASroute(ASroute);
 }
 
-/**
- * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
- */
-static void parse_E_bypassRoute(sg_platf_route_cbarg_t route)
-{
-  /*FIXME:REMOVE:xbt_assert(current_routing->parse_bypassroute,
-             "Bypassing mechanism not implemented by routing '%s'",
-             current_routing->name);*/
-
-  current_routing->parseBypassroute(route);
-}
-
-/**
- * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
- */
-static void parse_E_bypassASroute(sg_platf_route_cbarg_t ASroute)
-{
-  /*FIXME:REMOVE:xbt_assert(current_routing->parse_bypassroute,
-             "Bypassing mechanism not implemented by routing '%s'",
-             current_routing->name);*/
-  current_routing->parseBypassroute(ASroute);
-}
-
-static void routing_parse_trace(sg_platf_trace_cbarg_t trace)
+void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
 {
   tmgr_trace_t tmgr_trace;
   if (!trace->file || strcmp(trace->file, "") != 0) {
@@ -280,7 +220,7 @@ static void routing_parse_trace(sg_platf_trace_cbarg_t trace)
   xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL);
 }
 
-static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
+void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
 {
   xbt_assert(xbt_dict_get_or_null
               (traces_set_list, trace_connect->trace),
@@ -404,6 +344,8 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
   current_routing = new_as;
   current_routing->p_netElem = info;
 
+  routingEdgeCreatedCallbacks(info);
+  asCreatedCallbacks(new_as);
 }
 
 /**
@@ -417,7 +359,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
  * even if you add stuff to a closed AS
  *
  */
-void routing_AS_end(sg_platf_AS_cbarg_t /*AS*/)
+void routing_AS_end()
 {
 
   if (current_routing == NULL) {
@@ -722,7 +664,7 @@ void routing_cluster_add_backbone(void* bb) {
   XBT_DEBUG("Add a backbone to AS '%s'", current_routing->p_name);
 }
 
-static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
+void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
 {
   int start, end, i;
   char *groups , *host_id , *link_id = NULL;
@@ -770,10 +712,10 @@ 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;
-      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;
+      host.power_peak = xbt_dynar_new(sizeof(double), NULL);
+      xbt_dynar_push(host.power_peak,&cabinet->power);
       sg_platf_new_host(&host);
+      xbt_dynar_free(&host.power_peak);
       sg_platf_new_link(&link);
 
       char* link_up       = bprintf("%s_UP",link_id);
@@ -912,9 +854,8 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
         XBT_DEBUG("\tstate_file=\"\"");
       }
 
-      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.power_peak = xbt_dynar_new(sizeof(double), NULL);
+      xbt_dynar_push(host.power_peak,&cluster->power);
       host.pstate = 0;
 
       //host.power_peak = cluster->power;
@@ -923,6 +864,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
       host.initial_state = SURF_RESOURCE_ON;
       host.coord = "";
       sg_platf_new_host(&host);
+      xbt_dynar_free(&host.power_peak);
       XBT_DEBUG("</host>");
 
       XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,
@@ -1051,7 +993,7 @@ static void routing_parse_postparse(void) {
   xbt_dict_free(&random_value);
 }
 
-static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
+void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
 {
   char *host_id = NULL;
   char *link_id = NULL;
@@ -1076,9 +1018,8 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
   host.initial_state = SURF_RESOURCE_ON;
   host.id = host_id;
 
-  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.power_peak = xbt_dynar_new(sizeof(double), NULL);
+  xbt_dynar_push(host.power_peak,&peer->power);
   host.pstate = 0;
   //host.power_peak = peer->power;
   host.power_scale = 1.0;
@@ -1086,6 +1027,7 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
   host.state_trace = peer->state_trace;
   host.core_amount = 1;
   sg_platf_new_host(&host);
+  xbt_dynar_free(&host.power_peak);
 
   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
   memset(&link, 0, sizeof(link));
@@ -1273,28 +1215,11 @@ static void check_disk_attachment()
 
 void routing_register_callbacks()
 {
-  sg_platf_host_add_cb(parse_S_host);
-  sg_platf_router_add_cb(parse_S_router);
-  sg_platf_host_link_add_cb(parse_S_host_link);
-  sg_platf_route_add_cb(parse_E_route);
-  sg_platf_ASroute_add_cb(parse_E_ASroute);
-  sg_platf_bypassRoute_add_cb(parse_E_bypassRoute);
-  sg_platf_bypassASroute_add_cb(parse_E_bypassASroute);
-
   sg_platf_cluster_add_cb(routing_parse_cluster);
-  sg_platf_cabinet_add_cb(routing_parse_cabinet);
 
-  sg_platf_peer_add_cb(routing_parse_peer);
   sg_platf_postparse_add_cb(routing_parse_postparse);
   sg_platf_postparse_add_cb(check_disk_attachment);
 
-  /* we care about the ASes while parsing the platf. Incredible, isnt it? */
-  sg_platf_AS_end_add_cb(routing_AS_end);
-  sg_platf_AS_begin_add_cb(routing_AS_begin);
-
-  sg_platf_trace_add_cb(routing_parse_trace);
-  sg_platf_trace_connect_add_cb(routing_parse_trace_connect);
-
   instr_routing_define_callbacks();
 }