Logo AND Algorithmique Numérique Distribuée

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