Bug 2038 - Stop method does not stop next wave in WaveformGenerator
This commit is contained in:
@@ -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
|
||||
------------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <ns3/spectrum-phy.h>
|
||||
#include <ns3/spectrum-channel.h>
|
||||
#include <ns3/trace-source-accessor.h>
|
||||
#include <ns3/event-id.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -105,9 +106,9 @@ public:
|
||||
*/
|
||||
double GetDutyCycle () const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* set the AntennaModel to be used
|
||||
*
|
||||
*
|
||||
* \param a the Antenna Model
|
||||
*/
|
||||
void SetAntenna (Ptr<AntennaModel> a);
|
||||
@@ -139,7 +140,7 @@ private:
|
||||
Time m_period;
|
||||
double m_dutyCycle;
|
||||
Time m_startTime;
|
||||
bool m_active;
|
||||
EventId m_nextWave;
|
||||
|
||||
TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
|
||||
TracedCallback<Ptr<const Packet> > m_phyTxEndTrace;
|
||||
|
||||
121
src/spectrum/test/spectrum-waveform-generator-test.cc
Normal file
121
src/spectrum/test/spectrum-waveform-generator-test.cc
Normal file
@@ -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 <luisbelem@gmail.com>
|
||||
*/
|
||||
#include <ns3/core-module.h>
|
||||
#include <ns3/test.h>
|
||||
#include <ns3/spectrum-module.h>
|
||||
|
||||
|
||||
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<const Packet> newPkt);
|
||||
double m_period;
|
||||
double m_dutyCycle;
|
||||
double m_stop;
|
||||
int m_fails;
|
||||
};
|
||||
|
||||
void
|
||||
WaveformGeneratorTestCase::TraceWave (Ptr<const Packet> 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<SpectrumValue> txPsd = MicrowaveOvenSpectrumValueHelper::CreatePowerSpectralDensityMwo1 ();
|
||||
|
||||
SpectrumChannelHelper channelHelper = SpectrumChannelHelper::Default ();
|
||||
channelHelper.SetChannel ("ns3::SingleModelSpectrumChannel");
|
||||
Ptr<SpectrumChannel> channel = channelHelper.Create ();
|
||||
|
||||
Ptr<Node> n = CreateObject<Node> ();
|
||||
|
||||
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<WaveformGenerator> wave = waveformGeneratorDevices.Get (0)->GetObject<NonCommunicatingNetDevice> ()->GetPhy ()->GetObject<WaveformGenerator> ();
|
||||
|
||||
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;
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user