Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[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)`
44  */
45 extern surf_callback(void, NetworkLinkPtr) 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)`
50  */
51 extern surf_callback(void, NetworkActionPtr) networkActionStateChangedCallbacks;
52
53 /*********
54  * Tools *
55  *********/
56
57 void net_define_callbacks(void);
58
59 /*********
60  * Model *
61  *********/
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
65  */
66 class NetworkModel : public Model {
67 public:
68   /**
69    * @brief NetworkModel constructor
70    */
71   NetworkModel() : Model("network") {
72   };
73
74   /**
75    * @brief NetworkModel constructor
76    * 
77    * @param name The name of the NetworkModel
78    */
79   NetworkModel(const char *name) : Model(name) {
80         f_networkSolve = lmm_solve;
81         m_haveGap = false;
82   };
83
84   /**
85    * @brief The destructor of the NetworkModel
86    */
87   ~NetworkModel() {
88         if (p_maxminSystem)
89           lmm_system_free(p_maxminSystem);
90         if (p_actionHeap)
91           xbt_heap_free(p_actionHeap);
92         if (p_modifiedSet)
93           delete p_modifiedSet;
94   }
95
96   /**
97    * @brief Create a NetworkLink
98    * 
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
109    */
110   virtual NetworkLinkPtr createResource(const char *name,
111                                    double bw_initial,
112                                    tmgr_trace_t bw_trace,
113                                    double lat_initial,
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;
119
120
121   virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
122
123   /**
124    * @brief Create a communication between two [TODO]
125    * @details [TODO]
126    * 
127    * @param src The source [TODO]
128    * @param dst The destination [TODO]
129    * @param size The size of the communication in bytes
130    * @param rate The 
131    * @return The action representing the communication
132    */
133   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
134                                            double size, double rate)=0;
135
136   /**
137    * @brief Get the route between two RoutingEdge
138    * @details [TODO]
139    * 
140    * @param src [TODO]
141    * @param dst [TODO]
142    * 
143    * @return A xbt_dynar_t of [TODO]
144    */
145   virtual xbt_dynar_t getRoute(RoutingEdgePtr src, RoutingEdgePtr dst); //FIXME: kill field? That is done by the routing nowadays
146
147   /**
148    * @brief Function pointer to the function to use to solve the lmm_system_t
149    * 
150    * @param system The lmm_system_t to solve
151    */
152   void (*f_networkSolve)(lmm_system_t);
153
154   /**
155    * @brief [brief description]
156    * @details [long description]
157    * 
158    * @param size [description]
159    * @return [description]
160    */
161   virtual double latencyFactor(double size);
162
163   /**
164    * @brief [brief description]
165    * @details [long description]
166    * 
167    * @param size [description]
168    * @return [description]
169    */
170   virtual double bandwidthFactor(double size);
171
172   /**
173    * @brief [brief description]
174    * @details [long description]
175    * 
176    * @param rate [description]
177    * @param bound [description]
178    * @param size [description]
179    * @return [description]
180    */
181   virtual double bandwidthConstraint(double rate, double bound, double size);
182   bool m_haveGap;
183 };
184
185 /************
186  * Resource *
187  ************/
188  /** @ingroup SURF_network_interface
189   * @brief SURF network link interface class
190   * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
191   */
192 class NetworkLink : public Resource {
193 public:
194   /**
195    * @brief NetworkLink constructor
196    * 
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
200    */
201   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
202
203   /**
204    * @brief NetworkLink constructor
205    * 
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]
212    */
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);
217
218   /**
219    * @brief NetworkLink destructor
220    */
221   ~NetworkLink();
222
223   /**
224    * @brief Get the bandwidth in bytes per second of current NetworkLink
225    * 
226    * @return The bandwith in bytes per second of the current NetworkLink
227    */
228   virtual double getBandwidth();
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 Check if the NetworkLink is shared
239    * @details [long description]
240    * 
241    * @return true if the current NetwokrLink is shared, false otherwise
242    */
243   virtual bool isShared();
244
245   /**
246    * @brief Check if the NetworkLink is used
247    * 
248    * @return true if the current NetwokrLink is used, false otherwise
249    */
250   bool isUsed();
251
252   void setState(e_surf_resource_state_t state);
253
254   /* Using this object with the public part of
255     model does not make sense */
256   double m_latCurrent;
257   tmgr_trace_event_t p_latEvent;
258
259   /* LMM */
260   tmgr_trace_event_t p_stateEvent;
261   s_surf_metric_t p_power;
262 };
263
264 /**********
265  * Action *
266  **********/
267 /** @ingroup SURF_network_interface
268  * @brief SURF network action interface class
269  * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
270  */
271 class NetworkAction : public Action {
272 public:
273   /**
274    * @brief NetworkAction constructor
275    * 
276    * @param model The NetworkModel associated to this NetworkAction
277    * @param cost The cost of this  NetworkAction in [TODO]
278    * @param failed [description]
279    */
280   NetworkAction(ModelPtr model, double cost, bool failed)
281   : Action(model, cost, failed) {}
282
283   /**
284    * @brief NetworkAction constructor
285    * 
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
290    */
291   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
292   : Action(model, cost, failed, var) {};
293
294   void setState(e_surf_action_state_t state);
295
296 #ifdef HAVE_LATENCY_BOUND_TRACKING
297   /**
298    * @brief Check if the action is limited by latency.
299    *
300    * @return 1 if action is limited by latency, 0 otherwise
301    */
302   virtual int getLatencyLimited() {return m_latencyLimited;}
303 #endif
304
305   double m_latency;
306   double m_latCurrent;
307   double m_weight;
308   double m_rate;
309   const char* p_senderLinkName;
310   double m_senderGap;
311   double m_senderSize;
312   xbt_fifo_item_t p_senderFifoItem;
313 #ifdef HAVE_LATENCY_BOUND_TRACKING
314   int m_latencyLimited;
315 #endif
316
317 };
318
319 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
320
321