A Discrete-Event Network Simulator
API
waveform-generator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
20 #include "waveform-generator.h"
21 
22 #include <ns3/antenna-model.h>
23 #include <ns3/double.h>
24 #include <ns3/log.h>
25 #include <ns3/object-factory.h>
26 #include <ns3/packet-burst.h>
27 #include <ns3/simulator.h>
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("WaveformGenerator");
33 
34 NS_OBJECT_ENSURE_REGISTERED(WaveformGenerator);
35 
37  : m_mobility(nullptr),
38  m_netDevice(nullptr),
39  m_channel(nullptr),
40  m_txPowerSpectralDensity(nullptr),
41  m_startTime(Seconds(0))
42 {
43 }
44 
46 {
47 }
48 
49 void
51 {
52  NS_LOG_FUNCTION(this);
53  m_channel = nullptr;
54  m_netDevice = nullptr;
55  m_mobility = nullptr;
56  if (m_nextWave.IsRunning())
57  {
59  }
60 }
61 
62 TypeId
64 {
65  static TypeId tid =
66  TypeId("ns3::WaveformGenerator")
68  .SetGroupName("Spectrum")
69  .AddConstructor<WaveformGenerator>()
70  .AddAttribute(
71  "Period",
72  "the period (=1/frequency)",
73  TimeValue(Seconds(1.0)),
76  .AddAttribute("DutyCycle",
77  "the duty cycle of the generator, i.e., the fraction of the period that "
78  "is occupied by a signal",
79  DoubleValue(0.5),
82  MakeDoubleChecker<double>())
83  .AddTraceSource("TxStart",
84  "Trace fired when a new transmission is started",
86  "ns3::Packet::TracedCallback")
87  .AddTraceSource("TxEnd",
88  "Trace fired when a previously started transmission is finished",
90  "ns3::Packet::TracedCallback");
91  return tid;
92 }
93 
96 {
97  return m_netDevice;
98 }
99 
102 {
103  return m_mobility;
104 }
105 
108 {
109  // this device is not interested in RX
110  return nullptr;
111 }
112 
113 void
115 {
116  m_netDevice = d;
117 }
118 
119 void
121 {
122  m_mobility = m;
123 }
124 
125 void
127 {
129  m_channel = c;
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION(this << params);
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION(this << *txPsd);
142  m_txPowerSpectralDensity = txPsd;
143 }
144 
147 {
148  return m_antenna;
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION(this << a);
155  m_antenna = a;
156 }
157 
158 void
160 {
161  m_period = period;
162 }
163 
164 Time
166 {
167  return m_period;
168 }
169 
170 void
172 {
173  m_dutyCycle = dutyCycle;
174 }
175 
176 double
178 {
179  return m_dutyCycle;
180 }
181 
182 void
184 {
185  NS_LOG_FUNCTION(this);
186 
187  Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters>();
188  txParams->duration = Time(m_period.GetTimeStep() * m_dutyCycle);
189  txParams->psd = m_txPowerSpectralDensity;
190  txParams->txPhy = GetObject<SpectrumPhy>();
191  txParams->txAntenna = m_antenna;
192 
193  NS_LOG_LOGIC("generating waveform : " << *m_txPowerSpectralDensity);
194  m_phyTxStartTrace(nullptr);
195  m_channel->StartTx(txParams);
196 
197  NS_LOG_LOGIC("scheduling next waveform");
199 }
200 
201 void
203 {
204  NS_LOG_FUNCTION(this);
205  if (!m_nextWave.IsRunning())
206  {
207  NS_LOG_LOGIC("generator was not active, now starting");
208  m_startTime = Now();
210  }
211 }
212 
213 void
215 {
216  NS_LOG_FUNCTION(this);
217  if (m_nextWave.IsRunning())
218  {
219  m_nextWave.Cancel();
220  }
221 }
222 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:605
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:46
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:445
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Simple SpectrumPhy implementation that sends customizable waveform.
void SetDevice(Ptr< NetDevice > d) override
Set the associated NetDevice instance.
static TypeId GetTypeId()
Get the type ID.
void SetChannel(Ptr< SpectrumChannel > c) override
Set the channel attached to this device.
Ptr< MobilityModel > GetMobility() const override
Get the associated MobilityModel instance.
EventId m_nextWave
Next waveform generation event.
TracedCallback< Ptr< const Packet > > m_phyTxStartTrace
TracedCallback: Tx start.
Ptr< MobilityModel > m_mobility
Mobility model.
Ptr< Object > GetAntenna() const override
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
Ptr< AntennaModel > m_antenna
Antenna model.
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used
void StartRx(Ptr< SpectrumSignalParameters > params) override
Notify the SpectrumPhy instance of an incoming signal.
Ptr< SpectrumChannel > m_channel
Channel.
Ptr< const SpectrumModel > GetRxSpectrumModel() const override
virtual void GenerateWaveform()
Generates a waveform.
Ptr< NetDevice > m_netDevice
Owning NetDevice.
Ptr< NetDevice > GetDevice() const override
Get the associated NetDevice instance.
Ptr< SpectrumValue > m_txPowerSpectralDensity
Tx PSD.
virtual void Start()
Start the waveform generator.
void DoDispose() override
Destructor implementation.
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txs)
Set the Power Spectral Density used for outgoing waveforms.
double m_dutyCycle
Duty Cycle (should be in [0,1])
void SetDutyCycle(double value)
void SetMobility(Ptr< MobilityModel > m) override
Set the mobility model associated with this device.
void SetPeriod(Time period)
Set the period according to which the WaveformGenerator switches on and off.
virtual void Stop()
Stop the waveform generator.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
TracedCallback: Tx end.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
Ptr< AntennaModel > txAntenna
The AntennaModel instance that was used to transmit this signal.
Time duration
The duration of the packet transmission.
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.