A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("WaveformGeneratorHelper");
37 
38 namespace ns3 {
39 
40 
42 {
43  m_phy.SetTypeId ("ns3::WaveformGenerator");
44  m_device.SetTypeId ("ns3::NonCommunicatingNetDevice");
45  m_antenna.SetTypeId ("ns3::IsotropicAntennaModel");
46 }
47 
49 {
50 }
51 
52 void
54 {
55  m_channel = channel;
56 }
57 
58 void
59 WaveformGeneratorHelper::SetChannel (std::string channelName)
60 {
61  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
62  m_channel = channel;
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this << txPsd);
69  m_txPsd = txPsd;
70 }
71 
72 
73 void
75 {
76  m_phy.Set (name, v);
77 }
78 
79 
80 void
82 {
83  m_device.Set (name, v);
84 }
85 
86 void
88  std::string n0, const AttributeValue &v0,
89  std::string n1, const AttributeValue &v1,
90  std::string n2, const AttributeValue &v2,
91  std::string n3, const AttributeValue &v3,
92  std::string n4, const AttributeValue &v4,
93  std::string n5, const AttributeValue &v5,
94  std::string n6, const AttributeValue &v6,
95  std::string n7, const AttributeValue &v7)
96 {
97  ObjectFactory factory;
98  factory.SetTypeId (type);
99  factory.Set (n0, v0);
100  factory.Set (n1, v1);
101  factory.Set (n2, v2);
102  factory.Set (n3, v3);
103  factory.Set (n4, v4);
104  factory.Set (n5, v5);
105  factory.Set (n6, v6);
106  factory.Set (n7, v7);
107  m_antenna = factory;
108 }
109 
112 {
114  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
115  {
116  Ptr<Node> node = *i;
117 
119 
121  NS_ASSERT (phy);
122 
123  dev->SetPhy (phy);
124 
125  NS_ASSERT (node);
126  phy->SetMobility (node->GetObject<MobilityModel> ());
127 
128  NS_ASSERT (dev);
129  phy->SetDevice (dev);
130 
131  NS_ASSERT_MSG (m_txPsd, "you forgot to call WaveformGeneratorHelper::SetTxPowerSpectralDensity ()");
132  phy->SetTxPowerSpectralDensity (m_txPsd);
133 
134  NS_ASSERT_MSG (m_channel, "you forgot to call WaveformGeneratorHelper::SetChannel ()");
135  phy->SetChannel (m_channel);
136  dev->SetChannel (m_channel);
137 
138  Ptr<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
139  NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
140  phy->SetAntenna (antenna);
141 
142  node->AddDevice (dev);
143  devices.Add (dev);
144  }
145  return devices;
146 }
147 
150 {
151  return Install (NodeContainer (node));
152 }
153 
155 WaveformGeneratorHelper::Install (std::string nodeName) const
156 {
157  Ptr<Node> node = Names::Find<Node> (nodeName);
158  return Install (node);
159 }
160 
161 
162 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
tuple devices
Definition: first.py:32
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Hold a value for an Attribute.
Definition: attribute.h:56
NetDeviceContainer Install(NodeContainer c) const
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:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void SetTypeId(TypeId tid)
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)
Simple SpectrumPhy implementation that sends customizable waveform.
Keep track of the current position and velocity of an object.
Ptr< Object > Create(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void Set(std::string name, const AttributeValue &value)
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())
#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:84
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
instantiate subclasses of ns3::Object.
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:120
Ptr< T > GetObject(void) const
Definition: object.h:362
void SetChannel(Ptr< SpectrumChannel > channel)
set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper ...