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 "yans-wifi-channel.h"
25 #include "ns3/propagation-loss-model.h"
26 #include "ns3/propagation-delay-model.h"
27 #include "wifi-utils.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
32 
33 NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::YansWifiChannel")
39  .SetParent<Channel> ()
40  .SetGroupName ("Wifi")
41  .AddConstructor<YansWifiChannel> ()
42  .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
43  PointerValue (),
45  MakePointerChecker<PropagationLossModel> ())
46  .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
47  PointerValue (),
49  MakePointerChecker<PropagationDelayModel> ())
50  ;
51  return tid;
52 }
53 
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 
60 {
61  NS_LOG_FUNCTION (this);
62  m_phyList.clear ();
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this << loss);
69  m_loss = loss;
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION (this << delay);
76  m_delay = delay;
77 }
78 
79 void
80 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm, Time duration) const
81 {
82  NS_LOG_FUNCTION (this << sender << packet << txPowerDbm << duration.GetSeconds ());
83  Ptr<MobilityModel> senderMobility = sender->GetMobility ();
84  NS_ASSERT (senderMobility != 0);
85  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
86  {
87  if (sender != (*i))
88  {
89  //For now don't account for inter channel interference nor channel bonding
90  if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
91  {
92  continue;
93  }
94 
95  Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
96  Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
97  double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
98  NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
99  "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
100  Ptr<Packet> copy = packet->Copy ();
101  Ptr<NetDevice> dstNetDevice = (*i)->GetDevice ();
102  uint32_t dstNode;
103  if (dstNetDevice == 0)
104  {
105  dstNode = 0xffffffff;
106  }
107  else
108  {
109  dstNode = dstNetDevice->GetNode ()->GetId ();
110  }
111 
113  delay, &YansWifiChannel::Receive,
114  (*i), copy, rxPowerDbm, duration);
115  }
116  }
117 }
118 
119 void
120 YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
121 {
122  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
123  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
124 }
125 
126 uint32_t
128 {
129  return m_phyList.size ();
130 }
131 
133 YansWifiChannel::GetDevice (uint32_t i) const
134 {
135  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION (this << phy);
142  m_phyList.push_back (phy);
143 }
144 
145 int64_t
147 {
148  NS_LOG_FUNCTION (this << stream);
149  int64_t currentStream = stream;
150  currentStream += m_loss->AssignStreams (stream);
151  return (currentStream - stream);
152 }
153 
154 } //namespace ns3
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1482
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 "...
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
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:42
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:201
Abstract Channel Base Class.
Definition: channel.h:43
void StartReceivePreambleAndHeader(Ptr< Packet > packet, double rxPowerW, Time rxDuration)
Starting receiving the plcp of a packet (i.e.
Definition: wifi-phy.cc:2423
void Send(Ptr< YansWifiPhy > sender, Ptr< const Packet > packet, double txPowerDbm, Time duration) const
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
tuple phy
Definition: third.py:86
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:220
virtual uint32_t GetNDevices(void) const
Ptr< PropagationLossModel > m_loss
Propagation loss model.
static void Receive(Ptr< YansWifiPhy > receiver, Ptr< Packet > packet, double txPowerDbm, Time duration)
This method is scheduled by Send for each associated YansWifiPhy.
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...
PhyList m_phyList
List of YansWifiPhys connected to this YansWifiChannel.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
Definition: pointer.h:36
static TypeId GetTypeId(void)
Get the type ID.
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1469
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:269
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:672
void Add(Ptr< YansWifiPhy > phy)
Adds the given YansWifiPhy to the PHY list.
a channel to interconnect ns3::YansWifiPhy objects.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
double GetRxGain(void) const
Return the reception gain (dB).
Definition: wifi-phy.cc:569
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...