Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'model_types_rework_part1' into 'master'
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 11 Mar 2021 18:12:51 +0000 (18:12 +0000)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 11 Mar 2021 18:12:51 +0000 (18:12 +0000)
Model types rework - Part 1

See merge request simgrid/simgrid!54

40 files changed:
include/simgrid/kernel/routing/ClusterZone.hpp
include/simgrid/kernel/routing/DijkstraZone.hpp
include/simgrid/kernel/routing/DragonflyZone.hpp
include/simgrid/kernel/routing/EmptyZone.hpp
include/simgrid/kernel/routing/FatTreeZone.hpp
include/simgrid/kernel/routing/FloydZone.hpp
include/simgrid/kernel/routing/FullZone.hpp
include/simgrid/kernel/routing/NetPoint.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/kernel/routing/RoutedZone.hpp
include/simgrid/kernel/routing/TorusZone.hpp
include/simgrid/kernel/routing/VivaldiZone.hpp
include/simgrid/kernel/routing/WifiZone.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/EmptyZone.cpp
src/kernel/routing/FatTreeZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetPoint.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/kernel/routing/TorusZone.cpp
src/kernel/routing/VivaldiZone.cpp
src/kernel/routing/WifiZone.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/disk_s19.cpp
src/surf/host_clm03.cpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_ib.cpp
src/surf/network_ns3.cpp
src/surf/network_smpi.cpp
src/surf/ptask_L07.cpp
src/surf/sg_platf.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index 7d0cbb9..fdb8b65 100644 (file)
@@ -67,7 +67,7 @@ namespace routing {
 
 class ClusterZone : public NetZoneImpl {
 public:
-  explicit ClusterZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit ClusterZone(const std::string& name);
 
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
index 0154499..91fb35d 100644 (file)
@@ -35,9 +35,10 @@ private:
   xbt_node_t route_graph_new_node(int id);
   xbt_node_t node_map_search(int id);
   void new_edge(int src_id, int dst_id, RouteCreationArgs* e_route);
+  void do_seal() override;
 
 public:
-  DijkstraZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel, bool cached);
+  DijkstraZone(const std::string& name, bool cached);
 
   /* For each vertex (node) already in the graph,
    * make sure it also has a loopback link; this loopback
@@ -50,7 +51,6 @@ public:
    * After this function returns, any node in the graph
    * will have a loopback attached to it.
    */
-  void seal() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat) override;
   void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                  std::vector<resource::LinkImpl*>& link_list, bool symmetrical) override;
index dc15b66..83a7b96 100644 (file)
@@ -67,16 +67,16 @@ public:
     unsigned node;
   };
 
-  explicit DragonflyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit DragonflyZone(const std::string& name);
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void parse_specific_arguments(ClusterCreationArgs* cluster) override;
-  void seal() override;
 
   Coords rankId_to_coords(int rank_id) const;
   XBT_ATTRIB_DEPRECATED_v330("Please use rankId_to_coords(int)") void rankId_to_coords(int rank_id,
                                                                                        unsigned int coords[4]) const;
 
 private:
+  void do_seal() override;
   void generate_routers();
   void generate_links();
   void generate_link(const std::string& id, int numlinks, resource::LinkImpl** linkup,
index 96457a0..2ed304b 100644 (file)
@@ -21,7 +21,7 @@ namespace routing {
 
 class XBT_PRIVATE EmptyZone : public NetZoneImpl {
 public:
-  explicit EmptyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit EmptyZone(const std::string& name);
   ~EmptyZone() override;
 
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override
index 484de14..6b3d881 100644 (file)
@@ -98,19 +98,12 @@ public:
  */
 class XBT_PRIVATE FatTreeZone : public ClusterZone {
 public:
-  explicit FatTreeZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit FatTreeZone(const std::string& name);
   FatTreeZone(const FatTreeZone&) = delete;
   FatTreeZone& operator=(const FatTreeZone&) = delete;
   ~FatTreeZone() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
 
-  /** @brief Generate the fat tree
-   *
-   * Once all processing nodes have been added, this will make sure the fat
-   * tree is generated by calling generateLabels(), generateSwitches() and
-   * then connection all nodes between them, using their label.
-   */
-  void seal() override;
   /** @brief Read the parameters in topo_parameters field.
    *
    * It will also store the cluster for future use.
@@ -120,6 +113,13 @@ public:
   void generate_dot_file(const std::string& filename = "fat_tree.dot") const;
 
 private:
+  /** @brief Generate the fat tree
+   *
+   * Once all processing nodes have been added, this will make sure the fat
+   * tree is generated by calling generateLabels(), generateSwitches() and
+   * then connection all nodes between them, using their label.
+   */
+  void do_seal() override;
   // description of a PGFT (TODO : better doc)
   unsigned long levels_ = 0;
   std::vector<unsigned int> num_children_per_node_; // number of children by node
index 9a5b924..7601328 100644 (file)
@@ -23,7 +23,7 @@ namespace routing {
  */
 class XBT_PRIVATE FloydZone : public RoutedZone {
 public:
-  explicit FloydZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit FloydZone(const std::string& name);
   FloydZone(const FloydZone&) = delete;
   FloydZone& operator=(const FloydZone&) = delete;
   ~FloydZone() override;
@@ -31,7 +31,6 @@ public:
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                  std::vector<resource::LinkImpl*>& link_list, bool symmetrical) override;
-  void seal() override;
 
 private:
   /* vars to compute the Floyd algorithm. */
@@ -40,6 +39,7 @@ private:
   std::vector<RouteCreationArgs*> link_table_;
 
   void init_tables(unsigned int table_size);
+  void do_seal() override;
 };
 } // namespace routing
 } // namespace kernel
index 3eed494..7584894 100644 (file)
@@ -20,18 +20,18 @@ namespace routing {
  */
 class XBT_PRIVATE FullZone : public RoutedZone {
 public:
-  explicit FullZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit FullZone(const std::string& name);
   FullZone(const FullZone&) = delete;
   FullZone& operator=(const FullZone) = delete;
   ~FullZone() override;
 
-  void seal() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                  std::vector<resource::LinkImpl*>& link_list, bool symmetrical) override;
 
 private:
   std::vector<RouteCreationArgs*> routing_table_;
+  void do_seal() override;
 };
 } // namespace routing
 } // namespace kernel
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 b550fc4..b43331a 100644 (file)
@@ -70,14 +70,16 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
 
   std::map<std::pair<NetPoint*, NetPoint*>, BypassRoute*> bypass_routes_; // src x dst -> route
   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
