Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / resource / WifiLinkImpl.hpp
1 /* Copyright (c) 2019-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_NETWORK_WIFI_HPP_
7 #define SIMGRID_KERNEL_NETWORK_WIFI_HPP_
8
9 #include "src/kernel/resource/models/network_cm02.hpp"
10 #include "xbt/ex.h"
11
12 /***********
13  * Classes *
14  ***********/
15
16 namespace simgrid::kernel::resource {
17
18 class XBT_PRIVATE WifiLinkAction;
19
20 class WifiLinkImpl : public StandardLinkImpl {
21   /** @brief Hold every rates association between host and links (host name, rates id) */
22   std::map<std::string, int, std::less<>> host_rates_;
23
24   /** @brief A link can have several bandwidths attached to it (mostly use by wifi model) */
25   std::vector<Metric> bandwidths_;
26
27   bool use_callback_ = false;
28   /*
29    * Values used for the throughput degradation:
30    * ratio = x0_ + co_acc_ * nb_active_flux_ / x0_
31   **/
32   /** @brief base maximum throughput to compare to when computing the ratio */
33   const double x0_ = 5678270;
34   /** @brief linear regression factor */
35   const double co_acc_ = -5424;
36   /** @brief minimum number of concurrent flows before using the linear regression */
37   const int conc_lim_ = 20;
38   /** @brief current concurrency on the link */
39   int nb_active_flux_ = 0;
40
41   std::vector<Metric> decay_bandwidths_;
42
43 public:
44   WifiLinkImpl(const std::string& name, const std::vector<double>& bandwidths, lmm::System* system);
45
46   void set_host_rate(const s4u::Host* host, int rate_level);
47   /** @brief Get the AP rate associated to the host (or -1 if not associated to the AP) */
48   double get_host_rate(const s4u::Host* host) const;
49
50   s4u::Link::SharingPolicy get_sharing_policy() const override;
51   void apply_event(kernel::profile::Event*, double) override { THROW_UNIMPLEMENTED; }
52   void set_bandwidth(double) override { THROW_UNIMPLEMENTED; }
53   void set_latency(double) override;
54   bool toggle_callback();
55
56   static void update_bw_comm_end(const NetworkAction& action, Action::State state);
57   void inc_active_flux();
58   void dec_active_flux();
59   static double wifi_link_dynamic_sharing(const WifiLinkImpl& link, double capacity, int n);
60   double get_max_ratio() const;
61   size_t get_host_count() const;
62 };
63
64 class WifiLinkAction : public NetworkCm02Action {
65   WifiLinkImpl* src_wifi_link_;
66   WifiLinkImpl* dst_wifi_link_;
67
68 public:
69   WifiLinkAction() = delete;
70   WifiLinkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, WifiLinkImpl* src_wifi_link,
71                  WifiLinkImpl* dst_wifi_link)
72       : NetworkCm02Action(model, src, dst, cost, failed), src_wifi_link_(src_wifi_link), dst_wifi_link_(dst_wifi_link)
73   {
74   }
75
76   WifiLinkImpl* get_src_link() const { return src_wifi_link_; }
77   WifiLinkImpl* get_dst_link() const { return dst_wifi_link_; }
78 };
79
80 } // namespace simgrid::kernel::resource
81 #endif