1 /* Copyright (c) 2013-2019. 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 #include "network_wifi.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/surf/surf_interface.hpp"
10 #include "simgrid/sg_config.hpp"
11 #include "src/kernel/resource/profile/Event.hpp"
12 #include "surf/surf.hpp"
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
27 NetworkWifiLink::NetworkWifiLink(NetworkCm02Model* model, const std::string& name, std::vector<double> bandwidths,
28 s4u::Link::SharingPolicy policy, lmm::System* system)
30 model, name, 1 / sg_bandwidth_factor, 0, policy,
31 system) // Since link use bw*sg_bandwidth_factor we should divise in order to as 1 as bound in the lmm system
33 for (auto bandwidth : bandwidths) {
34 bandwidths_.push_back({bandwidth, 1.0, nullptr});
38 void NetworkWifiLink::set_host_rate(s4u::Host* host, int rate_level)
40 auto insert_done = host_rates_.insert(std::make_pair(host->get_name(), rate_level));
41 if (insert_done.second == false)
42 insert_done.first->second = rate_level;
45 double NetworkWifiLink::get_host_rate(sg_host_t host)
47 std::map<xbt::string, int>::iterator host_rates_it;
48 host_rates_it = host_rates_.find(host->get_name());
50 if (host_rates_it == host_rates_.end())
53 int rate_id = host_rates_it->second;
54 xbt_assert(rate_id >= 0 && rate_id < (int)bandwidths_.size(), "Host \"%s\" has an invalid rate \"%d\"",
55 host->get_name().c_str(), rate_id);
57 Metric rate = bandwidths_[rate_id];
58 return rate.peak * rate.scale;
61 s4u::Link::SharingPolicy NetworkWifiLink::get_sharing_policy()
63 return s4u::Link::SharingPolicy::WIFI;
66 } // namespace resource
68 } // namespace simgrid