38#include "ns3/attribute-container.h"
39#include "ns3/boolean.h"
40#include "ns3/command-line.h"
41#include "ns3/config.h"
42#include "ns3/double.h"
44#include "ns3/gnuplot.h"
45#include "ns3/he-configuration.h"
46#include "ns3/ht-configuration.h"
48#include "ns3/mobility-helper.h"
49#include "ns3/packet-socket-client.h"
50#include "ns3/packet-socket-helper.h"
51#include "ns3/packet-socket-server.h"
52#include "ns3/propagation-delay-model.h"
53#include "ns3/propagation-loss-model.h"
54#include "ns3/rng-seed-manager.h"
57#include "ns3/uinteger.h"
58#include "ns3/wifi-mac.h"
59#include "ns3/wifi-net-device.h"
60#include "ns3/yans-wifi-helper.h"
90 NS_LOG_DEBUG(
"Change from " << oldVal <<
" to " << newVal);
173 dB_u snr{rss - noise};
177 actualDataset.
Add(snr, currentRate);
178 const auto newRss = rss - step.
stepSize;
179 rssModel->SetRss(newRss);
182 <<
"; setting new power to " << newRss);
195main(
int argc,
char* argv[])
197 std::vector<StandardInfo> serverStandards;
198 std::vector<StandardInfo> clientStandards;
205 bool broadcast =
false;
210 uint16_t serverNss = 1;
211 uint16_t clientNss = 1;
212 uint16_t serverShortGuardInterval = 800;
213 uint16_t clientShortGuardInterval = 800;
214 MHz_u serverChannelWidth{0};
215 MHz_u clientChannelWidth{0};
216 std::string wifiManager(
"Ideal");
217 std::string standard(
"802.11a");
220 bool infrastructure =
false;
227 cmd.AddValue(
"maxRetryCount",
228 "The maximum number of retransmission attempts for a Data packet",
230 cmd.AddValue(
"rtsThreshold",
"RTS threshold", rtsThreshold);
231 cmd.AddValue(
"maxAmpduSize",
"Max A-MPDU size", maxAmpduSize);
232 cmd.AddValue(
"stepSize",
"Power between steps (dBm)", stepSize);
233 cmd.AddValue(
"stepTime",
"Time on each step (seconds)", stepTime);
234 cmd.AddValue(
"broadcast",
"Send broadcast instead of unicast", broadcast);
235 cmd.AddValue(
"serverChannelWidth",
236 "Set channel width of the server (valid only for 802.11n or ac)",
238 cmd.AddValue(
"clientChannelWidth",
239 "Set channel width of the client (valid only for 802.11n or ac)",
241 cmd.AddValue(
"serverNss",
"Set nss of the server (valid only for 802.11n or ac)", serverNss);
242 cmd.AddValue(
"clientNss",
"Set nss of the client (valid only for 802.11n or ac)", clientNss);
243 cmd.AddValue(
"serverShortGuardInterval",
244 "Set short guard interval of the server (802.11n/ac/ax) in nanoseconds",
245 serverShortGuardInterval);
246 cmd.AddValue(
"clientShortGuardInterval",
247 "Set short guard interval of the client (802.11n/ac/ax) in nanoseconds",
248 clientShortGuardInterval);
251 "Set standard (802.11a, 802.11b, 802.11g, 802.11p-10MHz, 802.11p-5MHz, 802.11n-5GHz, "
252 "802.11n-2.4GHz, 802.11ac, 802.11ax-6GHz, 802.11ax-5GHz, 802.11ax-2.4GHz, 802.11be-6GHz, "
253 "802.11be-5GHz, 802.11be-2.4GHz)",
255 cmd.AddValue(
"wifiManager",
256 "Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, "
257 "MinstrelHt, Onoe, Rraa, ThompsonSampling)",
259 cmd.AddValue(
"infrastructure",
"Use infrastructure instead of adhoc", infrastructure);
260 cmd.Parse(argc, argv);
263 std::cout << std::endl
264 <<
"This program demonstrates and plots the operation of different " << std::endl;
265 std::cout <<
"Wi-Fi rate controls on different station configurations," << std::endl;
266 std::cout <<
"by stepping down the received signal strength across a wide range" << std::endl;
267 std::cout <<
"and observing the adjustment of the rate." << std::endl;
268 std::cout <<
"Run 'wifi-manager-example --PrintHelp' to show program options." << std::endl
274 "In ad hoc mode, we assume sender and receiver are similarly configured");
277 if (standard ==
"802.11b")
279 if (serverChannelWidth ==
MHz_u{0})
284 "Invalid channel width for standard " << standard);
285 NS_ABORT_MSG_IF(serverNss != 1,
"Invalid nss for standard " << standard);
286 if (clientChannelWidth ==
MHz_u{0})
291 "Invalid channel width for standard " << standard);
292 NS_ABORT_MSG_IF(clientNss != 1,
"Invalid nss for standard " << standard);
294 else if (standard ==
"802.11a" || standard ==
"802.11g")
296 if (serverChannelWidth ==
MHz_u{0})
301 "Invalid channel width for standard " << standard);
302 NS_ABORT_MSG_IF(serverNss != 1,
"Invalid nss for standard " << standard);
303 if (clientChannelWidth ==
MHz_u{0})
308 "Invalid channel width for standard " << standard);
309 NS_ABORT_MSG_IF(clientNss != 1,
"Invalid nss for standard " << standard);
311 else if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz")
315 if (serverChannelWidth ==
MHz_u{0})
320 "Invalid channel width for standard " << standard);
322 "Invalid nss " << serverNss <<
" for standard " << standard);
323 if (clientChannelWidth ==
MHz_u{0})
328 "Invalid channel width for standard " << standard);
330 "Invalid nss " << clientNss <<
" for standard " << standard);
332 else if (standard ==
"802.11ac")
334 if (serverChannelWidth ==
MHz_u{0})
339 serverChannelWidth !=
MHz_u{80} && serverChannelWidth !=
MHz_u{160} &&
340 serverChannelWidth !=
MHz_u{320},
341 "Invalid channel width for standard " << standard);
343 "Invalid nss " << serverNss <<
" for standard " << standard);
344 if (clientChannelWidth ==
MHz_u{0})
349 clientChannelWidth !=
MHz_u{80} && clientChannelWidth !=
MHz_u{160} &&
350 clientChannelWidth !=
MHz_u{320},
351 "Invalid channel width for standard " << standard);
353 "Invalid nss " << clientNss <<
" for standard " << standard);
355 else if (standard ==
"802.11ax-6GHz" || standard ==
"802.11ax-5GHz" ||
356 standard ==
"802.11ax-2.4GHz" || standard ==
"802.11be-6GHz" ||
357 standard ==
"802.11be-5GHz" || standard ==
"802.11be-2.4GHz")
362 if (serverChannelWidth ==
MHz_u{0})
367 serverChannelWidth !=
MHz_u{80} && serverChannelWidth !=
MHz_u{160} &&
368 serverChannelWidth !=
MHz_u{320},
369 "Invalid channel width for standard " << standard);
371 "Invalid nss " << serverNss <<
" for standard " << standard);
372 if (clientChannelWidth ==
MHz_u{0})
377 clientChannelWidth !=
MHz_u{80} && clientChannelWidth !=
MHz_u{160} &&
378 clientChannelWidth !=
MHz_u{320},
379 "Invalid channel width for standard " << standard);
381 "Invalid nss " << clientNss <<
" for standard " << standard);
385 uint32_t channelRateFactor = std::max(clientChannelWidth, serverChannelWidth) /
MHz_u{20};
386 channelRateFactor = channelRateFactor * std::max(clientNss, serverNss);
427 80 * channelRateFactor),
436 80 * channelRateFactor),
445 120 * channelRateFactor),
472 120 * channelRateFactor),
481 120 * channelRateFactor),
490 120 * channelRateFactor),
499 120 * channelRateFactor),
508 120 * channelRateFactor),
517 120 * channelRateFactor),
556 80 * channelRateFactor),
565 80 * channelRateFactor),
574 120 * channelRateFactor),
601 160 * channelRateFactor),
610 160 * channelRateFactor),
619 160 * channelRateFactor),
628 160 * channelRateFactor),
637 160 * channelRateFactor),
646 160 * channelRateFactor),
649 for (std::vector<StandardInfo>::size_type i = 0; i != serverStandards.size(); i++)
651 if (standard == serverStandards[i].m_name)
653 serverSelectedStandard = serverStandards[i];
656 for (std::vector<StandardInfo>::size_type i = 0; i != clientStandards.size(); i++)
658 if (standard == clientStandards[i].m_name)
660 clientSelectedStandard = clientStandards[i];
665 "Standard " << standard <<
" not found");
667 "Standard " << standard <<
" not found");
668 std::cout <<
"Testing " << serverSelectedStandard.
m_name <<
" with " << wifiManager <<
" ..."
671 "SNR values in wrong order");
672 steps =
static_cast<uint32_t>(std::abs(
static_cast<double>(clientSelectedStandard.
m_snrHigh -
677 <<
":" << clientSelectedStandard.
m_snrHigh);
681 std::string plotName =
"wifi-manager-example-";
682 std::string dataName =
"wifi-manager-example-";
683 plotName += wifiManager;
684 dataName += wifiManager;
687 plotName += standard;
688 dataName += standard;
689 if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz" || standard ==
"802.11ac" ||
690 standard ==
"802.11ax-6GHz" || standard ==
"802.11ax-5GHz" || standard ==
"802.11ax-2.4GHz")
692 plotName +=
"-server_";
693 dataName +=
"-server_";
694 std::ostringstream oss;
695 oss << serverChannelWidth <<
"MHz_" << serverShortGuardInterval <<
"ns_" << serverNss
697 plotName += oss.str();
698 dataName += oss.str();
699 plotName +=
"-client_";
700 dataName +=
"-client_";
702 oss << clientChannelWidth <<
"MHz_" << clientShortGuardInterval <<
"ns_" << clientNss
704 plotName += oss.str();
705 dataName += oss.str();
709 std::ofstream outfile(dataName);
738 wifiChannel->SetPropagationDelayModel(delayModel);
740 wifiChannel->SetPropagationLossModel(rssLossModel);
743 wifi.SetRemoteStationManager(
"ns3::" + wifiManager +
"WifiManager",
758 {0, serverSelectedStandard.
m_width, serverSelectedStandard.
m_band, 0}});
759 wifiPhy.
Set(
"ChannelSettings", channelValue);
760 serverDevice =
wifi.Install(wifiPhy, wifiMac, serverNode);
764 {0, clientSelectedStandard.
m_width, clientSelectedStandard.
m_band, 0}});
765 wifiPhy.
Set(
"ChannelSettings", channelValue);
766 clientDevice =
wifi.Install(wifiPhy, wifiMac, clientNode);
770 wifiMac.
SetType(
"ns3::AdhocWifiMac");
772 {0, serverSelectedStandard.
m_width, serverSelectedStandard.
m_band, 0}});
773 wifiPhy.
Set(
"ChannelSettings", channelValue);
774 serverDevice =
wifi.Install(wifiPhy, wifiMac, serverNode);
777 {0, clientSelectedStandard.
m_width, clientSelectedStandard.
m_band, 0}});
778 wifiPhy.
Set(
"ChannelSettings", channelValue);
779 clientDevice =
wifi.Install(wifiPhy, wifiMac, clientNode);
785 Config::Set(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
789 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$ns3::" + wifiManager +
797 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
798 NS_LOG_INFO(
"Setting initial AP position to " << Vector(ap1_x, ap1_y, 0.0));
799 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
800 NS_LOG_INFO(
"Setting initial STA position to " << Vector(sta1_x, sta1_y, 0.0));
801 mobility.SetPositionAllocator(positionAlloc);
802 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
821 auto t_clientNss =
static_cast<uint8_t
>(clientNss);
822 auto t_serverNss =
static_cast<uint8_t
>(serverNss);
823 wifiPhyPtrClient->SetNumberOfAntennas(t_clientNss);
824 wifiPhyPtrClient->SetMaxSupportedTxSpatialStreams(t_clientNss);
825 wifiPhyPtrClient->SetMaxSupportedRxSpatialStreams(t_clientNss);
826 wifiPhyPtrServer->SetNumberOfAntennas(t_serverNss);
827 wifiPhyPtrServer->SetMaxSupportedTxSpatialStreams(t_serverNss);
828 wifiPhyPtrServer->SetMaxSupportedRxSpatialStreams(t_serverNss);
830 if (serverSelectedStandard.
m_name ==
"802.11n-5GHz" ||
831 serverSelectedStandard.
m_name ==
"802.11n-2.4GHz" ||
832 serverSelectedStandard.
m_name ==
"802.11ac")
835 clientHtConfiguration->m_sgiSupported = (clientShortGuardInterval == 400);
837 serverHtConfiguration->m_sgiSupported = (serverShortGuardInterval == 400);
839 else if (serverSelectedStandard.
m_name ==
"802.11ax-6GHz" ||
840 serverSelectedStandard.
m_name ==
"802.11ax-5GHz" ||
841 serverSelectedStandard.
m_name ==
"802.11ax-2.4GHz" ||
842 serverSelectedStandard.
m_name ==
"802.11be-6GHz" ||
843 serverSelectedStandard.
m_name ==
"802.11be-5GHz" ||
844 serverSelectedStandard.
m_name ==
"802.11be-2.4GHz")
846 wndServer->GetHeConfiguration()->SetGuardInterval(
NanoSeconds(serverShortGuardInterval));
847 wndClient->GetHeConfiguration()->SetGuardInterval(
NanoSeconds(clientShortGuardInterval));
851 const auto BOLTZMANN = 1.3803e-23;
853 const dBm_u noise = noiseDensity + (10 * log10(clientSelectedStandard.
m_width * 1000000));
855 NS_LOG_DEBUG(
"Channel width " << wifiPhyPtrClient->GetChannelWidth() <<
" noise " << noise);
856 NS_LOG_DEBUG(
"NSS " << wifiPhyPtrClient->GetMaxSupportedTxSpatialStreams());
858 const dBm_u rssCurrent = (clientSelectedStandard.
m_snrHigh + noise);
859 rssLossModel->SetRss(rssCurrent);
860 NS_LOG_INFO(
"Setting initial Rss to " << rssCurrent);
872 packetSocketHelper.
Install(serverNode);
873 packetSocketHelper.
Install(clientNode);
891 client->SetRemote(socketAddr);
897 double rate = clientSelectedStandard.
m_yMax * 1e6 * 1.10;
898 double clientInterval =
static_cast<double>(
packetSize) * 8 / rate;
899 NS_LOG_DEBUG(
"Setting interval to " << clientInterval <<
" sec for rate of " << rate
903 clientNode->AddApplication(client);
906 server->SetLocal(socketAddr);
908 serverNode->AddApplication(server);
916 wndServer->GetMac()->GetAddress(),
918 "Expected BA agreement established for standard "
927 std::ostringstream xMinStr;
928 std::ostringstream xMaxStr;
929 std::ostringstream yMaxStr;
930 std::string xRangeStr(
"set xrange [");
931 xMinStr << clientSelectedStandard.
m_xMin;
932 xRangeStr.append(xMinStr.str());
933 xRangeStr.append(
":");
934 xMaxStr << clientSelectedStandard.
m_xMax;
935 xRangeStr.append(xMaxStr.str());
936 xRangeStr.append(
"]");
937 std::string yRangeStr(
"set yrange [0:");
938 yMaxStr << clientSelectedStandard.
m_yMax;
939 yRangeStr.append(yMaxStr.str());
940 yRangeStr.append(
"]");
942 std::string title(
"Results for ");
943 title.append(standard);
944 title.append(
" with ");
945 title.append(wifiManager);
947 if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz" || standard ==
"802.11ac" ||
948 standard ==
"802.11ax-6GHz" || standard ==
"802.11ax-5GHz" ||
949 standard ==
"802.11ax-2.4GHz" || standard ==
"802.11be-6GHz" ||
950 standard ==
"802.11be-5GHz" || standard ==
"802.11be-2.4GHz")
952 std::ostringstream serverGiStrStr;
953 std::ostringstream serverWidthStrStr;
954 std::ostringstream serverNssStrStr;
955 title.append(
"server: width=");
956 serverWidthStrStr << serverSelectedStandard.
m_width;
957 title.append(serverWidthStrStr.str());
959 title.append(
" GI=");
960 serverGiStrStr << serverShortGuardInterval;
961 title.append(serverGiStrStr.str());
963 title.append(
" nss=");
964 serverNssStrStr << serverNss;
965 title.append(serverNssStrStr.str());
967 std::ostringstream clientGiStrStr;
968 std::ostringstream clientWidthStrStr;
969 std::ostringstream clientNssStrStr;
970 title.append(
"client: width=");
971 clientWidthStrStr << clientSelectedStandard.
m_width;
972 title.append(clientWidthStrStr.str());
974 title.append(
" GI=");
975 clientGiStrStr << clientShortGuardInterval;
976 title.append(clientGiStrStr.str());
978 title.append(
" nss=");
979 clientNssStrStr << clientNss;
980 title.append(clientNssStrStr.str());
982 gnuplot.
SetTerminal(
"postscript eps color enh \"Times-BoldItalic\"");
983 gnuplot.
SetLegend(
"SNR (dB)",
"Rate (Mb/s)");
a polymophic address class
void Set(const T &c)
Copy items from container c.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Class to represent a 2D points plot.
void Add(double x, double y)
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void SetTerminal(const std::string &terminal)
void AppendExtra(const std::string &extra)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void SetExtra(const std::string &extra)
void SetTitle(const std::string &title)
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
Hold together all Wifi-related objects.
void Set(std::string name, const AttributeValue &v)
void DisablePreambleDetectionModel()
Disable the preamble detection model on all links.
std::list< WifiChannelConfig::TupleWithoutUnits > ChannelSegments
segments identifying an operating channel
AttributeContainerValue< ChannelTupleValue, ';'> ChannelSettingsValue
AttributeValue type of a ChannelSegments object.
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void SetDefault(std::string name, const AttributeValue &value)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
void Set(std::string path, const AttributeValue &value)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyBand
Identifies the PHY band.
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
double MHz_u
MHz weak type.
double dBm_per_Hz_u
dBm/Hz weak type
MHz_u GetDefaultChannelWidth(WifiStandard standard, WifiPhyBand band)
Get the default channel width for the given PHY standard and band.
double dBm_u
dBm weak type
StandardInfo(std::string name, WifiStandard standard, WifiPhyBand band, MHz_u width, dB_u snrLow, dB_u snrHigh, double xMin, double xMax, double yMax)
Constructor.
WifiStandard m_standard
standard
WifiPhyBand m_band
PHY band.
dB_u m_snrHigh
highest SNR
MHz_u m_width
channel width
double stepTime
step size in seconds
uint64_t g_intervalRate
Rate in an interval.
void ChangeSignalAndReportRate(Ptr< FixedRssLossModel > rssModel, Step step, dBm_u rss, dBm_u noise, Gnuplot2dDataset &rateDataset, Gnuplot2dDataset &actualDataset)
Change the signal model and report the rate.
void RateChange(uint64_t oldVal, uint64_t newVal)
Rate changed.
void PacketRx(Ptr< const Packet > pkt, const Address &addr)
Packet received.
double g_intervalBytes
Bytes received in an interval.
static const uint32_t packetSize
Packet size generated at the AP.