Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Torus/Fat-Tree/Dragonfly: Aggregate callbacks
authorBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 30 Apr 2021 09:50:29 +0000 (11:50 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 30 Apr 2021 09:53:56 +0000 (11:53 +0200)
Put set callbacks in an object.
Less (or encapsulated) arguments for create_zones.
Remove create_cluster_zone (create_star_zone does its job for C++
interfaces).

12 files changed:
examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp
include/simgrid/kernel/routing/ClusterZone.hpp
include/simgrid/kernel/routing/TorusZone.hpp
include/simgrid/s4u/NetZone.hpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/DragonflyZone_test.cpp
src/kernel/routing/FatTreeZone.cpp
src/kernel/routing/FatTreeZone_test.cpp
src/kernel/routing/TorusZone.cpp
src/kernel/routing/TorusZone_test.cpp
src/surf/sg_platf.cpp

index 7633262..a473bcd 100644 (file)
@@ -171,8 +171,8 @@ static sg4::Link* create_limiter(sg4::NetZone* zone, const std::vector<unsigned
 static void create_torus_cluster()
 {
   /* create the torus cluster, 10Gbs link between elements in the cluster */
-  sg4::create_torus_zone("cluster", nullptr, {2, 2, 2}, 10e9, 10e-6, sg4::Link::SharingPolicy::SPLITDUPLEX,
-                         create_hostzone, {}, create_limiter)
+  sg4::create_torus_zone("cluster", nullptr, {2, 2, 2}, {create_hostzone, {}, create_limiter}, 10e9, 10e-6,
+                         sg4::Link::SharingPolicy::SPLITDUPLEX)
       ->seal();
 }
 
@@ -224,8 +224,8 @@ static void create_torus_cluster()
 static void create_fatTree_cluster()
 {
   /* create the fat tree cluster, 10Gbs link between elements in the cluster */
-  sg4::create_fatTree_zone("cluster", nullptr, {2, {2, 3}, {1, 2}, {1, 1}}, 10e9, 10e-6,
-                           sg4::Link::SharingPolicy::SPLITDUPLEX, create_hostzone, {}, create_limiter)
+  sg4::create_fatTree_zone("cluster", nullptr, {2, {2, 3}, {1, 2}, {1, 1}}, {create_hostzone, {}, create_limiter}, 10e9,
+                           10e-6, sg4::Link::SharingPolicy::SPLITDUPLEX)
       ->seal();
 }
 
@@ -272,8 +272,8 @@ static void create_fatTree_cluster()
 static void create_dragonfly_cluster()
 {
   /* create the dragonfly cluster, 10Gbs link between elements in the cluster */
-  sg4::create_dragonfly_zone("cluster", nullptr, {{2, 2}, {2, 1}, {2, 2}, 2}, 10e9, 10e-6,
-                             sg4::Link::SharingPolicy::SPLITDUPLEX, create_hostzone, {}, create_limiter)
+  sg4::create_dragonfly_zone("cluster", nullptr, {{2, 2}, {2, 1}, {2, 2}, 2}, {create_hostzone, {}, create_limiter},
+                             10e9, 10e-6, sg4::Link::SharingPolicy::SPLITDUPLEX)
       ->seal();
 }
 
index fb6a615..1280241 100644 (file)
@@ -115,10 +115,8 @@ public:
   }
   /** Fill the leaf retriving netpoint from a user's callback */
   void fill_leaf_from_cb(unsigned int position, const std::vector<unsigned int>& dimensions,
-                         const std::function<s4u::ClusterNetPointCb>& set_netpoint_cb,
-                         const std::function<s4u::ClusterLinkCb>& set_loopback_cb,
-                         const std::function<s4u::ClusterLinkCb>& set_limiter_cb, NetPoint** node_netpoint,
-                         s4u::Link** lb_link, s4u::Link** limiter_link);
+                         const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint, s4u::Link** lb_link,
+                         s4u::Link** limiter_link);
 };
 } // namespace routing
 } // namespace kernel
