A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-waveform-generator-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Luis Pacheco <luisbelem@gmail.com>
18 */
19#include <ns3/core-module.h>
20#include <ns3/spectrum-module.h>
21#include <ns3/test.h>
22
23NS_LOG_COMPONENT_DEFINE("WaveformGeneratorTest");
24
25using namespace ns3;
26
33{
34 public:
42 WaveformGeneratorTestCase(double period, double dutyCycle, double stop);
44
45 private:
46 void DoRun() override;
47
52 void TraceWave(Ptr<const Packet> newPkt);
53 double m_period;
54 double m_dutyCycle;
55 double m_stop;
56 int m_fails;
57};
58
59void
61{
62 if (Now().GetSeconds() > m_stop)
63 {
64 m_fails++;
65 }
66}
67
68WaveformGeneratorTestCase::WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
69 : TestCase("Check stop method"),
70 m_period(period),
71 m_dutyCycle(dutyCycle),
72 m_stop(stop),
73 m_fails(0)
74{
75}
76
78{
79}
80
81void
83{
85
87 channelHelper.SetChannel("ns3::SingleModelSpectrumChannel");
88 Ptr<SpectrumChannel> channel = channelHelper.Create();
89
90 Ptr<Node> n = CreateObject<Node>();
91
92 WaveformGeneratorHelper waveformGeneratorHelper;
93 waveformGeneratorHelper.SetTxPowerSpectralDensity(txPsd);
94 waveformGeneratorHelper.SetChannel(channel);
95 waveformGeneratorHelper.SetPhyAttribute("Period", TimeValue(Seconds(m_period)));
96 waveformGeneratorHelper.SetPhyAttribute("DutyCycle", DoubleValue(m_dutyCycle));
97 NetDeviceContainer waveformGeneratorDevices = waveformGeneratorHelper.Install(n);
98
99 Ptr<WaveformGenerator> wave = waveformGeneratorDevices.Get(0)
100 ->GetObject<NonCommunicatingNetDevice>()
101 ->GetPhy()
103
104 wave->TraceConnectWithoutContext("TxStart",
106
109
112
113 NS_TEST_ASSERT_MSG_EQ(m_fails, 0, "Wave started after the stop method was called");
114
116}
117
124{
125 public:
127};
128
130 : TestSuite("waveform-generator", SYSTEM)
131{
132 NS_LOG_INFO("creating WaveformGeneratorTestSuite");
133
134 // Stop while wave is active
136 // Stop after wave
138}
139
double m_period
waveform period (seconds)
void DoRun() override
Implementation to actually run this TestCase.
void TraceWave(Ptr< const Packet > newPkt)
Trace if the waveform is active.
WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
Constructor.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
This class implements a device which does not communicate, in the sense that it does not interact wit...
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Setup a SpectrumChannel.
Ptr< SpectrumChannel > Create() const
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void SetChannel(std::string type, Ts &&... args)
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
AttributeValue implementation for Time.
Definition: nstime.h:1423
Create a Waveform generator, which can be used to inject specific noise in the channel.
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
Simple SpectrumPhy implementation that sends customizable waveform.
virtual void Start()
Start the waveform generator.
virtual void Stop()
Stop the waveform generator.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:702
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite
Static variable for test initialization.