5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator-ngmn-gaming.cc
1// Copyright (c) 2022 CTTC
2// Copyright (c) 2023 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3//
4// SPDX-License-Identifier: GPL-2.0-only
5
6#include "traffic-generator-ngmn-gaming.h"
7
8#include "ns3/address.h"
9#include "ns3/boolean.h"
10#include "ns3/double.h"
11#include "ns3/log.h"
12#include "ns3/node.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"
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("TrafficGeneratorNgmnGaming");
27NS_OBJECT_ENSURE_REGISTERED(TrafficGeneratorNgmnGaming);
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::TrafficGeneratorNgmnGaming")
34 .SetParent<TrafficGenerator>()
35 .SetGroupName("Applications")
36 .AddConstructor<TrafficGeneratorNgmnGaming>()
37 .AddAttribute("IsDownlink",
38 "If set to true the traffic will be generated according to "
39 "parameters and model for gaming downlink, otherwise, if false,"
40 "it will be generated according to parameters and model for uplink.",
41 BooleanValue(true),
42 MakeBooleanAccessor(&TrafficGeneratorNgmnGaming::m_isDownlink),
43 MakeBooleanChecker())
44 .AddAttribute("aParamPacketSizeUl",
45 "The a parameter in number of bytes for the packet size "
46 "calculation in uplink according to the NGMN white paper Annex A. The "
47 "packet size is "
48 "determined using Largest Extreme Value Distribution "
49 "(also known as Fisher-Tippett distribution) random variable.",
50 UintegerValue(45),
51 MakeUintegerAccessor(&TrafficGeneratorNgmnGaming::m_aParamPacketSizeUl),
52 MakeUintegerChecker<uint32_t>())
53 .AddAttribute("bParamPacketSizeUl",
54 "The b parameter in number of bytes for the packet size "
55 " calculation in uplink according to the NGMN white paper Annex A. The "
56 "packet size is "
57 "determined using Largest Extreme Value Distribution "
58 "(also known as Fisher-Tippett distribution) random variable.",
59 DoubleValue(5.7),
60 MakeDoubleAccessor(&TrafficGeneratorNgmnGaming::m_bParamPacketSizeUl),
61 MakeDoubleChecker<double>())
62 .AddAttribute("PacketArrivalUl",
63 "Packet arrival time in milliseconds for uplink. "
64 "Packet arrival in uplink is deterministic",
65 UintegerValue(40),
66 MakeUintegerAccessor(&TrafficGeneratorNgmnGaming::m_packetArrivalUl),
67 MakeUintegerChecker<uint32_t>())
68 .AddAttribute(
69 "aParamPacketSizeDl",
70 "The a parameter in number of bytes for the packet size "
71 "calculation in downlink according to NGMN white paper Annex A. The packet size is "
72 "determined using the Largest Extreme Value Distribution "
73 "(also known as Fisher-Tippett distribution) random variable.",
74 UintegerValue(120),
75 MakeUintegerAccessor(&TrafficGeneratorNgmnGaming::m_aParamPacketSizeDl),
76 MakeUintegerChecker<uint32_t>())
77 .AddAttribute(
78 "bParamPacketSizeDl",
79 "The b parameter in number of bytes for the packet size "
80 "calculation in downlink according to NGMN white paper Annex A. The packet size is "
81 "determined using the Largest Extreme Value Distribution "
82 "(also known as Fisher-Tippett distribution) random variable.",
83 DoubleValue(36),
84 MakeDoubleAccessor(&TrafficGeneratorNgmnGaming::m_bParamPacketSizeDl),
85 MakeDoubleChecker<double>())
86 .AddAttribute(
87 "aParamPacketArrivalDl",
88 "The a parameter for the packet arrival "
89 "calculation in downlink according to NGMN white paper Annex A. The packet arrival "
90 "in downlink is determined using Largest Extreme Value Distribution "
91 "(also known as Fisher-Tippett distribution) random variable.",
92 DoubleValue(55),
93 MakeDoubleAccessor(&TrafficGeneratorNgmnGaming::m_aParamPacketArrivalDl),
94 MakeDoubleChecker<double>())
95 .AddAttribute(
96 "bParamPacketArrivalDl",
97 "The b parameter for the packet arrival "
98 "calculation in downlink according to NGMN white paper Annex A. The packet arrival"
99 "in downlink is determined using Largest Extreme Value Distribution "
100 "(also known as Fisher-Tippett distribution) random variable.",
101 DoubleValue(5.7),
102 MakeDoubleAccessor(&TrafficGeneratorNgmnGaming::m_bParamPacketArrivalDl),
103 MakeDoubleChecker<double>())
104 .AddAttribute(
105 "InitialPacketArrivalMin",
106 "The minimum value in milliseconds for the "
107 "initial packet arrival calculation according to NGMN white paper Annex A. "
108 "The packet arrival in both, downlink and uplink, is determined using the "
109 "Uniform Distribution.",
110 UintegerValue(0),
111 MakeUintegerAccessor(&TrafficGeneratorNgmnGaming::m_initialPacketArrivalMin),
112 MakeUintegerChecker<uint32_t>())
113 .AddAttribute(
114 "InitialPacketArrivalMax",
115 "The maximum value in milliseconds for the "
116 "initial packet arrival calculation according to NGMN white paper Annex A. "
117 "The packet arrival in both, downlink and uplink, is determined using the "
118 "Uniform Distribution.",
119 UintegerValue(40),
120 MakeUintegerAccessor(&TrafficGeneratorNgmnGaming::m_initialPacketArrivalMax),
121 MakeUintegerChecker<uint32_t>())
122 .AddAttribute("Remote",
123 "The address of the destination",
124 AddressValue(),
125 MakeAddressAccessor(&TrafficGenerator::SetRemote),
126 MakeAddressChecker())
127 .AddAttribute("Protocol",
128 "The type of protocol to use.",
129 TypeIdValue(TcpSocketFactory::GetTypeId()),
130 MakeTypeIdAccessor(&TrafficGenerator::SetProtocol),
131 MakeTypeIdChecker())
132 .AddTraceSource("Tx",
133 "A new packet is created and is sent",
134 MakeTraceSourceAccessor(&TrafficGenerator::m_txTrace),
135 "ns3::TrafficGenerator::TxTracedCallback");
136 return tid;
137}
138
139TrafficGeneratorNgmnGaming::TrafficGeneratorNgmnGaming()
141{
142 NS_LOG_FUNCTION(this);
143}
144
145TrafficGeneratorNgmnGaming::~TrafficGeneratorNgmnGaming()
146{
147 NS_LOG_FUNCTION(this);
148}
149
150void
151TrafficGeneratorNgmnGaming::StartApplication()
152{
153 NS_LOG_FUNCTION(this);
154 Simulator::Schedule(GetInitialPacketArrivalTime(), &TrafficGenerator::SendPacketBurst, this);
155}
156
157void
158TrafficGeneratorNgmnGaming::PacketBurstSent()
159{
160 NS_LOG_FUNCTION(this);
161 NS_ABORT_MSG(
162 "This function should not be called for the gaming traffic"); // in NGMN description of the
163 // gaming traffic there is no
164 // notion of frames or packet
165 // bursts, just packets
166}
167
168void
169TrafficGeneratorNgmnGaming::GenerateNextPacketBurstSize()
170{
171 NS_LOG_FUNCTION(this);
172 SetPacketBurstSizeInPackets(1);
173}
174
175Time
176TrafficGeneratorNgmnGaming::GetInitialPacketArrivalTime() const
177{
178 return MilliSeconds(ceil(m_initPacketArrivalVariable->GetValue()));
179}
180
181uint32_t
182TrafficGeneratorNgmnGaming::GetNextPacketSize() const
183{
184 NS_LOG_FUNCTION(this);
185 // here we follow Annex A of NGMN white paper for gaming UL and DL
186 // the packet size should be generated according to the largest Extreme Value Distribution
187 // (also known as Fisher-Tippett distribution)
188 // According to NGMN document, the values for this distribution can be
189 // generated by the following procedure: y = a - b * ln (-ln (y)), where y is
190 // drawn from a uniform random variable with range [0, 1]
191 double y = m_packetSizeRandomVariable->GetValue();
192 double x = 0;
193 uint32_t a = 0;
194 double b = 0.0;
195
196 if (m_isDownlink)
197 {
198 a = m_aParamPacketSizeDl;
199 b = m_bParamPacketSizeDl;
200 }
201 else
202 {
203 a = m_aParamPacketSizeUl;
204 b = m_bParamPacketSizeUl;
205 }
206 x = a - b * log(-log(y));
207 // Because packet size has to be integer number of bytes, the largest integer less than
208 // or equal to x is used as the actual packet size
209 return floor(x);
210}
211
212Time
213TrafficGeneratorNgmnGaming::GetNextPacketTime() const
214{
215 NS_LOG_FUNCTION(this);
216 // here we follow the Annex A of the NGMN white paper for gaming UL and DL
217 // The packet arrival for the downlink should be generated according to the
218 // largest Extreme Value Distribution (also known as Fisher-Tippett distribution)
219 // According to the NGMN document, the values for this distribution can be
220 // generated by the following procedure: y = a - b * ln (-ln (y)), where y is
221 // drawn from a uniform random variable with range [0, 1]
222 // The packet arrival for the uplink is deterministic and can be configured.
223 Time x = MilliSeconds(0);
224 if (m_isDownlink)
225 {
226 double y = m_packetArrivalVariable->GetValue();
227 double a = m_aParamPacketArrivalDl;
228 double b = m_bParamPacketArrivalDl;
229 // Because we need here an integer number of milliseconds,
231 // or equal to x is used as the actual packet arrival time in ms
232 x = MilliSeconds(floor(a - b * log(-log(y))));
233 }
234 else
235 {
236 x = MilliSeconds(m_packetArrivalUl);
237 }
238 return x;
239}
240
241void
242TrafficGeneratorNgmnGaming::DoDispose()
243{
244 NS_LOG_FUNCTION(this);
245 m_initPacketArrivalVariable = nullptr;
246 m_packetSizeRandomVariable = nullptr;
247 m_packetArrivalVariable = nullptr;
248
249 // chain up
250 TrafficGenerator::DoDispose();
251}
252
253void
254TrafficGeneratorNgmnGaming::DoInitialize()
255{
256 NS_LOG_FUNCTION(this);
257 m_initPacketArrivalVariable = CreateObject<UniformRandomVariable>();
258 m_initPacketArrivalVariable->SetAttribute("Min", DoubleValue(m_initialPacketArrivalMin));
259 m_initPacketArrivalVariable->SetAttribute("Max", DoubleValue(m_initialPacketArrivalMax));
260 m_packetSizeRandomVariable = CreateObject<UniformRandomVariable>();
261 m_packetSizeRandomVariable->SetAttribute("Min", DoubleValue(0));
262 m_packetSizeRandomVariable->SetAttribute("Max", DoubleValue(1));
263 m_packetArrivalVariable = CreateObject<UniformRandomVariable>();
264 m_packetArrivalVariable->SetAttribute("Min", DoubleValue(0));
265 m_packetArrivalVariable->SetAttribute("Max", DoubleValue(1));
266 // chain up
267 TrafficGenerator::DoInitialize();
268}
269
270int64_t
272{
273 m_initPacketArrivalVariable->SetStream(stream);
274 m_packetSizeRandomVariable->SetStream(stream + 1);
275 m_packetArrivalVariable->SetStream(stream + 2);
276
277 return 3;
278}
279
280} // Namespace ns3
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.