A Discrete-Event Network Simulator
API
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 
21 #include "spectrum-wifi-helper.h"
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-wifi-phy.h"
31 #include "ns3/wifi-net-device.h"
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("SpectrumWifiHelper");
37 
39  : WifiPhyHelper(nLinks)
40 {
41  NS_ABORT_IF(m_phy.size() != nLinks);
42  for (auto& phy : m_phy)
43  {
44  phy.SetTypeId("ns3::SpectrumWifiPhy");
45  }
46  m_channels.resize(m_phy.size());
47  SetInterferenceHelper("ns3::InterferenceHelper");
48  SetErrorRateModel("ns3::TableBasedErrorRateModel");
49 }
50 
51 void
53 {
54  for (auto& ch : m_channels)
55  {
56  ch = channel;
57  }
58 }
59 
60 void
61 SpectrumWifiPhyHelper::SetChannel(std::string channelName)
62 {
63  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
64  for (auto& ch : m_channels)
65  {
66  ch = channel;
67  }
68 }
69 
70 void
72 {
73  m_channels.at(linkId) = channel;
74 }
75 
76 void
77 SpectrumWifiPhyHelper::SetChannel(uint8_t linkId, std::string channelName)
78 {
79  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
80  m_channels.at(linkId) = channel;
81 }
82 
83 std::vector<Ptr<WifiPhy>>
85 {
86  std::vector<Ptr<WifiPhy>> ret;
87 
88  for (std::size_t i = 0; i < m_phy.size(); i++)
89  {
91  phy->CreateWifiSpectrumPhyInterface(device);
92  auto interference = m_interferenceHelper.Create<InterferenceHelper>();
93  phy->SetInterferenceHelper(interference);
94  Ptr<ErrorRateModel> error = m_errorRateModel.at(i).Create<ErrorRateModel>();
95  phy->SetErrorRateModel(error);
96  if (m_frameCaptureModel.at(i).IsTypeIdSet())
97  {
98  auto frameCapture = m_frameCaptureModel.at(i).Create<FrameCaptureModel>();
99  phy->SetFrameCaptureModel(frameCapture);
100  }
101  if (m_preambleDetectionModel.at(i).IsTypeIdSet())
102  {
103  auto preambleDetection =
105  phy->SetPreambleDetectionModel(preambleDetection);
106  }
107  phy->SetChannel(m_channels.at(i));
108  phy->SetDevice(device);
109  phy->SetMobility(node->GetObject<MobilityModel>());
110  ret.emplace_back(phy);
111  }
112 
113  return ret;
114 }
115 
116 } // 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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
the interface for Wifi's preamble detection models
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
std::vector< Ptr< SpectrumChannel > > m_channels
the channels
std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const override
SpectrumWifiPhyHelper(uint8_t nLinks=1)
Create a PHY helper.
void SetChannel(Ptr< SpectrumChannel > channel)
802.11 PHY layer model
create PHY objects
Definition: wifi-helper.h:50
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
Definition: wifi-helper.h:551
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
Definition: wifi-helper.h:543
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
Definition: wifi-helper.h:242
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
Definition: wifi-helper.h:243
std::vector< ObjectFactory > m_phy
PHY object.
Definition: wifi-helper.h:239
std::vector< ObjectFactory > m_errorRateModel
error rate model
Definition: wifi-helper.h:241
ObjectFactory m_interferenceHelper
interference helper
Definition: wifi-helper.h:240
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:81
phy
Definition: third.py:82