Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a bit more method chaining in the internals
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 24 Feb 2021 16:47:32 +0000 (17:47 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 24 Feb 2021 17:09:56 +0000 (18:09 +0100)
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/kernel/routing/WifiZone.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Link.hpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/WifiZone.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/surf/sg_platf.cpp

index 52b88e4..62c25c3 100644 (file)
@@ -120,12 +120,10 @@ public:
   int get_host_count() const;
 
   /** @brief Make a host within that NetZone */
-  s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate, int core_count,
-                         const std::unordered_map<std::string, std::string>* props);
+  s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate, int core_count);
   /** @brief Make a link within that NetZone */
   virtual s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths, double latency,
-                                 s4u::Link::SharingPolicy policy,
-                                 const std::unordered_map<std::string, std::string>* props);
+                                 s4u::Link::SharingPolicy policy);
   /** @brief Creates a new route in this NetZone */
   virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                                 std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
index c695e6e..f08aa1f 100644 (file)
@@ -28,8 +28,7 @@ public:
   void seal() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths, double latency,
-                         s4u::Link::SharingPolicy policy,
-                         const std::unordered_map<std::string, std::string>* props) override;
+                         s4u::Link::SharingPolicy policy) override;
   NetPoint* get_access_point() {return access_point_;}
 
 private:
index fe1dcc4..6c909ec 100644 (file)
@@ -46,7 +46,7 @@ public:
 
 protected:
   virtual ~Host(); // Call destroy() instead of manually deleting it.
-  void set_netpoint(kernel::routing::NetPoint* netpoint) { pimpl_netpoint_ = netpoint; }
+  Host* set_netpoint(kernel::routing::NetPoint* netpoint);
 #endif
 
 public:
@@ -100,9 +100,9 @@ public:
   bool is_on() const;
 
   const char* get_property(const std::string& key) const;
-  void set_property(const std::string& key, const std::string& value);
+  Host* set_property(const std::string& key, const std::string& value);
   const std::unordered_map<std::string, std::string>* get_properties() const;
-  void set_properties(const std::unordered_map<std::string, std::string>& properties);
+  Host* set_properties(const std::unordered_map<std::string, std::string>& properties);
 
   void set_state_profile(kernel::profile::Profile* p);
   void set_speed_profile(kernel::profile::Profile* p);
index d3f06f4..58e2612 100644 (file)
@@ -101,7 +101,9 @@ public:
   void set_latency_profile(kernel::profile::Profile* profile);
 
   const char* get_property(const std::string& key) const;
-  void set_property(const std::string& key, const std::string& value);
+  Link* set_property(const std::string& key, const std::string& value);
+  const std::unordered_map<std::string, std::string>* get_properties() const;
+  Link* set_properties(const std::unordered_map<std::string, std::string>& properties);
 
   /* The signals */
   /** @brief Callback signal fired when a new Link is created */
index ec9c601..215fe47 100644 (file)
@@ -66,8 +66,7 @@ int NetZoneImpl::get_host_count() const
 }
 
 s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<double>& bandwidths, double latency,
-                                    s4u::Link::SharingPolicy policy,
-                                    const std::unordered_map<std::string, std::string>* props)
+                                    s4u::Link::SharingPolicy policy)
 {
   static double last_warned_latency = sg_surf_precision;
   if (latency != 0.0 && latency < last_warned_latency) {
@@ -79,28 +78,19 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<d
 
   auto* l = surf_network_model->create_link(name, bandwidths, latency, policy);
 
-  if (props)
-    l->set_properties(*props);
-
   return l->get_iface();
 }
+
 s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate,
-                                    int coreAmount, const std::unordered_map<std::string, std::string>* props)
+                                    int coreAmount)
 {
-  auto* res = new s4u::Host(name);
-
   if (hierarchy_ == RoutingMode::unset)
     hierarchy_ = RoutingMode::base;
 
-  res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this));
+  auto* res = (new s4u::Host(name))->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this));
 
   surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount);
 
-  if (props != nullptr)
-    res->set_properties(*props);
-
-  s4u::Host::on_creation(*res); // notify the signal
-
   return res;
 }
 
index 5eae791..5296561 100644 (file)
@@ -56,15 +56,14 @@ void WifiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
   }
 }
 s4u::Link* WifiZone::create_link(const std::string& name, const std::vector<double>& bandwidths, double latency,
-                                 s4u::Link::SharingPolicy policy,
-                                 const std::unordered_map<std::string, std::string>* props)
+                                 s4u::Link::SharingPolicy policy)
 {
   xbt_assert(wifi_link_ == nullptr,
              "WIFI netzone %s contains more than one link. Please only declare one, the wifi link.", get_cname());
   xbt_assert(policy == s4u::Link::SharingPolicy::WIFI, "Link %s in WIFI zone %s must follow the WIFI sharing policy.",
              name.c_str(), get_cname());
 
-  auto s4u_link = NetZoneImpl::create_link(name, bandwidths, latency, policy, props);
+  auto s4u_link = NetZoneImpl::create_link(name, bandwidths, latency, policy);
   wifi_link_    = s4u_link->get_impl();
   return s4u_link;
 }
