A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-uplink-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-ue-phy.h"
32 #include "lte-test-uplink-sinr.h"
33 
34 NS_LOG_COMPONENT_DEFINE ("LteUplinkSinrTest");
35 
36 namespace ns3 {
37 
38 
47  : TestSuite ("lte-uplink-sinr", SYSTEM)
48 {
53 
54  Bands bands;
55  BandInfo bi;
56 
57  bi.fl = 2.400e9;
58  bi.fc = 2.410e9;
59  bi.fh = 2.420e9;
60  bands.push_back (bi);
61 
62  bi.fl = 2.420e9;
63  bi.fc = 2.431e9;
64  bi.fh = 2.442e9;
65  bands.push_back (bi);
66 
67  sm = Create<SpectrumModel> (bands);
68 
72  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue> (sm);
73  (*rxPsd1)[0] = 1.255943215755e-15;
74  (*rxPsd1)[1] = 0.0;
75 
76  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
77  (*rxPsd2)[0] = 0.0;
78  (*rxPsd2)[1] = 7.204059965732e-16;
79 
80  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
81  (*theoreticalSinr1)[0] = 3.72589167251055;
82  (*theoreticalSinr1)[1] = 3.72255684126076;
83 
84  AddTestCase (new LteUplinkSinrTestCase (rxPsd1, rxPsd2, theoreticalSinr1, "sdBm = [-46 -inf] and [-inf -48]"));
85 
89  Ptr<SpectrumValue> rxPsd3 = Create<SpectrumValue> (sm);
90  (*rxPsd3)[0] = 2.505936168136e-17;
91  (*rxPsd3)[1] = 0.0;
92 
93  Ptr<SpectrumValue> rxPsd4 = Create<SpectrumValue> (sm);
94  (*rxPsd4)[0] = 0.0;
95  (*rxPsd4)[1] = 3.610582885110e-17;
96 
97  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
98  (*theoreticalSinr2)[0] = 0.0743413124381667;
99  (*theoreticalSinr2)[1] = 0.1865697965291756;
100 
101  AddTestCase (new LteUplinkSinrTestCase (rxPsd3, rxPsd4, theoreticalSinr2, "sdBm = [-63 -inf] and [-inf -61]"));
102 
103 }
104 
106 
107 
113  : TestCase ("SINR calculation in uplink: " + name),
114  m_sv1 (sv1),
115  m_sv2 (sv2),
116  m_sm (sv1->GetSpectrumModel ()),
117  m_sinr (sinr)
118 {
119  NS_LOG_INFO ("Creating LteUplinkSinrTestCase");
120 }
121 
123 {
124 }
125 
126 void
128 {
132  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
133  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
134  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
135 
136  ulPhy->SetCellId (100);
137 
138  Ptr<LteCqiSinrChunkProcessor> chunkProcessor = Create<LteCqiSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
139  ulPhy->AddSinrChunkProcessor (chunkProcessor);
140 
148  // Number of packet bursts (2 data + 4 interferences)
149  int numOfDataPbs = 2;
150  int numOfIntfPbs = 4;
151  int numOfPbs = numOfDataPbs + numOfIntfPbs;
152 
153  // Number of packets in the packet bursts
154  int numOfPkts = 10;
155 
156  // Packet bursts
157  Ptr<PacketBurst> packetBursts[numOfPbs];
158 
159  // Packets
160  Ptr<Packet> pkt[numOfPbs][numOfPkts];
161 
162  // Phy tags
163  LtePhyTag pktTag[numOfPbs];
164 
165 
169  int pb = 0;
170  for ( int dataPb = 0 ; dataPb < numOfDataPbs ; dataPb++, pb++ )
171  {
172  // Create packet burst
173  packetBursts[pb] = CreateObject<PacketBurst> ();
174 
175  // Create packets and add them to the burst
176  for ( int i = 0 ; i < numOfPkts ; i++ )
177  {
178  pkt[pb][i] = Create<Packet> (1000);
179 
180  if ( i == 0 )
181  {
182  // Create phy tag (same for all data packet burst)
183  // and add to the first packet
184  pktTag[pb] = LtePhyTag (100);
185  pkt[pb][i]->AddPacketTag ( pktTag[pb] );
186  }
187 
188  packetBursts[pb]->AddPacket ( pkt[pb][i] );
189  }
190  }
191  for ( int intfPb = 0 ; intfPb < numOfIntfPbs ; intfPb++, pb++ )
192  {
193  // Create packet burst
194  packetBursts[pb] = CreateObject<PacketBurst> ();
195 
196  // Create packets and add them to the burst
197  for ( int i = 0 ; i < numOfPkts ; i++ )
198  {
199  pkt[pb][i] = Create<Packet> (1000);
200 
201  if ( i == 0 )
202  {
203  // Create phy tag (different for each packet burst)
204  // and add to the first packet
205  pktTag[pb] = LtePhyTag (100 * (pb + 1));
206  pkt[pb][i]->AddPacketTag ( pktTag[pb] );
207  }
208 
209  packetBursts[pb]->AddPacket ( pkt[pb][i] );
210  }
211  }
212 
213 
214  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
215  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
216  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
217  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
218  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
219 
220  (*noisePsd)[0] = 5.000000000000e-19;
221  (*noisePsd)[1] = 4.545454545455e-19;
222 
223  (*i1)[0] = 5.000000000000e-18;
224  (*i2)[0] = 5.000000000000e-16;
225  (*i3)[0] = 1.581138830084e-16;
226  (*i4)[0] = 7.924465962306e-17;
227  (*i1)[1] = 1.437398936440e-18;
228  (*i2)[1] = 5.722388235428e-16;
229  (*i3)[1] = 7.204059965732e-17;
230  (*i4)[1] = 5.722388235428e-17;
231 
232  Time ts = Seconds (1);
233  Time ds = Seconds (1);
234  Time ti1 = Seconds (0);
235  Time di1 = Seconds (3);
236  Time ti2 = Seconds (0.7);
237  Time di2 = Seconds (1);
238  Time ti3 = Seconds (1.2);
239  Time di3 = Seconds (1);
240  Time ti4 = Seconds (1.5);
241  Time di4 = Seconds (0.1);
242 
243  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
244 
249  // 2 UEs send data to the eNB through 2 subcarriers
250  Ptr<LteSpectrumSignalParameters> sp1 = Create<LteSpectrumSignalParameters> ();
251  sp1->psd = m_sv1;
252  sp1->txPhy = 0;
253  sp1->duration = ds;
254  sp1->packetBurst = packetBursts[0];
255  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
256 
257  Ptr<LteSpectrumSignalParameters> sp2 = Create<LteSpectrumSignalParameters> ();
258  sp2->psd = m_sv2;
259  sp2->txPhy = 0;
260  sp2->duration = ds;
261  sp2->packetBurst = packetBursts[1];
262  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
263 
264 
265  Ptr<LteSpectrumSignalParameters> ip1 = Create<LteSpectrumSignalParameters> ();
266  ip1->psd = i1;
267  ip1->txPhy = 0;
268  ip1->duration = di1;
269  ip1->packetBurst = packetBursts[2];
270  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
271 
272  Ptr<LteSpectrumSignalParameters> ip2 = Create<LteSpectrumSignalParameters> ();
273  ip2->psd = i2;
274  ip2->txPhy = 0;
275  ip2->duration = di2;
276  ip2->packetBurst = packetBursts[3];
277  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
278 
279  Ptr<LteSpectrumSignalParameters> ip3 = Create<LteSpectrumSignalParameters> ();
280  ip3->psd = i3;
281  ip3->txPhy = 0;
282  ip3->duration = di3;
283  ip3->packetBurst = packetBursts[4];
284  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
285 
286  Ptr<LteSpectrumSignalParameters> ip4 = Create<LteSpectrumSignalParameters> ();
287  ip4->psd = i4;
288  ip4->txPhy = 0;
289  ip4->duration = di4;
290  ip4->packetBurst = packetBursts[5];
291  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
292 
293  Simulator::Stop (Seconds (5.0));
294  Simulator::Run ();
295 
300  SpectrumValue calculatedSinr = uePhy->GetSinr ();
301 
302  NS_LOG_INFO ("Theoretical SINR: " << *m_sinr);
303  NS_LOG_INFO ("Calculated SINR: " << calculatedSinr);
304 
305  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (calculatedSinr, *m_sinr, 0.0000001, "Wrong SINR !");
306  ulPhy->Dispose ();
308 
309 }
310 
311 } // namespace ns3
312