Logo AND Algorithmique Numérique Distribuée

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