index becb093..b87640b 100644 (file)
@@ -37,6 +37,12 @@ Host::Host(const std::string& name) : name_(name)
   new surf::HostImpl(this);
 }
 
+Host* Host::set_netpoint(kernel::routing::NetPoint* netpoint)
+{
+  pimpl_netpoint_ = netpoint;
+  return this;
+}
+
 Host::~Host()
 {
   delete pimpl_;
@@ -192,14 +198,16 @@ const char* Host::get_property(const std::string& key) const
   return this->pimpl_->get_property(key);
 }
 
-void Host::set_property(const std::string& key, const std::string& value)
+Host* Host::set_property(const std::string& key, const std::string& value)
 {
   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
+  return this;
 }
 
-void Host::set_properties(const std::unordered_map<std::string, std::string>& properties)
+Host* Host::set_properties(const std::unordered_map<std::string, std::string>& properties)
 {
   kernel::actor::simcall([this, &properties] { this->pimpl_->set_properties(properties); });
+  return this;
 }
 
 /** Specify a profile turning the host on and off according to an exhaustive list or a stochastic law.
index 6d71cf2..59cee96 100644 (file)
@@ -126,10 +126,23 @@ const char* Link::get_property(const std::string& key) const
 {
   return this->pimpl_->get_property(key);
 }
-void Link::set_property(const std::string& key, const std::string& value)
+Link* Link::set_property(const std::string& key, const std::string& value)
 {
   simgrid::kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
+  return this;
 }
+
+const std::unordered_map<std::string, std::string>* Link::get_properties() const
+{
+  return this->pimpl_->get_properties();
+}
+
+Link* Link::set_properties(const std::unordered_map<std::string, std::string>& properties)
+{
+  kernel::actor::simcall([this, &properties] { this->pimpl_->set_properties(properties); });
+  return this;
+}
+
 } // namespace s4u
 } // namespace simgrid
 
index 809225f..2995790 100644 (file)
@@ -66,16 +66,13 @@ void sg_platf_exit() {
 /** @brief Add a host to the current AS */
 void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args)
 {
-  std::unordered_map<std::string, std::string> props;
+  simgrid::s4u::Host* host = routing_get_current()->create_host(args->id, args->speed_per_pstate, args->core_amount);
+
   if (args->properties) {
-    for (auto const& elm : *args->properties)
-      props.insert({elm.first, elm.second});
+    host->set_properties(*args->properties);
     delete args->properties;
   }
 
-  simgrid::s4u::Host* host =
-      routing_get_current()->create_host(args->id, args->speed_per_pstate, args->core_amount, &props);
-
   host->pimpl_->set_disks(args->disks, host);
 
   /* Change from the defaults */
@@ -87,6 +84,8 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args)
     host->set_pstate(args->pstate);
   if (not args->coord.empty())
     new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord);
+
+  simgrid::s4u::Host::on_creation(*host); // notify the signal
 }
 
 /** @brief Add a "router" to the network element list */
@@ -110,13 +109,10 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name,
 
 static void sg_platf_new_link(const simgrid::kernel::routing::LinkCreationArgs* args, const std::string& link_name)
 {
-  std::unordered_map<std::string, std::string> props;
-  if (args->properties)
-    for (auto const& elm : *args->properties)
-      props.insert({elm.first, elm.second});
+  simgrid::s4u::Link* link = routing_get_current()->create_link(link_name, args->bandwidths, args->latency, args->policy);
 
-  const simgrid::s4u::Link* link =
-      routing_get_current()->create_link(link_name, args->bandwidths, args->latency, args->policy, &props);
+  if (args->properties)
+    link->set_properties(*args->properties);
 
   simgrid::kernel::resource::LinkImpl* l = link->get_impl();
   if (args->latency_trace)
@@ -425,7 +421,7 @@ void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer)
 
   std::vector<double> speed_per_pstate;
   speed_per_pstate.push_back(peer->speed);
-  simgrid::s4u::Host* host = as->create_host(peer->id, speed_per_pstate, 1, nullptr);
+  simgrid::s4u::Host* host = as->create_host(peer->id, speed_per_pstate, 1);
 
   as->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out, peer->coord);
 
@@ -434,6 +430,7 @@ void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer)
     host->set_state_profile(peer->state_trace);
   if (peer->speed_trace)
     host->set_speed_profile(peer->speed_trace);
+  simgrid::s4u::Host::on_creation(*host); // notify the signal
 }
 
 /* Pick the right models for CPU, net and host, and call their model_init_preparse */