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 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 [brief description]
145 * @details [long description]
147 * @param size [description]
148 * @return [description]
150 virtual double latencyFactor(double size);
153 * @brief [brief description]
154 * @details [long description]
156 * @param size [description]
157 * @return [description]
159 virtual double bandwidthFactor(double size);
162 * @brief [brief description]
163 * @details [long description]
165 * @param rate [description]
166 * @param bound [description]
167 * @param size [description]
168 * @return [description]
170 virtual double bandwidthConstraint(double rate, double bound, double size);
177 /** @ingroup SURF_network_interface
178 * @brief SURF network link interface class
179 * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
181 class NetworkLink : public Resource {
184 * @brief NetworkLink constructor
186 * @param model The CpuModel associated to this NetworkLink
187 * @param name The name of the NetworkLink
188 * @param props Dictionary of properties associated to this NetworkLink
190 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
193 * @brief NetworkLink constructor
195 * @param model The CpuModel associated to this NetworkLink
196 * @param name The name of the NetworkLink
197 * @param props Dictionary of properties associated to this NetworkLink
198 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
199 * @param history [TODO]
200 * @param state_trace [TODO]
202 NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
203 lmm_constraint_t constraint,
204 tmgr_history_t history,
205 tmgr_trace_t state_trace);
208 * @brief NetworkLink destructor
213 * @brief Get the bandwidth in bytes per second of current NetworkLink
215 * @return The bandwith in bytes per second of the current NetworkLink
217 virtual double getBandwidth();
220 * @brief Get the latency in seconds of current NetworkLink
222 * @return The latency in seconds of the current NetworkLink
224 virtual double getLatency();
227 * @brief Check if the NetworkLink is shared
228 * @details [long description]
230 * @return true if the current NetwokrLink is shared, false otherwise
232 virtual bool isShared();
235 * @brief Check if the NetworkLink is used
237 * @return true if the current NetwokrLink is used, false otherwise
241 void setState(e_surf_resource_state_t state);
243 /* Using this object with the public part of
244 model does not make sense */
246 tmgr_trace_event_t p_latEvent;
249 tmgr_trace_event_t p_stateEvent;
250 s_surf_metric_t p_power;
256 /** @ingroup SURF_network_interface
257 * @brief SURF network action interface class
258 * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
260 class NetworkAction : public Action {
263 * @brief NetworkAction constructor
265 * @param model The NetworkModel associated to this NetworkAction
266 * @param cost The cost of this NetworkAction in [TODO]
267 * @param failed [description]
269 NetworkAction(ModelPtr model, double cost, bool failed)
270 : Action(model, cost, failed) {}
273 * @brief NetworkAction constructor
275 * @param model The NetworkModel associated to this NetworkAction
276 * @param cost The cost of this NetworkAction in [TODO]
277 * @param failed [description]
278 * @param var The lmm variable associated to this Action if it is part of a LMM component
280 NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
281 : Action(model, cost, failed, var) {};
283 void setState(e_surf_action_state_t state);
285 #ifdef HAVE_LATENCY_BOUND_TRACKING
287 * @brief Check if the action is limited by latency.
289 * @return 1 if action is limited by latency, 0 otherwise
291 virtual int getLatencyLimited() {return m_latencyLimited;}
298 const char* p_senderLinkName;
301 xbt_fifo_item_t p_senderFifoItem;
302 #ifdef HAVE_LATENCY_BOUND_TRACKING
303 int m_latencyLimited;
308 #endif /* SURF_NETWORK_INTERFACE_HPP_ */