Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove more occurences of 'surf' with uppercases
[simgrid.git] / src / kernel / resource / NetworkModel.hpp
1 /* Copyright (c) 2004-2023. 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 "src/kernel/resource/NetworkModelFactors.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 Model_network_interface
22  * @brief 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 NetworkModelFactors {
26 public:
27   static config::Flag<double> cfg_tcp_gamma;
28   static config::Flag<bool> cfg_crosstraffic;
29   static config::Flag<double> cfg_weight_S_parameter;
30
31   using Model::Model;
32   NetworkModel(const NetworkModel&) = delete;
33   NetworkModel& operator=(const NetworkModel&) = delete;
34   ~NetworkModel() override;
35
36   /**
37    * @brief Create a [WiFi]Link
38    *
39    * @param name The name of the Link
40    * @param bandwidths The vector of bandwidths of the Link in bytes per second
41    */
42   virtual StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
43
44   virtual StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) = 0;
45
46   /**
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.
49    *
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
55    */
56   virtual Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool streamed) = 0;
57
58   double next_occurring_event_full(double now) override;
59
60   std::unique_ptr<StandardLinkImpl, StandardLinkImpl::Deleter> loopback_;
61 };
62
63 /**********
64  * Action *
65  **********/
66 /** @ingroup Model_network_interface
67  * @brief Network action interface class
68  * @details A NetworkAction represents a communication between two [hosts](@ref HostImpl)
69  */
70 class NetworkAction : public Action {
71   s4u::Host& src_;
72   s4u::Host& dst_;
73
74 public:
75   /** @brief Constructor
76    *
77    * @param model The NetworkModel associated to this NetworkAction
78    * @param cost The cost of this  NetworkAction in bytes
79    * @param failed Actions can be created in a failed state
80    */
81   NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed)
82       : Action(model, cost, failed), src_(src), dst_(dst)
83   {
84   }
85
86   /**
87    * @brief NetworkAction constructor
88    *
89    * @param model The NetworkModel associated to this NetworkAction
90    * @param cost The cost of this  NetworkAction in bytes
91    * @param failed Actions can be created in a failed state
92    * @param var The lmm variable associated to this Action if it is part of a LMM component
93    */
94   NetworkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, lmm::Variable* var)
95       : Action(model, cost, failed, var), src_(src), dst_(dst){};
96
97   void set_state(Action::State state) override;
98   virtual std::list<StandardLinkImpl*> get_links() const;
99
100   double latency_         = 0.; // Delay before the action starts
101   double lat_current_     = 0.; // Used to compute the communication RTT, and accordingly limit the communication rate
102   double sharing_penalty_ = {};
103
104   s4u::Host& get_src() const { return src_; }
105   s4u::Host& get_dst() const { return dst_; }
106 };
107
108 /* Insert link(s) at the end of vector `result' (at the beginning, and reversed, for insert_link_latency()), and add
109  * link->get_latency() to *latency when latency is not null
110  */
111 void add_link_latency(std::vector<StandardLinkImpl*>& result, StandardLinkImpl* link, double* latency);
112 void add_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
113                       double* latency);
114 void insert_link_latency(std::vector<StandardLinkImpl*>& result, const std::vector<StandardLinkImpl*>& links,
115                          double* latency);
116
117 } // namespace simgrid::kernel::resource
118
119 #endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODEL_HPP */