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 
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite
A suite of tests to run.
Definition: test.h:1342
#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:278
WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
encapsulates test code
Definition: test.h:1155
This class implements a device which does not communicate, in the sense that it does not interact wit...
void TraceWave(Ptr< const Packet > newPkt)
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
channel
Definition: third.py:85
Simple SpectrumPhy implementation that sends customizable waveform.
AttributeValue implementation for Time.
Definition: nstime.h:1076
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:168
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Create a Waveform generator, which can be used to inject specific noise in the channel.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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())
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
Setup a SpectrumChannel.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Ptr< SpectrumChannel > Create(void) const