A Discrete-Event Network Simulator
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 Duy Nguyen
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Duy Nguyen <duy@soe.ucsc.edu>
19  * Matías Richart <mrichart@fing.edu.uy>
20  */
25 #include "ns3/traced-value.h"
26 #include "ns3/wifi-remote-station-manager.h"
27 #include <fstream>
28 #include <map>
30 namespace ns3 {
32 class UniformRandomVariable;
37 struct RateInfo
38 {
45  uint32_t retryCount;
46  uint32_t adjustedRetryCount;
47  uint32_t numRateAttempt;
48  uint32_t numRateSuccess;
49  uint32_t prob;
54  uint32_t ewmaProb;
55  uint32_t throughput;
57  uint32_t prevNumRateAttempt;
58  uint32_t prevNumRateSuccess;
59  uint64_t successHist;
60  uint64_t attemptHist;
64 };
70 typedef std::vector<RateInfo> MinstrelRate;
75 typedef std::vector<std::vector<uint8_t> > SampleRate;
84 {
93  uint8_t m_col;
94  uint8_t m_index;
95  uint16_t m_maxTpRate;
96  uint16_t m_maxTpRate2;
97  uint16_t m_maxProbRate;
98  uint8_t m_nModes;
103  uint16_t m_sampleRate;
105  uint32_t m_shortRetry;
106  uint32_t m_longRetry;
107  uint32_t m_retry;
108  uint16_t m_txrate;
112  std::ofstream m_statsFile;
113 };
158 {
159 public:
164  static TypeId GetTypeId (void);
166  virtual ~MinstrelWifiManager ();
168  void SetupPhy (const Ptr<WifiPhy> phy) override;
169  void SetupMac (const Ptr<WifiMac> mac) override;
170  int64_t AssignStreams (int64_t stream) override;
177  void UpdateRate (MinstrelWifiRemoteStation *station);
184  void UpdateStats (MinstrelWifiRemoteStation *station);
192  uint16_t FindRate (MinstrelWifiRemoteStation *station);
216  uint32_t CountRetries (MinstrelWifiRemoteStation *station);
230  void UpdateRetry (MinstrelWifiRemoteStation *station);
237  void CheckInit (MinstrelWifiRemoteStation *station);
246 private:
247  void DoInitialize (void) override;
248  WifiRemoteStation * DoCreateStation (void) const override;
249  void DoReportRxOk (WifiRemoteStation *station,
250  double rxSnr, WifiMode txMode) override;
251  void DoReportRtsFailed (WifiRemoteStation *station) override;
252  void DoReportDataFailed (WifiRemoteStation *station) override;
253  void DoReportRtsOk (WifiRemoteStation *station,
254  double ctsSnr, WifiMode ctsMode, double rtsSnr) override;
255  void DoReportDataOk (WifiRemoteStation *station, double ackSnr, WifiMode ackMode,
256  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override;
257  void DoReportFinalRtsFailed (WifiRemoteStation *station) override;
258  void DoReportFinalDataFailed (WifiRemoteStation *station) override;
260  WifiTxVector DoGetRtsTxVector (WifiRemoteStation *station) override;
263  Ptr<const Packet> packet, bool normally) override;
272  Time GetCalcTxTime (WifiMode mode) const;
279  void AddCalcTxTime (WifiMode mode, Time t);
286  void RateInit (MinstrelWifiRemoteStation *station);
294  uint16_t GetNextSample (MinstrelWifiRemoteStation *station);
317  Time CalculateTimeUnicastPacket (Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries);
331  void PrintTable (MinstrelWifiRemoteStation *station);
338  typedef std::map<WifiMode, Time> TxTime;
343  uint8_t m_ewmaLevel;
344  uint8_t m_sampleCol;
345  uint32_t m_pktLen;
353 };
355 } //namespace ns3
357 #endif /* MINSTREL_WIFI_MANAGER_H */
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void CheckInit(MinstrelWifiRemoteStation *station)
Check for initializations.
void PrintTable(MinstrelWifiRemoteStation *station)
Print Minstrel Table.
uint16_t m_maxProbRate
rate with highest probability of success in bps
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool m_printStats
whether statistics table should be printed.
uint8_t m_lookAroundRate
the % to try other rates than our current rate
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time perfectTxTime
Perfect transmission time calculation, or frame calculation Given a bit rate and a packet length n by...
Implementation of Minstrel Rate Control AlgorithmMinstrel is a rate control algorithm implemented in ...
uint16_t m_maxTpRate
the current throughput rate in bps
uint16_t m_txrate
current transmit rate in bps
uint16_t m_maxTpRate2
second highest throughput rate in bps
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t numRateSuccess
number of successful packets
uint8_t numSamplesSkipped
number of samples skipped
hold per-remote-station state for Minstrel Wifi manager.
Time m_updateStats
how frequent do we calculate the stats
void UpdateStats(MinstrelWifiRemoteStation *station)
Update the Minstrel Table.
uint16_t m_sampleRate
current sample rate in bps
MinstrelRate m_minstrelTable
minstrel table
std::ofstream m_statsFile
stats file
bool m_sampleDeferred
a flag to indicate sample rate is on the second stage
std::vector< std::vector< uint8_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint8_t.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint32_t retryCount
retry limit
uint8_t m_nModes
number of modes supported
uint32_t m_pktLen
packet length used for calculate mode TxTime
uint32_t adjustedRetryCount
adjust the retry limit for this rate
Definition: third.py:93
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...
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 DoInitialize(void) override
Initialize() implementation.
A struct to contain all information related to a data rate.
bool m_isSampling
a flag to indicate we are currently sampling
int m_numSamplesDeferred
number samples deferred
SampleRate m_sampleTable
sample table
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 prevNumRateSuccess
Number of successful frames transmitted with previous rate.
uint16_t GetNextSample(MinstrelWifiRemoteStation *station)
Get the next sample from Sample Table.
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally) override
void PrintSampleTable(MinstrelWifiRemoteStation *station)
Print Sample Table.
Definition: third.py:99
uint32_t prevNumRateAttempt
Number of transmission attempts with previous rate.
int sampleLimit
sample limit
uint64_t attemptHist
Aggregate of all transmission attempts.
uint64_t successHist
Aggregate of all transmission successes.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
hold a list of per-remote-station state.
uint32_t m_longRetry
long retries such as data packets
uint16_t FindRate(MinstrelWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model...
bool m_initialized
for initializing tables
uint32_t ewmaProb
EWMA calculation ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100.
uint32_t numRateAttempt
how many number of attempts so far
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
TxTime m_calcTxTime
to hold all the calculated TxTime for all modes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void UpdateRate(MinstrelWifiRemoteStation *station)
Update the rate.
WifiTxVector GetDataTxVector(MinstrelWifiRemoteStation *station)
Get data transmit vector.
std::map< WifiMode, Time > TxTime
typedef for a vector of a pair of Time, WifiMode.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t throughput
throughput of a rate in bps
uint32_t m_retry
total retries short + long
int m_totalPacketsCount
total number of packets as of now
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
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.
void UpdateRetry(MinstrelWifiRemoteStation *station)
Update the number of retries and reset accordingly.
int m_samplePacketsCount
how many packets we have sample so far
static TypeId GetTypeId(void)
Get the type ID.
void InitSampleTable(MinstrelWifiRemoteStation *station)
Initialize Sample Table.
WifiRemoteStation * DoCreateStation(void) const override
WifiTxVector GetRtsTxVector(MinstrelWifiRemoteStation *station)
Get RTS transmit vector.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
uint32_t CountRetries(MinstrelWifiRemoteStation *station)
Get the number of retries.
bool m_printSamples
whether samples table should be printed.
uint32_t m_shortRetry
short retries such as control packets
uint8_t m_sampleCol
number of sample columns
Time GetCalcTxTime(WifiMode mode) const
Estimate the TxTime of a packet with a given mode.
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t m_ewmaLevel
exponential weighted moving average
Time CalculateTimeUnicastPacket(Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries)
Estimate the time to transmit the given packet with the given number of retries.
void RateInit(MinstrelWifiRemoteStation *station)
Initialize Minstrel Table.
hold per-remote-station state.
uint32_t prob
(# packets success)/(# total packets)
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Update packet counters.
Time m_nextStatsUpdate
10 times every second