diff --git a/src/spectrum/model/spectrum-channel.cc b/src/spectrum/model/spectrum-channel.cc index 596a45ea7..068380c9a 100644 --- a/src/spectrum/model/spectrum-channel.cc +++ b/src/spectrum/model/spectrum-channel.cc @@ -158,6 +158,12 @@ SpectrumChannel::AddSpectrumTransmitFilter(Ptr filter) m_filter = filter; } +Ptr +SpectrumChannel::GetSpectrumTransmitFilter() const +{ + return m_filter; +} + void SpectrumChannel::SetPropagationDelayModel(Ptr delay) { diff --git a/src/spectrum/model/spectrum-channel.h b/src/spectrum/model/spectrum-channel.h index e7114002c..f4708fbd3 100644 --- a/src/spectrum/model/spectrum-channel.h +++ b/src/spectrum/model/spectrum-channel.h @@ -125,6 +125,13 @@ class SpectrumChannel : public Channel */ void AddSpectrumTransmitFilter(Ptr 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 GetSpectrumTransmitFilter() const; + /** * Used by attached PHY instances to transmit signals on the channel * diff --git a/src/spectrum/model/spectrum-transmit-filter.cc b/src/spectrum/model/spectrum-transmit-filter.cc index 42f5a4819..076285d6f 100644 --- a/src/spectrum/model/spectrum-transmit-filter.cc +++ b/src/spectrum/model/spectrum-transmit-filter.cc @@ -61,6 +61,12 @@ SpectrumTransmitFilter::SetNext(Ptr next) m_next = next; } +Ptr +SpectrumTransmitFilter::GetNext() const +{ + return m_next; +} + bool SpectrumTransmitFilter::Filter(Ptr params, Ptr receiverPhy) diff --git a/src/spectrum/model/spectrum-transmit-filter.h b/src/spectrum/model/spectrum-transmit-filter.h index f13d408ab..b004f7102 100644 --- a/src/spectrum/model/spectrum-transmit-filter.h +++ b/src/spectrum/model/spectrum-transmit-filter.h @@ -55,6 +55,13 @@ class SpectrumTransmitFilter : public Object */ void SetNext(Ptr next); + /** + * Return the next transmit filter in the chain + * + * \return next transmit filter in the chain + */ + Ptr GetNext() const; + /** * Evaluate whether the signal to be scheduled on the receiving Phy should * instead be filtered (discarded) before being processed in this channel diff --git a/src/wifi/helper/spectrum-wifi-helper.cc b/src/wifi/helper/spectrum-wifi-helper.cc index 55b1757b2..149397101 100644 --- a/src/wifi/helper/spectrum-wifi-helper.cc +++ b/src/wifi/helper/spectrum-wifi-helper.cc @@ -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 channel) { m_channels[WHOLE_WIFI_SPECTRUM] = channel; + AddWifiBandwidthFilter(channel); } void @@ -60,6 +63,7 @@ SpectrumWifiPhyHelper::SetChannel(const std::string& channelName) { Ptr channel = Names::Find(channelName); m_channels[WHOLE_WIFI_SPECTRUM] = channel; + AddWifiBandwidthFilter(channel); } void @@ -67,6 +71,7 @@ SpectrumWifiPhyHelper::AddChannel(const Ptr channel, const FrequencyRange& freqRange) { m_channels[freqRange] = channel; + AddWifiBandwidthFilter(channel); } void @@ -74,6 +79,33 @@ SpectrumWifiPhyHelper::AddChannel(const std::string& channelName, const Frequenc { Ptr channel = Names::Find(channelName); AddChannel(channel, freqRange); + AddWifiBandwidthFilter(channel); +} + +void +SpectrumWifiPhyHelper::AddWifiBandwidthFilter(Ptr channel) +{ + Ptr p = channel->GetSpectrumTransmitFilter(); + bool found = false; + while (p && !found) + { + if (DynamicCast(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 pWifi = CreateObject(); + channel->AddSpectrumTransmitFilter(pWifi); + NS_LOG_DEBUG("Adding WifiBandwidthFilter to channel " << channel); + } } std::vector> diff --git a/src/wifi/helper/spectrum-wifi-helper.h b/src/wifi/helper/spectrum-wifi-helper.h index 78d093895..a58cfeed7 100644 --- a/src/wifi/helper/spectrum-wifi-helper.h +++ b/src/wifi/helper/spectrum-wifi-helper.h @@ -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> Create(Ptr node, Ptr 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 channel); std::map> m_channels; ///< the spectrum channels };