From 0901e95ce479eefd7e2600f699f614410f735864 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Thu, 18 May 2023 19:57:08 +0200 Subject: [PATCH] wifi: Add Txop support for link swapping --- src/wifi/model/qos-txop.cc | 8 ++-- src/wifi/model/txop.cc | 87 ++++++++++++++++++++++++-------------- src/wifi/model/txop.h | 22 +++++++--- src/wifi/model/wifi-mac.cc | 13 ++++++ 4 files changed, 88 insertions(+), 42 deletions(-) diff --git a/src/wifi/model/qos-txop.cc b/src/wifi/model/qos-txop.cc index fb5233e93..8d02ea937 100644 --- a/src/wifi/model/qos-txop.cc +++ b/src/wifi/model/qos-txop.cc @@ -640,9 +640,9 @@ QosTxop::GotAddBaResponse(const MgtAddBaResponseHeader& respHdr, Mac48Address re m_baManager->NotifyOriginatorAgreementRejected(recipient, tid); } - for (uint8_t linkId = 0; linkId < GetNLinks(); linkId++) + for (const auto& [id, link] : GetLinks()) { - StartAccessIfNeeded(linkId); + StartAccessIfNeeded(id); } } @@ -662,9 +662,9 @@ QosTxop::NotifyOriginatorAgreementNoReply(const Mac48Address& recipient, uint8_t m_baManager->NotifyOriginatorAgreementNoReply(recipient, tid); // the recipient has been "unblocked" and transmissions can resume using normal // acknowledgment, hence start access (if needed) on all the links - for (uint8_t linkId = 0; linkId < GetNLinks(); linkId++) + for (const auto& [id, link] : GetLinks()) { - StartAccessIfNeeded(linkId); + StartAccessIfNeeded(id); } } diff --git a/src/wifi/model/txop.cc b/src/wifi/model/txop.cc index 011b97deb..1a645db79 100644 --- a/src/wifi/model/txop.cc +++ b/src/wifi/model/txop.cc @@ -169,15 +169,33 @@ Txop::CreateLinkEntity() const Txop::LinkEntity& Txop::GetLink(uint8_t linkId) const { - NS_ASSERT(linkId < m_links.size()); - NS_ASSERT(m_links.at(linkId)); // check that the pointer owns an object - return *m_links.at(linkId); + auto it = m_links.find(linkId); + NS_ASSERT(it != m_links.cend()); + NS_ASSERT(it->second); // check that the pointer owns an object + return *it->second; } -uint8_t -Txop::GetNLinks() const +const std::map>& +Txop::GetLinks() const { - return m_links.size(); + return m_links; +} + +void +Txop::SwapLinks(std::map links) +{ + NS_LOG_FUNCTION(this); + + decltype(m_links) tmp; + tmp.swap(m_links); // move all links to temporary map + for (const auto& [from, to] : links) + { + auto nh = tmp.extract(from); + nh.key() = to; + m_links.insert(std::move(nh)); + } + // move links remaining in tmp to m_links + m_links.merge(tmp); } void @@ -192,12 +210,9 @@ Txop::SetWifiMac(const Ptr mac) { NS_LOG_FUNCTION(this << mac); m_mac = mac; - m_links.resize(m_mac->GetNLinks()); - uint8_t linkId = 0; - for (auto& link : m_links) + for (const auto linkId : m_mac->GetLinkIds()) { - link = CreateLinkEntity(); - link->id = linkId++; + m_links.emplace(linkId, CreateLinkEntity()); } } @@ -229,9 +244,10 @@ void Txop::SetMinCws(std::vector minCws) { NS_ABORT_IF(minCws.size() != m_links.size()); - for (std::size_t linkId = 0; linkId < minCws.size(); linkId++) + std::size_t i = 0; + for (const auto& [id, link] : m_links) { - SetMinCw(minCws[linkId], linkId); + SetMinCw(minCws[i++], id); } } @@ -258,9 +274,10 @@ void Txop::SetMaxCws(std::vector maxCws) { NS_ABORT_IF(maxCws.size() != m_links.size()); - for (std::size_t linkId = 0; linkId < maxCws.size(); linkId++) + std::size_t i = 0; + for (const auto& [id, link] : m_links) { - SetMaxCw(maxCws[linkId], linkId); + SetMaxCw(maxCws[i++], id); } } @@ -355,9 +372,10 @@ void Txop::SetAifsns(std::vector aifsns) { NS_ABORT_IF(aifsns.size() != m_links.size()); - for (std::size_t linkId = 0; linkId < aifsns.size(); linkId++) + std::size_t i = 0; + for (const auto& [id, link] : m_links) { - SetAifsn(aifsns[linkId], linkId); + SetAifsn(aifsns[i++], id); } } @@ -381,9 +399,10 @@ Txop::SetTxopLimits(const std::vector