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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
9
10#include "ns3/aloha-noack-net-device.h"
11#include "ns3/antenna-model.h"
12#include "ns3/config.h"
13#include "ns3/half-duplex-ideal-phy.h"
14#include "ns3/log.h"
15#include "ns3/mac48-address.h"
16#include "ns3/mobility-model.h"
17#include "ns3/names.h"
18#include "ns3/propagation-delay-model.h"
19#include "ns3/simulator.h"
20#include "ns3/spectrum-channel.h"
21#include "ns3/spectrum-propagation-loss-model.h"
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("AdhocAlohaNoackIdealPhyHelper");
27
29{
30 m_phy.SetTypeId("ns3::HalfDuplexIdealPhy");
31 m_device.SetTypeId("ns3::AlohaNoackNetDevice");
32 m_queue.SetTypeId("ns3::DropTailQueue<Packet>");
33 m_antenna.SetTypeId("ns3::IsotropicAntennaModel");
34}
35
39
40void
45
46void
48{
50 m_channel = channel;
51}
52
53void
59
60void
66
67void
69{
70 m_phy.Set(name, v);
71}
72
73void
75{
76 m_device.Set(name, v);
77}
78
81{
82 NetDeviceContainer devices;
83 for (auto i = c.Begin(); i != c.End(); ++i)
84 {
85 Ptr<Node> node = *i;
86
87 Ptr<AlohaNoackNetDevice> dev = (m_device.Create())->GetObject<AlohaNoackNetDevice>();
88 dev->SetAddress(Mac48Address::Allocate());
89 Ptr<Queue<Packet>> q = (m_queue.Create())->GetObject<Queue<Packet>>();
90 dev->SetQueue(q);
91
92 // note that we could have used a SpectrumPhyHelper here, but
93 // given that it is straightforward to handle the configuration
94 // in this helper here, we avoid asking the user to pass us a
95 // SpectrumPhyHelper, so to spare him some typing.
96
97 Ptr<HalfDuplexIdealPhy> phy = (m_phy.Create())->GetObject<HalfDuplexIdealPhy>();
98 NS_ASSERT(phy);
99
100 dev->SetPhy(phy);
101
102 NS_ASSERT(node);
103 phy->SetMobility(node->GetObject<MobilityModel>());
104
105 NS_ASSERT(dev);
106 phy->SetDevice(dev);
107
109 m_txPsd,
110 "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetTxPowerSpectralDensity ()");
111 phy->SetTxPowerSpectralDensity(m_txPsd);
112
115 "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetNoisePowerSpectralDensity ()");
116 phy->SetNoisePowerSpectralDensity(m_noisePsd);
117
118 NS_ASSERT_MSG(m_channel, "you forgot to call AdhocAlohaNoackIdealPhyHelper::SetChannel ()");
119 phy->SetChannel(m_channel);
120 dev->SetChannel(m_channel);
121 m_channel->AddRx(phy);
122
123 phy->SetGenericPhyTxEndCallback(
125 phy->SetGenericPhyRxStartCallback(
127 phy->SetGenericPhyRxEndOkCallback(
129 dev->SetGenericPhyTxStartCallback(MakeCallback(&HalfDuplexIdealPhy::StartTx, phy));
130
131 Ptr<AntennaModel> antenna = (m_antenna.Create())->GetObject<AntennaModel>();
132 NS_ASSERT_MSG(antenna, "error in creating the AntennaModel object");
133 phy->SetAntenna(antenna);
134
135 node->AddDevice(dev);
136 devices.Add(dev);
137 }
138 return devices;
139}
140
146
148AdhocAlohaNoackIdealPhyHelper::Install(std::string nodeName) const
149{
150 Ptr<Node> node = Names::Find<Node>(nodeName);
151 return Install(node);
152}
153
154} // 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:59
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.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
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.
Template class for packet Queues.
Definition queue.h:257
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:684