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
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:587
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:47
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:415
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Simple SpectrumPhy implementation that sends customizable waveform.
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
EventId m_nextWave
Next waveform generation event.
TracedCallback< Ptr< const Packet > > m_phyTxStartTrace
TracedCallback: Tx start.
Ptr< MobilityModel > m_mobility
Mobility model.
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Ptr< AntennaModel > m_antenna
Antenna model.
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used
Ptr< SpectrumChannel > m_channel
Channel.
Ptr< NetDevice > GetDevice() const
Get the associated NetDevice instance.
virtual void GenerateWaveform()
Generates a waveform.
Ptr< NetDevice > m_netDevice
Owning NetDevice.
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Ptr< MobilityModel > GetMobility() const
Get the associated MobilityModel instance.
Ptr< SpectrumValue > m_txPowerSpectralDensity
Tx PSD.
virtual void Start()
Start the waveform generator.
virtual void DoDispose(void)
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)
Ptr< Object > GetAntenna() const
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
static TypeId GetTypeId(void)
Get the type ID.
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)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
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:1309
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:45
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522