A Discrete-Event Network Simulator
API
on-off-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "on-off-helper.h"
21 #include "ns3/inet-socket-address.h"
22 #include "ns3/packet-socket-address.h"
23 #include "ns3/string.h"
24 #include "ns3/data-rate.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/names.h"
27 #include "ns3/random-variable-stream.h"
28 #include "ns3/onoff-application.h"
29 
30 namespace ns3 {
31 
32 OnOffHelper::OnOffHelper (std::string protocol, Address address)
33 {
34  m_factory.SetTypeId ("ns3::OnOffApplication");
35  m_factory.Set ("Protocol", StringValue (protocol));
36  m_factory.Set ("Remote", AddressValue (address));
37 }
38 
39 void
40 OnOffHelper::SetAttribute (std::string name, const AttributeValue &value)
41 {
42  m_factory.Set (name, value);
43 }
44 
47 {
48  return ApplicationContainer (InstallPriv (node));
49 }
50 
52 OnOffHelper::Install (std::string nodeName) const
53 {
54  Ptr<Node> node = Names::Find<Node> (nodeName);
55  return ApplicationContainer (InstallPriv (node));
56 }
57 
60 {
62  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
63  {
64  apps.Add (InstallPriv (*i));
65  }
66 
67  return apps;
68 }
69 
72 {
74  node->AddApplication (app);
75 
76  return app;
77 }
78 
79 int64_t
81 {
82  int64_t currentStream = stream;
83  Ptr<Node> node;
84  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
85  {
86  node = (*i);
87  for (uint32_t j = 0; j < node->GetNApplications (); j++)
88  {
89  Ptr<OnOffApplication> onoff = DynamicCast<OnOffApplication> (node->GetApplication (j));
90  if (onoff)
91  {
92  currentStream += onoff->AssignStreams (currentStream);
93  }
94  }
95  }
96  return (currentStream - stream);
97 }
98 
99 void
101 {
102  m_factory.Set ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1000]"));
103  m_factory.Set ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
104  m_factory.Set ("DataRate", DataRateValue (dataRate));
105  m_factory.Set ("PacketSize", UintegerValue (packetSize));
106 }
107 
108 } // namespace ns3
a polymophic address class
Definition: address.h:91
AttributeValue implementation for Address.
Definition: address.h:278
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:61
Hold a value for an Attribute.
Definition: attribute.h:69
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
uint32_t GetNApplications(void) const
Definition: node.cc:178
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:170
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
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:41
Hold an unsigned integer type.
Definition: uinteger.h:44
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize