Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow users to retrieve hosts and links by the zone in which they have been declared
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Thu, 31 Mar 2022 02:14:56 +0000 (04:14 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Thu, 31 Mar 2022 02:14:56 +0000 (04:14 +0200)
examples/cpp/routing-get-clusters/s4u-routing-get-clusters.tesh
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/resource/StandardLinkImpl.cpp
src/kernel/resource/StandardLinkImpl.hpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/WifiZone.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp

index f03b745..4068163 100644 (file)
@@ -31,16 +31,28 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@) bob_cluster
 > [  0.000000] (maestro@)    node-0.simgrid.org
 > [  0.000000] (maestro@)    node-1.simgrid.org
-> [  0.000000] (maestro@)    node-2.simgrid.org
-> [  0.000000] (maestro@)    node-3.simgrid.org
-> [  0.000000] (maestro@)    node-4.simgrid.org
-> [  0.000000] (maestro@)    node-5.simgrid.org
-> [  0.000000] (maestro@)    node-6.simgrid.org
-> [  0.000000] (maestro@)    node-7.simgrid.org
-> [  0.000000] (maestro@)    node-8.simgrid.org
-> [  0.000000] (maestro@)    node-9.simgrid.org
 > [  0.000000] (maestro@)    node-10.simgrid.org
+> [  0.000000] (maestro@)    node-100.simgrid.org
+> [  0.000000] (maestro@)    node-101.simgrid.org
+> [  0.000000] (maestro@)    node-102.simgrid.org
+> [  0.000000] (maestro@)    node-103.simgrid.org
+> [  0.000000] (maestro@)    node-104.simgrid.org
+> [  0.000000] (maestro@)    node-105.simgrid.org
+> [  0.000000] (maestro@)    node-106.simgrid.org
+> [  0.000000] (maestro@)    node-107.simgrid.org
+> [  0.000000] (maestro@)    node-108.simgrid.org
+> [  0.000000] (maestro@)    node-109.simgrid.org
 > [  0.000000] (maestro@)    node-11.simgrid.org
+> [  0.000000] (maestro@)    node-110.simgrid.org
+> [  0.000000] (maestro@)    node-111.simgrid.org
+> [  0.000000] (maestro@)    node-112.simgrid.org
+> [  0.000000] (maestro@)    node-113.simgrid.org
+> [  0.000000] (maestro@)    node-114.simgrid.org
+> [  0.000000] (maestro@)    node-115.simgrid.org
+> [  0.000000] (maestro@)    node-116.simgrid.org
+> [  0.000000] (maestro@)    node-117.simgrid.org
+> [  0.000000] (maestro@)    node-118.simgrid.org
+> [  0.000000] (maestro@)    node-119.simgrid.org
 > [  0.000000] (maestro@)    node-12.simgrid.org
 > [  0.000000] (maestro@)    node-13.simgrid.org
 > [  0.000000] (maestro@)    node-14.simgrid.org
@@ -49,6 +61,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-17.simgrid.org
 > [  0.000000] (maestro@)    node-18.simgrid.org
 > [  0.000000] (maestro@)    node-19.simgrid.org
+> [  0.000000] (maestro@)    node-2.simgrid.org
 > [  0.000000] (maestro@)    node-20.simgrid.org
 > [  0.000000] (maestro@)    node-21.simgrid.org
 > [  0.000000] (maestro@)    node-22.simgrid.org
@@ -59,6 +72,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-27.simgrid.org
 > [  0.000000] (maestro@)    node-28.simgrid.org
 > [  0.000000] (maestro@)    node-29.simgrid.org
+> [  0.000000] (maestro@)    node-3.simgrid.org
 > [  0.000000] (maestro@)    node-30.simgrid.org
 > [  0.000000] (maestro@)    node-31.simgrid.org
 > [  0.000000] (maestro@)    node-32.simgrid.org
@@ -69,6 +83,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-37.simgrid.org
 > [  0.000000] (maestro@)    node-38.simgrid.org
 > [  0.000000] (maestro@)    node-39.simgrid.org
