From 4cc78981307e8e7edfaf2a9498f3606a1bdae447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Mon, 29 Apr 2024 17:48:49 +0200 Subject: [PATCH] applications: Use common class for source applications Proposed by Sharan Naribole --- .../model/bulk-send-application.cc | 20 +-------------- .../model/bulk-send-application.h | 10 ++------ src/applications/model/onoff-application.cc | 20 +-------------- src/applications/model/onoff-application.h | 10 ++------ .../model/three-gpp-http-client.cc | 23 ++++------------- .../model/three-gpp-http-client.h | 17 +++---------- src/applications/model/udp-client.cc | 24 +----------------- src/applications/model/udp-client.h | 15 +++-------- src/applications/model/udp-echo-client.cc | 24 +----------------- src/applications/model/udp-echo-client.h | 15 +++-------- src/applications/model/udp-trace-client.cc | 25 +------------------ src/applications/model/udp-trace-client.h | 15 +++-------- 12 files changed, 29 insertions(+), 189 deletions(-) diff --git a/src/applications/model/bulk-send-application.cc b/src/applications/model/bulk-send-application.cc index ead5da68e..b29f21a03 100644 --- a/src/applications/model/bulk-send-application.cc +++ b/src/applications/model/bulk-send-application.cc @@ -8,7 +8,6 @@ #include "bulk-send-application.h" -#include "ns3/address.h" #include "ns3/boolean.h" #include "ns3/log.h" #include "ns3/node.h" @@ -34,7 +33,7 @@ BulkSendApplication::GetTypeId() { static TypeId tid = TypeId("ns3::BulkSendApplication") - .SetParent() + .SetParent() .SetGroupName("Applications") .AddConstructor() .AddAttribute("SendSize", @@ -42,23 +41,6 @@ BulkSendApplication::GetTypeId() UintegerValue(512), MakeUintegerAccessor(&BulkSendApplication::m_sendSize), MakeUintegerChecker(1)) - .AddAttribute("Remote", - "The address of the destination", - AddressValue(), - MakeAddressAccessor(&BulkSendApplication::m_peer), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&BulkSendApplication::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send IPv4 packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&BulkSendApplication::m_tos), - MakeUintegerChecker()) .AddAttribute("MaxBytes", "The total number of bytes to send. " "Once these bytes are sent, " diff --git a/src/applications/model/bulk-send-application.h b/src/applications/model/bulk-send-application.h index d60587740..f94c08628 100644 --- a/src/applications/model/bulk-send-application.h +++ b/src/applications/model/bulk-send-application.h @@ -10,9 +10,8 @@ #define BULK_SEND_APPLICATION_H #include "seq-ts-size-header.h" +#include "source-application.h" -#include "ns3/address.h" -#include "ns3/application.h" #include "ns3/event-id.h" #include "ns3/ptr.h" #include "ns3/traced-callback.h" @@ -20,7 +19,6 @@ namespace ns3 { -class Address; class Socket; class TcpHeader; class TcpSocketBase; @@ -64,7 +62,7 @@ class TcpSocketBase; * (enable its "EnableSeqTsSizeHeader" attribute), or users may extract * the header via trace sources. */ -class BulkSendApplication : public Application +class BulkSendApplication : public SourceApplication { public: /** @@ -74,7 +72,6 @@ class BulkSendApplication : public Application static TypeId GetTypeId(); BulkSendApplication(); - ~BulkSendApplication() override; /** @@ -113,10 +110,7 @@ class BulkSendApplication : public Application void SendData(const Address& from, const Address& to); Ptr m_socket; //!< Associated socket - Address m_peer; //!< Peer address - Address m_local; //!< Local address to bind to bool m_connected; //!< True if connected - uint8_t m_tos; //!< The packets Type of Service uint32_t m_sendSize; //!< Size of data to send each time uint64_t m_maxBytes; //!< Limit total number of bytes sent uint64_t m_totBytes; //!< Total bytes sent so far diff --git a/src/applications/model/onoff-application.cc b/src/applications/model/onoff-application.cc index e47744a3a..a157be206 100644 --- a/src/applications/model/onoff-application.cc +++ b/src/applications/model/onoff-application.cc @@ -12,7 +12,6 @@ #include "onoff-application.h" -#include "ns3/address.h" #include "ns3/boolean.h" #include "ns3/data-rate.h" #include "ns3/inet-socket-address.h" @@ -44,7 +43,7 @@ OnOffApplication::GetTypeId() { static TypeId tid = TypeId("ns3::OnOffApplication") - .SetParent() + .SetParent() .SetGroupName("Applications") .AddConstructor() .AddAttribute("DataRate", @@ -57,23 +56,6 @@ OnOffApplication::GetTypeId() UintegerValue(512), MakeUintegerAccessor(&OnOffApplication::m_pktSize), MakeUintegerChecker(1)) - .AddAttribute("Remote", - "The address of the destination", - AddressValue(), - MakeAddressAccessor(&OnOffApplication::m_peer), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&OnOffApplication::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send IPv4 packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&OnOffApplication::m_tos), - MakeUintegerChecker()) .AddAttribute("OnTime", "A RandomVariableStream used to pick the duration of the 'On' state.", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"), diff --git a/src/applications/model/onoff-application.h b/src/applications/model/onoff-application.h index be41f7440..6fedec01b 100644 --- a/src/applications/model/onoff-application.h +++ b/src/applications/model/onoff-application.h @@ -14,9 +14,8 @@ #define ONOFF_APPLICATION_H #include "seq-ts-size-header.h" +#include "source-application.h" -#include "ns3/address.h" -#include "ns3/application.h" #include "ns3/data-rate.h" #include "ns3/event-id.h" #include "ns3/ptr.h" @@ -25,7 +24,6 @@ namespace ns3 { -class Address; class RandomVariableStream; class Socket; @@ -82,7 +80,7 @@ class Socket; * the header via trace sources. Note that the continuity of the sequence * number may be disrupted across On/Off cycles. */ -class OnOffApplication : public Application +class OnOffApplication : public SourceApplication { public: /** @@ -92,7 +90,6 @@ class OnOffApplication : public Application static TypeId GetTypeId(); OnOffApplication(); - ~OnOffApplication() override; /** @@ -141,10 +138,7 @@ class OnOffApplication : public Application void SendPacket(); Ptr m_socket; //!< Associated socket - Address m_peer; //!< Peer address - Address m_local; //!< Local address to bind to bool m_connected; //!< True if connected - uint8_t m_tos; //!< The packets Type of Service Ptr m_onTime; //!< rng for On Time Ptr m_offTime; //!< rng for Off Time DataRate m_cbrRate; //!< Rate that data is generated diff --git a/src/applications/model/three-gpp-http-client.cc b/src/applications/model/three-gpp-http-client.cc index 0907dfe2c..0a7580c32 100644 --- a/src/applications/model/three-gpp-http-client.cc +++ b/src/applications/model/three-gpp-http-client.cc @@ -51,7 +51,7 @@ ThreeGppHttpClient::GetTypeId() { static TypeId tid = TypeId("ns3::ThreeGppHttpClient") - .SetParent() + .SetParent() .AddConstructor() .AddAttribute( "Variables", @@ -73,23 +73,6 @@ ThreeGppHttpClient::GetTypeId() MakeUintegerChecker(), TypeId::DEPRECATED, "Replaced by Remote in ns-3.44.") - .AddAttribute("Remote", - "The address of the destination server", - AddressValue(), - MakeAddressAccessor(&ThreeGppHttpClient::SetRemote), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&ThreeGppHttpClient::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&ThreeGppHttpClient::m_tos), - MakeUintegerChecker()) .AddTraceSource("RxPage", "A page has been received.", MakeTraceSourceAccessor(&ThreeGppHttpClient::m_rxPageTrace), @@ -433,6 +416,10 @@ ThreeGppHttpClient::OpenConnection() NS_LOG_INFO(this << " Connecting to " << ipv6 << " port " << port << " / " << m_peer << "."); } + else + { + NS_ASSERT_MSG(false, "Incompatible address type: " << m_peer); + } const auto ret [[maybe_unused]] = m_socket->Connect(m_peer); NS_LOG_DEBUG(this << " Connect() return value= " << ret diff --git a/src/applications/model/three-gpp-http-client.h b/src/applications/model/three-gpp-http-client.h index bb2837c76..452623ba6 100644 --- a/src/applications/model/three-gpp-http-client.h +++ b/src/applications/model/three-gpp-http-client.h @@ -10,10 +10,10 @@ #ifndef THREE_GPP_HTTP_CLIENT_H #define THREE_GPP_HTTP_CLIENT_H +#include "source-application.h" #include "three-gpp-http-header.h" #include -#include #include #include @@ -94,7 +94,7 @@ class ThreeGppHttpVariables; * and the timestamp when the packet is transmitted (which will be used to * compute the delay and RTT of the packet). */ -class ThreeGppHttpClient : public Application +class ThreeGppHttpClient : public SourceApplication { public: /** @@ -105,6 +105,7 @@ class ThreeGppHttpClient : public Application * ThreeGppHttpClientHelper. */ ThreeGppHttpClient(); + void SetRemote(const Address& addr) override; /** * Returns the object TypeId. @@ -185,12 +186,6 @@ class ThreeGppHttpClient : public Application void StartApplication() override; void StopApplication() override; - /** - * \brief set the remote address (temporary function until deprecated attributes are removed) - * \param addr remote address - */ - void SetRemote(const Address& addr); - /** * \brief set the remote port (temporary function until deprecated attributes are removed) * \param port remote port @@ -390,14 +385,8 @@ class ThreeGppHttpClient : public Application /// The `Variables` attribute. Ptr m_httpVariables; - /// The `RemoteServerAddress` attribute. The address of the web server. - Address m_peer; /// The `RemoteServerPort` attribute. std::optional m_peerPort; - /// The `Local` attribute. - Address m_local; - /// The `Tos` attribute. - uint8_t m_tos; // TRACE SOURCES diff --git a/src/applications/model/udp-client.cc b/src/applications/model/udp-client.cc index da1140289..00ac05f97 100644 --- a/src/applications/model/udp-client.cc +++ b/src/applications/model/udp-client.cc @@ -35,7 +35,7 @@ UdpClient::GetTypeId() { static TypeId tid = TypeId("ns3::UdpClient") - .SetParent() + .SetParent() .SetGroupName("Applications") .AddConstructor() .AddAttribute( @@ -67,27 +67,6 @@ UdpClient::GetTypeId() MakeUintegerChecker(), TypeId::DEPRECATED, "Replaced by Remote in ns-3.44.") - .AddAttribute("Remote", - "The address of the destination", - AddressValue(), - MakeAddressAccessor( - (void(UdpClient::*)(const Address&)) & - UdpClient::SetRemote, // this is needed to indicate which version - // of the function overload to use - &UdpClient::GetRemote), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&UdpClient::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send IPv4 packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&UdpClient::m_tos), - MakeUintegerChecker()) .AddAttribute("PacketSize", "Size of packets generated. The minimum packet size is 12 bytes which is " "the size of the header carrying the sequence number and the time stamp.", @@ -109,7 +88,6 @@ UdpClient::UdpClient() : m_sent{0}, m_totalTx{0}, m_socket{nullptr}, - m_peer{}, m_peerPort{}, m_sendEvent{} { diff --git a/src/applications/model/udp-client.h b/src/applications/model/udp-client.h index f960328bf..8fa3bf5b3 100644 --- a/src/applications/model/udp-client.h +++ b/src/applications/model/udp-client.h @@ -11,7 +11,8 @@ #ifndef UDP_CLIENT_H #define UDP_CLIENT_H -#include "ns3/application.h" +#include "source-application.h" + #include "ns3/deprecated.h" #include "ns3/event-id.h" #include "ns3/ipv4-address.h" @@ -33,7 +34,7 @@ class Packet; * in their payloads * */ -class UdpClient : public Application +class UdpClient : public SourceApplication { public: /** @@ -54,12 +55,7 @@ class UdpClient : public Application */ NS_DEPRECATED_3_44("Use SetRemote without port parameter instead") void SetRemote(const Address& ip, uint16_t port); - - /** - * \brief set the remote address - * \param addr remote address - */ - void SetRemote(const Address& addr); + void SetRemote(const Address& addr) override; /** * \return the total bytes sent by this app @@ -106,10 +102,7 @@ class UdpClient : public Application uint32_t m_sent; //!< Counter for sent packets uint64_t m_totalTx; //!< Total bytes sent Ptr m_socket; //!< Socket - Address m_peer; //!< Peer address std::optional m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44 - Address m_local; //!< Local address to bind to - uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet #ifdef NS3_LOG_ENABLE diff --git a/src/applications/model/udp-echo-client.cc b/src/applications/model/udp-echo-client.cc index 327e1bd34..8ea2f9a50 100644 --- a/src/applications/model/udp-echo-client.cc +++ b/src/applications/model/udp-echo-client.cc @@ -27,7 +27,7 @@ UdpEchoClient::GetTypeId() { static TypeId tid = TypeId("ns3::UdpEchoClient") - .SetParent() + .SetParent() .SetGroupName("Applications") .AddConstructor() .AddAttribute( @@ -60,28 +60,6 @@ UdpEchoClient::GetTypeId() MakeUintegerChecker(), TypeId::DEPRECATED, "Replaced by Remote in ns-3.44.") - .AddAttribute( - "Remote", - "The address of the destination", - AddressValue(), - MakeAddressAccessor( - (void(UdpEchoClient::*)(const Address&)) & - UdpEchoClient::SetRemote, // this is needed to indicate which version of the - // function overload to use - &UdpEchoClient::GetRemote), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&UdpEchoClient::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send IPv4 packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&UdpEchoClient::m_tos), - MakeUintegerChecker()) .AddAttribute( "PacketSize", "Size of echo data in outbound packets", diff --git a/src/applications/model/udp-echo-client.h b/src/applications/model/udp-echo-client.h index 0aa386b44..0a9795c13 100644 --- a/src/applications/model/udp-echo-client.h +++ b/src/applications/model/udp-echo-client.h @@ -7,7 +7,8 @@ #ifndef UDP_ECHO_CLIENT_H #define UDP_ECHO_CLIENT_H -#include "ns3/application.h" +#include "source-application.h" + #include "ns3/deprecated.h" #include "ns3/event-id.h" #include "ns3/ipv4-address.h" @@ -28,7 +29,7 @@ class Packet; * * Every packet sent should be returned by the server and received here. */ -class UdpEchoClient : public Application +class UdpEchoClient : public SourceApplication { public: /** @@ -49,12 +50,7 @@ class UdpEchoClient : public Application */ NS_DEPRECATED_3_44("Use SetRemote without port parameter instead") void SetRemote(const Address& ip, uint16_t port); - - /** - * \brief set the remote address - * \param addr remote address - */ - void SetRemote(const Address& addr); + void SetRemote(const Address& addr) override; /** * Set the data size of the packet (the number of bytes that are sent as data @@ -175,10 +171,7 @@ class UdpEchoClient : public Application uint32_t m_sent; //!< Counter for sent packets Ptr m_socket; //!< Socket - Address m_peer; //!< Remote peer address std::optional m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44 - Address m_local; //!< Local address to bind to - uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet /// Callbacks for tracing the packet Tx events diff --git a/src/applications/model/udp-trace-client.cc b/src/applications/model/udp-trace-client.cc index 916032047..c89eef324 100644 --- a/src/applications/model/udp-trace-client.cc +++ b/src/applications/model/udp-trace-client.cc @@ -53,7 +53,7 @@ UdpTraceClient::GetTypeId() { static TypeId tid = TypeId("ns3::UdpTraceClient") - .SetParent() + .SetParent() .SetGroupName("Applications") .AddConstructor() .AddAttribute("RemoteAddress", @@ -78,28 +78,6 @@ UdpTraceClient::GetTypeId() MakeUintegerChecker(), TypeId::DEPRECATED, "Replaced by Remote in ns-3.44.") - .AddAttribute( - "Remote", - "The address of the destination", - AddressValue(), - MakeAddressAccessor( - (void(UdpTraceClient::*)(const Address&)) & - UdpTraceClient::SetRemote, // this is needed to indicate which version of - // the function overload to use - &UdpTraceClient::GetRemote), - MakeAddressChecker()) - .AddAttribute("Local", - "The Address on which to bind the socket. If not set, it is generated " - "automatically.", - AddressValue(), - MakeAddressAccessor(&UdpTraceClient::m_local), - MakeAddressChecker()) - .AddAttribute("Tos", - "The Type of Service used to send IPv4 packets. " - "All 8 bits of the TOS byte are set (including ECN bits).", - UintegerValue(0), - MakeUintegerAccessor(&UdpTraceClient::m_tos), - MakeUintegerChecker()) .AddAttribute("MaxPacketSize", "The maximum size of a packet (including the SeqTsHeader, 12 bytes).", UintegerValue(1024), @@ -123,7 +101,6 @@ UdpTraceClient::GetTypeId() UdpTraceClient::UdpTraceClient() : m_sent{0}, m_socket{nullptr}, - m_peer{}, m_peerPort{}, m_sendEvent{}, m_currentEntry{0} diff --git a/src/applications/model/udp-trace-client.h b/src/applications/model/udp-trace-client.h index 59f0a711c..561849cbe 100644 --- a/src/applications/model/udp-trace-client.h +++ b/src/applications/model/udp-trace-client.h @@ -10,7 +10,8 @@ #ifndef UDP_TRACE_CLIENT_H #define UDP_TRACE_CLIENT_H -#include "ns3/application.h" +#include "source-application.h" + #include "ns3/event-id.h" #include "ns3/ipv4-address.h" #include "ns3/ptr.h" @@ -50,7 +51,7 @@ class Packet; * * The latter behavior can be changed through the "TraceLoop" attribute. */ -class UdpTraceClient : public Application +class UdpTraceClient : public SourceApplication { public: /** @@ -71,12 +72,7 @@ class UdpTraceClient : public Application */ NS_DEPRECATED_3_44("Use SetRemote without port parameter instead") void SetRemote(const Address& ip, uint16_t port); - - /** - * \brief set the remote address - * \param addr remote address - */ - void SetRemote(const Address& addr); + void SetRemote(const Address& addr) override; /** * \brief Set the trace file to be used by the application @@ -162,10 +158,7 @@ class UdpTraceClient : public Application uint32_t m_sent; //!< Counter for sent packets Ptr m_socket; //!< Socket - Address m_peer; //!< Peer address std::optional m_peerPort; //!< Remote peer port (deprecated) // NS_DEPRECATED_3_44 - Address m_local; //!< Local address to bind to - uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet std::vector m_entries; //!< Entries in the trace to send