A Discrete-Event Network Simulator
API
spectrum-wifi-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
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  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Ghada Badawy <gbadawy@gmail.com>
20  * Sébastien Deronne <sebastien.deronne@gmail.com>
21  *
22  * Ported from yans-wifi-phy.cc by several contributors starting
23  * with Nicola Baldo and Dean Armstrong
24  */
25 
26 #include "spectrum-wifi-phy.h"
27 #include "ns3/wifi-spectrum-value-helper.h"
28 #include "ns3/log.h"
29 #include "ns3/boolean.h"
31 #include "wifi-utils.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("SpectrumWifiPhy");
36 
37 NS_OBJECT_ENSURE_REGISTERED (SpectrumWifiPhy);
38 
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::SpectrumWifiPhy")
43  .SetParent<WifiPhy> ()
44  .SetGroupName ("Wifi")
45  .AddConstructor<SpectrumWifiPhy> ()
46  .AddAttribute ("DisableWifiReception", "Prevent Wi-Fi frame sync from ever happening",
47  BooleanValue (false),
50  .AddTraceSource ("SignalArrival",
51  "Signal arrival",
53  "ns3::SpectrumWifiPhy::SignalArrivalCallback")
54  ;
55  return tid;
56 }
57 
59 {
60  NS_LOG_FUNCTION (this);
61 }
62 
64 {
65  NS_LOG_FUNCTION (this);
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION (this);
72  m_channel = 0;
74 }
75 
76 void
78 {
79  NS_LOG_FUNCTION (this);
81  // This connection is deferred until frequency and channel width are set
83  {
85  }
86  else
87  {
88  NS_FATAL_ERROR ("SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at initialization time");
89  }
90 }
91 
94 {
95  NS_LOG_FUNCTION (this);
97  {
98  return m_rxSpectrumModel;
99  }
100  else
101  {
102  if (GetFrequency () == 0)
103  {
104  NS_LOG_DEBUG ("Frequency is not set; returning 0");
105  return 0;
106  }
107  else
108  {
109  NS_LOG_DEBUG ("Creating spectrum model from frequency/width pair of (" << GetFrequency () << ", " << (uint16_t)GetChannelWidth () << ")");
111  }
112  }
113  return m_rxSpectrumModel;
114 }
115 
118 {
119  return m_channel;
120 }
121 
122 void
124 {
125  m_channel = channel;
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION (this);
132  NS_ASSERT_MSG (IsInitialized (), "Executing method before run-time");
133  NS_LOG_DEBUG ("Run-time change of spectrum model from frequency/width pair of (" << GetFrequency () << ", " << (uint16_t)GetChannelWidth () << ")");
134  // Replace existing spectrum model with new one, and must call AddRx ()
135  // on the SpectrumChannel to provide this new spectrum model to it
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION (this << (uint16_t) nch);
145  if (IsInitialized ())
146  {
148  }
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this << freq);
155  WifiPhy::SetFrequency (freq);
156  if (IsInitialized ())
157  {
159  }
160 }
161 
162 void
163 SpectrumWifiPhy::SetChannelWidth (uint8_t channelwidth)
164 {
165  NS_LOG_FUNCTION (this << (uint16_t) channelwidth);
166  WifiPhy::SetChannelWidth (channelwidth);
167  if (IsInitialized ())
168  {
170  }
171 }
172 
173 void
175 {
176  NS_LOG_FUNCTION (this << standard);
177  WifiPhy::ConfigureStandard (standard);
178  if (IsInitialized ())
179  {
181  }
182 }
183 
184 void
186 {
187  m_operationalChannelList.push_back (channelNumber);
188 }
189 
190 std::vector<uint8_t>
192 {
193  std::vector<uint8_t> channelList;
194  channelList.push_back (GetChannelNumber ()); // first channel of list
195  for (std::vector<uint8_t>::size_type i = 0; i != m_operationalChannelList.size (); i++)
196  {
198  {
199  channelList.push_back (m_operationalChannelList[i]);
200  }
201  }
202  return channelList;
203 }
204 
205 void
207 {
208  m_operationalChannelList.clear ();
209 }
210 
211 void
213 {
214  NS_LOG_FUNCTION (this << rxParams);
215  Time rxDuration = rxParams->duration;
216  Ptr<SpectrumValue> receivedSignalPsd = rxParams->psd;
217  NS_LOG_DEBUG ("Received signal with PSD " << *receivedSignalPsd << " and duration " << rxDuration.As (Time::NS));
218  uint32_t senderNodeId = 0;
219  if (rxParams->txPhy)
220  {
221  senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
222  }
223  NS_LOG_DEBUG ("Received signal from " << senderNodeId << " with unfiltered power " << WToDbm (Integral (*receivedSignalPsd)) << " dBm");
224  // Integrate over our receive bandwidth (i.e., all that the receive
225  // spectral mask representing our filtering allows) to find the
226  // total energy apparent to the "demodulator".
228  SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
229  // Add receiver antenna gain
230  NS_LOG_DEBUG ("Signal power received (watts) before antenna gain: " << Integral (filteredSignal));
231  double rxPowerW = Integral (filteredSignal) * DbToRatio (GetRxGain ());
232  NS_LOG_DEBUG ("Signal power received after antenna gain: " << rxPowerW << " W (" << WToDbm (rxPowerW) << " dBm)");
233 
234  Ptr<WifiSpectrumSignalParameters> wifiRxParams = DynamicCast<WifiSpectrumSignalParameters> (rxParams);
235 
236  // Log the signal arrival to the trace source
237  m_signalCb (wifiRxParams ? true : false, senderNodeId, WToDbm (rxPowerW), rxDuration);
238  if (wifiRxParams == 0)
239  {
240  NS_LOG_INFO ("Received non Wi-Fi signal");
241  m_interference.AddForeignSignal (rxDuration, rxPowerW);
243  return;
244  }
245  if (wifiRxParams && m_disableWifiReception)
246  {
247  NS_LOG_INFO ("Received Wi-Fi signal but blocked from syncing");
248  m_interference.AddForeignSignal (rxDuration, rxPowerW);
250  return;
251  }
252 
253  NS_LOG_INFO ("Received Wi-Fi signal");
254  Ptr<Packet> packet = wifiRxParams->packet->Copy ();
255  StartReceivePreambleAndHeader (packet, rxPowerW, rxDuration);
256 }
257 
260 {
262 }
263 
266 {
267  return m_antenna;
268 }
269 
270 void
272 {
273  NS_LOG_FUNCTION (this << a);
274  m_antenna = a;
275 }
276 
277 void
279 {
280  NS_LOG_FUNCTION (this << device);
281  m_wifiSpectrumPhyInterface = CreateObject<WifiSpectrumPhyInterface> ();
282  m_wifiSpectrumPhyInterface->SetSpectrumWifiPhy (this);
283  m_wifiSpectrumPhyInterface->SetDevice (device);
284 }
285 
287 SpectrumWifiPhy::GetTxPowerSpectralDensity (uint16_t centerFrequency, uint8_t channelWidth, double txPowerW, WifiModulationClass modulationClass) const
288 {
289  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW);
291  switch (modulationClass)
292  {
293  case WIFI_MOD_CLASS_OFDM:
295  v = WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (centerFrequency, channelWidth, txPowerW, GetGuardBandwidth ());
296  break;
297  case WIFI_MOD_CLASS_DSSS:
300  break;
301  case WIFI_MOD_CLASS_HT:
302  case WIFI_MOD_CLASS_VHT:
303  v = WifiSpectrumValueHelper::CreateHtOfdmTxPowerSpectralDensity (centerFrequency, channelWidth, txPowerW, GetGuardBandwidth ());
304  break;
305  case WIFI_MOD_CLASS_HE:
306  v = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (centerFrequency, channelWidth, txPowerW, GetGuardBandwidth ());
307  break;
308  default:
309  NS_FATAL_ERROR ("modulation class unknown: " << modulationClass);
310  break;
311  }
312  return v;
313 }
314 
315 void
317 {
318  NS_LOG_DEBUG ("Start transmission: signal power before antenna gain=" << GetPowerDbm (txVector.GetTxPowerLevel ()) << "dBm");
319  double txPowerWatts = DbmToW (GetPowerDbm (txVector.GetTxPowerLevel ()) + GetTxGain ());
320  Ptr<SpectrumValue> txPowerSpectrum = GetTxPowerSpectralDensity (GetFrequency (), GetChannelWidth (), txPowerWatts, txVector.GetMode ().GetModulationClass ());
321  Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> ();
322  txParams->duration = txDuration;
323  txParams->psd = txPowerSpectrum;
324  NS_ASSERT_MSG (m_wifiSpectrumPhyInterface, "SpectrumPhy() is not set; maybe forgot to call CreateWifiSpectrumPhyInterface?");
325  txParams->txPhy = m_wifiSpectrumPhyInterface->GetObject<SpectrumPhy> ();
326  txParams->txAntenna = m_antenna;
327  txParams->packet = packet;
328  NS_LOG_DEBUG ("Starting transmission with power " << WToDbm (txPowerWatts) << " dBm on channel " << (uint16_t) GetChannelNumber ());
329  NS_LOG_DEBUG ("Starting transmission with integrated spectrum power " << WToDbm (Integral (*txPowerSpectrum)) << " dBm; spectrum model Uid: " << txPowerSpectrum->GetSpectrumModel ()->GetUid ());
330  m_channel->StartTx (txParams);
331 }
332 
333 double
335 {
336  double bandBandwidth = 0;
337  switch (GetStandard ())
338  {
348  // Use OFDM subcarrier width of 312.5 KHz as band granularity
349  bandBandwidth = 312500;
350  break;
353  // Use OFDM subcarrier width of 78.125 KHz as band granularity
354  bandBandwidth = 78125;
355  break;
356  default:
357  NS_FATAL_ERROR ("Standard unknown: " << GetStandard ());
358  break;
359  }
360  return bandBandwidth;
361 }
362 
363 uint32_t
365 {
366  double guardBandwidth = 0;
367  switch (GetStandard ())
368  {
380  // Use 10 MHZ
381  guardBandwidth = 10;
382  break;
383  default:
384  NS_FATAL_ERROR ("Standard unknown: " << GetStandard ());
385  break;
386  }
387  return guardBandwidth;
388 }
389 
390 } //namespace ns3
ERP-OFDM PHY (Clause 19, Section 19.5)
tuple channel
Definition: third.py:85
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1496
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
TracedCallback< bool, uint32_t, double, Time > m_signalCb
Signal callback.
void AddForeignSignal(Time duration, double rxPower)
Add a non-Wifi signal to interference helper.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:54
double GetTxGain(void) const
Return the transmission gain (dB).
Definition: wifi-phy.cc:572
AttributeValue implementation for Boolean.
Definition: boolean.h:36
HT PHY for the 5 GHz band (clause 20)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
double Integral(const SpectrumValue &arg)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level Phy interface to this Sp...
802.11 PHY layer model
Definition: wifi-phy.h:164
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:41
Ptr< Channel > GetChannel(void) const
Return the Channel this WifiPhy is connected to.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
void StartTx(Ptr< Packet > packet, WifiTxVector txVector, Time txDuration)
static Ptr< SpectrumValue > CreateDsssTxPowerSpectralDensity(uint32_t centerFrequency, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to DSSS.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
HE PHY for the 2.4 GHz band (clause 26)
void StartReceivePreambleAndHeader(Ptr< Packet > packet, double rxPowerW, Time rxDuration)
Starting receiving the plcp of a packet (i.e.
Definition: wifi-phy.cc:2374
static TypeId GetTypeId(void)
Get the type ID.
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
bool m_disableWifiReception
forces this Phy to fail to sync on any signal
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
HT PHY for the 2.4 GHz band (clause 20)
VHT PHY (Clause 22)
Definition: wifi-mode.h:60
Ptr< const SpectrumModel > GetRxSpectrumModel() const
HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:48
static Ptr< SpectrumValue > CreateRfFilter(uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, uint8_t guardBandwidth)
Create a spectral density corresponding to the RF filter.
Ptr< WifiSpectrumPhyInterface > GetSpectrumPhy(void) const
virtual void SetFrequency(uint16_t freq)
Definition: wifi-phy.cc:1213
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1270
void SetAntenna(const Ptr< AntennaModel > antenna)
double GetBandBandwidth(void) const
virtual void SetChannelNumber(uint8_t id)
Set channel number.
static Ptr< SpectrumValue > CreateHeOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM High Efficiency (HE) (802...
uint8_t GetTxPowerLevel(void) const
void DoInitialize(void)
Initialize() implementation.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
uint32_t GetGuardBandwidth(void) const
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:726
std::vector< uint8_t > GetOperationalChannelList(void) const
Return a list of channels to which it may be possible to roam By default, this method will return the...
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM High Throughput (HT) (802...
HE PHY for the 5 GHz band (clause 26)
Ptr< AntennaModel > GetRxAntenna(void) const
Get the antenna model used for reception.
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, uint8_t guardBandwidth)
Return a SpectrumModel instance corresponding to the center frequency and channel width...
Ptr< SpectrumValue > GetTxPowerSpectralDensity(uint16_t centerFrequency, uint8_t channelWidth, double txPowerW, WifiModulationClass modulationClass) const
HT PHY (Clause 20)
Definition: wifi-mode.h:58
void DoDispose(void)
Destructor implementation.
802.11 PHY layer modelThis PHY implements a spectrum-aware enhancement of the 802.11 SpectrumWifiPhy model.
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
virtual void SetFrequency(uint16_t freq)
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void SetChannelWidth(uint8_t channelwidth)
Definition: wifi-phy.cc:1296
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
bool IsInitialized(void) const
Check if the object has been initialized.
Definition: object.cc:208
virtual void SetChannelNumber(uint8_t id)
Set channel number.
Definition: wifi-phy.cc:1442
virtual void DoInitialize(void)
Initialize() implementation.
Definition: wifi-phy.cc:415
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:48
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:34
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
uint8_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1304
WifiModulationClass
This enumeration defines the modulation classes per (Table 9-4 "Modulation classes"; IEEE 802...
Definition: wifi-mode.h:36
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
InterferenceHelper m_interference
Pointer to InterferenceHelper.
Definition: wifi-phy.h:1686
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Ptr< AntennaModel > m_antenna
antenna model
OFDM PHY (Clause 17)
Definition: wifi-mode.h:56
std::vector< uint8_t > m_operationalChannelList
List of possible channels.
virtual void SetChannelWidth(uint8_t channelwidth)
void ClearOperationalChannelList(void)
Clear the list of operational channels.
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
Spectrum phy interface.
void ResetSpectrumModel(void)
Perform run-time spectrum model change.
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
nanosecond
Definition: nstime.h:117
void AddOperationalChannel(uint8_t channelNumber)
Add a channel number to the list of operational channels.
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1147
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:487
WifiMode GetMode(void) const
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
Set of values corresponding to a given SpectrumModel.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
void SwitchMaybeToCcaBusy(void)
Check if Phy state should move to CCA busy state based on current state of interference tracker...
Definition: wifi-phy.cc:3625
WifiPhyStandard GetStandard(void) const
Get the configured Wi-Fi standard.
Definition: wifi-phy.cc:1207
double GetRxGain(void) const
Return the reception gain (dB).
Definition: wifi-phy.cc:585
HE PHY (Clause 26)
Definition: wifi-mode.h:62
DSSS PHY (Clause 15)
Definition: wifi-mode.h:46
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...