Adding API to set user callbacks for bandwidth and network factors.
Valid for CM02 models and its childrens (SMPI, IB, etc).
Not fully working yet.
include include/simgrid/kernel/future.hpp
include include/simgrid/kernel/resource/Action.hpp
include include/simgrid/kernel/resource/Model.hpp
+include include/simgrid/kernel/resource/NetworkModelIntf.hpp
include include/simgrid/kernel/resource/Resource.hpp
include include/simgrid/kernel/routing/ClusterZone.hpp
include include/simgrid/kernel/routing/DijkstraZone.hpp
class Resource;
class CpuModel;
class NetworkModel;
+class NetworkModelIntf;
class LinkImpl;
class NetworkAction;
class DiskImpl;
--- /dev/null
+/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */
+
+/* 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. */
+
+#ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP
+#define SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP
+
+#include <simgrid/s4u/Link.hpp>
+#include <simgrid/s4u/NetZone.hpp>
+
+#include <unordered_set>
+#include <vector>
+
+namespace simgrid {
+namespace kernel {
+namespace resource {
+
+/** @ingroup SURF_interface
+ * @brief Network Model interface class
+ * @details Defines the methods that a Network model must implement
+ */
+class XBT_PUBLIC NetworkModelIntf {
+public:
+ using NetworkFactorCb = double(double size, const std::vector<s4u::Link*>& links,
+ const std::unordered_set<s4u::NetZone*>& netzones);
+ virtual void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) = 0;
+ virtual void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) = 0;
+};
+
+} // namespace resource
+} // namespace kernel
+} // namespace simgrid
+
+#endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP */
\ No newline at end of file
s4u::Link* create_link(const std::string& name, const std::vector<std::string>& bandwidths);
s4u::Link* create_link(const std::string& name, const std::string& bandwidth);
+ kernel::resource::NetworkModelIntf* get_network_model() const;
+
/**
* @brief Make a router within that NetZone
*
#include "simgrid/s4u/NetZone.hpp"
#include "simgrid/simix.hpp"
#include "simgrid/zone.h"
+#include "src/surf/network_interface.hpp"
#include "xbt/parse_units.hpp"
namespace simgrid {
{
return pimpl_->get_netpoint();
}
+
+kernel::resource::NetworkModelIntf* NetZone::get_network_model() const
+{
+ kernel::resource::NetworkModelIntf* model = pimpl_->get_network_model().get();
+ return model;
+}
} // namespace s4u
} // namespace simgrid
loopback_->seal();
}
+void NetworkCm02Model::check_lat_factor_cb()
+{
+ if (not simgrid::config::is_default("network/latency-factor")) {
+ throw std::invalid_argument(
+ "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them.");
+ }
+}
+
+void NetworkCm02Model::check_bw_factor_cb()
+{
+ if (not simgrid::config::is_default("network/bandwidth-factor")) {
+ throw std::invalid_argument(
+ "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them.");
+ }
+}
+
+void NetworkCm02Model::set_lat_factor_cb(const std::function<NetworkFactorCb>& cb)
+{
+ if (not cb)
+ throw std::invalid_argument("NetworkModelIntf: Invalid callback");
+ check_lat_factor_cb();
+
+ lat_factor_cb_ = cb;
+}
+
+void NetworkCm02Model::set_bw_factor_cb(const std::function<NetworkFactorCb>& cb)
+{
+ if (not cb)
+ throw std::invalid_argument("NetworkModelIntf: Invalid callback");
+ check_bw_factor_cb();
+
+ bw_factor_cb_ = cb;
+}
+
LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector<double>& bandwidths)
{
xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth.");
#include <xbt/base.h>
#include "network_interface.hpp"
+#include "simgrid/kernel/resource/NetworkModelIntf.hpp"
#include "xbt/graph.h"
#include "xbt/string.hpp"
void update_actions_state_lazy(double now, double delta) override;
void update_actions_state_full(double now, double delta) override;
Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
+ void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override;
+ void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override;
+
+protected:
+ virtual void check_lat_factor_cb();
+ virtual void check_bw_factor_cb();
+ std::function<NetworkFactorCb> lat_factor_cb_;
+ std::function<NetworkFactorCb> bw_factor_cb_;
};
/************
using NetworkAction::NetworkAction;
void update_remains_lazy(double now) override;
};
-}
-}
+} // namespace resource
+} // namespace kernel
} // namespace simgrid
#endif /* SURF_NETWORK_CM02_HPP_ */
#define SURF_NETWORK_INTERFACE_HPP_
#include "simgrid/kernel/resource/Model.hpp"
+#include "simgrid/kernel/resource/NetworkModelIntf.hpp"
#include "simgrid/kernel/resource/Resource.hpp"
#include "simgrid/s4u/Link.hpp"
#include "src/kernel/lmm/maxmin.hpp"
* @brief SURF network model interface class
* @details A model is an object which handles the interactions between its Resources and its Actions
*/
-class NetworkModel : public Model {
+class NetworkModel : public Model, public NetworkModelIntf {
public:
static config::Flag<double> cfg_tcp_gamma;
static config::Flag<bool> cfg_crosstraffic;
double next_occurring_event_full(double now) override;
+ virtual void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
+ virtual void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
+
LinkImpl* loopback_ = nullptr;
};
* Profile must contain absolute values */
virtual LinkImpl* set_latency_profile(kernel::profile::Profile* profile);
- Metric latency_ = {0.0, 0, nullptr};
- Metric bandwidth_ = {1.0, 0, nullptr};
+ Metric latency_ = {0.0, 0, nullptr};
+ Metric bandwidth_ = {1.0, 0, nullptr};
};
/**********
} // namespace simgrid
#endif /* SURF_NETWORK_INTERFACE_HPP_ */
-
-
namespace kernel {
namespace resource {
+void NetworkSmpiModel::check_lat_factor_cb()
+{
+ if (not simgrid::config::is_default("smpi/lat-factor")) {
+ throw std::invalid_argument(
+ "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them.");
+ }
+}
+
+void NetworkSmpiModel::check_bw_factor_cb()
+{
+ if (not simgrid::config::is_default("smpi/bw-factor")) {
+ throw std::invalid_argument(
+ "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them.");
+ }
+}
+
double NetworkSmpiModel::get_bandwidth_factor(double size)
{
static std::vector<s_smpi_factor_t> smpi_bw_factor;
double get_latency_factor(double size) override;
double get_bandwidth_factor(double size) override;
double get_bandwidth_constraint(double rate, double bound, double size) override;
+
+protected:
+ virtual void check_lat_factor_cb() override;
+ virtual void check_bw_factor_cb() override;
};
} // namespace resource
} // namespace kernel
-}
+} // namespace simgrid
#endif
include/simgrid/s4u.hpp
include/simgrid/kernel/resource/Action.hpp
+ include/simgrid/kernel/resource/NetworkModelIntf.hpp
include/simgrid/kernel/resource/Model.hpp
include/simgrid/kernel/resource/Resource.hpp