Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'split_link_impl' into 'master'
[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     auto* link = cluster->create_split_duplex_link(hostname, "125MBps")->set_latency("24us")->seal();
39
40     /* add link and backbone for communications from the host */
41     cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr,
42                        std::vector<sg4::LinkInRoute>{{link, sg4::LinkInRoute::Direction::UP}, l_bb}, true);
43   }
44
45   /* create router */
46   auto* router = cluster->create_router(prefix + name + "-router" + suffix);
47
48   cluster->seal();
49   return std::make_pair(cluster, router);
50 }
51
52 /** @brief Programmatic version of griffon.xml */
53 extern "C" void load_platform(const sg4::Engine& e);
54 void load_platform(const sg4::Engine& /*e*/)
55 {
56   /**
57    * C++ version of griffon.xml
58    * Old Grid5000 cluster (not available anymore): 3 cabinets containing homogeneous nodes connected through a backbone
59    *                                  1.25GBps shared link
60    *                          ___________________________________
61    *          1              /                |                  \
62    *                        /                 |                   \
63    *                       /                  |                    \
64    *     ________________ /             ______|__________           \_________________
65    *     |               |              |               |            |               |
66    *     | cab1 router   |              | cab2 router   |            | cab3 router   |
67    *     |_______________|              |_______________|            |_______________|
68    *     ++++++++++++++++               ++++++++++++++++             ++++++++++++++++++  <-- 1.25 backbone
69    *     / /   | |    \ \              / /    | |    \ \             / /     | |     \ \
70    *    / /    | |     \ \            / /     | |     \ \           / /      | |      \ \ <-- 125Mbps links
71    *   / /     | |      \ \          / /      | |      \ \         / /       | |       \ \
72    * host1     ...      hostN      host1      ...      hostM      host1      ...       hostQ
73    */
74
75   auto* root = sg4::create_star_zone("AS_griffon");
76   sg4::NetZone* cab_zone;
77   simgrid::kernel::routing::NetPoint* router;
78
79   /* create top link */
80   sg4::Link* link = root->create_link("backbone", "1.25GBps")->set_latency("24us")->seal();
81
82   /* create cabinet1 */
83   std::vector<int> rad(32);
84   std::iota(rad.begin(), rad.end(), 1); // 1-29,58,59,60
85   rad[rad.size() - 1]        = 60;
86   rad[rad.size() - 2]        = 59;
87   rad[rad.size() - 3]        = 58;
88   std::tie(cab_zone, router) = create_cabinet(root, "cabinet1", rad);
89   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {link});
90
91   /* create cabinet2 */
92   rad.resize(28);
93   std::iota(rad.begin(), rad.end(), 30); // 30-57
94   std::tie(cab_zone, router) = create_cabinet(root, "cabinet2", rad);
95   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {link});
96
97   /* create cabinet3 */
98   rad.resize(32);
99   std::iota(rad.begin(), rad.end(), 61); // 61-92
100   std::tie(cab_zone, router) = create_cabinet(root, "cabinet3", rad);
101   root->add_route(cab_zone->get_netpoint(), nullptr, router, nullptr, {link});
102
103   root->seal();
104 }