A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::SourceApplication Class Referenceabstract

Base class for source applications. More...

#include "source-application.h"

Inheritance diagram for ns3::SourceApplication:
Collaboration diagram for ns3::SourceApplication:

Public Member Functions

 SourceApplication (bool allowPacketSocket=true)
 Constructor.
 ~SourceApplication () override
Address GetRemote () const
 get the remote address
Ptr< SocketGetSocket () const
 Get the socket this application is attached to.
virtual void SetRemote (const Address &addr)
 set the remote address
Public Member Functions inherited from ns3::Application
 Application ()
 ~Application () override
virtual int64_t AssignStreams (int64_t stream)
 Assign a fixed random variable stream number to the random variables used by this Application object.
Ptr< NodeGetNode () const
void SetNode (Ptr< Node > node)
void SetStartTime (Time start)
 Specify application start time.
void SetStopTime (Time stop)
 Specify application stop time.
Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 ~Object () override
 Destructor.
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
void Dispose ()
 Dispose of this Object.
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
TypeId GetInstanceTypeId () const final
 Get the most derived TypeId for this Object.
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
template<typename T>
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
template<typename T>
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
bool IsInitialized () const
 Check if the object has been initialized.
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
uint32_t GetReferenceCount () const
 Get the reference count of the object.
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
void Ref () const
 Increment the reference count.
void Unref () const
 Decrement the reference count.
Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
Static Public Member Functions inherited from ns3::Application
static TypeId GetTypeId ()
 Get the type ID.
Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.

Protected Types

typedef void(* ConnectionEventCallback) (Ptr< Socket > socket, const Address &local, const Address &remote)
 TracedCallback signature for connection success/failure event.

Protected Member Functions

bool CloseSocket ()
 Close the socket.
void DoDispose () override
 Destructor implementation.
Protected Member Functions inherited from ns3::Application
void DoInitialize () override
 Initialize() implementation.
Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.

Protected Attributes

bool m_connected {false}
 flag whether socket is connected
TracedCallback< Ptr< Socket >, const Address &, const Address & > m_connectionFailure
 Traced Callback: connection failure event.
TracedCallback< Ptr< Socket >, const Address &, const Address & > m_connectionSuccess
 Traced Callback: connection success event.
Address m_local
 Local address to bind to.
Address m_peer
 Peer address.
TypeId m_protocolTid
 Protocol TypeId value.
Ptr< Socketm_socket
 Socket.
uint8_t m_tos
 The packets Type of Service.
TracedCallback< Ptr< const Packet > > m_txTrace
 Traced Callback: transmitted packets.
Protected Attributes inherited from ns3::Application
Ptr< Nodem_node
 The node that this application is installed on.
EventId m_startEvent
 The event that will fire at m_startTime to start the application.
Time m_startTime
 The simulation time that the application will start.
EventId m_stopEvent
 The event that will fire at m_stopTime to end the application.
Time m_stopTime
 The simulation time that the application will end.

Private Member Functions

virtual void CancelEvents ()=0
 Cancel all pending events.
void ConnectionFailed (Ptr< Socket > socket)
 Handle a Connection Failed event.
void ConnectionSucceeded (Ptr< Socket > socket)
 Handle a Connection Succeed event.
virtual void DoConnectionFailed (Ptr< Socket > socket)
 Application specific code for child subclasses upon a Connection Failed event.
virtual void DoConnectionSucceeded (Ptr< Socket > socket)
 Application specific code for child subclasses upon a Connection Succeed event.
virtual void DoStartApplication ()
 Application specific startup code for child subclasses.
virtual void DoStopApplication ()
 Application specific shutdown code for child subclasses.
void StartApplication () override
 Application specific startup code.
void StopApplication () override
 Application specific shutdown code.

Private Attributes

bool m_allowPacketSocket
 Allow use of packet socket.

Additional Inherited Members

Public Types inherited from ns3::Application
typedef void(* DelayAddressCallback) (const Time &delay, const Address &from)
 Common callback signature for packet delay and address.
typedef void(* StateTransitionCallback) (const std::string &oldState, const std::string &newState)
 Common signature used by callbacks to application's state transition trace source.

Detailed Description

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.

Config Paths

ns3::SourceApplication is accessible through the following paths with Config::Set and Config::Connect:

  • "/NodeList/[i]/ApplicationList/[i]/$ns3::SourceApplication"

Attributes

  • Local: The Address on which to bind the socket. If not set, it is generated automatically when needed by the application.
    • Set with class: ns3::AddressValue
    • Underlying type: Address
    • Initial value:
    • Flags: constructwriteread
    • Support level: SUPPORTED
  • Remote: The address of the destination, made of the remote IP address and the destination port
    • Set with class: ns3::AddressValue
    • Underlying type: Address
    • Initial value:
    • Flags: constructwriteread
    • Support level: SUPPORTED
  • Tos: The Type of Service used to send IPv4 packets. All 8 bits of the TOS byte are set (including ECN bits).
    • Set with class: ns3::UintegerValue
    • Underlying type: uint8_t 0:255
    • Initial value: 0
    • Flags: constructwriteread
    • Support level: SUPPORTED

