A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
adhoc-aloha-noack-ideal-phy-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
20
21#include "ns3/aloha-noack-net-device.h"
22#include "ns3/antenna-model.h"
23#include "ns3/config.h"
24#include "ns3/half-duplex-ideal-phy.h"
25#include "ns3/log.h"
26#include "ns3/mac48-address.h"
27#include "ns3/mobility-model.h"
28#include "ns3/names.h"
29#include "ns3/propagation-delay-model.h"
30#include "ns3/simulator.h"
31#include "ns3/spectrum-channel.h"
32#include "ns3/spectrum-propagation-loss-model.h"
33
34namespace ns3
35{
36
37NS_LOG_COMPONENT_DEFINE("AdhocAlohaNoackIdealPhyHelper");
38
40{
41 m_phy.SetTypeId("ns3::HalfDuplexIdealPhy");
42 m_device.SetTypeId("ns3::AlohaNoackNetDevice");
43 m_queue.SetTypeId("ns3::DropTailQueue<Packet>");
44 m_antenna.SetTypeId("ns3::IsotropicAntennaModel");
45}
46
48{
49}
50
51void
53{
54 m_channel = channel;
55}
56
57void
59{
60 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel>(channelName);
61 m_channel = channel;
62}
63
64void
66{
67 NS_LOG_FUNCTION(this << txPsd);
68 m_txPsd = txPsd;
69}
70
71void
73{
74 NS_LOG_FUNCTION(this << noisePsd);
75 m_noisePsd = noisePsd;
76}
77
78void
80{
81 m_phy.Set(name, v);
82}
83
84void
86{
87 m_device.Set(name, v);
88}
89
92{
93 NetDeviceContainer devices;
94 for (auto i = c.Begin(); i != c.End(); ++i)
95 {
96 Ptr<Node> node = *i;
97
98 Ptr<AlohaNoackNetDevice> dev = (m_device.Create())->GetObject<AlohaNoackNetDevice>();
99 dev->SetAddress(Mac48Address::Allocate());
100 Ptr<Queue<Packet>> q = (m_queue.Create())->GetObject<Queue<Packet>>();
101 dev->SetQueue(q);
102
103 // note that we could have used a SpectrumPhyHelper here, but
104 // given that it is straightforward to handle the configuration
105 // in this helper here, we avoid asking the user to pass us a
106 // SpectrumPhyHelper, so to spare him some typing.
107
108 Ptr<HalfDuplexIdealPhy> phy = (m_phy.Create())->GetObject<HalfDuplexIdealPhy>();
109 NS_ASSERT(phy);
110
111 dev->SetPhy(phy);
112
113 NS_ASSERT(node);
114 phy->SetMobility(node->GetObject<MobilityModel>());
115
116 NS_ASSERT(dev);
117 phy->SetDevice(dev);
118
120 m_txPsd,
121 "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity ()");
122 phy->SetTxPowerSpectralDensity(m_txPsd);
123
126 "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity ()");
127 phy->SetNoisePowerSpectralDensity(m_noisePsd);
128
129 NS_ASSERT_MSG(m_channel, "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetChannel ()");
130 phy->SetChannel(m_channel);
131 dev->SetChannel(m_channel);
132 m_channel->AddRx(phy);
133
134 phy->SetGenericPhyTxEndCallback(
136 phy->SetGenericPhyRxStartCallback(
138 phy->SetGenericPhyRxEndOkCallback(
140 dev->SetGenericPhyTxStartCallback(MakeCallback(&HalfDuplexIdealPhy::StartTx, phy));
141
142 Ptr<AntennaModel> antenna = (m_antenna.Create())->GetObject<AntennaModel>();
143 NS_ASSERT_MSG(antenna, "error in creating the AntennaModel object");
144 phy->SetAntenna(antenna);
145
146 node->AddDevice(dev);
147 devices.Add(dev);
148 }
149 return devices;
150}
151
154{
155 return Install(NodeContainer(node));
156}
157
159AdhocAlohaNoackIdealPhyHelper::Install(std::string nodeName) const
160{
161 Ptr<Node> node = Names::Find<Node>(nodeName);
162 return Install(node);
163}
164
165} // namespace ns3
void SetPhyAttribute(std::string name, const AttributeValue &v)
ObjectFactory m_queue
Object factory for the Queue objects.
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Ptr< SpectrumValue > m_noisePsd
Noise power spectral density.
Ptr< SpectrumValue > m_txPsd
Tx power spectral density.
void SetNoisePowerSpectralDensity(Ptr< SpectrumValue > noisePsd)
ObjectFactory m_phy
Object factory for the phy objects.
ObjectFactory m_antenna
Object factory for the Antenna objects.
ObjectFactory m_device
Object factory for the NetDevice objects.
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper
NetDeviceContainer Install(NodeContainer c) const
void NotifyReceptionStart()
Notify the MAC that the PHY has started a reception.
void NotifyTransmissionEnd(Ptr< const Packet >)
Notify the MAC that the PHY has finished a previously started transmission.
void NotifyReceptionEndOk(Ptr< Packet > p)
Notify the MAC that the PHY finished a reception successfully.
Hold a value for an Attribute.
Definition: attribute.h:70
bool StartTx(Ptr< Packet > p)
Start a transmission.
static Mac48Address Allocate()
Allocate a new Mac48Address.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Template class for packet Queues.
Definition: queue.h:268
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:706