Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
corrected wifi with loic infos
[simgrid.git] / src / surf / network_ns3.cpp
index 34d92a0..923c4ab 100644 (file)
@@ -20,6 +20,9 @@
 #include <ns3/application-container.h>
 #include <ns3/event-id.h>
 
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+
 #include "network_ns3.hpp"
 #include "ns3/ns3_simulator.hpp"
 
@@ -48,6 +51,15 @@ static ns3::NodeContainer nodes;
 static ns3::NodeContainer Cluster_nodes;
 static ns3::Ipv4InterfaceContainer interfaces;
 
+/* wifi globals */
+static ns3::WifiHelper wifi;
+static ns3::YansWifiPhyHelper wifiPhy = ns3::YansWifiPhyHelper::Default ();
+static ns3::YansWifiChannelHelper wifiChannel = ns3::YansWifiChannelHelper::Default ();
+static ns3::WifiMacHelper wifiMac;
+static ns3::MobilityHelper mobility;
+static int mobility_delta = 10;
+static int mobility_base = 0;
+
 static int number_of_nodes = 0;
 static int number_of_clusters_nodes = 0;
 static int number_of_links = 1;
@@ -129,7 +141,6 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
 static void postparse_cb()
 {
   IPV4addr.shrink_to_fit();
-
   ns3::GlobalRouteManager::BuildGlobalRoutingDatabase();
   ns3::GlobalRouteManager::InitializeRoutes();
 }
@@ -205,14 +216,14 @@ double NetworkNS3Model::next_occurring_event(double now)
     return -1.0;
 
   XBT_DEBUG("doing a ns3 simulation for a duration of %f", now);
-  ns3_simulator(now);  
+  ns3_simulator(now);
   time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - surf_get_clock();
   // NS-3 stops as soon as a flow ends,
   // but it does not process the other flows that may finish at the same (simulated) time.
   // If another flow ends at the same time, time_to_next_flow_completion = 0
   if(double_equals(time_to_next_flow_completion, 0, sg_surf_precision))
-    time_to_next_flow_completion = 0.0; 
+    time_to_next_flow_completion = 0.0;
+
   XBT_DEBUG("min       : %f", now);
   XBT_DEBUG("ns3  time : %f", ns3::Simulator::Now().GetSeconds());
   XBT_DEBUG("surf time : %f", surf_get_clock());
@@ -286,8 +297,7 @@ LinkNS3::LinkNS3(NetworkNS3Model* model, const std::string& name, double bandwid
 {
   bandwidth_.peak = bandwidth;
   latency_.peak   = latency;
-
-  /* If wifi, create the wifizone now. If not, don't do anything: the links will be created in routeCreate_cb */
+  sharing_policy_ = policy;
 
   s4u::Link::on_creation(*this->get_iface());
 }
@@ -384,7 +394,7 @@ void NetworkNS3Action::update_remains_lazy(double /*now*/)
 
 void ns3_simulator(double maxSeconds)
 {
-  ns3::EventId id; 
+  ns3::EventId id;
   if (maxSeconds > 0.0) // If there is a maximum amount of time to run
     id = ns3::Simulator::Schedule(ns3::Seconds(maxSeconds), &ns3::Simulator::Stop);
 
@@ -484,10 +494,34 @@ void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double
   ns3::Ptr<ns3::Node> b = dst->ns3_node_;
 
   if (policy == simgrid::s4u::Link::SharingPolicy::WIFI) {
-    /* Install a ns3::WifiHelper */
+      wifi.SetStandard (ns3::WIFI_PHY_STANDARD_80211n_5GHZ);
+      ns3::Config::Set("/NodeList//DeviceList//$ns3::WifiNetDevice/Phy/ChannelWidth",ns3::UintegerValue (40));
+
+      wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+
+      wifiPhy.SetChannel (wifiChannel.Create ());
+
+      wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+                                    "ControlMode", ns3::StringValue ("HtMcs3"),
+                                    "DataMode", ns3::StringValue ("HtMcs3"));
+
+      mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+
+      wifiMac.SetType("ns3::ApWifiMac");
+      netA.Add(wifi.Install (wifiPhy, wifiMac, a));
+
+      wifiMac.SetType ("ns3::StaWifiMac",
+                   "ActiveProbing", ns3::BooleanValue (false));
+      netA.Add(wifi.Install (wifiPhy, wifiMac, b));
+
+      ns3::Ptr<ns3::ListPositionAllocator> positionAllocS = ns3::CreateObject<ns3::ListPositionAllocator> ();
+      positionAllocS->Add(ns3::Vector(-5, 0, 0.0));
+      positionAllocS->Add(ns3::Vector(5, 0, 0.0));
+      mobility.SetPositionAllocator(positionAllocS);
+      mobility.Install(a);
+      mobility.Install(b);
   } else {
     ns3::PointToPointHelper pointToPoint;
-
     XBT_DEBUG("\tAdd PTP from %d to %d bw:'%f Bps' lat:'%fs'", srcNum, dstNum, bw, lat);
     pointToPoint.SetDeviceAttribute("DataRate",
                                     ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps