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_
10 #include <boost/unordered_map.hpp>
14 #include "surf_interface.hpp"
15 #include "surf_routing.hpp"
17 #include "simgrid/link.h"
29 /** @ingroup SURF_callbacks
30 * @brief Callbacks handler which emits the callbacks after Link creation
31 * @details Callback functions have the following signature: `void(Link*)`
33 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkCreatedCallbacks;
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks handler which emits the callbacks after Link destruction
37 * @details Callback functions have the following signature: `void(Link*)`
39 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkDestructedCallbacks;
41 /** @ingroup SURF_callbacks
42 * @brief Callbacks handler which emits the callbacks after Link State changed
43 * @details Callback functions have the following signature: `void(LinkAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45 XBT_PUBLIC_DATA( surf_callback(void, Link*, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
47 /** @ingroup SURF_callbacks
48 * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
49 * @details Callback functions have the following signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
51 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
53 /** @ingroup SURF_callbacks
54 * @brief Callbacks handler which emits the callbacks after communication created
55 * @details Callback functions have the following signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)`
57 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, RoutingEdge *src, RoutingEdge *dst, double size, double rate)) networkCommunicateCallbacks;
62 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
64 XBT_PUBLIC(void) net_add_traces();
69 /** @ingroup SURF_network_interface
70 * @brief SURF network model interface class
71 * @details A model is an object which handles the interactions between its Resources and its Actions
73 class NetworkModel : public Model {
75 /** @brief Constructor */
76 NetworkModel() : Model() { }
78 /** @brief Destructor */
81 lmm_system_free(p_maxminSystem);
83 xbt_heap_free(p_actionHeap);
89 * @brief Create a Link
91 * @param name The name of the Link
92 * @param bw_initial The initial bandwidth of the Link in bytes per second
93 * @param bw_trace The trace associated to the Link bandwidth
94 * @param lat_initial The initial latency of the Link in seconds
95 * @param lat_trace The trace associated to the Link latency
96 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
97 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
98 * @param policy The sharing policy of the Link
99 * @param properties Dictionary of properties associated to this Resource
100 * @return The created Link
102 virtual Link* createLink(const char *name,
104 tmgr_trace_t bw_trace,
106 tmgr_trace_t lat_trace,
107 e_surf_resource_state_t state_initial,
108 tmgr_trace_t state_trace,
109 e_surf_link_sharing_policy_t policy,
110 xbt_dict_t properties)=0;
112 virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {};
115 * @brief Create a communication between two hosts.
116 * @details It makes calls to the routing part, and execute the communication
117 * between the two end points.
119 * @param src The source of the communication
120 * @param dst The destination of the communication
121 * @param size The size of the communication in bytes
122 * @param rate Allows to limit the transfer rate. Negative value means
124 * @return The action representing the communication
126 virtual Action *communicate(RoutingEdge *src, RoutingEdge *dst,
127 double size, double rate)=0;
129 /** @brief Function pointer to the function to use to solve the lmm_system_t
131 * @param system The lmm_system_t to solve
133 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
136 * @brief Get the right multiplicative factor for the latency.
137 * @details Depending on the model, the effective latency when sending
138 * a message might be different from the theoretical latency of the link,
139 * in function of the message size. In order to account for this, this
140 * function gets this factor.
142 * @param size The size of the message.
143 * @return The latency factor.
145 virtual double latencyFactor(double size);
148 * @brief Get the right multiplicative factor for the bandwidth.
149 * @details Depending on the model, the effective bandwidth when sending
150 * a message might be different from the theoretical bandwidth of the link,
151 * in function of the message size. In order to account for this, this
152 * function gets this factor.
154 * @param size The size of the message.
155 * @return The bandwidth factor.
157 virtual double bandwidthFactor(double size);
160 * @brief Get definitive bandwidth.
161 * @details It gives the minimum bandwidth between the one that would
162 * occur if no limitation was enforced, and the one arbitrary limited.
163 * @param rate The desired maximum bandwidth.
164 * @param bound The bandwidth with only the network taken into account.
165 * @param size The size of the message.
166 * @return The new bandwidth.
168 virtual double bandwidthConstraint(double rate, double bound, double size);
169 double shareResourcesFull(double now);
170 bool m_haveGap = false;
176 /** @ingroup SURF_network_interface
177 * @brief SURF network link interface class
178 * @details A Link represents the link between two [hosts](\ref Host)
180 class Link : public Resource {
183 * @brief Link constructor
185 * @param model The NetworkModel associated to this Link
186 * @param name The name of the Link
187 * @param props Dictionary of properties associated to this Link
189 Link(NetworkModel *model, const char *name, xbt_dict_t props);
192 * @brief Link constructor
194 * @param model The NetworkModel associated to this Link
195 * @param name The name of the Link
196 * @param props Dictionary of properties associated to this Link
197 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
198 * @param history [TODO]
199 * @param state_trace [TODO]
201 Link(NetworkModel *model, const char *name, xbt_dict_t props,
202 lmm_constraint_t constraint,
203 tmgr_history_t history,
204 tmgr_trace_t state_trace);
206 /** @brief Link destructor */
209 /** @brief Get the bandwidth in bytes per second of current Link */
210 virtual double getBandwidth();
212 /** @brief Update the bandwidth in bytes per second of current Link */
213 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
215 /** @brief Get the latency in seconds of current Link */
216 virtual double getLatency();
218 /** @brief Update the latency in seconds of current Link */
219 virtual void updateLatency(double value, double date=surf_get_clock())=0;
222 * @brief Check if the Link is shared
224 * @return true if the current NetwokrLink is shared, false otherwise
226 virtual bool isShared();
228 /** @brief Check if the Link is used */
231 void setState(e_surf_resource_state_t state);
233 /* Using this object with the public part of
234 model does not make sense */
236 tmgr_trace_event_t p_latEvent;
239 tmgr_trace_event_t p_stateEvent = NULL;
240 s_surf_metric_t p_power;
244 void *getData() { return userData;}
245 void setData(void *d) { userData=d;}
247 void *userData = NULL;
249 /* List of all links */
251 static boost::unordered_map<std::string, Link *> *links;
253 static Link *byName(const char* name);
254 static int linksAmount();
255 static Link **linksList();
256 static void linksExit();
262 /** @ingroup SURF_network_interface
263 * @brief SURF network action interface class
264 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
266 class NetworkAction : public Action {
268 /** @brief Constructor
270 * @param model The NetworkModel associated to this NetworkAction
271 * @param cost The cost of this NetworkAction in [TODO]
272 * @param failed [description]
274 NetworkAction(Model *model, double cost, bool failed)
275 : Action(model, cost, failed) {}
278 * @brief NetworkAction constructor
280 * @param model The NetworkModel associated to this NetworkAction
281 * @param cost The cost of this NetworkAction in [TODO]
282 * @param failed [description]
283 * @param var The lmm variable associated to this Action if it is part of a
286 NetworkAction(Model *model, double cost, bool failed, lmm_variable_t var)
287 : Action(model, cost, failed, var) {};
289 void setState(e_surf_action_state_t state);
291 #ifdef HAVE_LATENCY_BOUND_TRACKING
293 * @brief Check if the action is limited by latency.
295 * @return 1 if action is limited by latency, 0 otherwise
297 virtual int getLatencyLimited() {return m_latencyLimited;}
304 const char* p_senderLinkName;
307 xbt_fifo_item_t p_senderFifoItem;
308 #ifdef HAVE_LATENCY_BOUND_TRACKING
309 int m_latencyLimited;
314 #endif /* SURF_NETWORK_INTERFACE_HPP_ */