diff --git a/RELEASE_NOTES b/RELEASE_NOTES index f4c0daaa1..596753d0f 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -55,6 +55,7 @@ Bugs fixed - Bug 2028 - remove unnecessary Time to double conversions in Wifi models - Bug 2029 - new CQI generation approach fix - Bug 2030 - provide default values for WifiTxVector +- Bug 2038 - Stop method does not stop next wave in WaveformGenerator Known issues ------------ diff --git a/src/spectrum/model/waveform-generator.cc b/src/spectrum/model/waveform-generator.cc index 59bf2257c..eaa06d74a 100644 --- a/src/spectrum/model/waveform-generator.cc +++ b/src/spectrum/model/waveform-generator.cc @@ -36,11 +36,10 @@ NS_OBJECT_ENSURE_REGISTERED (WaveformGenerator); WaveformGenerator::WaveformGenerator () : m_mobility (0), - m_netDevice (0), - m_channel (0), - m_txPowerSpectralDensity (0), - m_startTime (Seconds (0)), - m_active (false) + m_netDevice (0), + m_channel (0), + m_txPowerSpectralDensity (0), + m_startTime (Seconds (0)) { } @@ -59,6 +58,10 @@ WaveformGenerator::DoDispose (void) m_channel = 0; m_netDevice = 0; m_mobility = 0; + if (m_nextWave.IsRunning ()) + { + m_nextWave.Cancel (); + } } TypeId @@ -205,11 +208,8 @@ WaveformGenerator::GenerateWaveform () m_phyTxStartTrace (0); m_channel->StartTx (txParams); - if (m_active) - { - NS_LOG_LOGIC ("scheduling next waveform"); - Simulator::Schedule (m_period, &WaveformGenerator::GenerateWaveform, this); - } + NS_LOG_LOGIC ("scheduling next waveform"); + m_nextWave = Simulator::Schedule (m_period, &WaveformGenerator::GenerateWaveform, this); } @@ -217,12 +217,11 @@ void WaveformGenerator::Start () { NS_LOG_FUNCTION (this); - if (!m_active) + if (!m_nextWave.IsRunning ()) { NS_LOG_LOGIC ("generator was not active, now starting"); - m_active = true; m_startTime = Now (); - Simulator::ScheduleNow (&WaveformGenerator::GenerateWaveform, this); + m_nextWave = Simulator::ScheduleNow (&WaveformGenerator::GenerateWaveform, this); } } @@ -231,8 +230,10 @@ void WaveformGenerator::Stop () { NS_LOG_FUNCTION (this); - m_active = false; + if (m_nextWave.IsRunning ()) + { + m_nextWave.Cancel (); + + } } - - } // namespace ns3 diff --git a/src/spectrum/model/waveform-generator.h b/src/spectrum/model/waveform-generator.h index 0acf0c1eb..b59cbd1af 100644 --- a/src/spectrum/model/waveform-generator.h +++ b/src/spectrum/model/waveform-generator.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace ns3 { @@ -105,9 +106,9 @@ public: */ double GetDutyCycle () const; - /** + /** * set the AntennaModel to be used - * + * * \param a the Antenna Model */ void SetAntenna (Ptr a); @@ -139,7 +140,7 @@ private: Time m_period; double m_dutyCycle; Time m_startTime; - bool m_active; + EventId m_nextWave; TracedCallback > m_phyTxStartTrace; TracedCallback > m_phyTxEndTrace; diff --git a/src/spectrum/test/spectrum-waveform-generator-test.cc b/src/spectrum/test/spectrum-waveform-generator-test.cc new file mode 100644 index 000000000..1b480262e --- /dev/null +++ b/src/spectrum/test/spectrum-waveform-generator-test.cc @@ -0,0 +1,121 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 CTTC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Luis Pacheco + */ +#include +#include +#include + + +NS_LOG_COMPONENT_DEFINE ("WaveformGeneratorTest"); + +using namespace ns3; + + + +class WaveformGeneratorTestCase : public TestCase +{ +public: + WaveformGeneratorTestCase (double period, double dutyCycle, double stop); + virtual ~WaveformGeneratorTestCase (); + +private: + virtual void DoRun (void); + + void TraceWave (Ptr newPkt); + double m_period; + double m_dutyCycle; + double m_stop; + int m_fails; +}; + +void +WaveformGeneratorTestCase::TraceWave (Ptr newPkt) +{ + if (Now ().GetSeconds () > m_stop) + { + m_fails++; + } +} + +WaveformGeneratorTestCase::WaveformGeneratorTestCase (double period, double dutyCycle, double stop) + : TestCase ("Check stop method"), + m_period (period), + m_dutyCycle (dutyCycle), + m_stop (stop), + m_fails (0) +{ +} + +WaveformGeneratorTestCase::~WaveformGeneratorTestCase () +{ +} + + +void +WaveformGeneratorTestCase::DoRun (void) +{ + Ptr txPsd = MicrowaveOvenSpectrumValueHelper::CreatePowerSpectralDensityMwo1 (); + + SpectrumChannelHelper channelHelper = SpectrumChannelHelper::Default (); + channelHelper.SetChannel ("ns3::SingleModelSpectrumChannel"); + Ptr channel = channelHelper.Create (); + + Ptr n = CreateObject (); + + WaveformGeneratorHelper waveformGeneratorHelper; + waveformGeneratorHelper.SetTxPowerSpectralDensity (txPsd); + waveformGeneratorHelper.SetChannel (channel); + waveformGeneratorHelper.SetPhyAttribute ("Period", TimeValue (Seconds (m_period))); + waveformGeneratorHelper.SetPhyAttribute ("DutyCycle", DoubleValue (m_dutyCycle)); + NetDeviceContainer waveformGeneratorDevices = waveformGeneratorHelper.Install (n); + + Ptr wave = waveformGeneratorDevices.Get (0)->GetObject ()->GetPhy ()->GetObject (); + + wave->TraceConnectWithoutContext ("TxStart", MakeCallback (&WaveformGeneratorTestCase::TraceWave,this)); + + Simulator::Schedule (Seconds (1.0), &WaveformGenerator::Start, wave); + Simulator::Schedule (Seconds (m_stop), &WaveformGenerator::Stop, wave); + + Simulator::Stop (Seconds (3.0)); + Simulator::Run (); + + NS_TEST_ASSERT_MSG_EQ (m_fails, 0, "Wave started after the stop method was called"); + + Simulator::Destroy (); +} + + +class WaveformGeneratorTestSuite : public TestSuite +{ +public: + WaveformGeneratorTestSuite (); +}; + +WaveformGeneratorTestSuite::WaveformGeneratorTestSuite () + : TestSuite ("waveform-generator", SYSTEM) +{ + NS_LOG_INFO ("creating WaveformGeneratorTestSuite"); + + // Stop while wave is active + AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.2), TestCase::QUICK); + // Stop after wave + AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.7), TestCase::QUICK); +} + +static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite; diff --git a/src/spectrum/wscript b/src/spectrum/wscript index 211fdef3e..1114f9028 100644 --- a/src/spectrum/wscript +++ b/src/spectrum/wscript @@ -39,6 +39,7 @@ def build(bld): 'test/spectrum-interference-test.cc', 'test/spectrum-value-test.cc', 'test/spectrum-ideal-phy-test.cc', + 'test/spectrum-waveform-generator-test.cc', ] headers = bld(features='ns3header')