1 /* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u.hpp>
7 namespace sg4 = simgrid::s4u;
10 * @brief Create a new cluster netzone inside the root netzone
12 * This function creates the cluster, adding the hosts and links properly.
14 * @param root Root netzone
15 * @param cluster_suffix ID of the cluster being created
16 * @param host List of hostname inside the cluster
17 * @param single_link_host Hostname of "special" node
19 static sg4::NetZone* create_cluster(const sg4::NetZone* root, const std::string& cluster_suffix,
20 const std::vector<std::string>& hosts, const std::string& single_link_host)
22 auto* cluster = sg4::create_star_zone("cluster" + cluster_suffix)->set_parent(root);
24 /* create the backbone link */
25 const sg4::Link* l_bb = cluster->create_link("backbone" + cluster_suffix, "20Gbps")->set_latency("500us");
27 /* create all hosts and connect them to outside world */
28 for (const auto& hostname : hosts) {
30 const sg4::Host* host = cluster->create_host(hostname, "1Gf");
32 const sg4::Link* l_up = cluster->create_link(hostname + "_up", "1Gbps")->set_latency("100us");
33 /* create DOWN link, if needed */
34 const sg4::Link* l_down = l_up;
35 if (hostname != single_link_host) {
36 l_down = cluster->create_link(hostname + "_down", "1Gbps")->set_latency("100us");
38 sg4::LinkInRoute backbone{l_bb};
39 sg4::LinkInRoute link_up{l_up};
40 sg4::LinkInRoute link_down{l_down};
42 /* add link UP and backbone for communications from the host */
43 cluster->add_route(host, nullptr, {link_up, backbone}, false);
44 /* add backbone and link DOWN for communications to the host */
45 cluster->add_route(nullptr, host, {backbone, link_down}, false);
49 cluster->set_gateway(cluster->create_router("router" + cluster_suffix));
55 /** @brief Programmatic version of routing_cluster.xml */
56 extern "C" void load_platform(const sg4::Engine& e);
57 void load_platform(const sg4::Engine& e)
61 * Target platform: 2 simular but irregular clusters.
62 * Nodes use full-duplex links to connect to the backbone, except one node that uses a single
65 * router1 - - - - - - link1-2 - - - - - - router2
66 * __________________________ _________________________
68 * | backbone1 | | backbone2 |
69 * |________________________| |________________________|
71 *l1_up / / l1_down | l3 l2_up\ \ l2_down l4_up / / l4_down | l6 l5_up\ \ l5_down
73 * host1 host3 host2 host4 host6 host5
76 auto* root = sg4::create_full_zone("AS0");
78 /* create left cluster */
79 auto* left_cluster = create_cluster(root, "1", {"host1", "host2", "host3"}, "host3");
80 /* create right cluster */
81 auto* right_cluster = create_cluster(root, "2", {"host4", "host5", "host6"}, "host6");
83 /* connect both clusters */
84 const sg4::Link* l = root->create_link("link1-2", "20Gbps")->set_latency("500us");
85 sg4::LinkInRoute link{l};
86 root->add_route(left_cluster, right_cluster, {link});