Attributes defined in parent class ns3::Application

  • StartTime: Time at which the application will start
    • Set with class: ns3::TimeValue
    • Underlying type: Time -9.22337e+18ns:+9.22337e+18ns
    • Initial value: +0ns
    • Flags: constructwriteread
    • Support level: SUPPORTED
  • StopTime: Time at which the application will stop
    • Set with class: ns3::TimeValue
    • Underlying type: Time -9.22337e+18ns:+9.22337e+18ns
    • Initial value: +0ns
    • Flags: constructwriteread
    • Support level: SUPPORTED

TraceSources

Group: Applications
Size of this type is 264 bytes (on a 64-bit architecture).

Definition at line 38 of file source-application.h.

Member Typedef Documentation

◆ ConnectionEventCallback

typedef void(* ns3::SourceApplication::ConnectionEventCallback) (Ptr< Socket > socket, const Address &local, const Address &remote)
protected

TracedCallback signature for connection success/failure event.

Parameters
[in]socketThe socket for which connection succeeded/failed.
[in]localThe local address.
[in]remoteThe remote address.

Definition at line 91 of file source-application.h.

Constructor & Destructor Documentation

◆ SourceApplication()

ns3::SourceApplication::SourceApplication ( bool allowPacketSocket = true)
explicit

Constructor.

Parameters
allowPacketSocketflag whether the application should allow the use of packet sockets

Definition at line 66 of file source-application.cc.

References m_allowPacketSocket, and NS_LOG_FUNCTION.

Referenced by ns3::ThreeGppHttpClient::ThreeGppHttpClient(), ns3::UdpClient::UdpClient(), ns3::UdpEchoClient::UdpEchoClient(), ns3::UdpTraceClient::UdpTraceClient(), ns3::BulkSendApplication::GetTypeId(), ns3::OnOffApplication::GetTypeId(), ns3::ThreeGppHttpClient::GetTypeId(), ns3::UdpClient::GetTypeId(), ns3::UdpEchoClient::GetTypeId(), and ns3::UdpTraceClient::GetTypeId().

Here is the caller graph for this function:

◆ ~SourceApplication()

ns3::SourceApplication::~SourceApplication ( )
override

Definition at line 72 of file source-application.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ CancelEvents()

virtual void ns3::SourceApplication::CancelEvents ( )
privatepure virtual

Cancel all pending events.

Implemented in ns3::BulkSendApplication, ns3::OnOffApplication, ns3::ThreeGppHttpClient, ns3::UdpClient, ns3::UdpEchoClient, and ns3::UdpTraceClient.

Referenced by DoDispose(), StartApplication(), and StopApplication().

Here is the caller graph for this function:

◆ CloseSocket()

bool ns3::SourceApplication::CloseSocket ( )
protected

Close the socket.

Returns
true if the socket was closed, false if there was no socket to close

Definition at line 170 of file source-application.cc.

References m_connected, m_socket, and ns3::MakeNullCallback().

Referenced by ns3::ThreeGppHttpClient::DoDispose(), ns3::OnOffApplication::ScheduleNextTx(), and StopApplication().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConnectionFailed()

void ns3::SourceApplication::ConnectionFailed ( Ptr< Socket > socket)
private

Handle a Connection Failed event.

Parameters
socketthe not connected socket

Definition at line 194 of file source-application.cc.

References DoConnectionFailed(), m_connected, m_connectionFailure, m_local, m_peer, and NS_LOG_FUNCTION.

Referenced by StartApplication().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConnectionSucceeded()

void ns3::SourceApplication::ConnectionSucceeded ( Ptr< Socket > socket)
private

Handle a Connection Succeed event.

Parameters
socketthe connected socket

Definition at line 185 of file source-application.cc.

References DoConnectionSucceeded(), m_connected, m_connectionSuccess, m_local, m_peer, and NS_LOG_FUNCTION.

Referenced by StartApplication().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoConnectionFailed()

void ns3::SourceApplication::DoConnectionFailed ( Ptr< Socket > socket)
privatevirtual

Application specific code for child subclasses upon a Connection Failed event.

Parameters
socketthe not connected socket

Reimplemented in ns3::ThreeGppHttpClient.

Definition at line 221 of file source-application.cc.

References NS_LOG_FUNCTION.

Referenced by ConnectionFailed().

Here is the caller graph for this function:

◆ DoConnectionSucceeded()

void ns3::SourceApplication::DoConnectionSucceeded ( Ptr< Socket > socket)
privatevirtual

Application specific code for child subclasses upon a Connection Succeed event.

Parameters
socketthe connected socket

Reimplemented in ns3::BulkSendApplication, ns3::OnOffApplication, and ns3::ThreeGppHttpClient.

Definition at line 215 of file source-application.cc.

References NS_LOG_FUNCTION.

Referenced by ConnectionSucceeded().

Here is the caller graph for this function:

◆ DoDispose()

void ns3::SourceApplication::DoDispose ( )
overrideprotectedvirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Application.

Reimplemented in ns3::ThreeGppHttpClient.

Definition at line 78 of file source-application.cc.

