Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a few warnings when building doc (mostly related to doxygen).
[simgrid.git] / include / simgrid / s4u / Link.hpp
1 /* Copyright (c) 2004-2021. 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 #ifndef S4U_LINK_HPP
7 #define S4U_LINK_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/kernel/resource/Action.hpp>
11 #include <simgrid/link.h>
12 #include <string>
13 #include <unordered_map>
14 #include <xbt/Extendable.hpp>
15 #include <xbt/base.h>
16 #include <xbt/signal.hpp>
17
18 /***********
19  * Classes *
20  ***********/
21
22 namespace simgrid {
23
24 extern template class XBT_PUBLIC xbt::Extendable<s4u::Link>;
25
26 namespace s4u {
27 /**
28  * @beginrst
29  * A Link represents the network facilities between :cpp:class:`hosts <simgrid::s4u::Host>`.
30  * @endrst
31  */
32 class XBT_PUBLIC Link : public xbt::Extendable<Link> {
33 #ifndef DOXYGEN
34   friend kernel::resource::LinkImpl;
35 #endif
36
37   // Links are created from the NetZone, and destroyed by their private implementation when the simulation ends
38   explicit Link(kernel::resource::LinkImpl* pimpl) : pimpl_(pimpl) {}
39   virtual ~Link() = default;
40   // The private implementation, that never changes
41   kernel::resource::LinkImpl* const pimpl_;
42
43 public:
44   enum class SharingPolicy { WIFI = 3, SPLITDUPLEX = 2, SHARED = 1, FATPIPE = 0 };
45
46   kernel::resource::LinkImpl* get_impl() const { return pimpl_; }
47
48   /** @brief Retrieve a link from its name */
49   static Link* by_name(const std::string& name);
50   static Link* by_name_or_null(const std::string& name);
51
52   /** @brief Retrieves the name of that link as a C++ string */
53   const std::string& get_name() const;
54   /** @brief Retrieves the name of that link as a C string */
55   const char* get_cname() const;
56
57   /** Get/Set the bandwidth of the current Link (in bytes per second) */
58   double get_bandwidth() const;
59   Link* set_bandwidth(double value);
60
61   /** Get/Set the latency of the current Link (in seconds) */
62   double get_latency() const;
63   /**
64    * @brief Set link's latency
65    *
66    * @param value New latency value (in s)
67    */
68   Link* set_latency(double value);
69   /**
70    * @brief Set latency (string version)
71    *
72    * @throw std::invalid_argument if latency format is incorrect.
73    */
74   Link* set_latency(const std::string& value);
75
76   /** @brief Describes how the link is shared between flows */
77   Link* set_sharing_policy(SharingPolicy policy);
78   SharingPolicy get_sharing_policy() const;
79
80   /** Setup the profile with states events (ON or OFF). The profile must contain boolean values. */
81   Link* set_state_profile(kernel::profile::Profile* profile);
82   /** Setup the profile with bandwidth events (peak speed changes due to external load).
83    * The profile must contain percentages (value between 0 and 1). */
84   Link* set_bandwidth_profile(kernel::profile::Profile* profile);
85   /** Setup the profile file with latency events (peak latency changes due to external load).
86    * The profile must contain absolute values */
87   Link* set_latency_profile(kernel::profile::Profile* profile);
88
89   const std::unordered_map<std::string, std::string>* get_properties() const;
90   const char* get_property(const std::string& key) const;
91   Link* set_properties(const std::unordered_map<std::string, std::string>& properties);
92   Link* set_property(const std::string& key, const std::string& value);
93
94   /**
95    * @brief Set the number of communications that can shared this link at the same time
96    *
97    * Use this method to serialize communication flows going through this link.
98    * Use -1 to set no limit.
99    *
100    * @param limit  Number of concurrent flows
101    */
102   Link* set_concurrency_limit(int limit);
103
104   /** @brief Set the level of communication speed of the given host on this wifi link.
105    *
106    * The bandwidth of a wifi link for a given host depends on its SNR (signal to noise ratio),
107    * which ultimately depends on the distance between the host and the station and the material between them.
108    *
109    * This is modeled in SimGrid by providing several bandwidths to wifi links, one per SNR level (just provide
110    * comma-separated values in the XML file). By default, the first level in the list is used, but you can use the
111    * current function to specify that a given host uses another level of bandwidth. This can be used to take the
112    * location of hosts into account, or even to model mobility in your SimGrid simulation.
113    *
114    * Note that this function asserts that the link is actually a wifi link */
115   void set_host_wifi_rate(const s4u::Host* host, int level) const;
116
117   /** @brief Returns the current load (in bytes per second) */
118   double get_usage() const;
119
120   /** @brief Check if the Link is used (at least one flow uses the link) */
121   bool is_used() const;
122
123   /** @brief Check if the Link is shared (not a FATPIPE) */
124   bool is_shared() const;
125
126   void turn_on();
127   void turn_off();
128   bool is_on() const;
129
130   Link* seal();
131
132   /* The signals */
133   /** @brief Callback signal fired when a new Link is created */
134   static xbt::signal<void(Link&)> on_creation;
135
136   /** @brief Callback signal fired when a Link is destroyed */
137   static xbt::signal<void(Link const&)> on_destruction;
138
139   /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */
140   static xbt::signal<void(Link const&)> on_state_change;
141
142   /** @brief Callback signal fired when the bandwidth of a Link changes */
143   static xbt::signal<void(Link const&)> on_bandwidth_change;
144
145   /** @brief Callback signal fired when a communication starts */
146   static xbt::signal<void(kernel::resource::NetworkAction&)> on_communicate;
147
148   /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */
149   static xbt::signal<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>
150       on_communication_state_change;
151 };
152 } // namespace s4u
153 } // namespace simgrid
154
155 #endif /* S4U_LINK_HPP */