-  resource::NetworkModel* network_model_;
-  resource::CpuModel* cpu_model_vm_;
-  resource::CpuModel* cpu_model_pm_;
-  resource::DiskModel* disk_model_;
-  simgrid::surf::HostModel* host_model_;
+  std::shared_ptr<resource::NetworkModel> network_model_;
+  std::shared_ptr<resource::CpuModel> cpu_model_vm_;
+  std::shared_ptr<resource::CpuModel> cpu_model_pm_;
+  std::shared_ptr<resource::DiskModel> disk_model_;
+  std::shared_ptr<simgrid::surf::HostModel> host_model_;
+  /** @brief Perform sealing procedure for derived classes, if necessary */
+  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();
@@ -107,15 +109,15 @@ public:
   RoutingMode hierarchy_ = RoutingMode::unset;
 
   /** @brief Retrieves the network model associated to this NetZone */
-  resource::NetworkModel* get_network_model() const { return network_model_; }
+  const std::shared_ptr<resource::NetworkModel>& get_network_model() const { return network_model_; }
   /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */
-  resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; }
+  const std::shared_ptr<resource::CpuModel>& get_cpu_vm_model() const { return cpu_model_vm_; }
   /** @brief Retrieves the CPU model for physical machines associated to this NetZone */
-  resource::CpuModel* get_cpu_pm_model() const { return cpu_model_pm_; }
+  const std::shared_ptr<resource::CpuModel>& get_cpu_pm_model() const { return cpu_model_pm_; }
   /** @brief Retrieves the disk model associated to this NetZone */
-  resource::DiskModel* get_disk_model() const { return disk_model_; }
+  const std::shared_ptr<resource::DiskModel>& get_disk_model() const { return disk_model_; }
   /** @brief Retrieves the host model associated to this NetZone */
-  simgrid::surf::HostModel* get_host_model() const { return host_model_; }
+  const std::shared_ptr<surf::HostModel>& get_host_model() const { return host_model_; }
 
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
@@ -145,11 +147,19 @@ public:
                                 std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
 
   /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
-  virtual void seal() { sealed_ = true; };
+  void seal();
   virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
   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(std::shared_ptr<resource::NetworkModel> netmodel);
+  void set_cpu_vm_model(std::shared_ptr<resource::CpuModel> cpu_model);
+  void set_cpu_pm_model(std::shared_ptr<resource::CpuModel> cpu_model);
+  void set_disk_model(std::shared_ptr<resource::DiskModel> disk_model);
+  void set_host_model(std::shared_ptr<surf::HostModel> host_model);
 
   /* @brief get the route between two nodes in the full platform
    *
index f3c6698..6e061e2 100644 (file)
@@ -50,7 +50,7 @@ namespace routing {
 
 class XBT_PRIVATE RoutedZone : public NetZoneImpl {
 public:
-  explicit RoutedZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit RoutedZone(const std::string& name);
 
   void get_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) override;
index ca14c6f..4eff9c1 100644 (file)
@@ -21,7 +21,7 @@ namespace routing {
 
 class XBT_PRIVATE TorusZone : public ClusterZone {
 public:
-  explicit TorusZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit TorusZone(const std::string& name);
   void create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position) override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void parse_specific_arguments(ClusterCreationArgs* cluster) override;
index 943c27e..ab0ad8c 100644 (file)
@@ -46,7 +46,7 @@ namespace routing {
 
 class XBT_PRIVATE VivaldiZone : public ClusterZone {
 public:
-  explicit VivaldiZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit VivaldiZone(const std::string& name);
 
   void set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, const std::string& coord);
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
index 15cc9b0..e325ca0 100644 (file)
@@ -20,17 +20,17 @@ namespace routing {
  */
 class XBT_PRIVATE WifiZone : public RoutedZone {
 public:
-  explicit WifiZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
+  explicit WifiZone(const std::string& name);
   WifiZone(const WifiZone&) = delete;
   WifiZone& operator=(const WifiZone) = delete;
 
-  void seal() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths,
                          s4u::Link::SharingPolicy policy) override;
-  NetPoint* get_access_point() {return access_point_;}
+  NetPoint* get_access_point() { return access_point_; }
 
 private:
+  void do_seal() override;
   resource::LinkImpl* wifi_link_ = nullptr; // Representing the air media (there is no such thing in NS-3)
   NetPoint* access_point_        = nullptr; // Zone's gateway to the external world
 };
index f8de83a..a99954b 100644 (file)
@@ -434,7 +434,7 @@ CommImpl* CommImpl::start()
     /* FIXME[donassolo]: getting the network_model from the origin host
      * Soon we need to change this function to first get the routes and later
      * create the respective surf actions */
-    auto* net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
+    auto net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
 
     surf_action_ = net_model->communicate(from_, to_, size_, rate_);
     surf_action_->set_activity(this);
