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"
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks handler which emits the callbacks after Link creation
37 * @details Callback functions have the following signature: `void(Link*)`
39 XBT_PUBLIC_DATA( surf_callback(void, simgrid::surf::Link*)) networkLinkCreatedCallbacks;
41 /** @ingroup SURF_callbacks
42 * @brief Callbacks handler which emits the callbacks after Link destruction
43 * @details Callback functions have the following signature: `void(Link*)`
45 XBT_PUBLIC_DATA( surf_callback(void, simgrid::surf::Link*)) networkLinkDestructedCallbacks;
47 /** @ingroup SURF_callbacks
48 * @brief Callbacks handler which emits the callbacks after Link State changed
49 * @details Callback functions have the following signature: `void(LinkAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
51 XBT_PUBLIC_DATA( surf_callback(void, simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
53 /** @ingroup SURF_callbacks
54 * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
55 * @details Callback functions have the following signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
57 XBT_PUBLIC_DATA( surf_callback(void, simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
59 /** @ingroup SURF_callbacks
60 * @brief Callbacks handler which emits the callbacks after communication created
61 * @details Callback functions have the following signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)`
63 XBT_PUBLIC_DATA( surf_callback(void, simgrid::surf::NetworkAction*, simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst, double size, double rate)) networkCommunicateCallbacks;
71 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
73 XBT_PUBLIC(void) net_add_traces();
82 /** @ingroup SURF_network_interface
83 * @brief SURF network model interface class
84 * @details A model is an object which handles the interactions between its Resources and its Actions
86 class NetworkModel : public Model {
88 /** @brief Constructor */
89 NetworkModel() : Model() { }
91 /** @brief Destructor */
94 lmm_system_free(p_maxminSystem);
96 xbt_heap_free(p_actionHeap);
102 * @brief Create a Link
104 * @param name The name of the Link
105 * @param bw_initial The initial bandwidth of the Link in bytes per second
106 * @param bw_trace The trace associated to the Link bandwidth
107 * @param lat_initial The initial latency of the Link in seconds
108 * @param lat_trace The trace associated to the Link latency
109 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
110 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
111 * @param policy The sharing policy of the Link
112 * @param properties Dictionary of properties associated to this Resource
113 * @return The created Link
115 virtual Link* createLink(const char *name,
117 tmgr_trace_t bw_trace,
119 tmgr_trace_t lat_trace,
120 e_surf_resource_state_t state_initial,
121 tmgr_trace_t state_trace,
122 e_surf_link_sharing_policy_t policy,
123 xbt_dict_t properties)=0;
126 * @brief Create a communication between two hosts.
127 * @details It makes calls to the routing part, and execute the communication
128 * between the two end points.
130 * @param src The source of the communication
131 * @param dst The destination of the communication
132 * @param size The size of the communication in bytes
133 * @param rate Allows to limit the transfer rate. Negative value means
135 * @return The action representing the communication
137 virtual Action *communicate(RoutingEdge *src, RoutingEdge *dst,
138 double size, double rate)=0;
140 /** @brief Function pointer to the function to use to solve the lmm_system_t
142 * @param system The lmm_system_t to solve
144 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
147 * @brief Get the right multiplicative factor for the latency.
148 * @details Depending on the model, the effective latency when sending
149 * a message might be different from the theoretical latency of the link,
150 * in function of the message size. In order to account for this, this
151 * function gets this factor.
153 * @param size The size of the message.
154 * @return The latency factor.
156 virtual double latencyFactor(double size);
159 * @brief Get the right multiplicative factor for the bandwidth.
160 * @details Depending on the model, the effective bandwidth when sending
161 * a message might be different from the theoretical bandwidth of the link,
162 * in function of the message size. In order to account for this, this
163 * function gets this factor.
165 * @param size The size of the message.
166 * @return The bandwidth factor.
168 virtual double bandwidthFactor(double size);
171 * @brief Get definitive bandwidth.
172 * @details It gives the minimum bandwidth between the one that would
173 * occur if no limitation was enforced, and the one arbitrary limited.
174 * @param rate The desired maximum bandwidth.
175 * @param bound The bandwidth with only the network taken into account.
176 * @param size The size of the message.
177 * @return The new bandwidth.
179 virtual double bandwidthConstraint(double rate, double bound, double size);
180 double shareResourcesFull(double now);
186 /** @ingroup SURF_network_interface
187 * @brief SURF network link interface class
188 * @details A Link represents the link between two [hosts](\ref Host)
190 class Link : public simgrid::surf::Resource {
193 * @brief Link constructor
195 * @param model The NetworkModel associated to this Link
196 * @param name The name of the Link
197 * @param props Dictionary of properties associated to this Link
199 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props);
202 * @brief Link constructor
204 * @param model The NetworkModel associated to this Link
205 * @param name The name of the Link
206 * @param props Dictionary of properties associated to this Link
207 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
208 * @param history [TODO]
209 * @param state_trace [TODO]
211 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
212 lmm_constraint_t constraint,
213 tmgr_history_t history,
214 tmgr_trace_t state_trace);
216 /** @brief Link destructor */
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 setState(e_surf_resource_state_t state);
239 /* Using this object with the public part of
240 model does not make sense */
241 double m_latCurrent = 0;
242 tmgr_trace_event_t p_latEvent = NULL;
245 tmgr_trace_event_t p_stateEvent = NULL;
246 s_surf_metric_t p_speed;
250 void *getData() { return userData;}
251 void setData(void *d) { userData=d;}
253 void *userData = NULL;
255 /* List of all links */
257 static boost::unordered_map<std::string, Link *> *links;
259 static Link *byName(const char* name);
260 static int linksAmount();
261 static Link **linksList();
262 static void linksExit();
268 /** @ingroup SURF_network_interface
269 * @brief SURF network action interface class
270 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
272 class NetworkAction : public simgrid::surf::Action {
274 /** @brief Constructor
276 * @param model The NetworkModel associated to this NetworkAction
277 * @param cost The cost of this NetworkAction in [TODO]
278 * @param failed [description]
280 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
281 : simgrid::surf::Action(model, cost, failed) {}
284 * @brief NetworkAction constructor
286 * @param model The NetworkModel associated to this NetworkAction
287 * @param cost The cost of this NetworkAction in [TODO]
288 * @param failed [description]
289 * @param var The lmm variable associated to this Action if it is part of a
292 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
293 : simgrid::surf::Action(model, cost, failed, var) {};
295 void setState(e_surf_action_state_t state);
297 #ifdef HAVE_LATENCY_BOUND_TRACKING
299 * @brief Check if the action is limited by latency.
301 * @return 1 if action is limited by latency, 0 otherwise
303 virtual int getLatencyLimited() {return m_latencyLimited;}
310 const char* p_senderLinkName;
312 xbt_fifo_item_t p_senderFifoItem;
313 #ifdef HAVE_LATENCY_BOUND_TRACKING
314 int m_latencyLimited;
322 #endif /* SURF_NETWORK_INTERFACE_HPP_ */