A Discrete-Event Network Simulator
API
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ns3::OnOffApplication Class Reference

Generate traffic to a single destination according to an OnOff pattern. More...

#include "onoff-application.h"

+ Inheritance diagram for ns3::OnOffApplication:

Public Member Functions

 OnOffApplication ()
 
virtual ~OnOffApplication ()
 
int64_t AssignStreams (int64_t stream)
 Assign a fixed random variable stream number to the random variables used by this model. More...
 
Ptr< SocketGetSocket (void) const
 Return a pointer to associated socket. More...
 
void SetMaxBytes (uint64_t maxBytes)
 Set the total number of bytes to send. More...
 
- Public Member Functions inherited from ns3::Application
 Application ()
 
virtual ~Application ()
 
Ptr< NodeGetNode () const
 
void SetNode (Ptr< Node > node)
 
void SetStartTime (Time start)
 Specify application start time. More...
 
void SetStopTime (Time stop)
 Specify application stop time. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

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

Protected Member Functions

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

Private Member Functions

void CancelEvents ()
 Cancel all pending events. More...
 
void ConnectionFailed (Ptr< Socket > socket)
 Handle a Connection Failed event. More...
 
void ConnectionSucceeded (Ptr< Socket > socket)
 Handle a Connection Succeed event. More...
 
void ScheduleNextTx ()
 Schedule the next packet transmission. More...
 
void ScheduleStartEvent ()
 Schedule the next On period start. More...
 
void ScheduleStopEvent ()
 Schedule the next Off period start. More...
 
void SendPacket ()
 Send a packet. More...
 
virtual void StartApplication (void)
 Application specific startup code. More...
 
void StartSending ()
 Start an On period. More...
 
virtual void StopApplication (void)
 Application specific shutdown code. More...
 
void StopSending ()
 Start an Off period. More...
 

Private Attributes

DataRate m_cbrRate
 Rate that data is generated. More...
 
DataRate m_cbrRateFailSafe
 Rate that data is generated (check copy) More...
 
bool m_connected
 True if connected. More...
 
Time m_lastStartTime
 Time last packet sent. More...
 
uint64_t m_maxBytes
 Limit total number of bytes sent. More...
 
Ptr< RandomVariableStreamm_offTime
 rng for Off Time More...
 
Ptr< RandomVariableStreamm_onTime
 rng for On Time More...
 
Address m_peer
 Peer address. More...
 
uint32_t m_pktSize
 Size of packets. More...
 
uint32_t m_residualBits
 Number of generated, but not sent, bits. More...
 
EventId m_sendEvent
 Event id of pending "send packet" event. More...
 
Ptr< Socketm_socket
 Associated socket. More...
 
EventId m_startStopEvent
 Event id for next start or stop event. More...
 
TypeId m_tid
 Type of the socket used. More...
 
uint64_t m_totBytes
 Total bytes sent so far. More...
 
TracedCallback< Ptr< const Packet > > m_txTrace
 Traced Callback: transmitted packets. More...
 
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
 Callbacks for tracing the packet Tx events, includes source and destination addresses. More...
 

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. More...
 
typedef void(* StateTransitionCallback) (const std::string &oldState, const std::string &newState)
 Common signature used by callbacks to application's state transition trace source. More...
 
- Protected Attributes inherited from ns3::Application
Ptr< Nodem_node
 The node that this application is installed on. More...
 
EventId m_startEvent
 The event that will fire at m_startTime to start the application. More...
 
Time m_startTime
 The simulation time that the application will start. More...
 
EventId m_stopEvent
 The event that will fire at m_stopTime to end the application. More...
 
Time m_stopTime
 The simulation time that the application will end. More...
 

Detailed Description

Generate traffic to a single destination according to an OnOff pattern.


This traffic generator follows an On/Off pattern: after Application::StartApplication is called, "On" and "Off" states alternate. The duration of each of these states is determined with the onTime and the offTime random variables. During the "Off" state, no traffic is generated. During the "On" state, cbr traffic is generated. This cbr traffic is characterized by the specified "data rate" and "packet size".

