Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow to add a disk to a host after a load_platform from xml
[simgrid.git] / src / surf / network_ns3.cpp
index 222766f6247b8bc94a49aee8ebfecd1bbfa75626..aaa77ed748745c02ba83953f9fd80830f2946205 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -51,8 +51,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns
 extern std::map<std::string, SgFlow*, std::less<>> flow_from_sock;
 extern std::map<std::string, ns3::ApplicationContainer, std::less<>> sink_from_sock;
 
-static ns3::InternetStackHelper stack;
-
 static int number_of_links    = 1;
 static int number_of_networks = 1;
 
@@ -67,6 +65,7 @@ static std::string transformIpv4Address(ns3::Ipv4Address from)
 
 NetPointNs3::NetPointNs3()
 {
+  static ns3::InternetStackHelper stack;
   stack.Install(ns3_node_);
 }
 
@@ -262,16 +261,13 @@ static void routeCreation_cb(bool symmetrical, const simgrid::kernel::routing::N
     XBT_DEBUG("\tLink (%s) bw:%fbps lat:%fs", link->get_cname(), link->get_bandwidth(), link->get_latency());
 
     ns3_add_direct_route(src, dst, link->get_bandwidth(), link->get_latency(), link->get_sharing_policy());
-  } else {
-    static bool warned_about_long_routes = false;
-
-    if (not warned_about_long_routes)
-      XBT_WARN("Ignoring a route between %s and %s of length %zu: Only routes of length 1 are considered with ns-3.\n"
-               "WARNING: You can ignore this warning if your hosts can still communicate when only considering routes "
-               "of length 1.\n"
-               "WARNING: Remove long routes to avoid this harmless message; subsequent long routes will be silently "
-               "ignored.",
-               src->get_cname(), dst->get_cname(), link_list.size());
+  } else if (static bool warned_about_long_routes = false; not warned_about_long_routes) {
+    XBT_WARN("Ignoring a route between %s and %s of length %zu: Only routes of length 1 are considered with ns-3.\n"
+             "WARNING: You can ignore this warning if your hosts can still communicate when only considering routes "
+             "of length 1.\n"
+             "WARNING: Remove long routes to avoid this harmless message; subsequent long routes will be silently "
+             "ignored.",
+             src->get_cname(), dst->get_cname(), link_list.size());
     warned_about_long_routes = true;
   }
 }
@@ -279,12 +275,16 @@ static void routeCreation_cb(bool symmetrical, const simgrid::kernel::routing::N
 /*********
  * Model *
  *********/
-void surf_network_model_init_NS3()
+// We can't use SIMGRID_REGISTER_NETWORK_MODEL here because ns-3 has a dash in its name
+static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_ns3_network_model_register()
 {
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>("NS3 network model");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
+  simgrid_network_models().add(
+      "ns-3", "Network pseudo-model using the real ns-3 simulator instead of an analytic model", []() {
+        auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>("NS3 network model");
+        auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+        engine->add_model(net_model);
+        engine->get_netzone_root()->set_network_model(net_model);
+      });
 }
 
 static simgrid::config::Flag<std::string>
@@ -368,7 +368,7 @@ StandardLinkImpl* NetworkNS3Model::create_wifi_link(const std::string& name, con
   return link;
 }
 
-Action* NetworkNS3Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
+Action* NetworkNS3Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool /*streamed*/)
 {
   xbt_assert(rate == -1,
              "Communication over ns-3 links cannot specify a specific rate. Please use -1 as a value instead of %f.",