A Discrete-Event Network Simulator
API
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"
33 
34 
35 
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("AdhocAlohaNoackIdealPhyHelper");
40 
42 {
43  m_phy.SetTypeId ("ns3::HalfDuplexIdealPhy");
44  m_device.SetTypeId ("ns3::AlohaNoackNetDevice");
45  m_queue.SetTypeId ("ns3::DropTailQueue<Packet>");
46  m_antenna.SetTypeId ("ns3::IsotropicAntennaModel");
47 }
48 
50 {
51 }
52 
53 void
55 {
57 }
58 
59 void
61 {
62  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION (this << txPsd);
70  m_txPsd = txPsd;
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this << noisePsd);
77  m_noisePsd = noisePsd;
78 }
79 
80 void
82 {
83  m_phy.Set (name, v);
84 }
85 
86 
87 void
89 {
90  m_device.Set (name, v);
91 }
92 
93 void
95  std::string n0, const AttributeValue &v0,
96  std::string n1, const AttributeValue &v1,
97  std::string n2, const AttributeValue &v2,
98  std::string n3, const AttributeValue &v3,
99  std::string n4, const AttributeValue &v4,
100  std::string n5, const AttributeValue &v5,
101  std::string n6, const AttributeValue &v6,
102  std::string n7, const AttributeValue &v7)
103 {
104  ObjectFactory factory;
105  factory.SetTypeId (type);
106  factory.Set (n0, v0);
107  factory.Set (n1, v1);
108  factory.Set (n2, v2);
109  factory.Set (n3, v3);
110  factory.Set (n4, v4);
111  factory.Set (n5, v5);
112  factory.Set (n6, v6);
113  factory.Set (n7, v7);
114  m_antenna = factory;
115 }
116 
119 {
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<Packet> > q = (m_queue.Create ())->GetObject<Queue<Packet> > ();
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);
141  phy->SetMobility (node->GetObject<MobilityModel> ());
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);
154  dev->SetChannel (m_channel);
155  m_channel->AddRx (phy);
156 
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));
161 
162  Ptr<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
163  NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
164  phy->SetAntenna (antenna);
165 
166  node->AddDevice (dev);
167  devices.Add (dev);
168  }
169  return devices;
170 }
171 
174 {
175  return Install (NodeContainer (node));
176 }
177 
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
Ptr< SpectrumValue > m_noisePsd
Noise power spectral density.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
void NotifyReceptionStart()
Notify the MAC that the PHY has started a reception.
bool StartTx(Ptr< Packet > p)
Start a transmission.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold a value for an Attribute.
Definition: attribute.h:68
void SetPhyAttribute(std::string name, const AttributeValue &v)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
ObjectFactory m_queue
Object factory for the Queue objects.
channel
Definition: third.py:85
phy
Definition: third.py:86
void NotifyReceptionEndOk(Ptr< Packet > p)
Notify the MAC that the PHY finished a reception successfully.
Keep track of the current position and velocity of an object.
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Ptr< SpectrumValue > m_txPsd
Tx power spectral density.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void NotifyTransmissionEnd(Ptr< const Packet >)
Notify the MAC that the PHY has finished a previously started transmission.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
Instantiate subclasses of ns3::Object.
ObjectFactory m_phy
Object factory for the phy objects.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
ObjectFactory m_antenna
Object factory for the Antenna objects.
void SetAntenna(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper ...
devices
Definition: first.py:32
ObjectFactory m_device
Object factory for the NetDevice objects.
NetDeviceContainer Install(NodeContainer c) const
void SetNoisePowerSpectralDensity(Ptr< SpectrumValue > noisePsd)
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.