Logo AND Algorithmique Numérique Distribuée

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