Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add create_link in s4u::NetZone
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 1 Apr 2021 16:15:37 +0000 (18:15 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 1 Apr 2021 17:12:21 +0000 (19:12 +0200)
With SharingPolicy as parameter since it's mandatory to decide if we
must create a WiFi link or not.

Setting default as SHARED according to DTD

include/simgrid/s4u/NetZone.hpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Netzone.cpp

index db9b525..222afc1 100644 (file)
@@ -7,6 +7,7 @@
 #define SIMGRID_S4U_NETZONE_HPP
 
 #include <simgrid/forward.h>
+#include <simgrid/s4u/Link.hpp>
 #include <xbt/graph.h>
 #include <xbt/signal.hpp>
 
@@ -78,14 +79,28 @@ public:
   static xbt::signal<void(NetZone const&)> on_seal;
 
   /**
-   * @brief Create a Host
+   * @brief Create a host
    *
-   * @param name  Host name
+   * @param name Host name
    * @param speed_per_state Vector of CPU's speeds
    */
   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
   /** @brief Create a Host (string version) */
   s4u::Host* create_host(const std::string& name, const std::vector<std::string>& speed_per_pstate);
+
+  /**
+   * @brief Create a link
+   *
+   * @param name Link name
+   * @param bandwidths Link's speed (vector for wifi links)
+   * @param policy Link sharing policy
+   */
+  s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths,
+                         Link::SharingPolicy policy = Link::SharingPolicy::SHARED);
+
+  /** @brief Create a link (string version) */
+  s4u::Link* create_link(const std::string& name, const std::vector<std::string>& bandwidths,
+                         Link::SharingPolicy policy = Link::SharingPolicy::SHARED);
 };
 
 // External constructors so that the types (and the types of their content) remain hidden
index 6878516..81aa555 100644 (file)
@@ -274,7 +274,8 @@ Host* Host::set_pstate_speed(const std::vector<double>& speed_per_state)
 
 std::vector<double> Host::convert_pstate_speed_vector(const std::vector<std::string>& speed_per_state)
 {
-  std::vector<double> speed_list(speed_per_state.size());
+  std::vector<double> speed_list;
+  speed_list.reserve(speed_per_state.size());
   for (const auto& speed_str : speed_per_state) {
     try {
       double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, "");
index 9660a89..57c83f3 100644 (file)
@@ -3,12 +3,14 @@
 /* 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. */
 
+#include "simgrid/Exception.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/NetZone.hpp"
 #include "simgrid/simix.hpp"
 #include "simgrid/zone.h"
+#include "xbt/parse_units.hpp"
 
 namespace simgrid {
 namespace s4u {
@@ -128,6 +130,30 @@ s4u::Host* NetZone::create_host(const std::string& name, const std::vector<std::
 {
   return create_host(name, Host::convert_pstate_speed_vector(speed_per_pstate));
 }
+
+s4u::Link* NetZone::create_link(const std::string& name, const std::vector<double>& bandwidths,
+                                s4u::Link::SharingPolicy policy)
+{
+  return kernel::actor::simcall(
+      [this, &name, &bandwidths, &policy] { return pimpl_->create_link(name, bandwidths, policy); });
+}
+
+s4u::Link* NetZone::create_link(const std::string& name, const std::vector<std::string>& bandwidths,
+                                s4u::Link::SharingPolicy policy)
+{
+  std::vector<double> bw;
+  bw.reserve(bandwidths.size());
+  for (const auto& speed_str : bandwidths) {
+    try {
+      double speed = xbt_parse_get_bandwidth("", 0, speed_str.c_str(), nullptr, "");
+      bw.push_back(speed);
+    } catch (const simgrid::ParseError&) {
+      xbt_die("Link: Impossible to create_link, invalid bandwidth %s", speed_str.c_str());
+    }
+  }
+  return create_link(name, bw, policy);
+}
+
 } // namespace s4u
 } // namespace simgrid