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_
11 #include "src/surf/network_cm02.hpp"
12 #include "xbt/string.hpp"
18 namespace simgrid::kernel::resource {
20 class XBT_PRIVATE WifiLinkAction;
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_;
26 /** @brief A link can have several bandwidths attached to it (mostly use by wifi model) */
27 std::vector<Metric> bandwidths_;
29 bool use_callback_ = false;
31 * Values used for the throughput degradation:
32 * ratio = x0_ + co_acc_ * nb_active_flux_ / x0_
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;
43 std::vector<Metric> decay_bandwidths_;
46 WifiLinkImpl(const std::string& name, const std::vector<double>& bandwidths, lmm::System* system);
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;
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();
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;
68 class WifiLinkAction : public NetworkCm02Action {
69 WifiLinkImpl* src_wifi_link_;
70 WifiLinkImpl* dst_wifi_link_;
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)
80 WifiLinkImpl* get_src_link() const { return src_wifi_link_; }
81 WifiLinkImpl* get_dst_link() const { return dst_wifi_link_; }
84 } // namespace simgrid::kernel::resource