28#include "ns3/antenna-module.h"
29#include "ns3/applications-module.h"
30#include "ns3/buildings-module.h"
31#include "ns3/config-store-module.h"
32#include "ns3/core-module.h"
33#include "ns3/flow-monitor-module.h"
34#include "ns3/internet-apps-module.h"
35#include "ns3/internet-module.h"
36#include "ns3/mobility-module.h"
37#include "ns3/nr-module.h"
38#include "ns3/point-to-point-module.h"
42NS_LOG_COMPONENT_DEFINE(
"CttcNrSimpleQosSched");
45main(
int argc,
char* argv[])
54 uint16_t ueNumPergNb = 2;
59 Time simTime = MilliSeconds(1000);
60 Time udpAppStartTime = MilliSeconds(400);
64 uint16_t numerology = 0;
65 double centralFrequency = 4e9;
66 double bandwidth = 5e6;
67 double totalTxPower = 43;
69 bool enableOfdma =
false;
71 uint8_t priorityTrafficScenario = 0;
73 uint16_t mcsTable = 2;
76 std::string simTag =
"default";
77 std::string outputDir =
"./";
86 cmd.AddValue(
"gNbNum",
"The number of gNbs in multiple-ue topology", gNbNum);
87 cmd.AddValue(
"ueNumPergNb",
"The number of UE per gNb in multiple-ue topology", ueNumPergNb);
88 cmd.AddValue(
"logging",
"Enable logging", logging);
89 cmd.AddValue(
"priorityTrafficScenario",
90 "The traffic scenario for the case of priority. Can be 0: saturation"
92 priorityTrafficScenario);
93 cmd.AddValue(
"simTime",
"Simulation time", simTime);
94 cmd.AddValue(
"numerology",
"The numerology to be used", numerology);
95 cmd.AddValue(
"centralFrequency",
"The system frequency to be used", centralFrequency);
96 cmd.AddValue(
"bandwidth",
"The system bandwidth to be used", bandwidth);
97 cmd.AddValue(
"totalTxPower",
98 "total tx power that will be proportionally assigned to"
99 " bands, CCs and bandwidth parts depending on each BWP bandwidth ",
101 cmd.AddValue(
"simTag",
102 "tag to be appended to output filenames to distinguish simulation campaigns",
104 cmd.AddValue(
"outputDir",
"directory where to store simulation results", outputDir);
105 cmd.AddValue(
"enableOfdma",
106 "If set to true it enables Ofdma scheduler. Default value is false (Tdma)",
109 cmd.Parse(argc, argv);
115 (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_LEVEL_INFO);
116 LogComponentEnable(
"NrMacSchedulerNs3", logLevel1);
117 LogComponentEnable(
"NrMacSchedulerTdma", logLevel1);
120 Config::SetDefault(
"ns3::NrRlcUm::MaxTxBufferSize", UintegerValue(999999999));
127 int64_t randomStream = 1;
140 gridScenario.SetScenarioHeight(3);
141 gridScenario.SetScenarioLength(3);
145 uint32_t udpPacketSizeULL;
146 uint32_t udpPacketSizeBe;
147 uint32_t lambdaULL = 1000;
148 uint32_t lambdaBe = 1000;
150 if (priorityTrafficScenario == 0)
152 udpPacketSizeULL = 3000;
153 udpPacketSizeBe = 3000;
155 else if (priorityTrafficScenario == 1)
157 udpPacketSizeULL = 3000;
158 udpPacketSizeBe = 1252;
162 NS_ABORT_MSG(
"The priorityTrafficScenario chosen is not correct. "
163 "Please choose among 0: saturation and 1: medium-load");
171 NodeContainer ueLowLatContainer;
172 NodeContainer ueVoiceContainer;
178 j % 2 == 0 ? ueLowLatContainer.Add(ue) : ueVoiceContainer.Add(ue);
181 if (priorityTrafficScenario == 1)
183 lambdaULL = 1000 / ueLowLatContainer.GetN();
184 lambdaBe = 1000 / ueVoiceContainer.GetN();
188 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
189 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
190 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
193 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
194 nrHelper->SetEpcHelper(nrEpcHelper);
195 nrEpcHelper->SetAttribute(
"S1uLinkDelay", TimeValue(MilliSeconds(0)));
197 std::stringstream schedulerType;
201 subType = !enableOfdma ?
"Tdma" :
"Ofdma";
203 schedulerType <<
"ns3::NrMacScheduler" << subType << sched;
204 std::cout <<
"SchedulerType: " << schedulerType.str() << std::endl;
205 nrHelper->SetSchedulerTypeId(TypeId::LookupByName(schedulerType.str()));
208 std::string errorModel =
"ns3::NrEesmIrT" + std::to_string(mcsTable);
209 nrHelper->SetDlErrorModel(errorModel);
210 nrHelper->SetUlErrorModel(errorModel);
217 idealBeamformingHelper->SetAttribute(
"BeamformingMethod",
221 nrHelper->SetUeAntennaAttribute(
"NumRows", UintegerValue(1));
222 nrHelper->SetUeAntennaAttribute(
"NumColumns", UintegerValue(1));
223 nrHelper->SetUeAntennaAttribute(
"AntennaElement",
224 PointerValue(CreateObject<IsotropicAntennaModel>()));
227 nrHelper->SetGnbAntennaAttribute(
"NumRows", UintegerValue(1));
228 nrHelper->SetGnbAntennaAttribute(
"NumColumns", UintegerValue(1));
229 nrHelper->SetGnbAntennaAttribute(
"AntennaElement",
230 PointerValue(CreateObject<IsotropicAntennaModel>()));
239 const uint8_t numOfCcs = 1;
253 bandConf.m_numBwp = 1;
256 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
258 channelHelper->ConfigureFactories(
"UMi",
"Default",
"ThreeGpp");
260 channelHelper->SetPathlossAttribute(
"ShadowingEnabled", BooleanValue(
false));
261 Config::SetDefault(
"ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(MilliSeconds(0)));
262 channelHelper->SetChannelConditionModelAttribute(
"UpdatePeriod", TimeValue(MilliSeconds(0)));
264 channelHelper->AssignChannelsToBands({band});
267 double x = pow(10, totalTxPower / 10);
269 Packet::EnableChecking();
270 Packet::EnablePrinting();
272 uint32_t bwpIdForLowLat = 0;
273 uint32_t bwpIdForVoice = 0;
276 nrHelper->SetGnbBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB",
277 UintegerValue(bwpIdForLowLat));
278 nrHelper->SetGnbBwpManagerAlgorithmAttribute(
"GBR_CONV_VOICE", UintegerValue(bwpIdForVoice));
281 nrHelper->SetUeBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB", UintegerValue(bwpIdForLowLat));
282 nrHelper->SetUeBwpManagerAlgorithmAttribute(
"GBR_CONV_VOICE", UintegerValue(bwpIdForVoice));
288 NetDeviceContainer gnbNetDev =
290 NetDeviceContainer ueLowLatNetDev = nrHelper->InstallUeDevice(ueLowLatContainer, allBwps);
291 NetDeviceContainer ueVoiceNetDev = nrHelper->InstallUeDevice(ueVoiceContainer, allBwps);
293 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
294 randomStream += nrHelper->AssignStreams(ueLowLatNetDev, randomStream);
295 randomStream += nrHelper->AssignStreams(ueVoiceNetDev, randomStream);
297 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetAttribute(
"Numerology", UintegerValue(numerology));
298 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetAttribute(
"TxPower", DoubleValue(10 * log10(x)));
302 auto [remoteHost, remoteHostIpv4Address] =
303 nrEpcHelper->SetupRemoteHost(
"100Gb/s", 2500, Seconds(0.000));
305 InternetStackHelper internet;
309 Ipv4InterfaceContainer ueLowLatIpIface;
310 Ipv4InterfaceContainer ueVoiceIpIface;
311 ueLowLatIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueLowLatNetDev));
312 ueVoiceIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueVoiceNetDev));
315 nrHelper->AttachToClosestGnb(ueLowLatNetDev, gnbNetDev);
316 nrHelper->AttachToClosestGnb(ueVoiceNetDev, gnbNetDev);
322 uint16_t dlPortLowLat = 1234;
323 uint16_t dlPortVoice = 1235;
325 ApplicationContainer serverApps;
328 UdpServerHelper dlPacketSinkLowLat(dlPortLowLat);
329 UdpServerHelper dlPacketSinkVoice(dlPortVoice);
332 serverApps.Add(dlPacketSinkLowLat.Install(ueLowLatContainer));
333 serverApps.Add(dlPacketSinkVoice.Install(ueVoiceContainer));
341 UdpClientHelper dlClientLowLat;
342 dlClientLowLat.SetAttribute(
"RemotePort", UintegerValue(dlPortLowLat));
343 dlClientLowLat.SetAttribute(
"MaxPackets", UintegerValue(0xFFFFFFFF));
344 dlClientLowLat.SetAttribute(
"PacketSize", UintegerValue(udpPacketSizeULL));
345 dlClientLowLat.SetAttribute(
"Interval", TimeValue(Seconds(1.0 / lambdaULL)));
351 Ptr<NrEpcTft> lowLatTft = Create<NrEpcTft>();
355 lowLatTft->Add(dlpfLowLat);
358 UdpClientHelper dlClientVoice;
359 dlClientVoice.SetAttribute(
"RemotePort", UintegerValue(dlPortVoice));
360 dlClientVoice.SetAttribute(
"MaxPackets", UintegerValue(0xFFFFFFFF));
361 dlClientVoice.SetAttribute(
"PacketSize", UintegerValue(udpPacketSizeBe));
362 dlClientVoice.SetAttribute(
"Interval", TimeValue(Seconds(1.0 / lambdaBe)));
368 Ptr<NrEpcTft> voiceTft = Create<NrEpcTft>();
372 voiceTft->Add(dlpfVoice);
375 ApplicationContainer clientApps;
377 for (uint32_t i = 0; i < ueLowLatContainer.GetN(); ++i)
379 Ptr<NetDevice> ueDevice = ueLowLatNetDev.Get(i);
380 Address ueAddress = ueLowLatIpIface.GetAddress(i);
384 dlClientLowLat.SetAttribute(
"RemoteAddress", AddressValue(ueAddress));
385 clientApps.Add(dlClientLowLat.Install(remoteHost));
388 nrHelper->ActivateDedicatedEpsBearer(ueDevice, lowLatBearer, lowLatTft);
391 for (uint32_t i = 0; i < ueVoiceContainer.GetN(); ++i)
393 Ptr<NetDevice> ueDevice = ueVoiceNetDev.Get(i);
394 Address ueAddress = ueVoiceIpIface.GetAddress(i);
398 dlClientVoice.SetAttribute(
"RemoteAddress", AddressValue(ueAddress));
399 clientApps.Add(dlClientVoice.Install(remoteHost));
402 nrHelper->ActivateDedicatedEpsBearer(ueDevice, voiceBearer, voiceTft);
406 serverApps.Start(udpAppStartTime);
407 clientApps.Start(udpAppStartTime);
408 serverApps.Stop(simTime);
409 clientApps.Stop(simTime);
414 FlowMonitorHelper flowmonHelper;
415 NodeContainer endpointNodes;
416 endpointNodes.Add(remoteHost);
419 Ptr<ns3::FlowMonitor> monitor = flowmonHelper.Install(endpointNodes);
420 monitor->SetAttribute(
"DelayBinWidth", DoubleValue(0.001));
421 monitor->SetAttribute(
"JitterBinWidth", DoubleValue(0.001));
422 monitor->SetAttribute(
"PacketSizeBinWidth", DoubleValue(20));
424 Simulator::Stop(simTime);
435 monitor->CheckForLostPackets();
436 Ptr<Ipv4FlowClassifier> classifier =
437 DynamicCast<Ipv4FlowClassifier>(flowmonHelper.GetClassifier());
438 FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
440 double averageFlowThroughput = 0.0;
441 double averageFlowDelay = 0.0;
443 std::ofstream outFile;
444 std::string filename = outputDir +
"/" + simTag;
445 outFile.open(filename.c_str(), std::ofstream::out | std::ofstream::trunc);
446 if (!outFile.is_open())
448 std::cerr <<
"Can't open file " << filename << std::endl;
452 outFile.setf(std::ios_base::fixed);
454 double flowDuration = (simTime - udpAppStartTime).GetSeconds();
455 for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin();
459 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
460 std::stringstream protoStream;
461 protoStream << (uint16_t)t.protocol;
464 protoStream.str(
"TCP");
466 if (t.protocol == 17)
468 protoStream.str(
"UDP");
470 outFile <<
"Flow " << i->first <<
" (" << t.sourceAddress <<
":" << t.sourcePort <<
" -> "
471 << t.destinationAddress <<
":" << t.destinationPort <<
") proto "
472 << protoStream.str() <<
"\n";
473 outFile <<
" Tx Packets: " << i->second.txPackets <<
"\n";
474 outFile <<
" Tx Bytes: " << i->second.txBytes <<
"\n";
475 outFile <<
" TxOffered: " << i->second.txBytes * 8.0 / flowDuration / 1000.0 / 1000.0
477 outFile <<
" Rx Bytes: " << i->second.rxBytes <<
"\n";
478 if (i->second.rxPackets > 0)
481 averageFlowThroughput += i->second.rxBytes * 8.0 / flowDuration / 1000 / 1000;
482 averageFlowDelay += 1000 * i->second.delaySum.GetSeconds() / i->second.rxPackets;
484 outFile <<
" Throughput: " << i->second.rxBytes * 8.0 / flowDuration / 1000 / 1000
486 outFile <<
" Mean delay: "
487 << 1000 * i->second.delaySum.GetSeconds() / i->second.rxPackets <<
" ms\n";
490 outFile <<
" Mean jitter: "
491 << 1000 * i->second.jitterSum.GetSeconds() / i->second.rxPackets <<
" ms\n";
495 outFile <<
" Throughput: 0 Mbps\n";
496 outFile <<
" Mean delay: 0 ms\n";
497 outFile <<
" Mean jitter: 0 ms\n";
499 outFile <<
" Rx Packets: " << i->second.rxPackets <<
"\n";
502 outFile <<
"\n\n Mean flow throughput: " << averageFlowThroughput / stats.size() <<
"\n";
503 outFile <<
" Mean flow delay: " << averageFlowDelay / stats.size() <<
"\n";
507 std::ifstream f(filename.c_str());
511 std::cout << f.rdbuf();
514 Simulator::Destroy();
Manages the correct creation of operation bands, component carriers and bandwidth parts.
OperationBandInfo CreateOperationBandContiguousCc(const SimpleOperationBandConf &conf)
Create an operation band with the CC specified.
static BandwidthPartInfoPtrVector GetAllBwps(const std::vector< std::reference_wrapper< OperationBandInfo > > &operationBands)
Get all the BWP pointers from the specified vector of operation bands.
The GridScenarioHelper class.
void SetRows(uint32_t r)
SetRows.
void SetHorizontalBsDistance(double d)
SetHorizontalBsDistance.
void SetVerticalBsDistance(double d)
SetVerticalBsDistance.
void CreateScenario() override
Create the scenario, with the configured parameter.
int64_t AssignStreams(int64_t stream)
void SetColumns(uint32_t c)
SetColumns.
const NodeContainer & GetUserTerminals() const
Get the list of user nodes.
void SetBsNumber(std::size_t n)
Set the number of base stations.
void SetUtNumber(std::size_t n)
Set the number of UT/UE.
const NodeContainer & GetBaseStations() const
Get the list of gnb/base station nodes.
@ ErrorModel
Error Model version (can use different error models, see NrErrorModel)
This class contains the specification of EPS Bearers.
@ NGBR_LOW_LAT_EMBB
Non-GBR Low Latency eMBB applications.
@ GBR_CONV_VOICE
GBR Conversational Voice.
void SetBsHeight(double h)
SetGnbHeight.
void SetUtHeight(double h)
SetUeHeight.
void SetSectorization(SiteSectorizationType numSectors)
Sets the number of sectors of every site.
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
uint16_t localPortStart
start of the port number range of the UE
uint16_t localPortEnd
end of the port number range of the UE
Operation band information structure.