X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/86f0b802957d99f6262ce3336293d9b5f2e63890..7ec4bfe63855f02819ad397d3b29babf4421ea00:/src/s4u/s4u_Link.cpp diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index ba86b41b75..83919625a3 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -3,18 +3,16 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include - -#include "simgrid/Exception.hpp" -#include "simgrid/s4u/Engine.hpp" -#include "simgrid/s4u/Link.hpp" -#include "simgrid/sg_config.hpp" -#include "simgrid/simix.hpp" -#include "src/kernel/lmm/maxmin.hpp" +#include +#include +#include +#include +#include +#include + +#include "src/surf/SplitDuplexLinkImpl.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/network_wifi.hpp" -#include "xbt/log.h" -#include "xbt/parse_units.hpp" namespace simgrid { @@ -26,7 +24,6 @@ xbt::signal Link::on_creation; xbt::signal Link::on_destruction; xbt::signal Link::on_state_change; xbt::signal Link::on_bandwidth_change; -xbt::signal Link::on_communicate; xbt::signal Link::on_communication_state_change; @@ -35,6 +32,16 @@ Link* Link::by_name(const std::string& name) return Engine::get_instance()->link_by_name(name); } +kernel::resource::LinkImpl* Link::get_impl() const +{ + auto* link_impl = dynamic_cast(pimpl_); + xbt_assert(link_impl != nullptr, "Impossible to get a LinkImpl* from link. %s.", + (get_sharing_policy() == SharingPolicy::SPLITDUPLEX + ? "For a Split-Duplex link, you should call this method to each UP/DOWN member" + : "Please report this bug")); + return link_impl; +} + Link* Link::by_name_or_null(const std::string& name) { return Engine::get_instance()->link_by_name_or_null(name); @@ -92,13 +99,13 @@ Link* Link::set_bandwidth(double value) return this; } -Link* Link::set_sharing_policy(Link::SharingPolicy policy) +Link* Link::set_sharing_policy(Link::SharingPolicy policy, const NonLinearResourceCb& cb) { - if (policy == SharingPolicy::SPLITDUPLEX) - throw std::invalid_argument(std::string("Impossible to set split-duplex for the link: ") + get_name() + - std::string(". You should create a link-up and link-down to emulate this behavior")); + if (policy == SharingPolicy::SPLITDUPLEX || policy == SharingPolicy::WIFI) + throw std::invalid_argument(std::string("Impossible to set wifi or split-duplex for the link: ") + get_name() + + std::string(". Use appropriate create function in NetZone.")); - kernel::actor::simcall([this, policy] { pimpl_->set_sharing_policy(policy); }); + kernel::actor::simcall([this, policy, &cb] { pimpl_->set_sharing_policy(policy, cb); }); return this; } Link::SharingPolicy Link::get_sharing_policy() const @@ -113,6 +120,12 @@ void Link::set_host_wifi_rate(const s4u::Host* host, int level) const wlink->set_host_rate(host, level); } +Link* Link::set_concurrency_limit(int limit) +{ + kernel::actor::simcall([this, limit] { pimpl_->set_concurrency_limit(limit); }); + return this; +} + double Link::get_usage() const { return this->pimpl_->get_constraint()->get_usage(); @@ -129,6 +142,7 @@ void Link::turn_off() Link* Link::seal() { kernel::actor::simcall([this]() { this->pimpl_->seal(); }); + s4u::Link::on_creation(*this); // notify the signal return this; } @@ -179,6 +193,25 @@ Link* Link::set_properties(const std::unordered_map& p return this; } +Link* SplitDuplexLink::get_link_up() const +{ + const auto* pimpl = dynamic_cast(pimpl_); + xbt_assert(pimpl, "Requesting link_up from a non split-duplex link: %s", get_cname()); + return pimpl->get_link_up(); +} + +Link* SplitDuplexLink::get_link_down() const +{ + const auto* pimpl = dynamic_cast(pimpl_); + xbt_assert(pimpl, "Requesting link_down from a non split-duplex link: %s", get_cname()); + return pimpl->get_link_down(); +} + +SplitDuplexLink* SplitDuplexLink::by_name(const std::string& name) +{ + return Engine::get_instance()->split_duplex_link_by_name(name); +} + } // namespace s4u } // namespace simgrid @@ -189,11 +222,6 @@ const char* sg_link_get_name(const_sg_link_t link) return link->get_cname(); } -const char* sg_link_name(const_sg_link_t link) // XBT_ATTRIB_DEPRECATED_v330 -{ - return sg_link_get_name(link); -} - sg_link_t sg_link_by_name(const char* name) { return simgrid::s4u::Link::by_name(name); @@ -214,16 +242,6 @@ void sg_link_set_bandwidth(sg_link_t link, double value) link->set_bandwidth(value); } -double sg_link_bandwidth(const_sg_link_t link) // XBT_ATTRIB_DEPRECATED_v330 -{ - return sg_link_get_bandwidth(link); -} - -void sg_link_bandwidth_set(sg_link_t link, double value) // XBT_ATTRIB_DEPRECATED_v330 -{ - sg_link_set_bandwidth(link, value); -} - double sg_link_get_latency(const_sg_link_t link) { return link->get_latency(); @@ -234,16 +252,6 @@ void sg_link_set_latency(sg_link_t link, double value) link->set_latency(value); } -double sg_link_latency(const_sg_link_t link) // XBT_ATTRIB_DEPRECATED_v330 -{ - return sg_link_get_latency(link); -} - -void sg_link_latency_set(sg_link_t link, double value) // XBT_ATTRIB_DEPRECATED_v330 -{ - sg_link_set_latency(link, value); -} - void* sg_link_get_data(const_sg_link_t link) { return link->get_data(); @@ -254,16 +262,6 @@ void sg_link_set_data(sg_link_t link, void* data) link->set_data(data); } -void* sg_link_data(const_sg_link_t link) // XBT_ATTRIB_DEPRECATED_v330 -{ - return sg_link_get_data(link); -} - -void sg_link_data_set(sg_link_t link, void* data) // XBT_ATTRIB_DEPRECATED_v330 -{ - sg_link_set_data(link, data); -} - size_t sg_link_count() { return simgrid::s4u::Engine::get_instance()->get_link_count(); @@ -273,8 +271,8 @@ sg_link_t* sg_link_list() { std::vector links = simgrid::s4u::Engine::get_instance()->get_all_links(); - sg_link_t* res = xbt_new(sg_link_t, links.size()); - memcpy(res, links.data(), sizeof(sg_link_t) * links.size()); + auto* res = xbt_new(sg_link_t, links.size()); + std::copy(begin(links), end(links), res); return res; }