1 /* Copyright (c) 2013-2020. 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. */
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Link.hpp"
10 #include "simgrid/sg_config.hpp"
11 #include "simgrid/simix.hpp"
12 #include "src/kernel/lmm/maxmin.hpp"
13 #include "src/surf/network_interface.hpp"
19 xbt::signal<void(Link&)> Link::on_creation;
20 xbt::signal<void(Link const&)> Link::on_destruction;
21 xbt::signal<void(Link const&)> Link::on_state_change;
22 xbt::signal<void(Link const&)> Link::on_bandwidth_change;
23 xbt::signal<void(kernel::resource::NetworkAction&, Host* src, Host* dst)> Link::on_communicate;
24 xbt::signal<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>
25 Link::on_communication_state_change;
27 Link* Link::by_name(const std::string& name)
29 return Engine::get_instance()->link_by_name(name);
32 Link* Link::by_name_or_null(const std::string& name)
34 return Engine::get_instance()->link_by_name_or_null(name);
37 const std::string& Link::get_name() const
39 return this->pimpl_->get_name();
41 const char* Link::get_cname() const
43 return this->pimpl_->get_cname();
45 bool Link::is_used() const
47 return this->pimpl_->is_used();
50 double Link::get_latency() const
52 return this->pimpl_->get_latency();
55 double Link::get_bandwidth() const
57 return this->pimpl_->get_bandwidth();
60 Link::SharingPolicy Link::get_sharing_policy() const
62 return this->pimpl_->get_sharing_policy();
65 double Link::get_usage() const
67 return this->pimpl_->get_constraint()->get_usage();
72 simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_on(); });
76 simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_off(); });
79 bool Link::is_on() const
81 return this->pimpl_->is_on();
84 void Link::set_state_profile(kernel::profile::Profile* profile)
86 simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
88 void Link::set_bandwidth_profile(kernel::profile::Profile* profile)
90 simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); });
92 void Link::set_latency_profile(kernel::profile::Profile* trace)
94 simgrid::kernel::actor::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
97 const char* Link::get_property(const std::string& key) const
99 return this->pimpl_->get_property(key);
101 void Link::set_property(const std::string& key, const std::string& value)
103 simgrid::kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
106 } // namespace simgrid
108 /* **************************** Public C interface *************************** */
110 const char* sg_link_name(const_sg_link_t link)
112 return link->get_cname();
114 sg_link_t sg_link_by_name(const char* name)
116 return simgrid::s4u::Link::by_name(name);
119 int sg_link_is_shared(const_sg_link_t link)
121 return (int)link->get_sharing_policy();
123 double sg_link_bandwidth(const_sg_link_t link)
125 return link->get_bandwidth();
127 double sg_link_latency(const_sg_link_t link)
129 return link->get_latency();
131 void* sg_link_data(const_sg_link_t link)
133 return link->get_data();
135 void sg_link_data_set(sg_link_t link, void* data)
137 link->set_data(data);
141 return simgrid::s4u::Engine::get_instance()->get_link_count();
144 sg_link_t* sg_link_list()
146 std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
148 sg_link_t* res = xbt_new(sg_link_t, links.size());
149 memcpy(res, links.data(), sizeof(sg_link_t) * links.size());