Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / examples / platforms / routing_cluster.cpp
1 /* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <simgrid/s4u.hpp>
7 namespace sg4 = simgrid::s4u;
8
9 /**
10  * @brief Create a new cluster netzone inside the root netzone
11  *
12  * This function creates the cluster, adding the hosts and links properly.
13  *
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
18  */
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)
21 {
22   auto* cluster = sg4::create_star_zone("cluster" + cluster_suffix);
23   cluster->set_parent(root);
24
25   /* create the backbone link */
26   const sg4::Link* l_bb = cluster->create_link("backbone" + cluster_suffix, 2.25e9)->set_latency(5e-4)->seal();
27
28   /* create all hosts and connect them to outside world */
29   for (const auto& hostname : hosts) {
30     /* create host */
31     const sg4::Host* host = cluster->create_host(hostname, 1e9);
32     /* create UP link */
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();
38     }
39     sg4::LinkInRoute backbone{l_bb};
40     sg4::LinkInRoute link_up{l_up};
41     sg4::LinkInRoute link_down{l_down};
42
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);
47   }
48
49   /* create router */
50   cluster->create_router("router" + cluster_suffix);
51
52   cluster->seal();
53 }
54
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)
58 {
59   /**
60    *
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
63    * shared link.
64
65    *                  router1 - - - - - - link1-2 - - - - - - router2
66    *       __________________________                   _________________________
67    *       |                        |                   |                        |
68    *       |        backbone1       |                   |      backbone2         |
69    *       |________________________|                   |________________________|
70    *       / /         |          \ \                   / /         |          \ \
71    *l1_up / / l1_down  | l3   l2_up\ \ l2_down   l4_up / / l4_down  | l6   l5_up\ \ l5_down
72    *     / /           |            \ \               / /           |            \ \
73    *   host1         host3         host2           host4         host6          host5
74    */
75
76   auto* root = sg4::create_full_zone("AS0");
77
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");
82
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});
88
89   root->seal();
90 }