A Discrete-Event Network Simulator
API
spectrum-waveform-generator-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Luis Pacheco <luisbelem@gmail.com>
19  */
20 #include <ns3/core-module.h>
21 #include <ns3/test.h>
22 #include <ns3/spectrum-module.h>
23 
24 
25 NS_LOG_COMPONENT_DEFINE ("WaveformGeneratorTest");
26 
27 using namespace ns3;
28 
29 
30 
32 {
33 public:
34  WaveformGeneratorTestCase (double period, double dutyCycle, double stop);
35  virtual ~WaveformGeneratorTestCase ();
36 
37 private:
38  virtual void DoRun (void);
39 
40  void TraceWave (Ptr<const Packet> newPkt);
41  double m_period;
42  double m_dutyCycle;
43  double m_stop;
44  int m_fails;
45 };
46 
47 void
49 {
50  if (Now ().GetSeconds () > m_stop)
51  {
52  m_fails++;
53  }
54 }
55 
56 WaveformGeneratorTestCase::WaveformGeneratorTestCase (double period, double dutyCycle, double stop)
57  : TestCase ("Check stop method"),
58  m_period (period),
59  m_dutyCycle (dutyCycle),
60  m_stop (stop),
61  m_fails (0)
62 {
63 }
64 
66 {
67 }
68 
69 
70 void
72 {
73  Ptr<SpectrumValue> txPsd = MicrowaveOvenSpectrumValueHelper::CreatePowerSpectralDensityMwo1 ();
74 
75  SpectrumChannelHelper channelHelper = SpectrumChannelHelper::Default ();
76  channelHelper.SetChannel ("ns3::SingleModelSpectrumChannel");
77  Ptr<SpectrumChannel> channel = channelHelper.Create ();
78 
79  Ptr<Node> n = CreateObject<Node> ();
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)->GetObject<NonCommunicatingNetDevice> ()->GetPhy ()->GetObject<WaveformGenerator> ();
89 
91 
92  Simulator::Schedule (Seconds (1.0), &WaveformGenerator::Start, wave);
93  Simulator::Schedule (Seconds (m_stop), &WaveformGenerator::Stop, wave);
94 
95  Simulator::Stop (Seconds (3.0));
96  Simulator::Run ();
97 
98  NS_TEST_ASSERT_MSG_EQ (m_fails, 0, "Wave started after the stop method was called");
99 
100  Simulator::Destroy ();
101 }
102 
103 
105 {
106 public:
108 };
109 
111  : TestSuite ("waveform-generator", SYSTEM)
112 {
113  NS_LOG_INFO ("creating WaveformGeneratorTestSuite");
114 
115  // Stop while wave is active
116  AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.2), TestCase::QUICK);
117  // Stop after wave
118  AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.7), TestCase::QUICK);
119 }
120 
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
WaveformGeneratorTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: spectrum-waveform-generator-test.cc:71
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
WaveformGeneratorTestCase::m_fails
int m_fails
Definition: spectrum-waveform-generator-test.cc:44
ns3::SpectrumChannelHelper::SetChannel
void SetChannel(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: spectrum-helper.cc:45
WaveformGeneratorTestCase::TraceWave
void TraceWave(Ptr< const Packet > newPkt)
Definition: spectrum-waveform-generator-test.cc:48
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WaveformGeneratorTestCase::~WaveformGeneratorTestCase
virtual ~WaveformGeneratorTestCase()
Definition: spectrum-waveform-generator-test.cc:65
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
third.channel
channel
Definition: third.py:92
WaveformGeneratorTestCase::m_stop
double m_stop
Definition: spectrum-waveform-generator-test.cc:43
WaveformGeneratorTestSuite
Definition: spectrum-waveform-generator-test.cc:105
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NonCommunicatingNetDevice
This class implements a device which does not communicate, in the sense that it does not interact wit...
Definition: non-communicating-net-device.h:54
ns3::TestCase
encapsulates test code
Definition: test.h:1154
WaveformGeneratorTestCase::WaveformGeneratorTestCase
WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
Definition: spectrum-waveform-generator-test.cc:56
ns3::SpectrumChannelHelper::Create
Ptr< SpectrumChannel > Create(void) const
Definition: spectrum-helper.cc:157
ns3::Ptr< const Packet >
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
ns3::WaveformGeneratorHelper::Install
NetDeviceContainer Install(NodeContainer c) const
Definition: waveform-generator-helper.cc:110
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::WaveformGeneratorHelper::SetPhyAttribute
void SetPhyAttribute(std::string name, const AttributeValue &v)
Definition: waveform-generator-helper.cc:73
ns3::WaveformGeneratorHelper::SetTxPowerSpectralDensity
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
Definition: waveform-generator-helper.cc:65
ns3::WaveformGeneratorHelper
Create a Waveform generator, which can be used to inject specific noise in the channel.
Definition: waveform-generator-helper.h:46
WaveformGeneratorTestSuite::WaveformGeneratorTestSuite
WaveformGeneratorTestSuite()
Definition: spectrum-waveform-generator-test.cc:110
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::WaveformGenerator
Simple SpectrumPhy implementation that sends customizable waveform.
Definition: waveform-generator.h:54
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
WaveformGeneratorTestCase::m_dutyCycle
double m_dutyCycle
Definition: spectrum-waveform-generator-test.cc:42
g_waveformGeneratorTestSuite
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite
Definition: spectrum-waveform-generator-test.cc:121
WaveformGeneratorTestCase::m_period
double m_period
Definition: spectrum-waveform-generator-test.cc:41
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
ns3::WaveformGeneratorHelper::SetChannel
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper
Definition: waveform-generator-helper.cc:52
WaveformGeneratorTestCase
Definition: spectrum-waveform-generator-test.cc:32
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::SpectrumChannelHelper
Setup a SpectrumChannel.
Definition: spectrum-helper.h:45
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37