41 #include "ns3/config.h" 42 #include "ns3/uinteger.h" 43 #include "ns3/boolean.h" 44 #include "ns3/double.h" 45 #include "ns3/gnuplot.h" 46 #include "ns3/command-line.h" 47 #include "ns3/yans-wifi-helper.h" 49 #include "ns3/propagation-loss-model.h" 50 #include "ns3/propagation-delay-model.h" 51 #include "ns3/rng-seed-manager.h" 52 #include "ns3/mobility-helper.h" 53 #include "ns3/wifi-net-device.h" 54 #include "ns3/packet-socket-helper.h" 55 #include "ns3/packet-socket-client.h" 56 #include "ns3/packet-socket-server.h" 57 #include "ns3/ht-configuration.h" 58 #include "ns3/he-configuration.h" 80 NS_LOG_DEBUG (
"Change from " << oldVal <<
" to " << newVal);
112 m_standard (standard),
139 actualDataset.
Add (snr, currentRate);
146 int main (
int argc,
char *argv[])
148 std::vector <StandardInfo> serverStandards;
149 std::vector <StandardInfo> clientStandards;
151 uint32_t rtsThreshold = 999999;
152 uint32_t maxAmpduSize = 65535;
161 uint16_t serverNss = 1;
162 uint16_t clientNss = 1;
163 uint16_t serverShortGuardInterval = 800;
164 uint16_t clientShortGuardInterval = 800;
165 uint16_t serverChannelWidth = 20;
166 uint16_t clientChannelWidth = 20;
167 std::string wifiManager (
"Ideal");
168 std::string standard (
"802.11a");
171 bool infrastructure =
false;
172 uint32_t maxSlrc = 7;
173 uint32_t maxSsrc = 7;
176 cmd.AddValue (
"maxSsrc",
"The maximum number of retransmission attempts for a RTS packet", maxSsrc);
177 cmd.AddValue (
"maxSlrc",
"The maximum number of retransmission attempts for a Data packet", maxSlrc);
178 cmd.AddValue (
"rtsThreshold",
"RTS threshold", rtsThreshold);
179 cmd.AddValue (
"maxAmpduSize",
"Max A-MPDU size", maxAmpduSize);
180 cmd.AddValue (
"stepSize",
"Power between steps (dBm)", stepSize);
181 cmd.AddValue (
"stepTime",
"Time on each step (seconds)", stepTime);
182 cmd.AddValue (
"broadcast",
"Send broadcast instead of unicast", broadcast);
183 cmd.AddValue (
"serverChannelWidth",
"Set channel width of the server (valid only for 802.11n or ac)", serverChannelWidth);
184 cmd.AddValue (
"clientChannelWidth",
"Set channel width of the client (valid only for 802.11n or ac)", clientChannelWidth);
185 cmd.AddValue (
"serverNss",
"Set nss of the server (valid only for 802.11n or ac)", serverNss);
186 cmd.AddValue (
"clientNss",
"Set nss of the client (valid only for 802.11n or ac)", clientNss);
187 cmd.AddValue (
"serverShortGuardInterval",
"Set short guard interval of the server (802.11n/ac/ax) in nanoseconds", serverShortGuardInterval);
188 cmd.AddValue (
"clientShortGuardInterval",
"Set short guard interval of the client (802.11n/ac/ax) in nanoseconds", clientShortGuardInterval);
189 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);
190 cmd.AddValue (
"wifiManager",
"Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, MinstrelHt, Onoe, Rraa)", wifiManager);
191 cmd.AddValue (
"infrastructure",
"Use infrastructure instead of adhoc", infrastructure);
192 cmd.Parse (argc,argv);
195 std::cout << std::endl <<
"This program demonstrates and plots the operation of different " << std::endl;
196 std::cout <<
"Wi-Fi rate controls on different station configurations," << std::endl;
197 std::cout <<
"by stepping down the received signal strength across a wide range" << std::endl;
198 std::cout <<
"and observing the adjustment of the rate." << std::endl;
199 std::cout <<
"Run 'wifi-manager-example --PrintHelp' to show program options." << std::endl << std::endl;
201 if (infrastructure ==
false)
203 NS_ABORT_MSG_IF (serverNss != clientNss,
"In ad hoc mode, we assume sender and receiver are similarly configured");
206 if (standard ==
"802.11b")
208 NS_ABORT_MSG_IF (serverChannelWidth != 22 && serverChannelWidth != 22,
"Invalid channel width for standard " << standard);
209 NS_ABORT_MSG_IF (serverNss != 1,
"Invalid nss for standard " << standard);
210 NS_ABORT_MSG_IF (clientChannelWidth != 22 && clientChannelWidth != 22,
"Invalid channel width for standard " << standard);
211 NS_ABORT_MSG_IF (clientNss != 1,
"Invalid nss for standard " << standard);
213 else if (standard ==
"802.11a" || standard ==
"802.11g")
215 NS_ABORT_MSG_IF (serverChannelWidth != 20,
"Invalid channel width for standard " << standard);
216 NS_ABORT_MSG_IF (serverNss != 1,
"Invalid nss for standard " << standard);
217 NS_ABORT_MSG_IF (clientChannelWidth != 20,
"Invalid channel width for standard " << standard);
218 NS_ABORT_MSG_IF (clientNss != 1,
"Invalid nss for standard " << standard);
220 else if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz")
222 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40,
"Invalid channel width for standard " << standard);
223 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
224 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40,
"Invalid channel width for standard " << standard);
225 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
227 else if (standard ==
"802.11ac")
229 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160,
"Invalid channel width for standard " << standard);
230 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
231 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160,
"Invalid channel width for standard " << standard);
232 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
234 else if (standard ==
"802.11ax-5GHz" || standard ==
"802.11ax-2.4GHz")
236 NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160,
"Invalid channel width for standard " << standard);
237 NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4,
"Invalid nss " << serverNss <<
" for standard " << standard);
238 NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160,
"Invalid channel width for standard " << standard);
239 NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4,
"Invalid nss " << clientNss <<
" for standard " << standard);
243 uint32_t channelRateFactor =
std::max (clientChannelWidth, serverChannelWidth) / 20;
244 channelRateFactor = channelRateFactor *
std::max (clientNss, serverNss);
273 for (std::vector<StandardInfo>::size_type i = 0; i != serverStandards.size (); i++)
275 if (standard == serverStandards[i].m_name)
277 serverSelectedStandard = serverStandards[i];
280 for (std::vector<StandardInfo>::size_type i = 0; i != clientStandards.size (); i++)
282 if (standard == clientStandards[i].m_name)
284 clientSelectedStandard = clientStandards[i];
290 std::cout <<
"Testing " << serverSelectedStandard.
m_name <<
" with " << wifiManager <<
" ..." << std::endl;
292 steps =
static_cast<uint32_t
> (std::abs (static_cast<double> (clientSelectedStandard.
m_snrHigh - clientSelectedStandard.
m_snrLow ) / stepSize) + 1);
294 Ptr<Node> clientNode = CreateObject<Node> ();
295 Ptr<Node> serverNode = CreateObject<Node> ();
297 std::string plotName =
"wifi-manager-example-";
298 std::string dataName =
"wifi-manager-example-";
299 plotName += wifiManager;
300 dataName += wifiManager;
303 plotName += standard;
304 dataName += standard;
305 if (standard ==
"802.11n-5GHz" 306 || standard ==
"802.11n-2.4GHz" 307 || standard ==
"802.11ac" 308 || standard ==
"802.11ax-5GHz" 309 || standard ==
"802.11ax-2.4GHz")
311 plotName +=
"-server_";
312 dataName +=
"-server_";
313 std::ostringstream oss;
314 oss << serverChannelWidth <<
"MHz_" << serverShortGuardInterval <<
"ns_" << serverNss <<
"SS";
315 plotName += oss.str ();
316 dataName += oss.str ();
317 plotName +=
"-client_";
318 dataName +=
"-client_";
320 oss << clientChannelWidth <<
"MHz_" << clientShortGuardInterval <<
"ns_" << clientNss <<
"SS";
321 plotName += oss.str ();
322 dataName += oss.str ();
326 std::ofstream outfile (dataName.c_str ());
346 wifi.SetRemoteStationManager (
"ns3::" + wifiManager +
"WifiManager",
"RtsCtsThreshold",
UintegerValue (rtsThreshold));
355 wifiMac.
SetType (
"ns3::StaWifiMac",
357 serverDevice =
wifi.Install (wifiPhy, wifiMac, serverNode);
358 wifiMac.
SetType (
"ns3::ApWifiMac",
360 clientDevice =
wifi.Install (wifiPhy, wifiMac, clientNode);
364 wifiMac.
SetType (
"ns3::AdhocWifiMac");
365 serverDevice =
wifi.Install (wifiPhy, wifiMac, serverNode);
366 clientDevice =
wifi.Install (wifiPhy, wifiMac, clientNode);
371 wifi.AssignStreams (serverDevice, 100);
372 wifi.AssignStreams (clientDevice, 100);
382 positionAlloc->
Add (Vector (ap1_x, ap1_y, 0.0));
383 NS_LOG_INFO (
"Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
384 positionAlloc->
Add (Vector (sta1_x, sta1_y, 0.0));
385 NS_LOG_INFO (
"Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
386 mobility.SetPositionAllocator (positionAlloc);
387 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
406 uint8_t t_clientNss =
static_cast<uint8_t
> (clientNss);
407 uint8_t t_serverNss =
static_cast<uint8_t
> (serverNss);
409 wifiPhyPtrClient->SetMaxSupportedTxSpatialStreams (t_clientNss);
410 wifiPhyPtrClient->SetMaxSupportedRxSpatialStreams (t_clientNss);
415 if (serverSelectedStandard.
m_name ==
"802.11n-5GHz" 416 || serverSelectedStandard.
m_name ==
"802.11n-2.4GHz" 417 || serverSelectedStandard.
m_name ==
"802.11ac")
420 wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.
m_width);
426 else if (serverSelectedStandard.
m_name ==
"802.11ax-5GHz" 427 || serverSelectedStandard.
m_name ==
"802.11ax-2.4GHz")
430 wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.
m_width);
431 wndServer->GetHeConfiguration ()->SetGuardInterval (
NanoSeconds (clientShortGuardInterval));
434 NS_LOG_DEBUG (
"Channel width " << wifiPhyPtrClient->GetChannelWidth () <<
" noiseDbm " <<
noiseDbm);
435 NS_LOG_DEBUG (
"NSS " << wifiPhyPtrClient->GetMaxSupportedTxSpatialStreams ());
440 rssLossModel->
SetRss (rssCurrent);
441 NS_LOG_INFO (
"Setting initial Rss to " << rssCurrent);
446 packetSocketHelper.
Install (serverNode);
447 packetSocketHelper.
Install (clientNode);
471 double rate = clientSelectedStandard.
m_yMax * 1e6 * 1.10;
472 double clientInterval =
static_cast<double> (
packetSize) * 8 / rate;
473 NS_LOG_DEBUG (
"Setting interval to " << clientInterval <<
" sec for rate of " << rate <<
" bits/sec");
481 serverNode->AddApplication (server);
487 gnuplot.AddDataset (rateDataset);
488 gnuplot.AddDataset (actualDataset);
490 std::ostringstream xMinStr, xMaxStr, yMaxStr;
491 std::string xRangeStr (
"set xrange [");
492 xMinStr << clientSelectedStandard.
m_xMin;
493 xRangeStr.append (xMinStr.str ());
494 xRangeStr.append (
":");
495 xMaxStr << clientSelectedStandard.
m_xMax;
496 xRangeStr.append (xMaxStr.str ());
497 xRangeStr.append (
"]");
498 std::string yRangeStr (
"set yrange [0:");
499 yMaxStr << clientSelectedStandard.
m_yMax;
500 yRangeStr.append (yMaxStr.str ());
501 yRangeStr.append (
"]");
503 std::string title (
"Results for ");
504 title.append (standard);
505 title.append (
" with ");
506 title.append (wifiManager);
507 title.append (
"\\n");
508 if (standard ==
"802.11n-5GHz" 509 || standard ==
"802.11n-2.4GHz" 510 || standard ==
"802.11ac" 511 || standard ==
"802.11n-5GHz" 512 || standard ==
"802.11ax-2.4GHz")
514 std::ostringstream serverGiStrStr;
515 std::ostringstream serverWidthStrStr;
516 std::ostringstream serverNssStrStr;
517 title.append (
"server: width=");
518 serverWidthStrStr << serverSelectedStandard.
m_width;
519 title.append (serverWidthStrStr.str ());
520 title.append (
"MHz");
521 title.append (
" GI=");
522 serverGiStrStr << serverShortGuardInterval;
523 title.append (serverGiStrStr.str ());
525 title.append (
" nss=");
526 serverNssStrStr << serverNss;
527 title.append (serverNssStrStr.str ());
528 title.append (
"\\n");
529 std::ostringstream clientGiStrStr;
530 std::ostringstream clientWidthStrStr;
531 std::ostringstream clientNssStrStr;
532 title.append (
"client: width=");
533 clientWidthStrStr << clientSelectedStandard.
m_width;
534 title.append (clientWidthStrStr.str ());
535 title.append (
"MHz");
536 title.append (
" GI=");
537 clientGiStrStr << clientShortGuardInterval;
538 title.append (clientGiStrStr.str ());
540 title.append (
" nss=");
541 clientNssStrStr << clientNss;
542 title.append (clientNssStrStr.str ());
544 gnuplot.SetTerminal (
"postscript eps color enh \"Times-BoldItalic\"");
545 gnuplot.SetLegend (
"SNR (dB)",
"Rate (Mb/s)");
546 gnuplot.SetTitle (title);
547 gnuplot.SetExtra (xRangeStr);
548 gnuplot.AppendExtra (yRangeStr);
549 gnuplot.AppendExtra (
"set key top left");
550 gnuplot.GenerateOutput (outfile);
ERP-OFDM PHY (Clause 19, Section 19.5)
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
#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.
Ptr< HeConfiguration > GetHeConfiguration(void) const
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.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Make it easy to create and manage PHY objects for the YANS model.
void Set(std::string path, const AttributeValue &value)
static const uint32_t packetSize
void SetShortGuardIntervalSupported(bool enable)
Enable or disable SGI support.
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)
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.
static void SetRun(uint64_t run)
Set the run number of simulation.
a polymophic address class
void SetChannel(Ptr< YansWifiChannel > channel)
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
HE PHY for the 5 GHz band (clause 26)
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.
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
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< WifiPhy > GetPhy(void) const
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.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void SetMaxSupportedRxSpatialStreams(uint8_t streams)
create MAC layers for a ns3::WifiNetDevice.
static Time Now(void)
Return the current simulation virtual time.
The IEEE 802.11 SSID Information Element.
StandardInfo(std::string name, WifiPhyStandard standard, uint16_t width, double snrLow, double snrHigh, double xMin, double xMax, double yMax)
Constructor.
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())
static void SetSeed(uint32_t seed)
Set the seed.
Helper class used to assign positions and mobility models to nodes.
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
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual void SetChannelWidth(uint16_t channelWidth)
WifiPhyStandard m_standard
standard
#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.
void SetDefault(std::string name, const AttributeValue &value)
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 Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
void SetNumberOfAntennas(uint8_t antennas)
void RateChange(uint64_t oldVal, uint64_t newVal)
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< HtConfiguration > GetHtConfiguration(void) const
void SetStartTime(Time start)
Specify application start time.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...