A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ns3/packet.h"
21 #include "ns3/simulator.h"
22 #include "ns3/mobility-model.h"
23 #include "ns3/net-device.h"
24 #include "ns3/node.h"
25 #include "ns3/log.h"
26 #include "ns3/pointer.h"
27 #include "ns3/object-factory.h"
28 #include "yans-wifi-channel.h"
29 #include "yans-wifi-phy.h"
30 #include "ns3/propagation-loss-model.h"
31 #include "ns3/propagation-delay-model.h"
32 
33 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
34 
35 namespace ns3 {
36 
37 NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel)
38  ;
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::YansWifiChannel")
45  .AddConstructor<YansWifiChannel> ()
46  .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
47  PointerValue (),
48  MakePointerAccessor (&YansWifiChannel::m_loss),
49  MakePointerChecker<PropagationLossModel> ())
50  .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
51  PointerValue (),
52  MakePointerAccessor (&YansWifiChannel::m_delay),
53  MakePointerChecker<PropagationDelayModel> ())
54  ;
55  return tid;
56 }
57 
59 {
60 }
62 {
64  m_phyList.clear ();
65 }
66 
67 void
69 {
70  m_loss = loss;
71 }
72 void
74 {
75  m_delay = delay;
76 }
77 
78 void
79 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm,
80  WifiTxVector txVector, WifiPreamble preamble) const
81 {
82  Ptr<MobilityModel> senderMobility = sender->GetMobility ()->GetObject<MobilityModel> ();
83  NS_ASSERT (senderMobility != 0);
84  uint32_t j = 0;
85  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++, j++)
86  {
87  if (sender != (*i))
88  {
89  // For now don't account for inter channel interference
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<Object> dstNetDevice = m_phyList[j]->GetDevice ();
102  uint32_t dstNode;
103  if (dstNetDevice == 0)
104  {
105  dstNode = 0xffffffff;
106  }
107  else
108  {
109  dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId ();
110  }
112  delay, &YansWifiChannel::Receive, this,
113  j, copy, rxPowerDbm, txVector, preamble);
114  }
115  }
116 }
117 
118 void
119 YansWifiChannel::Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm,
120  WifiTxVector txVector, WifiPreamble preamble) const
121 {
122  m_phyList[i]->StartReceivePacket (packet, rxPowerDbm, txVector, preamble);
123 }
124 
125 uint32_t
127 {
128  return m_phyList.size ();
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  int64_t currentStream = stream;
146  currentStream += m_loss->AssignStreams (stream);
147  return (currentStream - stream);
148 }
149 
150 } // namespace ns3
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
double GetDistanceFrom(Ptr< const MobilityModel > position) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void SetPropagationLossModel(Ptr< PropagationLossModel > loss)
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint16_t GetChannelNumber() const
Return the current channel number.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:29
Keep track of the current position and velocity of an object.
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
virtual uint32_t GetNDevices(void) const
Ptr< PropagationLossModel > m_loss
Propagation loss model.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:904
PhyList m_phyList
List of YansWifiPhys connected to this YansWifiChannel.
Ptr< Packet > Copy(void) const
Definition: packet.cc:122
hold objects of type Ptr
Definition: pointer.h:33
static TypeId GetTypeId(void)
Wifi Channel interface specificationThis class works in tandem with the ns3::WifiPhy class...
Definition: wifi-channel.h:42
void Receive(uint32_t i, Ptr< Packet > packet, double rxPowerDbm, WifiTxVector txVector, WifiPreamble preamble) const
This method is scheduled by Send for each associated YansWifiPhy.
Network layer to device interface.
Definition: net-device.h:75
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
void Add(Ptr< YansWifiPhy > phy)
Adds the given YansWifiPhy to the PHY list.
NS_LOG_COMPONENT_DEFINE("YansWifiChannel")
void Send(Ptr< YansWifiPhy > sender, Ptr< const Packet > packet, double txPowerDbm, WifiTxVector txVector, WifiPreamble preamble) const
Ptr< T > GetObject(void) const
Definition: object.h:361
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
Ptr< Object > GetMobility(void)
Return the mobility model this PHY is associated with.