Logo AND Algorithmique Numérique Distribuée

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