From 9cccb540315b9453bfc60e07d953ae81b44bd049 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 23 Oct 2022 21:57:59 +0200 Subject: [PATCH] Allow to set the network factors callback from userland w/o relying on NetworkModelIntf - this file is soon private, as the other kernel headers - this was missing a simcall anyway --- .../cpp/network-factors/s4u-network-factors.cpp | 13 +++++-------- include/simgrid/s4u/NetZone.hpp | 8 ++++++++ src/s4u/s4u_Netzone.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/examples/cpp/network-factors/s4u-network-factors.cpp b/examples/cpp/network-factors/s4u-network-factors.cpp index 4eca7b86a2..abeeab7e64 100644 --- a/examples/cpp/network-factors/s4u-network-factors.cpp +++ b/examples/cpp/network-factors/s4u-network-factors.cpp @@ -3,20 +3,18 @@ /* 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. */ -/* This example shows how to build set customized communication factors +/* This example shows how to build set custom communication factors * - * It uses the interface provided by NetworkModelIntf to register 2 callbacks that - * are called everytime a communication occurs. + * It uses the netzone interface to register 2 callbacks that are called for every communications. * * These factors are used to change the communication time depending on the message size * and destination. * * This example uses factors obtained by some experiments on dahu cluster in Grid'5000. - * You must change the values according to the calibration of your enviroment. + * You should change the values according to the calibration of your enviroment. */ #include -#include #include namespace sg4 = simgrid::s4u; @@ -232,9 +230,8 @@ int main(int argc, char* argv[]) /* create platform */ load_platform(); /* setting network factors callbacks */ - simgrid::kernel::resource::NetworkModelIntf* model = e.get_netzone_root()->get_network_model(); - model->set_lat_factor_cb(latency_factor_cb); - model->set_bw_factor_cb(bandwidth_factor_cb); + e.get_netzone_root()->set_latency_factor_cb(latency_factor_cb); + e.get_netzone_root()->set_bandwidth_factor_cb(bandwidth_factor_cb); sg4::Host* host = e.host_by_name("dahu-1.grid5000.fr"); sg4::Host* host_remote = e.host_by_name("dahu-10.grid5000.fr"); diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index e974320790..361cf4f707 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -153,6 +154,13 @@ public: /** @brief Seal this netzone configuration */ NetZone* seal(); + + void set_latency_factor_cb(std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb); + void set_bandwidth_factor_cb(std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb); }; // External constructors so that the types (and the types of their content) remain hidden diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index bd00dc9e81..ec5b427cb2 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -113,6 +113,20 @@ NetZone* NetZone::seal() kernel::actor::simcall_answered([this] { pimpl_->seal(); }); return this; } +void NetZone::set_latency_factor_cb( + std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb) +{ + kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_lat_factor_cb(cb); }); +} +void NetZone::set_bandwidth_factor_cb( + std::function& /*links*/, + const std::unordered_set& /*netzones*/)> const& cb) +{ + kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_bw_factor_cb(cb); }); +} s4u::Host* NetZone::create_host(const std::string& name, double speed) { -- 2.20.1