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 
38  : m_mobility (0),
39  m_netDevice (0),
40  m_channel (0),
41  m_txPowerSpectralDensity (0),
42  m_startTime (Seconds (0)),
43  m_active (false)
44 {
45 
46 }
47 
48 
50 {
51 
52 }
53 
54 
55 void
57 {
58  NS_LOG_FUNCTION (this);
59  m_channel = 0;
60  m_netDevice = 0;
61  m_mobility = 0;
62 }
63 
64 TypeId
66 {
67  static TypeId tid = TypeId ("ns3::WaveformGenerator")
69  .AddConstructor<WaveformGenerator> ()
70  .AddAttribute ("Period",
71  "the period (=1/frequency)",
72  TimeValue (Seconds (1.0)),
73  MakeTimeAccessor (&WaveformGenerator::SetPeriod,
75  MakeTimeChecker ())
76  .AddAttribute ("DutyCycle",
77  "the duty cycle of the generator, i.e., the fraction of the period that is occupied by a signal",
78  DoubleValue (0.5),
79  MakeDoubleAccessor (&WaveformGenerator::SetDutyCycle,
81  MakeDoubleChecker<double> ())
82  .AddTraceSource ("TxStart",
83  "Trace fired when a new transmission is started",
85  .AddTraceSource ("TxEnd",
86  "Trace fired when a previosuly started transmission is finished",
88  ;
89  return tid;
90 }
91 
92 
93 
96 {
97  return m_netDevice;
98 }
99 
100 
103 {
104  return m_mobility;
105 }
106 
107 
110 {
111  // this device is not interested in RX
112  return 0;
113 }
114 
115 void
117 {
118  m_netDevice = d;
119 }
120 
121 
122 void
124 {
125  m_mobility = m;
126 }
127 
128 
129 void
131 {
133  m_channel = c;
134 }
135 
136 
137 
138 void
140 {
141  NS_LOG_FUNCTION (this << params);
142 }
143 
144 void
146 {
147  NS_LOG_FUNCTION (this << *txPsd);
148  m_txPowerSpectralDensity = txPsd;
149 }
150 
153 {
154  return m_antenna;
155 }
156 
157 void
159 {
160  NS_LOG_FUNCTION (this << a);
161  m_antenna = a;
162 }
163 
164 void
166 {
167  m_period = period;
168 }
169 
170 Time
172 {
173  return m_period;
174 }
175 
176 
177 
178 void
180 {
181  m_dutyCycle = dutyCycle;
182 }
183 
185 {
186  return m_dutyCycle;
187 }
188 
189 
190 
191 void
193 {
194  NS_LOG_FUNCTION (this);
195 
196  Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> ();
197  txParams->duration = Time (m_period * m_dutyCycle);
198  txParams->psd = m_txPowerSpectralDensity;
199  txParams->txPhy = GetObject<SpectrumPhy> ();
200  txParams->txAntenna = m_antenna;
201 
202  NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
203  m_phyTxStartTrace (0);
204  m_channel->StartTx (txParams);
205 
206  if (m_active)
207  {
208  NS_LOG_LOGIC ("scheduling next waveform");
210  }
211 }
212 
213 
214 void
216 {
217  NS_LOG_FUNCTION (this);
218  if (!m_active)
219  {
220  NS_LOG_LOGIC ("generator was not active, now starting");
221  m_active = true;
222  m_startTime = Now ();
224  }
225 }
226 
227 
228 void
230 {
231  NS_LOG_FUNCTION (this);
232  m_active = false;
233 }
234 
235 
236 } // namespace ns3
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
Ptr< AntennaModel > m_antenna
Ptr< MobilityModel > m_mobility
TracedCallback< Ptr< const Packet > > m_phyTxStartTrace
Ptr< SpectrumValue > m_txPowerSpectralDensity
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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.
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:825
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:1008
static TypeId GetTypeId(void)
void SetPeriod(Time period)
Set the period according to which the WaveformGenerator switches on and off.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
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:986
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:441
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:610
Ptr< const SpectrumModel > GetRxSpectrumModel() const