Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
NetworkModelIntf: Interface to dynamic factors
authorBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 26 Mar 2021 17:27:38 +0000 (18:27 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 24 May 2021 07:33:25 +0000 (09:33 +0200)
Adding API to set user callbacks for bandwidth and network factors.
Valid for CM02 models and its childrens (SMPI, IB, etc).

Not fully working yet.

MANIFEST.in
include/simgrid/forward.h
include/simgrid/kernel/resource/NetworkModelIntf.hpp [new file with mode: 0644]
include/simgrid/s4u/NetZone.hpp
src/s4u/s4u_Netzone.cpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_interface.hpp
src/surf/network_smpi.cpp
src/surf/network_smpi.hpp
tools/cmake/DefinePackages.cmake

index 8416dc1..c264244 100644 (file)
@@ -1976,6 +1976,7 @@ include include/simgrid/kernel/Timer.hpp
 include include/simgrid/kernel/future.hpp
 include include/simgrid/kernel/resource/Action.hpp
 include include/simgrid/kernel/resource/Model.hpp
+include include/simgrid/kernel/resource/NetworkModelIntf.hpp
 include include/simgrid/kernel/resource/Resource.hpp
 include include/simgrid/kernel/routing/ClusterZone.hpp
 include include/simgrid/kernel/routing/DijkstraZone.hpp
index 7f110d5..32a23f4 100644 (file)
@@ -161,6 +161,7 @@ class Model;
 class Resource;
 class CpuModel;
 class NetworkModel;
+class NetworkModelIntf;
 class LinkImpl;
 class NetworkAction;
 class DiskImpl;
diff --git a/include/simgrid/kernel/resource/NetworkModelIntf.hpp b/include/simgrid/kernel/resource/NetworkModelIntf.hpp
new file mode 100644 (file)
index 0000000..bafd98e
--- /dev/null
@@ -0,0 +1,35 @@
+/* Copyright (c) 2004-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. */
+
+#ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP
+#define SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP
+
+#include <simgrid/s4u/Link.hpp>
+#include <simgrid/s4u/NetZone.hpp>
+
+#include <unordered_set>
+#include <vector>
+
+namespace simgrid {
+namespace kernel {
+namespace resource {
+
+/** @ingroup SURF_interface
+ * @brief Network Model interface class
+ * @details Defines the methods that a Network model must implement
+ */
+class XBT_PUBLIC NetworkModelIntf {
+public:
+  using NetworkFactorCb     = double(double size, const std::vector<s4u::Link*>& links,
+                                 const std::unordered_set<s4u::NetZone*>& netzones);
+  virtual void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb)        = 0;
+  virtual void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb)         = 0;
+};
+
+} // namespace resource
+} // namespace kernel
+} // namespace simgrid
+
+#endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP */
\ No newline at end of file
index b4dc45b..9daaf7b 100644 (file)
@@ -129,6 +129,8 @@ public:
   s4u::Link* create_link(const std::string& name, const std::vector<std::string>& bandwidths);
   s4u::Link* create_link(const std::string& name, const std::string& bandwidth);
 
+  kernel::resource::NetworkModelIntf* get_network_model() const;
+
   /**
    * @brief Make a router within that NetZone
    *
index 17ac925..3d768ab 100644 (file)
@@ -10,6 +10,7 @@
 #include "simgrid/s4u/NetZone.hpp"
 #include "simgrid/simix.hpp"
 #include "simgrid/zone.h"
+#include "src/surf/network_interface.hpp"
 #include "xbt/parse_units.hpp"
 
 namespace simgrid {
@@ -204,6 +205,12 @@ kernel::routing::NetPoint* NetZone::get_netpoint()
 {
   return pimpl_->get_netpoint();
 }
+
+kernel::resource::NetworkModelIntf* NetZone::get_network_model() const
+{
+  kernel::resource::NetworkModelIntf* model = pimpl_->get_network_model().get();
+  return model;
+}
 } // namespace s4u
 } // namespace simgrid
 
index 19db714..08bd06a 100644 (file)
@@ -93,6 +93,40 @@ NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name)
   loopback_->seal();
 }
 
+void NetworkCm02Model::check_lat_factor_cb()
+{
+  if (not simgrid::config::is_default("network/latency-factor")) {
+    throw std::invalid_argument(
+        "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them.");
+  }
+}
+
+void NetworkCm02Model::check_bw_factor_cb()
+{
+  if (not simgrid::config::is_default("network/bandwidth-factor")) {
+    throw std::invalid_argument(
+        "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them.");
+  }
+}
+
+void NetworkCm02Model::set_lat_factor_cb(const std::function<NetworkFactorCb>& cb)
+{
+  if (not cb)
+    throw std::invalid_argument("NetworkModelIntf: Invalid callback");
+  check_lat_factor_cb();
+
+  lat_factor_cb_ = cb;
+}
+
+void NetworkCm02Model::set_bw_factor_cb(const std::function<NetworkFactorCb>& cb)
+{
+  if (not cb)
+    throw std::invalid_argument("NetworkModelIntf: Invalid callback");
+  check_bw_factor_cb();
+
+  bw_factor_cb_ = cb;
+}
+
 LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector<double>& bandwidths)
 {
   xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth.");
index dfa4e8e..6765921 100644 (file)
@@ -9,6 +9,7 @@
 #include <xbt/base.h>
 
 #include "network_interface.hpp"
+#include "simgrid/kernel/resource/NetworkModelIntf.hpp"
 #include "xbt/graph.h"
 #include "xbt/string.hpp"
 
@@ -36,6 +37,14 @@ public:
   void update_actions_state_lazy(double now, double delta) override;
   void update_actions_state_full(double now, double delta) override;
   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
+  void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override;
+  void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override;
+
+protected:
+  virtual void check_lat_factor_cb();
+  virtual void check_bw_factor_cb();
+  std::function<NetworkFactorCb> lat_factor_cb_;
+  std::function<NetworkFactorCb> bw_factor_cb_;
 };
 
 /************
@@ -60,7 +69,7 @@ public:
   using NetworkAction::NetworkAction;
   void update_remains_lazy(double now) override;
 };
-}
-}
+} // namespace resource
+} // namespace kernel
 } // namespace simgrid
 #endif /* SURF_NETWORK_CM02_HPP_ */
