applications: Use common class for source applications

Proposed by Sharan Naribole
This commit is contained in:
Sébastien Deronne
2024-04-29 17:48:49 +02:00
parent 5916924b5e
commit 4cc7898130
12 changed files with 29 additions and 189 deletions

View File

@@ -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<Application>()
.SetParent<SourceApplication>()
.SetGroupName("Applications")
.AddConstructor<BulkSendApplication>()
.AddAttribute("SendSize",
@@ -42,23 +41,6 @@ BulkSendApplication::GetTypeId()
UintegerValue(512),
MakeUintegerAccessor(&BulkSendApplication::m_sendSize),
MakeUintegerChecker<uint32_t>(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<uint8_t>())
.AddAttribute("MaxBytes",
"The total number of bytes to send. "
"Once these bytes are sent, "

View File

@@ -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<Socket> 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

View File

@@ -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<Application>()
.SetParent<SourceApplication>()
.SetGroupName("Applications")
.AddConstructor<OnOffApplication>()
.AddAttribute("DataRate",
@@ -57,23 +56,6 @@ OnOffApplication::GetTypeId()
UintegerValue(512),
MakeUintegerAccessor(&OnOffApplication::m_pktSize),
MakeUintegerChecker<uint32_t>(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<uint8_t>())
.AddAttribute("OnTime",
"A RandomVariableStream used to pick the duration of the 'On' state.",
StringValue("ns3::ConstantRandomVariable[Constant=1.0]"),

View File

@@ -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<Socket> 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<RandomVariableStream> m_onTime; //!< rng for On Time
Ptr<RandomVariableStream> m_offTime; //!< rng for Off Time
DataRate m_cbrRate; //!< Rate that data is generated

View File

@@ -51,7 +51,7 @@ ThreeGppHttpClient::GetTypeId()
{
static TypeId tid =
TypeId("ns3::ThreeGppHttpClient")
.SetParent<Application>()
.SetParent<SourceApplication>()
.AddConstructor<ThreeGppHttpClient>()
.AddAttribute(
"Variables",
@@ -73,23 +73,6 @@ ThreeGppHttpClient::GetTypeId()
MakeUintegerChecker<uint16_t>(),
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<uint8_t>())
.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

View File

@@ -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 <ns3/address.h>
#include <ns3/application.h>
#include <ns3/traced-callback.h>
#include <optional>
@@ -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<ThreeGppHttpVariables> m_httpVariables;
/// The `RemoteServerAddress` attribute. The address of the web server.
Address m_peer;
/// The `RemoteServerPort` attribute.
std::optional<uint16_t> m_peerPort;
/// The `Local` attribute.
Address m_local;
/// The `Tos` attribute.
uint8_t m_tos;
// TRACE SOURCES

View File

@@ -35,7 +35,7 @@ UdpClient::GetTypeId()
{
static TypeId tid =
TypeId("ns3::UdpClient")
.SetParent<Application>()
.SetParent<SourceApplication>()
.SetGroupName("Applications")
.AddConstructor<UdpClient>()
.AddAttribute(
@@ -67,27 +67,6 @@ UdpClient::GetTypeId()
MakeUintegerChecker<uint16_t>(),
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<uint8_t>())
.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{}
{

View File

@@ -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<Socket> m_socket; //!< Socket
Address m_peer; //!< Peer address
std::optional<uint16_t> 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

View File

@@ -27,7 +27,7 @@ UdpEchoClient::GetTypeId()
{
static TypeId tid =
TypeId("ns3::UdpEchoClient")
.SetParent<Application>()
.SetParent<SourceApplication>()
.SetGroupName("Applications")
.AddConstructor<UdpEchoClient>()
.AddAttribute(
@@ -60,28 +60,6 @@ UdpEchoClient::GetTypeId()
MakeUintegerChecker<uint16_t>(),
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<uint8_t>())
.AddAttribute(
"PacketSize",
"Size of echo data in outbound packets",

View File

@@ -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<Socket> m_socket; //!< Socket
Address m_peer; //!< Remote peer address
std::optional<uint16_t> 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

View File

@@ -53,7 +53,7 @@ UdpTraceClient::GetTypeId()
{
static TypeId tid =
TypeId("ns3::UdpTraceClient")
.SetParent<Application>()
.SetParent<SourceApplication>()
.SetGroupName("Applications")
.AddConstructor<UdpTraceClient>()
.AddAttribute("RemoteAddress",
@@ -78,28 +78,6 @@ UdpTraceClient::GetTypeId()
MakeUintegerChecker<uint16_t>(),
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<uint8_t>())
.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}

View File

@@ -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<Socket> m_socket; //!< Socket
Address m_peer; //!< Peer address
std::optional<uint16_t> 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<TraceEntry> m_entries; //!< Entries in the trace to send