5G-LENA nr-v3.3-120-gdac69c56
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 Ptr<Node> pgw = nrEpcHelper->GetPgwNode();
122 NodeContainer remoteHostContainer;
123 remoteHostContainer.Create(1);
124 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
125 InternetStackHelper internet;
126 internet.Install(remoteHostContainer);
127
128 // connect a remoteHost to pgw. Setup routing too
129 PointToPointHelper p2ph;
130 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
131 p2ph.SetDeviceAttribute("Mtu", UintegerValue(2500));
132 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
133 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
134 Ipv4AddressHelper ipv4h;
135 ipv4h.SetBase("1.0.0.0", "255.0.0.0");
136 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
137 Ipv4StaticRoutingHelper ipv4RoutingHelper;
138 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
139 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
140 remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
141 internet.Install(ueNode);
142 Ipv4InterfaceContainer ueIpIface;
143 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
144 // assign IP address to UEs, and install UDP downlink applications
145 uint16_t dlPort = 1234;
146 ApplicationContainer clientApps;
147 ApplicationContainer serverApps;
148
149 Ptr<Node> ue = ueNode.Get(0);
150 // Set the default gateway for the UE
151 Ptr<Ipv4StaticRouting> ueStaticRouting =
152 ipv4RoutingHelper.GetStaticRouting(ue->GetObject<Ipv4>());
153 ueStaticRouting->SetDefaultRoute(nrEpcHelper->GetUeDefaultGatewayAddress(), 1);
154
155 UdpServerHelper dlPacketSinkHelper(dlPort);
156 serverApps.Add(dlPacketSinkHelper.Install(ueNode.Get(0)));
157
158 UdpClientHelper dlClient(ueIpIface.GetAddress(0), dlPort);
159 dlClient.SetAttribute("Interval", TimeValue(MicroSeconds(10000)));
160 dlClient.SetAttribute("MaxPackets", UintegerValue(0xFFFFFFFF));
161 clientApps.Add(dlClient.Install(remoteHost));
162
163 // start server and client apps
164 serverApps.Start(MilliSeconds(400));
165 clientApps.Start(MilliSeconds(400));
166 serverApps.Stop(MilliSeconds(800));
167 clientApps.Stop(MilliSeconds(800));
168
169 // attach UEs to the closest gNB
170 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
171
172 Simulator::Stop(MilliSeconds(800));
173 Simulator::Run();
174 Simulator::Destroy();
175
176 // A wide variety of test macros are available in src/core/test.h
177 NS_TEST_ASSERT_MSG_EQ(true, true, "true doesn't equal true for some reason");
178 // Use this one for floating point comparisons
179 NS_TEST_ASSERT_MSG_EQ_TOL(0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
180}
181
182class NrSystemTestConfigurationsTestSuite : public TestSuite
183{
184 public:
185 NrSystemTestConfigurationsTestSuite();
186};
187
188NrSystemTestConfigurationsTestSuite::NrSystemTestConfigurationsTestSuite()
189 : TestSuite("nr-system-test-configurations", Type::SYSTEM)
190{
191 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=rr",
192 0,
193 "ns3::NrMacSchedulerTdmaRR"),
194 Duration::QUICK);
195 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=rr",
196 2,
197 "ns3::NrMacSchedulerTdmaRR"),
198 Duration::QUICK);
199 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=rr",
200 4,
201 "ns3::NrMacSchedulerTdmaRR"),
202 Duration::QUICK);
203
204 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=pf",
205 0,
206 "ns3::NrMacSchedulerTdmaPF"),
207 Duration::QUICK);
208 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=pf",
209 2,
210 "ns3::NrMacSchedulerTdmaPF"),
211 Duration::QUICK);
212 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=pf",
213 4,
214 "ns3::NrMacSchedulerTdmaPF"),
215 Duration::QUICK);
216
217 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=mr",
218 0,
219 "ns3::NrMacSchedulerTdmaMR"),
220 Duration::QUICK);
221 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=mr",
222 2,
223 "ns3::NrMacSchedulerTdmaMR"),
224 Duration::QUICK);
225 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=mr",
226 4,
227 "ns3::NrMacSchedulerTdmaMR"),
228 Duration::QUICK);
229}
230
231// Do not forget to allocate an instance of this TestSuite
232static 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.