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)`
45 extern surf_callback(void, NetworkLinkPtr) 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)`
51 extern surf_callback(void, NetworkActionPtr) networkActionStateChangedCallbacks;
57 void net_define_callbacks(void);
62 /** @ingroup SURF_network_interface
63 * @brief SURF network model interface class
64 * @details A model is an object which handle the interactions between its Resources and its Actions
66 class NetworkModel : public Model {
69 * @brief NetworkModel constructor
71 NetworkModel() : Model("network") {
75 * @brief NetworkModel constructor
77 * @param name The name of the NetworkModel
79 NetworkModel(const char *name) : Model(name) {
80 f_networkSolve = lmm_solve;
85 * @brief The destructor of the NetworkModel
89 lmm_system_free(p_maxminSystem);
91 xbt_heap_free(p_actionHeap);
97 * @brief Create a NetworkLink
99 * @param name The name of the NetworkLink
100 * @param bw_initial The initial bandwidth of the NetworkLink in bytes per second
101 * @param bw_trace The trace associated to the NetworkLink bandwidth [TODO]
102 * @param lat_initial The initial latency of the NetworkLink in seconds
103 * @param lat_trace The trace associated to the NetworkLink latency [TODO]
104 * @param state_initial The initial NetworkLink (state)[e_surf_resource_state_t]
105 * @param state_trace The trace associated to the NetworkLink (state)[e_surf_resource_state_t] [TODO]
106 * @param policy The sharing policy of the NetworkLink
107 * @param properties Dictionary of properties associated to this Resource
108 * @return The created NetworkLink
110 virtual NetworkLinkPtr createResource(const char *name,
112 tmgr_trace_t bw_trace,
114 tmgr_trace_t lat_trace,
115 e_surf_resource_state_t state_initial,
116 tmgr_trace_t state_trace,
117 e_surf_link_sharing_policy_t policy,
118 xbt_dict_t properties)=0;
121 virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
124 * @brief Create a communication between two [TODO]
127 * @param src The source [TODO]
128 * @param dst The destination [TODO]
129 * @param size The size of the communication in bytes
131 * @return The action representing the communication
133 virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
134 double size, double rate)=0;
137 * @brief Get the route between two RoutingEdge
143 * @return A xbt_dynar_t of [TODO]
145 virtual xbt_dynar_t getRoute(RoutingEdgePtr src, RoutingEdgePtr dst); //FIXME: kill field? That is done by the routing nowadays
148 * @brief Function pointer to the function to use to solve the lmm_system_t
150 * @param system The lmm_system_t to solve
152 void (*f_networkSolve)(lmm_system_t);
155 * @brief [brief description]
156 * @details [long description]
158 * @param size [description]
159 * @return [description]
161 virtual double latencyFactor(double size);
164 * @brief [brief description]
165 * @details [long description]
167 * @param size [description]
168 * @return [description]
170 virtual double bandwidthFactor(double size);
173 * @brief [brief description]
174 * @details [long description]
176 * @param rate [description]
177 * @param bound [description]
178 * @param size [description]
179 * @return [description]
181 virtual double bandwidthConstraint(double rate, double bound, double size);
188 /** @ingroup SURF_network_interface
189 * @brief SURF network link interface class
190 * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
192 class NetworkLink : public Resource {
195 * @brief NetworkLink constructor
197 * @param model The CpuModel associated to this NetworkLink
198 * @param name The name of the NetworkLink
199 * @param props Dictionary of properties associated to this NetworkLink
201 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
204 * @brief NetworkLink constructor
206 * @param model The CpuModel associated to this NetworkLink
207 * @param name The name of the NetworkLink
208 * @param props Dictionary of properties associated to this NetworkLink
209 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
210 * @param history [TODO]
211 * @param state_trace [TODO]
213 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
214 lmm_constraint_t constraint,
215 tmgr_history_t history,
216 tmgr_trace_t state_trace);
219 * @brief NetworkLink destructor
224 * @brief Get the bandwidth in bytes per second of current NetworkLink
226 * @return The bandwith in bytes per second of the current NetworkLink
228 virtual double getBandwidth();
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 Check if the NetworkLink is shared
239 * @details [long description]
241 * @return true if the current NetwokrLink is shared, false otherwise
243 virtual bool isShared();
246 * @brief Check if the NetworkLink is used
248 * @return true if the current NetwokrLink is used, false otherwise
252 void setState(e_surf_resource_state_t state);
254 /* Using this object with the public part of
255 model does not make sense */
257 tmgr_trace_event_t p_latEvent;
260 tmgr_trace_event_t p_stateEvent;
261 s_surf_metric_t p_power;
267 /** @ingroup SURF_network_interface
268 * @brief SURF network action interface class
269 * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
271 class NetworkAction : public Action {
274 * @brief NetworkAction 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(ModelPtr model, double cost, bool failed)
281 : 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 LMM component
291 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
292 : Action(model, cost, failed, var) {};
294 void setState(e_surf_action_state_t state);
300 const char* p_senderLinkName;
303 xbt_fifo_item_t p_senderFifoItem;
304 #ifdef HAVE_LATENCY_BOUND_TRACKING
305 int m_latencyLimited;
310 #endif /* SURF_NETWORK_INTERFACE_HPP_ */