5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
cttc-error-model-amc.cc
Go to the documentation of this file.
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
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"
11#include "ns3/log.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"
17
18#include <chrono>
19
60using namespace ns3;
61
62NS_LOG_COMPONENT_DEFINE("CttcErrorModelAmcExample");
63
64static Ptr<ListPositionAllocator>
65GetGnbPositions(double gNbHeight = 10.0)
66{
67 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
68 pos->Add(Vector(0.0, 0.0, gNbHeight));
69
70 return pos;
71}
72
73static Ptr<ListPositionAllocator>
74GetUePositions(double ueY, double ueHeight = 1.5)
75{
76 Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator>();
77 pos->Add(Vector(0.0, ueY, ueHeight));
78
79 return pos;
80}
81
82static std::vector<uint64_t> packetsTime;
83
84static void
85PrintRxPkt([[maybe_unused]] std::string context, Ptr<const Packet> pkt)
86{
87 // ASSUMING ONE UE
88 SeqTsHeader seqTs;
89 pkt->PeekHeader(seqTs);
90 packetsTime.push_back((Simulator::Now() - seqTs.GetTs()).GetMicroSeconds());
91}
92
93int
94main(int argc, char* argv[])
95{
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;
102 double ueY = 30.0;
103
104 double simTime = 5.0; // 5 seconds: to give time AMC to stabilize
105 uint32_t pktSize = 500;
106 Time udpAppStartTime = MilliSeconds(1000);
107 Time packetInterval = MilliSeconds(200);
108 Time updateChannelInterval = MilliSeconds(0); // no channel updates to test AMC
109
110 std::string errorModel = "ns3::NrEesmCcT1";
111
112 CommandLine cmd(__FILE__);
113
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",
118 errorModel);
119 cmd.AddValue("ueY", "Y position of any UE", ueY);
120 cmd.AddValue("pktSize", "Packet Size", pktSize);
121
122 cmd.Parse(argc, argv);
123
124 uint32_t packets = (simTime - udpAppStartTime.GetSeconds()) / packetInterval.GetSeconds();
125 NS_ABORT_IF(packets == 0);
126
127 /*
128 * Default values for the simulation. We are progressively removing all
129 * the instances of SetDefault, but we need it for legacy code (LTE)
130 */
131 Config::SetDefault("ns3::NrRlcUm::MaxTxBufferSize", UintegerValue(999999999));
132
133 /*
134 * TODO: remove all the instances of SetDefault, NrEesmErrorModel, NrAmc
135 */
136
137 Config::SetDefault("ns3::NrAmc::ErrorModelType", TypeIdValue(TypeId::LookupByName(errorModel)));
138 Config::SetDefault("ns3::NrAmc::AmcModel",
139 EnumValue(NrAmc::ErrorModel)); // NrAmc::ShannonModel or NrAmc::ErrorModel
140
141 // create base stations and mobile terminals
142 NodeContainer gNbNodes;
143 NodeContainer ueNodes;
144 MobilityHelper mobility;
145
146 double gNbHeight = 10.0;
147 double ueHeight = 1.5;
148
149 gNbNodes.Create(gNbNum);
150 ueNodes.Create(ueNum);
151
152 Ptr<ListPositionAllocator> gNbPositionAlloc = GetGnbPositions(gNbHeight);
153 Ptr<ListPositionAllocator> uePositionAlloc = GetUePositions(ueY, ueHeight);
154
155 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
156 mobility.SetPositionAllocator(gNbPositionAlloc);
157 mobility.Install(gNbNodes);
158
159 mobility.SetPositionAllocator(uePositionAlloc);
160 mobility.Install(ueNodes);
161
162 /*
163 * Setup the NR module. We create the various helpers needed for the
164 * NR simulation:
165 * - nrEpcHelper, which will setup the core network
166 * - IdealBeamformingHelper, which takes care of the beamforming part
167 * - NrHelper, which takes care of creating and connecting the various
168 * part of the NR stack
169 * - NrChannelHelper, which will setup the spectrum channel
170 */
171 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
172 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
173 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
174 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
175 // Put the pointers inside nrHelper
176 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
177 nrHelper->SetEpcHelper(nrEpcHelper);
178 // Set the channel using UMi scenario, default channel condition and 3GPP channel model
179 channelHelper->ConfigureFactories("UMi", "Default", "ThreeGpp");
180
181 /*
182 * Spectrum division. We create one operational band, with one CC, and the CC with a single
183 * bandwidth part.
184 */
186 CcBwpCreator ccBwpCreator;
187 const uint8_t numCcPerBand = 1;
188
189 CcBwpCreator::SimpleOperationBandConf bandConf(centralFrequencyBand,
190 bandwidthBand,
191 numCcPerBand);
192 OperationBandInfo band = ccBwpCreator.CreateOperationBandContiguousCc(bandConf);
193 // Set channel features
194 Config::SetDefault("ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(updateChannelInterval));
195 channelHelper->SetChannelConditionModelAttribute("UpdatePeriod", TimeValue(MilliSeconds(0)));
196 channelHelper->SetPathlossAttribute("ShadowingEnabled", BooleanValue(false));
197 // Set the channel for the band
198 channelHelper->AssignChannelsToBands({band});
199 allBwps = CcBwpCreator::GetAllBwps({band});
200
201 Packet::EnableChecking();
202 Packet::EnablePrinting();
203
204 /*
205 * Case (i): Attributes valid for all the nodes
206 */
207 // Beamforming method
208 idealBeamformingHelper->SetAttribute("BeamformingMethod",
209 TypeIdValue(DirectPathBeamforming::GetTypeId()));
210
211 // Core latency
212 nrEpcHelper->SetAttribute("S1uLinkDelay", TimeValue(MilliSeconds(0)));
213
214 // Antennas for all the UEs
215 nrHelper->SetUeAntennaAttribute("NumRows", UintegerValue(2));
216 nrHelper->SetUeAntennaAttribute("NumColumns", UintegerValue(4));
217 nrHelper->SetUeAntennaAttribute("AntennaElement",
218 PointerValue(CreateObject<IsotropicAntennaModel>()));
219
220 // Antennas for all the gNbs
221 nrHelper->SetGnbAntennaAttribute("NumRows", UintegerValue(4));
222 nrHelper->SetGnbAntennaAttribute("NumColumns", UintegerValue(8));
223 nrHelper->SetGnbAntennaAttribute("AntennaElement",
224 PointerValue(CreateObject<IsotropicAntennaModel>()));
225
226 // Scheduler
227 nrHelper->SetSchedulerAttribute("FixedMcsDl", BooleanValue(false));
228 nrHelper->SetSchedulerAttribute("FixedMcsUl", BooleanValue(false));
229
230 // Error Model: UE and GNB with same spectrum error model.
231 nrHelper->SetUlErrorModel(errorModel);
232 nrHelper->SetDlErrorModel(errorModel);
233
234 // Both DL and UL AMC will have the same model behind.
235 nrHelper->SetGnbDlAmcAttribute(
236 "AmcModel",
237 EnumValue(NrAmc::ErrorModel)); // NrAmc::ShannonModel or NrAmc::ErrorModel
238 nrHelper->SetGnbUlAmcAttribute(
239 "AmcModel",
240 EnumValue(NrAmc::ErrorModel)); // NrAmc::ShannonModel or NrAmc::ErrorModel
241
242 uint32_t bwpId = 0;
243
244 // gNb routing between Bearer and bandwidh part
245 nrHelper->SetGnbBwpManagerAlgorithmAttribute("NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
246
247 // Ue routing between Bearer and bandwidth part
248 nrHelper->SetUeBwpManagerAlgorithmAttribute("NGBR_LOW_LAT_EMBB", UintegerValue(bwpId));
249
250 NetDeviceContainer gnbNetDev = nrHelper->InstallGnbDevice(gNbNodes, allBwps);
251 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNodes, allBwps);
252
253 int64_t randomStream = 1;
254 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
255 randomStream += nrHelper->AssignStreams(ueNetDev, randomStream);
256
257 /*
258 * Case (iii): Go node for node and change the attributes we have to setup
259 * per-node.
260 */
261
262 // Get the first netdevice (gnbNetDev.Get (0)) and the first bandwidth part (0)
263 // and set the attribute.
264 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)
265 ->SetAttribute("Numerology", UintegerValue(numerologyBwp));
266 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetAttribute("TxPower", DoubleValue(totalTxPower));
267
268 // create the internet and install the IP stack on the UEs
269 // get SGW/PGW and create a single RemoteHost
270 auto [remoteHost, remoteHostIpv4Address] =
271 nrEpcHelper->SetupRemoteHost("100Gb/s", 2500, Seconds(0.000));
272
273 InternetStackHelper internet;
274
275 internet.Install(ueNodes);
276 Ipv4InterfaceContainer ueIpIface;
277 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
278
279 // assign IP address to UEs, and install UDP downlink applications
280 uint16_t dlPort = 1234;
281 ApplicationContainer clientApps;
282 ApplicationContainer serverApps;
283
284 ApplicationContainer clientAppsEmbb;
285 ApplicationContainer serverAppsEmbb;
286
287 UdpServerHelper dlPacketSinkHelper(dlPort);
288 serverApps.Add(dlPacketSinkHelper.Install(ueNodes));
289
290 // configure here UDP traffic
291 for (uint32_t j = 0; j < ueNodes.GetN(); ++j)
292 {
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));
297
298 clientApps.Add(dlClient.Install(remoteHost));
299 }
300
301 for (uint32_t j = 0; j < serverApps.GetN(); ++j)
302 {
303 Ptr<UdpServer> client = DynamicCast<UdpServer>(serverApps.Get(j));
304 NS_ASSERT(client != nullptr);
305 std::stringstream ss;
306 ss << j;
307 client->TraceConnect("Rx", ss.str(), MakeCallback(&PrintRxPkt));
308 }
309
310 // start UDP server and client apps
311 serverApps.Start(udpAppStartTime);
312 clientApps.Start(udpAppStartTime);
313 serverApps.Stop(Seconds(simTime));
314 clientApps.Stop(Seconds(simTime));
315
316 // attach UEs to the closest gNB
317 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
318
319 // enable the traces provided by the nr module
320 // nrHelper->EnableTraces();
321
322 Simulator::Stop(Seconds(simTime));
323
324 auto start = std::chrono::steady_clock::now();
325
326 Simulator::Run();
327
328 auto end = std::chrono::steady_clock::now();
329
330 uint64_t sum = 0;
331 uint32_t cont = 0;
332 for (auto& v : packetsTime)
333 {
334 if (v < 100000)
335 {
336 sum += v;
337 cont++;
338 }
339 }
340 std::cout << "Packets received: " << packetsTime.size() << std::endl;
341 std::cout << "Counter (packets not affected by reordering): " << +cont << std::endl;
342
343 if (!packetsTime.empty() && cont > 0)
344 {
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;
348 }
349 else
350 {
351 std::cout << "Average e2e latency: Not Available" << std::endl;
352 }
353
354 for (auto it = serverApps.Begin(); it != serverApps.End(); ++it)
355 {
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;
360 }
361
362 Simulator::Destroy();
363
364 std::cout << "Running time: "
365 << std::chrono::duration_cast<std::chrono::seconds>(end - start).count() << " s."
366 << std::endl;
367 return 0;
368}
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.
static TypeId GetTypeId()
Get the type id.
@ ErrorModel
Error Model version (can use different error models, see NrErrorModel)
Definition nr-amc.h:81
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.