Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ba829aace751d708460544f1f63468ceddda1f84
[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 Link;
20 typedef Link *LinkPtr;
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 Link creation
31  * @details Callback functions have the following signature: `void(LinkPtr)`
32  */
33 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr)) networkLinkCreatedCallbacks;
34
35 /** @ingroup SURF_callbacks
36  * @brief Callbacks handler which emits the callbacks after Link destruction
37  * @details Callback functions have the following signature: `void(LinkPtr)`
38  */
39 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr)) networkLinkDestructedCallbacks;
40
41 /** @ingroup SURF_callbacks
42  * @brief Callbacks handler which emits the callbacks after Link State changed
43  * @details Callback functions have the following signature: `void(LinkActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
44  */
45 XBT_PUBLIC_DATA( surf_callback(void, LinkPtr, 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   /** @brief NetworkModel constructor */
76   NetworkModel() : Model("network") {
77     f_networkSolve = lmm_solve;
78   };
79
80   /** @brief NetworkModel constructor */
81   NetworkModel(const char *name) : Model(name) {
82         f_networkSolve = lmm_solve;
83   };
84
85   /** @brief The destructor of the NetworkModel */
86   ~NetworkModel() {
87         if (p_maxminSystem)
88           lmm_system_free(p_maxminSystem);
89         if (p_actionHeap)
90           xbt_heap_free(p_actionHeap);
91         if (p_modifiedSet)
92           delete p_modifiedSet;
93   }
94
95   /**
96    * @brief Create a Link
97    *
98    * @param name The name of the Link
99    * @param bw_initial The initial bandwidth of the Link in bytes per second
100    * @param bw_trace The trace associated to the Link bandwidth
101    * @param lat_initial The initial latency of the Link in seconds
102    * @param lat_trace The trace associated to the Link latency
103    * @param state_initial The initial Link (state)[e_surf_resource_state_t]
104    * @param state_trace The trace associated to the Link (state)[e_surf_resource_state_t]
105    * @param policy The sharing policy of the Link
106    * @param properties Dictionary of properties associated to this Resource
107    * @return The created Link
108    */
109   virtual LinkPtr createLink(const char *name,
110                                    double bw_initial,
111                                    tmgr_trace_t bw_trace,
112                                    double lat_initial,
113                                    tmgr_trace_t lat_trace,
114                                    e_surf_resource_state_t state_initial,
115                                    tmgr_trace_t state_trace,
116                                    e_surf_link_sharing_policy_t policy,
117                                    xbt_dict_t properties)=0;
118
119   virtual void gapAppend(double /*size*/, const LinkPtr /*link*/, NetworkActionPtr /*action*/) {};
120
121   /**
122    * @brief Create a communication between two hosts.
123    * @details It makes calls to the routing part, and execute the communication
124    * between the two end points.
125    *
126    * @param src The source of the communication
127    * @param dst The destination of the communication
128    * @param size The size of the communication in bytes
129    * @param rate Allows to limit the transfer rate. Negative value means
130    * unlimited.
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 Get the right multiplicative factor for the latency.
145    * @details Depending on the model, the effective latency when sending
146    * a message might be different from the theoretical latency of the link,
147    * in function of the message size. In order to account for this, this
148    * function gets this factor.
149    *
150    * @param size The size of the message.
151    * @return The latency factor.
152    */
153   virtual double latencyFactor(double size);
154
155   /**
156    * @brief Get the right multiplicative factor for the bandwidth.
157    * @details Depending on the model, the effective bandwidth when sending
158    * a message might be different from the theoretical bandwidth of the link,
159    * in function of the message size. In order to account for this, this
160    * function gets this factor.
161    *
162    * @param size The size of the message.
163    * @return The bandwidth factor.
164    */
165   virtual double bandwidthFactor(double size);
166
167   /**
168    * @brief Get definitive bandwidth.
169    * @details It gives the minimum bandwidth between the one that would
170    * occur if no limitation was enforced, and the one arbitrary limited.
171    * @param rate The desired maximum bandwidth.
172    * @param bound The bandwidth with only the network taken into account.
173    * @param size The size of the message.
174    * @return The new bandwidth.
175    */
176   virtual double bandwidthConstraint(double rate, double bound, double size);
177   double shareResourcesFull(double now);
178   bool m_haveGap = false;
179 };
180
181 /************
182  * Resource *
183  ************/
184  /** @ingroup SURF_network_interface
185   * @brief SURF network link interface class
186   * @details A Link represents the link between two [hosts](\ref Host)
187   */
188 class Link : public Resource {
189 public:
190   /**
191    * @brief Link constructor
192    *
193    * @param model The NetworkModel associated to this Link
194    * @param name The name of the Link
195    * @param props Dictionary of properties associated to this Link
196    */
197   Link(NetworkModelPtr model, const char *name, xbt_dict_t props);
198
199   /**
200    * @brief Link constructor
201    *
202    * @param model The NetworkModel associated to this Link
203    * @param name The name of the Link
204    * @param props Dictionary of properties associated to this Link
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   Link(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   /** @brief Link destructor */
215   ~Link();
216
217   /** @brief Get the bandwidth in bytes per second of current Link */
218   virtual double getBandwidth();
219
220   /** @brief Update the bandwidth in bytes per second of current Link */
221   virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
222
223   /** @brief Get the latency in seconds of current Link */
224   virtual double getLatency();
225
226   /** @brief Update the latency in seconds of current Link */
227   virtual void updateLatency(double value, double date=surf_get_clock())=0;
228
229   /**
230    * @brief Check if the Link is shared
231    *
232    * @return true if the current NetwokrLink is shared, false otherwise
233    */
234   virtual bool isShared();
235
236   /** @brief Check if the Link is used */
237   bool isUsed();
238
239   void setState(e_surf_resource_state_t state);
240
241   /* Using this object with the public part of
242     model does not make sense */
243   double m_latCurrent;
244   tmgr_trace_event_t p_latEvent;
245
246   /* LMM */
247   tmgr_trace_event_t p_stateEvent;
248   s_surf_metric_t p_power;
249 };
250
251 /**********
252  * Action *
253  **********/
254 /** @ingroup SURF_network_interface
255  * @brief SURF network action interface class
256  * @details A NetworkAction represents a communication between two [hosts](\ref Host)
257  */
258 class NetworkAction : public Action {
259 public:
260   /**
261    * @brief NetworkAction constructor
262    *
263    * @param model The NetworkModel associated to this NetworkAction
264    * @param cost The cost of this  NetworkAction in [TODO]
265    * @param failed [description]
266    */
267   NetworkAction(ModelPtr model, double cost, bool failed)
268   : Action(model, cost, failed) {}
269
270   /**
271    * @brief NetworkAction constructor
272    *
273    * @param model The NetworkModel associated to this NetworkAction
274    * @param cost The cost of this  NetworkAction in [TODO]
275    * @param failed [description]
276    * @param var The lmm variable associated to this Action if it is part of a
277    * LMM component
278    */
279   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
280   : Action(model, cost, failed, var) {};
281
282   void setState(e_surf_action_state_t state);
283
284 #ifdef HAVE_LATENCY_BOUND_TRACKING
285   /**
286    * @brief Check if the action is limited by latency.
287    *
288    * @return 1 if action is limited by latency, 0 otherwise
289    */
290   virtual int getLatencyLimited() {return m_latencyLimited;}
291 #endif
292
293   double m_latency;
294   double m_latCurrent;
295   double m_weight;
296   double m_rate;
297   const char* p_senderLinkName;
298   double m_senderGap;
299   double m_senderSize;
300   xbt_fifo_item_t p_senderFifoItem;
301 #ifdef HAVE_LATENCY_BOUND_TRACKING
302   int m_latencyLimited;
303 #endif
304
305 };
306
307 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
308
309