Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s4u::Host::create_disk, human-friendly string version
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 8 Apr 2021 16:47:41 +0000 (18:47 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 8 Apr 2021 16:47:41 +0000 (18:47 +0200)
include/simgrid/s4u/Host.hpp
src/s4u/s4u_Host.cpp

index eee8596..4ecd0d5 100644 (file)
@@ -165,7 +165,20 @@ public:
   Host* set_pstate(int pstate_index);
 
   std::vector<Disk*> get_disks() const;
+  /**
+   * @brief Create and add disk in the host
+   *
+   * @param name Disk name
+   * @param read_bandwidth Reading speed of the disk
+   * @param write_bandwidth Writing speed of the disk
+   */
   Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
+  /**
+   * @brief Human-friendly version of create_disk function.
+   *
+   * @throw std::invalid_argument if read/write speeds are incorrect
+   */
+  Disk* create_disk(const std::string& name, const std::string& read_bandwidth, const std::string& write_bandwidth);
   void add_disk(const Disk* disk);
   void remove_disk(const std::string& disk_name);
 
index 44ef6a1..ced3915 100644 (file)
@@ -317,6 +317,24 @@ Disk* Host::create_disk(const std::string& name, double read_bandwidth, double w
   });
 }
 
+Disk* Host::create_disk(const std::string& name, const std::string& read_bandwidth, const std::string& write_bandwidth)
+{
+  double d_read, d_write;
+  try {
+    d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth.c_str(), nullptr, "");
+  } catch (const simgrid::ParseError&) {
+    throw std::invalid_argument(std::string("Impossible to create disk: ") + name.c_str() +
+                                std::string(". Invalid read bandwidth: ") + read_bandwidth);
+  }
+  try {
+    d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth.c_str(), nullptr, "");
+  } catch (const simgrid::ParseError&) {
+    throw std::invalid_argument(std::string("Impossible to create disk: ") + name.c_str() +
+                                std::string(". Invalid write bandwidth: ") + write_bandwidth);
+  }
+  return create_disk(name, d_read, d_write);
+}
+
 void Host::add_disk(const Disk* disk)
 {
   kernel::actor::simcall([this, disk] { this->pimpl_->add_disk(disk); });