A Discrete-Event Network Simulator
API
spectrum-wifi-helper.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008 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 * S├ębastien Deronne <sebastien.deronne@gmail.com>
20 */
21
22#include "ns3/log.h"
23#include "ns3/names.h"
24#include "ns3/spectrum-wifi-phy.h"
25#include "ns3/interference-helper.h"
26#include "ns3/error-rate-model.h"
27#include "ns3/frame-capture-model.h"
28#include "ns3/preamble-detection-model.h"
29#include "ns3/mobility-model.h"
30#include "ns3/wifi-net-device.h"
32
33namespace ns3 {
34
35NS_LOG_COMPONENT_DEFINE ("SpectrumWifiHelper");
36
38 : WifiPhyHelper (nLinks)
39{
40 NS_ABORT_IF (m_phy.size () != nLinks);
41 for (auto& phy : m_phy)
42 {
43 phy.SetTypeId ("ns3::SpectrumWifiPhy");
44 }
45 m_channels.resize (m_phy.size ());
46 SetInterferenceHelper ("ns3::InterferenceHelper");
47 SetErrorRateModel ("ns3::TableBasedErrorRateModel");
48}
49
50void
52{
53 for (auto& ch : m_channels)
54 {
55 ch = channel;
56 }
57}
58
59void
60SpectrumWifiPhyHelper::SetChannel (std::string channelName)
61{
62 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
63 for (auto& ch : m_channels)
64 {
65 ch = channel;
66 }
67}
68
69void
71{
72 m_channels.at (linkId) = channel;
73}
74
75void
76SpectrumWifiPhyHelper::SetChannel (uint8_t linkId, std::string channelName)
77{
78 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
79 m_channels.at (linkId) = channel;
80}
81
82std::vector<Ptr<WifiPhy>>
84{
85 std::vector<Ptr<WifiPhy>> ret;
87
88 for (std::size_t i = 0; i < m_phy.size (); i++)
89 {
91 phy->CreateWifiSpectrumPhyInterface (device);
92 phy->SetInterferenceHelper (interference);
93 Ptr<ErrorRateModel> error = m_errorRateModel.at (i).Create<ErrorRateModel> ();
94 phy->SetErrorRateModel (error);
95 if (m_frameCaptureModel.at (i).IsTypeIdSet ())
96 {
97 auto frameCapture = m_frameCaptureModel.at (i).Create<FrameCaptureModel> ();
98 phy->SetFrameCaptureModel (frameCapture);
99 }
100 if (m_preambleDetectionModel.at (i).IsTypeIdSet ())
101 {
102 auto preambleDetection = m_preambleDetectionModel.at (i).Create<PreambleDetectionModel> ();
103 phy->SetPreambleDetectionModel (preambleDetection);
104 }
105 phy->SetChannel (m_channels.at (i));
106 phy->SetDevice (device);
107 phy->SetMobility (node->GetObject<MobilityModel> ());
108 ret.push_back (phy);
109 }
110
111 return ret;
112}
113
114} //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(void) const
Create an Object instance of the configured TypeId.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
the interface for Wifi's preamble detection models
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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:49
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
Definition: wifi-helper.h:531
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
Definition: wifi-helper.h:523
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
Definition: wifi-helper.h:237
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
Definition: wifi-helper.h:238
std::vector< ObjectFactory > m_phy
PHY object.
Definition: wifi-helper.h:234
std::vector< ObjectFactory > m_errorRateModel
error rate model
Definition: wifi-helper.h:236
ObjectFactory m_interferenceHelper
interference helper
Definition: wifi-helper.h:235
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:83
phy
Definition: third.py:84