Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make single argument constructor LinkInRoute::LinkInRoute(const Link*) explicit.
[simgrid.git] / examples / platforms / routing_cluster.cpp
1 /* Copyright (c) 2006-2021. 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 =
27       cluster->create_link("backbone" + cluster_suffix, std::vector<double>{2.25e9})->set_latency(5e-4)->seal();
28
29   /* create all hosts and connect them to outside world */
30   for (const auto& hostname : hosts) {
31     /* create host */
32     const sg4::Host* host = cluster->create_host(hostname, std::vector<double>{1e9});
33     /* create UP link */
34     const sg4::Link* l_up =
35         cluster->create_link(hostname + "_up", std::vector<double>{1.25e8})->set_latency(0.0001)->seal();
36     /* create DOWN link, if needed */
37     const sg4::Link* l_down = l_up;
38     if (hostname != single_link_host) {
39       l_down = cluster->create_link(hostname + "_down", std::vector<double>{1.25e8})->set_latency(0.0001)->seal();
40     }
41     sg4::LinkInRoute backbone{l_bb};
42     sg4::LinkInRoute link_up{l_up};
43     sg4::LinkInRoute link_down{l_down};
44
45     /* add link UP and backbone for communications from the host */
46     cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, {link_up, backbone}, false);
47     /* add backbone and link DOWN for communications to the host */
48     cluster->add_route(nullptr, host->get_netpoint(), nullptr, nullptr, {backbone, link_down}, false);
49   }
50
51   /* create router */
52   cluster->create_router("router" + cluster_suffix);
53
54   cluster->seal();
55 }
56
57 /** @brief Programmatic version of routing_cluster.xml */
58 extern "C" void load_platform(const sg4::Engine& e);
59 void load_platform(const sg4::Engine& e)
60 {
61   /**
62    *
63    * Target platform: 2 simular but irregular clusters.
64    * Nodes use full-duplex links to connect to the backbone, except one node that uses a single
65    * shared link.
66
67    *                  router1 - - - - - - link1-2 - - - - - - router2
68    *       __________________________                   _________________________
69    *       |                        |                   |                        |
70    *       |        backbone1       |                   |      backbone2         |
71    *       |________________________|                   |________________________|
72    *       / /         |          \ \                   / /         |          \ \
73    *l1_up / / l1_down  | l3   l2_up\ \ l2_down   l4_up / / l4_down  | l6   l5_up\ \ l5_down
74    *     / /           |            \ \               / /           |            \ \
75    *   host1         host3         host2           host4         host6          host5
76    */
77
78   auto* root = sg4::create_full_zone("AS0");
79
80   /* create left cluster */
81   create_cluster(root, "1", {"host1", "host2", "host3"}, "host3");
82   /* create right cluster */
83   create_cluster(root, "2", {"host4", "host5", "host6"}, "host6");
84
85   /* connect both cluster through their respective routers */
86   const sg4::Link* l = root->create_link("link1-2", std::vector<double>{2.25e9})->set_latency(5e-4)->seal();
87   sg4::LinkInRoute link{l};
88   root->add_route(e.netpoint_by_name_or_null("cluster1"), e.netpoint_by_name_or_null("cluster2"),
89                   e.netpoint_by_name_or_null("router1"), e.netpoint_by_name_or_null("router2"), {link});
90
91   root->seal();
92 }