Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adjust add_route to accept route between netzones
[simgrid.git] / src / kernel / routing / NetZoneImpl.cpp
index 6caa246..c1ebb3e 100644 (file)
@@ -109,6 +109,8 @@ NetZoneImpl::~NetZoneImpl()
 void NetZoneImpl::add_child(NetZoneImpl* new_zone)
 {
   xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname());
+  /* set the father behavior */
+  hierarchy_ = RoutingMode::recursive;
   children_.push_back(new_zone);
 }
 
@@ -138,11 +140,14 @@ int NetZoneImpl::get_host_count() const
   return count;
 }
 
-s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
+s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
 {
-  auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth);
+  auto* res = (new surf::HostImpl(name))->get_iface();
+  res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
 
-  return l->get_iface();
+  cpu_model_pm_->create_cpu(res, speed_per_pstate);
+
+  return res;
 }
 
 s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<double>& bandwidths)
@@ -150,24 +155,20 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<d
   return network_model_->create_link(name, bandwidths)->get_iface();
 }
 
-s4u::Link* NetZoneImpl::create_wifi_link(const std::string& name, const std::vector<double>& bandwidths)
+s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
 {
-  return network_model_->create_wifi_link(name, bandwidths)->get_iface();
+  auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth);
+
+  return l->get_iface();
 }
 
-s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
+NetPoint* NetZoneImpl::create_router(const std::string& name)
 {
-  if (hierarchy_ == RoutingMode::unset)
-    hierarchy_ = RoutingMode::base;
-
-  auto* res = (new surf::HostImpl(name))->get_iface();
-  res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
+  xbt_assert(nullptr == 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());
 
-  cpu_model_pm_->create_cpu(res, speed_per_pstate);
-
-  return res;
+  return (new NetPoint(name, NetPoint::Type::Router))->set_englobing_zone(this);
 }
-
 int NetZoneImpl::add_component(NetPoint* elm)
 {
   vertices_.push_back(elm);
@@ -476,7 +477,7 @@ void NetZoneImpl::seal()
   for (auto* host : get_all_hosts()) {
     host->seal();
   }
-  for (auto* sub_net : *get_children()) {
+  for (auto* sub_net : get_children()) {
     sub_net->seal();
   }
   sealed_ = true;
@@ -487,6 +488,16 @@ void NetZoneImpl::set_parent(NetZoneImpl* parent)
   xbt_assert(not sealed_, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname());
   parent_ = parent;
   netpoint_->set_englobing_zone(parent_);
+  if (parent) {
+    /* adding this class as child */
+    parent->add_child(this);
+    /* copying models from parent host, to be reviewed when we allow multi-models */
+    set_network_model(parent->get_network_model());
+    set_cpu_pm_model(parent->get_cpu_pm_model());
+    set_cpu_vm_model(parent->get_cpu_vm_model());
+    set_disk_model(parent->get_disk_model());
+    set_host_model(parent->get_host_model());
+  }
 }
 
 void NetZoneImpl::set_network_model(std::shared_ptr<resource::NetworkModel> netmodel)