1 /* Copyright (c) 2004-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. */
9 #include <simgrid/forward.h>
10 #include <simgrid/kernel/resource/Action.hpp>
11 #include <simgrid/link.h>
13 #include <unordered_map>
14 #include <xbt/Extendable.hpp>
16 #include <xbt/signal.hpp>
24 extern template class XBT_PUBLIC xbt::Extendable<s4u::Link>;
29 * A Link represents the network facilities between :cpp:class:`hosts <simgrid::s4u::Host>`.
32 class XBT_PUBLIC Link : public xbt::Extendable<Link> {
33 friend kernel::resource::LinkImpl;
35 // Links are created from the NetZone, and destroyed by their private implementation when the simulation ends
36 explicit Link(kernel::resource::LinkImpl* pimpl) : pimpl_(pimpl) {}
37 virtual ~Link() = default;
38 // The private implementation, that never changes
39 kernel::resource::LinkImpl* const pimpl_;
42 enum class SharingPolicy { WIFI = 3, SPLITDUPLEX = 2, SHARED = 1, FATPIPE = 0 };
44 kernel::resource::LinkImpl* get_impl() const { return pimpl_; }
46 /** @brief Retrieve a link from its name */
47 static Link* by_name(const std::string& name);
48 static Link* by_name_or_null(const std::string& name);
50 /** @brief Retrieves the name of that link as a C++ string */
51 const std::string& get_name() const;
52 /** @brief Retrieves the name of that link as a C string */
53 const char* get_cname() const;
55 /** @brief Get the bandwidth in bytes per second of current Link */
56 double get_bandwidth() const;
58 /** @brief Get the latency in seconds of current Link */
59 double get_latency() const;
61 /** @brief Describes how the link is shared between flows */
62 SharingPolicy get_sharing_policy() const;
64 /** @brief Returns the current load (in flops per second) */
65 double get_usage() const;
67 /** @brief Check if the Link is used (at least one flow uses the link) */
74 /** Setup the profile with states events (ON or OFF). The profile must contain boolean values. */
75 void set_state_profile(kernel::profile::Profile* profile);
76 /** Setup the profile with bandwidth events (peak speed changes due to external load).
77 * The profile must contain percentages (value between 0 and 1). */
78 void set_bandwidth_profile(kernel::profile::Profile* profile);
79 /** Setup the profile file with latency events (peak latency changes due to external load).
80 * The profile must contain absolute values */
81 void set_latency_profile(kernel::profile::Profile* profile);
83 const char* get_property(const std::string& key) const;
84 void set_property(const std::string& key, const std::string& value);
87 /** @brief Callback signal fired when a new Link is created */
88 static xbt::signal<void(Link&)> on_creation;
90 /** @brief Callback signal fired when a Link is destroyed */
91 static xbt::signal<void(Link const&)> on_destruction;
93 /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */
94 static xbt::signal<void(Link const&)> on_state_change;
96 /** @brief Callback signal fired when the bandwidth of a Link changes */
97 static xbt::signal<void(Link const&)> on_bandwidth_change;
99 /** @brief Callback signal fired when a communication starts */
100 static xbt::signal<void(kernel::resource::NetworkAction&, Host* src, Host* dst)> on_communicate;
102 /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */
103 static xbt::signal<void(kernel::resource::NetworkAction&, kernel::resource::Action::State)>
104 on_communication_state_change;
107 } // namespace simgrid
109 #endif /* S4U_LINK_HPP */