Skip to content

Commit

Permalink
wifi: Rename types and variables for BlockAckManager agreements
Browse files Browse the repository at this point in the history
  • Loading branch information
stavallo authored and Stefano Avallone committed Jan 25, 2023
1 parent 1180733 commit e318b39
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 77 deletions.
122 changes: 67 additions & 55 deletions src/wifi/model/block-ack-manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BlockAckManager::GetTypeId()
.AddConstructor<BlockAckManager>()
.AddTraceSource("AgreementState",
"The state of the ADDBA handshake",
MakeTraceSourceAccessor(&BlockAckManager::m_agreementState),
MakeTraceSourceAccessor(&BlockAckManager::m_originatorAgreementState),
"ns3::BlockAckManager::AgreementStateTracedCallback");
return tid;
}
Expand All @@ -80,7 +80,7 @@ void
BlockAckManager::DoDispose()
{
NS_LOG_FUNCTION(this);
m_agreements.clear();
m_originatorAgreements.clear();
m_bars.clear();
m_queue = nullptr;
m_bamMap.clear();
Expand All @@ -96,7 +96,7 @@ BlockAckManager::OriginatorAgreementOptConstRef
BlockAckManager::GetAgreementAsOriginator(Mac48Address recipient, uint8_t tid) const
{
NS_LOG_FUNCTION(this << recipient << +tid);
if (auto it = m_agreements.find({recipient, tid}); it != m_agreements.end())
if (auto it = m_originatorAgreements.find({recipient, tid}); it != m_originatorAgreements.end())
{
return std::cref(it->second.first);
}
Expand Down Expand Up @@ -128,25 +128,28 @@ BlockAckManager::CreateOriginatorAgreement(const MgtAddBaRequestHeader* reqHdr,
agreement.SetDelayedBlockAck();
}
agreement.SetState(OriginatorBlockAckAgreement::PENDING);
m_agreementState(Simulator::Now(), recipient, tid, OriginatorBlockAckAgreement::PENDING);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::PENDING);
if (auto existingAgreement = GetAgreementAsOriginator(recipient, tid))
{
NS_ASSERT_MSG(existingAgreement->get().IsReset(),
"Existing agreement must be in RESET state");
}
m_agreements.insert_or_assign({recipient, tid},
std::make_pair(std::move(agreement), PacketQueue{}));
m_originatorAgreements.insert_or_assign({recipient, tid},
std::make_pair(std::move(agreement), PacketQueue{}));
m_blockPackets(recipient, tid);
}

