Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SplitDuplexLinkImpl always have SharingPolicy::SPLITDUPLEX. Use a sdingle assert...
[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
42     /* add link UP and backbone for communications from the host */
43     cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, std::vector<sg4::LinkInRoute>{l_up, l_bb},
44                        false);
45     /* add backbone and link DOWN for communications to the host */
46     cluster->add_route(nullptr, host->get_netpoint(), nullptr, nullptr, std::vector<sg4::LinkInRoute>{l_bb, l_down},
47                        false);
48   }
49
50   /* create router */
51   cluster->create_router("router" + cluster_suffix);
52
53   cluster->seal();
54 }
55
56 /** @brief Programmatic version of routing_cluster.xml */
57 extern "C" void load_platform(const sg4::Engine& e);
58 void load_platform(const sg4::Engine& e)
59 {
60   /**
61    *
62    * Target platform: 2 simular but irregular clusters.
63    * Nodes use full-duplex links to connect to the backbone, except one node that uses a single
64    * shared link.
65
66    *                  router1 - - - - - - link1-2 - - - - - - router2
67    *       __________________________                   _________________________
68    *       |                        |                   |                        |
69    *       |        backbone1       |                   |      backbone2         |
70    *       |________________________|                   |________________________|
71    *       / /         |          \ \                   / /         |          \ \
72    *l1_up / / l1_down  | l3   l2_up\ \ l2_down   l4_up / / l4_down  | l6   l5_up\ \ l5_down
73    *     / /           |            \ \               / /           |            \ \
74    *   host1         host3         host2           host4         host6          host5
75    */
76
77   auto* root = sg4::create_full_zone("AS0");
78
79   /* create left cluster */
80   create_cluster(root, "1", {"host1", "host2", "host3"}, "host3");
81   /* create right cluster */
82   create_cluster(root, "2", {"host4", "host5", "host6"}, "host6");
83
84   /* connect both cluster through their respective routers */
85   const sg4::Link* link = root->create_link("link1-2", std::vector<double>{2.25e9})->set_latency(5e-4)->seal();
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 }