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 #ifndef SURF_NETWORK_INTERFACE_HPP_
11 #define SURF_NETWORK_INTERFACE_HPP_
18 typedef NetworkModel *NetworkModelPtr;
21 typedef NetworkLink *NetworkLinkPtr;
24 typedef NetworkAction *NetworkActionPtr;
30 /** @ingroup SURF_callbacks
31 * @brief Callbacks handler which emit the callbacks after NetworkLink creation
32 * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
34 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkCreatedCallbacks;
36 /** @ingroup SURF_callbacks
37 * @brief Callbacks handler which emit the callbacks after NetworkLink destruction
38 * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
40 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkDestructedCallbacks;
42 /** @ingroup SURF_callbacks
43 * @brief Callbacks handler which emit the callbacks after NetworkLink State changed
44 * @details Callback functions have the following signature: `void(NetworkLinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
46 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
48 /** @ingroup SURF_callbacks
49 * @brief Callbacks handler which emit the callbacks after NetworkAction State changed
50 * @details Callback functions have the following signature: `void(NetworkActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
52 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
54 /** @ingroup SURF_callbacks
55 * @brief Callbacks handler which emit the callbacks after communication created
56 * @details Callback functions have the following signature: `void(NetworkActionPtr action, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)`
58 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)) networkCommunicateCallbacks;
63 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
65 XBT_PUBLIC(void) net_add_traces();
70 /** @ingroup SURF_network_interface
71 * @brief SURF network model interface class
72 * @details A model is an object which handle the interactions between its Resources and its Actions
74 class NetworkModel : public Model {
77 * @brief NetworkModel constructor
79 NetworkModel() : Model("network") {
83 * @brief NetworkModel constructor
85 * @param name The name of the NetworkModel
87 NetworkModel(const char *name) : Model(name) {
88 f_networkSolve = lmm_solve;
93 * @brief The destructor of the NetworkModel
97 lmm_system_free(p_maxminSystem);
99 xbt_heap_free(p_actionHeap);
101 delete p_modifiedSet;
105 * @brief Create a NetworkLink
107 * @param name The name of the NetworkLink
108 * @param bw_initial The initial bandwidth of the NetworkLink in bytes per second
109 * @param bw_trace The trace associated to the NetworkLink bandwidth
110 * @param lat_initial The initial latency of the NetworkLink in seconds
111 * @param lat_trace The trace associated to the NetworkLink latency
112 * @param state_initial The initial NetworkLink (state)[e_surf_resource_state_t]
113 * @param state_trace The trace associated to the NetworkLink (state)[e_surf_resource_state_t]
114 * @param policy The sharing policy of the NetworkLink
115 * @param properties Dictionary of properties associated to this Resource
116 * @return The created NetworkLink
118 virtual NetworkLinkPtr createNetworkLink(const char *name,
120 tmgr_trace_t bw_trace,
122 tmgr_trace_t lat_trace,
123 e_surf_resource_state_t state_initial,
124 tmgr_trace_t state_trace,
125 e_surf_link_sharing_policy_t policy,
126 xbt_dict_t properties)=0;
128 virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
131 * @brief Create a communication between two workstations.
132 * @details It makes calls to the routing part, and execute the communication
133 * between the two end points.
135 * @param src The source of the communication
136 * @param dst The destination of the communication
137 * @param size The size of the communication in bytes
138 * @param rate Allows to limit the transfer rate. Negative value means
140 * @return The action representing the communication
142 virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
143 double size, double rate)=0;
146 * @brief Function pointer to the function to use to solve the lmm_system_t
148 * @param system The lmm_system_t to solve
150 void (*f_networkSolve)(lmm_system_t);
153 * @brief Gets the right multiplicative factor for the latency.
154 * @details According to the model, the effective latency when sending
155 * a message might be different from the theoretical latency in function
156 * of its size. In order to account for this, this function get this factor.
158 * @param size The size of the message.
159 * @return The latency factor.
161 virtual double latencyFactor(double size);
164 * @brief Gets the right multiplicative factor for the bandwidth.
165 * @details According to the model, the effective bandwidth when sending
166 * a message might be different from the theoretical bandwidth in function
167 * of its size. In order to account for this, this function get this factor.
169 * @param size The size of the message.
170 * @return The bandwidth factor.
172 virtual double bandwidthFactor(double size);
175 * @brief Gets definitive bandwidth.
176 * @details It gives the minimum bandwidth between the one that would
177 * occur if no limitation was enforced, and the maximum wanted bandwidth
178 * @param rate The desired maximum bandwidth.
179 * @param bound The bandwidth with only the network taken into account.
180 * @param size The size of the message.
181 * @return The new bandwidth.
183 virtual double bandwidthConstraint(double rate, double bound, double size);
190 /** @ingroup SURF_network_interface
191 * @brief SURF network link interface class
192 * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
194 class NetworkLink : public Resource {
197 * @brief NetworkLink constructor
199 * @param model The CpuModel associated to this NetworkLink
200 * @param name The name of the NetworkLink
201 * @param props Dictionary of properties associated to this NetworkLink
203 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
206 * @brief NetworkLink constructor
208 * @param model The CpuModel associated to this NetworkLink
209 * @param name The name of the NetworkLink
210 * @param props Dictionary of properties associated to this NetworkLink
211 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
212 * @param history [TODO]
213 * @param state_trace [TODO]
215 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
216 lmm_constraint_t constraint,
217 tmgr_history_t history,
218 tmgr_trace_t state_trace);
221 * @brief NetworkLink destructor
226 * @brief Get the bandwidth in bytes per second of current NetworkLink
228 * @return The bandwith in bytes per second of the current NetworkLink
230 virtual double getBandwidth();
233 * @brief Update the bandwidth in bytes per second of current NetworkLink
235 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
238 * @brief Get the latency in seconds of current NetworkLink
240 * @return The latency in seconds of the current NetworkLink
242 virtual double getLatency();
245 * @brief Update the latency in seconds of current NetworkLink
247 virtual void updateLatency(double value, double date=surf_get_clock())=0;
250 * @brief Check if the NetworkLink is shared
251 * @details [long description]
253 * @return true if the current NetwokrLink is shared, false otherwise
255 virtual bool isShared();
258 * @brief Check if the NetworkLink is used
260 * @return true if the current NetwokrLink is used, false otherwise
264 void setState(e_surf_resource_state_t state);
266 /* Using this object with the public part of
267 model does not make sense */
269 tmgr_trace_event_t p_latEvent;
272 tmgr_trace_event_t p_stateEvent;
273 s_surf_metric_t p_power;
279 /** @ingroup SURF_network_interface
280 * @brief SURF network action interface class
281 * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
283 class NetworkAction : public Action {
286 * @brief NetworkAction constructor
288 * @param model The NetworkModel associated to this NetworkAction
289 * @param cost The cost of this NetworkAction in [TODO]
290 * @param failed [description]
292 NetworkAction(ModelPtr model, double cost, bool failed)
293 : Action(model, cost, failed) {}
296 * @brief NetworkAction constructor
298 * @param model The NetworkModel associated to this NetworkAction
299 * @param cost The cost of this NetworkAction in [TODO]
300 * @param failed [description]
301 * @param var The lmm variable associated to this Action if it is part of a LMM component
303 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
304 : Action(model, cost, failed, var) {};
306 void setState(e_surf_action_state_t state);
308 #ifdef HAVE_LATENCY_BOUND_TRACKING
310 * @brief Check if the action is limited by latency.
312 * @return 1 if action is limited by latency, 0 otherwise
314 virtual int getLatencyLimited() {return m_latencyLimited;}
321 const char* p_senderLinkName;
324 xbt_fifo_item_t p_senderFifoItem;
325 #ifdef HAVE_LATENCY_BOUND_TRACKING
326 int m_latencyLimited;
331 #endif /* SURF_NETWORK_INTERFACE_HPP_ */