A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-downlink-sinr.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  */
20 
21 #include "ns3/simulator.h"
22 
23 #include "ns3/log.h"
24 
25 #include "ns3/spectrum-test.h"
26 
27 #include "ns3/lte-phy-tag.h"
28 #include "ns3/lte-sinr-chunk-processor.h"
29 #include "ns3/lte-spectrum-signal-parameters.h"
30 
31 #include "lte-test-downlink-sinr.h"
32 #include "lte-test-ue-phy.h"
33 
34 
35 NS_LOG_COMPONENT_DEFINE ("LteDownlinkSinrTest");
36 
37 namespace ns3 {
38 
39 
49  : TestSuite ("lte-downlink-sinr", SYSTEM)
50 {
55 
56  Bands bands;
57  BandInfo bi;
58 
59  bi.fl = 2.400e9;
60  bi.fc = 2.410e9;
61  bi.fh = 2.420e9;
62  bands.push_back (bi);
63 
64  bi.fl = 2.420e9;
65  bi.fc = 2.431e9;
66  bi.fh = 2.442e9;
67  bands.push_back (bi);
68 
69  sm = Create<SpectrumModel> (bands);
70 
74  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue> (sm);
75  (*rxPsd1)[0] = 1.255943215755e-15;
76  (*rxPsd1)[1] = 7.204059965732e-16;
77 
78  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
79  (*theoreticalSinr1)[0] = 3.72589167251055;
80  (*theoreticalSinr1)[1] = 3.72255684126076;
81 
82  AddTestCase (new LteDownlinkSinrTestCase (rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"));
83 
87  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
88  (*rxPsd2)[0] = 2.505936168136e-17;
89  (*rxPsd2)[1] = 3.610582885110e-17;
90 
91  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
92  (*theoreticalSinr2)[0] = 0.0743413124381667;
93  (*theoreticalSinr2)[1] = 0.1865697965291756;
94 
95  AddTestCase (new LteDownlinkSinrTestCase (rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"));
96 
97 }
98 
100 
101 
107  : TestCase ("SINR calculation in downlink: " + name),
108  m_sv (sv),
109  m_sm (sv->GetSpectrumModel ()),
110  m_sinr (sinr)
111 {
112  NS_LOG_INFO ("Creating LenaDownlinkSinrTestCase");
113 }
114 
116 {
117 }
118 
119 void
121 {
125  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
126  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
127  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
128 
129  dlPhy->SetCellId (100);
130 
131  Ptr<LteCqiSinrChunkProcessor> chunkProcessor = Create<LteCqiSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
132  dlPhy->AddSinrChunkProcessor (chunkProcessor);
133 
141  // Number of packet bursts (1 data + 4 interferences)
142  int numOfPbs = 5;
143 
144  // Number of packets in the packet bursts
145  int numOfPkts = 10;
146 
147  // Packet bursts
148  Ptr<PacketBurst> packetBursts[numOfPbs];
149 
150  // Packets
151  Ptr<Packet> pkt[numOfPbs][numOfPkts];
152 
153  // Phy tags
154  LtePhyTag pktTag[numOfPbs];
155 
159  for ( int pb = 0 ; pb < numOfPbs ; pb++ )
160  {
161  // Create packet burst
162  packetBursts[pb] = CreateObject<PacketBurst> ();
163 
164  // Create packets and add them to the burst
165  for ( int i = 0 ; i < numOfPkts ; i++ )
166  {
167  pkt[pb][i] = Create<Packet> (1000);
168 
169  if ( i == 0 )
170  {
171  // Create phy tag (different for each packet burst)
172  // and add to the first packet
173  pktTag[pb] = LtePhyTag (100 * (pb + 1));
174  pkt[pb][i]->AddPacketTag ( pktTag[pb] );
175  }
176 
177  packetBursts[pb]->AddPacket ( pkt[pb][i] );
178  }
179  }
180 
181 
182  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
183  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
184  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
185  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
186  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
187 
188  (*noisePsd)[0] = 5.000000000000e-19;
189  (*noisePsd)[1] = 4.545454545455e-19;
190 
191  (*i1)[0] = 5.000000000000e-18;
192  (*i2)[0] = 5.000000000000e-16;
193  (*i3)[0] = 1.581138830084e-16;
194  (*i4)[0] = 7.924465962306e-17;
195  (*i1)[1] = 1.437398936440e-18;
196  (*i2)[1] = 5.722388235428e-16;
197  (*i3)[1] = 7.204059965732e-17;
198  (*i4)[1] = 5.722388235428e-17;
199 
200  Time ts = Seconds (1);
201  Time ds = Seconds (1);
202  Time ti1 = Seconds (0);
203  Time di1 = Seconds (3);
204  Time ti2 = Seconds (0.7);
205  Time di2 = Seconds (1);
206  Time ti3 = Seconds (1.2);
207  Time di3 = Seconds (1);
208  Time ti4 = Seconds (1.5);
209  Time di4 = Seconds (0.1);
210 
211  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
212 
217  // eNB sends data to 2 UEs through 2 subcarriers
218  Ptr<LteSpectrumSignalParameters> sp1 = Create<LteSpectrumSignalParameters> ();
219  sp1->psd = m_sv;
220  sp1->txPhy = 0;
221  sp1->duration = ds;
222  sp1->packetBurst = packetBursts[0];
223  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
224 
225 
226  Ptr<LteSpectrumSignalParameters> ip1 = Create<LteSpectrumSignalParameters> ();
227  ip1->psd = i1;
228  ip1->txPhy = 0;
229  ip1->duration = di1;
230  ip1->packetBurst = packetBursts[1];
231  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
232 
233  Ptr<LteSpectrumSignalParameters> ip2 = Create<LteSpectrumSignalParameters> ();
234  ip2->psd = i2;
235  ip2->txPhy = 0;
236  ip2->duration = di2;
237  ip2->packetBurst = packetBursts[2];
238  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
239 
240  Ptr<LteSpectrumSignalParameters> ip3 = Create<LteSpectrumSignalParameters> ();
241  ip3->psd = i3;
242  ip3->txPhy = 0;
243  ip3->duration = di3;
244  ip3->packetBurst = packetBursts[3];
245  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
246 
247  Ptr<LteSpectrumSignalParameters> ip4 = Create<LteSpectrumSignalParameters> ();
248  ip4->psd = i4;
249  ip4->txPhy = 0;
250  ip4->duration = di4;
251  ip4->packetBurst = packetBursts[4];
252  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
253 
254  Simulator::Stop (Seconds (5.0));
255  Simulator::Run ();
256 
261  SpectrumValue calculatedSinr = uePhy->GetSinr ();
262 
263  NS_LOG_INFO ("Theoretical SINR: " << *m_sinr);
264  NS_LOG_INFO ("Calculated SINR: " << calculatedSinr);
265 
266  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(calculatedSinr, *m_sinr, 0.0000001, "Wrong SINR !");
267  dlPhy->Dispose ();
269 }
270 
271 } // namespace ns3
272