A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-wifi-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 * Sébastien Deronne <sebastien.deronne@gmail.com>
19 */
20
22
23#include "ns3/error-rate-model.h"
24#include "ns3/frame-capture-model.h"
25#include "ns3/interference-helper.h"
26#include "ns3/log.h"
27#include "ns3/mobility-model.h"
28#include "ns3/names.h"
29#include "ns3/preamble-detection-model.h"
30#include "ns3/spectrum-channel.h"
31#include "ns3/spectrum-transmit-filter.h"
32#include "ns3/spectrum-wifi-phy.h"
33#include "ns3/wifi-bandwidth-filter.h"
34#include "ns3/wifi-net-device.h"
35#include "ns3/wifi-spectrum-value-helper.h"
36
37namespace ns3
38{
39
40NS_LOG_COMPONENT_DEFINE("SpectrumWifiHelper");
41
43 : WifiPhyHelper(nLinks)
44{
45 NS_ABORT_IF(m_phy.size() != nLinks);
46 for (auto& phy : m_phy)
47 {
48 phy.SetTypeId("ns3::SpectrumWifiPhy");
49 }
50 SetInterferenceHelper("ns3::InterferenceHelper");
51 SetErrorRateModel("ns3::TableBasedErrorRateModel");
52}
53
54void
56{
59}
60
61void
62SpectrumWifiPhyHelper::SetChannel(const std::string& channelName)
63{
64 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
67}
68
69void
71 const FrequencyRange& freqRange)
72{
73 m_channels[freqRange] = channel;
75}
76
77void
78SpectrumWifiPhyHelper::AddChannel(const std::string& channelName, const FrequencyRange& freqRange)
79{
80 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
81 AddChannel(channel, freqRange);
83}
84
85void
87{
88 Ptr<const SpectrumTransmitFilter> p = channel->GetSpectrumTransmitFilter();
89 bool found = false;
90 while (p && !found)
91 {
92 if (DynamicCast<const WifiBandwidthFilter>(p))
93 {
94 NS_LOG_DEBUG("Found existing WifiBandwidthFilter for channel " << channel);
95 found = true;
96 }
97 else
98 {
99 NS_LOG_DEBUG("Found different SpectrumTransmitFilter for channel " << channel);
100 p = p->GetNext();
101 }
102 }
103 if (!found)
104 {
105 Ptr<WifiBandwidthFilter> pWifi = CreateObject<WifiBandwidthFilter>();
106 channel->AddSpectrumTransmitFilter(pWifi);
107 NS_LOG_DEBUG("Adding WifiBandwidthFilter to channel " << channel);
108 }
109}
110
111std::vector<Ptr<WifiPhy>>
113{
114 std::vector<Ptr<WifiPhy>> ret;
115
116 for (std::size_t i = 0; i < m_phy.size(); i++)
117 {
118 Ptr<SpectrumWifiPhy> phy = m_phy.at(i).Create<SpectrumWifiPhy>();
119 auto interference = m_interferenceHelper.Create<InterferenceHelper>();
120 phy->SetInterferenceHelper(interference);
122 phy->SetErrorRateModel(error);
123 if (m_frameCaptureModel.at(i).IsTypeIdSet())
124 {
125 auto frameCapture = m_frameCaptureModel.at(i).Create<FrameCaptureModel>();
126 phy->SetFrameCaptureModel(frameCapture);
127 }
128 if (m_preambleDetectionModel.at(i).IsTypeIdSet())
129 {
130 auto preambleDetection =
132 phy->SetPreambleDetectionModel(preambleDetection);
133 }
134 for (const auto& [freqRange, channel] : m_channels)
135 {
136 phy->AddChannel(channel, freqRange);
137 }
138 phy->SetDevice(device);
139 phy->SetMobility(node->GetObject<MobilityModel>());
140 ret.emplace_back(phy);
141 }
142
143 return ret;
144}
145
146} // namespace ns3
the interface for Wifi's error models
the interface for Wifi's frame capture models
handles interference calculations
Keep track of the current position and velocity of an object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
the interface for Wifi's preamble detection models
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const override
SpectrumWifiPhyHelper(uint8_t nLinks=1)
Create a PHY helper.
void AddChannel(const Ptr< SpectrumChannel > channel, const FrequencyRange &freqRange=WHOLE_WIFI_SPECTRUM)
void AddChannel(const std::string &channelName, const FrequencyRange &freqRange=WHOLE_WIFI_SPECTRUM)
void SetChannel(const Ptr< SpectrumChannel > channel)
void AddWifiBandwidthFilter(Ptr< SpectrumChannel > channel)
std::map< FrequencyRange, Ptr< SpectrumChannel > > m_channels
the spectrum channels
802.11 PHY layer model
create PHY objects
Definition: wifi-helper.h:49
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
Definition: wifi-helper.h:550
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
Definition: wifi-helper.h:542
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
Definition: wifi-helper.h:241
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
Definition: wifi-helper.h:242
std::vector< ObjectFactory > m_phy
PHY object.
Definition: wifi-helper.h:238
std::vector< ObjectFactory > m_errorRateModel
error rate model
Definition: wifi-helper.h:240
ObjectFactory m_interferenceHelper
interference helper
Definition: wifi-helper.h:239
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr FrequencyRange WHOLE_WIFI_SPECTRUM
Identifier for the frequency range covering the whole wifi spectrum.
Struct defining a frequency range between minFrequency (MHz) and maxFrequency (MHz).