From 1ab959a5121a044481eacfc1fe6c4df36de4a209 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Mon, 1 May 2023 13:07:07 +0200 Subject: [PATCH] wifi: Add a method to get the link on which a PHY is operating --- src/wifi/model/wifi-mac.cc | 21 +++++++++++++++++++++ src/wifi/model/wifi-mac.h | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/wifi/model/wifi-mac.cc b/src/wifi/model/wifi-mac.cc index 830360723..abfe6e69c 100644 --- a/src/wifi/model/wifi-mac.cc +++ b/src/wifi/model/wifi-mac.cc @@ -963,6 +963,27 @@ WifiMac::GetLinkIdByAddress(const Mac48Address& address) const return std::nullopt; } +std::optional +WifiMac::GetLinkForPhy(Ptr phy) const +{ + for (const auto& [id, link] : m_links) + { + if (link->phy == phy) + { + return id; + } + } + return std::nullopt; +} + +std::optional +WifiMac::GetLinkForPhy(std::size_t phyId) const +{ + NS_ABORT_UNLESS(phyId < m_device->GetNPhys()); + auto phy = m_device->GetPhy(phyId); + return GetLinkForPhy(phy); +} + void WifiMac::SwapLinks(std::map links) { diff --git a/src/wifi/model/wifi-mac.h b/src/wifi/model/wifi-mac.h index 1f167669b..a95521ac0 100644 --- a/src/wifi/model/wifi-mac.h +++ b/src/wifi/model/wifi-mac.h @@ -150,6 +150,22 @@ class WifiMac : public Object */ virtual std::optional GetLinkIdByAddress(const Mac48Address& address) const; + /** + * Get the ID of the link (if any) on which the given PHY is operating. + * + * \param phy the given PHY + * \return the ID of the link (if any) on which the given PHY is operating + */ + std::optional GetLinkForPhy(Ptr phy) const; + + /** + * Get the ID of the link (if any) on which the given PHY is operating. + * + * \param phyId the index of the given PHY in the vector of PHYs held by WifiNetDevice + * \return the ID of the link (if any) on which the given PHY is operating + */ + std::optional GetLinkForPhy(std::size_t phyId) const; + /** * \param remoteAddr the (MLD or link) address of a remote device * \return the MLD address of the remote device having the given (MLD or link) address, if