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