Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
useless cosmetics around the host creation
[simgrid.git] / src / surf / sg_platf.cpp
index 632ae08..f5df970 100644 (file)
@@ -19,6 +19,7 @@
 #include "src/include/simgrid/sg_config.h"
 #include "src/surf/xml/platf_private.hpp"
 
+#include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "surf/surf_routing.h" // FIXME: brain dead public header
@@ -72,67 +73,43 @@ void sg_platf_exit() {
   surf_parse_lex_destroy();
 }
 
-/** @brief Add an "host" to the current AS */
-void sg_platf_new_host(sg_platf_host_cbarg_t host)
+/** @brief Add an host to the current AS */
+void sg_platf_new_host(sg_platf_host_cbarg_t hostArgs)
 {
-  xbt_assert(sg_host_by_name(host->id) == nullptr, "Refusing to create a second host named '%s'.", host->id);
-
   simgrid::kernel::routing::AsImpl* current_routing = routing_get_current();
-  if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset)
-    current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::base;
-
-  simgrid::kernel::routing::NetCard *netcard =
-      new simgrid::kernel::routing::NetCardImpl(host->id, simgrid::kernel::routing::NetCard::Type::Host, current_routing);
 
-  sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
-  h->pimpl_netcard = netcard;
-
-  if(mount_list) {
-    xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
-    mount_list = nullptr;
-  }
-
-  if (host->coord && strcmp(host->coord, "")) {
-    unsigned int cursor;
-    char*str;
+  simgrid::s4u::Host* host = new simgrid::s4u::Host(hostArgs->id);
+  current_routing->attachHost(host);
 
-    xbt_assert(COORD_HOST_LEVEL, "To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
-    /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/
-    xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
-    xbt_assert(xbt_dynar_length(ctn_str)==3,"Coordinates of %s must have 3 dimensions", host->id);
+  if (hostArgs->coord && strcmp(hostArgs->coord, ""))
+    new simgrid::kernel::routing::vivaldi::Coords(host, hostArgs->coord);
 
-    xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),nullptr);
-    xbt_dynar_foreach(ctn_str,cursor, str) {
-      double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
-      xbt_dynar_push(ctn,&val);
-    }
-    xbt_dynar_free(&ctn_str);
-    xbt_dynar_shrink(ctn, 0);
-    h->extension_set(COORD_HOST_LEVEL, (void *) ctn);
-  }
+  surf_cpu_model_pm->createCpu(host, &hostArgs->speed_per_pstate, hostArgs->core_amount);
 
-  simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h, &host->speed_per_pstate, host->core_amount);
-  if (host->state_trace)
-    cpu->setStateTrace(host->state_trace);
-  if (host->speed_trace)
-    cpu->setSpeedTrace(host->speed_trace);
-  surf_host_model->createHost(host->id, netcard, cpu)->attach(h);
+  new simgrid::surf::HostImpl(host, mount_list);
+  xbt_lib_set(storage_lib, hostArgs->id, ROUTING_STORAGE_HOST_LEVEL, static_cast<void*>(mount_list));
+  mount_list = nullptr;
 
-  if (host->properties) {
+  if (hostArgs->properties) {
     xbt_dict_cursor_t cursor=nullptr;
     char *key,*data;
-    xbt_dict_foreach(host->properties,cursor,key,data)
-      h->setProperty(key,data);
-    xbt_dict_free(&host->properties);
+    xbt_dict_foreach (hostArgs->properties, cursor, key, data)
+      host->setProperty(key, data);
+    xbt_dict_free(&hostArgs->properties);
   }
 
-  if (host->pstate != 0)
-    cpu->setPState(host->pstate);
+  /* Change from the default */
+  if (hostArgs->state_trace)
+    host->pimpl_cpu->setStateTrace(hostArgs->state_trace);
+  if (hostArgs->speed_trace)
+    host->pimpl_cpu->setSpeedTrace(hostArgs->speed_trace);
+  if (hostArgs->pstate != 0)
+    host->pimpl_cpu->setPState(hostArgs->pstate);
 
-  simgrid::s4u::Host::onCreation(*h);
+  simgrid::s4u::Host::onCreation(*host);
 
   if (TRACE_is_enabled() && TRACE_needs_platform())
-    sg_instr_new_host(host);
+    sg_instr_new_host(*host);
 }
 
 /** @brief Add a "router" to the network element list */
@@ -846,6 +823,6 @@ void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink)
   if (as_cluster->privateLinks_.find(netcard->id()) != as_cluster->privateLinks_.end())
     surf_parse_error("Host_link for '%s' is already defined!",hostlink->id);
 
-  XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name(), netcard->id());
+  XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name().c_str(), netcard->id());
   as_cluster->privateLinks_.insert({netcard->id(), link_up_down});
 }