Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Also cleanup the network/weight-S parameter
[simgrid.git] / src / kernel / resource / NetworkModel.hpp
1 /* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP
8
9 #include "simgrid/kernel/resource/Model.hpp"
10 #include "simgrid/kernel/resource/NetworkModelIntf.hpp"
11 #include "src/kernel/resource/StandardLinkImpl.hpp"
12
13 #include <list>
14
15 namespace simgrid::kernel::resource {
16
17 /*********
18  * Model *
19  *********/
20
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
24  */
25 class NetworkModel : public Model, public NetworkModelIntf {
26 public:
27   static config::Flag<double> cfg_tcp_gamma;
28   static config::Flag<bool> cfg_crosstraffic;
29   static double cfg_latency_factor;
30   static double cfg_bandwidth_factor;
31   static config::Flag<double> cfg_weight_S_parameter;
32
33   using Model::Model;
34   NetworkModel(const NetworkModel&) = delete;
35   NetworkModel& operator=(const NetworkModel&) = delete;
36   ~NetworkModel() override;
37
38   /**
39    * @brief Create a [WiFi]Link
40    *
41    * @param name The name of the Link
42    * @param bandwidths The vector of bandwidths of the Link in bytes per second
43    */
44   virtual StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
45
46   virtual StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
47
48   /**
49    * @brief Create a communication between two hosts.
50    * @details It makes calls to the routing part, and execute the communication between the two end points.
51    *
52    * @param src The source of the communication
53    * @param dst The destination of the communication
54    * @param size The size of the communication in bytes
55    * @param rate Allows to limit the transfer rate. Negative value means unlimited.
56    * @return The action representing the communication
57    */
58   virtual Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) = 0;
59
60   /**
61    * @brief Get the right multiplicative factor for the latency.
62    * @details Depending on the model, the effective latency when sending a message might be different from the
63    * theoretical latency of the link, in function of the message size. In order to account for this, this function gets
64    * this factor.
65    *
66    * @param size The size of the message.
67    * @return The latency factor.
68    */
69   virtual double get_latency_factor(double /* size */) { return cfg_latency_factor; }
70
71   /**
72    * @brief Get the right multiplicative factor for the bandwidth.
73    * @details Depending on the model, the effective bandwidth when sending a message might be different from the
74    * theoretical bandwidth of the link, in function of the message size. In order to account for this, this function
75    * gets this factor.
76    *
77    * @param size The size of the message.
78    * @return The bandwidth factor.
79    */
80   virtual double get_bandwidth_factor(double /* size*/) { return cfg_bandwidth_factor; }
81
82   double next_occurring_event_full(double now) override;
83
84   void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
85   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
86
87   std::unique_ptr<StandardLinkImpl, StandardLinkImpl::Deleter> loopback_;
88 };
89
90 /**********
91  * Action *
92  **********/
93 /** @ingroup SURF_network_interface
94  * @brief SURF network action interface class
95  * @details A NetworkAction represents a communication between two [hosts](@ref HostImpl)
96  */
97 class NetworkAction : public Action {
98   s4u::Host& src_;
99   s4u::Host& dst_;
100
101 public:
102   /** @brief Constructor
103    *
104    * @param model The NetworkModel associated to this NetworkAction
105    * @param cost The cost of this  NetworkAction in [TODO]
106    * @param failed [description]
107    */
108   NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed)
109       : Action(model, cost, failed), src_(src), dst_(dst)
110   {
111   }
112
113   /**
114    * @brief NetworkAction constructor
115    *
116    * @param model The NetworkModel associated to this NetworkAction
117    * @param cost The cost of this  NetworkAction in bytes
118    * @param failed Actions can be created in a failed state
119    * @param var The lmm variable associated to this Action if it is part of a LMM component
120    */
121   NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, lmm::Variable* var)
122       : Action(model, cost, failed, var), src_(src), dst_(dst){};
123
124   void set_state(Action::State state) override;
125   virtual std::list<StandardLinkImpl*> get_links() const;
126
127   double latency_         = 0.; // Delay before the action starts
128   double lat_current_     = 0.; // Used to compute the communication RTT, and accordingly limit the communication rate
129   double sharing_penalty_ = {};
130
131   s4u::Host& get_src() const { return src_; }
132   s4u::Host& get_dst() const { return dst_; }
133 };
134
135 /* Insert link(s) at the end of vector `result' (at the beginning, and reversed, for insert_link_latency()), and add
136  * link->get_latency() to *latency when latency is not null
137  */
138 void add_link_latency(std::vector<StandardLinkImpl*>& result, StandardLinkImpl* link, double* latency);
139 void add_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
140                       double* latency);
141 void insert_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
142                          double* latency);
143
144 } // namespace simgrid::kernel::resource
145
146 #endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP */