A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("WaveformGenerator");
32 
33 namespace ns3 {
34 
35 NS_OBJECT_ENSURE_REGISTERED (WaveformGenerator)
36  ;
37 
39  : m_mobility (0),
40  m_netDevice (0),
41  m_channel (0),
42  m_txPowerSpectralDensity (0),
43  m_startTime (Seconds (0)),
44  m_active (false)
45 {
46 
47 }
48 
49 
51 {
52 
53 }
54 
55 
56 void
58 {
59  NS_LOG_FUNCTION (this);
60  m_channel = 0;
61  m_netDevice = 0;
62  m_mobility = 0;
63 }
64 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::WaveformGenerator")
70  .AddConstructor<WaveformGenerator> ()
71  .AddAttribute ("Period",
72  "the period (=1/frequency)",
73  TimeValue (Seconds (1.0)),
74  MakeTimeAccessor (&WaveformGenerator::SetPeriod,
76  MakeTimeChecker ())
77  .AddAttribute ("DutyCycle",
78  "the duty cycle of the generator, i.e., the fraction of the period that is occupied by a signal",
79  DoubleValue (0.5),
80  MakeDoubleAccessor (&WaveformGenerator::SetDutyCycle,
82  MakeDoubleChecker<double> ())
83  .AddTraceSource ("TxStart",
84  "Trace fired when a new transmission is started",
86  .AddTraceSource ("TxEnd",
87  "Trace fired when a previosuly started transmission is finished",
89  ;
90  return tid;
91 }
92 
93 
94 
97 {
98  return m_netDevice;
99 }
100 
101 
104 {
105  return m_mobility;
106 }
107 
108 
111 {
112  // this device is not interested in RX
113  return 0;
114 }
115 
116 void
118 {
119  m_netDevice = d;
120 }
121 
122 
123 void
125 {
126  m_mobility = m;
127 }
128 
129 
130 void
132 {
134  m_channel = c;
135 }
136 
137 
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << params);
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION (this << *txPsd);
149  m_txPowerSpectralDensity = txPsd;
150 }
151 
154 {
155  return m_antenna;
156 }
157 
158 void
160 {
161  NS_LOG_FUNCTION (this << a);
162  m_antenna = a;
163 }
164 
165 void
167 {
168  m_period = period;
169 }
170 
171 Time
173 {
174  return m_period;
175 }
176 
177 
178 
179 void
181 {
182  m_dutyCycle = dutyCycle;
183 }
184 
186 {
187  return m_dutyCycle;
188 }
189 
190 
191 
192 void
194 {
195  NS_LOG_FUNCTION (this);
196 
197  Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> ();
198  txParams->duration = Time (m_period * m_dutyCycle);
199  txParams->psd = m_txPowerSpectralDensity;
200  txParams->txPhy = GetObject<SpectrumPhy> ();
201  txParams->txAntenna = m_antenna;
202 
203  NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
204  m_phyTxStartTrace (0);
205  m_channel->StartTx (txParams);
206 
207  if (m_active)
208  {
209  NS_LOG_LOGIC ("scheduling next waveform");
211  }
212 }
213 
214 
215 void
217 {
218  NS_LOG_FUNCTION (this);
219  if (!m_active)
220  {
221  NS_LOG_LOGIC ("generator was not active, now starting");
222  m_active = true;
223  m_startTime = Now ();
225  }
226 }
227 
228 
229 void
231 {
232  NS_LOG_FUNCTION (this);
233  m_active = false;
234 }
235 
236 
237 } // namespace ns3
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance
Ptr< AntennaModel > m_antenna
Ptr< MobilityModel > m_mobility
TracedCallback< Ptr< const Packet > > m_phyTxStartTrace
Ptr< SpectrumValue > m_txPowerSpectralDensity
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txs)
Set the Power Spectral Density used for outgoing waveforms.
void SetDutyCycle(double value)
virtual void Start()
Start the waveform generator.
Ptr< AntennaModel > GetRxAntenna()
get the AntennaModel used by the NetDevice for reception
hold objects of type ns3::Time
Definition: nstime.h:961
static TypeId GetTypeId(void)
NS_LOG_COMPONENT_DEFINE("WaveformGenerator")
void SetPeriod(Time period)
Set the period according to which the WaveformGenerator switches on and off.
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:985
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used
virtual void Stop()
Stop the waveform generator.
Ptr< MobilityModel > GetMobility()
get the associated MobilityModel instance
Ptr< SpectrumChannel > m_channel
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:452
Ptr< NetDevice > m_netDevice
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Ptr< NetDevice > GetDevice()
get the associated NetDevice instance
Hold a floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
Ptr< const SpectrumModel > GetRxSpectrumModel() const