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 <boost/unordered_map.hpp>
16 #include "surf_interface.hpp"
17 #include "surf_routing.hpp"
18 #include "src/surf/PropertyHolder.hpp"
20 #include "simgrid/link.h"
37 /** @brief Callback signal fired when the state of a NetworkAction changes
38 * Signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */
39 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)>) networkActionStateChangedCallbacks;
41 /** @brief Callback signal fired when a NetworkAction is created (when a communication starts)
42 * Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)` */
43 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst, double size, double rate)>) networkCommunicateCallbacks;
51 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
60 /** @ingroup SURF_network_interface
61 * @brief SURF network model interface class
62 * @details A model is an object which handles the interactions between its Resources and its Actions
64 class NetworkModel : public Model {
66 /** @brief Constructor */
67 NetworkModel() : Model() { }
69 /** @brief Destructor */
72 lmm_system_free(p_maxminSystem);
74 xbt_heap_free(p_actionHeap);
80 * @brief Create a Link
82 * @param name The name of the Link
83 * @param bw_initial The initial bandwidth of the Link in bytes per second
84 * @param bw_trace The trace associated to the Link bandwidth
85 * @param lat_initial The initial latency of the Link in seconds
86 * @param lat_trace The trace associated to the Link latency
87 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
88 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
89 * @param policy The sharing policy of the Link
90 * @param properties Dictionary of properties associated to this Resource
91 * @return The created Link
93 virtual Link* createLink(const char *name,
95 tmgr_trace_t bw_trace,
97 tmgr_trace_t lat_trace,
99 tmgr_trace_t state_trace,
100 e_surf_link_sharing_policy_t policy,
101 xbt_dict_t properties)=0;
104 * @brief Create a communication between two hosts.
105 * @details It makes calls to the routing part, and execute the communication
106 * between the two end points.
108 * @param src The source of the communication
109 * @param dst The destination of the communication
110 * @param size The size of the communication in bytes
111 * @param rate Allows to limit the transfer rate. Negative value means
113 * @return The action representing the communication
115 virtual Action *communicate(NetCard *src, NetCard *dst,
116 double size, double rate)=0;
118 /** @brief Function pointer to the function to use to solve the lmm_system_t
120 * @param system The lmm_system_t to solve
122 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
125 * @brief Get the right multiplicative factor for the latency.
126 * @details Depending on the model, the effective latency when sending
127 * a message might be different from the theoretical latency of the link,
128 * in function of the message size. In order to account for this, this
129 * function gets this factor.
131 * @param size The size of the message.
132 * @return The latency factor.
134 virtual double latencyFactor(double size);
137 * @brief Get the right multiplicative factor for the bandwidth.
138 * @details Depending on the model, the effective bandwidth when sending
139 * a message might be different from the theoretical bandwidth of the link,
140 * in function of the message size. In order to account for this, this
141 * function gets this factor.
143 * @param size The size of the message.
144 * @return The bandwidth factor.
146 virtual double bandwidthFactor(double size);
149 * @brief Get definitive bandwidth.
150 * @details It gives the minimum bandwidth between the one that would
151 * occur if no limitation was enforced, and the one arbitrary limited.
152 * @param rate The desired maximum bandwidth.
153 * @param bound The bandwidth with only the network taken into account.
154 * @param size The size of the message.
155 * @return The new bandwidth.
157 virtual double bandwidthConstraint(double rate, double bound, double size);
158 double shareResourcesFull(double now);
164 /** @ingroup SURF_network_interface
165 * @brief SURF network link interface class
166 * @details A Link represents the link between two [hosts](\ref Host)
169 public simgrid::surf::Resource,
170 public simgrid::surf::PropertyHolder {
173 * @brief Link constructor
175 * @param model The NetworkModel associated to this Link
176 * @param name The name of the Link
177 * @param props Dictionary of properties associated to this Link
179 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props);
182 * @brief Link constructor
184 * @param model The NetworkModel associated to this Link
185 * @param name The name of the Link
186 * @param props Dictionary of properties associated to this Link
187 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
188 * @param history [TODO]
189 * @param state_trace [TODO]
191 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
192 lmm_constraint_t constraint,
193 tmgr_history_t history,
194 tmgr_trace_t state_trace);
196 /* Link destruction logic */
197 /**************************/
201 void destroy(); // Must be called instead of the destructor
203 bool currentlyDestroying_ = false;
206 /** @brief Callback signal fired when a new Link is created.
207 * Signature: void(Link*) */
208 static simgrid::xbt::signal<void(simgrid::surf::Link*)> onCreation;
210 /** @brief Callback signal fired when a Link is destroyed.
211 * Signature: void(Link*) */
212 static simgrid::xbt::signal<void(simgrid::surf::Link*)> onDestruction;
214 /** @brief Callback signal fired when the state of a Link changes
215 * Signature: `void(LinkAction *action, int previouslyOn, int currentlyOn)` */
216 static simgrid::xbt::signal<void(simgrid::surf::Link*, int, int)> onStateChange;
219 /** @brief Get the bandwidth in bytes per second of current Link */
220 virtual double getBandwidth();
222 /** @brief Update the bandwidth in bytes per second of current Link */
223 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
225 /** @brief Get the latency in seconds of current Link */
226 virtual double getLatency();
228 /** @brief Update the latency in seconds of current Link */
229 virtual void updateLatency(double value, double date=surf_get_clock())=0;
231 /** @brief The sharing policy is a @{link #e_surf_link_sharing_policy_t} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
232 virtual int sharingPolicy();
234 /** @brief Check if the Link is used */
237 void turnOn() override;
238 void turnOff() override;
240 /* Using this object with the public part of
241 model does not make sense */
242 double m_latCurrent = 0;
243 tmgr_trace_event_t p_latEvent = NULL;
246 tmgr_trace_event_t p_stateEvent = NULL;
247 s_surf_metric_t p_speed;
251 void *getData() { return userData;}
252 void setData(void *d) { userData=d;}
254 void *userData = NULL;
256 /* List of all links */
258 static boost::unordered_map<std::string, Link *> *links;
260 static Link *byName(const char* name);
261 static int linksAmount();
262 static Link **linksList();
263 static void linksExit();
269 /** @ingroup SURF_network_interface
270 * @brief SURF network action interface class
271 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
273 class NetworkAction : public simgrid::surf::Action {
275 /** @brief Constructor
277 * @param model The NetworkModel associated to this NetworkAction
278 * @param cost The cost of this NetworkAction in [TODO]
279 * @param failed [description]
281 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
282 : simgrid::surf::Action(model, cost, failed) {}
285 * @brief NetworkAction constructor
287 * @param model The NetworkModel associated to this NetworkAction
288 * @param cost The cost of this NetworkAction in [TODO]
289 * @param failed [description]
290 * @param var The lmm variable associated to this Action if it is part of a
293 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
294 : simgrid::surf::Action(model, cost, failed, var) {};
296 void setState(e_surf_action_state_t state);
298 #ifdef HAVE_LATENCY_BOUND_TRACKING
300 * @brief Check if the action is limited by latency.
302 * @return 1 if action is limited by latency, 0 otherwise
304 virtual int getLatencyLimited() {return m_latencyLimited;}
311 const char* p_senderLinkName;
313 xbt_fifo_item_t p_senderFifoItem;
314 #ifdef HAVE_LATENCY_BOUND_TRACKING
315 int m_latencyLimited;
323 #endif /* SURF_NETWORK_INTERFACE_HPP_ */