5#include "ns3/antenna-module.h"
6#include "ns3/applications-module.h"
7#include "ns3/core-module.h"
8#include "ns3/internet-apps-module.h"
9#include "ns3/internet-module.h"
10#include "ns3/ipv4-global-routing-helper.h"
12#include "ns3/mobility-module.h"
13#include "ns3/nr-helper.h"
14#include "ns3/nr-module.h"
15#include "ns3/nr-point-to-point-epc-helper.h"
16#include "ns3/point-to-point-helper.h"
60NS_LOG_COMPONENT_DEFINE(
"CttcErrorModelExample");
62static Ptr<ListPositionAllocator>
63GetGnbPositions(
double gNbHeight = 10.0)
65 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
66 pos->Add(Vector(0.0, 0.0, gNbHeight));
71static Ptr<ListPositionAllocator>
72GetUePositions(
double ueY,
double ueHeight = 1.5)
74 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
75 pos->Add(Vector(0.0, ueY, ueHeight));
80static std::vector<uint64_t> packetsTime;
83PrintRxPkt([[maybe_unused]] std::string context, Ptr<const Packet> pkt)
87 pkt->PeekHeader(seqTs);
88 packetsTime.push_back((Simulator::Now() - seqTs.GetTs()).GetMicroSeconds());
92main(
int argc,
char* argv[])
95 const uint8_t gNbNum = 1;
96 const uint8_t ueNum = 1;
97 double totalTxPower = 4;
98 uint16_t numerologyBwp = 4;
99 double centralFrequencyBand = 28e9;
100 double bandwidthBand = 100e6;
103 double simTime = 10.0;
104 uint32_t pktSize = 500;
105 Time udpAppStartTime = MilliSeconds(1000);
106 Time packetInterval = MilliSeconds(200);
107 Time updateChannelInterval = MilliSeconds(150);
110 std::string errorModel =
"ns3::NrEesmCcT1";
112 CommandLine cmd(__FILE__);
114 cmd.AddValue(
"simTime",
"Simulation time", simTime);
115 cmd.AddValue(
"mcs",
"The MCS that will be used in this example", mcs);
116 cmd.AddValue(
"errorModelType",
117 "Error model type: ns3::NrEesmCcT1, ns3::NrEesmCcT2, ns3::NrEesmIrT1, "
118 "ns3::NrEesmIrT2, ns3::NrLteMiErrorModel",
120 cmd.AddValue(
"ueY",
"Y position of any UE", ueY);
121 cmd.AddValue(
"pktSize",
"Packet Size", pktSize);
122 cmd.AddValue(
"isUl",
"Is this an UL transmission?", isUl);
124 cmd.Parse(argc, argv);
126 uint32_t packets = (simTime - udpAppStartTime.GetSeconds()) / packetInterval.GetSeconds();
127 NS_ABORT_IF(packets == 0);
133 Config::SetDefault(
"ns3::NrRlcUm::MaxTxBufferSize", UintegerValue(999999999));
135 Config::SetDefault(
"ns3::NrAmc::ErrorModelType", TypeIdValue(TypeId::LookupByName(errorModel)));
136 Config::SetDefault(
"ns3::NrAmc::AmcModel",
140 NodeContainer gNbNodes;
141 NodeContainer ueNodes;
142 MobilityHelper mobility;
144 double gNbHeight = 10.0;
145 double ueHeight = 1.5;
147 gNbNodes.Create(gNbNum);
148 ueNodes.Create(ueNum);
150 Ptr<ListPositionAllocator> gNbPositionAlloc = GetGnbPositions(gNbHeight);
151 Ptr<ListPositionAllocator> uePositionAlloc = GetUePositions(ueY, ueHeight);
153 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
154 mobility.SetPositionAllocator(gNbPositionAlloc);
155 mobility.Install(gNbNodes);
157 mobility.SetPositionAllocator(uePositionAlloc);
158 mobility.Install(ueNodes);
169 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
170 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
171 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
172 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
175 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
176 nrHelper->SetEpcHelper(nrEpcHelper);
179 channelHelper->ConfigureFactories(
"UMi",
"Default",
"ThreeGpp");
186 const uint8_t numCcPerBand = 1;
193 Config::SetDefault(
"ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(updateChannelInterval));
194 channelHelper->SetChannelConditionModelAttribute(
"UpdatePeriod", TimeValue(MilliSeconds(0)));
195 channelHelper->SetPathlossAttribute(
"ShadowingEnabled", BooleanValue(
false));
198 channelHelper->AssignChannelsToBands({band});
201 Packet::EnableChecking();
202 Packet::EnablePrinting();
208 idealBeamformingHelper->SetAttribute(
"BeamformingMethod",
212 nrEpcHelper->SetAttribute(
"S1uLinkDelay", TimeValue(MilliSeconds(0)));
215 nrHelper->SetUeAntennaAttribute(
"NumRows", UintegerValue(2));
216 nrHelper->SetUeAntennaAttribute(
"NumColumns", UintegerValue(4));
217 nrHelper->SetUeAntennaAttribute(
"AntennaElement",
218 PointerValue(CreateObject<IsotropicAntennaModel>()));
221 nrHelper->SetGnbAntennaAttribute(
"NumRows", UintegerValue(4));
222 nrHelper->SetGnbAntennaAttribute(
"NumColumns", UintegerValue(8));
223 nrHelper->SetGnbAntennaAttribute(
"AntennaElement",
224 PointerValue(CreateObject<IsotropicAntennaModel>()));
227 nrHelper->SetSchedulerAttribute(
"FixedMcsDl", BooleanValue(
true));
228 nrHelper->SetSchedulerAttribute(
"FixedMcsUl", BooleanValue(
true));
229 nrHelper->SetSchedulerAttribute(
"StartingMcsDl", UintegerValue(mcs));
230 nrHelper->SetSchedulerAttribute(
"StartingMcsUl", UintegerValue(mcs));
233 nrHelper->SetUlErrorModel(errorModel);
234 nrHelper->SetDlErrorModel(errorModel);
241 nrHelper->SetUePhyAttribute(
"TxPower", DoubleValue(totalTxPower));
246 nrHelper->SetGnbBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
249 nrHelper->SetUeBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
251 NetDeviceContainer gnbNetDev = nrHelper->InstallGnbDevice(gNbNodes, allBwps);
252 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNodes, allBwps);
254 int64_t randomStream = 1;
255 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
256 randomStream += nrHelper->AssignStreams(ueNetDev, randomStream);
265 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)
266 ->SetAttribute(
"Numerology", UintegerValue(numerologyBwp));
267 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetAttribute(
"TxPower", DoubleValue(totalTxPower));
271 auto [remoteHost, remoteHostIpv4Address] =
272 nrEpcHelper->SetupRemoteHost(
"100Gb/s", 2500, Seconds(0.000));
273 NodeContainer remoteHostContainer(remoteHost);
275 InternetStackHelper internet;
276 internet.Install(ueNodes);
277 Ipv4InterfaceContainer ueIpIface;
278 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
281 uint16_t dlPort = 1234;
282 UdpServerHelper dlPacketSinkHelper(dlPort);
283 ApplicationContainer txApps;
284 ApplicationContainer sinkApps;
285 NodeContainer txNodes;
286 NodeContainer sinkNodes;
287 std::vector<Ipv4Address> sinkIps;
291 sinkIps.push_back(remoteHostIpv4Address);
292 sinkNodes = remoteHostContainer;
297 sinkIps.resize(ueIpIface.GetN());
298 for (uint32_t i = 0; i < ueIpIface.GetN(); i++)
300 sinkIps[i] = ueIpIface.GetAddress(i);
303 txNodes = remoteHostContainer;
307 for (uint32_t i = 0; i < txNodes.GetN(); ++i)
309 for (uint32_t j = 0; j < sinkNodes.GetN(); ++j)
311 UdpClientHelper dlClient(sinkIps[j], dlPort);
312 dlClient.SetAttribute(
"MaxPackets", UintegerValue(packets));
313 dlClient.SetAttribute(
"PacketSize", UintegerValue(pktSize));
314 dlClient.SetAttribute(
"Interval", TimeValue(packetInterval));
316 txApps.Add(dlClient.Install(txNodes.Get(i)));
320 sinkApps.Add(dlPacketSinkHelper.Install(sinkNodes));
321 for (uint32_t j = 0; j < sinkApps.GetN(); ++j)
323 Ptr<UdpServer> client = DynamicCast<UdpServer>(sinkApps.Get(j));
324 NS_ASSERT(client !=
nullptr);
325 std::stringstream ss;
327 client->TraceConnect(
"Rx", ss.str(), MakeCallback(&PrintRxPkt));
331 sinkApps.Start(udpAppStartTime);
332 txApps.Start(udpAppStartTime);
333 sinkApps.Stop(Seconds(simTime));
334 txApps.Stop(Seconds(simTime));
337 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
342 Simulator::Stop(Seconds(simTime));
344 auto start = std::chrono::steady_clock::now();
348 auto end = std::chrono::steady_clock::now();
352 for (
auto& v : packetsTime)
360 std::cout <<
"Packets received: " << packetsTime.size() << std::endl;
361 std::cout <<
"Counter (packets not affected by reordering): " << +cont << std::endl;
363 if (!packetsTime.empty() && cont > 0)
365 std::cout <<
"Average e2e latency (over all received packets): " << sum / packetsTime.size()
366 <<
" us" << std::endl;
367 std::cout <<
"Average e2e latency (over counter): " << sum / cont <<
" us" << std::endl;
371 std::cout <<
"Average e2e latency: Not Available" << std::endl;
374 for (
auto it = sinkApps.Begin(); it != sinkApps.End(); ++it)
376 uint64_t recv = DynamicCast<UdpServer>(*it)->GetReceived();
377 std::cout <<
"Sent: " << packets <<
" Recv: " << recv <<
" Lost: " << packets - recv
378 <<
" pkts, ( " << (
static_cast<double>(packets - recv) / packets) * 100.0
379 <<
" % )" << std::endl;
382 Simulator::Destroy();
384 std::cout <<
"Running time: "
385 << std::chrono::duration_cast<std::chrono::seconds>(end - start).count() <<
" s."
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.
@ ShannonModel
Shannon based model (very conservative)
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.