1 /* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "network_interface.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/sg_config.hpp"
9 #include "src/kernel/resource/profile/Profile.hpp"
10 #include "src/surf/surf_interface.hpp"
11 #include "surf/surf.hpp"
15 #ifndef NETWORK_INTERFACE_CPP_
16 #define NETWORK_INTERFACE_CPP_
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, that fuel communications");
28 /** @brief Command-line option 'network/TCP-gamma' -- see @ref options_model_network_gamma */
29 config::Flag<double> NetworkModel::cfg_tcp_gamma(
31 "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; "
32 "Use the last given value, which is the max window size)",
35 /** @brief Command-line option 'network/crosstraffic' -- see @ref options_model_network_crosstraffic */
36 config::Flag<bool> NetworkModel::cfg_crosstraffic(
37 "network/crosstraffic",
38 "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)", "yes");
40 NetworkModel::~NetworkModel() = default;
42 double NetworkModel::next_occurring_event_full(double now)
44 double minRes = Model::next_occurring_event_full(now);
46 for (Action const& action : *get_started_action_set()) {
47 const auto& net_action = static_cast<const NetworkAction&>(action);
48 if (net_action.latency_ > 0)
49 minRes = (minRes < 0) ? net_action.latency_ : std::min(minRes, net_action.latency_);
52 XBT_DEBUG("Min of share resources %f", minRes);
61 void NetworkAction::set_state(Action::State state)
63 Action::State previous = get_state();
64 if (previous != state) { // Trigger only if the state changed
65 Action::set_state(state);
66 s4u::Link::on_communication_state_change(*this, previous);
70 /** @brief returns a list of all Links that this action is using */
71 std::list<LinkImpl*> NetworkAction::get_links() const
73 std::list<LinkImpl*> retlist;
74 int llen = get_variable()->get_number_of_constraint();
76 for (int i = 0; i < llen; i++) {
77 /* Beware of composite actions: ptasks put links and cpus together */
78 if (auto* link = dynamic_cast<LinkImpl*>(get_variable()->get_constraint(i)->get_id()))
79 retlist.push_back(link);
85 static void add_latency(const std::vector<LinkImpl*>& links, double* latency)
88 *latency = std::accumulate(begin(links), end(links), *latency,
89 [](double lat, const auto* link) { return lat + link->get_latency(); });
92 void add_link_latency(std::vector<LinkImpl*>& result, LinkImpl* link, double* latency)
94 result.push_back(link);
96 *latency += link->get_latency();
99 void add_link_latency(std::vector<LinkImpl*>& result, const std::vector<LinkImpl*>& links, double* latency)
101 result.insert(result.end(), begin(links), end(links));
102 add_latency(links, latency);
105 void insert_link_latency(std::vector<LinkImpl*>& result, const std::vector<LinkImpl*>& links, double* latency)
107 result.insert(result.begin(), rbegin(links), rend(links));
108 add_latency(links, latency);
111 } // namespace resource
112 } // namespace kernel
113 } // namespace simgrid
115 #endif /* NETWORK_INTERFACE_CPP_ */