+> [  0.000000] (maestro@)    node-4.simgrid.org
 > [  0.000000] (maestro@)    node-40.simgrid.org
 > [  0.000000] (maestro@)    node-41.simgrid.org
 > [  0.000000] (maestro@)    node-42.simgrid.org
@@ -79,6 +94,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-47.simgrid.org
 > [  0.000000] (maestro@)    node-48.simgrid.org
 > [  0.000000] (maestro@)    node-49.simgrid.org
+> [  0.000000] (maestro@)    node-5.simgrid.org
 > [  0.000000] (maestro@)    node-50.simgrid.org
 > [  0.000000] (maestro@)    node-51.simgrid.org
 > [  0.000000] (maestro@)    node-52.simgrid.org
@@ -89,6 +105,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-57.simgrid.org
 > [  0.000000] (maestro@)    node-58.simgrid.org
 > [  0.000000] (maestro@)    node-59.simgrid.org
+> [  0.000000] (maestro@)    node-6.simgrid.org
 > [  0.000000] (maestro@)    node-60.simgrid.org
 > [  0.000000] (maestro@)    node-61.simgrid.org
 > [  0.000000] (maestro@)    node-62.simgrid.org
@@ -99,6 +116,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-67.simgrid.org
 > [  0.000000] (maestro@)    node-68.simgrid.org
 > [  0.000000] (maestro@)    node-69.simgrid.org
+> [  0.000000] (maestro@)    node-7.simgrid.org
 > [  0.000000] (maestro@)    node-70.simgrid.org
 > [  0.000000] (maestro@)    node-71.simgrid.org
 > [  0.000000] (maestro@)    node-72.simgrid.org
@@ -109,6 +127,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-77.simgrid.org
 > [  0.000000] (maestro@)    node-78.simgrid.org
 > [  0.000000] (maestro@)    node-79.simgrid.org
+> [  0.000000] (maestro@)    node-8.simgrid.org
 > [  0.000000] (maestro@)    node-80.simgrid.org
 > [  0.000000] (maestro@)    node-81.simgrid.org
 > [  0.000000] (maestro@)    node-82.simgrid.org
@@ -119,6 +138,7 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-87.simgrid.org
 > [  0.000000] (maestro@)    node-88.simgrid.org
 > [  0.000000] (maestro@)    node-89.simgrid.org
+> [  0.000000] (maestro@)    node-9.simgrid.org
 > [  0.000000] (maestro@)    node-90.simgrid.org
 > [  0.000000] (maestro@)    node-91.simgrid.org
 > [  0.000000] (maestro@)    node-92.simgrid.org
@@ -129,26 +149,6 @@ $ ${bindir:=.}/s4u-routing-get-clusters ${platfdir}/cluster_dragonfly.xml "--log
 > [  0.000000] (maestro@)    node-97.simgrid.org
 > [  0.000000] (maestro@)    node-98.simgrid.org
 > [  0.000000] (maestro@)    node-99.simgrid.org
-> [  0.000000] (maestro@)    node-100.simgrid.org
-> [  0.000000] (maestro@)    node-101.simgrid.org
-> [  0.000000] (maestro@)    node-102.simgrid.org
-> [  0.000000] (maestro@)    node-103.simgrid.org
-> [  0.000000] (maestro@)    node-104.simgrid.org
-> [  0.000000] (maestro@)    node-105.simgrid.org
-> [  0.000000] (maestro@)    node-106.simgrid.org
-> [  0.000000] (maestro@)    node-107.simgrid.org
-> [  0.000000] (maestro@)    node-108.simgrid.org
-> [  0.000000] (maestro@)    node-109.simgrid.org
-> [  0.000000] (maestro@)    node-110.simgrid.org
-> [  0.000000] (maestro@)    node-111.simgrid.org
-> [  0.000000] (maestro@)    node-112.simgrid.org
-> [  0.000000] (maestro@)    node-113.simgrid.org
-> [  0.000000] (maestro@)    node-114.simgrid.org
-> [  0.000000] (maestro@)    node-115.simgrid.org
-> [  0.000000] (maestro@)    node-116.simgrid.org
-> [  0.000000] (maestro@)    node-117.simgrid.org
-> [  0.000000] (maestro@)    node-118.simgrid.org
-> [  0.000000] (maestro@)    node-119.simgrid.org
 > [  0.000000] (maestro@) bob_cluster' dragonfly topology:
 > [  0.000000] (maestro@)    0: (0, 0, 0, 0)
 > [  0.000000] (maestro@)    1: (0, 0, 0, 1)
