A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-interference.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Manuel Requena <manuel.requena@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/string.h"
25 #include "ns3/double.h"
26 #include <ns3/enum.h>
27 #include "ns3/boolean.h"
28 #include "ns3/mobility-helper.h"
29 #include "ns3/lte-helper.h"
30 #include "ns3/ff-mac-scheduler.h"
31 
32 #include "ns3/lte-enb-phy.h"
33 #include "ns3/lte-enb-net-device.h"
34 
35 #include "ns3/lte-ue-phy.h"
36 #include "ns3/lte-ue-net-device.h"
37 
38 #include "lte-test-interference.h"
39 
41 
42 NS_LOG_COMPONENT_DEFINE ("LteInterferenceTest");
43 
44 namespace ns3 {
45 
46 
47 void
49  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
50  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
51 {
52  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
53 }
54 
55 void
57  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
58  uint8_t mcs, uint16_t sizeTb)
59 {
60  testcase->UlScheduling (frameNo, subframeNo, rnti, mcs, sizeTb);
61 }
62 
63 
69  : TestSuite ("lte-interference", SYSTEM)
70 {
71  NS_LOG_INFO ("Creating LteInterferenceTestSuite");
72 
73  AddTestCase (new LteInterferenceTestCase ("d1=3000, d2=6000", 3000.000000, 6000.000000, 3.844681, 1.714583, 0.761558, 0.389662, 6, 4));
74  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=10", 50.000000, 10.000000, 0.040000, 0.040000, 0.010399, 0.010399, 0, 0));
75  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=20", 50.000000, 20.000000, 0.160000, 0.159998, 0.041154, 0.041153, 0, 0));
76  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=50", 50.000000, 50.000000, 0.999997, 0.999907, 0.239828, 0.239808, 2, 2));
77  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=100", 50.000000, 100.000000, 3.999955, 3.998520, 0.785259, 0.785042, 6, 6));
78  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=200", 50.000000, 200.000000, 15.999282, 15.976339, 1.961072, 1.959533, 14, 14));
79  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=500", 50.000000, 500.000000, 99.971953, 99.082845, 4.254003, 4.241793, 22, 22));
80  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=1000", 50.000000, 1000.000000, 399.551632, 385.718468, 6.194952, 6.144825, 28, 28));
81  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=10000", 50.000000, 10000.000000, 35964.181431, 8505.970614, 12.667381, 10.588084, 28, 28));
82  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=100000", 50.000000, 100000.000000, 327284.773828, 10774.181090, 15.853097, 10.928917, 28, 28));
83  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=1000000", 50.000000, 1000000.000000, 356132.574152, 10802.988445, 15.974963, 10.932767, 28, 28));
84  AddTestCase (new LteInterferenceTestCase ("d1=4500, d2=12600", 4500.000000, 12600.000000, 6.654462, 1.139831, 1.139781, 0.270399, 8, 2));
85  AddTestCase (new LteInterferenceTestCase ("d1=5400, d2=12600", 5400.000000, 12600.000000, 4.621154, 0.791549, 0.876368, 0.193019, 6, 0));
86 
87 
88 }
89 
91 
92 
97 LteInterferenceTestCase::LteInterferenceTestCase (std::string name, double d1, double d2, double dlSinr, double ulSinr, double dlSe, double ulSe, uint16_t dlMcs, uint16_t ulMcs)
98  : TestCase (name),
99  m_d1 (d1),
100  m_d2 (d2),
101  m_dlSinrDb (10 * std::log10 (dlSinr)),
102  m_ulSinrDb (10 * std::log10 (ulSinr)),
103  m_dlSe (dlSe),
104  m_ulSe (ulSe),
105  m_dlMcs (dlMcs),
106  m_ulMcs (ulMcs)
107 {
108 }
109 
111 {
112 }
113 
114 void
116 {
117  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
118  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
119  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
120  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
121  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
122 // lteHelper->EnableLogComponents ();
123  lteHelper->EnableMacTraces ();
124  lteHelper->EnableRlcTraces ();
125  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
126 
127  // Create Nodes: eNodeB and UE
128  NodeContainer enbNodes;
129  NodeContainer ueNodes1;
130  NodeContainer ueNodes2;
131  enbNodes.Create (2);
132  ueNodes1.Create (1);
133  ueNodes2.Create (1);
134  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes1, ueNodes2);
135 
136  // the topology is the following:
137  // d2
138  // UE1-----------eNB2
139  // | |
140  // d1| |d1
141  // | d2 |
142  // eNB1----------UE2
143  //
144  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
145  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB1
146  positionAlloc->Add (Vector (m_d2, m_d1, 0.0)); // eNB2
147  positionAlloc->Add (Vector (0.0, m_d1, 0.0)); // UE1
148  positionAlloc->Add (Vector (m_d2, 0.0, 0.0)); // UE2
149  MobilityHelper mobility;
150  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
151  mobility.SetPositionAllocator (positionAlloc);
152  mobility.Install (allNodes);
153 
154  // Create Devices and install them in the Nodes (eNB and UE)
155  NetDeviceContainer enbDevs;
156  NetDeviceContainer ueDevs1;
157  NetDeviceContainer ueDevs2;
158  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
159  lteHelper->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
160  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
161  ueDevs1 = lteHelper->InstallUeDevice (ueNodes1);
162  ueDevs2 = lteHelper->InstallUeDevice (ueNodes2);
163 
164  lteHelper->Attach (ueDevs1, enbDevs.Get (0));
165  lteHelper->Attach (ueDevs2, enbDevs.Get (1));
166 
167  // Activate an EPS bearer
169  EpsBearer bearer (q);
170  lteHelper->ActivateEpsBearer (ueDevs1, bearer, EpcTft::Default ());
171  lteHelper->ActivateEpsBearer (ueDevs2, bearer, EpcTft::Default ());
172 
173  // Use testing chunk processor in the PHY layer
174  // It will be used to test that the SNR is as intended
175  // we plug in two instances, one for DL and one for UL
176 
177  Ptr<LtePhy> ue1Phy = ueDevs1.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
178  Ptr<LteTestSinrChunkProcessor> testDlSinr1 = Create<LteTestSinrChunkProcessor> (ue1Phy);
179  ue1Phy->GetDownlinkSpectrumPhy ()->AddDataSinrChunkProcessor (testDlSinr1);
180 
181  Ptr<LtePhy> enb1phy = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
182  Ptr<LteTestSinrChunkProcessor> testUlSinr1 = Create<LteTestSinrChunkProcessor> (enb1phy);
183  enb1phy->GetUplinkSpectrumPhy ()->AddDataSinrChunkProcessor (testUlSinr1);
184 
185  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
187 
188  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/UlScheduling",
190 
191 
192  // same as above for eNB2 and UE2
193 
194  Ptr<LtePhy> ue2Phy = ueDevs2.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
195  Ptr<LteTestSinrChunkProcessor> testDlSinr2 = Create<LteTestSinrChunkProcessor> (ue2Phy);
196  ue2Phy->GetDownlinkSpectrumPhy ()->AddDataSinrChunkProcessor (testDlSinr2);
197 
198  Ptr<LtePhy> enb2phy = enbDevs.Get (1)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
199  Ptr<LteTestSinrChunkProcessor> testUlSinr2 = Create<LteTestSinrChunkProcessor> (enb2phy);
200  enb1phy->GetUplinkSpectrumPhy ()->AddDataSinrChunkProcessor (testUlSinr2);
201 
202  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/DlScheduling",
204 
205  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/UlScheduling",
207 
208 
209  Simulator::Stop (Seconds (0.020));
210  Simulator::Run ();
211 
212 
213  double dlSinr1Db = 10.0 * std::log10 (testDlSinr1->GetSinr ()->operator[] (0));
214  NS_TEST_ASSERT_MSG_EQ_TOL (dlSinr1Db, m_dlSinrDb, 0.01, "Wrong SINR in DL! (eNB1 --> UE1)");
215 
216  double ulSinr1Db = 10.0 * std::log10 (testUlSinr1->GetSinr ()->operator[] (0));
217  NS_TEST_ASSERT_MSG_EQ_TOL (ulSinr1Db, m_ulSinrDb, 0.01, "Wrong SINR in UL! (UE1 --> eNB1)");
218 
219  double dlSinr2Db = 10.0 * std::log10 (testDlSinr2->GetSinr ()->operator[] (0));
220  NS_TEST_ASSERT_MSG_EQ_TOL (dlSinr2Db, m_dlSinrDb, 0.01, "Wrong SINR in DL! (eNB2 --> UE2)");
221 
222  double ulSinr2Db = 10.0 * std::log10 (testUlSinr2->GetSinr ()->operator[] (0));
223  NS_TEST_ASSERT_MSG_EQ_TOL (ulSinr2Db, m_ulSinrDb, 0.01, "Wrong SINR in UL! (UE2 --> eNB2)");
224 
226 
227 }
228 
229 
230 void
231 LteInterferenceTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
232  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
233 {
239  if ( (frameNo > 1) || (subframeNo > 9) )
240  {
241  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcsTb1, m_dlMcs, "Wrong DL MCS ");
242  }
243 }
244 
245 void
246 LteInterferenceTestCase::UlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
247  uint8_t mcs, uint16_t sizeTb)
248 {
254  if ( (frameNo > 1) && (subframeNo > 6) )
255  {
256  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcs, m_ulMcs, "Wrong UL MCS");
257  }
258 }
259 
260 } // namespace ns3
261