A Discrete-Event Network Simulator
API
waveform-generator.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 #include <ns3/object-factory.h>
23 #include <ns3/log.h>
24 #include <ns3/simulator.h>
25 #include <ns3/double.h>
26 #include <ns3/packet-burst.h>
27 #include <ns3/antenna-model.h>
28 
29 #include "waveform-generator.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("WaveformGenerator");
34 
35 NS_OBJECT_ENSURE_REGISTERED (WaveformGenerator);
36 
38  : m_mobility (0),
39  m_netDevice (0),
40  m_channel (0),
41  m_txPowerSpectralDensity (0),
42  m_startTime (Seconds (0))
43 {
44 
45 }
46 
47 
49 {
50 
51 }
52 
53 
54 void
56 {
57  NS_LOG_FUNCTION (this);
58  m_channel = 0;
59  m_netDevice = 0;
60  m_mobility = 0;
61  if (m_nextWave.IsRunning ())
62  {
63  m_nextWave.Cancel ();
64  }
65 }
66 
67 TypeId
69 {
70  static TypeId tid = TypeId ("ns3::WaveformGenerator")
72  .SetGroupName ("Spectrum")
73  .AddConstructor<WaveformGenerator> ()
74  .AddAttribute ("Period",
75  "the period (=1/frequency)",
76  TimeValue (Seconds (1.0)),
79  MakeTimeChecker ())
80  .AddAttribute ("DutyCycle",
81  "the duty cycle of the generator, i.e., the fraction of the period that is occupied by a signal",
82  DoubleValue (0.5),
85  MakeDoubleChecker<double> ())
86  .AddTraceSource ("TxStart",
87  "Trace fired when a new transmission is started",
89  "ns3::Packet::TracedCallback")
90  .AddTraceSource ("TxEnd",
91  "Trace fired when a previously started transmission is finished",
93  "ns3::Packet::TracedCallback")
94  ;
95  return tid;
96 }
97 
98 
99 
102 {
103  return m_netDevice;
104 }
105 
106 
109 {
110  return m_mobility;
111 }
112 
113 
116 {
117  // this device is not interested in RX
118  return 0;
119 }
120 
121 void
123 {
124  m_netDevice = d;
125 }
126 
127 
128 void
130 {
131  m_mobility = m;
132 }
133 
134 
135 void
137 {
139  m_channel = c;
140 }
141 
142 
143 
144 void
146 {
147  NS_LOG_FUNCTION (this << params);
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION (this << *txPsd);
154  m_txPowerSpectralDensity = txPsd;
155 }
156 
159 {
160  return m_antenna;
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this << a);
167  m_antenna = a;
168 }
169 
170 void
172 {
173  m_period = period;
174 }
175 
176 Time
178 {
179  return m_period;
180 }
181 
182 
183 
184 void
186 {
187  m_dutyCycle = dutyCycle;
188 }
189 
191 {
192  return m_dutyCycle;
193 }
194 
195 
196 
197 void
199 {
200  NS_LOG_FUNCTION (this);
201 
202  Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> ();
203  txParams->duration = Time (m_period.GetTimeStep () * m_dutyCycle);
204  txParams->psd = m_txPowerSpectralDensity;
205  txParams->txPhy = GetObject<SpectrumPhy> ();
206  txParams->txAntenna = m_antenna;
207 
208  NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
209  m_phyTxStartTrace (0);
210  m_channel->StartTx (txParams);
211 
212  NS_LOG_LOGIC ("scheduling next waveform");
214 }
215 
216 
217 void
219 {
220  NS_LOG_FUNCTION (this);
221  if (!m_nextWave.IsRunning ())
222  {
223  NS_LOG_LOGIC ("generator was not active, now starting");
224  m_startTime = Now ();
226  }
227 }
228 
229 
230 void
232 {
233  NS_LOG_FUNCTION (this);
234  if (m_nextWave.IsRunning ())
235  {
236  m_nextWave.Cancel ();
237 
238  }
239 }
240 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::WaveformGenerator::SetDevice
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Definition: waveform-generator.cc:122
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::WaveformGenerator::Start
virtual void Start()
Start the waveform generator.
Definition: waveform-generator.cc:218
ns3::WaveformGenerator::GetDevice
Ptr< NetDevice > GetDevice() const
Get the associated NetDevice instance.
Definition: waveform-generator.cc:101
waveform-generator.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WaveformGenerator::GetPeriod
Time GetPeriod() const
Definition: waveform-generator.cc:177
ns3::WaveformGenerator::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: waveform-generator.cc:55
ns3::WaveformGenerator::m_phyTxEndTrace
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
TracedCallback: Tx end.
Definition: waveform-generator.h:153
ns3::WaveformGenerator::m_txPowerSpectralDensity
Ptr< SpectrumValue > m_txPowerSpectralDensity
Tx PSD.
Definition: waveform-generator.h:146
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::WaveformGenerator::m_startTime
Time m_startTime
Start time.
Definition: waveform-generator.h:149
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::WaveformGenerator::m_period
Time m_period
Period.
Definition: waveform-generator.h:147
ns3::WaveformGenerator::m_nextWave
EventId m_nextWave
Next waveform generation event.
Definition: waveform-generator.h:150
ns3::Time::GetTimeStep
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:416
ns3::WaveformGenerator::SetTxPowerSpectralDensity
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txs)
Set the Power Spectral Density used for outgoing waveforms.
Definition: waveform-generator.cc:151
ns3::Ptr< NetDevice >
ns3::WaveformGenerator::SetChannel
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: waveform-generator.cc:136
ns3::EventId::IsRunning
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
ns3::WaveformGenerator::m_antenna
Ptr< AntennaModel > m_antenna
Antenna model.
Definition: waveform-generator.h:137
ns3::SpectrumPhy
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:46
ns3::WaveformGenerator::GetMobility
Ptr< MobilityModel > GetMobility() const
Get the associated MobilityModel instance.
Definition: waveform-generator.cc:108
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WaveformGenerator::Stop
virtual void Stop()
Stop the waveform generator.
Definition: waveform-generator.cc:231
ns3::WaveformGenerator::m_phyTxStartTrace
TracedCallback< Ptr< const Packet > > m_phyTxStartTrace
TracedCallback: Tx start.
Definition: waveform-generator.h:152
ns3::WaveformGenerator::~WaveformGenerator
virtual ~WaveformGenerator()
Definition: waveform-generator.cc:48
ns3::WaveformGenerator::GenerateWaveform
virtual void GenerateWaveform()
Generates a waveform.
Definition: waveform-generator.cc:198
ns3::WaveformGenerator::StartRx
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
Definition: waveform-generator.cc:145
ns3::WaveformGenerator::GetDutyCycle
double GetDutyCycle() const
Definition: waveform-generator.cc:190
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::MakeDoubleAccessor
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log-macros-enabled.h:209
ns3::WaveformGenerator
Simple SpectrumPhy implementation that sends customizable waveform.
Definition: waveform-generator.h:54
ns3::WaveformGenerator::GetRxAntenna
Ptr< AntennaModel > GetRxAntenna() const
Get the AntennaModel used by the NetDevice for reception.
Definition: waveform-generator.cc:158
ns3::WaveformGenerator::GetRxSpectrumModel
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Definition: waveform-generator.cc:115
ns3::WaveformGenerator::m_netDevice
Ptr< NetDevice > m_netDevice
Owning NetDevice.
Definition: waveform-generator.h:138
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
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WaveformGenerator::m_mobility
Ptr< MobilityModel > m_mobility
Mobility model.
Definition: waveform-generator.h:136
ns3::WaveformGenerator::SetAntenna
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used
Definition: waveform-generator.cc:164
ns3::WaveformGenerator::WaveformGenerator
WaveformGenerator()
Definition: waveform-generator.cc:37
ns3::TracedValueCallback::Time
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:813
ns3::WaveformGenerator::m_dutyCycle
double m_dutyCycle
Duty Cycle (should be in [0,1])
Definition: waveform-generator.h:148
ns3::WaveformGenerator::SetDutyCycle
void SetDutyCycle(double value)
Definition: waveform-generator.cc:185
ns3::WaveformGenerator::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: waveform-generator.cc:68
ns3::Simulator::ScheduleNow
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:587
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1354
ns3::WaveformGenerator::m_channel
Ptr< SpectrumChannel > m_channel
Channel.
Definition: waveform-generator.h:139
ns3::WaveformGenerator::SetMobility
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: waveform-generator.cc:129
ns3::WaveformGenerator::SetPeriod
void SetPeriod(Time period)
Set the period according to which the WaveformGenerator switches on and off.
Definition: waveform-generator.cc:171