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/double.h"
12#include "ns3/radio-bearer-stats-calculator.h"
13#include "ns3/string.h"
14#include <ns3/boolean.h>
15#include <ns3/buildings-helper.h>
16#include <ns3/buildings-propagation-loss-model.h>
17#include <ns3/enum.h>
18#include <ns3/eps-bearer.h>
19#include <ns3/log.h>
20#include <ns3/lte-enb-net-device.h>
21#include <ns3/lte-enb-phy.h>
22#include <ns3/lte-helper.h>
23#include <ns3/lte-ue-net-device.h>
24#include <ns3/lte-ue-phy.h>
25#include <ns3/lte-ue-rrc.h>
26#include <ns3/mobility-building-info.h>
27#include <ns3/mobility-helper.h>
28#include <ns3/net-device-container.h>
29#include <ns3/node-container.h>
30#include <ns3/object.h>
31#include <ns3/packet.h>
32#include <ns3/pf-ff-mac-scheduler.h>
33#include <ns3/pointer.h>
34#include <ns3/ptr.h>
35#include <ns3/rr-ff-mac-scheduler.h>
36#include <ns3/simulator.h>
37#include <ns3/spectrum-error-model.h>
38#include <ns3/spectrum-interference.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 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(false));
117 Config::SetDefault("ns3::LteAmc::AmcModel", EnumValue(LteAmc::PiroEW2010));
118 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(m_useIdealRrc));
119 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
120 StringValue(CreateTempDirFilename("DlMacStats.txt")));
121 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
122 StringValue(CreateTempDirFilename("UlMacStats.txt")));
123 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
124 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
125 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
126 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
127
128 // Disable Uplink Power Control
129 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
130
131 /**
132 * Initialize Simulation Scenario: 1 eNB and m_nUser UEs
133 */
134
136 Config::SetDefault("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue(false));
137 Config::SetDefault("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue(false));
138
139 // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false));
140
141 lteHelper->SetAttribute("PathlossModel",
142 StringValue("ns3::HybridBuildingsPropagationLossModel"));
143 lteHelper->SetPathlossModelAttribute("ShadowSigmaOutdoor", DoubleValue(0.0));
144 lteHelper->SetPathlossModelAttribute("ShadowSigmaIndoor", DoubleValue(0.0));
145 lteHelper->SetPathlossModelAttribute("ShadowSigmaExtWalls", DoubleValue(0.0));
146
147 // lteHelper->EnableLogComponents ();
148
149 // Create Nodes: eNodeB and UE
150 NodeContainer enbNodes;
151 NodeContainer ueNodes;
152 enbNodes.Create(1);
153 ueNodes.Create(1);
154
155 // Install Mobility Model
156 MobilityHelper mobility;
157 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
158 mobility.Install(enbNodes);
159 BuildingsHelper::Install(enbNodes);
160 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
161 mobility.Install(ueNodes);
163
164 // Create Devices and install them in the Nodes (eNB and UE)
165 NetDeviceContainer enbDevs;
166 NetDeviceContainer ueDevs;
167 lteHelper->SetSchedulerType(m_schedulerType);
168 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
169 ueDevs = lteHelper->InstallUeDevice(ueNodes);
170
171 // Attach a UE to a eNB
172 lteHelper->Attach(ueDevs, enbDevs.Get(0));
173
174 // Activate an EPS bearer
176 EpsBearer bearer(q);
177 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
178
179 Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
180 Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy();
181 enbPhy->SetAttribute("TxPower", DoubleValue(46.0));
182 enbPhy->SetAttribute("NoiseFigure", DoubleValue(5.0));
183 Ptr<MobilityModel> mmenb = enbNodes.Get(0)->GetObject<MobilityModel>();
184 mmenb->SetPosition(Vector(0.0, 0.0, 30.0));
185
186 // Set UE's position and power
187 Ptr<MobilityModel> mmue = ueNodes.Get(0)->GetObject<MobilityModel>();
188 mmue->SetPosition(Vector(m_dist, 0.0, 1.0));
189 Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get(0)->GetObject<LteUeNetDevice>();
190 Ptr<LteUePhy> uePhy = lteUeDev->GetPhy();
191 uePhy->SetAttribute("TxPower", DoubleValue(23.0));
192 uePhy->SetAttribute("NoiseFigure", DoubleValue(9.0));
193
194 // need to allow for RRC connection establishment + SRS before enabling traces
195 lteHelper->EnableRlcTraces();
196 lteHelper->EnableMacTraces();
197 double simulationTime = 0.6;
198 double tolerance = 0.1;
199
200 uint8_t rnti = 1;
201 Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
202
203 PointerValue ptrval;
204 enbNetDev->GetCcMap()[0]->GetAttribute("FfMacScheduler", ptrval);
205 Ptr<PfFfMacScheduler> pfsched;
206 Ptr<RrFfMacScheduler> rrsched;
207 if (m_schedulerType == "ns3::RrFfMacScheduler")
208 {
209 rrsched = ptrval.Get<RrFfMacScheduler>();
210 if (!rrsched)
211 {
212 NS_FATAL_ERROR("No RR Scheduler available");
213 }
216 rrsched,
217 rnti,
218 1);
221 rrsched,
222 rnti,
223 2);
224 }
225 else if (m_schedulerType == "ns3::PfFfMacScheduler")
226 {
227 pfsched = ptrval.Get<PfFfMacScheduler>();
228 if (!pfsched)
229 {
230 NS_FATAL_ERROR("No Pf Scheduler available");
231 }
232
235 pfsched,
236 rnti,
237 1);
240 pfsched,
241 rnti,
242 2);
243 }
244 else
245 {
246 NS_FATAL_ERROR("Scheduler not supported by this test");
247 }
248
249 Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats();
250 rlcStats->SetAttribute("EpochDuration", TimeValue(Seconds(0.1)));
251
252 NS_LOG_INFO(m_schedulerType << " MIMO test:");
253 double sampleTime = 0.199999; // at 0.2 RlcStats are reset
254 for (std::size_t j = 0; j < m_estThrDl.size(); j++)
255 {
256 NS_LOG_INFO("\t test with user at distance " << m_dist << " time " << sampleTime);
257 // get the imsi
258 uint64_t imsi = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetImsi();
259 uint8_t lcId = 3;
260 Time t = Seconds(sampleTime);
261 Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
262 sampleTime += 0.2;
263 }
264 Simulator::Stop(Seconds(simulationTime));
267
268 NS_LOG_INFO("Check consistency");
269 for (std::size_t i = 0; i < m_estThrDl.size(); i++)
270 {
271 NS_LOG_INFO("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at(i) << " ref "
272 << m_estThrDl.at(i));
274 m_estThrDl.at(i),
275 m_estThrDl.at(i) * tolerance,
276 " Unfair Throughput!");
277 }
278}
279
280void
282 uint64_t imsi,
283 uint8_t lcId)
284{
285 m_dlDataRxed.push_back(rlcStats->GetDlRxData(imsi, lcId));
286 NS_LOG_INFO(Simulator::Now() << "\t get bytes " << m_dlDataRxed.at(m_dlDataRxed.size() - 1));
287}
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:560
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
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:1431
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#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:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.