index fbfd798..9d6273e 100644 (file)
@@ -27,7 +27,7 @@ class XBT_PRIVATE TorusZone : public ClusterZone {
 
 public:
   using ClusterZone::ClusterZone;
-  void create_links_for_node(int id, int rank, unsigned int position);
+  void create_links(int id, int rank, unsigned int position);
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void set_topology(const std::vector<unsigned int>& dimensions);
 
index 3b41276..085788e 100644 (file)
@@ -146,35 +146,48 @@ private:
 
 // External constructors so that the types (and the types of their content) remain hidden
 XBT_PUBLIC NetZone* create_full_zone(const std::string& name);
-XBT_PUBLIC NetZone* create_cluster_zone(const std::string& name);
 XBT_PUBLIC NetZone* create_star_zone(const std::string& name);
 XBT_PUBLIC NetZone* create_dijkstra_zone(const std::string& name, bool cache);
 XBT_PUBLIC NetZone* create_empty_zone(const std::string& name);
 XBT_PUBLIC NetZone* create_floyd_zone(const std::string& name);
 XBT_PUBLIC NetZone* create_vivaldi_zone(const std::string& name);
 XBT_PUBLIC NetZone* create_wifi_zone(const std::string& name);
-/**
- * @brief Callback used to set the netpoint and gateway located at some leaf of clusters (Torus, FatTree, etc)
- *
- * The netpoint can be either a host, router or another netzone.
- * Gateway must be non-null if netpoint is a netzone
- *
- * @param zone: The newly create zone, needed for creating new resources (hosts, links)
- * @param coord: the coordinates of the element
- * @param id: Internal identifier of the element
- * @return pair<NetPoint*, NetPoint*>: returns a pair of netpoint and gateway.
- */
-using ClusterNetPointCb = std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>(
-    NetZone* zone, const std::vector<unsigned int>& coord, int id);
-/**
- * @brief Callback used to set the links for some leaf of the cluster (Torus, FatTree, etc)
- *
- * @param zone: The newly create zone, needed for creating new resources (hosts, links)
- * @param coord: the coordinates of the element
- * @param id: Internal identifier of the element
- * @return Pointer to the Link
- */
-using ClusterLinkCb = Link*(NetZone* zone, const std::vector<unsigned int>& coord, int id);
+
+// Extra data structure for complex constructors
+
+/** @brief Aggregates the callbacks used to build clusters netzones (Torus/Dragronfly/Fat-Tree) */
+struct ClusterCallbacks {
+  /**
+   * @brief Callback used to set the netpoint and gateway located at some leaf of clusters (Torus, FatTree, etc)
+   *
+   * The netpoint can be either a host, router or another netzone.
+   * Gateway must be non-null if netpoint is a netzone
+   *
+   * @param zone: The newly create zone, needed for creating new resources (hosts, links)
+   * @param coord: the coordinates of the element
+   * @param id: Internal identifier of the element
+   * @return pair<NetPoint*, NetPoint*>: returns a pair of netpoint and gateway.
+   */
+  using ClusterNetPointCb = std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>(
+      NetZone* zone, const std::vector<unsigned int>& coord, int id);
+  /**
+   * @brief Callback used to set the links for some leaf of the cluster (Torus, FatTree, etc)
+   *
+   * @param zone: The newly create zone, needed for creating new resources (hosts, links)
+   * @param coord: the coordinates of the element
+   * @param id: Internal identifier of the element
+   * @return Pointer to the Link
+   */
+  using ClusterLinkCb = Link*(NetZone* zone, const std::vector<unsigned int>& coord, int id);
+
+  std::function<ClusterNetPointCb> netpoint;
+  std::function<ClusterLinkCb> loopback = {};
+  std::function<ClusterLinkCb> limiter  = {};
+  explicit ClusterCallbacks(std::function<ClusterNetPointCb> set_netpoint) : netpoint(set_netpoint){/*nothing to do */};
+  ClusterCallbacks(std::function<ClusterNetPointCb> set_netpoint, std::function<ClusterLinkCb> set_loopback,
+                   std::function<ClusterLinkCb> set_limiter)
+      : netpoint(set_netpoint), loopback(set_loopback), limiter(set_limiter){/*nothing to do */};
+};
 /**
  * @brief Create a torus zone
  *
@@ -194,20 +207,16 @@ using ClusterLinkCb = Link*(NetZone* zone, const std::vector<unsigned int>& coor
  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
  * the netzone
  * @param dimensions List of positive integers (> 0) which determines the torus' dimensions
+ * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
  * @param bandwidth Characteristics of the inter-nodes link
  * @param latency Characteristics of the inter-nodes link
  * @param sharing_policy Characteristics of the inter-nodes link
- * @param set_netpoint Callback to set the netpoint of an element in the torus
- * @param set_loopback Callback to set the loopback
- * @param set_limiter Callback to set the limiter
  * @return Pointer to new netzone
  */
 XBT_PUBLIC NetZone* create_torus_zone(const std::string& name, const NetZone* parent,
-                                      const std::vector<unsigned int>& dimensions, double bandwidth, double latency,
-                                      Link::SharingPolicy sharing_policy,
-                                      const std::function<ClusterNetPointCb>& set_netpoint,
-                                      const std::function<ClusterLinkCb>& set_loopback = {},
-                                      const std::function<ClusterLinkCb>& set_limiter  = {});
+                                      const std::vector<unsigned int>& dimensions,
+                                      const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
+                                      Link::SharingPolicy sharing_policy);
 
 /** @brief Aggregates the parameters necessary to build a Fat-tree zone */
 struct FatTreeParams {
@@ -239,19 +248,15 @@ struct FatTreeParams {
  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
  * the netzone
  * @param parameters Characteristics of this Fat-Tree
+ * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
  * @param bandwidth Characteristics of the inter-nodes link
  * @param latency Characteristics of the inter-nodes link
  * @param sharing_policy Characteristics of the inter-nodes link
- * @param set_netpoint Callback to set the netpoint of an element in the torus
- * @param set_loopback Callback to set the loopback
- * @param set_limiter Callback to set the limiter
  * @return Pointer to new netzone
  */
 XBT_PUBLIC NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, const FatTreeParams& parameters,
-                                        double bandwidth, double latency, Link::SharingPolicy sharing_policy,
-                                        const std::function<ClusterNetPointCb>& set_netpoint,
-                                        const std::function<ClusterLinkCb>& set_loopback = {},
-                                        const std::function<ClusterLinkCb>& set_limiter  = {});
+                                        const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
+                                        Link::SharingPolicy sharing_policy);
 
 /** @brief Aggregates the parameters necessary to build a Dragonfly zone */
 struct DragonflyParams {
@@ -285,20 +290,15 @@ struct DragonflyParams {
  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
  * the netzone
  * @param parameters Characteristics of this Dragonfly
+ * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
  * @param bandwidth Characteristics of the inter-nodes link
  * @param latency Characteristics of the inter-nodes link
  * @param sharing_policy Characteristics of the inter-nodes link
- * @param set_netpoint Callback to set the netpoint of an element in the torus
- * @param set_loopback Callback to set the loopback
- * @param set_limiter Callback to set the limiter
  * @return Pointer to new netzone
  */
 XBT_PUBLIC NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent,
-                                          const DragonflyParams& parameters, double bandwidth, double latency,
-                                          Link::SharingPolicy sharing_policy,
-                                          const std::function<ClusterNetPointCb>& set_netpoint,
-                                          const std::function<ClusterLinkCb>& set_loopback = {},
-                                          const std::function<ClusterLinkCb>& set_limiter  = {});
+                                          const DragonflyParams& parameters, const ClusterCallbacks& set_callbacks,
+                                          double bandwidth, double latency, Link::SharingPolicy sharing_policy);
 
 } // namespace s4u
 } // namespace simgrid
index fc35ba1..5d31b78 100644 (file)
@@ -175,9 +175,7 @@ NetPoint* ClusterZone::get_gateway(unsigned int position)
 }
 
 void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector<unsigned int>& dimensions,
-                                    const std::function<s4u::ClusterNetPointCb>& set_netpoint_cb,
-                                    const std::function<s4u::ClusterLinkCb>& set_loopback_cb,
-                                    const std::function<s4u::ClusterLinkCb>& set_limiter_cb, NetPoint** node_netpoint,
+                                    const s4u::ClusterCallbacks& set_callbacks, NetPoint** node_netpoint,
                                     s4u::Link** lb_link, s4u::Link** limiter_link)
 {
   xbt_assert(node_netpoint, "Invalid node_netpoint parameter");
@@ -203,7 +201,7 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector<uns
   kernel::routing::NetPoint* netpoint = nullptr;
   kernel::routing::NetPoint* gw       = nullptr;
   auto dims                           = index_to_dims(position);
-  std::tie(netpoint, gw)              = set_netpoint_cb(get_iface(), dims, position);
+  std::tie(netpoint, gw)              = set_callbacks.netpoint(get_iface(), dims, position);
   xbt_assert(netpoint, "set_netpoint(elem=%u): Invalid netpoint (nullptr)", position);
   if (netpoint->is_netzone()) {
     xbt_assert(gw && not gw->is_netzone(),
@@ -215,16 +213,16 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector<uns
   // setting gateway
   set_gateway(position, gw);
 
-  if (set_loopback_cb) {
-    s4u::Link* loopback = set_loopback_cb(get_iface(), dims, position);
+  if (set_callbacks.loopback) {
+    s4u::Link* loopback = set_callbacks.loopback(get_iface(), dims, position);
     xbt_assert(loopback, "set_loopback: Invalid loopback link (nullptr) for element %u", position);
     set_loopback();
     add_private_link_at(node_pos(netpoint->id()), {loopback->get_impl(), loopback->get_impl()});
     *lb_link = loopback;
   }
 
-  if (set_limiter_cb) {
-    s4u::Link* limiter = set_limiter_cb(get_iface(), dims, position);
+  if (set_callbacks.limiter) {
+    s4u::Link* limiter = set_callbacks.limiter(get_iface(), dims, position);
     xbt_assert(limiter, "set_limiter: Invalid limiter link (nullptr) for element %u", position);
     set_limiter();
     add_private_link_at(node_pos_with_loopback(netpoint->id()), {limiter->get_impl(), limiter->get_impl()});
@@ -235,12 +233,4 @@ void ClusterZone::fill_leaf_from_cb(unsigned int position, const std::vector<uns
 
 } // namespace routing
 } // namespace kernel
-
-namespace s4u {
-NetZone* create_cluster_zone(const std::string& name)
-{
-  return (new kernel::routing::ClusterZone(name))->get_iface();
-}
-} // namespace s4u
-
 } // namespace simgrid
index 4a72dee..f6e7d95 100644 (file)
@@ -390,10 +390,8 @@ DragonflyParams::DragonflyParams(const std::pair<unsigned int, unsigned int>& gr
 }
 
 NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent, const DragonflyParams& params,
-                               double bandwidth, double latency, Link::SharingPolicy sharing_policy,
-                               const std::function<ClusterNetPointCb>& set_netpoint,
-                               const std::function<ClusterLinkCb>& set_loopback,
-                               const std::function<ClusterLinkCb>& set_limiter)
+                               const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
+                               Link::SharingPolicy sharing_policy)
 {
   /* initial checks */
   if (bandwidth <= 0)
@@ -419,7 +417,7 @@ NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent, c
     kernel::routing::NetPoint* netpoint;
     Link* limiter;
     Link* loopback;
-    zone->fill_leaf_from_cb(i, dimensions, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter);
+    zone->fill_leaf_from_cb(i, dimensions, set_callbacks, &netpoint, &loopback, &limiter);
   }
 
   return zone->get_iface();
index 254680c..0f0edb1 100644 (file)
@@ -32,74 +32,76 @@ TEST_CASE("kernel::routing::DragonflyZone: Creating Zone", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
-  REQUIRE(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10,
-                                simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
+  ClusterCallbacks callbacks(create_host);
+  REQUIRE(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, 10,
+                                simgrid::s4u::Link::SharingPolicy::SHARED));
 }
 
 TEST_CASE("kernel::routing::DragonflyZone: Invalid params", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
+  ClusterCallbacks callbacks(create_host);
 
   SECTION("0 nodes")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 0}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 0}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 groups")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{0, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{0, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
   SECTION("0 groups links")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 0}, {4, 3}, {5, 1}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 0}, {4, 3}, {5, 1}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 chassis")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {0, 3}, {5, 1}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {0, 3}, {5, 1}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 chassis links")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 0}, {5, 1}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 0}, {5, 1}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 routers")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {0, 1}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {0, 1}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 routers links")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 0}, 2}, 1e9, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 0}, 2}, callbacks, 1e9,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 bandwidth")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 0, 10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 0,
+                                            10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Negative latency")
   {
-    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, -10,
-                                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9,
+                                            -10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 }
\ No newline at end of file
index 5bda963..5613a21 100644 (file)
@@ -500,10 +500,8 @@ FatTreeParams::FatTreeParams(unsigned int n_levels, const std::vector<unsigned i
 }
 
 NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, const FatTreeParams& params,
-                             double bandwidth, double latency, Link::SharingPolicy sharing_policy,
-                             const std::function<ClusterNetPointCb>& set_netpoint,
-                             const std::function<ClusterLinkCb>& set_loopback,
-                             const std::function<ClusterLinkCb>& set_limiter)
+                             const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
+                             Link::SharingPolicy sharing_policy)
 {
   /* initial checks */
   if (bandwidth <= 0)
@@ -526,7 +524,7 @@ NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, con
     kernel::routing::NetPoint* netpoint;
     Link* limiter;
     Link* loopback;
-    zone->fill_leaf_from_cb(i, params.down, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter);
+    zone->fill_leaf_from_cb(i, params.down, set_callbacks, &netpoint, &loopback, &limiter);
     zone->add_processing_node(i, limiter ? limiter->get_impl() : nullptr, loopback ? loopback->get_impl() : nullptr);
   }
 
index a1923f9..171314f 100644 (file)
@@ -32,75 +32,77 @@ TEST_CASE("kernel::routing::FatTreeZone: Creating Zone", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
-  REQUIRE(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 1e9, 10,
-                              simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
+  ClusterCallbacks callbacks(create_host);
+  REQUIRE(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
+                              simgrid::s4u::Link::SharingPolicy::SHARED));
 }
 
 TEST_CASE("kernel::routing::FatTreeZone: Invalid params", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
+  ClusterCallbacks callbacks(create_host);
 
   SECTION("0 levels")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {0, {4, 4}, {1, 2}, {1, 2}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {0, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9,
+                                          10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Invalid down links")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4}, {1, 2}, {1, 2}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
+                                          simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Invalid up links")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1}, {1, 2}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1}, {1, 2}}, callbacks, 1e9, 10,
+                                          simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Invalid link count")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1}}, callbacks, 1e9, 10,
+                                          simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Down links with zeroes")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 0}, {1, 2}, {1, 2}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 0}, {1, 2}, {1, 2}}, callbacks, 1e9,
+                                          10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Up links with zeroes")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {0, 2}, {1, 2}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {0, 2}, {1, 2}}, callbacks, 1e9,
+                                          10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Link count with zeroes")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 0}}, 1e9, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 0}}, callbacks, 1e9,
+                                          10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("0 bandwidth")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 0, 10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 0, 10,
+                                          simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 
   SECTION("Negative latency")
   {
-    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, 1e9, -10,
-                                          simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_fatTree_zone("test", e.e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9,
+                                          -10, simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 }
\ No newline at end of file
index f8bf90a..793e9a6 100644 (file)
@@ -21,7 +21,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-void TorusZone::create_links_for_node(int id, int rank, unsigned int position)
+void TorusZone::create_links(int id, int rank, unsigned int position)
 {
   /* Create all links that exist in the torus. Each rank creates @a dimensions-1 links */
   int dim_product = 1; // Needed to calculate the next neighbor_id
@@ -197,10 +197,8 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
 namespace s4u {
 
 NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const std::vector<unsigned int>& dimensions,
-                           double bandwidth, double latency, Link::SharingPolicy sharing_policy,
-                           const std::function<ClusterNetPointCb>& set_netpoint,
-                           const std::function<ClusterLinkCb>& set_loopback,
-                           const std::function<ClusterLinkCb>& set_limiter)
+                           const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
+                           Link::SharingPolicy sharing_policy)
 {
   int tot_elements = std::accumulate(dimensions.begin(), dimensions.end(), 1, std::multiplies<>());
   if (dimensions.empty() || tot_elements <= 0)
@@ -223,9 +221,9 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const
     kernel::routing::NetPoint* netpoint;
     Link* limiter;
     Link* loopback;
-    zone->fill_leaf_from_cb(i, dimensions, set_netpoint, set_loopback, set_limiter, &netpoint, &loopback, &limiter);
+    zone->fill_leaf_from_cb(i, dimensions, set_callbacks, &netpoint, &loopback, &limiter);
 
-    zone->create_links_for_node(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id()));
+    zone->create_links(netpoint->id(), i, zone->node_pos_with_loopback_limiter(netpoint->id()));
   }
 
   return zone->get_iface();
index 4bc09ca..526794d 100644 (file)
@@ -32,37 +32,39 @@ TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
-  REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10,
-                            simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
+  ClusterCallbacks callbacks(create_host);
+  REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, callbacks, 1e9, 10,
+                            simgrid::s4u::Link::SharingPolicy::SHARED));
 }
 
 TEST_CASE("kernel::routing::TorusZone: Invalid params", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
+  ClusterCallbacks callbacks(create_host);
 
   SECTION("Empty dimensions")
   {
-    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, 1e9, 10,
-                                        simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, callbacks, 1e9, 10,
+                                        simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
   SECTION("One 0 dimension")
   {
-    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, 1e9, 10,
-                                        simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, callbacks, 1e9, 10,
+                                        simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
   SECTION("Invalid bandwidth")
   {
-    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 0, 10,
-                                        simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, callbacks, 0, 10,
+                                        simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
   SECTION("Invalid latency")
   {
-    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 1e9, -10,
-                                        simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
+    REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, callbacks, 1e9, -10,
+                                        simgrid::s4u::Link::SharingPolicy::SHARED),
                       std::invalid_argument);
   }
 }
\ No newline at end of file
index cf04a3b..4df101c 100644 (file)
@@ -217,8 +217,8 @@ static void sg_platf_new_cluster_hierarchical(const simgrid::kernel::routing::Cl
   using simgrid::kernel::routing::TorusZone;
 
   auto set_host = std::bind(sg_platf_cluster_create_host, cluster, _1, _2, _3);
-  std::function<simgrid::s4u::ClusterLinkCb> set_loopback{};
-  std::function<simgrid::s4u::ClusterLinkCb> set_limiter{};
+  std::function<simgrid::s4u::ClusterCallbacks::ClusterLinkCb> set_loopback{};
+  std::function<simgrid::s4u::ClusterCallbacks::ClusterLinkCb> set_limiter{};
 
   if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
     set_loopback = std::bind(sg_platf_cluster_create_loopback, cluster, _1, _2, _3);
@@ -233,18 +233,18 @@ static void sg_platf_new_cluster_hierarchical(const simgrid::kernel::routing::Cl
   switch (cluster->topology) {
     case simgrid::kernel::routing::ClusterTopology::TORUS:
       zone = simgrid::s4u::create_torus_zone(
-          cluster->id, parent, TorusZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw, cluster->lat,
-          cluster->sharing_policy, set_host, set_loopback, set_limiter);
+          cluster->id, parent, TorusZone::parse_topo_parameters(cluster->topo_parameters),
+          {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy);
       break;
     case simgrid::kernel::routing::ClusterTopology::DRAGONFLY:
       zone = simgrid::s4u::create_dragonfly_zone(
-          cluster->id, parent, DragonflyZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw,
-          cluster->lat, cluster->sharing_policy, set_host, set_loopback, set_limiter);
+          cluster->id, parent, DragonflyZone::parse_topo_parameters(cluster->topo_parameters),
+          {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy);
       break;
     case simgrid::kernel::routing::ClusterTopology::FAT_TREE:
       zone = simgrid::s4u::create_fatTree_zone(
-          cluster->id, parent, FatTreeZone::parse_topo_parameters(cluster->topo_parameters), cluster->bw, cluster->lat,
-          cluster->sharing_policy, set_host, set_loopback, set_limiter);
+          cluster->id, parent, FatTreeZone::parse_topo_parameters(cluster->topo_parameters),
+          {set_host, set_loopback, set_limiter}, cluster->bw, cluster->lat, cluster->sharing_policy);
       break;
     default:
       THROW_IMPOSSIBLE;