index fb18e9d..9890254 100644 (file)
@@ -151,7 +151,10 @@ public:
   kernel::routing::NetPoint* get_netpoint() const { return netpoint_; }
 
   std::vector<s4u::Host*> get_all_hosts() const;
-  int get_host_count() const;
+  size_t get_host_count() const;
+
+  std::vector<s4u::Link*> get_all_links() const;
+  size_t get_link_count() const;
 
   /** @brief Make a host within that NetZone */
   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
index 4cc2b76..ee06be4 100644 (file)
@@ -68,6 +68,12 @@ void StandardLinkImpl::latency_check(double latency) const
   }
 }
 
+StandardLinkImpl* StandardLinkImpl::set_englobing_zone(routing::NetZoneImpl* englobing_zone)
+{
+  englobing_zone_ = englobing_zone;
+  return this;
+}
+
 void StandardLinkImpl::turn_on()
 {
   if (not is_on()) {
index 0077755..f63b892 100644 (file)
@@ -21,6 +21,7 @@ namespace resource {
 class StandardLinkImpl : public LinkImpl {
   s4u::Link piface_;
   s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
+  routing::NetZoneImpl* englobing_zone_    = nullptr;
 
 protected:
   explicit StandardLinkImpl(const std::string& name);
@@ -46,6 +47,10 @@ public:
   /** @brief Get the latency in seconds of current Link */
   double get_latency() const override { return latency_.peak * latency_.scale; }
 
+  routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
+  /** @brief Set the NetZone in which this Link is included */
+  StandardLinkImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
+
   /** @brief The sharing policy */
   void set_sharing_policy(s4u::Link::SharingPolicy policy, const s4u::NonLinearResourceCb& cb) override;
   s4u::Link::SharingPolicy get_sharing_policy() const override { return sharing_policy_; }
index 39b6936..fd03d35 100644 (file)
@@ -128,23 +128,23 @@ void NetZoneImpl::add_child(NetZoneImpl* new_zone)
  */
 std::vector<s4u::Host*> NetZoneImpl::get_all_hosts() const
 {
-  std::vector<s4u::Host*> res;
-  for (auto const& card : get_vertices()) {
-    s4u::Host* host = s4u::Host::by_name_or_null(card->get_name());
-    if (host != nullptr)
-      res.push_back(host);
-  }
-  return res;
+  return s4u::Engine::get_instance()->get_filtered_hosts(
+      [this](const s4u::Host* host) { return host->get_impl()->get_englobing_zone() == this; });
 }
-int NetZoneImpl::get_host_count() const
+size_t NetZoneImpl::get_host_count() const
 {
-  int count = 0;
-  for (auto const& card : get_vertices()) {
-    const s4u::Host* host = s4u::Host::by_name_or_null(card->get_name());
-    if (host != nullptr)
-      count++;
-  }
-  return count;
+  return get_all_hosts().size();
+}
+
+std::vector<s4u::Link*> NetZoneImpl::get_all_links() const
+{
+  return s4u::Engine::get_instance()->get_filtered_links(
+      [this](const s4u::Link* link) { return link->get_impl()->get_englobing_zone() == this; });
+}
+
+size_t NetZoneImpl::get_link_count() const
+{
+  return get_all_links().size();
 }
 
 s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
@@ -153,7 +153,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<d
              "Impossible to create host: %s. Invalid CPU model: nullptr. Have you set the parent of this NetZone: %s?",
              name.c_str(), get_cname());
   xbt_assert(not sealed_, "Impossible to create host: %s. NetZone %s already sealed", name.c_str(), get_cname());
-  auto* res = (new resource::HostImpl(name))->get_iface();
+  auto* res = (new resource::HostImpl(name))->set_englobing_zone(this)->get_iface();
   res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
 
   cpu_model_pm_->create_cpu(res, speed_per_pstate);
@@ -168,7 +168,7 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<d
       "Impossible to create link: %s. Invalid network model: nullptr. Have you set the parent of this NetZone: %s?",
       name.c_str(), get_cname());
   xbt_assert(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname());
-  return network_model_->create_link(name, bandwidths)->get_iface();
+  return network_model_->create_link(name, bandwidths)->set_englobing_zone(this)->get_iface();
 }
 
 s4u::SplitDuplexLink* NetZoneImpl::create_split_duplex_link(const std::string& name,
@@ -180,8 +180,8 @@ s4u::SplitDuplexLink* NetZoneImpl::create_split_duplex_link(const std::string& n
       name.c_str(), get_cname());
   xbt_assert(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname());
 
-  auto* link_up                  = network_model_->create_link(name + "_UP", bandwidths);
-  auto* link_down                = network_model_->create_link(name + "_DOWN", bandwidths);
+  auto* link_up                  = network_model_->create_link(name + "_UP", bandwidths)->set_englobing_zone(this);
+  auto* link_down                = network_model_->create_link(name + "_DOWN", bandwidths)->set_englobing_zone(this);
   auto link                      = std::make_unique<resource::SplitDuplexLinkImpl>(name, link_up, link_down);
   auto* link_iface               = link->get_iface();
   EngineImpl::get_instance()->add_split_duplex_link(name, std::move(link));
index b5925e3..81596ca 100644 (file)
@@ -50,7 +50,7 @@ s4u::Link* WifiZone::create_link(const std::string& name, const std::vector<doub
   xbt_assert(wifi_link_ == nullptr,
              "WIFI netzone %s contains more than one link. Please only declare one, the wifi link.", get_cname());
 
-  wifi_link_ = get_network_model()->create_wifi_link(name, bandwidths);
+  wifi_link_ = get_network_model()->create_wifi_link(name, bandwidths)->set_englobing_zone(this);
   wifi_link_->set_sharing_policy(s4u::Link::SharingPolicy::WIFI, {});
   return wifi_link_->get_iface();
 }
index cb63f32..0b28ab2 100644 (file)
@@ -111,6 +111,12 @@ void HostImpl::turn_off(const actor::ActorImpl* issuer)
   actors_at_boot_.erase(elm, end(actors_at_boot_));
 }
 
+HostImpl* HostImpl::set_englobing_zone(routing::NetZoneImpl* englobing_zone)
+{
+  englobing_zone_ = englobing_zone;
+  return this;
+}
+
 std::vector<s4u::ActorPtr> HostImpl::get_all_actors()
 {
   std::vector<s4u::ActorPtr> res;
index 36f71ba..e9a291c 100644 (file)
@@ -52,6 +52,7 @@ class XBT_PRIVATE HostImpl : public xbt::PropertyHolder {
   s4u::Host piface_;
   std::map<std::string, DiskImpl*, std::less<>> disks_;
   xbt::string name_{"noname"};
+  routing::NetZoneImpl* englobing_zone_ = nullptr;
   bool sealed_ = false;
 
 protected:
@@ -77,6 +78,10 @@ public:
   /** Retrieves the name of that host as a C string */
   const char* get_cname() const { return name_.c_str(); }
 
+  routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
+  /** @brief Set the NetZone in which this Host is included */
+  HostImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
+
   void turn_on() const;
   void turn_off(const actor::ActorImpl* issuer);
   std::vector<s4u::ActorPtr> get_all_actors();