A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
udp-echo-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 "udp-echo-helper.h"
21 #include "ns3/udp-echo-server.h"
22 #include "ns3/udp-echo-client.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/names.h"
25 
26 namespace ns3 {
27 
29 {
30  m_factory.SetTypeId (UdpEchoServer::GetTypeId ());
31  SetAttribute ("Port", UintegerValue (port));
32 }
33 
34 void
36  std::string name,
37  const AttributeValue &value)
38 {
39  m_factory.Set (name, value);
40 }
41 
44 {
45  return ApplicationContainer (InstallPriv (node));
46 }
47 
49 UdpEchoServerHelper::Install (std::string nodeName) const
50 {
51  Ptr<Node> node = Names::Find<Node> (nodeName);
52  return ApplicationContainer (InstallPriv (node));
53 }
54 
57 {
59  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
60  {
61  apps.Add (InstallPriv (*i));
62  }
63 
64  return apps;
65 }
66 
69 {
70  Ptr<Application> app = m_factory.Create<UdpEchoServer> ();
71  node->AddApplication (app);
72 
73  return app;
74 }
75 
77 {
78  m_factory.SetTypeId (UdpEchoClient::GetTypeId ());
79  SetAttribute ("RemoteAddress", AddressValue (address));
80  SetAttribute ("RemotePort", UintegerValue (port));
81 }
82 
84 {
85  m_factory.SetTypeId (UdpEchoClient::GetTypeId ());
86  SetAttribute ("RemoteAddress", AddressValue (Address(address)));
87  SetAttribute ("RemotePort", UintegerValue (port));
88 }
89 
90 UdpEchoClientHelper::UdpEchoClientHelper (Ipv6Address address, uint16_t port)
91 {
92  m_factory.SetTypeId (UdpEchoClient::GetTypeId ());
93  SetAttribute ("RemoteAddress", AddressValue (Address(address)));
94  SetAttribute ("RemotePort", UintegerValue (port));
95 }
96 
97 void
99  std::string name,
100  const AttributeValue &value)
101 {
102  m_factory.Set (name, value);
103 }
104 
105 void
107 {
108  app->GetObject<UdpEchoClient>()->SetFill (fill);
109 }
110 
111 void
112 UdpEchoClientHelper::SetFill (Ptr<Application> app, uint8_t fill, uint32_t dataLength)
113 {
114  app->GetObject<UdpEchoClient>()->SetFill (fill, dataLength);
115 }
116 
117 void
118 UdpEchoClientHelper::SetFill (Ptr<Application> app, uint8_t *fill, uint32_t fillLength, uint32_t dataLength)
119 {
120  app->GetObject<UdpEchoClient>()->SetFill (fill, fillLength, dataLength);
121 }
122 
125 {
126  return ApplicationContainer (InstallPriv (node));
127 }
128 
130 UdpEchoClientHelper::Install (std::string nodeName) const
131 {
132  Ptr<Node> node = Names::Find<Node> (nodeName);
133  return ApplicationContainer (InstallPriv (node));
134 }
135 
138 {
140  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
141  {
142  apps.Add (InstallPriv (*i));
143  }
144 
145  return apps;
146 }
147 
149 UdpEchoClientHelper::InstallPriv (Ptr<Node> node) const
150 {
151  Ptr<Application> app = m_factory.Create<UdpEchoClient> ();
152  node->AddApplication (app);
153 
154  return app;
155 }
156 
157 } // namespace ns3
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:148
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.
a polymophic address class
Definition: address.h:86
ApplicationContainer Install(Ptr< Node > node) const
Ptr< Application > InstallPriv(Ptr< Node > node) const
UdpEchoClientHelper(Address ip, uint16_t port)
Ptr< Object > Create(void) const
Hold an unsigned integer type.
Definition: uinteger.h:46
A Udp Echo client.
void SetFill(Ptr< Application > app, std::string fill)
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 SetAttribute(std::string name, const AttributeValue &value)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
hold objects of type ns3::Address
UdpEchoServerHelper(uint16_t port)
A Udp Echo server.
void SetAttribute(std::string name, const AttributeValue &value)
ApplicationContainer Install(Ptr< Node > node) const