1 /* Copyright (c) 2009-2021. 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 "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"
12 #include <unordered_set>
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_wifi, surf, "Routing part of surf");
20 void WifiZone::do_seal()
22 const char* AP_name = get_property("access_point");
23 if (AP_name != nullptr) {
24 access_point_ = sg_netpoint_by_name_or_null(AP_name);
25 xbt_assert(access_point_ != nullptr, "Access point '%s' of WIFI zone '%s' does not exist: no such host or router.",
26 AP_name, get_cname());
27 xbt_assert(access_point_->is_host() || access_point_->is_router(),
28 "Access point '%s' of WIFI zone '%s' must be either a host or a router.", AP_name, get_cname());
32 void WifiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
34 XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());
36 if (wifi_link_ != nullptr) {
37 // If src and dst are nodes, not access_point, we need to traverse the link twice
38 // Otherwise (if src or dst is access_point), we need to traverse the link only once
40 if (src != access_point_) {
41 XBT_DEBUG("src %s is not our gateway", src->get_cname());
42 res->link_list.push_back(wifi_link_);
44 *lat += wifi_link_->get_latency();
46 if (dst != access_point_) {
47 XBT_DEBUG("dst %s is not our gateway", dst->get_cname());
48 res->link_list.push_back(wifi_link_);
50 *lat += wifi_link_->get_latency();
55 s4u::Link* WifiZone::create_link(const std::string& name, const std::vector<double>& bandwidths,
56 s4u::Link::SharingPolicy policy)
58 xbt_assert(wifi_link_ == nullptr,
59 "WIFI netzone %s contains more than one link. Please only declare one, the wifi link.", get_cname());
60 xbt_assert(policy == s4u::Link::SharingPolicy::WIFI, "Link %s in WIFI zone %s must follow the WIFI sharing policy.",
61 name.c_str(), get_cname());
63 auto s4u_link = NetZoneImpl::create_link(name, bandwidths, policy);
64 wifi_link_ = s4u_link->get_impl();
67 } // namespace routing
71 NetZone* create_wifi_zone(const std::string& name)
73 return (new kernel::routing::WifiZone(name))->get_iface();
77 } // namespace simgrid