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"
23 /** @ingroup SURF_network_interface
24 * @brief SURF network model interface class
25 * @details A model is an object which handles the interactions between its Resources and its Actions
27 class NetworkModel : public Model, public NetworkModelIntf {
29 static config::Flag<double> cfg_tcp_gamma;
30 static config::Flag<bool> cfg_crosstraffic;
33 NetworkModel(const NetworkModel&) = delete;
34 NetworkModel& operator=(const NetworkModel&) = delete;
35 ~NetworkModel() override;
38 * @brief Create a [WiFi]Link
40 * @param name The name of the Link
41 * @param bandwidths The vector of bandwidths of the Link in bytes per second
43 virtual StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
45 virtual StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
48 * @brief Create a communication between two hosts.
49 * @details It makes calls to the routing part, and execute the communication between the two end points.
51 * @param src The source of the communication
52 * @param dst The destination of the communication
53 * @param size The size of the communication in bytes
54 * @param rate Allows to limit the transfer rate. Negative value means unlimited.
55 * @return The action representing the communication
57 virtual Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) = 0;
60 * @brief Get the right multiplicative factor for the latency.
61 * @details Depending on the model, the effective latency when sending a message might be different from the
62 * theoretical latency of the link, in function of the message size. In order to account for this, this function gets
65 * @param size The size of the message.
66 * @return The latency factor.
68 virtual double get_latency_factor(double /* size */) { return sg_latency_factor; }
71 * @brief Get the right multiplicative factor for the bandwidth.
72 * @details Depending on the model, the effective bandwidth when sending a message might be different from the
73 * theoretical bandwidth of the link, in function of the message size. In order to account for this, this function
76 * @param size The size of the message.
77 * @return The bandwidth factor.
79 virtual double get_bandwidth_factor(double /* size*/) { return sg_bandwidth_factor; }
81 double next_occurring_event_full(double now) override;
83 void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
84 void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
86 std::unique_ptr<StandardLinkImpl, StandardLinkImpl::Deleter> loopback_;
92 /** @ingroup SURF_network_interface
93 * @brief SURF network action interface class
94 * @details A NetworkAction represents a communication between two [hosts](@ref HostImpl)
96 class NetworkAction : public Action {
101 /** @brief Constructor
103 * @param model The NetworkModel associated to this NetworkAction
104 * @param cost The cost of this NetworkAction in [TODO]
105 * @param failed [description]
107 NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed)
108 : Action(model, cost, failed), src_(src), dst_(dst)
113 * @brief NetworkAction constructor
115 * @param model The NetworkModel associated to this NetworkAction
116 * @param cost The cost of this NetworkAction in bytes
117 * @param failed Actions can be created in a failed state
118 * @param var The lmm variable associated to this Action if it is part of a LMM component
120 NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, lmm::Variable* var)
121 : Action(model, cost, failed, var), src_(src), dst_(dst){};
123 void set_state(Action::State state) override;
124 virtual std::list<StandardLinkImpl*> get_links() const;
126 double latency_ = 0.; // Delay before the action starts
127 double lat_current_ = 0.; // Used to compute the communication RTT, and accordingly limit the communication rate
128 double sharing_penalty_ = {};
130 s4u::Host& get_src() const { return src_; }
131 s4u::Host& get_dst() const { return dst_; }
134 /* Insert link(s) at the end of vector `result' (at the beginning, and reversed, for insert_link_latency()), and add
135 * link->get_latency() to *latency when latency is not null
137 void add_link_latency(std::vector<StandardLinkImpl*>& result, StandardLinkImpl* link, double* latency);
138 void add_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
140 void insert_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
143 } // namespace resource
144 } // namespace kernel
145 } // namespace simgrid
147 #endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP */