+
+/** @brief Auxiliary function to create hosts */
+static std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>
+create_torus_host(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
+ const std::vector<unsigned int>& coord, int id)
+{
+ std::string host_id = std::string(cluster->prefix) + std::to_string(id) + cluster->suffix;
+ XBT_DEBUG("TorusCluster: creating host=%s speed=%f", host_id.c_str(), cluster->speeds.front());
+ s4u::Host* host = zone->create_host(host_id, cluster->speeds)
+ ->set_core_count(cluster->core_amount)
+ ->set_properties(cluster->properties)
+ ->seal();
+ return std::make_pair(host->get_netpoint(), nullptr);
+}
+
+/** @brief Auxiliary function to create loopback links */
+static s4u::Link* create_torus_loopback(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
+ const std::vector<unsigned int>& coord, int id)
+{
+ std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id) + "_loopback";
+ XBT_DEBUG("TorusCluster: creating loopback link=%s bw=%f", link_id.c_str(), cluster->loopback_bw);
+
+ s4u::Link* loopback = zone->create_link(link_id, cluster->loopback_bw)
+ ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE)
+ ->set_latency(cluster->loopback_lat)
+ ->seal();
+ return loopback;
+}
+
+/** @brief Auxiliary function to create limiter links */
+static s4u::Link* create_torus_limiter(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
+ const std::vector<unsigned int>& coord, int id)
+{
+ std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id) + "_limiter";
+ XBT_DEBUG("TorusCluster: creating limiter link=%s bw=%f", link_id.c_str(), cluster->limiter_link);
+
+ s4u::Link* limiter = zone->create_link(link_id, cluster->limiter_link)->seal();
+ return limiter;
+}
+
+s4u::NetZone* create_torus_zone_with_hosts(const kernel::routing::ClusterCreationArgs* cluster,
+ const s4u::NetZone* parent)
+{
+ using namespace std::placeholders;
+ auto set_host = std::bind(create_torus_host, cluster, _1, _2, _3);
+ std::function<s4u::TorusLinkCb> set_loopback{};
+ std::function<s4u::TorusLinkCb> set_limiter{};
+
+ if (cluster->loopback_bw > 0 || cluster->loopback_lat > 0) {
+ set_loopback = std::bind(create_torus_loopback, cluster, _1, _2, _3);
+ }
+
+ if (cluster->limiter_link > 0) {
+ set_loopback = std::bind(create_torus_limiter, cluster, _1, _2, _3);
+ }
+
+ return 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);
+}
+