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"
19 #include "simgrid/link.h"
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks handler which emits the callbacks after Link creation
33 * @details Callback functions have the following signature: `void(Link*)`
35 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkCreatedCallbacks;
37 /** @ingroup SURF_callbacks
38 * @brief Callbacks handler which emits the callbacks after Link destruction
39 * @details Callback functions have the following signature: `void(Link*)`
41 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkDestructedCallbacks;
43 /** @ingroup SURF_callbacks
44 * @brief Callbacks handler which emits the callbacks after Link State changed
45 * @details Callback functions have the following signature: `void(LinkAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
47 XBT_PUBLIC_DATA( surf_callback(void, Link*, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
49 /** @ingroup SURF_callbacks
50 * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
51 * @details Callback functions have the following signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
53 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
55 /** @ingroup SURF_callbacks
56 * @brief Callbacks handler which emits the callbacks after communication created
57 * @details Callback functions have the following signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)`
59 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, RoutingEdge *src, RoutingEdge *dst, double size, double rate)) networkCommunicateCallbacks;
64 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
66 XBT_PUBLIC(void) net_add_traces();
71 /** @ingroup SURF_network_interface
72 * @brief SURF network model interface class
73 * @details A model is an object which handles the interactions between its Resources and its Actions
75 class NetworkModel : public Model {
77 /** @brief Constructor */
78 NetworkModel() : Model() { }
80 /** @brief Destructor */
83 lmm_system_free(p_maxminSystem);
85 xbt_heap_free(p_actionHeap);
91 * @brief Create a Link
93 * @param name The name of the Link
94 * @param bw_initial The initial bandwidth of the Link in bytes per second
95 * @param bw_trace The trace associated to the Link bandwidth
96 * @param lat_initial The initial latency of the Link in seconds
97 * @param lat_trace The trace associated to the Link latency
98 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
99 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
100 * @param policy The sharing policy of the Link
101 * @param properties Dictionary of properties associated to this Resource
102 * @return The created Link
104 virtual Link* createLink(const char *name,
106 tmgr_trace_t bw_trace,
108 tmgr_trace_t lat_trace,
109 e_surf_resource_state_t state_initial,
110 tmgr_trace_t state_trace,
111 e_surf_link_sharing_policy_t policy,
112 xbt_dict_t properties)=0;
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);
175 /** @ingroup SURF_network_interface
176 * @brief SURF network link interface class
177 * @details A Link represents the link between two [hosts](\ref Host)
179 class Link : public Resource {
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
188 Link(NetworkModel *model, const char *name, xbt_dict_t props);
191 * @brief Link constructor
193 * @param model The NetworkModel associated to this Link
194 * @param name The name of the Link
195 * @param props Dictionary of properties associated to this Link
196 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
197 * @param history [TODO]
198 * @param state_trace [TODO]
200 Link(NetworkModel *model, const char *name, xbt_dict_t props,
201 lmm_constraint_t constraint,
202 tmgr_history_t history,
203 tmgr_trace_t state_trace);
205 /** @brief Link destructor */
208 /** @brief Get the bandwidth in bytes per second of current Link */
209 virtual double getBandwidth();
211 /** @brief Update the bandwidth in bytes per second of current Link */
212 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
214 /** @brief Get the latency in seconds of current Link */
215 virtual double getLatency();
217 /** @brief Update the latency in seconds of current Link */
218 virtual void updateLatency(double value, double date=surf_get_clock())=0;
221 * @brief Check if the Link is shared
223 * @return true if the current NetwokrLink is shared, false otherwise
225 virtual bool isShared();
227 /** @brief Check if the Link is used */
230 void setState(e_surf_resource_state_t state);
232 /* Using this object with the public part of
233 model does not make sense */
235 tmgr_trace_event_t p_latEvent;
238 tmgr_trace_event_t p_stateEvent = NULL;
239 s_surf_metric_t p_power;
243 void *getData() { return userData;}
244 void setData(void *d) { userData=d;}
246 void *userData = NULL;
248 /* List of all links */
250 static boost::unordered_map<std::string, Link *> *links;
252 static Link *byName(const char* name);
253 static int linksAmount();
254 static Link **linksList();
255 static void linksExit();
261 /** @ingroup SURF_network_interface
262 * @brief SURF network action interface class
263 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
265 class NetworkAction : public Action {
267 /** @brief Constructor
269 * @param model The NetworkModel associated to this NetworkAction
270 * @param cost The cost of this NetworkAction in [TODO]
271 * @param failed [description]
273 NetworkAction(Model *model, double cost, bool failed)
274 : Action(model, cost, failed) {}
277 * @brief NetworkAction constructor
279 * @param model The NetworkModel associated to this NetworkAction
280 * @param cost The cost of this NetworkAction in [TODO]
281 * @param failed [description]
282 * @param var The lmm variable associated to this Action if it is part of a
285 NetworkAction(Model *model, double cost, bool failed, lmm_variable_t var)
286 : Action(model, cost, failed, var) {};
288 void setState(e_surf_action_state_t state);
290 #ifdef HAVE_LATENCY_BOUND_TRACKING
292 * @brief Check if the action is limited by latency.
294 * @return 1 if action is limited by latency, 0 otherwise
296 virtual int getLatencyLimited() {return m_latencyLimited;}
303 const char* p_senderLinkName;
305 xbt_fifo_item_t p_senderFifoItem;
306 #ifdef HAVE_LATENCY_BOUND_TRACKING
307 int m_latencyLimited;
312 #endif /* SURF_NETWORK_INTERFACE_HPP_ */