1 /* Copyright (c) 2004-2017. 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 SURF_NETWORK_INTERFACE_HPP_
7 #define SURF_NETWORK_INTERFACE_HPP_
9 #include "simgrid/s4u/Link.hpp"
10 #include "src/surf/PropertyHolder.hpp"
11 #include "src/surf/surf_interface.hpp"
13 #include <unordered_map>
25 /** @ingroup SURF_network_interface
26 * @brief SURF network model interface class
27 * @details A model is an object which handles the interactions between its Resources and its Actions
29 class NetworkModel : public Model {
31 /** @brief Constructor */
32 NetworkModel() : Model() { }
34 /** @brief Destructor */
35 ~NetworkModel() override;
38 * @brief Create a Link
40 * @param name The name of the Link
41 * @param bandwidth The initial bandwidth of the Link in bytes per second
42 * @param latency The initial latency of the Link in seconds
43 * @param policy The sharing policy of the Link
45 virtual LinkImpl* createLink(const char* name, double bandwidth, double latency,
46 e_surf_link_sharing_policy_t policy) = 0;
49 * @brief Create a communication between two hosts.
50 * @details It makes calls to the routing part, and execute the communication
51 * between the two end points.
53 * @param src The source of the communication
54 * @param dst The destination of the communication
55 * @param size The size of the communication in bytes
56 * @param rate Allows to limit the transfer rate. Negative value means
58 * @return The action representing the communication
60 virtual Action* communicate(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double size, double rate) = 0;
62 /** @brief Function pointer to the function to use to solve the lmm_system_t
64 * @param system The lmm_system_t to solve
66 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
69 * @brief Get the right multiplicative factor for the latency.
70 * @details Depending on the model, the effective latency when sending
71 * a message might be different from the theoretical latency of the link,
72 * in function of the message size. In order to account for this, this
73 * function gets this factor.
75 * @param size The size of the message.
76 * @return The latency factor.
78 virtual double latencyFactor(double size);
81 * @brief Get the right multiplicative factor for the bandwidth.
82 * @details Depending on the model, the effective bandwidth when sending
83 * a message might be different from the theoretical bandwidth of the link,
84 * in function of the message size. In order to account for this, this
85 * function gets this factor.
87 * @param size The size of the message.
88 * @return The bandwidth factor.
90 virtual double bandwidthFactor(double size);
93 * @brief Get definitive bandwidth.
94 * @details It gives the minimum bandwidth between the one that would
95 * occur if no limitation was enforced, and the one arbitrary limited.
96 * @param rate The desired maximum bandwidth.
97 * @param bound The bandwidth with only the network taken into account.
98 * @param size The size of the message.
99 * @return The new bandwidth.
101 virtual double bandwidthConstraint(double rate, double bound, double size);
102 double nextOccuringEventFull(double now) override;
104 LinkImpl* loopback_ = nullptr;
110 /** @ingroup SURF_network_interface
111 * @brief SURF network link interface class
112 * @details A Link represents the link between two [hosts](\ref simgrid::surf::HostImpl)
114 class LinkImpl : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
116 LinkImpl(simgrid::surf::NetworkModel* model, const char* name, lmm_constraint_t constraint);
117 ~LinkImpl() override;
119 void destroy(); // Must be called instead of the destructor
121 bool currentlyDestroying_ = false;
124 /** @brief Public interface */
127 /** @brief Get the bandwidth in bytes per second of current Link */
128 virtual double bandwidth();
130 /** @brief Update the bandwidth in bytes per second of current Link */
131 virtual void setBandwidth(double value) = 0;
133 /** @brief Get the latency in seconds of current Link */
134 virtual double latency();
136 /** @brief Update the latency in seconds of current Link */
137 virtual void setLatency(double value) = 0;
139 /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2:
141 virtual int sharingPolicy();
143 /** @brief Check if the Link is used */
144 bool isUsed() override;
146 void turnOn() override;
147 void turnOff() override;
149 virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF).
150 Trace must contain boolean values. */
151 virtual void setBandwidthTrace(tmgr_trace_t trace); /*< setup the trace file with bandwidth events (peak speed changes due to external load).
152 Trace must contain percentages (value between 0 and 1). */
153 virtual void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to external load).
154 Trace must contain absolute values */
156 tmgr_trace_iterator_t stateEvent_ = nullptr;
157 s_surf_metric_t latency_ = {1.0, 0, nullptr};
158 s_surf_metric_t bandwidth_ = {1.0, 0, nullptr};
162 void *getData() { return userData;}
163 void setData(void *d) { userData=d;}
165 void *userData = nullptr;
167 /* List of all links. FIXME: should move to the Engine */
169 static std::unordered_map<std::string, LinkImpl*>* links;
172 static LinkImpl* byName(const char* name);
173 static int linksCount();
174 static LinkImpl** linksList();
175 static void linksExit();
181 /** @ingroup SURF_network_interface
182 * @brief SURF network action interface class
183 * @details A NetworkAction represents a communication between two [hosts](\ref HostImpl)
185 class NetworkAction : public simgrid::surf::Action {
187 /** @brief Constructor
189 * @param model The NetworkModel associated to this NetworkAction
190 * @param cost The cost of this NetworkAction in [TODO]
191 * @param failed [description]
193 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
194 : simgrid::surf::Action(model, cost, failed) {}
197 * @brief NetworkAction constructor
199 * @param model The NetworkModel associated to this NetworkAction
200 * @param cost The cost of this NetworkAction in [TODO]
201 * @param failed [description]
202 * @param var The lmm variable associated to this Action if it is part of a
205 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
206 : simgrid::surf::Action(model, cost, failed, var) {};
208 void setState(simgrid::surf::Action::State state) override;
218 #endif /* SURF_NETWORK_INTERFACE_HPP_ */