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::surf::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::surf::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);
53 XBT_PUBLIC(void) net_add_traces();
62 /** @ingroup SURF_network_interface
63 * @brief SURF network model interface class
64 * @details A model is an object which handles the interactions between its Resources and its Actions
66 class NetworkModel : public Model {
68 /** @brief Constructor */
69 NetworkModel() : Model() { }
71 /** @brief Destructor */
74 lmm_system_free(p_maxminSystem);
76 xbt_heap_free(p_actionHeap);
82 * @brief Create a Link
84 * @param name The name of the Link
85 * @param bw_initial The initial bandwidth of the Link in bytes per second
86 * @param bw_trace The trace associated to the Link bandwidth
87 * @param lat_initial The initial latency of the Link in seconds
88 * @param lat_trace The trace associated to the Link latency
89 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
90 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
91 * @param policy The sharing policy of the Link
92 * @param properties Dictionary of properties associated to this Resource
93 * @return The created Link
95 virtual Link* createLink(const char *name,
97 tmgr_trace_t bw_trace,
99 tmgr_trace_t lat_trace,
101 tmgr_trace_t state_trace,
102 e_surf_link_sharing_policy_t policy,
103 xbt_dict_t properties)=0;
106 * @brief Create a communication between two hosts.
107 * @details It makes calls to the routing part, and execute the communication
108 * between the two end points.
110 * @param src The source of the communication
111 * @param dst The destination of the communication
112 * @param size The size of the communication in bytes
113 * @param rate Allows to limit the transfer rate. Negative value means
115 * @return The action representing the communication
117 virtual Action *communicate(NetCard *src, NetCard *dst,
118 double size, double rate)=0;
120 /** @brief Function pointer to the function to use to solve the lmm_system_t
122 * @param system The lmm_system_t to solve
124 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
127 * @brief Get the right multiplicative factor for the latency.
128 * @details Depending on the model, the effective latency when sending
129 * a message might be different from the theoretical latency of the link,
130 * in function of the message size. In order to account for this, this
131 * function gets this factor.
133 * @param size The size of the message.
134 * @return The latency factor.
136 virtual double latencyFactor(double size);
139 * @brief Get the right multiplicative factor for the bandwidth.
140 * @details Depending on the model, the effective bandwidth when sending
141 * a message might be different from the theoretical bandwidth of the link,
142 * in function of the message size. In order to account for this, this
143 * function gets this factor.
145 * @param size The size of the message.
146 * @return The bandwidth factor.
148 virtual double bandwidthFactor(double size);
151 * @brief Get definitive bandwidth.
152 * @details It gives the minimum bandwidth between the one that would
153 * occur if no limitation was enforced, and the one arbitrary limited.
154 * @param rate The desired maximum bandwidth.
155 * @param bound The bandwidth with only the network taken into account.
156 * @param size The size of the message.
157 * @return The new bandwidth.
159 virtual double bandwidthConstraint(double rate, double bound, double size);
160 double shareResourcesFull(double now);
166 /** @ingroup SURF_network_interface
167 * @brief SURF network link interface class
168 * @details A Link represents the link between two [hosts](\ref Host)
171 public simgrid::surf::Resource,
172 public simgrid::surf::PropertyHolder {
175 * @brief Link constructor
177 * @param model The NetworkModel associated to this Link
178 * @param name The name of the Link
179 * @param props Dictionary of properties associated to this Link
181 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props);
184 * @brief Link constructor
186 * @param model The NetworkModel associated to this Link
187 * @param name The name of the Link
188 * @param props Dictionary of properties associated to this Link
189 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
190 * @param history [TODO]
191 * @param state_trace [TODO]
193 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
194 lmm_constraint_t constraint,
195 tmgr_history_t history,
196 tmgr_trace_t state_trace);
198 /* Link destruction logic */
199 /**************************/
203 void destroy(); // Must be called instead of the destructor
205 bool currentlyDestroying_ = false;
208 /** @brief Callback signal fired when a new Link is created.
209 * Signature: void(Link*) */
210 static simgrid::surf::signal<void(simgrid::surf::Link*)> onCreation;
212 /** @brief Callback signal fired when a Link is destroyed.
213 * Signature: void(Link*) */
214 static simgrid::surf::signal<void(simgrid::surf::Link*)> onDestruction;
216 /** @brief Callback signal fired when the state of a Link changes
217 * Signature: `void(LinkAction *action, int previouslyOn, int currentlyOn)` */
218 static simgrid::surf::signal<void(simgrid::surf::Link*, int, int)> onStateChange;
221 /** @brief Get the bandwidth in bytes per second of current Link */
222 virtual double getBandwidth();
224 /** @brief Update the bandwidth in bytes per second of current Link */
225 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
227 /** @brief Get the latency in seconds of current Link */
228 virtual double getLatency();
230 /** @brief Update the latency in seconds of current Link */
231 virtual void updateLatency(double value, double date=surf_get_clock())=0;
233 /** @brief The sharing policy is a @{link #e_surf_link_sharing_policy_t} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
234 virtual int sharingPolicy();
236 /** @brief Check if the Link is used */
239 void turnOn() override;
240 void turnOff() override;
242 /* Using this object with the public part of
243 model does not make sense */
244 double m_latCurrent = 0;
245 tmgr_trace_event_t p_latEvent = NULL;
248 tmgr_trace_event_t p_stateEvent = NULL;
249 s_surf_metric_t p_speed;
253 void *getData() { return userData;}
254 void setData(void *d) { userData=d;}
256 void *userData = NULL;
258 /* List of all links */
260 static boost::unordered_map<std::string, Link *> *links;
262 static Link *byName(const char* name);
263 static int linksAmount();
264 static Link **linksList();
265 static void linksExit();
271 /** @ingroup SURF_network_interface
272 * @brief SURF network action interface class
273 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
275 class NetworkAction : public simgrid::surf::Action {
277 /** @brief Constructor
279 * @param model The NetworkModel associated to this NetworkAction
280 * @param cost The cost of this NetworkAction in [TODO]
281 * @param failed [description]
283 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
284 : simgrid::surf::Action(model, cost, failed) {}
287 * @brief NetworkAction constructor
289 * @param model The NetworkModel associated to this NetworkAction
290 * @param cost The cost of this NetworkAction in [TODO]
291 * @param failed [description]
292 * @param var The lmm variable associated to this Action if it is part of a
295 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
296 : simgrid::surf::Action(model, cost, failed, var) {};
298 void setState(e_surf_action_state_t state);
300 #ifdef HAVE_LATENCY_BOUND_TRACKING
302 * @brief Check if the action is limited by latency.
304 * @return 1 if action is limited by latency, 0 otherwise
306 virtual int getLatencyLimited() {return m_latencyLimited;}
313 const char* p_senderLinkName;
315 xbt_fifo_item_t p_senderFifoItem;
316 #ifdef HAVE_LATENCY_BOUND_TRACKING
317 int m_latencyLimited;
325 #endif /* SURF_NETWORK_INTERFACE_HPP_ */