Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add "attach" attribute to storage tag in platform description
[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 Function pointer to the function to use to solve the lmm_system_t
138    * 
139    * @param system The lmm_system_t to solve
140    */
141   void (*f_networkSolve)(lmm_system_t);
142
143   /**
144    * @brief [brief description]
145    * @details [long description]
146    * 
147    * @param size [description]
148    * @return [description]
149    */
150   virtual double latencyFactor(double size);
151
152   /**
153    * @brief [brief description]
154    * @details [long description]
155    * 
156    * @param size [description]
157    * @return [description]
158    */
159   virtual double bandwidthFactor(double size);
160
161   /**
162    * @brief [brief description]
163    * @details [long description]
164    * 
165    * @param rate [description]
166    * @param bound [description]
167    * @param size [description]
168    * @return [description]
169    */
170   virtual double bandwidthConstraint(double rate, double bound, double size);
171   bool m_haveGap;
172 };
173
174 /************
175  * Resource *
176  ************/
177  /** @ingroup SURF_network_interface
178   * @brief SURF network link interface class
179   * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
180   */
181 class NetworkLink : public Resource {
182 public:
183   /**
184    * @brief NetworkLink constructor
185    * 
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
189    */
190   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
191
192   /**
193    * @brief NetworkLink constructor
194    * 
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]
201    */
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);
206
207   /**
208    * @brief NetworkLink destructor
209    */
210   ~NetworkLink();
211
212   /**
213    * @brief Get the bandwidth in bytes per second of current NetworkLink
214    * 
215    * @return The bandwith in bytes per second of the current NetworkLink
216    */
217   virtual double getBandwidth();
218
219   /**
220    * @brief Get the latency in seconds of current NetworkLink
221    * 
222    * @return The latency in seconds of the current NetworkLink
223    */
224   virtual double getLatency();
225
226   /**
227    * @brief Check if the NetworkLink is shared
228    * @details [long description]
229    * 
230    * @return true if the current NetwokrLink is shared, false otherwise
231    */
232   virtual bool isShared();
233
234   /**
235    * @brief Check if the NetworkLink is used
236    * 
237    * @return true if the current NetwokrLink is used, false otherwise
238    */
239   bool isUsed();
240
241   void setState(e_surf_resource_state_t state);
242
243   /* Using this object with the public part of
244     model does not make sense */
245   double m_latCurrent;
246   tmgr_trace_event_t p_latEvent;
247
248   /* LMM */
249   tmgr_trace_event_t p_stateEvent;
250   s_surf_metric_t p_power;
251 };
252
253 /**********
254  * Action *
255  **********/
256 /** @ingroup SURF_network_interface
257  * @brief SURF network action interface class
258  * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
259  */
260 class NetworkAction : public Action {
261 public:
262   /**
263    * @brief NetworkAction constructor
264    * 
265    * @param model The NetworkModel associated to this NetworkAction
266    * @param cost The cost of this  NetworkAction in [TODO]
267    * @param failed [description]
268    */
269   NetworkAction(ModelPtr model, double cost, bool failed)
270   : Action(model, cost, failed) {}
271
272   /**
273    * @brief NetworkAction constructor
274    * 
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
279    */
280   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
281   : Action(model, cost, failed, var) {};
282
283   void setState(e_surf_action_state_t state);
284
285 #ifdef HAVE_LATENCY_BOUND_TRACKING
286   /**
287    * @brief Check if the action is limited by latency.
288    *
289    * @return 1 if action is limited by latency, 0 otherwise
290    */
291   virtual int getLatencyLimited() {return m_latencyLimited;}
292 #endif
293
294   double m_latency;
295   double m_latCurrent;
296   double m_weight;
297   double m_rate;
298   const char* p_senderLinkName;
299   double m_senderGap;
300   double m_senderSize;
301   xbt_fifo_item_t p_senderFifoItem;
302 #ifdef HAVE_LATENCY_BOUND_TRACKING
303   int m_latencyLimited;
304 #endif
305
306 };
307
308 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
309
310