A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
udp-client-server-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: 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
29
UdpServerHelper::UdpServerHelper
()
30
{
31
}
32
33
UdpServerHelper::UdpServerHelper
(uint16_t
port
)
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
45
ApplicationContainer
46
UdpServerHelper::Install
(
NodeContainer
c)
47
{
48
ApplicationContainer
apps;
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
61
Ptr<UdpServer>
62
UdpServerHelper::GetServer
(
void
)
63
{
64
return
m_server
;
65
}
66
67
UdpClientHelper::UdpClientHelper
()
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
78
UdpClientHelper::UdpClientHelper
(
Ipv4Address
address, uint16_t
port
)
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
98
ApplicationContainer
99
UdpClientHelper::Install
(
NodeContainer
c)
100
{
101
ApplicationContainer
apps;
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
112
UdpTraceClientHelper::UdpTraceClientHelper
()
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
146
ApplicationContainer
147
UdpTraceClientHelper::Install
(
NodeContainer
c)
148
{
149
ApplicationContainer
apps;
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
src
applications
helper
udp-client-server-helper.cc
Generated on Tue May 14 2013 11:08:16 for ns-3 by
1.8.1.2