Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d326305dd1886c6f2a41a3b1ec0bf5b4a7e04720
[simgrid.git] / examples / platforms / griffon.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 <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   sg4::Link* l_bb = cluster->create_link("backbone-" + name, "1.25GBps")->seal();
31
32   /* create all hosts and connect them to outside world */
33   for (const auto& id : radicals) {
34     std::string hostname = prefix + std::to_string(id) + suffix;
35     /* create host */
36     const sg4::Host* host = cluster->create_host(hostname, "286.087kf");
37     /* create UP/DOWN link */
38     sg4::Link* l_up   = cluster->create_link(hostname + "_up", "125MBps")->set_latency("24us")->seal();
39     sg4::Link* l_down = cluster->create_link(hostname + "_down", "125MBps")->set_latency("24us")->seal();
40
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);
45   }
46
47   /* create router */
48   auto* router = cluster->create_router(prefix + name + "-router" + suffix);
49
50   cluster->seal();
51   return std::make_pair(cluster, router);
52 }
53
54 /** @brief Programmatic version of griffon.xml */
55 extern "C" void load_platform(const sg4::Engine& e);
56 void load_platform(const sg4::Engine& /*e*/)
57 {
58   /**
59    * C++ version of griffon.xml
60    * Old Grid5000 cluster (not available anymore): 3 cabinets containing homogeneous nodes connected through a backbone
61    *                                  1.25GBps shared link
62    *                          ___________________________________
63    *          1              /                |                  \
64    *                        /                 |                   \
65    *                       /                  |                    \
66    *     ________________ /             ______|__________           \_________________
67    *     |               |              |               |            |               |
68    *     | cab1 router   |              | cab2 router   |            | cab3 router   |
69    *     |_______________|              |_______________|            |_______________|
70    *     ++++++++++++++++               ++++++++++++++++             ++++++++++++++++++  <-- 1.25 backbone
71    *     / /   | |    \ \              / /    | |    \ \             / /     | |     \ \
72    *    / /    | |     \ \            / /     | |     \ \           / /      | |      \ \ <-- 125Mbps links
73    *   / /     | |      \ \          / /      | |      \ \         / /       | |       \ \
74    * host1     ...      hostN      host1      ...      hostM      host1      ...       hostQ
75    */
76
77   auto* root = sg4::create_star_zone("AS_griffon");
78   sg4::NetZone* cab_zone;
79   simgrid::kernel::routing::NetPoint* router;
80
81   /* create top link */
82   sg4::Link* link = root->create_link("backbone", "1.25GBps")->set_latency("24us")->seal();
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, {link});
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, {link});
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, {link});
104
105   root->seal();
106 }