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 NetworkLink *NetworkLinkPtr;
23 typedef NetworkAction *NetworkActionPtr;
29 /** @ingroup SURF_callbacks
30 * @brief Callbacks handler which emit the callbacks after NetworkLink creation
31 * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
33 extern surf_callback(void, NetworkLinkPtr) networkLinkCreatedCallbacks;
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks handler which emit the callbacks after NetworkLink destruction
37 * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
39 extern surf_callback(void, NetworkLinkPtr) networkLinkDestructedCallbacks;
41 /** @ingroup SURF_callbacks
42 * @brief Callbacks handler which emit the callbacks after NetworkLink State changed
43 * @details Callback functions have the following signature: `void(NetworkLinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45 extern surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resource_state_t) networkLinkStateChangedCallbacks;
47 /** @ingroup SURF_callbacks
48 * @brief Callbacks handler which emit 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 extern surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t) networkActionStateChangedCallbacks;
53 /** @ingroup SURF_callbacks
54 * @brief Callbacks handler which emit 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 extern surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) networkCommunicateCallbacks;
63 void net_define_callbacks(void);
68 /** @ingroup SURF_network_interface
69 * @brief SURF network model interface class
70 * @details A model is an object which handle the interactions between its Resources and its Actions
72 class NetworkModel : public Model {
75 * @brief NetworkModel constructor
77 NetworkModel() : Model("network") {
81 * @brief NetworkModel constructor
83 * @param name The name of the NetworkModel
85 NetworkModel(const char *name) : Model(name) {
86 f_networkSolve = lmm_solve;
91 * @brief The destructor of the NetworkModel
95 lmm_system_free(p_maxminSystem);
97 xbt_heap_free(p_actionHeap);
103 * @brief Create a NetworkLink
105 * @param name The name of the NetworkLink
106 * @param bw_initial The initial bandwidth of the NetworkLink in bytes per second
107 * @param bw_trace The trace associated to the NetworkLink bandwidth [TODO]
108 * @param lat_initial The initial latency of the NetworkLink in seconds
109 * @param lat_trace The trace associated to the NetworkLink latency [TODO]
110 * @param state_initial The initial NetworkLink (state)[e_surf_resource_state_t]
111 * @param state_trace The trace associated to the NetworkLink (state)[e_surf_resource_state_t] [TODO]
112 * @param policy The sharing policy of the NetworkLink
113 * @param properties Dictionary of properties associated to this Resource
114 * @return The created NetworkLink
116 virtual NetworkLinkPtr createResource(const char *name,
118 tmgr_trace_t bw_trace,
120 tmgr_trace_t lat_trace,
121 e_surf_resource_state_t state_initial,
122 tmgr_trace_t state_trace,
123 e_surf_link_sharing_policy_t policy,
124 xbt_dict_t properties)=0;
127 virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
130 * @brief Create a communication between two [TODO]
133 * @param src The source [TODO]
134 * @param dst The destination [TODO]
135 * @param size The size of the communication in bytes
137 * @return The action representing the communication
139 virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
140 double size, double rate)=0;
143 * @brief Function pointer to the function to use to solve the lmm_system_t
145 * @param system The lmm_system_t to solve
147 void (*f_networkSolve)(lmm_system_t);
150 * @brief [brief description]
151 * @details [long description]
153 * @param size [description]
154 * @return [description]
156 virtual double latencyFactor(double size);
159 * @brief [brief description]
160 * @details [long description]
162 * @param size [description]
163 * @return [description]
165 virtual double bandwidthFactor(double size);
168 * @brief [brief description]
169 * @details [long description]
171 * @param rate [description]
172 * @param bound [description]
173 * @param size [description]
174 * @return [description]
176 virtual double bandwidthConstraint(double rate, double bound, double size);
183 /** @ingroup SURF_network_interface
184 * @brief SURF network link interface class
185 * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
187 class NetworkLink : public Resource {
190 * @brief NetworkLink constructor
192 * @param model The CpuModel associated to this NetworkLink
193 * @param name The name of the NetworkLink
194 * @param props Dictionary of properties associated to this NetworkLink
196 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
199 * @brief NetworkLink constructor
201 * @param model The CpuModel associated to this NetworkLink
202 * @param name The name of the NetworkLink
203 * @param props Dictionary of properties associated to this NetworkLink
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 NetworkLink(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);
214 * @brief NetworkLink destructor
219 * @brief Get the bandwidth in bytes per second of current NetworkLink
221 * @return The bandwith in bytes per second of the current NetworkLink
223 virtual double getBandwidth();
226 * @brief Update the bandwidth in bytes per second of current NetworkLink
228 virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
231 * @brief Get the latency in seconds of current NetworkLink
233 * @return The latency in seconds of the current NetworkLink
235 virtual double getLatency();
238 * @brief Update the latency in seconds of current NetworkLink
240 virtual void updateLatency(double value, double date=surf_get_clock())=0;
243 * @brief Check if the NetworkLink is shared
244 * @details [long description]
246 * @return true if the current NetwokrLink is shared, false otherwise
248 virtual bool isShared();
251 * @brief Check if the NetworkLink is used
253 * @return true if the current NetwokrLink is used, false otherwise
257 void setState(e_surf_resource_state_t state);
259 /* Using this object with the public part of
260 model does not make sense */
262 tmgr_trace_event_t p_latEvent;
265 tmgr_trace_event_t p_stateEvent;
266 s_surf_metric_t p_power;
272 /** @ingroup SURF_network_interface
273 * @brief SURF network action interface class
274 * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
276 class NetworkAction : public Action {
279 * @brief NetworkAction constructor
281 * @param model The NetworkModel associated to this NetworkAction
282 * @param cost The cost of this NetworkAction in [TODO]
283 * @param failed [description]
285 NetworkAction(ModelPtr model, double cost, bool failed)
286 : Action(model, cost, failed) {}
289 * @brief NetworkAction constructor
291 * @param model The NetworkModel associated to this NetworkAction
292 * @param cost The cost of this NetworkAction in [TODO]
293 * @param failed [description]
294 * @param var The lmm variable associated to this Action if it is part of a LMM component
296 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
297 : Action(model, cost, failed, var) {};
299 void setState(e_surf_action_state_t state);
301 #ifdef HAVE_LATENCY_BOUND_TRACKING
303 * @brief Check if the action is limited by latency.
305 * @return 1 if action is limited by latency, 0 otherwise
307 virtual int getLatencyLimited() {return m_latencyLimited;}
314 const char* p_senderLinkName;
317 xbt_fifo_item_t p_senderFifoItem;
318 #ifdef HAVE_LATENCY_BOUND_TRACKING
319 int m_latencyLimited;
324 #endif /* SURF_NETWORK_INTERFACE_HPP_ */