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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
10
11#include <ns3/antenna-model.h>
12#include <ns3/double.h>
13#include <ns3/log.h>
14#include <ns3/object-factory.h>
15#include <ns3/packet-burst.h>
16#include <ns3/simulator.h>
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("WaveformGenerator");
22
23NS_OBJECT_ENSURE_REGISTERED(WaveformGenerator);
24
26 : m_mobility(nullptr),
27 m_netDevice(nullptr),
28 m_channel(nullptr),
29 m_txPowerSpectralDensity(nullptr),
30 m_startTime(Seconds(0))
31{
32}
33
37
38void
40{
41 NS_LOG_FUNCTION(this);
42 m_channel = nullptr;
43 m_netDevice = nullptr;
44 m_mobility = nullptr;
46 {
48 }
49}
50
53{
54 static TypeId tid =
55 TypeId("ns3::WaveformGenerator")
57 .SetGroupName("Spectrum")
58 .AddConstructor<WaveformGenerator>()
59 .AddAttribute(
60 "Period",
61 "the period (=1/frequency)",
62 TimeValue(Seconds(1.0)),
65 .AddAttribute("DutyCycle",
66 "the duty cycle of the generator, i.e., the fraction of the period that "
67 "is occupied by a signal",
68 DoubleValue(0.5),
72 .AddTraceSource("TxStart",
73 "Trace fired when a new transmission is started",
75 "ns3::Packet::TracedCallback")
76 .AddTraceSource("TxEnd",
77 "Trace fired when a previously started transmission is finished",
79 "ns3::Packet::TracedCallback");
80 return tid;
81}
82
85{
86 return m_netDevice;
87}
88
91{
92 return m_mobility;
93}
94
97{
98 // this device is not interested in RX
99 return nullptr;
100}
101
102void
107
108void
113
114void
120
121void
126
127void
133
136{
137 return m_antenna;
138}
139
140void
146
147void
149{
150 m_period = period;
151}
152
153Time
155{
156 return m_period;
157}
158
159void
161{
162 m_dutyCycle = dutyCycle;
163}
164
165double
167{
168 return m_dutyCycle;
169}
170
171void
173{
174 NS_LOG_FUNCTION(this);
175
177 txParams->duration = Time(m_period.GetTimeStep() * m_dutyCycle);
178 txParams->psd = m_txPowerSpectralDensity;
179 txParams->txPhy = GetObject<SpectrumPhy>();
180 txParams->txAntenna = m_antenna;
181
182 NS_LOG_LOGIC("generating waveform : " << *m_txPowerSpectralDensity);
183 m_phyTxStartTrace(nullptr);
184 m_channel->StartTx(txParams);
185
186 NS_LOG_LOGIC("scheduling next waveform");
188}
189
190void
192{
193 NS_LOG_FUNCTION(this);
194 if (!m_nextWave.IsPending())
195 {
196 NS_LOG_LOGIC("generator was not active, now starting");
197 m_startTime = Now();
199 }
200}
201
202void
204{
205 NS_LOG_FUNCTION(this);
206 if (m_nextWave.IsPending())
207 {
209 }
210}
211} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:594
Abstract base class for Spectrum-aware PHY layers.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:434
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416