From 9f575d0fbfaeb2a0f046f2c67e63cb20b02625d0 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 1 Jul 2021 14:19:49 +0200 Subject: [PATCH] Sonar variety --- .../cpp/comm-serialize/s4u-comm-serialize.cpp | 3 +- .../network-factors/s4u-network-factors.cpp | 4 +- .../plugin-prodcons/s4u-plugin-prodcons.cpp | 2 +- examples/platforms/griffon.cpp | 6 +-- examples/platforms/routing_cluster.cpp | 9 ++-- src/kernel/EngineImpl.hpp | 2 +- src/kernel/routing/DijkstraZone_test.cpp | 4 +- src/kernel/routing/FloydZone_test.cpp | 4 +- src/kernel/routing/FullZone_test.cpp | 4 +- src/kernel/routing/NetZoneImpl.cpp | 48 +++++++++---------- src/kernel/routing/StarZone_test.cpp | 2 +- src/s4u/s4u_Link.cpp | 4 +- src/surf/network_wifi.cpp | 2 +- src/surf/network_wifi.hpp | 2 +- src/surf/sg_platf.cpp | 16 +++---- src/surf/xml/surfxml_sax_cb.cpp | 2 +- teshsuite/s4u/seal-platform/seal-platform.cpp | 4 +- 17 files changed, 60 insertions(+), 58 deletions(-) diff --git a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp index 81a52d9da5..fa2d5014ce 100644 --- a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp +++ b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp @@ -104,7 +104,8 @@ int main(int argc, char* argv[]) auto* receiver = zone->create_host("receiver", 1)->seal(); /* create split-duplex link1 (UP/DOWN), limiting the number of concurrent flows in it for 2 */ - auto* link = zone->create_split_duplex_link("link1", 10e9)->set_latency(10e-6)->set_concurrency_limit(2)->seal(); + const auto* link = + zone->create_split_duplex_link("link1", 10e9)->set_latency(10e-6)->set_concurrency_limit(2)->seal(); /* create routes between nodes */ zone->add_route(sender->get_netpoint(), receiver->get_netpoint(), nullptr, nullptr, diff --git a/examples/cpp/network-factors/s4u-network-factors.cpp b/examples/cpp/network-factors/s4u-network-factors.cpp index 60018a1d9f..922f0b4fd8 100644 --- a/examples/cpp/network-factors/s4u-network-factors.cpp +++ b/examples/cpp/network-factors/s4u-network-factors.cpp @@ -75,13 +75,13 @@ static void load_platform() /* create host */ const sg4::Host* host = root->create_host(hostname, 1)->set_core_count(32)->seal(); /* create UP/DOWN link */ - sg4::Link* l = root->create_split_duplex_link(hostname, BW_REMOTE)->set_latency(LATENCY)->seal(); + const sg4::Link* l = root->create_split_duplex_link(hostname, BW_REMOTE)->set_latency(LATENCY)->seal(); /* add link UP/DOWN for communications from the host */ root->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, std::vector{{l, sg4::LinkInRoute::Direction::UP}}, true); - sg4::Link* loopback = root->create_link(hostname + "_loopback", BW_LOCAL)->set_latency(LATENCY)->seal(); + const sg4::Link* loopback = root->create_link(hostname + "_loopback", BW_LOCAL)->set_latency(LATENCY)->seal(); root->add_route(host->get_netpoint(), host->get_netpoint(), nullptr, nullptr, std::vector{loopback}); } diff --git a/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp b/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp index d9eb7d888b..0ad772e532 100644 --- a/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp +++ b/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) const auto* host = cluster->create_host(hostname, "1Gf"); std::string linkname = std::string("cluster") + "_link_" + std::to_string(i); - auto* link = cluster->create_split_duplex_link(linkname, "1Gbps"); + const auto* link = cluster->create_split_duplex_link(linkname, "1Gbps"); cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, std::vector{{link, sg4::LinkInRoute::Direction::UP}}, true); diff --git a/examples/platforms/griffon.cpp b/examples/platforms/griffon.cpp index 3b9207a7d2..4d040428cb 100644 --- a/examples/platforms/griffon.cpp +++ b/examples/platforms/griffon.cpp @@ -27,7 +27,7 @@ create_cabinet(const sg4::NetZone* root, const std::string& name, const std::vec cluster->set_parent(root); /* create the backbone link */ - sg4::Link* l_bb = cluster->create_link("backbone-" + name, "1.25GBps")->seal(); + const sg4::Link* l_bb = cluster->create_link("backbone-" + name, "1.25GBps")->seal(); /* create all hosts and connect them to outside world */ for (const auto& id : radicals) { @@ -35,7 +35,7 @@ create_cabinet(const sg4::NetZone* root, const std::string& name, const std::vec /* create host */ const sg4::Host* host = cluster->create_host(hostname, "286.087kf"); /* create UP/DOWN link */ - auto* link = cluster->create_split_duplex_link(hostname, "125MBps")->set_latency("24us")->seal(); + const sg4::Link* link = cluster->create_split_duplex_link(hostname, "125MBps")->set_latency("24us")->seal(); /* add link and backbone for communications from the host */ cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, @@ -77,7 +77,7 @@ void load_platform(const sg4::Engine& /*e*/) simgrid::kernel::routing::NetPoint* router; /* create top link */ - sg4::Link* link = root->create_link("backbone", "1.25GBps")->set_latency("24us")->seal(); + const sg4::Link* link = root->create_link("backbone", "1.25GBps")->set_latency("24us")->seal(); /* create cabinet1 */ std::vector rad(32); diff --git a/examples/platforms/routing_cluster.cpp b/examples/platforms/routing_cluster.cpp index 0f150b1937..e5fc346bb7 100644 --- a/examples/platforms/routing_cluster.cpp +++ b/examples/platforms/routing_cluster.cpp @@ -23,7 +23,7 @@ static void create_cluster(const sg4::NetZone* root, const std::string& cluster_ cluster->set_parent(root); /* create the backbone link */ - sg4::Link* l_bb = + const sg4::Link* l_bb = cluster->create_link("backbone" + cluster_suffix, std::vector{2.25e9})->set_latency(5e-4)->seal(); /* create all hosts and connect them to outside world */ @@ -31,9 +31,10 @@ static void create_cluster(const sg4::NetZone* root, const std::string& cluster_ /* create host */ const sg4::Host* host = cluster->create_host(hostname, std::vector{1e9}); /* create UP link */ - sg4::Link* l_up = cluster->create_link(hostname + "_up", std::vector{1.25e8})->set_latency(0.0001)->seal(); + const sg4::Link* l_up = + cluster->create_link(hostname + "_up", std::vector{1.25e8})->set_latency(0.0001)->seal(); /* create DOWN link, if needed */ - sg4::Link* l_down = l_up; + const sg4::Link* l_down = l_up; if (hostname != single_link_host) { l_down = cluster->create_link(hostname + "_down", std::vector{1.25e8})->set_latency(0.0001)->seal(); } @@ -81,7 +82,7 @@ void load_platform(const sg4::Engine& e) create_cluster(root, "2", {"host4", "host5", "host6"}, "host6"); /* connect both cluster through their respective routers */ - sg4::Link* link = root->create_link("link1-2", std::vector{2.25e9})->set_latency(5e-4)->seal(); + const sg4::Link* link = root->create_link("link1-2", std::vector{2.25e9})->set_latency(5e-4)->seal(); root->add_route(e.netpoint_by_name_or_null("cluster1"), e.netpoint_by_name_or_null("cluster2"), e.netpoint_by_name_or_null("router1"), e.netpoint_by_name_or_null("router2"), {link}); diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index 79fa6568ea..5f5aa83f20 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -37,7 +37,7 @@ class EngineImpl { std::map> links_; /* save split-duplex links separately, keep links_ with only LinkImpl* seen by the user * members of a split-duplex are saved in the links_ */ - std::map> split_duplex_links_; + std::map, std::less<>> split_duplex_links_; std::unordered_map netpoints_; std::unordered_map mailboxes_; diff --git a/src/kernel/routing/DijkstraZone_test.cpp b/src/kernel/routing/DijkstraZone_test.cpp index d222e968d5..e941407585 100644 --- a/src/kernel/routing/DijkstraZone_test.cpp +++ b/src/kernel/routing/DijkstraZone_test.cpp @@ -25,8 +25,8 @@ TEST_CASE("kernel::routing::DijkstraZone: mix new routes and hosts", "") simgrid::s4u::Engine e("test"); auto* zone = simgrid::s4u::create_dijkstra_zone("test", false); - const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); - simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); + const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); + const simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); for (int i = 0; i < 10; i++) { std::string cpu_name = "CPU" + std::to_string(i); const simgrid::s4u::Host* cpu = zone->create_host(cpu_name, 1e9)->seal(); diff --git a/src/kernel/routing/FloydZone_test.cpp b/src/kernel/routing/FloydZone_test.cpp index d47351cc7f..b66397f12e 100644 --- a/src/kernel/routing/FloydZone_test.cpp +++ b/src/kernel/routing/FloydZone_test.cpp @@ -24,8 +24,8 @@ TEST_CASE("kernel::routing::FloydZone: mix new routes and hosts", "") simgrid::s4u::Engine e("test"); auto* zone = simgrid::s4u::create_floyd_zone("test"); - const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); - simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); + const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); + const simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); for (int i = 0; i < 10; i++) { std::string cpu_name = "CPU" + std::to_string(i); const simgrid::s4u::Host* cpu = zone->create_host(cpu_name, 1e9)->seal(); diff --git a/src/kernel/routing/FullZone_test.cpp b/src/kernel/routing/FullZone_test.cpp index f67e156c10..ba308a2ec4 100644 --- a/src/kernel/routing/FullZone_test.cpp +++ b/src/kernel/routing/FullZone_test.cpp @@ -24,8 +24,8 @@ TEST_CASE("kernel::routing::FullZone: mix new routes and hosts", "[bug]") simgrid::s4u::Engine e("test"); auto* zone = simgrid::s4u::create_full_zone("test"); - const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); - simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); + const simgrid::s4u::Host* nic = zone->create_host("nic", 1e9)->seal(); + const simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); for (int i = 0; i < 10; i++) { std::string cpu_name = "CPU" + std::to_string(i); const simgrid::s4u::Host* cpu = zone->create_host(cpu_name, 1e9)->seal(); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index d357d6af6c..95d41532ca 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -207,31 +207,31 @@ std::vector NetZoneImpl::get_link_list_impl(const std::vect std::vector links; for (const auto& link : link_list) { + if (link.get_link()->get_sharing_policy() != s4u::Link::SharingPolicy::SPLITDUPLEX) { + links.push_back(link.get_link()->get_impl()); + continue; + } + // split-duplex links + const auto* sd_link = dynamic_cast(link.get_link()); + xbt_assert(sd_link, + "Add_route: cast to SpliDuplexLink impossible. This should not happen, please contact SimGrid team"); resource::LinkImpl* link_impl; - if (link.get_link()->get_sharing_policy() == s4u::Link::SharingPolicy::SPLITDUPLEX) { - const auto* sd_link = dynamic_cast(link.get_link()); - xbt_assert(sd_link, - "Add_route: cast to SpliDuplexLink impossible. This should not happen, please contact SimGrid team"); - switch (link.get_direction()) { - case s4u::LinkInRoute::Direction::UP: - if (backroute) - link_impl = sd_link->get_link_down()->get_impl(); - else - link_impl = sd_link->get_link_up()->get_impl(); - break; - case s4u::LinkInRoute::Direction::DOWN: - if (backroute) - link_impl = sd_link->get_link_up()->get_impl(); - else - link_impl = sd_link->get_link_down()->get_impl(); - break; - case s4u::LinkInRoute::Direction::NONE: - default: - throw std::invalid_argument("Invalid add_route. Split-Duplex link without a direction: " + - link.get_link()->get_name()); - } - } else { - link_impl = link.get_link()->get_impl(); + switch (link.get_direction()) { + case s4u::LinkInRoute::Direction::UP: + if (backroute) + link_impl = sd_link->get_link_down()->get_impl(); + else + link_impl = sd_link->get_link_up()->get_impl(); + break; + case s4u::LinkInRoute::Direction::DOWN: + if (backroute) + link_impl = sd_link->get_link_up()->get_impl(); + else + link_impl = sd_link->get_link_down()->get_impl(); + break; + default: + throw std::invalid_argument("Invalid add_route. Split-Duplex link without a direction: " + + link.get_link()->get_name()); } links.push_back(link_impl); } diff --git a/src/kernel/routing/StarZone_test.cpp b/src/kernel/routing/StarZone_test.cpp index ef27bf5c3e..934af82a3e 100644 --- a/src/kernel/routing/StarZone_test.cpp +++ b/src/kernel/routing/StarZone_test.cpp @@ -283,7 +283,7 @@ TEST_CASE("kernel::routing::StarZone: mix new routes and hosts", "") simgrid::s4u::Engine e("test"); auto* zone = simgrid::s4u::create_star_zone("test"); - simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); + const simgrid::s4u::Link* link = zone->create_link("my_link", 1e6)->seal(); for (int i = 0; i < 10; i++) { std::string cpu_name = "CPU" + std::to_string(i); const simgrid::s4u::Host* cpu = zone->create_host(cpu_name, 1e9)->seal(); diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index cd3b19aad9..74ad674909 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -195,14 +195,14 @@ Link* Link::set_properties(const std::unordered_map& p Link* SplitDuplexLink::get_link_up() const { - kernel::resource::SplitDuplexLinkImpl* pimpl = dynamic_cast(pimpl_); + const auto* pimpl = dynamic_cast(pimpl_); xbt_assert(pimpl, "Requesting link_up from a non split-duplex link: %s", get_cname()); return pimpl->get_link_up(); } Link* SplitDuplexLink::get_link_down() const { - kernel::resource::SplitDuplexLinkImpl* pimpl = dynamic_cast(pimpl_); + const auto* pimpl = dynamic_cast(pimpl_); xbt_assert(pimpl, "Requesting link_down from a non split-duplex link: %s", get_cname()); return pimpl->get_link_down(); } diff --git a/src/surf/network_wifi.cpp b/src/surf/network_wifi.cpp index c82d321548..9f0707baf5 100644 --- a/src/surf/network_wifi.cpp +++ b/src/surf/network_wifi.cpp @@ -17,7 +17,7 @@ namespace resource { * Resource * ************/ -NetworkWifiLink::NetworkWifiLink(const std::string& name, std::vector bandwidths, lmm::System* system) +NetworkWifiLink::NetworkWifiLink(const std::string& name, const std::vector& bandwidths, lmm::System* system) : LinkImpl(name) { this->set_constraint(system->constraint_new(this, 1)); diff --git a/src/surf/network_wifi.hpp b/src/surf/network_wifi.hpp index 6f5ad3596f..71850b588e 100644 --- a/src/surf/network_wifi.hpp +++ b/src/surf/network_wifi.hpp @@ -42,7 +42,7 @@ class NetworkWifiLink : public LinkImpl { std::vector decay_bandwidths_; public: - NetworkWifiLink(const std::string& name, std::vector bandwidths, lmm::System* system); + NetworkWifiLink(const std::string& name, const std::vector& bandwidths, lmm::System* system); void set_host_rate(const s4u::Host* host, int rate_level); /** @brief Get the AP rate associated to the host (or -1 if not associated to the AP) */ diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 0774f2ab88..d0f03c203b 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -257,7 +257,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA zone->set_property(elm.first, elm.second); /* Make the backbone */ - simgrid::s4u::Link* backbone = nullptr; + const simgrid::s4u::Link* backbone = nullptr; if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) { std::string bb_name = std::string(cluster->id) + "_backbone"; XBT_DEBUG(" ", bb_name.c_str(), cluster->bb_bw, @@ -288,17 +288,17 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA std::string loopback_name = link_id + "_loopback"; XBT_DEBUG("", loopback_name.c_str(), cluster->loopback_bw); - auto* loopback = zone->create_link(loopback_name, std::vector{cluster->loopback_bw}) - ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE) - ->set_latency(cluster->loopback_lat) - ->seal(); + const auto* loopback = zone->create_link(loopback_name, std::vector{cluster->loopback_bw}) + ->set_sharing_policy(simgrid::s4u::Link::SharingPolicy::FATPIPE) + ->set_latency(cluster->loopback_lat) + ->seal(); zone->add_route(host->get_netpoint(), host->get_netpoint(), nullptr, nullptr, std::vector{loopback}); } // add a limiter link (shared link to account for maximal bandwidth of the node) - simgrid::s4u::Link* limiter = nullptr; + const simgrid::s4u::Link* limiter = nullptr; if (cluster->limiter_link > 0) { std::string limiter_name = std::string(link_id) + "_limiter"; XBT_DEBUG("", limiter_name.c_str(), cluster->limiter_link); @@ -307,7 +307,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA } // create link - simgrid::s4u::Link* link; + const simgrid::s4u::Link* link; if (cluster->sharing_policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) { link = zone->create_split_duplex_link(link_id, cluster->bw)->set_latency(cluster->lat)->seal(); } else { @@ -355,7 +355,7 @@ void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* clu static void sg_platf_cluster_set_hostlink(simgrid::kernel::routing::StarZone* zone, simgrid::kernel::routing::NetPoint* netpoint, const simgrid::s4u::Link* link_up, const simgrid::s4u::Link* link_down, - simgrid::s4u::Link* backbone) + const simgrid::s4u::Link* backbone) { XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->get_cname(), netpoint->id()); if (backbone) { diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 1a0edf9536..465b580d15 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -481,7 +481,7 @@ void ETag_surfxml_link(){ void STag_surfxml_link___ctn() { - simgrid::s4u::Link* link; + const simgrid::s4u::Link* link; simgrid::s4u::LinkInRoute::Direction direction = simgrid::s4u::LinkInRoute::Direction::NONE; switch (A_surfxml_link___ctn_direction) { case AU_surfxml_link___ctn_direction: diff --git a/teshsuite/s4u/seal-platform/seal-platform.cpp b/teshsuite/s4u/seal-platform/seal-platform.cpp index 0701900a57..bbc2fe8d73 100644 --- a/teshsuite/s4u/seal-platform/seal-platform.cpp +++ b/teshsuite/s4u/seal-platform/seal-platform.cpp @@ -69,7 +69,7 @@ static sg4::NetZone* create_zone(const sg4::NetZone* root, const std::string& id std::string hostname = id + "-cpu-" + std::to_string(i); auto* host = zone->create_host(hostname, 1e9); host->create_disk("disk-" + hostname, 1e9, 1e6); - auto* link = zone->create_link("link-" + hostname, 1e9); + const auto* link = zone->create_link("link-" + hostname, 1e9); zone->add_route(host->get_netpoint(), router, nullptr, nullptr, std::vector{link}); } return zone; @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) auto* root = sg4::create_full_zone("root"); auto* zoneA = create_zone(root, "A"); auto* zoneB = create_zone(root, "B"); - auto* link = root->create_link("root-link", 1e10); + const auto* link = root->create_link("root-link", 1e10); root->add_route(zoneA->get_netpoint(), zoneB->get_netpoint(), e.netpoint_by_name("routerA"), e.netpoint_by_name("routerB"), std::vector{link}); -- 2.20.1