Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into jbod
[simgrid.git] / teshsuite / models / cm02-tcpgamma / cm02-tcpgamma.cpp
1 /* Copyright (c) 2017-2023. 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 /**
7  * Test CM02 model wrt TCP gamma
8  *
9  * Platform: single link
10  *
11  *   S1 ___[ L1 ]___S2
12  *
13  * Link L1: 1Gb/s, 10ms
14  */
15
16 #include "src/kernel/resource/WifiLinkImpl.hpp"
17 #include <simgrid/s4u.hpp>
18 #include <xbt/config.hpp>
19
20 namespace sg4 = simgrid::s4u;
21
22 XBT_LOG_NEW_DEFAULT_CATEGORY(cm02_tcpgamma, "Messages specific for this simulation");
23
24 static void run_ping_test(sg4::Link const* testlink)
25 {
26   auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
27
28   simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("host1"), [mailbox, testlink]() {
29     double start_time   = simgrid::s4u::Engine::get_clock();
30     static auto message = std::string("message");
31     mailbox->put(&message, 1e10);
32     double end_time = simgrid::s4u::Engine::get_clock();
33     XBT_INFO("  Actual result: Sending 10Gb with bw=%.0eb, lat=%.0es lasts %f seconds (TCP_Gamma=%.0f).",
34              testlink->get_bandwidth(), testlink->get_latency(), end_time - start_time,
35              simgrid::config::get_value<double>("network/TCP-gamma"));
36   });
37   simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("host2"),
38                               [mailbox]() { mailbox->get<std::string>(); });
39   simgrid::s4u::this_actor::sleep_for(500);
40 }
41
42 /* We need a separate actor so that it can sleep after each test */
43 static void main_dispatcher(sg4::Link* testlink)
44 {
45   XBT_INFO("-----------------------------------------------------------");
46   XBT_INFO("This test set enforces the impact of the latency and TCP-gamma parameter on the bandwidth."); 
47   XBT_INFO("See the documentation about the CM02 TCP performance model.");
48   XBT_INFO("-----------------------------------------------------------");
49   XBT_INFO("TEST with latency = 0 sec (and the default value of Gamma):");
50   XBT_INFO("  Expectation: Gamma/2lat is not defined, so the physical bandwidth is used; The communication lasts 1 sec.");
51   run_ping_test(testlink);
52   XBT_INFO("-----------------------------------------------------------");
53   testlink->set_latency(0.00001);
54   XBT_INFO("TEST with latency = 0.00001 sec");
55   XBT_INFO("  Expectation: Gamma/2lat is about 209 Gb/s, which is larger than the physical bandwidth.");
56   XBT_INFO("    So communication is limited by the physical bandwidth and lasts 1.00001 sec.");
57   run_ping_test(testlink);
58   XBT_INFO("-----------------------------------------------------------");
59   testlink->set_latency(0.001);
60   XBT_INFO("TEST with latency = 0.001 sec");
61   XBT_INFO("  Expectation: Gamma/2lat is about 2 Gb/s, which is smaller than the physical bandwidth.");
62   XBT_INFO("    So the communication is limited by the latency and lasts 4.768372 + 0.001 sec.");
63   run_ping_test(testlink);
64   XBT_INFO("-----------------------------------------------------------");
65   testlink->set_latency(0.1);
66   XBT_INFO("TEST with latency = 0.1 sec");
67   XBT_INFO("  Expectation: Gamma/2lat is about 2 Gb/s, which is smaller than the physical bandwidth.");
68   XBT_INFO("    So the communication is limited by the latency and lasts 476.837158 + 0.1 sec.");
69   run_ping_test(testlink);
70   XBT_INFO("-----------------------------------------------------------");
71   XBT_INFO("TEST with latency = 0.001 sec and TCP_Gamma = 0");
72   sg4::Engine::set_config("network/TCP-gamma:0");
73   testlink->set_latency(0.001);
74   XBT_INFO("  Expectation: The latency=0.001s should make the communication to be limited by the latency.");
75   XBT_INFO("    But since gamma=0, the physical bandwidth is still used. So the communication lasts 1.001 sec.");
76   run_ping_test(testlink);
77   XBT_INFO("-----------------------------------------------------------");
78 }
79
80 int main(int argc, char** argv)
81 {
82   sg4::Engine::set_config("network/crosstraffic:0");
83
84   simgrid::s4u::Engine engine(&argc, argv);
85   auto* zone  = sg4::create_full_zone("world");
86   auto const* host1 = zone->create_host("host1", 1e6)->seal();
87   auto const* host2 = zone->create_host("host2", 1e6)->seal();
88   auto* testlink    = zone->create_link("L1", 1e10)->seal();
89   zone->add_route(host1, host2, {testlink});
90
91   simgrid::s4u::Actor::create("dispatcher", engine.host_by_name("host1"), main_dispatcher, testlink);
92   engine.run();
93
94   return 0;
95 }