Add WifiBandwidthFilter automatically with SpectrumWifiPhyHelper

This commit is contained in:
Tom Henderson
2022-12-15 18:40:42 -08:00
parent a9f496456d
commit 29f27e6fde
6 changed files with 68 additions and 0 deletions

View File

@@ -158,6 +158,12 @@ SpectrumChannel::AddSpectrumTransmitFilter(Ptr<SpectrumTransmitFilter> filter)
m_filter = filter;
}
Ptr<const SpectrumTransmitFilter>
SpectrumChannel::GetSpectrumTransmitFilter() const
{
return m_filter;
}
void
SpectrumChannel::SetPropagationDelayModel(Ptr<PropagationDelayModel> delay)
{

View File

@@ -125,6 +125,13 @@ class SpectrumChannel : public Channel
*/
void AddSpectrumTransmitFilter(Ptr<SpectrumTransmitFilter> filter);
/**
* Get the transmit filter, or first in a chain of transmit filters
* if more than one is present.
* \returns a pointer to the transmit filter.
*/
Ptr<const SpectrumTransmitFilter> GetSpectrumTransmitFilter() const;
/**
* Used by attached PHY instances to transmit signals on the channel
*

View File

@@ -61,6 +61,12 @@ SpectrumTransmitFilter::SetNext(Ptr<SpectrumTransmitFilter> next)
m_next = next;
}
Ptr<const SpectrumTransmitFilter>
SpectrumTransmitFilter::GetNext() const
{
return m_next;
}
bool
SpectrumTransmitFilter::Filter(Ptr<const SpectrumSignalParameters> params,
Ptr<const SpectrumPhy> receiverPhy)

View File

@@ -55,6 +55,13 @@ class SpectrumTransmitFilter : public Object
*/
void SetNext(Ptr<SpectrumTransmitFilter> next);
/**
* Return the next transmit filter in the chain
*
* \return next transmit filter in the chain
*/
Ptr<const SpectrumTransmitFilter> GetNext() const;
/**
* Evaluate whether the signal to be scheduled on the receiving Phy should
* instead be filtered (discarded) before being processed in this channel

View File

@@ -28,7 +28,9 @@
#include "ns3/names.h"
#include "ns3/preamble-detection-model.h"
#include "ns3/spectrum-channel.h"
#include "ns3/spectrum-transmit-filter.h"
#include "ns3/spectrum-wifi-phy.h"
#include "ns3/wifi-bandwidth-filter.h"
#include "ns3/wifi-net-device.h"
#include "ns3/wifi-spectrum-value-helper.h"
@@ -53,6 +55,7 @@ void
SpectrumWifiPhyHelper::SetChannel(const Ptr<SpectrumChannel> channel)
{
m_channels[WHOLE_WIFI_SPECTRUM] = channel;
AddWifiBandwidthFilter(channel);
}
void
@@ -60,6 +63,7 @@ SpectrumWifiPhyHelper::SetChannel(const std::string& channelName)
{
Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
m_channels[WHOLE_WIFI_SPECTRUM] = channel;
AddWifiBandwidthFilter(channel);
}
void
@@ -67,6 +71,7 @@ SpectrumWifiPhyHelper::AddChannel(const Ptr<SpectrumChannel> channel,
const FrequencyRange& freqRange)
{
m_channels[freqRange] = channel;
AddWifiBandwidthFilter(channel);
}
void
@@ -74,6 +79,33 @@ SpectrumWifiPhyHelper::AddChannel(const std::string& channelName, const Frequenc
{
Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
AddChannel(channel, freqRange);
AddWifiBandwidthFilter(channel);
}
void
SpectrumWifiPhyHelper::AddWifiBandwidthFilter(Ptr<SpectrumChannel> channel)
{
Ptr<const SpectrumTransmitFilter> p = channel->GetSpectrumTransmitFilter();
bool found = false;
while (p && !found)
{
if (DynamicCast<const WifiBandwidthFilter>(p))
{
NS_LOG_DEBUG("Found existing WifiBandwidthFilter for channel " << channel);
found = true;
}
else
{
NS_LOG_DEBUG("Found different SpectrumTransmitFilter for channel " << channel);
p = p->GetNext();
}
}
if (!found)
{
Ptr<WifiBandwidthFilter> pWifi = CreateObject<WifiBandwidthFilter>();
channel->AddSpectrumTransmitFilter(pWifi);
NS_LOG_DEBUG("Adding WifiBandwidthFilter to channel " << channel);
}
}
std::vector<Ptr<WifiPhy>>

View File

@@ -33,6 +33,9 @@ class SpectrumChannel;
* The Pcap and ASCII traces generated by the EnableAscii and EnablePcap methods defined
* in this class correspond to PHY-level traces and come to us via WifiPhyHelper
*
* This helper will install an instance of a WifiBandwidthFilter on any SpectrumChannel
* added to this helper (via one of the SetChannel methods), unless one has
* previously been installed on the channel object.
*/
class SpectrumWifiPhyHelper : public WifiPhyHelper
{
@@ -87,6 +90,13 @@ 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;
/**
* \param channel The channel to inspect to possibly add a WifiBandwidthFilter
*
* This method will add a WifiBandwidthFilter object to the SpectrumChannel, only if
* one has not yet been added.
*/
void AddWifiBandwidthFilter(Ptr<SpectrumChannel> channel);
std::map<FrequencyRange, Ptr<SpectrumChannel>> m_channels; ///< the spectrum channels
};