A Discrete-Event Network Simulator
API
waveform-generator-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/waveform-generator.h"
30 #include "ns3/non-communicating-net-device.h"
32 
33 
34 
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("WaveformGeneratorHelper");
39 
41 {
42  m_phy.SetTypeId ("ns3::WaveformGenerator");
43  m_device.SetTypeId ("ns3::NonCommunicatingNetDevice");
44  m_antenna.SetTypeId ("ns3::IsotropicAntennaModel");
45 }
46 
48 {
49 }
50 
51 void
53 {
55 }
56 
57 void
58 WaveformGeneratorHelper::SetChannel (std::string channelName)
59 {
60  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION (this << txPsd);
68  m_txPsd = txPsd;
69 }
70 
71 
72 void
74 {
75  m_phy.Set (name, v);
76 }
77 
78 
79 void
81 {
82  m_device.Set (name, v);
83 }
84 
85 void
87  std::string n0, const AttributeValue &v0,
88  std::string n1, const AttributeValue &v1,
89  std::string n2, const AttributeValue &v2,
90  std::string n3, const AttributeValue &v3,
91  std::string n4, const AttributeValue &v4,
92  std::string n5, const AttributeValue &v5,
93  std::string n6, const AttributeValue &v6,
94  std::string n7, const AttributeValue &v7)
95 {
96  ObjectFactory factory;
97  factory.SetTypeId (type);
98  factory.Set (n0, v0);
99  factory.Set (n1, v1);
100  factory.Set (n2, v2);
101  factory.Set (n3, v3);
102  factory.Set (n4, v4);
103  factory.Set (n5, v5);
104  factory.Set (n6, v6);
105  factory.Set (n7, v7);
106  m_antenna = factory;
107 }
108 
111 {
113  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
114  {
115  Ptr<Node> node = *i;
116 
118 
120  NS_ASSERT (phy);
121 
122  dev->SetPhy (phy);
123 
124  NS_ASSERT (node);
125  phy->SetMobility (node->GetObject<MobilityModel> ());
126 
127  NS_ASSERT (dev);
128  phy->SetDevice (dev);
129 
130  NS_ASSERT_MSG (m_txPsd, "you forgot to call WaveformGeneratorHelper::SetTxPowerSpectralDensity ()");
131  phy->SetTxPowerSpectralDensity (m_txPsd);
132 
133  NS_ASSERT_MSG (m_channel, "you forgot to call WaveformGeneratorHelper::SetChannel ()");
134  phy->SetChannel (m_channel);
135  dev->SetChannel (m_channel);
136 
137  Ptr<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
138  NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
139  phy->SetAntenna (antenna);
140 
141  node->AddDevice (dev);
142  devices.Add (dev);
143  }
144  return devices;
145 }
146 
149 {
150  return Install (NodeContainer (node));
151 }
152 
154 WaveformGeneratorHelper::Install (std::string nodeName) const
155 {
156  Ptr<Node> node = Names::Find<Node> (nodeName);
157  return Install (node);
158 }
159 
160 
161 } // namespace ns3
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 "...
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
ObjectFactory m_device
Object factory for the NetDevice objects.
ObjectFactory m_phy
Object factory for the phy objects.
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:204
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.
This class implements a device which does not communicate, in the sense that it does not interact wit...
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
channel
Definition: third.py:92
phy
Definition: third.py:93
Simple SpectrumPhy implementation that sends customizable waveform.
Keep track of the current position and velocity of an object.
NetDeviceContainer Install(NodeContainer c) const
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
holds a vector of ns3::NetDevice pointers
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 Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
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 SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Instantiate subclasses of ns3::Object.
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.
Ptr< SpectrumValue > m_txPsd
Tx power spectral density.
devices
Definition: first.py:32
Ptr< SpectrumChannel > m_channel
Channel.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper ...