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 
28 #include "ns3/mobility-helper.h"
29 #include "ns3/lte-helper.h"
30 
31 #include "ns3/lte-enb-phy.h"
32 #include "ns3/lte-enb-net-device.h"
33 
34 #include "ns3/lte-ue-phy.h"
35 #include "ns3/lte-ue-net-device.h"
36 
37 #include "lte-test-interference.h"
38 
40 
41 NS_LOG_COMPONENT_DEFINE ("LteInterferenceTest");
42 
43 namespace ns3 {
44 
45 
46 void
48  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
49  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
50 {
51  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
52 }
53 
54 void
56  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
57  uint8_t mcs, uint16_t sizeTb)
58 {
59  testcase->UlScheduling (frameNo, subframeNo, rnti, mcs, sizeTb);
60 }
61 
62 
68  : TestSuite ("lte-interference", SYSTEM)
69 {
70  NS_LOG_INFO ("Creating LteInterferenceTestSuite");
71 
72  AddTestCase (new LteInterferenceTestCase ("d1=3000, d2=6000", 3000.000000, 6000.000000, 3.844681, 1.714583, 0.761558, 0.389662, 6, 4));
73  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=10", 50.000000, 10.000000, 0.040000, 0.040000, 0.010399, 0.010399, 0, 0));
74  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=20", 50.000000, 20.000000, 0.160000, 0.159998, 0.041154, 0.041153, 0, 0));
75  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=50", 50.000000, 50.000000, 0.999997, 0.999907, 0.239828, 0.239808, 2, 2));
76  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=100", 50.000000, 100.000000, 3.999955, 3.998520, 0.785259, 0.785042, 6, 6));
77  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=200", 50.000000, 200.000000, 15.999282, 15.976339, 1.961072, 1.959533, 14, 14));
78  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=500", 50.000000, 500.000000, 99.971953, 99.082845, 4.254003, 4.241793, 22, 22));
79  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=1000", 50.000000, 1000.000000, 399.551632, 385.718468, 6.194952, 6.144825, 28, 28));
80  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=10000", 50.000000, 10000.000000, 35964.181431, 8505.970614, 12.667381, 10.588084, 28, 28));
81  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=100000", 50.000000, 100000.000000, 327284.773828, 10774.181090, 15.853097, 10.928917, 28, 28));
82  AddTestCase (new LteInterferenceTestCase ("d1=50, d2=1000000", 50.000000, 1000000.000000, 356132.574152, 10802.988445, 15.974963, 10.932767, 28, 28));
83  AddTestCase (new LteInterferenceTestCase ("d1=4500, d2=12600", 4500.000000, 12600.000000, 6.654462, 1.139831, 1.139781, 0.270399, 8, 2));
84  AddTestCase (new LteInterferenceTestCase ("d1=5400, d2=12600", 5400.000000, 12600.000000, 4.621154, 0.791549, 0.876368, 0.193019, 6, 0));
85 
86 
87 }
88 
90 
91 
96 LteInterferenceTestCase::LteInterferenceTestCase (std::string name, double d1, double d2, double dlSinr, double ulSinr, double dlSe, double ulSe, uint16_t dlMcs, uint16_t ulMcs)
97  : TestCase (name),
98  m_d1 (d1),
99  m_d2 (d2),
100  m_dlSinrDb (10 * log10 (dlSinr)),
101  m_ulSinrDb (10 * log10 (ulSinr)),
102  m_dlSe (dlSe),
103  m_ulSe (ulSe),
104  m_dlMcs (dlMcs),
105  m_ulMcs (ulMcs)
106 {
107 }
108 
110 {
111 }
112 
113 void
115 {
116  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
117  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
118  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
119 // lteHelper->EnableLogComponents ();
120  lteHelper->EnableMacTraces ();
121  lteHelper->EnableRlcTraces ();
122  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
123 
124  // Create Nodes: eNodeB and UE
125  NodeContainer enbNodes;
126  NodeContainer ueNodes1;
127  NodeContainer ueNodes2;
128  enbNodes.Create (2);
129  ueNodes1.Create (1);
130  ueNodes2.Create (1);
131  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes1, ueNodes2);
132 
133  // the topology is the following:
134  // d2
135  // UE1-----------eNB2
136  // | |
137  // d1| |d1
138  // | d2 |
139  // eNB1----------UE2
140  //
141  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
142  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB1
143  positionAlloc->Add (Vector (m_d2, m_d1, 0.0)); // eNB2
144  positionAlloc->Add (Vector (0.0, m_d1, 0.0)); // UE1
145  positionAlloc->Add (Vector (m_d2, 0.0, 0.0)); // UE2
146  MobilityHelper mobility;
147  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
148  mobility.SetPositionAllocator (positionAlloc);
149  mobility.Install (allNodes);
150 
151  // Create Devices and install them in the Nodes (eNB and UE)
152  NetDeviceContainer enbDevs;
153  NetDeviceContainer ueDevs1;
154  NetDeviceContainer ueDevs2;
155  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
156  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
157  ueDevs1 = lteHelper->InstallUeDevice (ueNodes1);
158  ueDevs2 = lteHelper->InstallUeDevice (ueNodes2);
159 
160  lteHelper->Attach (ueDevs1, enbDevs.Get (0));
161  lteHelper->Attach (ueDevs2, enbDevs.Get (1));
162 
163  // Activate an EPS bearer
165  EpsBearer bearer (q);
166  lteHelper->ActivateEpsBearer (ueDevs1, bearer, EpcTft::Default ());
167  lteHelper->ActivateEpsBearer (ueDevs2, bearer, EpcTft::Default ());
168 
169  // Use testing chunk processor in the PHY layer
170  // It will be used to test that the SNR is as intended
171  // we plug in two instances, one for DL and one for UL
172 
173  Ptr<LtePhy> ue1Phy = ueDevs1.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
174  Ptr<LteTestSinrChunkProcessor> testDlSinr1 = Create<LteTestSinrChunkProcessor> (ue1Phy);
175  ue1Phy->GetDownlinkSpectrumPhy ()->AddSinrChunkProcessor (testDlSinr1);
176 
177  Ptr<LtePhy> enb1phy = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
178  Ptr<LteTestSinrChunkProcessor> testUlSinr1 = Create<LteTestSinrChunkProcessor> (enb1phy);
179  enb1phy->GetUplinkSpectrumPhy ()->AddSinrChunkProcessor (testUlSinr1);
180 
181  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
183 
184  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/UlScheduling",
186 
187 
188  // same as above for eNB2 and UE2
189 
190  Ptr<LtePhy> ue2Phy = ueDevs2.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
191  Ptr<LteTestSinrChunkProcessor> testDlSinr2 = Create<LteTestSinrChunkProcessor> (ue2Phy);
192  ue2Phy->GetDownlinkSpectrumPhy ()->AddSinrChunkProcessor (testDlSinr2);
193 
194  Ptr<LtePhy> enb2phy = enbDevs.Get (1)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
195  Ptr<LteTestSinrChunkProcessor> testUlSinr2 = Create<LteTestSinrChunkProcessor> (enb2phy);
196  enb1phy->GetUplinkSpectrumPhy ()->AddSinrChunkProcessor (testUlSinr2);
197 
198  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/DlScheduling",
200 
201  Config::Connect ("/NodeList/1/DeviceList/0/LteEnbMac/UlScheduling",
203 
204 
205  Simulator::Stop (Seconds (0.020));
206  Simulator::Run ();
207 
208 
209  double dlSinr1Db = 10.0 * log10 (testDlSinr1->GetSinr ()->operator[] (0));
210  NS_TEST_ASSERT_MSG_EQ_TOL (dlSinr1Db, m_dlSinrDb, 0.01, "Wrong SINR in DL! (eNB1 --> UE1)");
211 
212  double ulSinr1Db = 10.0 * log10 (testUlSinr1->GetSinr ()->operator[] (0));
213  NS_TEST_ASSERT_MSG_EQ_TOL (ulSinr1Db, m_ulSinrDb, 0.01, "Wrong SINR in UL! (UE1 --> eNB1)");
214 
215  double dlSinr2Db = 10.0 * log10 (testDlSinr2->GetSinr ()->operator[] (0));
216  NS_TEST_ASSERT_MSG_EQ_TOL (dlSinr2Db, m_dlSinrDb, 0.01, "Wrong SINR in DL! (eNB2 --> UE2)");
217 
218  double ulSinr2Db = 10.0 * log10 (testUlSinr2->GetSinr ()->operator[] (0));
219  NS_TEST_ASSERT_MSG_EQ_TOL (ulSinr2Db, m_ulSinrDb, 0.01, "Wrong SINR in UL! (UE2 --> eNB2)");
220 
222 
223 }
224 
225 
226 void
227 LteInterferenceTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
228  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
229 {
235  if ( (frameNo > 1) || (subframeNo > 9) )
236  {
237  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcsTb1, m_dlMcs, "Wrong DL MCS ");
238  }
239 }
240 
241 void
242 LteInterferenceTestCase::UlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
243  uint8_t mcs, uint16_t sizeTb)
244 {
250  if ( (frameNo > 1) && (subframeNo > 4) )
251  {
252  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcs, m_ulMcs, "Wrong UL MCS");
253  }
254 }
255 
256 } // namespace ns3
257