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 Packet;
24
25/**
26 * @ingroup udpecho
27 * @brief A Udp Echo client
28 *
29 * Every packet sent should be returned by the server and received here.
30 */
32{
33 public:
34 /**
35 * @brief Get the type ID.
36 * @return the object TypeId
37 */
38 static TypeId GetTypeId();
39
41 ~UdpEchoClient() override;
42
43 static constexpr uint16_t DEFAULT_PORT{0}; //!< default port
44
45 /**
46 * @brief set the remote address and port
47 * @param ip remote IP address
48 * @param port remote port
49 */
50 NS_DEPRECATED_3_44("Use SetRemote without port parameter instead")
51 void SetRemote(const Address& ip, uint16_t port);
52 void SetRemote(const Address& addr) override;
53
54 /**
55 * Set the data size of the packet (the number of bytes that are sent as data
56 * to the server). The contents of the data are set to unspecified (don't
57 * care) by this call.
58 *
59 * @warning If you have set the fill data for the echo client using one of the
60 * SetFill calls, this will undo those effects.
61 *
62 * @param dataSize The size of the echo data you want to sent.
63 */
64 void SetDataSize(uint32_t dataSize);
65
66 /**
67 * Get the number of data bytes that will be sent to the server.
68 *
69 * @warning The number of bytes may be modified by calling any one of the
70 * SetFill methods. If you have called SetFill, then the number of
71 * data bytes will correspond to the size of an initialized data buffer.
72 * If you have not called a SetFill method, the number of data bytes will
73 * correspond to the number of don't care bytes that will be sent.
74 *
75 * @returns The number of data bytes.
76 */
77 uint32_t GetDataSize() const;
78
79 /**
80 * Set the data fill of the packet (what is sent as data to the server) to
81 * the zero-terminated contents of the fill string string.
82 *
83 * @warning The size of resulting echo packets will be automatically adjusted
84 * to reflect the size of the fill string -- this means that the PacketSize
85 * attribute may be changed as a result of this call.
86 *
87 * @param fill The string to use as the actual echo data bytes.
88 */
89 void SetFill(std::string fill);
90
91 /**
92 * Set the data fill of the packet (what is sent as data to the server) to
93 * the repeated contents of the fill byte. i.e., the fill byte will be
94 * used to initialize the contents of the data packet.
95 *
96 * @warning The size of resulting echo packets will be automatically adjusted
97 * to reflect the dataSize parameter -- this means that the PacketSize
98 * attribute may be changed as a result of this call.
99 *
100 * @param fill The byte to be repeated in constructing the packet data..
101 * @param dataSize The desired size of the resulting echo packet data.
102 */
103 void SetFill(uint8_t fill, uint32_t dataSize);
104
105 /**
106 * Set the data fill of the packet (what is sent as data to the server) to
107 * the contents of the fill buffer, repeated as many times as is required.
108 *
109 * Initializing the packet to the contents of a provided single buffer is
110 * accomplished by setting the fillSize set to your desired dataSize
111 * (and providing an appropriate buffer).
112 *
113 * @warning The size of resulting echo packets will be automatically adjusted
114 * to reflect the dataSize parameter -- this means that the PacketSize
115 * attribute of the Application may be changed as a result of this call.
116 *
117 * @param fill The fill pattern to use when constructing packets.
118 * @param fillSize The number of bytes in the provided fill pattern.
119 * @param dataSize The desired size of the final echo data.
120 */
121 void SetFill(uint8_t* fill, uint32_t fillSize, uint32_t dataSize);
122
123 private:
124 void DoStartApplication() override;
125 void CancelEvents() override;
126
127 /**
128 * @brief Set the remote port (temporary function until deprecated attributes are removed)
129 * @param port remote port
130 */
131 void SetPort(uint16_t port);
132
133 /**
134 * @brief Get the remote port (temporary function until deprecated attributes are removed)
135 * @return the remote port
136 */
137 uint16_t GetPort() const;
138
139 /**
140 * @brief Get the remote address (temporary function until deprecated attributes are removed)
141 * @return the remote address
142 */
143 Address GetRemote() const;
144
145 /**
146 * @brief Schedule the next packet transmission
147 * @param dt time interval between packets.
148 */
149 void ScheduleTransmit(Time dt);
150 /**
151 * @brief Send a packet
152 */
153 void Send();
154
155 /**
156 * @brief Handle a packet reception.
157 *
158 * This function is called by lower layers.
159 *
160 * @param socket the socket the packet was received to.
161 */
162 void HandleRead(Ptr<Socket> socket);
163
164 uint32_t m_count; //!< Maximum number of packets the application will send
165 Time m_interval; //!< Packet inter-send time
166 uint32_t m_size; //!< Size of the sent packet
167
168 uint32_t m_dataSize{0}; //!< packet payload size (must be equal to m_size)
169 uint8_t* m_data{nullptr}; //!< packet payload data
170
171 uint32_t m_sent{0}; //!< Counter for sent packets
172 std::optional<uint16_t> m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44
173 EventId m_sendEvent; //!< Event to send the next packet
174
175 /// Callbacks for tracing the packet Rx events
177
178 /// Callbacks for tracing the packet Tx events, includes source and destination addresses
180
181 /// Callbacks for tracing the packet Rx events, includes source and destination addresses
183};
184
185} // namespace ns3
186
187#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
SourceApplication(bool allowPacketSocket=true)
Constructor.
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 ...
void CancelEvents() override
Cancel all pending events.
Time m_interval
Packet inter-send time.
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.
void SetRemote(const Address &ip, uint16_t port)
set the remote address and port
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 >, 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)
void DoStartApplication() override
Application specific startup code for child subclasses.
uint16_t port
Definition dsdv-manet.cc:33
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
#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.
STL namespace.
#define private