1 /* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SURF_NETWORK_WIFI_HPP_
7 #define SURF_NETWORK_WIFI_HPP_
9 #include "src/surf/network_cm02.hpp"
16 namespace simgrid::kernel::resource {
18 class XBT_PRIVATE WifiLinkAction;
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> host_rates_;
24 /** @brief A link can have several bandwidths attached to it (mostly use by wifi model) */
25 std::vector<Metric> bandwidths_;
27 bool use_callback_ = false;
29 * Values used for the throughput degradation:
30 * ratio = x0_ + co_acc_ * nb_active_flux_ / x0_
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;
41 std::vector<Metric> decay_bandwidths_;
44 WifiLinkImpl(const std::string& name, const std::vector<double>& bandwidths, lmm::System* system);
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;
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();
56 static void update_bw_comm_start(const kernel::activity::CommImpl&);
57 static void update_bw_comm_end(const simgrid::kernel::resource::NetworkAction& action,
58 simgrid::kernel::resource::Action::State state);
59 void inc_active_flux();
60 void dec_active_flux();
61 static double wifi_link_dynamic_sharing(const WifiLinkImpl& link, double capacity, int n);
62 double get_max_ratio() const;
63 size_t get_host_count() const;
66 class WifiLinkAction : public NetworkCm02Action {
67 WifiLinkImpl* src_wifi_link_;
68 WifiLinkImpl* dst_wifi_link_;
71 WifiLinkAction() = delete;
72 WifiLinkAction(Model* model, s4u::Host& src, s4u::Host& dst, double cost, bool failed, WifiLinkImpl* src_wifi_link,
73 WifiLinkImpl* dst_wifi_link)
74 : NetworkCm02Action(model, src, dst, cost, failed), src_wifi_link_(src_wifi_link), dst_wifi_link_(dst_wifi_link)
78 WifiLinkImpl* get_src_link() const { return src_wifi_link_; }
79 WifiLinkImpl* get_dst_link() const { return dst_wifi_link_; }
82 } // namespace simgrid::kernel::resource