Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
chain reaction when solving implicit cast smells
[simgrid.git] / src / kernel / routing / NetZoneImpl.cpp
1 /* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/include/simgrid/sg_config.hpp"
11 #include "src/kernel/EngineImpl.hpp"
12 #include "src/kernel/resource/DiskImpl.hpp"
13 #include "src/surf/HostImpl.hpp"
14 #include "src/surf/SplitDuplexLinkImpl.hpp"
15 #include "src/surf/cpu_interface.hpp"
16 #include "src/surf/network_interface.hpp"
17 #include "surf/surf.hpp"
18
19 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_route);
20
21 namespace simgrid {
22 namespace kernel {
23 namespace routing {
24
25 /* Pick the right models for CPU, net and host, and call their model_init_preparse */
26 static void surf_config_models_setup()
27 {
28   std::string host_model_name    = simgrid::config::get_value<std::string>("host/model");
29   std::string network_model_name = simgrid::config::get_value<std::string>("network/model");
30   std::string cpu_model_name     = simgrid::config::get_value<std::string>("cpu/model");
31   std::string disk_model_name    = simgrid::config::get_value<std::string>("disk/model");
32
33   /* The compound host model is needed when using non-default net/cpu models */
34   if ((not simgrid::config::is_default("network/model") || not simgrid::config::is_default("cpu/model")) &&
35       simgrid::config::is_default("host/model")) {
36     host_model_name = "compound";
37     simgrid::config::set_value("host/model", host_model_name);
38   }
39
40   XBT_DEBUG("host model: %s", host_model_name.c_str());
41   if (host_model_name == "compound") {
42     xbt_assert(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model");
43     xbt_assert(not network_model_name.empty(), "Set a network model to use with the 'compound' host model");
44
45     const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name);
46     cpu_model->model_init_preparse();
47
48     const auto* network_model = find_model_description(surf_network_model_description, network_model_name);
49     network_model->model_init_preparse();
50   }
51
52   XBT_DEBUG("Call host_model_init");
53   const auto* host_model = find_model_description(surf_host_model_description, host_model_name);
54   host_model->model_init_preparse();
55
56   XBT_DEBUG("Call vm_model_init");
57   /* ideally we should get back the pointer to CpuModel from model_init_preparse(), but this
58    * requires changing the declaration of surf_cpu_model_description.
59    * To be reviewed in the future */
60   surf_vm_model_init_HL13(
61       simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->get_cpu_pm_model().get());
62
63   XBT_DEBUG("Call disk_model_init");
64   const auto* disk_model = find_model_description(surf_disk_model_description, disk_model_name);
65   disk_model->model_init_preparse();
66 }
67
68 xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
69                  kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
70                  std::vector<kernel::resource::LinkImpl*> const& link_list)>
71     NetZoneImpl::on_route_creation;
72
73 NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name)
74 {
75   /* workaroud: first netzoneImpl will be the root netzone.
76    * Without globals and with current surf_*_model_description init functions, we need
77    * the root netzone to exist when creating the models.
78    * This was usually done at sg_platf.cpp, during XML parsing */
79   if (not s4u::Engine::get_instance()->get_netzone_root()) {
80     s4u::Engine::get_instance()->set_netzone_root(&piface_);
81     /* root netzone set, initialize models */
82     simgrid::s4u::Engine::on_platform_creation();
83
84     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
85      * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
86      *
87      * I'm not sure for <trace> and <trace_connect>, there may be a bug here
88      * (FIXME: check it out by creating a file beginning with one of these tags)
89      * but cluster and peer come down to zone creations, so putting this verification here is correct.
90      */
91     surf_config_models_setup();
92   }
93
94   xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(get_name()),
95              "Refusing to create a second NetZone called '%s'.", get_cname());
96   netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone);
97   XBT_DEBUG("NetZone '%s' created with the id '%lu'", get_cname(), netpoint_->id());
98   _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
99                             * any further config now that we created some real content */
100   simgrid::s4u::NetZone::on_creation(piface_); // notify the signal
101 }
102
103 NetZoneImpl::~NetZoneImpl()
104 {
105   for (auto const& nz : children_)
106     delete nz;
107
108   for (auto const& kv : bypass_routes_)
109     delete kv.second;
110
111   s4u::Engine::get_instance()->netpoint_unregister(netpoint_);
112 }
113
114 void NetZoneImpl::add_child(NetZoneImpl* new_zone)
115 {
116   xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname());
117   /* set the parent behavior */
118   hierarchy_ = RoutingMode::recursive;
119   children_.push_back(new_zone);
120 }
121
122 /** @brief Returns the list of the hosts found in this NetZone (not recursively)
123  *
124  * Only the hosts that are directly contained in this NetZone are retrieved,
125  * not the ones contained in sub-netzones.
126  */
127 std::vector<s4u::Host*> NetZoneImpl::get_all_hosts() const
128 {
129   std::vector<s4u::Host*> res;
130   for (auto const& card : get_vertices()) {
131     s4u::Host* host = s4u::Host::by_name_or_null(card->get_name());
132     if (host != nullptr)
133       res.push_back(host);
134   }
135   return res;
136 }
137 int NetZoneImpl::get_host_count() const
138 {
139   int count = 0;
140   for (auto const& card : get_vertices()) {
141     const s4u::Host* host = s4u::Host::by_name_or_null(card->get_name());
142     if (host != nullptr)
143       count++;
144   }
145   return count;
146 }
147
148 s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
149 {
150   xbt_assert(cpu_model_pm_,
151              "Impossible to create host: %s. Invalid CPU model: nullptr. Have you set the parent of this NetZone: %s?",
152              name.c_str(), get_cname());
153   auto* res = (new surf::HostImpl(name))->get_iface();
154   res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
155
156   cpu_model_pm_->create_cpu(res, speed_per_pstate);
157
158   return res;
159 }
160
161 s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<double>& bandwidths)
162 {
163   xbt_assert(
164       network_model_,
165       "Impossible to create link: %s. Invalid network model: nullptr. Have you set the parent of this NetZone: %s?",
166       name.c_str(), get_cname());
167   return network_model_->create_link(name, bandwidths)->get_iface();
168 }
169
170 s4u::SplitDuplexLink* NetZoneImpl::create_split_duplex_link(const std::string& name,
171                                                             const std::vector<double>& bandwidths)
172 {
173   auto* link_up                  = network_model_->create_link(name + "_UP", bandwidths);
174   auto* link_down                = network_model_->create_link(name + "_DOWN", bandwidths);
175   auto link                      = std::make_unique<resource::SplitDuplexLinkImpl>(name, link_up, link_down);
176   auto* link_iface               = link->get_iface();
177   EngineImpl::get_instance()->add_split_duplex_link(name, std::move(link));
178   return link_iface;
179 }
180
181 s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
182 {
183   xbt_assert(disk_model_,
184              "Impossible to create disk: %s. Invalid disk model: nullptr. Have you set the parent of this NetZone: %s?",
185              name.c_str(), get_cname());
186   auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth);
187
188   return l->get_iface();
189 }
190
191 NetPoint* NetZoneImpl::create_router(const std::string& name)
192 {
193   xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(name),
194              "Refusing to create a router named '%s': this name already describes a node.", name.c_str());
195
196   return (new NetPoint(name, NetPoint::Type::Router))->set_englobing_zone(this);
197 }
198
199 unsigned long NetZoneImpl::add_component(NetPoint* elm)
200 {
201   vertices_.push_back(elm);
202   return vertices_.size() - 1; // The rank of the newly created object
203 }
204
205 std::vector<resource::LinkImpl*> NetZoneImpl::get_link_list_impl(const std::vector<s4u::LinkInRoute>& link_list,
206                                                                  bool backroute) const
207 {
208   std::vector<resource::LinkImpl*> links;
209
210   for (const auto& link : link_list) {
211     if (link.get_link()->get_sharing_policy() != s4u::Link::SharingPolicy::SPLITDUPLEX) {
212       links.push_back(link.get_link()->get_impl());
213       continue;
214     }
215     // split-duplex links
216     const auto* sd_link = dynamic_cast<const s4u::SplitDuplexLink*>(link.get_link());
217     xbt_assert(sd_link,
218                "Add_route: cast to SpliDuplexLink impossible. This should not happen, please contact SimGrid team");
219     resource::LinkImpl* link_impl;
220     switch (link.get_direction()) {
221       case s4u::LinkInRoute::Direction::UP:
222         if (backroute)
223           link_impl = sd_link->get_link_down()->get_impl();
224         else
225           link_impl = sd_link->get_link_up()->get_impl();
226         break;
227       case s4u::LinkInRoute::Direction::DOWN:
228         if (backroute)
229           link_impl = sd_link->get_link_up()->get_impl();
230         else
231           link_impl = sd_link->get_link_down()->get_impl();
232         break;
233       default:
234         throw std::invalid_argument("Invalid add_route. Split-Duplex link without a direction: " +
235                                     link.get_link()->get_name());
236     }
237     links.push_back(link_impl);
238   }
239   return links;
240 }
241
242 void NetZoneImpl::add_route(NetPoint* /*src*/, NetPoint* /*dst*/, NetPoint* /*gw_src*/, NetPoint* /*gw_dst*/,
243                             const std::vector<s4u::LinkInRoute>& /*link_list_*/, bool /*symmetrical*/)
244 {
245   xbt_die("NetZone '%s' does not accept new routes (wrong class).", get_cname());
246 }
247
248 void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
249                                    const std::vector<s4u::LinkInRoute>& link_list)
250 {
251   /* Argument validity checks */
252   if (gw_dst) {
253     XBT_DEBUG("Load bypassNetzoneRoute from %s@%s to %s@%s", src->get_cname(), gw_src->get_cname(), dst->get_cname(),
254               gw_dst->get_cname());
255     xbt_assert(not link_list.empty(), "Bypass route between %s@%s and %s@%s cannot be empty.", src->get_cname(),
256                gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
257     xbt_assert(bypass_routes_.find({src, dst}) == bypass_routes_.end(),
258                "The bypass route between %s@%s and %s@%s already exists.", src->get_cname(), gw_src->get_cname(),
259                dst->get_cname(), gw_dst->get_cname());
260   } else {
261     XBT_DEBUG("Load bypassRoute from %s to %s", src->get_cname(), dst->get_cname());
262     xbt_assert(not link_list.empty(), "Bypass route between %s and %s cannot be empty.", src->get_cname(),
263                dst->get_cname());
264     xbt_assert(bypass_routes_.find({src, dst}) == bypass_routes_.end(),
265                "The bypass route between %s and %s already exists.", src->get_cname(), dst->get_cname());
266   }
267
268   /* Build a copy that will be stored in the dict */
269   auto* newRoute = new BypassRoute(gw_src, gw_dst);
270   auto converted_list = get_link_list_impl(link_list, false);
271   newRoute->links.insert(newRoute->links.end(), begin(converted_list), end(converted_list));
272
273   /* Store it */
274   bypass_routes_.insert({{src, dst}, newRoute});
275 }
276
277 /** @brief Get the common ancestor and its first children in each line leading to src and dst
278  *
279  * In the recursive case, this sets common_ancestor, src_ancestor and dst_ancestor are set as follows.
280  * @verbatim
281  *         platform root
282  *               |
283  *              ...                <- possibly long path
284  *               |
285  *         common_ancestor
286  *           /        \
287  *          /          \
288  *         /            \          <- direct links
289  *        /              \
290  *       /                \
291  *  src_ancestor     dst_ancestor  <- must be different in the recursive case
292  *      |                   |
293  *     ...                 ...     <-- possibly long paths (one hop or more)
294  *      |                   |
295  *     src                 dst
296  *  @endverbatim
297  *
298  *  In the base case (when src and dst are in the same netzone), things are as follows:
299  *  @verbatim
300  *                  platform root
301  *                        |
302  *                       ...                      <-- possibly long path
303  *                        |
304  * common_ancestor==src_ancestor==dst_ancestor    <-- all the same value
305  *                   /        \
306  *                  /          \                  <-- direct links (exactly one hop)
307  *                 /            \
308  *              src              dst
309  *  @endverbatim
310  *
311  * A specific recursive case occurs when src is the ancestor of dst. In this case,
312  * the base case routing should be used so the common_ancestor is specifically set
313  * to src_ancestor==dst_ancestor.
314  * Naturally, things are completely symmetrical if dst is the ancestor of src.
315  * @verbatim
316  *            platform root
317  *                  |
318  *                 ...                <-- possibly long path
319  *                  |
320  *  src == src_ancestor==dst_ancestor==common_ancestor <-- same value
321  *                  |
322  *                 ...                <-- possibly long path (one hop or more)
323  *                  |
324  *                 dst
325  *  @endverbatim
326  */
327 static void find_common_ancestors(const NetPoint* src, const NetPoint* dst,
328                                   /* OUT */ NetZoneImpl** common_ancestor, NetZoneImpl** src_ancestor,
329                                   NetZoneImpl** dst_ancestor)
330 {
331   /* Deal with the easy base case */
332   if (src->get_englobing_zone() == dst->get_englobing_zone()) {
333     *common_ancestor = src->get_englobing_zone();
334     *src_ancestor    = *common_ancestor;
335     *dst_ancestor    = *common_ancestor;
336     return;
337   }
338
339   /* engage the full recursive search */
340
341   /* (1) find the path to root of src and dst*/
342   const NetZoneImpl* src_as = src->get_englobing_zone();
343   const NetZoneImpl* dst_as = dst->get_englobing_zone();
344
345   xbt_assert(src_as, "Host %s must be in a netzone", src->get_cname());
346   xbt_assert(dst_as, "Host %s must be in a netzone", dst->get_cname());
347
348   /* (2) find the path to the root routing component */
349   std::vector<NetZoneImpl*> path_src;
350   NetZoneImpl* current = src->get_englobing_zone();
351   while (current != nullptr) {
352     path_src.push_back(current);
353     current = current->get_parent();
354   }
355   std::vector<NetZoneImpl*> path_dst;
356   current = dst->get_englobing_zone();
357   while (current != nullptr) {
358     path_dst.push_back(current);
359     current = current->get_parent();
360   }
361
362   /* (3) find the common parent.
363    * Before that, index_src and index_dst may be different, they both point to nullptr in path_src/path_dst
364    * So we move them down simultaneously as long as they point to the same content.
365    *
366    * This works because all SimGrid platform have a unique root element (that is the last element of both paths).
367    */
368   NetZoneImpl* parent = nullptr; // the netzone we dropped on the previous loop iteration
369   while (path_src.size() > 1 && path_dst.size() > 1 && path_src.back() == path_dst.back()) {
370     parent = path_src.back();
371     path_src.pop_back();
372     path_dst.pop_back();
373   }
374
375   /* (4) we found the difference at least. Finalize the returned values */
376   *src_ancestor = path_src.back();                  /* the first different parent of src */
377   *dst_ancestor = path_dst.back();                  /* the first different parent of dst */
378   if (*src_ancestor == *dst_ancestor) {             // src is the ancestor of dst, or the contrary
379     *common_ancestor = *src_ancestor;
380   } else {
381     xbt_assert(parent != nullptr);
382     *common_ancestor = parent;
383   }
384 }
385
386 /* PRECONDITION: this is the common ancestor of src and dst */
387 bool NetZoneImpl::get_bypass_route(const NetPoint* src, const NetPoint* dst,
388                                    /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
389                                    std::unordered_set<NetZoneImpl*>& netzones)
390 {
391   // If never set a bypass route return nullptr without any further computations
392   if (bypass_routes_.empty())
393     return false;
394
395   /* Base case, no recursion is needed */
396   if (dst->get_englobing_zone() == this && src->get_englobing_zone() == this) {
397     if (bypass_routes_.find({src, dst}) != bypass_routes_.end()) {
398       const BypassRoute* bypassedRoute = bypass_routes_.at({src, dst});
399       add_link_latency(links, bypassedRoute->links, latency);
400       XBT_DEBUG("Found a bypass route from '%s' to '%s' with %zu links", src->get_cname(), dst->get_cname(),
401                 bypassedRoute->links.size());
402       return true;
403     }
404     return false;
405   }
406
407   /* Engage recursive search */
408
409   /* (1) find the path to the root routing component */
410   std::vector<NetZoneImpl*> path_src;
411   NetZoneImpl* current = src->get_englobing_zone();
412   while (current != nullptr) {
413     path_src.push_back(current);
414     current = current->parent_;
415   }
416
417   std::vector<NetZoneImpl*> path_dst;
418   current = dst->get_englobing_zone();
419   while (current != nullptr) {
420     path_dst.push_back(current);
421     current = current->parent_;
422   }
423
424   /* (2) find the common parent */
425   while (path_src.size() > 1 && path_dst.size() > 1 && path_src.back() == path_dst.back()) {
426     path_src.pop_back();
427     path_dst.pop_back();
428   }
429
430   /* (3) Search for a bypass making the path up to the ancestor useless */
431   const BypassRoute* bypassedRoute = nullptr;
432   std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*> key;
433   // Search for a bypass with the given indices. Returns true if found. Initialize variables `bypassedRoute' and `key'.
434   auto lookup = [&bypassedRoute, &key, &path_src, &path_dst, this](unsigned src_index, unsigned dst_index) {
435     if (src_index < path_src.size() && dst_index < path_dst.size()) {
436       key      = {path_src[src_index]->netpoint_, path_dst[dst_index]->netpoint_};
437       auto bpr = bypass_routes_.find(key);
438       if (bpr != bypass_routes_.end()) {
439         bypassedRoute = bpr->second;
440         return true;
441       }
442     }
443     return false;
444   };
445
446   for (unsigned max = 0, max_index = std::max(path_src.size(), path_dst.size()); max < max_index; max++) {
447     for (unsigned i = 0; i < max; i++) {
448       if (lookup(i, max) || lookup(max, i))
449         break;
450     }
451     if (bypassedRoute || lookup(max, max))
452       break;
453   }
454
455   /* (4) If we have the bypass, use it. If not, caller will do the Right Thing. */
456   if (bypassedRoute) {
457     XBT_DEBUG("Found a bypass route from '%s' to '%s' with %zu links. We may have to complete it with recursive "
458               "calls to getRoute",
459               src->get_cname(), dst->get_cname(), bypassedRoute->links.size());
460     if (src != key.first)
461       get_global_route_with_netzones(src, bypassedRoute->gw_src, links, latency, netzones);
462     add_link_latency(links, bypassedRoute->links, latency);
463     if (dst != key.second)
464       get_global_route_with_netzones(bypassedRoute->gw_dst, dst, links, latency, netzones);
465     return true;
466   }
467   XBT_DEBUG("No bypass route from '%s' to '%s'.", src->get_cname(), dst->get_cname());
468   return false;
469 }
470
471 void NetZoneImpl::get_global_route(const NetPoint* src, const NetPoint* dst,
472                                    /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency)
473 {
474   std::unordered_set<NetZoneImpl*> netzones;
475   get_global_route_with_netzones(src, dst, links, latency, netzones);
476 }
477
478 void NetZoneImpl::get_global_route_with_netzones(const NetPoint* src, const NetPoint* dst,
479                                                  /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
480                                                  std::unordered_set<NetZoneImpl*>& netzones)
481 {
482   Route route;
483
484   XBT_DEBUG("Resolve route from '%s' to '%s'", src->get_cname(), dst->get_cname());
485
486   /* Find how src and dst are interconnected */
487   NetZoneImpl* common_ancestor;
488   NetZoneImpl* src_ancestor;
489   NetZoneImpl* dst_ancestor;
490   find_common_ancestors(src, dst, &common_ancestor, &src_ancestor, &dst_ancestor);
491   XBT_DEBUG("find_common_ancestors: common ancestor '%s' src ancestor '%s' dst ancestor '%s'",
492             common_ancestor->get_cname(), src_ancestor->get_cname(), dst_ancestor->get_cname());
493
494   netzones.insert(src->get_englobing_zone());
495   netzones.insert(dst->get_englobing_zone());
496   netzones.insert(common_ancestor);
497   /* Check whether a direct bypass is defined. If so, use it and bail out */
498   if (common_ancestor->get_bypass_route(src, dst, links, latency, netzones))
499     return;
500
501   /* If src and dst are in the same netzone, life is good */
502   if (src_ancestor == dst_ancestor) { /* SURF_ROUTING_BASE */
503     route.link_list_ = std::move(links);
504     common_ancestor->get_local_route(src, dst, &route, latency);
505     links = std::move(route.link_list_);
506     return;
507   }
508
509   /* Not in the same netzone, no bypass. We'll have to find our path between the netzones recursively */
510   common_ancestor->get_local_route(src_ancestor->netpoint_, dst_ancestor->netpoint_, &route, latency);
511   xbt_assert((route.gw_src_ != nullptr) && (route.gw_dst_ != nullptr), "Bad gateways for route from '%s' to '%s'.",
512              src->get_cname(), dst->get_cname());
513
514   /* If source gateway is not our source, we have to recursively find our way up to this point */
515   if (src != route.gw_src_)
516     get_global_route_with_netzones(src, route.gw_src_, links, latency, netzones);
517   links.insert(links.end(), begin(route.link_list_), end(route.link_list_));
518
519   /* If dest gateway is not our destination, we have to recursively find our way from this point */
520   if (route.gw_dst_ != dst)
521     get_global_route_with_netzones(route.gw_dst_, dst, links, latency, netzones);
522 }
523
524 void NetZoneImpl::seal()
525 {
526   /* already sealed netzone */
527   if (sealed_)
528     return;
529   do_seal(); // derived class' specific sealing procedure
530
531   /* seals sub-netzones and hosts */
532   for (auto* host : get_all_hosts()) {
533     host->seal();
534   }
535   for (auto* sub_net : get_children()) {
536     sub_net->seal();
537   }
538   sealed_ = true;
539   s4u::NetZone::on_seal(piface_);
540 }
541
542 void NetZoneImpl::set_parent(NetZoneImpl* parent)
543 {
544   xbt_assert(not sealed_, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname());
545   parent_ = parent;
546   netpoint_->set_englobing_zone(parent_);
547   if (parent) {
548     /* adding this class as child */
549     parent->add_child(this);
550     /* copying models from parent host, to be reviewed when we allow multi-models */
551     set_network_model(parent->get_network_model());
552     set_cpu_pm_model(parent->get_cpu_pm_model());
553     set_cpu_vm_model(parent->get_cpu_vm_model());
554     set_disk_model(parent->get_disk_model());
555     set_host_model(parent->get_host_model());
556   }
557 }
558
559 void NetZoneImpl::set_network_model(std::shared_ptr<resource::NetworkModel> netmodel)
560 {
561   xbt_assert(not sealed_, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname());
562   network_model_ = std::move(netmodel);
563 }
564
565 void NetZoneImpl::set_cpu_vm_model(std::shared_ptr<resource::CpuModel> cpu_model)
566 {
567   xbt_assert(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
568   cpu_model_vm_ = std::move(cpu_model);
569 }
570
571 void NetZoneImpl::set_cpu_pm_model(std::shared_ptr<resource::CpuModel> cpu_model)
572 {
573   xbt_assert(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname());
574   cpu_model_pm_ = std::move(cpu_model);
575 }
576
577 void NetZoneImpl::set_disk_model(std::shared_ptr<resource::DiskModel> disk_model)
578 {
579   xbt_assert(not sealed_, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname());
580   disk_model_ = std::move(disk_model);
581 }
582
583 void NetZoneImpl::set_host_model(std::shared_ptr<surf::HostModel> host_model)
584 {
585   xbt_assert(not sealed_, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname());
586   host_model_ = std::move(host_model);
587 }
588
589 const NetZoneImpl* NetZoneImpl::get_netzone_recursive(const NetPoint* netpoint) const
590 {
591   xbt_assert(netpoint && netpoint->is_netzone(), "Netpoint %s must be of the type NetZone",
592              netpoint ? netpoint->get_cname() : "nullptr");
593
594   if (netpoint == netpoint_)
595     return this;
596
597   for (const auto* children : children_) {
598     const NetZoneImpl* netzone = children->get_netzone_recursive(netpoint);
599     if (netzone)
600       return netzone;
601   }
602   return nullptr;
603 }
604
605 bool NetZoneImpl::is_component_recursive(const NetPoint* netpoint) const
606 {
607   /* check direct components */
608   if (std::any_of(begin(vertices_), end(vertices_), [netpoint](const auto* elem) { return elem == netpoint; }))
609     return true;
610
611   /* check childrens */
612   return std::any_of(begin(children_), end(children_),
613                      [netpoint](const auto* child) { return child->is_component_recursive(netpoint); });
614 }
615 } // namespace routing
616 } // namespace kernel
617 } // namespace simgrid