5G-LENA nr-v4.1
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-system-test-configurations.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 a header file from your module to test.
6#include "ns3/applications-module.h"
7#include "ns3/config-store-module.h"
8#include "ns3/core-module.h"
9#include "ns3/internet-module.h"
10#include "ns3/mobility-module.h"
11#include "ns3/network-module.h"
12#include "ns3/nr-module.h"
13#include "ns3/point-to-point-helper.h"
14
15using namespace ns3;
16
24// This is an example TestCase.
25class NrSystemTestConfigurationsTestCase1 : public TestCase
26{
27 public:
28 NrSystemTestConfigurationsTestCase1(std::string name,
29 uint32_t numerology,
30 std::string scheduler);
31 ~NrSystemTestConfigurationsTestCase1() override;
32
33 private:
34 void DoRun() override;
35
36 uint32_t m_numerology;
37 std::string m_scheduler;
38};
39
40NrSystemTestConfigurationsTestCase1::NrSystemTestConfigurationsTestCase1(std::string name,
41 uint32_t numerology,
42 std::string scheduler)
43 : TestCase(name)
44{
45 m_numerology = numerology;
46 m_scheduler = scheduler;
47}
48
49NrSystemTestConfigurationsTestCase1::~NrSystemTestConfigurationsTestCase1()
50{
51}
52
53void
54NrSystemTestConfigurationsTestCase1::DoRun()
55{
56 // set mobile device and base station antenna heights in meters, according to the chosen
57 // scenario
58 double hBS = 35.0; // base station antenna height in meters;
59 double hUT = 1.5; // user antenna height in meters;
60
61 // create base stations and mobile terminals
62 NodeContainer gnbNode;
63 NodeContainer ueNode;
64 gnbNode.Create(1);
65 ueNode.Create(1);
66
67 // position the base stations
68 Ptr<ListPositionAllocator> gnbPositionAlloc = CreateObject<ListPositionAllocator>();
69 gnbPositionAlloc->Add(Vector(0.0, 0.0, hBS));
70
71 MobilityHelper gnbMobility;
72 gnbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
73 gnbMobility.SetPositionAllocator(gnbPositionAlloc);
74 gnbMobility.Install(gnbNode);
75
76 // position the mobile terminals and enable the mobility
77 MobilityHelper uemobility;
78 uemobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
79 uemobility.Install(ueNode);
80
81 ueNode.Get(0)->GetObject<MobilityModel>()->SetPosition(Vector(0, 10, hUT));
82
83 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
84 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
85 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
86
87 // Put the pointers inside nrHelper
88 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
89 nrHelper->SetEpcHelper(nrEpcHelper);
90 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
91 // Set the channel with UMi scenario
92 channelHelper->ConfigureFactories("UMi");
93 // Set spectrum attributes
94 Config::SetDefault("ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(MilliSeconds(100)));
95
96 channelHelper->SetChannelConditionModelAttribute("UpdatePeriod", TimeValue(MilliSeconds(100)));
97 channelHelper->SetPathlossAttribute("ShadowingEnabled", BooleanValue(false));
99 CcBwpCreator ccBwpCreator;
100 const uint8_t numCcPerBand = 1; // in this example, both bands have a single CC
101
102 // Create the configuration for the CcBwpHelper. SimpleOperationBandConf creates
103 // a single BWP per CC
104 CcBwpCreator::SimpleOperationBandConf bandConf1(28e9, 100e6, numCcPerBand);
105
106 // By using the configuration created, it is time to make the operation bands
107 OperationBandInfo band1 = ccBwpCreator.CreateOperationBandContiguousCc(bandConf1);
108 // Set the channel for the band
109 channelHelper->AssignChannelsToBands({band1});
110 allBwps = CcBwpCreator::GetAllBwps({band1});
111
112 nrHelper->SetGnbPhyAttribute("Numerology", UintegerValue(m_numerology));
113 nrHelper->SetSchedulerTypeId(TypeId::LookupByName(m_scheduler));
114
115 // install nr net devices
116 NetDeviceContainer gnbNetDev = nrHelper->InstallGnbDevice(gnbNode, allBwps);
117 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNode, allBwps);
118
119 // create the internet and install the IP stack on the UEs
120 // get SGW/PGW and create a single RemoteHost
121 auto [remoteHost, remoteHostIpv4Address] =
122 nrEpcHelper->SetupRemoteHost("100Gb/s", 2500, Seconds(0.000));
123
124 InternetStackHelper internet;
125 internet.Install(ueNode);
126 Ipv4InterfaceContainer ueIpIface;
127 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
128
129 // assign IP address to UEs, and install UDP downlink applications
130 uint16_t dlPort = 1234;
131 ApplicationContainer clientApps;
132 ApplicationContainer serverApps;
133
134 UdpServerHelper dlPacketSinkHelper(dlPort);
135 serverApps.Add(dlPacketSinkHelper.Install(ueNode.Get(0)));
136
137 UdpClientHelper dlClient(ueIpIface.GetAddress(0), dlPort);
138 dlClient.SetAttribute("Interval", TimeValue(MicroSeconds(10000)));
139 dlClient.SetAttribute("MaxPackets", UintegerValue(0xFFFFFFFF));
140 clientApps.Add(dlClient.Install(remoteHost));
141
142 // start server and client apps
143 serverApps.Start(MilliSeconds(400));
144 clientApps.Start(MilliSeconds(400));
145 serverApps.Stop(MilliSeconds(800));
146 clientApps.Stop(MilliSeconds(800));
147
148 // attach UEs to the closest gNB
149 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
150
151 Simulator::Stop(MilliSeconds(800));
152 Simulator::Run();
153 Simulator::Destroy();
154
155 // A wide variety of test macros are available in src/core/test.h
156 NS_TEST_ASSERT_MSG_EQ(true, true, "true doesn't equal true for some reason");
157 // Use this one for floating point comparisons
158 NS_TEST_ASSERT_MSG_EQ_TOL(0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
159}
160
161class NrSystemTestConfigurationsTestSuite : public TestSuite
162{
163 public:
164 NrSystemTestConfigurationsTestSuite();
165};
166
167NrSystemTestConfigurationsTestSuite::NrSystemTestConfigurationsTestSuite()
168 : TestSuite("nr-system-test-configurations", Type::SYSTEM)
169{
170 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=rr",
171 0,
172 "ns3::NrMacSchedulerTdmaRR"),
173 Duration::QUICK);
174 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=rr",
175 2,
176 "ns3::NrMacSchedulerTdmaRR"),
177 Duration::QUICK);
178 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=rr",
179 4,
180 "ns3::NrMacSchedulerTdmaRR"),
181 Duration::QUICK);
182
183 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=pf",
184 0,
185 "ns3::NrMacSchedulerTdmaPF"),
186 Duration::QUICK);
187 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=pf",
188 2,
189 "ns3::NrMacSchedulerTdmaPF"),
190 Duration::QUICK);
191 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=pf",
192 4,
193 "ns3::NrMacSchedulerTdmaPF"),
194 Duration::QUICK);
195
196 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=mr",
197 0,
198 "ns3::NrMacSchedulerTdmaMR"),
199 Duration::QUICK);
200 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=mr",
201 2,
202 "ns3::NrMacSchedulerTdmaMR"),
203 Duration::QUICK);
204 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=mr",
205 4,
206 "ns3::NrMacSchedulerTdmaMR"),
207 Duration::QUICK);
208}
209
210// Do not forget to allocate an instance of this TestSuite
211static NrSystemTestConfigurationsTestSuite nrTestSuite;
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.
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.