A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-eht-network.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "ns3/attribute-container.h"
10#include "ns3/boolean.h"
11#include "ns3/command-line.h"
12#include "ns3/config.h"
13#include "ns3/double.h"
14#include "ns3/eht-phy.h"
15#include "ns3/enum.h"
16#include "ns3/internet-stack-helper.h"
17#include "ns3/ipv4-address-helper.h"
18#include "ns3/log.h"
19#include "ns3/mobility-helper.h"
20#include "ns3/multi-model-spectrum-channel.h"
21#include "ns3/neighbor-cache-helper.h"
22#include "ns3/on-off-helper.h"
23#include "ns3/packet-sink-helper.h"
24#include "ns3/packet-sink.h"
25#include "ns3/spectrum-wifi-helper.h"
26#include "ns3/ssid.h"
27#include "ns3/string.h"
28#include "ns3/udp-client-server-helper.h"
29#include "ns3/udp-server.h"
30#include "ns3/uinteger.h"
31#include "ns3/wifi-acknowledgment.h"
32#include "ns3/wifi-static-setup-helper.h"
33
34#include <algorithm>
35#include <array>
36#include <functional>
37#include <numeric>
38
39// This is a simple example in order to show how to configure an IEEE 802.11be Wi-Fi network.
40//
41// It outputs the UDP or TCP goodput for every EHT MCS value, which depends on the MCS value (0 to
42// 13), the channel width (20, 40, 80, 160 or 320 MHz) and the guard interval (800ns, 1600ns or
43// 3200ns). The PHY bitrate is constant over all the simulation run. The user can also specify the
44// distance between the access point and the station: the larger the distance the smaller the
45// goodput.
46//
47// The simulation assumes a configurable number of stations in an infrastructure network:
48//
49// STA AP
50// * *
51// | |
52// n1 n2
53//
54// Packets in this simulation belong to BestEffort Access Class (AC_BE).
55// By selecting an acknowledgment sequence for DL MU PPDUs, it is possible to aggregate a
56// Round Robin scheduler to the AP, so that DL MU PPDUs are sent by the AP via DL OFDMA.
57
58using namespace ns3;
59
60NS_LOG_COMPONENT_DEFINE("eht-wifi-network");
61
62/**
63 * @param udp true if UDP is used, false if TCP is used
64 * @param serverApp a container of server applications
65 * @param payloadSize the size in bytes of the packets
66 * @return the bytes received by each server application
67 */
68std::vector<uint64_t>
69GetRxBytes(bool udp, const ApplicationContainer& serverApp, uint32_t payloadSize)
70{
71 std::vector<uint64_t> rxBytes(serverApp.GetN(), 0);
72 if (udp)
73 {
74 for (uint32_t i = 0; i < serverApp.GetN(); i++)
75 {
76 rxBytes[i] = payloadSize * DynamicCast<UdpServer>(serverApp.Get(i))->GetReceived();
77 }
78 }
79 else
80 {
81 for (uint32_t i = 0; i < serverApp.GetN(); i++)
82 {
83 rxBytes[i] = DynamicCast<PacketSink>(serverApp.Get(i))->GetTotalRx();
84 }
85 }
86 return rxBytes;
87}
88
89/**
90 * Print average throughput over an intermediate time interval.
91 * @param rxBytes a vector of the amount of bytes received by each server application
92 * @param udp true if UDP is used, false if TCP is used
93 * @param serverApp a container of server applications
94 * @param payloadSize the size in bytes of the packets
95 * @param tputInterval the duration of an intermediate time interval
96 * @param simulationTime the simulation time in seconds
97 */
98void
99PrintIntermediateTput(std::vector<uint64_t>& rxBytes,
100 bool udp,
101 const ApplicationContainer& serverApp,
102 uint32_t payloadSize,
103 Time tputInterval,
104 Time simulationTime)
105{
106 auto newRxBytes = GetRxBytes(udp, serverApp, payloadSize);
107 Time now = Simulator::Now();
108
109 std::cout << "[" << (now - tputInterval).As(Time::S) << " - " << now.As(Time::S)
110 << "] Per-STA Throughput (Mbit/s):";
111
112 for (std::size_t i = 0; i < newRxBytes.size(); i++)
113 {
114 std::cout << "\t\t(" << i << ") "
115 << (newRxBytes[i] - rxBytes[i]) * 8. / tputInterval.GetMicroSeconds(); // Mbit/s
116 }
117 std::cout << std::endl;
118
119 rxBytes.swap(newRxBytes);
120
121 if (now < (simulationTime - NanoSeconds(1)))
122 {
123 Simulator::Schedule(Min(tputInterval, simulationTime - now - NanoSeconds(1)),
125 rxBytes,
126 udp,
127 serverApp,
128 payloadSize,
129 tputInterval,
130 simulationTime);
131 }
132}
133
134int
135main(int argc, char* argv[])
136{
137 bool udp{true};
138 bool downlink{true};
139 bool useRts{false};
140 bool use80Plus80{false};
141 uint16_t mpduBufferSize{512};
142 std::string emlsrMgrTypeId{"ns3::DefaultEmlsrManager"};
143 std::string emlsrLinks;
144 uint16_t paddingDelayUsec{32};
145 uint16_t transitionDelayUsec{128};
146 Time channelSwitchDelay{"100us"};
147 bool switchAuxPhy{true};
148 uint16_t auxPhyChWidth{20};
149 bool auxPhyTxCapable{true};
150 Time simulationTime{"10s"};
151 bool staticSetup{true};
152 auto clientAppStartTime = Seconds(1);
153 meter_u distance{1.0};
154 double frequency{5}; // whether the first link operates in the 2.4, 5 or 6 GHz
155 double frequency2{0}; // whether the second link operates in the 2.4, 5 or 6 GHz (0 means no
156 // second link exists)
157 double frequency3{
158 0}; // whether the third link operates in the 2.4, 5 or 6 GHz (0 means no third link exists)
159 std::size_t nStations{1};
160 std::string dlAckSeqType{"NO-OFDMA"};
161 bool enableUlOfdma{false};
162 bool enableBsrp{false};
163 std::string mcsStr;
164 std::vector<uint64_t> mcsValues;
165 int channelWidth{-1}; // in MHz, -1 indicates an unset value
166 int guardInterval{-1}; // in nanoseconds, -1 indicates an unset value
167 uint32_t payloadSize =
168 700; // must fit in the max TX duration when transmitting at MCS 0 over an RU of 26 tones
169 Time tputInterval{0}; // interval for detailed throughput measurement
170 double minExpectedThroughput{0.0};
171 double maxExpectedThroughput{0.0};
172 Time accessReqInterval{0};
173
174 CommandLine cmd(__FILE__);
175 cmd.AddValue("staticSetup",
176 "Whether devices are configured using the static setup helper",
177 staticSetup);
178 cmd.AddValue(
179 "frequency",
180 "Whether the first link operates in the 2.4, 5 or 6 GHz band (other values gets rejected)",
181 frequency);
182 cmd.AddValue(
183 "frequency2",
184 "Whether the second link operates in the 2.4, 5 or 6 GHz band (0 means the device has one "
185 "link, otherwise the band must be different than first link and third link)",
186 frequency2);
187 cmd.AddValue(
188 "frequency3",
189 "Whether the third link operates in the 2.4, 5 or 6 GHz band (0 means the device has up to "
190 "two links, otherwise the band must be different than first link and second link)",
191 frequency3);
192 cmd.AddValue("emlsrMgrTypeId", "The ns-3 TypeId of the EMLSR manager to use", emlsrMgrTypeId);
193 cmd.AddValue("emlsrLinks",
194 "The comma separated list of IDs of EMLSR links (for MLDs only)",
195 emlsrLinks);
196 cmd.AddValue("emlsrPaddingDelay",
197 "The EMLSR padding delay in microseconds (0, 32, 64, 128 or 256)",
198 paddingDelayUsec);
199 cmd.AddValue("emlsrTransitionDelay",
200 "The EMLSR transition delay in microseconds (0, 16, 32, 64, 128 or 256)",
201 transitionDelayUsec);
202 cmd.AddValue("emlsrAuxSwitch",
203 "Whether Aux PHY should switch channel to operate on the link on which "
204 "the Main PHY was operating before moving to the link of the Aux PHY. ",
205 switchAuxPhy);
206 cmd.AddValue("emlsrAuxChWidth",
207 "The maximum channel width (MHz) supported by Aux PHYs.",
208 auxPhyChWidth);
209 cmd.AddValue("emlsrAuxTxCapable",
210 "Whether Aux PHYs are capable of transmitting.",
211 auxPhyTxCapable);
212 cmd.AddValue("channelSwitchDelay", "The PHY channel switch delay", channelSwitchDelay);
213 cmd.AddValue("distance",
214 "Distance in meters between the station and the access point",
215 distance);
216 cmd.AddValue("simulationTime", "Simulation time", simulationTime);
217 cmd.AddValue("udp", "UDP if set to 1, TCP otherwise", udp);
218 cmd.AddValue("downlink",
219 "Generate downlink flows if set to 1, uplink flows otherwise",
220 downlink);
221 cmd.AddValue("useRts", "Enable/disable RTS/CTS", useRts);
222 cmd.AddValue("use80Plus80", "Enable/disable use of 80+80 MHz", use80Plus80);
223 cmd.AddValue("mpduBufferSize",
224 "Size (in number of MPDUs) of the BlockAck buffer",
225 mpduBufferSize);
226 cmd.AddValue("nStations", "Number of non-AP EHT stations", nStations);
227 cmd.AddValue("dlAckType",
228 "Ack sequence type for DL OFDMA (NO-OFDMA, ACK-SU-FORMAT, MU-BAR, AGGR-MU-BAR)",
229 dlAckSeqType);
230 cmd.AddValue("enableUlOfdma",
231 "Enable UL OFDMA (useful if DL OFDMA is enabled and TCP is used)",
232 enableUlOfdma);
233 cmd.AddValue("enableBsrp",
234 "Enable BSRP (useful if DL and UL OFDMA are enabled and TCP is used)",
235 enableBsrp);
236 cmd.AddValue(
237 "muSchedAccessReqInterval",
238 "Duration of the interval between two requests for channel access made by the MU scheduler",
239 accessReqInterval);
240 cmd.AddValue(
241 "mcs",
242 "list of comma separated MCS values to test; if unset, all MCS values (0-13) are tested",
243 mcsStr);
244 cmd.AddValue("channelWidth",
245 "if set, limit testing to a specific channel width expressed in MHz (20, 40, 80, "
246 "160 or 320 MHz)",
247 channelWidth);
248 cmd.AddValue("guardInterval",
249 "if set, limit testing to a specific guard interval duration expressed in "
250 "nanoseconds (800, 1600 or 3200 ns)",
251 guardInterval);
252 cmd.AddValue("payloadSize", "The application payload size in bytes", payloadSize);
253 cmd.AddValue("tputInterval", "duration of intervals for throughput measurement", tputInterval);
254 cmd.AddValue("minExpectedThroughput",
255 "if set, simulation fails if the lowest throughput is below this value",
256 minExpectedThroughput);
257 cmd.AddValue("maxExpectedThroughput",
258 "if set, simulation fails if the highest throughput is above this value",
259 maxExpectedThroughput);
260 cmd.Parse(argc, argv);
261
262 if (useRts)
263 {
264 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("0"));
265 Config::SetDefault("ns3::WifiDefaultProtectionManager::EnableMuRts", BooleanValue(true));
266 }
267
268 if (dlAckSeqType == "ACK-SU-FORMAT")
269 {
270 Config::SetDefault("ns3::WifiDefaultAckManager::DlMuAckSequenceType",
272 }
273 else if (dlAckSeqType == "MU-BAR")
274 {
275 Config::SetDefault("ns3::WifiDefaultAckManager::DlMuAckSequenceType",
277 }
278 else if (dlAckSeqType == "AGGR-MU-BAR")
279 {
280 Config::SetDefault("ns3::WifiDefaultAckManager::DlMuAckSequenceType",
282 }
283 else if (dlAckSeqType != "NO-OFDMA")
284 {
285 NS_ABORT_MSG("Invalid DL ack sequence type (must be NO-OFDMA, ACK-SU-FORMAT, MU-BAR or "
286 "AGGR-MU-BAR)");
287 }
288
289 double prevThroughput[15] = {0};
290
291 std::cout << "MCS value"
292 << "\t\t"
293 << "Channel width"
294 << "\t\t"
295 << "GI"
296 << "\t\t\t"
297 << "Throughput" << '\n';
298 uint8_t minMcs = 0;
299 uint8_t maxMcs = 13;
300
301 if (mcsStr.empty())
302 {
303 for (uint8_t mcs = minMcs; mcs <= maxMcs; ++mcs)
304 {
305 mcsValues.push_back(mcs);
306 }
307 }
308 else
309 {
310 AttributeContainerValue<UintegerValue, ',', std::vector> attr;
312 checker->SetItemChecker(MakeUintegerChecker<uint8_t>());
313 attr.DeserializeFromString(mcsStr, checker);
314 mcsValues = attr.Get();
315 std::sort(mcsValues.begin(), mcsValues.end());
316 }
317
318 int minChannelWidth = 20;
319 int maxChannelWidth =
320 ((frequency != 2.4) && (frequency2 != 2.4) && (frequency3 != 2.4))
321 ? (((frequency == 6) && (frequency2 == 0) && (frequency3 == 0)) ? 320 : 160)
322 : 40;
323 if ((channelWidth != -1) &&
324 ((channelWidth < minChannelWidth) || (channelWidth > maxChannelWidth)))
325 {
326 NS_FATAL_ERROR("Invalid channel width: " << channelWidth << " MHz");
327 }
328 if (channelWidth >= minChannelWidth && channelWidth <= maxChannelWidth)
329 {
330 minChannelWidth = channelWidth;
331 maxChannelWidth = channelWidth;
332 }
333 int minGi = enableUlOfdma ? 1600 : 800;
334 int maxGi = 3200;
335 if (guardInterval >= minGi && guardInterval <= maxGi)
336 {
337 minGi = guardInterval;
338 maxGi = guardInterval;
339 }
340
341 for (const auto mcs : mcsValues)
342 {
343 uint8_t index = 0;
344 double previous = 0;
345 for (int width = minChannelWidth; width <= maxChannelWidth; width *= 2) // MHz
346 {
347 const auto is80Plus80 = (use80Plus80 && (width == 160));
348 const std::string widthStr = is80Plus80 ? "80+80" : std::to_string(width);
349 const auto segmentWidthStr = is80Plus80 ? "80" : widthStr;
350 for (int gi = maxGi; gi >= minGi; gi /= 2) // Nanoseconds
351 {
352 if (!udp)
353 {
354 Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(payloadSize));
355 }
356
358 wifiStaNodes.Create(nStations);
360 wifiApNode.Create(1);
361
362 NetDeviceContainer apDevice;
366
367 wifi.SetStandard(WIFI_STANDARD_80211be);
368 std::array<std::string, 3> channelStr;
369 std::array<FrequencyRange, 3> freqRanges;
370 uint8_t nLinks = 0;
371 std::string dataModeStr = "EhtMcs" + std::to_string(mcs);
372 std::string ctrlRateStr;
373 uint64_t nonHtRefRateMbps = EhtPhy::GetNonHtReferenceRate(mcs) / 1e6;
374
375 if (frequency2 == frequency || frequency3 == frequency ||
376 (frequency3 != 0 && frequency3 == frequency2))
377 {
378 NS_FATAL_ERROR("Frequency values must be unique!");
379 }
380
381 for (auto freq : {frequency, frequency2, frequency3})
382 {
383 if (nLinks > 0 && freq == 0)
384 {
385 break;
386 }
387 channelStr[nLinks] = "{0, " + segmentWidthStr + ", ";
388 if (freq == 6)
389 {
390 channelStr[nLinks] += "BAND_6GHZ, 0}";
391 freqRanges[nLinks] = WIFI_SPECTRUM_6_GHZ;
392 Config::SetDefault("ns3::LogDistancePropagationLossModel::ReferenceLoss",
393 DoubleValue(48));
394 wifi.SetRemoteStationManager(nLinks,
395 "ns3::ConstantRateWifiManager",
396 "DataMode",
397 StringValue(dataModeStr),
398 "ControlMode",
399 StringValue(dataModeStr));
400 }
401 else if (freq == 5)
402 {
403 channelStr[nLinks] += "BAND_5GHZ, 0}";
404 freqRanges[nLinks] = WIFI_SPECTRUM_5_GHZ;
405 ctrlRateStr = "OfdmRate" + std::to_string(nonHtRefRateMbps) + "Mbps";
406 wifi.SetRemoteStationManager(nLinks,
407 "ns3::ConstantRateWifiManager",
408 "DataMode",
409 StringValue(dataModeStr),
410 "ControlMode",
411 StringValue(ctrlRateStr));
412 }
413 else if (freq == 2.4)
414 {
415 channelStr[nLinks] += "BAND_2_4GHZ, 0}";
416 freqRanges[nLinks] = WIFI_SPECTRUM_2_4_GHZ;
417 Config::SetDefault("ns3::LogDistancePropagationLossModel::ReferenceLoss",
418 DoubleValue(40));
419 ctrlRateStr = "ErpOfdmRate" + std::to_string(nonHtRefRateMbps) + "Mbps";
420 wifi.SetRemoteStationManager(nLinks,
421 "ns3::ConstantRateWifiManager",
422 "DataMode",
423 StringValue(dataModeStr),
424 "ControlMode",
425 StringValue(ctrlRateStr));
426 }
427 else
428 {
429 NS_FATAL_ERROR("Wrong frequency value!");
430 }
431
432 if (is80Plus80)
433 {
434 channelStr[nLinks] += std::string(";") + channelStr[nLinks];
435 }
436
437 nLinks++;
438 }
439
440 if (nLinks > 1 && !emlsrLinks.empty())
441 {
442 wifi.ConfigEhtOptions("EmlsrActivated", BooleanValue(true));
443 }
444
445 Ssid ssid = Ssid("ns3-80211be");
446
448 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
449 phy.Set("ChannelSwitchDelay", TimeValue(channelSwitchDelay));
450
451 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
452 mac.SetEmlsrManager(emlsrMgrTypeId,
453 "EmlsrLinkSet",
454 StringValue(emlsrLinks),
455 "EmlsrPaddingDelay",
456 TimeValue(MicroSeconds(paddingDelayUsec)),
457 "EmlsrTransitionDelay",
458 TimeValue(MicroSeconds(transitionDelayUsec)),
459 "SwitchAuxPhy",
460 BooleanValue(switchAuxPhy),
461 "AuxPhyTxCapable",
462 BooleanValue(auxPhyTxCapable),
463 "AuxPhyChannelWidth",
464 UintegerValue(auxPhyChWidth));
465 for (uint8_t linkId = 0; linkId < nLinks; linkId++)
466 {
467 phy.Set(linkId, "ChannelSettings", StringValue(channelStr[linkId]));
468
469 auto spectrumChannel = CreateObject<MultiModelSpectrumChannel>();
471 spectrumChannel->AddPropagationLossModel(lossModel);
472 phy.AddChannel(spectrumChannel, freqRanges[linkId]);
473 }
474 staDevices = wifi.Install(phy, mac, wifiStaNodes);
475
476 if (dlAckSeqType != "NO-OFDMA")
477 {
478 mac.SetMultiUserScheduler("ns3::RrMultiUserScheduler",
479 "EnableUlOfdma",
480 BooleanValue(enableUlOfdma),
481 "EnableBsrp",
482 BooleanValue(enableBsrp),
483 "AccessReqInterval",
484 TimeValue(accessReqInterval));
485 }
486 mac.SetType("ns3::ApWifiMac",
487 "EnableBeaconJitter",
488 BooleanValue(false),
489 "BeaconGeneration",
490 BooleanValue(!staticSetup),
491 "Ssid",
492 SsidValue(ssid));
493 apDevice = wifi.Install(phy, mac, wifiApNode);
494
495 int64_t streamNumber = 100;
496 streamNumber += WifiHelper::AssignStreams(apDevice, streamNumber);
497 streamNumber += WifiHelper::AssignStreams(staDevices, streamNumber);
498
499 // Set guard interval and MPDU buffer size
501 "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HeConfiguration/GuardInterval",
503 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MpduBufferSize",
504 UintegerValue(mpduBufferSize));
505
506 // mobility.
509
510 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
511 positionAlloc->Add(Vector(distance, 0.0, 0.0));
512 mobility.SetPositionAllocator(positionAlloc);
513
514 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
515
516 mobility.Install(wifiApNode);
517 mobility.Install(wifiStaNodes);
518
519 if (staticSetup)
520 {
521 /* static setup of association and BA agreements */
522 auto apDev = DynamicCast<WifiNetDevice>(apDevice.Get(0));
523 NS_ASSERT(apDev);
525 WifiStaticSetupHelper::SetStaticEmlsr(apDev, staDevices);
526 WifiStaticSetupHelper::SetStaticBlockAck(apDev, staDevices, {0});
527 clientAppStartTime = MilliSeconds(1);
528 }
529
530 /* Internet stack*/
532 stack.Install(wifiApNode);
533 stack.Install(wifiStaNodes);
534 streamNumber += stack.AssignStreams(wifiApNode, streamNumber);
535 streamNumber += stack.AssignStreams(wifiStaNodes, streamNumber);
536
538 address.SetBase("192.168.1.0", "255.255.255.0");
539 Ipv4InterfaceContainer staNodeInterfaces;
540 Ipv4InterfaceContainer apNodeInterface;
541
542 staNodeInterfaces = address.Assign(staDevices);
543 apNodeInterface = address.Assign(apDevice);
544
545 if (staticSetup)
546 {
547 /* static setup of ARP cache */
548 NeighborCacheHelper nbCache;
549 nbCache.PopulateNeighborCache();
550 }
551
552 /* Setting applications */
553 ApplicationContainer serverApp;
554 auto serverNodes = downlink ? std::ref(wifiStaNodes) : std::ref(wifiApNode);
556 NodeContainer clientNodes;
557 for (std::size_t i = 0; i < nStations; i++)
558 {
559 serverInterfaces.Add(downlink ? staNodeInterfaces.Get(i)
560 : apNodeInterface.Get(0));
561 clientNodes.Add(downlink ? wifiApNode.Get(0) : wifiStaNodes.Get(i));
562 }
563
564 const auto maxLoad = nLinks *
566 MHz_u{static_cast<double>(width)},
567 NanoSeconds(gi),
568 1) /
569 nStations;
570 if (udp)
571 {
572 // UDP flow
573 uint16_t port = 9;
575 serverApp = server.Install(serverNodes.get());
576 streamNumber += server.AssignStreams(serverNodes.get(), streamNumber);
577
578 serverApp.Start(Seconds(0));
579 serverApp.Stop(simulationTime + clientAppStartTime);
580 const auto packetInterval = payloadSize * 8.0 / maxLoad;
581
582 for (std::size_t i = 0; i < nStations; i++)
583 {
585 client.SetAttribute("MaxPackets", UintegerValue(4294967295U));
586 client.SetAttribute("Interval", TimeValue(Seconds(packetInterval)));
587 client.SetAttribute("PacketSize", UintegerValue(payloadSize));
588 ApplicationContainer clientApp = client.Install(clientNodes.Get(i));
589 streamNumber += client.AssignStreams(clientNodes.Get(i), streamNumber);
590
591 clientApp.Start(clientAppStartTime);
592 clientApp.Stop(simulationTime + clientAppStartTime);
593 }
594 }
595 else
596 {
597 // TCP flow
598 uint16_t port = 50000;
600 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", localAddress);
601 serverApp = packetSinkHelper.Install(serverNodes.get());
602 streamNumber += packetSinkHelper.AssignStreams(serverNodes.get(), streamNumber);
603
604 serverApp.Start(Seconds(0));
605 serverApp.Stop(simulationTime + clientAppStartTime);
606
607 for (std::size_t i = 0; i < nStations; i++)
608 {
609 OnOffHelper onoff("ns3::TcpSocketFactory", Ipv4Address::GetAny());
610 onoff.SetAttribute("OnTime",
611 StringValue("ns3::ConstantRandomVariable[Constant=1]"));
612 onoff.SetAttribute("OffTime",
613 StringValue("ns3::ConstantRandomVariable[Constant=0]"));
614 onoff.SetAttribute("PacketSize", UintegerValue(payloadSize));
615 onoff.SetAttribute("DataRate", DataRateValue(maxLoad));
617 InetSocketAddress(serverInterfaces.GetAddress(i), port));
618 onoff.SetAttribute("Remote", remoteAddress);
619 ApplicationContainer clientApp = onoff.Install(clientNodes.Get(i));
620 streamNumber += onoff.AssignStreams(clientNodes.Get(i), streamNumber);
621
622 clientApp.Start(clientAppStartTime);
623 clientApp.Stop(simulationTime + clientAppStartTime);
624 }
625 }
626
627 // cumulative number of bytes received by each server application
628 std::vector<uint64_t> cumulRxBytes(nStations, 0);
629
630 if (tputInterval.IsStrictlyPositive())
631 {
632 Simulator::Schedule(clientAppStartTime + tputInterval,
634 cumulRxBytes,
635 udp,
636 serverApp,
637 payloadSize,
638 tputInterval,
639 simulationTime + clientAppStartTime);
640 }
641
642 Simulator::Stop(simulationTime + clientAppStartTime);
644
645 // When multiple stations are used, there are chances that association requests
646 // collide and hence the throughput may be lower than expected. Therefore, we relax
647 // the check that the throughput cannot decrease by introducing a scaling factor (or
648 // tolerance)
649 auto tolerance = 0.10;
650 cumulRxBytes = GetRxBytes(udp, serverApp, payloadSize);
651 auto rxBytes = std::accumulate(cumulRxBytes.cbegin(), cumulRxBytes.cend(), 0.0);
652 auto throughput = (rxBytes * 8) / simulationTime.GetMicroSeconds(); // Mbit/s
653
655
656 std::cout << +mcs << "\t\t\t" << widthStr << " MHz\t\t"
657 << (widthStr.size() > 3 ? "" : "\t") << gi << " ns\t\t\t" << throughput
658 << " Mbit/s" << std::endl;
659
660 // test first element
661 if (mcs == minMcs && width == 20 && gi == 3200)
662 {
663 if (throughput * (1 + tolerance) < minExpectedThroughput)
664 {
665 NS_LOG_ERROR("Obtained throughput " << throughput << " is not expected!");
666 exit(1);
667 }
668 }
669 // test last element
670 if (mcs == maxMcs && width == maxChannelWidth && gi == 800)
671 {
672 if (maxExpectedThroughput > 0 &&
673 throughput > maxExpectedThroughput * (1 + tolerance))
674 {
675 NS_LOG_ERROR("Obtained throughput " << throughput << " is not expected!");
676 exit(1);
677 }
678 }
679 // test previous throughput is smaller (for the same mcs)
680 if (throughput * (1 + tolerance) > previous)
681 {
682 previous = throughput;
683 }
684 else if (throughput > 0)
685 {
686 NS_LOG_ERROR("Obtained throughput " << throughput << " is not expected!");
687 exit(1);
688 }
689 // test previous throughput is smaller (for the same channel width and GI)
690 if (throughput * (1 + tolerance) > prevThroughput[index])
691 {
692 prevThroughput[index] = throughput;
693 }
694 else if (throughput > 0)
695 {
696 NS_LOG_ERROR("Obtained throughput " << throughput << " is not expected!");
697 exit(1);
698 }
699 index++;
700 }
701 }
702 }
703 return 0;
704}
#define Min(a, b)
a polymophic address class
Definition address.h:90
AttributeValue implementation for Address.
Definition address.h:275
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
uint32_t GetN() const
Get the number of Ptr<Application> stored in this container.
A container for one type of attribute.
AttributeValue implementation for Boolean.
Definition boolean.h:26
Parse command-line arguments.
AttributeValue implementation for DataRate.
Definition data-rate.h:285
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
static uint64_t GetDataRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
Return the data rate corresponding to the supplied EHT MCS index, channel width, guard interval,...
Definition eht-phy.cc:388
static uint64_t GetNonHtReferenceRate(uint8_t mcsValue)
Calculate the rate in bps of the non-HT Reference Rate corresponding to the supplied HE MCS index.
Definition eht-phy.cc:401
Hold variables of type enum.
Definition enum.h:52
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
Helper class used to assign positions and mobility models to nodes.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
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.
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Make it easy to create and manage PHY objects for the spectrum model.
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
AttributeValue implementation for Ssid.
Definition ssid.h:85
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:409
@ S
second
Definition nstime.h:107
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:404
AttributeValue implementation for Time.
Definition nstime.h:1456
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Create a server application which waits for input UDP packets and uses the information carried into t...
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.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
static void SetStaticAssociation(Ptr< WifiNetDevice > bssDev, const NetDeviceContainer &clientDevs)
Bypass static capabilities exchange for input devices.
static void SetStaticBlockAck(Ptr< WifiNetDevice > apDev, const NetDeviceContainer &clientDevs, const std::set< tid_t > &tids, std::optional< Mac48Address > gcrGroupAddr=std::nullopt)
Bypass ADDBA Request-Response exchange sequence between AP and STAs for given TIDs.
static void SetStaticEmlsr(Ptr< WifiNetDevice > apDev, const NetDeviceContainer &clientDevs)
Bypass EML Operating Mode Notification exchange sequence between AP MLD and input non-AP devices.
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< AttributeChecker > MakeAttributeContainerChecker()
Make uninitialized AttributeContainerChecker using explicit types.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
void Set(std::string path, const AttributeValue &value)
Definition config.cc:872
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1393
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1405
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1381
@ WIFI_STANDARD_80211be
address
Definition first.py:36
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr FrequencyRange WIFI_SPECTRUM_6_GHZ
Identifier for the frequency range covering the wifi spectrum in the 6 GHz band.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
constexpr FrequencyRange WIFI_SPECTRUM_5_GHZ
Identifier for the frequency range covering the wifi spectrum in the 5 GHz band.
constexpr FrequencyRange WIFI_SPECTRUM_2_4_GHZ
Identifier for the frequency range covering the wifi spectrum in the 2.4 GHz band.
double meter_u
meter weak type
Definition wifi-units.h:32
STL namespace.
staDevices
Definition third.py:87
ssid
Definition third.py:82
mac
Definition third.py:81
wifi
Definition third.py:84
wifiApNode
Definition third.py:75
mobility
Definition third.py:92
wifiStaNodes
Definition third.py:73
phy
Definition third.py:78
std::ofstream throughput
void PrintIntermediateTput(std::vector< uint64_t > &rxBytes, bool udp, const ApplicationContainer &serverApp, uint32_t payloadSize, Time tputInterval, Time simulationTime)
Print average throughput over an intermediate time interval.
std::vector< uint64_t > GetRxBytes(bool udp, const ApplicationContainer &serverApp, uint32_t payloadSize)