References CancelEvents(), ns3::Application::DoDispose(), m_socket, and NS_LOG_FUNCTION.

Referenced by ns3::ThreeGppHttpClient::DoDispose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoStartApplication()

void ns3::SourceApplication::DoStartApplication ( )
privatevirtual

Application specific startup code for child subclasses.

Reimplemented in ns3::BulkSendApplication, ns3::OnOffApplication, ns3::ThreeGppHttpClient, ns3::UdpClient, ns3::UdpEchoClient, and ns3::UdpTraceClient.

Definition at line 203 of file source-application.cc.

References NS_LOG_FUNCTION.

Referenced by StartApplication().

Here is the caller graph for this function:

◆ DoStopApplication()

void ns3::SourceApplication::DoStopApplication ( )
privatevirtual

Application specific shutdown code for child subclasses.

Reimplemented in ns3::ThreeGppHttpClient.

Definition at line 209 of file source-application.cc.

References NS_LOG_FUNCTION.

Referenced by StopApplication().

Here is the caller graph for this function:

◆ GetRemote()

Address ns3::SourceApplication::GetRemote ( ) const

get the remote address

Returns
the remote address

Definition at line 97 of file source-application.cc.

References m_peer.

Referenced by GetTypeId().

Here is the caller graph for this function:

◆ GetSocket()

Ptr< Socket > ns3::SourceApplication::GetSocket ( ) const

Get the socket this application is attached to.

Returns
pointer to associated socket

Definition at line 103 of file source-application.cc.

References m_socket.

◆ GetTypeId()

TypeId ns3::SourceApplication::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 26 of file source-application.cc.

References ns3::Application::Application(), GetRemote(), m_connectionFailure, m_connectionSuccess, m_local, m_tos, m_txTrace, ns3::MakeAddressAccessor(), ns3::MakeAddressChecker(), ns3::MakeTraceSourceAccessor(), ns3::MakeUintegerAccessor(), ns3::MakeUintegerChecker(), ns3::TypeId::SetParent(), and SetRemote().

Here is the call graph for this function:

◆ SetRemote()

void ns3::SourceApplication::SetRemote ( const Address & addr)
virtual

set the remote address

Parameters
addrremote address

Reimplemented in ns3::ThreeGppHttpClient, ns3::UdpClient, ns3::UdpEchoClient, and ns3::UdpTraceClient.

Definition at line 87 of file source-application.cc.

References ns3::Address::IsInvalid(), m_peer, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartApplication()

void ns3::SourceApplication::StartApplication ( )
overrideprivatevirtual

Application specific startup code.

The StartApplication method is called at the start time specified by Start This method should be overridden by all or most application subclasses.

Reimplemented from ns3::Application.

Definition at line 109 of file source-application.cc.

References CancelEvents(), ConnectionFailed(), ConnectionSucceeded(), ns3::Socket::CreateSocket(), DoStartApplication(), ns3::Application::GetNode(), ns3::Inet6SocketAddress::IsMatchingType(), ns3::InetSocketAddress::IsMatchingType(), ns3::PacketSocketAddress::IsMatchingType(), m_allowPacketSocket, m_local, m_peer, m_protocolTid, m_socket, m_tos, ns3::MakeCallback(), NS_ABORT_MSG_IF, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Here is the call graph for this function:

◆ StopApplication()

void ns3::SourceApplication::StopApplication ( )
overrideprivatevirtual

Application specific shutdown code.

The StopApplication method is called at the stop time specified by Stop This method should be overridden by all or most application subclasses.

Reimplemented from ns3::Application.

Definition at line 161 of file source-application.cc.

References CancelEvents(), CloseSocket(), DoStopApplication(), and NS_LOG_FUNCTION.

Here is the call graph for this function:

Member Data Documentation

◆ m_allowPacketSocket

bool ns3::SourceApplication::m_allowPacketSocket
private

Allow use of packet socket.

Definition at line 154 of file source-application.h.

Referenced by SourceApplication(), and StartApplication().

◆ m_connected

◆ m_connectionFailure

TracedCallback<Ptr<Socket>, const Address&, const Address&> ns3::SourceApplication::m_connectionFailure
protected

Traced Callback: connection failure event.

Definition at line 99 of file source-application.h.

Referenced by ConnectionFailed(), and GetTypeId().

◆ m_connectionSuccess

TracedCallback<Ptr<Socket>, const Address&, const Address&> ns3::SourceApplication::m_connectionSuccess
protected

Traced Callback: connection success event.

Definition at line 96 of file source-application.h.

Referenced by ConnectionSucceeded(), and GetTypeId().

◆ m_local

Address ns3::SourceApplication::m_local
protected

Local address to bind to.

Definition at line 106 of file source-application.h.

Referenced by ConnectionFailed(), ConnectionSucceeded(), GetTypeId(), and StartApplication().

◆ m_peer

◆ m_protocolTid

◆ m_socket

◆ m_tos

uint8_t ns3::SourceApplication::m_tos
protected

The packets Type of Service.

Definition at line 107 of file source-application.h.

Referenced by GetTypeId(), and StartApplication().

◆ m_txTrace


The documentation for this class was generated from the following files: