-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcttc-nr-traffic-3gpp-xr-qos-sched.cc
637 lines (552 loc) · 24 KB
/
cttc-nr-traffic-3gpp-xr-qos-sched.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
// Copyright (c) 2023 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
//
// SPDX-License-Identifier: GPL-2.0-only
#include "ns3/antenna-module.h"
#include "ns3/applications-module.h"
#include "ns3/boolean.h"
#include "ns3/config-store-module.h"
#include "ns3/config-store.h"
#include "ns3/core-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/internet-module.h"
#include "ns3/lte-enb-rrc.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/nr-module.h"
#include "ns3/packet-sink.h"
#include "ns3/point-to-point-module.h"
#include "ns3/xr-traffic-mixer-helper.h"
#include <vector>
#include <fstream>
#include <iomanip>
/**
* \file cttc-nr-traffic-3gpp-xr_neco.cc
* \ingroup examples
* \brief Simple topology consisting of 1 GNB and various UEs.
* Can be configured with different 3GPP XR traffic generators (by using
* XR traffic mixer helper).
*
* To run the simulation with the default configuration one shall run the
* following in the command line:
*
* ./ns3 run cttc-nr-traffic-generator-3gpp-xr_neco
*
*/
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("CttcNrTraffic3gppXrNeco");
void
WriteBytesSent(Ptr<TrafficGenerator> trafficGenerator,
uint64_t* previousBytesSent,
uint64_t* previousWindowBytesSent,
enum NrXrConfig NrXrConfig,
std::ofstream* outFileTx)
{
uint64_t totalBytesSent = trafficGenerator->GetTotalBytes();
(*outFileTx) << "\n"
<< Simulator::Now().GetMilliSeconds() << "\t" << *previousWindowBytesSent
<< std::endl;
(*outFileTx) << "\n"
<< Simulator::Now().GetMilliSeconds() << "\t"
<< totalBytesSent - *previousBytesSent << std::endl;
*previousWindowBytesSent = totalBytesSent - *previousBytesSent;
*previousBytesSent = totalBytesSent;
};
void
WriteBytesReceived(Ptr<PacketSink> packetSink, uint64_t* previousBytesReceived)
{
uint64_t totalBytesReceived = packetSink->GetTotalRx();
*previousBytesReceived = totalBytesReceived;
};
void
ConfigureXrApp(NodeContainer& ueContainer,
uint32_t i,
Ipv4InterfaceContainer& ueIpIface,
enum NrXrConfig config,
uint16_t port,
std::string transportProtocol,
NodeContainer& remoteHostContainer,
NetDeviceContainer& ueNetDev,
Ptr<NrHelper> nrHelper,
EpsBearer& bearer,
Ptr<EpcTft> tft,
bool isMx1,
std::vector<Ptr<EpcTft>>& tfts,
ApplicationContainer& serverApps,
ApplicationContainer& clientApps,
ApplicationContainer& pingApps)
{
XrTrafficMixerHelper trafficMixerHelper;
Ipv4Address ipAddress = ueIpIface.GetAddress(i, 0);
trafficMixerHelper.ConfigureXr(config);
auto it = XrPreconfig.find(config);
std::vector<Address> addresses;
std::vector<InetSocketAddress> localAddresses;
for (uint j = 0; j < it->second.size(); j++)
{
addresses.emplace_back(InetSocketAddress(ipAddress, port + j));
// The sink will always listen to the specified ports
localAddresses.emplace_back(InetSocketAddress(Ipv4Address::GetAny(), port + j));
}
ApplicationContainer currentUeClientApps;
currentUeClientApps.Add(
trafficMixerHelper.Install(transportProtocol, addresses, remoteHostContainer.Get(0)));
// Seed the ARP cache by pinging early in the simulation
// This is a workaround until a static ARP capability is provided
PingHelper ping(ipAddress);
pingApps.Add(ping.Install(remoteHostContainer));
Ptr<NetDevice> ueDevice = ueNetDev.Get(i);
// Activate a dedicated bearer for the traffic type per node
nrHelper->ActivateDedicatedEpsBearer(ueDevice, bearer, tft);
// Activate a dedicated bearer for the traffic type per node
if (isMx1)
{
nrHelper->ActivateDedicatedEpsBearer(ueDevice, bearer, tft);
}
else
{
NS_ASSERT(tfts.size() >= currentUeClientApps.GetN());
for (uint32_t j = 0; j < currentUeClientApps.GetN(); j++)
{
nrHelper->ActivateDedicatedEpsBearer(ueDevice, bearer, tfts[j]);
}
}
for (uint32_t j = 0; j < currentUeClientApps.GetN(); j++)
{
PacketSinkHelper dlPacketSinkHelper(transportProtocol, localAddresses.at(j));
Ptr<Application> packetSink = dlPacketSinkHelper.Install(ueContainer.Get(i)).Get(0);
serverApps.Add(packetSink);
}
clientApps.Add(currentUeClientApps);
}
int
main(int argc, char* argv[])
{
// set simulation time and mobility
uint32_t appDuration = 10000;
uint32_t appStartTimeMs = 400;
uint16_t numerology = 0;
uint16_t arUeNum = 0;
uint16_t vrUeNum = 4;
uint16_t cgUeNum = 4;
double centralFrequency = 4e9;
double bandwidth = 10e6;
double txPower = 41;
bool isMx1 = true;
bool useUdp = true;
double distance = 450;
uint32_t rngRun = 1;
double dppV = 0.0;
bool enableVirtualQueue = true;
// MAC scheduler type: RR, PF, MR, Qos, DPP
std::string schedulerType = "DPP";
bool enableOfdma = true;
bool logging = false;
CommandLine cmd(__FILE__);
cmd.AddValue("enableOfdma",
"If set to true it enables Ofdma scheduler. Default value is false (Tdma)",
enableOfdma),
cmd.AddValue("schedulerType",
"PF: Proportional Fair (default), RR: Round-Robin, Qos",
schedulerType);
cmd.AddValue("dppV", "Drift Plus Penalty V value", dppV);
cmd.AddValue("enableVirtualQueue", "Enable the throughput virtual queue", enableVirtualQueue);
cmd.AddValue("logging", "Enable logging", logging);
cmd.AddValue("arUeNum", "The number of AR UEs", arUeNum);
cmd.AddValue("vrUeNum", "The number of VR UEs", vrUeNum);
cmd.AddValue("cgUeNum", "The number of CG UEs", cgUeNum);
cmd.AddValue("numerology", "The numerology to be used.", numerology);
cmd.AddValue("txPower", "Tx power to be configured to gNB", txPower);
cmd.AddValue("frequency", "The system frequency", centralFrequency);
cmd.AddValue("bandwidth", "The system bandwidth", bandwidth);
cmd.AddValue("useUdp",
"if true, the NGMN applications will run over UDP connection, otherwise a TCP "
"connection will be used.",
useUdp);
cmd.AddValue("distance",
"The radius of the disc (in meters) that the UEs will be distributed."
"Default value is 450m",
distance);
cmd.AddValue("isMx1",
"if true M SDFs will be mapped to 1 DRB, otherwise the mapping will "
"be 1x1, i.e., 1 SDF to 1 DRB.",
isMx1);
cmd.AddValue("rngRun", "Rng run random number.", rngRun);
cmd.AddValue("appDuration", "Duration of the application in milliseconds.", appDuration);
cmd.Parse(argc, argv);
// NS_ABORT_MSG_IF(appDuration < 1000, "The appDuration should be at least 1000ms.");
NS_ABORT_MSG_IF(
!vrUeNum && !arUeNum && !cgUeNum,
"Activate at least one type of XR traffic by configuring the number of XR users");
// enable logging or not
if (logging)
{
//LogLevel logLevel1 =
// (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_LEVEL_INFO);
//LogComponentEnable("NrMacSchedulerNs3", logLevel1);
//LogComponentEnable("NrMacSchedulerTdma", logLevel1);
LogComponentEnable("NrMacSchedulerNs3", LOG_LEVEL_WARN);
// LogComponentEnable("NrMacSchedulerOfdmaDPP", LOG_LEVEL_DEBUG);
}
uint32_t simTimeMs = appStartTimeMs + appDuration + 2000;
// Set simulation run number
SeedManager::SetRun(rngRun);
// setup the nr simulation
Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
// simple band configuration and initialize
CcBwpCreator ccBwpCreator;
CcBwpCreator::SimpleOperationBandConf bandConf(centralFrequency,
bandwidth,
1,
BandwidthPartInfo::UMa_LoS);
OperationBandInfo band = ccBwpCreator.CreateOperationBandContiguousCc(bandConf);
nrHelper->InitializeOperationBand(&band);
BandwidthPartInfoPtrVector allBwps = CcBwpCreator::GetAllBwps({band});
nrHelper->SetGnbPhyAttribute("TxPower", DoubleValue(txPower));
nrHelper->SetGnbPhyAttribute("Numerology", UintegerValue(numerology));
nrHelper->SetGnbPhyAttribute("NoiseFigure", DoubleValue(5));
nrHelper->SetUePhyAttribute("TxPower", DoubleValue(23));
nrHelper->SetUePhyAttribute("NoiseFigure", DoubleValue(7));
Config::SetDefault("ns3::LteRlcUm::MaxTxBufferSize", UintegerValue(999999999));
Config::SetDefault("ns3::LteEnbRrc::EpsBearerToRlcMapping",
EnumValue(useUdp ? LteEnbRrc::RLC_UM_ALWAYS : LteEnbRrc::RLC_AM_ALWAYS));
Config::SetDefault("ns3::NrMacSchedulerOfdmaDPP::DppV", DoubleValue(dppV));
Config::SetDefault("ns3::NrMacSchedulerOfdmaDPP::enableVirtualQueue", BooleanValue(true));
nrHelper->SetGnbAntennaAttribute("NumRows", UintegerValue(4));
nrHelper->SetGnbAntennaAttribute("NumColumns", UintegerValue(8));
nrHelper->SetGnbAntennaAttribute("AntennaElement",
PointerValue(CreateObject<ThreeGppAntennaModel>()));
nrHelper->SetGnbAntennaAttribute("AntennaHorizontalSpacing", DoubleValue(0.5));
nrHelper->SetGnbAntennaAttribute("AntennaVerticalSpacing", DoubleValue(0.8));
nrHelper->SetGnbAntennaAttribute("DowntiltAngle", DoubleValue(0 * M_PI / 180.0));
nrHelper->SetUeAntennaAttribute("NumRows", UintegerValue(1));
nrHelper->SetUeAntennaAttribute("NumColumns", UintegerValue(1));
nrHelper->SetUeAntennaAttribute("AntennaElement",
PointerValue(CreateObject<IsotropicAntennaModel>()));
// Set up MAC scheduler
std::stringstream scheduler;
std::string subType;
subType = enableOfdma == false ? "Tdma" : "Ofdma";
scheduler << "ns3::NrMacScheduler" << subType << schedulerType;
std::cout << "Scheduler: " << scheduler.str() << std::endl;
nrHelper->SetSchedulerTypeId(TypeId::LookupByName(scheduler.str()));
// Beamforming method
Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
idealBeamformingHelper->SetAttribute("BeamformingMethod",
TypeIdValue(DirectPathBeamforming::GetTypeId()));
nrHelper->SetBeamformingHelper(idealBeamformingHelper);
Ptr<NrPointToPointEpcHelper> epcHelper = CreateObject<NrPointToPointEpcHelper>();
nrHelper->SetEpcHelper(epcHelper);
epcHelper->SetAttribute("S1uLinkDelay", TimeValue(MilliSeconds(0)));
// Initialize nrHelper
nrHelper->Initialize();
NodeContainer gNbNodes;
NodeContainer ueNodes;
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
const double gNbHeight = 25;
const double ueHeight = 1.5;
gNbNodes.Create(1);
ueNodes.Create(arUeNum + vrUeNum + cgUeNum);
Ptr<ListPositionAllocator> bsPositionAlloc = CreateObject<ListPositionAllocator>();
bsPositionAlloc->Add(Vector(0.0, 0.0, gNbHeight));
mobility.SetPositionAllocator(bsPositionAlloc);
mobility.Install(gNbNodes);
Ptr<RandomDiscPositionAllocator> ueDiscPositionAlloc =
CreateObject<RandomDiscPositionAllocator>();
ueDiscPositionAlloc->SetX(0.0);
ueDiscPositionAlloc->SetY(0.0);
ueDiscPositionAlloc->SetZ(ueHeight);
mobility.SetPositionAllocator(ueDiscPositionAlloc);
for (uint32_t i = 0; i < ueNodes.GetN(); i++)
{
mobility.Install(ueNodes.Get(i));
}
/*
* Create various NodeContainer(s) for the different traffic types.
* In ueArContainer, ueVrContainer, ueCgContainer, we will put
* AR, VR, CG UEs, respectively.*/
NodeContainer ueArContainer;
NodeContainer ueVrContainer;
NodeContainer ueCgContainer;
for (auto j = 0; j < arUeNum; ++j)
{
Ptr<Node> ue = ueNodes.Get(j);
ueArContainer.Add(ue);
}
for (auto j = arUeNum; j < arUeNum + vrUeNum; ++j)
{
Ptr<Node> ue = ueNodes.Get(j);
ueVrContainer.Add(ue);
}
for (auto j = arUeNum + vrUeNum; j < arUeNum + vrUeNum + cgUeNum; ++j)
{
Ptr<Node> ue = ueNodes.Get(j);
ueCgContainer.Add(ue);
}
NetDeviceContainer gNbNetDev = nrHelper->InstallGnbDevice(gNbNodes, allBwps);
NetDeviceContainer ueArNetDev = nrHelper->InstallUeDevice(ueArContainer, allBwps);
NetDeviceContainer ueVrNetDev = nrHelper->InstallUeDevice(ueVrContainer, allBwps);
NetDeviceContainer ueCgNetDev = nrHelper->InstallUeDevice(ueCgContainer, allBwps);
int64_t randomStream = 1;
randomStream += nrHelper->AssignStreams(gNbNetDev, randomStream);
randomStream += nrHelper->AssignStreams(ueArNetDev, randomStream);
randomStream += nrHelper->AssignStreams(ueVrNetDev, randomStream);
randomStream += nrHelper->AssignStreams(ueCgNetDev, randomStream);
for (auto it = gNbNetDev.Begin(); it != gNbNetDev.End(); ++it)
{
DynamicCast<NrGnbNetDevice>(*it)->UpdateConfig();
}
for (auto it = ueArNetDev.Begin(); it != ueArNetDev.End(); ++it)
{
DynamicCast<NrUeNetDevice>(*it)->UpdateConfig();
}
for (auto it = ueVrNetDev.Begin(); it != ueVrNetDev.End(); ++it)
{
DynamicCast<NrUeNetDevice>(*it)->UpdateConfig();
}
for (auto it = ueCgNetDev.Begin(); it != ueCgNetDev.End(); ++it)
{
DynamicCast<NrUeNetDevice>(*it)->UpdateConfig();
}
// create the internet and install the IP stack on the UEs
// get SGW/PGW and create a single RemoteHost
Ptr<Node> pgw = epcHelper->GetPgwNode();
NodeContainer remoteHostContainer;
remoteHostContainer.Create(1);
Ptr<Node> remoteHost = remoteHostContainer.Get(0);
InternetStackHelper internet;
internet.Install(remoteHostContainer);
// connect a remoteHost to pgw. Setup routing too
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
p2ph.SetDeviceAttribute("Mtu", UintegerValue(1000));
p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.000)));
NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
Ipv4AddressHelper ipv4h;
ipv4h.SetBase("1.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
internet.Install(ueNodes);
Ipv4InterfaceContainer ueArIpIface;
Ipv4InterfaceContainer ueVrIpIface;
Ipv4InterfaceContainer ueCgIpIface;
ueArIpIface = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueArNetDev));
ueVrIpIface = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueVrNetDev));
ueCgIpIface = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueCgNetDev));
// Set the default gateway for the UEs
for (uint32_t j = 0; j < ueNodes.GetN(); ++j)
{
Ptr<Ipv4StaticRouting> ueStaticRouting =
ipv4RoutingHelper.GetStaticRouting(ueNodes.Get(j)->GetObject<Ipv4>());
ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(), 1);
}
// attach UEs to the closest eNB
nrHelper->AttachToClosestEnb(ueArNetDev, gNbNetDev);
nrHelper->AttachToClosestEnb(ueVrNetDev, gNbNetDev);
nrHelper->AttachToClosestEnb(ueCgNetDev, gNbNetDev);
// Install sink application
ApplicationContainer serverApps;
// configure the transport protocol to be used
std::string transportProtocol;
transportProtocol = useUdp == true ? "ns3::UdpSocketFactory" : "ns3::TcpSocketFactory";
uint16_t dlPortArStart = 1121; // AR has 3 flows
uint16_t dlPortArStop = 1124;
uint16_t dlPortVrStart = 1131;
uint16_t dlPortCgStart = 1141;
// The bearer that will carry AR traffic
EpsBearer arBearer(EpsBearer::NGBR_LOW_LAT_EMBB);
// GbrQosInformation qosUe1flow;
// qosUe1flow.gbrDl = 1e6; // Downlink GBR
// EpsBearer arBearer(EpsBearer::GBR_LIVE_UL_76, qosUe1flow);
Ptr<EpcTft> arTft = Create<EpcTft>();
EpcTft::PacketFilter dlpfAr;
std::vector<Ptr<EpcTft>> arTfts;
if (isMx1)
{
dlpfAr.localPortStart = dlPortArStart;
dlpfAr.localPortEnd = dlPortArStop;
arTft->Add(dlpfAr);
}
else
{
// create 3 xrTfts for 1x1 mapping
for (uint32_t i = 0; i < 3; i++)
{
Ptr<EpcTft> tempTft = Create<EpcTft>();
dlpfAr.localPortStart = dlPortArStart + i;
dlpfAr.localPortEnd = dlPortArStart + i;
tempTft->Add(dlpfAr);
arTfts.emplace_back(tempTft);
}
}
// The bearer that will carry VR traffic
// EpsBearer vrBearer(EpsBearer::NGBR_LOW_LAT_EMBB);
GbrQosInformation qosVrflow;
qosVrflow.gbrDl = 0; // Downlink GBR
EpsBearer vrBearer(EpsBearer::NGBR_LOW_LAT_EMBB, qosVrflow);
Ptr<EpcTft> vrTft = Create<EpcTft>();
EpcTft::PacketFilter dlpfVr;
dlpfVr.localPortStart = dlPortVrStart;
dlpfVr.localPortEnd = dlPortVrStart;
vrTft->Add(dlpfVr);
// The bearer that will carry CG traffic
// EpsBearer cgBearer(EpsBearer::NGBR_LOW_LAT_EMBB);
GbrQosInformation qosCgflow;
qosCgflow.gbrDl = 4e6; // Downlink GBR
EpsBearer cgBearer(EpsBearer::GBR_GAMING, qosCgflow);
Ptr<EpcTft> cgTft = Create<EpcTft>();
EpcTft::PacketFilter dlpfCg;
dlpfCg.localPortStart = dlPortCgStart;
dlpfCg.localPortEnd = dlPortCgStart;
cgTft->Add(dlpfCg);
// Install traffic generators
ApplicationContainer clientApps;
ApplicationContainer pingApps;
std::ostringstream xrFileTag;
for (uint32_t i = 0; i < ueArContainer.GetN(); ++i)
{
ConfigureXrApp(ueArContainer,
i,
ueArIpIface,
AR_M3,
dlPortArStart,
transportProtocol,
remoteHostContainer,
ueArNetDev,
nrHelper,
arBearer,
arTft,
isMx1,
arTfts,
serverApps,
clientApps,
pingApps);
}
// TODO for VR and CG of 2 flows Tfts and isMx1 have to be set. Currently they are
// hardcoded for 1 flow
for (uint32_t i = 0; i < ueVrContainer.GetN(); ++i)
{
ConfigureXrApp(ueVrContainer,
i,
ueVrIpIface,
VR_DL1,
dlPortVrStart,
transportProtocol,
remoteHostContainer,
ueVrNetDev,
nrHelper,
vrBearer,
vrTft,
1,
arTfts,
serverApps,
clientApps,
pingApps);
}
for (uint32_t i = 0; i < ueCgContainer.GetN(); ++i)
{
ConfigureXrApp(ueCgContainer,
i,
ueCgIpIface,
CG_DL1,
dlPortCgStart,
transportProtocol,
remoteHostContainer,
ueCgNetDev,
nrHelper,
cgBearer,
cgTft,
1,
arTfts,
serverApps,
clientApps,
pingApps);
}
pingApps.Start(MilliSeconds(100));
pingApps.Stop(MilliSeconds(appStartTimeMs));
// start server and client apps
serverApps.Start(MilliSeconds(appStartTimeMs));
clientApps.Start(MilliSeconds(appStartTimeMs));
serverApps.Stop(MilliSeconds(simTimeMs));
clientApps.Stop(MilliSeconds(appStartTimeMs + appDuration));
FlowMonitorHelper flowmonHelper;
NodeContainer endpointNodes;
endpointNodes.Add(remoteHost);
endpointNodes.Add(ueNodes);
Ptr<ns3::FlowMonitor> monitor = flowmonHelper.Install(endpointNodes);
monitor->SetAttribute("DelayBinWidth", DoubleValue(0.0001));
monitor->SetAttribute("JitterBinWidth", DoubleValue(0.001));
monitor->SetAttribute("PacketSizeBinWidth", DoubleValue(20));
Simulator::Stop(MilliSeconds(simTimeMs));
Simulator::Run();
std::ofstream outputFile("res.txt");
outputFile << "Thput\tRx\tDuration\n";
// Print per-flow statistics
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier =
DynamicCast<Ipv4FlowClassifier>(flowmonHelper.GetClassifier());
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
double averageFlowThroughput = 0.0;
double averageFlowDelay = 0.0;
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin();
i != stats.end();
++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
std::stringstream protoStream;
protoStream << (uint16_t)t.protocol;
if (t.protocol == 6)
{
protoStream.str("TCP");
}
if (t.protocol == 17)
{
protoStream.str("UDP");
}
Time txDuration = MilliSeconds(appDuration);
std::cout << "Flow " << i->first << " (" << t.sourceAddress << ":" << t.sourcePort << " -> "
<< t.destinationAddress << ":" << t.destinationPort << ") proto "
<< protoStream.str() << "\n";
std::cout << " Tx Packets: " << i->second.txPackets << "\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " TxOffered: "
<< ((i->second.txBytes * 8.0) / txDuration.GetSeconds()) * 1e-6 << " Mbps\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
if (i->second.rxPackets > 0)
{
// Measure the duration of the flow from receiver's perspective
Time rxDuration = i->second.timeLastRxPacket - i->second.timeFirstTxPacket;
averageFlowThroughput += ((i->second.rxBytes * 8.0) / rxDuration.GetSeconds()) * 1e-6;
averageFlowDelay += 1000 * i->second.delaySum.GetSeconds() / i->second.rxPackets;
double throughput = ((i->second.rxBytes * 8.0) / rxDuration.GetSeconds()) * 1e-6;
double delay = 1000 * i->second.delaySum.GetSeconds() / i->second.rxPackets;
double jitter = 1000 * i->second.jitterSum.GetSeconds() / i->second.rxPackets;
std::cout << " Throughput: " << throughput << " Mbps\n";
// std::cout << i->second.rxBytes * 8.0 << " / " << rxDuration.GetSeconds() << std::endl;
// std::cout << "tf = " << i->second.timeLastRxPacket << " t0 = " << i->second.timeFirstTxPacket << std::endl;
// double thput_prueba = ((i->second.rxBytes * 8.0) / txDuration.GetSeconds()) * 1e-6;
// std::cout << " Throughput*: " << thput_prueba << " Mbps\n";
std::cout << " Mean delay: " << delay << " ms\n";
std::cout << " Mean jitter: " << jitter << " ms\n";
outputFile << throughput << "\t" << i->second.rxBytes * 8.0 << "\t" << rxDuration.GetSeconds() << std::endl;
}
else
{
std::cout << " Throughput: 0 Mbps\n";
std::cout << " Mean delay: 0 ms\n";
std::cout << " Mean upt: 0 Mbps \n";
std::cout << " Mean jitter: 0 ms\n";
outputFile << 0 << "\t" << 0 << "\t" << 0 << std::endl;
}
std::cout << " Rx Packets: " << i->second.rxPackets << "\n";
}
std::cout << "\n\n Mean flow throughput: " << averageFlowThroughput / stats.size()
<< "Mbps \n";
std::cout << " Mean flow delay: " << averageFlowDelay / stats.size() << " ms\n";
Simulator::Destroy();
return 0;
}