A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-cqi-generation.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Piotr Gawlowicz
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Piotr Gawlowicz <gawlowicz.p@gmail.com>
19  *
20  */
21 
22 #include <ns3/simulator.h>
23 #include <ns3/log.h>
24 #include <ns3/callback.h>
25 #include <ns3/config.h>
26 #include <ns3/string.h>
27 #include <ns3/double.h>
28 #include <ns3/enum.h>
29 #include <ns3/boolean.h>
30 #include <ns3/pointer.h>
31 #include "ns3/ff-mac-scheduler.h"
32 #include "ns3/mobility-helper.h"
33 #include "ns3/lte-helper.h"
34 
36 
37 NS_LOG_COMPONENT_DEFINE ("LteCqiGenerationTest");
38 
39 using namespace ns3;
40 
41 void
43  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
44  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
45 {
46  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
47 }
48 
49 void
51  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
52  uint8_t mcs, uint16_t sizeTb)
53 {
54  testcase->UlScheduling (frameNo, subframeNo, rnti, mcs, sizeTb);
55 }
56 
57 
63  : TestSuite ("lte-cqi-generation", SYSTEM)
64 {
65 // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_DEBUG);
66 // LogComponentEnable ("LteCqiGenerationTest", logLevel);
67  NS_LOG_INFO ("Creating LteCqiGenerationTestSuite");
68 
69  AddTestCase (new LteCqiGenerationTestCase ("UsePdcchForCqiGeneration", false, 4, 2), TestCase::QUICK);
70  AddTestCase (new LteCqiGenerationTestCase ("UsePdschForCqiGeneration", true, 28, 2), TestCase::QUICK);
71 
72 }
73 
75 
76 
77 LteCqiGenerationTestCase::LteCqiGenerationTestCase (std::string name, bool usePdcchForCqiGeneration,
78  uint16_t dlMcs, uint16_t ulMcs)
79  : TestCase ("Downlink Power Control: " + name),
80  m_dlMcs (dlMcs),
81  m_ulMcs (ulMcs)
82 {
83  m_usePdcchForCqiGeneration = usePdcchForCqiGeneration;
84  NS_LOG_INFO ("Creating LteCqiGenerationTestCase");
85 }
86 
88 {
89 }
90 
91 void
92 LteCqiGenerationTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
93  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
94 {
95  // need to allow for RRC connection establishment + CQI feedback reception
96  if (Simulator::Now () > MilliSeconds (35))
97  {
98 // NS_LOG_UNCOND("DL MSC: " << (uint32_t)mcsTb1 << " expected DL MCS: " << (uint32_t)m_dlMcs);
99  NS_TEST_ASSERT_MSG_EQ ((uint32_t)mcsTb1, (uint32_t)m_dlMcs, "Wrong DL MCS ");
100  }
101 }
102 
103 void
104 LteCqiGenerationTestCase::UlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
105  uint8_t mcs, uint16_t sizeTb)
106 {
107  // need to allow for RRC connection establishment + SRS transmission
108  if (Simulator::Now () > MilliSeconds (50))
109  {
110 // NS_LOG_UNCOND("UL MSC: " << (uint32_t)mcs << " expected UL MCS: " << (uint32_t)m_ulMcs);
111  NS_TEST_ASSERT_MSG_EQ ((uint32_t)mcs, (uint32_t)m_ulMcs, "Wrong UL MCS");
112  }
113 }
114 
115 void
117 {
118  NS_LOG_DEBUG ("LteCqiGenerationTestCase");
119 
120  Config::Reset ();
121  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
122  Config::SetDefault ("ns3::LteHelper::UsePdschForCqiGeneration", BooleanValue (m_usePdcchForCqiGeneration));
123 
124  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (true));
125  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (true));
126 
127  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
128 
129  // Create Nodes: eNodeB and UE
130  NodeContainer enbNodes;
131  NodeContainer ueNodes1;
132  NodeContainer ueNodes2;
133  enbNodes.Create (2);
134  ueNodes1.Create (1);
135  ueNodes2.Create (1);
136  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes1, ueNodes2);
137 
138  /*
139  * The topology is the following:
140  *
141  * eNB1 UE1 UE2 eNB2
142  * | | |
143  * x -------------------------- x -------------------------- x
144  * 500 m 500 m
145  *
146  */
147 
148  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
149  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB1
150  positionAlloc->Add (Vector (1000, 0.0, 0.0)); // eNB2
151  positionAlloc->Add (Vector (500.0, 0.0, 0.0)); // UE1
152  positionAlloc->Add (Vector (500, 0.0, 0.0)); // UE2
153  MobilityHelper mobility;
154  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
155  mobility.SetPositionAllocator (positionAlloc);
156  mobility.Install (allNodes);
157 
158  // Create Devices and install them in the Nodes (eNB and UE)
159  NetDeviceContainer enbDevs;
160  NetDeviceContainer ueDevs1;
161  NetDeviceContainer ueDevs2;
162  lteHelper->SetSchedulerType ("ns3::PfFfMacScheduler");
163  lteHelper->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
164 
165  lteHelper->SetFfrAlgorithmType ("ns3::LteFrHardAlgorithm");
166 
167  lteHelper->SetFfrAlgorithmAttribute ("DlSubBandOffset", UintegerValue (0));
168  lteHelper->SetFfrAlgorithmAttribute ("DlSubBandwidth", UintegerValue (12));
169  lteHelper->SetFfrAlgorithmAttribute ("UlSubBandOffset", UintegerValue (0));
170  lteHelper->SetFfrAlgorithmAttribute ("UlSubBandwidth", UintegerValue (25));
171  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (0)));
172 
173  lteHelper->SetFfrAlgorithmAttribute ("DlSubBandOffset", UintegerValue (12));
174  lteHelper->SetFfrAlgorithmAttribute ("DlSubBandwidth", UintegerValue (12));
175  lteHelper->SetFfrAlgorithmAttribute ("UlSubBandOffset", UintegerValue (0));
176  lteHelper->SetFfrAlgorithmAttribute ("UlSubBandwidth", UintegerValue (25));
177  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (1)));
178 
179  ueDevs1 = lteHelper->InstallUeDevice (ueNodes1);
180  ueDevs2 = lteHelper->InstallUeDevice (ueNodes2);
181 
182  // Attach a UE to a eNB
183  lteHelper->Attach (ueDevs1, enbDevs.Get (0));
184  lteHelper->Attach (ueDevs2, enbDevs.Get (1));
185 
186  // Activate an EPS bearer
187  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
188  EpsBearer bearer (q);
189  lteHelper->ActivateDataRadioBearer (ueDevs1, bearer);
190  lteHelper->ActivateDataRadioBearer (ueDevs2, bearer);
191 
192  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
194 
195  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/UlScheduling",
197 
198  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/DlScheduling",
200 
201  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/UlScheduling",
203 
204  Simulator::Stop (Seconds (1.100));
205  Simulator::Run ();
206 
207  Simulator::Destroy ();
208 }
Hold a bool native type.
Definition: boolean.h:38
NetDeviceContainer InstallEnbDevice(NodeContainer c)
create a set of eNB devices
Definition: lte-helper.cc:382
void DlScheduling(uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:652
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1289
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1480
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:709
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:853
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
LteCqiGenerationTestCase(std::string name, bool usePdcchForCqiGeneration, uint16_t dlMcs, uint16_t ulMcs)
encapsulates test code
Definition: test.h:1113
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Call ActivateDataRadioBearer (ueDevice, bearer) for each UE device in a given set.
Definition: lte-helper.cc:963
a 3d vector
Definition: vector.h:31
void SetFfrAlgorithmType(std::string type)
Definition: lte-helper.cc:252
void SetSchedulerType(std::string type)
Definition: lte-helper.cc:225
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold variables of type 'enum'
Definition: enum.h:37
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
Definition: uinteger.h:46
void SetSchedulerAttribute(std::string n, const AttributeValue &v)
set an attribute for the scheduler to be created
Definition: lte-helper.cc:239
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:148
holds a vector of ns3::NetDevice pointers
void UlScheduling(uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcs, uint16_t sizeTb)
static LteCqiGenerationTestSuite lteCqiGenerationTestSuite
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:677
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
NetDeviceContainer InstallUeDevice(NodeContainer c)
create a set of UE devices
Definition: lte-helper.cc:397
Helper class used to assign positions and mobility models to nodes.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
void LteTestDlSchedulingCallback(LteCqiGenerationTestCase *testcase, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
void SetFfrAlgorithmAttribute(std::string n, const AttributeValue &v)
set an attribute for the FFR algorithm to be created
Definition: lte-helper.cc:260
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
void LteTestUlSchedulingCallback(LteCqiGenerationTestCase *testcase, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcs, uint16_t sizeTb)