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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Sébastien Deronne <sebastien.deronne@gmail.com>
8 */
9
11
12#include "ns3/error-rate-model.h"
13#include "ns3/frame-capture-model.h"
14#include "ns3/interference-helper.h"
15#include "ns3/log.h"
16#include "ns3/mobility-model.h"
17#include "ns3/names.h"
18#include "ns3/preamble-detection-model.h"
19#include "ns3/spectrum-channel.h"
20#include "ns3/spectrum-transmit-filter.h"
21#include "ns3/spectrum-wifi-phy.h"
22#include "ns3/wifi-bandwidth-filter.h"
23#include "ns3/wifi-net-device.h"
24#include "ns3/wifi-spectrum-value-helper.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("SpectrumWifiHelper");
30
32 : WifiPhyHelper(nLinks)
33{
34 NS_ABORT_IF(m_phys.size() != nLinks);
35 for (auto& phy : m_phys)
36 {
37 phy.SetTypeId("ns3::SpectrumWifiPhy");
38 }
39 SetInterferenceHelper("ns3::InterferenceHelper");
40 SetErrorRateModel("ns3::TableBasedErrorRateModel");
41}
42
43void
48
49void
50SpectrumWifiPhyHelper::SetChannel(const std::string& channelName)
51{
52 AddChannel(channelName);
53}
54
55void
57 const FrequencyRange& freqRange)
58{
59 m_channels[freqRange] = channel;
61}
62
63void
64SpectrumWifiPhyHelper::AddChannel(const std::string& channelName, const FrequencyRange& freqRange)
65{
67 AddChannel(channel, freqRange);
68}
69
70void
72{
73 Ptr<const SpectrumTransmitFilter> p = channel->GetSpectrumTransmitFilter();
74 bool found = false;
75 while (p && !found)
76 {
78 {
79 NS_LOG_DEBUG("Found existing WifiBandwidthFilter for channel " << channel);
80 found = true;
81 }
82 else
83 {
84 NS_LOG_DEBUG("Found different SpectrumTransmitFilter for channel " << channel);
85 p = p->GetNext();
86 }
87 }
88 if (!found)
89 {
91 channel->AddSpectrumTransmitFilter(pWifi);
92 NS_LOG_DEBUG("Adding WifiBandwidthFilter to channel " << channel);
93 }
94}
95
96void
98{
99 if (auto it = m_interfacesMap.find(linkId); it == m_interfacesMap.end())
100 {
101 m_interfacesMap.insert({linkId, {freqRange}});
102 }
103 else
104 {
105 it->second.emplace(freqRange);
106 }
107}
108
109void
114
115std::vector<Ptr<WifiPhy>>
117{
118 std::vector<Ptr<WifiPhy>> ret;
119
120 for (std::size_t i = 0; i < m_phys.size(); i++)
121 {
122 auto phy = m_phys.at(i).Create<SpectrumWifiPhy>();
123 auto interference = m_interferenceHelper.Create<InterferenceHelper>();
124 phy->SetInterferenceHelper(interference);
125 auto error = m_errorRateModel.at(i).Create<ErrorRateModel>();
126 phy->SetErrorRateModel(error);
127 if (m_frameCaptureModel.at(i).IsTypeIdSet())
128 {
129 auto frameCapture = m_frameCaptureModel.at(i).Create<FrameCaptureModel>();
130 phy->SetFrameCaptureModel(frameCapture);
131 }
132 if (m_preambleDetectionModel.at(i).IsTypeIdSet())
133 {
134 auto preambleDetection =
136 phy->SetPreambleDetectionModel(preambleDetection);
137 }
138 InstallPhyInterfaces(i, phy);
139 phy->SetChannelSwitchedCallback(
141 phy->SetDevice(device);
142 phy->SetMobility(node->GetObject<MobilityModel>());
143 ret.emplace_back(phy);
144 }
145
146 return ret;
147}
148
149void
151{
152 if (!m_interfacesMap.contains(linkId))
153 {
154 // default setup: set all interfaces to this link
155 for (const auto& [freqRange, channel] : m_channels)
156 {
157 phy->AddChannel(channel, freqRange);
158 }
159 }
160 else
161 {
162 for (const auto& freqRange : m_interfacesMap.at(linkId))
163 {
164 phy->AddChannel(m_channels.at(freqRange), freqRange);
165 }
166 }
167}
168
169void
171{
172 for (const auto& otherPhy : phy->GetDevice()->GetPhys())
173 {
174 auto spectrumPhy = DynamicCast<SpectrumWifiPhy>(otherPhy);
175 NS_ASSERT(spectrumPhy);
176 if (spectrumPhy == phy)
177 {
178 // this is the PHY that has switched
179 continue;
180 }
181 if (spectrumPhy->GetCurrentFrequencyRange() == phy->GetCurrentFrequencyRange())
182 {
183 // this is the active interface
184 continue;
185 }
186 if (const auto& interfaces = spectrumPhy->GetSpectrumPhyInterfaces();
187 !interfaces.contains(phy->GetCurrentFrequencyRange()))
188 {
189 // no interface attached to that channel
190 continue;
191 }
192 spectrumPhy->ConfigureInterface(phy->GetOperatingChannel().GetFrequencies(),
193 phy->GetChannelWidth());
194 }
195}
196
197} // 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.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
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.
std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const override
void ResetPhyToFreqRangeMapping()
Reset mapping of the spectrum PHY interfaces added to the PHY instances.
SpectrumWifiPhyHelper(uint8_t nLinks=1)
Create a PHY helper.
std::map< uint8_t, std::set< FrequencyRange > > m_interfacesMap
map of the spectrum PHY interfaces to be added to the PHY instance corresponding to a given link ID
void AddChannel(const Ptr< SpectrumChannel > channel, const FrequencyRange &freqRange=WHOLE_WIFI_SPECTRUM)
void InstallPhyInterfaces(uint8_t linkId, Ptr< SpectrumWifiPhy > phy) const
Install PHY interfaces to the PHY instance of a given link based on the currently configured mapping ...
void SetChannel(const Ptr< SpectrumChannel > channel)
static void SpectrumChannelSwitched(Ptr< SpectrumWifiPhy > phy)
Function that is notified when a spectrum channel switched.
void AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange &freqRange)
Add a given spectrum PHY interface to the PHY instance corresponding of a given link.
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:39
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
std::vector< ObjectFactory > m_phys
PHY objects.
std::vector< ObjectFactory > m_errorRateModel
error rate model
ObjectFactory m_interferenceHelper
interference helper
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Struct defining a frequency range between minFrequency and maxFrequency.