Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add limiter and loopback link support in fat trees
[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 /***********
15  * Classes *
16  ***********/
17 class NetworkModel;
18 typedef NetworkModel *NetworkModelPtr;
19
20 class NetworkLink;
21 typedef NetworkLink *NetworkLinkPtr;
22
23 class NetworkAction;
24 typedef NetworkAction *NetworkActionPtr;
25
26 /*************
27  * Callbacks *
28  *************/
29
30 /** @ingroup SURF_callbacks
31  * @brief Callbacks handler which emit the callbacks after NetworkLink creation
32  * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
33  */
34 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkCreatedCallbacks;
35
36 /** @ingroup SURF_callbacks
37  * @brief Callbacks handler which emit the callbacks after NetworkLink destruction
38  * @details Callback functions have the following signature: `void(NetworkLinkPtr)`
39  */
40 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr)) networkLinkDestructedCallbacks;
41
42 /** @ingroup SURF_callbacks
43  * @brief Callbacks handler which emit the callbacks after NetworkLink State changed
44  * @details Callback functions have the following signature: `void(NetworkLinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45  */
46 XBT_PUBLIC_DATA( surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
47
48 /** @ingroup SURF_callbacks
49  * @brief Callbacks handler which emit the callbacks after NetworkAction State changed
50  * @details Callback functions have the following signature: `void(NetworkActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
51  */
52 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
53
54 /** @ingroup SURF_callbacks
55  * @brief Callbacks handler which emit the callbacks after communication created
56  * @details Callback functions have the following signature: `void(NetworkActionPtr action, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)`
57  */
58 XBT_PUBLIC_DATA( surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)) networkCommunicateCallbacks;
59
60 /*********
61  * Tools *
62  *********/
63 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
64
65 XBT_PUBLIC(void) net_add_traces();
66
67 /*********
68  * Model *
69  *********/
70 /** @ingroup SURF_network_interface
71  * @brief SURF network model interface class
72  * @details A model is an object which handle the interactions between its Resources and its Actions
73  */
74 class NetworkModel : public Model {
75 public:
76   /**
77    * @brief NetworkModel constructor
78    */
79   NetworkModel() : Model("network") {
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 [TODO]
110    * @param lat_initial The initial latency of the NetworkLink in seconds
111    * @param lat_trace The trace associated to the NetworkLink latency [TODO]
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] [TODO]
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 [TODO]
132    * @details [TODO]
133    *
134    * @param src The source [TODO]
135    * @param dst The destination [TODO]
136    * @param size The size of the communication in bytes
137    * @param rate The
138    * @return The action representing the communication
139    */
140   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
141                                            double size, double rate)=0;
142
143   /**
144    * @brief Function pointer to the function to use to solve the lmm_system_t
145    *
146    * @param system The lmm_system_t to solve
147    */
148   void (*f_networkSolve)(lmm_system_t);
149
150   /**
151    * @brief [brief description]
152    * @details [long description]
153    *
154    * @param size [description]
155    * @return [description]
156    */
157   virtual double latencyFactor(double size);
158
159   /**
160    * @brief [brief description]
161    * @details [long description]
162    *
163    * @param size [description]
164    * @return [description]
165    */
166   virtual double bandwidthFactor(double size);
167
168   /**
169    * @brief [brief description]
170    * @details [long description]
171    *
172    * @param rate [description]
173    * @param bound [description]
174    * @param size [description]
175    * @return [description]
176    */
177   virtual double bandwidthConstraint(double rate, double bound, double size);
178   bool m_haveGap;
179 };
180
181 /************
182  * Resource *
183  ************/
184  /** @ingroup SURF_network_interface
185   * @brief SURF network link interface class
186   * @details A NetworkLink represent the link between two [Workstations](\ref Workstation)
187   */
188 class NetworkLink : public Resource {
189 public:
190   /**
191    * @brief NetworkLink constructor
192    *
193    * @param model The CpuModel associated to this NetworkLink
194    * @param name The name of the NetworkLink
195    * @param props Dictionary of properties associated to this NetworkLink
196    */
197   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props);
198
199   /**
200    * @brief NetworkLink constructor
201    *
202    * @param model The CpuModel associated to this NetworkLink
203    * @param name The name of the NetworkLink
204    * @param props Dictionary of properties associated to this NetworkLink
205    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
206    * @param history [TODO]
207    * @param state_trace [TODO]
208    */
209   NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
210                       lmm_constraint_t constraint,
211                   tmgr_history_t history,
212                   tmgr_trace_t state_trace);
213
214   /**
215    * @brief NetworkLink destructor
216    */
217   ~NetworkLink();
218
219   /**
220    * @brief Get the bandwidth in bytes per second of current NetworkLink
221    *
222    * @return The bandwith in bytes per second of the current NetworkLink
223    */
224   virtual double getBandwidth();
225
226   /**
227    * @brief Update the bandwidth in bytes per second of current NetworkLink
228    */
229   virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
230
231   /**
232    * @brief Get the latency in seconds of current NetworkLink
233    *
234    * @return The latency in seconds of the current NetworkLink
235    */
236   virtual double getLatency();
237
238   /**
239    * @brief Update the latency in seconds of current NetworkLink
240    */
241   virtual void updateLatency(double value, double date=surf_get_clock())=0;
242
243   /**
244    * @brief Check if the NetworkLink is shared
245    * @details [long description]
246    *
247    * @return true if the current NetwokrLink is shared, false otherwise
248    */
249   virtual bool isShared();
250
251   /**
252    * @brief Check if the NetworkLink is used
253    *
254    * @return true if the current NetwokrLink is used, false otherwise
255    */
256   bool isUsed();
257
258   void setState(e_surf_resource_state_t state);
259
260   /* Using this object with the public part of
261     model does not make sense */
262   double m_latCurrent;
263   tmgr_trace_event_t p_latEvent;
264
265   /* LMM */
266   tmgr_trace_event_t p_stateEvent;
267   s_surf_metric_t p_power;
268 };
269
270 /**********
271  * Action *
272  **********/
273 /** @ingroup SURF_network_interface
274  * @brief SURF network action interface class
275  * @details A NetworkAction represent a communication bettween two [Workstations](\ref Workstation)
276  */
277 class NetworkAction : public Action {
278 public:
279   /**
280    * @brief NetworkAction constructor
281    *
282    * @param model The NetworkModel associated to this NetworkAction
283    * @param cost The cost of this  NetworkAction in [TODO]
284    * @param failed [description]
285    */
286   NetworkAction(ModelPtr model, double cost, bool failed)
287   : Action(model, cost, failed) {}
288
289   /**
290    * @brief NetworkAction constructor
291    *
292    * @param model The NetworkModel associated to this NetworkAction
293    * @param cost The cost of this  NetworkAction in [TODO]
294    * @param failed [description]
295    * @param var The lmm variable associated to this Action if it is part of a LMM component
296    */
297   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
298   : Action(model, cost, failed, var) {};
299
300   void setState(e_surf_action_state_t state);
301
302 #ifdef HAVE_LATENCY_BOUND_TRACKING
303   /**
304    * @brief Check if the action is limited by latency.
305    *
306    * @return 1 if action is limited by latency, 0 otherwise
307    */
308   virtual int getLatencyLimited() {return m_latencyLimited;}
309 #endif
310
311   double m_latency;
312   double m_latCurrent;
313   double m_weight;
314   double m_rate;
315   const char* p_senderLinkName;
316   double m_senderGap;
317   double m_senderSize;
318   xbt_fifo_item_t p_senderFifoItem;
319 #ifdef HAVE_LATENCY_BOUND_TRACKING
320   int m_latencyLimited;
321 #endif
322
323 };
324
325 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
326
327