1 /* Copyright (c) 2008-2021. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <simgrid/s4u.hpp>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(basic_parsing_test, "[usage] basic-parsing-test <platform-file>");
12 namespace sg4 = simgrid::s4u;
14 static void test_one_link(const std::vector<sg4::Host*>& hosts)
16 const sg4::Host* h1 = hosts[0];
17 const sg4::Host* h2 = hosts[1];
18 std::vector<sg4::Link*> route;
20 double min_bandwidth = -1;
22 XBT_INFO("Route between %s and %s", h1->get_cname(), h2->get_cname());
23 h1->route_to(h2, route, &latency);
24 XBT_INFO("Route size %zu", route.size());
26 for (auto link: route) {
27 double bandwidth = link->get_bandwidth();
28 XBT_INFO(" Link %s: latency = %f, bandwidth = %f", link->get_cname(), link->get_latency(), bandwidth);
29 if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
30 min_bandwidth = bandwidth;
32 XBT_INFO("Route latency = %f, route bandwidth = %f", latency, min_bandwidth);
35 static void test_full_link(const std::vector<sg4::Host*>& hosts)
37 size_t list_size = hosts.size();
38 for (size_t i = 0; i < list_size; i++) {
39 const sg4::Host* h1 = hosts[i];
40 for (size_t j = 0; j < list_size; j++) {
41 const sg4::Host* h2 = hosts[j];
42 XBT_INFO("Route between %s and %s", h1->get_cname(), h2->get_cname());
43 std::vector<sg4::Link*> route;
45 double min_bandwidth = -1;
46 h1->route_to(h2, route, &latency);
47 XBT_INFO(" Route size %zu", route.size());
49 for (auto link: route) {
50 double bandwidth = link->get_bandwidth();
51 XBT_INFO(" Link %s: latency = %f, bandwidth = %f", link->get_cname(), link->get_latency(), bandwidth);
52 if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
53 min_bandwidth = bandwidth;
55 XBT_INFO(" Route latency = %f, route bandwidth = %f", latency, min_bandwidth);
60 int main(int argc, char** argv)
62 sg4::Engine e(&argc, argv);
64 /* creation of the environment */
65 e.load_platform(argv[1]);
66 XBT_INFO("Workstation number: %zu, link number: %zu", e.get_host_count(), e.get_link_count());
68 std::vector<sg4::Host*> hosts = e.get_all_hosts();
70 if (strcmp(argv[2], "ONE_LINK") == 0)
72 if (strcmp(argv[2], "FULL_LINK") == 0)
73 test_full_link(hosts);
74 if (strcmp(argv[2], "PROP") == 0)
75 XBT_INFO("SG_TEST_mem: %s", e.host_by_name("host1")->get_property("SG_TEST_mem"));