40 #include "ns3/core-module.h"
41 #include "ns3/network-module.h"
42 #include "ns3/wifi-module.h"
43 #include "ns3/stats-module.h"
44 #include "ns3/mobility-module.h"
45 #include "ns3/propagation-module.h"
68 NS_LOG_DEBUG (
"Change from " << oldVal <<
" to " << newVal);
105 StandardInfo (std::string name,
enum WifiPhyStandard standard, uint16_t width,
double snrLow,
double snrHigh,
double xMin,
double xMax,
double yMax)
107 m_standard (standard),
134 actualDataset.
Add (snr, currentRate);
141 int main (
int argc,
char *argv[])
143 std::vector <StandardInfo> serverStandards;
144 std::vector <StandardInfo> clientStandards;
146 uint32_t rtsThreshold = 999999;
147 uint32_t maxAmpduSize = 65535;
156 uint16_t serverNss = 1;
157 uint16_t clientNss = 1;
158 uint16_t serverShortGuardInterval = 800;
159 uint16_t clientShortGuardInterval = 800;
160 uint16_t serverChannelWidth = 20;
161 uint16_t clientChannelWidth = 20;
162 std::string wifiManager (
"Ideal");
163 std::string standard (
"802.11a");
166 bool infrastructure =
false;
169 cmd.
AddValue (
"rtsThreshold",
"RTS threshold", rtsThreshold);
170 cmd.
AddValue (
"maxAmpduSize",
"Max A-MPDU size", maxAmpduSize);
171 cmd.
AddValue (
"stepSize",
"Power between steps (dBm)", stepSize);
172 cmd.
AddValue (
"stepTime",
"Time on each step (seconds)", stepTime);
173 cmd.
AddValue (
"broadcast",
"Send broadcast instead of unicast", broadcast);
174 cmd.
AddValue (
"serverChannelWidth",
"Set channel width of the server (valid only for 802.11n or ac)", serverChannelWidth);
175 cmd.
AddValue (
"clientChannelWidth",
"Set channel width of the client (valid only for 802.11n or ac)", clientChannelWidth);
176 cmd.
AddValue (
"serverNss",
"Set nss of the server (valid only for 802.11n or ac)", serverNss);
177 cmd.
AddValue (
"clientNss",
"Set nss of the client (valid only for 802.11n or ac)", clientNss);
178 cmd.
AddValue (
"serverShortGuardInterval",
"Set short guard interval of the server (802.11n/ac/ax) in nanoseconds", serverShortGuardInterval);
179 cmd.
AddValue (
"clientShortGuardInterval",
"Set short guard interval of the client (802.11n/ac/ax) in nanoseconds", clientShortGuardInterval);
180 cmd.
AddValue (
"standard",
"Set standard (802.11a, 802.11b, 802.11g, 802.11n-5GHz, 802.11n-2.4GHz, 802.11ac, 802.11-holland, 802.11-10MHz, 802.11-5MHz, 802.11ax-5GHz, 802.11ax-2.4GHz)", standard);
181 cmd.
AddValue (
"wifiManager",
"Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, MinstrelHt, Onoe, Rraa)", wifiManager);
182 cmd.
AddValue (
"infrastructure",
"Use infrastructure instead of adhoc", infrastructure);
183 cmd.
Parse (argc,argv);
186 std::cout << std::endl <<
"This program demonstrates and plots the operation of different " << std::endl;
187 std::cout <<
"Wi-Fi rate controls on different station configurations," << std::endl;
188 std::cout <<
"by stepping down the received signal strength across a wide range" << std::endl;
189 std::cout <<
"and observing the adjustment of the rate." << std::endl;
190 std::cout <<
"Run 'wifi-manager-example --PrintHelp' to show program options."<< std::endl << std::endl;
192 if (infrastructure ==
false)
194 NS_ABORT_MSG_IF (serverNss != clientNss,
"In ad hoc mode, we assume sender and receiver are similarly configured");
197 if (standard ==
"802.11b")
199 NS_ABORT_MSG_IF (serverChannelWidth != 22 && serverChannelWidth != 22,
"Invalid channel width for standard " << standard);
200 NS_ABORT_MSG_IF (serverNss != 1,
"Invalid nss for standard " << standard);
201 NS_ABORT_MSG_IF (clientChannelWidth != 22 && clientChannelWidth != 22,
"Invalid channel width for standard " << standard);
202 NS_ABORT_MSG_IF (clientNss != 1,
"Invalid nss for standard " << standard);
204 else if (standard ==
"802.11a" || standard ==
"802.11g")
206 NS_ABORT_MSG_IF (serverChannelWidth != 20,
"Invalid channel width for standard " << standard);
207 NS_ABORT_MSG_IF (serverNss != 1,
"Invalid nss for standard " << standard);
208 NS_ABORT_MSG_IF (clientChannelWidth != 20,
"Invalid channel width for standard " << standard);
209 NS_ABORT_MSG_IF (clientNss != 1,
"Invalid nss for standard " << standard);
211 else if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz")
213 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40,
"Invalid channel width for standard " << standard);
214 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
215 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40,
"Invalid channel width for standard " << standard);
216 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
218 else if (standard ==
"802.11ac")
220 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160,
"Invalid channel width for standard " << standard);
221 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
222 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160,
"Invalid channel width for standard " << standard);
223 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
225 else if (standard ==
"802.11ax-5GHz" || standard ==
"802.11ax-2.4GHz")
227 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160,
"Invalid channel width for standard " << standard);
228 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
229 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160,
"Invalid channel width for standard " << standard);
230 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
233 std::string plotName =
"wifi-manager-example-";
234 std::string dataName =
"wifi-manager-example-";
235 plotName += wifiManager;
236 dataName += wifiManager;
239 plotName += standard;
240 dataName += standard;
241 if (standard ==
"802.11n-5GHz" ||
242 standard ==
"802.11n-2.4GHz" ||
243 standard ==
"802.11ac" ||
244 standard ==
"802.11ax-5GHz" ||
245 standard ==
"802.11ax-2.4GHz")
247 plotName +=
"-server=";
248 dataName +=
"-server=";
249 std::ostringstream oss;
250 oss << serverChannelWidth <<
"MHz_" << serverShortGuardInterval <<
"ns_" << serverNss <<
"SS";
251 plotName += oss.str ();
252 dataName += oss.str ();
253 plotName +=
"-client=";
254 dataName +=
"-client=";
256 oss << clientChannelWidth <<
"MHz_" << clientShortGuardInterval <<
"ns_" << clientNss <<
"SS";
257 plotName += oss.str ();
258 dataName += oss.str ();
262 std::ofstream outfile (dataName.c_str ());
266 uint32_t channelRateFactor =
std::max (clientChannelWidth, serverChannelWidth) / 20;
267 channelRateFactor = channelRateFactor *
std::max (clientNss, serverNss);
296 for (std::vector<StandardInfo>::size_type i = 0; i != serverStandards.size (); i++)
298 if (standard == serverStandards[i].m_name)
300 serverSelectedStandard = serverStandards[i];
303 for (std::vector<StandardInfo>::size_type i = 0; i != clientStandards.size (); i++)
305 if (standard == clientStandards[i].m_name)
307 clientSelectedStandard = clientStandards[i];
313 std::cout <<
"Testing " << serverSelectedStandard.
m_name <<
" with " << wifiManager <<
" ..." << std::endl;
315 steps = std::abs ((
int) (clientSelectedStandard.
m_snrHigh - clientSelectedStandard.
m_snrLow ) / stepSize) + 1;
317 Ptr<Node> clientNode = CreateObject<Node> ();
318 Ptr<Node> serverNode = CreateObject<Node> ();
321 wifi.SetStandard (serverSelectedStandard.
m_standard);
334 wifi.SetRemoteStationManager (
"ns3::" + wifiManager +
"WifiManager",
"RtsCtsThreshold",
UintegerValue (rtsThreshold));
343 wifiMac.
SetType (
"ns3::StaWifiMac",
346 serverDevice = wifi.Install (wifiPhy, wifiMac, serverNode);
347 wifiMac.
SetType (
"ns3::ApWifiMac",
350 clientDevice = wifi.Install (wifiPhy, wifiMac, clientNode);
354 wifiMac.
SetType (
"ns3::AdhocWifiMac",
356 serverDevice = wifi.Install (wifiPhy, wifiMac, serverNode);
357 clientDevice = wifi.Install (wifiPhy, wifiMac, clientNode);
360 if (wifiManager ==
"MinstrelHt")
372 positionAlloc->
Add (Vector (ap1_x, ap1_y, 0.0));
373 NS_LOG_INFO (
"Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
374 positionAlloc->
Add (Vector (sta1_x, sta1_y, 0.0));
375 NS_LOG_INFO (
"Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
397 wifiPhyPtrClient->SetMaxSupportedTxSpatialStreams (clientNss);
398 wifiPhyPtrClient->SetMaxSupportedRxSpatialStreams (clientNss);
403 if (serverSelectedStandard.
m_name ==
"802.11n-5GHz"
404 || serverSelectedStandard.
m_name ==
"802.11n-2.4GHz"
405 || serverSelectedStandard.
m_name ==
"802.11ac")
409 wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.
m_width);
410 wifiPhyPtrClient->SetShortGuardInterval (clientShortGuardInterval == 400);
412 else if (serverSelectedStandard.
m_name ==
"802.11ax-5GHz"
413 || serverSelectedStandard.
m_name ==
"802.11ax-2.4GHz")
417 wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.
m_width);
418 wifiPhyPtrClient->SetGuardInterval (
NanoSeconds (clientShortGuardInterval));
420 NS_LOG_DEBUG (
"Channel width " << wifiPhyPtrClient->GetChannelWidth () <<
" noiseDbm " <<
noiseDbm);
421 NS_LOG_DEBUG (
"NSS " << wifiPhyPtrClient->GetMaxSupportedTxSpatialStreams ());
426 rssLossModel->
SetRss (rssCurrent);
427 NS_LOG_INFO (
"Setting initial Rss to " << rssCurrent);
432 packetSocketHelper.
Install (serverNode);
433 packetSocketHelper.
Install (clientNode);
457 double rate = clientSelectedStandard.
m_yMax * 1e6 * 1.10;
458 double clientInterval =
static_cast<double> (
packetSize) * 8 / rate;
459 NS_LOG_DEBUG (
"Setting interval to " << clientInterval <<
" sec for rate of " << rate <<
" bits/sec");
467 serverNode->AddApplication (server);
473 gnuplot.AddDataset (rateDataset);
474 gnuplot.AddDataset (actualDataset);
476 std::ostringstream xMinStr, xMaxStr, yMaxStr;
477 std::string xRangeStr (
"set xrange [");
478 xMinStr << clientSelectedStandard.
m_xMin;
479 xRangeStr.append (xMinStr.str ());
480 xRangeStr.append (
":");
481 xMaxStr << clientSelectedStandard.
m_xMax;
482 xRangeStr.append (xMaxStr.str ());
483 xRangeStr.append (
"]");
484 std::string yRangeStr (
"set yrange [0:");
485 yMaxStr << clientSelectedStandard.
m_yMax;
486 yRangeStr.append (yMaxStr.str ());
487 yRangeStr.append (
"]");
489 std::string title (
"Results for ");
490 title.append (standard);
491 title.append (
" with ");
492 title.append (wifiManager);
493 title.append (
"\\n");
494 if (standard ==
"802.11n-5GHz"
495 || standard ==
"802.11n-2.4GHz"
496 || standard ==
"802.11ac"
497 || standard ==
"802.11n-5GHz"
498 || standard ==
"802.11ax-2.4GHz")
500 std::ostringstream serverGiStrStr;
501 std::ostringstream serverWidthStrStr;
502 std::ostringstream serverNssStrStr;
503 title.append (
"server: width=");
504 serverWidthStrStr << serverSelectedStandard.
m_width;
505 title.append (serverWidthStrStr.str ());
506 title.append (
"MHz");
507 title.append (
" GI=");
508 serverGiStrStr << serverShortGuardInterval;
509 title.append (serverGiStrStr.str ());
511 title.append (
" nss=");
512 serverNssStrStr << serverNss;
513 title.append (serverNssStrStr.str ());
514 title.append (
"\\n");
515 std::ostringstream clientGiStrStr;
516 std::ostringstream clientWidthStrStr;
517 std::ostringstream clientNssStrStr;
518 title.append (
"client: width=");
519 clientWidthStrStr << clientSelectedStandard.
m_width;
520 title.append (clientWidthStrStr.str ());
521 title.append (
"MHz");
522 title.append (
" GI=");
523 clientGiStrStr << clientShortGuardInterval;
524 title.append (clientGiStrStr.str ());
526 title.append (
" nss=");
527 clientNssStrStr << clientNss;
528 title.append (clientNssStrStr.str ());
530 gnuplot.SetTerminal (
"postscript eps color enh \"Times-BoldItalic\"");
531 gnuplot.SetLegend (
"SNR (dB)",
"Rate (Mb/s)");
532 gnuplot.SetTitle (title);
533 gnuplot.SetExtra (xRangeStr);
534 gnuplot.AppendExtra (yRangeStr);
535 gnuplot.AppendExtra (
"set key top left");
536 gnuplot.GenerateOutput (outfile);
ERP-OFDM PHY (Clause 19, Section 19.5)
void Set(std::string name, const AttributeValue &v)
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
AttributeValue implementation for Boolean.
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
HT PHY for the 5 GHz band (clause 20)
Class to represent a 2D points plot.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Make it easy to create and manage PHY objects for the yans model.
an address for a packet socket
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
HE PHY for the 2.4 GHz band (clause 26)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
double m_snrLow
lowest SNR
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
const double NOISE_DBM_Hz
HT PHY for the 2.4 GHz band (clause 20)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
double stepSize
step size in dBm
helps to create WifiNetDevice objects
void ChangeSignalAndReportRate(Ptr< FixedRssLossModel > rssModel, struct Step step, double rss, Gnuplot2dDataset &rateDataset, Gnuplot2dDataset &actualDataset)
Give ns3::PacketSocket powers to ns3::Node.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
a polymophic address class
void SetChannel(Ptr< YansWifiChannel > channel)
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
Ptr< WifiPhy > GetPhy(void) const
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
HE PHY for the 5 GHz band (clause 26)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
AttributeValue implementation for Time.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Hold together all Wifi-related objects.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
void Add(double x, double y)
void PacketRx(Ptr< const Packet > pkt, const Address &addr)
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
double m_snrHigh
highest SNR
enum WifiPhyStandard m_standard
standard
void RateChangeMinstrelHt(uint64_t newVal, Mac48Address dest)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPhysicalAddress(const Address address)
Set the destination address.
virtual void SetChannelWidth(uint8_t channelwidth)
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void SetShortGuardInterval(bool shortGuardInterval)
Enable or disable support for HT/VHT short guard interval.
void SetMaxSupportedRxSpatialStreams(uint8_t streams)
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
create MAC layers for a ns3::WifiNetDevice.
static Time Now(void)
Return the current simulation virtual time.
void SetGuardInterval(Time guardInterval)
The IEEE 802.11 SSID Information Element.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Helper class used to assign positions and mobility models to nodes.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
uint16_t m_width
channel width
void SetMaxSupportedTxSpatialStreams(uint8_t streams)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
AttributeValue implementation for Ssid.
double stepTime
step size in seconds
void SetProtocol(uint16_t protocol)
Set the protocol.
void Add(Vector v)
Add a position to the list of positions.
void Parse(int argc, char *argv[])
Parse the program arguments.
void SetNumberOfAntennas(uint8_t antennas)
static const uint32_t packetSize
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
void RateChange(uint64_t oldVal, uint64_t newVal)
This class can be used to hold variables of floating point type such as 'double' or 'float'...
StandardInfo(std::string name, enum WifiPhyStandard standard, uint16_t width, double snrLow, double snrHigh, double xMin, double xMax, double yMax)
Constructor.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void SetStartTime(Time start)
Specify application start time.