A Discrete-Event Network Simulator
API
udp-echo-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 "udp-echo-helper.h"
20 
21 #include "ns3/names.h"
22 #include "ns3/udp-echo-client.h"
23 #include "ns3/udp-echo-server.h"
24 #include "ns3/uinteger.h"
25 
26 namespace ns3
27 {
28 
30 {
33 }
34 
35 void
36 UdpEchoServerHelper::SetAttribute(std::string name, const AttributeValue& value)
37 {
38  m_factory.Set(name, value);
39 }
40 
43 {
44  return ApplicationContainer(InstallPriv(node));
45 }
46 
48 UdpEchoServerHelper::Install(std::string nodeName) const
49 {
50  Ptr<Node> node = Names::Find<Node>(nodeName);
51  return ApplicationContainer(InstallPriv(node));
52 }
53 
56 {
58  for (auto i = c.Begin(); i != c.End(); ++i)
59  {
60  apps.Add(InstallPriv(*i));
61  }
62 
63  return apps;
64 }
65 
68 {
70  node->AddApplication(app);
71 
72  return app;
73 }
74 
76 {
78  SetAttribute("RemoteAddress", AddressValue(address));
79  SetAttribute("RemotePort", UintegerValue(port));
80 }
81 
83 {
85  SetAttribute("RemoteAddress", AddressValue(address));
86 }
87 
88 void
89 UdpEchoClientHelper::SetAttribute(std::string name, const AttributeValue& value)
90 {
91  m_factory.Set(name, value);
92 }
93 
94 void
96 {
97  app->GetObject<UdpEchoClient>()->SetFill(fill);
98 }
99 
100 void
101 UdpEchoClientHelper::SetFill(Ptr<Application> app, uint8_t fill, uint32_t dataLength)
102 {
103  app->GetObject<UdpEchoClient>()->SetFill(fill, dataLength);
104 }
105 
106 void
108  uint8_t* fill,
109  uint32_t fillLength,
110  uint32_t dataLength)
111 {
112  app->GetObject<UdpEchoClient>()->SetFill(fill, fillLength, dataLength);
113 }
114 
117 {
118  return ApplicationContainer(InstallPriv(node));
119 }
120 
122 UdpEchoClientHelper::Install(std::string nodeName) const
123 {
124  Ptr<Node> node = Names::Find<Node>(nodeName);
125  return ApplicationContainer(InstallPriv(node));
126 }
127 
130 {
132  for (auto i = c.Begin(); i != c.End(); ++i)
133  {
134  apps.Add(InstallPriv(*i));
135  }
136 
137  return apps;
138 }
139 
142 {
144  node->AddApplication(app);
145 
146  return app;
147 }
148 
149 } // 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.
Hold a value for an Attribute.
Definition: attribute.h:70
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 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.
UdpEchoClientHelper(Address ip, uint16_t port)
Create UdpEchoClientHelper which will make life easier for people trying to set up simulations with e...
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
ObjectFactory m_factory
Object factory.
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install an ns3::UdpEchoClient on the node configured with all the attributes set with SetAttribute.
void SetFill(Ptr< Application > app, std::string fill)
Given a pointer to a UdpEchoClient application, set the data fill of the packet (what is sent as data...
A Udp Echo client.
static TypeId GetTypeId()
Get the type ID.
UdpEchoServerHelper(uint16_t port)
Create UdpEchoServerHelper which will make life easier for people trying to set up simulations with e...
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install an ns3::UdpEchoServer on the node configured with all the attributes set with SetAttribute.
ObjectFactory m_factory
Object factory.
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
A Udp Echo server.
static TypeId GetTypeId()
Get the type ID.
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t port
Definition: dsdv-manet.cc:44
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.