Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Explicitely create, store, and expose NetZone gateway(s)
authorFred Suter <suterf@ornl.gov>
Thu, 21 Sep 2023 15:39:29 +0000 (11:39 -0400)
committerFred Suter <suterf@ornl.gov>
Thu, 21 Sep 2023 15:39:29 +0000 (11:39 -0400)
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/s4u/NetZone.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Netzone.cpp

index ffb4322..ed13e52 100644 (file)
@@ -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<kernel::routing::NetPoint*> vertices_;
+  std::vector<NetPoint*> vertices_;
   std::map<std::string, resource::StandardLinkImpl*, std::less<>> 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::string, std::unique_ptr<resource::SplitDuplexLinkImpl>, std::less<>> split_duplex_links_;
   std::map<std::string, resource::HostImpl*, std::less<>> hosts_;
+  std::map<std::string, NetPoint*, std::less<>> gateways_;
 
   NetZoneImpl* parent_ = nullptr;
   std::vector<NetZoneImpl*> 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<std::pair<const NetPoint*, const NetPoint*>, 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<kernel::routing::NetPoint*> get_vertices() const { return vertices_; }
+  std::vector<NetPoint*> 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<s4u::Host*> get_all_hosts() const;
   size_t get_host_count() const;
index e9b909f..967f348 100644 (file)
@@ -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<std::string, xbt_node_t, std::less<>>* nodes,
                          std::map<std::string, xbt_edge_t, std::less<>>* edges);
index 5ed1d62..08df429 100644 (file)
@@ -669,6 +669,24 @@ void NetZoneImpl::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xb
   }
 }
 
+void NetZoneImpl::set_gateway(const std::string& name, NetPoint* router)
+{
+  xbt_enforce(not sealed_, "Impossible to create gateway: %s. NetZone %s already sealed", name.c_str(), get_cname());
+  if (auto gateway_it = gateways_.find(name); gateway_it != gateways_.end())
+    xbt_die("Impossible to create a gateway named %s. It already exists", name.c_str());
+  else
+    gateways_[name] = router;
+}
+
+NetPoint* NetZoneImpl::get_gateway() const
+{
+  xbt_enforce(not gateways_.empty(), "No default gateway has been defined for NetZone '%s'. Try to seal it first", get_cname());
+  xbt_enforce(gateways_.size() < 2, "NetZone '%s' has more than one gateway, please provide a gateway name", get_cname());
+  auto gateway_it = gateways_.find("default");
+  xbt_enforce(gateway_it != gateways_.end(), "NetZone '%s' hasno default gateway, please define one", get_cname());
+  return gateway_it->second;
+}
+
 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();
index 49b23a0..c600849 100644 (file)
@@ -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();