void
BlockAckManager::DestroyOriginatorAgreement(Mac48Address recipient, uint8_t tid)
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
if (it != m_agreements.end())
auto it = m_originatorAgreements.find({recipient, tid});
if (it != m_originatorAgreements.end())
{
m_agreements.erase(it);
m_originatorAgreements.erase(it);
// remove scheduled BAR
for (std::list<Bar>::const_iterator i = m_bars.begin(); i != m_bars.end();)
{
Expand All @@ -169,8 +172,8 @@ BlockAckManager::UpdateOriginatorAgreement(const MgtAddBaResponseHeader* respHdr
{
NS_LOG_FUNCTION(this << respHdr << recipient << startingSeq);
uint8_t tid = respHdr->GetTid();
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
if (it != m_agreements.end())
auto it = m_originatorAgreements.find({recipient, tid});
if (it != m_originatorAgreements.end())
{
OriginatorBlockAckAgreement& agreement = it->second.first;
agreement.SetBufferSize(respHdr->GetBufferSize());
Expand All @@ -188,10 +191,10 @@ BlockAckManager::UpdateOriginatorAgreement(const MgtAddBaResponseHeader* respHdr
}
if (!it->second.first.IsEstablished())
{
m_agreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::ESTABLISHED);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::ESTABLISHED);
}
agreement.SetState(OriginatorBlockAckAgreement::ESTABLISHED);
if (agreement.GetTimeout() != 0)
Expand All @@ -216,8 +219,8 @@ BlockAckManager::StorePacket(Ptr<WifiMpdu> mpdu)
uint8_t tid = mpdu->GetHeader().GetQosTid();
Mac48Address recipient = mpdu->GetHeader().GetAddr1();

AgreementsI agreementIt = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(agreementIt != m_agreements.end());
auto agreementIt = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(agreementIt != m_originatorAgreements.end());

uint16_t mpduDist =
agreementIt->second.first.GetDistance(mpdu->GetHeader().GetSequenceNumber());
Expand Down Expand Up @@ -280,8 +283,8 @@ BlockAckManager::GetBar(bool remove, uint8_t tid, Mac48Address address)
if (nextBar->bar->GetHeader().IsBlockAckReq())
{
auto bam = m_bamMap.at(QosUtilsMapTidToAc(nextBar->tid));
AgreementsI it = bam->m_agreements.find(std::make_pair(recipient, nextBar->tid));
if (it == m_agreements.end())
auto it = bam->m_originatorAgreements.find({recipient, nextBar->tid});
if (it == m_originatorAgreements.end())
{
// BA agreement was torn down; remove this BAR and continue
nextBar = m_bars.erase(nextBar);
Expand Down Expand Up @@ -320,8 +323,8 @@ uint32_t
BlockAckManager::GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsCI it = m_agreements.find(std::make_pair(recipient, tid));
if (it == m_agreements.end())
auto it = m_originatorAgreements.find({recipient, tid});
if (it == m_originatorAgreements.end())
{
return 0;
}
Expand All @@ -339,7 +342,7 @@ BlockAckManager::PacketQueueI
BlockAckManager::HandleInFlightMpdu(uint8_t linkId,
PacketQueueI mpduIt,
MpduStatus status,
const AgreementsI& it,
const OriginatorAgreementsI& it,
const Time& now)
{
NS_LOG_FUNCTION(this << linkId << **mpduIt << +static_cast<uint8_t>(status));
Expand Down Expand Up @@ -411,8 +414,8 @@ BlockAckManager::NotifyGotAck(uint8_t linkId, Ptr<const WifiMpdu> mpdu)
Mac48Address recipient = mpdu->GetHeader().GetAddr1();
uint8_t tid = mpdu->GetHeader().GetQosTid();

AgreementsI it = m_agreements.find({recipient, tid});
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
NS_ASSERT(it->second.first.IsEstablished());

it->second.first.NotifyAckedMpdu(mpdu);
Expand All @@ -438,8 +441,8 @@ BlockAckManager::NotifyMissedAck(uint8_t linkId, Ptr<WifiMpdu> mpdu)
Mac48Address recipient = mpdu->GetHeader().GetAddr1();
uint8_t tid = mpdu->GetHeader().GetQosTid();

AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
NS_ASSERT(it->second.first.IsEstablished());

// remove the frame from the queue of outstanding packets (it will be re-inserted
Expand Down Expand Up @@ -475,8 +478,8 @@ BlockAckManager::NotifyGotBlockAck(uint8_t linkId,
tid = *tids.begin();
}

AgreementsI it = m_agreements.find({recipient, tid});
if (it == m_agreements.end() || !it->second.first.IsEstablished())
auto it = m_originatorAgreements.find({recipient, tid});
if (it == m_originatorAgreements.end() || !it->second.first.IsEstablished())
{
return {0, 0};
}
Expand Down Expand Up @@ -542,8 +545,8 @@ BlockAckManager::NotifyMissedBlockAck(uint8_t linkId, Mac48Address recipient, ui
{
NS_LOG_FUNCTION(this << linkId << recipient << +tid);

auto it = m_agreements.find({recipient, tid});
if (it == m_agreements.end() || !it->second.first.IsEstablished())
auto it = m_originatorAgreements.find({recipient, tid});
if (it == m_originatorAgreements.end() || !it->second.first.IsEstablished())
{
return;
}
Expand Down Expand Up @@ -577,8 +580,8 @@ BlockAckManager::NotifyDiscardedMpdu(Ptr<const WifiMpdu> mpdu)

Mac48Address recipient = mpdu->GetHeader().GetAddr1();
uint8_t tid = mpdu->GetHeader().GetQosTid();
AgreementsI it = m_agreements.find({recipient, tid});
if (it == m_agreements.end() || !it->second.first.IsEstablished())
auto it = m_originatorAgreements.find({recipient, tid});
if (it == m_originatorAgreements.end() || !it->second.first.IsEstablished())
{
NS_LOG_DEBUG("No established Block Ack agreement");
return;
Expand Down Expand Up @@ -638,8 +641,8 @@ CtrlBAckRequestHeader
BlockAckManager::GetBlockAckReqHeader(Mac48Address recipient, uint8_t tid) const
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsCI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());

CtrlBAckRequestHeader reqHdr;
reqHdr.SetType((*it).second.first.GetBlockAckReqType());
Expand Down Expand Up @@ -710,14 +713,14 @@ BlockAckManager::NotifyOriginatorAgreementEstablished(Mac48Address recipient,
uint16_t startingSeq)
{
NS_LOG_FUNCTION(this << recipient << +tid << startingSeq);
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
if (!it->second.first.IsEstablished())
{
m_agreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::ESTABLISHED);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::ESTABLISHED);
}
it->second.first.SetState(OriginatorBlockAckAgreement::ESTABLISHED);
it->second.first.SetStartingSequence(startingSeq);
Expand All @@ -727,11 +730,14 @@ void
BlockAckManager::NotifyOriginatorAgreementRejected(Mac48Address recipient, uint8_t tid)
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
if (!it->second.first.IsRejected())
{
m_agreementState(Simulator::Now(), recipient, tid, OriginatorBlockAckAgreement::REJECTED);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::REJECTED);
}
it->second.first.SetState(OriginatorBlockAckAgreement::REJECTED);
}
Expand All @@ -740,11 +746,14 @@ void
BlockAckManager::NotifyOriginatorAgreementNoReply(Mac48Address recipient, uint8_t tid)
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
if (!it->second.first.IsNoReply())
{
m_agreementState(Simulator::Now(), recipient, tid, OriginatorBlockAckAgreement::NO_REPLY);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::NO_REPLY);
}
it->second.first.SetState(OriginatorBlockAckAgreement::NO_REPLY);
m_unblockPackets(recipient, tid);
Expand All @@ -754,11 +763,14 @@ void
BlockAckManager::NotifyOriginatorAgreementReset(Mac48Address recipient, uint8_t tid)
{
NS_LOG_FUNCTION(this << recipient << +tid);
AgreementsI it = m_agreements.find(std::make_pair(recipient, tid));
NS_ASSERT(it != m_agreements.end());
auto it = m_originatorAgreements.find({recipient, tid});
NS_ASSERT(it != m_originatorAgreements.end());
if (!it->second.first.IsReset())
{
m_agreementState(Simulator::Now(), recipient, tid, OriginatorBlockAckAgreement::RESET);
m_originatorAgreementState(Simulator::Now(),
recipient,
tid,
OriginatorBlockAckAgreement::RESET);
}
it->second.first.SetState(OriginatorBlockAckAgreement::RESET);
}
Expand All @@ -773,8 +785,8 @@ BlockAckManager::SetQueue(const Ptr<WifiMacQueue> queue)
bool
BlockAckManager::NeedBarRetransmission(uint8_t tid, Mac48Address recipient)
{
AgreementsI it = m_agreements.find({recipient, tid});
if (it == m_agreements.end() || !it->second.first.IsEstablished())
auto it = m_originatorAgreements.find({recipient, tid});
if (it == m_originatorAgreements.end() || !it->second.first.IsEstablished())
{
// If the inactivity timer has expired, QosTxop::SendDelbaFrame has been called and
// has destroyed the agreement, hence we get here and correctly return false
Expand Down Expand Up @@ -842,8 +854,8 @@ uint16_t
BlockAckManager::GetRecipientBufferSize(Mac48Address recipient, uint8_t tid) const
{
uint16_t size = 0;
AgreementsCI it = m_agreements.find(std::make_pair(recipient, tid));
if (it != m_agreements.end())
auto it = m_originatorAgreements.find({recipient, tid});
if (it != m_originatorAgreements.end())
{
size = it->second.first.GetBufferSize();
}
Expand All @@ -854,8 +866,8 @@ uint16_t
BlockAckManager::GetOriginatorStartingSequence(Mac48Address recipient, uint8_t tid) const
{
uint16_t seqNum = 0;
AgreementsCI it = m_agreements.find(std::make_pair(recipient, tid));
if (it != m_agreements.end())
auto it = m_originatorAgreements.find({recipient, tid});
if (it != m_originatorAgreements.end())
{
seqNum = it->second.first.GetStartingSequence();
}
Expand Down
36 changes: 14 additions & 22 deletions src/wifi/model/block-ack-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,23 +417,15 @@ class BlockAckManager : public Object
* typedef for an iterator for PacketQueue.
*/
typedef std::list<Ptr<WifiMpdu>>::iterator PacketQueueI;
/**
* typedef for a map between MAC address and block ack agreement.
*/
typedef std::map<std::pair<Mac48Address, uint8_t>,
std::pair<OriginatorBlockAckAgreement, PacketQueue>>
Agreements;
/**
* typedef for an iterator for Agreements.
*/
typedef std::map<std::pair<Mac48Address, uint8_t>,
std::pair<OriginatorBlockAckAgreement, PacketQueue>>::iterator AgreementsI;
/**
* typedef for a const iterator for Agreements.
*/
typedef std::map<std::pair<Mac48Address, uint8_t>,
std::pair<OriginatorBlockAckAgreement, PacketQueue>>::const_iterator
AgreementsCI;

/// agreement key typedef (MAC address and TID)
using AgreementKey = std::pair<Mac48Address, uint8_t>;

/// AgreementKey-indexed map of originator block ack agreements
using OriginatorAgreements =
std::map<AgreementKey, std::pair<OriginatorBlockAckAgreement, PacketQueue>>;
/// typedef for an iterator for Agreements
using OriginatorAgreementsI = OriginatorAgreements::iterator;

/**
* Handle the given in flight MPDU based on its given status. If the status is
Expand All @@ -453,16 +445,16 @@ class BlockAckManager : public Object
PacketQueueI HandleInFlightMpdu(uint8_t linkId,
PacketQueueI mpduIt,
MpduStatus status,
const AgreementsI& it,
const OriginatorAgreementsI& it,
const Time& now);

/**
* This data structure contains, for each block ack agreement (recipient, TID), a set of packets
* for which an ack by block ack is requested.
* This data structure contains, for each originator block ack agreement (recipient, TID),
* a set of packets for which an ack by block ack is requested.
* Every packet or fragment indicated as correctly received in BlockAck frame is
* erased from this data structure. Pushed back in retransmission queue otherwise.
*/
Agreements m_agreements;
OriginatorAgreements m_originatorAgreements;

std::list<Bar> m_bars; ///< list of BARs

Expand All @@ -481,7 +473,7 @@ class BlockAckManager : public Object
* The trace source fired when a state transition occurred.
*/
TracedCallback<Time, Mac48Address, uint8_t, OriginatorBlockAckAgreement::State>
m_agreementState;
m_originatorAgreementState;
};

} // namespace ns3
Expand Down

0 comments on commit e318b39

Please sign in to comment.