Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3 wifi working with 2 nodes 1 route, does not take lat or bw for now
authoradrien gougeon <adrien.gougeon@inria.fr>
Tue, 9 Jun 2020 17:41:46 +0000 (19:41 +0200)
committeradrien gougeon <adrien.gougeon@inria.fr>
Tue, 9 Jun 2020 17:41:46 +0000 (19:41 +0200)
CMakeLists.txt
src/surf/network_ns3.cpp

index 4b48876..f511ad0 100644 (file)
@@ -230,7 +230,7 @@ if(enable_ns3)
   include(FindNS3)
   if (SIMGRID_HAVE_NS3)
     set(SIMGRID_HAVE_NS3 1)
-    foreach(lib core csma point-to-point internet network applications)
+    foreach(lib core csma point-to-point internet network applications wifi)
       set(SIMGRID_DEP "${SIMGRID_DEP} -lns${NS3_VERSION}-${lib}${NS3_SUFFIX}")
     endforeach()
   else()
index f74f504..5f72405 100644 (file)
 #include <ns3/application-container.h>
 #include <ns3/event-id.h>
 
+#include "ns3/core-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+
+
 #include "network_ns3.hpp"
 #include "ns3/ns3_simulator.hpp"
 
@@ -48,6 +53,13 @@ static ns3::NodeContainer nodes;
 static ns3::NodeContainer Cluster_nodes;
 static ns3::Ipv4InterfaceContainer interfaces;
 
+/* wifi globals */
+static ns3::YansWifiChannelHelper channel = ns3::YansWifiChannelHelper::Default ();
+static ns3::YansWifiPhyHelper phy = ns3::YansWifiPhyHelper::Default ();
+static ns3::WifiHelper wifi;
+static ns3::WifiMacHelper mac;
+static ns3::MobilityHelper mobility;
+
 static int number_of_nodes = 0;
 static int number_of_clusters_nodes = 0;
 static int number_of_links = 1;
@@ -93,6 +105,8 @@ 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)
 {
+  XBT_INFO("routeCreation_cb START");
+
   if (link_list.size() == 1) {
     auto* link = static_cast<simgrid::kernel::resource::LinkNS3*>(link_list[0]);
 
@@ -110,7 +124,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
     xbt_assert(host_src != nullptr, "Network element %s does not seem to be ns-3-ready", src->get_cname());
     xbt_assert(host_dst != nullptr, "Network element %s does not seem to be ns-3-ready", dst->get_cname());
 
+    XBT_INFO("routeCreation_cb MID");
     ns3_add_direct_route(host_src, host_dst, link->get_bandwidth(), link->get_latency(), link->get_sharing_policy());
+    XBT_INFO("routeCreation_cb MID2");
   } else {
     static bool warned_about_long_routes = false;
 
@@ -123,6 +139,7 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin
                src->get_cname(), dst->get_cname(), link_list.size());
     warned_about_long_routes = true;
   }
+  XBT_INFO("routeCreation_cb END");
 }
 
 /* Create the ns3 topology based on routing strategy */
@@ -179,7 +196,9 @@ NetworkNS3Model::~NetworkNS3Model() {
 LinkImpl* NetworkNS3Model::create_link(const std::string& name, const std::vector<double>& bandwidths, double latency,
                                        s4u::Link::SharingPolicy policy)
 {
+  XBT_INFO("create_link START");
   xbt_assert(bandwidths.size() == 1, "ns-3 links must use only 1 bandwidth.");
+  XBT_INFO("create_link END");
   return new LinkNS3(this, name, bandwidths[0], latency, policy);
 }
 
@@ -205,14 +224,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());
@@ -284,12 +303,37 @@ LinkNS3::LinkNS3(NetworkNS3Model* model, const std::string& name, double bandwid
                  s4u::Link::SharingPolicy policy)
     : LinkImpl(model, name, nullptr)
 {
+  XBT_INFO("LinkNS3 START");
   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 */
+  if (policy == s4u::Link::SharingPolicy::WIFI) {
+        ns3::NodeContainer ap_nodes;
+        ap_nodes.Create(1);
+
+        phy.SetChannel (channel.Create ());
+
+        wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
+
+        mac.SetType ("ns3::ApWifiMac");
+        ns3::NetDeviceContainer apDevices;
+        apDevices = wifi.Install (phy, mac, ap_nodes);
+
+        mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+        mobility.Install (ap_nodes);
+
+        stack.Install(ap_nodes);
+
+        ns3::Ipv4AddressHelper address;
+        std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
+        address.SetBase(addr.c_str(), "255.255.0.0");
+        interfaces.Add(address.Assign(apDevices));
+  }
 
   s4u::Link::on_creation(*this->get_iface());
+  XBT_INFO("LinkNS3 END");
 }
 
 LinkNS3::~LinkNS3() = default;
@@ -384,7 +428,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);
 
@@ -474,6 +518,8 @@ static std::string transformIpv4Address(ns3::Ipv4Address from)
 void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double lat,
                           simgrid::s4u::Link::SharingPolicy policy)
 {
+  XBT_INFO("add_direct_route START");
+
   ns3::Ipv4AddressHelper address;
   ns3::NetDeviceContainer netA;
 
@@ -483,8 +529,18 @@ void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double
   ns3::Ptr<ns3::Node> a = src->ns3_node_;
   ns3::Ptr<ns3::Node> b = dst->ns3_node_;
 
+  bool initial_ip_reserved;
+
   if (policy == simgrid::s4u::Link::SharingPolicy::WIFI) {
-    /* Install a ns3::WifiHelper */
+      mac.SetType ("ns3::StaWifiMac",
+                   "ActiveProbing", ns3::BooleanValue (false));
+      netA.Add(wifi.Install (phy, mac, a));
+      netA.Add(wifi.Install (phy, mac, b));
+
+      mobility.Install (a);
+      mobility.Install (b);
+
+      initial_ip_reserved = true;
   } else {
     ns3::PointToPointHelper pointToPoint;
 
@@ -494,21 +550,29 @@ void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double
     pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
 
     netA.Add(pointToPoint.Install(a, b));
+    initial_ip_reserved = false;
   }
 
-  std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
-  address.SetBase(addr.c_str(), "255.255.0.0");
+  XBT_INFO("1");
+  std::string addr = simgrid::xbt::string_printf("%d.%d.0.10", number_of_networks, number_of_links, initial_ip_reserved);
+  address.SetBase(addr.c_str(), "255.255.0.0", "0.0.0.2");
   XBT_DEBUG("\tInterface stack '%s'", addr.c_str());
+  XBT_INFO("1.5");
   interfaces.Add(address.Assign (netA));
 
+  XBT_INFO("2");
+
   if (IPV4addr.size() <= (unsigned)srcNum)
     IPV4addr.resize(srcNum + 1);
   IPV4addr[srcNum] = transformIpv4Address(interfaces.GetAddress(interfaces.GetN() - 2));
 
+  XBT_INFO("3");
+
   if (IPV4addr.size() <= (unsigned)dstNum)
     IPV4addr.resize(dstNum + 1);
   IPV4addr[dstNum] = transformIpv4Address(interfaces.GetAddress(interfaces.GetN() - 1));
 
+  XBT_INFO("4");
   if (number_of_links == 255){
     xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
     number_of_links = 1;
@@ -516,4 +580,5 @@ void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double
   } else {
     number_of_links++;
   }
+  XBT_INFO("5");
 }