11#include "ns3/double.h"
12#include "ns3/inet-socket-address.h"
13#include "ns3/inet6-socket-address.h"
16#include "ns3/nstime.h"
17#include "ns3/packet-socket-address.h"
18#include "ns3/packet.h"
19#include "ns3/random-variable-stream.h"
20#include "ns3/simulator.h"
21#include "ns3/socket-factory.h"
22#include "ns3/socket.h"
23#include "ns3/uinteger.h"
36 TypeId(
"ns3::TgaxVoipTraffic")
38 .SetGroupName(
"Applications")
42 "The type of protocol to use. This should be a subclass of ns3::SocketFactory",
48 "ActivePacketPayloadSize",
49 "Size in bytes for payload of packets generated during periods of active talking.",
54 "SilencePacketPayloadSize",
55 "Size in bytes for payload of packets generated during periods of silence.",
59 .AddAttribute(
"MeanActiveStateDuration",
60 "Mean duration of active/talking state.",
64 .AddAttribute(
"MeanInactiveStateDuration",
65 "Mean duration of inactive/silence state.",
69 .AddAttribute(
"VoiceEncoderInterval",
70 "Interval between generation of voice packets.",
74 .AddAttribute(
"SilenceEncoderInterval",
75 "Interval between generation of silence packets. "
76 "This implementation requires the value of this attribute to be a "
77 "multiple of VoiceEncoderInterval",
82 "VoiceToSilenceProbability",
83 "The probability to transition from active talking state to silence state.",
88 "SilenceToVoiceProbability",
89 "The probability to transition from silence state to active talking state.",
93 .AddAttribute(
"ScaleDelayJitter",
94 "Scale of laplacian distribution used to calculate delay jitter for "
99 .AddAttribute(
"BoundDelayJitter",
100 "Bound of laplacian distribution used to calculate delay jitter for "
101 "generated packets. For no jitter, set this attribute to zero.",
107 "A VoIP packet is sent, this trace also reports the jitter applied to the packet",
109 "ns3::TgaxVoipTraffic::TxTracedCallback")
110 .AddTraceSource(
"StateUpdate",
111 "Voice activity state updated",
113 "ns3::TgaxVoipTraffic::StateUpdatedCallback");
136 auto currentStream = stream;
142 return (currentStream - stream);
190 event.second.Cancel();
209 "Silence encoder frame duration should be a multiple of voice encoder frame duration");
225 const auto size = packet->GetSize();
240 << size <<
" bytes to "
247 << size <<
" bytes to "
297 <<
" to " << newState <<
" for "
354 os <<
"Active talking";
This class can be used to hold variables of floating point type such as 'double' or 'float'.
The exponential distribution Random Number Generator (RNG).
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
The laplacian distribution Random Number Generator (RNG).
virtual void DoInitialize()
Initialize() implementation.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
TypeId m_protocolTid
Protocol TypeId value.
SourceApplication(bool allowPacketSocket=true)
Constructor.
Ptr< Socket > m_socket
Socket.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
bool m_connected
flag whether socket is connected
Address m_peer
Peer address.
double m_inactiveToActive
Probability to transition from inactive/silence state to active/talking state.
~TgaxVoipTraffic() override
uint32_t m_activePacketSize
Size in bytes for payload of active packets.
VoiceActivityState m_currentState
Hold the current voice activity state.
Ptr< UniformRandomVariable > m_inactiveUniform
Uniform random variable to generate state transitions from inactive state.
Time m_silenceInterval
Interval between generation of silence packets.
void CancelEvents() override
Cancel all pending events.
TracedCallback< Ptr< const Packet >, Time > m_txJitterTrace
Traced Callback: transmitted packets and their jitters.
Time m_remainingEncodingDuration
The remaining duration to encode the current frame.
TracedCallback< VoiceActivityState, Time > m_stateUpdate
Traced Callback: voice activity state updated.
bool m_pendingStateTransition
Flag whether a state transition should once duration of current state has elapsed.
void ScheduleNext()
Schedule the next state update.
void SendPacket(uint64_t eventId, Ptr< Packet > packet, Time jitter)
Transmit one VoIP packet.
std::map< uint64_t, EventId > m_txPacketEvents
Event IDs of pending TX events.
VoiceActivityState
Voice activity states.
void SetInactiveExponentialMean(Time mean)
Set the mean of the exponential distribution used to calculate durations of inactive/silent state.
static TypeId GetTypeId()
Get the type ID.
Time m_remainingStateDuration
The remaining duration in the current state.
void SetActiveExponentialMean(Time mean)
Set the mean of the exponential distribution used to calculate durations of active/talking state.
Time GetStateUpdateInterval() const
Get the interval between two state updates.
Time m_voiceInterval
Interval between generation of voice packets.
Time GetEncoderFrameDuration() const
Get the duration to encode a frame based on the current state.
void DoConnectionSucceeded(Ptr< Socket > socket) override
Application specific code for child subclasses upon a Connection Succeed event.
Ptr< ExponentialRandomVariable > m_inactiveExponential
Exponential random variable to generate inactive/silent state durations.
uint32_t m_silencePacketSize
Size in bytes for payload of silence packets.
Ptr< ExponentialRandomVariable > m_activeExponential
Exponential random variable to generate active/talking state durations.
Ptr< UniformRandomVariable > m_activeUniform
Uniform random variable to generate state transitions from active state.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this Application object.
Ptr< LaplacianRandomVariable > m_delayJitterLaplacian
Laplacian random variable to generate delay jitter.
Time m_delayJitterBound
Bound of laplacian distribution used to calculate delay jitter.
uint64_t m_nextEventId
The next event ID.
void DoInitialize() override
Initialize() implementation.
double m_activeToInactive
Probability to transition from active/talking state to inactive/silence state.
void DoStartApplication() override
Application specific startup code for child subclasses.
void UpdateState()
Update voice activity state.
EventId m_stateUpdateEvent
Event ID of pending state update event scheduling.
Time m_delayJitterScale
Scale of laplacian distribution used to calculate delay jitter.
Simulation virtual time values and global simulation resolution.
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
@ ATTR_GET
The attribute can be read.
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AttributeValue implementation for TypeId.
Hold an unsigned integer type.
High precision numerical type, implementing Q64.64 fixed precision.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)