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
adhoc-aloha-noack-ideal-phy-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
#include "ns3/propagation-delay-model.h"
21
#include "ns3/spectrum-propagation-loss-model.h"
22
#include "ns3/mobility-model.h"
23
#include "ns3/log.h"
24
#include "ns3/config.h"
25
#include "ns3/simulator.h"
26
#include "ns3/names.h"
27
#include "ns3/antenna-model.h"
28
#include "ns3/spectrum-channel.h"
29
#include "ns3/half-duplex-ideal-phy.h"
30
#include "ns3/mac48-address.h"
31
#include "ns3/aloha-noack-net-device.h"
32
#include "
adhoc-aloha-noack-ideal-phy-helper.h
"
33
34
35
36
37
NS_LOG_COMPONENT_DEFINE
(
"AdhocAlohaNoackIdealPhyHelper"
);
38
39
namespace
ns3 {
40
41
42
AdhocAlohaNoackIdealPhyHelper::AdhocAlohaNoackIdealPhyHelper
()
43
{
44
m_phy
.
SetTypeId
(
"ns3::HalfDuplexIdealPhy"
);
45
m_device
.
SetTypeId
(
"ns3::AlohaNoackNetDevice"
);
46
m_queue
.
SetTypeId
(
"ns3::DropTailQueue"
);
47
m_antenna
.
SetTypeId
(
"ns3::IsotropicAntennaModel"
);
48
}
49
50
AdhocAlohaNoackIdealPhyHelper::~AdhocAlohaNoackIdealPhyHelper
()
51
{
52
}
53
54
void
55
AdhocAlohaNoackIdealPhyHelper::SetChannel
(
Ptr<SpectrumChannel>
channel)
56
{
57
m_channel
= channel;
58
}
59
60
void
61
AdhocAlohaNoackIdealPhyHelper::SetChannel
(std::string channelName)
62
{
63
Ptr<SpectrumChannel>
channel = Names::Find<SpectrumChannel> (channelName);
64
m_channel
= channel;
65
}
66
67
void
68
AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity
(
Ptr<SpectrumValue>
txPsd)
69
{
70
NS_LOG_FUNCTION
(
this
<< txPsd);
71
m_txPsd
= txPsd;
72
}
73
74
void
75
AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity
(
Ptr<SpectrumValue>
noisePsd)
76
{
77
NS_LOG_FUNCTION
(
this
<< noisePsd);
78
m_noisePsd
= noisePsd;
79
}
80
81
void
82
AdhocAlohaNoackIdealPhyHelper::SetPhyAttribute
(std::string name,
const
AttributeValue
&v)
83
{
84
m_phy
.
Set
(name, v);
85
}
86
87
88
void
89
AdhocAlohaNoackIdealPhyHelper::SetDeviceAttribute
(std::string name,
const
AttributeValue
&v)
90
{
91
m_device
.
Set
(name, v);
92
}
93
94
void
95
AdhocAlohaNoackIdealPhyHelper::SetAntenna
(std::string type,
96
std::string n0,
const
AttributeValue
&v0,
97
std::string n1,
const
AttributeValue
&v1,
98
std::string n2,
const
AttributeValue
&v2,
99
std::string n3,
const
AttributeValue
&v3,
100
std::string n4,
const
AttributeValue
&v4,
101
std::string n5,
const
AttributeValue
&v5,
102
std::string n6,
const
AttributeValue
&v6,
103
std::string n7,
const
AttributeValue
&v7)
104
{
105
ObjectFactory
factory;
106
factory.
SetTypeId
(type);
107
factory.
Set
(n0, v0);
108
factory.
Set
(n1, v1);
109
factory.
Set
(n2, v2);
110
factory.
Set
(n3, v3);
111
factory.
Set
(n4, v4);
112
factory.
Set
(n5, v5);
113
factory.
Set
(n6, v6);
114
factory.
Set
(n7, v7);
115
m_antenna
= factory;
116
}
117
118
NetDeviceContainer
119
AdhocAlohaNoackIdealPhyHelper::Install
(
NodeContainer
c)
const
120
{
121
NetDeviceContainer
devices;
122
for
(
NodeContainer::Iterator
i = c.
Begin
(); i != c.
End
(); ++i)
123
{
124
Ptr<Node>
node = *i;
125
126
Ptr<AlohaNoackNetDevice>
dev = (
m_device
.
Create
())->GetObject<AlohaNoackNetDevice> ();
127
dev->SetAddress (
Mac48Address::Allocate
());
128
Ptr<Queue>
q = (
m_queue
.
Create
())->GetObject<Queue> ();
129
dev->SetQueue (q);
130
131
// note that we could have used a SpectrumPhyHelper here, but
132
// given that it is straightforward to handle the configuration
133
// in this helper here, we avoid asking the user to pass us a
134
// SpectrumPhyHelper, so to spare him some typing.
135
136
Ptr<HalfDuplexIdealPhy>
phy = (
m_phy
.
Create
())->GetObject<HalfDuplexIdealPhy> ();
137
NS_ASSERT
(phy);
138
139
dev->SetPhy (phy);
140
141
NS_ASSERT
(node);
142
phy->SetMobility (node->
GetObject
<
MobilityModel
> ());
143
144
NS_ASSERT
(dev);
145
phy->SetDevice (dev);
146
147
NS_ASSERT_MSG
(
m_txPsd
,
"you forgot to call AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity ()"
);
148
phy->SetTxPowerSpectralDensity (
m_txPsd
);
149
150
NS_ASSERT_MSG
(
m_noisePsd
,
"you forgot to call AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity ()"
);
151
phy->SetNoisePowerSpectralDensity (
m_noisePsd
);
152
153
NS_ASSERT_MSG
(
m_channel
,
"you forgot to call AdhocAlohaNoackIdealPhyHelper::SetChannel ()"
);
154
phy->SetChannel (
m_channel
);
155
dev->SetChannel (
m_channel
);
156
m_channel
->
AddRx
(phy);
157
158
phy->SetGenericPhyTxEndCallback (
MakeCallback
(&
AlohaNoackNetDevice::NotifyTransmissionEnd
, dev));
159
phy->SetGenericPhyRxStartCallback (
MakeCallback
(&
AlohaNoackNetDevice::NotifyReceptionStart
, dev));
160
phy->SetGenericPhyRxEndOkCallback (
MakeCallback
(&
AlohaNoackNetDevice::NotifyReceptionEndOk
, dev));
161
dev->SetGenericPhyTxStartCallback (
MakeCallback
(&
HalfDuplexIdealPhy::StartTx
, phy));
162
163
Ptr<AntennaModel>
antenna = (
m_antenna
.
Create
())->GetObject<AntennaModel> ();
164
NS_ASSERT_MSG
(antenna,
"error in creating the AntennaModel object"
);
165
phy->SetAntenna (antenna);
166
167
node->
AddDevice
(dev);
168
devices.
Add
(dev);
169
}
170
return
devices;
171
}
172
173
NetDeviceContainer
174
AdhocAlohaNoackIdealPhyHelper::Install
(
Ptr<Node>
node)
const
175
{
176
return
Install
(
NodeContainer
(node));
177
}
178
179
NetDeviceContainer
180
AdhocAlohaNoackIdealPhyHelper::Install
(std::string nodeName)
const
181
{
182
Ptr<Node>
node = Names::Find<Node> (nodeName);
183
return
Install
(node);
184
}
185
186
187
}
// namespace ns3
src
spectrum
helper
adhoc-aloha-noack-ideal-phy-helper.cc
Generated on Tue Oct 9 2012 16:45:46 for ns-3 by
1.8.1.2