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  m_loss = loss;
69 }
70 
71 void
73 {
74  m_delay = delay;
75 }
76 
77 void
78 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm, Time duration) const
79 {
80  NS_LOG_FUNCTION (this << sender << packet << txPowerDbm << duration.GetSeconds ());
81  Ptr<MobilityModel> senderMobility = sender->GetMobility ();
82  NS_ASSERT (senderMobility != 0);
83  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
84  {
85  if (sender != (*i))
86  {
87  //For now don't account for inter channel interference nor channel bonding
88  if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
89  {
90  continue;
91  }
92 
93  Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
94  Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
95  double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
96  NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
97  "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
98  Ptr<Packet> copy = packet->Copy ();
99  Ptr<NetDevice> dstNetDevice = (*i)->GetDevice ();
100  uint32_t dstNode;
101  if (dstNetDevice == 0)
102  {
103  dstNode = 0xffffffff;
104  }
105  else
106  {
107  dstNode = dstNetDevice->GetNode ()->GetId ();
108  }
109 
111  delay, &YansWifiChannel::Receive,
112  (*i), copy, rxPowerDbm, duration);
113  }
114  }
115 }
116 
117 void
118 YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
119 {
120  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
121  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
122 }
123 
124 uint32_t
126 {
127  return m_phyList.size ();
128 }
129 
131 YansWifiChannel::GetDevice (uint32_t i) const
132 {
133  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
134 }
135 
136 void
138 {
139  m_phyList.push_back (phy);
140 }
141 
142 int64_t
144 {
145  NS_LOG_FUNCTION (this << stream);
146  int64_t currentStream = stream;
147  currentStream += m_loss->AssignStreams (stream);
148  return (currentStream - stream);
149 }
150 
151 } //namespace ns3
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1496
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: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: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:2374
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:341
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:688
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:585
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...