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_
17 typedef NetworkModel *NetworkModelPtr;
20 typedef Link *LinkPtr;
23 typedef NetworkAction *NetworkActionPtr;
29 /** @ingroup SURF_callbacks
30 * @brief Callbacks handler which emits the callbacks after Link creation
31 * @details Callback functions have the following signature: `void(LinkPtr)`
33 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr)) 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(LinkPtr)`
39 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr)) 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(LinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr, 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(NetworkActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
51 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, 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(NetworkActionPtr action, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)`
57 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr 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 NetworkModel constructor */
76 NetworkModel() : Model("network") {
77 f_networkSolve = lmm_solve;
80 /** @brief NetworkModel constructor */
81 NetworkModel(const char *name) : Model(name) {
82 f_networkSolve = lmm_solve;
85 /** @brief The destructor of the NetworkModel */
88 lmm_system_free(p_maxminSystem);
90 xbt_heap_free(p_actionHeap);
96 * @brief Create a Link
98 * @param name The name of the Link
99 * @param bw_initial The initial bandwidth of the Link in bytes per second
100 * @param bw_trace The trace associated to the Link bandwidth
101 * @param lat_initial The initial latency of the Link in seconds
102 * @param lat_trace The trace associated to the Link latency
103 * @param state_initial The initial Link (state)[e_surf_resource_state_t]
104 * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
105 * @param policy The sharing policy of the Link
106 * @param properties Dictionary of properties associated to this Resource
107 * @return The created Link
109 virtual LinkPtr createLink(const char *name,
111 tmgr_trace_t bw_trace,
113 tmgr_trace_t lat_trace,
114 e_surf_resource_state_t state_initial,
115 tmgr_trace_t state_trace,
116 e_surf_link_sharing_policy_t policy,
117 xbt_dict_t properties)=0;
119 virtual void gapAppend(double /*size*/, const LinkPtr /*link*/, NetworkActionPtr /*action*/) {};
122 * @brief Create a communication between two hosts.
123 * @details It makes calls to the routing part, and execute the communication
124 * between the two end points.
126 * @param src The source of the communication
127 * @param dst The destination of the communication
128 * @param size The size of the communication in bytes
129 * @param rate Allows to limit the transfer rate. Negative value means
131 * @return The action representing the communication
133 virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
134 double size, double rate)=0;
137 * @brief Function pointer to the function to use to solve the lmm_system_t
139 * @param system The lmm_system_t to solve
141 void (*f_networkSolve)(lmm_system_t);
144 * @brief Get the right multiplicative factor for the latency.
145 * @details Depending on the model, the effective latency when sending
146 * a message might be different from the theoretical latency of the link,
147 * in function of the message size. In order to account for this, this
148 * function gets this factor.
150 * @param size The size of the message.
151 * @return The latency factor.
153 virtual double latencyFactor(double size);
156 * @brief Get the right multiplicative factor for the bandwidth.
157 * @details Depending on the model, the effective bandwidth when sending
158 * a message might be different from the theoretical bandwidth of the link,
159 * in function of the message size. In order to account for this, this
160 * function gets this factor.
162 * @param size The size of the message.
163 * @return The bandwidth factor.
165 virtual double bandwidthFactor(double size);
168 * @brief Get definitive bandwidth.
169 * @details It gives the minimum bandwidth between the one that would
170 * occur if no limitation was enforced, and the one arbitrary limited.
171 * @param rate The desired maximum bandwidth.
172 * @param bound The bandwidth with only the network taken into account.
173 * @param size The size of the message.
174 * @return The new bandwidth.
176 virtual double bandwidthConstraint(double rate, double bound, double size);
177 double shareResourcesFull(double now);
178 bool m_haveGap = false;
184 /** @ingroup SURF_network_interface
185 * @brief SURF network link interface class
186 * @details A Link represents the link between two [hosts](\ref Host)
188 class Link : public Resource {
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
197 Link(NetworkModelPtr model, const char *name, xbt_dict_t props);
200 * @brief Link constructor
202 * @param model The NetworkModel associated to this Link
203 * @param name The name of the Link
204 * @param props Dictionary of properties associated to this Link
205 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
206 * @param history [TODO]
207 * @param state_trace [TODO]
209 Link(NetworkModelPtr model, const char *name, xbt_dict_t props,
210 lmm_constraint_t constraint,
211 tmgr_history_t history,
212 tmgr_trace_t state_trace);
214 /** @brief Link destructor */
217 /** @brief Get the bandwidth in bytes per second of current Link */
218 virtual double getBandwidth();
220 /** @brief Update the bandwidth in bytes per second of current Link */
221 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
223 /** @brief Get the latency in seconds of current Link */
224 virtual double getLatency();
226 /** @brief Update the latency in seconds of current Link */
227 virtual void updateLatency(double value, double date=surf_get_clock())=0;
230 * @brief Check if the Link is shared
232 * @return true if the current NetwokrLink is shared, false otherwise
234 virtual bool isShared();
236 /** @brief Check if the Link is used */
239 void setState(e_surf_resource_state_t state);
241 /* Using this object with the public part of
242 model does not make sense */
244 tmgr_trace_event_t p_latEvent;
247 tmgr_trace_event_t p_stateEvent;
248 s_surf_metric_t p_power;
254 /** @ingroup SURF_network_interface
255 * @brief SURF network action interface class
256 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
258 class NetworkAction : public Action {
261 * @brief NetworkAction constructor
263 * @param model The NetworkModel associated to this NetworkAction
264 * @param cost The cost of this NetworkAction in [TODO]
265 * @param failed [description]
267 NetworkAction(ModelPtr model, double cost, bool failed)
268 : Action(model, cost, failed) {}
271 * @brief NetworkAction constructor
273 * @param model The NetworkModel associated to this NetworkAction
274 * @param cost The cost of this NetworkAction in [TODO]
275 * @param failed [description]
276 * @param var The lmm variable associated to this Action if it is part of a
279 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
280 : Action(model, cost, failed, var) {};
282 void setState(e_surf_action_state_t state);
284 #ifdef HAVE_LATENCY_BOUND_TRACKING
286 * @brief Check if the action is limited by latency.
288 * @return 1 if action is limited by latency, 0 otherwise
290 virtual int getLatencyLimited() {return m_latencyLimited;}
297 const char* p_senderLinkName;
300 xbt_fifo_item_t p_senderFifoItem;
301 #ifdef HAVE_LATENCY_BOUND_TRACKING
302 int m_latencyLimited;
307 #endif /* SURF_NETWORK_INTERFACE_HPP_ */