1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SURF_NETWORK_INTERFACE_HPP_
8 #define SURF_NETWORK_INTERFACE_HPP_
12 #include <unordered_map>
16 #include "surf_interface.hpp"
17 #include "src/surf/PropertyHolder.hpp"
19 #include "simgrid/link.h"
20 #include "simgrid/s4u/Link.hpp"
32 /** @ingroup SURF_network_interface
33 * @brief SURF network model interface class
34 * @details A model is an object which handles the interactions between its Resources and its Actions
36 class NetworkModel : public Model {
38 /** @brief Constructor */
39 NetworkModel() : Model() { }
41 /** @brief Destructor */
42 ~NetworkModel() override;
45 * @brief Create a Link
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
52 virtual LinkImpl* createLink(const char* name, double bandwidth, double latency,
53 e_surf_link_sharing_policy_t policy) = 0;
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.
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
65 * @return The action representing the communication
67 virtual Action* communicate(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double size, double rate) = 0;
69 /** @brief Function pointer to the function to use to solve the lmm_system_t
71 * @param system The lmm_system_t to solve
73 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
76 * @brief Get the right multiplicative factor for the latency.
77 * @details Depending on the model, the effective latency when sending
78 * a message might be different from the theoretical latency of the link,
79 * in function of the message size. In order to account for this, this
80 * function gets this factor.
82 * @param size The size of the message.
83 * @return The latency factor.
85 virtual double latencyFactor(double size);
88 * @brief Get the right multiplicative factor for the bandwidth.
89 * @details Depending on the model, the effective bandwidth when sending
90 * a message might be different from the theoretical bandwidth of the link,
91 * in function of the message size. In order to account for this, this
92 * function gets this factor.
94 * @param size The size of the message.
95 * @return The bandwidth factor.
97 virtual double bandwidthFactor(double size);
100 * @brief Get definitive bandwidth.
101 * @details It gives the minimum bandwidth between the one that would
102 * occur if no limitation was enforced, and the one arbitrary limited.
103 * @param rate The desired maximum bandwidth.
104 * @param bound The bandwidth with only the network taken into account.
105 * @param size The size of the message.
106 * @return The new bandwidth.
108 virtual double bandwidthConstraint(double rate, double bound, double size);
109 double nextOccuringEventFull(double now) override;
111 LinkImpl* loopback_ = nullptr;
117 /** @ingroup SURF_network_interface
118 * @brief SURF network link interface class
119 * @details A Link represents the link between two [hosts](\ref simgrid::surf::HostImpl)
121 class LinkImpl : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
123 LinkImpl(simgrid::surf::NetworkModel* model, const char* name, lmm_constraint_t constraint);
124 ~LinkImpl() override;
126 void destroy(); // Must be called instead of the destructor
128 bool currentlyDestroying_ = false;
131 /** @brief Public interface */
134 /** @brief Get the bandwidth in bytes per second of current Link */
135 virtual double bandwidth();
137 /** @brief Update the bandwidth in bytes per second of current Link */
138 virtual void setBandwidth(double value) = 0;
140 /** @brief Get the latency in seconds of current Link */
141 virtual double latency();
143 /** @brief Update the latency in seconds of current Link */
144 virtual void setLatency(double value) = 0;
146 /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2:
148 virtual int sharingPolicy();
150 /** @brief Check if the Link is used */
151 bool isUsed() override;
153 void turnOn() override;
154 void turnOff() override;
156 virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF).
157 Trace must contain boolean values. */
158 virtual void setBandwidthTrace(tmgr_trace_t trace); /*< setup the trace file with bandwidth events (peak speed changes due to external load).
159 Trace must contain percentages (value between 0 and 1). */
160 virtual void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to external load).
161 Trace must contain absolute values */
163 tmgr_trace_iterator_t stateEvent_ = nullptr;
164 s_surf_metric_t latency_ = {1.0, 0, nullptr};
165 s_surf_metric_t bandwidth_ = {1.0, 0, nullptr};
169 void *getData() { return userData;}
170 void setData(void *d) { userData=d;}
172 void *userData = nullptr;
174 /* List of all links. FIXME: should move to the Engine */
176 static std::unordered_map<std::string, LinkImpl*>* links;
179 static LinkImpl* byName(const char* name);
180 static int linksCount();
181 static LinkImpl** linksList();
182 static void linksExit();
188 /** @ingroup SURF_network_interface
189 * @brief SURF network action interface class
190 * @details A NetworkAction represents a communication between two [hosts](\ref HostImpl)
192 class NetworkAction : public simgrid::surf::Action {
194 /** @brief Constructor
196 * @param model The NetworkModel associated to this NetworkAction
197 * @param cost The cost of this NetworkAction in [TODO]
198 * @param failed [description]
200 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
201 : simgrid::surf::Action(model, cost, failed) {}
204 * @brief NetworkAction constructor
206 * @param model The NetworkModel associated to this NetworkAction
207 * @param cost The cost of this NetworkAction in [TODO]
208 * @param failed [description]
209 * @param var The lmm variable associated to this Action if it is part of a
212 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
213 : simgrid::surf::Action(model, cost, failed, var) {};
215 void setState(simgrid::surf::Action::State state) override;
221 const char* senderLinkName_;
223 xbt_fifo_item_t senderFifoItem_;
228 #endif /* SURF_NETWORK_INTERFACE_HPP_ */