Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Add missing include
[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 NetworkAction;
30
31     /** @brief Callback signal fired when the state of a NetworkAction changes
32      *  Signature: `void(NetworkAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */
33     XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) networkActionStateChangedCallbacks;
34
35   }
36 }
37 /*********
38  * Model *
39  *********/
40
41 namespace simgrid {
42   namespace surf {
43
44     /** @ingroup SURF_network_interface
45      * @brief SURF network model interface class
46      * @details A model is an object which handles the interactions between its Resources and its Actions
47      */
48     class NetworkModel : public Model {
49     public:
50       /** @brief Constructor */
51       NetworkModel() : Model() { }
52
53       /** @brief Destructor */
54       ~NetworkModel() override;
55
56       /**
57        * @brief Create a Link
58        *
59        * @param name The name of the Link
60        * @param bandwidth The initial bandwidth of the Link in bytes per second
61        * @param latency The initial latency of the Link in seconds
62        * @param policy The sharing policy of the Link
63        * @param props Dictionary of properties associated to this Link
64        */
65       virtual Link* createLink(const char *name, double bandwidth, double latency,
66           e_surf_link_sharing_policy_t policy, xbt_dict_t properties)=0;
67
68       /**
69        * @brief Create a communication between two hosts.
70        * @details It makes calls to the routing part, and execute the communication
71        *          between the two end points.
72        *
73        * @param src The source of the communication
74        * @param dst The destination of the communication
75        * @param size The size of the communication in bytes
76        * @param rate Allows to limit the transfer rate. Negative value means
77        * unlimited.
78        * @return The action representing the communication
79        */
80       virtual Action *communicate(NetCard *src, NetCard *dst, double size, double rate)=0;
81
82       /** @brief Function pointer to the function to use to solve the lmm_system_t
83        *
84        * @param system The lmm_system_t to solve
85        */
86       void (*f_networkSolve)(lmm_system_t) = lmm_solve;
87
88       /**
89        * @brief Get the right multiplicative factor for the latency.
90        * @details Depending on the model, the effective latency when sending
91        * a message might be different from the theoretical latency of the link,
92        * in function of the message size. In order to account for this, this
93        * function gets this factor.
94        *
95        * @param size The size of the message.
96        * @return The latency factor.
97        */
98       virtual double latencyFactor(double size);
99
100       /**
101        * @brief Get the right multiplicative factor for the bandwidth.
102        * @details Depending on the model, the effective bandwidth when sending
103        * a message might be different from the theoretical bandwidth of the link,
104        * in function of the message size. In order to account for this, this
105        * function gets this factor.
106        *
107        * @param size The size of the message.
108        * @return The bandwidth factor.
109        */
110       virtual double bandwidthFactor(double size);
111
112       /**
113        * @brief Get definitive bandwidth.
114        * @details It gives the minimum bandwidth between the one that would
115        * occur if no limitation was enforced, and the one arbitrary limited.
116        * @param rate The desired maximum bandwidth.
117        * @param bound The bandwidth with only the network taken into account.
118        * @param size The size of the message.
119        * @return The new bandwidth.
120        */
121       virtual double bandwidthConstraint(double rate, double bound, double size);
122       double next_occuring_event_full(double now) override;
123     };
124
125     /************
126      * Resource *
127      ************/
128     /** @ingroup SURF_network_interface
129      * @brief SURF network link interface class
130      * @details A Link represents the link between two [hosts](\ref simgrid::surf::HostImpl)
131      */
132     class Link :
133         public simgrid::surf::Resource,
134         public simgrid::surf::PropertyHolder {
135         public:
136
137       /** @brief Constructor of non-LMM links */
138       Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props);
139       /** @brief Constructor of LMM links */
140       Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
141
142       /* Link destruction logic */
143       /**************************/
144         protected:
145       ~Link() override;
146         public:
147       void destroy(); // Must be called instead of the destructor
148         private:
149       bool currentlyDestroying_ = false;
150
151         public:
152       /** @brief Callback signal fired when a new Link is created.
153        *  Signature: void(Link*) */
154       static simgrid::xbt::signal<void(simgrid::surf::Link*)> onCreation;
155
156       /** @brief Callback signal fired when a Link is destroyed.
157        *  Signature: void(Link*) */
158       static simgrid::xbt::signal<void(simgrid::surf::Link*)> onDestruction;
159
160       /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off)
161        *  Signature: `void(Link*)` */
162       static simgrid::xbt::signal<void(simgrid::surf::Link*)> onStateChange;
163
164       /** @brief Callback signal fired when a communication starts
165        *  Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst)` */
166       static simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst)> onCommunicate;
167
168
169
170       /** @brief Get the bandwidth in bytes per second of current Link */
171       virtual double getBandwidth();
172
173       /** @brief Update the bandwidth in bytes per second of current Link */
174       virtual void updateBandwidth(double value)=0;
175
176       /** @brief Get the latency in seconds of current Link */
177       virtual double getLatency();
178
179       /** @brief Update the latency in seconds of current Link */
180       virtual void updateLatency(double value)=0;
181
182       /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
183       virtual int sharingPolicy();
184
185       /** @brief Check if the Link is used */
186       bool isUsed() override;
187
188       void turnOn() override;
189       void turnOff() override;
190
191       virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain boolean values. */
192       virtual void setBandwidthTrace(tmgr_trace_t trace); /*< setup the trace file with bandwidth events (peak speed changes due to external load). Trace must contain percentages (value between 0 and 1). */
193       virtual void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to external load). Trace must contain absolute values */
194
195       tmgr_trace_iterator_t m_stateEvent = NULL;
196       s_surf_metric_t m_latency = {1.0,0,NULL};
197       s_surf_metric_t m_bandwidth = {1.0,0,NULL};
198
199       /* User data */
200         public:
201       void *getData()        { return userData;}
202       void  setData(void *d) { userData=d;}
203         private:
204       void *userData = NULL;
205
206       /* List of all links */
207         private:
208       static boost::unordered_map<std::string, Link *> *links;
209         public:
210       static Link *byName(const char* name);
211       static int linksCount();
212       static Link **linksList();
213       static void linksExit();
214     };
215
216     /**********
217      * Action *
218      **********/
219     /** @ingroup SURF_network_interface
220      * @brief SURF network action interface class
221      * @details A NetworkAction represents a communication between two [hosts](\ref HostImpl)
222      */
223     class NetworkAction : public simgrid::surf::Action {
224     public:
225       /** @brief Constructor
226        *
227        * @param model The NetworkModel associated to this NetworkAction
228        * @param cost The cost of this  NetworkAction in [TODO]
229        * @param failed [description]
230        */
231       NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
232     : simgrid::surf::Action(model, cost, failed) {}
233
234       /**
235        * @brief NetworkAction constructor
236        *
237        * @param model The NetworkModel associated to this NetworkAction
238        * @param cost The cost of this  NetworkAction in [TODO]
239        * @param failed [description]
240        * @param var The lmm variable associated to this Action if it is part of a
241        * LMM component
242        */
243       NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
244       : simgrid::surf::Action(model, cost, failed, var) {};
245
246       void setState(simgrid::surf::Action::State state) override;
247
248       double latency_;
249       double latCurrent_;
250       double weight_;
251       double rate_;
252       const char* senderLinkName_;
253       double senderSize_;
254       xbt_fifo_item_t senderFifoItem_;
255     };
256   }
257 }
258
259 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
260
261