From: SUTER Frederic Date: Thu, 31 Mar 2022 02:14:56 +0000 (+0200) Subject: allow users to retrieve hosts and links by the zone in which they have been declared X-Git-Tag: v3.32~339 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cfe9a9b1ef010f96338b992051bd5ddbbe803385 allow users to retrieve hosts and links by the zone in which they have been declared --- diff --git a/examples/cpp/routing-get-clusters/s4u-routing-get-clusters.tesh b/examples/cpp/routing-get-clusters/s4u-routing-get-clusters.tesh index f03b7453fd..406816376a 100644 --- a/examples/cpp/routing-get-clusters/s4u-routing-get-clusters.tesh +++ b/examples/cpp/routing-get-clusters/s4u-routing-get-clusters.tesh @@ -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) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index fb18e9da24..9890254743 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -151,7 +151,10 @@ public: kernel::routing::NetPoint* get_netpoint() const { return netpoint_; } std::vector get_all_hosts() const; - int get_host_count() const; + size_t get_host_count() const; + + std::vector 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& speed_per_pstate); diff --git a/src/kernel/resource/StandardLinkImpl.cpp b/src/kernel/resource/StandardLinkImpl.cpp index 4cc2b76d5c..ee06be462e 100644 --- a/src/kernel/resource/StandardLinkImpl.cpp +++ b/src/kernel/resource/StandardLinkImpl.cpp @@ -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()) { diff --git a/src/kernel/resource/StandardLinkImpl.hpp b/src/kernel/resource/StandardLinkImpl.hpp index 0077755b02..f63b892abc 100644 --- a/src/kernel/resource/StandardLinkImpl.hpp +++ b/src/kernel/resource/StandardLinkImpl.hpp @@ -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_; } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 39b693659e..fd03d356cb 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -128,23 +128,23 @@ void NetZoneImpl::add_child(NetZoneImpl* new_zone) */ std::vector NetZoneImpl::get_all_hosts() const { - std::vector 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 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& speed_per_pstate) @@ -153,7 +153,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vectorget_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::vectorcreate_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(name, link_up, link_down); auto* link_iface = link->get_iface(); EngineImpl::get_instance()->add_split_duplex_link(name, std::move(link)); diff --git a/src/kernel/routing/WifiZone.cpp b/src/kernel/routing/WifiZone.cpp index b5925e3e64..81596ca6fa 100644 --- a/src/kernel/routing/WifiZone.cpp +++ b/src/kernel/routing/WifiZone.cpp @@ -50,7 +50,7 @@ s4u::Link* WifiZone::create_link(const std::string& name, const std::vectorcreate_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(); } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index cb63f32b76..0b28ab2a5a 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -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 HostImpl::get_all_actors() { std::vector res; diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 36f71baddf..e9a291ce91 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -52,6 +52,7 @@ class XBT_PRIVATE HostImpl : public xbt::PropertyHolder { s4u::Host piface_; std::map> 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 get_all_actors();