21 #include "wifi-remote-station-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/assert.h"
26 #include "ns3/boolean.h"
27 #include "ns3/double.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/wifi-phy.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "wifi-mac-header.h"
32 #include "wifi-mac-trailer.h"
51 static TypeId GetTypeId (
void);
56 virtual void Print (std::ostream &os)
const;
62 TxModeTag::TxModeTag ()
65 TxModeTag::TxModeTag (WifiMode rtsMode, WifiMode dataMode)
66 : m_rtsMode (rtsMode),
71 TxModeTag::GetRtsMode (
void)
const
76 TxModeTag::GetDataMode (
void)
const
81 TxModeTag::GetTypeId (
void)
83 static TypeId tid = TypeId (
"ns3::TxModeTag")
85 .AddConstructor<TxModeTag> ()
86 .AddAttribute (
"RtsTxMode",
87 "Tx mode of rts to use later",
88 EmptyAttributeValue (),
89 MakeWifiModeAccessor (&TxModeTag::GetRtsMode),
90 MakeWifiModeChecker ())
91 .AddAttribute (
"DataTxMode",
92 "Tx mode of data to use later",
93 EmptyAttributeValue (),
94 MakeWifiModeAccessor (&TxModeTag::GetDataMode),
95 MakeWifiModeChecker ())
124 os <<
"Rts=" << m_rtsMode <<
", Data=" << m_dataMode;
132 NS_OBJECT_ENSURE_REGISTERED (WifiRemoteStationManager);
135 WifiRemoteStationManager::GetTypeId (
void)
137 static TypeId tid = TypeId (
"ns3::WifiRemoteStationManager")
138 .SetParent<Object> ()
139 .AddAttribute (
"IsLowLatency",
"If true, we attempt to modelize a so-called low-latency device: a device"
140 " where decisions about tx parameters can be made on a per-packet basis and feedback about the"
141 " transmission of each packet is obtained before sending the next. Otherwise, we modelize a "
142 " high-latency device, that is a device where we cannot update our decision about tx parameters"
143 " after every packet transmission.",
146 MakeBooleanChecker ())
147 .AddAttribute (
"MaxSsrc",
"The maximum number of retransmission attempts for an RTS. This value"
148 " will not have any effect on some rate control algorithms.",
150 MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSsrc),
151 MakeUintegerChecker<uint32_t> ())
152 .AddAttribute (
"MaxSlrc",
"The maximum number of retransmission attempts for a DATA packet. This value"
153 " will not have any effect on some rate control algorithms.",
155 MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSlrc),
156 MakeUintegerChecker<uint32_t> ())
157 .AddAttribute (
"RtsCtsThreshold",
"If the size of the data packet + LLC header + MAC header + FCS trailer is bigger than "
158 "this value, we use an RTS/CTS handshake before sending the data, as per IEEE Std. 802.11-2007, Section 9.2.6. "
159 "This value will not have any effect on some rate control algorithms.",
160 UintegerValue (2346),
161 MakeUintegerAccessor (&WifiRemoteStationManager::m_rtsCtsThreshold),
162 MakeUintegerChecker<uint32_t> ())
163 .AddAttribute (
"FragmentationThreshold",
"If the size of the data packet + LLC header + MAC header + FCS trailer is bigger"
164 "than this value, we fragment it such that the size of the fragments are equal or smaller "
165 "than this value, as per IEEE Std. 802.11-2007, Section 9.4. "
166 "This value will not have any effect on some rate control algorithms.",
167 UintegerValue (2346),
168 MakeUintegerAccessor (&WifiRemoteStationManager::DoSetFragmentationThreshold,
169 &WifiRemoteStationManager::DoGetFragmentationThreshold),
170 MakeUintegerChecker<uint32_t> ())
171 .AddAttribute (
"NonUnicastMode",
"Wifi mode used for non-unicast transmissions.",
173 MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
174 MakeWifiModeChecker ())
175 .AddTraceSource (
"MacTxRtsFailed",
176 "The transmission of a RTS by the MAC layer has failed",
178 .AddTraceSource (
"MacTxDataFailed",
179 "The transmission of a data packet by the MAC layer has failed",
181 .AddTraceSource (
"MacTxFinalRtsFailed",
182 "The transmission of a RTS has exceeded the maximum number of attempts",
184 .AddTraceSource (
"MacTxFinalDataFailed",
185 "The transmission of a data packet has exceeded the maximum number of attempts",
191 WifiRemoteStationManager::WifiRemoteStationManager ()
195 WifiRemoteStationManager::~WifiRemoteStationManager ()
201 for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
206 for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
221 m_defaultTxMode = phy->
GetMode (0);
226 WifiRemoteStationManager::GetMaxSsrc (
void)
const
231 WifiRemoteStationManager::GetMaxSlrc (
void)
const
236 WifiRemoteStationManager::GetRtsCtsThreshold (
void)
const
238 return m_rtsCtsThreshold;
241 WifiRemoteStationManager::GetFragmentationThreshold (
void)
const
243 return DoGetFragmentationThreshold ();
246 WifiRemoteStationManager::SetMaxSsrc (uint32_t maxSsrc)
251 WifiRemoteStationManager::SetMaxSlrc (uint32_t maxSlrc)
256 WifiRemoteStationManager::SetRtsCtsThreshold (uint32_t threshold)
258 m_rtsCtsThreshold = threshold;
261 WifiRemoteStationManager::SetFragmentationThreshold (uint32_t threshold)
263 DoSetFragmentationThreshold (threshold);
271 state->m_operationalRateSet.clear ();
279 for (WifiModeListIterator i = state->m_operationalRateSet.begin (); i != state->m_operationalRateSet.end (); i++)
287 state->m_operationalRateSet.push_back (mode);
290 WifiRemoteStationManager::IsBrandNew (
Mac48Address address)
const
296 return LookupState (address)->m_state == WifiRemoteStationState::BRAND_NEW;
299 WifiRemoteStationManager::IsAssociated (Mac48Address address)
const
301 if (address.IsGroup ())
305 return LookupState (address)->m_state == WifiRemoteStationState::GOT_ASSOC_TX_OK;
308 WifiRemoteStationManager::IsWaitAssocTxOk (Mac48Address address)
const
310 if (address.IsGroup ())
314 return LookupState (address)->m_state == WifiRemoteStationState::WAIT_ASSOC_TX_OK;
317 WifiRemoteStationManager::RecordWaitAssocTxOk (Mac48Address address)
320 LookupState (address)->m_state = WifiRemoteStationState::WAIT_ASSOC_TX_OK;
323 WifiRemoteStationManager::RecordGotAssocTxOk (Mac48Address address)
326 LookupState (address)->m_state = WifiRemoteStationState::GOT_ASSOC_TX_OK;
329 WifiRemoteStationManager::RecordGotAssocTxFailed (Mac48Address address)
332 LookupState (address)->m_state = WifiRemoteStationState::DISASSOC;
335 WifiRemoteStationManager::RecordDisassociated (Mac48Address address)
338 LookupState (address)->m_state = WifiRemoteStationState::DISASSOC;
353 ConstCast<Packet> (packet)->RemovePacketTag (tag);
364 return GetNonUnicastMode ();
370 found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
372 return tag.GetDataMode ();
374 return DoGetDataMode (Lookup (address, header), fullPacketSize);
385 found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
387 return tag.GetRtsMode ();
398 DoReportRtsFailed (station);
407 DoReportDataFailed (station);
411 double ctsSnr,
WifiMode ctsMode,
double rtsSnr)
415 station->m_state->m_info.NotifyTxSuccess (station->m_ssrc);
417 DoReportRtsOk (station, ctsSnr, ctsMode, rtsSnr);
421 double ackSnr,
WifiMode ackMode,
double dataSnr)
425 station->m_state->m_info.NotifyTxSuccess (station->m_slrc);
427 DoReportDataOk (station, ackSnr, ackMode, dataSnr);
434 station->m_state->m_info.NotifyTxFailed ();
437 DoReportFinalRtsFailed (station);
444 station->m_state->m_info.NotifyTxFailed ();
447 DoReportFinalDataFailed (station);
458 DoReportRxOk (station, rxSnr, txMode);
469 return DoNeedRts (Lookup (address, header), packet, normally);
477 bool normally = station->m_ssrc < GetMaxSsrc ();
486 bool normally = station->m_slrc < GetMaxSlrc ();
503 WifiRemoteStationManager::DoSetFragmentationThreshold (uint32_t threshold)
510 NS_LOG_WARN (
"Fragmentation threshold should be larger than 256. Setting to 256.");
511 m_fragmentationThreshold = 256;
519 if (threshold % 2 != 0)
521 NS_LOG_WARN (
"Fragmentation threshold should be an even number. Setting to " << threshold - 1);
522 m_fragmentationThreshold = threshold - 1;
526 m_fragmentationThreshold = threshold;
532 WifiRemoteStationManager::DoGetFragmentationThreshold (
void)
const
534 return m_fragmentationThreshold;
538 WifiRemoteStationManager::GetNFragments (
const WifiMacHeader *header, Ptr<const Packet> packet)
541 uint32_t nFragments = (packet->GetSize () / (GetFragmentationThreshold () - header->GetSize () -
WIFI_MAC_FCS_LENGTH));
544 if ((packet->GetSize () % (GetFragmentationThreshold () - header->GetSize () -
WIFI_MAC_FCS_LENGTH)) > 0)
556 uint32_t nFragment = GetNFragments (header, packet);
557 if (fragmentNumber >= nFragment)
562 if (fragmentNumber == nFragment - 1)
564 uint32_t lastFragmentSize = packet->
GetSize () - (fragmentNumber * (GetFragmentationThreshold () - header->GetSize () -
WIFI_MAC_FCS_LENGTH));
565 return lastFragmentSize;
578 NS_ASSERT (fragmentNumber < GetNFragments (header, packet));
579 uint32_t fragmentOffset = fragmentNumber * (GetFragmentationThreshold () - header->GetSize () -
WIFI_MAC_FCS_LENGTH);
580 return fragmentOffset;
587 bool isLast = fragmentNumber == (GetNFragments (header, packet) - 1);
614 if ((!found || i->GetPhyRate () > mode.
GetPhyRate ())
690 <<
". Check standard and selected rates match.");
710 WifiRemoteStationManager::GetInfo (
Mac48Address address)
713 return state->m_info;
716 WifiRemoteStationState *
717 WifiRemoteStationManager::LookupState (Mac48Address address)
const
719 for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
721 if ((*i)->m_address == address)
726 WifiRemoteStationState *state =
new WifiRemoteStationState ();
727 state->m_state = WifiRemoteStationState::BRAND_NEW;
728 state->m_address = address;
729 state->m_operationalRateSet.push_back (GetDefaultMode ());
730 const_cast<WifiRemoteStationManager *
> (
this)->m_states.push_back (state);
737 if (header->IsQosData ())
739 tid = header->GetQosTid ();
745 return Lookup (address, tid);
748 WifiRemoteStationManager::Lookup (
Mac48Address address, uint8_t tid)
const
750 for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
752 if ((*i)->m_tid == tid
753 && (*i)->m_state->m_address == address)
758 WifiRemoteStationState *state = LookupState (address);
761 station->m_state = state;
762 station->m_tid = tid;
766 const_cast<WifiRemoteStationManager *
> (
this)->m_stations.push_back (station);
772 WifiRemoteStationManager::GetDefaultMode (
void)
const
774 return m_defaultTxMode;
777 WifiRemoteStationManager::Reset (
void)
779 for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
789 WifiRemoteStationManager::AddBasicMode (WifiMode mode)
791 for (uint32_t i = 0; i < GetNBasicModes (); i++)
793 if (GetBasicMode (i) == mode)
801 WifiRemoteStationManager::GetNBasicModes (
void)
const
806 WifiRemoteStationManager::GetBasicMode (uint32_t i)
const
812 WifiRemoteStationManager::GetNonUnicastMode (
void)
const
814 if (m_nonUnicastMode == WifiMode ())
816 return GetBasicMode (0);
820 return m_nonUnicastMode;
850 WifiRemoteStationManager::GetSupported (
const WifiRemoteStation *station, uint32_t i)
const
856 WifiRemoteStationManager::GetNSupported (
const WifiRemoteStation *station)
const
858 return station->m_state->m_operationalRateSet.size ();
862 WifiRemoteStationInfo::WifiRemoteStationInfo ()
863 : m_memoryTime (
Seconds (1.0)),
882 m_failAvg = (double)retryCounter / (1 + (
double) retryCounter) * (1.0 - coefficient) + coefficient *
m_failAvg;
void Write(const uint8_t *buffer, uint32_t size)
bool NeedDataRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
WifiMode GetCtsMode(Mac48Address address, WifiMode rtsMode)
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header)
virtual uint32_t GetNModes(void) const =0
virtual void Print(std::ostream &os) const
virtual void Serialize(TagBuffer i) const
void AddPacketTag(const Tag &tag) const
enum WifiModulationClass GetModulationClass() const
#define NS_ASSERT(condition)
static const uint16_t WIFI_MAC_FCS_LENGTH
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
Time m_memoryTime
averaging coefficient depends on the memory time
bool IsLastFragment(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
TracedCallback< Mac48Address > m_macTxFinalRtsFailed
virtual TypeId GetInstanceTypeId(void) const
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
bool IsMandatory(void) const
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
Tid independent remote station statistics.
#define NS_FATAL_ERROR(msg)
fatal error handling
double m_failAvg
moving percentage of failed frames
TracedCallback< Mac48Address > m_macTxFinalDataFailed
virtual bool DoNeedDataRetransmission(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
Time m_lastUpdate
when last update has occured
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header)
int64_t GetMicroSeconds(void) const
double CalculateAveragingCoefficient()
Calculate averaging coefficient for frame error rate. Depends on time of the last update...
void ReportRtsFailed(Mac48Address address, const WifiMacHeader *header)
virtual bool DoNeedRtsRetransmission(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
void NotifyTxSuccess(uint32_t retryCounter)
Updates average frame error rate when data or RTS was transmitted successfully.
WifiMode GetControlAnswerMode(Mac48Address address, WifiMode reqMode)
WifiModeList m_bssBasicRateSet
void ReportDataOk(Mac48Address address, const WifiMacHeader *header, double ackSnr, WifiMode ackMode, double dataSnr)
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)=0
tag a set of bytes in a packet
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fullPacketSize)
void AddSupportedMode(Mac48Address address, WifiMode mode)
WifiModeList m_operationalRateSet
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
uint64_t GetPhyRate(void) const
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
TracedCallback< Mac48Address > m_macTxRtsFailed
virtual bool IsLowLatency(void) const =0
virtual WifiMode GetMode(uint32_t mode) const =0
void ReportRtsOk(Mac48Address address, const WifiMacHeader *header, double ctsSnr, WifiMode ctsMode, double rtsSnr)
WifiMode GetDataMode(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fullPacketSize)
TracedCallback< Mac48Address > m_macTxDataFailed
double GetFrameErrorRate() const
Returns frame error rate (probability that frame is corrupted due to transmission error)...
virtual bool DoNeedFragmentation(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
void NotifyTxFailed()
Updates average frame error rate when final data or RTS has failed.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
WifiMode GetRtsMode(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual uint32_t GetSerializedSize(void) const
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)=0
virtual void DoDispose(void)
virtual void Deserialize(TagBuffer i)
WifiMode GetAckMode(Mac48Address address, WifiMode dataMode)
void ReportRxOk(Mac48Address address, const WifiMacHeader *header, double rxSnr, WifiMode txMode)
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void Read(uint8_t *buffer, uint32_t size)
bool NeedRtsRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
bool NeedRts(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
a unique identifier for an interface.
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
hold per-remote-station state.
virtual WifiRemoteStation * DoCreateStation(void) const =0