From: Fred Suter Date: Thu, 21 Sep 2023 15:39:29 +0000 (-0400) Subject: Explicitely create, store, and expose NetZone gateway(s) X-Git-Tag: v3.35~106 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/de00769095da24e77ceab237b324c2c3a4f94a9d Explicitely create, store, and expose NetZone gateway(s) --- diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index ffb432216a..ed13e52c52 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -74,12 +74,13 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { s4u::NetZone piface_; // our content, as known to our graph routing algorithm (maps vertex_id -> vertex) - std::vector vertices_; + std::vector vertices_; std::map> links_; /* save split-duplex links separately, keep links_ with only LinkImpl* seen by the user * members of a split-duplex are saved in the links_ */ std::map, std::less<>> split_duplex_links_; std::map> hosts_; + std::map> gateways_; NetZoneImpl* parent_ = nullptr; std::vector children_; // sub-netzones @@ -87,7 +88,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { bool sealed_ = false; // We cannot add more content when sealed std::map, BypassRoute*> bypass_routes_; // src x dst -> route - routing::NetPoint* netpoint_ = nullptr; // Our representative in the parent NetZone + NetPoint* netpoint_ = nullptr; // Our representative in the parent NetZone protected: explicit NetZoneImpl(const std::string& name); @@ -142,7 +143,7 @@ public: const s4u::NetZone* get_iface() const { return &piface_; } s4u::NetZone* get_iface() { return &piface_; } unsigned int get_table_size() const { return vertices_.size(); } - std::vector get_vertices() const { return vertices_; } + std::vector get_vertices() const { return vertices_; } NetZoneImpl* get_parent() const { return parent_; } /** @brief Returns the list of direct children (no grand-children). This returns the internal data, no copy. * Don't mess with it.*/ @@ -156,7 +157,12 @@ public: const char* get_cname() const { return name_.c_str(); }; /** @brief Gets the netpoint associated to this netzone */ - kernel::routing::NetPoint* get_netpoint() const { return netpoint_; } + NetPoint* get_netpoint() const { return netpoint_; } + + void set_gateway(const std::string& name, NetPoint* router); + /** @brief Gets the gateway associated to this netzone */ + NetPoint* get_gateway() const; + NetPoint* get_gateway(const std::string& name) const { return gateways_.at(name); } std::vector get_all_hosts() const; size_t get_host_count() const; diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index e9b909fc20..967f348ce6 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -57,7 +57,12 @@ public: const char* get_property(const std::string& key) const; void set_property(const std::string& key, const std::string& value); /** @brief Get the netpoint associated to this netzone */ - kernel::routing::NetPoint* get_netpoint(); + kernel::routing::NetPoint* get_netpoint() const; + /** @brief Get the gateway associated to this netzone */ + kernel::routing::NetPoint* get_gateway() const; + kernel::routing::NetPoint* get_gateway(const std::string& name) const; + void set_gateway(kernel::routing::NetPoint* router); + void set_gateway(const std::string& name, kernel::routing::NetPoint* router); void extract_xbt_graph(const s_xbt_graph_t* graph, std::map>* nodes, std::map>* edges); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 5ed1d62097..08df429aca 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -669,6 +669,24 @@ void NetZoneImpl::get_graph(const s_xbt_graph_t* graph, std::mapsecond; +} + void NetZoneImpl::seal() { /* already sealed netzone */ @@ -676,6 +694,10 @@ void NetZoneImpl::seal() return; do_seal(); // derived class' specific sealing procedure + // for zone with a single host, this host is its own default gateway + if (gateways_.empty() && hosts_.size() == 1) + gateways_["default"] = hosts_.begin()->second->get_iface()->get_netpoint(); + /* seals sub-netzones and hosts */ for (auto* host : get_all_hosts()) { host->seal(); diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 49b23a0837..c6008494a3 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -231,11 +231,31 @@ kernel::routing::NetPoint* NetZone::create_router(const std::string& name) return kernel::actor::simcall_answered([this, &name] { return pimpl_->create_router(name); }); } -kernel::routing::NetPoint* NetZone::get_netpoint() +kernel::routing::NetPoint* NetZone::get_netpoint() const { return pimpl_->get_netpoint(); } +kernel::routing::NetPoint* NetZone::get_gateway() const +{ + return pimpl_->get_gateway(); +} + +kernel::routing::NetPoint* NetZone::get_gateway(const std::string& name) const +{ + return pimpl_->get_gateway(name); +} + +void NetZone::set_gateway(kernel::routing::NetPoint* router) +{ + set_gateway("default", router); +} + +void NetZone::set_gateway(const std::string& name, kernel::routing::NetPoint* router) +{ + kernel::actor::simcall_answered([this, name, router] { pimpl_->set_gateway(name, router); }); +} + kernel::resource::NetworkModel* NetZone::get_network_model() const { return pimpl_->get_network_model().get();