Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix lua compilation
[simgrid.git] / src / surf / network_ns3.cpp
index 1195cc7..1180f02 100644 (file)
@@ -185,7 +185,10 @@ static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs con
 {
   ns3::NodeContainer Nodes;
 
-  for (int const& i : *cluster.radicals) {
+  xbt_assert(cluster.topology == simgrid::kernel::routing::ClusterTopology::FLAT,
+             "NS-3 is supported only by flat clusters. Do not use with other topologies");
+
+  for (int const& i : cluster.radicals) {
     // Create private link
     std::string host_id = cluster.prefix + std::to_string(i) + cluster.suffix;
     auto* src           = simgrid::s4u::Host::by_name(host_id)->get_netpoint();
@@ -229,6 +232,10 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
                              simgrid::kernel::routing::NetPoint* /*gw_dst*/,
                              std::vector<simgrid::kernel::resource::LinkImpl*> const& link_list)
 {
+  /* ignoring routes from StarZone, not supported */
+  if (not src || not dst)
+    return;
+
   if (link_list.size() == 1) {
     auto const* link = static_cast<simgrid::kernel::resource::LinkNS3*>(link_list[0]);
 
@@ -270,7 +277,7 @@ static simgrid::config::Flag<std::string>
 static simgrid::config::Flag<std::string> ns3_seed(
     "ns3/seed",
     "The random seed provided to ns-3. Either 'time' to seed with time(), blank to not set (default), or a number.", "",
-    [](std::string val) {
+    [](const std::string& val) {
       if (val.length() == 0)
         return;
       if (strcasecmp(val.c_str(), "time") == 0) {
@@ -327,13 +334,15 @@ NetworkNS3Model::NetworkNS3Model(const std::string& name) : NetworkModel(name)
   s4u::NetZone::on_seal.connect(&zoneCreation_cb);
 }
 
-LinkImpl* NetworkNS3Model::create_link(const std::string& name, const std::vector<double>& bandwidths,
-                                       s4u::Link::SharingPolicy policy)
+LinkImpl* NetworkNS3Model::create_link(const std::string& name, const std::vector<double>& bandwidths)
 {
   xbt_assert(bandwidths.size() == 1, "ns-3 links must use only 1 bandwidth.");
-  auto link = new LinkNS3(name, bandwidths[0], policy);
-  link->set_model(this);
-  return link;
+  return (new LinkNS3(name, bandwidths[0]))->set_model(this);
+}
+
+LinkImpl* NetworkNS3Model::create_wifi_link(const std::string& name, const std::vector<double>& bandwidths)
+{
+  return create_link(name, bandwidths)->set_sharing_policy(s4u::Link::SharingPolicy::WIFI);
 }
 
 Action* NetworkNS3Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
@@ -434,8 +443,7 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
  * Resource *
  ************/
 
-LinkNS3::LinkNS3(const std::string& name, double bandwidth, s4u::Link::SharingPolicy policy)
-    : LinkImpl(name), sharing_policy_(policy)
+LinkNS3::LinkNS3(const std::string& name, double bandwidth) : LinkImpl(name)
 {
   bandwidth_.peak = bandwidth;
 }
@@ -464,6 +472,12 @@ LinkImpl* LinkNS3::set_latency(double latency)
   latency_.peak = latency;
   return this;
 }
+
+LinkImpl* LinkNS3::set_sharing_policy(s4u::Link::SharingPolicy policy)
+{
+  sharing_policy_ = policy;
+  return this;
+}
 /**********
  * Action *
  **********/