applications: Add common class for source applications
Proposed by Sharan Naribole
This commit is contained in:
@@ -15,6 +15,7 @@ build_lib(
|
||||
model/seq-ts-echo-header.cc
|
||||
model/seq-ts-header.cc
|
||||
model/seq-ts-size-header.cc
|
||||
model/source-application.cc
|
||||
model/three-gpp-http-client.cc
|
||||
model/three-gpp-http-header.cc
|
||||
model/three-gpp-http-server.cc
|
||||
@@ -39,6 +40,7 @@ build_lib(
|
||||
model/seq-ts-echo-header.h
|
||||
model/seq-ts-header.h
|
||||
model/seq-ts-size-header.h
|
||||
model/source-application.h
|
||||
model/three-gpp-http-client.h
|
||||
model/three-gpp-http-header.h
|
||||
model/three-gpp-http-server.h
|
||||
|
||||
77
src/applications/model/source-application.cc
Normal file
77
src/applications/model/source-application.cc
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Author: Sébastien Deronne <sebastien.deronne@gmail.com>
|
||||
*/
|
||||
|
||||
#include "source-application.h"
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/uinteger.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE("SourceApplication");
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED(SourceApplication);
|
||||
|
||||
TypeId
|
||||
SourceApplication::GetTypeId()
|
||||
{
|
||||
static TypeId tid =
|
||||
TypeId("ns3::SourceApplication")
|
||||
.SetParent<Application>()
|
||||
.SetGroupName("Applications")
|
||||
.AddAttribute(
|
||||
"Remote",
|
||||
"The address of the destination, made of the remote IP address and the "
|
||||
"destination port",
|
||||
AddressValue(),
|
||||
MakeAddressAccessor(&SourceApplication::SetRemote, &SourceApplication::GetRemote),
|
||||
MakeAddressChecker())
|
||||
.AddAttribute("Local",
|
||||
"The Address on which to bind the socket. If not set, it is generated "
|
||||
"automatically when needed by the application.",
|
||||
AddressValue(),
|
||||
MakeAddressAccessor(&SourceApplication::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(&SourceApplication::m_tos),
|
||||
MakeUintegerChecker<uint8_t>());
|
||||
return tid;
|
||||
}
|
||||
|
||||
SourceApplication::SourceApplication()
|
||||
: m_peer{}
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
}
|
||||
|
||||
SourceApplication::~SourceApplication()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
}
|
||||
|
||||
void
|
||||
SourceApplication::SetRemote(const Address& addr)
|
||||
{
|
||||
NS_LOG_FUNCTION(this << addr);
|
||||
if (!addr.IsInvalid())
|
||||
{
|
||||
m_peer = addr;
|
||||
}
|
||||
}
|
||||
|
||||
Address
|
||||
SourceApplication::GetRemote() const
|
||||
{
|
||||
return m_peer;
|
||||
}
|
||||
|
||||
} // Namespace ns3
|
||||
66
src/applications/model/source-application.h
Normal file
66
src/applications/model/source-application.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Author: Sébastien Deronne <sebastien.deronne@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_APPLICATION_H
|
||||
#define SOURCE_APPLICATION_H
|
||||
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/application.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
/**
|
||||
* \ingroup applications
|
||||
* \brief Base class for source applications.
|
||||
*
|
||||
* This class can be used as a base class for source applications.
|
||||
* A source application is one that primarily sources new data towards a single remote client
|
||||
* address and port, and may also receive data (such as an HTTP server).
|
||||
*
|
||||
* The main purpose of this base class application public API is to provide a uniform way to
|
||||
* configure remote and local addresses.
|
||||
*
|
||||
* Unlike the SinkApplication, the SourceApplication does not expose an individual Port attribute.
|
||||
* Instead, the port values are embedded in the Local and Remote address attributes, which should be
|
||||
* configured to an InetSocketAddress or Inet6SocketAddress value that contains the desired port
|
||||
* number.
|
||||
*/
|
||||
class SourceApplication : public Application
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Get the type ID.
|
||||
* \return the object TypeId
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
|
||||
SourceApplication();
|
||||
~SourceApplication() override;
|
||||
|
||||
/**
|
||||
* \brief set the remote address
|
||||
* \param addr remote address
|
||||
*/
|
||||
virtual void SetRemote(const Address& addr);
|
||||
|
||||
/**
|
||||
* \brief get the remote address
|
||||
* \return the remote address
|
||||
*/
|
||||
Address GetRemote() const;
|
||||
|
||||
protected:
|
||||
Address m_peer; //!< Peer address
|
||||
Address m_local; //!< Local address to bind to
|
||||
uint8_t m_tos; //!< The packets Type of Service
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* SOURCE_APPLICATION_H */
|
||||
Reference in New Issue
Block a user