#include "src/surf/surf_interface.hpp"
#include "surf/surf.hpp"
+#include <numeric>
+
#ifndef NETWORK_INTERFACE_CPP_
#define NETWORK_INTERFACE_CPP_
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, that fuels communications");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_network, ker_resource, "Network resources, that fuel communications");
/*********
* Model *
if (name != "__loopback__")
xbt_assert(not s4u::Link::by_name_or_null(name), "Link '%s' declared several times in the platform.", name.c_str());
- latency_.scale = 1;
- bandwidth_.scale = 1;
-
s4u::Engine::get_instance()->link_register(name, &piface_);
XBT_DEBUG("Create link '%s'", name.c_str());
}
void LinkImpl::seal()
{
+ if (is_sealed())
+ return;
+
xbt_assert(this->get_model(), "Cannot seal Link(%s) without setting the Network model first", this->get_cname());
Resource::seal();
s4u::Link::on_creation(piface_);
return retlist;
}
+
+static void add_latency(const std::vector<LinkImpl*>& links, double* latency)
+{
+ if (latency)
+ *latency = std::accumulate(begin(links), end(links), *latency,
+ [](double lat, const auto* link) { return lat + link->get_latency(); });
+}
+
+void add_link_latency(std::vector<LinkImpl*>& result, LinkImpl* link, double* latency)
+{
+ result.push_back(link);
+ if (latency)
+ *latency += link->get_latency();
+}
+
+void add_link_latency(std::vector<LinkImpl*>& result, const std::vector<LinkImpl*>& links, double* latency)
+{
+ result.insert(result.end(), begin(links), end(links));
+ add_latency(links, latency);
+}
+
+void insert_link_latency(std::vector<LinkImpl*>& result, const std::vector<LinkImpl*>& links, double* latency)
+{
+ result.insert(result.begin(), rbegin(links), rend(links));
+ add_latency(links, latency);
+}
+
} // namespace resource
} // namespace kernel
} // namespace simgrid