wifi: Extend helper to configure mapping between spectrum PHY interfaces and PHY instances

This commit is contained in:
Sharan Naribole
2023-08-07 20:13:21 +02:00
committed by Sébastien Deronne
parent 58ce22aa2f
commit 5439c98fe5
2 changed files with 62 additions and 5 deletions

View File

@@ -104,6 +104,19 @@ SpectrumWifiPhyHelper::AddWifiBandwidthFilter(Ptr<SpectrumChannel> channel)
}
}
void
SpectrumWifiPhyHelper::AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange& freqRange)
{
if (auto it = m_interfacesMap.find(linkId); it == m_interfacesMap.end())
{
m_interfacesMap.insert({linkId, {freqRange}});
}
else
{
it->second.emplace(freqRange);
}
}
std::vector<Ptr<WifiPhy>>
SpectrumWifiPhyHelper::Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const
{
@@ -114,7 +127,7 @@ SpectrumWifiPhyHelper::Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const
auto phy = m_phys.at(i).Create<SpectrumWifiPhy>();
auto interference = m_interferenceHelper.Create<InterferenceHelper>();
phy->SetInterferenceHelper(interference);
Ptr<ErrorRateModel> error = m_errorRateModel.at(i).Create<ErrorRateModel>();
auto error = m_errorRateModel.at(i).Create<ErrorRateModel>();
phy->SetErrorRateModel(error);
if (m_frameCaptureModel.at(i).IsTypeIdSet())
{
@@ -127,10 +140,7 @@ SpectrumWifiPhyHelper::Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const
m_preambleDetectionModel.at(i).Create<PreambleDetectionModel>();
phy->SetPreambleDetectionModel(preambleDetection);
}
for (const auto& [freqRange, channel] : m_channels)
{
phy->AddChannel(channel, freqRange);
}
InstallPhyInterfaces(i, phy);
phy->SetDevice(device);
phy->SetMobility(node->GetObject<MobilityModel>());
ret.emplace_back(phy);
@@ -139,4 +149,24 @@ SpectrumWifiPhyHelper::Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const
return ret;
}
void
SpectrumWifiPhyHelper::InstallPhyInterfaces(uint8_t linkId, Ptr<SpectrumWifiPhy> phy) const
{
if (m_interfacesMap.count(linkId) == 0)
{
// default setup: set all interfaces to this link
for (const auto& [freqRange, channel] : m_channels)
{
phy->AddChannel(channel, freqRange);
}
}
else
{
for (const auto& freqRange : m_interfacesMap.at(linkId))
{
phy->AddChannel(m_channels.at(freqRange), freqRange);
}
}
}
} // namespace ns3

View File

@@ -22,10 +22,14 @@
#include "wifi-helper.h"
#include <map>
#include <set>
namespace ns3
{
class SpectrumChannel;
class SpectrumWifiPhy;
/**
* \brief Make it easy to create and manage PHY objects for the spectrum model.
@@ -81,6 +85,16 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper
void AddChannel(const std::string& channelName,
const FrequencyRange& freqRange = WHOLE_WIFI_SPECTRUM);
/**
* Add a given spectrum PHY interface to the PHY instance corresponding of a given link.
* If no mapping has been specified for a given link, all spectrum PHY interfaces will
* be added to the PHY instance of that link.
*
* \param linkId ID of the link to setup
* \param freqRange frequency range handled by of the spectrum PHY interface
*/
void AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange& freqRange);
private:
/**
* \param node the node on which we wish to create a wifi PHY
@@ -90,6 +104,16 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper
* This method implements the pure virtual method defined in \ref ns3::WifiPhyHelper.
*/
std::vector<Ptr<WifiPhy>> Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const override;
/**
* \brief Install PHY interfaces to the PHY instance of a given link
* based on the currently configured mapping (\see AddPhyInterface).
*
* \param linkId ID of the link to setup
* \param phy spectrum PHY instance of the link
*/
void InstallPhyInterfaces(uint8_t linkId, Ptr<SpectrumWifiPhy> phy) const;
/**
* \param channel The channel to inspect to possibly add a WifiBandwidthFilter
*
@@ -99,6 +123,9 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper
void AddWifiBandwidthFilter(Ptr<SpectrumChannel> channel);
std::map<FrequencyRange, Ptr<SpectrumChannel>> m_channels; ///< the spectrum channels
std::map<uint8_t /* linkId */, std::set<FrequencyRange>>
m_interfacesMap; ///< map of the spectrum PHY interfaces to be added to the PHY instance
///< corresponding to a given link ID
};
} // namespace ns3