author | Peter D. Barnes, Jr. <barnes26@llnl.gov> |
Fri, 26 Sep 2014 15:51:00 -0700 | |
changeset 10968 | 2d29fee2b7b8 |
parent 7836 | 9cf68ee51869 |
permissions | -rw-r--r-- |
6349 | 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" |
|
7836
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
27 |
#include "ns3/antenna-model.h" |
6349 | 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 |
namespace ns3 { |
|
38 |
||
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
7836
diff
changeset
|
39 |
NS_LOG_COMPONENT_DEFINE ("AdhocAlohaNoackIdealPhyHelper"); |
6349 | 40 |
|
41 |
AdhocAlohaNoackIdealPhyHelper::AdhocAlohaNoackIdealPhyHelper () |
|
42 |
{ |
|
43 |
m_phy.SetTypeId ("ns3::HalfDuplexIdealPhy"); |
|
44 |
m_device.SetTypeId ("ns3::AlohaNoackNetDevice"); |
|
45 |
m_queue.SetTypeId ("ns3::DropTailQueue"); |
|
7836
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
46 |
m_antenna.SetTypeId ("ns3::IsotropicAntennaModel"); |
6349 | 47 |
} |
48 |
||
49 |
AdhocAlohaNoackIdealPhyHelper::~AdhocAlohaNoackIdealPhyHelper () |
|
50 |
{ |
|
51 |
} |
|
52 |
||
53 |
void |
|
54 |
AdhocAlohaNoackIdealPhyHelper::SetChannel (Ptr<SpectrumChannel> channel) |
|
55 |
{ |
|
56 |
m_channel = channel; |
|
57 |
} |
|
58 |
||
59 |
void |
|
60 |
AdhocAlohaNoackIdealPhyHelper::SetChannel (std::string channelName) |
|
61 |
{ |
|
62 |
Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName); |
|
63 |
m_channel = channel; |
|
64 |
} |
|
65 |
||
66 |
void |
|
67 |
AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity (Ptr<SpectrumValue> txPsd) |
|
68 |
{ |
|
69 |
NS_LOG_FUNCTION (this << txPsd); |
|
70 |
m_txPsd = txPsd; |
|
71 |
} |
|
72 |
||
73 |
void |
|
74 |
AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity (Ptr<SpectrumValue> noisePsd) |
|
75 |
{ |
|
76 |
NS_LOG_FUNCTION (this << noisePsd); |
|
77 |
m_noisePsd = noisePsd; |
|
78 |
} |
|
79 |
||
80 |
void |
|
81 |
AdhocAlohaNoackIdealPhyHelper::SetPhyAttribute (std::string name, const AttributeValue &v) |
|
82 |
{ |
|
83 |
m_phy.Set (name, v); |
|
84 |
} |
|
85 |
||
86 |
||
87 |
void |
|
88 |
AdhocAlohaNoackIdealPhyHelper::SetDeviceAttribute (std::string name, const AttributeValue &v) |
|
89 |
{ |
|
90 |
m_device.Set (name, v); |
|
91 |
} |
|
92 |
||
7836
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
93 |
void |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
94 |
AdhocAlohaNoackIdealPhyHelper::SetAntenna (std::string type, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
95 |
std::string n0, const AttributeValue &v0, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
96 |
std::string n1, const AttributeValue &v1, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
97 |
std::string n2, const AttributeValue &v2, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
98 |
std::string n3, const AttributeValue &v3, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
99 |
std::string n4, const AttributeValue &v4, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
100 |
std::string n5, const AttributeValue &v5, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
101 |
std::string n6, const AttributeValue &v6, |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
102 |
std::string n7, const AttributeValue &v7) |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
103 |
{ |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
104 |
ObjectFactory factory; |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
105 |
factory.SetTypeId (type); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
106 |
factory.Set (n0, v0); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
107 |
factory.Set (n1, v1); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
108 |
factory.Set (n2, v2); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
109 |
factory.Set (n3, v3); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
110 |
factory.Set (n4, v4); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
111 |
factory.Set (n5, v5); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
112 |
factory.Set (n6, v6); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
113 |
factory.Set (n7, v7); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
114 |
m_antenna = factory; |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
115 |
} |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
116 |
|
6349 | 117 |
NetDeviceContainer |
118 |
AdhocAlohaNoackIdealPhyHelper::Install (NodeContainer c) const |
|
119 |
{ |
|
120 |
NetDeviceContainer devices; |
|
121 |
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
|
122 |
{ |
|
123 |
Ptr<Node> node = *i; |
|
124 |
||
125 |
Ptr<AlohaNoackNetDevice> dev = (m_device.Create ())->GetObject<AlohaNoackNetDevice> (); |
|
126 |
dev->SetAddress (Mac48Address::Allocate ()); |
|
127 |
Ptr<Queue> q = (m_queue.Create ())->GetObject<Queue> (); |
|
128 |
dev->SetQueue (q); |
|
129 |
||
130 |
// note that we could have used a SpectrumPhyHelper here, but |
|
131 |
// given that it is straightforward to handle the configuration |
|
132 |
// in this helper here, we avoid asking the user to pass us a |
|
133 |
// SpectrumPhyHelper, so to spare him some typing. |
|
134 |
||
135 |
Ptr<HalfDuplexIdealPhy> phy = (m_phy.Create ())->GetObject<HalfDuplexIdealPhy> (); |
|
136 |
NS_ASSERT (phy); |
|
137 |
||
138 |
dev->SetPhy (phy); |
|
139 |
||
140 |
NS_ASSERT (node); |
|
7553
2b93d333dea6
Bug 1271 - stronger type checking in SpectrumPhy
Nicola Baldo <nbaldo@cttc.es>
parents:
6969
diff
changeset
|
141 |
phy->SetMobility (node->GetObject<MobilityModel> ()); |
6349 | 142 |
|
143 |
NS_ASSERT (dev); |
|
144 |
phy->SetDevice (dev); |
|
145 |
||
146 |
NS_ASSERT_MSG (m_txPsd, "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity ()"); |
|
147 |
phy->SetTxPowerSpectralDensity (m_txPsd); |
|
148 |
||
149 |
NS_ASSERT_MSG (m_noisePsd, "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity ()"); |
|
150 |
phy->SetNoisePowerSpectralDensity (m_noisePsd); |
|
151 |
||
152 |
NS_ASSERT_MSG (m_channel, "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetChannel ()"); |
|
153 |
phy->SetChannel (m_channel); |
|
6355
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
154 |
dev->SetChannel (m_channel); |
6349 | 155 |
m_channel->AddRx (phy); |
156 |
||
6969 | 157 |
phy->SetGenericPhyTxEndCallback (MakeCallback (&AlohaNoackNetDevice::NotifyTransmissionEnd, dev)); |
158 |
phy->SetGenericPhyRxStartCallback (MakeCallback (&AlohaNoackNetDevice::NotifyReceptionStart, dev)); |
|
159 |
phy->SetGenericPhyRxEndOkCallback (MakeCallback (&AlohaNoackNetDevice::NotifyReceptionEndOk, dev)); |
|
160 |
dev->SetGenericPhyTxStartCallback (MakeCallback (&HalfDuplexIdealPhy::StartTx, phy)); |
|
6349 | 161 |
|
7836
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
162 |
Ptr<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> (); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
163 |
NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object"); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
164 |
phy->SetAntenna (antenna); |
9cf68ee51869
integrated AntennaModel with spectrum
Nicola Baldo <nbaldo@cttc.es>
parents:
7553
diff
changeset
|
165 |
|
6349 | 166 |
node->AddDevice (dev); |
167 |
devices.Add (dev); |
|
168 |
} |
|
169 |
return devices; |
|
170 |
} |
|
171 |
||
172 |
NetDeviceContainer |
|
173 |
AdhocAlohaNoackIdealPhyHelper::Install (Ptr<Node> node) const |
|
174 |
{ |
|
175 |
return Install (NodeContainer (node)); |
|
176 |
} |
|
177 |
||
178 |
NetDeviceContainer |
|
179 |
AdhocAlohaNoackIdealPhyHelper::Install (std::string nodeName) const |
|
180 |
{ |
|
181 |
Ptr<Node> node = Names::Find<Node> (nodeName); |
|
182 |
return Install (node); |
|
183 |
} |
|
184 |
||
185 |
||
186 |
} // namespace ns3 |