From: Frederic Suter Date: Tue, 22 Oct 2019 07:26:54 +0000 (+0200) Subject: make host's pimpl_netpoint private X-Git-Tag: v3.25~494 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1c200a6a6d23fe2f911b2ae427706806daef7b47 make host's pimpl_netpoint private * getter is public * setter is protected --- diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index f9f856afc9..c36c54a71c 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -38,6 +38,7 @@ namespace s4u { class XBT_PUBLIC Host : public xbt::Extendable { friend vm::VMModel; // Use the pimpl_cpu to compute the VM sharing friend vm::VirtualMachineImpl; // creates the the pimpl_cpu + friend kernel::routing::NetZoneImpl; public: explicit Host(const std::string& name); @@ -45,6 +46,7 @@ public: /** Host destruction logic */ protected: virtual ~Host(); + void set_netpoint(kernel::routing::NetPoint* netpoint) { pimpl_netpoint_ = netpoint; } private: bool currently_destroying_ = false; @@ -77,6 +79,8 @@ public: /** Retrieves the name of that host as a C string */ const char* get_cname() const { return name_.c_str(); } + kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; } + int get_actor_count(); std::vector get_all_actors(); @@ -145,6 +149,7 @@ public: private: xbt::string name_{"noname"}; std::unordered_map* mounts_ = nullptr; // caching + kernel::routing::NetPoint* pimpl_netpoint_ = nullptr; public: #ifndef DOXYGEN @@ -152,8 +157,6 @@ public: kernel::resource::Cpu* pimpl_cpu = nullptr; // TODO, this could be a unique_ptr surf::HostImpl* pimpl_ = nullptr; - /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */ - kernel::routing::NetPoint* pimpl_netpoint = nullptr; #endif }; } // namespace s4u diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 95bf51d7ee..69bd67247a 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -69,7 +69,7 @@ HostContainer::HostContainer(simgrid::s4u::Host const& host, NetZoneContainer* f { xbt_assert(father, "Only the Root container has no father"); - netpoint_ = host.pimpl_netpoint; + netpoint_ = host.get_netpoint(); xbt_assert(netpoint_, "Element '%s' not found", host.get_cname()); trivaNodeTypes.insert(type_->get_name()); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 670720c3cf..ff8fe36d84 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -100,7 +100,7 @@ simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector if (hierarchy_ == RoutingMode::unset) hierarchy_ = RoutingMode::base; - res->pimpl_netpoint = new NetPoint(name, NetPoint::Type::Host, this); + res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this)); surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount); diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 9a4c1d0ae8..128b757062 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -283,7 +283,7 @@ void VirtualMachineImpl::set_physical_host(s4u::Host* destination) std::string pm_name_dst = destination->get_name(); /* update net_elm with that of the destination physical host */ - piface_->pimpl_netpoint = destination->pimpl_netpoint; + piface_->pimpl_netpoint_ = destination->get_netpoint(); physical_host_ = destination; diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 4f6345537f..e812231543 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -35,7 +35,7 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host XBT_DEBUG("Create VM %s", get_cname()); /* Currently, a VM uses the network resource of its physical host */ - pimpl_netpoint = physical_host->pimpl_netpoint; + set_netpoint(physical_host->get_netpoint()); // Create a VCPU for this VM std::vector speeds; @@ -54,7 +54,7 @@ VirtualMachine::~VirtualMachine() XBT_DEBUG("destroy %s", get_cname()); /* Don't free these things twice: they are the ones of my physical host */ - pimpl_netpoint = nullptr; + set_netpoint(nullptr); } void VirtualMachine::start() diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index a891bc6d35..459c2900c1 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -42,8 +42,8 @@ Host::~Host() xbt_assert(currently_destroying_, "Please call h->destroy() instead of manually deleting it."); delete pimpl_; - if (pimpl_netpoint != nullptr) // not removed yet by a children class - Engine::get_instance()->netpoint_unregister(pimpl_netpoint); + if (pimpl_netpoint_ != nullptr) // not removed yet by a children class + Engine::get_instance()->netpoint_unregister(pimpl_netpoint_); delete pimpl_cpu; delete mounts_; } @@ -160,7 +160,7 @@ void Host::route_to(Host* dest, std::vector& links, double* latency) /** @brief Just like Host::routeTo, but filling an array of link implementations */ void Host::route_to(Host* dest, std::vector& links, double* latency) { - kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint, dest->pimpl_netpoint, links, latency); + kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint_, dest->get_netpoint(), links, latency); if (XBT_LOG_ISENABLED(surf_route, xbt_log_priority_debug)) { XBT_CDEBUG(surf_route, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(), (latency == nullptr ? -1 : *latency)); @@ -172,7 +172,7 @@ void Host::route_to(Host* dest, std::vector& links, /** @brief Returns the networking zone englobing that host */ NetZone* Host::get_englobing_zone() { - return pimpl_netpoint->get_englobing_zone()->get_iface(); + return pimpl_netpoint_->get_englobing_zone()->get_iface(); } void Host::send_to(Host* dest, double byte_amount) @@ -386,7 +386,7 @@ xbt_dynar_t sg_hosts_as_dynar() std::vector list = simgrid::s4u::Engine::get_instance()->get_all_hosts(); auto last = std::remove_if(begin(list), end(list), [](const simgrid::s4u::Host* host) { - return not host || not host->pimpl_netpoint || not host->pimpl_netpoint->is_host(); + return not host || not host->get_netpoint() || not host->get_netpoint()->is_host(); }); std::sort(begin(list), last, [](const simgrid::s4u::Host* a, const simgrid::s4u::Host* b) { return a->get_name() < b->get_name(); }); diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 1e14879a5e..df15a7a897 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -75,7 +75,7 @@ static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs con // Create private link std::string host_id = cluster.prefix + std::to_string(i) + cluster.suffix; - auto* host_src = simgrid::s4u::Host::by_name(host_id)->pimpl_netpoint->extension(); + auto* host_src = simgrid::s4u::Host::by_name(host_id)->get_netpoint()->extension(); xbt_assert(host_src, "Cannot find a ns-3 host of name %s", host_id.c_str()); // Any ns-3 route is symmetrical @@ -323,8 +323,8 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s static int port_number = 1025; // Port number is limited from 1025 to 65 000 - unsigned int node1 = src->pimpl_netpoint->extension()->node_num; - unsigned int node2 = dst->pimpl_netpoint->extension()->node_num; + unsigned int node1 = src->get_netpoint()->extension()->node_num; + unsigned int node2 = dst->get_netpoint()->extension()->node_num; ns3::Ptr src_node = src->pimpl_netpoint->extension()->ns3_node_; ns3::Ptr dst_node = dst->pimpl_netpoint->extension()->ns3_node_; diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 2359340d52..9f7b6350fd 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -93,7 +93,7 @@ void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* args) if (args->pstate != 0) host->set_pstate(args->pstate); if (not args->coord.empty()) - new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netpoint, args->coord); + new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord); } /** @brief Add a "router" to the network element list */ @@ -503,7 +503,7 @@ void sg_platf_new_peer(simgrid::kernel::routing::PeerCreationArgs* peer) speed_per_pstate.push_back(peer->speed); simgrid::s4u::Host* host = as->create_host(peer->id.c_str(), speed_per_pstate, 1, nullptr); - as->set_peer_link(host->pimpl_netpoint, peer->bw_in, peer->bw_out, peer->coord); + as->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out, peer->coord); /* Change from the defaults */ if (peer->state_trace) @@ -667,7 +667,7 @@ void sg_platf_new_Zone_seal() /** @brief Add a link connecting a host to the rest of its AS (which must be cluster or vivaldi) */ void sg_platf_new_hostlink(simgrid::kernel::routing::HostLinkCreationArgs* hostlink) { - simgrid::kernel::routing::NetPoint* netpoint = simgrid::s4u::Host::by_name(hostlink->id)->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* netpoint = simgrid::s4u::Host::by_name(hostlink->id)->get_netpoint(); xbt_assert(netpoint, "Host '%s' not found!", hostlink->id.c_str()); xbt_assert(dynamic_cast(current_routing), "Only hosts from Cluster and Vivaldi ASes can get a host_link."); diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index ce9155bcd2..da1a39aadf 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -122,11 +122,11 @@ static void dump_routes() for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host simgrid::s4u::Host* host1 = hosts[it_src]; - simgrid::kernel::routing::NetPoint* src = host1->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* src = host1->get_netpoint(); for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host simgrid::s4u::Host* host2 = hosts[it_dst]; std::vector route; - simgrid::kernel::routing::NetPoint* dst = host2->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* dst = host2->get_netpoint(); simgrid::kernel::routing::NetZoneImpl::get_global_route(src, dst, route, nullptr); if (not route.empty()) { std::printf(" \n ", host1->get_cname(), host2->get_cname()); @@ -164,7 +164,7 @@ static void dump_routes() simgrid::s4u::Host* host2 = hosts[it_dst]; std::printf(" \n ", value1->get_cname(), host2->get_cname()); std::vector route; - simgrid::kernel::routing::NetPoint* netcardDst = host2->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* netcardDst = host2->get_netpoint(); simgrid::kernel::routing::NetZoneImpl::get_global_route(value1, netcardDst, route, nullptr); for (auto const& link : route) std::printf("", link->get_cname()); diff --git a/teshsuite/simdag/is-router/is-router.cpp b/teshsuite/simdag/is-router/is-router.cpp index 35441dfc55..e48c032a47 100644 --- a/teshsuite/simdag/is-router/is-router.cpp +++ b/teshsuite/simdag/is-router/is-router.cpp @@ -29,7 +29,7 @@ int main(int argc, char **argv) int it; sg_host_t host; xbt_dynar_foreach(hosts, it, host) { - simgrid::kernel::routing::NetPoint* nc = host->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* nc = host->get_netpoint(); const char *type = "buggy"; if (nc->is_router()) type = "router";