1 /* Copyright (c) 2004-2014. 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 #include "surf_interface.hpp"
8 #include "surf_routing.hpp"
10 #include "simgrid/link.h"
12 #ifndef SURF_NETWORK_INTERFACE_HPP_
13 #define SURF_NETWORK_INTERFACE_HPP_
19 typedef NetworkModel *NetworkModelPtr;
22 typedef NetworkAction *NetworkActionPtr;
28 /** @ingroup SURF_callbacks
29 * @brief Callbacks handler which emits the callbacks after Link creation
30 * @details Callback functions have the following signature: `void(Link*)`
32 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkCreatedCallbacks;
34 /** @ingroup SURF_callbacks
35 * @brief Callbacks handler which emits the callbacks after Link destruction
36 * @details Callback functions have the following signature: `void(Link*)`
38 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkDestructedCallbacks;
40 /** @ingroup SURF_callbacks
41 * @brief Callbacks handler which emits the callbacks after Link State changed
42 * @details Callback functions have the following signature: `void(LinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
44 XBT_PUBLIC_DATA( surf_callback(void, Link*, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
46 /** @ingroup SURF_callbacks
47 * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
48 * @details Callback functions have the following signature: `void(NetworkActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
50 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
52 /** @ingroup SURF_callbacks
53 * @brief Callbacks handler which emits the callbacks after communication created
54 * @details Callback functions have the following signature: `void(NetworkActionPtr action, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)`
56 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)) networkCommunicateCallbacks;
61 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
63 XBT_PUBLIC(void) net_add_traces();
68 /** @ingroup SURF_network_interface
69 * @brief SURF network model interface class
70 * @details A model is an object which handles the interactions between its Resources and its Actions
72 class NetworkModel : public Model {
74 /** @brief NetworkModel constructor */
75 NetworkModel() : Model("network") {
76 f_networkSolve = lmm_solve;
79 /** @brief NetworkModel constructor */
80 NetworkModel(const char *name) : Model(name) {
81 f_networkSolve = lmm_solve;
84 /** @brief The destructor of the NetworkModel */
87 lmm_system_free(p_maxminSystem);
89 xbt_heap_free(p_actionHeap);
95 * @brief Create a Link
97 * @param name The name of the Link
98 * @param bw_initial The initial bandwidth of the Link in bytes per second
99 * @param bw_trace The trace associated to the Link bandwidth
100 * @param lat_initial The initial latency of the Link in seconds
101 * @param lat_trace The trace associated to the Link latency
102 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
103 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
104 * @param policy The sharing policy of the Link
105 * @param properties Dictionary of properties associated to this Resource
106 * @return The created Link
108 virtual Link* createLink(const char *name,
110 tmgr_trace_t bw_trace,
112 tmgr_trace_t lat_trace,
113 e_surf_resource_state_t state_initial,
114 tmgr_trace_t state_trace,
115 e_surf_link_sharing_policy_t policy,
116 xbt_dict_t properties)=0;
118 virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkActionPtr /*action*/) {};
121 * @brief Create a communication between two hosts.
122 * @details It makes calls to the routing part, and execute the communication
123 * between the two end points.
125 * @param src The source of the communication
126 * @param dst The destination of the communication
127 * @param size The size of the communication in bytes
128 * @param rate Allows to limit the transfer rate. Negative value means
130 * @return The action representing the communication
132 virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
133 double size, double rate)=0;
136 * @brief Function pointer to the function to use to solve the lmm_system_t
138 * @param system The lmm_system_t to solve
140 void (*f_networkSolve)(lmm_system_t);
143 * @brief Get the right multiplicative factor for the latency.
144 * @details Depending on the model, the effective latency when sending
145 * a message might be different from the theoretical latency of the link,
146 * in function of the message size. In order to account for this, this
147 * function gets this factor.
149 * @param size The size of the message.
150 * @return The latency factor.
152 virtual double latencyFactor(double size);
155 * @brief Get the right multiplicative factor for the bandwidth.
156 * @details Depending on the model, the effective bandwidth when sending
157 * a message might be different from the theoretical bandwidth of the link,
158 * in function of the message size. In order to account for this, this
159 * function gets this factor.
161 * @param size The size of the message.
162 * @return The bandwidth factor.
164 virtual double bandwidthFactor(double size);
167 * @brief Get definitive bandwidth.
168 * @details It gives the minimum bandwidth between the one that would
169 * occur if no limitation was enforced, and the one arbitrary limited.
170 * @param rate The desired maximum bandwidth.
171 * @param bound The bandwidth with only the network taken into account.
172 * @param size The size of the message.
173 * @return The new bandwidth.
175 virtual double bandwidthConstraint(double rate, double bound, double size);
176 double shareResourcesFull(double now);
177 bool m_haveGap = false;
183 /** @ingroup SURF_network_interface
184 * @brief SURF network link interface class
185 * @details A Link represents the link between two [hosts](\ref Host)
187 class Link : public Resource {
190 * @brief Link constructor
192 * @param model The NetworkModel associated to this Link
193 * @param name The name of the Link
194 * @param props Dictionary of properties associated to this Link
196 Link(NetworkModelPtr model, const char *name, xbt_dict_t props);
199 * @brief Link constructor
201 * @param model The NetworkModel associated to this Link
202 * @param name The name of the Link
203 * @param props Dictionary of properties associated to this Link
204 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
205 * @param history [TODO]
206 * @param state_trace [TODO]
208 Link(NetworkModelPtr model, const char *name, xbt_dict_t props,
209 lmm_constraint_t constraint,
210 tmgr_history_t history,
211 tmgr_trace_t state_trace);
213 /** @brief Link destructor */
216 /** @brief Get the bandwidth in bytes per second of current Link */
217 virtual double getBandwidth();
219 /** @brief Update the bandwidth in bytes per second of current Link */
220 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
222 /** @brief Get the latency in seconds of current Link */
223 virtual double getLatency();
225 /** @brief Update the latency in seconds of current Link */
226 virtual void updateLatency(double value, double date=surf_get_clock())=0;
229 * @brief Check if the Link is shared
231 * @return true if the current NetwokrLink is shared, false otherwise
233 virtual bool isShared();
235 /** @brief Check if the Link is used */
238 void setState(e_surf_resource_state_t state);
240 /* Using this object with the public part of
241 model does not make sense */
243 tmgr_trace_event_t p_latEvent;
246 tmgr_trace_event_t p_stateEvent;
247 s_surf_metric_t p_power;
250 void *getData() { return userData;}
251 void setData(void *d) { userData=d;}
259 /** @ingroup SURF_network_interface
260 * @brief SURF network action interface class
261 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
263 class NetworkAction : public Action {
266 * @brief NetworkAction constructor
268 * @param model The NetworkModel associated to this NetworkAction
269 * @param cost The cost of this NetworkAction in [TODO]
270 * @param failed [description]
272 NetworkAction(ModelPtr model, double cost, bool failed)
273 : Action(model, cost, failed) {}
276 * @brief NetworkAction constructor
278 * @param model The NetworkModel associated to this NetworkAction
279 * @param cost The cost of this NetworkAction in [TODO]
280 * @param failed [description]
281 * @param var The lmm variable associated to this Action if it is part of a
284 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
285 : Action(model, cost, failed, var) {};
287 void setState(e_surf_action_state_t state);
289 #ifdef HAVE_LATENCY_BOUND_TRACKING
291 * @brief Check if the action is limited by latency.
293 * @return 1 if action is limited by latency, 0 otherwise
295 virtual int getLatencyLimited() {return m_latencyLimited;}
302 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_ */