Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplyfying create_host and exporting it to s4u::NetZone
[simgrid.git] / src / kernel / routing / VivaldiZone.cpp
index be055b4..8035418 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -55,17 +55,12 @@ static inline double euclidean_dist_comp(int index, std::vector<double>* src, st
 
 static std::vector<double>* netpoint_get_coords(NetPoint* np)
 {
-  vivaldi::Coords* coords = np->extension<vivaldi::Coords>();
+  auto* coords = np->extension<vivaldi::Coords>();
   xbt_assert(coords, "Please specify the Vivaldi coordinates of %s %s (%p)",
              (np->is_netzone() ? "Netzone" : (np->is_host() ? "Host" : "Router")), np->get_cname(), np);
   return &coords->coords;
 }
 
-VivaldiZone::VivaldiZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
-{
-}
-
 void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, const std::string& coord)
 {
   xbt_assert(netpoint->get_englobing_zone() == this,
@@ -73,13 +68,15 @@ void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out,
 
   new vivaldi::Coords(netpoint, coord);
 
-  std::string link_up      = "link_" + netpoint->get_name() + "_UP";
-  std::string link_down    = "link_" + netpoint->get_name() + "_DOWN";
+  std::string link_up   = "link_" + netpoint->get_name() + "_UP";
+  std::string link_down = "link_" + netpoint->get_name() + "_DOWN";
   resource::LinkImpl* linkUp =
-      network_model_->create_link(link_up, std::vector<double>(1, bw_out), 0, s4u::Link::SharingPolicy::SHARED);
+      get_network_model()->create_link(link_up, std::vector<double>(1, bw_out), s4u::Link::SharingPolicy::SHARED);
+  linkUp->seal();
   resource::LinkImpl* linkDown =
-      network_model_->create_link(link_down, std::vector<double>(1, bw_in), 0, s4u::Link::SharingPolicy::SHARED);
-  private_links_.insert({netpoint->id(), {linkUp, linkDown}});
+      get_network_model()->create_link(link_down, std::vector<double>(1, bw_in), s4u::Link::SharingPolicy::SHARED);
+  linkDown->seal();
+  add_private_link_at(netpoint->id(), {linkUp, linkDown});
 }
 
 void VivaldiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
@@ -94,30 +91,19 @@ void VivaldiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg
   }
 
   /* Retrieve the private links */
-  auto src_link = private_links_.find(src->id());
-  if (src_link != private_links_.end()) {
-    std::pair<resource::LinkImpl*, resource::LinkImpl*> info = src_link->second;
-    if (info.first) {
-      route->link_list.push_back(info.first);
-      if (lat)
-        *lat += info.first->get_latency();
-    }
-  } else {
-    XBT_DEBUG("Source of private link (%u) doesn't exist", src->id());
+  if (private_link_exists_at(src->id())) {
+    auto src_link = get_uplink_from(src->id());
+    route->link_list.push_back(src_link);
+    if (lat)
+      *lat += src_link->get_latency();
   }
 
-  auto dst_link = private_links_.find(dst->id());
-  if (dst_link != private_links_.end()) {
-    std::pair<resource::LinkImpl*, resource::LinkImpl*> info = dst_link->second;
-    if (info.second) {
-      route->link_list.push_back(info.second);
-      if (lat)
-        *lat += info.second->get_latency();
-    }
-  } else {
-    XBT_DEBUG("Destination of private link (%u) doesn't exist", dst->id());
+  if (private_link_exists_at(dst->id())) {
+    auto dst_link = get_downlink_to(dst->id());
+    route->link_list.push_back(dst_link);
+    if (lat)
+      *lat += dst_link->get_latency();
   }
-
   /* Compute the extra latency due to the euclidean distance if needed */
   if (lat) {
     std::vector<double>* srcCoords = netpoint_get_coords(src);
@@ -133,4 +119,12 @@ void VivaldiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg
 }
 } // namespace routing
 } // namespace kernel
+
+namespace s4u {
+NetZone* createVivaldiZone(const std::string& name)
+{
+  return (new kernel::routing::VivaldiZone(name))->get_iface();
+}
+} // namespace s4u
+
 } // namespace simgrid