Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill dead code
[simgrid.git] / src / surf / network_interface.hpp
1 /* Copyright (c) 2004-2015. 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 #ifndef SURF_NETWORK_INTERFACE_HPP_
8 #define SURF_NETWORK_INTERFACE_HPP_
9
10 #include <xbt/base.h>
11
12 #include <boost/unordered_map.hpp>
13
14 #include "xbt/fifo.h"
15 #include "xbt/dict.h"
16 #include "surf_interface.hpp"
17 #include "surf_routing.hpp"
18
19 #include "simgrid/link.h"
20
21 /***********
22  * Classes *
23  ***********/
24 class NetworkModel;
25 class NetworkAction;
26
27 /*************
28  * Callbacks *
29  *************/
30
31 /** @ingroup SURF_callbacks
32  * @brief Callbacks handler which emits the callbacks after Link creation
33  * @details Callback functions have the following signature: `void(Link*)`
34  */
35 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkCreatedCallbacks;
36
37 /** @ingroup SURF_callbacks
38  * @brief Callbacks handler which emits the callbacks after Link destruction
39  * @details Callback functions have the following signature: `void(Link*)`
40  */
41 XBT_PUBLIC_DATA( surf_callback(void, Link*)) networkLinkDestructedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks handler which emits the callbacks after Link State changed
45  * @details Callback functions have the following signature: `void(LinkAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
46  */
47 XBT_PUBLIC_DATA( surf_callback(void, Link*, e_surf_resource_state_t, e_surf_resource_state_t)) networkLinkStateChangedCallbacks;
48
49 /** @ingroup SURF_callbacks
50  * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
51  * @details Callback functions have the following signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
52  */
53 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)) networkActionStateChangedCallbacks;
54
55 /** @ingroup SURF_callbacks
56  * @brief Callbacks handler which emits the callbacks after communication created
57  * @details Callback functions have the following signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)`
58  */
59 XBT_PUBLIC_DATA( surf_callback(void, NetworkAction*, RoutingEdge *src, RoutingEdge *dst, double size, double rate)) networkCommunicateCallbacks;
60
61 /*********
62  * Tools *
63  *********/
64 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
65
66 XBT_PUBLIC(void) net_add_traces();
67
68 /*********
69  * Model *
70  *********/
71 /** @ingroup SURF_network_interface
72  * @brief SURF network model interface class
73  * @details A model is an object which handles the interactions between its Resources and its Actions
74  */
75 class NetworkModel : public Model {
76 public:
77   /** @brief Constructor */
78   NetworkModel() : Model() { }
79
80   /** @brief Destructor */
81   ~NetworkModel() {
82         if (p_maxminSystem)
83           lmm_system_free(p_maxminSystem);
84         if (p_actionHeap)
85           xbt_heap_free(p_actionHeap);
86         if (p_modifiedSet)
87           delete p_modifiedSet;
88   }
89
90   /**
91    * @brief Create a Link
92    *
93    * @param name The name of the Link
94    * @param bw_initial The initial bandwidth of the Link in bytes per second
95    * @param bw_trace The trace associated to the Link bandwidth
96    * @param lat_initial The initial latency of the Link in seconds
97    * @param lat_trace The trace associated to the Link latency
98    * @param state_initial The initial Link (state)[e_surf_resource_state_t]
99    * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
100    * @param policy The sharing policy of the Link
101    * @param properties Dictionary of properties associated to this Resource
102    * @return The created Link
103    */
104   virtual Link* createLink(const char *name,
105                                    double bw_initial,
106                                    tmgr_trace_t bw_trace,
107                                    double lat_initial,
108                                    tmgr_trace_t lat_trace,
109                                    e_surf_resource_state_t state_initial,
110                                    tmgr_trace_t state_trace,
111                                    e_surf_link_sharing_policy_t policy,
112                                    xbt_dict_t properties)=0;
113
114   virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {};
115
116   /**
117    * @brief Create a communication between two hosts.
118    * @details It makes calls to the routing part, and execute the communication
119    * between the two end points.
120    *
121    * @param src The source of the communication
122    * @param dst The destination of the communication
123    * @param size The size of the communication in bytes
124    * @param rate Allows to limit the transfer rate. Negative value means
125    * unlimited.
126    * @return The action representing the communication
127    */
128   virtual Action *communicate(RoutingEdge *src, RoutingEdge *dst,
129                                            double size, double rate)=0;
130
131   /** @brief Function pointer to the function to use to solve the lmm_system_t
132    *
133    * @param system The lmm_system_t to solve
134    */
135   void (*f_networkSolve)(lmm_system_t) = lmm_solve;
136
137   /**
138    * @brief Get the right multiplicative factor for the latency.
139    * @details Depending on the model, the effective latency when sending
140    * a message might be different from the theoretical latency of the link,
141    * in function of the message size. In order to account for this, this
142    * function gets this factor.
143    *
144    * @param size The size of the message.
145    * @return The latency factor.
146    */
147   virtual double latencyFactor(double size);
148
149   /**
150    * @brief Get the right multiplicative factor for the bandwidth.
151    * @details Depending on the model, the effective bandwidth when sending
152    * a message might be different from the theoretical bandwidth of the link,
153    * in function of the message size. In order to account for this, this
154    * function gets this factor.
155    *
156    * @param size The size of the message.
157    * @return The bandwidth factor.
158    */
159   virtual double bandwidthFactor(double size);
160
161   /**
162    * @brief Get definitive bandwidth.
163    * @details It gives the minimum bandwidth between the one that would
164    * occur if no limitation was enforced, and the one arbitrary limited.
165    * @param rate The desired maximum bandwidth.
166    * @param bound The bandwidth with only the network taken into account.
167    * @param size The size of the message.
168    * @return The new bandwidth.
169    */
170   virtual double bandwidthConstraint(double rate, double bound, double size);
171   double shareResourcesFull(double now);
172   bool m_haveGap = false;
173 };
174
175 /************
176  * Resource *
177  ************/
178  /** @ingroup SURF_network_interface
179   * @brief SURF network link interface class
180   * @details A Link represents the link between two [hosts](\ref Host)
181   */
182 class Link : public Resource {
183 public:
184   /**
185    * @brief Link constructor
186    *
187    * @param model The NetworkModel associated to this Link
188    * @param name The name of the Link
189    * @param props Dictionary of properties associated to this Link
190    */
191   Link(NetworkModel *model, const char *name, xbt_dict_t props);
192
193   /**
194    * @brief Link constructor
195    *
196    * @param model The NetworkModel associated to this Link
197    * @param name The name of the Link
198    * @param props Dictionary of properties associated to this Link
199    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
200    * @param history [TODO]
201    * @param state_trace [TODO]
202    */
203   Link(NetworkModel *model, const char *name, xbt_dict_t props,
204               lmm_constraint_t constraint,
205               tmgr_history_t history,
206               tmgr_trace_t state_trace);
207
208   /** @brief Link destructor */
209   ~Link();
210
211   /** @brief Get the bandwidth in bytes per second of current Link */
212   virtual double getBandwidth();
213
214   /** @brief Update the bandwidth in bytes per second of current Link */
215   virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
216
217   /** @brief Get the latency in seconds of current Link */
218   virtual double getLatency();
219
220   /** @brief Update the latency in seconds of current Link */
221   virtual void updateLatency(double value, double date=surf_get_clock())=0;
222
223   /**
224    * @brief Check if the Link is shared
225    *
226    * @return true if the current NetwokrLink is shared, false otherwise
227    */
228   virtual bool isShared();
229
230   /** @brief Check if the Link is used */
231   bool isUsed();
232
233   void setState(e_surf_resource_state_t state);
234
235   /* Using this object with the public part of
236     model does not make sense */
237   double m_latCurrent;
238   tmgr_trace_event_t p_latEvent;
239
240   /* LMM */
241   tmgr_trace_event_t p_stateEvent = NULL;
242   s_surf_metric_t p_power;
243
244   /* User data */
245 public:
246   void *getData()        { return userData;}
247   void  setData(void *d) { userData=d;}
248 private:
249   void *userData = NULL;
250
251   /* List of all links */
252 private:
253   static boost::unordered_map<std::string, Link *> *links;
254 public:
255   static Link *byName(const char* name);
256   static int linksAmount();
257   static Link **linksList();
258   static void linksExit();
259 };
260
261 /**********
262  * Action *
263  **********/
264 /** @ingroup SURF_network_interface
265  * @brief SURF network action interface class
266  * @details A NetworkAction represents a communication between two [hosts](\ref Host)
267  */
268 class NetworkAction : public Action {
269 public:
270   /** @brief Constructor
271    *
272    * @param model The NetworkModel associated to this NetworkAction
273    * @param cost The cost of this  NetworkAction in [TODO]
274    * @param failed [description]
275    */
276   NetworkAction(Model *model, double cost, bool failed)
277   : Action(model, cost, failed) {}
278
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    * @param var The lmm variable associated to this Action if it is part of a
286    * LMM component
287    */
288   NetworkAction(Model *model, double cost, bool failed, lmm_variable_t var)
289   : Action(model, cost, failed, var) {};
290
291   void setState(e_surf_action_state_t state);
292
293 #ifdef HAVE_LATENCY_BOUND_TRACKING
294   /**
295    * @brief Check if the action is limited by latency.
296    *
297    * @return 1 if action is limited by latency, 0 otherwise
298    */
299   virtual int getLatencyLimited() {return m_latencyLimited;}
300 #endif
301
302   double m_latency;
303   double m_latCurrent;
304   double m_weight;
305   double m_rate;
306   const char* p_senderLinkName;
307   double m_senderGap;
308   double m_senderSize;
309   xbt_fifo_item_t p_senderFifoItem;
310 #ifdef HAVE_LATENCY_BOUND_TRACKING
311   int m_latencyLimited;
312 #endif
313
314 };
315
316 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
317
318