1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SURF_NETWORK_INTERFACE_HPP_
8 #define SURF_NETWORK_INTERFACE_HPP_
12 #include <boost/unordered_map.hpp>
16 #include "surf_interface.hpp"
17 #include "surf_routing.hpp"
18 #include "src/surf/PropertyHolder.hpp"
20 #include "simgrid/link.h"
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;
47 XBT_PUBLIC(void) netlink_parse_init(sg_platf_link_cbarg_t link);
56 /** @ingroup SURF_network_interface
57 * @brief SURF network model interface class
58 * @details A model is an object which handles the interactions between its Resources and its Actions
60 class NetworkModel : public Model {
62 /** @brief Constructor */
63 NetworkModel() : Model() { }
65 /** @brief Destructor */
68 lmm_system_free(maxminSystem_);
70 xbt_heap_free(actionHeap_);
75 * @brief Create a Link
77 * @param name The name of the Link
78 * @param bandwidth The initial bandwidth of the Link in bytes per second
79 * @param latency The initial latency of the Link in seconds
80 * @param policy The sharing policy of the Link
81 * @param properties Dictionary of properties associated to this Resource
82 * @return The created Link
84 virtual Link* createLink(const char *name, double bandwidth, double latency,
85 e_surf_link_sharing_policy_t policy, xbt_dict_t properties)=0;
88 * @brief Create a communication between two hosts.
89 * @details It makes calls to the routing part, and execute the communication
90 * between the two end points.
92 * @param src The source of the communication
93 * @param dst The destination of the communication
94 * @param size The size of the communication in bytes
95 * @param rate Allows to limit the transfer rate. Negative value means
97 * @return The action representing the communication
99 virtual Action *communicate(NetCard *src, NetCard *dst, double size, double rate)=0;
101 /** @brief Function pointer to the function to use to solve the lmm_system_t
103 * @param system The lmm_system_t to solve
105 void (*f_networkSolve)(lmm_system_t) = lmm_solve;
108 * @brief Get the right multiplicative factor for the latency.
109 * @details Depending on the model, the effective latency when sending
110 * a message might be different from the theoretical latency of the link,
111 * in function of the message size. In order to account for this, this
112 * function gets this factor.
114 * @param size The size of the message.
115 * @return The latency factor.
117 virtual double latencyFactor(double size);
120 * @brief Get the right multiplicative factor for the bandwidth.
121 * @details Depending on the model, the effective bandwidth when sending
122 * a message might be different from the theoretical bandwidth of the link,
123 * in function of the message size. In order to account for this, this
124 * function gets this factor.
126 * @param size The size of the message.
127 * @return The bandwidth factor.
129 virtual double bandwidthFactor(double size);
132 * @brief Get definitive bandwidth.
133 * @details It gives the minimum bandwidth between the one that would
134 * occur if no limitation was enforced, and the one arbitrary limited.
135 * @param rate The desired maximum bandwidth.
136 * @param bound The bandwidth with only the network taken into account.
137 * @param size The size of the message.
138 * @return The new bandwidth.
140 virtual double bandwidthConstraint(double rate, double bound, double size);
141 double next_occuring_event_full(double now) override;
147 /** @ingroup SURF_network_interface
148 * @brief SURF network link interface class
149 * @details A Link represents the link between two [hosts](\ref Host)
152 public simgrid::surf::Resource,
153 public simgrid::surf::PropertyHolder {
156 * @brief Link constructor
158 * @param model The NetworkModel associated to this Link
159 * @param name The name of the Link
160 * @param props Dictionary of properties associated to this Link
162 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props);
165 * @brief Link constructor
167 * @param model The NetworkModel associated to this Link
168 * @param name The name of the Link
169 * @param props Dictionary of properties associated to this Link
170 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
172 Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
174 /* Link destruction logic */
175 /**************************/
179 void destroy(); // Must be called instead of the destructor
181 bool currentlyDestroying_ = false;
184 /** @brief Callback signal fired when a new Link is created.
185 * Signature: void(Link*) */
186 static simgrid::xbt::signal<void(simgrid::surf::Link*)> onCreation;
188 /** @brief Callback signal fired when a Link is destroyed.
189 * Signature: void(Link*) */
190 static simgrid::xbt::signal<void(simgrid::surf::Link*)> onDestruction;
192 /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off)
193 * Signature: `void(Link*)` */
194 static simgrid::xbt::signal<void(simgrid::surf::Link*)> onStateChange;
196 /** @brief Callback signal fired when a communication starts
197 * Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst)` */
198 static simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst)> onCommunicate;
202 /** @brief Get the bandwidth in bytes per second of current Link */
203 virtual double getBandwidth();
205 /** @brief Update the bandwidth in bytes per second of current Link */
206 virtual void updateBandwidth(double value)=0;
208 /** @brief Get the latency in seconds of current Link */
209 virtual double getLatency();
211 /** @brief Update the latency in seconds of current Link */
212 virtual void updateLatency(double value)=0;
214 /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
215 virtual int sharingPolicy();
217 /** @brief Check if the Link is used */
218 bool isUsed() override;
220 void turnOn() override;
221 void turnOff() override;
223 virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain boolean values. */
224 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). */
225 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 */
227 tmgr_trace_iterator_t m_stateEvent = NULL;
228 s_surf_metric_t m_latency = {1.0,0,NULL};
229 s_surf_metric_t m_bandwidth = {1.0,0,NULL};
233 void *getData() { return userData;}
234 void setData(void *d) { userData=d;}
236 void *userData = NULL;
238 /* List of all links */
240 static boost::unordered_map<std::string, Link *> *links;
242 static Link *byName(const char* name);
243 static int linksCount();
244 static Link **linksList();
245 static void linksExit();
251 /** @ingroup SURF_network_interface
252 * @brief SURF network action interface class
253 * @details A NetworkAction represents a communication between two [hosts](\ref Host)
255 class NetworkAction : public simgrid::surf::Action {
257 /** @brief Constructor
259 * @param model The NetworkModel associated to this NetworkAction
260 * @param cost The cost of this NetworkAction in [TODO]
261 * @param failed [description]
263 NetworkAction(simgrid::surf::Model *model, double cost, bool failed)
264 : simgrid::surf::Action(model, cost, failed) {}
267 * @brief NetworkAction constructor
269 * @param model The NetworkModel associated to this NetworkAction
270 * @param cost The cost of this NetworkAction in [TODO]
271 * @param failed [description]
272 * @param var The lmm variable associated to this Action if it is part of a
275 NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
276 : simgrid::surf::Action(model, cost, failed, var) {};
278 void setState(simgrid::surf::Action::State state) override;
284 const char* senderLinkName_;
286 xbt_fifo_item_t senderFifoItem_;
291 #endif /* SURF_NETWORK_INTERFACE_HPP_ */