Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / surf / network_interface.hpp
1 /* Copyright (c) 2004-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "surf_interface.hpp"
8 #include "surf_routing.hpp"
9
10 #ifndef SURF_NETWORK_INTERFACE_HPP_
11 #define SURF_NETWORK_INTERFACE_HPP_
12
13 /***********
14  * Classes *
15  ***********/
16 class NetworkModel;
17 typedef NetworkModel *NetworkModelPtr;
18
19 class NetworkLink;
20 typedef NetworkLink *NetworkLinkPtr;
21
22 class NetworkAction;
23 typedef NetworkAction *NetworkActionPtr;
24
25 /*************
26  * Callbacks *
27  *************/
28
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)`
32  */
33 extern surf_callback(void, NetworkLinkPtr) networkLinkCreatedCallbacks;
34
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)`
38  */
39 extern surf_callback(void, NetworkLinkPtr) networkLinkDestructedCallbacks;
40
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)`
44  */
45 extern surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resource_state_t) networkLinkStateChangedCallbacks;
46
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)`
50  */
51 extern surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t) networkActionStateChangedCallbacks;
52
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)`
56  */
57 extern surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) networkCommunicateCallbacks;
58
59 /*********
60  * Tools *
61  *********/
62
63 void net_define_callbacks(void);
64
65 /*********
66  * Model *
67  *********/
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
71  */
72 class NetworkModel : public Model {
73 public:
74   /**
75    * @brief NetworkModel constructor
76    */
77   NetworkModel() : Model("network") {
78   };
79
80   /**
81    * @brief NetworkModel constructor
82    *
83    * @param name The name of the NetworkModel
84    */
85   NetworkModel(const char *name) : Model(name) {
86         f_networkSolve = lmm_solve;
87         m_haveGap = false;
88   };
89
90   /**
91    * @brief The destructor of the NetworkModel
92    */
93   ~NetworkModel() {
94         if (p_maxminSystem)
95           lmm_system_free(p_maxminSystem);
96         if (p_actionHeap)
97           xbt_heap_free(p_actionHeap);
98         if (p_modifiedSet)
99           delete p_modifiedSet;
100   }
101
102   /**
103    * @brief Create a NetworkLink
104    *
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
115    */
116   virtual NetworkLinkPtr createResource(const char *name,
117                                    double bw_initial,
118                                    tmgr_trace_t bw_trace,
119                                    double lat_initial,
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;
125
126
127   virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
128
129   /**
130    * @brief Create a communication between two [TODO]
131    * @details [TODO]
132    *
133    * @param src The source [TODO]
134    * @param dst The destination [TODO]
135    * @param size The size of the communication in bytes
136    * @param rate The
137    * @return The action representing the communication
138    */
139   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
140                                            double size, double rate)=0;
141
142   /**
143    * @brief Function pointer to the function to use to solve the lmm_system_t
144    *
145    * @param system The lmm_system_t to solve
146    */
147   void (*f_networkSolve)(lmm_system_t);
148
149   /**
150    * @brief [brief description]
151    * @details [long description]
152    *
153    * @param size [description]
154    * @return [description]
155    */
156   virtual double latencyFactor(double size);
157
158   /**
159    * @brief [brief description]
160    * @details [long description]
161    *
162    * @param size [description]
163    * @return [description]
164    */
165   virtual double bandwidthFactor(double size);
166
167   /**
168    * @brief [brief description]
169    * @details [long description]
170    *
171    * @param rate [description]
172    * @param bound [description]
173    * @param size [description]
174    * @return [description]
175    */
176   virtual double bandwidthConstraint(double rate, double bound, double size);
177   bool m_haveGap;
178 };
179
180 /************
181  * Resource *
182  ************/
183  /** @ingroup SURF_network_interface
184   * @brief SURF network link interface class
185   * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
186   */
187 class NetworkLink : public Resource {
188 public:
189   /**
190    * @brief NetworkLink constructor
191    *
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
195    */
196   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
197
198   /**
199    * @brief NetworkLink constructor
200    *
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]
207    */
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);
212
213   /**
214    * @brief NetworkLink destructor
215    */
216   ~NetworkLink();
217
218   /**
219    * @brief Get the bandwidth in bytes per second of current NetworkLink
220    *
221    * @return The bandwith in bytes per second of the current NetworkLink
222    */
223   virtual double getBandwidth();
224
225   /**
226    * @brief Update the bandwidth in bytes per second of current NetworkLink
227    */
228   virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
229
230   /**
231    * @brief Get the latency in seconds of current NetworkLink
232    *
233    * @return The latency in seconds of the current NetworkLink
234    */
235   virtual double getLatency();
236
237   /**
238    * @brief Update the latency in seconds of current NetworkLink
239    */
240   virtual void updateLatency(double value, double date=surf_get_clock())=0;
241
242   /**
243    * @brief Check if the NetworkLink is shared
244    * @details [long description]
245    *
246    * @return true if the current NetwokrLink is shared, false otherwise
247    */
248   virtual bool isShared();
249
250   /**
251    * @brief Check if the NetworkLink is used
252    *
253    * @return true if the current NetwokrLink is used, false otherwise
254    */
255   bool isUsed();
256
257   void setState(e_surf_resource_state_t state);
258
259   /* Using this object with the public part of
260     model does not make sense */
261   double m_latCurrent;
262   tmgr_trace_event_t p_latEvent;
263
264   /* LMM */
265   tmgr_trace_event_t p_stateEvent;
266   s_surf_metric_t p_power;
267 };
268
269 /**********
270  * Action *
271  **********/
272 /** @ingroup SURF_network_interface
273  * @brief SURF network action interface class
274  * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
275  */
276 class NetworkAction : public Action {
277 public:
278   /**
279    * @brief NetworkAction constructor
280    *
281    * @param model The NetworkModel associated to this NetworkAction
282    * @param cost The cost of this  NetworkAction in [TODO]
283    * @param failed [description]
284    */
285   NetworkAction(ModelPtr model, double cost, bool failed)
286   : Action(model, cost, failed) {}
287
288   /**
289    * @brief NetworkAction constructor
290    *
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
295    */
296   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
297   : Action(model, cost, failed, var) {};
298
299   void setState(e_surf_action_state_t state);
300
301 #ifdef HAVE_LATENCY_BOUND_TRACKING
302   /**
303    * @brief Check if the action is limited by latency.
304    *
305    * @return 1 if action is limited by latency, 0 otherwise
306    */
307   virtual int getLatencyLimited() {return m_latencyLimited;}
308 #endif
309
310   double m_latency;
311   double m_latCurrent;
312   double m_weight;
313   double m_rate;
314   const char* p_senderLinkName;
315   double m_senderGap;
316   double m_senderSize;
317   xbt_fifo_item_t p_senderFifoItem;
318 #ifdef HAVE_LATENCY_BOUND_TRACKING
319   int m_latencyLimited;
320 #endif
321
322 };
323
324 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
325
326