Logo AND Algorithmique Numérique Distribuée

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