Note: When an application is started, the first packet transmission occurs after a delay equal to (packet size/bit rate). Note also, when an application transitions into an off state in between packet transmissions, the remaining time until when the next transmission would have occurred is cached and is used when the application starts up again. Example: packet size = 1000 bits, bit rate = 500 bits/sec. If the application is started at time 3 seconds, the first packet transmission will be scheduled for time 5 seconds (3 + 1000/500) and subsequent transmissions at 2 second intervals. If the above application were instead stopped at time 4 seconds, and restarted at time 5.5 seconds, then the first packet would be sent at time 6.5 seconds, because when it was stopped at 4 seconds, there was only 1 second remaining until the originally scheduled transmission, and this time remaining information is cached and used to schedule the next transmission upon restarting.

If the underlying socket type supports broadcast, this application will automatically enable the SetAllowBroadcast(true) socket option.

Config Paths

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

Attributes

Attributes defined in parent class ns3::Application

TraceSources

Size of this type is 304 bytes (on a 64-bit architecture).

Definition at line 86 of file onoff-application.h.

Constructor & Destructor Documentation

◆ OnOffApplication()

ns3::OnOffApplication::OnOffApplication ( )

Definition at line 102 of file onoff-application.cc.

References NS_LOG_FUNCTION.

◆ ~OnOffApplication()

ns3::OnOffApplication::~OnOffApplication ( )
virtual

Definition at line 112 of file onoff-application.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AssignStreams()

int64_t ns3::OnOffApplication::AssignStreams ( int64_t  stream)

Assign a fixed random variable stream number to the random variables used by this model.

Parameters
streamfirst stream index to use
Returns
the number of stream indices assigned by this model

Definition at line 132 of file onoff-application.cc.

References m_offTime, m_onTime, NS_LOG_FUNCTION, and ns3::RandomVariableStream::SetStream().

◆ CancelEvents()

void ns3::OnOffApplication::CancelEvents ( )
private

◆ ConnectionFailed()

void ns3::OnOffApplication::ConnectionFailed ( Ptr< Socket socket)
private

Handle a Connection Failed event.

Parameters
socketthe not connected socket

Definition at line 323 of file onoff-application.cc.

References NS_LOG_FUNCTION.

Referenced by StartApplication().

◆ ConnectionSucceeded()

void ns3::OnOffApplication::ConnectionSucceeded ( Ptr< Socket socket)
private

Handle a Connection Succeed event.

Parameters
socketthe connected socket

Definition at line 317 of file onoff-application.cc.

References m_connected, and NS_LOG_FUNCTION.

Referenced by StartApplication().

◆ DoDispose()

void ns3::OnOffApplication::DoDispose ( void  )
protectedvirtual

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.

Definition at line 141 of file onoff-application.cc.

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

◆ GetSocket()

Ptr< Socket > ns3::OnOffApplication::GetSocket ( void  ) const

Return a pointer to associated socket.

Returns
pointer to associated socket

Definition at line 125 of file onoff-application.cc.

References m_socket, and NS_LOG_FUNCTION.

◆ GetTypeId()

TypeId ns3::OnOffApplication::GetTypeId ( void  )
static

◆ ScheduleNextTx()

void ns3::OnOffApplication::ScheduleNextTx ( )
private

◆ ScheduleStartEvent()

void ns3::OnOffApplication::ScheduleStartEvent ( )
private

◆ ScheduleStopEvent()

void ns3::OnOffApplication::ScheduleStopEvent ( )
private

◆ SendPacket()

void ns3::OnOffApplication::SendPacket ( void  )
private

◆ SetMaxBytes()

void ns3::OnOffApplication::SetMaxBytes ( uint64_t  maxBytes)

Set the total number of bytes to send.

Once these bytes are sent, no packet is sent again, even in on state. The value zero means that there is no limit.

Parameters
maxBytesthe total number of bytes to send

Definition at line 118 of file onoff-application.cc.

References m_maxBytes, and NS_LOG_FUNCTION.

◆ StartApplication()

void ns3::OnOffApplication::StartApplication ( void  )
privatevirtual

◆ StartSending()

void ns3::OnOffApplication::StartSending ( )
private

Start an On period.

Definition at line 224 of file onoff-application.cc.

References m_lastStartTime, ns3::Simulator::Now(), NS_LOG_FUNCTION, ScheduleNextTx(), and ScheduleStopEvent().

Referenced by ScheduleStartEvent().

◆ StopApplication()

void ns3::OnOffApplication::StopApplication ( void  )
privatevirtual

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 192 of file onoff-application.cc.

References CancelEvents(), ns3::Socket::Close(), m_socket, NS_LOG_FUNCTION, and NS_LOG_WARN.

Referenced by ScheduleNextTx().

