A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
yans-wifi-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 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 * Author: Mathieu Lacage, <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "yans-wifi-channel.h"
21
22#include "wifi-net-device.h"
23#include "wifi-ppdu.h"
24#include "wifi-psdu.h"
25#include "wifi-utils.h"
26#include "yans-wifi-phy.h"
27
28#include "ns3/log.h"
29#include "ns3/mobility-model.h"
30#include "ns3/node.h"
31#include "ns3/pointer.h"
32#include "ns3/propagation-delay-model.h"
33#include "ns3/propagation-loss-model.h"
34#include "ns3/simulator.h"
35
36namespace ns3
37{
38
39NS_LOG_COMPONENT_DEFINE("YansWifiChannel");
40
41NS_OBJECT_ENSURE_REGISTERED(YansWifiChannel);
42
43TypeId
45{
46 static TypeId tid =
47 TypeId("ns3::YansWifiChannel")
49 .SetGroupName("Wifi")
50 .AddConstructor<YansWifiChannel>()
51 .AddAttribute("PropagationLossModel",
52 "A pointer to the propagation loss model attached to this channel.",
55 MakePointerChecker<PropagationLossModel>())
56 .AddAttribute("PropagationDelayModel",
57 "A pointer to the propagation delay model attached to this channel.",
60 MakePointerChecker<PropagationDelayModel>());
61 return tid;
62}
63
65{
66 NS_LOG_FUNCTION(this);
67}
68
70{
71 NS_LOG_FUNCTION(this);
72 m_phyList.clear();
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << loss);
79 m_loss = loss;
80}
81
82void
84{
85 NS_LOG_FUNCTION(this << delay);
86 m_delay = delay;
87}
88
89void
90YansWifiChannel::Send(Ptr<YansWifiPhy> sender, Ptr<const WifiPpdu> ppdu, double txPowerDbm) const
91{
92 NS_LOG_FUNCTION(this << sender << ppdu << txPowerDbm);
93 Ptr<MobilityModel> senderMobility = sender->GetMobility();
94 NS_ASSERT(senderMobility);
95 for (auto i = m_phyList.begin(); i != m_phyList.end(); i++)
96 {
97 if (sender != (*i))
98 {
99 // For now don't account for inter channel interference nor channel bonding
100 if ((*i)->GetChannelNumber() != sender->GetChannelNumber())
101 {
102 continue;
103 }
104
105 Ptr<MobilityModel> receiverMobility = (*i)->GetMobility()->GetObject<MobilityModel>();
106 Time delay = m_delay->GetDelay(senderMobility, receiverMobility);
107 double rxPowerDbm = m_loss->CalcRxPower(txPowerDbm, senderMobility, receiverMobility);
108 NS_LOG_DEBUG("propagation: txPower="
109 << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, "
110 << "distance=" << senderMobility->GetDistanceFrom(receiverMobility)
111 << "m, delay=" << delay);
112 Ptr<NetDevice> dstNetDevice = (*i)->GetDevice();
113 uint32_t dstNode;
114 if (!dstNetDevice)
115 {
116 dstNode = 0xffffffff;
117 }
118 else
119 {
120 dstNode = dstNetDevice->GetNode()->GetId();
121 }
122
124 delay,
126 (*i),
127 ppdu,
128 rxPowerDbm);
129 }
130 }
131}
132
133void
135{
136 NS_LOG_FUNCTION(phy << ppdu << rxPowerDbm);
137 // Do no further processing if signal is too weak
138 // Current implementation assumes constant RX power over the PPDU duration
139 // Compare received TX power per MHz to normalized RX sensitivity
140 uint16_t txWidth = ppdu->GetTxChannelWidth();
141 if ((rxPowerDbm + phy->GetRxGain()) < phy->GetRxSensitivity() + RatioToDb(txWidth / 20.0))
142 {
143 NS_LOG_INFO("Received signal too weak to process: " << rxPowerDbm << " dBm");
144 return;
145 }
147 rxPowerW.insert(
148 {{{0, 0}, {0, 0}}, (DbmToW(rxPowerDbm + phy->GetRxGain()))}); // dummy band for YANS
149 phy->StartReceivePreamble(ppdu, rxPowerW, ppdu->GetTxDuration());
150}
151
152std::size_t
154{
155 return m_phyList.size();
156}
157
159YansWifiChannel::GetDevice(std::size_t i) const
160{
161 return m_phyList[i]->GetDevice();
162}
163
164void
166{
167 NS_LOG_FUNCTION(this << phy);
168 m_phyList.push_back(phy);
169}
170
171int64_t
173{
174 NS_LOG_FUNCTION(this << stream);
175 int64_t currentStream = stream;
176 currentStream += m_loss->AssignStreams(stream);
177 return (currentStream - stream);
178}
179
180} // namespace ns3
Abstract Channel Base Class.
Definition: channel.h:45
Keep track of the current position and velocity of an object.
AttributeValue implementation for Pointer.
Definition: pointer.h:48
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:588
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
a channel to interconnect ns3::YansWifiPhy objects.
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
static TypeId GetTypeId()
Get the type ID.
static void Receive(Ptr< YansWifiPhy > receiver, Ptr< const WifiPpdu > ppdu, double txPowerDbm)
This method is scheduled by Send for each associated YansWifiPhy.
void Send(Ptr< YansWifiPhy > sender, Ptr< const WifiPpdu > ppdu, double txPowerDbm) const
Ptr< NetDevice > GetDevice(std::size_t i) const override
PhyList m_phyList
List of YansWifiPhys connected to this YansWifiChannel.
Ptr< PropagationLossModel > m_loss
Propagation loss model.
std::size_t GetNDevices() const override
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
void Add(Ptr< YansWifiPhy > phy)
Adds the given YansWifiPhy to the PHY list.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:259
#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
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:52
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:40
std::map< WifiSpectrumBandInfo, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:77
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.