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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Luis Pacheco <luisbelem@gmail.com>
7 */
8#include <ns3/core-module.h>
9#include <ns3/spectrum-module.h>
10#include <ns3/test.h>
11
12NS_LOG_COMPONENT_DEFINE("WaveformGeneratorTest");
13
14using namespace ns3;
15
16/**
17 * \ingroup spectrum-tests
18 *
19 * \brief Waveform generator Test
20 */
22{
23 public:
24 /**
25 * Constructor
26 *
27 * \param period waveform period (seconds)
28 * \param dutyCycle waveform duty cycle
29 * \param stop stop time (seconds)
30 */
31 WaveformGeneratorTestCase(double period, double dutyCycle, double stop);
33
34 private:
35 void DoRun() override;
36
37 /**
38 * Trace if the waveform is active
39 * \param newPkt unused.
40 */
41 void TraceWave(Ptr<const Packet> newPkt);
42 double m_period; //!< waveform period (seconds)
43 double m_dutyCycle; //!< waveform duty cycle
44 double m_stop; //!< stop time (seconds)
45 int m_fails; //!< failure check
46};
47
48void
50{
51 if (Now().GetSeconds() > m_stop)
52 {
53 m_fails++;
54 }
55}
56
57WaveformGeneratorTestCase::WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
58 : TestCase("Check stop method"),
59 m_period(period),
60 m_dutyCycle(dutyCycle),
61 m_stop(stop),
62 m_fails(0)
63{
64}
65
69
70void
72{
74
76 channelHelper.SetChannel("ns3::SingleModelSpectrumChannel");
77 Ptr<SpectrumChannel> channel = channelHelper.Create();
78
80
81 WaveformGeneratorHelper waveformGeneratorHelper;
82 waveformGeneratorHelper.SetTxPowerSpectralDensity(txPsd);
83 waveformGeneratorHelper.SetChannel(channel);
84 waveformGeneratorHelper.SetPhyAttribute("Period", TimeValue(Seconds(m_period)));
85 waveformGeneratorHelper.SetPhyAttribute("DutyCycle", DoubleValue(m_dutyCycle));
86 NetDeviceContainer waveformGeneratorDevices = waveformGeneratorHelper.Install(n);
87
88 Ptr<WaveformGenerator> wave = waveformGeneratorDevices.Get(0)
89 ->GetObject<NonCommunicatingNetDevice>()
90 ->GetPhy()
92
93 wave->TraceConnectWithoutContext("TxStart",
95
98
101
102 NS_TEST_ASSERT_MSG_EQ(m_fails, 0, "Wave started after the stop method was called");
103
105}
106
107/**
108 * \ingroup spectrum-tests
109 *
110 * \brief Waveform generator TestSuite
111 */
113{
114 public:
116};
117
119 : TestSuite("waveform-generator", Type::SYSTEM)
120{
121 NS_LOG_INFO("creating WaveformGeneratorTestSuite");
122
123 // Stop while wave is active
124 AddTestCase(new WaveformGeneratorTestCase(1.0, 0.5, 1.2), TestCase::Duration::QUICK);
125 // Stop after wave
126 AddTestCase(new WaveformGeneratorTestCase(1.0, 0.5, 1.7), TestCase::Duration::QUICK);
127}
128
129/// Static variable for test initialization
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:31
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:511
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
#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:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:684
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite
Static variable for test initialization.