From: adrien gougeon Date: Wed, 8 Jul 2020 15:15:08 +0000 (+0200) Subject: added possibility to change mcs, nss and distance between nodes X-Git-Tag: v3.26~418^2~9 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3b3874b095c1a645006649b8a7445f81d816f01d added possibility to change mcs, nss and distance between nodes --- diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index da6422705c..2982843b05 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -79,59 +79,16 @@ NetPointNs3::NetPointNs3() : ns3_node_(ns3::CreateObject(0)) } WifiZone::WifiZone(std::string name_, simgrid::s4u::Host* host_, ns3::Ptr ap_node_, - ns3::Ptr channel_, int network_, int link_) : - name(name_), host(host_), ap_node(ap_node_), channel(channel_), network(network_), link(link_){ + ns3::Ptr channel_, int mcs_, int nss_, int network_, int link_) : + name(name_), host(host_), ap_node(ap_node_), channel(channel_), mcs(mcs_), nss(nss_), + network(network_), link(link_) { n_sta_nodes = 0; wifi_zones[name_] = this; } -const char* WifiZone::get_cname() { - return name.c_str(); -} - -simgrid::s4u::Host* WifiZone::get_host(){ - return host; -} - -ns3::Ptr WifiZone::get_ap_node() { - return ap_node; -} - -ns3::Ptr WifiZone::get_channel() { - return channel; -} - -int WifiZone::get_network() { - return network; -} - -int WifiZone::get_link() { - return link; -} - -int WifiZone::get_n_sta_nodes() { - return n_sta_nodes; -} - -void WifiZone::set_ap_node(ns3::Ptr ap_node_) { - ap_node = ap_node_; -} - -void WifiZone::set_network(int network_) { - network = network_; -} - -void WifiZone::set_link(int link_) { - link = link_; -} - -void WifiZone::add_sta_node() { - n_sta_nodes++; -} - -bool WifiZone::is_ap(ns3::Ptr ap){ +bool WifiZone::is_ap(ns3::Ptr node){ for (std::pair zone : wifi_zones) - if (zone.second->get_ap_node() == ap) + if (zone.second->get_ap_node() == node) return true; return false; } @@ -151,14 +108,16 @@ std::unordered_map WifiZone::wifi_zones; static void initialize_ns3_wifi() { wifi.SetStandard (ns3::WIFI_PHY_STANDARD_80211n_5GHZ); - wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "ControlMode", ns3::StringValue ("HtMcs0"), - "DataMode", ns3::StringValue ("HtMcs3")); - - std::vector hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts(); - for (auto host : hosts) - if (host->get_property("cell")) - new WifiZone(host->get_property("cell"), host, nullptr, wifiChannel.Create (), 0, 0); + + for (auto host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) { + const char* wifi_link = host->get_property("wifi_link"); + const char* wifi_mcs = host->get_property("wifi_mcs"); + const char* wifi_nss = host->get_property("wifi_nss"); + + if (wifi_link) + new WifiZone(wifi_link, host, host->get_netpoint()->extension()->ns3_node_, + wifiChannel.Create (), wifi_mcs ? atoi(wifi_mcs) : 3, wifi_nss ? atoi(wifi_nss) : 1, 0, 0); + } } /************* @@ -206,6 +165,9 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoin auto* host_src = src->extension(); auto* host_dst = dst->extension(); + host_src->set_name(src->get_name()); + host_dst->set_name(dst->get_name()); + 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()); @@ -395,13 +357,20 @@ LinkNS3::LinkNS3(NetworkNS3Model* model, const std::string& name, double bandwid ns3::NetDeviceContainer netA; WifiZone* zone = WifiZone::by_name(name); - xbt_assert(zone != 0, "Link name '%s' does not match the 'cell' property of a host.", name.c_str()); - NetPointNs3* netpoint_ns3 = zone->get_host()->get_netpoint()->extension(); + xbt_assert(zone != 0, "Link name '%s' does not match the 'wifi_link' property of a host.", name.c_str()); + NetPointNs3* netpoint_ns3 = zone->get_host()->get_netpoint()->extension(); - zone->set_ap_node(netpoint_ns3->ns3_node_); + wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", + "ControlMode", ns3::StringValue ("HtMcs0"), + "DataMode", ns3::StringValue ("HtMcs" + std::to_string(zone->get_mcs()))); wifiPhy.SetChannel (zone->get_channel()); + wifiPhy.Set("Antennas", ns3::UintegerValue(zone->get_nss())); + wifiPhy.Set("MaxSupportedTxSpatialStreams", ns3::UintegerValue(zone->get_nss())); + wifiPhy.Set("MaxSupportedRxSpatialStreams", ns3::UintegerValue(zone->get_nss())); + wifiMac.SetType("ns3::ApWifiMac"); + netA.Add(wifi.Install (wifiPhy, wifiMac, zone->get_ap_node())); ns3::Ptr positionAllocS = ns3::CreateObject (); @@ -633,15 +602,25 @@ void ns3_add_direct_route(NetPointNs3* src, NetPointNs3* dst, double bw, double WifiZone* zone = WifiZone::by_name(link_name); + wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", + "ControlMode", ns3::StringValue ("HtMcs0"), + "DataMode", ns3::StringValue ("HtMcs" + std::to_string(zone->get_mcs()))); + wifiPhy.SetChannel (zone->get_channel()); + wifiPhy.Set("Antennas", ns3::UintegerValue(zone->get_nss())); + wifiPhy.Set("MaxSupportedTxSpatialStreams", ns3::UintegerValue(zone->get_nss())); + wifiPhy.Set("MaxSupportedRxSpatialStreams", ns3::UintegerValue(zone->get_nss())); wifiMac.SetType ("ns3::StaWifiMac"); + netA.Add(wifi.Install (wifiPhy, wifiMac, staNode)); ns3::Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns3::UintegerValue (40)); + NetPointNs3* sta_netpointNs3 = WifiZone::is_ap(src->ns3_node_) ? dst : src; + const char* wifi_distance = simgrid::s4u::Host::by_name(sta_netpointNs3->name_)->get_property("wifi_distance"); ns3::Ptr positionAllocS = ns3::CreateObject (); - positionAllocS->Add(ns3::Vector(10, 0, 0)); + positionAllocS->Add(ns3::Vector( wifi_distance ? atof(wifi_distance) : 10.0 , 0, 0)); mobility.SetPositionAllocator(positionAllocS); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install(staNode); diff --git a/src/surf/ns3/ns3_simulator.hpp b/src/surf/ns3/ns3_simulator.hpp index 20c81b7124..04944b13d1 100644 --- a/src/surf/ns3/ns3_simulator.hpp +++ b/src/surf/ns3/ns3_simulator.hpp @@ -19,9 +19,13 @@ class NetPointNs3 { public: static simgrid::xbt::Extension EXTENSION_ID; + void set_name(std::string name) {name_ = name;} + explicit NetPointNs3(); + std::string name_; int node_num; ns3::Ptr ns3_node_; + }; XBT_PUBLIC void ns3_initialize(std::string TcpProtocol); @@ -55,22 +59,23 @@ static inline std::string transform_socket_ptr(ns3::Ptr local_socke class XBT_PRIVATE WifiZone { public: WifiZone(std::string name_, simgrid::s4u::Host* host_, ns3::Ptr ap_node_, - ns3::Ptr channel_, int network_, int link_); - - const char* get_cname(); - simgrid::s4u::Host* get_host(); - ns3::Ptr get_ap_node(); - ns3::Ptr get_channel(); - int get_network(); - int get_link(); - int get_n_sta_nodes(); - - void set_ap_node(ns3::Ptr ap_node_); - void set_network(int network_); - void set_link(int link_); - void add_sta_node(); - static bool is_ap(ns3::Ptr ap); - + ns3::Ptr channel_, int mcs_, int nss_, int network_, int link_); + + const char* get_cname() {return name.c_str();} + simgrid::s4u::Host* get_host(){return host;} + ns3::Ptr get_ap_node() {return ap_node;} + ns3::Ptr get_channel() {return channel;} + int get_mcs() {return mcs;} + int get_nss() {return nss;} + int get_network() {return network;} + int get_link() {return link;} + int get_n_sta_nodes() {return n_sta_nodes;} + + void set_network(int network_) {network = network_;} + void set_link(int link_) {link = link_;} + void add_sta_node() {n_sta_nodes++;} + + static bool is_ap(ns3::Ptr node); static WifiZone* by_name(std::string name); private: @@ -78,9 +83,11 @@ private: simgrid::s4u::Host* host; ns3::Ptr ap_node; ns3::Ptr channel; + int mcs; + int nss; int network; int link; - int n_sta_nodes; + int n_sta_nodes = 0; static std::unordered_map wifi_zones; };