21 #include "ns3/assert.h"
22 #include "ns3/simulator.h"
23 #include "ns3/fatal-error.h"
58 recipient (recipient),
62 NS_LOG_FUNCTION (
this << bar << recipient << static_cast<uint32_t> (tid) << immediate);
89 NS_LOG_FUNCTION (
this << recipient << static_cast<uint32_t> (tid) << state);
91 it =
m_agreements.find (std::make_pair (recipient, tid));
97 return it->second.first.IsInactive ();
99 return it->second.first.IsEstablished ();
101 return it->second.first.IsPending ();
103 return it->second.first.IsUnsuccessful ();
115 std::pair<Mac48Address, uint8_t> key (recipient, reqHdr->
GetTid ());
120 agreement.SetBufferSize (0);
125 agreement.SetImmediateBlockAck ();
129 agreement.SetDelayedBlockAck ();
133 std::pair<OriginatorBlockAckAgreement, PacketQueue> value (agreement, queue);
147 if ((*i)->hdr.GetAddr1 () == recipient && (*i)->hdr.GetQosTid () == tid)
158 for (std::list<Bar>::iterator i =
m_bars.begin (); i !=
m_bars.end ();)
160 if (i->recipient == recipient && i->tid == tid)
176 uint8_t tid = respHdr->
GetTid ();
214 Item item (packet, hdr, tStamp);
217 it->second.second.push_back (item);
230 packet = queueIt->packet;
253 i->second.second.erase (queueIt);
283 uint32_t nPackets = 0;
288 uint16_t currentSeq = 0;
289 while (queueIt != (*it).second.second.end ())
291 currentSeq = (*queueIt).hdr.GetSequenceNumber ();
294 while (queueIt != (*it).second.second.end () && (*queueIt).hdr.GetSequenceNumber () == currentSeq)
308 uint32_t nPackets = 0;
309 uint16_t currentSeq = 0;
312 std::list<PacketQueueI>::const_iterator it =
m_retryPackets.begin ();
315 if ((*it)->hdr.GetAddr1 () == recipient && (*it)->hdr.GetQosTid () == tid)
317 currentSeq = (*it)->hdr.GetSequenceNumber ();
320 while (it !=
m_retryPackets.end () && (*it)->hdr.GetSequenceNumber () == currentSeq)
341 uint16_t sequenceFirstLost = 0;
347 bool foundFirstLost =
false;
351 if (it->second.first.m_inactivityEvent.IsRunning ())
356 it->second.first.m_inactivityEvent.Cancel ();
357 Time timeout = MicroSeconds (1024 * it->second.first.GetTimeout ());
365 for (
PacketQueueI queueIt = it->second.second.begin (); queueIt != queueEnd;)
368 (*queueIt).hdr.GetFragmentNumber ()))
370 queueIt = it->second.second.erase (queueIt);
376 foundFirstLost =
true;
377 sequenceFirstLost = (*queueIt).hdr.GetSequenceNumber ();
378 (*it).second.first.SetStartingSequence (sequenceFirstLost);
387 for (
PacketQueueI queueIt = it->second.second.begin (); queueIt != queueEnd;)
391 uint16_t currentSeq = (*queueIt).hdr.GetSequenceNumber ();
392 while (queueIt != queueEnd
393 && (*queueIt).hdr.GetSequenceNumber () == currentSeq)
395 queueIt = it->second.second.erase (queueIt);
402 foundFirstLost =
true;
403 sequenceFirstLost = (*queueIt).hdr.GetSequenceNumber ();
404 (*it).second.first.SetStartingSequence (sequenceFirstLost);
445 if ((*it).second.first.IsBlockAckRequestNeeded ()
484 NS_LOG_FUNCTION (
this << recipient << static_cast<uint32_t> (tid) << startingSeq);
489 it->second.first.SetStartingSequence (startingSeq);
507 NS_LOG_FUNCTION (
this << recipient << static_cast<uint32_t> (tid) << nextSeqNumber);
519 nextSeq = nextSeqNumber;
521 it->second.first.NotifyMpduTransmission (nextSeq);
525 Bar request (bar, recipient, tid, it->second.first.IsImmediateBlockAck ());
526 m_bars.push_back (request);
540 NS_LOG_FUNCTION (
this << recipient << static_cast<uint32_t> (tid) << startingSeq);
597 if (j->second.second.empty ())
603 for (
PacketQueueI i = j->second.second.begin (); i != j->second.second.end (); i++)
615 if ((*it)->hdr.GetAddr1 () == j->second.first.GetPeer ()
616 && (*it)->hdr.GetQosTid () == j->second.first.GetTid ()
617 && (*it)->hdr.GetSequenceNumber () == i->hdr.GetSequenceNumber ())
628 j->second.second.erase (j->second.second.begin (), end);
629 j->second.first.SetStartingSequence (end->hdr.GetSequenceNumber ());
672 std::list<PacketQueueI>::const_iterator it =
m_retryPackets.begin ();
675 if ((*it)->hdr.GetAddr1 () == recipient && (*it)->hdr.GetQosTid () == tid)
677 return (*it)->hdr.GetSequenceNumber ();
void SetUnblockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
uint8_t GetTid(void) const
Return the Traffic ID (TID).
keep track of time values and allow control of global simulation resolution
#define NS_LOG_FUNCTION(parameters)
std::list< Item > PacketQueue
typedef for a list of Item struct.
Maintains the state and information about transmitted MPDUs with ack policy block ack for an originat...
uint16_t GetTimeout(void) const
Return the timeout.
void NotifyGotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient)
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::const_iterator AgreementsCI
typedef for a const iterator for Agreements.
void CreateAgreement(const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient)
void StorePacket(Ptr< const Packet > packet, const WifiMacHeader &hdr, Time tStamp)
uint8_t m_blockAckThreshold
Agreements m_agreements
This data structure contains, for each block ack agreement (recipient, tid), a set of packets for whi...
#define NS_ASSERT(condition)
bool HasBar(struct Bar &bar)
uint32_t GetSize(void) const
void InactivityTimeout(Mac48Address, uint8_t)
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::iterator AgreementsI
typedef for an iterator for Agreements.
void SetBlockAckType(enum BlockAckType bAckType)
bool HasPackets(void) const
Returns true if there are packets that need of retransmission or at least a BAR is scheduled...
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
BlockAckType
Enumeration for different block ACK policies.
#define NS_FATAL_ERROR(msg)
fatal error handling
uint16_t GetStartingSequence(void) const
Return the starting squence number.
Handles sequence numbering of IEEE 802.11 data frames.
Ptr< Packet > ScheduleBlockAckReqIfNeeded(Mac48Address recipient, uint8_t tid)
void SetQueue(Ptr< WifiMacQueue > queue)
void NotifyAgreementEstablished(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
NS_LOG_COMPONENT_DEFINE("BlockAckManager")
void UpdateAgreement(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
uint32_t GetNRetryNeededPackets(Mac48Address recipient, uint8_t tid) const
uint32_t GetNextPacketSize(void) const
uint16_t GetSeqNumOfNextRetryPacket(Mac48Address recipient, uint8_t tid) const
void NotifyAgreementUnsuccessful(Mac48Address recipient, uint8_t tid)
bool HasOtherFragments(uint16_t sequenceNumber) const
std::list< PacketQueueI > m_retryPackets
This list contains all iterators to stored packets that need to be retransmitted. ...
void SetTxMiddle(MacTxMiddle *txMiddle)
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
void SetStartingSequence(uint16_t seq)
Set starting sequence number.
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, enum OriginatorBlockAckAgreement::State state) const
Callback< void, Mac48Address, uint8_t > m_blockPackets
Ptr< const Packet > GetNextPacket(WifiMacHeader &hdr)
static Time Now(void)
Return the "current simulation time".
State
Represents the state for this agreement.
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > callback)
void SetMaxPacketDelay(Time maxDelay)
void SetDelayedBlockAck(void)
Set Block ACK policy to delayed ACK.
EventId m_inactivityEvent
void SetAmsduSupport(bool supported)
Enable or disable A-MSDU support.
A struct for packet, Wifi header, and timestamp.
bool SwitchToBlockAckIfNeeded(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
std::list< Item >::const_iterator PacketQueueCI
typedef for a const iterator for PacketQueue.
Callback< void, Mac48Address, uint8_t > m_unblockPackets
uint32_t GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
enum BlockAckType m_blockAckType
void CleanupBuffers(void)
This method removes packets whose lifetime was exceeded.
void SetBlockAckThreshold(uint8_t nPackets)
void SetImmediateBlockAck(void)
Set Block ACK policy to immediate ACK.
void SetTimeout(uint16_t timeout)
Set timeout.
void SetState(enum State state)
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
void SetBufferSize(uint16_t bufferSize)
Set buffer size.
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
Ptr< const Packet > packet
void NotifyMpduTransmission(Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber)
void AddHeader(const Header &header)
Add header to this packet.
void TearDownBlockAck(Mac48Address recipient, uint8_t tid)
Ptr< WifiMacQueue > m_queue
void CompleteExchange(void)
std::list< Item >::iterator PacketQueueI
typedef for an iterator for PacketQueue.