X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7e6b08e18f46d49f5e9e5d5f19ba86d959cf09b7..4c753f8d4cabd4104f3f7109823f16be2ebdcce3:/src/s4u/s4u_Link.cpp diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index cd3b19aad9..1e1e5eb7b5 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -1,20 +1,18 @@ -/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2022. The SimGrid Team. All rights reserved. */ /* 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 +#include +#include +#include +#include +#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/surf/SplitDuplexLinkImpl.hpp" -#include "src/surf/network_interface.hpp" -#include "src/surf/network_wifi.hpp" -#include "xbt/log.h" -#include "xbt/parse_units.hpp" +#include "src/kernel/resource/LinkImpl.hpp" +#include "src/kernel/resource/SplitDuplexLinkImpl.hpp" +#include "src/kernel/resource/WifiLinkImpl.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,12 +32,14 @@ Link* Link::by_name(const std::string& name) return Engine::get_instance()->link_by_name(name); } -kernel::resource::LinkImpl* Link::get_impl() const +kernel::resource::StandardLinkImpl* Link::get_impl() const { - xbt_assert( - get_sharing_policy() != SharingPolicy::SPLITDUPLEX, - "Impossible to get a LinkImpl* from a Split-Duplex link. You should call this method to each UP/DOWN member"); - return dynamic_cast(pimpl_); + 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) @@ -73,7 +72,7 @@ double Link::get_latency() const Link* Link::set_latency(double value) { - kernel::actor::simcall([this, value] { pimpl_->set_latency(value); }); + kernel::actor::simcall_object_access(pimpl_, [this, value] { pimpl_->set_latency(value); }); return this; } @@ -83,8 +82,7 @@ Link* Link::set_latency(const std::string& value) try { d_value = xbt_parse_get_time("", 0, value, ""); } catch (const simgrid::ParseError&) { - throw std::invalid_argument(std::string("Impossible to set latency for link: ") + get_name() + - std::string(". Invalid value: ") + value); + throw std::invalid_argument("Impossible to set latency for link: " + get_name() + ". Invalid value: " + value); } return set_latency(d_value); } @@ -96,17 +94,17 @@ double Link::get_bandwidth() const Link* Link::set_bandwidth(double value) { - kernel::actor::simcall([this, value] { pimpl_->set_bandwidth(value); }); + kernel::actor::simcall_object_access(pimpl_, [this, value] { pimpl_->set_bandwidth(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(". Use NetZone::create_split_duplex_link.")); + if (policy == SharingPolicy::SPLITDUPLEX || policy == SharingPolicy::WIFI) + throw std::invalid_argument("Impossible to set wifi or split-duplex for the link: " + get_name() + + ". Use appropriate create function in NetZone."); - kernel::actor::simcall([this, policy] { pimpl_->set_sharing_policy(policy); }); + kernel::actor::simcall_object_access(pimpl_, [this, policy, &cb] { pimpl_->set_sharing_policy(policy, cb); }); return this; } Link::SharingPolicy Link::get_sharing_policy() const @@ -116,14 +114,14 @@ Link::SharingPolicy Link::get_sharing_policy() const void Link::set_host_wifi_rate(const s4u::Host* host, int level) const { - auto* wlink = dynamic_cast(pimpl_); + auto* wlink = dynamic_cast(pimpl_); xbt_assert(wlink != nullptr, "Link %s does not seem to be a wifi link.", get_cname()); wlink->set_host_rate(host, level); } Link* Link::set_concurrency_limit(int limit) { - kernel::actor::simcall([this, limit] { pimpl_->set_concurrency_limit(limit); }); + kernel::actor::simcall_object_access(pimpl_, [this, limit] { pimpl_->set_concurrency_limit(limit); }); return this; } @@ -134,15 +132,16 @@ double Link::get_usage() const void Link::turn_on() { - kernel::actor::simcall([this]() { this->pimpl_->turn_on(); }); + kernel::actor::simcall_answered([this]() { this->pimpl_->turn_on(); }); } void Link::turn_off() { - kernel::actor::simcall([this]() { this->pimpl_->turn_off(); }); + kernel::actor::simcall_answered([this]() { this->pimpl_->turn_off(); }); } Link* Link::seal() { - kernel::actor::simcall([this]() { this->pimpl_->seal(); }); + kernel::actor::simcall_answered([this]() { this->pimpl_->seal(); }); + s4u::Link::on_creation(*this); // notify the signal return this; } @@ -154,21 +153,21 @@ bool Link::is_on() const Link* Link::set_state_profile(kernel::profile::Profile* profile) { xbt_assert(not pimpl_->is_sealed(), "Cannot set a state profile once the Link is sealed"); - kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); }); + kernel::actor::simcall_object_access(pimpl_, [this, profile]() { this->pimpl_->set_state_profile(profile); }); return this; } Link* Link::set_bandwidth_profile(kernel::profile::Profile* profile) { xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Link is sealed"); - kernel::actor::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); }); + kernel::actor::simcall_object_access(pimpl_, [this, profile]() { this->pimpl_->set_bandwidth_profile(profile); }); return this; } Link* Link::set_latency_profile(kernel::profile::Profile* profile) { xbt_assert(not pimpl_->is_sealed(), "Cannot set a latency profile once the Link is sealed"); - kernel::actor::simcall([this, profile]() { this->pimpl_->set_latency_profile(profile); }); + kernel::actor::simcall_object_access(pimpl_, [this, profile]() { this->pimpl_->set_latency_profile(profile); }); return this; } @@ -178,7 +177,7 @@ const char* Link::get_property(const std::string& key) const } Link* Link::set_property(const std::string& key, const std::string& value) { - kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); + kernel::actor::simcall_object_access(pimpl_, [this, &key, &value] { this->pimpl_->set_property(key, value); }); return this; } @@ -189,20 +188,20 @@ const std::unordered_map* Link::get_properties() const Link* Link::set_properties(const std::unordered_map& properties) { - kernel::actor::simcall([this, &properties] { this->pimpl_->set_properties(properties); }); + kernel::actor::simcall_object_access(pimpl_, [this, &properties] { this->pimpl_->set_properties(properties); }); return this; } Link* SplitDuplexLink::get_link_up() const { - kernel::resource::SplitDuplexLinkImpl* pimpl = dynamic_cast(pimpl_); + 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 { - kernel::resource::SplitDuplexLinkImpl* pimpl = dynamic_cast(pimpl_); + 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(); } @@ -222,11 +221,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); @@ -247,16 +241,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(); @@ -267,19 +251,9 @@ 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(); + return link->get_data(); } void sg_link_set_data(sg_link_t link, void* data) @@ -287,16 +261,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();