5G-LENA nr-v3.0-32-g83aee33
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/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7// Include a header file from your module to test.
8#include "ns3/applications-module.h"
9#include "ns3/config-store-module.h"
10#include "ns3/core-module.h"
11#include "ns3/internet-module.h"
12#include "ns3/mobility-module.h"
13#include "ns3/network-module.h"
14#include "ns3/nr-module.h"
15#include "ns3/point-to-point-helper.h"
16
17using namespace ns3;
18
26// This is an example TestCase.
27class NrSystemTestConfigurationsTestCase1 : public TestCase
28{
29 public:
30 NrSystemTestConfigurationsTestCase1(std::string name,
31 uint32_t numerology,
32 std::string scheduler);
33 ~NrSystemTestConfigurationsTestCase1() override;
34
35 private:
36 void DoRun() override;
37
38 uint32_t m_numerology;
39 std::string m_scheduler;
40};
41
42NrSystemTestConfigurationsTestCase1::NrSystemTestConfigurationsTestCase1(std::string name,
43 uint32_t numerology,
44 std::string scheduler)
45 : TestCase(name)
46{
47 m_numerology = numerology;
48 m_scheduler = scheduler;
49}
50
51NrSystemTestConfigurationsTestCase1::~NrSystemTestConfigurationsTestCase1()
52{
53}
54
55void
56NrSystemTestConfigurationsTestCase1::DoRun()
57{
58 // set mobile device and base station antenna heights in meters, according to the chosen
59 // scenario
60 double hBS = 35.0; // base station antenna height in meters;
61 double hUT = 1.5; // user antenna height in meters;
62
63 // create base stations and mobile terminals
64 NodeContainer enbNode;
65 NodeContainer ueNode;
66 enbNode.Create(1);
67 ueNode.Create(1);
68
69 // position the base stations
70 Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<ListPositionAllocator>();
71 enbPositionAlloc->Add(Vector(0.0, 0.0, hBS));
72
73 MobilityHelper enbmobility;
74 enbmobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
75 enbmobility.SetPositionAllocator(enbPositionAlloc);
76 enbmobility.Install(enbNode);
77
78 // position the mobile terminals and enable the mobility
79 MobilityHelper uemobility;
80 uemobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
81 uemobility.Install(ueNode);
82
83 ueNode.Get(0)->GetObject<MobilityModel>()->SetPosition(Vector(0, 10, hUT));
84
85 Ptr<NrPointToPointEpcHelper> epcHelper = CreateObject<NrPointToPointEpcHelper>();
86 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
87 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
88
89 // Put the pointers inside nrHelper
90 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
91 nrHelper->SetEpcHelper(epcHelper);
92
94 CcBwpCreator ccBwpCreator;
95 const uint8_t numCcPerBand = 1; // in this example, both bands have a single CC
96
97 // Create the configuration for the CcBwpHelper. SimpleOperationBandConf creates
98 // a single BWP per CC
100 100e6,
101 numCcPerBand,
103
104 // By using the configuration created, it is time to make the operation bands
105 OperationBandInfo band1 = ccBwpCreator.CreateOperationBandContiguousCc(bandConf1);
106
107 Config::SetDefault("ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(MilliSeconds(100)));
108 nrHelper->SetChannelConditionModelAttribute("UpdatePeriod", TimeValue(MilliSeconds(100)));
109 nrHelper->SetPathlossAttribute("ShadowingEnabled", BooleanValue(false));
110
111 nrHelper->InitializeOperationBand(&band1);
112
113 allBwps = CcBwpCreator::GetAllBwps({band1});
114
115 nrHelper->SetGnbPhyAttribute("Numerology", UintegerValue(m_numerology));
116 nrHelper->SetSchedulerTypeId(TypeId::LookupByName(m_scheduler));
117
118 // install nr net devices
119 NetDeviceContainer enbNetDev = nrHelper->InstallGnbDevice(enbNode, allBwps);
120 NetDeviceContainer ueNetDev = nrHelper->InstallUeDevice(ueNode, allBwps);
121
122 for (auto it = enbNetDev.Begin(); it != enbNetDev.End(); ++it)
123 {
124 DynamicCast<NrGnbNetDevice>(*it)->UpdateConfig();
125 }
126
127 for (auto it = ueNetDev.Begin(); it != ueNetDev.End(); ++it)
128 {
129 DynamicCast<NrUeNetDevice>(*it)->UpdateConfig();
130 }
131
132 // create the internet and install the IP stack on the UEs
133 // get SGW/PGW and create a single RemoteHost
134 Ptr<Node> pgw = epcHelper->GetPgwNode();
135 NodeContainer remoteHostContainer;
136 remoteHostContainer.Create(1);
137 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
138 InternetStackHelper internet;
139 internet.Install(remoteHostContainer);
140
141 // connect a remoteHost to pgw. Setup routing too
142 PointToPointHelper p2ph;
143 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
144 p2ph.SetDeviceAttribute("Mtu", UintegerValue(2500));
145 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
146 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
147 Ipv4AddressHelper ipv4h;
148 ipv4h.SetBase("1.0.0.0", "255.0.0.0");
149 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
150 Ipv4StaticRoutingHelper ipv4RoutingHelper;
151 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
152 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
153 remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
154 internet.Install(ueNode);
155 Ipv4InterfaceContainer ueIpIface;
156 ueIpIface = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
157 // assign IP address to UEs, and install UDP downlink applications
158 uint16_t dlPort = 1234;
159 ApplicationContainer clientApps;
160 ApplicationContainer serverApps;
161
162 Ptr<Node> ue = ueNode.Get(0);
163 // Set the default gateway for the UE
164 Ptr<Ipv4StaticRouting> ueStaticRouting =
165 ipv4RoutingHelper.GetStaticRouting(ue->GetObject<Ipv4>());
166 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(), 1);
167
168 UdpServerHelper dlPacketSinkHelper(dlPort);
169 serverApps.Add(dlPacketSinkHelper.Install(ueNode.Get(0)));
170
171 UdpClientHelper dlClient(ueIpIface.GetAddress(0), dlPort);
172 dlClient.SetAttribute("Interval", TimeValue(MicroSeconds(10000)));
173 dlClient.SetAttribute("MaxPackets", UintegerValue(0xFFFFFFFF));
174 clientApps.Add(dlClient.Install(remoteHost));
175
176 // start server and client apps
177 serverApps.Start(MilliSeconds(400));
178 clientApps.Start(MilliSeconds(400));
179 serverApps.Stop(MilliSeconds(800));
180 clientApps.Stop(MilliSeconds(800));
181
182 // attach UEs to the closest eNB
183 nrHelper->AttachToClosestEnb(ueNetDev, enbNetDev);
184
185 Simulator::Stop(MilliSeconds(800));
186 Simulator::Run();
187 Simulator::Destroy();
188
189 // A wide variety of test macros are available in src/core/test.h
190 NS_TEST_ASSERT_MSG_EQ(true, true, "true doesn't equal true for some reason");
191 // Use this one for floating point comparisons
192 NS_TEST_ASSERT_MSG_EQ_TOL(0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
193}
194
195class NrSystemTestConfigurationsTestSuite : public TestSuite
196{
197 public:
198 NrSystemTestConfigurationsTestSuite();
199};
200
201NrSystemTestConfigurationsTestSuite::NrSystemTestConfigurationsTestSuite()
202 : TestSuite("nr-system-test-configurations", Type::SYSTEM)
203{
204 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=rr",
205 0,
206 "ns3::NrMacSchedulerTdmaRR"),
207 Duration::QUICK);
208 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=rr",
209 2,
210 "ns3::NrMacSchedulerTdmaRR"),
211 Duration::QUICK);
212 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=rr",
213 4,
214 "ns3::NrMacSchedulerTdmaRR"),
215 Duration::QUICK);
216
217 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=pf",
218 0,
219 "ns3::NrMacSchedulerTdmaPF"),
220 Duration::QUICK);
221 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=pf",
222 2,
223 "ns3::NrMacSchedulerTdmaPF"),
224 Duration::QUICK);
225 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=pf",
226 4,
227 "ns3::NrMacSchedulerTdmaPF"),
228 Duration::QUICK);
229
230 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=0, scheduler=mr",
231 0,
232 "ns3::NrMacSchedulerTdmaMR"),
233 Duration::QUICK);
234 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=2, scheduler=mr",
235 2,
236 "ns3::NrMacSchedulerTdmaMR"),
237 Duration::QUICK);
238 AddTestCase(new NrSystemTestConfigurationsTestCase1("num=4, scheduler=mr",
239 4,
240 "ns3::NrMacSchedulerTdmaMR"),
241 Duration::QUICK);
242}
243
244// Do not forget to allocate an instance of this TestSuite
245static 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
@ UMi_StreetCanyon
UMi_StreetCanyon.
Minimum configuration requirements for a OperationBand.
Operation band information structure.