Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
NetZoneImpl: simpler constructor
authorBruno Donassolo <bruno.donassolo@inria.fr>
Wed, 10 Mar 2021 18:53:33 +0000 (19:53 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 11 Mar 2021 17:27:15 +0000 (18:27 +0100)
NetZoneImpl(std::string& name);
One step towards a simple contructor and set() idiom.
Removed father and network model from constructor.

Collateral effect:

NetPoint:
- removed NetZoneImpl* from its constructor
- added method set_englobing_zone(NetZoneImpl*)

In the past, we could create the NetPoint in NetZoneImpl with the
pointer to the father. But now, the father is only set latter at
set_father method.

include/simgrid/kernel/routing/NetPoint.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/EmptyZone.cpp
src/kernel/routing/NetPoint.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/surf/sg_platf.cpp

index e6cc4b3..c5f5535 100644 (file)
@@ -28,7 +28,7 @@ class NetPoint : public xbt::Extendable<NetPoint> {
 public:
   enum class Type { Host, Router, NetZone };
 
-  NetPoint(const std::string& name, NetPoint::Type component_type, NetZoneImpl* netzone_p);
+  NetPoint(const std::string& name, NetPoint::Type component_type);
 
   // Our rank in the vertices_ array of the netzone that contains us.
   unsigned int id() const { return id_; }
@@ -36,6 +36,8 @@ public:
   const char* get_cname() const { return name_.c_str(); }
   /** @brief the NetZone in which this NetPoint is included */
   NetZoneImpl* get_englobing_zone() { return englobing_zone_; }
+  /** @brief Set the NetZone in which this NetPoint is included */
+  NetPoint* set_englobing_zone(NetZoneImpl* netzone_p);
 
   bool is_netzone() const { return component_type_ == Type::NetZone; }
   bool is_host() const { return component_type_ == Type::Host; }
@@ -46,7 +48,7 @@ public:
   bool operator<(const NetPoint& rhs) const { return name_ < rhs.name_; }
 
 private:
-  unsigned int id_;
+  unsigned int id_ = -1;
   std::string name_;
   NetPoint::Type component_type_;
   NetZoneImpl* englobing_zone_;
index b641b4b..d530a4e 100644 (file)
@@ -79,7 +79,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
   virtual void do_seal(){};
 
 protected:
-  explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model);
+  explicit NetZoneImpl(const std::string& name);
   NetZoneImpl(const NetZoneImpl&) = delete;
   NetZoneImpl& operator=(const NetZoneImpl&) = delete;
   virtual ~NetZoneImpl();
@@ -152,6 +152,10 @@ public:
   virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
                          std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
+  /** @brief Set parent of this Netzone */
+  void set_parent(NetZoneImpl* parent);
+  /** @brief Set network model for this Netzone */
+  void set_network_model(simgrid::kernel::resource::NetworkModel* netmodel);
 
   /* @brief get the route between two nodes in the full platform
    *
index 0a78108..dab5f1c 100644 (file)
@@ -18,7 +18,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 ClusterZone::ClusterZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : NetZoneImpl(father, name, netmodel)
+    : NetZoneImpl(name)
 {
 }
 
index 139d80e..ffd7a5a 100644 (file)
@@ -15,8 +15,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-EmptyZone::EmptyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : NetZoneImpl(father, name, netmodel)
+EmptyZone::EmptyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel) : NetZoneImpl(name)
 {
 }
 
index c37e5d8..14c4c70 100644 (file)
@@ -19,19 +19,23 @@ namespace routing {
 
 simgrid::xbt::signal<void(NetPoint&)> NetPoint::on_creation;
 
-NetPoint::NetPoint(const std::string& name, NetPoint::Type componentType, NetZoneImpl* netzone_p)
-    : name_(name), component_type_(componentType), englobing_zone_(netzone_p)
+NetPoint::NetPoint(const std::string& name, NetPoint::Type componentType) : name_(name), component_type_(componentType)
 {
-  if (netzone_p != nullptr)
-    id_ = netzone_p->add_component(this);
-  else
-    id_ = static_cast<decltype(id_)>(-1);
   simgrid::s4u::Engine::get_instance()->netpoint_register(this);
   simgrid::kernel::routing::NetPoint::on_creation(*this);
 }
+
+NetPoint* NetPoint::set_englobing_zone(NetZoneImpl* netzone_p)
+{
+  englobing_zone_ = netzone_p;
+  if (netzone_p != nullptr)
+    id_ = netzone_p->add_component(this);
+  return this;
 }
-}
-} // namespace simgrid::kernel::routing
+
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
 
 /** @brief Retrieve a netpoint from its name
  *
index ed41a9f..dc5e9be 100644 (file)
@@ -21,13 +21,11 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model)
-    : piface_(this), father_(father), name_(name), network_model_(network_model)
+NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name)
 {
   xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(get_name()),
              "Refusing to create a second NetZone called '%s'.", get_cname());
-
-  netpoint_     = new NetPoint(name_, NetPoint::Type::NetZone, father_);
+  netpoint_     = new NetPoint(name_, NetPoint::Type::NetZone);
   cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
       simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_VM));
   cpu_model_pm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
@@ -98,7 +96,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<d
     hierarchy_ = RoutingMode::base;
 
   auto* res = new s4u::Host(name);
-  res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this));
+  res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
 
   cpu_model_pm_->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal();
 
@@ -408,6 +406,18 @@ void NetZoneImpl::seal()
   sealed_ = true;
 }
 
+void NetZoneImpl::set_parent(NetZoneImpl* parent)
+{
+  xbt_assert(sealed_ == false, "Impossible to set father to an already sealed NetZone(%s)", this->get_cname());
+  father_ = parent;
+  netpoint_->set_englobing_zone(father_);
+}
+
+void NetZoneImpl::set_network_model(simgrid::kernel::resource::NetworkModel* netmodel)
+{
+  network_model_ = netmodel;
+}
+
 } // namespace routing
 } // namespace kernel
 } // namespace simgrid
index bd992cc..0dbc7f3 100644 (file)
@@ -55,7 +55,7 @@ namespace kernel {
 namespace routing {
 
 RoutedZone::RoutedZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : NetZoneImpl(father, name, netmodel)
+    : NetZoneImpl(name)
 {
 }
 
index 867b0d2..2d4bfe6 100644 (file)
@@ -100,8 +100,8 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name,
   xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name),
              "Refusing to create a router named '%s': this name already describes a node.", name.c_str());
 
-  auto* netpoint =
-      new simgrid::kernel::routing::NetPoint(name, simgrid::kernel::routing::NetPoint::Type::Router, current_routing);
+  auto* netpoint = new simgrid::kernel::routing::NetPoint(name, simgrid::kernel::routing::NetPoint::Type::Router);
+  netpoint->set_englobing_zone(current_routing);
   XBT_DEBUG("Router '%s' has the id %u", netpoint->get_cname(), netpoint->id());
 
   if (coords && strcmp(coords, ""))
@@ -545,6 +545,8 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
   } else {
     xbt_die("Not a valid model!");
   }
+  new_zone->set_parent(current_routing);
+  new_zone->set_network_model(netmodel);
 
   if (current_routing == nullptr) { /* it is the first one */
     simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone->get_iface());