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