A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-manager-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Tom Henderson <tomhend@u.washington.edu>
7 * Matías Richart <mrichart@fing.edu.uy>
8 * Sébastien Deronne <sebastien.deronne@gmail.com>
9 */
10
11// Test the operation of a wifi manager as the SNR is varied, and create
12// a gnuplot output file for plotting.
13//
14// The test consists of a device acting as server and a device as client generating traffic.
15//
16// The output consists of a plot of the rate observed and selected at the client device.
17// A special FixedRss propagation loss model is used to set a specific receive
18// power on the receiver. The noise power is exclusively the thermal noise
19// for the channel bandwidth (no noise figure is configured). Furthermore,
20// the CCA sensitivity attribute in WifiPhy can prevent signals from being
21// received even though the error model would permit it. Therefore, for
22// the purpose of this example, the CCA sensitivity is lowered to a value
23// that disables it, and furthermore, the preamble detection model (which
24// also contains a similar threshold) is disabled.
25//
26// By default, the 802.11a standard using IdealWifiManager is plotted. Several command line
27// arguments can change the following options:
28// --wifiManager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, MinstrelHt, Onoe, Rraa,
29// ThompsonSampling)
30// --standard (802.11a, 802.11b, 802.11g, 802.11p-10MHz, 802.11p-5MHz, 802.11n-5GHz, 802.11n-2.4GHz,
31// 802.11ac, 802.11ax-6GHz, 802.11ax-5GHz, 802.11ax-2.4GHz)
32// --serverShortGuardInterval and --clientShortGuardInterval (for 802.11n/ac)
33// --serverNss and --clientNss (for 802.11n/ac)
34// --serverChannelWidth and --clientChannelWidth (for 802.11n/ac)
35// --broadcast instead of unicast (default is unicast)
36// --rtsThreshold (by default, value of 99999 disables it)
37
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"
43#include "ns3/enum.h"
44#include "ns3/gnuplot.h"
45#include "ns3/he-configuration.h"
46#include "ns3/ht-configuration.h"
47#include "ns3/log.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"
55#include "ns3/ssid.h"
56#include "ns3/tuple.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"
61
62using namespace ns3;
63
64NS_LOG_COMPONENT_DEFINE("WifiManagerExample");
65
66double g_intervalBytes = 0; //!< Bytes received in an interval.
67uint64_t g_intervalRate = 0; //!< Rate in an interval.
68
69/**
70 * Packet received.
71 *
72 * @param pkt The packet.
73 * @param addr The sender address.
74 */
75void
77{
78 g_intervalBytes += pkt->GetSize();
79}
80
81/**
82 * Rate changed.
83 *
84 * @param oldVal Old value.
85 * @param newVal New value.
86 */
87void
88RateChange(uint64_t oldVal, uint64_t newVal)
89{
90 NS_LOG_DEBUG("Change from " << oldVal << " to " << newVal);
91 g_intervalRate = newVal;
92}
93
94/// Step structure
95struct Step
96{
97 dB_u stepSize; ///< step size
98 double stepTime; ///< step size in seconds
99};
100
101/// StandardInfo structure
103{
105 {
106 m_name = "none";
107 }
108
109 /**
110 * Constructor
111 *
112 * @param name reference name
113 * @param standard wifi standard
114 * @param band PHY band
115 * @param width channel width
116 * @param snrLow SNR low
117 * @param snrHigh SNR high
118 * @param xMin x minimum
119 * @param xMax x maximum
120 * @param yMax y maximum
121 */
122 StandardInfo(std::string name,
123 WifiStandard standard,
124 WifiPhyBand band,
125 MHz_u width,
126 dB_u snrLow,
127 dB_u snrHigh,
128 double xMin,
129 double xMax,
130 double yMax)
131 : m_name(name),
132 m_standard(standard),
133 m_band(band),
134 m_width(width),
135 m_snrLow(snrLow),
136 m_snrHigh(snrHigh),
137 m_xMin(xMin),
138 m_xMax(xMax),
139 m_yMax(yMax)
140 {
141 }
142
143 std::string m_name; ///< name
145 WifiPhyBand m_band; ///< PHY band
146 MHz_u m_width; ///< channel width
147 dB_u m_snrLow; ///< lowest SNR
148 dB_u m_snrHigh; ///< highest SNR
149 double m_xMin; ///< X minimum
150 double m_xMax; ///< X maximum
151 double m_yMax; ///< Y maximum
152};
153
154/**
155 * Change the signal model and report the rate.
156 *
157 * @param rssModel The new RSS model.
158 * @param step The step to use.
159 * @param rss The RSS.
160 * @param noise The noise.
161 * @param rateDataset The rate dataset.
162 * @param actualDataset The actual dataset.
163 */
164void
166 Step step,
167 dBm_u rss,
168 dBm_u noise,
169 Gnuplot2dDataset& rateDataset,
170 Gnuplot2dDataset& actualDataset)
171{
172 NS_LOG_FUNCTION(rssModel << step.stepSize << step.stepTime << rss);
173 dB_u snr{rss - noise};
174 rateDataset.Add(snr, g_intervalRate / 1e6);
175 // Calculate received rate since last interval
176 double currentRate = ((g_intervalBytes * 8) / step.stepTime) / 1e6; // Mb/s
177 actualDataset.Add(snr, currentRate);
178 const auto newRss = rss - step.stepSize;
179 rssModel->SetRss(newRss);
180 NS_LOG_INFO("At time " << Simulator::Now().As(Time::S) << "; selected rate "
181 << (g_intervalRate / 1e6) << "; observed rate " << currentRate
182 << "; setting new power to " << newRss);
183 g_intervalBytes = 0;
186 rssModel,
187 step,
188 newRss,
189 noise,
190 rateDataset,
191 actualDataset);
192}
193
194int
195main(int argc, char* argv[])
196{
197 std::vector<StandardInfo> serverStandards;
198 std::vector<StandardInfo> clientStandards;
199 uint32_t steps;
200 uint32_t rtsThreshold = 999999; // disabled even for large A-MPDU
201 uint32_t maxAmpduSize = 65535;
202 dB_u stepSize{1};
203 double stepTime = 1; // seconds
204 uint32_t packetSize = 1024; // bytes
205 bool broadcast = false;
206 int ap1_x = 0;
207 int ap1_y = 0;
208 int sta1_x = 5;
209 int sta1_y = 0;
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}; // use default for standard and band
215 MHz_u clientChannelWidth{0}; // use default for standard and band
216 std::string wifiManager("Ideal");
217 std::string standard("802.11a");
218 StandardInfo serverSelectedStandard;
219 StandardInfo clientSelectedStandard;
220 bool infrastructure = false;
221 uint32_t maxRetryCount = 7;
222
225
226 CommandLine cmd(__FILE__);
227 cmd.AddValue("maxRetryCount",
228 "The maximum number of retransmission attempts for a Data packet",
229 maxRetryCount);
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)",
237 serverChannelWidth);
238 cmd.AddValue("clientChannelWidth",
239 "Set channel width of the client (valid only for 802.11n or ac)",
240 clientChannelWidth);
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);
249 cmd.AddValue(
250 "standard",
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)",
254 standard);
255 cmd.AddValue("wifiManager",
256 "Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, "
257 "MinstrelHt, Onoe, Rraa, ThompsonSampling)",
258 wifiManager);
259 cmd.AddValue("infrastructure", "Use infrastructure instead of adhoc", infrastructure);
260 cmd.Parse(argc, argv);
261
262 // Print out some explanation of what this program does
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
269 << std::endl;
270
271 if (!infrastructure)
272 {
273 NS_ABORT_MSG_IF(serverNss != clientNss,
274 "In ad hoc mode, we assume sender and receiver are similarly configured");
275 }
276
277 if (standard == "802.11b")
278 {
279 if (serverChannelWidth == MHz_u{0})
280 {
282 }
283 NS_ABORT_MSG_IF(serverChannelWidth != MHz_u{22},
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})
287 {
289 }
290 NS_ABORT_MSG_IF(clientChannelWidth != MHz_u{22},
291 "Invalid channel width for standard " << standard);
292 NS_ABORT_MSG_IF(clientNss != 1, "Invalid nss for standard " << standard);
293 }
294 else if (standard == "802.11a" || standard == "802.11g")
295 {
296 if (serverChannelWidth == MHz_u{0})
297 {
299 }
300 NS_ABORT_MSG_IF(serverChannelWidth != MHz_u{20},
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})
304 {
306 }
307 NS_ABORT_MSG_IF(clientChannelWidth != MHz_u{20},
308 "Invalid channel width for standard " << standard);
309 NS_ABORT_MSG_IF(clientNss != 1, "Invalid nss for standard " << standard);
310 }
311 else if (standard == "802.11n-5GHz" || standard == "802.11n-2.4GHz")
312 {
313 WifiPhyBand band =
314 (standard == "802.11n-2.4GHz" ? WIFI_PHY_BAND_2_4GHZ : WIFI_PHY_BAND_5GHZ);
315 if (serverChannelWidth == MHz_u{0})
316 {
317 serverChannelWidth = GetDefaultChannelWidth(WIFI_STANDARD_80211n, band);
318 }
319 NS_ABORT_MSG_IF(serverChannelWidth != MHz_u{20} && serverChannelWidth != MHz_u{40},
320 "Invalid channel width for standard " << standard);
321 NS_ABORT_MSG_IF(serverNss == 0 || serverNss > 4,
322 "Invalid nss " << serverNss << " for standard " << standard);
323 if (clientChannelWidth == MHz_u{0})
324 {
325 clientChannelWidth = GetDefaultChannelWidth(WIFI_STANDARD_80211n, band);
326 }
327 NS_ABORT_MSG_IF(clientChannelWidth != MHz_u{20} && clientChannelWidth != MHz_u{40},
328 "Invalid channel width for standard " << standard);
329 NS_ABORT_MSG_IF(clientNss == 0 || clientNss > 4,
330 "Invalid nss " << clientNss << " for standard " << standard);
331 }
332 else if (standard == "802.11ac")
333 {
334 if (serverChannelWidth == MHz_u{0})
335 {
337 }
338 NS_ABORT_MSG_IF(serverChannelWidth != MHz_u{20} && serverChannelWidth != MHz_u{40} &&
339 serverChannelWidth != MHz_u{80} && serverChannelWidth != MHz_u{160} &&
340 serverChannelWidth != MHz_u{320},
341 "Invalid channel width for standard " << standard);
342 NS_ABORT_MSG_IF(serverNss == 0 || serverNss > 4,
343 "Invalid nss " << serverNss << " for standard " << standard);
344 if (clientChannelWidth == MHz_u{0})
345 {
347 }
348 NS_ABORT_MSG_IF(clientChannelWidth != MHz_u{20} && clientChannelWidth != MHz_u{40} &&
349 clientChannelWidth != MHz_u{80} && clientChannelWidth != MHz_u{160} &&
350 clientChannelWidth != MHz_u{320},
351 "Invalid channel width for standard " << standard);
352 NS_ABORT_MSG_IF(clientNss == 0 || clientNss > 4,
353 "Invalid nss " << clientNss << " for standard " << standard);
354 }
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")
358 {
359 WifiPhyBand band = (standard == "802.11ax-2.4GHz" ? WIFI_PHY_BAND_2_4GHZ
360 : standard == "802.11ax-6GHz" ? WIFI_PHY_BAND_6GHZ
362 if (serverChannelWidth == MHz_u{0})
363 {
364 serverChannelWidth = GetDefaultChannelWidth(WIFI_STANDARD_80211ax, band);
365 }
366 NS_ABORT_MSG_IF(serverChannelWidth != MHz_u{20} && serverChannelWidth != MHz_u{40} &&
367 serverChannelWidth != MHz_u{80} && serverChannelWidth != MHz_u{160} &&
368 serverChannelWidth != MHz_u{320},
369 "Invalid channel width for standard " << standard);
370 NS_ABORT_MSG_IF(serverNss == 0 || serverNss > 4,
371 "Invalid nss " << serverNss << " for standard " << standard);
372 if (clientChannelWidth == MHz_u{0})
373 {
374 clientChannelWidth = GetDefaultChannelWidth(WIFI_STANDARD_80211ax, band);
375 }
376 NS_ABORT_MSG_IF(clientChannelWidth != MHz_u{20} && clientChannelWidth != MHz_u{40} &&
377 clientChannelWidth != MHz_u{80} && clientChannelWidth != MHz_u{160} &&
378 clientChannelWidth != MHz_u{320},
379 "Invalid channel width for standard " << standard);
380 NS_ABORT_MSG_IF(clientNss == 0 || clientNss > 4,
381 "Invalid nss " << clientNss << " for standard " << standard);
382 }
383
384 // As channel width increases, scale up plot's yRange value
385 uint32_t channelRateFactor = std::max(clientChannelWidth, serverChannelWidth) / MHz_u{20};
386 channelRateFactor = channelRateFactor * std::max(clientNss, serverNss);
387
388 // The first number is channel width, second is minimum SNR, third is maximum
389 // SNR, fourth and fifth provide xrange axis limits, and sixth the yaxis
390 // maximum
391 serverStandards = {
392 StandardInfo("802.11a",
395 MHz_u{20},
396 dB_u{3},
397 dB_u{27},
398 0,
399 30,
400 60),
401 StandardInfo("802.11b",
404 MHz_u{22},
405 dB_u{-5},
406 dB_u{11},
407 -6,
408 15,
409 15),
410 StandardInfo("802.11g",
413 MHz_u{20},
414 dB_u{-5},
415 dB_u{27},
416 -6,
417 30,
418 60),
419 StandardInfo("802.11n-5GHz",
422 serverChannelWidth,
423 dB_u{3},
424 dB_u{30},
425 0,
426 35,
427 80 * channelRateFactor),
428 StandardInfo("802.11n-2.4GHz",
431 serverChannelWidth,
432 dB_u{3},
433 dB_u{30},
434 0,
435 35,
436 80 * channelRateFactor),
437 StandardInfo("802.11ac",
440 serverChannelWidth,
441 dB_u{5},
442 dB_u{50},
443 0,
444 55,
445 120 * channelRateFactor),
446 StandardInfo("802.11p-10MHz",
449 MHz_u{10},
450 dB_u{3},
451 dB_u{27},
452 0,
453 30,
454 60),
455 StandardInfo("802.11p-5MHz",
458 MHz_u{5},
459 dB_u{3},
460 dB_u{27},
461 0,
462 30,
463 60),
464 StandardInfo("802.11ax-6GHz",
467 serverChannelWidth,
468 dB_u{5},
469 dB_u{55},
470 0,
471 60,
472 120 * channelRateFactor),
473 StandardInfo("802.11ax-5GHz",
476 serverChannelWidth,
477 dB_u{5},
478 dB_u{55},
479 0,
480 60,
481 120 * channelRateFactor),
482 StandardInfo("802.11ax-2.4GHz",
485 serverChannelWidth,
486 dB_u{5},
487 dB_u{55},
488 0,
489 60,
490 120 * channelRateFactor),
491 StandardInfo("802.11be-6GHz",
494 serverChannelWidth,
495 5,
496 55,
497 0,
498 60,
499 120 * channelRateFactor),
500 StandardInfo("802.11be-5GHz",
503 serverChannelWidth,
504 5,
505 55,
506 0,
507 60,
508 120 * channelRateFactor),
509 StandardInfo("802.11be-2.4GHz",
512 serverChannelWidth,
513 5,
514 55,
515 0,
516 60,
517 120 * channelRateFactor),
518 };
519
520 clientStandards = {
521 StandardInfo("802.11a",
524 MHz_u{20},
525 dB_u{3},
526 dB_u{27},
527 0,
528 30,
529 60),
530 StandardInfo("802.11b",
533 MHz_u{22},
534 dB_u{-5},
535 dB_u{11},
536 -6,
537 15,
538 15),
539 StandardInfo("802.11g",
542 MHz_u{20},
543 dB_u{-5},
544 dB_u{27},
545 -6,
546 30,
547 60),
548 StandardInfo("802.11n-5GHz",
551 clientChannelWidth,
552 dB_u{3},
553 dB_u{30},
554 0,
555 35,
556 80 * channelRateFactor),
557 StandardInfo("802.11n-2.4GHz",
560 clientChannelWidth,
561 dB_u{3},
562 dB_u{30},
563 0,
564 35,
565 80 * channelRateFactor),
566 StandardInfo("802.11ac",
569 clientChannelWidth,
570 dB_u{5},
571 dB_u{50},
572 0,
573 55,
574 120 * channelRateFactor),
575 StandardInfo("802.11p-10MHz",
578 MHz_u{10},
579 dB_u{3},
580 dB_u{27},
581 0,
582 30,
583 60),
584 StandardInfo("802.11p-5MHz",
587 MHz_u{5},
588 dB_u{3},
589 dB_u{27},
590 0,
591 30,
592 60),
593 StandardInfo("802.11ax-6GHz",
596 clientChannelWidth,
597 dB_u{5},
598 dB_u{55},
599 0,
600 60,
601 160 * channelRateFactor),
602 StandardInfo("802.11ax-5GHz",
605 clientChannelWidth,
606 dB_u{5},
607 dB_u{55},
608 0,
609 60,
610 160 * channelRateFactor),
611 StandardInfo("802.11ax-2.4GHz",
614 clientChannelWidth,
615 dB_u{5},
616 dB_u{55},
617 0,
618 60,
619 160 * channelRateFactor),
620 StandardInfo("802.11be-6GHz",
623 clientChannelWidth,
624 5,
625 55,
626 0,
627 60,
628 160 * channelRateFactor),
629 StandardInfo("802.11be-5GHz",
632 clientChannelWidth,
633 5,
634 55,
635 0,
636 60,
637 160 * channelRateFactor),
638 StandardInfo("802.11be-2.4GHz",
641 clientChannelWidth,
642 5,
643 55,
644 0,
645 60,
646 160 * channelRateFactor),
647 };
648
649 for (std::vector<StandardInfo>::size_type i = 0; i != serverStandards.size(); i++)
650 {
651 if (standard == serverStandards[i].m_name)
652 {
653 serverSelectedStandard = serverStandards[i];
654 }
655 }
656 for (std::vector<StandardInfo>::size_type i = 0; i != clientStandards.size(); i++)
657 {
658 if (standard == clientStandards[i].m_name)
659 {
660 clientSelectedStandard = clientStandards[i];
661 }
662 }
663
664 NS_ABORT_MSG_IF(serverSelectedStandard.m_name == "none",
665 "Standard " << standard << " not found");
666 NS_ABORT_MSG_IF(clientSelectedStandard.m_name == "none",
667 "Standard " << standard << " not found");
668 std::cout << "Testing " << serverSelectedStandard.m_name << " with " << wifiManager << " ..."
669 << std::endl;
670 NS_ABORT_MSG_IF(clientSelectedStandard.m_snrLow >= clientSelectedStandard.m_snrHigh,
671 "SNR values in wrong order");
672 steps = static_cast<uint32_t>(std::abs(static_cast<double>(clientSelectedStandard.m_snrHigh -
673 clientSelectedStandard.m_snrLow) /
674 stepSize) +
675 1);
676 NS_LOG_DEBUG("Using " << steps << " steps for SNR range " << clientSelectedStandard.m_snrLow
677 << ":" << clientSelectedStandard.m_snrHigh);
678 Ptr<Node> clientNode = CreateObject<Node>();
679 Ptr<Node> serverNode = CreateObject<Node>();
680
681 std::string plotName = "wifi-manager-example-";
682 std::string dataName = "wifi-manager-example-";
683 plotName += wifiManager;
684 dataName += wifiManager;
685 plotName += "-";
686 dataName += "-";
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")
691 {
692 plotName += "-server_";
693 dataName += "-server_";
694 std::ostringstream oss;
695 oss << serverChannelWidth << "MHz_" << serverShortGuardInterval << "ns_" << serverNss
696 << "SS";
697 plotName += oss.str();
698 dataName += oss.str();
699 plotName += "-client_";
700 dataName += "-client_";
701 oss.str("");
702 oss << clientChannelWidth << "MHz_" << clientShortGuardInterval << "ns_" << clientNss
703 << "SS";
704 plotName += oss.str();
705 dataName += oss.str();
706 }
707 plotName += ".eps";
708 dataName += ".plt";
709 std::ofstream outfile(dataName);
710 Gnuplot gnuplot = Gnuplot(plotName);
711
712 Config::SetDefault("ns3::WifiMac::FrameRetryLimit", UintegerValue(maxRetryCount));
713 Config::SetDefault("ns3::MinstrelWifiManager::PrintStats", BooleanValue(true));
714 Config::SetDefault("ns3::MinstrelWifiManager::PrintSamples", BooleanValue(true));
715 Config::SetDefault("ns3::MinstrelHtWifiManager::PrintStats", BooleanValue(true));
716 // Disable the default noise figure of 7 dBm in WifiPhy; the calculations
717 // of SNR below assume that the only noise is thermal noise
718 Config::SetDefault("ns3::WifiPhy::RxNoiseFigure", DoubleValue(0));
719
720 // By default, the CCA sensitivity is -82 dBm, meaning if the RSS is
721 // below this value, the receiver will reject the Wi-Fi frame.
722 // However, we want to probe the error model down to low SNR values,
723 // and we have disabled the noise figure, so the noise level in 20 MHz
724 // will be about -101 dBm. Therefore, lower the CCA sensitivity to a
725 // value that disables it (e.g. -110 dBm)
726 Config::SetDefault("ns3::WifiPhy::CcaSensitivity", DoubleValue(-110));
727
729 wifi.SetStandard(serverSelectedStandard.m_standard);
730 YansWifiPhyHelper wifiPhy;
731 // Disable the preamble detection model for the same reason that we
732 // disabled CCA sensitivity above-- we want to enable reception at low SNR
734
738 wifiChannel->SetPropagationDelayModel(delayModel);
740 wifiChannel->SetPropagationLossModel(rssLossModel);
741 wifiPhy.SetChannel(wifiChannel);
742
743 wifi.SetRemoteStationManager("ns3::" + wifiManager + "WifiManager",
744 "RtsCtsThreshold",
745 UintegerValue(rtsThreshold));
746
747 NetDeviceContainer serverDevice;
748 NetDeviceContainer clientDevice;
749
751
752 WifiMacHelper wifiMac;
753 if (infrastructure)
754 {
755 Ssid ssid = Ssid("ns-3-ssid");
756 wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
757 channelValue.Set(WifiPhy::ChannelSegments{
758 {0, serverSelectedStandard.m_width, serverSelectedStandard.m_band, 0}});
759 wifiPhy.Set("ChannelSettings", channelValue);
760 serverDevice = wifi.Install(wifiPhy, wifiMac, serverNode);
761
762 wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
763 channelValue.Set(WifiPhy::ChannelSegments{
764 {0, clientSelectedStandard.m_width, clientSelectedStandard.m_band, 0}});
765 wifiPhy.Set("ChannelSettings", channelValue);
766 clientDevice = wifi.Install(wifiPhy, wifiMac, clientNode);
767 }
768 else
769 {
770 wifiMac.SetType("ns3::AdhocWifiMac");
771 channelValue.Set(WifiPhy::ChannelSegments{
772 {0, serverSelectedStandard.m_width, serverSelectedStandard.m_band, 0}});
773 wifiPhy.Set("ChannelSettings", channelValue);
774 serverDevice = wifi.Install(wifiPhy, wifiMac, serverNode);
775
776 channelValue.Set(WifiPhy::ChannelSegments{
777 {0, clientSelectedStandard.m_width, clientSelectedStandard.m_band, 0}});
778 wifiPhy.Set("ChannelSettings", channelValue);
779 clientDevice = wifi.Install(wifiPhy, wifiMac, clientNode);
780 }
781
782 WifiHelper::AssignStreams(serverDevice, 100);
783 WifiHelper::AssignStreams(clientDevice, 200);
784
785 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
786 UintegerValue(maxAmpduSize));
787
789 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$ns3::" + wifiManager +
790 "WifiManager/Rate",
792
793 // Configure the mobility.
796 // Initial position of AP and STA
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");
803 mobility.Install(clientNode);
804 mobility.Install(serverNode);
805
806 Gnuplot2dDataset rateDataset(clientSelectedStandard.m_name + std::string("-rate selected"));
807 Gnuplot2dDataset actualDataset(clientSelectedStandard.m_name + std::string("-observed"));
808 Step step;
809 step.stepSize = stepSize;
810 step.stepTime = stepTime;
811
812 // Perform post-install configuration from defaults for channel width,
813 // guard interval, and nss, if necessary
814 // Obtain pointer to the WifiPhy
815 Ptr<NetDevice> ndClient = clientDevice.Get(0);
816 Ptr<NetDevice> ndServer = serverDevice.Get(0);
817 Ptr<WifiNetDevice> wndClient = ndClient->GetObject<WifiNetDevice>();
818 Ptr<WifiNetDevice> wndServer = ndServer->GetObject<WifiNetDevice>();
819 Ptr<WifiPhy> wifiPhyPtrClient = wndClient->GetPhy();
820 Ptr<WifiPhy> wifiPhyPtrServer = wndServer->GetPhy();
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);
829 // Only set the guard interval for HT and VHT modes
830 if (serverSelectedStandard.m_name == "802.11n-5GHz" ||
831 serverSelectedStandard.m_name == "802.11n-2.4GHz" ||
832 serverSelectedStandard.m_name == "802.11ac")
833 {
834 Ptr<HtConfiguration> clientHtConfiguration = wndClient->GetHtConfiguration();
835 clientHtConfiguration->m_sgiSupported = (clientShortGuardInterval == 400);
836 Ptr<HtConfiguration> serverHtConfiguration = wndServer->GetHtConfiguration();
837 serverHtConfiguration->m_sgiSupported = (serverShortGuardInterval == 400);
838 }
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")
845 {
846 wndServer->GetHeConfiguration()->SetGuardInterval(NanoSeconds(serverShortGuardInterval));
847 wndClient->GetHeConfiguration()->SetGuardInterval(NanoSeconds(clientShortGuardInterval));
848 }
849
850 // Configure signal and noise, and schedule first iteration
851 const auto BOLTZMANN = 1.3803e-23;
852 const dBm_per_Hz_u noiseDensity = WToDbm(BOLTZMANN * 290); // 290K @ 20 MHz
853 const dBm_u noise = noiseDensity + (10 * log10(clientSelectedStandard.m_width * 1000000));
854
855 NS_LOG_DEBUG("Channel width " << wifiPhyPtrClient->GetChannelWidth() << " noise " << noise);
856 NS_LOG_DEBUG("NSS " << wifiPhyPtrClient->GetMaxSupportedTxSpatialStreams());
857
858 const dBm_u rssCurrent = (clientSelectedStandard.m_snrHigh + noise);
859 rssLossModel->SetRss(rssCurrent);
860 NS_LOG_INFO("Setting initial Rss to " << rssCurrent);
861 // Move the STA by stepsSize meters every stepTime seconds
862 Simulator::Schedule(Seconds(0.5 + stepTime),
864 rssLossModel,
865 step,
866 rssCurrent,
867 noise,
868 rateDataset,
869 actualDataset);
870
871 PacketSocketHelper packetSocketHelper;
872 packetSocketHelper.Install(serverNode);
873 packetSocketHelper.Install(clientNode);
874
875 PacketSocketAddress socketAddr;
876 socketAddr.SetSingleDevice(serverDevice.Get(0)->GetIfIndex());
877 if (broadcast)
878 {
879 socketAddr.SetPhysicalAddress(serverDevice.Get(0)->GetBroadcast());
880 }
881 else
882 {
883 socketAddr.SetPhysicalAddress(serverDevice.Get(0)->GetAddress());
884 }
885 // Arbitrary protocol type.
886 // Note: PacketSocket doesn't have any L4 multiplexing or demultiplexing
887 // The only mux/demux is based on the protocol field
888 socketAddr.SetProtocol(1);
889
891 client->SetRemote(socketAddr);
892 client->SetStartTime(Seconds(0.5)); // allow simulation warmup
893 client->SetAttribute("MaxPackets", UintegerValue(0)); // unlimited
894 client->SetAttribute("PacketSize", UintegerValue(packetSize));
895
896 // Set a maximum rate 10% above the yMax specified for the selected standard
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
900 << " bits/sec");
901
902 client->SetAttribute("Interval", TimeValue(Seconds(clientInterval)));
903 clientNode->AddApplication(client);
904
906 server->SetLocal(socketAddr);
907 server->TraceConnectWithoutContext("Rx", MakeCallback(&PacketRx));
908 serverNode->AddApplication(server);
909
910 Simulator::Stop(Seconds((steps + 1) * stepTime));
912
913 if (serverSelectedStandard.m_standard >= WIFI_STANDARD_80211n)
914 {
915 NS_ABORT_MSG_UNLESS(wndClient->GetMac()->GetBaAgreementEstablishedAsOriginator(
916 wndServer->GetMac()->GetAddress(),
917 0),
918 "Expected BA agreement established for standard "
919 << serverSelectedStandard.m_standard);
920 }
921
923
924 gnuplot.AddDataset(rateDataset);
925 gnuplot.AddDataset(actualDataset);
926
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("]");
941
942 std::string title("Results for ");
943 title.append(standard);
944 title.append(" with ");
945 title.append(wifiManager);
946 title.append("\\n");
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")
951 {
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());
958 title.append("MHz");
959 title.append(" GI=");
960 serverGiStrStr << serverShortGuardInterval;
961 title.append(serverGiStrStr.str());
962 title.append("ns");
963 title.append(" nss=");
964 serverNssStrStr << serverNss;
965 title.append(serverNssStrStr.str());
966 title.append("\\n");
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());
973 title.append("MHz");
974 title.append(" GI=");
975 clientGiStrStr << clientShortGuardInterval;
976 title.append(clientGiStrStr.str());
977 title.append("ns");
978 title.append(" nss=");
979 clientNssStrStr << clientNss;
980 title.append(clientNssStrStr.str());
981 }
982 gnuplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
983 gnuplot.SetLegend("SNR (dB)", "Rate (Mb/s)");
984 gnuplot.SetTitle(title);
985 gnuplot.SetExtra(xRangeStr);
986 gnuplot.AppendExtra(yRangeStr);
987 gnuplot.AppendExtra("set key top left");
988 gnuplot.GenerateOutput(outfile);
989 outfile.close();
990
991 return 0;
992}
a polymophic address class
Definition address.h:114
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'.
Definition double.h:31
Class to represent a 2D points plot.
Definition gnuplot.h:105
void Add(double x, double y)
Definition gnuplot.cc:366
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition gnuplot.h:359
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:785
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:765
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:753
void AppendExtra(const std::string &extra)
Definition gnuplot.cc:778
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:791
void SetExtra(const std::string &extra)
Definition gnuplot.cc:772
void SetTitle(const std::string &title)
Definition gnuplot.cc:759
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.
Definition ptr.h:70
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.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
The IEEE 802.11 SSID Information Element.
Definition ssid.h:27
AttributeValue implementation for Ssid.
Definition ssid.h:98
@ S
second
Definition nstime.h:106
Hold an unsigned integer type.
Definition uinteger.h:34
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
Definition wifi-phy.h:957
AttributeContainerValue< ChannelTupleValue, ';'> ChannelSettingsValue
AttributeValue type of a ChannelSegments object.
Definition wifi-phy.h:964
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...
Definition callback.h:690
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition config.cc:942
void Set(std::string path, const AttributeValue &value)
Definition config.cc:872
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:136
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:99
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#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.
Definition log.h:274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1364
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyBand
Identifies the PHY band.
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211be
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ 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.
Definition wifi-utils.cc:38
double MHz_u
MHz weak type.
Definition wifi-units.h:31
double dBm_per_Hz_u
dBm/Hz weak type
Definition wifi-units.h:37
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
Definition wifi-units.h:27
double dB_u
dB weak type
Definition wifi-units.h:28
ssid
Definition third.py:82
wifi
Definition third.py:84
mobility
Definition third.py:92
StandardInfo structure.
std::string m_name
name
StandardInfo(std::string name, WifiStandard standard, WifiPhyBand band, MHz_u width, dB_u snrLow, dB_u snrHigh, double xMin, double xMax, double yMax)
Constructor.
double m_yMax
Y maximum.
WifiStandard m_standard
standard
WifiPhyBand m_band
PHY band.
double m_xMax
X maximum.
dB_u m_snrHigh
highest SNR
double m_xMin
X minimum.
MHz_u m_width
channel width
dB_u m_snrLow
lowest SNR
Step structure.
double stepTime
step size in seconds
dB_u stepSize
step size
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.