1 /* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP
9 #include "simgrid/kernel/resource/Model.hpp"
10 #include "simgrid/kernel/resource/NetworkModelIntf.hpp"
11 #include "src/kernel/resource/StandardLinkImpl.hpp"
15 namespace simgrid::kernel::resource {
21 /** @ingroup SURF_network_interface
22 * @brief SURF network model interface class
23 * @details A model is an object which handles the interactions between its Resources and its Actions
25 class NetworkModel : public Model, public NetworkModelIntf {
27 static config::Flag<double> cfg_tcp_gamma;
28 static config::Flag<bool> cfg_crosstraffic;
29 static config::Flag<double> cfg_weight_S_parameter;
32 NetworkModel(const NetworkModel&) = delete;
33 NetworkModel& operator=(const NetworkModel&) = delete;
34 ~NetworkModel() override;
37 * @brief Create a [WiFi]Link
39 * @param name The name of the Link
40 * @param bandwidths The vector of bandwidths of the Link in bytes per second
42 virtual StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
44 virtual StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
47 * @brief Create a communication between two hosts.
48 * @details It makes calls to the routing part, and execute the communication between the two end points.
50 * @param src The source of the communication
51 * @param dst The destination of the communication
52 * @param size The size of the communication in bytes
53 * @param rate Allows to limit the transfer rate. Negative value means unlimited.
54 * @return The action representing the communication
56 virtual Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) = 0;
59 * @brief Get the right multiplicative factor for the latency.
60 * @details Depending on the model, the effective latency when sending a message might be different from the
61 * theoretical latency of the link, in function of the message size. In order to account for this, this function gets
64 * @param size The size of the message.
65 * @return The latency factor.
67 virtual double get_latency_factor(double size = 0);
70 * @brief Get the right multiplicative factor for the bandwidth.
71 * @details Depending on the model, the effective bandwidth when sending a message might be different from the
72 * theoretical bandwidth of the link, in function of the message size. In order to account for this, this function
75 * @param size The size of the message.
76 * @return The bandwidth factor.
78 virtual double get_bandwidth_factor(double size = 0);
80 double next_occurring_event_full(double now) override;
82 void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
83 void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
85 std::unique_ptr<StandardLinkImpl, StandardLinkImpl::Deleter> loopback_;
91 /** @ingroup SURF_network_interface
92 * @brief SURF network action interface class
93 * @details A NetworkAction represents a communication between two [hosts](@ref HostImpl)
95 class NetworkAction : public Action {
100 /** @brief Constructor
102 * @param model The NetworkModel associated to this NetworkAction
103 * @param cost The cost of this NetworkAction in [TODO]
104 * @param failed [description]
106 NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed)
107 : Action(model, cost, failed), src_(src), dst_(dst)
112 * @brief NetworkAction constructor
114 * @param model The NetworkModel associated to this NetworkAction
115 * @param cost The cost of this NetworkAction in bytes
116 * @param failed Actions can be created in a failed state
117 * @param var The lmm variable associated to this Action if it is part of a LMM component
119 NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, lmm::Variable* var)
120 : Action(model, cost, failed, var), src_(src), dst_(dst){};
122 void set_state(Action::State state) override;
123 virtual std::list<StandardLinkImpl*> get_links() const;
125 double latency_ = 0.; // Delay before the action starts
126 double lat_current_ = 0.; // Used to compute the communication RTT, and accordingly limit the communication rate
127 double sharing_penalty_ = {};
129 s4u::Host& get_src() const { return src_; }
130 s4u::Host& get_dst() const { return dst_; }
133 /* Insert link(s) at the end of vector `result' (at the beginning, and reversed, for insert_link_latency()), and add
134 * link->get_latency() to *latency when latency is not null
136 void add_link_latency(std::vector<StandardLinkImpl*>& result, StandardLinkImpl* link, double* latency);
137 void add_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
139 void insert_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
142 } // namespace simgrid::kernel::resource
144 #endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP */