A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-mimo.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7 */
8
9#include "lte-test-mimo.h"
10
11#include "ns3/boolean.h"
12#include "ns3/buildings-helper.h"
13#include "ns3/buildings-propagation-loss-model.h"
14#include "ns3/double.h"
15#include "ns3/enum.h"
16#include "ns3/eps-bearer.h"
17#include "ns3/log.h"
18#include "ns3/lte-enb-net-device.h"
19#include "ns3/lte-enb-phy.h"
20#include "ns3/lte-helper.h"
21#include "ns3/lte-ue-net-device.h"
22#include "ns3/lte-ue-phy.h"
23#include "ns3/lte-ue-rrc.h"
24#include "ns3/mobility-building-info.h"
25#include "ns3/mobility-helper.h"
26#include "ns3/net-device-container.h"
27#include "ns3/node-container.h"
28#include "ns3/object.h"
29#include "ns3/packet.h"
30#include "ns3/pf-ff-mac-scheduler.h"
31#include "ns3/pointer.h"
32#include "ns3/ptr.h"
33#include "ns3/radio-bearer-stats-calculator.h"
34#include "ns3/rr-ff-mac-scheduler.h"
35#include "ns3/simulator.h"
36#include "ns3/spectrum-error-model.h"
37#include "ns3/spectrum-interference.h"
38#include "ns3/string.h"
39#include "ns3/test.h"
40
41#include <iostream>
42#include <sstream>
43#include <string>
44
45using namespace ns3;
46
47NS_LOG_COMPONENT_DEFINE("LteTestMimo");
48
50 : TestSuite("lte-mimo", Type::SYSTEM)
51{
52 NS_LOG_INFO("creating LenaMimoTestCase");
53
54 // RR DOWNLINK- DISTANCE 300
55 // interval 1 : [0.1, 0.2) sec TxMode 0: MCS 20 -> TB size 1191 bytes
56 // interval 2 : [0.3, 0.4) sec TxMode 1: MCS 26 -> TB size 1836 bytes
57 // interval 3 : [0.5, 0.6) sec TxMode 2: MCS 18 -> TB size 967 bytes (x2 layers)
58 // -->
59 std::vector<uint32_t> estThrDl;
60 estThrDl.push_back(119100); // interval 1 : estimated throughput for TxMode 1
61 estThrDl.push_back(183600); // interval 2 : estimated throughput for TxMode 2
62 estThrDl.push_back(193400); // interval 3 : estimated throughput for TxMode 3
63 AddTestCase(new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", true),
64 TestCase::Duration::QUICK);
65 AddTestCase(new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", true),
66 TestCase::Duration::QUICK);
67 AddTestCase(new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", false),
68 TestCase::Duration::QUICK);
69 AddTestCase(new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", false),
70 TestCase::Duration::QUICK);
71}
72
73/**
74 * @ingroup lte-test
75 * Static variable for test initialization
76 */
78
79std::string
80LenaMimoTestCase::BuildNameString(uint16_t dist, std::string schedulerType, bool useIdealRrc)
81{
82 std::ostringstream oss;
83 oss << " UE distance " << dist << " m"
84 << " Scheduler " << schedulerType;
85 if (useIdealRrc)
86 {
87 oss << ", ideal RRC";
88 }
89 else
90 {
91 oss << ", real RRC";
92 }
93 return oss.str();
94}
95
97 std::vector<uint32_t> estThrDl,
98 std::string schedulerType,
99 bool useIdealRrc)
100 : TestCase(BuildNameString(dist, schedulerType, useIdealRrc)),
101 m_dist(dist),
102 m_estThrDl(estThrDl),
103 m_schedulerType(schedulerType),
104 m_useIdealRrc(useIdealRrc)
105{
106}
107
111
112void
114{
115 NS_LOG_FUNCTION(this << GetName());
116 SetDataDir(NS_TEST_SOURCEDIR);
117 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(false));
118 Config::SetDefault("ns3::LteAmc::AmcModel", EnumValue(LteAmc::PiroEW2010));
119 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(m_useIdealRrc));
120 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
121 StringValue(CreateTempDirFilename("DlMacStats.txt")));
122 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
123 StringValue(CreateTempDirFilename("UlMacStats.txt")));
124 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
125 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
126 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
127 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
128
129 // Disable Uplink Power Control
130 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
131
132 /**
133 * Initialize Simulation Scenario: 1 eNB and m_nUser UEs
134 */
135
137 Config::SetDefault("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue(false));
138 Config::SetDefault("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue(false));
139
140 // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false));
141
142 lteHelper->SetAttribute("PathlossModel",
143 StringValue("ns3::HybridBuildingsPropagationLossModel"));
144 lteHelper->SetPathlossModelAttribute("ShadowSigmaOutdoor", DoubleValue(0.0));
145 lteHelper->SetPathlossModelAttribute("ShadowSigmaIndoor", DoubleValue(0.0));
146 lteHelper->SetPathlossModelAttribute("ShadowSigmaExtWalls", DoubleValue(0.0));
147
148 // lteHelper->EnableLogComponents ();
149
150 // Create Nodes: eNodeB and UE
151 NodeContainer enbNodes;
152 NodeContainer ueNodes;
153 enbNodes.Create(1);
154 ueNodes.Create(1);
155
156 // Install Mobility Model
157 MobilityHelper mobility;
158 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
159 mobility.Install(enbNodes);
160 BuildingsHelper::Install(enbNodes);
161 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
162 mobility.Install(ueNodes);
164
165 // Create Devices and install them in the Nodes (eNB and UE)
166 NetDeviceContainer enbDevs;
167 NetDeviceContainer ueDevs;
168 lteHelper->SetSchedulerType(m_schedulerType);
169 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
170 ueDevs = lteHelper->InstallUeDevice(ueNodes);
171
172 // Attach a UE to a eNB
173 lteHelper->Attach(ueDevs, enbDevs.Get(0));
174
175 // Activate an EPS bearer
177 EpsBearer bearer(q);
178 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
179
180 Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
181 Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy();
182 enbPhy->SetAttribute("TxPower", DoubleValue(46.0));
183 enbPhy->SetAttribute("NoiseFigure", DoubleValue(5.0));
184 Ptr<MobilityModel> mmenb = enbNodes.Get(0)->GetObject<MobilityModel>();
185 mmenb->SetPosition(Vector(0.0, 0.0, 30.0));
186
187 // Set UE's position and power
188 Ptr<MobilityModel> mmue = ueNodes.Get(0)->GetObject<MobilityModel>();
189 mmue->SetPosition(Vector(m_dist, 0.0, 1.0));
190 Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get(0)->GetObject<LteUeNetDevice>();
191 Ptr<LteUePhy> uePhy = lteUeDev->GetPhy();
192 uePhy->SetAttribute("TxPower", DoubleValue(23.0));
193 uePhy->SetAttribute("NoiseFigure", DoubleValue(9.0));
194
195 // need to allow for RRC connection establishment + SRS before enabling traces
196 lteHelper->EnableRlcTraces();
197 lteHelper->EnableMacTraces();
198 double simulationTime = 0.6;
199 double tolerance = 0.1;
200
201 uint8_t rnti = 1;
202 Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
203
204 PointerValue ptrval;
205 enbNetDev->GetCcMap()[0]->GetAttribute("FfMacScheduler", ptrval);
206 Ptr<PfFfMacScheduler> pfsched;
207 Ptr<RrFfMacScheduler> rrsched;
208 if (m_schedulerType == "ns3::RrFfMacScheduler")
209 {
210 rrsched = ptrval.Get<RrFfMacScheduler>();
211 if (!rrsched)
212 {
213 NS_FATAL_ERROR("No RR Scheduler available");
214 }
217 rrsched,
218 rnti,
219 1);
222 rrsched,
223 rnti,
224 2);
225 }
226 else if (m_schedulerType == "ns3::PfFfMacScheduler")
227 {
228 pfsched = ptrval.Get<PfFfMacScheduler>();
229 if (!pfsched)
230 {
231 NS_FATAL_ERROR("No Pf Scheduler available");
232 }
233
236 pfsched,
237 rnti,
238 1);
241 pfsched,
242 rnti,
243 2);
244 }
245 else
246 {
247 NS_FATAL_ERROR("Scheduler not supported by this test");
248 }
249
250 Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats();
251 rlcStats->SetAttribute("EpochDuration", TimeValue(Seconds(0.1)));
252
253 NS_LOG_INFO(m_schedulerType << " MIMO test:");
254 double sampleTime = 0.199999; // at 0.2 RlcStats are reset
255 for (std::size_t j = 0; j < m_estThrDl.size(); j++)
256 {
257 NS_LOG_INFO("\t test with user at distance " << m_dist << " time " << sampleTime);
258 // get the imsi
259 uint64_t imsi = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetImsi();
260 uint8_t lcId = 3;
261 Time t = Seconds(sampleTime);
262 Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
263 sampleTime += 0.2;
264 }
265 Simulator::Stop(Seconds(simulationTime));
268
269 NS_LOG_INFO("Check consistency");
270 for (std::size_t i = 0; i < m_estThrDl.size(); i++)
271 {
272 NS_LOG_INFO("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at(i) << " ref "
273 << m_estThrDl.at(i));
275 m_estThrDl.at(i),
276 m_estThrDl.at(i) * tolerance,
277 " Unfair Throughput!");
278 }
279}
280
281void
283 uint64_t imsi,
284 uint8_t lcId)
285{
286 m_dlDataRxed.push_back(rlcStats->GetDlRxData(imsi, lcId));
287 NS_LOG_INFO(Simulator::Now() << "\t get bytes " << m_dlDataRxed.at(m_dlDataRxed.size() - 1));
288}
This system test program creates different test cases with a single eNB and single UE.
void DoRun() override
Implementation to actually run this TestCase.
~LenaMimoTestCase() override
void GetRlcBufferSample(Ptr< RadioBearerStatsCalculator > rlcStats, uint64_t imsi, uint8_t rnti)
Get RLC buffer sample.
std::string m_schedulerType
the scheduler type
LenaMimoTestCase(uint16_t dist, std::vector< uint32_t > estThrDl, std::string schedulerType, bool useIdealRrc)
Constructor.
bool m_useIdealRrc
whether to use the ideal RRC
std::vector< uint64_t > m_dlDataRxed
DL data received.
std::vector< uint32_t > m_estThrDl
estimated throughput DL
uint16_t m_dist
the distance
static std::string BuildNameString(uint16_t dist, std::string schedulerType, bool useIdealRrc)
Builds the test name string based on provided parameter values.
Lena Test Mimo Suite.
AttributeValue implementation for Boolean.
Definition boolean.h:26
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
Qci
QoS Class Indicator.
Definition eps-bearer.h:95
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition eps-bearer.h:96
The eNodeB device implementation.
The LteUeNetDevice class implements the UE net device.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Implements the SCHED SAP and CSCHED SAP for a Proportional Fair scheduler.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
transmission mode configuration update
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update function.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
std::string GetName() const
Definition test.cc:367
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
AttributeValue implementation for Time.
Definition nstime.h:1432
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
static LenaTestMimoSuite lenaTestMimoSuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition test.h:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.