◆ StopSending()

void ns3::OnOffApplication::StopSending ( )
private

Start an Off period.

Definition at line 232 of file onoff-application.cc.

References CancelEvents(), NS_LOG_FUNCTION, and ScheduleStartEvent().

Referenced by ScheduleStopEvent().

Member Data Documentation

◆ m_cbrRate

DataRate ns3::OnOffApplication::m_cbrRate
private

Rate that data is generated.

Definition at line 156 of file onoff-application.h.

Referenced by CancelEvents(), GetTypeId(), ScheduleNextTx(), and StartApplication().

◆ m_cbrRateFailSafe

DataRate ns3::OnOffApplication::m_cbrRateFailSafe
private

Rate that data is generated (check copy)

Definition at line 157 of file onoff-application.h.

Referenced by CancelEvents(), and StartApplication().

◆ m_connected

bool ns3::OnOffApplication::m_connected
private

True if connected.

Definition at line 153 of file onoff-application.h.

Referenced by ConnectionSucceeded().

◆ m_lastStartTime

Time ns3::OnOffApplication::m_lastStartTime
private

Time last packet sent.

Definition at line 160 of file onoff-application.h.

Referenced by CancelEvents(), SendPacket(), and StartSending().

◆ m_maxBytes

uint64_t ns3::OnOffApplication::m_maxBytes
private

Limit total number of bytes sent.

Definition at line 161 of file onoff-application.h.

Referenced by GetTypeId(), ScheduleNextTx(), and SetMaxBytes().

◆ m_offTime

Ptr<RandomVariableStream> ns3::OnOffApplication::m_offTime
private

rng for Off Time

Definition at line 155 of file onoff-application.h.

Referenced by AssignStreams(), GetTypeId(), and ScheduleStartEvent().

◆ m_onTime

Ptr<RandomVariableStream> ns3::OnOffApplication::m_onTime
private

rng for On Time

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

Referenced by AssignStreams(), GetTypeId(), and ScheduleStopEvent().

◆ m_peer

Address ns3::OnOffApplication::m_peer
private

Peer address.

Definition at line 152 of file onoff-application.h.

Referenced by GetTypeId(), SendPacket(), and StartApplication().

◆ m_pktSize

uint32_t ns3::OnOffApplication::m_pktSize
private

Size of packets.

Definition at line 158 of file onoff-application.h.

Referenced by GetTypeId(), ScheduleNextTx(), and SendPacket().

◆ m_residualBits

uint32_t ns3::OnOffApplication::m_residualBits
private

Number of generated, but not sent, bits.

Definition at line 159 of file onoff-application.h.

Referenced by CancelEvents(), ScheduleNextTx(), and SendPacket().

◆ m_sendEvent

EventId ns3::OnOffApplication::m_sendEvent
private

Event id of pending "send packet" event.

Definition at line 164 of file onoff-application.h.

Referenced by CancelEvents(), ScheduleNextTx(), and SendPacket().

◆ m_socket

Ptr<Socket> ns3::OnOffApplication::m_socket
private

Associated socket.

Definition at line 151 of file onoff-application.h.

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

◆ m_startStopEvent

EventId ns3::OnOffApplication::m_startStopEvent
private

Event id for next start or stop event.

Definition at line 163 of file onoff-application.h.

Referenced by CancelEvents(), ScheduleStartEvent(), and ScheduleStopEvent().

◆ m_tid

TypeId ns3::OnOffApplication::m_tid
private

Type of the socket used.

Definition at line 165 of file onoff-application.h.

Referenced by GetTypeId(), and StartApplication().

◆ m_totBytes

uint64_t ns3::OnOffApplication::m_totBytes
private

Total bytes sent so far.

Definition at line 162 of file onoff-application.h.

Referenced by ScheduleNextTx(), and SendPacket().

◆ m_txTrace

TracedCallback<Ptr<const Packet> > ns3::OnOffApplication::m_txTrace
private

Traced Callback: transmitted packets.

Definition at line 168 of file onoff-application.h.

Referenced by GetTypeId(), and SendPacket().

◆ m_txTraceWithAddresses

TracedCallback<Ptr<const Packet>, const Address &, const Address &> ns3::OnOffApplication::m_txTraceWithAddresses
private

Callbacks for tracing the packet Tx events, includes source and destination addresses.

Definition at line 171 of file onoff-application.h.

Referenced by GetTypeId(), and SendPacket().


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