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/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 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
38 
39 NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel);
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::YansWifiChannel")
45  .SetParent<Channel> ()
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 
71 void
73 {
74  NS_LOG_FUNCTION (this << loss);
75  m_loss = loss;
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION (this << delay);
82  m_delay = delay;
83 }
84 
85 void
86 YansWifiChannel::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 = Copy (ppdu);
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 
119  delay, &YansWifiChannel::Receive,
120  (*i), copy, rxPowerDbm);
121  }
122  }
123 }
124 
125 void
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  }
136  phy->StartReceivePreamble (ppdu, DbmToW (rxPowerDbm + phy->GetRxGain ()));
137 }
138 
139 std::size_t
141 {
142  return m_phyList.size ();
143 }
144 
146 YansWifiChannel::GetDevice (std::size_t i) const
147 {
148  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this << phy);
155  m_phyList.push_back (phy);
156 }
157 
158 int64_t
160 {
161  NS_LOG_FUNCTION (this << stream);
162  int64_t currentStream = stream;
163  currentStream += m_loss->AssignStreams (stream);
164  return (currentStream - stream);
165 }
166 
167 } //namespace ns3
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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...
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:41
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Abstract Channel Base Class.
Definition: channel.h:43
static void Receive(Ptr< YansWifiPhy > receiver, Ptr< WifiPpdu > ppdu, double txPowerDbm)
This method is scheduled by Send for each associated YansWifiPhy.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
phy
Definition: third.py:93
Keep track of the current position and velocity of an object.
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
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:227
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Ptr< PropagationLossModel > m_loss
Propagation loss model.
PhyList m_phyList
List of YansWifiPhys connected to this YansWifiChannel.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:461
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:754
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1540
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1484
Network layer to device interface.
Definition: net-device.h:95
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
virtual std::size_t GetNDevices(void) const
void Add(Ptr< YansWifiPhy > phy)
Adds the given YansWifiPhy to the PHY list.
a channel to interconnect ns3::YansWifiPhy objects.
void Send(Ptr< YansWifiPhy > sender, Ptr< const WifiPpdu > ppdu, double txPowerDbm) const
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:690
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...