Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix cosmetics
[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   /** @brief Should we use the decay model ? */
30   bool use_decay_model_ = false;
31   /** @brief Wifi maximal bit rate according to the ns-3 802.11n standard */
32   const double wifi_max_rate_ = 54 * 1e6 / 8;
33   /** @brief minimum bit rate observed with ns3 during our calibration experiments */
34   const double wifi_min_rate_ = 41.70837 * 1e6 / 8;
35   /** @brief Amount of stations used in the reference point to rescale SimGrid predictions to fit ns-3 ones */
36   const int model_n_ = 5;
37   /** @brief Bit rate observed on ns3 at the reference point used for rescaling */
38   const double model_rate_ = 42.61438 * 1e6 / 8;
39   /** @brief The bandwidth to use for each SNR level, corrected with the decay rescale mechanism */
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   void refresh_decay_bandwidths();
54   bool toggle_decay_model();
55   size_t get_host_count() const;
56 };
57
58 class WifiLinkAction : public NetworkCm02Action {
59   WifiLinkImpl* src_wifi_link_;
60   WifiLinkImpl* dst_wifi_link_;
61
62 public:
63   WifiLinkAction() = delete;
64   WifiLinkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, WifiLinkImpl* src_wifi_link,
65                  WifiLinkImpl* dst_wifi_link)
66       : NetworkCm02Action(model, src, dst, cost, failed), src_wifi_link_(src_wifi_link), dst_wifi_link_(dst_wifi_link)
67   {
68   }
69
70   WifiLinkImpl* get_src_link() const { return src_wifi_link_; }
71   WifiLinkImpl* get_dst_link() const { return dst_wifi_link_; }
72 };
73
74 } // namespace simgrid::kernel::resource
75 #endif