Logo AND Algorithmique Numérique Distribuée

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