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 
void TraceWave(Ptr< const Packet > newPkt)
WaveformGeneratorTestCase(double period, double dutyCycle, double stop)
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:293
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:1154
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:1344
AttributeValue implementation for Time.
Definition: nstime.h:1353
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:166
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
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:1642
channel
Definition: third.py:92
static WaveformGeneratorTestSuite g_waveformGeneratorTestSuite