A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
on-off-helper.cc
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 {
73  Ptr<Application> app = m_factory.Create<Application> ();
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
100 OnOffHelper::SetConstantRate (DataRate dataRate, uint32_t packetSize)
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
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:148
uint32_t GetNApplications(void) const
Definition: node.cc:167
hold variables of type string
Definition: string.h:19
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
Hold a value for an Attribute.
Definition: attribute.h:51
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
int64_t AssignStreams(NodeContainer c, int64_t stream)
a polymophic address class
Definition: address.h:86
Class for representing data rates.
Definition: data-rate.h:71
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:159
The base class for all ns3 applications.
Definition: application.h:61
Ptr< Object > Create(void) const
Hold an unsigned integer type.
Definition: uinteger.h:46
OnOffHelper(std::string protocol, Address address)
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
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)
hold objects of type ns3::Address
hold objects of type ns3::DataRate
Ptr< Application > InstallPriv(Ptr< Node > node) const
ApplicationContainer Install(NodeContainer c) const
void SetAttribute(std::string name, const AttributeValue &value)