From 36f318bf846ce5271b53a53deeb90ed0340b441f Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Tue, 13 Apr 2021 11:39:20 +0200 Subject: [PATCH] improve router creation --- include/simgrid/kernel/routing/NetPoint.hpp | 2 +- .../simgrid/kernel/routing/NetZoneImpl.hpp | 2 ++ src/kernel/routing/NetPoint.cpp | 3 ++- src/kernel/routing/NetZoneImpl.cpp | 25 ++++++++++++------- src/surf/sg_platf.cpp | 12 ++------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/simgrid/kernel/routing/NetPoint.hpp b/include/simgrid/kernel/routing/NetPoint.hpp index 33d1be544d..7b4126c146 100644 --- a/include/simgrid/kernel/routing/NetPoint.hpp +++ b/include/simgrid/kernel/routing/NetPoint.hpp @@ -52,7 +52,7 @@ private: unsigned int id_ = -1; std::string name_; NetPoint::Type component_type_; - NetZoneImpl* englobing_zone_; + NetZoneImpl* englobing_zone_ = nullptr; }; } // namespace routing } // namespace kernel diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index f829d7fe03..bbd3899e88 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -134,6 +134,8 @@ public: s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth); /** @brief Make a link within that NetZone */ virtual s4u::Link* create_link(const std::string& name, const std::vector& bandwidths); + /** @brief Make a router within that NetZone */ + NetPoint* create_router(const std::string& name); /** @brief Creates a new route in this NetZone */ virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, std::vector& link_list, bool symmetrical); diff --git a/src/kernel/routing/NetPoint.cpp b/src/kernel/routing/NetPoint.cpp index fad35e5e8b..5112bc65bd 100644 --- a/src/kernel/routing/NetPoint.cpp +++ b/src/kernel/routing/NetPoint.cpp @@ -36,7 +36,8 @@ NetPoint* NetPoint::set_englobing_zone(NetZoneImpl* netzone_p) NetPoint* NetPoint::set_coordinates(const std::string& coords) { - new vivaldi::Coords(this, coords); + if (not coords.empty()) + new vivaldi::Coords(this, coords); return this; } } // namespace routing diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index a47f4b43f5..c1ebb3e8e1 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -140,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& 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& bandwidths) @@ -152,16 +155,20 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vectorcreate_link(name, bandwidths)->get_iface(); } -s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector& speed_per_pstate) +s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) { - auto* res = (new surf::HostImpl(name))->get_iface(); - res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this)); - - cpu_model_pm_->create_cpu(res, speed_per_pstate); + auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth); - return res; + return l->get_iface(); } +NetPoint* NetZoneImpl::create_router(const std::string& name) +{ + 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()); + + return (new NetPoint(name, NetPoint::Type::Router))->set_englobing_zone(this); +} int NetZoneImpl::add_component(NetPoint* elm) { vertices_.push_back(elm); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 90bd01c367..b50f628d52 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -70,7 +70,6 @@ void sg_platf_new_host_begin(const simgrid::kernel::routing::HostCreationArgs* a ->set_core_count(args->core_amount) ->set_state_profile(args->state_trace) ->set_speed_profile(args->speed_trace); - // host->get_impl()->set_disks(args->disks); } void sg_platf_new_host_set_properties(const std::unordered_map& props) @@ -96,16 +95,9 @@ void sg_platf_new_host_seal(int pstate) /** @brief Add a "router" to the network element list */ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, const std::string& coords) { - 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); - netpoint->set_englobing_zone(current_routing); + auto* netpoint = current_routing->create_router(name)->set_coordinates(coords); XBT_DEBUG("Router '%s' has the id %u", netpoint->get_cname(), netpoint->id()); - if (not coords.empty()) - netpoint->set_coordinates(coords); - return netpoint; } @@ -243,7 +235,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster XBT_DEBUG("", cluster->router_id.c_str()); if (cluster->router_id.empty()) cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix; - current_zone->set_router(sg_platf_new_router(cluster->router_id, "")); + current_zone->set_router(current_zone->create_router(cluster->router_id)); // Make the backbone if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) { -- 2.30.2