Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / platforms / griffon.cpp
1 /* Copyright (c) 2006-2022. 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 <numeric>
7 #include <simgrid/s4u.hpp>
8 namespace sg4 = simgrid::s4u;
9
10 /**
11  * @brief Create a new cabinet
12  *
13  * This function creates the cabinet, adding the hosts and links properly.
14  * See figure below for more details of each cabinet
15  *
16  * @param root Root netzone
17  * @param name Cabinet name
18  * @param radicals IDs of nodes inside the cabinet
19  * @return netzone,router the created netzone and its router
20  */
21 static std::pair<sg4::NetZone*, simgrid::kernel::routing::NetPoint*>
22 create_cabinet(const sg4::NetZone* root, const std::string& name, const std::vector<int>& radicals)
23 {
24   auto* cluster      = sg4::create_star_zone(name);
25   std::string prefix = "griffon-";
26   std::string suffix = ".nancy.grid5000.fr";
27   cluster->set_parent(root);
28
29   /* create the backbone link */
30   const sg4::Link* l_bb = cluster->create_link("backbone-" + name, "1.25GBps")->seal();
31   sg4::LinkInRoute backbone(l_bb);
32
33   /* create all hosts and connect them to outside world */
34   for (const auto& id : radicals) {
35     std::string hostname = prefix + std::to_string(id) + suffix;
36     /* create host */
37     const sg4::Host* host = cluster->create_host(hostname, "286.087kf");
38     /* create UP/DOWN link */
39     const sg4::Link* link = cluster->create_split_duplex_link(hostname, "125MBps")->set_latency("24us")->seal();
40
41     /* add link and backbone for communications from the host */
42     cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr,
43                        {{link, sg4::LinkInRoute::Direction::UP}, backbone}, true);
44   }
45
46   /* create router */
47   auto* router = cluster->create_router(prefix + name + "-router" + suffix);
48
49   cluster->seal();
50   return std::make_pair(cluster, router);
51 }
52
53 /** @brief Programmatic version of griffon.xml */
54 extern "C" void load_platform(const sg4::Engine& e);
55 void load_platform(const sg4::Engine& /*e*/)
56 {
57   /**
58    * C++ version of griffon.xml
59    * Old Grid5000 cluster (not available anymore): 3 cabinets containing homogeneous nodes connected through a backbone
60    *                                  1.25GBps shared link
61    *                          ___________________________________
62    *          1              /                |                  \
63    *                        /                 |                   \
64    *                       /                  |                    \
65    *     ________________ /             ______|__________           \_________________
66    *     |               |              |               |            |               |
67    *     | cab1 router   |              | cab2 router   |            | cab3 router   |
68    *     |_______________|              |_______________|            |_______________|
69    *     ++++++++++++++++               ++++++++++++++++             ++++++++++++++++++  <-- 1.25 backbone
70    *     / /   | |    \ \              / /    | |    \ \             / /     | |     \ \
71    *    / /    | |     \ \            / /     | |     \ \           / /      | |      \ \ <-- 125Mbps links
72    *   / /     | |      \ \          / /      | |      \ \         / /       | |       \ \
73    * host1     ...      hostN      host1      ...      hostM      host1      ...       hostQ
74    */
75
76   auto* root = sg4::create_star_zone("AS_griffon");
77   sg4::NetZone* cab_zone;
78   simgrid::kernel::routing::NetPoint* router;
79
80   /* create top link */
81   const sg4::Link* l_bb = root->create_link("backbone", "1.25GBps")->set_latency("24us")->seal();
82   sg4::LinkInRoute backbone{l_bb};
83
84   /* create cabinet1 */
85   std::vector<int> rad(32);
86   std::iota(rad.begin(), rad.end(), 1); // 1-29,58,59,60
87   rad[rad.size() - 1]        = 60;
88   rad[rad.size() - 2]        = 59;
89   rad[rad.size() - 3]        = 58;
90   std::tie(cab_zone, router) = create_cabinet(root, "cabinet1", rad);
91   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {backbone});
92
93   /* create cabinet2 */
94   rad.resize(28);
95   std::iota(rad.begin(), rad.end(), 30); // 30-57
96   std::tie(cab_zone, router) = create_cabinet(root, "cabinet2", rad);
97   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {backbone});
98
99   /* create cabinet3 */
100   rad.resize(32);
101   std::iota(rad.begin(), rad.end(), 61); // 61-92
102   std::tie(cab_zone, router) = create_cabinet(root, "cabinet3", rad);
103   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {backbone});
104
105   root->seal();
106 }