A Discrete-Event Network Simulator
API
yans-wifi-channel.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2006,2007 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 * Author: Mathieu Lacage, <mathieu.lacage@sophia.inria.fr>
19 */
20
21#include "ns3/simulator.h"
22#include "ns3/log.h"
23#include "ns3/pointer.h"
24#include "ns3/wifi-net-device.h"
25#include "ns3/node.h"
26#include "ns3/propagation-loss-model.h"
27#include "ns3/propagation-delay-model.h"
28#include "ns3/mobility-model.h"
29#include "yans-wifi-channel.h"
30#include "yans-wifi-phy.h"
31#include "wifi-utils.h"
32#include "wifi-ppdu.h"
33#include "wifi-psdu.h"
34
35namespace ns3 {
36
37NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
38
39NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel);
40
41TypeId
43{
44 static TypeId tid = TypeId ("ns3::YansWifiChannel")
46 .SetGroupName ("Wifi")
47 .AddConstructor<YansWifiChannel> ()
48 .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
49 PointerValue (),
51 MakePointerChecker<PropagationLossModel> ())
52 .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
53 PointerValue (),
55 MakePointerChecker<PropagationDelayModel> ())
56 ;
57 return tid;
58}
59
61{
62 NS_LOG_FUNCTION (this);
63}
64
66{
67 NS_LOG_FUNCTION (this);
68 m_phyList.clear ();
69}
70
71void
73{
74 NS_LOG_FUNCTION (this << loss);
75 m_loss = loss;
76}
77
78void
80{
81 NS_LOG_FUNCTION (this << delay);
82 m_delay = delay;
83}
84
85void
86YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const WifiPpdu> ppdu, double txPowerDbm) const
87{
88 NS_LOG_FUNCTION (this << sender << ppdu << txPowerDbm);
89 Ptr<MobilityModel> senderMobility = sender->GetMobility ();
90 NS_ASSERT (senderMobility != 0);
91 for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
92 {
93 if (sender != (*i))
94 {
95 //For now don't account for inter channel interference nor channel bonding
96 if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
97 {
98 continue;
99 }
100
101 Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
102 Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
103 double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
104 NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
105 "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
106 Ptr<WifiPpdu> copy = ppdu->Copy ();
107 Ptr<NetDevice> dstNetDevice = (*i)->GetDevice ();
108 uint32_t dstNode;
109 if (dstNetDevice == 0)
110 {
111 dstNode = 0xffffffff;
112 }
113 else
114 {
115 dstNode = dstNetDevice->GetNode ()->GetId ();
116 }
117
120 (*i), copy, rxPowerDbm);
121 }
122 }
123}
124
125void
127{
128 NS_LOG_FUNCTION (phy << ppdu << rxPowerDbm);
129 // Do no further processing if signal is too weak
130 // Current implementation assumes constant RX power over the PPDU duration
131 if ((rxPowerDbm + phy->GetRxGain ()) < phy->GetRxSensitivity ())
132 {
133 NS_LOG_INFO ("Received signal too weak to process: " << rxPowerDbm << " dBm");
134 return;
135 }
137 rxPowerW.insert ({std::make_pair (0, 0), (DbmToW (rxPowerDbm + phy->GetRxGain ()))}); //dummy band for YANS
138 phy->StartReceivePreamble (ppdu, rxPowerW, ppdu->GetTxDuration ());
139}
140
141std::size_t
143{
144 return m_phyList.size ();
145}
146
148YansWifiChannel::GetDevice (std::size_t i) const
149{
150 return m_phyList[i]->GetDevice ();
151}
152
153void
155{
156 NS_LOG_FUNCTION (this << phy);
157 m_phyList.push_back (phy);
158}
159
160int64_t
162{
163 NS_LOG_FUNCTION (this << stream);
164 int64_t currentStream = stream;
165 currentStream += m_loss->AssignStreams (stream);
166 return (currentStream - stream);
167}
168
169} //namespace ns3
Abstract Channel Base Class.
Definition: channel.h:44
Keep track of the current position and velocity of an object.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
virtual Ptr< Node > GetNode(void) const =0
uint32_t GetId(void) const
Definition: node.cc:109
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Hold objects of type Ptr<T>.
Definition: pointer.h:37
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 ...
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:895
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:544
a channel to interconnect ns3::YansWifiPhy objects.
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
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.
static void Receive(Ptr< YansWifiPhy > receiver, Ptr< WifiPpdu > ppdu, double txPowerDbm)
This method is scheduled by Send for each associated YansWifiPhy.
static TypeId GetTypeId(void)
Get the type ID.
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.
std::size_t GetNDevices(void) const override
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:37
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:75
phy
Definition: third.py:93
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.