index a3dcab0..3b0c893 100644 (file)
@@ -7,6 +7,7 @@
 #define SURF_NETWORK_INTERFACE_HPP_
 
 #include "simgrid/kernel/resource/Model.hpp"
+#include "simgrid/kernel/resource/NetworkModelIntf.hpp"
 #include "simgrid/kernel/resource/Resource.hpp"
 #include "simgrid/s4u/Link.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
@@ -30,7 +31,7 @@ namespace resource {
  * @brief SURF network model interface class
  * @details A model is an object which handles the interactions between its Resources and its Actions
  */
-class NetworkModel : public Model {
+class NetworkModel : public Model, public NetworkModelIntf {
 public:
   static config::Flag<double> cfg_tcp_gamma;
   static config::Flag<bool> cfg_crosstraffic;
@@ -97,6 +98,9 @@ public:
 
   double next_occurring_event_full(double now) override;
 
+  virtual void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
+  virtual void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override { THROW_UNIMPLEMENTED; }
+
   LinkImpl* loopback_ = nullptr;
 };
 
@@ -156,8 +160,8 @@ public:
    * Profile must contain absolute values */
   virtual LinkImpl* set_latency_profile(kernel::profile::Profile* profile);
 
-  Metric latency_                   = {0.0, 0, nullptr};
-  Metric bandwidth_                 = {1.0, 0, nullptr};
+  Metric latency_   = {0.0, 0, nullptr};
+  Metric bandwidth_ = {1.0, 0, nullptr};
 };
 
 /**********
@@ -209,5 +213,3 @@ public:
 } // namespace simgrid
 
 #endif /* SURF_NETWORK_INTERFACE_HPP_ */
-
-
index 54772d2..4c9adb6 100644 (file)
@@ -43,6 +43,22 @@ namespace simgrid {
 namespace kernel {
 namespace resource {
 
+void NetworkSmpiModel::check_lat_factor_cb()
+{
+  if (not simgrid::config::is_default("smpi/lat-factor")) {
+    throw std::invalid_argument(
+        "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them.");
+  }
+}
+
+void NetworkSmpiModel::check_bw_factor_cb()
+{
+  if (not simgrid::config::is_default("smpi/bw-factor")) {
+    throw std::invalid_argument(
+        "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them.");
+  }
+}
+
 double NetworkSmpiModel::get_bandwidth_factor(double size)
 {
   static std::vector<s_smpi_factor_t> smpi_bw_factor;
index 3e5b4d7..ea69e4a 100644 (file)
@@ -22,9 +22,13 @@ public:
   double get_latency_factor(double size) override;
   double get_bandwidth_factor(double size) override;
   double get_bandwidth_constraint(double rate, double bound, double size) override;
+
+protected:
+  virtual void check_lat_factor_cb() override;
+  virtual void check_bw_factor_cb() override;
 };
 } // namespace resource
 } // namespace kernel
-}
+} // namespace simgrid
 
 #endif
index d756d58..e368f54 100644 (file)
@@ -718,6 +718,7 @@ set(headers_to_install
   include/simgrid/s4u.hpp
 
   include/simgrid/kernel/resource/Action.hpp
+  include/simgrid/kernel/resource/NetworkModelIntf.hpp
   include/simgrid/kernel/resource/Model.hpp
   include/simgrid/kernel/resource/Resource.hpp