Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
split the wifi model into its own files
[simgrid.git] / src / surf / network_wifi.cpp
1 /* Copyright (c) 2013-2019. 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 #include "network_wifi.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/surf/surf_interface.hpp"
9 /*
10 #include "simgrid/sg_config.hpp"
11 #include "src/kernel/resource/profile/Event.hpp"
12 #include "surf/surf.hpp"
13
14 #include <algorithm>
15 #include <numeric>
16 */
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
18
19 namespace simgrid {
20 namespace kernel {
21 namespace resource {
22
23 /************
24  * Resource *
25  ************/
26
27 NetworkWifiLink::NetworkWifiLink(NetworkCm02Model* model, const std::string& name, std::vector<double> bandwidths,
28                                  s4u::Link::SharingPolicy policy, lmm::System* system)
29     : NetworkCm02Link(
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
32 {
33   for (auto bandwidth : bandwidths) {
34     bandwidths_.push_back({bandwidth, 1.0, nullptr});
35   }
36 }
37
38 void NetworkWifiLink::set_host_rate(s4u::Host* host, int rate_level)
39 {
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;
43 }
44
45 double NetworkWifiLink::get_host_rate(sg_host_t host)
46 {
47   std::map<xbt::string, int>::iterator host_rates_it;
48   host_rates_it = host_rates_.find(host->get_name());
49
50   if (host_rates_it == host_rates_.end())
51     return -1;
52
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);
56
57   Metric rate = bandwidths_[rate_id];
58   return rate.peak * rate.scale;
59 }
60
61 s4u::Link::SharingPolicy NetworkWifiLink::get_sharing_policy()
62 {
63   return s4u::Link::SharingPolicy::WIFI;
64 }
65
66 } // namespace resource
67 } // namespace kernel
68 } // namespace simgrid