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 
37 {
38 public:
46  WaveformGeneratorTestCase (double period, double dutyCycle, double stop);
47  virtual ~WaveformGeneratorTestCase ();
48 
49 private:
50  virtual void DoRun (void);
51 
56  void TraceWave (Ptr<const Packet> newPkt);
57  double m_period;
58  double m_dutyCycle;
59  double m_stop;
60  int m_fails;
61 };
62 
63 void
65 {
66  if (Now ().GetSeconds () > m_stop)
67  {
68  m_fails++;
69  }
70 }
71 
72 WaveformGeneratorTestCase::WaveformGeneratorTestCase (double period, double dutyCycle, double stop)
73  : TestCase ("Check stop method"),
74  m_period (period),
75  m_dutyCycle (dutyCycle),
76  m_stop (stop),
77  m_fails (0)
78 {
79 }
80 
82 {
83 }
84 
85 
86 void
88 {
89  Ptr<SpectrumValue> txPsd = MicrowaveOvenSpectrumValueHelper::CreatePowerSpectralDensityMwo1 ();
90 
91  SpectrumChannelHelper channelHelper = SpectrumChannelHelper::Default ();
92  channelHelper.SetChannel ("ns3::SingleModelSpectrumChannel");
93  Ptr<SpectrumChannel> channel = channelHelper.Create ();
94 
95  Ptr<Node> n = CreateObject<Node> ();
96 
97  WaveformGeneratorHelper waveformGeneratorHelper;
98  waveformGeneratorHelper.SetTxPowerSpectralDensity (txPsd);
99  waveformGeneratorHelper.SetChannel (channel);
100  waveformGeneratorHelper.SetPhyAttribute ("Period", TimeValue (Seconds (m_period)));
101  waveformGeneratorHelper.SetPhyAttribute ("DutyCycle", DoubleValue (m_dutyCycle));
102  NetDeviceContainer waveformGeneratorDevices = waveformGeneratorHelper.Install (n);
103 
104  Ptr<WaveformGenerator> wave = waveformGeneratorDevices.Get (0)->GetObject<NonCommunicatingNetDevice> ()->GetPhy ()->GetObject<WaveformGenerator> ();
105 
107 
108  Simulator::Schedule (Seconds (1.0), &WaveformGenerator::Start, wave);
109  Simulator::Schedule (Seconds (m_stop), &WaveformGenerator::Stop, wave);
110 
111  Simulator::Stop (Seconds (3.0));
112  Simulator::Run ();
113 
114  NS_TEST_ASSERT_MSG_EQ (m_fails, 0, "Wave started after the stop method was called");
115 
116  Simulator::Destroy ();
117 }
118 
119 
126 {
127 public:
129 };
130 
132  : TestSuite ("waveform-generator", SYSTEM)
133 {
134  NS_LOG_INFO ("creating WaveformGeneratorTestSuite");
135 
136  // Stop while wave is active
137  AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.2), TestCase::QUICK);
138  // Stop after wave
139  AddTestCase (new WaveformGeneratorTestCase (1.0, 0.5, 1.7), TestCase::QUICK);
140 }
141 
double m_period
waveform period (seconds)
void TraceWave(Ptr< const Packet > newPkt)
Trace if the waveform is active.
WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
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...
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Setup a SpectrumChannel.
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())
Ptr< SpectrumChannel > Create(void) const
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
AttributeValue implementation for Time.
Definition: nstime.h:1308
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#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:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:1648
channel
Definition: third.py:92
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite
Static variable for test initialization.