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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage, <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "yans-wifi-channel.h"
10
11#include "wifi-net-device.h"
12#include "wifi-ppdu.h"
13#include "wifi-psdu.h"
14#include "wifi-utils.h"
15#include "yans-wifi-phy.h"
16
17#include "ns3/log.h"
18#include "ns3/mobility-model.h"
19#include "ns3/node.h"
20#include "ns3/pointer.h"
21#include "ns3/propagation-delay-model.h"
22#include "ns3/propagation-loss-model.h"
23#include "ns3/simulator.h"
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("YansWifiChannel");
29
30NS_OBJECT_ENSURE_REGISTERED(YansWifiChannel);
31
32TypeId
34{
35 static TypeId tid =
36 TypeId("ns3::YansWifiChannel")
38 .SetGroupName("Wifi")
39 .AddConstructor<YansWifiChannel>()
40 .AddAttribute("PropagationLossModel",
41 "A pointer to the propagation loss model attached to this channel.",
45 .AddAttribute("PropagationDelayModel",
46 "A pointer to the propagation delay model attached to this channel.",
50 return tid;
51}
52
57
63
64void
70
71void
77
78void
80{
81 NS_LOG_FUNCTION(this << sender << ppdu << txPower);
82 Ptr<MobilityModel> senderMobility = sender->GetMobility();
83 NS_ASSERT(senderMobility);
84 for (auto i = m_phyList.begin(); i != m_phyList.end(); i++)
85 {
86 if (sender != (*i))
87 {
88 // For now don't account for inter channel interference nor channel bonding
89 if ((*i)->GetChannelNumber() != sender->GetChannelNumber())
90 {
91 continue;
92 }
93
94 auto receiverMobility = (*i)->GetMobility()->GetObject<MobilityModel>();
95 const auto delay = m_delay->GetDelay(senderMobility, receiverMobility);
96 const auto rxPower = m_loss->CalcRxPower(txPower, senderMobility, receiverMobility);
97 NS_LOG_DEBUG("propagation: txPower="
98 << txPower << "dBm, rxPower=" << rxPower << "dBm, "
99 << "distance=" << senderMobility->GetDistanceFrom(receiverMobility)
100 << "m, delay=" << delay);
101 auto dstNetDevice = (*i)->GetDevice();
102 uint32_t dstNode;
103 if (!dstNetDevice)
104 {
105 dstNode = 0xffffffff;
106 }
107 else
108 {
109 dstNode = dstNetDevice->GetNode()->GetId();
110 }
111
113 delay,
115 (*i),
116 ppdu,
117 rxPower);
118 }
119 }
120}
121
122void
124{
125 NS_LOG_FUNCTION(phy << ppdu << rxPower);
126 const auto totalRxPower = rxPower + phy->GetRxGain();
127 phy->TraceSignalArrival(ppdu, totalRxPower, ppdu->GetTxDuration());
128 // Do no further processing if signal is too weak
129 // Current implementation assumes constant RX power over the PPDU duration
130 // Compare received TX power per MHz to normalized RX sensitivity
131 const auto txWidth = ppdu->GetTxChannelWidth();
132 if (totalRxPower < phy->GetRxSensitivity() + RatioToDb(txWidth / 20.0))
133 {
134 NS_LOG_INFO("Received signal too weak to process: " << rxPower << " dBm");
135 return;
136 }
138 rxPowerW.insert({{{{0, 0}}, {{0, 0}}}, (DbmToW(totalRxPower))}); // dummy band for YANS
139 phy->StartReceivePreamble(ppdu, rxPowerW, ppdu->GetTxDuration());
140}
141
142std::size_t
144{
145 return m_phyList.size();
146}
147
149YansWifiChannel::GetDevice(std::size_t i) const
150{
151 return m_phyList[i]->GetDevice();
152}
153
154void
156{
157 NS_LOG_FUNCTION(this << phy);
158 m_phyList.push_back(phy);
159}
160
161int64_t
163{
164 NS_LOG_FUNCTION(this << stream);
165 int64_t currentStream = stream;
166 currentStream += m_loss->AssignStreams(stream);
167 return (currentStream - stream);
168}
169
170} // namespace ns3
Abstract Channel Base Class.
Definition channel.h:34
Keep track of the current position and velocity of an object.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:577
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
a channel to interconnect ns3::YansWifiPhy objects.
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
static void Receive(Ptr< YansWifiPhy > receiver, Ptr< const WifiPpdu > ppdu, dBm_u txPower)
This method is scheduled by Send for each associated YansWifiPhy.
static TypeId GetTypeId()
Get the type ID.
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
void Send(Ptr< YansWifiPhy > sender, Ptr< const WifiPpdu > ppdu, dBm_u txPower) const
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:55
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#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
#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:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:44
std::map< WifiSpectrumBandInfo, Watt_u > RxPowerWattPerChannelBand
A map of the received power for each band.
Definition phy-entity.h:45
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:31
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.