From: Bruno Donassolo Date: Thu, 1 Apr 2021 17:00:10 +0000 (+0200) Subject: Friendly set_latency, accepts strings. X-Git-Tag: v3.28~485 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5aabb61f939c0a2f538f72a5e5e0b0da427cd9c7 Friendly set_latency, accepts strings. Human-friendly version for set_latency function. Accepts strings such as "1ms". --- diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index 9ee6439ba1..05808a12f9 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -58,7 +58,14 @@ public: /** Get/Set the latency of the current Link (in seconds) */ double get_latency() const; + /** + * @brief Set link's latency + * + * @param value New latency value (in s) + */ Link* set_latency(double value); + /** @brief Set latency (string version) */ + Link* set_latency(const std::string& value); /** @brief Describes how the link is shared between flows */ SharingPolicy get_sharing_policy() const; diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index e4a4494a91..7b195fb265 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -5,6 +5,7 @@ #include +#include "simgrid/Exception.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Link.hpp" #include "simgrid/sg_config.hpp" @@ -13,6 +14,7 @@ #include "src/surf/network_interface.hpp" #include "src/surf/network_wifi.hpp" #include "xbt/log.h" +#include "xbt/parse_units.hpp" namespace simgrid { @@ -67,6 +69,17 @@ Link* Link::set_latency(double value) return this; } +Link* Link::set_latency(const std::string& value) +{ + double d_value = 0.0; + try { + d_value = xbt_parse_get_time("", 0, value.c_str(), nullptr, ""); + } catch (const simgrid::ParseError&) { + xbt_die("Link: Impossible to latency, invalid value %s", value.c_str()); + } + return set_latency(d_value); +} + double Link::get_bandwidth() const { return this->pimpl_->get_bandwidth();