A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
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
{
62
NS_LOG_FUNCTION_NOARGS
();
63
m_phyList
.clear ();
64
}
65
66
void
67
YansWifiChannel::SetPropagationLossModel
(
Ptr<PropagationLossModel>
loss)
68
{
69
m_loss
= loss;
70
}
71
void
72
YansWifiChannel::SetPropagationDelayModel
(
Ptr<PropagationDelayModel>
delay)
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
}
110
Simulator::ScheduleWithContext
(dstNode,
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
125
YansWifiChannel::GetNDevices
(
void
)
const
126
{
127
return
m_phyList
.size ();
128
}
129
Ptr<NetDevice>
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
142
YansWifiChannel::AssignStreams
(int64_t stream)
143
{
144
int64_t currentStream = stream;
145
currentStream +=
m_loss
->
AssignStreams
(stream);
146
return
(currentStream - stream);
147
}
148
149
}
// namespace ns3
src
wifi
model
yans-wifi-channel.cc
Generated on Tue Nov 13 2012 10:32:25 for ns-3 by
1.8.1.2