27#include "ns3/ht-configuration.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#include "ns3/wifi-psdu.h"
40#define Min(a, b) ((a < b) ? a : b)
41#define Max(a, b) ((a > b) ? a : b)
57 .maxWidth =
MHz_u{40},
67 .maxWidth =
MHz_u{160},
77 .maxWidth =
MHz_u{160},
110 TypeId(
"ns3::MinstrelHtWifiManager")
112 .AddConstructor<MinstrelHtWifiManager>()
113 .SetGroupName(
"Wifi")
114 .AddAttribute(
"UpdateStatistics",
115 "The interval between updating statistics table",
119 .AddAttribute(
"LegacyUpdateStatistics",
120 "The interval between updating statistics table (for legacy Minstrel)",
124 .AddAttribute(
"LookAroundRate",
125 "The percentage to try other rates (for legacy Minstrel)",
129 .AddAttribute(
"EWMA",
134 .AddAttribute(
"SampleColumn",
135 "The number of columns used for sampling",
139 .AddAttribute(
"PacketLength",
140 "The packet length used for calculating mode TxTime (bytes)",
144 .AddAttribute(
"UseLatestAmendmentOnly",
145 "Use only the latest amendment when it is supported by both peers",
149 .AddAttribute(
"PrintStats",
150 "Control the printing of the statistics table",
154 .AddTraceSource(
"Rate",
155 "Traced value for rate changes (b/s)",
157 "ns3::TracedValueCallback::Uint64");
189 int64_t numStreamsAssigned = 0;
191 numStreamsAssigned++;
193 return numStreamsAssigned;
217 for (
MHz_u chWidth{20}; chWidth <= standardInfos.maxWidth; chWidth *= 2)
219 for (
const auto& guardInterval : standardInfos.guardIntervals)
221 for (uint8_t streams = 1; streams <= standardInfos.maxStreams; ++streams)
238 (guardInterval.GetNanoSeconds() ==
242 && (
GetPhy()->GetMaxSupportedTxSpatialStreams() >=
249 for (uint8_t i = 0; i <= standardInfos.maxMcs; ++i)
253 (standardInfos.maxMcs + 1))
255 WifiMode mode = mcsList.at(mcsIndex);
275 NS_LOG_DEBUG(
"Initialized group " << groupId <<
": (" << +streams <<
","
276 << guardInterval <<
"," << chWidth <<
")");
387 txvector.SetGuardInterval(gi);
388 txvector.SetChannelWidth(chWidth);
389 txvector.SetMode(mode);
399 const auto it =
m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.find(mode);
408 m_minstrelGroups[groupId].ratesFirstMpduTxTimeTable.insert(std::make_pair(mode, t));
436 station->m_index = 0;
437 station->m_maxTpRate = 0;
438 station->m_maxTpRate2 = 0;
439 station->m_maxProbRate = 0;
440 station->m_nModes = 0;
441 station->m_totalPacketsCount = 0;
442 station->m_samplePacketsCount = 0;
443 station->m_isSampling =
false;
444 station->m_sampleRate = 0;
445 station->m_sampleDeferred =
false;
446 station->m_shortRetry = 0;
447 station->m_longRetry = 0;
448 station->m_txrate = 0;
449 station->m_initialized =
false;
452 station->m_sampleGroup = 0;
453 station->m_numSamplesSlow = 0;
454 station->m_sampleCount = 16;
455 station->m_sampleWait = 0;
456 station->m_sampleTries = 4;
458 station->m_avgAmpduLen = 1;
459 station->m_ampduLen = 0;
460 station->m_ampduPacketCount = 0;
464 station->m_isHt =
static_cast<bool>(
GetPhy()->
GetDevice()->GetHtConfiguration());
525 if (!station->m_initialized)
529 NS_LOG_DEBUG(
"DoReportRtsFailed m_txrate = " << station->m_txrate);
530 station->m_shortRetry++;
549 if (!station->m_initialized)
563 if (!station->m_initialized)
568 NS_LOG_DEBUG(
"DoReportDataFailed " << station <<
"\t rate " << station->m_txrate
569 <<
"\tlongRetry \t" << station->m_longRetry);
571 if (!station->m_isHt)
577 const auto rateId =
GetRateId(station->m_txrate);
578 const auto groupId =
GetGroupId(station->m_txrate);
579 station->m_groupsTable[groupId]
580 .m_ratesTable[rateId]
591 MHz_u dataChannelWidth,
594 NS_LOG_FUNCTION(
this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << dataNss);
598 if (!station->m_initialized)
603 if (!station->m_isHt)
607 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
608 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
609 <<
" (before update).");
611 station->m_minstrelTable[station->m_txrate].numRateSuccess++;
612 station->m_minstrelTable[station->m_txrate].numRateAttempt++;
618 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
619 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
620 <<
" (after update).");
625 if (station->m_nModes >= 1)
632 const auto rateId =
GetRateId(station->m_txrate);
633 const auto groupId =
GetGroupId(station->m_txrate);
636 "DoReportDataOk m_txrate = "
638 <<
", attempt = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt
639 <<
", success = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess
640 <<
" (before update).");
642 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess++;
643 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt++;
648 "DoReportDataOk m_txrate = "
650 <<
", attempt = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt
651 <<
", success = " << station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess
652 <<
" (after update).");
654 station->m_isSampling =
false;
655 station->m_sampleDeferred =
false;
663 if (station->m_nModes >= 1)
665 station->m_txrate =
FindRate(station);
669 NS_LOG_DEBUG(
"Next rate to use TxRate = " << station->m_txrate);
679 if (!station->m_initialized)
684 NS_LOG_DEBUG(
"DoReportFinalDataFailed - TxRate=" << station->m_txrate);
686 if (!station->m_isHt)
693 if (station->m_nModes >= 1)
702 station->m_isSampling =
false;
703 station->m_sampleDeferred =
false;
711 if (station->m_nModes >= 1)
713 station->m_txrate =
FindRate(station);
716 NS_LOG_DEBUG(
"Next rate to use TxRate = " << station->m_txrate);
721 uint16_t nSuccessfulMpdus,
722 uint16_t nFailedMpdus,
725 MHz_u dataChannelWidth,
728 NS_LOG_FUNCTION(
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr
729 << dataChannelWidth << dataNss);
733 if (!station->m_initialized)
738 NS_ASSERT_MSG(station->m_isHt,
"A-MPDU Tx Status called but this is a non-HT STA.");
740 NS_LOG_DEBUG(
"DoReportAmpduTxStatus. TxRate=" << station->m_txrate
741 <<
" SuccMpdus=" << nSuccessfulMpdus
742 <<
" FailedMpdus=" << nFailedMpdus);
744 station->m_ampduPacketCount++;
745 station->m_ampduLen += nSuccessfulMpdus + nFailedMpdus;
749 const auto rateId =
GetRateId(station->m_txrate);
750 const auto groupId =
GetGroupId(station->m_txrate);
751 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess += nSuccessfulMpdus;
752 station->m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt +=
753 nSuccessfulMpdus + nFailedMpdus;
755 if (nSuccessfulMpdus == 0 && station->m_longRetry <
CountRetries(station))
762 station->m_isSampling =
false;
763 station->m_sampleDeferred =
false;
771 if (station->m_nModes >= 1)
773 station->m_txrate =
FindRate(station);
775 NS_LOG_DEBUG(
"Next rate to use TxRate = " << station->m_txrate);
827 station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount)
835 (station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
836 station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount))
844 (station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
845 station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount +
846 station->
m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount))
853 NS_FATAL_ERROR(
"Max retries reached and m_longRetry not cleared properly. longRetry= "
864 1 + station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount)
872 1 + station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount +
873 station->
m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount)
880 NS_FATAL_ERROR(
"Max retries reached and m_longRetry not cleared properly. longRetry= "
897 uint16_t nSuccessfulMpdus,
898 uint16_t nFailedMpdus)
929 if (group.
chWidth <= allowedWidth)
931 NS_LOG_DEBUG(
"Channel width is not greater than allowed width, nothing to do");
940 auto width = group.
chWidth / 2;
942 while (width >=
MHz_u{20})
944 if (width > allowedWidth)
969 if (!station->m_initialized)
974 if (!station->m_isHt)
987 NS_LOG_DEBUG(
"DoGetDataMode m_txrate= " << station->m_txrate);
989 const auto rateId =
GetRateId(station->m_txrate);
990 const auto groupId =
GetGroupId(station->m_txrate);
991 const auto mcsIndex = station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex;
993 NS_LOG_DEBUG(
"DoGetDataMode rateId= " << rateId <<
" groupId= " << groupId
1039 if (!station->m_initialized)
1044 if (!station->m_isHt)
1050 NS_LOG_DEBUG(
"DoGetRtsMode m_txrate=" << station->m_txrate);
1066 const auto rateId =
GetRateId(station->m_txrate);
1067 const auto groupId =
GetGroupId(station->m_txrate);
1068 const auto mcsIndex = station->m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex;
1071 const auto lastDataRate = lastRate.GetNonHtReferenceRate();
1075 bool rateFound =
false;
1077 for (uint8_t i = 0; i < nBasicRates; i++)
1080 if (rate <= lastDataRate)
1091 const auto rate = mode.GetDataRate(
MHz_u{20});
1092 if (rate <= lastDataRate)
1115std::list<Ptr<WifiMpdu>>
1120 std::list<Ptr<WifiMpdu>> mpdusToDrop;
1126 (mpdu->GetRetryCount() <
GetMac()->GetFrameRetryLimit())))
1129 mpdusToDrop.push_back(mpdu);
1146 if (!station->m_initialized)
1153 if (!station->m_isHt)
1162 if (station->m_longRetry >= maxRetries)
1164 NS_LOG_DEBUG(
"No re-transmission allowed. Retries: " << station->m_longRetry
1165 <<
" Max retries: " << maxRetries);
1170 NS_LOG_DEBUG(
"Re-transmit. Retries: " << station->m_longRetry
1171 <<
" Max retries: " << maxRetries);
1188 return station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].retryCount +
1189 station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].retryCount +
1190 station->
m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount;
1194 return 1 + station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTp2RateId].retryCount +
1195 station->
m_groupsTable[maxProbGroupId].m_ratesTable[maxProbRateId].retryCount;
1204 const auto index = station->
m_groupsTable[sampleGroup].m_index;
1206 const auto sampleIndex = station->
m_sampleTable[index][col];
1207 const auto rateIndex =
GetIndex(sampleGroup, sampleIndex);
1265 const auto sampleGroupId =
GetGroupId(sampleIdx);
1266 const auto sampleRateId =
GetRateId(sampleIdx);
1270 station->
m_groupsTable[sampleGroupId].m_ratesTable[sampleRateId].supported)
1279 const auto sampleRateInfo =
1280 station->
m_groupsTable[sampleGroupId].m_ratesTable[sampleRateId];
1284 <<
" SampleRate= " << sampleIdx
1285 <<
" SampleProb= " << sampleRateInfo.ewmaProb);
1288 sampleIdx != station->
m_maxProbRate && sampleRateInfo.ewmaProb <= 95)
1304 const auto sampleDuration = sampleRateInfo.perfectTxTime;
1305 const auto maxTp2Duration =
1306 station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].perfectTxTime;
1307 const auto maxProbDuration = station->
m_groupsTable[maxProbGroupId]
1308 .m_ratesTable[maxProbRateId]
1312 << sampleDuration <<
" maxTp2Duration= " << maxTp2Duration
1313 <<
" maxProbDuration= " << maxProbDuration <<
" sampleStreams= "
1314 << +sampleStreams <<
" maxTpStreams= " << +maxTpStreams);
1315 if (sampleDuration < maxTp2Duration ||
1316 (sampleStreams < maxTpStreams && sampleDuration < maxProbDuration))
1331 if (sampleRateInfo.numSamplesSkipped >= 20 && station->
m_numSamplesSlow <= 2)
1400 station->
m_groupsTable[j].m_ratesTable[i].retryUpdated =
false;
1409 << station->
m_groupsTable[j].m_ratesTable[i].numRateSuccess);
1412 if (station->
m_groupsTable[j].m_ratesTable[i].numRateAttempt > 0)
1414 station->
m_groupsTable[j].m_ratesTable[i].numSamplesSkipped = 0;
1420 (100 * station->
m_groupsTable[j].m_ratesTable[i].numRateSuccess) /
1426 if (station->
m_groupsTable[j].m_ratesTable[i].successHist == 0)
1428 station->
m_groupsTable[j].m_ratesTable[i].ewmaProb = tempProb;
1442 station->
m_groupsTable[j].m_ratesTable[i].ewmaProb = tempProb;
1455 station->
m_groupsTable[j].m_ratesTable[i].numSamplesSkipped++;
1459 station->
m_groupsTable[j].m_ratesTable[i].prevNumRateSuccess =
1461 station->
m_groupsTable[j].m_ratesTable[i].prevNumRateAttempt =
1463 station->
m_groupsTable[j].m_ratesTable[i].numRateSuccess = 0;
1464 station->
m_groupsTable[j].m_ratesTable[i].numRateAttempt = 0;
1466 if (station->
m_groupsTable[j].m_ratesTable[i].throughput != 0)
1494 std::size_t groupId,
1513 const auto txTime = station->
m_groupsTable[groupId].m_ratesTable[rateId].perfectTxTime;
1516 return 90 / txTime.GetSeconds();
1520 return ewmaProb / txTime.GetSeconds();
1530 std::size_t tmpGroupId;
1534 std::size_t groupId;
1538 std::size_t maxGPGroupId;
1539 uint8_t maxGPRateId;
1549 tmpProb = station->
m_groupsTable[tmpGroupId].m_ratesTable[tmpRateId].ewmaProb;
1550 tmpTh = station->
m_groupsTable[tmpGroupId].m_ratesTable[tmpRateId].throughput;
1554 currentTh = station->
m_groupsTable[groupId].m_ratesTable[rateId].throughput;
1555 if (currentTh > tmpTh)
1562 maxGPTh = station->
m_groupsTable[maxGPGroupId].m_ratesTable[maxGPRateId].throughput;
1564 if (currentTh > maxGPTh)
1593 std::size_t groupId;
1597 std::size_t maxTpGroupId;
1598 uint8_t maxTpRateId;
1599 std::size_t maxTp2GroupId;
1600 uint8_t maxTp2RateId;
1608 prob = station->
m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb;
1609 th = station->
m_groupsTable[groupId].m_ratesTable[rateId].throughput;
1613 maxTpProb = station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].ewmaProb;
1614 maxTpTh = station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].throughput;
1618 maxTp2Prob = station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].ewmaProb;
1619 maxTp2Th = station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].throughput;
1621 if (th > maxTpTh || (th == maxTpTh && prob > maxTpProb))
1626 else if (th > maxTp2Th || (th == maxTp2Th && prob > maxTp2Prob))
1637 maxTpTh = station->
m_groupsTable[maxTpGroupId].m_ratesTable[maxTpRateId].throughput;
1641 maxTp2Prob = group->
m_ratesTable[maxTp2RateId].ewmaProb;
1642 maxTp2Th = station->
m_groupsTable[maxTp2GroupId].m_ratesTable[maxTp2RateId].throughput;
1644 if (th > maxTpTh || (th == maxTpTh && prob > maxTpProb))
1649 else if (th > maxTp2Th || (th == maxTp2Th && prob > maxTp2Prob))
1666 bool noSupportedGroupFound =
true;
1667 for (std::size_t groupId = 0; groupId <
m_numGroups; groupId++)
1729 noSupportedGroupFound =
false;
1738 station->
m_groupsTable[groupId].m_ratesTable[i].supported =
false;
1743 for (uint8_t i = 0; i < station->
m_nModes; i++)
1752 auto rateId = mode.GetMcsValue();
1758 station->
m_groupsTable[groupId].m_ratesTable[rateId].supported =
true;
1759 station->
m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex =
1761 station->
m_groupsTable[groupId].m_ratesTable[rateId].numRateAttempt = 0;
1762 station->
m_groupsTable[groupId].m_ratesTable[rateId].numRateSuccess = 0;
1763 station->
m_groupsTable[groupId].m_ratesTable[rateId].prob = 0;
1764 station->
m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb = 0;
1765 station->
m_groupsTable[groupId].m_ratesTable[rateId].prevNumRateAttempt = 0;
1766 station->
m_groupsTable[groupId].m_ratesTable[rateId].prevNumRateSuccess = 0;
1767 station->
m_groupsTable[groupId].m_ratesTable[rateId].numSamplesSkipped = 0;
1768 station->
m_groupsTable[groupId].m_ratesTable[rateId].successHist = 0;
1769 station->
m_groupsTable[groupId].m_ratesTable[rateId].attemptHist = 0;
1770 station->
m_groupsTable[groupId].m_ratesTable[rateId].throughput = 0;
1771 station->
m_groupsTable[groupId].m_ratesTable[rateId].perfectTxTime =
1773 station->
m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 0;
1774 station->
m_groupsTable[groupId].m_ratesTable[rateId].adjustedRetryCount = 0;
1782 if (noSupportedGroupFound)
1797 if (!station->
m_groupsTable[groupId].m_ratesTable[rateId].retryUpdated)
1805 std::size_t groupId,
1818 if (station->
m_groupsTable[groupId].m_ratesTable[rateId].ewmaProb < 1)
1820 station->
m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 1;
1824 station->
m_groupsTable[groupId].m_ratesTable[rateId].retryCount = 2;
1825 station->
m_groupsTable[groupId].m_ratesTable[rateId].retryUpdated =
true;
1831 station->
m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex)) +
1835 station->
m_groupsTable[groupId].m_ratesTable[rateId].mcsIndex)) *
1839 cwTime = (cw / 2) * slotTime;
1840 cw =
Min((cw + 1) * 2, cwMax);
1841 cwTime += (cw / 2) * slotTime;
1842 cw =
Min((cw + 1) * 2, cwMax);
1845 txTime = cwTime + 2 * (dataTxTime + ackTime);
1851 cwTime = (cw / 2) * slotTime;
1852 cw =
Min((cw + 1) * 2, cwMax);
1855 txTime += cwTime + ackTime + dataTxTime;
1857 (++station->
m_groupsTable[groupId].m_ratesTable[rateId].retryCount < 7));
1872 diff = currentProb - ewmaProb;
1873 incr = (100 - weight) * diff / 100;
1874 tmp = oldEwmsd * oldEwmsd;
1875 tmp = weight * (tmp + diff * incr) / 100;
1893 for (uint8_t i = 0; i < numSampleRates; i++)
1900 newIndex = (i + uv) % numSampleRates;
1917 std::ostringstream tmp;
1919 station->
m_statsFile.open(tmp.str(), std::ios::out);
1923 <<
" best ____________rate__________ ________statistics________ "
1924 "________last_______ ______sum-of________\n"
1925 <<
" mode guard # rate [name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] "
1926 "[prob.|retry|suc|att] [#success | #attempts]\n";
1932 station->
m_statsFile <<
"\nTotal packet count:: ideal "
1943 std::size_t groupId,
1949 for (uint8_t i = 0; i < numRates; i++)
1961 const auto idx =
GetIndex(groupId, i);
1962 if (idx == maxTpRate)
1970 if (idx == maxTpRate2)
1978 if (idx == maxProbRate)
1989 of << std::setw(4) <<
" MCS"
1996 of << std::setw(7) <<
" MCS" << +i <<
"/" <<
static_cast<int>(group.
streams);
1999 of <<
" " << std::setw(3) << idx <<
" ";
2008 << std::setw(7) << station->
m_groupsTable[groupId].m_ratesTable[i].throughput / 100
2009 <<
" " << std::setw(7) << station->
m_groupsTable[groupId].m_ratesTable[i].ewmaProb
2010 <<
" " << std::setw(7) << station->
m_groupsTable[groupId].m_ratesTable[i].ewmsdProb
2011 <<
" " << std::setw(7) << station->
m_groupsTable[groupId].m_ratesTable[i].prob
2012 <<
" " << std::setw(2) << station->
m_groupsTable[groupId].m_ratesTable[i].retryCount
2013 <<
" " << std::setw(3)
2014 << station->
m_groupsTable[groupId].m_ratesTable[i].prevNumRateSuccess <<
" "
2015 << std::setw(3) << station->
m_groupsTable[groupId].m_ratesTable[i].prevNumRateAttempt
2016 <<
" " << std::setw(9)
2017 << station->
m_groupsTable[groupId].m_ratesTable[i].successHist <<
" "
2018 << std::setw(9) << station->
m_groupsTable[groupId].m_ratesTable[i].attemptHist
2053 const auto it = std::find(standardInfos.guardIntervals.cbegin(),
2054 standardInfos.guardIntervals.cend(),
2056 const auto giIndex = std::distance(standardInfos.guardIntervals.cbegin(), it);
2057 const auto widthIndex = std::log2(chWidth /
MHz_u{20});
2058 return (standardInfos.maxStreams * standardInfos.guardIntervals.size() * widthIndex) +
2059 (standardInfos.maxStreams * giIndex) + streams - 1;
2066 const auto numWidths = std::log2(standardInfos.maxWidth /
MHz_u{20}) + 1;
2067 return numWidths * standardInfos.guardIntervals.size() * standardInfos.maxStreams;
2083 return allHtGroups + vhtGroupId;
2095 return allHtGroups + allVhtGroups + heGroupId;
2123 std::size_t groupId = 0;
2125 while (groupId < m_numGroups && !station->m_groupsTable[groupId].m_supported)
2129 while (rateId < m_numRates && !station->m_groupsTable[groupId].m_ratesTable[rateId].supported)
2134 station->
m_groupsTable[groupId].m_ratesTable[rateId].supported);
2144 while (rateId < m_numRates && !station->m_groupsTable[groupId].m_ratesTable[rateId].supported)
2149 station->
m_groupsTable[groupId].m_ratesTable[rateId].supported);
2157 WifiModeList mcsList(phyMcsList.cbegin(), phyMcsList.cend());
AttributeValue implementation for Boolean.
Implementation of Minstrel-HT Rate Control Algorithm.
static TypeId GetTypeId()
Get the type ID.
uint32_t CountRetries(MinstrelHtWifiRemoteStation *station)
Count retries.
void StatsDump(MinstrelHtWifiRemoteStation *station, std::size_t groupId, std::ofstream &of)
Print group statistics.
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.
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
Time GetFirstMpduTxTime(std::size_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
MinstrelMcsGroups m_minstrelGroups
Global array for groups information.
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.
std::list< Ptr< WifiMpdu > > DoGetMpdusToDropOnTxFailure(WifiRemoteStation *station, Ptr< WifiPsdu > psdu) override
Find the MPDUs to drop (possibly based on their frame retry count) in the given PSDU,...
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.
~MinstrelHtWifiManager() override
void AddMpduTxTime(std::size_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
void PrintTable(MinstrelHtWifiRemoteStation *station)
Printing Minstrel Table.
std::size_t GetHeGroupId(uint8_t streams, Time guardInterval, MHz_u chWidth)
Returns the groupId of an HE MCS with the given number of streams, GI and channel width used.
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.
void AddFirstMpduTxTime(std::size_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
double CalculateThroughput(MinstrelHtWifiRemoteStation *station, std::size_t groupId, uint8_t rateId, double ewmaProb)
Return the average throughput of the MCS defined by groupId and rateId.
Time m_updateStats
How frequent do we calculate the stats.
Time GetMpduTxTime(std::size_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
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.
bool ShouldAddMcsToGroup(WifiMode mode, std::size_t groupId)
Check whether a given MCS mode should be added to a given group.
std::size_t GetGroupId(uint16_t index)
Return the groupId from the global index.
std::size_t GetIdInGroup(WifiModulationClass mc, uint8_t streams, Time guardInterval, MHz_u chWidth)
Returns the Id of a MCS of a given modulation class with the given number of streams,...
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void CheckInit(MinstrelHtWifiRemoteStation *station)
Check for initializations.
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
std::size_t GetNumGroups(WifiModulationClass mc)
Returns the number of groups for a given modulation class.
void UpdateRetry(MinstrelHtWifiRemoteStation *station)
Update the number of retries and reset accordingly.
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...
std::size_t GetVhtGroupId(uint8_t streams, Time guardInterval, MHz_u chWidth)
Returns the groupId of a VHT MCS with the given number of streams, GI and channel width used.
bool IsValidMcs(uint8_t streams, MHz_u chWidth, WifiMode mode)
Check the validity of a combination of number of streams, chWidth and mode.
void InitializeGroups(WifiModulationClass mc)
Initialize all groups belonging to a given modulation class.
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.
std::size_t GetHtGroupId(uint8_t streams, Time guardInterval, MHz_u chWidth)
Returns the groupId of an HT MCS with the given number of streams, GI and channel width used.
std::size_t m_numGroups
Number of groups Minstrel should consider.
Time CalculateMpduTxDuration(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...
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.
WifiModeList GetDeviceMcsList(WifiModulationClass mc) const
Returns a list of only the MCS supported by the device for a given modulation class.
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.
uint16_t GetNextSample(MinstrelHtWifiRemoteStation *station)
Getting the next sample from Sample Table.
uint16_t GetIndex(std::size_t groupId, uint8_t rateId)
Returns the global index corresponding to the groupId and rateId.
void UpdateStats(MinstrelHtWifiRemoteStation *station)
Update the Minstrel Table.
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.
std::size_t GetGroupIdForType(McsGroupType type, uint8_t streams, Time guardInterval, MHz_u chWidth)
Returns the group ID of an MCS of a given group type with the given number of streams,...
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.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
represent a single transmission mode
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
uint8_t GetMcsValue() const
Time GetBlockAckTxTime() const
Return the estimated BlockAck TX time for this PHY.
static Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype=NORMAL_MPDU, uint16_t staId=SU_STA_ID)
Time GetSlot() const
Return the slot duration for this PHY.
Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
MHz_u GetTxBandwidth(WifiMode mode, MHz_u maxAllowedBandWidth=MHz_u{ std::numeric_limits< double >::max()}) const
Get the bandwidth for a transmission occurring on the current operating channel and using the given W...
Ptr< WifiNetDevice > GetDevice() const
Return the device this PHY is associated with.
std::list< WifiMode > GetMcsList() const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
std::list< WifiMode > GetModeList() const
The WifiPhy::GetModeList() method is used (e.g., by a WifiRemoteStationManager) to determine the set ...
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
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 shortest supported HE guard interval duration.
uint8_t GetDefaultTxPowerLevel() const
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...
Ptr< WifiMac > GetMac() const
Return the WifiMac.
uint8_t GetNumberOfAntennas() const
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...
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.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
MpduType
The type of an MPDU.
@ 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.
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
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.
McsGroupType
Available MCS group types.
@ WIFI_MINSTREL_GROUP_VHT
const std::map< WifiModulationClass, MinstrelHtWifiManager::StandardInfo > minstrelHtStandardInfos
standard information for each modulation class
double MHz_u
MHz weak type.
std::vector< MinstrelHtRateInfo > MinstrelHtRate
Data structure for a Minstrel Rate table.
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes.
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.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
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.
double ewmaProb
Exponential weighted moving average of probability.
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
uint8_t m_index
vector index
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
SampleRate m_sampleTable
sample table
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.