Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Replace the override word with MC_OVERRIDE
[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 #include "xbt/fifo.h"
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 emits the callbacks after NetworkLink creation
31  * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
32  */
33 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkCreatedCallbacks;
34
35 /** @ingroup SURF_callbacks
36  * @brief Callbacks handler which emits the callbacks after NetworkLink destruction
37  * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
38  */
39 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkDestructedCallbacks;
40
41 /** @ingroup SURF_callbacks
42  * @brief Callbacks handler which emits 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 XBT_PUBLIC_DATA( 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 emits 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 XBT_PUBLIC_DATA( 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 emits 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 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)) networkCommunicateCallbacks;
58
59 /*********
60  * Tools *
61  *********/
62 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
63
64 XBT_PUBLIC(void) net_add_traces();
65
66 /*********
67  * Model *
68  *********/
69 /** @ingroup SURF_network_interface
70  * @brief SURF network model interface class
71  * @details A model is an object which handles the interactions between its Resources and its Actions
72  */
73 class NetworkModel : public Model {
74 public:
75   /**
76    * @brief NetworkModel constructor
77    */
78   NetworkModel() : Model("network") {
79     f_networkSolve = lmm_solve;
80   };
81
82   /**
83    * @brief NetworkModel constructor
84    *
85    * @param name The name of the NetworkModel
86    */
87   NetworkModel(const char *name) : Model(name) {
88         f_networkSolve = lmm_solve;
89         m_haveGap = false;
90   };
91
92   /**
93    * @brief The destructor of the NetworkModel
94    */
95   ~NetworkModel() {
96         if (p_maxminSystem)
97           lmm_system_free(p_maxminSystem);
98         if (p_actionHeap)
99           xbt_heap_free(p_actionHeap);
100         if (p_modifiedSet)
101           delete p_modifiedSet;
102   }
103
104   /**
105    * @brief Create a NetworkLink
106    *
107    * @param name The name of the NetworkLink
108    * @param bw_initial The initial bandwidth of the NetworkLink in bytes per second
109    * @param bw_trace The trace associated to the NetworkLink bandwidth
110    * @param lat_initial The initial latency of the NetworkLink in seconds
111    * @param lat_trace The trace associated to the NetworkLink latency
112    * @param state_initial The initial NetworkLink (state)[e_surf_resource_state_t]
113    * @param state_trace The trace associated to the NetworkLink (state)[e_surf_resource_state_t]
114    * @param policy The sharing policy of the NetworkLink
115    * @param properties Dictionary of properties associated to this Resource
116    * @return The created NetworkLink
117    */
118   virtual NetworkLinkPtr createNetworkLink(const char *name,
119                                    double bw_initial,
120                                    tmgr_trace_t bw_trace,
121                                    double lat_initial,
122                                    tmgr_trace_t lat_trace,
123                                    e_surf_resource_state_t state_initial,
124                                    tmgr_trace_t state_trace,
125                                    e_surf_link_sharing_policy_t policy,
126                                    xbt_dict_t properties)=0;
127
128   virtual void gapAppend(double /*size*/, const NetworkLinkPtr /*link*/, NetworkActionPtr /*action*/) {};
129
130   /**
131    * @brief Create a communication between two workstations.
132    * @details It makes calls to the routing part, and execute the communication
133    * between the two end points.
134    *
135    * @param src The source of the communication
136    * @param dst The destination of the communication
137    * @param size The size of the communication in bytes
138    * @param rate Allows to limit the transfer rate. Negative value means
139    * unlimited.
140    * @return The action representing the communication
141    */
142   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
143                                            double size, double rate)=0;
144
145   /**
146    * @brief Function pointer to the function to use to solve the lmm_system_t
147    *
148    * @param system The lmm_system_t to solve
149    */
150   void (*f_networkSolve)(lmm_system_t);
151
152   /**
153    * @brief Get the right multiplicative factor for the latency.
154    * @details Depending on the model, the effective latency when sending
155    * a message might be different from the theoretical latency of the link,
156    * in function of the message size. In order to account for this, this
157    * function gets this factor.
158    *
159    * @param size The size of the message.
160    * @return The latency factor.
161    */
162   virtual double latencyFactor(double size);
163
164   /**
165    * @brief Get the right multiplicative factor for the bandwidth.
166    * @details Depending on the model, the effective bandwidth when sending
167    * a message might be different from the theoretical bandwidth of the link,
168    * in function of the message size. In order to account for this, this
169    * function gets this factor.
170    *
171    * @param size The size of the message.
172    * @return The bandwidth factor.
173    */
174   virtual double bandwidthFactor(double size);
175
176   /**
177    * @brief Get definitive bandwidth.
178    * @details It gives the minimum bandwidth between the one that would
179    * occur if no limitation was enforced, and the one arbitrary limited.
180    * @param rate The desired maximum bandwidth.
181    * @param bound The bandwidth with only the network taken into account.
182    * @param size The size of the message.
183    * @return The new bandwidth.
184    */
185   virtual double bandwidthConstraint(double rate, double bound, double size);
186   double shareResourcesFull(double now);
187   bool m_haveGap;
188 };
189
190 /************
191  * Resource *
192  ************/
193  /** @ingroup SURF_network_interface
194   * @brief SURF network link interface class
195   * @details A NetworkLink represents the link between two [Workstations](\ref Workstation)
196   */
197 class NetworkLink : public Resource {
198 public:
199   /**
200    * @brief NetworkLink constructor
201    *
202    * @param model The NetworkModel associated to this NetworkLink
203    * @param name The name of the NetworkLink
204    * @param props Dictionary of properties associated to this NetworkLink
205    */
206   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
207
208   /**
209    * @brief NetworkLink constructor
210    *
211    * @param model The NetworkModel associated to this NetworkLink
212    * @param name The name of the NetworkLink
213    * @param props Dictionary of properties associated to this NetworkLink
214    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
215    * @param history [TODO]
216    * @param state_trace [TODO]
217    */
218   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
219               lmm_constraint_t constraint,
220               tmgr_history_t history,
221               tmgr_trace_t state_trace);
222
223   /**
224    * @brief NetworkLink destructor
225    */
226   ~NetworkLink();
227
228   /**
229    * @brief Get the bandwidth in bytes per second of current NetworkLink
230    *
231    * @return The bandwith in bytes per second of the current NetworkLink
232    */
233   virtual double getBandwidth();
234
235   /**
236    * @brief Update the bandwidth in bytes per second of current NetworkLink
237    */
238   virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
239
240   /**
241    * @brief Get the latency in seconds of current NetworkLink
242    *
243    * @return The latency in seconds of the current NetworkLink
244    */
245   virtual double getLatency();
246
247   /**
248    * @brief Update the latency in seconds of current NetworkLink
249    */
250   virtual void updateLatency(double value, double date=surf_get_clock())=0;
251
252   /**
253    * @brief Check if the NetworkLink is shared
254    *
255    * @return true if the current NetwokrLink is shared, false otherwise
256    */
257   virtual bool isShared();
258
259   /**
260    * @brief Check if the NetworkLink is used
261    *
262    * @return true if the current NetwokrLink is used, false otherwise
263    */
264   bool isUsed();
265
266   void setState(e_surf_resource_state_t state);
267
268   /* Using this object with the public part of
269     model does not make sense */
270   double m_latCurrent;
271   tmgr_trace_event_t p_latEvent;
272
273   /* LMM */
274   tmgr_trace_event_t p_stateEvent;
275   s_surf_metric_t p_power;
276 };
277
278 /**********
279  * Action *
280  **********/
281 /** @ingroup SURF_network_interface
282  * @brief SURF network action interface class
283  * @details A NetworkAction represents a communication between two
284  * [Workstations](\ref Workstation)
285  */
286 class NetworkAction : public Action {
287 public:
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    */
295   NetworkAction(ModelPtr model, double cost, bool failed)
296   : Action(model, cost, failed) {}
297
298   /**
299    * @brief NetworkAction constructor
300    *
301    * @param model The NetworkModel associated to this NetworkAction
302    * @param cost The cost of this  NetworkAction in [TODO]
303    * @param failed [description]
304    * @param var The lmm variable associated to this Action if it is part of a
305    * LMM component
306    */
307   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
308   : Action(model, cost, failed, var) {};
309
310   void setState(e_surf_action_state_t state);
311
312 #ifdef HAVE_LATENCY_BOUND_TRACKING
313   /**
314    * @brief Check if the action is limited by latency.
315    *
316    * @return 1 if action is limited by latency, 0 otherwise
317    */
318   virtual int getLatencyLimited() {return m_latencyLimited;}
319 #endif
320
321   double m_latency;
322   double m_latCurrent;
323   double m_weight;
324   double m_rate;
325   const char* p_senderLinkName;
326   double m_senderGap;
327   double m_senderSize;
328   xbt_fifo_item_t p_senderFifoItem;
329 #ifdef HAVE_LATENCY_BOUND_TRACKING
330   int m_latencyLimited;
331 #endif
332
333 };
334
335 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
336
337