5G-LENA nr-v3.3-120-gdac69c56
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
traffic-generator-test.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-test.h"
7
8#include "ns3/boolean.h"
9#include "ns3/ping-helper.h"
10#include "ns3/rng-seed-manager.h"
11
12namespace ns3
13{
14
15bool TGT_ENABLE_PRINTING =
16 false; // variable that allows printing of tested generated random values to files
17
18TrafficGeneratorTestCase::TrafficGeneratorTestCase(std::string name,
19 TypeId trafficGeneratorType,
20 std::string transportProtocol)
21 : TestCase("(TX bytes == RX bytes) when " + name)
22{
23 m_trafficGeneratorType = trafficGeneratorType;
24 m_transportProtocol = transportProtocol;
25}
26
27TrafficGeneratorTestCase::~TrafficGeneratorTestCase()
28{
29}
30
31void
32TrafficGeneratorTestCase::DoRun()
33{
34 RngSeedManager::SetSeed(1);
35 RngSeedManager::SetRun(1);
36
37 NodeContainer nodes;
38 nodes.Create(2);
39 InternetStackHelper internet;
40 internet.Install(nodes);
41 // link the two nodes
42 Ptr<SimpleNetDevice> txDev = CreateObject<SimpleNetDevice>();
43 Ptr<SimpleNetDevice> rxDev = CreateObject<SimpleNetDevice>();
44 nodes.Get(0)->AddDevice(txDev);
45 nodes.Get(1)->AddDevice(rxDev);
46 Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel>();
47 rxDev->SetChannel(channel1);
48 txDev->SetChannel(channel1);
49 NetDeviceContainer devices;
50 devices.Add(txDev);
51 devices.Add(rxDev);
52 Ipv4AddressHelper ipv4;
53 ipv4.SetBase("10.1.1.0", "255.255.255.0");
54 Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign(devices);
55
56 // install the packet sink at the receiver node
57 uint16_t port = 4000;
58 InetSocketAddress rxAddress(Ipv4Address::GetAny(), port);
59
60 PacketSinkHelper packetSinkHelper(m_transportProtocol, rxAddress);
61
62 // install the application on the rx device
63 ApplicationContainer sinkApplication = packetSinkHelper.Install(nodes.Get(1));
64 sinkApplication.Start(Seconds(1));
65 sinkApplication.Stop(Seconds(4));
66
67 // install the traffic generator at the transmitter node
68 TrafficGeneratorHelper trafficGeneratorHelper(
69 m_transportProtocol,
70 InetSocketAddress(ipv4Interfaces.GetAddress(1, 0), port),
71 m_trafficGeneratorType);
72
73 ApplicationContainer generatorApplication = trafficGeneratorHelper.Install(nodes.Get(0));
74 generatorApplication.Start(Seconds(2));
75 generatorApplication.Stop(Seconds(3));
76
77 // Seed the ARP cache by pinging early in the simulation
78 // This is a workaround until a static ARP capability is provided
79 PingHelper pingHelper(ipv4Interfaces.GetAddress(1, 0));
80 ApplicationContainer pingApps = pingHelper.Install(nodes.Get(0));
81 pingApps.Start(Seconds(1));
82 pingApps.Stop(Seconds(2));
83
84 Ptr<TrafficGenerator> trafficGenerator =
85 generatorApplication.Get(0)->GetObject<TrafficGenerator>();
86 trafficGenerator->Initialize();
87 trafficGenerator->AssignStreams(1);
88
89 Simulator::Run();
90
91 uint64_t totalBytesSent = trafficGenerator->GetTotalBytes();
92
93 Ptr<PacketSink> packetSink = sinkApplication.Get(0)->GetObject<PacketSink>();
94 uint64_t totalBytesReceived = packetSink->GetTotalRx();
95
96 NS_TEST_ASSERT_MSG_EQ(totalBytesSent, totalBytesReceived, "Packets were lost !");
97
98 Simulator::Destroy();
99}
100
101TrafficGeneratorNgmnFtpTestCase::TrafficGeneratorNgmnFtpTestCase()
102 : TestCase(
103 "(The mean file size == 2MBytes) && (The mean reading time == 180 seconds) for NGMN FTP")
104{
105}
106
107TrafficGeneratorNgmnFtpTestCase::~TrafficGeneratorNgmnFtpTestCase()
108{
109}
110
111void
112TrafficGeneratorNgmnFtpTestCase::DoRun()
113{
114 RngSeedManager::SetSeed(1);
115 RngSeedManager::SetRun(1);
116
117 Ptr<TrafficGeneratorNgmnFtpMulti> trafficGenerator =
118 CreateObject<TrafficGeneratorNgmnFtpMulti>();
119 // we need to call it manually because in this test since we do not run the simulation, nothing
120 // will call DoInitialize
121 trafficGenerator->Initialize();
122 trafficGenerator->AssignStreams(1);
123 uint64_t totalFileSizeBytes = 0;
124 Time totalReadingTime = Seconds(0);
125 uint16_t repetitions = 1000;
126
128
129 std::ofstream outFileFtpReadingTime;
130 std::ofstream outFileFtpFileSize;
131
132 if (TGT_ENABLE_PRINTING)
133 {
134 std::string fileNameReadingTime = "ftp-reading-time.csv";
135 outFileFtpReadingTime.open(fileNameReadingTime.c_str(), std::ios_base::out);
136
137 NS_ABORT_MSG_IF(!outFileFtpReadingTime.is_open(),
138 "Can't open file " << fileNameReadingTime);
139 outFileFtpReadingTime.setf(std::ios_base::fixed);
140
141 std::string fileNameFileSize = "ftp-file-size.csv";
142 outFileFtpFileSize.open(fileNameFileSize.c_str(), std::ios_base::out);
143 ;
144 NS_ABORT_MSG_IF(!outFileFtpFileSize.is_open(), "Can't open file " << fileNameFileSize);
145 outFileFtpFileSize.setf(std::ios_base::fixed);
146 }
147
148 for (uint16_t i = 0; i < repetitions; i++)
149 {
150 trafficGenerator->GenerateNextPacketBurstSize();
151 uint32_t fileSize = trafficGenerator->GetPacketBurstSizeInBytes();
152 totalFileSizeBytes += fileSize;
153 Time readingTime = trafficGenerator->GetNextReadingTime();
154 totalReadingTime += readingTime;
155
156 if (TGT_ENABLE_PRINTING)
157 {
158 outFileFtpFileSize << fileSize << "\n";
159 outFileFtpReadingTime << readingTime.GetSeconds() << "\n";
160 }
161 }
162
163 if (TGT_ENABLE_PRINTING)
164 {
165 outFileFtpFileSize.close();
166 outFileFtpReadingTime.close();
167 }
168
169 uint64_t averageFileSize = totalFileSizeBytes / repetitions;
170 Time averageReadingTime = totalReadingTime / repetitions;
171 // According to the NMGN white paper the mean value should be approx. 2MBytes
172 NS_TEST_ASSERT_MSG_EQ_TOL(averageFileSize,
173 2e6,
174 2e6 * 0.1,
175 "The mean FTP file size is not according to the NGMN white paper.");
176 NS_TEST_ASSERT_MSG_EQ_TOL(averageReadingTime,
177 Seconds(180),
178 Seconds(180 * 0.1),
179 "The mean reading time according to the NGMN white paper.");
180 Simulator::Destroy();
181}
182
183TrafficGeneratorNgmnVideoTestCase::TrafficGeneratorNgmnVideoTestCase()
184 : TestCase("(The mean packet size == 100 Bytes) && (The mean packet arrival time == 6 ms) for "
185 "NGMN VIDEO")
186{
187}
188
189TrafficGeneratorNgmnVideoTestCase::~TrafficGeneratorNgmnVideoTestCase()
190{
191}
192
193void
194TrafficGeneratorNgmnVideoTestCase::DoRun()
195{
196 RngSeedManager::SetSeed(1);
197 RngSeedManager::SetRun(1);
198
199 Ptr<TrafficGeneratorNgmnVideo> trafficGenerator = CreateObject<TrafficGeneratorNgmnVideo>();
200 trafficGenerator->Initialize();
201 trafficGenerator->AssignStreams(1);
202 uint64_t totalPacketSize = 0;
203 Time totalPacketTime = Seconds(0);
204 uint16_t repetitions = 1000;
205
206 std::ofstream outFileVideoPacketSize;
207 std::ofstream outFileVideoPacketTime;
208
209 if (TGT_ENABLE_PRINTING)
210 {
211 std::string fileNameVideoPacketSize = "video-packet-size.csv";
212 outFileVideoPacketSize.open(fileNameVideoPacketSize.c_str(), std::ios_base::out);
213 ;
214 NS_ABORT_MSG_IF(!outFileVideoPacketSize.is_open(),
215 "Can't open file " << fileNameVideoPacketSize);
216 outFileVideoPacketSize.setf(std::ios_base::fixed);
217
218 std::string fileNameVideoPacketTime = "video-packet-time.csv";
219 outFileVideoPacketTime.open(fileNameVideoPacketTime.c_str(), std::ios_base::out);
220 ;
221 NS_ABORT_MSG_IF(!outFileVideoPacketTime.is_open(),
222 "Can't open file " << fileNameVideoPacketTime);
223 outFileVideoPacketTime.setf(std::ios_base::fixed);
224 }
225
226 for (uint16_t i = 0; i < repetitions; i++)
227 {
228 uint32_t packetSize = trafficGenerator->GetNextPacketSize();
229 Time packetTime = trafficGenerator->GetNextPacketTime();
230
231 totalPacketSize += packetSize;
232 totalPacketTime += packetTime;
233
234 if (TGT_ENABLE_PRINTING)
235 {
236 outFileVideoPacketSize << packetSize << "\n";
237 outFileVideoPacketTime << packetTime.GetSeconds() << "\n";
238 }
239 }
240
241 if (TGT_ENABLE_PRINTING)
242 {
243 outFileVideoPacketSize.close();
244 outFileVideoPacketTime.close();
245 }
246
247 uint64_t averagePacketSize = totalPacketSize / repetitions;
248 Time averagePacketTime = totalPacketTime / repetitions;
249 NS_TEST_ASSERT_MSG_EQ_TOL(
250 averagePacketSize,
251 100,
252 100 * 0.01,
253 "The mean video packet size is not according to the NGMN white paper.");
254 NS_TEST_ASSERT_MSG_EQ_TOL(
255 averagePacketTime,
256 MilliSeconds(6),
257 MilliSeconds(6) * 0.05,
258 "The mean video packet size is not according to the NGMN white paper.");
259 Simulator::Destroy();
260}
261
262TrafficGeneratorNgmnGamingTestCase::TrafficGeneratorNgmnGamingTestCase()
263 : TestCase("Check the mean initial packet arrival time, the mean packet size and the mean "
264 "packet arrival time for the NGMN GAMING DL and UL.")
265{
266}
267
268TrafficGeneratorNgmnGamingTestCase::~TrafficGeneratorNgmnGamingTestCase()
269{
270}
271
272void
273TrafficGeneratorNgmnGamingTestCase::DoRun()
274{
275 RngSeedManager::SetSeed(1);
276 RngSeedManager::SetRun(1);
277
278 Ptr<TrafficGeneratorNgmnGaming> trafficGenerator = CreateObject<TrafficGeneratorNgmnGaming>();
279 trafficGenerator->Initialize();
280 trafficGenerator->AssignStreams(1);
281 double eulerConst = 0.577215665; // truncated to 9 decimals, we dont need more precision since
282 // we will anyway use some tolerance
283 uint16_t repetitions = 1000;
284 uint64_t totalPacketSizeDl = 0;
285 Time totalPacketTimeDl = Seconds(0);
286 Time totalInitPacketTimeDl = Seconds(0);
287 uint64_t totalPacketSizeUl = 0;
288 Time totalInitPacketTimeUl = Seconds(0);
289 Time totalPacketTimeUl = Seconds(0);
290
291 std::ofstream outFileGamingPacketSizeDl;
292 std::ofstream outFileGamingPacketTimeDl;
293 std::ofstream outFileGamingInitPacketTimeDl;
294
295 std::ofstream outFileGamingPacketSizeUl;
296 std::ofstream outFileGamingPacketTimeUl;
297 std::ofstream outFileGamingInitPacketTimeUl;
298
299 if (TGT_ENABLE_PRINTING)
300 {
301 std::string fileNameGamingPacketSizeDl = "gaming-packet-size-dl.csv";
302 outFileGamingPacketSizeDl.open(fileNameGamingPacketSizeDl.c_str(), std::ios_base::out);
303 ;
304 NS_ABORT_MSG_IF(!outFileGamingPacketSizeDl.is_open(),
305 "Can't open file " << fileNameGamingPacketSizeDl);
306 outFileGamingPacketSizeDl.setf(std::ios_base::fixed);
307
308 std::string fileNameGamingPacketTimeDl = "gaming-packet-time-dl.csv";
309 outFileGamingPacketTimeDl.open(fileNameGamingPacketTimeDl.c_str(), std::ios_base::out);
310 ;
311 NS_ABORT_MSG_IF(!outFileGamingPacketTimeDl.is_open(),
312 "Can't open file " << fileNameGamingPacketTimeDl);
313 outFileGamingPacketTimeDl.setf(std::ios_base::fixed);
314
315 std::string fileNameGamingInitPacketTimeDl = "gaming-packet-init-time-dl.csv";
316 outFileGamingInitPacketTimeDl.open(fileNameGamingInitPacketTimeDl.c_str(),
317 std::ios_base::out);
318 ;
319 NS_ABORT_MSG_IF(!outFileGamingInitPacketTimeDl.is_open(),
320 "Can't open file " << fileNameGamingInitPacketTimeDl);
321 outFileGamingInitPacketTimeDl.setf(std::ios_base::fixed);
322
323 std::string fileNameGamingPacketSizeUl = "gaming-packet-size-ul.csv";
324 outFileGamingPacketSizeUl.open(fileNameGamingPacketSizeUl.c_str(), std::ios_base::out);
325 ;
326 NS_ABORT_MSG_IF(!outFileGamingPacketSizeUl.is_open(),
327 "Can't open file " << fileNameGamingPacketSizeUl);
328 outFileGamingPacketSizeUl.setf(std::ios_base::fixed);
329
330 std::string fileNameGamingPacketTimeUl = "gaming-packet-time-ul.csv";
331 outFileGamingPacketTimeUl.open(fileNameGamingPacketTimeUl.c_str(), std::ios_base::out);
332 ;
333 NS_ABORT_MSG_IF(!outFileGamingPacketTimeUl.is_open(),
334 "Can't open file " << fileNameGamingPacketTimeUl);
335 outFileGamingPacketTimeUl.setf(std::ios_base::fixed);
336
337 std::string fileNameGamingInitPacketTimeUl = "gaming-packet-init-time-ul.csv";
338 outFileGamingInitPacketTimeUl.open(fileNameGamingInitPacketTimeUl.c_str(),
339 std::ios_base::out);
340 ;
341 NS_ABORT_MSG_IF(!outFileGamingInitPacketTimeUl.is_open(),
342 "Can't open file " << fileNameGamingInitPacketTimeUl);
343 outFileGamingInitPacketTimeUl.setf(std::ios_base::fixed);
344 }
345
346 trafficGenerator->SetAttribute("IsDownlink", BooleanValue(true));
347 for (uint16_t i = 0; i < repetitions; i++)
348 {
349 uint32_t packetSizeDl = trafficGenerator->GetNextPacketSize();
350 Time initPacketTimeDl = trafficGenerator->GetInitialPacketArrivalTime();
351 Time packetTimeDl = trafficGenerator->GetNextPacketTime();
352
353 totalPacketSizeDl += packetSizeDl;
354 totalInitPacketTimeDl += initPacketTimeDl;
355 totalPacketTimeDl += packetTimeDl;
356
357 if (TGT_ENABLE_PRINTING)
358 {
359 outFileGamingPacketSizeDl << packetSizeDl << "\n";
360 outFileGamingInitPacketTimeDl << initPacketTimeDl.GetSeconds() << "\n";
361 outFileGamingPacketTimeDl << packetTimeDl.GetSeconds() << "\n";
362 }
363 }
364 uint64_t averagePacketSizeDl = totalPacketSizeDl / repetitions;
365 Time averageInitPacketTimeDl = totalInitPacketTimeDl / repetitions;
366 Time averagePacketArrivalTimeDl = totalPacketTimeDl / repetitions;
367
368 trafficGenerator->SetAttribute("IsDownlink", BooleanValue(false));
369 for (uint16_t i = 0; i < repetitions; i++)
370 {
371 uint32_t packetSizeUl = trafficGenerator->GetNextPacketSize();
372 Time initPacketTimeUl = trafficGenerator->GetInitialPacketArrivalTime();
373 Time packetTimeUl = trafficGenerator->GetNextPacketTime();
374
375 totalPacketSizeUl += packetSizeUl;
376 totalInitPacketTimeUl += initPacketTimeUl;
377 totalPacketTimeUl += packetTimeUl;
378
379 if (TGT_ENABLE_PRINTING)
380 {
381 outFileGamingPacketSizeUl << packetSizeUl << "\n";
382 outFileGamingInitPacketTimeUl << initPacketTimeUl.GetSeconds() << "\n";
383 outFileGamingPacketTimeUl << packetTimeUl.GetSeconds() << "\n";
384 }
385 }
386
387 if (TGT_ENABLE_PRINTING)
388 {
389 outFileGamingPacketSizeDl.close();
390 outFileGamingPacketTimeDl.close();
391 outFileGamingInitPacketTimeDl.close();
392
393 outFileGamingPacketSizeUl.close();
394 outFileGamingPacketTimeUl.close();
395 outFileGamingInitPacketTimeUl.close();
396 }
397
398 uint64_t averagePacketSizeUl = totalPacketSizeUl / repetitions;
399 Time averageInitPacketTimeUl = totalInitPacketTimeUl / repetitions;
400 Time averagePacketArrivalTimeUl = totalPacketTimeUl / repetitions;
401
402 // check the mean DL packet size
403 uint32_t aPacketSizeDl = 120; // in bytes
404 uint32_t bPacketSizeDl = 36;
405 uint32_t meanPacketSizeDl = floor(aPacketSizeDl + bPacketSizeDl * eulerConst);
406 NS_TEST_ASSERT_MSG_EQ_TOL(
407 averagePacketSizeDl,
408 meanPacketSizeDl,
409 meanPacketSizeDl * 0.02,
410 "The mean DL gaming packet size is not according to the NGMN white paper.");
411
412 // test the mean UL packet size
413 uint32_t aPacketSizeUl = 45;
414 double bPacketSizeUl = 5.7;
415 uint32_t meanPacketSizeUl = floor(aPacketSizeUl + bPacketSizeUl * eulerConst);
416 NS_TEST_ASSERT_MSG_EQ_TOL(
417 averagePacketSizeUl,
418 meanPacketSizeUl,
419 meanPacketSizeUl * 0.03,
420 "The mean UL gaming packet size is not according to the NGMN white paper.");
421
422 // test the mean UL and DL initial packet arrival time
423 uint32_t meanInitPacketTimeUl = 20;
424 uint32_t meanInitPacketTimeDl = 20;
425 NS_TEST_ASSERT_MSG_EQ_TOL(
426 averageInitPacketTimeUl,
427 MilliSeconds(meanInitPacketTimeUl),
428 MilliSeconds(meanInitPacketTimeUl) * 0.05,
429 "The mean initial UL gaming packet time is not according to the NGMN white paper.");
430 NS_TEST_ASSERT_MSG_EQ_TOL(
431 averageInitPacketTimeDl,
432 MilliSeconds(meanInitPacketTimeDl),
433 MilliSeconds(meanInitPacketTimeDl) * 0.05,
434 "The mean initial DL gaming packet time is not according to the NGMN white paper.");
435
436 // test the mean UL and DL packet arrival time
437 uint32_t meanPacketArrivalTimeUl = 40; // ms
438 uint32_t aPacketTimeDl = 55; // ms
439 uint32_t bPacketTimeDl = 6;
440 uint32_t meanPacketArrivalTimeDl = floor(aPacketTimeDl + bPacketTimeDl * eulerConst);
441 NS_TEST_ASSERT_MSG_EQ(
442 averagePacketArrivalTimeUl,
443 MilliSeconds(meanPacketArrivalTimeUl),
444 "The mean arrival time of the UL gaming packets is not according to the NGMN white paper.");
445 NS_TEST_ASSERT_MSG_EQ_TOL(
446 averagePacketArrivalTimeDl,
447 MilliSeconds(meanPacketArrivalTimeDl),
448 MilliSeconds(meanPacketArrivalTimeDl) * 0.01,
449 "The mean arrival time of the DL gaming packets is not according to the NGMN white paper.");
450
451 Simulator::Destroy();
452}
453
454TrafficGeneratorNgmnVoipTestCase::TrafficGeneratorNgmnVoipTestCase(std::string transportProtocol)
455 : TestCase("(NGMN VoIP throughput == 12.2 Kbps) when " + transportProtocol)
456{
457 m_transportProtocol = transportProtocol;
458}
459
460TrafficGeneratorNgmnVoipTestCase::~TrafficGeneratorNgmnVoipTestCase()
461{
462}
463
464void
465TrafficGeneratorNgmnVoipTestCase::DoRun()
466{
467 RngSeedManager::SetSeed(1);
468 RngSeedManager::SetRun(1);
469
470 NodeContainer nodes;
471 nodes.Create(2);
472 InternetStackHelper internet;
473 internet.Install(nodes);
474 // link the two nodes
475 Ptr<SimpleNetDevice> txDev = CreateObject<SimpleNetDevice>();
476 Ptr<SimpleNetDevice> rxDev = CreateObject<SimpleNetDevice>();
477 nodes.Get(0)->AddDevice(txDev);
478 nodes.Get(1)->AddDevice(rxDev);
479 Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel>();
480 rxDev->SetChannel(channel1);
481 txDev->SetChannel(channel1);
482 NetDeviceContainer devices;
483 devices.Add(txDev);
484 devices.Add(rxDev);
485 Ipv4AddressHelper ipv4;
486 ipv4.SetBase("10.1.1.0", "255.255.255.0");
487 Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign(devices);
488 double durationInSeconds = 1000;
489
490 // install the packet sink at the receiver node
491 uint16_t port = 4000;
492 InetSocketAddress rxAddress(Ipv4Address::GetAny(), port);
493
494 PacketSinkHelper packetSinkHelper(m_transportProtocol, rxAddress);
495
496 // install the application on the rx device
497 ApplicationContainer sinkApplication = packetSinkHelper.Install(nodes.Get(1));
498 sinkApplication.Start(Seconds(1));
499 sinkApplication.Stop(Seconds(durationInSeconds));
500
501 // install the traffic generator at the transmitter node
502 TrafficGeneratorHelper trafficGeneratorHelper(
503 m_transportProtocol,
504 InetSocketAddress(ipv4Interfaces.GetAddress(1, 0), port),
505 TrafficGeneratorNgmnVoip::GetTypeId());
506
507 ApplicationContainer generatorApplication = trafficGeneratorHelper.Install(nodes.Get(0));
508 generatorApplication.Start(Seconds(2));
509 generatorApplication.Stop(Seconds(durationInSeconds));
510
511 // Seed the ARP cache by pinging early in the simulation
512 // This is a workaround until a static ARP capability is provided
513 PingHelper pingHelper(ipv4Interfaces.GetAddress(1, 0));
514 ApplicationContainer pingApps = pingHelper.Install(nodes.Get(0));
515 pingApps.Start(Seconds(1));
516 pingApps.Stop(Seconds(2));
517
518 Ptr<TrafficGeneratorNgmnVoip> trafficGenerator =
519 generatorApplication.Get(0)->GetObject<TrafficGeneratorNgmnVoip>();
520 trafficGenerator->Initialize();
521 trafficGenerator->AssignStreams(1);
522
523 Simulator::Run();
524
525 uint64_t totalBytesSent = trafficGenerator->GetTotalBytes();
526
527 Ptr<PacketSink> packetSink = sinkApplication.Get(0)->GetObject<PacketSink>();
528 uint64_t totalBytesReceived = packetSink->GetTotalRx();
529
530 NS_TEST_ASSERT_MSG_EQ_TOL(((double)totalBytesSent * 8) / durationInSeconds,
531 6.475e3,
532 6.475e3 * 0.15,
533 "TX: The NGMN VoIP traffic offered throughput is not as expected!");
534 NS_TEST_ASSERT_MSG_EQ_TOL(((double)totalBytesReceived * 8) / durationInSeconds,
535 6.475e3,
536 6.475e3 * 0.15,
537 "RX: The NGMN VoIP traffic received throughput is not as expected!");
538
539 Simulator::Destroy();
540}
541
542TrafficGeneratorThreeGppHttpTestCase::TrafficGeneratorThreeGppHttpTestCase()
543 : TestCase(
544 "(The mean object size == 10710Bytes) && (The mean embedded object size == 7758B)"
545 "&& (The mean number of embedded objects == 5.64) && (The mean reading time == 30seconds)"
546 "&& (The mean parsing time == 0.13seconds) for 3GPP HTTP")
547{
548}
549
550TrafficGeneratorThreeGppHttpTestCase::~TrafficGeneratorThreeGppHttpTestCase()
551{
552}
553
554void
555TrafficGeneratorThreeGppHttpTestCase::DoRun()
556{
557 RngSeedManager::SetSeed(1);
558 RngSeedManager::SetRun(1);
559
560 Ptr<ThreeGppHttpVariables> trafficGenerator = CreateObject<ThreeGppHttpVariables>();
561 // we need to call it manually because in this test since we do not run the simulation, nothing
562 // will call DoInitialize
563 trafficGenerator->Initialize();
564 trafficGenerator->AssignStreams(1);
565 uint64_t totalNumEmbeddedObjects = 0;
566 uint64_t totalObjectSize = 0;
567 uint64_t totalEmbeddedObjectSize = 0;
568 Time totalReadingTime = Seconds(0);
569 Time totalParsingTime = Seconds(0);
570 uint16_t repetitions = 10000;
571
573
574 std::ofstream outFileHttpReadingTime;
575 std::ofstream outFileHttpParsingTime;
576 std::ofstream outFileHttpObjectSize;
577 std::ofstream outFileHttpEmbeddedObjectSize;
578 std::ofstream outFileHttpNumber;
579
580 if (TGT_ENABLE_PRINTING)
581 {
582 std::string fileNameReadingTime = "http-reading-time.csv";
583 outFileHttpReadingTime.open(fileNameReadingTime.c_str(), std::ios_base::out);
584 ;
585 NS_ABORT_MSG_IF(!outFileHttpReadingTime.is_open(),
586 "Can't open file " << fileNameReadingTime);
587 outFileHttpReadingTime.setf(std::ios_base::fixed);
588
589 std::string fileNameParsingTime = "http-parsing-time.csv";
590 outFileHttpParsingTime.open(fileNameParsingTime.c_str(), std::ios_base::out);
591 ;
592 NS_ABORT_MSG_IF(!outFileHttpParsingTime.is_open(),
593 "Can't open file " << fileNameParsingTime);
594 outFileHttpParsingTime.setf(std::ios_base::fixed);
595
596 std::string fileNameObjectSize = "http-object-size.csv";
597 outFileHttpObjectSize.open(fileNameObjectSize.c_str(), std::ios_base::out);
598 ;
599 NS_ABORT_MSG_IF(!outFileHttpObjectSize.is_open(), "Can't open file " << fileNameObjectSize);
600 outFileHttpObjectSize.setf(std::ios_base::fixed);
601
602 std::string fileNameEmbObjectSize = "http-embedded-object-size.csv";
603 outFileHttpEmbeddedObjectSize.open(fileNameEmbObjectSize.c_str(), std::ios_base::out);
604 ;
605 NS_ABORT_MSG_IF(!outFileHttpEmbeddedObjectSize.is_open(),
606 "Can't open file " << fileNameEmbObjectSize);
607 outFileHttpEmbeddedObjectSize.setf(std::ios_base::fixed);
608
609 std::string fileNameNumber = "http-number-objects.csv";
610 outFileHttpNumber.open(fileNameNumber.c_str(), std::ios_base::out);
611 ;
612 NS_ABORT_MSG_IF(!outFileHttpNumber.is_open(), "Can't open file " << fileNameNumber);
613 outFileHttpNumber.setf(std::ios_base::fixed);
614 }
615
616 for (uint16_t i = 0; i < repetitions; i++)
617 {
618 uint32_t numEmbeddedObjects = trafficGenerator->GetNumOfEmbeddedObjects();
619 totalNumEmbeddedObjects += numEmbeddedObjects;
620 Time readingTime = trafficGenerator->GetReadingTime();
621 totalReadingTime += readingTime;
622 Time parsingTime = trafficGenerator->GetParsingTime();
623 totalParsingTime += parsingTime;
624 uint32_t objectSize = trafficGenerator->GetMainObjectSize();
625 totalObjectSize += objectSize;
626 uint32_t embeddedObjectSize = trafficGenerator->GetEmbeddedObjectSize();
627 totalEmbeddedObjectSize += embeddedObjectSize;
628
629 if (TGT_ENABLE_PRINTING)
630 {
631 outFileHttpObjectSize << objectSize << "\n";
632 outFileHttpEmbeddedObjectSize << embeddedObjectSize << "\n";
633 outFileHttpNumber << numEmbeddedObjects << "\n";
634 outFileHttpReadingTime << readingTime.GetSeconds() << "\n";
635 outFileHttpParsingTime << parsingTime.GetSeconds() << "\n";
636 }
637 }
638
639 if (TGT_ENABLE_PRINTING)
640 {
641 outFileHttpObjectSize.close();
642 outFileHttpEmbeddedObjectSize.close();
643 outFileHttpNumber.close();
644 outFileHttpReadingTime.close();
645 outFileHttpParsingTime.close();
646 }
647
648 double avgNumEmbObjects = ((double)totalNumEmbeddedObjects) / repetitions;
649 uint64_t avgObjectSize = totalObjectSize / repetitions;
650 uint64_t avgEmbObjectSize = totalEmbeddedObjectSize / repetitions;
651 Time averageReadingTime = totalReadingTime / repetitions;
652 Time averageParsingTime = totalParsingTime / repetitions;
653
654 NS_TEST_ASSERT_MSG_EQ_TOL(avgNumEmbObjects,
655 5.64,
656 5.64 * 0.1,
657 "The mean number of embedded objects per page is not according to "
658 "the 3GPP."); // 10% tolerance used because of the quantization used
659 // for the number of embedded objects
660 NS_TEST_ASSERT_MSG_EQ_TOL(avgObjectSize,
661 10710,
662 10710 * 0.03,
663 "The mean main object size is not according to the 3GPP.");
664 NS_TEST_ASSERT_MSG_EQ_TOL(avgEmbObjectSize,
665 7758,
666 7758 * 0.03,
667 "The mean embedded object size is not according to the 3GPP.");
668 NS_TEST_ASSERT_MSG_EQ_TOL(averageReadingTime,
669 Seconds(30),
670 Seconds(30 * 0.03),
671 "The mean reading time is not according to the 3GPP.");
672 NS_TEST_ASSERT_MSG_EQ_TOL(averageParsingTime,
673 Seconds(0.13),
674 Seconds(0.13 * 0.03),
675 "The mean parsing time is not according to the 3GPP.");
676 Simulator::Destroy();
677}
678
679TrafficGeneratorTestSuite::TrafficGeneratorTestSuite()
680 : TestSuite("traffic-generator-test", Type::UNIT)
681{
682 std::list<TypeId> trafficGeneratorTypes = {TrafficGeneratorNgmnFtpMulti::GetTypeId(),
683 TrafficGeneratorNgmnVideo::GetTypeId(),
684 TrafficGeneratorNgmnGaming::GetTypeId(),
685 TrafficGeneratorNgmnVoip::GetTypeId()};
686
687 std::list<std::string> transportProtocols = {"ns3::UdpSocketFactory", "ns3::TcpSocketFactory"};
688
689 for (const auto& trafficGeneratorType : trafficGeneratorTypes)
690 {
691 for (const auto& transportProtocol : transportProtocols)
692 {
693 std::string name = trafficGeneratorType.GetName() + " and " + transportProtocol;
694 AddTestCase(new TrafficGeneratorTestCase(name, trafficGeneratorType, transportProtocol),
695 Duration::QUICK);
696 }
697 }
698
699 AddTestCase(new TrafficGeneratorNgmnFtpTestCase(), Duration::QUICK);
700 AddTestCase(new TrafficGeneratorNgmnVideoTestCase(), Duration::QUICK);
701 AddTestCase(new TrafficGeneratorNgmnGamingTestCase(), Duration::QUICK);
702 AddTestCase(new TrafficGeneratorNgmnVoipTestCase("ns3::UdpSocketFactory"), Duration::QUICK);
703 AddTestCase(new TrafficGeneratorNgmnVoipTestCase("ns3::TcpSocketFactory"), Duration::QUICK);
704 // AddTestCase(new TrafficGeneratorThreeGppHttpTestCase(), Duration::QUICK);
705}
706
707static TrafficGeneratorTestSuite
708 trafficGeneratorTestSuite;
709
710}; // namespace ns3