A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
yans-wifi-channel.cc
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 TypeId
40 YansWifiChannel::GetTypeId (void)
41 {
42  static TypeId tid = TypeId ("ns3::YansWifiChannel")
43  .SetParent<WifiChannel> ()
44  .AddConstructor<YansWifiChannel> ()
45  .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
46  PointerValue (),
47  MakePointerAccessor (&YansWifiChannel::m_loss),
48  MakePointerChecker<PropagationLossModel> ())
49  .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
50  PointerValue (),
51  MakePointerAccessor (&YansWifiChannel::m_delay),
52  MakePointerChecker<PropagationDelayModel> ())
53  ;
54  return tid;
55 }
56 
57 YansWifiChannel::YansWifiChannel ()
58 {
59 }
60 YansWifiChannel::~YansWifiChannel ()
61 {
63  m_phyList.clear ();
64 }
65 
66 void
68 {
69  m_loss = loss;
70 }
71 void
73 {
74  m_delay = delay;
75 }
76 
77 void
78 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm,
79  WifiMode wifiMode, WifiPreamble preamble) const
80 {
81  Ptr<MobilityModel> senderMobility = sender->GetMobility ()->GetObject<MobilityModel> ();
82  NS_ASSERT (senderMobility != 0);
83  uint32_t j = 0;
84  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++, j++)
85  {
86  if (sender != (*i))
87  {
88  // For now don't account for inter channel interference
89  if ((*i)->GetChannelNumber () != sender->GetChannelNumber ())
90  {
91  continue;
92  }
93 
94  Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
95  Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
96  double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
97  NS_LOG_DEBUG ("propagation: txPower=" << txPowerDbm << "dbm, rxPower=" << rxPowerDbm << "dbm, " <<
98  "distance=" << senderMobility->GetDistanceFrom (receiverMobility) << "m, delay=" << delay);
99  Ptr<Packet> copy = packet->Copy ();
100  Ptr<Object> dstNetDevice = m_phyList[j]->GetDevice ();
101  uint32_t dstNode;
102  if (dstNetDevice == 0)
103  {
104  dstNode = 0xffffffff;
105  }
106  else
107  {
108  dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId ();
109  }
111  delay, &YansWifiChannel::Receive, this,
112  j, copy, rxPowerDbm, wifiMode, preamble);
113  }
114  }
115 }
116 
117 void
118 YansWifiChannel::Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm,
119  WifiMode txMode, WifiPreamble preamble) const
120 {
121  m_phyList[i]->StartReceivePacket (packet, rxPowerDbm, txMode, preamble);
122 }
123 
124 uint32_t
126 {
127  return m_phyList.size ();
128 }
130 YansWifiChannel::GetDevice (uint32_t i) const
131 {
132  return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
133 }
134 
135 void
136 YansWifiChannel::Add (Ptr<YansWifiPhy> phy)
137 {
138  m_phyList.push_back (phy);
139 }
140 
141 int64_t
143 {
144  int64_t currentStream = stream;
145  currentStream += m_loss->AssignStreams (stream);
146  return (currentStream - stream);
147 }
148 
149 } // namespace ns3
keep track of time unit.
Definition: nstime.h:149
double GetDistanceFrom(Ptr< const MobilityModel > position) const
int64_t AssignStreams(int64_t stream)
void SetPropagationLossModel(Ptr< PropagationLossModel > loss)
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint16_t GetChannelNumber() const
Return current channel number, see SetChannelNumber()
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
WifiPreamble
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
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)
Definition: simulator.h:900
Ptr< Packet > Copy(void) const
Definition: packet.cc:131
Network layer to device interface.
Definition: net-device.h:75
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Ptr< T > GetObject(void) const
Definition: object.h:332
void Send(Ptr< YansWifiPhy > sender, Ptr< const Packet > packet, double txPowerDbm, WifiMode wifiMode, WifiPreamble preamble) const
int64_t AssignStreams(int64_t stream)