Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / resource / StandardLinkImpl.hpp
1 /* Copyright (c) 2004-2023. 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_STANDARDLINKIMPL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_STANDARDLINKIMPL_HPP
8
9 #include "src/kernel/resource/LinkImpl.hpp"
10
11 /***********
12  * Classes *
13  ***********/
14
15 namespace simgrid::kernel::resource {
16 /************
17  * Resource *
18  ************/
19 class StandardLinkImpl : public LinkImpl {
20   s4u::Link piface_;
21   s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
22   routing::NetZoneImpl* englobing_zone_    = nullptr;
23
24 protected:
25   explicit StandardLinkImpl(const std::string& name);
26   StandardLinkImpl(const StandardLinkImpl&) = delete;
27   StandardLinkImpl& operator=(const StandardLinkImpl&) = delete;
28   ~StandardLinkImpl() override                         = default; // Use destroy() instead of this destructor.
29
30   Metric latency_   = {0.0, 1, nullptr};
31   Metric bandwidth_ = {1.0, 1, nullptr};
32
33 public:
34   void destroy(); // Must be called instead of the destructor
35   class Deleter {
36   public:
37     void operator()(StandardLinkImpl* link) const;
38   };
39
40   void latency_check(double latency) const;
41
42   /** @brief Public interface */
43   const s4u::Link* get_iface() const { return &piface_; }
44   s4u::Link* get_iface() { return &piface_; }
45
46   /** @brief Get the bandwidth in bytes per second of current Link */
47   double get_bandwidth() const override { return bandwidth_.peak * bandwidth_.scale; }
48
49   /** @brief Get the latency in seconds of current Link */
50   double get_latency() const override { return latency_.peak * latency_.scale; }
51
52   routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
53   /** @brief Set the NetZone in which this Link is included */
54   StandardLinkImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
55
56   /** @brief The sharing policy */
57   void set_sharing_policy(s4u::Link::SharingPolicy policy, const s4u::NonLinearResourceCb& cb) override;
58   s4u::Link::SharingPolicy get_sharing_policy() const override { return sharing_policy_; }
59
60   void turn_on() override;
61   void turn_off() override;
62
63   void seal() override;
64
65   void on_bandwidth_change() const;
66
67   /* setup the profile file with bandwidth events (peak speed changes due to external load).
68    * Profile must contain percentages (value between 0 and 1). */
69   void set_bandwidth_profile(kernel::profile::Profile* profile) override;
70   /* setup the profile file with latency events (peak latency changes due to external load).
71    * Profile must contain absolute values */
72   void set_latency_profile(kernel::profile::Profile* profile) override;
73 };
74
75 } // namespace simgrid::kernel::resource
76
77 #endif /* SIMGRID_KERNEL_RESOURCE_STANDARDLINKIMPL_HPP */