1 /* Copyright (c) 2017-2022. The SimGrid Team. All rights reserved. */
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. */
7 * Test NetworkCm02Link::set_bandwidth and set_latency.
9 * Math behind: https://hal.inria.fr/inria-00361031/document
10 * - Fig. 1 and Eq. 7 in the paper
15 * S1 ___[ 1 ]___ ___[ 2 ]___ C1
19 * S2 ___[ 3 ]__/ \__[ 4 ]___ C2
25 * Links: [1], [2], [3]: 1Gb/s, 10ms
26 * Link: [0] bottleneck: 1Mb/s, 20ms
27 * Link: [4]: We'll change the bandwidth and latency to see the impact on the
28 * sharing of the bottleneck link between the 2 flows.
31 #include <simgrid/s4u.hpp>
33 namespace sg4 = simgrid::s4u;
35 XBT_LOG_NEW_DEFAULT_CATEGORY(cm02_set_lat_bw, "Messages specific for this simulation");
37 static void sender(const std::string& recv_name, sg4::Link* l4)
39 sg4::Mailbox* mbox = sg4::Mailbox::by_name(recv_name);
40 XBT_INFO("Comm to %s, same weight/penalty (w_a == w_b, ~20) for everybody, each comm should take 1s and finish at "
43 auto* payload = new double(sg4::Engine::get_clock());
44 auto comm = mbox->put_async(payload, 1e3);
46 sg4::this_actor::sleep_until(10); // synchronize senders
48 if (recv_name == "C2") {
49 XBT_INFO("Comm Flow B to C2: after 1s, change latency of L4 to increase penalty for flow B (w_b = 2* w_a)");
50 XBT_INFO("rho_a = 2*rho_b, flow A receives twice the bandwidth than flow B");
52 XBT_INFO("Comm Flow A to C1");
54 payload = new double(sg4::Engine::get_clock());
55 comm = mbox->put_async(payload, 1e3);
56 sg4::this_actor::sleep_for(1);
60 sg4::this_actor::sleep_until(20); // synchronize senders
62 l4->set_latency(1e-9);
64 if (recv_name == "C2") {
65 XBT_INFO("Comm Flow B to C2: after 1s, change bandwidth of L4 to increase penalty for flow B (w_b = 2* w_a)");
66 XBT_INFO("rho_a = 2*rho_b, flow A receives twice the bandwidth than flow B");
68 XBT_INFO("Comm Flow A to C1");
70 payload = new double(sg4::Engine::get_clock());
71 comm = mbox->put_async(payload, 1e3);
72 sg4::this_actor::sleep_for(1);
74 l4->set_bandwidth(1e3);
76 sg4::this_actor::sleep_until(30);
78 payload = new double(-1.0);
79 mbox->put(payload, 0);
82 static void receiver()
84 sg4::Mailbox* mbox = sg4::Mailbox::by_name(sg4::this_actor::get_host()->get_name());
86 auto payload = mbox->get_unique<double>();
89 XBT_INFO("Received data. Elapsed %lf", sg4::Engine::get_clock() - *payload);
94 /*************************************************************************************************/
95 int main(int argc, char** argv)
97 sg4::Engine e(&argc, argv);
98 /* keep it simple, no network factors nor crosstrafic */
99 sg4::Engine::set_config("network/model:CM02");
100 sg4::Engine::set_config("network/weight-S:20537");
101 sg4::Engine::set_config("network/crosstraffic:0");
103 /* dog-bone platform */
104 std::unordered_map<std::string, sg4::Host*> hosts;
105 std::unordered_map<std::string, sg4::Link*> links;
106 auto* zone = sg4::create_full_zone("dog_zone");
107 for (const auto& name : {"S1", "S2", "C1", "C2"}) {
108 hosts[name] = zone->create_host(name, 1e6)->seal();
111 for (const auto& name : {"L1", "L2", "L3", "L4"}) {
112 links[name] = zone->create_link(name, 1e9)->set_latency(1e-9)->seal();
114 links["L0"] = zone->create_link("L0", 1e3)->seal();
115 zone->add_route(hosts["S1"]->get_netpoint(), hosts["C1"]->get_netpoint(), nullptr, nullptr,
116 {sg4::LinkInRoute(links["L1"]), sg4::LinkInRoute(links["L0"]), sg4::LinkInRoute(links["L2"])});
117 zone->add_route(hosts["S2"]->get_netpoint(), hosts["C2"]->get_netpoint(), nullptr, nullptr,
118 {sg4::LinkInRoute(links["L3"]), sg4::LinkInRoute(links["L0"]), sg4::LinkInRoute(links["L4"])});
122 sg4::Actor::create("", hosts["S1"], sender, "C1", nullptr);
123 sg4::Actor::create("", hosts["C1"], receiver);
124 sg4::Actor::create("", hosts["S2"], sender, "C2", links["L4"]);
125 sg4::Actor::create("", hosts["C2"], receiver);