A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("WaveformGenerator");
33
34NS_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
49void
51{
52 NS_LOG_FUNCTION(this);
53 m_channel = nullptr;
54 m_netDevice = nullptr;
55 m_mobility = nullptr;
57 {
59 }
60}
61
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
113void
115{
116 m_netDevice = d;
117}
118
119void
121{
122 m_mobility = m;
123}
124
125void
127{
129 m_channel = c;
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << params);
136}
137
138void
140{
141 NS_LOG_FUNCTION(this << *txPsd);
143}
144
147{
148 return m_antenna;
149}
150
151void
153{
154 NS_LOG_FUNCTION(this << a);
155 m_antenna = a;
156}
157
158void
160{
161 m_period = period;
162}
163
164Time
166{
167 return m_period;
168}
169
170void
172{
173 m_dutyCycle = dutyCycle;
174}
175
176double
178{
179 return m_dutyCycle;
180}
181
182void
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
201void
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
213void
215{
216 NS_LOG_FUNCTION(this);
217 if (m_nextWave.IsRunning())
218 {
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
AttributeValue implementation for Time.
Definition: nstime.h:1413
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
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.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1434
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.