A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
udp-echo-client.h
Go to the documentation of this file.
1/*
2 * Copyright 2007 University of Washington
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
18#ifndef UDP_ECHO_CLIENT_H
19#define UDP_ECHO_CLIENT_H
20
21#include "ns3/application.h"
22#include "ns3/event-id.h"
23#include "ns3/ipv4-address.h"
24#include "ns3/ptr.h"
25#include "ns3/traced-callback.h"
26
27namespace ns3
28{
29
30class Socket;
31class Packet;
32
33/**
34 * \ingroup udpecho
35 * \brief A Udp Echo client
36 *
37 * Every packet sent should be returned by the server and received here.
38 */
40{
41 public:
42 /**
43 * \brief Get the type ID.
44 * \return the object TypeId
45 */
46 static TypeId GetTypeId();
47
49
50 ~UdpEchoClient() override;
51
52 /**
53 * \brief set the remote address and port
54 * \param ip remote IP address
55 * \param port remote port
56 */
57 void SetRemote(Address ip, uint16_t port);
58 /**
59 * \brief set the remote address
60 * \param addr remote address
61 */
62 void SetRemote(Address addr);
63
64 /**
65 * Set the data size of the packet (the number of bytes that are sent as data
66 * to the server). The contents of the data are set to unspecified (don't
67 * care) by this call.
68 *
69 * \warning If you have set the fill data for the echo client using one of the
70 * SetFill calls, this will undo those effects.
71 *
72 * \param dataSize The size of the echo data you want to sent.
73 */
74 void SetDataSize(uint32_t dataSize);
75
76 /**
77 * Get the number of data bytes that will be sent to the server.
78 *
79 * \warning The number of bytes may be modified by calling any one of the
80 * SetFill methods. If you have called SetFill, then the number of
81 * data bytes will correspond to the size of an initialized data buffer.
82 * If you have not called a SetFill method, the number of data bytes will
83 * correspond to the number of don't care bytes that will be sent.
84 *
85 * \returns The number of data bytes.
86 */
87 uint32_t GetDataSize() const;
88
89 /**
90 * Set the data fill of the packet (what is sent as data to the server) to
91 * the zero-terminated contents of the fill string string.
92 *
93 * \warning The size of resulting echo packets will be automatically adjusted
94 * to reflect the size of the fill string -- this means that the PacketSize
95 * attribute may be changed as a result of this call.
96 *
97 * \param fill The string to use as the actual echo data bytes.
98 */
99 void SetFill(std::string fill);
100
101 /**
102 * Set the data fill of the packet (what is sent as data to the server) to
103 * the repeated contents of the fill byte. i.e., the fill byte will be
104 * used to initialize the contents of the data packet.
105 *
106 * \warning The size of resulting echo packets will be automatically adjusted
107 * to reflect the dataSize parameter -- this means that the PacketSize
108 * attribute may be changed as a result of this call.
109 *
110 * \param fill The byte to be repeated in constructing the packet data..
111 * \param dataSize The desired size of the resulting echo packet data.
112 */
113 void SetFill(uint8_t fill, uint32_t dataSize);
114
115 /**
116 * Set the data fill of the packet (what is sent as data to the server) to
117 * the contents of the fill buffer, repeated as many times as is required.
118 *
119 * Initializing the packet to the contents of a provided single buffer is
120 * accomplished by setting the fillSize set to your desired dataSize
121 * (and providing an appropriate buffer).
122 *
123 * \warning The size of resulting echo packets will be automatically adjusted
124 * to reflect the dataSize parameter -- this means that the PacketSize
125 * attribute of the Application may be changed as a result of this call.
126 *
127 * \param fill The fill pattern to use when constructing packets.
128 * \param fillSize The number of bytes in the provided fill pattern.
129 * \param dataSize The desired size of the final echo data.
130 */
131 void SetFill(uint8_t* fill, uint32_t fillSize, uint32_t dataSize);
132
133 private:
134 void StartApplication() override;
135 void StopApplication() override;
136
137 /**
138 * \brief Schedule the next packet transmission
139 * \param dt time interval between packets.
140 */
141 void ScheduleTransmit(Time dt);
142 /**
143 * \brief Send a packet
144 */
145 void Send();
146
147 /**
148 * \brief Handle a packet reception.
149 *
150 * This function is called by lower layers.
151 *
152 * \param socket the socket the packet was received to.
153 */
154 void HandleRead(Ptr<Socket> socket);
155
156 uint32_t m_count; //!< Maximum number of packets the application will send
157 Time m_interval; //!< Packet inter-send time
158 uint32_t m_size; //!< Size of the sent packet
159
160 uint32_t m_dataSize; //!< packet payload size (must be equal to m_size)
161 uint8_t* m_data; //!< packet payload data
162
163 uint32_t m_sent; //!< Counter for sent packets
165 Address m_peerAddress; //!< Remote peer address
166 uint16_t m_peerPort; //!< Remote peer port
167 uint8_t m_tos; //!< The packets Type of Service
168 EventId m_sendEvent; //!< Event to send the next packet
169
170 /// Callbacks for tracing the packet Tx events
172
173 /// Callbacks for tracing the packet Rx events
175
176 /// Callbacks for tracing the packet Tx events, includes source and destination addresses
178
179 /// Callbacks for tracing the packet Rx events, includes source and destination addresses
181};
182
183} // namespace ns3
184
185#endif /* UDP_ECHO_CLIENT_H */
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
A Udp Echo client.
void SetFill(std::string fill)
Set the data fill of the packet (what is sent as data to the server) to the zero-terminated contents ...
Time m_interval
Packet inter-send time.
void Send()
Send a packet.
void StopApplication() override
Application specific shutdown code.
Ptr< Socket > m_socket
Socket.
void HandleRead(Ptr< Socket > socket)
Handle a packet reception.
EventId m_sendEvent
Event to send the next packet.
uint32_t m_size
Size of the sent packet.
uint8_t m_tos
The packets Type of Service.
uint32_t GetDataSize() const
Get the number of data bytes that will be sent to the server.
uint32_t m_count
Maximum number of packets the application will send.
static TypeId GetTypeId()
Get the type ID.
Address m_peerAddress
Remote peer address.
uint8_t * m_data
packet payload data
uint32_t m_sent
Counter for sent packets.
void StartApplication() override
Application specific startup code.
void ScheduleTransmit(Time dt)
Schedule the next packet transmission.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
Callbacks for tracing the packet Tx events, includes source and destination addresses.
TracedCallback< Ptr< const Packet > > m_txTrace
Callbacks for tracing the packet Tx events.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_rxTraceWithAddresses
Callbacks for tracing the packet Rx events, includes source and destination addresses.
void SetDataSize(uint32_t dataSize)
Set the data size of the packet (the number of bytes that are sent as data to the server).
uint16_t m_peerPort
Remote peer port.
TracedCallback< Ptr< const Packet > > m_rxTrace
Callbacks for tracing the packet Rx events.
uint32_t m_dataSize
packet payload size (must be equal to m_size)
void SetRemote(Address ip, uint16_t port)
set the remote address and port
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.