index 0a78108..c4782e4 100644 (file)
@@ -17,10 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
 namespace simgrid {
 namespace kernel {
 namespace routing {
-ClusterZone::ClusterZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : NetZoneImpl(father, name, netmodel)
-{
-}
+ClusterZone::ClusterZone(const std::string& name) : NetZoneImpl(name) {}
 
 void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
 {
@@ -41,7 +38,7 @@ void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg
   }
 
   if (not src->is_router()) { // No private link for the private router
-    if (has_limiter_) {      // limiter for sender
+    if (has_limiter_) {       // limiter for sender
       std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id()));
       route->link_list.push_back(info.first);
     }
@@ -128,10 +125,10 @@ void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, in
   std::string link_id = cluster->id + "_link_" + std::to_string(id);
 
   LinkCreationArgs link;
-  link.id        = link_id;
+  link.id = link_id;
   link.bandwidths.push_back(cluster->bw);
-  link.latency   = cluster->lat;
-  link.policy    = cluster->sharing_policy;
+  link.latency = cluster->lat;
+  link.policy  = cluster->sharing_policy;
   sg_platf_new_link(&link);
 
   const s4u::Link* linkUp;
@@ -145,6 +142,6 @@ void ClusterZone::create_links_for_node(ClusterCreationArgs* cluster, int id, in
   }
   private_links_.insert({position, {linkUp->get_impl(), linkDown->get_impl()}});
 }
-}
-}
-}
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
index 7855c4f..5471809 100644 (file)
@@ -27,18 +27,16 @@ public:
   int graph_id_ = -1; /* used for caching internal graph id's */
 };
 
-DijkstraZone::DijkstraZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel, bool cached)
-    : RoutedZone(father, name, netmodel), cached_(cached)
-{
-}
+DijkstraZone::DijkstraZone(const std::string& name, bool cached) : RoutedZone(name), cached_(cached) {}
 
 void DijkstraZone::route_graph_delete(xbt_graph_t g)
 {
-  xbt_graph_free_graph(g, [](void* n) { delete static_cast<simgrid::kernel::routing::GraphNodeData*>(n); },
-                       [](void* e) { delete static_cast<simgrid::kernel::routing::RouteCreationArgs*>(e); }, nullptr);
+  xbt_graph_free_graph(
+      g, [](void* n) { delete static_cast<simgrid::kernel::routing::GraphNodeData*>(n); },
+      [](void* e) { delete static_cast<simgrid::kernel::routing::RouteCreationArgs*>(e); }, nullptr);
 }
 
