1 /* Copyright (c) 2019-2023. 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/kernel/resource/models/network_cm02.hpp"
15 namespace simgrid::kernel::resource {
17 class XBT_PRIVATE WifiLinkAction;
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_;
23 /** @brief A link can have several bandwidths attached to it (mostly use by wifi model) */
24 std::vector<Metric> bandwidths_;
26 bool use_callback_ = false;
28 * Values used for the throughput degradation:
29 * ratio = x0_ + co_acc_ * nb_active_flux_ / x0_
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;
40 std::vector<Metric> decay_bandwidths_;
43 WifiLinkImpl(const std::string& name, const std::vector<double>& bandwidths, lmm::System* system);
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;
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();
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;
65 class WifiLinkAction : public NetworkCm02Action {
66 WifiLinkImpl* src_wifi_link_;
67 WifiLinkImpl* dst_wifi_link_;
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)
77 WifiLinkImpl* get_src_link() const { return src_wifi_link_; }
78 WifiLinkImpl* get_dst_link() const { return dst_wifi_link_; }
81 } // namespace simgrid::kernel::resource