Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove declarations for never used signal slots.
[simgrid.git] / src / surf / network_interface.hpp
1 /* Copyright (c) 2004-2019. 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 SURF_NETWORK_INTERFACE_HPP_
7 #define SURF_NETWORK_INTERFACE_HPP_
8
9 #include "simgrid/kernel/resource/Model.hpp"
10 #include "simgrid/kernel/resource/Resource.hpp"
11 #include "simgrid/s4u/Link.hpp"
12 #include "src/kernel/lmm/maxmin.hpp"
13 #include "src/kernel/resource/profile/trace_mgr.hpp"
14 #include "src/surf/PropertyHolder.hpp"
15
16 #include <list>
17 #include <unordered_map>
18
19 /***********
20  * Classes *
21  ***********/
22
23 namespace simgrid {
24 namespace kernel {
25 namespace resource {
26 /*********
27  * Model *
28  *********/
29
30 /** @ingroup SURF_network_interface
31  * @brief SURF network model interface class
32  * @details A model is an object which handles the interactions between its Resources and its Actions
33  */
34 class NetworkModel : public Model {
35 public:
36   static simgrid::config::Flag<double> cfg_tcp_gamma;
37   static simgrid::config::Flag<bool> cfg_crosstraffic;
38
39   explicit NetworkModel(Model::UpdateAlgo algo) : Model(algo) {}
40   NetworkModel(const NetworkModel&) = delete;
41   NetworkModel& operator=(const NetworkModel&) = delete;
42   ~NetworkModel() override;
43
44   /**
45    * @brief Create a Link
46    *
47    * @param name The name of the Link
48    * @param bandwidth The initial bandwidth of the Link in bytes per second
49    * @param latency The initial latency of the Link in seconds
50    * @param policy The sharing policy of the Link
51    */
52   virtual LinkImpl* create_link(const std::string& name, double bandwidth, double latency,
53                                 s4u::Link::SharingPolicy policy) = 0;
54
55   /**
56    * @brief Create a communication between two hosts.
57    * @details It makes calls to the routing part, and execute the communication
58    *          between the two end points.
59    *
60    * @param src The source of the communication
61    * @param dst The destination of the communication
62    * @param size The size of the communication in bytes
63    * @param rate Allows to limit the transfer rate. Negative value means
64    * unlimited.
65    * @return The action representing the communication
66    */
67   virtual Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) = 0;
68
69   /**
70    * @brief Get the right multiplicative factor for the latency.
71    * @details Depending on the model, the effective latency when sending
72    * a message might be different from the theoretical latency of the link,
73    * in function of the message size. In order to account for this, this
74    * function gets this factor.
75    *
76    * @param size The size of the message.
77    * @return The latency factor.
78    */
79   virtual double get_latency_factor(double size);
80
81   /**
82    * @brief Get the right multiplicative factor for the bandwidth.
83    * @details Depending on the model, the effective bandwidth when sending
84    * a message might be different from the theoretical bandwidth of the link,
85    * in function of the message size. In order to account for this, this
86    * function gets this factor.
87    *
88    * @param size The size of the message.
89    * @return The bandwidth factor.
90    */
91   virtual double get_bandwidth_factor(double size);
92
93   /**
94    * @brief Get definitive bandwidth.
95    * @details It gives the minimum bandwidth between the one that would
96    * occur if no limitation was enforced, and the one arbitrary limited.
97    * @param rate The desired maximum bandwidth.
98    * @param bound The bandwidth with only the network taken into account.
99    * @param size The size of the message.
100    * @return The new bandwidth.
101    */
102   virtual double get_bandwidth_constraint(double rate, double bound, double size);
103   double next_occuring_event_full(double now) override;
104
105   LinkImpl* loopback_ = nullptr;
106 };
107
108 /************
109  * Resource *
110  ************/
111 /** @ingroup SURF_network_interface
112  * @brief SURF network link interface class
113  * @details A Link represents the link between two [hosts](@ref simgrid::surf::HostImpl)
114  */
115 class LinkImpl : public Resource, public simgrid::surf::PropertyHolder {
116 protected:
117   LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint);
118   LinkImpl(const LinkImpl&) = delete;
119   LinkImpl& operator=(const LinkImpl&) = delete;
120   ~LinkImpl() override;
121
122 public:
123   void destroy(); // Must be called instead of the destructor
124 private:
125   bool currently_destroying_ = false;
126
127 public:
128   /** @brief Public interface */
129   s4u::Link piface_;
130
131   /** @brief Get the bandwidth in bytes per second of current Link */
132   virtual double get_bandwidth();
133
134   /** @brief Update the bandwidth in bytes per second of current Link */
135   virtual void set_bandwidth(double value) = 0;
136
137   /** @brief Get the latency in seconds of current Link */
138   virtual double get_latency();
139
140   /** @brief Update the latency in seconds of current Link */
141   virtual void set_latency(double value) = 0;
142
143   /** @brief The sharing policy */
144   virtual s4u::Link::SharingPolicy get_sharing_policy();
145
146   /** @brief Check if the Link is used */
147   bool is_used() override;
148
149   void turn_on() override;
150   void turn_off() override;
151
152   void on_bandwidth_change();
153
154   virtual void
155   set_bandwidth_profile(kernel::profile::Profile* profile); /*< setup the profile file with bandwidth events
156                                                    (peak speed changes due to external load). Trace must
157                                                    contain percentages (value between 0 and 1). */
158   virtual void
159   set_latency_profile(kernel::profile::Profile* profile); /*< setup the trace file with latency events (peak
160                                                  latency changes due to external load).   Trace must contain
161                                                  absolute values */
162
163   Metric latency_                   = {1.0, 0, nullptr};
164   Metric bandwidth_                 = {1.0, 0, nullptr};
165
166   /* User data */
167   void* get_data() { return userdata_; }
168   void set_data(void* d) { userdata_ = d; }
169 private:
170   void* userdata_ = nullptr;
171 };
172
173 /**********
174  * Action *
175  **********/
176 /** @ingroup SURF_network_interface
177  * @brief SURF network action interface class
178  * @details A NetworkAction represents a communication between two [hosts](@ref simgrid::surf::HostImpl)
179  */
180 class NetworkAction : public Action {
181 public:
182   /** @brief Constructor
183    *
184    * @param model The NetworkModel associated to this NetworkAction
185    * @param cost The cost of this  NetworkAction in [TODO]
186    * @param failed [description]
187    */
188   NetworkAction(Model* model, double cost, bool failed) : Action(model, cost, failed) {}
189
190   /**
191    * @brief NetworkAction constructor
192    *
193    * @param model The NetworkModel associated to this NetworkAction
194    * @param cost The cost of this  NetworkAction in bytes
195    * @param failed Actions can be created in a failed state
196    * @param var The lmm variable associated to this Action if it is part of a LMM component
197    */
198   NetworkAction(Model* model, double cost, bool failed, lmm::Variable* var) : Action(model, cost, failed, var){};
199
200   void set_state(Action::State state) override;
201   virtual std::list<LinkImpl*> links();
202
203   double latency_    = {};
204   double lat_current_ = {};
205   double weight_     = {};
206   double rate_       = {};
207 };
208 }
209 }
210 } // namespace simgrid
211 /** @ingroup SURF_models
212  *  @brief The network model
213  */
214 XBT_PUBLIC_DATA simgrid::kernel::resource::NetworkModel* surf_network_model;
215
216 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
217
218