-void DijkstraZone::seal()
+void DijkstraZone::do_seal()
 {
   unsigned int cursor;
   xbt_node_t node = nullptr;
@@ -46,7 +44,7 @@ void DijkstraZone::seal()
   /* Add the loopback if needed */
   if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
     xbt_dynar_foreach (xbt_graph_get_nodes(route_graph_.get()), cursor, node) {
-      bool found = false;
+      bool found      = false;
       xbt_edge_t edge = nullptr;
       unsigned int cursor2;
       xbt_dynar_foreach (xbt_graph_node_get_outedges(node), cursor2, edge) {
@@ -68,8 +66,8 @@ void DijkstraZone::seal()
   const_xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_.get());
 
   xbt_dynar_foreach (nodes, cursor, node) {
-    auto* data          = static_cast<GraphNodeData*>(xbt_graph_node_get_data(node));
-    data->graph_id_     = cursor;
+    auto* data      = static_cast<GraphNodeData*>(xbt_graph_node_get_data(node));
+    data->graph_id_ = cursor;
   }
 }
 
@@ -126,7 +124,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr
   std::vector<int>& pred_arr = elm.first->second;
 
   if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
-    int nr_nodes      = xbt_dynar_length(nodes);
+    int nr_nodes = xbt_dynar_length(nodes);
     std::vector<double> cost_arr(nr_nodes); /* link cost from src to other hosts */
     pred_arr.resize(nr_nodes);              /* predecessors in path from src */
     using Qelt = std::pair<double, int>;
@@ -151,15 +149,15 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr
       int v_id = pqueue.top().second;
       pqueue.pop();
       const s_xbt_node_t* v_node = xbt_dynar_get_as(nodes, v_id, xbt_node_t);
-      xbt_edge_t edge   = nullptr;
+      xbt_edge_t edge            = nullptr;
       unsigned int cursor;
 
       xbt_dynar_foreach (xbt_graph_node_get_outedges(v_node), cursor, edge) {
         const s_xbt_node_t* u_node           = xbt_graph_edge_get_target(edge);
         const GraphNodeData* data            = static_cast<GraphNodeData*>(xbt_graph_node_get_data(u_node));
-        int u_id                           = data->graph_id_;
+        int u_id                             = data->graph_id_;
         const RouteCreationArgs* tmp_e_route = static_cast<RouteCreationArgs*>(xbt_graph_edge_get_data(edge));
-        int cost_v_u                       = tmp_e_route->link_list.size(); /* count of links, old model assume 1 */
+        int cost_v_u                         = tmp_e_route->link_list.size(); /* count of links, old model assume 1 */
 
         if (cost_v_u + cost_arr[v_id] < cost_arr[u_id]) {
           pred_arr[u_id] = v_id;
@@ -185,8 +183,8 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr
     const RouteCreationArgs* e_route = static_cast<RouteCreationArgs*>(xbt_graph_edge_get_data(edge));
 
     const NetPoint* prev_gw_src = gw_src;
-    gw_src                = e_route->gw_src;
-    NetPoint* gw_dst      = e_route->gw_dst;
+    gw_src                      = e_route->gw_src;
+    NetPoint* gw_dst            = e_route->gw_dst;
 
     if (v == dst_node_id)
       first_gw = gw_dst;
index a2fde68..850ed0e 100644 (file)
@@ -18,10 +18,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-DragonflyZone::DragonflyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
-{
-}
+DragonflyZone::DragonflyZone(const std::string& name) : ClusterZone(name) {}
 
 DragonflyZone::Coords DragonflyZone::rankId_to_coords(int rankId) const
 {
@@ -124,7 +121,7 @@ void DragonflyZone::parse_specific_arguments(ClusterCreationArgs* cluster)
 }
 
 /* Generate the cluster once every node is created */
-void DragonflyZone::seal()
+void DragonflyZone::do_seal()
 {
   if (this->num_nodes_per_blade_ == 0) {
     return;
@@ -150,9 +147,9 @@ void DragonflyZone::generate_link(const std::string& id, int numlinks, resource:
   *linkdown = nullptr;
   LinkCreationArgs linkTemplate;
   linkTemplate.bandwidths.push_back(this->bw_ * numlinks);
-  linkTemplate.latency   = this->lat_;
-  linkTemplate.policy    = this->sharing_policy_;
-  linkTemplate.id        = id;
+  linkTemplate.latency = this->lat_;
+  linkTemplate.policy  = this->sharing_policy_;
+  linkTemplate.id      = id;
   sg_platf_new_link(&linkTemplate);
   XBT_DEBUG("Generating link %s", linkTemplate.id.c_str());
   resource::LinkImpl* link;
@@ -215,7 +212,7 @@ void DragonflyZone::generate_links()
       for (unsigned int k = j + 1; k < this->num_chassis_per_group_; k++) {
         for (unsigned int l = 0; l < this->num_blades_per_chassis_; l++) {
           std::string id = "black_link_in_group_" + std::to_string(i) + "_between_chassis_" + std::to_string(j) +
-              "_and_" + std::to_string(k) +"_blade_" + std::to_string(l) + "_" + std::to_string(uniqueId);
+                           "_and_" + std::to_string(k) + "_blade_" + std::to_string(l) + "_" + std::to_string(uniqueId);
           this->generate_link(id, this->num_links_black_, &linkup, &linkdown);
 
           this->routers_[i * num_blades_per_chassis_ * num_chassis_per_group_ + j * num_blades_per_chassis_ + l]
@@ -233,10 +230,11 @@ void DragonflyZone::generate_links()
   // FIXME: in reality blue links may be attached to several different routers
   for (unsigned int i = 0; i < this->num_groups_; i++) {
     for (unsigned int j = i + 1; j < this->num_groups_; j++) {
-      unsigned int routernumi                 = i * num_blades_per_chassis_ * num_chassis_per_group_ + j;
-      unsigned int routernumj                 = j * num_blades_per_chassis_ * num_chassis_per_group_ + i;
-      std::string id = "blue_link_between_group_"+ std::to_string(i) +"_and_" + std::to_string(j) +"_routers_" +
-          std::to_string(routernumi) + "_and_" + std::to_string(routernumj) + "_" + std::to_string(uniqueId);
+      unsigned int routernumi = i * num_blades_per_chassis_ * num_chassis_per_group_ + j;
+      unsigned int routernumj = j * num_blades_per_chassis_ * num_chassis_per_group_ + i;
+      std::string id = "blue_link_between_group_" + std::to_string(i) + "_and_" + std::to_string(j) + "_routers_" +
+                       std::to_string(routernumi) + "_and_" + std::to_string(routernumj) + "_" +
+                       std::to_string(uniqueId);
       this->generate_link(id, this->num_links_blue_, &linkup, &linkdown);
 
       this->routers_[routernumi].blue_link_ = linkup;
@@ -273,9 +271,9 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
   XBT_DEBUG("dst : %u group, %u chassis, %u blade, %u node", targetCoords.group, targetCoords.chassis,
             targetCoords.blade, targetCoords.node);
 
-  DragonflyRouter* myRouter = &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
+  DragonflyRouter* myRouter      = &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
                                         myCoords.chassis * num_blades_per_chassis_ + myCoords.blade];
-  DragonflyRouter* targetRouter = &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
+  DragonflyRouter* targetRouter  = &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
                                             targetCoords.chassis * num_blades_per_chassis_ + targetCoords.blade];
   DragonflyRouter* currentRouter = myRouter;
 
@@ -348,6 +346,6 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
     *latency +=
         targetRouter->my_nodes_[targetCoords.node * num_links_per_link_ + num_links_per_link_ - 1]->get_latency();
 }
-}
-}
-} // namespace
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
index 139d80e..8f2b14c 100644 (file)
@@ -15,10 +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(const std::string& name) : NetZoneImpl(name) {}
 
 EmptyZone::~EmptyZone() = default;
 
index 228527a..8ac6979 100644 (file)
@@ -12,7 +12,6 @@
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf_private.hpp"
 
-
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 
@@ -22,8 +21,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-FatTreeZone::FatTreeZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
+FatTreeZone::FatTreeZone(const std::string& name) : ClusterZone(name)
 {
   XBT_DEBUG("Creating a new fat tree.");
 }
@@ -130,7 +128,7 @@ void FatTreeZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg
 /* This function makes the assumption that parse_specific_arguments() and
  * addNodes() have already been called
  */
-void FatTreeZone::seal()
+void FatTreeZone::do_seal()
 {
   if (this->levels_ == 0) {
     return;
@@ -178,9 +176,9 @@ void FatTreeZone::seal()
 
 int FatTreeZone::connect_node_to_parents(FatTreeNode* node)
 {
-  auto currentParentNode                                = this->nodes_.begin();
-  int connectionsNumber                                 = 0;
-  const int level                                       = node->level;
+  auto currentParentNode = this->nodes_.begin();
+  int connectionsNumber  = 0;
+  const int level        = node->level;
   XBT_DEBUG("We are connecting node %d(%u,%u) to his parents.", node->id, node->level, node->position);
   currentParentNode += this->get_level_position(level + 1);
   for (unsigned int i = 0; i < this->nodes_by_level_[level + 1]; i++) {
@@ -444,17 +442,17 @@ FatTreeNode::FatTreeNode(const ClusterCreationArgs* cluster, int id, int level,
   LinkCreationArgs linkTemplate;
   if (cluster->limiter_link != 0.0) {
     linkTemplate.bandwidths.push_back(cluster->limiter_link);
-    linkTemplate.latency   = 0;
-    linkTemplate.policy    = s4u::Link::SharingPolicy::SHARED;
-    linkTemplate.id        = "limiter_"+std::to_string(id);
+    linkTemplate.latency = 0;
+    linkTemplate.policy  = s4u::Link::SharingPolicy::SHARED;
+    linkTemplate.id      = "limiter_" + std::to_string(id);
     sg_platf_new_link(&linkTemplate);
     this->limiter_link_ = s4u::Link::by_name(linkTemplate.id)->get_impl();
   }
   if (cluster->loopback_bw != 0.0 || cluster->loopback_lat != 0.0) {
     linkTemplate.bandwidths.push_back(cluster->loopback_bw);
-    linkTemplate.latency   = cluster->loopback_lat;
-    linkTemplate.policy    = s4u::Link::SharingPolicy::FATPIPE;
-    linkTemplate.id        = "loopback_"+ std::to_string(id);
+    linkTemplate.latency = cluster->loopback_lat;
+    linkTemplate.policy  = s4u::Link::SharingPolicy::FATPIPE;
+    linkTemplate.id      = "loopback_" + std::to_string(id);
     sg_platf_new_link(&linkTemplate);
     this->loopback = s4u::Link::by_name(linkTemplate.id)->get_impl();
   }
@@ -466,8 +464,8 @@ FatTreeLink::FatTreeLink(const ClusterCreationArgs* cluster, FatTreeNode* downNo
   static int uniqueId = 0;
   LinkCreationArgs linkTemplate;
   linkTemplate.bandwidths.push_back(cluster->bw);
-  linkTemplate.latency   = cluster->lat;
-  linkTemplate.policy    = cluster->sharing_policy; // sthg to do with that ?
+  linkTemplate.latency = cluster->lat;
+  linkTemplate.policy  = cluster->sharing_policy; // sthg to do with that ?
   linkTemplate.id =
       "link_from_" + std::to_string(downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId);
   sg_platf_new_link(&linkTemplate);
index e374648..cfd4dab 100644 (file)
@@ -23,10 +23,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-FloydZone::FloydZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : RoutedZone(father, name, netmodel)
-{
-}
+FloydZone::FloydZone(const std::string& name) : RoutedZone(name) {}
 
 FloydZone::~FloydZone()
 {
@@ -139,7 +136,7 @@ void FloydZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoi
   }
 }
 
-void FloydZone::seal()
+void FloydZone::do_seal()
 {
   /* set the size of table routing */
   unsigned int table_size = get_table_size();
@@ -172,6 +169,6 @@ void FloydZone::seal()
     }
   }
 }
-}
-}
-}
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
index b7c0f33..b3138b5 100644 (file)
@@ -16,12 +16,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 namespace simgrid {
 namespace kernel {
 namespace routing {
-FullZone::FullZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : RoutedZone(father, name, netmodel)
-{
-}
+FullZone::FullZone(const std::string& name) : RoutedZone(name) {}
 
-void FullZone::seal()
+void FullZone::do_seal()
 {
   unsigned int table_size = get_table_size();
 
@@ -53,7 +50,7 @@ void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
 {
   XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
 
-  unsigned int table_size        = get_table_size();
+  unsigned int table_size          = get_table_size();
   const RouteCreationArgs* e_route = TO_ROUTE_FULL(src->id(), dst->id());
 
   if (e_route != nullptr) {
@@ -109,6 +106,6 @@ void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoin
     TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false);
   }
 }
-}
-}
-} // namespace
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
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 6ae49f1..4dd41be 100644 (file)
@@ -21,21 +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_);
-  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*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_PM));
-  disk_model_ = static_cast<simgrid::kernel::resource::DiskModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::DISK));
-  host_model_ = static_cast<simgrid::surf::HostModel*>(
-      simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::HOST));
+  netpoint_     = new NetPoint(name_, NetPoint::Type::NetZone);
   XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id());
 }
 
@@ -98,7 +88,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();
 
@@ -401,6 +391,50 @@ void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
   if (route.gw_dst != dst)
     get_global_route(route.gw_dst, dst, links, latency);
 }
+
+void NetZoneImpl::seal()
+{
+  do_seal(); // derived class' specific sealing procedure
+  sealed_ = true;
+}
+
+void NetZoneImpl::set_parent(NetZoneImpl* parent)
+{
+  xbt_assert(sealed_ == false, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname());
+  father_ = parent;
+  netpoint_->set_englobing_zone(father_);
+}
+
+void NetZoneImpl::set_network_model(std::shared_ptr<resource::NetworkModel> netmodel)
+{
+  xbt_assert(sealed_ == false, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname());
+  network_model_ = std::move(netmodel);
+}
+
+void NetZoneImpl::set_cpu_vm_model(std::shared_ptr<resource::CpuModel> cpu_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
+  cpu_model_vm_ = std::move(cpu_model);
+}
+
+void NetZoneImpl::set_cpu_pm_model(std::shared_ptr<resource::CpuModel> cpu_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
+  cpu_model_pm_ = std::move(cpu_model);
+}
+
+void NetZoneImpl::set_disk_model(std::shared_ptr<resource::DiskModel> disk_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname());
+  disk_model_ = std::move(disk_model);
+}
+
+void NetZoneImpl::set_host_model(std::shared_ptr<surf::HostModel> host_model)
+{
+  xbt_assert(sealed_ == false, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname());
+  host_model_ = std::move(host_model);
+}
+
 } // namespace routing
 } // namespace kernel
 } // namespace simgrid
index bd992cc..4df9a27 100644 (file)
@@ -3,14 +3,14 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "simgrid/kernel/routing/RoutedZone.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
+#include "src/surf/network_interface.hpp"
+#include "src/surf/xml/platf_private.hpp"
 #include "xbt/dict.h"
 #include "xbt/graph.h"
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
-#include "simgrid/kernel/routing/NetPoint.hpp"
-#include "simgrid/kernel/routing/RoutedZone.hpp"
-#include "src/surf/network_interface.hpp"
-#include "src/surf/xml/platf_private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing");
 
@@ -54,10 +54,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-RoutedZone::RoutedZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : NetZoneImpl(father, name, netmodel)
-{
-}
+RoutedZone::RoutedZone(const std::string& name) : NetZoneImpl(name) {}
 
 void RoutedZone::get_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)
@@ -77,8 +74,8 @@ void RoutedZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt
 
       xbt_node_t current;
       xbt_node_t previous;
-      const char *previous_name;
-      const char *current_name;
+      const charprevious_name;
+      const charcurrent_name;
 
       if (route.gw_src) {
         previous      = new_xbt_graph_node(graph, route.gw_src->get_cname(), nodes);
@@ -192,7 +189,7 @@ void RoutedZone::add_route_check_params(NetPoint* src, NetPoint* dst, NetPoint*
                gw_dst->get_cname(), dstName);
     xbt_assert(not link_list.empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName, gw_src->get_cname(),
                dstName, gw_dst->get_cname());
-    s4u::NetZone::on_route_creation(symmetrical,  gw_src, gw_dst, gw_src, gw_dst, link_list);
+    s4u::NetZone::on_route_creation(symmetrical, gw_src, gw_dst, gw_src, gw_dst, link_list);
   }
 }
 } // namespace routing
index 0c7b0bc..1a123c1 100644 (file)
@@ -18,10 +18,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "T
 namespace simgrid {
 namespace kernel {
 namespace routing {
-TorusZone::TorusZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
-{
-}
+TorusZone::TorusZone(const std::string& name) : ClusterZone(name) {}
 
 void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position)
 {
@@ -39,10 +36,10 @@ void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int
     // name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case)
     std::string link_id =
         std::string(cluster->id) + "_link_from_" + std::to_string(id) + "_to_" + std::to_string(neighbor_rank_id);
-    link.id        = link_id;
+    link.id = link_id;
     link.bandwidths.push_back(cluster->bw);
-    link.latency   = cluster->lat;
-    link.policy    = cluster->sharing_policy;
+    link.latency = cluster->lat;
+    link.policy  = cluster->sharing_policy;
     sg_platf_new_link(&link);
     resource::LinkImpl* linkUp;
     resource::LinkImpl* linkDown;
@@ -134,9 +131,9 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
       if ((current_node / dim_product) % cur_dim != (dst->id() / dim_product) % cur_dim) {
         if ((targetCoords[j] > myCoords[j] &&
              targetCoords[j] <= myCoords[j] + cur_dim / 2) // Is the target node on the right, without the wrap-around?
-            || (myCoords[j] > cur_dim / 2 &&
-                (myCoords[j] + cur_dim / 2) % cur_dim >=
-                    targetCoords[j])) { // Or do we need to use the wrap around to reach it?
+            ||
+            (myCoords[j] > cur_dim / 2 && (myCoords[j] + cur_dim / 2) % cur_dim >=
+                                              targetCoords[j])) { // Or do we need to use the wrap around to reach it?
           if ((current_node / dim_product) % cur_dim == cur_dim - 1)
             next_node = (current_node + dim_product - dim_product * cur_dim);
           else
@@ -175,7 +172,7 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
       route->link_list.push_back(info.first);
     }
 
-    info = private_links_.at(linkOffset);
+    info                    = private_links_.at(linkOffset);
     resource::LinkImpl* lnk = use_lnk_up ? info.first : info.second;
 
     route->link_list.push_back(lnk);
index 05c2463..70822eb 100644 (file)
@@ -61,10 +61,7 @@ static std::vector<double>* netpoint_get_coords(NetPoint* np)
   return &coords->coords;
 }
 
-VivaldiZone::VivaldiZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
-{
-}
+VivaldiZone::VivaldiZone(const std::string& name) : ClusterZone(name) {}
 
 void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, const std::string& coord)
 {
@@ -73,8 +70,8 @@ void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out,
 
   new vivaldi::Coords(netpoint, coord);
 
-  std::string link_up      = "link_" + netpoint->get_name() + "_UP";
-  std::string link_down    = "link_" + netpoint->get_name() + "_DOWN";
+  std::string link_up   = "link_" + netpoint->get_name() + "_UP";
+  std::string link_down = "link_" + netpoint->get_name() + "_DOWN";
   resource::LinkImpl* linkUp =
       get_network_model()->create_link(link_up, std::vector<double>(1, bw_out), s4u::Link::SharingPolicy::SHARED);
   linkUp->seal();
index 1985a95..3035640 100644 (file)
@@ -16,12 +16,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_wifi, surf, "Routing part of surf");
 namespace simgrid {
 namespace kernel {
 namespace routing {
-WifiZone::WifiZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : RoutedZone(father, name, netmodel)
-{
-}
+WifiZone::WifiZone(const std::string& name) : RoutedZone(name) {}
 
-void WifiZone::seal()
+void WifiZone::do_seal()
 {
   const char* AP_name = get_property("access_point");
   if (AP_name != nullptr) {
index 973cadc..cd9544b 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_cas01.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
@@ -49,11 +51,14 @@ void surf_cpu_model_init_Cas01()
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
   auto cpu_model_pm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>(algo);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
-                                                         std::move(cpu_model_pm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_pm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model_pm);
+
   auto cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>(algo);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
-                                                         std::move(cpu_model_vm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM, cpu_model_vm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_vm_model(cpu_model_vm);
 }
 
 namespace simgrid {
index c62b93b..6492de2 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "cpu_ti.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
@@ -269,16 +271,16 @@ int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
 void CpuTiModel::create_pm_vm_models()
 {
   auto cpu_model_pm = std::make_shared<CpuTiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
-                                                         std::move(cpu_model_pm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_pm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model_pm);
   auto cpu_model_vm = std::make_shared<CpuTiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
-                                                         std::move(cpu_model_vm), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM, cpu_model_vm,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_vm_model(cpu_model_vm);
 }
 
-CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
-{
-}
+CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL) {}
 
 Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
index c39c8f9..8e910ff 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "disk_s19.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -21,8 +22,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_disk);
 void surf_disk_model_init_default()
 {
   auto disk_model = std::make_shared<simgrid::kernel::resource::DiskS19Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK,
-                                                         std::move(disk_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK, disk_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_disk_model(disk_model);
 }
 
 namespace simgrid {
index fb5bab9..c29dd27 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "src/surf/host_clm03.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "surf/surf.hpp"
@@ -15,8 +17,9 @@ void surf_host_model_init_current_default()
 {
   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
   simgrid::config::set_default<bool>("network/crosstraffic", true);
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
   surf_cpu_model_init_Cas01();
   surf_network_model_init_LegrandVelho();
 }
@@ -24,8 +27,9 @@ void surf_host_model_init_current_default()
 void surf_host_model_init_compound()
 {
   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
 }
 
 namespace simgrid {
@@ -58,7 +62,7 @@ kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u
   /* FIXME[donassolo]: getting the network_model from the origin host
    * Soon we need to change this function to first get the routes and later
    * create the respective surf actions */
-  auto* net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
+  auto net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
     action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
index 856bc11..a392cd3 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/surf/network_cm02.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -38,8 +40,9 @@ double sg_weight_S_parameter = 0.0; /* default value; can be set by model or fro
 void surf_network_model_init_LegrandVelho()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::config::set_default<double>("network/latency-factor", 13.01);
   simgrid::config::set_default<double>("network/bandwidth-factor", 0.97);
@@ -64,8 +67,9 @@ void surf_network_model_init_CM02()
   simgrid::config::set_default<double>("network/weight-S", 0.0);
 
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 namespace simgrid {
index 2fc20ce..ba728d4 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_constant.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
@@ -16,17 +18,16 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 void surf_network_model_init_Constant()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 namespace simgrid {
 namespace kernel {
 namespace resource {
 
-NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
-{
-}
+NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL) {}
 
 LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
                                             s4u::Link::SharingPolicy)
index 6bd014a..6daaa8c 100644 (file)
@@ -22,7 +22,7 @@ static void IB_create_host_callback(simgrid::s4u::Host const& host)
   using simgrid::kernel::resource::NetworkIBModel;
 
   static int id = 0;
-  auto* ibModel = static_cast<NetworkIBModel*>(host.get_netpoint()->get_englobing_zone()->get_network_model());
+  auto* ibModel = static_cast<NetworkIBModel*>(host.get_netpoint()->get_englobing_zone()->get_network_model().get());
   ibModel->active_nodes.emplace(host.get_name(), IBNode(id));
   id++;
 }
@@ -70,8 +70,9 @@ static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& ac
 void surf_network_model_init_IB()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkIBModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::s4u::Link::on_communication_state_change.connect(IB_action_state_changed_callback);
   simgrid::s4u::Link::on_communicate.connect(IB_action_init_callback);
index dc283e2..cba54fc 100644 (file)
@@ -28,6 +28,7 @@
 #include "ns3/ns3_simulator.hpp"
 
 #include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "simgrid/kernel/routing/WifiZone.hpp"
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Engine.hpp"
@@ -260,8 +261,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
 void surf_network_model_init_NS3()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 }
 
 static simgrid::config::Flag<std::string>
index 72e8c02..0c32b4f 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_smpi.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "smpi_utils.hpp"
 #include "src/kernel/EngineImpl.hpp"
@@ -34,8 +36,9 @@ std::vector<s_smpi_factor_t> smpi_lat_factor;
 void surf_network_model_init_SMPI()
 {
   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkSmpiModel>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
-                                                         std::move(net_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   simgrid::config::set_default<double>("network/weight-S", 8775);
 }
@@ -44,9 +47,7 @@ namespace simgrid {
 namespace kernel {
 namespace resource {
 
-NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
-{
-}
+NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model() {}
 
 double NetworkSmpiModel::get_bandwidth_factor(double size)
 {
index dbb89d7..d735582 100644 (file)
@@ -4,6 +4,8 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "ptask_L07.hpp"
+#include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/profile/Event.hpp"
 #include "surf/surf.hpp"
@@ -22,8 +24,9 @@ void surf_host_model_init_ptask_L07()
   XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
 
   auto host_model = std::make_shared<simgrid::surf::HostL07Model>();
-  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
-                                                         std::move(host_model), true);
+  simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST, host_model,
+                                                         true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
 }
 
 namespace simgrid {
@@ -36,10 +39,12 @@ HostL07Model::HostL07Model() : HostModel()
 
   auto net_model = std::make_shared<NetworkL07Model>(this, maxmin_system);
   auto engine    = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(simgrid::kernel::resource::Model::Type::NETWORK, std::move(net_model), true);
+  engine->add_model(simgrid::kernel::resource::Model::Type::NETWORK, net_model, true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
 
   auto cpu_model = std::make_shared<CpuL07Model>(this, maxmin_system);
-  engine->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, std::move(cpu_model), true);
+  engine->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model, true);
+  simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_cpu_pm_model(cpu_model);
 }
 
 CpuL07Model::CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys)
index 867b0d2..c71b8b2 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, ""))
@@ -484,67 +484,44 @@ static void surf_config_models_setup()
 }
 
 /**
- * @brief Add a Zone to the platform
- *
- * Add a new autonomous system to the platform. Any elements (such as host, router or sub-Zone) added after this call
- * and before the corresponding call to sg_platf_new_Zone_seal() will be added to this Zone.
- *
- * Once this function was called, the configuration concerning the used models cannot be changed anymore.
+ * @brief Auxiliary function to build the object NetZoneImpl
  *
+ * Builds the objects, setting its father properties and root netzone if needed
  * @param zone the parameters defining the Zone to build.
+ * @return Pointer to recently created netzone
  */
-simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone)
+static simgrid::kernel::routing::NetZoneImpl*
+sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone)
 {
-  if (not surf_parse_models_setup_already_called) {
-    simgrid::s4u::Engine::on_platform_creation();
-
-    /* Initialize the surf models. That must be done after we got all config, and before we need the models.
-     * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
-     *
-     * I'm not sure for <trace> and <trace_connect>, there may be a bug here
-     * (FIXME: check it out by creating a file beginning with one of these tags)
-     * but cluster and peer come down to zone creations, so putting this verification here is correct.
-     */
-    surf_parse_models_setup_already_called = 1;
-    surf_config_models_setup();
-  }
-
-  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
-                            * any further config now that we created some real content */
-
   /* search the routing model */
   simgrid::kernel::routing::NetZoneImpl* new_zone = nullptr;
-  simgrid::kernel::resource::NetworkModel* netmodel =
-      current_routing == nullptr ? static_cast<simgrid::kernel::resource::NetworkModel*>(
-                                       simgrid::kernel::EngineImpl::get_instance()->get_default_model(
-                                           simgrid::kernel::resource::Model::Type::NETWORK))
-                                 : current_routing->get_network_model();
 
   if (strcasecmp(zone->routing.c_str(), "Cluster") == 0) {
-    new_zone = new simgrid::kernel::routing::ClusterZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::ClusterZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "ClusterDragonfly") == 0) {
-    new_zone = new simgrid::kernel::routing::DragonflyZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::DragonflyZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "ClusterTorus") == 0) {
-    new_zone = new simgrid::kernel::routing::TorusZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::TorusZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "ClusterFatTree") == 0) {
-    new_zone = new simgrid::kernel::routing::FatTreeZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::FatTreeZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "Dijkstra") == 0) {
-    new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, false);
+    new_zone = new simgrid::kernel::routing::DijkstraZone(zone->id, false);
   } else if (strcasecmp(zone->routing.c_str(), "DijkstraCache") == 0) {
-    new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, netmodel, true);
+    new_zone = new simgrid::kernel::routing::DijkstraZone(zone->id, true);
   } else if (strcasecmp(zone->routing.c_str(), "Floyd") == 0) {
-    new_zone = new simgrid::kernel::routing::FloydZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::FloydZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "Full") == 0) {
-    new_zone = new simgrid::kernel::routing::FullZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::FullZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "None") == 0) {
-    new_zone = new simgrid::kernel::routing::EmptyZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::EmptyZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "Vivaldi") == 0) {
-    new_zone = new simgrid::kernel::routing::VivaldiZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::VivaldiZone(zone->id);
   } else if (strcasecmp(zone->routing.c_str(), "Wifi") == 0) {
-    new_zone = new simgrid::kernel::routing::WifiZone(current_routing, zone->id, netmodel);
+    new_zone = new simgrid::kernel::routing::WifiZone(zone->id);
   } else {
     xbt_die("Not a valid model!");
   }
