diff --git a/src/lte/test/lena-test-downlink-sinr.cc b/src/lte/test/lena-test-downlink-sinr.cc index b4f42b74b..765d4f515 100644 --- a/src/lte/test/lena-test-downlink-sinr.cc +++ b/src/lte/test/lena-test-downlink-sinr.cc @@ -18,8 +18,7 @@ * Author: Manuel Requena */ -// #include "ns3/simulator.h" -// #include "ns3/test.h" +#include "ns3/simulator.h" #include "ns3/log.h" @@ -32,7 +31,7 @@ #include "ns3/lena-test-downlink-sinr.h" -NS_LOG_COMPONENT_DEFINE ("LenaTest"); +NS_LOG_COMPONENT_DEFINE ("LenaDownlinkSinrTest"); using namespace ns3; @@ -41,9 +40,29 @@ using namespace ns3; * Test 1.1 SINR calculation in downlink */ +/** + * TestSuite + */ + +LenaDownlinkSinrTestSuite::LenaDownlinkSinrTestSuite () + : TestSuite ("lena-downlink-sinr", SYSTEM) +{ + NS_LOG_INFO ("Creating LenaDownlinkSinrTestSuite"); + + AddTestCase (new LenaDownlinkSinrTestCase); +} + +static LenaDownlinkSinrTestSuite lenaDownlinkSinrTestSuite; + + +/** + * TestCase + */ + LenaDownlinkSinrTestCase::LenaDownlinkSinrTestCase () : TestCase ("SINR calculation in downlink") { + NS_LOG_INFO ("Creating LenaDownlinkSinrTestCase"); } LenaDownlinkSinrTestCase::~LenaDownlinkSinrTestCase () @@ -53,34 +72,37 @@ LenaDownlinkSinrTestCase::~LenaDownlinkSinrTestCase () void LenaDownlinkSinrTestCase::DoRun (void) { - LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL); - LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL); - LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL); - LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL); - LogComponentEnable ("LteRlc", LOG_LEVEL_ALL); - LogComponentEnable ("RrPacketScheduler", LOG_LEVEL_ALL); + LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL); - LogComponentEnable ("LtePhy", LOG_LEVEL_ALL); - LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL); - LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL); + LogComponentEnable ("LteEnbRrc", logLevel); + LogComponentEnable ("LteUeRrc", logLevel); + LogComponentEnable ("LteEnbMac", logLevel); + LogComponentEnable ("LteUeMac", logLevel); + LogComponentEnable ("LteRlc", logLevel); + LogComponentEnable ("RrPacketScheduler", logLevel); - LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL); - LogComponentEnable ("LteInterference", LOG_LEVEL_ALL); - LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL); + LogComponentEnable ("LtePhy", logLevel); + LogComponentEnable ("LteEnbPhy", logLevel); + LogComponentEnable ("LteUePhy", logLevel); - LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("LossModel", LOG_LEVEL_ALL); - LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL); - LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL); + LogComponentEnable ("LteSpectrumPhy", logLevel); + LogComponentEnable ("LteInterference", logLevel); + LogComponentEnable ("LteSinrChunkProcessor", logLevel); - LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL); - LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL); - LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL); + LogComponentEnable ("LtePropagationLossModel", logLevel); + LogComponentEnable ("LossModel", logLevel); + LogComponentEnable ("ShadowingLossModel", logLevel); + LogComponentEnable ("PenetrationLossModel", logLevel); + LogComponentEnable ("MultipathLossModel", logLevel); + LogComponentEnable ("PathLossModel", logLevel); - LogComponentEnable ("LenaTestSinrChunkProcessor", LOG_LEVEL_ALL); - LogComponentEnable ("LenaTest", LOG_LEVEL_ALL); + LogComponentEnable ("LteNetDevice", logLevel); + LogComponentEnable ("LteUeNetDevice", logLevel); + LogComponentEnable ("LteEnbNetDevice", logLevel); + + LogComponentEnable ("LenaTestSinrChunkProcessor", logLevel); + LogComponentEnable ("LenaDownlinkSinrTest", logLevel); + LogComponentEnable ("LenaUplinkSinrTest", logLevel); /** * Instantiate a single receiving LteSpectrumPhy @@ -91,8 +113,8 @@ LenaDownlinkSinrTestCase::DoRun (void) dlPhy->SetCellId (100); - Ptr p = Create (uePhy->GetObject ()); - dlPhy->AddSinrChunkProcessor (p); + Ptr chunkProcessor = Create (uePhy->GetObject ()); + dlPhy->AddSinrChunkProcessor (chunkProcessor); /** * Generate several calls to LteSpectrumPhy::StartRx corresponding to several signals. @@ -101,8 +123,8 @@ LenaDownlinkSinrTestCase::DoRun (void) * the others will have a different CellId and hence will be the interfering signals */ - // Number of packet bursts - int numOfPbs = 3; + // Number of packet bursts (1 data + 4 interferences) + int numOfPbs = 5; // Number of packets in the packet bursts int numOfPkts = 10; @@ -144,55 +166,86 @@ LenaDownlinkSinrTestCase::DoRun (void) /** * Build Spectrum Model values for signal */ - double myFreqs[] = {2.10, 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 2.17, 2.18, 2.19}; - int numOfFreqs = sizeof(myFreqs) / sizeof(double); - std::vector freqs (myFreqs, myFreqs + sizeof(myFreqs) / sizeof(double) ); + Ptr sm; - Ptr f = Create (freqs); - Ptr rxPsd = Create (f); - for ( int i = 0 ; i < numOfFreqs ; i++ ) - { - (*rxPsd)[i] = 1.11 + 0.01 * i; - } + Bands bands; + BandInfo bi; - Ptr noisePsd = Create (f); - for ( int i = 0 ; i < numOfFreqs ; i++ ) - { - (*noisePsd)[i] = 0.001; - } + bi.fl = 2.400e9; + bi.fc = 2.410e9; + bi.fh = 2.420e9; + bands.push_back (bi); - SpectrumValue saveRxPsd = *rxPsd; - SpectrumValue saveNoisePsd = *noisePsd; + bi.fl = 2.420e9; + bi.fc = 2.431e9; + bi.fh = 2.442e9; + bands.push_back (bi); + + sm = Create (bands); + + // Power Spectral Density of the signal of interest = [-46 -48] dBm and BW = [20 22] MHz + Ptr rxPsd = Create (sm); + (*rxPsd)[0] = 1.255943215755e-15; + (*rxPsd)[1] = 7.204059965732e-16; + + Ptr noisePsd = Create (sm); + Ptr i1 = Create (sm); + Ptr i2 = Create (sm); + Ptr i3 = Create (sm); + Ptr i4 = Create (sm); + + (*noisePsd)[0] = 5.000000000000e-19; + (*noisePsd)[1] = 4.545454545455e-19; + + (*i1)[0] = 5.000000000000e-18; + (*i2)[0] = 5.000000000000e-16; + (*i3)[0] = 1.581138830084e-16; + (*i4)[0] = 7.924465962306e-17; + (*i1)[1] = 1.437398936440e-18; + (*i2)[1] = 5.722388235428e-16; + (*i3)[1] = 7.204059965732e-17; + (*i4)[1] = 5.722388235428e-17; + + Time ts = Seconds (1); + Time ds = Seconds (1); + Time ti1 = Seconds (0); + Time di1 = Seconds (3); + Time ti2 = Seconds (0.7); + Time di2 = Seconds (1); + Time ti3 = Seconds (1.2); + Time di3 = Seconds (1); + Time ti4 = Seconds (1.5); + Time di4 = Seconds (0.1); dlPhy->SetNoisePowerSpectralDensity (noisePsd); - Time delay ("100ms"); - Time duration ("5ms"); - /** - * Schedule the reception of the signals + * Schedule the reception of the data signal plus the interference signals */ - for ( int pb = 0 ; pb < numOfPbs ; pb++) - { - Simulator::Schedule (delay, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[pb], rxPsd, dlPhy->GetSpectrumType(), duration); - } - Simulator::Stop (Seconds (1.0)); + Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[0], rxPsd, dlPhy->GetSpectrumType(), ds); + + Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[1], i1, dlPhy->GetSpectrumType(), di1); + Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[2], i2, dlPhy->GetSpectrumType(), di2); + Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[3], i3, dlPhy->GetSpectrumType(), di3); + Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, packetBursts[4], i4, dlPhy->GetSpectrumType(), di4); + + Simulator::Stop (Seconds (5.0)); Simulator::Run (); Simulator::Destroy (); /** - * Check that the values passed to LteSinrChunkProcessor::EvaluateSinrChunk () - * correspond to known values which have been calculated offline for the generated signals + * Check that the values passed to LteSinrChunkProcessor::EvaluateSinrChunk () correspond + * to known values which have been calculated offline (with octave) for the generated signals */ - NS_TEST_ASSERT_MSG_EQ (*rxPsd, saveRxPsd, "Data signal corrupted !"); - NS_TEST_ASSERT_MSG_EQ (*noisePsd, saveNoisePsd, "Noise signal corrupted !"); + SpectrumValue theoreticalSinr(sm); + theoreticalSinr[0] = 3.72589167251055; + theoreticalSinr[1] = 3.72255684126076; - SpectrumValue theoreticalSinr = (*rxPsd) / ( ( 2 * (*rxPsd) ) + (*noisePsd) ); - SpectrumValue calculatedSinr = p->GetSinr (); + SpectrumValue calculatedSinr = chunkProcessor->GetSinr (); -// NS_LOG_INFO ("Theoretical SINR: " << theoreticalSinr); -// NS_LOG_INFO ("Calculated SINR: " << calculatedSinr); + NS_LOG_INFO ("Theoretical SINR: " << theoreticalSinr); + NS_LOG_INFO ("Calculated SINR: " << calculatedSinr); - NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinr, theoreticalSinr, 0.000001, "Wrong SINR !"); + NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinr, theoreticalSinr, 0.0000001, "Wrong SINR !"); } diff --git a/src/lte/test/lena-test-downlink-sinr.h b/src/lte/test/lena-test-downlink-sinr.h index d003e7b21..81c7099fe 100644 --- a/src/lte/test/lena-test-downlink-sinr.h +++ b/src/lte/test/lena-test-downlink-sinr.h @@ -21,7 +21,6 @@ #ifndef LENA_TEST_DOWNLINK_SINR_H #define LENA_TEST_DOWNLINK_SINR_H -#include "ns3/simulator.h" #include "ns3/test.h" @@ -31,6 +30,13 @@ using namespace ns3; /** * Test 1.1 SINR calculation in downlink */ +class LenaDownlinkSinrTestSuite : public TestSuite +{ +public: + LenaDownlinkSinrTestSuite (); +}; + + class LenaDownlinkSinrTestCase : public TestCase { public: