A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tgax-voip-traffic.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#ifndef TGAX_VOIP_TRAFFIC_H
10#define TGAX_VOIP_TRAFFIC_H
11
12#include "source-application.h"
13
14#include "ns3/event-id.h"
15#include "ns3/ptr.h"
16#include "ns3/traced-callback.h"
17
18#include <map>
19
20namespace ns3
21{
22
26
27/**
28 * @ingroup applications
29 * @brief Generate VoIP traffic.
30 *
31 * This voip traffic generator follows requirements from IEEE 802.11-14/0571r12 - 11ax Evaluation
32 * Methodology (see applications documentation for full citation).
33 *
34 * The VoIP traffic alternates between periods of active talking and silence,
35 * with given probabilities to transition from one state to another.
36 * These state updates are assumed to be done at the speech encoder frame rate.
37 *
38 * Fixed-size VoIP packets are generated at every encoder frame interval,
39 * plus a random network packet arrival delay jitter (if BoundDelayJitter is non-zero).
40 * The size of these packets also depend on the current state.
41 *
42 * The VoIP model from the reference relies on UDP with compressed protocol headers.
43 * Since compressed protocol headers are not supported in the simulator, a packet socket
44 * is used instead, allowing user to tune payload sizes by adding up the size of the compressed
45 * headers.
46 *
47 * This model can also be used with usual UDP or TCP sockets. For the later, user should be warned
48 * that the model does not provide any mechanism when TX buffer is full.
49 */
51{
52 public:
53 /**
54 * @brief Get the type ID.
55 * @return the object TypeId
56 */
57 static TypeId GetTypeId();
58
60 ~TgaxVoipTraffic() override;
61
62 /**
63 * Voice activity states
64 */
65 enum class VoiceActivityState : uint8_t
66 {
67 INACTIVE_SILENCE = 0, //< Inactive/silence state
68 ACTIVE_TALKING = 1, //< Active/talking state
69 };
70
71 int64_t AssignStreams(int64_t stream) override;
72
73 protected:
74 void DoInitialize() override;
75
76 private:
77 void DoStartApplication() override;
78 void DoConnectionSucceeded(Ptr<Socket> socket) override;
79 void CancelEvents() override;
80
81 /**
82 * Set the mean of the exponential distribution used to calculate durations of active/talking
83 * state
84 * @param mean the mean value
85 */
87
88 /**
89 * Set the mean of the exponential distribution used to calculate durations of inactive/silent
90 * state
91 * @param mean the mean value
92 */
94
95 /**
96 * Update voice activity state
97 */
98 void UpdateState();
99
100 /**
101 * Schedule the next state update
102 */
103 void ScheduleNext();
104
105 /**
106 * Transmit one VoIP packet
107 * @param eventId the event ID
108 * @param packet the packet to transmit
109 * @param jitter the delay jitter applied to that packet
110 */
111 void SendPacket(uint64_t eventId, Ptr<Packet> packet, Time jitter);
112
113 /**
114 * Get the duration to encode a frame based on the current state
115 *
116 * @return the duration to encode a frame
117 */
119
120 /**
121 * Get the interval between two state updates
122 *
123 * @return the interval between two state updates
124 */
126
127 uint32_t m_activePacketSize; //!< Size in bytes for payload of active packets
128 uint32_t m_silencePacketSize; //!< Size in bytes for payload of silence packets
129 Time m_voiceInterval; //!< Interval between generation of voice packets
130 Time m_silenceInterval; //!< Interval between generation of silence packets
131 double m_activeToInactive; //!< Probability to transition from active/talking state to
132 //!< inactive/silence state
133 double m_inactiveToActive; //!< Probability to transition from inactive/silence state to
134 //!< active/talking state
135 Time m_delayJitterScale; //!< Scale of laplacian distribution used to calculate delay jitter
136 Time m_delayJitterBound; //!< Bound of laplacian distribution used to calculate delay jitter
137
139 m_inactiveExponential; //!< Exponential random variable to generate inactive/silent state
140 //!< durations
141 Ptr<ExponentialRandomVariable> m_activeExponential; //!< Exponential random variable to generate
142 //!< active/talking state durations
143 Ptr<UniformRandomVariable> m_inactiveUniform; //!< Uniform random variable to generate state
144 //!< transitions from inactive state
145 Ptr<UniformRandomVariable> m_activeUniform; //!< Uniform random variable to generate state
146 //!< transitions from active state
148 m_delayJitterLaplacian; //!< Laplacian random variable to generate delay jitter
149
151 VoiceActivityState::INACTIVE_SILENCE}; //!< Hold the current voice activity state
152 bool m_pendingStateTransition{false}; //!< Flag whether a state transition should once duration
153 //!< of current state has elapsed
154 Time m_remainingStateDuration; //!< The remaining duration in the current state
155 Time m_remainingEncodingDuration; //!< The remaining duration to encode the current frame
156
157 EventId m_stateUpdateEvent; //!< Event ID of pending state update event scheduling
158
159 std::map<uint64_t, EventId> m_txPacketEvents; //!< Event IDs of pending TX events
160 uint64_t m_nextEventId{0}; //!< The next event ID
161
162 /**
163 * TracedCallback signature for packet and jitter.
164 *
165 * @param [in] packet The packet.
166 * @param [in] jitter The networking jitter.
167 */
168 typedef void (*TxTracedCallback)(Ptr<const Packet> packet, Time jitter);
169
170 /**
171 * TracedCallback signature for state change.
172 *
173 * @param [in] state The new state.
174 * @param [in] duration The duration of the state.
175 */
176 typedef void (*StateUpdatedCallback)(VoiceActivityState state, Time duration);
177
178 /// Traced Callback: transmitted packets and their jitters.
180
181 /// Traced Callback: voice activity state updated.
183};
184
185/**
186 * Serialize voice activity state to ostream in a human-readable form.
187 *
188 * @param os std::ostream
189 * @param state the voice activity state
190 * @return std::ostream
191 */
192std::ostream& operator<<(std::ostream& os, TgaxVoipTraffic::VoiceActivityState state);
193
194} // namespace ns3
195
196#endif /* TGAX_VOIP_TRAFFIC_H */
An identifier for simulation events.
Definition event-id.h:45
The exponential distribution Random Number Generator (RNG).
The laplacian distribution Random Number Generator (RNG).
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
SourceApplication(bool allowPacketSocket=true)
Constructor.
double m_inactiveToActive
Probability to transition from inactive/silence state to active/talking state.
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.
void(* TxTracedCallback)(Ptr< const Packet > packet, Time jitter)
TracedCallback signature for packet and jitter.
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.
void(* StateUpdatedCallback)(VoiceActivityState state, Time duration)
TracedCallback signature for state change.
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.
Definition nstime.h:95
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:50
The uniform distribution Random Number Generator (RNG).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148