1 /* Copyright (c) 2004-2021. 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. */
6 #ifndef SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP
9 #include "src/surf/LinkImplIntf.hpp"
21 /** @ingroup SURF_network_interface
22 * @brief SURF network link interface class
23 * @details A Link represents the link between two [hosts](@ref simgrid::surf::HostImpl)
25 class LinkImpl : public LinkImplIntf {
27 s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
30 explicit LinkImpl(const std::string& name);
31 LinkImpl(const LinkImpl&) = delete;
32 LinkImpl& operator=(const LinkImpl&) = delete;
33 ~LinkImpl() override = default; // Use destroy() instead of this destructor.
36 void destroy(); // Must be called instead of the destructor
38 void latency_check(double latency) const;
40 /** @brief Public interface */
41 const s4u::Link* get_iface() const { return &piface_; }
42 s4u::Link* get_iface() { return &piface_; }
44 /** @brief Get the bandwidth in bytes per second of current Link */
45 double get_bandwidth() const override { return bandwidth_.peak * bandwidth_.scale; }
47 /** @brief Get the latency in seconds of current Link */
48 double get_latency() const override { return latency_.peak * latency_.scale; }
50 /** @brief The sharing policy */
51 void set_sharing_policy(s4u::Link::SharingPolicy policy) override;
52 s4u::Link::SharingPolicy get_sharing_policy() const override;
54 /** @brief Check if the Link is used */
55 bool is_used() const override;
57 void turn_on() override;
58 void turn_off() override;
62 void on_bandwidth_change() const;
64 /* setup the profile file with bandwidth events (peak speed changes due to external load).
65 * Profile must contain percentages (value between 0 and 1). */
66 void set_bandwidth_profile(kernel::profile::Profile* profile) override;
67 /* setup the profile file with latency events (peak latency changes due to external load).
68 * Profile must contain absolute values */
69 void set_latency_profile(kernel::profile::Profile* profile) override;
71 void set_concurrency_limit(int limit) const override;
73 Metric latency_ = {0.0, 1, nullptr};
74 Metric bandwidth_ = {1.0, 1, nullptr};
77 } // namespace resource
79 } // namespace simgrid
81 #endif /* SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP */