Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e49c884d50bb3cbf0d863c05eeeb836c754b4a9a
[simgrid.git] / src / surf / LinkImpl.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 SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP
8
9 #include "src/surf/LinkImplIntf.hpp"
10
11 /***********
12  * Classes *
13  ***********/
14
15 namespace simgrid {
16 namespace kernel {
17 namespace resource {
18 /************
19  * Resource *
20  ************/
21 /** @ingroup SURF_network_interface
22  * @brief SURF network link interface class
23  * @details A Link represents the link between two [hosts](@ref simgrid::kernel::resource::HostImpl)
24  */
25 class LinkImpl : public LinkImplIntf {
26   s4u::Link piface_;
27   s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
28
29 protected:
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.
34
35   Metric latency_   = {0.0, 1, nullptr};
36   Metric bandwidth_ = {1.0, 1, nullptr};
37
38 public:
39   void destroy(); // Must be called instead of the destructor
40
41   void latency_check(double latency) const;
42
43   /** @brief Public interface */
44   const s4u::Link* get_iface() const { return &piface_; }
45   s4u::Link* get_iface() { return &piface_; }
46
47   /** @brief Get the bandwidth in bytes per second of current Link */
48   double get_bandwidth() const override { return bandwidth_.peak * bandwidth_.scale; }
49
50   /** @brief Get the latency in seconds of current Link */
51   double get_latency() const override { return latency_.peak * latency_.scale; }
52
53   /** @brief The sharing policy */
54   void set_sharing_policy(s4u::Link::SharingPolicy policy, const s4u::NonLinearResourceCb& cb) override;
55   s4u::Link::SharingPolicy get_sharing_policy() const override { return sharing_policy_; }
56
57   void turn_on() override;
58   void turn_off() override;
59
60   void seal() override;
61
62   void on_bandwidth_change() const;
63
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;
70
71   void set_concurrency_limit(int limit) const override;
72 };
73
74 } // namespace resource
75 } // namespace kernel
76 } // namespace simgrid
77
78 #endif /* SIMGRID_KERNEL_RESOURCE_LINKIMPL_HPP */