25 #include "ns3/pointer.h"
26 #include "ns3/simulator.h"
27 #include "ns3/random-variable-stream.h"
40 #include "ns3/ht-frame-exchange-manager.h"
43 #undef NS_LOG_APPEND_CONTEXT
44 #define NS_LOG_APPEND_CONTEXT if (m_mac != 0) { std::clog << "[mac=" << m_mac->GetAddress () << "] "; }
57 .SetGroupName (
"Wifi")
59 .AddAttribute (
"UseExplicitBarAfterMissedBlockAck",
60 "Specify whether explicit BlockAckRequest should be sent upon missed BlockAck Response.",
64 .AddAttribute (
"AddBaResponseTimeout",
65 "The timeout to wait for ADDBA response after the Ack to "
66 "ADDBA request is received.",
71 .AddAttribute (
"FailedAddBaTimeout",
72 "The timeout after a failed BA agreement. During this "
73 "timeout, the originator resumes sending packets using normal "
74 "MPDU. After that, BA agreement is reset and the originator "
75 "will retry BA negotiation.",
80 .AddAttribute (
"BlockAckManager",
81 "The BlockAckManager object.",
84 MakePointerChecker<BlockAckManager> ())
85 .AddTraceSource (
"TxopTrace",
86 "Trace source for TXOP start and duration times",
88 "ns3::TracedValueCallback::Time")
102 m_muEdcaTimerStartTime (
Seconds (0))
135 uint32_t bufferSize =
m_queue->GetNBytes (tid, receiver);
137 uint8_t queueSize =
static_cast<uint8_t
> (std::ceil (
std::min (bufferSize, 64769u) / 256.0));
138 NS_LOG_DEBUG (
"Buffer size=" << bufferSize <<
" Queue Size=" << +queueSize);
285 return Create<const WifiMacQueueItem> (bar, hdr);
291 m_baManager->ScheduleBar (bar, skipIfNoDataQueued);
306 bool baManagerHasPackets = (
m_baManager->GetBar (
false) != 0);
313 bool ret = (baManagerHasPackets || queueIsNotEmpty);
321 return m_txMiddle->GetNextSequenceNumberFor (hdr);
327 return m_txMiddle->PeekNextSequenceNumberFor (hdr);
335 if (!mpdu->GetHeader ().IsQosData ())
340 Mac48Address recipient = mpdu->GetHeader ().GetAddr1 ();
341 uint8_t tid = mpdu->GetHeader ().GetQosTid ();
349 mpdu->GetHeader ().GetSequenceNumber ()))
372 return m_queue->PeekByTidAndAddress (tid, recipient, item);
378 while (item !=
nullptr && !item->IsFragment ())
380 if ((item->GetHeader ().IsRetry () || item->IsInFlight ())
383 NS_LOG_DEBUG (
"Removing an old packet from EDCA queue: " << *item);
392 else if (item->IsInFlight ())
397 else if (item->GetHeader ().HasData ()
398 && !
m_mac->CanForwardPacketsTo (item->GetHeader ().GetAddr1 ()))
400 NS_LOG_DEBUG (
"Skipping frame that cannot be forwarded: " << *item);
416 :
m_txMiddle->PeekNextSequenceNumberFor (&hdr));
425 NS_LOG_DEBUG (
"Packet beyond the end of the current transmit window");
431 if (!item->IsFragment () && !hdr.
IsRetry ())
435 NS_LOG_DEBUG (
"Packet peeked from EDCA queue: " << *item);
444 Time availableTime,
bool initialFrame)
448 NS_LOG_FUNCTION (
this << *peekedItem << &txParams << availableTime << initialFrame);
450 Mac48Address recipient = peekedItem->GetHeader ().GetAddr1 ();
455 Time actualAvailableTime = (initialFrame && txParams.
GetSize (recipient) == 0
458 if (!
m_qosFem->TryAddMpdu (peekedItem, txParams, actualAvailableTime))
468 if (peekedItem->GetHeader ().IsQosData ())
470 uint8_t tid = peekedItem->GetHeader ().GetQosTid ();
476 ||
IsInWindow (peekedItem->GetHeader ().GetSequenceNumber (),
482 && !peekedItem->GetHeader ().IsRetry () && !peekedItem->IsFragment ()
483 && !peekedItem->IsInFlight ())
486 mpdu = htFem->GetMsduAggregator ()->GetNextAmsdu (peekedItem, txParams, availableTime);
498 mpdu = peekedItem->GetItem ();
513 if (!mpdu->IsFragment () && !mpdu->GetHeader ().IsRetry () && !mpdu->IsInFlight ())
515 uint16_t sequence =
m_txMiddle->GetNextSequenceNumberFor (&mpdu->GetHeader ());
516 mpdu->GetHeader ().SetSequenceNumber (sequence);
523 return m_baManager->GetBlockAckReqType (recipient, tid);
529 return m_baManager->GetBlockAckType (recipient, tid);
575 return remainingTxop;
583 m_queue->PushFront (Create<WifiMacQueueItem> (packet, hdr));
594 uint8_t tid = respHdr->
GetTid ();
597 NS_LOG_DEBUG (
"block ack agreement established with " << recipient <<
" tid " << +tid);
605 uint16_t startingSeq =
m_txMiddle->GetNextSeqNumberByTidAndAddress (tid, recipient);
606 auto peekedItem =
m_queue->PeekByTidAndAddress (tid, recipient);
607 if (peekedItem !=
nullptr && peekedItem->GetHeader ().IsRetry ())
609 startingSeq = peekedItem->GetHeader ().GetSequenceNumber ();
611 m_baManager->UpdateAgreement (respHdr, recipient, startingSeq);
616 m_baManager->NotifyAgreementRejected (recipient, tid);
629 NS_LOG_DEBUG (
"received DELBA frame from=" << recipient);
636 NS_ASSERT (mpdu->GetHeader ().IsQosData ());
687 m_baManager->NotifyAgreementNoReply (recipient, tid);
708 m_baManager->NotifyAgreementReset (recipient, tid);
void NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
AttributeValue implementation for Boolean.
bool IsNull(void) const
Check for null implementation.
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > Bind(T a)
Bind the first arguments.
bool IsBroadcast(void) const
void AddHeader(const Header &header)
Add header to this packet.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
void Unblock(Mac48Address dest, uint8_t tid)
Un-block the given destination address and TID (e.g.
void Block(Mac48Address dest, uint8_t tid)
Block the given destination address and TID from sending (e.g.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Time m_muEdcaTimer
the MU EDCA Timer
QosTxop(AcIndex ac=AC_UNDEF)
Constructor.
uint32_t m_muCwMax
the MU CW maximum
uint32_t m_muCwMin
the MU CW minimum
uint8_t m_blockAckThreshold
the block ack threshold (use BA mechanism if number of packets in queue reaches this value.
TracedCallback< Time, Time > m_txopTrace
TXOP trace callback.
virtual bool IsTxopStarted(void) const
Return true if a TXOP has started.
void SetMuCwMax(uint16_t cwMax)
Set the maximum contention window size to use while the MU EDCA Timer is running.
Time m_failedAddBaTimeout
timeout after failed BA agreement
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i....
void SetQosFrameExchangeManager(const Ptr< QosFrameExchangeManager > qosFem)
Set the Frame Exchange Manager associated with this QoS STA.
bool IsQosTxop(void) const override
Check for QoS TXOP.
void DoInitialize(void) override
Initialize() implementation.
Time m_startTxop
the start TXOP time
void NotifyChannelAccessed(Time txopDuration) override
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
void NotifyChannelReleased(void) override
Called by the FrameExchangeManager to notify the completion of the transmissions.
void AssignSequenceNumber(Ptr< WifiMacQueueItem > mpdu) const
Assign a sequence number to the given MPDU, if it is not a fragment and it is not a retransmitted fra...
void AddBaResponseTimeout(Mac48Address recipient, uint8_t tid)
Callback when ADDBA response is not received after timeout.
void SetMuEdcaTimer(Time timer)
Set the MU EDCA Timer.
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
uint8_t m_muAifsn
the MU AIFSN
Time m_txopDuration
the duration of a TXOP
void DoDispose(void) override
Destructor implementation.
bool HasFramesToTransmit(void) override
Check if the Txop has frames to transmit.
virtual Time GetRemainingTxop(void) const
Return the remaining duration in the current TXOP.
bool IsQosOldPacket(Ptr< const WifiMacQueueItem > mpdu)
Check if the given MPDU is to be considered old according to the current starting sequence number of ...
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ack mechanism.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
AcIndex m_ac
the access category
bool MuEdcaTimerRunning(void) const
Return true if the MU EDCA Timer is running, false otherwise.
void SetDroppedMpduCallback(DroppedMpdu callback) override
bool m_useExplicitBarAfterMissedBlockAck
flag whether explicit BlockAckRequest should be sent upon missed BlockAck Response
Time GetFailedAddBaTimeout(void) const
Get the timeout for failed BA agreement.
void CompleteMpduTx(Ptr< WifiMacQueueItem > mpdu)
Stores an MPDU (part of an A-MPDU) in block ack agreement (i.e.
Ptr< const WifiMacQueueItem > PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
uint8_t GetQosQueueSize(uint8_t tid, Mac48Address receiver) const
Get the value for the Queue Size subfield of the QoS Control field of a QoS data frame of the given T...
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
uint32_t GetMinCw(void) const override
Return the minimum contention window size from the EDCA Parameter Set or the MU EDCA Parameter Set,...
void ResetBa(Mac48Address recipient, uint8_t tid)
Reset BA agreement after BA negotiation failed.
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Time GetAddBaResponseTimeout(void) const
Get the timeout for ADDBA response.
void StartMuEdcaTimerNow(void)
Start the MU EDCA Timer.
BlockAckType GetBlockAckType(Mac48Address recipient, uint8_t tid) const
uint8_t GetAifsn(void) const override
Return the number of slots that make up an AIFS according to the EDCA Parameter Set or the MU EDCA Pa...
Ptr< WifiMacQueueItem > GetNextMpdu(Ptr< const WifiMacQueueItem > peekedItem, WifiTxParameters &txParams, Time availableTime, bool initialFrame)
Prepare the frame to transmit starting from the MPDU that has been previously peeked by calling PeekN...
uint16_t GetBlockAckInactivityTimeout(void) const
Get the BlockAck inactivity timeout.
Ptr< BlockAckManager > GetBaManager(void)
Get the Block Ack Manager associated with this QosTxop.
bool UseExplicitBarAfterMissedBlockAck(void) const
Return true if an explicit BlockAckRequest is sent after a missed BlockAck.
bool EdcaDisabled(void) const
Return true if the EDCA is disabled (the MU EDCA Timer is running and the MU AIFSN is zero),...
void SetFailedAddBaTimeout(Time failedAddBaTimeout)
Set the timeout for failed BA agreement.
uint16_t m_blockAckInactivityTimeout
the BlockAck inactivity timeout value (in TUs, i.e.
void SetMuAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS while the MU EDCA Timer is running.
AcIndex GetAccessCategory(void) const
Get the access category of this object.
uint32_t GetMaxCw(void) const override
Return the maximum contention window size from the EDCA Parameter Set or the MU EDCA Parameter Set,...
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
Time m_muEdcaTimerStartTime
last start time of the MU EDCA Timer
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ack mechanism.
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received.
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the BlockAck inactivity timeout.
BlockAckReqType GetBlockAckReqType(Mac48Address recipient, uint8_t tid) const
void SetAddBaResponseTimeout(Time addBaResponseTimeout)
Set the timeout to wait for ADDBA response.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< QosFrameExchangeManager > m_qosFem
the QoS Frame Exchange Manager
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
void SetMuCwMin(uint16_t cwMin)
Set the minimum contention window size to use while the MU EDCA Timer is running.
Ptr< const WifiMacQueueItem > PeekNextMpdu(uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast(), Ptr< const WifiMacQueueItem > item=nullptr)
Peek the next frame to transmit to the given receiver and of the given TID from the EDCA queue.
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
the QoS blocked destinations
Time m_addBaResponseTimeout
timeout for ADDBA response
void ScheduleBar(Ptr< const WifiMacQueueItem > bar, bool skipIfNoDataQueued=false)
Ptr< BlockAckManager > m_baManager
the block ack manager
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
bool IsSuccess(void) const
Return whether the status code is success.
Simulation virtual time values and global simulation resolution.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
bool IsZero(void) const
Exactly equivalent to t == 0.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
AttributeValue implementation for Time.
Handle packet fragmentation and retransmissions for data and management frames.
Ptr< WifiMac > m_mac
the wifi MAC
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions.
ChannelAccessStatus m_access
channel access status
uint32_t m_cwMin
the minimum contention window
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
uint32_t m_cwMax
the maximum contention window
virtual void GenerateBackoff(void)
Generate a new backoff now.
void DoDispose(void) override
Destructor implementation.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
Implements the IEEE 802.11 MAC trailer.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
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 > MakePointerAccessor(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.
#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 ",...
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 Seconds(double 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.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
@ WIFI_MAC_DROP_QOS_OLD_PACKET
The different BlockAckRequest variants.
The different BlockAck variants.