From 11a84d2a50a791eb36fc12576335cf6158109c80 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 14 Feb 2017 01:45:05 +0100 Subject: [PATCH] complete a bit the C wrapper of s4u::Host --- include/simgrid/host.h | 6 ++++-- src/simgrid/host.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index e1d6c26daf..4fd737bff0 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -51,8 +51,10 @@ XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host); XBT_PUBLIC(int) sg_host_get_pstate(sg_host_t host); XBT_PUBLIC(void) sg_host_set_pstate(sg_host_t host,int pstate); XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host); -XBT_PUBLIC(const char *) sg_host_get_property_value(sg_host_t host, - const char *name); +XBT_PUBLIC(const char*) sg_host_get_property_value(sg_host_t host, const char* name); +XBT_PUBLIC(void) sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links); +XBT_PUBLIC(double) sg_host_route_latency(sg_host_t from, sg_host_t to); +XBT_PUBLIC(double) sg_host_route_bandwidth(sg_host_t from, sg_host_t to); XBT_PUBLIC(void) sg_host_dump(sg_host_t ws); SG_END_DECL() diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 9808aa6f69..30988adcff 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -189,6 +189,48 @@ const char *sg_host_get_property_value(sg_host_t host, const char *name) { return (const char*) xbt_dict_get_or_null(sg_host_get_properties(host), name); } +/** + * \brief Find a route between two hosts + * + * \param from where from + * \param to where to + * \param links [OUT] where to store the list of links (must exist, cannot be nullptr). + */ +void sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links) +{ + std::vector vlinks; + from->routeTo(to, &vlinks, nullptr); + for (auto link : vlinks) + xbt_dynar_push(links, &link); +} +/** + * \brief Find the latency of the route between two hosts + * + * \param from where from + * \param to where to + */ +double sg_host_route_latency(sg_host_t from, sg_host_t to) +{ + std::vector vlinks; + double res = 0; + from->routeTo(to, &vlinks, &res); + return res; +} +/** + * \brief Find the bandwitdh of the route between two hosts + * + * \param from where from + * \param to where to + */ +double sg_host_route_bandwidth(sg_host_t from, sg_host_t to) +{ + std::vector vlinks; + from->routeTo(to, &vlinks, nullptr); + double res = 0; + for (auto link : vlinks) + res += link->bandwidth(); + return res; +} /** @brief Displays debugging information about a host */ void sg_host_dump(sg_host_t host) -- 2.20.1