1 /* Copyright (c) 2006-2022. 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 void 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);
23 cluster->set_parent(root);
25 /* create the backbone link */
26 const sg4::Link* l_bb = cluster->create_link("backbone" + cluster_suffix, 2.25e9)->set_latency(5e-4)->seal();
28 /* create all hosts and connect them to outside world */
29 for (const auto& hostname : hosts) {
31 const sg4::Host* host = cluster->create_host(hostname, 1e9);
33 const sg4::Link* l_up = cluster->create_link(hostname + "_up", 1.25e8)->set_latency(0.0001)->seal();
34 /* create DOWN link, if needed */
35 const sg4::Link* l_down = l_up;
36 if (hostname != single_link_host) {
37 l_down = cluster->create_link(hostname + "_down", 1.25e8)->set_latency(0.0001)->seal();
39 sg4::LinkInRoute backbone{l_bb};
40 sg4::LinkInRoute link_up{l_up};
41 sg4::LinkInRoute link_down{l_down};
43 /* add link UP and backbone for communications from the host */
44 cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, {link_up, backbone}, false);
45 /* add backbone and link DOWN for communications to the host */
46 cluster->add_route(nullptr, host->get_netpoint(), nullptr, nullptr, {backbone, link_down}, false);
50 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 create_cluster(root, "1", {"host1", "host2", "host3"}, "host3");
80 /* create right cluster */
81 create_cluster(root, "2", {"host4", "host5", "host6"}, "host6");
83 /* connect both cluster through their respective routers */
84 const sg4::Link* l = root->create_link("link1-2", 2.25e9)->set_latency(5e-4)->seal();
85 sg4::LinkInRoute link{l};
86 root->add_route(e.netpoint_by_name_or_null("cluster1"), e.netpoint_by_name_or_null("cluster2"),
87 e.netpoint_by_name_or_null("router1"), e.netpoint_by_name_or_null("router2"), {link});