Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: that assert is particularly useless
[simgrid.git] / src / surf / network_ns3.cpp
index f74f504..e83f84e 100644 (file)
@@ -44,12 +44,9 @@ extern std::map<std::string, SgFlow*> flow_from_sock;
 extern std::map<std::string, ns3::ApplicationContainer> sink_from_sock;
 
 static ns3::InternetStackHelper stack;
-static ns3::NodeContainer nodes;
-static ns3::NodeContainer Cluster_nodes;
 static ns3::Ipv4InterfaceContainer interfaces;
 
 static int number_of_nodes = 0;
-static int number_of_clusters_nodes = 0;
 static int number_of_links = 1;
 static int number_of_networks = 1;
 
@@ -58,7 +55,6 @@ simgrid::xbt::Extension<simgrid::kernel::routing::NetPoint, NetPointNs3> NetPoin
 NetPointNs3::NetPointNs3() : ns3_node_(ns3::CreateObject<ns3::Node>(0))
 {
   stack.Install(ns3_node_);
-  nodes.Add(ns3_node_);
   node_num = number_of_nodes++;
 }
 
@@ -68,6 +64,8 @@ NetPointNs3::NetPointNs3() : ns3_node_(ns3::CreateObject<ns3::Node>(0))
 
 static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs const& cluster)
 {
+  ns3::NodeContainer Nodes;
+
   for (int const& i : *cluster.radicals) {
     // Routers don't create a router on the other end of the private link by themselves.
     // We just need this router to be given an ID so we create a temporary NetPointNS3 so that it gets one
@@ -82,10 +80,34 @@ static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs con
     ns3_add_direct_route(host_src, host_dst, cluster.bw, cluster.lat, cluster.sharing_policy);
 
     delete host_dst;
+
+    // Also add the host to the list of hosts that will be connected to the backbone
+    Nodes.Add(host_src->ns3_node_);
   }
 
-  //Create link backbone
-  ns3_add_cluster(cluster.id.c_str(), cluster.bb_bw, cluster.bb_lat);
+  // Create link backbone
+
+  xbt_assert(Nodes.GetN() <= 65000, "Cluster with ns-3 is limited to 65000 nodes");
+  ns3::CsmaHelper csma;
+  csma.SetChannelAttribute("DataRate",
+                           ns3::DataRateValue(ns3::DataRate(cluster.bb_bw * 8))); // ns-3 takes bps, but we provide Bps
+  csma.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(cluster.bb_lat)));
+  ns3::NetDeviceContainer devices = csma.Install(Nodes);
+  XBT_DEBUG("Create CSMA");
+
+  std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
+  XBT_DEBUG("Assign IP Addresses %s to CSMA.", addr.c_str());
+  ns3::Ipv4AddressHelper ipv4;
+  ipv4.SetBase(addr.c_str(), "255.255.0.0");
+  interfaces.Add(ipv4.Assign(devices));
+
+  if (number_of_links == 255) {
+    xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
+    number_of_links = 1;
+    number_of_networks++;
+  } else {
+    number_of_links++;
+  }
 }
 
 static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoint* src,
@@ -282,11 +304,11 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
 
 LinkNS3::LinkNS3(NetworkNS3Model* model, const std::string& name, double bandwidth, double latency,
                  s4u::Link::SharingPolicy policy)
-    : LinkImpl(model, name, nullptr)
+    : LinkImpl(model, name, nullptr), sharing_policy_(policy)
 {
   bandwidth_.peak = bandwidth;
   latency_.peak   = latency;
-  sharing_policy_ = policy;
+
   /* If wifi, create the wifizone now. If not, don't do anything: the links will be created in routeCreate_cb */
 
   s4u::Link::on_creation(*this->get_iface());
@@ -356,7 +378,6 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s
     port_number = 1025;
     XBT_WARN("Too many connections! Port number is saturated. Trying to use the oldest ports.");
   }
-  xbt_assert(port_number <= 65000, "Too many connections! Port number is saturated.");
 
   s4u::Link::on_communicate(*this);
 }
@@ -428,42 +449,6 @@ void ns3_initialize(std::string TcpProtocol)
   }
 }
 
-void ns3_add_cluster(const char* /*id*/, double bw, double lat)
-{
-  ns3::NodeContainer Nodes;
-
-  for (unsigned int i = number_of_clusters_nodes; i < Cluster_nodes.GetN(); i++) {
-    Nodes.Add(Cluster_nodes.Get(i));
-    XBT_DEBUG("Add node %u to cluster", i);
-  }
-  number_of_clusters_nodes = Cluster_nodes.GetN();
-
-  XBT_DEBUG("Add router %u to cluster", nodes.GetN() - Nodes.GetN() - 1);
-  Nodes.Add(nodes.Get(nodes.GetN()-Nodes.GetN()-1));
-
-  xbt_assert(Nodes.GetN() <= 65000, "Cluster with ns-3 is limited to 65000 nodes");
-  ns3::CsmaHelper csma;
-  csma.SetChannelAttribute("DataRate", ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps
-  csma.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
-  ns3::NetDeviceContainer devices = csma.Install(Nodes);
-  XBT_DEBUG("Create CSMA");
-
-  std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
-  XBT_DEBUG("Assign IP Addresses %s to CSMA.", addr.c_str());
-  ns3::Ipv4AddressHelper ipv4;
-  ipv4.SetBase(addr.c_str(), "255.255.0.0");
-  interfaces.Add(ipv4.Assign (devices));
-
-  if(number_of_links == 255){
-    xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
-    number_of_links = 1;
-    number_of_networks++;
-  }else{
-    number_of_links++;
-  }
-  XBT_DEBUG("Number of nodes in Cluster_nodes: %u", Cluster_nodes.GetN());
-}
-
 static std::string transformIpv4Address(ns3::Ipv4Address from)
 {
   std::stringstream sstream;