1 /* Copyright (c) 2006-2021. 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 */
27 cluster->create_link("backbone" + cluster_suffix, std::vector<double>{2.25e9})->set_latency(5e-4)->seal();
29 /* create all hosts and connect them to outside world */
30 for (const auto& hostname : hosts) {
32 const sg4::Host* host = cluster->create_host(hostname, std::vector<double>{1e9});
34 sg4::Link* l_up = cluster->create_link(hostname + "_up", std::vector<double>{1.25e8})->set_latency(0.0001)->seal();
35 /* create DOWN link, if needed */
36 sg4::Link* l_down = l_up;
37 if (hostname != single_link_host) {
38 l_down = cluster->create_link(hostname + "_down", std::vector<double>{1.25e8})->set_latency(0.0001)->seal();
41 /* add link UP and backbone for communications from the host */
42 cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, std::vector<sg4::Link*>{l_up, l_bb}, false);
43 /* add backbone and link DOWN for communications to the host */
44 cluster->add_route(nullptr, host->get_netpoint(), nullptr, nullptr, std::vector<sg4::Link*>{l_bb, l_down}, false);
48 cluster->create_router("router" + cluster_suffix);
53 /** @brief Programmatic version of routing_cluster.xml */
54 extern "C" void load_platform(const sg4::Engine& e);
55 void load_platform(const sg4::Engine& e)
59 * Target platform: 2 simular but irregular clusters.
60 * Nodes use full-duplex links to connect to the backbone, except one node that uses a single
63 * router1 - - - - - - link1-2 - - - - - - router2
64 * __________________________ _________________________
66 * | backbone1 | | backbone2 |
67 * |________________________| |________________________|
69 *l1_up / / l1_down | l3 l2_up\ \ l2_down l4_up / / l4_down | l6 l5_up\ \ l5_down
71 * host1 host3 host2 host4 host6 host5
74 auto* root = sg4::create_full_zone("AS0");
76 /* create left cluster */
77 create_cluster(root, "1", {"host1", "host2", "host3"}, "host3");
78 /* create right cluster */
79 create_cluster(root, "2", {"host4", "host5", "host6"}, "host6");
81 /* connect both cluster through their respective routers */
82 sg4::Link* link = root->create_link("link1-2", std::vector<double>{2.25e9})->set_latency(5e-4)->seal();
83 root->add_route(e.netpoint_by_name_or_null("cluster1"), e.netpoint_by_name_or_null("cluster2"),
84 e.netpoint_by_name_or_null("router1"), e.netpoint_by_name_or_null("router2"), {link});