+  new_zone->set_parent(current_routing);
 
   if (current_routing == nullptr) { /* it is the first one */
     simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone->get_iface());
@@ -554,8 +531,51 @@ simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::ke
       current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive;
     /* add to the sons dictionary */
     current_routing->get_children()->push_back(new_zone);
+    /* set models from parent netzone */
+    new_zone->set_network_model(current_routing->get_network_model());
+    new_zone->set_cpu_pm_model(current_routing->get_cpu_pm_model());
+    new_zone->set_cpu_vm_model(current_routing->get_cpu_vm_model());
+    new_zone->set_disk_model(current_routing->get_disk_model());
+    new_zone->set_host_model(current_routing->get_host_model());
+  }
+  return new_zone;
+}
+
+/**
+ * @brief Add a Zone to the platform
+ *
+ * Add a new autonomous system to the platform. Any elements (such as host, router or sub-Zone) added after this call
+ * and before the corresponding call to sg_platf_new_Zone_seal() will be added to this Zone.
+ *
+ * Once this function was called, the configuration concerning the used models cannot be changed anymore.
+ *
+ * @param zone the parameters defining the Zone to build.
+ */
+simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone)
+{
+  /* First create the zone.
+   * This order is important to assure that root netzone is set when models are setting
+   * the default mode for each resource (CPU, network, etc)
+   */
+  auto* new_zone = sg_platf_create_zone(zone);
+
+  if (not surf_parse_models_setup_already_called) {
+    simgrid::s4u::Engine::on_platform_creation();
+
+    /* Initialize the surf models. That must be done after we got all config, and before we need the models.
+     * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
+     *
+     * I'm not sure for <trace> and <trace_connect>, there may be a bug here
+     * (FIXME: check it out by creating a file beginning with one of these tags)
+     * but cluster and peer come down to zone creations, so putting this verification here is correct.
+     */
+    surf_parse_models_setup_already_called = 1;
+    surf_config_models_setup();
   }
 
+  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
+                            * any further config now that we created some real content */
+
   /* set the new current component of the tree */
   current_routing = new_zone;
   simgrid::s4u::NetZone::on_creation(*new_zone->get_iface()); // notify the signal
index 1286111..5cf04a0 100644 (file)
@@ -42,12 +42,12 @@ int main(int argc, char** argv)
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   parse_platform_file(argv[1]);
 
-  const_sg_netzone_t as_zone                         = sg_zone_get_by_name("AS0");
-  simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
-  simgrid::kernel::resource::CpuModel* cpu_model_pm  = as_zone->get_impl()->get_cpu_pm_model();
+  const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
+  auto net_model             = as_zone->get_impl()->get_network_model();
+  auto cpu_model_pm          = as_zone->get_impl()->get_cpu_pm_model();
 
-  XBT_DEBUG("CPU model: %p", cpu_model_pm);
-  XBT_DEBUG("Network model: %p", net_model);
+  XBT_DEBUG("CPU model: %p", cpu_model_pm.get());
+  XBT_DEBUG("Network model: %p", net_model.get());
   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
 
index 5288350..c79d19b 100644 (file)
@@ -38,8 +38,8 @@ int main(int argc, char** argv)
   hostB->pimpl_cpu->execution_start(1000.0);
   hostB->pimpl_cpu->sleep(7.32);
 
-  const_sg_netzone_t as_zone                         = sg_zone_get_by_name("AS0");
-  simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
+  const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
+  auto net_model             = as_zone->get_impl()->get_network_model();
   net_model->communicate(hostA, hostB, 150.0, -1.0);
 
   surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */