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/packet.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/pointer.h"
25 #include "ns3/net-device.h"
26 #include "ns3/node.h"
27 #include "ns3/propagation-loss-model.h"
28 #include "ns3/propagation-delay-model.h"
29 #include "ns3/mobility-model.h"
30 #include "yans-wifi-channel.h"
31 #include "yans-wifi-phy.h"
32 #include "wifi-utils.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
37 
38 NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::YansWifiChannel")
44  .SetParent<Channel> ()
45  .SetGroupName ("Wifi")
46  .AddConstructor<YansWifiChannel> ()
47  .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
48  PointerValue (),
50  MakePointerChecker<PropagationLossModel> ())
51  .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
52  PointerValue (),
54  MakePointerChecker<PropagationDelayModel> ())
55  ;
56  return tid;
57 }
58 
60 {
61  NS_LOG_FUNCTION (this);
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67  m_phyList.clear ();
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this << loss);
74  m_loss = loss;
75 }
76 
77 void
79 {
80  NS_LOG_FUNCTION (this << delay);
81  m_delay = delay;
82 }
83 
84 void
85 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm, Time duration) const
86 {
87  NS_LOG_FUNCTION (this << sender << packet << txPowerDbm << duration.GetSeconds ());
88  Ptr<MobilityModel> senderMobility = sender->GetMobility ();
89  NS_ASSERT (senderMobility != 0);
90  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
91  {
92  if (sender != (*i))
93  {
94  //For now don't account for inter channel interference nor channel bonding
95  if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
96  {
97  continue;
98  }
99 
100  Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
101  Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
102  double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
103  NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
104  "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
105  Ptr<Packet> copy = packet->Copy ();
106  Ptr<NetDevice> dstNetDevice = (*i)->GetDevice ();
107  uint32_t dstNode;
108  if (dstNetDevice == 0)
109  {
110  dstNode = 0xffffffff;
111  }
112  else
113  {
114  dstNode = dstNetDevice->GetNode ()->GetId ();
115  }
116 
118  delay, &YansWifiChannel::Receive,
119  (*i), copy, rxPowerDbm, duration);
120  }
121  }
122 }
123 
124 void
125 YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
126 {
127  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
128  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
129 }
130 
131 std::size_t
133 {
134  return m_phyList.size ();
135 }
136 
138 YansWifiChannel::GetDevice (std::size_t i) const
139 {
140  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION (this << phy);
147  m_phyList.push_back (phy);
148 }
149 
150 int64_t
152 {
153  NS_LOG_FUNCTION (this << stream);
154  int64_t currentStream = stream;
155  currentStream += m_loss->AssignStreams (stream);
156  return (currentStream - stream);
157 }
158 
159 } //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:38
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:202
Abstract Channel Base Class.
Definition: channel.h:43
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
phy
Definition: third.py:86
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:220
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.
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:459
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:668
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1415
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1475
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:270
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 Packet > packet, double txPowerDbm, Time duration) const
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...