From c0d470d50b2389ca52463e8bf33d39602aeda645 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 1 Apr 2021 18:15:37 +0200 Subject: [PATCH] Add create_link in s4u::NetZone With SharingPolicy as parameter since it's mandatory to decide if we must create a WiFi link or not. Setting default as SHARED according to DTD --- include/simgrid/s4u/NetZone.hpp | 19 +++++++++++++++++-- src/s4u/s4u_Host.cpp | 3 ++- src/s4u/s4u_Netzone.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index db9b525a4c..222afc1452 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -7,6 +7,7 @@ #define SIMGRID_S4U_NETZONE_HPP #include +#include #include #include @@ -78,14 +79,28 @@ public: static xbt::signal on_seal; /** - * @brief Create a Host + * @brief Create a host * - * @param name Host name + * @param name Host name * @param speed_per_state Vector of CPU's speeds */ s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate); /** @brief Create a Host (string version) */ s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate); + + /** + * @brief Create a link + * + * @param name Link name + * @param bandwidths Link's speed (vector for wifi links) + * @param policy Link sharing policy + */ + s4u::Link* create_link(const std::string& name, const std::vector& bandwidths, + Link::SharingPolicy policy = Link::SharingPolicy::SHARED); + + /** @brief Create a link (string version) */ + s4u::Link* create_link(const std::string& name, const std::vector& bandwidths, + Link::SharingPolicy policy = Link::SharingPolicy::SHARED); }; // External constructors so that the types (and the types of their content) remain hidden diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 687851657a..81aa55530b 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -274,7 +274,8 @@ Host* Host::set_pstate_speed(const std::vector& speed_per_state) std::vector Host::convert_pstate_speed_vector(const std::vector& speed_per_state) { - std::vector speed_list(speed_per_state.size()); + std::vector speed_list; + speed_list.reserve(speed_per_state.size()); for (const auto& speed_str : speed_per_state) { try { double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, ""); diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 9660a8977b..57c83f3cf8 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -3,12 +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/Exception.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/NetZone.hpp" #include "simgrid/simix.hpp" #include "simgrid/zone.h" +#include "xbt/parse_units.hpp" namespace simgrid { namespace s4u { @@ -128,6 +130,30 @@ s4u::Host* NetZone::create_host(const std::string& name, const std::vector& bandwidths, + s4u::Link::SharingPolicy policy) +{ + return kernel::actor::simcall( + [this, &name, &bandwidths, &policy] { return pimpl_->create_link(name, bandwidths, policy); }); +} + +s4u::Link* NetZone::create_link(const std::string& name, const std::vector& bandwidths, + s4u::Link::SharingPolicy policy) +{ + std::vector bw; + bw.reserve(bandwidths.size()); + for (const auto& speed_str : bandwidths) { + try { + double speed = xbt_parse_get_bandwidth("", 0, speed_str.c_str(), nullptr, ""); + bw.push_back(speed); + } catch (const simgrid::ParseError&) { + xbt_die("Link: Impossible to create_link, invalid bandwidth %s", speed_str.c_str()); + } + } + return create_link(name, bw, policy); +} + } // namespace s4u } // namespace simgrid -- 2.20.1