Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some 'const' qualifiers.
[simgrid.git] / src / kernel / routing / WifiZone.cpp
1 /* Copyright (c) 2009-2021. 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 "simgrid/kernel/routing/WifiZone.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "src/surf/network_interface.hpp"
9 #include "surf/surf.hpp"
10
11 #include <unordered_set>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_wifi, surf, "Routing part of surf");
14
15 namespace simgrid {
16 namespace kernel {
17 namespace routing {
18
19 void WifiZone::do_seal()
20 {
21   const char* AP_name = get_property("access_point");
22   if (AP_name != nullptr) {
23     access_point_ = sg_netpoint_by_name_or_null(AP_name);
24     xbt_assert(access_point_ != nullptr, "Access point '%s' of WIFI zone '%s' does not exist: no such host or router.",
25                AP_name, get_cname());
26     xbt_assert(access_point_->is_host() || access_point_->is_router(),
27                "Access point '%s' of WIFI zone '%s' must be either a host or a router.", AP_name, get_cname());
28   }
29 }
30
31 void WifiZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* res, double* lat)
32 {
33   XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
34
35   if (wifi_link_ != nullptr) {
36     // If src and dst are nodes, not access_point, we need to traverse the link twice
37     // Otherwise (if src or dst is access_point), we need to traverse the link only once
38
39     if (src != access_point_) {
40       XBT_DEBUG("src %s is not our gateway", src->get_cname());
41       res->link_list_.push_back(wifi_link_);
42       if (lat)
43         *lat += wifi_link_->get_latency();
44     }
45     if (dst != access_point_) {
46       XBT_DEBUG("dst %s is not our gateway", dst->get_cname());
47       res->link_list_.push_back(wifi_link_);
48       if (lat)
49         *lat += wifi_link_->get_latency();
50     }
51   }
52 }
53
54 s4u::Link* WifiZone::create_link(const std::string& name, const std::vector<double>& bandwidths)
55 {
56   xbt_assert(wifi_link_ == nullptr,
57              "WIFI netzone %s contains more than one link. Please only declare one, the wifi link.", get_cname());
58
59   wifi_link_ = get_network_model()->create_wifi_link(name, bandwidths);
60   wifi_link_->set_sharing_policy(s4u::Link::SharingPolicy::WIFI);
61   return wifi_link_->get_iface();
62 }
63 } // namespace routing
64 } // namespace kernel
65
66 namespace s4u {
67 NetZone* create_wifi_zone(const std::string& name)
68 {
69   return (new kernel::routing::WifiZone(name))->get_iface();
70 }
71 } // namespace s4u
72
73 } // namespace simgrid