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/mobility-model.h"
24 #include "ns3/net-device.h"
25 #include "ns3/node.h"
26 #include "ns3/log.h"
27 #include "ns3/pointer.h"
28 #include "ns3/object-factory.h"
29 #include "yans-wifi-channel.h"
30 #include "ns3/propagation-loss-model.h"
31 #include "ns3/propagation-delay-model.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
36 
37 NS_OBJECT_ENSURE_REGISTERED (YansWifiChannel);
38 
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::YansWifiChannel")
44  .SetGroupName ("Wifi")
45  .AddConstructor<YansWifiChannel> ()
46  .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
47  PointerValue (),
49  MakePointerChecker<PropagationLossModel> ())
50  .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
51  PointerValue (),
53  MakePointerChecker<PropagationDelayModel> ())
54  ;
55  return tid;
56 }
57 
59 {
60 }
61 
63 {
65  m_phyList.clear ();
66 }
67 
68 void
70 {
71  m_loss = loss;
72 }
73 
74 void
76 {
77  m_delay = delay;
78 }
79 
80 void
81 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm,
82  WifiTxVector txVector, WifiPreamble preamble, enum mpduType mpdutype, Time duration) const
83 {
84  Ptr<MobilityModel> senderMobility = sender->GetMobility ()->GetObject<MobilityModel> ();
85  NS_ASSERT (senderMobility != 0);
86  uint32_t j = 0;
87  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++, j++)
88  {
89  if (sender != (*i))
90  {
91  //For now don't account for inter channel interference
92  if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
93  {
94  continue;
95  }
96 
97  Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
98  Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
99  double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
100  NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
101  "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
102  Ptr<Packet> copy = packet->Copy ();
103  Ptr<Object> dstNetDevice = m_phyList[j]->GetDevice ();
104  uint32_t dstNode;
105  if (dstNetDevice == 0)
106  {
107  dstNode = 0xffffffff;
108  }
109  else
110  {
111  dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId ();
112  }
113 
114  struct Parameters parameters;
115  parameters.rxPowerDbm = rxPowerDbm;
116  parameters.type = mpdutype;
117  parameters.duration = duration;
118  parameters.txVector = txVector;
119  parameters.preamble = preamble;
120 
122  delay, &YansWifiChannel::Receive, this,
123  j, copy, parameters);
124  }
125  }
126 }
127 
128 void
129 YansWifiChannel::Receive (uint32_t i, Ptr<Packet> packet, struct Parameters parameters) const
130 {
131  m_phyList[i]->StartReceivePreambleAndHeader (packet, parameters.rxPowerDbm, parameters.txVector, parameters.preamble, parameters.type, parameters.duration);
132 }
133 
134 uint32_t
136 {
137  return m_phyList.size ();
138 }
139 
141 YansWifiChannel::GetDevice (uint32_t i) const
142 {
143  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
144 }
145 
146 void
148 {
149  m_phyList.push_back (phy);
150 }
151 
152 int64_t
154 {
155  int64_t currentStream = stream;
156  currentStream += m_loss->AssignStreams (stream);
157  return (currentStream - stream);
158 }
159 
160 } //namespace ns3
Ptr< PropagationDelayModel > m_delay
Propagation delay model.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
void Receive(uint32_t i, Ptr< Packet > packet, struct Parameters parameters) const
This method is scheduled by Send for each associated YansWifiPhy.
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)
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
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
Keep track of the current position and velocity of an object.
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
void Send(Ptr< YansWifiPhy > sender, Ptr< const Packet > packet, double txPowerDbm, WifiTxVector txVector, WifiPreamble preamble, enum mpduType mpdutype, Time duration) const
virtual uint16_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1329
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.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagatinLossModel(s) chained to the current one...
PhyList m_phyList
List of YansWifiPhys connected to this YansWifiChannel.
enum mpduType type
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
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)
Ptr< MobilityModel > GetMobility(void)
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:616
WifiPreamble preamble
Wifi Channel interface specificationThis class works in tandem with the ns3::WifiPhy class...
Definition: wifi-channel.h:43
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1319
Network layer to device interface.
Definition: net-device.h:405
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
WifiTxVector txVector
void Add(Ptr< YansWifiPhy > phy)
Adds the given YansWifiPhy to the PHY list.
A Yans wifi channelThis wifi channel implements the propagation model described in "Yet Another Netwo...
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
mpduType
This enumeration defines the type of an MPDU.
Definition: wifi-phy.h:56