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"
62NS_LOG_COMPONENT_DEFINE(
"CttcErrorModelAmcExample");
64static Ptr<ListPositionAllocator>
65GetGnbPositions(
double gNbHeight = 10.0)
67 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
68 pos->Add(Vector(0.0, 0.0, gNbHeight));
73static Ptr<ListPositionAllocator>
74GetUePositions(
double ueY,
double ueHeight = 1.5)
76 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
77 pos->Add(Vector(0.0, ueY, ueHeight));
82static std::vector<uint64_t> packetsTime;
85PrintRxPkt([[maybe_unused]] std::string context, Ptr<const Packet> pkt)
89 pkt->PeekHeader(seqTs);
90 packetsTime.push_back((Simulator::Now() - seqTs.GetTs()).GetMicroSeconds());
94main(
int argc,
char* argv[])
96 const uint8_t gNbNum = 1;
97 const uint8_t ueNum = 1;
98 double totalTxPower = 4;
99 uint16_t numerologyBwp = 4;
100 double centralFrequencyBand = 28e9;
101 double bandwidthBand = 100e6;
104 double simTime = 5.0;
105 uint32_t pktSize = 500;
106 Time udpAppStartTime = MilliSeconds(1000);
107 Time packetInterval = MilliSeconds(200);
108 Time updateChannelInterval = MilliSeconds(0);
110 std::string errorModel =
"ns3::NrEesmCcT1";
112 CommandLine cmd(__FILE__);
114 cmd.AddValue(
"simTime",
"Simulation time", simTime);
115 cmd.AddValue(
"errorModelType",
116 "Error model type: ns3::NrEesmCcT1, ns3::NrEesmCcT2, ns3::NrEesmIrT1, "
117 "ns3::NrEesmIrT2, ns3::NrLteMiErrorModel",
119 cmd.AddValue(
"ueY",
"Y position of any UE", ueY);
120 cmd.AddValue(
"pktSize",
"Packet Size", pktSize);
122 cmd.Parse(argc, argv);
124 uint32_t packets = (simTime - udpAppStartTime.GetSeconds()) / packetInterval.GetSeconds();
125 NS_ABORT_IF(packets == 0);
131 Config::SetDefault(
"ns3::NrRlcUm::MaxTxBufferSize", UintegerValue(999999999));
137 Config::SetDefault(
"ns3::NrAmc::ErrorModelType", TypeIdValue(TypeId::LookupByName(errorModel)));
138 Config::SetDefault(
"ns3::NrAmc::AmcModel",
142 NodeContainer gNbNodes;
143 NodeContainer ueNodes;
144 MobilityHelper mobility;
146 double gNbHeight = 10.0;
147 double ueHeight = 1.5;
149 gNbNodes.Create(gNbNum);
150 ueNodes.Create(ueNum);
152 Ptr<ListPositionAllocator> gNbPositionAlloc = GetGnbPositions(gNbHeight);
153 Ptr<ListPositionAllocator> uePositionAlloc = GetUePositions(ueY, ueHeight);
155 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
156 mobility.SetPositionAllocator(gNbPositionAlloc);
157 mobility.Install(gNbNodes);
159 mobility.SetPositionAllocator(uePositionAlloc);
160 mobility.Install(ueNodes);
171 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
172 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
173 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
174 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
176 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
177 nrHelper->SetEpcHelper(nrEpcHelper);
179 channelHelper->ConfigureFactories(
"UMi",
"Default",
"ThreeGpp");
187 const uint8_t numCcPerBand = 1;
194 Config::SetDefault(
"ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(updateChannelInterval));
195 channelHelper->SetChannelConditionModelAttribute(
"UpdatePeriod", TimeValue(MilliSeconds(0)));
196 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(
false));
228 nrHelper->SetSchedulerAttribute(
"FixedMcsUl", BooleanValue(
false));
231 nrHelper->SetUlErrorModel(errorModel);
232 nrHelper->SetDlErrorModel(errorModel);
235 nrHelper->SetGnbDlAmcAttribute(
238 nrHelper->SetGnbUlAmcAttribute(
245 nrHelper->SetGnbBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
248 nrHelper->SetUeBwpManagerAlgorithmAttribute(
"NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
250 NetDeviceContainer gnbNetDev = nrHelper->InstallGnbDevice(gNbNodes, allBwps);
251 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNodes, allBwps);
253 int64_t randomStream = 1;
254 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
255 randomStream += nrHelper->AssignStreams(ueNetDev, randomStream);
264 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)
265 ->SetAttribute(
"Numerology", UintegerValue(numerologyBwp));
266 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetAttribute(
"TxPower", DoubleValue(totalTxPower));
270 auto [remoteHost, remoteHostIpv4Address] =
271 nrEpcHelper->SetupRemoteHost(
"100Gb/s", 2500, Seconds(0.000));
273 InternetStackHelper internet;
275 internet.Install(ueNodes);
276 Ipv4InterfaceContainer ueIpIface;
277 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
280 uint16_t dlPort = 1234;
281 ApplicationContainer clientApps;
282 ApplicationContainer serverApps;
284 ApplicationContainer clientAppsEmbb;
285 ApplicationContainer serverAppsEmbb;
287 UdpServerHelper dlPacketSinkHelper(dlPort);
288 serverApps.Add(dlPacketSinkHelper.Install(ueNodes));
291 for (uint32_t j = 0; j < ueNodes.GetN(); ++j)
293 UdpClientHelper dlClient(ueIpIface.GetAddress(j), dlPort);
294 dlClient.SetAttribute(
"MaxPackets", UintegerValue(packets));
295 dlClient.SetAttribute(
"PacketSize", UintegerValue(pktSize));
296 dlClient.SetAttribute(
"Interval", TimeValue(packetInterval));
298 clientApps.Add(dlClient.Install(remoteHost));
301 for (uint32_t j = 0; j < serverApps.GetN(); ++j)
303 Ptr<UdpServer> client = DynamicCast<UdpServer>(serverApps.Get(j));
304 NS_ASSERT(client !=
nullptr);
305 std::stringstream ss;
307 client->TraceConnect(
"Rx", ss.str(), MakeCallback(&PrintRxPkt));
311 serverApps.Start(udpAppStartTime);
312 clientApps.Start(udpAppStartTime);
313 serverApps.Stop(Seconds(simTime));
314 clientApps.Stop(Seconds(simTime));
317 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
322 Simulator::Stop(Seconds(simTime));
324 auto start = std::chrono::steady_clock::now();
328 auto end = std::chrono::steady_clock::now();
332 for (
auto& v : packetsTime)
340 std::cout <<
"Packets received: " << packetsTime.size() << std::endl;
341 std::cout <<
"Counter (packets not affected by reordering): " << +cont << std::endl;
343 if (!packetsTime.empty() && cont > 0)
345 std::cout <<
"Average e2e latency (over all received packets): " << sum / packetsTime.size()
346 <<
" us" << std::endl;
347 std::cout <<
"Average e2e latency (over counter): " << sum / cont <<
" us" << std::endl;
351 std::cout <<
"Average e2e latency: Not Available" << std::endl;
354 for (
auto it = serverApps.Begin(); it != serverApps.End(); ++it)
356 uint64_t recv = DynamicCast<UdpServer>(*it)->GetReceived();
357 std::cout <<
"Sent: " << packets <<
" Recv: " << recv <<
" Lost: " << packets - recv
358 <<
" pkts, ( " << (
static_cast<double>(packets - recv) / packets) * 100.0
359 <<
" % )" << std::endl;
362 Simulator::Destroy();
364 std::cout <<
"Running time: "
365 << 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.
@ ErrorModel
Error Model version (can use different error models, see NrErrorModel)
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.