From b1b21c4883938f74241a257f6efa9d62caaffe28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Wed, 13 Sep 2023 12:43:47 +0200 Subject: [PATCH] wifi: Configure interfaces of all spectrum PHYs when the channel of one instance has changed --- examples/wireless/examples-to-run.py | 2 +- src/wifi/helper/spectrum-wifi-helper.cc | 30 +++++++++++++++++++++++++ src/wifi/helper/spectrum-wifi-helper.h | 6 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/examples/wireless/examples-to-run.py b/examples/wireless/examples-to-run.py index 7eef186fe..3acd036ee 100755 --- a/examples/wireless/examples-to-run.py +++ b/examples/wireless/examples-to-run.py @@ -60,7 +60,7 @@ cpp_examples = [ ("wifi-eht-network --simulationTime=0.1 --frequency=5 --useRts=1 --minExpectedThroughput=6 --maxExpectedThroughput=547", "True", "True"), ("wifi-eht-network --simulationTime=0.1 --frequency=2.4 --useRts=0 --useExtendedBlockAck=1 --frequency2=5 --minExpectedThroughput=12 --maxExpectedThroughput=500", "True", "True"), ("wifi-eht-network --simulationTime=0.1 --frequency=2.4 --useRts=1 --minExpectedThroughput=6 --maxExpectedThroughput=212", "True", "True"), - ("wifi-eht-network --simulationTime=0.22 --udp=0 --downlink=1 --useRts=0 --nStations=4 --dlAckType=ACK-SU-FORMAT --enableUlOfdma=1 --enableBsrp=0 --mcs=4 --frequency2=6 --minExpectedThroughput=35 --maxExpectedThroughput=280", "True", "True"), + ("wifi-eht-network --simulationTime=0.23 --udp=0 --downlink=1 --useRts=0 --nStations=4 --dlAckType=ACK-SU-FORMAT --enableUlOfdma=1 --enableBsrp=0 --mcs=4 --frequency2=6 --minExpectedThroughput=35 --maxExpectedThroughput=280", "True", "True"), ("wifi-eht-network --simulationTime=0.25 --frequency=2.4 --udp=0 --downlink=1 --useRts=0 --nStations=5 --dlAckType=MU-BAR --enableUlOfdma=1 --enableBsrp=1 --mcs=5 --frequency2=5 --useExtendedBlockAck=1 --minExpectedThroughput=40 --maxExpectedThroughput=100", "True", "True"), ("wifi-eht-network --simulationTime=0.3 --udp=0 --downlink=1 --useRts=1 --nStations=5 --dlAckType=AGGR-MU-BAR --enableUlOfdma=1 --enableBsrp=0 --mcs=6 --muSchedAccessReqInterval=50ms --frequency2=2.4 --minExpectedThroughput=50 --maxExpectedThroughput=140", "True", "True"), ("wifi-eht-network --simulationTime=0.2 --udp=1 --downlink=0 --useRts=0 --nStations=5 --dlAckType=AGGR-MU-BAR --enableUlOfdma=1 --enableBsrp=1 --mcs=5 --muSchedAccessReqInterval=50ms --frequency2=6 --minExpectedThroughput=70 --maxExpectedThroughput=715", "True", "True"), diff --git a/src/wifi/helper/spectrum-wifi-helper.cc b/src/wifi/helper/spectrum-wifi-helper.cc index dad7ccc4d..abd21004d 100644 --- a/src/wifi/helper/spectrum-wifi-helper.cc +++ b/src/wifi/helper/spectrum-wifi-helper.cc @@ -147,6 +147,8 @@ SpectrumWifiPhyHelper::Create(Ptr node, Ptr device) const phy->SetPreambleDetectionModel(preambleDetection); } InstallPhyInterfaces(i, phy); + phy->SetChannelSwitchedCallback( + MakeCallback(&SpectrumWifiPhyHelper::SpectrumChannelSwitched, this).Bind(phy)); phy->SetDevice(device); phy->SetMobility(node->GetObject()); ret.emplace_back(phy); @@ -175,4 +177,32 @@ SpectrumWifiPhyHelper::InstallPhyInterfaces(uint8_t linkId, Ptr } } +void +SpectrumWifiPhyHelper::SpectrumChannelSwitched(Ptr phy) const +{ + NS_LOG_FUNCTION(this << phy); + for (const auto& otherPhy : phy->GetDevice()->GetPhys()) + { + auto spectrumPhy = DynamicCast(otherPhy); + NS_ASSERT(spectrumPhy); + if (spectrumPhy == phy) + { + // this is the PHY that has switched + continue; + } + if (spectrumPhy->GetCurrentFrequencyRange() == phy->GetCurrentFrequencyRange()) + { + // this is the active interface + continue; + } + if (const auto& interfaces = spectrumPhy->GetSpectrumPhyInterfaces(); + interfaces.count(phy->GetCurrentFrequencyRange()) == 0) + { + // no interface attached to that channel + continue; + } + spectrumPhy->ConfigureInterface(phy->GetFrequency(), phy->GetChannelWidth()); + } +} + } // namespace ns3 diff --git a/src/wifi/helper/spectrum-wifi-helper.h b/src/wifi/helper/spectrum-wifi-helper.h index 0985a3c1f..481f2ece2 100644 --- a/src/wifi/helper/spectrum-wifi-helper.h +++ b/src/wifi/helper/spectrum-wifi-helper.h @@ -119,6 +119,12 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper */ void InstallPhyInterfaces(uint8_t linkId, Ptr phy) const; + /** + * Function that is notified when a spectrum channel switched + * \param phy spectrum PHY instance that has switched its channel + */ + void SpectrumChannelSwitched(Ptr phy) const; + /** * \param channel The channel to inspect to possibly add a WifiBandwidthFilter *