A Discrete-Event Network Simulator
API
on-off-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #include "on-off-helper.h"
20 
21 #include "ns3/data-rate.h"
22 #include "ns3/inet-socket-address.h"
23 #include "ns3/names.h"
24 #include "ns3/onoff-application.h"
25 #include "ns3/packet-socket-address.h"
26 #include "ns3/random-variable-stream.h"
27 #include "ns3/string.h"
28 #include "ns3/uinteger.h"
29 
30 namespace ns3
31 {
32 
34 {
35  m_factory.SetTypeId("ns3::OnOffApplication");
36  m_factory.Set("Protocol", StringValue(protocol));
37  m_factory.Set("Remote", AddressValue(address));
38 }
39 
40 void
41 OnOffHelper::SetAttribute(std::string name, const AttributeValue& value)
42 {
43  m_factory.Set(name, value);
44 }
45 
48 {
49  return ApplicationContainer(InstallPriv(node));
50 }
51 
53 OnOffHelper::Install(std::string nodeName) const
54 {
55  Ptr<Node> node = Names::Find<Node>(nodeName);
56  return ApplicationContainer(InstallPriv(node));
57 }
58 
61 {
63  for (auto i = c.Begin(); i != c.End(); ++i)
64  {
65  apps.Add(InstallPriv(*i));
66  }
67 
68  return apps;
69 }
70 
73 {
75  node->AddApplication(app);
76 
77  return app;
78 }
79 
80 int64_t
82 {
83  int64_t currentStream = stream;
84  Ptr<Node> node;
85  for (auto i = c.Begin(); i != c.End(); ++i)
86  {
87  node = (*i);
88  for (uint32_t j = 0; j < node->GetNApplications(); j++)
89  {
90  Ptr<OnOffApplication> onoff = DynamicCast<OnOffApplication>(node->GetApplication(j));
91  if (onoff)
92  {
93  currentStream += onoff->AssignStreams(currentStream);
94  }
95  }
96  }
97  return (currentStream - stream);
98 }
99 
100 void
102 {
103  m_factory.Set("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1000]"));
104  m_factory.Set("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
105  m_factory.Set("DataRate", DataRateValue(dataRate));
106  m_factory.Set("PacketSize", UintegerValue(packetSize));
107 }
108 
109 } // namespace ns3
a polymophic address class
Definition: address.h:101
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
The base class for all ns3 applications.
Definition: application.h:62
Hold a value for an Attribute.
Definition: attribute.h:70
Class for representing data rates.
Definition: data-rate.h:89
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.
uint32_t GetNApplications() const
Definition: node.cc:190
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:180
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:169
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.
OnOffHelper(std::string protocol, Address address)
Create an OnOffHelper to make it easier to work with OnOffApplications.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
ObjectFactory m_factory
Object factory.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install an ns3::OnOffApplication on the node configured with all the attributes set with SetAttribute...
Hold variables of type string.
Definition: string.h:56
Hold an unsigned integer type.
Definition: uinteger.h:45
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.