A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
udp-client-server-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: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  */
20 #include "udp-client-server-helper.h"
21 #include "ns3/udp-server.h"
22 #include "ns3/udp-client.h"
23 #include "ns3/udp-trace-client.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/string.h"
26 
27 namespace ns3 {
28 
30 {
31 }
32 
34 {
35  m_factory.SetTypeId (UdpServer::GetTypeId ());
36  SetAttribute ("Port", UintegerValue (port));
37 }
38 
39 void
40 UdpServerHelper::SetAttribute (std::string name, const AttributeValue &value)
41 {
42  m_factory.Set (name, value);
43 }
44 
47 {
49  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
50  {
51  Ptr<Node> node = *i;
52 
53  m_server = m_factory.Create<UdpServer> ();
54  node->AddApplication (m_server);
55  apps.Add (m_server);
56 
57  }
58  return apps;
59 }
60 
62 UdpServerHelper::GetServer (void)
63 {
64  return m_server;
65 }
66 
68 {
69 }
70 
71 UdpClientHelper::UdpClientHelper (Address address, uint16_t port)
72 {
73  m_factory.SetTypeId (UdpClient::GetTypeId ());
74  SetAttribute ("RemoteAddress", AddressValue (address));
75  SetAttribute ("RemotePort", UintegerValue (port));
76 }
77 
79 {
80  m_factory.SetTypeId (UdpClient::GetTypeId ());
81  SetAttribute ("RemoteAddress", AddressValue (Address(address)));
82  SetAttribute ("RemotePort", UintegerValue (port));
83 }
84 
85 UdpClientHelper::UdpClientHelper (Ipv6Address address, uint16_t port)
86 {
87  m_factory.SetTypeId (UdpClient::GetTypeId ());
88  SetAttribute ("RemoteAddress", AddressValue (Address(address)));
89  SetAttribute ("RemotePort", UintegerValue (port));
90 }
91 
92 void
93 UdpClientHelper::SetAttribute (std::string name, const AttributeValue &value)
94 {
95  m_factory.Set (name, value);
96 }
97 
100 {
102  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
103  {
104  Ptr<Node> node = *i;
105  Ptr<UdpClient> client = m_factory.Create<UdpClient> ();
106  node->AddApplication (client);
107  apps.Add (client);
108  }
109  return apps;
110 }
111 
113 {
114 }
115 
116 UdpTraceClientHelper::UdpTraceClientHelper (Address address, uint16_t port, std::string filename)
117 {
118  m_factory.SetTypeId (UdpTraceClient::GetTypeId ());
119  SetAttribute ("RemoteAddress", AddressValue (address));
120  SetAttribute ("RemotePort", UintegerValue (port));
121  SetAttribute ("TraceFilename", StringValue (filename));
122 }
123 
124 UdpTraceClientHelper::UdpTraceClientHelper (Ipv4Address address, uint16_t port, std::string filename)
125 {
126  m_factory.SetTypeId (UdpTraceClient::GetTypeId ());
127  SetAttribute ("RemoteAddress", AddressValue (Address (address)));
128  SetAttribute ("RemotePort", UintegerValue (port));
129  SetAttribute ("TraceFilename", StringValue (filename));
130 }
131 
132 UdpTraceClientHelper::UdpTraceClientHelper (Ipv6Address address, uint16_t port, std::string filename)
133 {
134  m_factory.SetTypeId (UdpTraceClient::GetTypeId ());
135  SetAttribute ("RemoteAddress", AddressValue (Address (address)));
136  SetAttribute ("RemotePort", UintegerValue (port));
137  SetAttribute ("TraceFilename", StringValue (filename));
138 }
139 
140 void
141 UdpTraceClientHelper::SetAttribute (std::string name, const AttributeValue &value)
142 {
143  m_factory.Set (name, value);
144 }
145 
148 {
150  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
151  {
152  Ptr<Node> node = *i;
153  Ptr<UdpTraceClient> client = m_factory.Create<UdpTraceClient> ();
154  node->AddApplication (client);
155  apps.Add (client);
156  }
157  return apps;
158 }
159 
160 } // namespace ns3
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:148
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 SetAttribute(std::string name, const AttributeValue &value)
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
ApplicationContainer Install(NodeContainer c)
ApplicationContainer Install(NodeContainer c)
a polymophic address class
Definition: address.h:86
Ptr< Object > Create(void) const
Hold an unsigned integer type.
Definition: uinteger.h:46
void SetAttribute(std::string name, const AttributeValue &value)
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)
A Udp client. Sends UDP packet carrying sequence number and time stamp in their payloads.
Definition: udp-client.h:43
A trace based streamer.
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
hold objects of type ns3::Address
ApplicationContainer Install(NodeContainer c)
void SetAttribute(std::string name, const AttributeValue &value)
A Udp server. Receives UDP packets from a remote host. UDP packets carry a 32bits sequence number fol...
Definition: udp-server.h:45