Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / surf / sg_platf.cpp
index 8742488..3dff876 100644 (file)
@@ -21,7 +21,7 @@
 #include "src/kernel/routing/FatTreeZone.hpp"
 #include "src/kernel/routing/FloydZone.hpp"
 #include "src/kernel/routing/FullZone.hpp"
-#include "src/kernel/routing/NetCard.hpp"
+#include "src/kernel/routing/NetPoint.hpp"
 #include "src/kernel/routing/NetZoneImpl.hpp"
 #include "src/kernel/routing/TorusZone.hpp"
 #include "src/kernel/routing/VivaldiZone.hpp"
@@ -65,20 +65,22 @@ void sg_platf_exit() {
 /** @brief Add an host to the current AS */
 void sg_platf_new_host(sg_platf_host_cbarg_t args)
 {
-  simgrid::s4u::Host* host = routing_get_current()->createHost(args->id, &args->speed_per_pstate, args->core_amount);
-
-  new simgrid::surf::HostImpl(host, mount_list);
-  xbt_lib_set(storage_lib, args->id, ROUTING_STORAGE_HOST_LEVEL, static_cast<void*>(mount_list));
-  mount_list = nullptr;
-
+  std::unordered_map<std::string, std::string> props;
   if (args->properties) {
     xbt_dict_cursor_t cursor=nullptr;
     char *key,*data;
     xbt_dict_foreach (args->properties, cursor, key, data)
-      host->setProperty(key, data);
+      props[key] = data;
     xbt_dict_free(&args->properties);
   }
 
+  simgrid::s4u::Host* host =
+      routing_get_current()->createHost(args->id, &args->speed_per_pstate, args->core_amount, &props);
+
+  host->pimpl_->storage_ = mount_list;
+  xbt_lib_set(storage_lib, args->id, ROUTING_STORAGE_HOST_LEVEL, static_cast<void*>(mount_list));
+  mount_list = nullptr;
+
   /* Change from the defaults */
   if (args->state_trace)
     host->pimpl_cpu->setStateTrace(args->state_trace);
@@ -87,33 +89,32 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args)
   if (args->pstate != 0)
     host->pimpl_cpu->setPState(args->pstate);
   if (args->coord && strcmp(args->coord, ""))
-    new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netcard, args->coord);
-
-  simgrid::s4u::Host::onCreation(*host);
+    new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netpoint, args->coord);
 
   if (TRACE_is_enabled() && TRACE_needs_platform())
     sg_instr_new_host(*host);
 }
 
 /** @brief Add a "router" to the network element list */
-void sg_platf_new_router(sg_platf_router_cbarg_t router)
+simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const char* coords)
 {
   simgrid::kernel::routing::NetZoneImpl* current_routing = routing_get_current();
 
   if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base;
-  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(router->id),
-             "Refusing to create a router named '%s': this name already describes a node.", router->id);
+  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(name),
+             "Refusing to create a router named '%s': this name already describes a node.", name);
 
-  simgrid::kernel::routing::NetCard* netcard =
-    new simgrid::kernel::routing::NetCard(router->id, simgrid::kernel::routing::NetCard::Type::Router, current_routing);
-  XBT_DEBUG("Router '%s' has the id %d", router->id, netcard->id());
+  simgrid::kernel::routing::NetPoint* netcard =
+      new simgrid::kernel::routing::NetPoint(name, simgrid::kernel::routing::NetPoint::Type::Router, current_routing);
+  XBT_DEBUG("Router '%s' has the id %d", name, netcard->id());
 
-  if (router->coord && strcmp(router->coord, ""))
-    new simgrid::kernel::routing::vivaldi::Coords(netcard, router->coord);
+  if (coords && strcmp(coords, ""))
+    new simgrid::kernel::routing::vivaldi::Coords(netcard, coords);
 
-  if (TRACE_is_enabled() && TRACE_needs_platform())
-    sg_instr_new_router(router);
+  sg_instr_new_router(name);
+
+  return netcard;
 }
 
 void sg_platf_new_link(sg_platf_link_cbarg_t link){
@@ -279,15 +280,13 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   // Add a router.
   XBT_DEBUG(" ");
   XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
-  char *newid = nullptr;
-  s_sg_platf_router_cbarg_t router;
-  memset(&router, 0, sizeof(router));
-  router.id = cluster->router_id;
-  if (!router.id || !strcmp(router.id, ""))
-    router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
-  sg_platf_new_router(&router);
-  current_as->router_ = simgrid::s4u::Engine::instance()->netcardByNameOrNull(router.id);
-  free(newid);
+  if (!cluster->router_id || !strcmp(cluster->router_id, "")) {
+    char* newid         = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
+    current_as->router_ = sg_platf_new_router(newid, NULL);
+    free(newid);
+  } else {
+    current_as->router_ = sg_platf_new_router(cluster->router_id, NULL);
+  }
 
   //Make the backbone
   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
@@ -556,10 +555,9 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
 
   std::vector<double> speedPerPstate;
   speedPerPstate.push_back(peer->speed);
-  simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1);
+  simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1, nullptr);
 
-  as->setPeerLink(host->pimpl_netcard, peer->bw_in, peer->bw_out, peer->coord);
-  simgrid::s4u::Host::onCreation(*host);
+  as->setPeerLink(host->pimpl_netpoint, peer->bw_in, peer->bw_out, peer->coord);
 
   /* Change from the defaults */
   if (peer->state_trace)
@@ -722,7 +720,7 @@ void sg_platf_new_AS_seal()
 /** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
 void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink)
 {
-  simgrid::kernel::routing::NetCard *netcard = sg_host_by_name(hostlink->id)->pimpl_netcard;
+  simgrid::kernel::routing::NetPoint* netcard = sg_host_by_name(hostlink->id)->pimpl_netpoint;
   xbt_assert(netcard, "Host '%s' not found!", hostlink->id);
   xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
              "Only hosts from Cluster and Vivaldi ASes can get an host_link.");