Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
77375de8d41fa31c585eb280fab0b08d0ed94368
[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 sg4::Link* testlink = nullptr;
25
26 static void run_ping_test()
27 {
28   auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
29
30   simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("host1"), [mailbox]() {
31     double start_time   = simgrid::s4u::Engine::get_clock();
32     static auto message = std::string("message");
33     mailbox->put(&message, 1e10);
34     double end_time = simgrid::s4u::Engine::get_clock();
35     XBT_INFO("  Actual result: Sending 10Gb with bw=%.0eb, lat=%.0es lasts %f seconds (TCP_Gamma=%.0f).",
36              testlink->get_bandwidth(), testlink->get_latency(), end_time - start_time,
37              simgrid::config::get_value<double>("network/TCP-gamma"));
38   });
39   simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("host2"),
40                               [mailbox]() { mailbox->get<std::string>(); });
41   simgrid::s4u::this_actor::sleep_for(500);
42 }
43
44 /* We need a separate actor so that it can sleep after each test */
45 static void main_dispatcher()
46 {
47   XBT_INFO("-----------------------------------------------------------");
48   XBT_INFO("This test set enforces the impact of the latency and TCP-gamma parameter on the bandwidth."); 
49   XBT_INFO("See the documentation about the CM02 TCP performance model.");
50   XBT_INFO("-----------------------------------------------------------");
51   XBT_INFO("TEST with latency = 0 sec (and the default value of Gamma):");
52   XBT_INFO("  Expectation: Gamma/2lat is not defined, so the physical bandwidth is used; The communication lasts 1 sec.");
53   run_ping_test();
54   XBT_INFO("-----------------------------------------------------------");
55   testlink->set_latency(0.00001);
56   XBT_INFO("TEST with latency = 0.00001 sec");
57   XBT_INFO("  Expectation: Gamma/2lat is about 209 Gb/s, which is larger than the physical bandwidth.");
58   XBT_INFO("    So communication is limited by the physical bandwidth and lasts 1.00001 sec.");
59   run_ping_test();
60   XBT_INFO("-----------------------------------------------------------");
61   testlink->set_latency(0.001);
62   XBT_INFO("TEST with latency = 0.001 sec");
63   XBT_INFO("  Expectation: Gamma/2lat is about 2 Gb/s, which is smaller than the physical bandwidth.");
64   XBT_INFO("    So the communication is limited by the latency and lasts 4.768372 + 0.001 sec.");
65   run_ping_test();
66   XBT_INFO("-----------------------------------------------------------");
67   testlink->set_latency(0.1);
68   XBT_INFO("TEST with latency = 0.1 sec");
69   XBT_INFO("  Expectation: Gamma/2lat is about 2 Gb/s, which is smaller than the physical bandwidth.");
70   XBT_INFO("    So the communication is limited by the latency and lasts 476.837158 + 0.1 sec.");
71   run_ping_test();
72   XBT_INFO("-----------------------------------------------------------");
73   XBT_INFO("TEST with latency = 0.001 sec and TCP_Gamma = 0");
74   sg4::Engine::set_config("network/TCP-gamma:0");
75   testlink->set_latency(0.001);
76   XBT_INFO("  Expectation: The latency=0.001s should make the communication to be limited by the latency.");
77   XBT_INFO("    But since gamma=0, the physical bandwidth is still used. So the communication lasts 1.001 sec.");
78   run_ping_test();
79   XBT_INFO("-----------------------------------------------------------");
80 }
81
82 int main(int argc, char** argv)
83 {
84   // sg4::Engine::set_config("network/model:CM02");
85   sg4::Engine::set_config("network/crosstraffic:0");
86
87   simgrid::s4u::Engine engine(&argc, argv);
88   auto* zone  = sg4::create_full_zone("world");
89   auto const* host1 = zone->create_host("host1", 1e6)->seal();
90   auto const* host2 = zone->create_host("host2", 1e6)->seal();
91   testlink    = zone->create_link("L1", 1e10)->seal();
92   zone->add_route(host1->get_netpoint(), host2->get_netpoint(), nullptr, nullptr, {sg4::LinkInRoute(testlink)});
93
94   simgrid::s4u::Actor::create("dispatcher", engine.host_by_name("host1"), main_dispatcher);
95   engine.run();
96
97   return 0;
98 }