A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
udp-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDCAST
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Amine Ismail <amine.ismail@sophia.inria.fr>
7 * <amine.ismail@udcast.com>
8 *
9 */
10
11#ifndef UDP_CLIENT_H
12#define UDP_CLIENT_H
13
14#include "source-application.h"
15
16#include "ns3/deprecated.h"
17#include "ns3/event-id.h"
18#include "ns3/ipv4-address.h"
19#include "ns3/ptr.h"
20#include <ns3/traced-callback.h>
21
22#include <optional>
23
24namespace ns3
25{
26
27class Socket;
28class Packet;
29
30/**
31 * @ingroup udpclientserver
32 *
33 * @brief A Udp client. Sends UDP packet carrying sequence number and time stamp
34 * in their payloads
35 *
36 */
38{
39 public:
40 /**
41 * @brief Get the type ID.
42 * @return the object TypeId
43 */
44 static TypeId GetTypeId();
45
46 UdpClient();
47 ~UdpClient() override;
48
49 static constexpr uint16_t DEFAULT_PORT{100}; //!< default port
50
51 /**
52 * @brief set the remote address and port
53 * @param ip remote IP address
54 * @param port remote port
55 */
56 NS_DEPRECATED_3_44("Use SetRemote without port parameter instead")
57 void SetRemote(const Address& ip, uint16_t port);
58 void SetRemote(const Address& addr) override;
59
60 /**
61 * @return the total bytes sent by this app
62 */
63 uint64_t GetTotalTx() const;
64
65 private:
66 void StartApplication() override;
67 void StopApplication() override;
68
69 /**
70 * @brief Send a packet
71 */
72 void Send();
73
74 /**
75 * @brief Set the remote port (temporary function until deprecated attributes are removed)
76 * @param port remote port
77 */
78 void SetPort(uint16_t port);
79
80 /**
81 * @brief Get the remote port (temporary function until deprecated attributes are removed)
82 * @return the remote port
83 */
84 uint16_t GetPort() const;
85
86 /**
87 * @brief Get the remote address (temporary function until deprecated attributes are removed)
88 * @return the remote address
89 */
90 Address GetRemote() const;
91
92 /// Traced Callback: transmitted packets.
94
95 /// Callbacks for tracing the packet Tx events, includes source and destination addresses
97
98 uint32_t m_count; //!< Maximum number of packets the application will send
99 Time m_interval; //!< Packet inter-send time
100 uint32_t m_size; //!< Size of the sent packet (including the SeqTsHeader)
101
102 uint32_t m_sent; //!< Counter for sent packets
103 uint64_t m_totalTx; //!< Total bytes sent
104 Ptr<Socket> m_socket; //!< Socket
105 std::optional<uint16_t> m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44
106 EventId m_sendEvent; //!< Event to send the next packet
107
108#ifdef NS3_LOG_ENABLE
109 std::string m_peerString; //!< Remote peer address string
110#endif // NS3_LOG_ENABLE
111};
112
113} // namespace ns3
114
115#endif /* UDP_CLIENT_H */
a polymophic address class
Definition address.h:90
An identifier for simulation events.
Definition event-id.h:45
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
Base class for source applications.
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 client.
Definition udp-client.h:38
Time m_interval
Packet inter-send time.
Definition udp-client.h:99
std::optional< uint16_t > m_peerPort
Remote peer port (deprecated) // NS_DEPRECATED_3_44.
Definition udp-client.h:105
uint64_t GetTotalTx() const
uint64_t m_totalTx
Total bytes sent.
Definition udp-client.h:103
~UdpClient() override
Definition udp-client.cc:97
std::string m_peerString
Remote peer address string.
Definition udp-client.h:109
uint32_t m_sent
Counter for sent packets.
Definition udp-client.h:102
Ptr< Socket > m_socket
Socket.
Definition udp-client.h:104
void SetPort(uint16_t port)
Set the remote port (temporary function until deprecated attributes are removed)
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
Callbacks for tracing the packet Tx events, includes source and destination addresses.
Definition udp-client.h:96
static constexpr uint16_t DEFAULT_PORT
default port
Definition udp-client.h:49
void Send()
Send a packet.
static TypeId GetTypeId()
Get the type ID.
Definition udp-client.cc:34
EventId m_sendEvent
Event to send the next packet.
Definition udp-client.h:106
uint32_t m_size
Size of the sent packet (including the SeqTsHeader)
Definition udp-client.h:100
uint32_t m_count
Maximum number of packets the application will send.
Definition udp-client.h:98
uint16_t GetPort() const
Get the remote port (temporary function until deprecated attributes are removed)
Address GetRemote() const
Get the remote address (temporary function until deprecated attributes are removed)
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
Definition udp-client.h:93
void StartApplication() override
Application specific startup code.
void StopApplication() override
Application specific shutdown code.
void SetRemote(const Address &ip, uint16_t port)
set the remote address and port
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:91
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
#define private