Logo AND Algorithmique Numérique Distribuée

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