Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4942e65ee60e09fadbf37f45e4a0af8b39310b52
[simgrid.git] / src / s4u / s4u_Link.cpp
1 /* Copyright (c) 2013-2020. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <algorithm>
7
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"
14 #include "xbt/log.h"
15
16 namespace simgrid {
17
18 template class xbt::Extendable<s4u::Link>;
19
20 namespace s4u {
21
22 xbt::signal<void(Link&)> Link::on_creation;
23 xbt::signal<void(Link const&)> Link::on_destruction;
24 xbt::signal<void(Link const&)> Link::on_state_change;
25 xbt::signal<void(Link const&)> Link::on_bandwidth_change;
26 xbt::signal<void(kernel::resource::NetworkAction&, Host* src, Host* dst)> Link::on_communicate;
27 xbt::signal<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>
28     Link::on_communication_state_change;
29
30 Link* Link::by_name(const std::string& name)
31 {
32   return Engine::get_instance()->link_by_name(name);
33 }
34
35 Link* Link::by_name_or_null(const std::string& name)
36 {
37   return Engine::get_instance()->link_by_name_or_null(name);
38 }
39
40 const std::string& Link::get_name() const
41 {
42   return this->pimpl_->get_name();
43 }
44 const char* Link::get_cname() const
45 {
46   return this->pimpl_->get_cname();
47 }
48 bool Link::is_used() const
49 {
50   return this->pimpl_->is_used();
51 }
52
53 double Link::get_latency() const
54 {
55   return this->pimpl_->get_latency();
56 }
57
58 double Link::get_bandwidth() const
59 {
60   return this->pimpl_->get_bandwidth();
61 }
62
63 Link::SharingPolicy Link::get_sharing_policy() const
64 {
65   return this->pimpl_->get_sharing_policy();
66 }
67
68 double Link::get_usage() const
69 {
70   return this->pimpl_->get_constraint()->get_usage();
71 }
72
73 void Link::turn_on()
74 {
75   simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_on(); });
76 }
77 void Link::turn_off()
78 {
79   simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_off(); });
80 }
81
82 bool Link::is_on() const
83 {
84   return this->pimpl_->is_on();
85 }
86
87 void Link::set_state_profile(kernel::profile::Profile* profile)
88 {
89   simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
90 }
91 void Link::set_bandwidth_profile(kernel::profile::Profile* profile)
92 {
93   simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); });
94 }
95 void Link::set_latency_profile(kernel::profile::Profile* trace)
96 {
97   simgrid::kernel::actor::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
98 }
99
100 const char* Link::get_property(const std::string& key) const
101 {
102   return this->pimpl_->get_property(key);
103 }
104 void Link::set_property(const std::string& key, const std::string& value)
105 {
106   simgrid::kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
107 }
108 } // namespace s4u
109 } // namespace simgrid
110
111 /* **************************** Public C interface *************************** */
112
113 const char* sg_link_name(const_sg_link_t link)
114 {
115   return link->get_cname();
116 }
117 sg_link_t sg_link_by_name(const char* name)
118 {
119   return simgrid::s4u::Link::by_name(name);
120 }
121
122 int sg_link_is_shared(const_sg_link_t link)
123 {
124   return (int)link->get_sharing_policy();
125 }
126 double sg_link_bandwidth(const_sg_link_t link)
127 {
128   return link->get_bandwidth();
129 }
130 double sg_link_latency(const_sg_link_t link)
131 {
132   return link->get_latency();
133 }
134 void* sg_link_data(const_sg_link_t link)
135 {
136   return link->get_data();
137 }
138 void sg_link_data_set(sg_link_t link, void* data)
139 {
140   link->set_data(data);
141 }
142 int sg_link_count()
143 {
144   return simgrid::s4u::Engine::get_instance()->get_link_count();
145 }
146
147 sg_link_t* sg_link_list()
148 {
149   std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
150
151   sg_link_t* res = xbt_new(sg_link_t, links.size());
152   memcpy(res, links.data(), sizeof(sg_link_t) * links.size());
153
154   return res;
155 }