6#include "traffic-generator-ngmn-voip.h"
8#include "ns3/address.h"
9#include "ns3/boolean.h"
10#include "ns3/double.h"
13#include "ns3/nstime.h"
14#include "ns3/packet.h"
15#include "ns3/simulator.h"
16#include "ns3/socket-factory.h"
17#include "ns3/socket.h"
18#include "ns3/tcp-socket-factory.h"
19#include "ns3/trace-source-accessor.h"
20#include "ns3/udp-socket-factory.h"
21#include "ns3/uinteger.h"
26NS_LOG_COMPONENT_DEFINE(
"TrafficGeneratorNgmnVoip");
27NS_OBJECT_ENSURE_REGISTERED(TrafficGeneratorNgmnVoip);
33 TypeId(
"ns3::TrafficGeneratorNgmnVoip")
35 .SetGroupName(
"Applications")
37 .AddAttribute(
"EncoderFrameLength",
38 "The encoder frame length in milliseconds. It is used for "
39 "the calculation of transition probabilities based on configured "
40 "voice activity factor (VAF).",
42 MakeUintegerAccessor(&TrafficGeneratorNgmnVoip::m_encoderFrameLength),
43 MakeUintegerChecker<uint32_t>())
44 .AddAttribute(
"MeanTalkSpurtDuration",
45 "Mean talk spurt duration in the "
46 "number of milliseconds.",
48 MakeUintegerAccessor(&TrafficGeneratorNgmnVoip::m_meanTalkSpurtDuration),
49 MakeUintegerChecker<uint32_t>())
50 .AddAttribute(
"VoiceActivityFactor",
51 "Voice activity factor, determines "
52 "the ratio of active versus inactive state. Expressed as the ratio.",
54 MakeDoubleAccessor(&TrafficGeneratorNgmnVoip::m_voiceActivityFactor),
55 MakeDoubleChecker<double>(0.0, 0.99))
56 .AddAttribute(
"VoicePayload",
57 "The voice packet payload in number of bytes.",
59 MakeUintegerAccessor(&TrafficGeneratorNgmnVoip::m_activePayload),
60 MakeUintegerChecker<uint32_t>())
61 .AddAttribute(
"SIDPeriodicity",
62 "The periodicity of SIDs is 160 ms during silence",
64 MakeUintegerAccessor(&TrafficGeneratorNgmnVoip::m_SIDPeriodicity),
65 MakeUintegerChecker<uint32_t>())
66 .AddAttribute(
"SIDPayload",
67 "The payload of SIDs.",
69 MakeUintegerAccessor(&TrafficGeneratorNgmnVoip::m_SIDPayload),
70 MakeUintegerChecker<uint32_t>())
71 .AddAttribute(
"Remote",
72 "The address of the destination",
76 .AddAttribute(
"Protocol",
77 "The type of protocol to use.",
78 TypeIdValue(TcpSocketFactory::GetTypeId()),
82 "A new packet is created and is sent",
83 MakeTraceSourceAccessor(&TrafficGenerator::m_txTrace),
84 "ns3::TrafficGenerator::TxTracedCallback");
88TrafficGeneratorNgmnVoip::TrafficGeneratorNgmnVoip()
91 NS_LOG_FUNCTION(
this);
94TrafficGeneratorNgmnVoip::~TrafficGeneratorNgmnVoip()
96 NS_LOG_FUNCTION(
this);
100TrafficGeneratorNgmnVoip::StartApplication()
102 NS_LOG_FUNCTION(
this);
106 m_a = ((double)m_encoderFrameLength / (
double)m_meanTalkSpurtDuration);
108 m_c = (m_a * m_voiceActivityFactor) / (1 - m_voiceActivityFactor);
115TrafficGeneratorNgmnVoip::StopApplication()
117 NS_LOG_FUNCTION(
this);
118 TrafficGenerator::StopApplication();
119 NS_ASSERT(m_updateState.IsPending());
120 m_updateState.Cancel();
124TrafficGeneratorNgmnVoip::UpdateState()
126 NS_LOG_FUNCTION(
this);
128 if (m_state == INACTIVE_STATE)
130 double randomValue = m_fromInactiveToActive->GetValue();
134 if (randomValue < m_c)
137 m_state = ACTIVE_STATE;
140 else if (m_state == ACTIVE_STATE)
142 double randomValue = m_fromActiveToInactive->GetValue();
145 if (randomValue < m_a)
148 m_state = INACTIVE_STATE;
153 m_updateState = Simulator::Schedule(MilliSeconds(m_encoderFrameLength),
154 &TrafficGeneratorNgmnVoip::UpdateState,
159TrafficGeneratorNgmnVoip::GenerateNextPacketBurstSize()
161 NS_LOG_FUNCTION(
this);
162 SetPacketBurstSizeInBytes(UINT32_MAX);
166TrafficGeneratorNgmnVoip::GetNextPacketSize()
const
168 NS_LOG_FUNCTION(
this);
169 if (m_state == ACTIVE_STATE)
171 return m_activePayload;
180TrafficGeneratorNgmnVoip::GetNextPacketTime()
const
182 NS_LOG_FUNCTION(
this);
183 if (m_state == INACTIVE_STATE)
185 return MilliSeconds(m_SIDPeriodicity);
189 return Seconds((
double)(m_activePayload * 8) / 12200);
194TrafficGeneratorNgmnVoip::DoDispose()
196 NS_LOG_FUNCTION(
this);
197 m_fromActiveToInactive =
nullptr;
198 m_fromInactiveToActive =
nullptr;
200 TrafficGenerator::DoDispose();
204TrafficGeneratorNgmnVoip::DoInitialize()
206 NS_LOG_FUNCTION(
this);
207 m_fromActiveToInactive = CreateObject<UniformRandomVariable>();
208 m_fromActiveToInactive->SetAttribute(
"Min", DoubleValue(0));
209 m_fromActiveToInactive->SetAttribute(
"Max", DoubleValue(1));
210 m_fromInactiveToActive = CreateObject<UniformRandomVariable>();
211 m_fromInactiveToActive->SetAttribute(
"Min", DoubleValue(0));
212 m_fromInactiveToActive->SetAttribute(
"Max", DoubleValue(1));
214 TrafficGenerator::DoInitialize();
220 m_fromActiveToInactive->SetStream(stream);
221 m_fromInactiveToActive->SetStream(stream + 1);
void SetRemote(Address remote)
Sets the remote address.
bool SendPacketBurst()
Send another packet burst, which can be e.g., a file, or a video frame.
void SetProtocol(TypeId protocol)
Sets the protocol.
int64_t AssignStreams(int64_t stream) override
static TypeId GetTypeId()
Get the type ID.