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 Packet;
28
29/**
30 * @ingroup udpclientserver
31 *
32 * @brief A Udp client. Sends UDP packet carrying sequence number and time stamp
33 * in their payloads
34 *
35 */
37{
38 public:
39 /**
40 * @brief Get the type ID.
41 * @return the object TypeId
42 */
43 static TypeId GetTypeId();
44
45 UdpClient();
46 ~UdpClient() override;
47
48 static constexpr uint16_t DEFAULT_PORT{100}; //!< default port
49
50 /**
51 * @brief set the remote address and port
52 * @param ip remote IP address
53 * @param port remote port
54 */
55 NS_DEPRECATED_3_44("Use SetRemote without port parameter instead")
56 void SetRemote(const Address& ip, uint16_t port);
57 void SetRemote(const Address& addr) override;
58
59 /**
60 * @return the total bytes sent by this app
61 */
62 uint64_t GetTotalTx() const;
63
64 private:
65 void DoStartApplication() override;
66 void CancelEvents() override;
67
68 /**
69 * @brief Send a packet
70 */
71 void Send();
72
73 /**
74 * @brief Set the remote port (temporary function until deprecated attributes are removed)
75 * @param port remote port
76 */
77 void SetPort(uint16_t port);
78
79 /**
80 * @brief Get the remote port (temporary function until deprecated attributes are removed)
81 * @return the remote port
82 */
83 uint16_t GetPort() const;
84
85 /**
86 * @brief Get the remote address (temporary function until deprecated attributes are removed)
87 * @return the remote address
88 */
89 Address GetRemote() const;
90
91 /// Callbacks for tracing the packet Tx events, includes source and destination addresses
93
94 uint32_t m_count; //!< Maximum number of packets the application will send
95 Time m_interval; //!< Packet inter-send time
96 uint32_t m_size; //!< Size of the sent packet (including the SeqTsHeader)
97
98 uint32_t m_sent{0}; //!< Counter for sent packets
99 uint64_t m_totalTx{0}; //!< Total bytes sent
100 std::optional<uint16_t> m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44
101 EventId m_sendEvent; //!< Event to send the next packet
102
103#ifdef NS3_LOG_ENABLE
104 std::string m_peerString; //!< Remote peer address string
105#endif // NS3_LOG_ENABLE
106};
107
108} // namespace ns3
109
110#endif /* UDP_CLIENT_H */
a polymophic address class
Definition address.h:111
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
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
Time m_interval
Packet inter-send time.
Definition udp-client.h:95
std::optional< uint16_t > m_peerPort
Remote peer port (deprecated) // NS_DEPRECATED_3_44.
Definition udp-client.h:100
uint64_t GetTotalTx() const
uint64_t m_totalTx
Total bytes sent.
Definition udp-client.h:99
~UdpClient() override
Definition udp-client.cc:92
std::string m_peerString
Remote peer address string.
Definition udp-client.h:104
uint32_t m_sent
Counter for sent packets.
Definition udp-client.h:98
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:92
void CancelEvents() override
Cancel all pending events.
static constexpr uint16_t DEFAULT_PORT
default port
Definition udp-client.h:48
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:101
uint32_t m_size
Size of the sent packet (including the SeqTsHeader).
Definition udp-client.h:96
uint32_t m_count
Maximum number of packets the application will send.
Definition udp-client.h:94
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).
void SetRemote(const Address &ip, uint16_t port)
set the remote address and port
Definition udp-client.cc:98
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.
#define private