A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
minstrel-ht-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Duy Nguyen
3 * Copyright (c) 2015 Ghada Badawy
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Duy Nguyen <duy@soe.ucsc.edu>
8 * Ghada Badawy <gbadawy@gmail.com>
9 * Matias Richart <mrichart@fing.edu.uy>
10 *
11 * Some Comments:
12 *
13 * 1) By default, Minstrel applies the multi-rate retry (the core of Minstrel
14 * algorithm). Otherwise, please use ConstantRateWifiManager instead.
15 *
16 * 2) Sampling is done differently from legacy Minstrel. Minstrel-HT tries
17 * to sample all rates in all groups at least once and to avoid many
18 * consecutive samplings.
19 *
20 * 3) Sample rate is tried only once, at first place of the MRR chain.
21 *
22 * reference: http://lwn.net/Articles/376765/
23 */
24
26
27#include "ns3/ht-configuration.h"
28#include "ns3/log.h"
29#include "ns3/packet.h"
30#include "ns3/random-variable-stream.h"
31#include "ns3/simulator.h"
32#include "ns3/wifi-mac.h"
33#include "ns3/wifi-net-device.h"
34#include "ns3/wifi-phy.h"
35
36#include <iomanip>
37
38#define Min(a, b) ((a < b) ? a : b)
39#define Max(a, b) ((a > b) ? a : b)
40
41NS_LOG_COMPONENT_DEFINE("MinstrelHtWifiManager");
42
43namespace ns3
44{
45
46/// MinstrelHtWifiRemoteStation structure
48{
49 uint8_t m_sampleGroup; //!< The group that the sample rate belongs to.
50
51 uint32_t m_sampleWait; //!< How many transmission attempts to wait until a new sample.
52 uint32_t m_sampleTries; //!< Number of sample tries after waiting sampleWait.
53 uint32_t m_sampleCount; //!< Max number of samples per update interval.
54 uint32_t m_numSamplesSlow; //!< Number of times a slow rate was sampled.
55
56 uint32_t m_avgAmpduLen; //!< Average number of MPDUs in an A-MPDU.
57 uint32_t m_ampduLen; //!< Number of MPDUs in an A-MPDU.
58 uint32_t m_ampduPacketCount; //!< Number of A-MPDUs transmitted.
59
60 McsGroupData m_groupsTable; //!< Table of groups with stats.
61 bool m_isHt; //!< If the station is HT capable.
62
63 std::ofstream m_statsFile; //!< File where statistics table is written.
64};
65
67
70{
71 static TypeId tid =
72 TypeId("ns3::MinstrelHtWifiManager")
74 .AddConstructor<MinstrelHtWifiManager>()
75 .SetGroupName("Wifi")
76 .AddAttribute("UpdateStatistics",
77 "The interval between updating statistics table",
81 .AddAttribute("LegacyUpdateStatistics",
82 "The interval between updating statistics table (for legacy Minstrel)",
86 .AddAttribute("LookAroundRate",
87 "The percentage to try other rates (for legacy Minstrel)",
88 UintegerValue(10),
91 .AddAttribute("EWMA",
92 "EWMA level",
93 UintegerValue(75),
96 .AddAttribute("SampleColumn",
97 "The number of columns used for sampling",
98 UintegerValue(10),
101 .AddAttribute("PacketLength",
102 "The packet length used for calculating mode TxTime (bytes)",
103 UintegerValue(1200),
106 .AddAttribute("UseLatestAmendmentOnly",
107 "Use only the latest amendment when it is supported by both peers",
108 BooleanValue(true),
111 .AddAttribute("PrintStats",
112 "Control the printing of the statistics table",
113 BooleanValue(false),
116 .AddTraceSource("Rate",
117 "Traced value for rate changes (b/s)",
119 "ns3::TracedValueCallback::Uint64");
120 return tid;
121}
122
124 : m_numGroups(0),
125 m_numRates(0),
126 m_currentRate(0)
127{
128 NS_LOG_FUNCTION(this);
130 /**
131 * Create the legacy Minstrel manager in case HT is not supported by the device
132 * or non-HT stations want to associate.
133 */
135}
136
138{
139 NS_LOG_FUNCTION(this);
140 for (uint8_t i = 0; i < m_numGroups; i++)
141 {
142 m_minstrelGroups[i].ratesFirstMpduTxTimeTable.clear();
143 m_minstrelGroups[i].ratesTxTimeTable.clear();
144 }
145}
146
147int64_t
149{
150 NS_LOG_FUNCTION(this << stream);
151 int64_t numStreamsAssigned = 0;
152 m_uniformRandomVariable->SetStream(stream);
153 numStreamsAssigned++;
154 numStreamsAssigned += m_legacyManager->AssignStreams(stream);
155 return numStreamsAssigned;
156}
157
158void
160{
161 NS_LOG_FUNCTION(this << phy);
162 // Setup PHY for legacy manager.
163 m_legacyManager->SetupPhy(phy);
165}
166
167void
169{
170 NS_LOG_FUNCTION(this << mac);
171 m_legacyManager->SetupMac(mac);
173}
174
175void
177{
178 NS_LOG_FUNCTION(this);
179 /**
180 * Here we initialize m_minstrelGroups with all the possible groups.
181 * If a group is not supported by the device, then it is marked as not supported.
182 * Then, after all initializations are finished, we check actual support for each receiving
183 * station.
184 */
185
186 if (GetHtSupported())
187 {
190 }
191 if (GetVhtSupported())
192 {
195 }
196 if (GetHeSupported())
197 {
200 }
201
202 /**
203 * Initialize the groups array.
204 * The HT groups come first, then the VHT ones, and finally the HE ones.
205 * Minstrel maintains different types of indexes:
206 * - A global continuous index, which identifies all rates within all groups, in [0,
207 * m_numGroups * m_numRates]
208 * - A groupId, which indexes a group in the array, in [0, m_numGroups]
209 * - A rateId, which identifies a rate within a group, in [0, m_numRates]
210 * - A deviceIndex, which indexes a MCS in the PHY MCS array.
211 * - A mcsIndex, which indexes a MCS in the wifi-remote-station-manager supported MCSs
212 * array.
213 */
214 NS_LOG_DEBUG("Initialize MCS Groups:");
216
217 if (GetHtSupported())
218 {
219 // Initialize all HT groups
220 for (MHz_u chWidth = 20; chWidth <= MAX_HT_WIDTH; chWidth *= 2)
221 {
222 for (int gi = 800; gi >= 400;)
223 {
224 const auto guardInterval = NanoSeconds(gi);
225 for (uint8_t streams = 1; streams <= MAX_HT_SUPPORTED_STREAMS; streams++)
226 {
227 uint8_t groupId = GetHtGroupId(streams, guardInterval, chWidth);
228
229 m_minstrelGroups[groupId].streams = streams;
230 m_minstrelGroups[groupId].gi = guardInterval;
231 m_minstrelGroups[groupId].chWidth = chWidth;
233 m_minstrelGroups[groupId].isSupported = false;
234
235 // Check capabilities of the device
237 (gi == 400)) /// Is SGI supported by the transmitter?
238 && (GetPhy()->GetChannelWidth() >=
239 chWidth) /// Is channel width supported by the transmitter?
240 && (GetPhy()->GetMaxSupportedTxSpatialStreams() >=
241 streams)) /// Are streams supported by the transmitter?
242 {
243 m_minstrelGroups[groupId].isSupported = true;
244
245 // Calculate TX time for all rates of the group
246 WifiModeList htMcsList = GetHtDeviceMcsList();
247 for (uint8_t i = 0; i < MAX_HT_GROUP_RATES; i++)
248 {
249 uint16_t deviceIndex = i + (m_minstrelGroups[groupId].streams - 1) * 8;
250 WifiMode mode = htMcsList[deviceIndex];
251 AddFirstMpduTxTime(groupId,
252 mode,
254 streams,
255 guardInterval,
256 chWidth,
257 mode,
259 AddMpduTxTime(groupId,
260 mode,
262 streams,
263 guardInterval,
264 chWidth,
265 mode,
267 }
268 NS_LOG_DEBUG("Initialized group " << +groupId << ": (" << +streams << ","
269 << guardInterval << "," << chWidth
270 << ")");
271 }
272 }
273 gi /= 2;
274 }
275 }
276 }
277
278 if (GetVhtSupported())
279 {
280 // Initialize all VHT groups
281 for (MHz_u chWidth = 20; chWidth <= MAX_VHT_WIDTH; chWidth *= 2)
282 {
283 for (int gi = 800; gi >= 400;)
284 {
285 const auto guardInterval = NanoSeconds(gi);
286 for (uint8_t streams = 1; streams <= MAX_VHT_SUPPORTED_STREAMS; streams++)
287 {
288 uint8_t groupId = GetVhtGroupId(streams, guardInterval, chWidth);
289
290 m_minstrelGroups[groupId].streams = streams;
291 m_minstrelGroups[groupId].gi = guardInterval;
292 m_minstrelGroups[groupId].chWidth = chWidth;
294 m_minstrelGroups[groupId].isSupported = false;
295
296 // Check capabilities of the device
298 (gi == 400)) /// Is SGI supported by the transmitter?
299 && (GetPhy()->GetChannelWidth() >=
300 chWidth) /// Is channel width supported by the transmitter?
301 && (GetPhy()->GetMaxSupportedTxSpatialStreams() >=
302 streams)) /// Are streams supported by the transmitter?
303 {
304 m_minstrelGroups[groupId].isSupported = true;
305
306 // Calculate TX time for all rates of the group
307 WifiModeList vhtMcsList = GetVhtDeviceMcsList();
308 for (uint8_t i = 0; i < MAX_VHT_GROUP_RATES; i++)
309 {
310 WifiMode mode = vhtMcsList[i];
311 // Check for invalid VHT MCSs and do not add time to array.
312 if (IsValidMcs(GetPhy(), streams, chWidth, mode))
313 {
315 groupId,
316 mode,
318 streams,
319 guardInterval,
320 chWidth,
321 mode,
323 AddMpduTxTime(groupId,
324 mode,
326 streams,
327 guardInterval,
328 chWidth,
329 mode,
331 }
332 }
333 NS_LOG_DEBUG("Initialized group " << +groupId << ": (" << +streams << ","
334 << gi << "," << chWidth << ")");
335 }
336 }
337 gi /= 2;
338 }
339 }
340 }
341
342 if (GetHeSupported())
343 {
344 // Initialize all HE groups
345 for (MHz_u chWidth = 20; chWidth <= MAX_HE_WIDTH; chWidth *= 2)
346 {
347 for (int gi = 3200; gi >= 800;)
348 {
349 const auto guardInterval = NanoSeconds(gi);
350 for (uint8_t streams = 1; streams <= MAX_HE_SUPPORTED_STREAMS; streams++)
351 {
352 uint8_t groupId = GetHeGroupId(streams, guardInterval, chWidth);
353
354 m_minstrelGroups[groupId].streams = streams;
355 m_minstrelGroups[groupId].gi = guardInterval;
356 m_minstrelGroups[groupId].chWidth = chWidth;
358 m_minstrelGroups[groupId].isSupported = false;
359
360 // Check capabilities of the device
361 if ((GetGuardInterval() <=
362 guardInterval) /// Is GI supported by the transmitter?
363 && (GetPhy()->GetChannelWidth() >=
364 chWidth) /// Is channel width supported by the transmitter?
365 && (GetPhy()->GetMaxSupportedTxSpatialStreams() >=
366 streams)) /// Are streams supported by the transmitter?
367 {
368 m_minstrelGroups[groupId].isSupported = true;
369
370 // Calculate tx time for all rates of the group
371 WifiModeList heMcsList = GetHeDeviceMcsList();
372 for (uint8_t i = 0; i < MAX_HE_GROUP_RATES; i++)
373 {
374 WifiMode mode = heMcsList.at(i);
375 // Check for invalid HE MCSs and do not add time to array.
376 if (IsValidMcs(GetPhy(), streams, chWidth, mode))
377 {
379 groupId,
380 mode,
382 streams,
383 guardInterval,
384 chWidth,
385 mode,
387 AddMpduTxTime(groupId,
388 mode,
390 streams,
391 guardInterval,
392 chWidth,
393 mode,
395 }
396 }
397 NS_LOG_DEBUG("Initialized group " << +groupId << ": (" << +streams << ","
398 << gi << "," << chWidth << ")");
399 }
400 }
401 gi /= 2;
402 }
403 }
404 }
405}
406
407bool
409{
410 NS_LOG_FUNCTION(this << phy << +streams << chWidth << mode);
411 WifiTxVector txvector;
412 txvector.SetNss(streams);
413 txvector.SetChannelWidth(chWidth);
414 txvector.SetMode(mode);
415 return txvector.IsValid();
416}
417
418Time
420 uint8_t streams,
421 Time gi,
422 MHz_u chWidth,
423 WifiMode mode,
424 MpduType mpduType)
425{
426 NS_LOG_FUNCTION(this << phy << +streams << gi << chWidth << mode << mpduType);
427 WifiTxVector txvector;
428 txvector.SetNss(streams);
429 txvector.SetGuardInterval(gi);
430 txvector.SetChannelWidth(chWidth);
431 txvector.SetNess(0);
432 txvector.SetStbc(false);
433 txvector.SetMode(mode);
436 WifiPhy::GetPayloadDuration(m_frameLength, txvector, phy->GetPhyBand(), mpduType);
437}
438
439Time
441{
442 NS_LOG_FUNCTION(this << +groupId << mode);
443 auto it = m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.find(mode);
444 NS_ASSERT(it != m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.end());
445 return it->second;
446}
447
448void
450{
451 NS_LOG_FUNCTION(this << +groupId << mode << t);
452 m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.insert(std::make_pair(mode, t));
453}
454
455Time
457{
458 NS_LOG_FUNCTION(this << +groupId << mode);
459 auto it = m_minstrelGroups[groupId].ratesTxTimeTable.find(mode);
460 NS_ASSERT(it != m_minstrelGroups[groupId].ratesTxTimeTable.end());
461 return it->second;
462}
463
464void
466{
467 NS_LOG_FUNCTION(this << +groupId << mode << t);
468 m_minstrelGroups[groupId].ratesTxTimeTable.insert(std::make_pair(mode, t));
469}
470
473{
474 NS_LOG_FUNCTION(this);
475 auto station = new MinstrelHtWifiRemoteStation();
476
477 // Initialize variables common to both stations.
478 station->m_nextStatsUpdate = Simulator::Now() + m_updateStats;
479 station->m_col = 0;
480 station->m_index = 0;
481 station->m_maxTpRate = 0;
482 station->m_maxTpRate2 = 0;
483 station->m_maxProbRate = 0;
484 station->m_nModes = 0;
485 station->m_totalPacketsCount = 0;
486 station->m_samplePacketsCount = 0;
487 station->m_isSampling = false;
488 station->m_sampleRate = 0;
489 station->m_sampleDeferred = false;
490 station->m_shortRetry = 0;
491 station->m_longRetry = 0;
492 station->m_txrate = 0;
493 station->m_initialized = false;
494
495 // Variables specific to HT station
496 station->m_sampleGroup = 0;
497 station->m_numSamplesSlow = 0;
498 station->m_sampleCount = 16;
499 station->m_sampleWait = 0;
500 station->m_sampleTries = 4;
501
502 station->m_avgAmpduLen = 1;
503 station->m_ampduLen = 0;
504 station->m_ampduPacketCount = 0;
505
506 // Use the variable in the station to indicate whether the device supports HT.
507 // When correct information available it will be checked.
508 station->m_isHt = static_cast<bool>(GetPhy()->GetDevice()->GetHtConfiguration());
509
510 return station;
511}
512
513void
515{
516 NS_LOG_FUNCTION(this << station);
517 // Note: we appear to be doing late initialization of the table
518 // to make sure that the set of supported rates has been initialized
519 // before we perform our own initialization.
520 if (!station->m_initialized)
521 {
522 /**
523 * Check if the station supports HT.
524 * Assume that if the device do not supports HT then
525 * the station will not support HT either.
526 * We save from using another check and variable.
527 */
529 {
530 NS_LOG_INFO("non-HT station " << station);
531 station->m_isHt = false;
532 // We will use non-HT minstrel for this station. Initialize the manager.
533 m_legacyManager->SetAttribute("UpdateStatistics", TimeValue(m_legacyUpdateStats));
534 m_legacyManager->SetAttribute("LookAroundRate", UintegerValue(m_lookAroundRate));
535 m_legacyManager->SetAttribute("EWMA", UintegerValue(m_ewmaLevel));
536 m_legacyManager->SetAttribute("SampleColumn", UintegerValue(m_nSampleCol));
537 m_legacyManager->SetAttribute("PacketLength", UintegerValue(m_frameLength));
538 m_legacyManager->SetAttribute("PrintStats", BooleanValue(m_printStats));
539 m_legacyManager->CheckInit(station);
540 }
541 else
542 {
543 NS_LOG_DEBUG("HT station " << station);
544 station->m_isHt = true;
545 station->m_nModes = GetNMcsSupported(station);
546 station->m_minstrelTable = MinstrelRate(station->m_nModes);
547 station->m_sampleTable = SampleRate(m_numRates, std::vector<uint8_t>(m_nSampleCol));
548 InitSampleTable(station);
549 RateInit(station);
550 station->m_initialized = true;
551 }
552 }
553}
554
555void
557{
558 NS_LOG_FUNCTION(this << st);
560 "DoReportRxOk m_txrate=" << static_cast<MinstrelHtWifiRemoteStation*>(st)->m_txrate);
561}
562
563void
565{
566 NS_LOG_FUNCTION(this << st);
567 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
568 CheckInit(station);
569 if (!station->m_initialized)
570 {
571 return;
572 }
573 NS_LOG_DEBUG("DoReportRtsFailed m_txrate = " << station->m_txrate);
574 station->m_shortRetry++;
575}
576
577void
579 double ctsSnr,
580 WifiMode ctsMode,
581 double rtsSnr)
582{
583 NS_LOG_FUNCTION(this << st);
584}
585
586void
588{
589 NS_LOG_FUNCTION(this << st);
590 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
591 NS_LOG_DEBUG("Final RTS failed");
592 CheckInit(station);
593 if (!station->m_initialized)
594 {
595 return;
596 }
597 UpdateRetry(station);
598}
599
600void
602{
603 NS_LOG_FUNCTION(this << st);
604 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
605
606 CheckInit(station);
607 if (!station->m_initialized)
608 {
609 return;
610 }
611
612 NS_LOG_DEBUG("DoReportDataFailed " << station << "\t rate " << station->m_txrate
613 << "\tlongRetry \t" << station->m_longRetry);
614
615 if (!station->m_isHt)
616 {
617 m_legacyManager->UpdateRate(station);
618 }
619 else if (station->m_longRetry < CountRetries(station))
620 {
621 uint8_t rateId = GetRateId(station->m_txrate);
622 uint8_t groupId = GetGroupId(station->m_txrate);
623 station->m_groupsTable[groupId]
624 .m_ratesTable[rateId]
625 .numRateAttempt++; // Increment the attempts counter for the rate used.
626 UpdateRate(station);
627 }
628}
629
630void
632 double ackSnr,
633 WifiMode ackMode,
634 double dataSnr,
635 MHz_u dataChannelWidth,
636 uint8_t dataNss)
637{
638 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
639 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
640
641 CheckInit(station);
642 if (!station->m_initialized)
643 {
644 return;
645 }
646
647 if (!station->m_isHt)
648 {
649 NS_LOG_DEBUG("DoReportDataOk m_txrate = "
650 << station->m_txrate
651 << ", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
652 << ", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
653 << " (before update).");
654
655 station->m_minstrelTable[station->m_txrate].numRateSuccess++;
656 station->m_minstrelTable[station->m_txrate].numRateAttempt++;
657
658 m_legacyManager->UpdatePacketCounters(station);
659
660 NS_LOG_DEBUG("DoReportDataOk m_txrate = "
661 << station->m_txrate
662 << ", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
663 << ", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
664 << " (after update).");
665
666 UpdateRetry(station);
667 m_legacyManager->UpdateStats(station);
668
669 if (station->m_nModes >= 1)
670 {
671 station->m_txrate = m_legacyManager->FindRate(station);
672 }
673 }
674 else
675 {
676 uint8_t rateId = GetRateId(station->m_txrate);
677 uint8_t groupId = GetGroupId(station->m_txrate);
678
680 "DoReportDataOk m_txrate = "
681 << station->m_txrate
682 << ", attempt = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt
683 << ", success = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess
684 << " (before update).");
685
686 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess++;
687 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt++;
688
689 UpdatePacketCounters(station, 1, 0);
690
692 "DoReportDataOk m_txrate = "
693 << station->m_txrate
694 << ", attempt = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt
695 << ", success = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess
696 << " (after update).");
697
698 station->m_isSampling = false;
699 station->m_sampleDeferred = false;
700
701 UpdateRetry(station);
702 if (Simulator::Now() >= station->m_nextStatsUpdate)
703 {
704 UpdateStats(station);
705 }
706
707 if (station->m_nModes >= 1)
708 {
709 station->m_txrate = FindRate(station);
710 }
711 }
712
713 NS_LOG_DEBUG("Next rate to use TxRate = " << station->m_txrate);
714}
715
716void
718{
719 NS_LOG_FUNCTION(this << st);
720 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
721
722 CheckInit(station);
723 if (!station->m_initialized)
724 {
725 return;
726 }
727
728 NS_LOG_DEBUG("DoReportFinalDataFailed - TxRate=" << station->m_txrate);
729
730 if (!station->m_isHt)
731 {
732 m_legacyManager->UpdatePacketCounters(station);
733
734 UpdateRetry(station);
735
736 m_legacyManager->UpdateStats(station);
737 if (station->m_nModes >= 1)
738 {
739 station->m_txrate = m_legacyManager->FindRate(station);
740 }
741 }
742 else
743 {
744 UpdatePacketCounters(station, 0, 1);
745
746 station->m_isSampling = false;
747 station->m_sampleDeferred = false;
748
749 UpdateRetry(station);
750 if (Simulator::Now() >= station->m_nextStatsUpdate)
751 {
752 UpdateStats(station);
753 }
754
755 if (station->m_nModes >= 1)
756 {
757 station->m_txrate = FindRate(station);
758 }
759 }
760 NS_LOG_DEBUG("Next rate to use TxRate = " << station->m_txrate);
761}
762
763void
765 uint16_t nSuccessfulMpdus,
766 uint16_t nFailedMpdus,
767 double rxSnr,
768 double dataSnr,
769 MHz_u dataChannelWidth,
770 uint8_t dataNss)
771{
772 NS_LOG_FUNCTION(this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr
773 << dataChannelWidth << +dataNss);
774 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
775
776 CheckInit(station);
777 if (!station->m_initialized)
778 {
779 return;
780 }
781
782 NS_ASSERT_MSG(station->m_isHt, "A-MPDU Tx Status called but this is a non-HT STA.");
783
784 NS_LOG_DEBUG("DoReportAmpduTxStatus. TxRate=" << station->m_txrate
785 << " SuccMpdus=" << nSuccessfulMpdus
786 << " FailedMpdus=" << nFailedMpdus);
787
788 station->m_ampduPacketCount++;
789 station->m_ampduLen += nSuccessfulMpdus + nFailedMpdus;
790
791 UpdatePacketCounters(station, nSuccessfulMpdus, nFailedMpdus);
792
793 uint8_t rateId = GetRateId(station->m_txrate);
794 uint8_t groupId = GetGroupId(station->m_txrate);
795 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess += nSuccessfulMpdus;
796 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt +=
797 nSuccessfulMpdus + nFailedMpdus;
798
799 if (nSuccessfulMpdus == 0 && station->m_longRetry < CountRetries(station))
800 {
801 // We do not receive a BlockAck. The entire AMPDU fail.
802 UpdateRate(station);
803 }
804 else
805 {
806 station->m_isSampling = false;
807 station->m_sampleDeferred = false;
808
809 UpdateRetry(station);
810 if (Simulator::Now() >= station->m_nextStatsUpdate)
811 {
812 UpdateStats(station);
813 }
814
815 if (station->m_nModes >= 1)
816 {
817 station->m_txrate = FindRate(station);
818 }
819 NS_LOG_DEBUG("Next rate to use TxRate = " << station->m_txrate);
820 }
821}
822
823void
825{
826 NS_LOG_FUNCTION(this << station);
827
828 /**
829 * Retry Chain table is implemented here.
830 *
831 * FIXME
832 * Currently, NS3 does not retransmit an entire A-MPDU when BACK is missing
833 * but retransmits each MPDU until MPDUs lifetime expires (or a BACK is received).
834 * Then, there is no way to control A-MPDU retries (no call to NeedDataRetransmission).
835 * So, it is possible that the A-MPDU keeps retrying after longRetry reaches its limit.
836 *
837 *
838 * Try | LOOKAROUND RATE | NORMAL RATE
839 * -------------------------------------------------------
840 * 1 | Random rate | Best throughput
841 * 2 | Next best throughput | Next best throughput
842 * 3 | Best probability | Best probability
843 *
844 * Note: For clarity, multiple blocks of if's and else's are used
845 * Following implementation in Linux, in MinstrelHT lowest base rate is not used.
846 * Explanation can be found here: http://marc.info/?l=linux-wireless&m=144602778611966&w=2
847 */
848
849 CheckInit(station);
850 if (!station->m_initialized)
851 {
852 return;
853 }
854 station->m_longRetry++;
855
856 /**
857 * Get the IDs for all rates.
858 */
859 uint8_t maxTpRateId = GetRateId(station->m_maxTpRate);
860 uint8_t maxTpGroupId = GetGroupId(station->m_maxTpRate);
861 uint8_t maxTp2RateId = GetRateId(station->m_maxTpRate2);
862 uint8_t maxTp2GroupId = GetGroupId(station->m_maxTpRate2);
863 uint8_t maxProbRateId = GetRateId(station->m_maxProbRate);
864 uint8_t maxProbGroupId = GetGroupId(station->m_maxProbRate);
865
866 /// For normal rate, we're not currently sampling random rates.
867 if (!station->m_isSampling)
868 {
869 /// Use best throughput rate.
870 if (station->m_longRetry <
871 station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount)
872 {
873 NS_LOG_DEBUG("Not Sampling; use the same rate again");
874 station->m_txrate = station->m_maxTpRate; //!< There are still a few retries.
875 }
876
877 /// Use second best throughput rate.
878 else if (station->m_longRetry <
879 (station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
880 station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount))
881 {
882 NS_LOG_DEBUG("Not Sampling; use the Max TP2");
883 station->m_txrate = station->m_maxTpRate2;
884 }
885
886 /// Use best probability rate.
887 else if (station->m_longRetry <=
888 (station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
889 station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount +
890 station->m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount))
891 {
892 NS_LOG_DEBUG("Not Sampling; use Max Prob");
893 station->m_txrate = station->m_maxProbRate;
894 }
895 else
896 {
897 NS_FATAL_ERROR("Max retries reached and m_longRetry not cleared properly. longRetry= "
898 << station->m_longRetry);
899 }
900 }
901
902 /// We're currently sampling random rates.
903 else
904 {
905 /// Sample rate is used only once
906 /// Use the best rate.
907 if (station->m_longRetry <
908 1 + station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount)
909 {
910 NS_LOG_DEBUG("Sampling use the MaxTP rate");
911 station->m_txrate = station->m_maxTpRate2;
912 }
913
914 /// Use the best probability rate.
915 else if (station->m_longRetry <=
916 1 + station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount +
917 station->m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount)
918 {
919 NS_LOG_DEBUG("Sampling use the MaxProb rate");
920 station->m_txrate = station->m_maxProbRate;
921 }
922 else
923 {
924 NS_FATAL_ERROR("Max retries reached and m_longRetry not cleared properly. longRetry= "
925 << station->m_longRetry);
926 }
927 }
928 NS_LOG_DEBUG("Next rate to use TxRate = " << station->m_txrate);
929}
930
931void
933{
934 NS_LOG_FUNCTION(this << station);
935 station->m_shortRetry = 0;
936 station->m_longRetry = 0;
937}
938
939void
941 uint16_t nSuccessfulMpdus,
942 uint16_t nFailedMpdus)
943{
944 NS_LOG_FUNCTION(this << station << nSuccessfulMpdus << nFailedMpdus);
945
946 station->m_totalPacketsCount += nSuccessfulMpdus + nFailedMpdus;
947 if (station->m_isSampling)
948 {
949 station->m_samplePacketsCount += nSuccessfulMpdus + nFailedMpdus;
950 }
951 if (station->m_totalPacketsCount == ~0)
952 {
953 station->m_samplePacketsCount = 0;
954 station->m_totalPacketsCount = 0;
955 }
956
957 if (!station->m_sampleWait && !station->m_sampleTries && station->m_sampleCount > 0)
958 {
959 station->m_sampleWait = 16 + 2 * station->m_avgAmpduLen;
960 station->m_sampleTries = 1;
961 station->m_sampleCount--;
962 }
963}
964
965uint16_t
967{
968 NS_LOG_FUNCTION(this << txRate << allowedWidth);
969
970 auto groupId = GetGroupId(txRate);
971 McsGroup group = m_minstrelGroups[groupId];
972
973 if (group.chWidth <= allowedWidth)
974 {
975 NS_LOG_DEBUG("Channel width is not greater than allowed width, nothing to do");
976 return txRate;
977 }
978
979 NS_ASSERT(GetPhy()->GetDevice()->GetHtConfiguration() != nullptr);
980 NS_ASSERT(static_cast<uint16_t>(group.chWidth) % 20 == 0);
981 // try halving the channel width and check if the group with the same number of
982 // streams and same GI is supported, until either a supported group is found or
983 // the width becomes lower than 20 MHz
984 auto width = group.chWidth / 2;
985
986 while (width >= 20)
987 {
988 if (width > allowedWidth)
989 {
990 width /= 2;
991 continue;
992 }
993
994 switch (group.type)
995 {
997 groupId = GetHtGroupId(group.streams, group.gi, width);
998 break;
1000 groupId = GetVhtGroupId(group.streams, group.gi, width);
1001 break;
1003 groupId = GetHeGroupId(group.streams, group.gi, width);
1004 break;
1005 default:
1006 NS_ABORT_MSG("Unknown group type: " << group.type);
1007 }
1008
1009 group = m_minstrelGroups[groupId];
1010 if (group.isSupported)
1011 {
1012 break;
1013 }
1014
1015 width /= 2;
1016 }
1017
1018 NS_ABORT_MSG_IF(width < 20, "No rate compatible with the allowed width found");
1019
1020 return GetIndex(groupId, GetRateId(txRate));
1021}
1022
1025{
1026 NS_LOG_FUNCTION(this << st << allowedWidth);
1027 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
1028
1029 if (!station->m_initialized)
1030 {
1031 CheckInit(station);
1032 }
1033
1034 if (!station->m_isHt)
1035 {
1036 WifiTxVector vector = m_legacyManager->GetDataTxVector(station);
1037 uint64_t dataRate = vector.GetMode().GetDataRate(vector);
1038 if (m_currentRate != dataRate && !station->m_isSampling)
1039 {
1040 NS_LOG_DEBUG("New datarate: " << dataRate);
1041 m_currentRate = dataRate;
1042 }
1043 return vector;
1044 }
1045
1046 station->m_txrate = UpdateRateAfterAllowedWidth(station->m_txrate, allowedWidth);
1047 NS_LOG_DEBUG("DoGetDataMode m_txrate= " << station->m_txrate);
1048
1049 uint8_t rateId = GetRateId(station->m_txrate);
1050 uint8_t groupId = GetGroupId(station->m_txrate);
1051 uint8_t mcsIndex = station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex;
1052
1053 NS_LOG_DEBUG("DoGetDataMode rateId= " << +rateId << " groupId= " << +groupId
1054 << " mode= " << GetMcsSupported(station, mcsIndex));
1055
1056 McsGroup group = m_minstrelGroups[groupId];
1057
1058 // Check consistency of rate selected.
1059 if (((group.type == WIFI_MINSTREL_GROUP_HE) && (group.gi < GetGuardInterval(station))) ||
1060 (((group.type == WIFI_MINSTREL_GROUP_HT) || (group.type == WIFI_MINSTREL_GROUP_VHT)) &&
1061 (group.gi.GetNanoSeconds() == 400) && !GetShortGuardIntervalSupported(station)) ||
1062 (group.chWidth > GetChannelWidth(station)) ||
1063 (group.streams > GetNumberOfSupportedStreams(station)))
1064 {
1065 NS_FATAL_ERROR("Inconsistent group selected. Group: ("
1066 << +group.streams << "," << group.gi << "," << group.chWidth << ")"
1067 << " Station capabilities: (" << GetNumberOfSupportedStreams(station) << ","
1068 << ((group.type == WIFI_MINSTREL_GROUP_HE)
1069 ? GetGuardInterval(station)
1070 : NanoSeconds(GetShortGuardIntervalSupported(station) ? 400 : 800))
1071 << "," << GetChannelWidth(station) << ")");
1072 }
1073 WifiMode mode = GetMcsSupported(station, mcsIndex);
1074 WifiTxVector txVector{
1075 mode,
1078 group.gi,
1080 group.streams,
1081 GetNess(station),
1082 GetPhy()->GetTxBandwidth(mode, group.chWidth),
1083 GetAggregation(station) && !station->m_isSampling};
1084 uint64_t dataRate = mode.GetDataRate(txVector);
1085 if (m_currentRate != dataRate && !station->m_isSampling)
1086 {
1087 NS_LOG_DEBUG("New datarate: " << dataRate);
1088 m_currentRate = dataRate;
1089 }
1090 return txVector;
1091}
1092
1095{
1096 NS_LOG_FUNCTION(this << st);
1097 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
1098
1099 if (!station->m_initialized)
1100 {
1101 CheckInit(station);
1102 }
1103
1104 if (!station->m_isHt)
1105 {
1106 return m_legacyManager->GetRtsTxVector(station);
1107 }
1108 else
1109 {
1110 NS_LOG_DEBUG("DoGetRtsMode m_txrate=" << station->m_txrate);
1111
1112 /* RTS is sent in a non-HT frame. RTS with HT is not supported yet in NS3.
1113 * When supported, decision of using HT has to follow rules in Section 9.7.6 from
1114 * 802.11-2012. From Sec. 9.7.6.5: "A frame other than a BlockAckReq or BlockAck that is
1115 * carried in a non-HT PPDU shall be transmitted by the STA using a rate no higher than the
1116 * highest rate in the BSSBasicRateSet parameter that is less than or equal to the rate or
1117 * non-HT reference rate (see 9.7.9) of the previously transmitted frame that was
1118 * directed to the same receiving STA. If no rate in the BSSBasicRateSet parameter meets
1119 * these conditions, the control frame shall be transmitted at a rate no higher than the
1120 * highest mandatory rate of the attached PHY that is less than or equal to the rate
1121 * or non-HT reference rate (see 9.7.9) of the previously transmitted frame that was
1122 * directed to the same receiving STA."
1123 */
1124
1125 // As we are in Minstrel HT, assume the last rate was an HT rate.
1126 uint8_t rateId = GetRateId(station->m_txrate);
1127 uint8_t groupId = GetGroupId(station->m_txrate);
1128 uint8_t mcsIndex = station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex;
1129
1130 WifiMode lastRate = GetMcsSupported(station, mcsIndex);
1131 uint64_t lastDataRate = lastRate.GetNonHtReferenceRate();
1132 uint8_t nBasicRates = GetNBasicModes();
1133
1134 WifiMode rtsRate;
1135 bool rateFound = false;
1136
1137 for (uint8_t i = 0; i < nBasicRates; i++)
1138 {
1139 uint64_t rate = GetBasicMode(i).GetDataRate(20);
1140 if (rate <= lastDataRate)
1141 {
1142 rtsRate = GetBasicMode(i);
1143 rateFound = true;
1144 }
1145 }
1146
1147 if (!rateFound)
1148 {
1149 Ptr<WifiPhy> phy = GetPhy();
1150 for (const auto& mode : phy->GetModeList())
1151 {
1152 uint64_t rate = mode.GetDataRate(20);
1153 if (rate <= lastDataRate)
1154 {
1155 rtsRate = mode;
1156 rateFound = true;
1157 }
1158 }
1159 }
1160
1161 NS_ASSERT(rateFound);
1162
1163 return WifiTxVector(
1164 rtsRate,
1167 NanoSeconds(800),
1168 1,
1169 1,
1170 0,
1171 GetPhy()->GetTxBandwidth(rtsRate, GetChannelWidth(station)),
1172 GetAggregation(station));
1173 }
1174}
1175
1176bool
1178 Ptr<const Packet> packet,
1179 bool normally)
1180{
1181 NS_LOG_FUNCTION(this << st << packet << normally);
1182
1183 auto station = static_cast<MinstrelHtWifiRemoteStation*>(st);
1184
1185 CheckInit(station);
1186 if (!station->m_initialized)
1187 {
1188 return normally;
1189 }
1190
1191 uint32_t maxRetries;
1192
1193 if (!station->m_isHt)
1194 {
1195 maxRetries = m_legacyManager->CountRetries(station);
1196 }
1197 else
1198 {
1199 maxRetries = CountRetries(station);
1200 }
1201
1202 if (station->m_longRetry >= maxRetries)
1203 {
1204 NS_LOG_DEBUG("No re-transmission allowed. Retries: " << station->m_longRetry
1205 << " Max retries: " << maxRetries);
1206 return false;
1207 }
1208 else
1209 {
1210 NS_LOG_DEBUG("Re-transmit. Retries: " << station->m_longRetry
1211 << " Max retries: " << maxRetries);
1212 return true;
1213 }
1214}
1215
1218{
1219 uint8_t maxProbRateId = GetRateId(station->m_maxProbRate);
1220 uint8_t maxProbGroupId = GetGroupId(station->m_maxProbRate);
1221 uint8_t maxTpRateId = GetRateId(station->m_maxTpRate);
1222 uint8_t maxTpGroupId = GetGroupId(station->m_maxTpRate);
1223 uint8_t maxTp2RateId = GetRateId(station->m_maxTpRate2);
1224 uint8_t maxTp2GroupId = GetGroupId(station->m_maxTpRate2);
1225
1226 if (!station->m_isSampling)
1227 {
1228 return station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
1229 station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount +
1230 station->m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount;
1231 }
1232 else
1233 {
1234 return 1 + station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount +
1235 station->m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount;
1236 }
1237}
1238
1239uint16_t
1241{
1242 NS_LOG_FUNCTION(this << station);
1243 uint8_t sampleGroup = station->m_sampleGroup;
1244 uint8_t index = station->m_groupsTable[sampleGroup].m_index;
1245 uint8_t col = station->m_groupsTable[sampleGroup].m_col;
1246 uint8_t sampleIndex = station->m_sampleTable[index][col];
1247 uint16_t rateIndex = GetIndex(sampleGroup, sampleIndex);
1248 NS_LOG_DEBUG("Next Sample is " << rateIndex);
1249 SetNextSample(station); // Calculate the next sample rate.
1250 return rateIndex;
1251}
1252
1253void
1255{
1256 NS_LOG_FUNCTION(this << station);
1257 do
1258 {
1259 station->m_sampleGroup++;
1260 station->m_sampleGroup %= m_numGroups;
1261 } while (!station->m_groupsTable[station->m_sampleGroup].m_supported);
1262
1263 station->m_groupsTable[station->m_sampleGroup].m_index++;
1264
1265 uint8_t sampleGroup = station->m_sampleGroup;
1266 uint8_t index = station->m_groupsTable[station->m_sampleGroup].m_index;
1267 uint8_t col = station->m_groupsTable[sampleGroup].m_col;
1268
1269 if (index >= m_numRates)
1270 {
1271 station->m_groupsTable[station->m_sampleGroup].m_index = 0;
1272 station->m_groupsTable[station->m_sampleGroup].m_col++;
1273 if (station->m_groupsTable[station->m_sampleGroup].m_col >= m_nSampleCol)
1274 {
1275 station->m_groupsTable[station->m_sampleGroup].m_col = 0;
1276 }
1277 index = station->m_groupsTable[station->m_sampleGroup].m_index;
1278 col = station->m_groupsTable[sampleGroup].m_col;
1279 }
1280 NS_LOG_DEBUG("New sample set: group= " << +sampleGroup
1281 << " index= " << +station->m_sampleTable[index][col]);
1282}
1283
1284uint16_t
1286{
1287 NS_LOG_FUNCTION(this << station);
1288 NS_LOG_DEBUG("FindRate packet=" << station->m_totalPacketsCount);
1289
1290 if ((station->m_samplePacketsCount + station->m_totalPacketsCount) == 0)
1291 {
1292 return station->m_maxTpRate;
1293 }
1294
1295 // If we have waited enough, then sample.
1296 if (station->m_sampleWait == 0 && station->m_sampleTries != 0)
1297 {
1298 // SAMPLING
1299 NS_LOG_DEBUG("Obtaining a sampling rate");
1300 /// Now go through the table and find an index rate.
1301 uint16_t sampleIdx = GetNextSample(station);
1302 NS_LOG_DEBUG("Sampling rate = " << sampleIdx);
1303
1304 // Evaluate if the sampling rate selected should be used.
1305 uint8_t sampleGroupId = GetGroupId(sampleIdx);
1306 uint8_t sampleRateId = GetRateId(sampleIdx);
1307
1308 // If the rate selected is not supported, then don't sample.
1309 if (station->m_groupsTable[sampleGroupId].m_supported &&
1310 station->m_groupsTable[sampleGroupId].m_ratesTable[sampleRateId].supported)
1311 {
1312 /**
1313 * Sampling might add some overhead to the frame.
1314 * Hence, don't use sampling for the currently used rates.
1315 *
1316 * Also do not sample if the probability is already higher than 95%
1317 * to avoid wasting airtime.
1318 */
1319 MinstrelHtRateInfo sampleRateInfo =
1320 station->m_groupsTable[sampleGroupId].m_ratesTable[sampleRateId];
1321
1322 NS_LOG_DEBUG("Use sample rate? MaxTpRate= "
1323 << station->m_maxTpRate << " CurrentRate= " << station->m_txrate
1324 << " SampleRate= " << sampleIdx
1325 << " SampleProb= " << sampleRateInfo.ewmaProb);
1326
1327 if (sampleIdx != station->m_maxTpRate && sampleIdx != station->m_maxTpRate2 &&
1328 sampleIdx != station->m_maxProbRate && sampleRateInfo.ewmaProb <= 95)
1329 {
1330 /**
1331 * Make sure that lower rates get sampled only occasionally,
1332 * if the link is working perfectly.
1333 */
1334
1335 uint8_t maxTpGroupId = GetGroupId(station->m_maxTpRate);
1336 uint8_t maxTp2GroupId = GetGroupId(station->m_maxTpRate2);
1337 uint8_t maxTp2RateId = GetRateId(station->m_maxTpRate2);
1338 uint8_t maxProbGroupId = GetGroupId(station->m_maxProbRate);
1339 uint8_t maxProbRateId = GetRateId(station->m_maxProbRate);
1340
1341 uint8_t maxTpStreams = m_minstrelGroups[maxTpGroupId].streams;
1342 uint8_t sampleStreams = m_minstrelGroups[sampleGroupId].streams;
1343
1344 Time sampleDuration = sampleRateInfo.perfectTxTime;
1345 Time maxTp2Duration =
1346 station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].perfectTxTime;
1347 Time maxProbDuration = station->m_groupsTable[maxProbGroupId]
1348 .m_ratesTable[maxProbRateId]
1349 .perfectTxTime;
1350
1351 NS_LOG_DEBUG("Use sample rate? SampleDuration= "
1352 << sampleDuration << " maxTp2Duration= " << maxTp2Duration
1353 << " maxProbDuration= " << maxProbDuration << " sampleStreams= "
1354 << +sampleStreams << " maxTpStreams= " << +maxTpStreams);
1355 if (sampleDuration < maxTp2Duration ||
1356 (sampleStreams < maxTpStreams && sampleDuration < maxProbDuration))
1357 {
1358 /// Set flag that we are currently sampling.
1359 station->m_isSampling = true;
1360
1361 /// set the rate that we're currently sampling
1362 station->m_sampleRate = sampleIdx;
1363
1364 NS_LOG_DEBUG("FindRate "
1365 << "sampleRate=" << sampleIdx);
1366 station->m_sampleTries--;
1367 return sampleIdx;
1368 }
1369 else
1370 {
1371 station->m_numSamplesSlow++;
1372 if (sampleRateInfo.numSamplesSkipped >= 20 && station->m_numSamplesSlow <= 2)
1373 {
1374 /// Set flag that we are currently sampling.
1375 station->m_isSampling = true;
1376
1377 /// set the rate that we're currently sampling
1378 station->m_sampleRate = sampleIdx;
1379
1380 NS_LOG_DEBUG("FindRate "
1381 << "sampleRate=" << sampleIdx);
1382 station->m_sampleTries--;
1383 return sampleIdx;
1384 }
1385 }
1386 }
1387 }
1388 }
1389 if (station->m_sampleWait > 0)
1390 {
1391 station->m_sampleWait--;
1392 }
1393
1394 /// Continue using the best rate.
1395
1396 NS_LOG_DEBUG("FindRate "
1397 << "maxTpRrate=" << station->m_maxTpRate);
1398 return station->m_maxTpRate;
1399}
1400
1401void
1403{
1404 NS_LOG_FUNCTION(this << station);
1405
1407
1408 station->m_numSamplesSlow = 0;
1409 station->m_sampleCount = 0;
1410
1411 double tempProb;
1412
1413 if (station->m_ampduPacketCount > 0)
1414 {
1415 uint32_t newLen = station->m_ampduLen / station->m_ampduPacketCount;
1416 station->m_avgAmpduLen =
1417 (newLen * (100 - m_ewmaLevel) + (station->m_avgAmpduLen * m_ewmaLevel)) / 100;
1418 station->m_ampduLen = 0;
1419 station->m_ampduPacketCount = 0;
1420 }
1421
1422 /* Initialize global rate indexes */
1423 station->m_maxTpRate = GetLowestIndex(station);
1424 station->m_maxTpRate2 = GetLowestIndex(station);
1425 station->m_maxProbRate = GetLowestIndex(station);
1426
1427 /// Update throughput and EWMA for each rate inside each group.
1428 for (uint8_t j = 0; j < m_numGroups; j++)
1429 {
1430 if (station->m_groupsTable[j].m_supported)
1431 {
1432 station->m_sampleCount++;
1433
1434 /* (re)Initialize group rate indexes */
1435 station->m_groupsTable[j].m_maxTpRate = GetLowestIndex(station, j);
1436 station->m_groupsTable[j].m_maxTpRate2 = GetLowestIndex(station, j);
1437 station->m_groupsTable[j].m_maxProbRate = GetLowestIndex(station, j);
1438
1439 for (uint8_t i = 0; i < m_numRates; i++)
1440 {
1441 if (station->m_groupsTable[j].m_ratesTable[i].supported)
1442 {
1443 station->m_groupsTable[j].m_ratesTable[i].retryUpdated = false;
1444
1446 +i << " "
1447 << GetMcsSupported(station,
1448 station->m_groupsTable[j].m_ratesTable[i].mcsIndex)
1449 << "\t attempt="
1450 << station->m_groupsTable[j].m_ratesTable[i].numRateAttempt
1451 << "\t success="
1452 << station->m_groupsTable[j].m_ratesTable[i].numRateSuccess);
1453
1454 /// If we've attempted something.
1455 if (station->m_groupsTable[j].m_ratesTable[i].numRateAttempt > 0)
1456 {
1457 station->m_groupsTable[j].m_ratesTable[i].numSamplesSkipped = 0;
1458 /**
1459 * Calculate the probability of success.
1460 * Assume probability scales from 0 to 100.
1461 */
1462 tempProb =
1463 (100 * station->m_groupsTable[j].m_ratesTable[i].numRateSuccess) /
1464 station->m_groupsTable[j].m_ratesTable[i].numRateAttempt;
1465
1466 /// Bookkeeping.
1467 station->m_groupsTable[j].m_ratesTable[i].prob = tempProb;
1468
1469 if (station->m_groupsTable[j].m_ratesTable[i].successHist == 0)
1470 {
1471 station->m_groupsTable[j].m_ratesTable[i].ewmaProb = tempProb;
1472 }
1473 else
1474 {
1475 station->m_groupsTable[j].m_ratesTable[i].ewmsdProb =
1476 CalculateEwmsd(station->m_groupsTable[j].m_ratesTable[i].ewmsdProb,
1477 tempProb,
1478 station->m_groupsTable[j].m_ratesTable[i].ewmaProb,
1479 m_ewmaLevel);
1480 /// EWMA probability
1481 tempProb =
1482 (tempProb * (100 - m_ewmaLevel) +
1483 station->m_groupsTable[j].m_ratesTable[i].ewmaProb * m_ewmaLevel) /
1484 100;
1485 station->m_groupsTable[j].m_ratesTable[i].ewmaProb = tempProb;
1486 }
1487
1488 station->m_groupsTable[j].m_ratesTable[i].throughput =
1489 CalculateThroughput(station, j, i, tempProb);
1490
1491 station->m_groupsTable[j].m_ratesTable[i].successHist +=
1492 station->m_groupsTable[j].m_ratesTable[i].numRateSuccess;
1493 station->m_groupsTable[j].m_ratesTable[i].attemptHist +=
1494 station->m_groupsTable[j].m_ratesTable[i].numRateAttempt;
1495 }
1496 else
1497 {
1498 station->m_groupsTable[j].m_ratesTable[i].numSamplesSkipped++;
1499 }
1500
1501 /// Bookkeeping.
1502 station->m_groupsTable[j].m_ratesTable[i].prevNumRateSuccess =
1503 station->m_groupsTable[j].m_ratesTable[i].numRateSuccess;
1504 station->m_groupsTable[j].m_ratesTable[i].prevNumRateAttempt =
1505 station->m_groupsTable[j].m_ratesTable[i].numRateAttempt;
1506 station->m_groupsTable[j].m_ratesTable[i].numRateSuccess = 0;
1507 station->m_groupsTable[j].m_ratesTable[i].numRateAttempt = 0;
1508
1509 if (station->m_groupsTable[j].m_ratesTable[i].throughput != 0)
1510 {
1511 SetBestStationThRates(station, GetIndex(j, i));
1512 SetBestProbabilityRate(station, GetIndex(j, i));
1513 }
1514 }
1515 }
1516 }
1517 }
1518
1519 // Try to sample all available rates during each interval.
1520 station->m_sampleCount *= 8;
1521
1522 // Recalculate retries for the rates selected.
1523 CalculateRetransmits(station, station->m_maxTpRate);
1524 CalculateRetransmits(station, station->m_maxTpRate2);
1525 CalculateRetransmits(station, station->m_maxProbRate);
1526
1527 NS_LOG_DEBUG("max tp=" << station->m_maxTpRate << "\nmax tp2=" << station->m_maxTpRate2
1528 << "\nmax prob=" << station->m_maxProbRate);
1529 if (m_printStats)
1530 {
1531 PrintTable(station);
1532 }
1533}
1534
1535double
1537 uint8_t groupId,
1538 uint8_t rateId,
1539 double ewmaProb)
1540{
1541 /**
1542 * Calculating throughput.
1543 * Do not account throughput if probability of success is below 10%
1544 * (as done in minstrel_ht linux implementation).
1545 */
1546 if (ewmaProb < 10)
1547 {
1548 return 0;
1549 }
1550 else
1551 {
1552 /**
1553 * For the throughput calculation, limit the probability value to 90% to
1554 * account for collision related packet error rate fluctuation.
1555 */
1556 Time txTime = station->m_groupsTable[groupId].m_ratesTable[rateId].perfectTxTime;
1557 if (ewmaProb > 90)
1558 {
1559 return 90 / txTime.GetSeconds();
1560 }
1561 else
1562 {
1563 return ewmaProb / txTime.GetSeconds();
1564 }
1565 }
1566}
1567
1568void
1570{
1571 GroupInfo* group;
1572 MinstrelHtRateInfo rate;
1573 uint8_t tmpGroupId;
1574 uint8_t tmpRateId;
1575 double tmpTh;
1576 double tmpProb;
1577 uint8_t groupId;
1578 uint8_t rateId;
1579 double currentTh;
1580 // maximum group probability (GP) variables
1581 uint8_t maxGPGroupId;
1582 uint8_t maxGPRateId;
1583 double maxGPTh;
1584
1585 groupId = GetGroupId(index);
1586 rateId = GetRateId(index);
1587 group = &station->m_groupsTable[groupId];
1588 rate = group->m_ratesTable[rateId];
1589
1590 tmpGroupId = GetGroupId(station->m_maxProbRate);
1591 tmpRateId = GetRateId(station->m_maxProbRate);
1592 tmpProb = station->m_groupsTable[tmpGroupId].m_ratesTable[tmpRateId].ewmaProb;
1593 tmpTh = station->m_groupsTable[tmpGroupId].m_ratesTable[tmpRateId].throughput;
1594
1595 if (rate.ewmaProb > 75)
1596 {
1597 currentTh = station->m_groupsTable[groupId].m_ratesTable[rateId].throughput;
1598 if (currentTh > tmpTh)
1599 {
1600 station->m_maxProbRate = index;
1601 }
1602
1603 maxGPGroupId = GetGroupId(group->m_maxProbRate);
1604 maxGPRateId = GetRateId(group->m_maxProbRate);
1605 maxGPTh = station->m_groupsTable[maxGPGroupId].m_ratesTable[maxGPRateId].throughput;
1606
1607 if (currentTh > maxGPTh)
1608 {
1609 group->m_maxProbRate = index;
1610 }
1611 }
1612 else
1613 {
1614 if (rate.ewmaProb > tmpProb)
1615 {
1616 station->m_maxProbRate = index;
1617 }
1618 maxGPRateId = GetRateId(group->m_maxProbRate);
1619 if (rate.ewmaProb > group->m_ratesTable[maxGPRateId].ewmaProb)
1620 {
1621 group->m_maxProbRate = index;
1622 }
1623 }
1624}
1625
1626/*
1627 * Find & sort topmost throughput rates
1628 *
1629 * If multiple rates provide equal throughput the sorting is based on their
1630 * current success probability. Higher success probability is preferred among
1631 * MCS groups.
1632 */
1633void
1635{
1636 uint8_t groupId;
1637 uint8_t rateId;
1638 double th;
1639 double prob;
1640 uint8_t maxTpGroupId;
1641 uint8_t maxTpRateId;
1642 uint8_t maxTp2GroupId;
1643 uint8_t maxTp2RateId;
1644 double maxTpTh;
1645 double maxTpProb;
1646 double maxTp2Th;
1647 double maxTp2Prob;
1648
1649 groupId = GetGroupId(index);
1650 rateId = GetRateId(index);
1651 prob = station->m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb;
1652 th = station->m_groupsTable[groupId].m_ratesTable[rateId].throughput;
1653
1654 maxTpGroupId = GetGroupId(station->m_maxTpRate);
1655 maxTpRateId = GetRateId(station->m_maxTpRate);
1656 maxTpProb = station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].ewmaProb;
1657 maxTpTh = station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].throughput;
1658
1659 maxTp2GroupId = GetGroupId(station->m_maxTpRate2);
1660 maxTp2RateId = GetRateId(station->m_maxTpRate2);
1661 maxTp2Prob = station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].ewmaProb;
1662 maxTp2Th = station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].throughput;
1663
1664 if (th > maxTpTh || (th == maxTpTh && prob > maxTpProb))
1665 {
1666 station->m_maxTpRate2 = station->m_maxTpRate;
1667 station->m_maxTpRate = index;
1668 }
1669 else if (th > maxTp2Th || (th == maxTp2Th && prob > maxTp2Prob))
1670 {
1671 station->m_maxTpRate2 = index;
1672 }
1673
1674 // Find best rates per group
1675
1676 GroupInfo* group = &station->m_groupsTable[groupId];
1677 maxTpGroupId = GetGroupId(group->m_maxTpRate);
1678 maxTpRateId = GetRateId(group->m_maxTpRate);
1679 maxTpProb = group->m_ratesTable[maxTpRateId].ewmaProb;
1680 maxTpTh = station->m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].throughput;
1681
1682 maxTp2GroupId = GetGroupId(group->m_maxTpRate2);
1683 maxTp2RateId = GetRateId(group->m_maxTpRate2);
1684 maxTp2Prob = group->m_ratesTable[maxTp2RateId].ewmaProb;
1685 maxTp2Th = station->m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].throughput;
1686
1687 if (th > maxTpTh || (th == maxTpTh && prob > maxTpProb))
1688 {
1689 group->m_maxTpRate2 = group->m_maxTpRate;
1690 group->m_maxTpRate = index;
1691 }
1692 else if (th > maxTp2Th || (th == maxTp2Th && prob > maxTp2Prob))
1693 {
1694 group->m_maxTpRate2 = index;
1695 }
1696}
1697
1698void
1700{
1701 NS_LOG_FUNCTION(this << station);
1702
1704
1705 /**
1706 * Initialize groups supported by the receiver.
1707 */
1708 NS_LOG_DEBUG("Supported groups by station:");
1709 bool noSupportedGroupFound = true;
1710 for (uint8_t groupId = 0; groupId < m_numGroups; groupId++)
1711 {
1712 if (m_minstrelGroups[groupId].isSupported)
1713 {
1714 station->m_groupsTable[groupId].m_supported = false;
1715
1716 if ((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_HE) &&
1717 !GetHeSupported(station))
1718 {
1719 // It is a HE group but the receiver does not support HE: skip
1720 continue;
1721 }
1722 if ((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_VHT) &&
1723 !GetVhtSupported(station))
1724 {
1725 // It is a VHT group but the receiver does not support VHT: skip
1726 continue;
1727 }
1728 if ((m_minstrelGroups[groupId].type != WIFI_MINSTREL_GROUP_HE) &&
1730 {
1731 // It is not a HE group and the receiver supports HE: skip since
1732 // UseLatestAmendmentOnly attribute is enabled
1733 continue;
1734 }
1735 if (!GetHeSupported(station) &&
1736 (m_minstrelGroups[groupId].type != WIFI_MINSTREL_GROUP_VHT) &&
1738 {
1739 // It is not a VHT group and the receiver supports VHT (but not HE): skip since
1740 // UseLatestAmendmentOnly attribute is enabled
1741 continue;
1742 }
1743 if (((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_HT) ||
1744 (m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_VHT)) &&
1745 (m_minstrelGroups[groupId].gi.GetNanoSeconds() == 400) &&
1747 {
1748 // It is a SGI group but the receiver does not support SGI: skip
1749 continue;
1750 }
1751 if ((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_HE) &&
1752 (m_minstrelGroups[groupId].gi < GetGuardInterval(station)))
1753 {
1754 // The receiver does not support the GI: skip
1755 continue;
1756 }
1757 if (GetChannelWidth(station) < m_minstrelGroups[groupId].chWidth)
1758 {
1759 // The receiver does not support the channel width: skip
1760 continue;
1761 }
1762 if (GetNumberOfSupportedStreams(station) < m_minstrelGroups[groupId].streams)
1763 {
1764 // The receiver does not support the number of spatial streams: skip
1765 continue;
1766 }
1767
1768 NS_LOG_DEBUG("Group: " << +groupId << " type: " << m_minstrelGroups[groupId].type
1769 << " streams: " << +m_minstrelGroups[groupId].streams
1770 << " GI: " << m_minstrelGroups[groupId].gi
1771 << " width: " << m_minstrelGroups[groupId].chWidth);
1772
1773 noSupportedGroupFound = false;
1774 station->m_groupsTable[groupId].m_supported = true;
1775 station->m_groupsTable[groupId].m_col = 0;
1776 station->m_groupsTable[groupId].m_index = 0;
1777
1778 station->m_groupsTable[groupId].m_ratesTable =
1779 MinstrelHtRate(m_numRates); /// Create the rate list for the group.
1780 for (uint8_t i = 0; i < m_numRates; i++)
1781 {
1782 station->m_groupsTable[groupId].m_ratesTable[i].supported = false;
1783 }
1784
1785 // Initialize all modes supported by the remote station that belong to the current
1786 // group.
1787 for (uint8_t i = 0; i < station->m_nModes; i++)
1788 {
1789 WifiMode mode = GetMcsSupported(station, i);
1790
1791 /// Use the McsValue as the index in the rate table.
1792 /// This way, MCSs not supported are not initialized.
1793 uint8_t rateId = mode.GetMcsValue();
1795 {
1796 rateId %= MAX_HT_GROUP_RATES;
1797 }
1798
1799 if (((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_HE) &&
1800 (mode.GetModulationClass() ==
1801 WIFI_MOD_CLASS_HE) /// If it is a HE MCS only add to a HE group.
1802 && IsValidMcs(GetPhy(),
1803 m_minstrelGroups[groupId].streams,
1804 m_minstrelGroups[groupId].chWidth,
1805 mode)) /// Check validity of the HE MCS
1806 || ((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_VHT) &&
1807 (mode.GetModulationClass() ==
1808 WIFI_MOD_CLASS_VHT) /// If it is a VHT MCS only add to a VHT group.
1809 && IsValidMcs(GetPhy(),
1810 m_minstrelGroups[groupId].streams,
1811 m_minstrelGroups[groupId].chWidth,
1812 mode)) /// Check validity of the VHT MCS
1813 || ((m_minstrelGroups[groupId].type == WIFI_MINSTREL_GROUP_HT) &&
1814 (mode.GetModulationClass() ==
1815 WIFI_MOD_CLASS_HT) /// If it is a HT MCS only add to a HT group.
1816 && (mode.GetMcsValue() <
1817 (m_minstrelGroups[groupId].streams *
1818 8)) /// Check if the HT MCS corresponds to groups number of streams.
1819 && (mode.GetMcsValue() >= ((m_minstrelGroups[groupId].streams - 1) * 8))))
1820 {
1821 NS_LOG_DEBUG("Mode " << +i << ": " << mode);
1822
1823 station->m_groupsTable[groupId].m_ratesTable[rateId].supported = true;
1824 station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex =
1825 i; /// Mapping between rateId and operationalMcsSet
1826 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt = 0;
1827 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess = 0;
1828 station->m_groupsTable[groupId].m_ratesTable[rateId].prob = 0;
1829 station->m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb = 0;
1830 station->m_groupsTable[groupId].m_ratesTable[rateId].prevNumRateAttempt = 0;
1831 station->m_groupsTable[groupId].m_ratesTable[rateId].prevNumRateSuccess = 0;
1832 station->m_groupsTable[groupId].m_ratesTable[rateId].numSamplesSkipped = 0;
1833 station->m_groupsTable[groupId].m_ratesTable[rateId].successHist = 0;
1834 station->m_groupsTable[groupId].m_ratesTable[rateId].attemptHist = 0;
1835 station->m_groupsTable[groupId].m_ratesTable[rateId].throughput = 0;
1836 station->m_groupsTable[groupId].m_ratesTable[rateId].perfectTxTime =
1837 GetFirstMpduTxTime(groupId, GetMcsSupported(station, i));
1838 station->m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 0;
1839 station->m_groupsTable[groupId].m_ratesTable[rateId].adjustedRetryCount = 0;
1840 CalculateRetransmits(station, groupId, rateId);
1841 }
1842 }
1843 }
1844 }
1845 /// make sure at least one group is supported, otherwise we end up with an infinite loop in
1846 /// SetNextSample
1847 if (noSupportedGroupFound)
1848 {
1849 NS_FATAL_ERROR("No supported group has been found");
1850 }
1851 SetNextSample(station); /// Select the initial sample index.
1852 UpdateStats(station); /// Calculate the initial high throughput rates.
1853 station->m_txrate = FindRate(station); /// Select the rate to use.
1854}
1855
1856void
1858{
1859 NS_LOG_FUNCTION(this << station << index);
1860 uint8_t groupId = GetGroupId(index);
1861 uint8_t rateId = GetRateId(index);
1862 if (!station->m_groupsTable[groupId].m_ratesTable[rateId].retryUpdated)
1863 {
1864 CalculateRetransmits(station, groupId, rateId);
1865 }
1866}
1867
1868void
1870 uint8_t groupId,
1871 uint8_t rateId)
1872{
1873 NS_LOG_FUNCTION(this << station << +groupId << +rateId);
1874
1875 uint32_t cw = 15; // Is an approximation.
1876 uint32_t cwMax = 1023;
1877 Time cwTime;
1878 Time txTime;
1879 Time dataTxTime;
1880 Time slotTime = GetPhy()->GetSlot();
1881 Time ackTime = GetPhy()->GetSifs() + GetPhy()->GetBlockAckTxTime();
1882
1883 if (station->m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb < 1)
1884 {
1885 station->m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 1;
1886 }
1887 else
1888 {
1889 station->m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 2;
1890 station->m_groupsTable[groupId].m_ratesTable[rateId].retryUpdated = true;
1891
1892 dataTxTime =
1894 groupId,
1895 GetMcsSupported(station,
1896 station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex)) +
1898 groupId,
1899 GetMcsSupported(station,
1900 station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex)) *
1901 (station->m_avgAmpduLen - 1);
1902
1903 /* Contention time for first 2 tries */
1904 cwTime = (cw / 2) * slotTime;
1905 cw = Min((cw + 1) * 2, cwMax);
1906 cwTime += (cw / 2) * slotTime;
1907 cw = Min((cw + 1) * 2, cwMax);
1908
1909 /* Total TX time for data and Contention after first 2 tries */
1910 txTime = cwTime + 2 * (dataTxTime + ackTime);
1911
1912 /* See how many more tries we can fit inside segment size */
1913 do
1914 {
1915 /* Contention time for this try */
1916 cwTime = (cw / 2) * slotTime;
1917 cw = Min((cw + 1) * 2, cwMax);
1918
1919 /* Total TX time after this try */
1920 txTime += cwTime + ackTime + dataTxTime;
1921 } while ((txTime < MilliSeconds(6)) &&
1922 (++station->m_groupsTable[groupId].m_ratesTable[rateId].retryCount < 7));
1923 }
1924}
1925
1926double
1928 double currentProb,
1929 double ewmaProb,
1930 double weight)
1931{
1932 double diff;
1933 double incr;
1934 double tmp;
1935
1936 /* calculate exponential weighted moving variance */
1937 diff = currentProb - ewmaProb;
1938 incr = (100 - weight) * diff / 100;
1939 tmp = oldEwmsd * oldEwmsd;
1940 tmp = weight * (tmp + diff * incr) / 100;
1941
1942 /* return standard deviation */
1943 return sqrt(tmp);
1944}
1945
1946void
1948{
1949 NS_LOG_FUNCTION(this << station);
1950 station->m_col = station->m_index = 0;
1951
1952 // for off-setting to make rates fall between 0 and nModes
1953 uint8_t numSampleRates = m_numRates;
1954
1955 uint16_t newIndex;
1956 for (uint8_t col = 0; col < m_nSampleCol; col++)
1957 {
1958 for (uint8_t i = 0; i < numSampleRates; i++)
1959 {
1960 /**
1961 * The next two lines basically tries to generate a random number
1962 * between 0 and the number of available rates
1963 */
1964 int uv = m_uniformRandomVariable->GetInteger(0, numSampleRates);
1965 newIndex = (i + uv) % numSampleRates;
1966
1967 // this loop is used for filling in other uninitialized places
1968 while (station->m_sampleTable[newIndex][col] != 0)
1969 {
1970 newIndex = (newIndex + 1) % m_numRates;
1971 }
1972 station->m_sampleTable[newIndex][col] = i;
1973 }
1974 }
1975}
1976
1977void
1979{
1980 if (!station->m_statsFile.is_open())
1981 {
1982 std::ostringstream tmp;
1983 tmp << "minstrel-ht-stats-" << station->m_state->m_address << ".txt";
1984 station->m_statsFile.open(tmp.str(), std::ios::out);
1985 }
1986
1987 station->m_statsFile
1988 << " best ____________rate__________ ________statistics________ "
1989 "________last_______ ______sum-of________\n"
1990 << " mode guard # rate [name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] "
1991 "[prob.|retry|suc|att] [#success | #attempts]\n";
1992 for (uint8_t i = 0; i < m_numGroups; i++)
1993 {
1994 StatsDump(station, i, station->m_statsFile);
1995 }
1996
1997 station->m_statsFile << "\nTotal packet count:: ideal "
1998 << Max(0, station->m_totalPacketsCount - station->m_samplePacketsCount)
1999 << " lookaround " << station->m_samplePacketsCount << "\n";
2000 station->m_statsFile << "Average # of aggregated frames per A-MPDU: " << station->m_avgAmpduLen
2001 << "\n\n";
2002
2003 station->m_statsFile.flush();
2004}
2005
2006void
2008 uint8_t groupId,
2009 std::ofstream& of)
2010{
2011 uint8_t numRates = m_numRates;
2012 McsGroup group = m_minstrelGroups[groupId];
2013 Time txTime;
2014 for (uint8_t i = 0; i < numRates; i++)
2015 {
2016 if (station->m_groupsTable[groupId].m_supported &&
2017 station->m_groupsTable[groupId].m_ratesTable[i].supported)
2018 {
2019 of << group.type << " " << group.chWidth << " " << group.gi << " " << +group.streams
2020 << " ";
2021
2022 uint16_t maxTpRate = station->m_maxTpRate;
2023 uint16_t maxTpRate2 = station->m_maxTpRate2;
2024 uint16_t maxProbRate = station->m_maxProbRate;
2025
2026 uint16_t idx = GetIndex(groupId, i);
2027 if (idx == maxTpRate)
2028 {
2029 of << 'A';
2030 }
2031 else
2032 {
2033 of << ' ';
2034 }
2035 if (idx == maxTpRate2)
2036 {
2037 of << 'B';
2038 }
2039 else
2040 {
2041 of << ' ';
2042 }
2043 if (idx == maxProbRate)
2044 {
2045 of << 'P';
2046 }
2047 else
2048 {
2049 of << ' ';
2050 }
2051
2052 if (group.type == WIFI_MINSTREL_GROUP_HT)
2053 {
2054 of << std::setw(4) << " MCS" << (group.streams - 1) * 8 + i;
2055 }
2056 else
2057 {
2058 of << std::setw(7) << " MCS" << +i << "/" << static_cast<int>(group.streams);
2059 }
2060
2061 of << " " << std::setw(3) << +idx << " ";
2062
2063 /* tx_time[rate(i)] in usec */
2064 txTime = GetFirstMpduTxTime(
2065 groupId,
2066 GetMcsSupported(station, station->m_groupsTable[groupId].m_ratesTable[i].mcsIndex));
2067 of << std::setw(6) << txTime.GetMicroSeconds() << " ";
2068
2069 of << std::setw(7) << CalculateThroughput(station, groupId, i, 100) / 100 << " "
2070 << std::setw(7) << station->m_groupsTable[groupId].m_ratesTable[i].throughput / 100
2071 << " " << std::setw(7) << station->m_groupsTable[groupId].m_ratesTable[i].ewmaProb
2072 << " " << std::setw(7) << station->m_groupsTable[groupId].m_ratesTable[i].ewmsdProb
2073 << " " << std::setw(7) << station->m_groupsTable[groupId].m_ratesTable[i].prob
2074 << " " << std::setw(2) << station->m_groupsTable[groupId].m_ratesTable[i].retryCount
2075 << " " << std::setw(3)
2076 << station->m_groupsTable[groupId].m_ratesTable[i].prevNumRateSuccess << " "
2077 << std::setw(3) << station->m_groupsTable[groupId].m_ratesTable[i].prevNumRateAttempt
2078 << " " << std::setw(9)
2079 << station->m_groupsTable[groupId].m_ratesTable[i].successHist << " "
2080 << std::setw(9) << station->m_groupsTable[groupId].m_ratesTable[i].attemptHist
2081 << "\n";
2082 }
2083 }
2084}
2085
2086uint16_t
2087MinstrelHtWifiManager::GetIndex(uint8_t groupId, uint8_t rateId)
2088{
2089 NS_LOG_FUNCTION(this << +groupId << +rateId);
2090 uint16_t index;
2091 index = groupId * m_numRates + rateId;
2092 return index;
2093}
2094
2095uint8_t
2097{
2098 NS_LOG_FUNCTION(this << index);
2099 uint8_t id;
2100 id = index % m_numRates;
2101 return id;
2102}
2103
2104uint8_t
2106{
2107 NS_LOG_FUNCTION(this << index);
2108 return index / m_numRates;
2109}
2110
2111uint8_t
2112MinstrelHtWifiManager::GetHtGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
2113{
2114 NS_LOG_FUNCTION(this << +txstreams << guardInterval << chWidth);
2115 uint8_t giIndex = (guardInterval.GetNanoSeconds() == 400) ? 1 : 0;
2116 uint8_t widthIndex = (chWidth == 40) ? 1 : 0;
2117 return (MAX_HT_SUPPORTED_STREAMS * 2 * widthIndex) + (MAX_HT_SUPPORTED_STREAMS * giIndex) +
2118 txstreams - 1;
2119}
2120
2121uint8_t
2122MinstrelHtWifiManager::GetVhtGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
2123{
2124 NS_LOG_FUNCTION(this << +txstreams << guardInterval << chWidth);
2125 uint8_t giIndex = (guardInterval.GetNanoSeconds() == 400) ? 1 : 0;
2126 uint8_t widthIndex;
2127 if (chWidth == 160)
2128 {
2129 widthIndex = 3;
2130 }
2131 else if (chWidth == 80)
2132 {
2133 widthIndex = 2;
2134 }
2135 else if (chWidth == 40)
2136 {
2137 widthIndex = 1;
2138 }
2139 else // 20 MHz
2140 {
2141 widthIndex = 0;
2142 }
2143 uint8_t groupId = (MAX_HT_STREAM_GROUPS * MAX_HT_SUPPORTED_STREAMS); /// add all HT groups
2144 groupId += (MAX_VHT_SUPPORTED_STREAMS * 2 * widthIndex) +
2145 (MAX_VHT_SUPPORTED_STREAMS * giIndex) + txstreams - 1;
2146 return groupId;
2147}
2148
2149uint8_t
2150MinstrelHtWifiManager::GetHeGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
2151{
2152 NS_LOG_FUNCTION(this << +txstreams << guardInterval << chWidth);
2153 uint8_t giIndex;
2154 if (const auto gi = guardInterval.GetNanoSeconds(); gi == 800)
2155 {
2156 giIndex = 2;
2157 }
2158 else if (gi == 1600)
2159 {
2160 giIndex = 1;
2161 }
2162 else // 3200 ns
2163 {
2164 giIndex = 0;
2165 }
2166 uint8_t widthIndex;
2167 if (chWidth == 160)
2168 {
2169 widthIndex = 3;
2170 }
2171 else if (chWidth == 80)
2172 {
2173 widthIndex = 2;
2174 }
2175 else if (chWidth == 40)
2176 {
2177 widthIndex = 1;
2178 }
2179 else // 20 MHz
2180 {
2181 widthIndex = 0;
2182 }
2183 uint8_t groupId = 0;
2184 if (GetHtSupported()) // This check is needed since HT is not supported in 6 GHz band
2185 {
2187 }
2188 if (GetVhtSupported()) // This check is needed since VHT is not supported in 2.4 and 6 GHz bands
2189 {
2190 groupId += MAX_VHT_STREAM_GROUPS * MAX_VHT_SUPPORTED_STREAMS; /// add all VHT groups
2191 }
2192 groupId += (MAX_HE_SUPPORTED_STREAMS * 3 * widthIndex) + (MAX_HE_SUPPORTED_STREAMS * giIndex) +
2193 txstreams - 1;
2194 return groupId;
2195}
2196
2197uint16_t
2199{
2200 NS_LOG_FUNCTION(this << station);
2201
2202 uint8_t groupId = 0;
2203 uint8_t rateId = 0;
2204 while (groupId < m_numGroups && !station->m_groupsTable[groupId].m_supported)
2205 {
2206 groupId++;
2207 }
2208 while (rateId < m_numRates && !station->m_groupsTable[groupId].m_ratesTable[rateId].supported)
2209 {
2210 rateId++;
2211 }
2212 NS_ASSERT(station->m_groupsTable[groupId].m_supported &&
2213 station->m_groupsTable[groupId].m_ratesTable[rateId].supported);
2214 return GetIndex(groupId, rateId);
2215}
2216
2217uint16_t
2219{
2220 NS_LOG_FUNCTION(this << station << +groupId);
2221
2222 uint8_t rateId = 0;
2223 while (rateId < m_numRates && !station->m_groupsTable[groupId].m_ratesTable[rateId].supported)
2224 {
2225 rateId++;
2226 }
2227 NS_ASSERT(station->m_groupsTable[groupId].m_supported &&
2228 station->m_groupsTable[groupId].m_ratesTable[rateId].supported);
2229 return GetIndex(groupId, rateId);
2230}
2231
2234{
2235 const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_HE);
2236 WifiModeList heMcsList(mcsList.begin(), mcsList.end());
2237 return heMcsList;
2238}
2239
2242{
2243 const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_VHT);
2244 WifiModeList vhtMcsList(mcsList.begin(), mcsList.end());
2245 return vhtMcsList;
2246}
2247
2250{
2251 const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_HT);
2252 WifiModeList htMcsList(mcsList.begin(), mcsList.end());
2253 return htMcsList;
2254}
2255
2256} // namespace ns3
#define Max(a, b)
#define Min(a, b)
Implementation of Minstrel-HT Rate Control Algorithm.
static TypeId GetTypeId()
Get the type ID.
uint32_t CountRetries(MinstrelHtWifiRemoteStation *station)
Count retries.
uint32_t m_frameLength
Frame length used to calculate modes TxTime in bytes.
void InitSampleTable(MinstrelHtWifiRemoteStation *station)
Initialize Sample Table.
bool m_printStats
If statistics table should be printed.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally) override
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
MinstrelMcsGroups m_minstrelGroups
Global array for groups information.
void AddMpduTxTime(uint8_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
void SetNextSample(MinstrelHtWifiRemoteStation *station)
Set the next sample from Sample Table.
uint8_t m_numRates
Number of rates per group Minstrel should consider.
uint16_t UpdateRateAfterAllowedWidth(uint16_t txRate, MHz_u allowedWidth)
Given the index of the current TX rate, check whether the channel width is not greater than the given...
uint8_t m_nSampleCol
Number of sample columns.
bool IsValidMcs(Ptr< WifiPhy > phy, uint8_t streams, MHz_u chWidth, WifiMode mode)
Check the validity of a combination of number of streams, chWidth and mode.
void RateInit(MinstrelHtWifiRemoteStation *station)
Initialize Minstrel Table.
void SetBestStationThRates(MinstrelHtWifiRemoteStation *station, uint16_t index)
Set index rate as maxTpRate or maxTp2Rate if is better than current values.
void PrintTable(MinstrelHtWifiRemoteStation *station)
Printing Minstrel Table.
void StatsDump(MinstrelHtWifiRemoteStation *station, uint8_t groupId, std::ofstream &of)
Print group statistics.
double CalculateThroughput(MinstrelHtWifiRemoteStation *station, uint8_t groupId, uint8_t rateId, double ewmaProb)
Return the average throughput of the MCS defined by groupId and rateId.
void AddFirstMpduTxTime(uint8_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
double CalculateEwmsd(double oldEwmsd, double currentProb, double ewmaProb, double weight)
Perform EWMSD (Exponentially Weighted Moving Standard Deviation) calculation.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void SetBestProbabilityRate(MinstrelHtWifiRemoteStation *station, uint16_t index)
Set index rate as maxProbRate if it is better than current value.
WifiModeList GetHeDeviceMcsList() const
Returns a list of only the HE MCS supported by the device.
Time m_updateStats
How frequent do we calculate the stats.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint16_t GetLowestIndex(MinstrelHtWifiRemoteStation *station)
Returns the lowest global index of the rates supported by the station.
void DoInitialize() override
Initialize() implementation.
WifiModeList GetVhtDeviceMcsList() const
Returns a list of only the VHT MCS supported by the device.
uint8_t GetVhtGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
Returns the groupId of a VHT MCS with the given number of streams, GI and channel width used.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void CheckInit(MinstrelHtWifiRemoteStation *station)
Check for initializations.
WifiModeList GetHtDeviceMcsList() const
Returns a list of only the HT MCS supported by the device.
void UpdateRetry(MinstrelHtWifiRemoteStation *station)
Update the number of retries and reset accordingly.
Time GetFirstMpduTxTime(uint8_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
Time GetMpduTxTime(uint8_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
uint8_t m_numGroups
Number of groups Minstrel should consider.
void CalculateRetransmits(MinstrelHtWifiRemoteStation *station, uint16_t index)
Calculate the number of retransmissions to set for the index rate.
void SetupPhy(const Ptr< WifiPhy > phy) override
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
uint8_t GetHeGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
Returns the groupId of an HE MCS with the given number of streams, GI and channel width used.
uint8_t m_ewmaLevel
Exponential weighted moving average level (or coefficient).
uint16_t FindRate(MinstrelHtWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
uint8_t m_lookAroundRate
The % to try other rates than our current rate.
void UpdateRate(MinstrelHtWifiRemoteStation *station)
Update rate.
uint8_t GetRateId(uint16_t index)
Return the rateId inside a group, from the global index.
Time m_legacyUpdateStats
How frequent do we calculate the stats for legacy MinstrelWifiManager.
uint8_t GetGroupId(uint16_t index)
Return the groupId from the global index.
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
Time CalculateMpduTxDuration(Ptr< WifiPhy > phy, uint8_t streams, Time gi, MHz_u chWidth, WifiMode mode, MpduType mpduType)
Estimates the TxTime of a frame with a given mode and group (stream, guard interval and channel width...
uint8_t GetHtGroupId(uint8_t txstreams, Time guardInterval, MHz_u chWidth)
Returns the groupId of an HT MCS with the given number of streams, GI and channel width used.
uint16_t GetNextSample(MinstrelHtWifiRemoteStation *station)
Getting the next sample from Sample Table.
void UpdateStats(MinstrelHtWifiRemoteStation *station)
Update the Minstrel Table.
uint16_t GetIndex(uint8_t groupId, uint8_t rateId)
Returns the global index corresponding to the groupId and rateId.
WifiRemoteStation * DoCreateStation() const override
Ptr< MinstrelWifiManager > m_legacyManager
Pointer to an instance of MinstrelWifiManager.
void SetupMac(const Ptr< WifiMac > mac) override
Set up MAC associated with this device since it is the object that knows the full set of timing param...
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void UpdatePacketCounters(MinstrelHtWifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus)
Update the number of sample count variables.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
bool m_useLatestAmendmentOnly
Flag if only the latest supported amendment by both peers should be used.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportAmpduTxStatus(WifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus, double rxSnr, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:407
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:402
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
represent a single transmission mode
Definition wifi-mode.h:40
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:111
uint64_t GetNonHtReferenceRate() const
Definition wifi-mode.cc:181
uint8_t GetMcsValue() const
Definition wifi-mode.cc:152
Time GetBlockAckTxTime() const
Return the estimated BlockAck TX time for this PHY.
Definition wifi-phy.cc:859
static Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype=NORMAL_MPDU, uint16_t staId=SU_STA_ID)
Definition wifi-phy.cc:1525
Time GetSlot() const
Return the slot duration for this PHY.
Definition wifi-phy.cc:835
Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
Definition wifi-phy.cc:823
MHz_u GetTxBandwidth(WifiMode mode, MHz_u maxAllowedBandWidth=std::numeric_limits< MHz_u >::max()) const
Get the bandwidth for a transmission occurring on the current operating channel and using the given W...
Definition wifi-phy.cc:1117
Ptr< WifiNetDevice > GetDevice() const
Return the device this PHY is associated with.
Definition wifi-phy.cc:641
std::list< WifiMode > GetMcsList() const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
Definition wifi-phy.cc:2098
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition wifi-phy.cc:1565
hold a list of per-remote-station state.
uint8_t GetNumberOfSupportedStreams(Mac48Address address) const
Return the number of spatial streams supported by the station.
uint8_t GetNess(const WifiRemoteStation *station) const
uint8_t GetNBasicModes() const
Return the number of basic modes we support.
Time GetGuardInterval() const
Return the supported HE guard interval duration.
Ptr< WifiPhy > GetPhy() const
Return the WifiPhy.
MHz_u GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
Ptr< const He6GhzBandCapabilities > GetStationHe6GhzCapabilities(const Mac48Address &from) const
Return the HE 6 GHz Band Capabilities sent by a remote station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled on the link this manager is associated wi...
uint8_t GetNMcsSupported(Mac48Address address) const
Return the number of MCS supported by the station.
WifiMode GetBasicMode(uint8_t i) const
Return a basic mode from the set of basic modes.
bool GetShortGuardIntervalSupported() const
Return whether the device has SGI support enabled.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
WifiMode GetMcsSupported(const WifiRemoteStation *station, uint8_t i) const
Return the WifiMode supported by the specified station at the specified index.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled on the link this manager is associated w...
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetStbc(bool stbc)
Sets if STBC is being used.
void SetNess(uint8_t ness)
Sets the Ness number.
void SetGuardInterval(Time guardInterval)
Sets the guard interval duration (in nanoseconds)
bool IsValid(WifiPhyBand band=WIFI_PHY_BAND_UNSPECIFIED) const
The standard disallows certain combinations of WifiMode, number of spatial streams,...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
void SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetNss(uint8_t nss)
Sets the number of Nss.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#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_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
MpduType
The type of an MPDU.
Definition wifi-types.h:41
@ WIFI_PREAMBLE_HT_MF
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ FIRST_MPDU_IN_AGGREGATE
The MPDU is the first aggregate in an A-MPDU with multiple MPDUs, but is not the last aggregate.
Definition wifi-types.h:48
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
Definition wifi-types.h:51
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
static const MHz_u MAX_HT_WIDTH
Maximal channel width.
static const uint8_t MAX_HT_GROUP_RATES
Number of rates (or MCS) per HT group.
static const uint8_t MAX_VHT_STREAM_GROUPS
Maximal number of groups per stream in VHT (4 possible channel widths and 2 possible GI configuration...
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
std::vector< McsGroup > MinstrelMcsGroups
Data structure for a table of group definitions.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
static const uint8_t MAX_VHT_GROUP_RATES
Number of rates (or MCS) per VHT group.
static const uint8_t MAX_VHT_SUPPORTED_STREAMS
Maximal number of streams supported by the VHT PHY layer.
static const uint8_t MAX_HT_SUPPORTED_STREAMS
Constants for maximum values.
static const uint8_t MAX_HE_GROUP_RATES
Number of rates (or MCS) per HE group.
static const MHz_u MAX_VHT_WIDTH
Maximal channel width.
static const uint8_t MAX_HT_STREAM_GROUPS
Maximal number of groups per stream in HT (2 possible channel widths and 2 possible GI configurations...
static const uint8_t MAX_HE_STREAM_GROUPS
Maximal number of groups per stream in HE (4 possible channel widths and 3 possible GI configurations...
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
std::vector< MinstrelHtRateInfo > MinstrelHtRate
Data structure for a Minstrel Rate table.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes.
Definition wifi-mode.h:251
std::vector< std::vector< uint8_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint8_t.
std::vector< GroupInfo > McsGroupData
Data structure for a table of groups.
static const uint8_t MAX_HE_SUPPORTED_STREAMS
Maximal number of streams supported by the HE PHY layer.
static const MHz_u MAX_HE_WIDTH
Maximal channel width.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
A struct to contain information of a group.
MinstrelHtRate m_ratesTable
Information about rates of this group.
uint16_t m_maxTpRate2
The second max throughput rate of this group in bps.
uint16_t m_maxProbRate
The highest success probability rate of this group in bps.
uint16_t m_maxTpRate
The max throughput rate of this group in bps.
Data structure to contain the information that defines a group.
MHz_u chWidth
channel width
Time gi
guard interval duration
McsGroupType type
identifies the group,
bool isSupported
flag whether group is supported
uint8_t streams
number of spatial streams
A struct to contain all statistics information related to a data rate.
Time perfectTxTime
Perfect transmission time calculation, or frame calculation.
double ewmaProb
Exponential weighted moving average of probability.
uint32_t numSamplesSkipped
Number of times this rate statistics were not updated because no attempts have been made.
MinstrelHtWifiRemoteStation structure.
McsGroupData m_groupsTable
Table of groups with stats.
uint32_t m_sampleCount
Max number of samples per update interval.
uint8_t m_sampleGroup
The group that the sample rate belongs to.
uint32_t m_ampduPacketCount
Number of A-MPDUs transmitted.
uint32_t m_numSamplesSlow
Number of times a slow rate was sampled.
uint32_t m_sampleTries
Number of sample tries after waiting sampleWait.
std::ofstream m_statsFile
File where statistics table is written.
uint32_t m_sampleWait
How many transmission attempts to wait until a new sample.
bool m_isHt
If the station is HT capable.
uint32_t m_avgAmpduLen
Average number of MPDUs in an A-MPDU.
uint32_t m_ampduLen
Number of MPDUs in an A-MPDU.
hold per-remote-station state for Minstrel Wifi manager.
uint16_t m_maxTpRate2
second highest throughput rate in bps
Time m_nextStatsUpdate
10 times every second
bool m_initialized
for initializing tables
uint16_t m_sampleRate
current sample rate in bps
uint16_t m_txrate
current transmit rate in bps
int m_totalPacketsCount
total number of packets as of now
bool m_isSampling
a flag to indicate we are currently sampling
MinstrelRate m_minstrelTable
minstrel table
uint32_t m_shortRetry
short retries such as control packets
uint16_t m_maxTpRate
the current throughput rate in bps
uint8_t m_nModes
number of modes supported
int m_samplePacketsCount
how many packets we have sample so far
uint8_t m_col
To keep track of the current position in the our random sample table going row by row from 1st column...
uint32_t m_longRetry
long retries such as data packets
uint16_t m_maxProbRate
rate with highest probability of success in bps
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.
void CalculateThroughput()
Calculate the throughput.
Definition wifi-tcp.cc:51