5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
cttc-3gpp-channel-example.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
18#include "ns3/antenna-module.h"
19#include "ns3/applications-module.h"
20#include "ns3/buildings-helper.h"
21#include "ns3/config-store.h"
22#include "ns3/core-module.h"
23#include "ns3/internet-module.h"
24#include "ns3/ipv4-global-routing-helper.h"
25#include "ns3/log.h"
26#include "ns3/mobility-module.h"
27#include "ns3/nr-helper.h"
28#include "ns3/nr-mac-scheduler-tdma-rr.h"
29#include "ns3/nr-module.h"
30#include "ns3/nr-point-to-point-epc-helper.h"
31#include "ns3/point-to-point-helper.h"
32
33using namespace ns3;
34
35int
36main(int argc, char* argv[])
37{
38 std::string scenario = "UMa"; // scenario
39 double frequency = 28e9; // central frequency
40 double bandwidth = 100e6; // bandwidth
41 double mobility = false; // whether to enable mobility
42 double simTime = 1; // in second
43 double speed = 1; // in m/s for walking UT.
44 bool logging = true; // whether to enable logging from the simulation, another option is by
45 // exporting the NS_LOG environment variable
46 double hBS; // base station antenna height in meters
47 double hUT; // user antenna height in meters
48 double txPower = 40; // txPower
49
50 CommandLine cmd(__FILE__);
51 cmd.AddValue("scenario",
52 "The scenario for the simulation. Choose among 'RMa', 'UMa', 'UMi', "
53 "'InH-OfficeMixed', 'InH-OfficeOpen'.",
54 scenario);
55 cmd.AddValue("frequency", "The central carrier frequency in Hz.", frequency);
56 cmd.AddValue("mobility",
57 "If set to 1 UEs will be mobile, when set to 0 UE will be static. By default, "
58 "they are mobile.",
59 mobility);
60 cmd.AddValue("logging", "If set to 0, log components will be disabled.", logging);
61 cmd.Parse(argc, argv);
62
63 // enable logging
64 if (logging)
65 {
66 // LogComponentEnable ("ThreeGppSpectrumPropagationLossModel", LOG_LEVEL_ALL);
67 LogComponentEnable("ThreeGppPropagationLossModel", LOG_LEVEL_ALL);
68 // LogComponentEnable ("ThreeGppChannelModel", LOG_LEVEL_ALL);
69 // LogComponentEnable ("ChannelConditionModel", LOG_LEVEL_ALL);
70 // LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
71 // LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
72 // LogComponentEnable ("NrRlcUm", LOG_LEVEL_LOGIC);
73 // LogComponentEnable ("NrPdcp", LOG_LEVEL_INFO);
74 }
75
76 /*
77 * Default values for the simulation. We are progressively removing all
78 * the instances of SetDefault, but we need it for legacy code (LTE)
79 */
80 Config::SetDefault("ns3::NrRlcUm::MaxTxBufferSize", UintegerValue(999999999));
81
82 // set mobile device and base station antenna heights in meters, according to the chosen
83 // scenario
84 if (scenario == "RMa")
85 {
86 hBS = 35;
87 hUT = 1.5;
88 }
89 else if (scenario == "UMa")
90 {
91 hBS = 25;
92 hUT = 1.5;
93 }
94 else if (scenario == "UMi-StreetCanyon")
95 {
96 hBS = 10;
97 hUT = 1.5;
98 }
99 else if (scenario == "InH-OfficeMixed" || scenario == "InH-OfficeOpen")
100 {
101 hBS = 3;
102 hUT = 1;
103 }
104 else
105 {
106 NS_ABORT_MSG("Scenario not supported. Choose among 'RMa', 'UMa', 'UMi', "
107 "'InH-OfficeMixed', and 'InH-OfficeOpen'.");
108 }
109
110 // create base stations and mobile terminals
111 NodeContainer gnbNodes;
112 NodeContainer ueNodes;
113 gnbNodes.Create(2);
114 ueNodes.Create(2);
115
116 // position the base stations
117 Ptr<ListPositionAllocator> gnbPositionAlloc = CreateObject<ListPositionAllocator>();
118 gnbPositionAlloc->Add(Vector(0.0, 0.0, hBS));
119 gnbPositionAlloc->Add(Vector(0.0, 80.0, hBS));
120 MobilityHelper gnbMobility;
121 gnbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
122 gnbMobility.SetPositionAllocator(gnbPositionAlloc);
123 gnbMobility.Install(gnbNodes);
124
125 // position the mobile terminals and enable the mobility
126 MobilityHelper uemobility;
127 uemobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
128 uemobility.Install(ueNodes);
129
130 if (mobility)
131 {
132 ueNodes.Get(0)->GetObject<MobilityModel>()->SetPosition(
133 Vector(90, 15, hUT)); // (x, y, z) in m
134 ueNodes.Get(0)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(
135 Vector(0, speed, 0)); // move UE1 along the y axis
136
137 ueNodes.Get(1)->GetObject<MobilityModel>()->SetPosition(
138 Vector(30, 50.0, hUT)); // (x, y, z) in m
139 ueNodes.Get(1)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(
140 Vector(-speed, 0, 0)); // move UE2 along the x axis
141 }
142 else
143 {
144 ueNodes.Get(0)->GetObject<MobilityModel>()->SetPosition(Vector(90, 15, hUT));
145 ueNodes.Get(0)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(Vector(0, 0, 0));
146
147 ueNodes.Get(1)->GetObject<MobilityModel>()->SetPosition(Vector(30, 50.0, hUT));
148 ueNodes.Get(1)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(Vector(0, 0, 0));
149 }
150
151 /*
152 * Create NR simulation helpers
153 */
154 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
155 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
156 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
157 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
158 nrHelper->SetEpcHelper(nrEpcHelper);
159
160 /*
161 * Spectrum configuration. We create a single operational band and configure the scenario.
162 */
163
165 CcBwpCreator ccBwpCreator;
166 const uint8_t numCcPerBand = 1; // in this example we have a single band, and that band is
167 // composed of a single component carrier
168
169 /* Create the configuration for the CcBwpHelper. SimpleOperationBandConf creates
170 * a single BWP per CC and a single BWP in CC.
171 *
172 * Hence, the configured spectrum is:
173 *
174 * |---------------Band---------------|
175 * |---------------CC-----------------|
176 * |---------------BWP----------------|
177 */
178 CcBwpCreator::SimpleOperationBandConf bandConf(frequency, bandwidth, numCcPerBand);
179 OperationBandInfo band = ccBwpCreator.CreateOperationBandContiguousCc(bandConf);
180 // Create the channel helper
181 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
182 // Set and configure the channel to the current band
183 channelHelper->ConfigureFactories(
184 scenario,
185 "Default",
186 "ThreeGpp"); // Configure the spectrum channel with the scenario
187 channelHelper->AssignChannelsToBands({band});
188 allBwps = CcBwpCreator::GetAllBwps({band});
189
190 // Configure ideal beamforming method
191 idealBeamformingHelper->SetAttribute("BeamformingMethod",
192 TypeIdValue(DirectPathBeamforming::GetTypeId()));
193
194 // Configure scheduler
195 nrHelper->SetSchedulerTypeId(NrMacSchedulerTdmaRR::GetTypeId());
196
197 // Antennas for the UEs
198 nrHelper->SetUeAntennaAttribute("NumRows", UintegerValue(2));
199 nrHelper->SetUeAntennaAttribute("NumColumns", UintegerValue(4));
200 nrHelper->SetUeAntennaAttribute("AntennaElement",
201 PointerValue(CreateObject<IsotropicAntennaModel>()));
202
203 // Antennas for the gNbs
204 nrHelper->SetGnbAntennaAttribute("NumRows", UintegerValue(8));
205 nrHelper->SetGnbAntennaAttribute("NumColumns", UintegerValue(8));
206 nrHelper->SetGnbAntennaAttribute("AntennaElement",
207 PointerValue(CreateObject<IsotropicAntennaModel>()));
208
209 // install nr net devices
210 NetDeviceContainer gnbNetDev = nrHelper->InstallGnbDevice(gnbNodes, allBwps);
211 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNodes, allBwps);
212
213 int64_t randomStream = 1;
214 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
215 randomStream += nrHelper->AssignStreams(ueNetDev, randomStream);
216
217 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)->SetTxPower(txPower);
218 nrHelper->GetGnbPhy(gnbNetDev.Get(1), 0)->SetTxPower(txPower);
219
220 // create the internet and install the IP stack on the UEs
221 // get SGW/PGW and create a single RemoteHost
222 auto [remoteHost, remoteHostIpv4Address] =
223 nrEpcHelper->SetupRemoteHost("100Gb/s", 2500, Seconds(0.010));
224
225 InternetStackHelper internet;
226 internet.Install(ueNodes);
227
228 Ipv4InterfaceContainer ueIpIface;
229 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
230
231 // assign IP address to UEs, and install UDP downlink applications
232 uint16_t dlPort = 1234;
233 ApplicationContainer clientApps;
234 ApplicationContainer serverApps;
235 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
236 {
237 Ptr<Node> ueNode = ueNodes.Get(u);
238 UdpServerHelper dlPacketSinkHelper(dlPort);
239 serverApps.Add(dlPacketSinkHelper.Install(ueNodes.Get(u)));
240
241 UdpClientHelper dlClient(ueIpIface.GetAddress(u), dlPort);
242 dlClient.SetAttribute("Interval", TimeValue(MicroSeconds(1)));
243 // dlClient.SetAttribute ("MaxPackets", UintegerValue(0xFFFFFFFF));
244 dlClient.SetAttribute("MaxPackets", UintegerValue(10));
245 dlClient.SetAttribute("PacketSize", UintegerValue(1500));
246 clientApps.Add(dlClient.Install(remoteHost));
247 }
248
249 // attach UEs to the closest gNB
250 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
251
252 // start server and client apps
253 serverApps.Start(Seconds(0.4));
254 clientApps.Start(Seconds(0.4));
255 serverApps.Stop(Seconds(simTime));
256 clientApps.Stop(Seconds(simTime - 0.2));
257
258 // enable the traces provided by the nr module
259 nrHelper->EnableTraces();
260
261 Simulator::Stop(Seconds(simTime));
262 Simulator::Run();
263
264 Ptr<UdpServer> serverApp = serverApps.Get(0)->GetObject<UdpServer>();
265 uint64_t receivedPackets = serverApp->GetReceived();
266
267 Simulator::Destroy();
268
269 if (receivedPackets == 10)
270 {
271 return EXIT_SUCCESS;
272 }
273 else
274 {
275 return EXIT_FAILURE;
276 }
277}
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.
static TypeId GetTypeId()
GetTypeId.
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.